Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
wolf3d
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
wolf3d
Commits
9c428361
Commit
9c428361
authored
Dec 22, 2007
by
Steven Fuller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
very basic joystick support.
parent
597376eb
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
187 additions
and
33 deletions
+187
-33
vi_comm.c
src/vi_comm.c
+4
-23
vi_comm.h
src/vi_comm.h
+3
-0
vi_sdl.c
src/vi_sdl.c
+174
-9
wl_menu.c
src/wl_menu.c
+6
-1
No files found.
src/vi_comm.c
View file @
9c428361
...
@@ -170,28 +170,6 @@ static void INL_ShutMouse(void)
...
@@ -170,28 +170,6 @@ static void INL_ShutMouse(void)
{
{
}
}
///////////////////////////////////////////////////////////////////////////
//
// INL_StartJoy() - Detects & auto-configures the specified joystick
// The auto-config assumes the joystick is centered
//
///////////////////////////////////////////////////////////////////////////
static
boolean
INL_StartJoy
(
word
joy
)
{
return
false
;
}
///////////////////////////////////////////////////////////////////////////
//
// INL_ShutJoy() - Cleans up the joystick stuff
//
///////////////////////////////////////////////////////////////////////////
static
void
INL_ShutJoy
(
word
joy
)
{
JoysPresent
[
joy
]
=
false
;
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
//
//
// IN_Startup() - Starts up the Input Mgr
// IN_Startup() - Starts up the Input Mgr
...
@@ -235,8 +213,11 @@ void IN_Shutdown(void)
...
@@ -235,8 +213,11 @@ void IN_Shutdown(void)
return
;
return
;
INL_ShutMouse
();
INL_ShutMouse
();
for
(
i
=
0
;
i
<
MaxJoys
;
i
++
)
for
(
i
=
0
;
i
<
MaxJoys
;
i
++
)
{
INL_ShutJoy
(
i
);
INL_ShutJoy
(
i
);
JoysPresent
[
i
]
=
false
;
}
INL_ShutKbd
();
INL_ShutKbd
();
IN_Started
=
false
;
IN_Started
=
false
;
...
...
src/vi_comm.h
View file @
9c428361
...
@@ -159,6 +159,9 @@ extern void IN_Startup(), IN_Shutdown(), IN_ClearKeysDown(),
...
@@ -159,6 +159,9 @@ extern void IN_Startup(), IN_Shutdown(), IN_ClearKeysDown(),
IN_GetJoyAbs
(
word
joy
,
word
*
xp
,
word
*
yp
),
IN_GetJoyAbs
(
word
joy
,
word
*
xp
,
word
*
yp
),
IN_SetupJoy
(
word
joy
,
word
minx
,
word
maxx
,
word
miny
,
word
maxy
),
IN_SetupJoy
(
word
joy
,
word
minx
,
word
maxx
,
word
miny
,
word
maxy
),
IN_Ack
();
IN_Ack
();
boolean
INL_StartJoy
(
word
joy
);
void
INL_ShutJoy
(
word
joy
);
extern
boolean
IN_UserInput
(
longword
delay
);
extern
boolean
IN_UserInput
(
longword
delay
);
extern
const
char
*
IN_GetScanName
(
ScanCode
);
extern
const
char
*
IN_GetScanName
(
ScanCode
);
...
...
src/vi_sdl.c
View file @
9c428361
...
@@ -2,6 +2,28 @@
...
@@ -2,6 +2,28 @@
#include "SDL.h"
#include "SDL.h"
#define JoyScaleMax 32768
#define JoyScaleShift 8
typedef
struct
{
SDL_Joystick
*
joystick
;
word
joyMinX
;
word
joyMinY
;
word
threshMinX
;
word
threshMinY
;
word
threshMaxX
;
word
threshMaxY
;
word
joyMaxX
;
word
joyMaxY
;
word
joyMultXL
;
word
joyMultYL
;
word
joyMultXH
;
word
joyMultYH
;
}
JoystickDef
;
static
JoystickDef
JoyDefs
[
MaxJoys
];
static
SDL_Surface
*
surface
;
static
SDL_Surface
*
surface
;
static
unsigned
int
sdl_palettemode
;
static
unsigned
int
sdl_palettemode
;
...
@@ -110,7 +132,9 @@ void VL_Startup()
...
@@ -110,7 +132,9 @@ void VL_Startup()
if
(
surface
->
flags
&
SDL_FULLSCREEN
)
if
(
surface
->
flags
&
SDL_FULLSCREEN
)
SDL_ShowCursor
(
0
);
SDL_ShowCursor
(
0
);
SDL_WM_SetCaption
(
GAMENAME
,
GAMENAME
);
SDL_WM_SetCaption
(
GAMENAME
,
GAMENAME
);
SDL_InitSubSystem
(
SDL_INIT_JOYSTICK
);
}
}
/*
/*
...
@@ -145,9 +169,9 @@ void VL_SetPalette(const byte *palette)
...
@@ -145,9 +169,9 @@ void VL_SetPalette(const byte *palette)
for
(
i
=
0
;
i
<
256
;
i
++
)
for
(
i
=
0
;
i
<
256
;
i
++
)
{
{
colors
[
i
].
r
=
palette
[
i
*
3
+
0
]
<<
2
;
colors
[
i
].
r
=
((
int
)
palette
[
i
*
3
+
0
]
*
255
)
/
63
;
colors
[
i
].
g
=
palette
[
i
*
3
+
1
]
<<
2
;
colors
[
i
].
g
=
((
int
)
palette
[
i
*
3
+
1
]
*
255
)
/
63
;
colors
[
i
].
b
=
palette
[
i
*
3
+
2
]
<<
2
;
colors
[
i
].
b
=
((
int
)
palette
[
i
*
3
+
2
]
*
255
)
/
63
;
}
}
SDL_SetPalette
(
surface
,
sdl_palettemode
,
colors
,
0
,
256
);
SDL_SetPalette
(
surface
,
sdl_palettemode
,
colors
,
0
,
256
);
}
}
...
@@ -335,6 +359,9 @@ void INL_Update()
...
@@ -335,6 +359,9 @@ void INL_Update()
boolean
DebouncedKeyboard
[
NumCodes
];
boolean
DebouncedKeyboard
[
NumCodes
];
memcpy
(
DebouncedKeyboard
,
InternalKeyboard
,
sizeof
(
DebouncedKeyboard
));
memcpy
(
DebouncedKeyboard
,
InternalKeyboard
,
sizeof
(
DebouncedKeyboard
));
/* poll joysticks */
SDL_JoystickUpdate
();
if
(
SDL_PollEvent
(
&
event
))
{
if
(
SDL_PollEvent
(
&
event
))
{
do
{
do
{
...
@@ -420,6 +447,43 @@ byte IN_MouseButtons()
...
@@ -420,6 +447,43 @@ byte IN_MouseButtons()
return
retr
;
return
retr
;
}
}
///////////////////////////////////////////////////////////////////////////
//
// INL_StartJoy() - Detects & auto-configures the specified joystick
// The auto-config assumes the joystick is centered
//
///////////////////////////////////////////////////////////////////////////
boolean
INL_StartJoy
(
word
joy
)
{
JoystickDef
*
def
;
def
=
&
JoyDefs
[
joy
];
memset
(
def
,
0
,
sizeof
(
*
def
));
def
->
joystick
=
SDL_JoystickOpen
(
joy
);
return
(
def
->
joystick
!=
NULL
);
}
///////////////////////////////////////////////////////////////////////////
//
// INL_ShutJoy() - Cleans up the joystick stuff
//
///////////////////////////////////////////////////////////////////////////
void
INL_ShutJoy
(
word
joy
)
{
JoystickDef
*
def
;
def
=
&
JoyDefs
[
joy
];
if
(
def
->
joystick
!=
NULL
)
{
SDL_JoystickClose
(
def
->
joystick
);
}
memset
(
def
,
0
,
sizeof
(
*
def
));
}
/*
/*
===================
===================
=
=
...
@@ -430,7 +494,7 @@ byte IN_MouseButtons()
...
@@ -430,7 +494,7 @@ byte IN_MouseButtons()
byte
IN_JoyButtons
()
byte
IN_JoyButtons
()
{
{
return
0
;
return
((
INL_GetJoyButtons
(
0
)
<<
0
)
|
(
INL_GetJoyButtons
(
1
)
<<
2
))
;
}
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
...
@@ -440,8 +504,17 @@ byte IN_JoyButtons()
...
@@ -440,8 +504,17 @@ byte IN_JoyButtons()
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
void
IN_GetJoyAbs
(
word
joy
,
word
*
xp
,
word
*
yp
)
void
IN_GetJoyAbs
(
word
joy
,
word
*
xp
,
word
*
yp
)
{
{
*
xp
=
0
;
JoystickDef
*
def
;
*
yp
=
0
;
def
=
&
JoyDefs
[
joy
];
if
(
def
->
joystick
!=
NULL
)
{
*
xp
=
((
int
)
SDL_JoystickGetAxis
(
def
->
joystick
,
1
)
+
32768
)
/
16
;
*
yp
=
((
int
)
SDL_JoystickGetAxis
(
def
->
joystick
,
0
)
+
32768
)
/
16
;
}
else
{
*
xp
=
0
;
*
yp
=
0
;
}
}
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
...
@@ -452,8 +525,57 @@ void IN_GetJoyAbs(word joy,word *xp,word *yp)
...
@@ -452,8 +525,57 @@ void IN_GetJoyAbs(word joy,word *xp,word *yp)
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
void
INL_GetJoyDelta
(
word
joy
,
int
*
dx
,
int
*
dy
)
void
INL_GetJoyDelta
(
word
joy
,
int
*
dx
,
int
*
dy
)
{
{
*
dx
=
0
;
word
x
,
y
;
*
dy
=
0
;
JoystickDef
*
def
;
IN_GetJoyAbs
(
joy
,
&
x
,
&
y
);
def
=
JoyDefs
+
joy
;
if
(
x
<
def
->
threshMinX
)
{
if
(
x
<
def
->
joyMinX
)
x
=
def
->
joyMinX
;
x
=
-
(
x
-
def
->
threshMinX
);
x
*=
def
->
joyMultXL
;
x
>>=
JoyScaleShift
;
*
dx
=
(
x
>
127
)
?
-
127
:
-
x
;
}
else
if
(
x
>
def
->
threshMaxX
)
{
if
(
x
>
def
->
joyMaxX
)
x
=
def
->
joyMaxX
;
x
=
x
-
def
->
threshMaxX
;
x
*=
def
->
joyMultXH
;
x
>>=
JoyScaleShift
;
*
dx
=
(
x
>
127
)
?
127
:
x
;
}
else
*
dx
=
0
;
if
(
y
<
def
->
threshMinY
)
{
if
(
y
<
def
->
joyMinY
)
y
=
def
->
joyMinY
;
y
=
-
(
y
-
def
->
threshMinY
);
y
*=
def
->
joyMultYL
;
y
>>=
JoyScaleShift
;
*
dy
=
(
y
>
127
)
?
-
127
:
-
y
;
}
else
if
(
y
>
def
->
threshMaxY
)
{
if
(
y
>
def
->
joyMaxY
)
y
=
def
->
joyMaxY
;
y
=
y
-
def
->
threshMaxY
;
y
*=
def
->
joyMultYH
;
y
>>=
JoyScaleShift
;
*
dy
=
(
y
>
127
)
?
127
:
y
;
}
else
*
dy
=
0
;
}
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
...
@@ -464,9 +586,32 @@ void INL_GetJoyDelta(word joy,int *dx,int *dy)
...
@@ -464,9 +586,32 @@ void INL_GetJoyDelta(word joy,int *dx,int *dy)
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
word
INL_GetJoyButtons
(
word
joy
)
word
INL_GetJoyButtons
(
word
joy
)
{
{
JoystickDef
*
def
;
def
=
&
JoyDefs
[
joy
];
if
(
def
->
joystick
!=
NULL
)
{
return
(
SDL_JoystickGetButton
(
def
->
joystick
,
0
)
<<
0
)
|
(
SDL_JoystickGetButton
(
def
->
joystick
,
1
)
<<
1
);
}
return
0
;
return
0
;
}
}
//
// INL_SetJoyScale() - Sets up scaling values for the specified joystick
//
static
void
INL_SetJoyScale
(
word
joy
)
{
JoystickDef
*
def
;
def
=
&
JoyDefs
[
joy
];
def
->
joyMultXL
=
JoyScaleMax
/
(
def
->
threshMinX
-
def
->
joyMinX
);
def
->
joyMultXH
=
JoyScaleMax
/
(
def
->
joyMaxX
-
def
->
threshMaxX
);
def
->
joyMultYL
=
JoyScaleMax
/
(
def
->
threshMinY
-
def
->
joyMinY
);
def
->
joyMultYH
=
JoyScaleMax
/
(
def
->
joyMaxY
-
def
->
threshMaxY
);
}
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
//
//
// IN_SetupJoy() - Sets up thresholding values and calls INL_SetJoyScale()
// IN_SetupJoy() - Sets up thresholding values and calls INL_SetJoyScale()
...
@@ -475,4 +620,24 @@ word INL_GetJoyButtons(word joy)
...
@@ -475,4 +620,24 @@ word INL_GetJoyButtons(word joy)
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
void
IN_SetupJoy
(
word
joy
,
word
minx
,
word
maxx
,
word
miny
,
word
maxy
)
void
IN_SetupJoy
(
word
joy
,
word
minx
,
word
maxx
,
word
miny
,
word
maxy
)
{
{
word
d
,
r
;
JoystickDef
*
def
;
def
=
&
JoyDefs
[
joy
];
def
->
joyMinX
=
minx
;
def
->
joyMaxX
=
maxx
;
r
=
maxx
-
minx
;
d
=
r
/
3
;
def
->
threshMinX
=
((
r
/
2
)
-
d
)
+
minx
;
def
->
threshMaxX
=
((
r
/
2
)
+
d
)
+
minx
;
def
->
joyMinY
=
miny
;
def
->
joyMaxY
=
maxy
;
r
=
maxy
-
miny
;
d
=
r
/
3
;
def
->
threshMinY
=
((
r
/
2
)
-
d
)
+
miny
;
def
->
threshMaxY
=
((
r
/
2
)
+
d
)
+
miny
;
INL_SetJoyScale
(
joy
);
}
}
src/wl_menu.c
View file @
9c428361
...
@@ -1411,7 +1411,9 @@ int CalibrateJoystick()
...
@@ -1411,7 +1411,9 @@ int CalibrateJoystick()
IN_GetJoyAbs
(
joystickport
,
&
xmax
,
&
ymax
);
IN_GetJoyAbs
(
joystickport
,
&
xmax
,
&
ymax
);
SD_PlaySound
(
SHOOTSND
);
SD_PlaySound
(
SHOOTSND
);
while
(
IN_JoyButtons
());
do
{
IN_CheckAck
();
}
while
(
IN_JoyButtons
());
//
//
// ASSIGN ACTUAL VALUES HERE
// ASSIGN ACTUAL VALUES HERE
...
@@ -1458,6 +1460,9 @@ void CP_Control()
...
@@ -1458,6 +1460,9 @@ void CP_Control()
case
JOYENABLE
:
case
JOYENABLE
:
joystickenabled
^=
1
;
joystickenabled
^=
1
;
if
(
joystickenabled
)
if
(
!
CalibrateJoystick
())
joystickenabled
=
0
;
DrawCtlScreen
();
DrawCtlScreen
();
CusItems
.
curpos
=-
1
;
CusItems
.
curpos
=-
1
;
ShootSnd
();
ShootSnd
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment