[Bf-committers] Joystick LogicBricks Patch

charlie carley snailrose at msn.com
Thu Dec 16 17:12:57 CET 2004



hello I would like someone to have a look at this patch, to see if it can 
make it into cvs
its missing the actual code, if needed i can post it somewhere
thanks
snailrose...

Index: source/blender/blenkernel/intern/sca.c
===================================================================
RCS file: 
/cvsroot/bf-blender/blender/source/blender/blenkernel/intern/sca.c,v
retrieving revision 1.3
diff -u -r1.3 sca.c
--- source/blender/blenkernel/intern/sca.c	25 Nov 2002 10:13:52 -0000	1.3
+++ source/blender/blenkernel/intern/sca.c	15 Dec 2004 20:56:33 -0000
@@ -172,6 +172,9 @@
	case SENS_MESSAGE:
		sens->data= MEM_callocN(sizeof(bMessageSensor), "messagesens");
		break;
+	case SENS_JOYSTICK:
+		sens->data= MEM_callocN(sizeof(bJoystickSensor), "joysticksens");
+		break;
	default:
		; /* this is very severe... I cannot make any memory for this        */
		/* logic brick...                                                    */
Index: source/blender/blenloader/intern/writefile.c
===================================================================
RCS file: 
/cvsroot/bf-blender/blender/source/blender/blenloader/intern/writefile.c,v
retrieving revision 1.35
diff -u -r1.35 writefile.c
--- source/blender/blenloader/intern/writefile.c	4 Dec 2004 21:49:01 
-0000	1.35
+++ source/blender/blenloader/intern/writefile.c	15 Dec 2004 20:57:54 -0000
@@ -472,6 +472,10 @@
		case SENS_MESSAGE:
			writestruct(wd, DATA, "bMessageSensor", 1, sens->data);
			break;
+		case SENS_JOYSTICK:
+			writestruct(wd, DATA, "bJoystickSensor", 1, sens->data);
+			break;
+
		default:
			; /* error: don't know how to write this file */
		}
Index: source/blender/makesdna/DNA_sensor_types.h
===================================================================
RCS file: 
/cvsroot/bf-blender/blender/source/blender/makesdna/DNA_sensor_types.h,v
retrieving revision 1.6
diff -u -r1.6 DNA_sensor_types.h
--- source/blender/makesdna/DNA_sensor_types.h	2 May 2004 23:45:00 -0000	1.6
+++ source/blender/makesdna/DNA_sensor_types.h	15 Dec 2004 21:01:01 -0000
@@ -151,6 +151,19 @@
	int pad;
} bSensor;

+typedef struct bJoystickSensor {
+	char name[32];
+	short type;
+	short pad;
+	int axis;
+	int axisf;
+	int button;
+	int	buttonf;
+	int hat;
+	int hatf;
+	int precision;
+} bJoystickSensor;
+
/* bMouseSensor->type: uses blender event defines */

/* propertysensor->type */
@@ -186,7 +199,7 @@
#define SENS_RANDOM     8
#define SENS_RAY        9
#define SENS_MESSAGE   10
-
+#define SENS_JOYSTICK  11
/* sensor->flag */
#define SENS_SHOW		1
#define SENS_DEL		2
@@ -223,6 +236,20 @@
#define BL_SENS_MOUSE_WHEEL_DOWN     6
#define BL_SENS_MOUSE_MOVEMENT       8
#define BL_SENS_MOUSE_MOUSEOVER      16
+
+#define SENS_JOY_BUTTON			0
+#define SENS_JOY_BUTTON_PRESSED	0
+#define SENS_JOY_BUTTON_RELEASED1
+
+#define SENS_JOY_AXIS			1
+#define SENS_JOY_X_AXIS			0
+#define SENS_JOY_Y_AXIS			1
+#define SENS_JOY_NEG_X_AXIS     2
+#define SENS_JOY_NEG_Y_AXIS     3
+#define SENS_JOY_PRECISION		4
+
+#define SENS_JOY_HAT			2
+#define SENS_JOY_HAT_DIR		0

#endif

Index: source/blender/src/buttons_logic.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/buttons_logic.c,v
retrieving revision 1.19
diff -u -r1.19 buttons_logic.c
--- source/blender/src/buttons_logic.c	7 Dec 2004 18:14:03 -0000	1.19
+++ source/blender/src/buttons_logic.c	15 Dec 2004 20:54:41 -0000
@@ -640,6 +640,9 @@
		return "Ray";
	case SENS_MESSAGE:
		return "Message";
+	case SENS_JOYSTICK:
+		return "Joystick";
+
	}
	return "unknown";
}
@@ -649,7 +652,7 @@
	/* the number needs to match defines in game.h */
	return "Sensors %t|Always %x0|Keyboard %x3|Mouse %x5|"
		"Touch %x1|Collision %x6|Near %x2|Radar %x7|"
-		"Property %x4|Random %x8|Ray %x9|Message %x10";
+		"Property %x4|Random %x8|Ray %x9|Message %x10|Joystick %x11";
}

static char *controller_name(int type)
@@ -928,6 +931,7 @@
	case SENS_RANDOM:		return TH_BUT_NEUTRAL;
	case SENS_RAY:			return TH_BUT_SETTING1;
	case SENS_MESSAGE:		return TH_BUT_SETTING2;
+	case SENS_JOYSTICK:		return TH_BUT_NEUTRAL;
	default:				return TH_BUT_NEUTRAL;
	}
}
@@ -980,6 +984,7 @@
	bRandomSensor    *randomSensor = NULL;
	bRaySensor       *raySens      = NULL;
	bMessageSensor   *mes          = NULL;
+	bJoystickSensor	 *joy		   = NULL;
	short ysize;
	char *str;

@@ -1297,6 +1302,64 @@
				", or empty for all");

			yco -= ysize;
+			break;
+		}
+	case SENS_JOYSTICK:
+		{
+
+			ysize =  72;
+
+			glRects(xco, yco-ysize, xco+width, yco);
+			uiEmboss((float)xco, (float)yco-ysize, (float)xco+width, (float)yco, 1);
+
+			/* line 1: header */
+			draw_default_sensor_header(sens, block, xco, yco, width);
+
+			joy= sens->data;
+
+
+			str= "Type %t|Button %x0|Axis %x1|Hat%x2";
+			uiDefButS(block, MENU, B_REDR, str, xco+10, yco-44, 0.6 * (width-20), 
19,
+				&joy->type, 0, 31, 0, 0,
+				"The type of event this joystick sensor is triggered on.");
+
+			if(joy->type == SENS_JOY_BUTTON)
+			{
+				uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.6 * (width-20), 
19,
+				&joy->button, 0, 18, 100, 0,
+				"Specify which button to use");
+
+				str = "Type %t|Pressed %x0|Released %x1";
+				uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 
0.4 * (width-20), 19,
+				&joy->buttonf, 2.0, 31, 0, 0,
+				"Button pressed or released.");
+			}
+			else if(joy->type == SENS_JOY_AXIS)
+			{
+				uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.6 * (width-20), 
19,
+				&joy->axis, 1, 2.0, 100, 0,
+				"Specify which axis to use");
+
+				uiDefButI(block, NUM, 1, "Threshold:", xco+10 + 0.6 * 
(width-20),yco-44, 0.4 * (width-20), 19,
+				&joy->precision, 0, 32768.0, 100, 0,
+				"Specify the precision of the axis");
+
+				str = "Type %t|Up Axis %x1 |Down Axis %x3|Left Axis %x2|Right Axis 
%x0";
+				uiDefButI(block, MENU, B_REDR, str, xco+10 + 0.6 * (width-20), yco-68, 
0.4 * (width-20), 19,
+				&joy->axisf, 2.0, 31, 0, 0,
+				"The direction of the axis");
+			}
+			else
+			{
+				uiDefButI(block, NUM, 1, "Number:", xco+10, yco-68, 0.6 * (width-20), 
19,
+				&joy->hat, 1, 2.0, 100, 0,
+				"Specify which hat to use");
+
+				uiDefButI(block, NUM, 1, "Direction:", xco+10 + 0.6 * (width-20), 
yco-68, 0.4 * (width-20), 19,
+				&joy->hatf, 0, 12, 100, 0,
+				"Specify hat direction");
+			}
+			yco-= ysize;
			break;
		}
	}
Index: source/gameengine/Converter/KX_ConvertSensors.cpp
===================================================================
RCS file: 
/cvsroot/bf-blender/blender/source/gameengine/Converter/KX_ConvertSensors.cpp,v
retrieving revision 1.5
diff -u -r1.5 KX_ConvertSensors.cpp
--- source/gameengine/Converter/KX_ConvertSensors.cpp	2 May 2004 23:45:02 
-0000	1.5
+++ source/gameengine/Converter/KX_ConvertSensors.cpp	15 Dec 2004 20:48:05 
-0000
@@ -65,7 +65,7 @@
#include "KX_NearSensor.h"
#include "KX_RadarSensor.h"
#include "KX_MouseFocusSensor.h"
-
+#include "SCA_JoystickSensor.h"
#include "KX_NetworkMessageSensor.h"

#include "SCA_PropertySensor.h"
@@ -609,6 +609,62 @@
						gamesensor = new SCA_RandomSensor(eventmgr, gameobj, randomSeed);
					}
				}
+				break;
+			}
+		case SENS_JOYSTICK:
+			{
+				int joysticktype = SCA_JoystickSensor::KX_JOYSENSORMODE_NODEF;
+
+				bJoystickSensor* bjoy = (bJoystickSensor*) sens->data;
+
+				SCA_JoystickManager *eventmgr
+					= (SCA_JoystickManager*) 
logicmgr->FindEventManager(SCA_EventManager::JOY_EVENTMGR);
+				if (eventmgr)
+				{
+					int axis	=0;
+					int axisf	=0;
+					int button	=0;
+					int buttonf =0;
+					int hat		=0;
+					int hatf	=0;
+					int prec	=0;
+
+					switch(bjoy->type)
+					{
+					case SENS_JOY_AXIS:
+						axis	= bjoy->axis;
+						axisf	= bjoy->axisf;
+						prec	= bjoy->precision;
+						joysticktype  = SCA_JoystickSensor::KX_JOYSENSORMODE_AXIS;
+						break;
+					case SENS_JOY_BUTTON:
+						button	= bjoy->button;
+						buttonf	= bjoy->buttonf;
+						joysticktype  = SCA_JoystickSensor::KX_JOYSENSORMODE_BUTTON;
+						break;
+					case SENS_JOY_HAT:
+						hat		= bjoy->hat;
+						hatf	= bjoy->hatf;
+						joysticktype  = SCA_JoystickSensor::KX_JOYSENSORMODE_HAT;
+						break;
+					default:
+						printf("Error: bad case statement\n");
+						break;
+					}
+					gamesensor = new SCA_JoystickSensor(
+						eventmgr,
+						gameobj,
+						joysticktype,
+						axis,axisf,
+						prec,
+						button,buttonf,
+						hat,hatf);
+				}
+				else
+				{
+					printf("Error there was a problem finding the event manager\n");
+				}
+
				break;
			}
		default:
Index: source/gameengine/GameLogic/SCA_EventManager.h
===================================================================
RCS file: 
/cvsroot/bf-blender/blender/source/gameengine/GameLogic/SCA_EventManager.h,v
retrieving revision 1.7
diff -u -r1.7 SCA_EventManager.h
--- source/gameengine/GameLogic/SCA_EventManager.h	16 Oct 2004 11:41:48 
-0000	1.7
+++ source/gameengine/GameLogic/SCA_EventManager.h	15 Dec 2004 21:18:30 
-0000
@@ -51,7 +51,8 @@
		RANDOM_EVENTMGR,
		RAY_EVENTMGR,
		RADAR_EVENTMGR,
-		NETWORK_EVENTMGR
+		NETWORK_EVENTMGR,
+		JOY_EVENTMGR
	};

	SCA_EventManager(EVENT_MANAGER_TYPE mgrtype);
Index: source/gameengine/GameLogic/SConscript
===================================================================
RCS file: 
/cvsroot/bf-blender/blender/source/gameengine/GameLogic/SConscript,v
retrieving revision 1.6
diff -u -r1.6 SConscript
--- source/gameengine/GameLogic/SConscript	16 May 2004 13:07:17 -0000	1.6
+++ source/gameengine/GameLogic/SConscript	15 Dec 2004 21:30:43 -0000
@@ -30,7 +30,13 @@
                 'SCA_RandomEventManager.cpp',
                 'SCA_RandomNumberGenerator.cpp',
                 'SCA_RandomSensor.cpp',
-                'SCA_TimeEventManager.cpp']
+                'SCA_TimeEventManager.cpp',
+				##Joystick Includes
+				'SCA_JoystickManager.cpp',
+				'SCA_JoystickSensor.cpp',
+				'Joystick/SCA_Joystick.cpp',
+				'Joystick/SCA_JoystickEvents.cpp'
+				]

sca_gamelogic_env.Append (CPPPATH=['.',
                                    '#/source/kernel/gen_system',
Index: source/gameengine/Ketsji/KX_Scene.cpp
===================================================================
RCS file: 
/cvsroot/bf-blender/blender/source/gameengine/Ketsji/KX_Scene.cpp,v
retrieving revision 1.12
diff -u -r1.12 KX_Scene.cpp
--- source/gameengine/Ketsji/KX_Scene.cpp	13 Dec 2004 09:53:30 -0000	1.12
+++ source/gameengine/Ketsji/KX_Scene.cpp	16 Dec 2004 15:41:38 -0000
@@ -53,6 +53,7 @@
#include "SCA_MouseManager.h"
#include "SCA_PropertyEventManager.h"
#include "KX_Camera.h"
+#include "SCA_JoystickManager.h"

#include "RAS_MeshObject.h"
#include "RAS_IRasterizer.h"
@@ -135,6 +136,8 @@
	KX_RayEventManager* raymgr = new KX_RayEventManager(m_logicmgr);

	KX_NetworkEventManager* netmgr = new KX_NetworkEventManager(m_logicmgr, 
ndi);
+
+	SCA_JoystickManager *joymgr	= new SCA_JoystickManager(m_logicmgr);

	m_logicmgr->RegisterEventManager(alwaysmgr);
	m_logicmgr->RegisterEventManager(propmgr);
@@ -144,6 +147,7 @@
	m_logicmgr->RegisterEventManager(rndmgr);
	m_logicmgr->RegisterEventManager(raymgr);
	m_logicmgr->RegisterEventManager(netmgr);
+	m_logicmgr->RegisterEventManager(joymgr);

	m_soundScene = new SND_Scene(adi);
	assert (m_networkDeviceInterface != NULL);
@@ -187,7 +191,7 @@

	if (m_euthanasyobjects)
		m_euthanasyobjects->Release();
-
+
	if (m_logicmgr)
		delete m_logicmgr;

@@ -204,7 +208,6 @@
	{
		delete m_bucketmanager;
	}
-
	Py_DECREF(m_attrlist);
}

Index: source/gameengine/Ketsji/KX_Scene.h
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/gameengine/Ketsji/KX_Scene.h,v
retrieving revision 1.11
diff -u -r1.11 KX_Scene.h
--- source/gameengine/Ketsji/KX_Scene.h	22 Nov 2004 10:19:19 -0000	1.11
+++ source/gameengine/Ketsji/KX_Scene.h	15 Dec 2004 20:41:43 -0000
@@ -83,7 +83,7 @@
class RAS_IPolyMaterial;
class RAS_IRasterizer;
class RAS_IRenderTools;
-
+class SCA_JoystickManager;
/**
  * The KX_Scene holds all data for an independent scene. It relates
  * KX_Objects to the specific objects in the modules.

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! 
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/



More information about the Bf-committers mailing list