Update to ZDoom r1679:

- Changed the definition of SBarInfoCoordinate to use bitfields to pack its
  members into 32 bits so that it can be stored in a plain old int without
  any transformations. The transformation coord -> int -> coord was
  destructive if the coordinate value was negative, causing the final
  coordinate to be centered even if the original was not.
- SBARINFO patch: Enable forcescaled with fullscreenoffsets.
- Fixed: Since UDMF allows for fractional vertex coordinates, it is no longer
  safe for P_AlignPlane() to truncate coordinates when searching for the
  furthest vertex from the line.
- The reorganized DirectInput game controller code finally compiles. (Ugh! It
  took far too long to reach this point.) Manual axis configuration is
  currently disabled, since I need to rewrite that, too. The eventual point of
  this is that the code will be modular enough that I can just plop in
  routines for XInput controllers and driver-less PlayStation 2 adapters
  without much fuss, since the old joystick code was very much DirectInput-
  centric.
- Changed AWeaponGiver to keep the weapon actor around instead of respawning a new
  one for each call.
- Fixed: AWeaponGiver::TryPickup checked the wrong item for ammo to give.
- fixed: FRandom::Random2(int mask) must return the difference between 2 byte values
  for compatibility.
- fixed: The sound name world/volcano/shoot was accidentally destroyed in the source.
- Reintroduced damage thrust clamping but with a higher threshold. The clamping
  is now also done in floating point before any fixed point overflows can occur.


git-svn-id: http://mancubus.net/svn/hosted/gzdoom/trunk@366 b0f79afe-0144-0410-b225-9a4edf0717df
This commit is contained in:
Christoph Oelckers 2009-06-24 22:19:34 +00:00
parent 30d7d8ca4b
commit 84a02cd630
19 changed files with 1422 additions and 816 deletions

View file

@ -111,7 +111,8 @@ if( WIN32 )
comctl32
comdlg32
ws2_32
setupapi )
setupapi
oleaut32 )
else( WIN32 )
option( NO_GTK "Disable GTK+ dialogs (Not applicable to Windows)" )
option( VALGRIND "Add special Valgrind sequences to self-modifying code" )
@ -416,6 +417,7 @@ if( WIN32 )
win32/i_input.cpp
win32/i_keyboard.cpp
win32/i_mouse.cpp
win32/i_dijoy.cpp
win32/i_main.cpp
win32/i_movie.cpp
win32/i_system.cpp

View file

@ -172,13 +172,17 @@ enum ESkillLevels
#define NUM_KEYS 0x19C
#define JOYAXIS_NONE 0
#define JOYAXIS_YAW 1
#define JOYAXIS_PITCH 2
#define JOYAXIS_FORWARD 3
#define JOYAXIS_SIDE 4
#define JOYAXIS_UP 5
//#define JOYAXIS_ROLL 6 // Ha ha. No roll for you.
enum EJoyAxis
{
JOYAXIS_None = -1,
JOYAXIS_Yaw,
JOYAXIS_Pitch,
JOYAXIS_Forward,
JOYAXIS_Side,
JOYAXIS_Up,
// JOYAXIS_Roll, // Ha ha. No roll for you.
NUM_JOYAXIS,
};
// [RH] dmflags bits (based on Q2's)
enum

View file

@ -207,8 +207,6 @@ EXTERN_CVAR (Bool, developer)
extern bool ToggleFullscreen;
extern float JoyAxes[6];
extern int Net_Arbitrator;
EXTERN_CVAR (Bool, var_friction)

View file

@ -41,6 +41,7 @@
#include "m_random.h"
#include "m_crc32.h"
#include "i_system.h"
#include "i_input.h"
#include "p_saveg.h"
#include "p_tick.h"
#include "d_main.h"
@ -575,22 +576,39 @@ void G_BuildTiccmd (ticcmd_t *cmd)
if (Button_MoveUp.bDown) cmd->ucmd.buttons |= BT_MOVEUP;
if (Button_ShowScores.bDown) cmd->ucmd.buttons |= BT_SHOWSCORES;
// [RH] Scale joystick moves to full range of allowed speeds
if (JoyAxes[JOYAXIS_PITCH] != 0)
// Handle joysticks/game controllers.
float joyaxes[NUM_JOYAXIS];
I_GetAxes(joyaxes);
// Remap some axes depending on button state.
if (Button_Strafe.bDown || (Button_Mlook.bDown && lookstrafe))
{
G_AddViewPitch (int((JoyAxes[JOYAXIS_PITCH] * 2048) / 256));
joyaxes[JOYAXIS_Side] = -joyaxes[JOYAXIS_Yaw];
joyaxes[JOYAXIS_Yaw] = 0;
}
if (Button_Mlook.bDown)
{
joyaxes[JOYAXIS_Pitch] = joyaxes[JOYAXIS_Forward];
joyaxes[JOYAXIS_Forward] = 0;
}
if (joyaxes[JOYAXIS_Pitch] != 0)
{
G_AddViewPitch(int(joyaxes[JOYAXIS_Pitch] * 2048));
LocalKeyboardTurner = true;
}
if (JoyAxes[JOYAXIS_YAW] != 0)
if (joyaxes[JOYAXIS_Yaw] != 0)
{
G_AddViewAngle (int((-1280 * JoyAxes[JOYAXIS_YAW]) / 256));
G_AddViewAngle(int(-1280 * joyaxes[JOYAXIS_Yaw]));
LocalKeyboardTurner = true;
}
side += int((MAXPLMOVE * JoyAxes[JOYAXIS_SIDE]) / 256);
forward += int((JoyAxes[JOYAXIS_FORWARD] * MAXPLMOVE) / 256);
fly += int(JoyAxes[JOYAXIS_UP] * 8);
side += int(MAXPLMOVE * joyaxes[JOYAXIS_Side]);
forward += int(joyaxes[JOYAXIS_Forward] * MAXPLMOVE);
fly += int(joyaxes[JOYAXIS_Up] * 2048);
// Handle mice.
if (!Button_Mlook.bDown && !freelook)
{
forward += (int)((float)mousey * m_forward);
@ -609,6 +627,7 @@ void G_BuildTiccmd (ticcmd_t *cmd)
mousex = mousey = 0;
// Build command.
if (forward > MAXPLMOVE)
forward = MAXPLMOVE;
else if (forward < -MAXPLMOVE)

View file

@ -173,7 +173,7 @@ DEFINE_ACTION_FUNCTION(AActor, A_VolcanoBlast)
blast->momx = FixedMul (1*FRACUNIT, finecosine[angle]);
blast->momy = FixedMul (1*FRACUNIT, finesine[angle]);
blast->momz = (FRACUNIT*5/2) + (pr_blast() << 10);
S_Sound (blast, CHAN_BODY, "world/self/shoot", 1, ATTN_NORM);
S_Sound (blast, CHAN_BODY, "world/volcano/shoot", 1, ATTN_NORM);
P_CheckMissileSpawn (blast);
}
}

View file

@ -618,23 +618,30 @@ IMPLEMENT_CLASS(AWeaponGiver)
bool AWeaponGiver::TryPickup(AActor *&toucher)
{
FDropItem *di = GetDropItems();
AWeapon *weap;
if (di != NULL)
{
const PClass *ti = PClass::FindClass(di->Name);
if (ti->IsDescendantOf(RUNTIME_CLASS(AWeapon)))
{
AWeapon *weap = static_cast<AWeapon*>(Spawn(di->Name, 0, 0, 0, NO_REPLACE));
if (weap != NULL)
if (master == NULL)
{
weap->ItemFlags &= ~IF_ALWAYSPICKUP; // use the flag of this item only.
if (weap->AmmoGive1 >= 0) weap->AmmoGive1 = AmmoGive1;
if (weap->AmmoGive2 >= 0) weap->AmmoGive2 = AmmoGive2;
bool res = weap->CallTryPickup(toucher);
if (!res) weap->Destroy();
else GoAwayAndDie();
return res;
master = weap = static_cast<AWeapon*>(Spawn(di->Name, 0, 0, 0, NO_REPLACE));
if (weap != NULL)
{
weap->ItemFlags &= ~IF_ALWAYSPICKUP; // use the flag of this item only.
if (AmmoGive1 >= 0) weap->AmmoGive1 = AmmoGive1;
if (AmmoGive2 >= 0) weap->AmmoGive2 = AmmoGive2;
weap->BecomeItem();
}
else return false;
}
weap = barrier_cast<AWeapon*>(master);
bool res = weap->CallTryPickup(toucher);
if (res) GoAwayAndDie();
return res;
}
}
return false;

View file

@ -49,23 +49,21 @@ class FScanner;
* This class is used to help prevent errors that may occur from adding or
* subtracting from coordinates.
*
* In order to provide the maximum flexibility, coordinates can be stored as an
* int with the 31st bit representing REL_CENTER. This class can handle this
* flag.
* In order to provide the maximum flexibility, coordinates are packed into
* an int with one bit reserved for relCenter.
*/
class SBarInfoCoordinate
{
public:
static const int REL_CENTER = 0x40000000;
SBarInfoCoordinate() {}
SBarInfoCoordinate(int coord, bool relCenter);
SBarInfoCoordinate(int value);
SBarInfoCoordinate &Add(int add);
int Coordinate() const { return value; }
bool RelCenter() const { return relCenter; }
int Value() const { return value | (relCenter ? REL_CENTER : 0); }
void Set(int coord, bool center) { value = coord; relCenter = center; }
void SetCoord(int coord) { value = coord; }
void SetRelCenter(bool center) { relCenter = center; }
int operator* () const { return Coordinate(); }
SBarInfoCoordinate operator+ (int add) const { return SBarInfoCoordinate(*this).Add(add); }
@ -76,8 +74,8 @@ class SBarInfoCoordinate
void operator-= (int sub) { Add(-sub); }
protected:
int value;
bool relCenter;
unsigned relCenter:1;
int value:31;
};
struct SBarInfoCommand; //we need to be able to use this before it is defined.
@ -171,8 +169,7 @@ struct SBarInfo
void ParseSBarInfo(int lump);
void ParseSBarInfoBlock(FScanner &sc, SBarInfoBlock &block);
void ParseMugShotBlock(FScanner &sc, FMugShotState &state);
void getCoordinates(FScanner &sc, bool fullScreenOffsets, int &x, int &y); //retrieves the next two arguments as x and y.
void getCoordinates(FScanner &sc, bool fullScreenOffsets, SBarInfoCoordinate &x, SBarInfoCoordinate &y);
void getCoordinates(FScanner &sc, bool fullScreenOffsets, SBarInfoCoordinate &x, SBarInfoCoordinate &y); //retrieves the next two arguments as x and y.
int getSignedInteger(FScanner &sc); //returns a signed integer.
int newImage(const char* patchname);
void Init();

View file

@ -96,15 +96,6 @@ SBarInfoCoordinate::SBarInfoCoordinate(int coord, bool relCenter) :
{
}
SBarInfoCoordinate::SBarInfoCoordinate(int value)
{
relCenter = ((value & REL_CENTER) != 0);
if(value < 0)
this->value = (value | REL_CENTER);
else
this->value = (value & (~REL_CENTER));
}
SBarInfoCoordinate &SBarInfoCoordinate::Add(int add)
{
value += add;
@ -265,10 +256,13 @@ void DSBarInfo::Draw (EHudState state)
{
hud = STBAR_NONE;
}
bool oldhud_scale = hud_scale;
if(script->huds[hud].forceScaled) //scale the statusbar
{
SetScaled(true, true);
setsizeneeded = true;
if(script->huds[hud].fullScreenOffsets)
hud_scale = true;
}
doCommands(script->huds[hud], 0, 0, script->huds[hud].alpha);
if(CPlayer->inventorytics > 0 && !(level.flags & LEVEL_NOINVENTORYBAR))
@ -301,6 +295,8 @@ void DSBarInfo::Draw (EHudState state)
doCommands(script->huds[popbar], script->popups[currentPopup-1].getXOffset(), script->popups[currentPopup-1].getYOffset(),
script->popups[currentPopup-1].getAlpha(script->huds[popbar].alpha));
}
if(script->huds[hud].forceScaled && script->huds[hud].fullScreenOffsets)
hud_scale = oldhud_scale;
}
void DSBarInfo::NewGame ()
@ -760,7 +756,7 @@ void DSBarInfo::doCommands(SBarInfoBlock &block, int xOffset, int yOffset, int a
{
drawingFont = cmd.font;
}
DrawNumber(CPlayer->mo->InvSel->Amount, 3, cmd.special2, cmd.special3, xOffset, yOffset, alpha, block.fullScreenOffsets, cmd.translation, cmd.special4, false, !!(cmd.flags & DRAWSELECTEDINVENTORY_DRAWSHADOW));
DrawNumber(CPlayer->mo->InvSel->Amount, 3, *(SBarInfoCoordinate*)&cmd.special2, *(SBarInfoCoordinate*)&cmd.special3, xOffset, yOffset, alpha, block.fullScreenOffsets, cmd.translation, cmd.special4, false, !!(cmd.flags & DRAWSELECTEDINVENTORY_DRAWSHADOW));
}
}
else if((cmd.flags & DRAWSELECTEDINVENTORY_ALTERNATEONEMPTY))
@ -789,7 +785,7 @@ void DSBarInfo::doCommands(SBarInfoBlock &block, int xOffset, int yOffset, int a
{
drawingFont = cmd.font;
}
DrawInventoryBar(cmd.special, cmd.value, cmd.x, cmd.y, xOffset, yOffset, alpha, block.fullScreenOffsets, alwaysshow, cmd.special2, cmd.special3, cmd.translation, artibox, noarrows, alwaysshowcounter, bgalpha);
DrawInventoryBar(cmd.special, cmd.value, cmd.x, cmd.y, xOffset, yOffset, alpha, block.fullScreenOffsets, alwaysshow, *(SBarInfoCoordinate*)&cmd.special2, *(SBarInfoCoordinate*)&cmd.special3, cmd.translation, artibox, noarrows, alwaysshowcounter, bgalpha);
break;
}
case SBARINFO_DRAWBAR:
@ -1203,8 +1199,8 @@ void DSBarInfo::doCommands(SBarInfoBlock &block, int xOffset, int yOffset, int a
int tmpX = *x;
int tmpY = *y;
screen->VirtualToRealCoordsInt(tmpX, tmpY, w, h, 320, 200, true);
x = tmpX;
y = tmpY;
x.SetCoord(tmpX);
y.SetCoord(tmpY);
}
}
else

View file

@ -765,12 +765,12 @@ void SBarInfo::ParseSBarInfoBlock(FScanner &sc, SBarInfoBlock &block)
sc.MustGetToken(',');
}
this->getCoordinates(sc, block.fullScreenOffsets, cmd.x, cmd.y);
cmd.special2 = *(cmd.x + 30);
cmd.special3 = *(cmd.y + 24);
*(SBarInfoCoordinate*)&cmd.special2 = cmd.x + 30;
*(SBarInfoCoordinate*)&cmd.special3 = cmd.y + 24;
cmd.translation = CR_GOLD;
if(sc.CheckToken(',')) //more font information
{
this->getCoordinates(sc, block.fullScreenOffsets, cmd.special2, cmd.special3);
this->getCoordinates(sc, block.fullScreenOffsets, *(SBarInfoCoordinate*)&cmd.special2, *(SBarInfoCoordinate*)&cmd.special3);
if(sc.CheckToken(','))
{
sc.MustGetToken(TK_Identifier);
@ -847,12 +847,12 @@ void SBarInfo::ParseSBarInfoBlock(FScanner &sc, SBarInfoBlock &block)
sc.MustGetToken(',');
this->getCoordinates(sc, block.fullScreenOffsets, cmd.x, cmd.y);
cmd.special2 = *(cmd.x + 26);
cmd.special3 = *(cmd.y + 22);
*(SBarInfoCoordinate*)&cmd.special2 = cmd.x + 26;
*(SBarInfoCoordinate*)&cmd.special3 = cmd.y + 22;
cmd.translation = CR_GOLD;
if(sc.CheckToken(',')) //more font information
{
this->getCoordinates(sc, block.fullScreenOffsets, cmd.special2, cmd.special3);
this->getCoordinates(sc, block.fullScreenOffsets, *(SBarInfoCoordinate*)&cmd.special2, *(SBarInfoCoordinate*)&cmd.special3);
if(sc.CheckToken(','))
{
sc.MustGetToken(TK_Identifier);
@ -1346,11 +1346,11 @@ void SBarInfo::ParseMugShotBlock(FScanner &sc, FMugShotState &state)
}
}
void SBarInfo::getCoordinates(FScanner &sc, bool fullScreenOffsets, int &x, int &y)
void SBarInfo::getCoordinates(FScanner &sc, bool fullScreenOffsets, SBarInfoCoordinate &x, SBarInfoCoordinate &y)
{
bool negative = false;
bool relCenter = false;
int *coords[2] = {&x, &y};
SBarInfoCoordinate *coords[2] = {&x, &y};
for(int i = 0;i < 2;i++)
{
negative = false;
@ -1361,7 +1361,7 @@ void SBarInfo::getCoordinates(FScanner &sc, bool fullScreenOffsets, int &x, int
// [-]INT center
negative = sc.CheckToken('-');
sc.MustGetToken(TK_IntConst);
*coords[i] = negative ? -sc.Number : sc.Number;
coords[i]->Set(negative ? -sc.Number : sc.Number, false);
if(sc.CheckToken('+'))
{
sc.MustGetToken(TK_Identifier);
@ -1371,24 +1371,12 @@ void SBarInfo::getCoordinates(FScanner &sc, bool fullScreenOffsets, int &x, int
}
if(fullScreenOffsets)
{
if(relCenter)
*coords[i] |= SBarInfoCoordinate::REL_CENTER;
else
*coords[i] &= ~SBarInfoCoordinate::REL_CENTER;
coords[i]->SetRelCenter(relCenter);
}
}
if(!fullScreenOffsets)
y = (negative ? -sc.Number : sc.Number) - (200 - this->height);
}
void SBarInfo::getCoordinates(FScanner &sc, bool fullScreenOffsets, SBarInfoCoordinate &x, SBarInfoCoordinate &y)
{
int tmpX = *x;
int tmpY = *y;
getCoordinates(sc, fullScreenOffsets, tmpX, tmpY);
x = tmpX;
y = tmpY;
y.SetCoord((negative ? -sc.Number : sc.Number) - (200 - this->height));
}
int SBarInfo::getSignedInteger(FScanner &sc)
@ -1497,8 +1485,8 @@ SBarInfoCommand::SBarInfoCommand() //sets the default values for more predicable
special3 = 0;
special4 = 0;
flags = 0;
x = 0;
y = 0;
x.Set(0, 0);
y.Set(0, 0);
value = 0;
image_index = 0;
sprite_index.SetInvalid();

View file

@ -302,6 +302,7 @@ menu_t MouseMenu =
*=======================================*/
EXTERN_CVAR (Bool, use_joystick)
#if 0
EXTERN_CVAR (Float, joy_speedmultiplier)
EXTERN_CVAR (Int, joy_xaxis)
EXTERN_CVAR (Int, joy_yaxis)
@ -325,6 +326,7 @@ EXTERN_CVAR (Float, joy_forwardspeed)
EXTERN_CVAR (Float, joy_sidespeed)
EXTERN_CVAR (Float, joy_upspeed)
EXTERN_CVAR (GUID, joy_guid)
#endif
static value_t JoyAxisMapNames[6] =
{
@ -344,9 +346,11 @@ static value_t Inversion[2] =
static menuitem_t JoystickItems[] =
{
#if 0
{ discrete, "Enable joystick", {&use_joystick}, {2.0}, {0.0}, {0.0}, {YesNo} },
{ discrete_guid,"Active joystick", {&joy_guid}, {0.0}, {0.0}, {0.0}, {NULL} },
{ slider, "Overall sensitivity", {&joy_speedmultiplier}, {0.9f}, {2.0}, {0.2f}, {NULL} },
#endif
{ redtext, " ", {NULL}, {0.0}, {0.0}, {0.0}, {NULL} },
{ whitetext,"Axis Assignments", {NULL}, {0.0}, {0.0}, {0.0}, {NULL} },
{ redtext, " ", {NULL}, {0.0}, {0.0}, {0.0}, {NULL} },
@ -1652,6 +1656,7 @@ int M_FindCurVal (float cur, valuestring_t *values, int numvals)
return v;
}
#if 0
int M_FindCurGUID (const GUID &guid, GUIDName *values, int numvals)
{
int v;
@ -1662,6 +1667,7 @@ int M_FindCurGUID (const GUID &guid, GUIDName *values, int numvals)
return v;
}
#endif
const char *M_FindCurVal(const char *cur, valueenum_t *values, int numvals)
{
@ -1919,6 +1925,7 @@ void M_OptDrawer ()
}
break;
#if 0
case discrete_guid:
{
int v, vals;
@ -1939,6 +1946,7 @@ void M_OptDrawer ()
}
break;
#endif
case nochoice:
screen->DrawText (SmallFont, CR_GOLD, indent + 14, y,
@ -2432,6 +2440,7 @@ void M_OptResponder (event_t *ev)
S_Sound (CHAN_VOICE | CHAN_UI, "menu/change", 1, ATTN_NONE);
break;
#if 0
case discrete_guid:
{
int cur;
@ -2446,6 +2455,7 @@ void M_OptResponder (event_t *ev)
}
S_Sound (CHAN_VOICE | CHAN_UI, "menu/change", 1, ATTN_NONE);
break;
#endif
case inverter:
value = item->a.cvar->GetGenericRep (CVAR_Float);
@ -2581,6 +2591,7 @@ void M_OptResponder (event_t *ev)
S_Sound (CHAN_VOICE | CHAN_UI, "menu/change", 1, ATTN_NONE);
break;
#if 0
case discrete_guid:
{
int cur;
@ -2595,6 +2606,7 @@ void M_OptResponder (event_t *ev)
}
S_Sound (CHAN_VOICE | CHAN_UI, "menu/change", 1, ATTN_NONE);
break;
#endif
case inverter:
value = item->a.cvar->GetGenericRep (CVAR_Float);
@ -3006,6 +3018,7 @@ CCMD (menu_mouse)
void UpdateJoystickMenu ()
{
#if 0
static FIntCVar * const cvars[8] =
{
&joy_xaxis, &joy_yaxis, &joy_zaxis,
@ -3113,6 +3126,7 @@ void UpdateJoystickMenu ()
{
CalcIndent (&JoystickMenu);
}
#endif
}
static void JoystickOptions ()

View file

@ -69,8 +69,8 @@ public:
// Returns (rand# & mask) - (rand# & mask)
int Random2(int mask)
{
int t = GenRand32() & mask;
return t - (GenRand32() & mask);
int t = GenRand32() & mask & 255;
return t - (GenRand32() & mask & 255);
}
// HITDICE macro used in Heretic and Hexen

View file

@ -462,7 +462,7 @@ void P_SpawnSlopeMakers (FMapThing *firstmt, FMapThing *lastmt)
static void P_AlignPlane (sector_t *sec, line_t *line, int which)
{
sector_t *refsec;
int bestdist;
double bestdist;
vertex_t *refvert = (*sec->lines)->v1; // Shut up, GCC
int i;
line_t **probe;
@ -471,23 +471,19 @@ static void P_AlignPlane (sector_t *sec, line_t *line, int which)
return;
// Find furthest vertex from the reference line. It, along with the two ends
// of the line will define the plane.
// of the line, will define the plane.
bestdist = 0;
for (i = sec->linecount*2, probe = sec->lines; i > 0; i--)
{
int dist;
double dist;
vertex_t *vert;
// Do calculations with only the upper bits, because the lower ones
// are all zero, and we would overflow for a lot of distances if we
// kept them around.
if (i & 1)
vert = (*probe++)->v2;
else
vert = (*probe)->v1;
dist = abs (((line->v1->y - vert->y) >> FRACBITS) * (line->dx >> FRACBITS) -
((line->v1->x - vert->x) >> FRACBITS) * (line->dy >> FRACBITS));
dist = fabs((double(line->v1->y) - vert->y) * line->dx -
(double(line->v1->x) - vert->x) * line->dy);
if (dist > bestdist)
{

View file

@ -30,112 +30,7 @@ CVAR (Bool, use_mouse, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Bool, m_noprescale, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Bool, m_filter, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Bool, sdl_nokeyrepeat, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
float JoyAxes[6];
//static int JoyActive;
//static BYTE JoyButtons[128];
//static BYTE JoyPOV[4];
static BYTE JoyAxisMap[8];
static float JoyAxisThresholds[8];
char *JoyAxisNames[8];
static const BYTE POVButtons[9] = { 0x01, 0x03, 0x02, 0x06, 0x04, 0x0C, 0x08, 0x09, 0x00 };
TArray<GUIDName> JoystickNames;
CVAR (Bool, use_joystick, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (GUID, joy_guid, NULL, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOINITCALL)
static void MapAxis (FIntCVar &var, int num)
{
if (var < JOYAXIS_NONE || var > JOYAXIS_UP)
{
var = JOYAXIS_NONE;
}
else
{
JoyAxisMap[num] = var;
}
}
CUSTOM_CVAR (Int, joy_xaxis, JOYAXIS_YAW, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 0);
}
CUSTOM_CVAR (Int, joy_yaxis, JOYAXIS_FORWARD, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 1);
}
CUSTOM_CVAR (Int, joy_zaxis, JOYAXIS_SIDE, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 2);
}
CUSTOM_CVAR (Int, joy_xrot, JOYAXIS_NONE, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 3);
}
CUSTOM_CVAR (Int, joy_yrot, JOYAXIS_NONE, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 4);
}
CUSTOM_CVAR (Int, joy_zrot, JOYAXIS_PITCH, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 5);
}
CUSTOM_CVAR (Int, joy_slider, JOYAXIS_NONE, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 6);
}
CUSTOM_CVAR (Int, joy_dial, JOYAXIS_NONE, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 7);
}
CUSTOM_CVAR (Float, joy_xthreshold, 0.15f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[0] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_ythreshold, 0.15f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[1] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_zthreshold, 0.15f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[2] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_xrotthreshold, 0.15f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[3] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_yrotthreshold, 0.15f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[4] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_zrotthreshold, 0.15f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[5] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_sliderthreshold, 0.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[6] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_dialthreshold, 0.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[7] = clamp (self * 256.f, 0.f, 256.f);
}
CVAR (Float, joy_speedmultiplier,1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Float, joy_yawspeed, -1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Float, joy_pitchspeed, -.75f,CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Float, joy_forwardspeed, -1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Float, joy_sidespeed, 1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Float, joy_upspeed, -1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
static FBaseCVar * const JoyConfigVars[] =
{
&joy_xaxis, &joy_yaxis, &joy_zaxis, &joy_xrot, &joy_yrot, &joy_zrot, &joy_slider, &joy_dial,
&joy_xthreshold, &joy_ythreshold, &joy_zthreshold, &joy_xrotthreshold, &joy_yrotthreshold, &joy_zrotthreshold, &joy_sliderthreshold, &joy_dialthreshold,
&joy_speedmultiplier, &joy_yawspeed, &joy_pitchspeed, &joy_forwardspeed, &joy_sidespeed,
&joy_upspeed
};
CVAR (Bool, use_joystick, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
EXTERN_CVAR (Bool, fullscreen)
@ -565,3 +460,11 @@ void I_StartFrame ()
InitKeySymMap ();
}
}
void I_GetAxes(float axes[NUM_JOYAXIS])
{
for (int i = 0; i < NUM_JOYAXIS; ++i)
{
axes[i] = 0;
}
}

View file

@ -4,16 +4,7 @@
void I_PutInClipboard (const char *str);
FString I_GetFromClipboard (bool use_primary_selection);
struct GUIDName
{
GUID ID;
char *Name;
};
extern TArray<GUIDName> JoystickNames;
extern char *JoyAxisNames[8];
extern void DI_EnumJoy ();
void I_GetAxes(float axes[NUM_JOYAXIS]);
#endif

View file

@ -3,5 +3,5 @@
// This file was automatically generated by the
// updaterevision tool. Do not edit by hand.
#define ZD_SVN_REVISION_STRING "1668"
#define ZD_SVN_REVISION_NUMBER 1668
#define ZD_SVN_REVISION_STRING "1679"
#define ZD_SVN_REVISION_NUMBER 1679

1237
src/win32/i_dijoy.cpp Normal file

File diff suppressed because it is too large Load diff

View file

@ -3,7 +3,7 @@
** Handles input from keyboard, mouse, and joystick
**
**---------------------------------------------------------------------------
** Copyright 1998-2006 Randy Heit
** Copyright 1998-2009 Randy Heit
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
@ -47,8 +47,8 @@
#endif
#include <windows.h>
#include <mmsystem.h>
#include <dbt.h>
#include <dinput.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
@ -128,8 +128,6 @@ extern bool SpawnEAXWindow;
static HMODULE DInputDLL;
static HRESULT InitJoystick ();
bool GUICapture;
extern FMouse *Mouse;
extern FKeyboard *Keyboard;
@ -141,11 +139,9 @@ extern BOOL vidactive;
extern HWND Window, ConWindow;
extern HWND EAXEditWindow;
extern void UpdateJoystickMenu ();
extern menu_t JoystickMenu;
EXTERN_CVAR (String, language)
EXTERN_CVAR (Bool, lookstrafe)
EXTERN_CVAR (Bool, use_joystick)
static int WheelDelta;
@ -155,151 +151,12 @@ static bool noidle = false;
LPDIRECTINPUT8 g_pdi;
LPDIRECTINPUT g_pdi3;
static LPDIRECTINPUTDEVICE8 g_pJoy;
TArray<GUIDName> JoystickNames;
static DIDEVCAPS JoystickCaps;
float JoyAxes[6];
static int JoyActive;
static BYTE JoyButtons[128];
static BYTE JoyPOV[4];
static BYTE JoyAxisMap[8];
static float JoyAxisThresholds[8];
char *JoyAxisNames[8];
static const size_t Axes[8] =
{
myoffsetof(DIJOYSTATE2,lX),
myoffsetof(DIJOYSTATE2,lY),
myoffsetof(DIJOYSTATE2,lZ),
myoffsetof(DIJOYSTATE2,lRx),
myoffsetof(DIJOYSTATE2,lRy),
myoffsetof(DIJOYSTATE2,lRz),
myoffsetof(DIJOYSTATE2,rglSlider[0]),
myoffsetof(DIJOYSTATE2,rglSlider[1])
};
static const BYTE POVButtons[9] = { 0x01, 0x03, 0x02, 0x06, 0x04, 0x0C, 0x08, 0x09, 0x00 };
BOOL AppActive = TRUE;
int SessionState = 0;
CVAR (Bool, use_joystick, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CUSTOM_CVAR (GUID, joy_guid, NULL, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOINITCALL)
{
if (g_pJoy != NULL)
{
DIDEVICEINSTANCE inst = { sizeof(DIDEVICEINSTANCE), };
if (SUCCEEDED(g_pJoy->GetDeviceInfo (&inst)) && self != inst.guidInstance)
{
DI_InitJoy ();
UpdateJoystickMenu ();
}
}
else
{
DI_InitJoy ();
UpdateJoystickMenu ();
}
}
static void MapAxis (FIntCVar &var, int num)
{
if (var < JOYAXIS_NONE || var > JOYAXIS_UP)
{
var = JOYAXIS_NONE;
}
else
{
JoyAxisMap[num] = var;
}
}
CUSTOM_CVAR (Int, joy_xaxis, JOYAXIS_YAW, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 0);
}
CUSTOM_CVAR (Int, joy_yaxis, JOYAXIS_FORWARD, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 1);
}
CUSTOM_CVAR (Int, joy_zaxis, JOYAXIS_SIDE, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 2);
}
CUSTOM_CVAR (Int, joy_xrot, JOYAXIS_NONE, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 3);
}
CUSTOM_CVAR (Int, joy_yrot, JOYAXIS_NONE, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 4);
}
CUSTOM_CVAR (Int, joy_zrot, JOYAXIS_PITCH, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 5);
}
CUSTOM_CVAR (Int, joy_slider, JOYAXIS_NONE, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 6);
}
CUSTOM_CVAR (Int, joy_dial, JOYAXIS_NONE, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 7);
}
CUSTOM_CVAR (Float, joy_xthreshold, 0.15f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[0] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_ythreshold, 0.15f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[1] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_zthreshold, 0.15f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[2] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_xrotthreshold, 0.15f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[3] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_yrotthreshold, 0.15f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[4] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_zrotthreshold, 0.15f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[5] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_sliderthreshold, 0.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[6] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_dialthreshold, 0.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[7] = clamp (self * 256.f, 0.f, 256.f);
}
CVAR (Float, joy_speedmultiplier,1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Float, joy_yawspeed, -1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Float, joy_pitchspeed, -.75f,CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Float, joy_forwardspeed, -1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Float, joy_sidespeed, 1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Float, joy_upspeed, -1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Bool, k_allowfullscreentoggle, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
static FBaseCVar * const JoyConfigVars[] =
{
&joy_xaxis, &joy_yaxis, &joy_zaxis, &joy_xrot, &joy_yrot, &joy_zrot, &joy_slider, &joy_dial,
&joy_xthreshold, &joy_ythreshold, &joy_zthreshold, &joy_xrotthreshold, &joy_yrotthreshold, &joy_zrotthreshold, &joy_sliderthreshold, &joy_dialthreshold,
&joy_speedmultiplier, &joy_yawspeed, &joy_pitchspeed, &joy_forwardspeed, &joy_sidespeed,
&joy_upspeed
};
extern int chatmodeon;
static void I_CheckGUICapture ()
@ -498,15 +355,18 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
return result;
}
for (int i = 0; i < NUM_JOYDEVICES; ++i)
{
if (CallHook(JoyDevices[i], hWnd, message, wParam, lParam, &result))
{
return result;
}
}
if (GUICapture && GUIWndProcHook(hWnd, message, wParam, lParam, &result))
{
return result;
}
event_t event;
memset (&event, 0, sizeof(event));
switch (message)
{
case WM_DESTROY:
@ -669,74 +529,6 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
}
break;
case WM_DEVICECHANGE:
if (wParam == DBT_DEVNODES_CHANGED ||
wParam == DBT_DEVICEARRIVAL ||
wParam == DBT_CONFIGCHANGED)
{
unsigned int i;
TArray<GUID> oldjoys;
for (i = 0; i < JoystickNames.Size(); ++i)
{
oldjoys.Push (JoystickNames[i].ID);
}
DI_EnumJoy ();
// If a new joystick was added and the joystick menu is open,
// switch to it.
if (menuactive != MENU_Off && CurrentMenu == &JoystickMenu)
{
for (i = 0; i < JoystickNames.Size(); ++i)
{
bool wasListed = false;
for (unsigned int j = 0; j < oldjoys.Size(); ++j)
{
if (oldjoys[j] == JoystickNames[i].ID)
{
wasListed = true;
break;
}
}
if (!wasListed)
{
joy_guid = JoystickNames[i].ID;
break;
}
}
}
// If the current joystick was removed,
// try to switch to a different one.
if (g_pJoy != NULL)
{
DIDEVICEINSTANCE inst = { sizeof(DIDEVICEINSTANCE), };
if (SUCCEEDED(g_pJoy->GetDeviceInfo (&inst)))
{
for (i = 0; i < JoystickNames.Size(); ++i)
{
if (JoystickNames[i].ID == inst.guidInstance)
{
break;
}
}
if (i == JoystickNames.Size ())
{
DI_InitJoy ();
}
}
}
else
{
DI_InitJoy ();
}
UpdateJoystickMenu ();
}
break;
case WM_PALETTECHANGED:
if ((HWND)wParam == Window)
break;
@ -763,376 +555,6 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
return 0;
}
/****** Joystick stuff ******/
void DI_JoyCheck ()
{
float mul;
event_t event;
HRESULT hr;
DIJOYSTATE2 js;
int i;
BYTE pov;
if (g_pJoy == NULL)
{
return;
}
hr = g_pJoy->Poll ();
if (FAILED(hr))
{
do
{
hr = g_pJoy->Acquire ();
}
while (hr == DIERR_INPUTLOST);
if (FAILED(hr))
return;
}
hr = g_pJoy->GetDeviceState (sizeof(DIJOYSTATE2), &js);
if (FAILED(hr))
return;
mul = joy_speedmultiplier;
if (Button_Speed.bDown)
{
mul *= 0.5f;
}
for (i = 0; i < 6; ++i)
{
JoyAxes[i] = 0.f;
}
for (i = 0; i < 8; ++i)
{
int vaxis = JoyAxisMap[i];
if (vaxis != JOYAXIS_NONE)
{
if (vaxis == JOYAXIS_YAW && (Button_Strafe.bDown ||
(Button_Mlook.bDown && lookstrafe)))
{
vaxis = JOYAXIS_SIDE;
}
else if (vaxis == JOYAXIS_FORWARD && Button_Mlook.bDown)
{
vaxis = JOYAXIS_PITCH;
}
float axisval = *((LONG *)((BYTE *)&js + Axes[i]));
if (fabsf(axisval) > JoyAxisThresholds[i])
{
if (axisval > 0.f)
{
axisval -= JoyAxisThresholds[i];
}
else
{
axisval += JoyAxisThresholds[i];
}
JoyAxes[vaxis] += axisval * mul * 256.f / (256.f - JoyAxisThresholds[i]);
}
}
}
JoyAxes[JOYAXIS_YAW] *= joy_yawspeed;
JoyAxes[JOYAXIS_PITCH] *= joy_pitchspeed;
JoyAxes[JOYAXIS_FORWARD] *= joy_forwardspeed;
JoyAxes[JOYAXIS_SIDE] *= joy_sidespeed;
JoyAxes[JOYAXIS_UP] *= joy_upspeed;
event.data2 = event.data3 = 0;
// Send button up/down events
for (i = 0; i < 128; ++i)
{
if ((js.rgbButtons[i] ^ JoyButtons[i]) & 0x80)
{
event.data1 = KEY_FIRSTJOYBUTTON + i;
if (JoyButtons[i])
{
event.type = EV_KeyUp;
JoyButtons[i] = 0;
}
else
{
event.type = EV_KeyDown;
JoyButtons[i] = 0x80;
}
D_PostEvent (&event);
}
}
for (i = 0; i < 4; ++i)
{
if (LOWORD(js.rgdwPOV[i]) == 0xFFFF)
{
pov = 8;
}
else
{
pov = ((js.rgdwPOV[i] + 2250) % 36000) / 4500;
}
pov = POVButtons[pov];
for (int j = 0; j < 4; ++j)
{
BYTE mask = 1 << j;
if ((JoyPOV[i] ^ pov) & mask)
{
event.data1 = KEY_JOYPOV1_UP + i*4 + j;
event.type = (pov & mask) ? EV_KeyDown : EV_KeyUp;
D_PostEvent (&event);
}
}
JoyPOV[i] = pov;
}
}
bool SetJoystickSection (bool create)
{
DIDEVICEINSTANCE inst = { sizeof(DIDEVICEINSTANCE), };
char section[80] = "Joystick.";
if (g_pJoy != NULL && SUCCEEDED(g_pJoy->GetDeviceInfo (&inst)))
{
FormatGUID (section + 9, countof(section) - 9, inst.guidInstance);
strcpy (section + 9 + 38, ".Axes");
return GameConfig->SetSection (section, create);
}
else
{
return false;
}
}
void LoadJoystickConfig ()
{
if (SetJoystickSection (false))
{
for (size_t i = 0; i < countof(JoyConfigVars); ++i)
{
const char *val = GameConfig->GetValueForKey (JoyConfigVars[i]->GetName());
UCVarValue cval;
if (val != NULL)
{
cval.String = const_cast<char *>(val);
JoyConfigVars[i]->SetGenericRep (cval, CVAR_String);
}
}
}
}
void SaveJoystickConfig ()
{
if (SetJoystickSection (true))
{
GameConfig->ClearCurrentSection ();
for (size_t i = 0; i < countof(JoyConfigVars); ++i)
{
UCVarValue cval = JoyConfigVars[i]->GetGenericRep (CVAR_String);
GameConfig->SetValueForKey (JoyConfigVars[i]->GetName(), cval.String);
}
}
}
BOOL CALLBACK EnumJoysticksCallback (LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef)
{
GUIDName name;
JoyActive++;
name.ID = lpddi->guidInstance;
name.Name = copystring (lpddi->tszInstanceName);
JoystickNames.Push (name);
return DIENUM_CONTINUE;
}
void DI_EnumJoy ()
{
unsigned int i;
for (i = 0; i < JoystickNames.Size(); ++i)
{
delete[] JoystickNames[i].Name;
}
JoyActive = 0;
JoystickNames.Clear ();
if (g_pdi != NULL && !Args->CheckParm ("-nojoy"))
{
g_pdi->EnumDevices (DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, NULL, DIEDFL_ALLDEVICES);
}
}
BOOL DI_InitJoy (void)
{
HRESULT hr;
unsigned int i;
if (g_pdi == NULL)
{
return TRUE;
}
if (g_pJoy != NULL)
{
SaveJoystickConfig ();
g_pJoy->Release ();
g_pJoy = NULL;
}
if (JoystickNames.Size() == 0)
{
return TRUE;
}
// Try to obtain the joystick specified by joy_guid
for (i = 0; i < JoystickNames.Size(); ++i)
{
if (JoystickNames[i].ID == joy_guid)
{
hr = g_pdi->CreateDevice (JoystickNames[i].ID, &g_pJoy, NULL);
if (FAILED(hr))
{
i = JoystickNames.Size();
}
break;
}
}
// If the preferred joystick could not be obtained, grab the first
// one available.
if (i == JoystickNames.Size())
{
for (i = 0; i <= JoystickNames.Size(); ++i)
{
hr = g_pdi->CreateDevice (JoystickNames[i].ID, &g_pJoy, NULL);
if (SUCCEEDED(hr))
{
break;
}
}
}
if (i == JoystickNames.Size())
{
JoyActive = 0;
return TRUE;
}
if (FAILED (InitJoystick ()))
{
JoyActive = 0;
g_pJoy->Release ();
g_pJoy = NULL;
}
else
{
LoadJoystickConfig ();
joy_guid = JoystickNames[i].ID;
}
return TRUE;
}
BOOL CALLBACK EnumAxesCallback (LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef)
{
DIPROPRANGE diprg =
{
{
sizeof (DIPROPRANGE),
sizeof (DIPROPHEADER),
lpddoi->dwType,
DIPH_BYID
},
-256,
+256
};
if (lpddoi->wUsagePage == 1)
{
if (lpddoi->wUsage >= 0x30 && lpddoi->wUsage <= 0x37)
{
JoyAxisNames[lpddoi->wUsage-0x30] = copystring (lpddoi->tszName);
}
}
if (FAILED(g_pJoy->SetProperty (DIPROP_RANGE, &diprg.diph)))
{
return DIENUM_STOP;
}
else
{
return DIENUM_CONTINUE;
}
}
static HRESULT InitJoystick ()
{
HRESULT hr;
memset (JoyPOV, 9, sizeof(JoyPOV));
for (int i = 0; i < 8; ++i)
{
if (JoyAxisNames[i])
{
delete[] JoyAxisNames[i];
JoyAxisNames[i] = NULL;
}
}
hr = g_pJoy->SetDataFormat (&c_dfDIJoystick2);
if (FAILED(hr))
{
Printf (PRINT_BOLD, "Could not set joystick data format.\n");
return hr;
}
hr = g_pJoy->SetCooperativeLevel (Window, DISCL_EXCLUSIVE|DISCL_FOREGROUND);
if (FAILED(hr))
{
Printf (PRINT_BOLD, "Could not set joystick cooperative level.\n");
return hr;
}
JoystickCaps.dwSize = sizeof(JoystickCaps);
hr = g_pJoy->GetCapabilities (&JoystickCaps);
if (FAILED(hr))
{
Printf (PRINT_BOLD, "Could not query joystick capabilities.\n");
return hr;
}
hr = g_pJoy->EnumObjects (EnumAxesCallback, NULL, DIDFT_AXIS);
if (FAILED(hr))
{
Printf (PRINT_BOLD, "Could not set joystick axes ranges.\n");
return hr;
}
g_pJoy->Acquire ();
return S_OK;
}
/****** Stuff from Andy Bay's mymouse.c ******/
/****************************************************************************
*
* DIInit
*
* Initialize the DirectInput variables.
*
****************************************************************************/
// [RH] Used to obtain DirectInput access to the mouse.
// (Preferred for Win95, but buggy under NT 4.)
bool I_InitInput (void *hwnd)
{
HRESULT hr;
@ -1198,8 +620,7 @@ bool I_InitInput (void *hwnd)
I_StartupMouse();
Printf ("I_StartupJoystick\n");
DI_EnumJoy ();
DI_InitJoy ();
I_StartupJoystick();
Printf ("I_StartupKeyboard\n");
I_StartupKeyboard();
@ -1221,11 +642,13 @@ void I_ShutdownInput ()
delete Mouse;
Mouse = NULL;
}
if (g_pJoy)
for (int i = 0; i < NUM_JOYDEVICES; ++i)
{
SaveJoystickConfig ();
g_pJoy->Release ();
g_pJoy = NULL;
if (JoyDevices[i] != NULL)
{
delete JoyDevices[i];
JoyDevices[i] = NULL;
}
}
if (g_pdi)
{
@ -1273,7 +696,6 @@ void I_GetEvent ()
}
}
//
// I_StartTic
//
@ -1292,7 +714,33 @@ void I_StartFrame ()
{
if (use_joystick)
{
DI_JoyCheck ();
for (int i = 0; i < NUM_JOYDEVICES; ++i)
{
if (JoyDevices[i] != NULL)
{
JoyDevices[i]->ProcessInput();
}
}
}
}
void I_GetAxes(float axes[NUM_JOYAXIS])
{
int i;
for (i = 0; i < NUM_JOYAXIS; ++i)
{
axes[i] = 0;
}
if (use_joystick)
{
for (i = 0; i < NUM_JOYDEVICES; ++i)
{
if (JoyDevices[i] != NULL)
{
JoyDevices[i]->AddAxes(axes);
}
}
}
}

View file

@ -35,24 +35,15 @@
#define __I_INPUT_H__
#include "doomtype.h"
#include "doomdef.h"
bool I_InitInput (void *hwnd);
void I_ShutdownInput ();
void I_PutInClipboard (const char *str);
FString I_GetFromClipboard (bool windows_has_no_selection_clipboard);
void I_GetEvent ();
struct GUIDName
{
GUID ID;
char *Name;
};
extern TArray<GUIDName> JoystickNames;
extern char *JoyAxisNames[8];
extern void DI_EnumJoy ();
void I_GetEvent();
void I_GetAxes(float axes[NUM_JOYAXIS]);
#ifdef USE_WINDOWS_DWORD
// Don't make these definitions available to the main body of the source code.
@ -118,9 +109,26 @@ protected:
void PostKeyEvent(int keynum, INTBOOL down, bool foreground);
};
class FJoystickCollection : public FInputDevice
{
public:
virtual void AddAxes(float axes[NUM_JOYAXIS]) = 0;
};
enum
{
INPUT_DIJoy,
INPUT_XInput,
INPUT_PS2EMS,
NUM_JOYDEVICES
};
extern FJoystickCollection *JoyDevices[NUM_JOYDEVICES];
void I_StartupMouse();
void I_CheckNativeMouse(bool prefer_native);
void I_StartupKeyboard();
void I_StartupJoystick();
// USB HID usage page numbers
#define HID_GENERIC_DESKTOP_PAGE 0x01

View file

@ -98,8 +98,6 @@ class Win32Video : public IVideo
bool m_IteratorFS;
bool m_IsFullscreen;
bool m_CalledCoInitialize;
void AddMode (int x, int y, int bits, int baseHeight, int doubling);
void FreeModes ();