Cleanup of inplib: don't include stuff from uqm/, some funcs and vars moved around, some dead stuff removed, others

git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@3226 8092fc87-c524-0410-9efc-e669fe64eaf9
This commit is contained in:
avolkov
2009-10-14 13:35:37 +00:00
parent 398552a22a
commit 934bbd3a8f
21 changed files with 109 additions and 68 deletions
+1 -4
View File
@@ -23,13 +23,10 @@
#include "libs/compiler.h"
#include "libs/uio.h"
typedef DWORD INPUT_STATE;
extern BOOLEAN InitInput (void);
extern BOOLEAN UninitInput (void);
extern BOOLEAN AnyButtonPress (BOOLEAN DetectSpecial);
extern void FlushInput (void);
extern void TFB_ResetControls (void);
/*
* Not used right now
+1 -1
View File
@@ -20,6 +20,6 @@
#define _INPINTRN_H
#include "libs/inplib.h"
#include "libs/input/input_common.h"
#endif /* _INPINTRN_H */
-3
View File
@@ -17,7 +17,4 @@
*/
#include "port.h"
#include "input_common.h"
#include "inpintrn.h"
volatile BOOLEAN ExitRequested, GamePaused;
+7 -2
View File
@@ -28,7 +28,12 @@ enum
// flags for TFB_InitInput
//#define TFB_INPUTFLAGS_ETC (1<<0)
int TFB_InitInput (int driver, int flags);
void TFB_UninitInput (void);
extern int TFB_InitInput (int driver, int flags);
extern void TFB_UninitInput (void);
#define MAX_FLIGHT_ALTERNATES 2
extern void TFB_SetInputVectors (volatile int menu[], int num_menu,
volatile int flight[], int num_templ, int num_flight);
#endif
+80 -30
View File
@@ -20,8 +20,8 @@
#include <assert.h>
#include <errno.h>
#include "../inpintrn.h"
#include "libs/graphics/sdl/sdl_common.h"
#include "libs/input/input_common.h"
#include "libs/input/sdl/vcontrol.h"
#include "libs/input/sdl/keynames.h"
#include "libs/memlib.h"
@@ -29,8 +29,6 @@
#include "libs/log.h"
#include "libs/reslib.h"
#include "options.h"
// XXX: we should not include anything from uqm/ inside libs/
#include "uqm/controls.h"
#define KBDBUFSIZE (1 << 8)
@@ -41,6 +39,14 @@ static int num_keys = 0;
static int *kbdstate = NULL;
// Holds all SDL keys +1 for holding invalid values
static volatile int *menu_vec;
static int num_menu;
// The last vector element is the character repeat "key"
#define KEY_MENU_ANY (num_menu - 1)
static volatile int *flight_vec;
static int num_templ;
static int num_flight;
static BOOLEAN InputInitialized = FALSE;
static BOOLEAN in_character_mode = FALSE;
@@ -98,12 +104,15 @@ register_menu_controls (int index)
if (!res_HasKey (buf))
break;
VControl_ParseGesture (&g, res_GetString (buf));
VControl_AddGestureBinding (&g, (int *)&ImmediateInputState.menu[index]);
VControl_AddGestureBinding (&g, (int *)&menu_vec[index]);
i++;
}
}
static VCONTROL_GESTURE controls[NUM_TEMPLATES][NUM_KEYS][2];
static VCONTROL_GESTURE *controls;
#define CONTROL_PTR(i, j, k) \
(controls + ((i) * num_flight + (j)) * MAX_FLIGHT_ALTERNATES + (k))
static void
register_flight_controls (void)
@@ -113,7 +122,7 @@ register_flight_controls (void)
buf[39] = '\0';
for (i = 0; i < NUM_TEMPLATES; i++)
for (i = 0; i < num_templ; i++)
{
/* Copy in name */
snprintf (buf, 39, "keys.%d.name", i+1);
@@ -126,11 +135,11 @@ register_flight_controls (void)
{
input_templates[i].name[0] = '\0';
}
for (j = 0; j < NUM_KEYS; j++)
for (j = 0; j < num_flight; j++)
{
for (k = 0; k < 2; k++)
for (k = 0; k < MAX_FLIGHT_ALTERNATES; k++)
{
VCONTROL_GESTURE *g = &controls[i][j][k];
VCONTROL_GESTURE *g = CONTROL_PTR(i, j, k);
snprintf (buf, 39, "keys.%d.%s.%d", i+1, flight_res_names[j], k+1);
if (!res_HasKey (buf))
{
@@ -138,7 +147,7 @@ register_flight_controls (void)
continue;
}
VControl_ParseGesture (g, res_GetString (buf));
VControl_AddGestureBinding (g, (int *)&ImmediateInputState.key[i][j]);
VControl_AddGestureBinding (g, (int *)(flight_vec + i * num_flight + j));
}
}
}
@@ -149,10 +158,19 @@ initKeyConfig (void)
{
int i;
if (!menu_vec || !flight_vec)
{
log_add (log_Fatal, "initKeyConfig(): invalid input vectors");
exit (EXIT_FAILURE);
}
controls = HCalloc (sizeof (*controls) * num_templ * num_flight
* MAX_FLIGHT_ALTERNATES);
/* First, load in the menu keys */
LoadResourceIndex (contentDir, "menu.key", "menu.");
LoadResourceIndex (configDir, "override.cfg", "menu.");
for (i = 0; i < NUM_MENU_KEYS; i++)
for (i = 0; i < num_menu; i++)
{
if (!menu_res_names[i])
break;
@@ -178,7 +196,23 @@ static void
resetKeyboardState (void)
{
memset (kbdstate, 0, sizeof (int) * num_keys);
ImmediateInputState.menu[KEY_MENU_ANY] = 0;
menu_vec[KEY_MENU_ANY] = 0;
}
void
TFB_SetInputVectors (volatile int menu[], int num_menu_, volatile int flight[],
int num_templ_, int num_flight_)
{
if (num_menu_ < 0 || num_templ_ < 0 || num_flight_ < 0)
{
log_add (log_Fatal, "TFB_SetInputVectors(): invalid vector size");
exit (EXIT_FAILURE);
}
menu_vec = menu;
num_menu = num_menu_;
flight_vec = flight;
num_templ = num_templ_;
num_flight = num_flight_;
}
int
@@ -189,8 +223,6 @@ TFB_InitInput (int driver, int flags)
(void)driver;
(void)flags;
GamePaused = ExitRequested = FALSE;
SDL_EnableUNICODE(1);
(void)SDL_GetKeyState (&num_keys);
kbdstate = (int *)HMalloc (sizeof (int) * (num_keys + 1));
@@ -237,6 +269,7 @@ void
TFB_UninitInput (void)
{
VControl_Uninit ();
HFree (controls);
HFree (kbdstate);
}
@@ -342,7 +375,7 @@ ProcessInputEvent (const SDL_Event *Event)
kbdbuf[kbdtail] = map_key;
kbdtail = newtail;
lastchar = map_key;
ImmediateInputState.menu[KEY_MENU_ANY]++;
menu_vec[KEY_MENU_ANY]++;
}
}
else if (Event->type == SDL_KEYUP)
@@ -350,13 +383,13 @@ ProcessInputEvent (const SDL_Event *Event)
if (kbdstate[k] == 0)
{ // something is fishy -- better to reset the
// repeatable state to avoid big problems
ImmediateInputState.menu[KEY_MENU_ANY] = 0;
menu_vec[KEY_MENU_ANY] = 0;
}
else
{
kbdstate[k]--;
if (ImmediateInputState.menu[KEY_MENU_ANY] > 0)
ImmediateInputState.menu[KEY_MENU_ANY]--;
if (menu_vec[KEY_MENU_ANY] > 0)
menu_vec[KEY_MENU_ANY]--;
}
}
}
@@ -372,17 +405,18 @@ TFB_ResetControls (void)
lastchar = 0;
}
void
FlushInput (void)
{
TFB_ResetControls ();
FlushInputState ();
}
void
InterrogateInputState (int template, int control, int index, char *buffer, int maxlen)
{
VCONTROL_GESTURE *g = &controls[template][control][index];
VCONTROL_GESTURE *g = CONTROL_PTR(template, control, index);
if (template >= num_templ || control >= num_flight
|| index >= MAX_FLIGHT_ALTERNATES)
{
log_add (log_Warning, "InterrogateInputState(): invalid control index");
buffer[0] = 0;
return;
}
switch (g->type)
{
@@ -411,11 +445,19 @@ InterrogateInputState (int template, int control, int index, char *buffer, int m
void
RemoveInputState (int template, int control, int index)
{
VCONTROL_GESTURE *g = &controls[template][control][index];
VCONTROL_GESTURE *g = CONTROL_PTR(template, control, index);
char keybuf[40];
keybuf[39] = '\0';
VControl_RemoveGestureBinding (g, (int *)&ImmediateInputState.key[template][control]);
if (template >= num_templ || control >= num_flight
|| index >= MAX_FLIGHT_ALTERNATES)
{
log_add (log_Warning, "RemoveInputState(): invalid control index");
return;
}
VControl_RemoveGestureBinding (g,
(int *)(flight_vec + template * num_flight + control));
g->type = VCONTROL_NONE;
snprintf (keybuf, 39, "keys.%d.%s.%d", template+1, flight_res_names[control], index+1);
@@ -431,6 +473,13 @@ RebindInputState (int template, int control, int index)
char keybuf[40], valbuf[40];
keybuf[39] = valbuf[39] = '\0';
if (template >= num_templ || control >= num_flight
|| index >= MAX_FLIGHT_ALTERNATES)
{
log_add (log_Warning, "RebindInputState(): invalid control index");
return;
}
/* Remove the old binding on this spot */
RemoveInputState (template, control, index);
@@ -442,8 +491,9 @@ RebindInputState (int template, int control, int index)
}
/* And now, add the new binding. */
VControl_AddGestureBinding (&g, (int *)&ImmediateInputState.key[template][control]);
controls[template][control][index] = g;
VControl_AddGestureBinding (&g,
(int *)(flight_vec + template * num_flight + control));
*CONTROL_PTR(template, control, index) = g;
snprintf (keybuf, 39, "keys.%d.%s.%d", template+1, flight_res_names[control], index+1);
VControl_DumpGesture (valbuf, 39, &g);
res_PutString (keybuf, valbuf);
+1 -2
View File
@@ -19,7 +19,6 @@
#ifndef INPUT_H
#define INPUT_H
void FlushInput (void);
void ProcessInputEvent (const SDL_Event *Event);
extern void ProcessInputEvent (const SDL_Event *Event);
#endif
+5
View File
@@ -482,6 +482,11 @@ main (int argc, char *argv[])
initAudio calls AssignTask, which currently blocks on
ProcessThreadLifecycles... */
// initAudio (snddriver, soundflags);
// Make sure that the compiler treats multidim arrays the way we expect
assert (sizeof (int [NUM_TEMPLATES * NUM_KEYS]) ==
sizeof (int [NUM_TEMPLATES][NUM_KEYS]));
TFB_SetInputVectors (ImmediateInputState.menu, NUM_MENU_KEYS,
(volatile int *)ImmediateInputState.key, NUM_TEMPLATES, NUM_KEYS);
TFB_InitInput (TFB_INPUTDRIVER_SDL, 0);
StartThread (Starcon2Main, NULL, 1024, "Starcon2Main");
-1
View File
@@ -24,7 +24,6 @@
#include "uqm/setup.h"
#include "uqm/shipcont.h"
#include "libs/graphics/gfx_common.h"
#include "libs/inplib.h"
#include "libs/mathlib.h"
#include "libs/inplib.h"
#include "libs/sound/sound.h"
-2
View File
@@ -25,7 +25,6 @@
#include "sounds.h"
#include "gamestr.h"
#include "libs/graphics/widgets.h"
#include "libs/inplib.h"
#include "libs/sound/trackplayer.h"
#include "libs/log.h"
#include "libs/resource/stringbank.h"
@@ -266,7 +265,6 @@ DoPopupWindow (const char *msg)
DrawStamp (&s);
DestroyDrawable (ReleaseDrawable (s.frame));
FlushInput ();
SetContextClipRect (&oldRect);
SetContext (oldContext);
UnlockMutex (GraphicsLock);
+1 -2
View File
@@ -95,8 +95,7 @@ extern volatile CONTROLLER_INPUT_STATE ImmediateInputState;
extern CONTROL_TEMPLATE PlayerControls[];
void UpdateInputState (void);
void FlushInputState (void);
void TFB_ResetControls (void);
extern void FlushInput (void);
void SetMenuRepeatDelay (DWORD min, DWORD max, DWORD step, BOOLEAN gestalt);
void SetDefaultMenuRepeatDelay (void);
void ResetKeyRepeat (void);
+2 -3
View File
@@ -24,7 +24,6 @@
#include "intel.h"
#include "setup.h"
#include "units.h"
#include "libs/inplib.h"
#include "libs/mathlib.h"
#include "libs/log.h"
@@ -572,7 +571,7 @@ ThrustShip (ELEMENT *ShipPtr, COUNT angle)
void
Pursue (ELEMENT *ShipPtr, EVALUATE_DESC *EvalDescPtr)
{
INPUT_STATE maneuver_state;
BYTE maneuver_state;
COUNT desired_thrust_angle, desired_turn_angle;
SIZE delta_x, delta_y;
SIZE ship_delta_x, ship_delta_y;
@@ -703,7 +702,7 @@ Pursue (ELEMENT *ShipPtr, EVALUATE_DESC *EvalDescPtr)
void
Entice (ELEMENT *ShipPtr, EVALUATE_DESC *EvalDescPtr)
{
INPUT_STATE maneuver_state;
BYTE maneuver_state;
COUNT desired_thrust_angle, desired_turn_angle;
COUNT cone_of_fire, travel_angle;
SIZE delta_x, delta_y;
+7 -3
View File
@@ -65,6 +65,9 @@ static MENU_SOUND_FLAGS sound_0, sound_1;
volatile CONTROLLER_INPUT_STATE ImmediateInputState;
volatile BOOLEAN ExitRequested;
volatile BOOLEAN GamePaused;
static void
_clear_menu_state (void)
{
@@ -291,8 +294,9 @@ SetDefaultMenuRepeatDelay ()
}
void
FlushInputState (void)
FlushInput (void)
{
TFB_ResetControls ();
_clear_menu_state ();
}
@@ -334,7 +338,7 @@ DoInput (void *pInputState, BOOLEAN resetInput)
SetMenuRepeatDelay (ACCELERATION_INCREMENT, MENU_REPEAT_DELAY,
ACCELERATION_INCREMENT, FALSE);
if (resetInput)
TFB_ResetControls ();
FlushInput ();
do
{
@@ -376,7 +380,7 @@ DoInput (void *pInputState, BOOLEAN resetInput)
} while (((INPUT_STATE_DESC*)pInputState)->InputFunc (pInputState));
if (resetInput)
TFB_ResetControls ();
FlushInput ();
}
void
-1
View File
@@ -25,7 +25,6 @@
#include "encount.h"
#include "planets/lander.h"
#include "gamestr.h"
#include "libs/inplib.h"
#include "load.h"
#include "options.h"
#include "save.h"
-4
View File
@@ -28,7 +28,6 @@
#include "libs/graphics/drawable.h"
#include "libs/sound/sound.h"
#include "libs/vidlib.h"
#include "libs/inplib.h"
#include "libs/log.h"
#include <ctype.h>
@@ -785,7 +784,6 @@ ShowSlidePresentation (STRING PresStr)
OldFont = SetContextFont (NULL);
UnlockMutex (GraphicsLock);
FlushInput ();
SetMenuSounds (MENU_SOUND_NONE, MENU_SOUND_NONE);
pis.MenuRepeatDelay = 0;
pis.InputFunc = DoPresentation;
@@ -891,8 +889,6 @@ ShowLegacyVideo (LEGACY_VIDEO vid)
if (!ref)
return FALSE;
// XXX: FlushInput() won't be need once DoInput(reset-input) works right
FlushInput ();
vis.MenuRepeatDelay = 0;
vis.InputFunc = DoVideoInput;
vis.CurVideo = ref;
+1 -2
View File
@@ -48,7 +48,6 @@
#include "util.h"
#include "libs/graphics/drawable.h"
#include "libs/gfxlib.h"
#include "libs/inplib.h"
#include "libs/mathlib.h"
#include "libs/log.h"
@@ -1098,7 +1097,7 @@ DoEdit (MELEE_STATE *pMS)
pMS->Initialized = 0;
else
pMS->Initialized = -1;
TFB_ResetControls ();
FlushInput ();
DoPickShip (pMS);
}
else if (pMS->row < NUM_MELEE_ROWS &&
+1 -1
View File
@@ -651,7 +651,7 @@ Devices (MENU_STATE *pMS)
pMS->first_item.y = 0;
pMS->CurFrame = (FRAME)DeviceMap;
TFB_ResetControls ();
FlushInput ();
DoManipulateDevices (pMS); /* to make sure it's initialized */
SetMenuSounds (MENU_SOUND_ARROWS, MENU_SOUND_SELECT);
DoInput (pMS, TRUE);
-1
View File
@@ -35,7 +35,6 @@
#include "../uqmdebug.h"
#include "libs/graphics/gfx_common.h"
#include "libs/mathlib.h"
#include "libs/inplib.h"
#include "libs/log.h"
-1
View File
@@ -317,7 +317,6 @@ RestartMenu (MENU_STATE *pMS)
if (TimeOut == ONE_SECOND / 8)
SleepThread (ONE_SECOND * 3);
DrawRestartMenuGraphic (pMS);
FlushInput ();
GLOBAL (CurrentActivity) &= ~CHECK_ABORT;
SetMenuSounds (MENU_SOUND_UP | MENU_SOUND_DOWN, MENU_SOUND_SELECT);
DoInput (pMS, TRUE);
+2 -3
View File
@@ -606,7 +606,8 @@ SaveProblem (void)
FlushGraphics ();
UnlockMutex (GraphicsLock);
while (AnyButtonPress (FALSE));
while (AnyButtonPress (FALSE))
;
do
{
TaskSwitch ();
@@ -622,8 +623,6 @@ SaveProblem (void)
SetContext (OldContext);
DestroyDrawable (ReleaseDrawable (s.frame));
UnlockMutex (GraphicsLock);
return;
}
// This function first writes to a memory file, and then writes the whole
-1
View File
@@ -30,7 +30,6 @@
#include "sounds.h"
#include "libs/graphics/gfx_common.h"
#include "libs/tasklib.h"
#include "libs/inplib.h"
MENU_STATE *pMenuState;
-1
View File
@@ -37,7 +37,6 @@
#include "libs/log.h"
#include "libs/gfxlib.h"
#include "libs/graphics/gfx_common.h"
#include "libs/inplib.h"
#include "libs/misc.h"
#include "uqmversion.h"