This commit is contained in:
2014-10-18 17:43:25 +01:00
commit f45b3ebaf8
97 changed files with 7544 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
//**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification,
// distribution or publication without the prior written
// consent of the author is prohibited.
//
// Created on 27. Dezember 2001, 00:14
//**********************************************************************************************
package de.hardcode.jxinput.directinput;
import de.hardcode.jxinput.Axis;
/**
*
* @author Herkules
*/
class DIAxis implements Axis
{
private final int mDeviceIdx;
private final int mIdx;
/**
* Creates a new instance of DIAxis.
*/
DIAxis( int devidx, int idx )
{
mDeviceIdx = devidx;
mIdx = idx;
}
public String getName()
{
return DirectInputDriver.getAxisName( mDeviceIdx, mIdx );
}
/**
* Denote wether this feature has changed beyond it's resolution since it got last
* updated.
*/
public boolean hasChanged()
{
return true;
}
public double getValue()
{
return DirectInputDriver.getAxisValue( mDeviceIdx, mIdx );
}
public int getType()
{
return DirectInputDriver.getAxisType( mDeviceIdx, mIdx );
}
/**
* Inform about the resolution of the axis.
*
* @return resolution, e.g. 2^-16
*/
public double getResolution()
{
// extend the driver here!!
// Here I assume typical 16 bit resolution
return ( getType() == Axis.SLIDER ? 1.0/65536.0 : 2.0/65536.0 ) ;
}
}

View File

@@ -0,0 +1,55 @@
//**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification,
// distribution or publication without the prior written
// consent of the author is prohibited.
//
// Created on 27. Dezember 2001, 00:14
//**********************************************************************************************
package de.hardcode.jxinput.directinput;
import de.hardcode.jxinput.Button;
/**
*
* @author Herkules
*/
class DIButton implements Button
{
private final int mDeviceIdx;
private final int mIdx;
/**
* Creates a new instance of DIButton.
*/
DIButton( int devidx, int idx )
{
mDeviceIdx = devidx;
mIdx = idx;
}
public String getName()
{
return DirectInputDriver.getButtonName( mDeviceIdx, mIdx );
}
/**
* Denote wether this feature has changed beyond it's resolution since it got last
* updated.
*/
public boolean hasChanged()
{
return true;
}
public int getType()
{
return DirectInputDriver.getButtonType( mDeviceIdx, mIdx );
}
public boolean getState()
{
return DirectInputDriver.getButtonState( mDeviceIdx, mIdx );
}
}

View File

@@ -0,0 +1,78 @@
//**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification,
// distribution or publication without the prior written
// consent of the author is prohibited.
//
// Created on 27. Dezember 2001, 23:40
//**********************************************************************************************
package de.hardcode.jxinput.directinput;
import de.hardcode.jxinput.Directional;
/**
*
* @author Herkules
*/
class DIDirectional implements Directional
{
private final int mDeviceIdx;
private final int mIdx;
/**
* Creates a new instance of DIDirectional.
*/
DIDirectional( int devidx, int idx )
{
mDeviceIdx = devidx;
mIdx = idx;
}
/** Features may have a name provided e.g. by the driver. */
public String getName()
{
return DirectInputDriver.getDirectionalName( mDeviceIdx, mIdx );
}
/**
* Denote wether this feature has changed beyond it's resolution since it got last
* updated.
*/
public boolean hasChanged()
{
return true;
}
public boolean isCentered()
{
return ( 0xffff == (DirectInputDriver.getDirection( mDeviceIdx, mIdx ) & 0xffff) );
}
public int getDirection()
{
return isCentered() ? 0 : DirectInputDriver.getDirection( mDeviceIdx, mIdx );
}
public double getValue()
{
if ( isCentered() )
return 0.0;
return 1.0;
}
/**
* Inform about the resolution of the value returned by <code>getValue()</code>.
*
* @return resolution, e.g. 1.0 for coolie hats
*/
public double getResolution()
{
// DI POV always return 0.0 or 1.0, so the resolution is 1.0.
return 1.0;
}
}

View File

@@ -0,0 +1,170 @@
//**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification,
// distribution or publication without the prior written
// consent of the author is prohibited.
//
// Created on 26. Dezember 2001, 00:40
//**********************************************************************************************
package de.hardcode.jxinput.directinput;
import de.hardcode.jxinput.JXInputDevice;
import de.hardcode.jxinput.Axis;
import de.hardcode.jxinput.Directional;
import de.hardcode.jxinput.Button;
/**
*
* @author Herkules
*/
public class DirectInputDevice implements JXInputDevice
{
int mDeviceIdx;
private DIAxis[] mAxes;
private DIButton[] mButtons;
private DIDirectional[] mDirectionals;
/**
* The number of DirectInput devices available with the driver.
*/
public static int getNumberOfDevices()
{
if ( DirectInputDriver.isAvailable() )
return DirectInputDriver.getNumberOfDevices();
return 0;
}
/**
* Update the state of all devices.
*/
public static void update()
{
if ( DirectInputDriver.isAvailable() )
DirectInputDriver.nativeupdate();
}
/**
* Creates a new instance of DirectInputDevice.
*/
public DirectInputDevice( int devidx )
{
mDeviceIdx = devidx;
init();
}
/**
* Reset the DirectInput connection.
*/
public static void reset()
{
if ( DirectInputDriver.isAvailable() )
DirectInputDriver.reset();
}
/**
* Initialisation of fields.
*/
private final void init()
{
//
// Allocate arrays for max. number of features
//
mAxes = new DIAxis [ getMaxNumberOfAxes() ];
mButtons = new DIButton [ getMaxNumberOfButtons() ];
mDirectionals = new DIDirectional [ getMaxNumberOfDirectionals() ];
//
// Fill arrays due to the state of the driver.
//
for ( int i = 0; i < mAxes.length; ++i )
{
if ( DirectInputDriver.isAxisAvailable( mDeviceIdx, i ) )
mAxes[ i ] = new DIAxis( mDeviceIdx, i );
}
for ( int i = 0; i < mButtons.length; ++i )
{
if ( DirectInputDriver.isButtonAvailable( mDeviceIdx, i ) )
mButtons[ i ] = new DIButton( mDeviceIdx, i );
}
for ( int i = 0; i < mDirectionals.length; ++i )
{
if ( DirectInputDriver.isDirectionalAvailable( mDeviceIdx, i ) )
mDirectionals[ i ] = new DIDirectional( mDeviceIdx, i );
}
}
/** Devices may have a name. */
public String getName()
{
String name = DirectInputDriver.getName( mDeviceIdx );
if ( null == name )
return "Win32 DirectInput Joystick";
return name;
}
/** Actual number of available buttons. */
public int getNumberOfButtons()
{
return DirectInputDriver.getNumberOfButtons( mDeviceIdx );
}
/** Actual number of available axes. */
public int getNumberOfAxes()
{
return DirectInputDriver.getNumberOfAxes( mDeviceIdx );
}
/** Actual number of available directional features. */
public int getNumberOfDirectionals()
{
return DirectInputDriver.getNumberOfDirectionals( mDeviceIdx );
}
/** Maximum number of buttons as an upper bound for index values. */
public int getMaxNumberOfButtons()
{
return DirectInputDriver.getMaxNumberOfButtons();
}
/** Maximum number of axes as an upper bound for index values. */
public int getMaxNumberOfAxes()
{
return DirectInputDriver.getMaxNumberOfAxes();
}
/** Maximum number of available directional features. */
public int getMaxNumberOfDirectionals()
{
return DirectInputDriver.getMaxNumberOfDirectionals();
}
public Axis getAxis(int idx)
{
return mAxes[ idx ];
}
public Button getButton(int idx)
{
return mButtons[ idx ];
}
public Directional getDirectional(int idx)
{
return mDirectionals[ idx ];
}
}

View File

@@ -0,0 +1,184 @@
//**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification,
// distribution or publication without the prior written
// consent of the author is prohibited.
//
// Created on 19. Dezember 2001, 22:44
//**********************************************************************************************
package de.hardcode.jxinput.directinput;
import java.lang.reflect.Array;
/**
* DirectInputDriver: the connection to the Win32 joystick.
* There is only one allowed, so the layout of this class is merely static.
*
* History:
*
* Changes since 0.1beta:
* - support of multiple devices addressed by the <code>dev</code> index
*
*
* @author Herkules
* @version 0.2beta
*/
class DirectInputDriver
{
private final static String NATIVE_LIB_NAME = "jxinput";
/** Remember wether nativeinit() succeeded. */
static boolean sIsOperational = false;
//
// Static arrays to hold the values.
//
private static double [][] sAxisValues;
private static boolean [][] sButtonStates;
private static int [][] sDirectionalValues;
/**
* Perform the static initialization.
*/
static
{
try
{
// Load the native lib.
System.loadLibrary( NATIVE_LIB_NAME );
init();
}
catch( SecurityException e )
{
Log.logger.warning("Native library jxinput not loaded due to a SecurityException.");
}
catch( UnsatisfiedLinkError e )
{
Log.logger.info("Native library jxinput not loaded due to an UnsatisfiedLinkError.");
}
}
private final static void init()
{
sIsOperational = false;
//
// Initialize it.
//
if ( nativeinit() )
{
int devs = getNumberOfDevices();
sAxisValues = new double [ devs ][ DirectInputDriver.getMaxNumberOfAxes() ];
sButtonStates = new boolean [ devs ][ DirectInputDriver.getMaxNumberOfButtons() ];
sDirectionalValues = new int [ devs ][ DirectInputDriver.getMaxNumberOfDirectionals() ];
// Bind the native lib to my variables.
bind();
// Remember I am fine.
sIsOperational = true;
}
}
/**
* Static ctor of DirectInputDriver.
* No object will be created due to the static layout.
*/
private DirectInputDriver()
{
}
// Administration
private static native boolean nativeinit();
private static native void nativeexit();
private static native void bind();
static native int getNumberOfDevices();
// Configuration
static native String getName( int dev );
static native int getNumberOfAxes( int dev );
static native int getNumberOfButtons( int dev );
static native int getNumberOfDirectionals( int dev );
static native int getMaxNumberOfAxes();
static native int getMaxNumberOfButtons();
static native int getMaxNumberOfDirectionals();
static native boolean isAxisAvailable( int dev, int idx );
static native String getAxisName( int dev, int idx );
static native int getAxisType( int dev, int idx );
static native boolean isButtonAvailable( int dev, int idx );
static native String getButtonName( int dev, int idx );
static native int getButtonType( int dev, int idx );
static native boolean isDirectionalAvailable( int dev, int idx );
static native String getDirectionalName( int dev, int idx );
// Operation
static native void nativeupdate();
public static boolean isAvailable()
{
return sIsOperational;
}
/**
* Shutdown the device and free all Win32 resources.
* It is not a good idea to access any joystick features after
* <code>shutdown()</code>.
*/
static void shutdown()
{
nativeexit();
sAxisValues = null;
sButtonStates = null;
sDirectionalValues = null;
}
/**
* Reset the device and free all Win32 resources.
*/
static void reset()
{
shutdown();
init();
}
static double getAxisValue( int dev, int idx )
{
return sAxisValues[ dev ][ idx ];
}
static boolean getButtonState( int dev, int idx )
{
return sButtonStates[ dev ][ idx ];
}
static int getDirection( int dev, int idx )
{
return sDirectionalValues[ dev ][ idx ];
}
/**
* @param args the command line arguments
*/
public static void main (String args[])
{
if ( ! sIsOperational )
return;
for( int i = 0; i < 5000; ++i )
nativeupdate();
shutdown();
}
}

View File

@@ -0,0 +1,34 @@
//**********************************************************************************************
// (C) Copyright 2002 by Dipl. Phys. Joerg Plewe, HARDCODE Development
// All rights reserved. Copying, modification,
// distribution or publication without the prior written
// consent of the author is prohibited.
//
// Created on 29. Oktober 2002, 22:57
//**********************************************************************************************
package de.hardcode.jxinput.directinput;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Herkules
*/
public class Log
{
public final static Logger logger = Logger.getLogger( Log.class.getPackage().getName() );
// static
// {
// logger.setLevel( Level.ALL );
// }
/**
* Creates a new instance of Log.
*/
private Log()
{
}
}