Added ctrl+g mouse grab toggle and alt+enter fullscreen toggle.

Mouse now works during game.

Escape currently exits game (since there is no menu).
This commit is contained in:
Steven Fuller 2001-08-13 01:20:45 +00:00 committed by Patryk Obara
parent f169c0479c
commit 9bc5ea655b
3 changed files with 75 additions and 46 deletions

View file

@ -9,6 +9,7 @@
#include "3dc.h" #include "3dc.h"
#include "platform.h" #include "platform.h"
#include "inline.h"
#include "gamedef.h" #include "gamedef.h"
#include "gameplat.h" #include "gameplat.h"
#include "ffstdio.h" #include "ffstdio.h"
@ -27,12 +28,33 @@
char LevelName[] = {"predbit6\0QuiteALongNameActually"}; /* the real way to load levels */ char LevelName[] = {"predbit6\0QuiteALongNameActually"}; /* the real way to load levels */
int DebouncedGotAnyKey;
unsigned char DebouncedKeyboardInput[MAX_NUMBER_OF_INPUT_KEYS];
int GotJoystick;
int GotMouse;
int JoystickEnabled;
int MouseVelX;
int MouseVelY;
extern int ScanDrawMode; /* to fix image loading */ extern int ScanDrawMode; /* to fix image loading */
extern SCREENDESCRIPTORBLOCK ScreenDescriptorBlock; /* this should be put in a header file */ extern SCREENDESCRIPTORBLOCK ScreenDescriptorBlock; /* this should be put in a header file */
extern unsigned char DebouncedKeyboardInput[MAX_NUMBER_OF_INPUT_KEYS];
extern unsigned char KeyboardInput[MAX_NUMBER_OF_INPUT_KEYS]; extern unsigned char KeyboardInput[MAX_NUMBER_OF_INPUT_KEYS];
extern int DebouncedGotAnyKey;
extern unsigned char GotAnyKey; extern unsigned char GotAnyKey;
extern int NormalFrameTime;
static SDL_Surface *surface;
void DirectReadKeyboard()
{
}
void DirectReadMouse()
{
}
void ReadJoysticks()
{
}
PROCESSORTYPES ReadProcessorType() PROCESSORTYPES ReadProcessorType()
{ {
@ -42,8 +64,8 @@ PROCESSORTYPES ReadProcessorType()
int InitialiseWindowsSystem() int InitialiseWindowsSystem()
{ {
ScanDrawMode = ScanDrawD3DHardwareRGB; ScanDrawMode = ScanDrawD3DHardwareRGB;
GotMouse = 1;
#if 1
if (SDL_Init(SDL_INIT_VIDEO) < 0) { if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, "SDL Init failed: %s\n", SDL_GetError()); fprintf(stderr, "SDL Init failed: %s\n", SDL_GetError());
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -55,15 +77,18 @@ int InitialiseWindowsSystem()
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
if (SDL_SetVideoMode(MyWidth, MyHeight, 0, SDL_OPENGL) == NULL) { if ((surface = SDL_SetVideoMode(MyWidth, MyHeight, 0, SDL_OPENGL)) == NULL) {
fprintf(stderr, "SDL SetVideoMode failed: %s\n", SDL_GetError()); fprintf(stderr, "SDL SetVideoMode failed: %s\n", SDL_GetError());
SDL_Quit(); SDL_Quit();
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
SDL_WM_SetCaption("Aliens vs Predator", "Aliens vs Predator"); SDL_WM_SetCaption("Aliens vs Predator", "Aliens vs Predator");
// SDL_ShowCursor(0); /* -w will disable to first fullscreen, -f will turn it on */
SDL_WM_ToggleFullScreen(surface);
SDL_WM_GrabInput(SDL_GRAB_ON);
SDL_ShowCursor(0);
glViewport(0, 0, MyWidth, MyHeight); glViewport(0, 0, MyWidth, MyHeight);
@ -82,7 +107,6 @@ int InitialiseWindowsSystem()
/* /*
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
*/ */
#endif
return 0; return 0;
} }
@ -311,10 +335,8 @@ static int KeySymToKey(int keysym)
} }
} }
static void handle_keypress(int keysym, int press) static void handle_keypress(int key, int press)
{ {
int key = KeySymToKey(keysym);
if (key == -1) if (key == -1)
return; return;
@ -329,8 +351,8 @@ static void handle_keypress(int keysym, int press)
void CheckForWindowsMessages() void CheckForWindowsMessages()
{ {
#if 1
SDL_Event event; SDL_Event event;
int x, y, buttons;
GotAnyKey = 0; GotAnyKey = 0;
DebouncedGotAnyKey = 0; DebouncedGotAnyKey = 0;
@ -340,19 +362,51 @@ void CheckForWindowsMessages()
do { do {
switch(event.type) { switch(event.type) {
case SDL_KEYDOWN: case SDL_KEYDOWN:
handle_keypress(event.key.keysym.sym, 1); handle_keypress(KeySymToKey(event.key.keysym.sym), 1);
break; break;
case SDL_KEYUP: case SDL_KEYUP:
handle_keypress(event.key.keysym.sym, 0); handle_keypress(KeySymToKey(event.key.keysym.sym), 0);
break; break;
case SDL_QUIT: case SDL_QUIT:
SDL_Quit(); // SDL_Quit();
exit(17); /* TODO tempy! */ // exit(17); /* TODO tempy! */
AvP.MainLoopRunning = 0; /* TODO */
break; break;
} }
} while (SDL_PollEvent(&event)); } while (SDL_PollEvent(&event));
} }
#endif
buttons = SDL_GetRelativeMouseState(&x, &y);
if (buttons & SDL_BUTTON(1))
handle_keypress(KEY_LMOUSE, 1);
else
handle_keypress(KEY_LMOUSE, 0);
if (buttons & SDL_BUTTON(2))
handle_keypress(KEY_MMOUSE, 1);
else
handle_keypress(KEY_MMOUSE, 0);
if (buttons & SDL_BUTTON(3))
handle_keypress(KEY_RMOUSE, 1);
else
handle_keypress(KEY_RMOUSE, 0);
MouseVelX = DIV_FIXED(x, NormalFrameTime);
MouseVelY = DIV_FIXED(y, NormalFrameTime);
if (KeyboardInput[KEY_LEFTALT] && DebouncedKeyboardInput[KEY_CR]) {
SDL_WM_ToggleFullScreen(surface);
}
if (KeyboardInput[KEY_LEFTCTRL] && DebouncedKeyboardInput[KEY_G]) {
SDL_GrabMode gm;
gm = SDL_WM_GrabInput(SDL_GRAB_QUERY);
SDL_WM_GrabInput((gm == SDL_GRAB_ON) ? SDL_GRAB_OFF : SDL_GRAB_ON);
}
if (DebouncedKeyboardInput[KEY_ESCAPE])
AvP.MainLoopRunning = 0;
/* ctrl-z for iconify window? */
} }
void InGameFlipBuffers() void InGameFlipBuffers()
@ -370,9 +424,7 @@ void ThisFramesRenderingHasBegun()
/* fprintf(stderr, "ThisFramesRenderingHasBegun()\n"); */ /* fprintf(stderr, "ThisFramesRenderingHasBegun()\n"); */
/* TODO: this should be in D3D_DrawBackdrop */ /* TODO: this should be in D3D_DrawBackdrop */
#if 1
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
#endif
} }
void ThisFramesRenderingHasFinished() void ThisFramesRenderingHasFinished()
@ -431,6 +483,10 @@ int main(int argc, char *argv[])
MarineInputSecondaryConfig = DefaultMarineInputSecondaryConfig; MarineInputSecondaryConfig = DefaultMarineInputSecondaryConfig;
PredatorInputSecondaryConfig = DefaultPredatorInputSecondaryConfig; PredatorInputSecondaryConfig = DefaultPredatorInputSecondaryConfig;
AlienInputSecondaryConfig = DefaultAlienInputSecondaryConfig; AlienInputSecondaryConfig = DefaultAlienInputSecondaryConfig;
ControlMethods = DefaultControlMethods; /* raise the default sensitivity for now */
ControlMethods.MouseXSensitivity = DEFAULT_MOUSEX_SENSITIVITY*2;
ControlMethods.MouseYSensitivity = DEFAULT_MOUSEY_SENSITIVITY*2;
LoadKeyConfiguration(); LoadKeyConfiguration();

View file

@ -474,31 +474,6 @@ BOOL ChangeDirectDrawObject()
} }
/* di_func.cpp */
unsigned char DebouncedGotAnyKey;
unsigned char DebouncedKeyboardInput[MAX_NUMBER_OF_INPUT_KEYS];
int GotJoystick;
int GotMouse;
int JoystickEnabled;
int MouseVelX;
int MouseVelY;
void DirectReadKeyboard()
{
// fprintf(stderr, "DirectReadKeyboard()\n");
}
void DirectReadMouse()
{
// fprintf(stderr, "DirectReadMouse()\n");
}
void ReadJoysticks()
{
// fprintf(stderr, "ReadJoysticks()\n");
}
/* dx_proj.cpp */ /* dx_proj.cpp */
int use_mmx_math = 0; int use_mmx_math = 0;

View file

@ -205,8 +205,6 @@ unsigned int timeGetTime()
secs--; secs--;
} }
printf("Ticks = %u\n", secs * 1000 + (usecs / 1000));
return secs * 1000 + (usecs / 1000); return secs * 1000 + (usecs / 1000);
} }