From: Côme BERNIGAUD Date: Sat, 5 Jun 2010 20:51:18 +0000 (+0400) Subject: Various SDL input and Game::* cleanups X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=735daf95aba0eef54d151daae01285f0959825d0;p=lugaru.git Various SDL input and Game::* cleanups --- CMakeLists.txt | 5 +- Source/Game.cpp | 357 +++++++++++++++ Source/Game.h | 468 ++++++++++---------- Source/GameDraw.cpp | 105 +++-- Source/GameInitDispose.cpp | 197 -------- Source/GameTick.cpp | 1088 ++++++++++++-------------------------------- Source/Globals.cpp | 3 +- Source/Input.cpp | 68 +++ Source/Input.h | 44 ++ Source/OpenGL_Windows.cpp | 247 +---------- Source/Settings.cpp | 82 ++-- Source/WinInput.cpp | 1008 ---------------------------------------- Source/WinInput.h | 156 ------- 13 files changed, 1107 insertions(+), 2721 deletions(-) create mode 100644 Source/Game.cpp create mode 100644 Source/Input.cpp create mode 100644 Source/Input.h delete mode 100644 Source/WinInput.cpp delete mode 100644 Source/WinInput.h --- diff --git a/CMakeLists.txt b/CMakeLists.txt index d19e669..e09a149 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,7 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") set(LUGARU_SRCS ${SRCDIR}/Frustum.cpp ${SRCDIR}/Account.cpp + ${SRCDIR}/Game.cpp ${SRCDIR}/GameDraw.cpp ${SRCDIR}/GameInitDispose.cpp ${SRCDIR}/GameTick.cpp @@ -77,7 +78,7 @@ set(LUGARU_SRCS ${SRCDIR}/Weapons.cpp ${SRCDIR}/OpenGL_Windows.cpp ${SRCDIR}/openal_wrapper.cpp - ${SRCDIR}/WinInput.cpp + ${SRCDIR}/Input.cpp ${SRCDIR}/Settings.cpp ${SRCDIR}/Stereo.cpp ) @@ -103,7 +104,7 @@ set(LUGARU_H ${SRCDIR}/Terrain.h ${SRCDIR}/Text.h ${SRCDIR}/Weapons.h - ${SRCDIR}/WinInput.h + ${SRCDIR}/Input.h ${SRCDIR}/alstubs.h ${SRCDIR}/binio.h ${SRCDIR}/openal_wrapper.h diff --git a/Source/Game.cpp b/Source/Game.cpp new file mode 100644 index 0000000..524009d --- /dev/null +++ b/Source/Game.cpp @@ -0,0 +1,357 @@ +#include "Game.h" +#include "openal_wrapper.h" +#include "SDL_thread.h" + +extern int mainmenu; +extern OPENAL_SAMPLE *samp[100]; +extern int channels[100]; +extern "C" void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused); + + + +Game::Game() +{ + terraintexture = 0; + terraintexture2 = 0; + terraintexture3 = 0; + screentexture = 0; + screentexture2 = 0; + logotexture = 0; + loadscreentexture = 0; + Maparrowtexture = 0; + Mapboxtexture = 0; + Mapcircletexture = 0; + cursortexture = 0; + + memset(Mainmenuitems, 0, sizeof(Mainmenuitems)); + + nummenuitems = 0; + + memset(startx, 0, sizeof(startx)); + memset(starty, 0, sizeof(starty)); + memset(endx, 0, sizeof(endx)); + memset(endy, 0, sizeof(endy)); + + memset(selectedlong, 0, sizeof(selectedlong)); + memset(offsetx, 0, sizeof(offsetx)); + memset(offsety, 0, sizeof(offsety)); + memset(movex, 0, sizeof(movex)); + memset(movey, 0, sizeof(movey)); + memset(endy, 0, sizeof(endy)); + + transition = 0; + anim = 0; + selected = 0; + loaddistrib = 0; + keyselect = 0; + indemo = 0; + + won = 0; + + entername = 0; + + memset(menustring, 0, sizeof(menustring)); + memset(registrationname, 0, sizeof(registrationname)); + registrationnumber = 0; + + newdetail = 0; + newscreenwidth = 0; + newscreenheight = 0; + + gameon = 0; + deltah = 0,deltav = 0; + mousecoordh = 0,mousecoordv = 0; + oldmousecoordh = 0,oldmousecoordv = 0; + rotation = 0,rotation2 = 0; + +// SkyBox skybox; + + cameramode = 0; + cameratogglekeydown = 0; + chattogglekeydown = 0; + olddrawmode = 0; + drawmode = 0; + drawmodetogglekeydown = 0; + explodetogglekeydown = 0; + detailtogglekeydown = 0; + firstload = 0; + oldbutton = 0; + + leveltime = 0; + loadtime = 0; + +// Model hawk; + +// XYZ hawkcoords; +// XYZ realhawkcoords; + + hawktexture = 0; + hawkrotation = 0; + hawkcalldelay = 0; +/* + Model eye; + Model iris; + Model cornea; +*/ + stealthloading = 0; + + campaignnumlevels = 0; + + memset(campaignmapname, 0, sizeof(campaignmapname)); + memset(campaigndescription, 0, sizeof(campaigndescription)); + memset(campaignchoosenext, 0, sizeof(campaignchoosenext)); + memset(campaignnumnext, 0, sizeof(campaignnumnext)); + memset(campaignnextlevel, 0, sizeof(campaignnextlevel)); + int campaignchoicesmade; + memset(campaignchoices, 0, sizeof(campaignchoices)); + memset(campaignlocationx, 0, sizeof(campaignlocationx)); + memset(campaignlocationy, 0, sizeof(campaignlocationy)); + memset(campaignlocationy, 0, sizeof(campaignlocationy)); + + campaignchoicenum = 0; + + memset(campaignchoicewhich, 0, sizeof(campaignchoicewhich)); + + whichchoice = 0; + + numlevelspassed = 0; + + memset(levelorder, 0, sizeof(levelorder)); + memset(levelvisible, 0, sizeof(levelvisible)); + memset(levelhighlight, 0, sizeof(levelhighlight)); + + minimap = 0; + + musictype = 0,oldmusictype = 0,oldoldmusictype = 0; + realthreat = 0; + +// Model rabbit; +// XYZ rabbitcoords; + +// XYZ mapcenter; + mapradius = 0; + +// Text text; + fps = 0; + +// XYZ cameraloc; + cameradist = 0; + + envtogglekeydown = 0; + slomotogglekeydown = 0; + texturesizetogglekeydown = 0; + freezetogglekeydown = 0; + drawtoggle = 0; + + editorenabled = 0; + editortype = 0; + editorsize = 0; + editorrotation = 0; + editorrotation2 = 0; + + brightness = 0; + + quit = 0; + tryquit = 0; + +// XYZ pathpoint[30]; + numpathpoints = 0; + memset(numpathpointconnect, 0, sizeof(numpathpointconnect)); + memset(pathpointconnect, 0, sizeof(pathpointconnect)); + pathpointselected = 0; + + endgame = 0; + scoreadded = 0; + numchallengelevels = 0; + + console = 0; + archiveselected = 0; + + memset(consoletext, 0, sizeof(consoletext)); + memset(consolechars, 0, sizeof(consolechars)); + chatting = 0; + memset(displaytext, 0, sizeof(displaytext)); + memset(displaychars, 0, sizeof(displaychars)); + memset(displaytime, 0, sizeof(displaytime)); + displayblinkdelay = 0; + displayblink = 0; + displayselected = 0; + consolekeydown = 0; + consoletogglekeydown = 0; + consoleblinkdelay = 0; + consoleblink = 0; + consoleselected = 0; +// memset(togglekey, 0, sizeof(togglekey)); +// memset(togglekeydelay, 0, sizeof(togglekeydelay)); + registernow = 0; + autocam = 0; + + crouchkey = 0,jumpkey = 0,forwardkey = 0,chatkey = 0,backkey = 0,leftkey = 0,rightkey = 0,drawkey = 0,throwkey = 0,attackkey = 0; + oldattackkey = 0; + + loading = 0; + talkdelay = 0; + + numboundaries = 0; +// XYZ boundary[360]; + + whichlevel = 0; + oldenvironment = 0; + targetlevel = 0; + changedelay = 0; + + memset(musicvolume, 0, sizeof(musicvolume)); + memset(oldmusicvolume, 0, sizeof(oldmusicvolume)); + musicselected = 0; + change = 0; + +//------------ + + waiting = false; + mainmenu = 0; + + accountactive = NULL; +} + +typedef struct { + Game* game; + void (Game::*method)(); +} params_thread; + +void Game::fireSound(int sound) { + float gLoc[3]={0,0,0}; + float vel[3]={0,0,0}; + OPENAL_Sample_SetMinMaxDistance(samp[sound], 9999.0f, 99999.0f); + PlaySoundEx( sound, samp[sound], NULL, true); + OPENAL_3D_SetAttributes(channels[sound], gLoc, vel); + OPENAL_SetVolume(channels[sound], 256); + OPENAL_SetPaused(channels[sound], false); + OPENAL_Sample_SetMinMaxDistance(samp[sound], 8.0f, 2000.0f); +} + +void Game::inputText(char* str, int* charselected, int* nb_chars) { + SDL_Event evenement; + int i; + + if(!waiting) { + waiting=true; + SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,SDL_DEFAULT_REPEAT_INTERVAL); + SDL_EnableUNICODE(true); + } + + SDL_PollEvent(&evenement); + + switch(evenement.type) { + case SDL_KEYDOWN: + if(evenement.key.keysym.sym == SDLK_ESCAPE) { + for(i=0;i<255;i++){ + str[i]=' '; + } + *nb_chars=0; + *charselected=0; + waiting=false; + } else if(evenement.key.keysym.sym==SDLK_BACKSPACE){ + if((*charselected)!=0) { + for(i=(*charselected)-1;i<255;i++){ + str[i]=str[i+1]; + } + str[255]=' '; + (*charselected)--; + (*nb_chars)--; + } + } else if(evenement.key.keysym.sym==SDLK_DELETE){ + for(i=(*charselected);i<255;i++){ + str[i]=str[i+1]; + } + str[255]=' '; + (*nb_chars)--; + } else if(evenement.key.keysym.sym==SDLK_LEFT){ + if((*charselected)!=0) + (*charselected)--; + } else if(evenement.key.keysym.sym==SDLK_RIGHT){ + if((*charselected)<(*nb_chars)) + (*charselected)++; + } else if(evenement.key.keysym.sym==SDLK_RETURN) { + waiting=false; + } else if((evenement.key.keysym.unicode<127)&&((*nb_chars)<60)&&(evenement.key.keysym.sym!=SDLK_LSHIFT)&&(evenement.key.keysym.sym!=SDLK_RSHIFT)) { + for(i=255;i>=(*charselected)+1;i--){ + str[i]=str[i-1]; + } + str[*charselected]=evenement.key.keysym.unicode; + (*charselected)++; + (*nb_chars)++; + } + break; + } + + if(!waiting) { + SDL_EnableKeyRepeat(0,0); // disable key repeat + SDL_EnableUNICODE(false); + } +} + +void Game::setKeySelected() { + waiting=true; + params_thread* data = new params_thread; + data->game = this; + data->method = &Game::setKeySelected_thread; + printf("launch thread\n"); + SDL_Thread* thread = SDL_CreateThread(Game::thread, data); + if ( thread == NULL ) { + fprintf(stderr, "Unable to create thread: %s\n", SDL_GetError()); + waiting=false; + return; + } +} + +void Game::setKeySelected_thread() { + int keycode=-1; + SDL_Event evenement; + while(keycode==-1) { + SDL_WaitEvent(&evenement); + switch(evenement.type) { + case SDL_KEYDOWN: + keycode = evenement.key.keysym.sym; + break; + case SDL_MOUSEBUTTONDOWN: + keycode = SDLK_LAST+evenement.button.button; + break; + default: + break; + } + } + if(keycode != SDLK_ESCAPE) { + fireSound(); + switch(keyselect) { + case 0: forwardkey=keycode; + break; + case 1: backkey=keycode; + break; + case 2: leftkey=keycode; + break; + case 3: rightkey=keycode; + break; + case 4: crouchkey=keycode; + break; + case 5: jumpkey=keycode; + break; + case 6: drawkey=keycode; + break; + case 7: throwkey=keycode; + break; + case 8: attackkey=keycode; + break; + default: + break; + } + } + keyselect=-1; + waiting=false; +} + +int Game::thread(void *data) { + params_thread* pt = (params_thread*)data; + if(pt) { + (pt->game->*(pt->method))(); + } +} diff --git a/Source/Game.h b/Source/Game.h index 1297fbd..389db5a 100644 --- a/Source/Game.h +++ b/Source/Game.h @@ -40,9 +40,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "TGALoader.h" -#if !PLATFORM_MACOSX -#include "WinInput.h" -#else +#if PLATFORM_MACOSX #include "Macinput.h" #endif @@ -63,238 +61,250 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include "gamegl.h" #include "Stereo.h" +#include "Account.h" extern GLuint rabbittexture; class Game { -public: - - typedef std::map TextureList; - typedef std::map GLTextureList; - typedef TextureList::iterator TexIter; - static TextureList textures; - - GLuint terraintexture; - GLuint terraintexture2; - GLuint terraintexture3; - GLuint screentexture; - GLuint screentexture2; - GLuint logotexture; - GLuint loadscreentexture; - GLuint Maparrowtexture; - GLuint Mapboxtexture; - GLuint Mapcircletexture; - GLuint cursortexture; - GLuint Mainmenuitems[10]; - - int nummenuitems; - int startx[100]; - int starty[100]; - int endx[100]; - int endy[100]; - float selectedlong[100]; - float offsetx[100]; - float offsety[100]; - float movex[100]; - float movey[100]; - float transition; - int anim; - int selected; - int loaddistrib; - int keyselect; - int indemo; - - bool won; - - bool entername; - - char menustring[100][256]; - char registrationname[256]; - float registrationnumber; - - int newdetail; - int newscreenwidth; - int newscreenheight; - - bool gameon; - float deltah,deltav; - int mousecoordh,mousecoordv; - int oldmousecoordh,oldmousecoordv; - float rotation,rotation2; - SkyBox skybox; - bool cameramode; - bool cameratogglekeydown; - bool chattogglekeydown; - int olddrawmode; - int drawmode; - bool drawmodetogglekeydown; - bool explodetogglekeydown; - bool detailtogglekeydown; - bool firstload; - bool oldbutton; - - float leveltime; - float loadtime; - - Model hawk; - XYZ hawkcoords; - XYZ realhawkcoords; - GLuint hawktexture; - float hawkrotation; - float hawkcalldelay; - - Model eye; - Model iris; - Model cornea; - - bool stealthloading; - - int campaignnumlevels; - char campaignmapname[50][256]; - char campaigndescription[50][256]; - int campaignchoosenext[50]; - int campaignnumnext[50]; - int campaignnextlevel[50][10]; - int campaignchoicesmade; - int campaignchoices[5000]; - int campaignlocationx[50]; - int campaignlocationy[50]; - int campaignchoicenum; - int campaignchoicewhich[10]; - int whichchoice; - - int numlevelspassed; - int levelorder[5000]; - int levelvisible[50]; - int levelhighlight[50]; - - bool minimap; - - int musictype,oldmusictype,oldoldmusictype; - bool realthreat; - - Model rabbit; - XYZ rabbitcoords; - - XYZ mapcenter; - float mapradius; - - Text text; - float fps; - - XYZ cameraloc; - float cameradist; - - bool envtogglekeydown; - bool slomotogglekeydown; - bool texturesizetogglekeydown; - bool freezetogglekeydown; - int drawtoggle; - - bool editorenabled; - int editortype; - float editorsize; - float editorrotation; - float editorrotation2; - - float brightness; - - int quit; - int tryquit; - - XYZ pathpoint[30]; - int numpathpoints; - int numpathpointconnect[30]; - int pathpointconnect[30][30]; - int pathpointselected; - - int endgame; - bool scoreadded; - int numchallengelevels; - - bool console; - int archiveselected; - char consoletext[15][256]; - int consolechars[15]; - bool chatting; - char displaytext[15][256]; - int displaychars[15]; - float displaytime[15]; - float displayblinkdelay; - bool displayblink; - int displayselected; - bool consolekeydown; - bool consoletogglekeydown; - float consoleblinkdelay; - bool consoleblink; - int consoleselected; - int togglekey[140]; - float togglekeydelay[140]; - bool registernow; - bool autocam; - - unsigned short crouchkey,jumpkey,forwardkey,chatkey,backkey,leftkey,rightkey,drawkey,throwkey,attackkey; - bool oldattackkey; - - long long MD5_string (char *string); - static void LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha); - static void LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize); - void LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize); - bool AddClothes(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize); - void InitGame(); - void LoadStuff(); - void LoadingScreen(); - void FadeLoadingScreen(float howmuch); - void Dispose(); - int DrawGLScene(StereoSide side); - void Tick(); - void TickOnce(); - void TickOnceAfter(); - void SetUpLighting(); - void Loadlevel(int which); - void Loadlevel(char *name); - void LoadSounds(); - void Setenvironment(int which); - GLvoid ReSizeGLScene(float fov, float near); - int findPathDist(int start,int end); - int checkcollide(XYZ startpoint, XYZ endpoint); - int checkcollide(XYZ startpoint, XYZ endpoint, int what); - int loading; - float talkdelay; - - int numboundaries; - XYZ boundary[360]; - - int whichlevel; - int oldenvironment; - int targetlevel; - float changedelay; - - float musicvolume[4]; - float oldmusicvolume[4]; - int musicselected; - int change; - Game(); - ~Game() { - for(int i=0;i<10;i++){ - if(Mainmenuitems[i])glDeleteTextures( 1, &Mainmenuitems[i] ); + public: + typedef std::map TextureList; + typedef std::map GLTextureList; + typedef TextureList::iterator TexIter; + static TextureList textures; + + GLuint terraintexture; + GLuint terraintexture2; + GLuint terraintexture3; + GLuint screentexture; + GLuint screentexture2; + GLuint logotexture; + GLuint loadscreentexture; + GLuint Maparrowtexture; + GLuint Mapboxtexture; + GLuint Mapcircletexture; + GLuint cursortexture; + GLuint Mainmenuitems[10]; + + int nummenuitems; + int startx[100]; + int starty[100]; + int endx[100]; + int endy[100]; + float selectedlong[100]; + float offsetx[100]; + float offsety[100]; + float movex[100]; + float movey[100]; + float transition; + int anim; + int selected; + int keyselect; + int loaddistrib; + int indemo; + + bool won; + + bool entername; + + char menustring[100][256]; + char registrationname[256]; + float registrationnumber; + + int newdetail; + int newscreenwidth; + int newscreenheight; + + bool gameon; + float deltah,deltav; + int mousecoordh,mousecoordv; + int oldmousecoordh,oldmousecoordv; + float rotation,rotation2; + SkyBox skybox; + bool cameramode; + bool cameratogglekeydown; + bool chattogglekeydown; + int olddrawmode; + int drawmode; + bool drawmodetogglekeydown; + bool explodetogglekeydown; + bool detailtogglekeydown; + bool firstload; + bool oldbutton; + + float leveltime; + float loadtime; + + Model hawk; + XYZ hawkcoords; + XYZ realhawkcoords; + GLuint hawktexture; + float hawkrotation; + float hawkcalldelay; + + Model eye; + Model iris; + Model cornea; + + bool stealthloading; + + int campaignnumlevels; + char campaignmapname[50][256]; + char campaigndescription[50][256]; + int campaignchoosenext[50]; + int campaignnumnext[50]; + int campaignnextlevel[50][10]; + int campaignchoicesmade; + int campaignchoices[5000]; + int campaignlocationx[50]; + int campaignlocationy[50]; + int campaignchoicenum; + int campaignchoicewhich[10]; + int whichchoice; + + int numlevelspassed; + int levelorder[5000]; + int levelvisible[50]; + int levelhighlight[50]; + + bool minimap; + + int musictype,oldmusictype,oldoldmusictype; + bool realthreat; + + Model rabbit; + XYZ rabbitcoords; + + XYZ mapcenter; + float mapradius; + + Text text; + float fps; + + XYZ cameraloc; + float cameradist; + + bool envtogglekeydown; + bool slomotogglekeydown; + bool texturesizetogglekeydown; + bool freezetogglekeydown; + int drawtoggle; + + bool editorenabled; + int editortype; + float editorsize; + float editorrotation; + float editorrotation2; + + float brightness; + + int quit; + int tryquit; + + XYZ pathpoint[30]; + int numpathpoints; + int numpathpointconnect[30]; + int pathpointconnect[30][30]; + int pathpointselected; + + int endgame; + bool scoreadded; + int numchallengelevels; + + bool console; + int archiveselected; + char consoletext[15][256]; + int consolechars[15]; + bool chatting; + char displaytext[15][256]; + int displaychars[15]; + float displaytime[15]; + float displayblinkdelay; + bool displayblink; + int displayselected; + bool consolekeydown; + bool consoletogglekeydown; + float consoleblinkdelay; + bool consoleblink; + int consoleselected; + //int togglekey[140]; + //float togglekeydelay[140]; + bool registernow; + bool autocam; + + unsigned short crouchkey,jumpkey,forwardkey,chatkey,backkey,leftkey,rightkey,drawkey,throwkey,attackkey; + bool oldattackkey; + + long long MD5_string (char *string); + static void LoadTexture(const char *fileName, GLuint *textureid,int mipmap, bool hasalpha); + static void LoadTextureSave(const char *fileName, GLuint *textureid,int mipmap,GLubyte *array, int *skinsize); + void LoadSave(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize); + bool AddClothes(const char *fileName, GLuint *textureid,bool mipmap,GLubyte *array, int *skinsize); + void InitGame(); + void LoadStuff(); + void LoadingScreen(); + void FadeLoadingScreen(float howmuch); + void Dispose(); + int DrawGLScene(StereoSide side); + void Tick(); + void TickOnce(); + void TickOnceAfter(); + void SetUpLighting(); + void Loadlevel(int which); + void Loadlevel(char *name); + void LoadSounds(); + void Setenvironment(int which); + GLvoid ReSizeGLScene(float fov, float near); + int findPathDist(int start,int end); + int checkcollide(XYZ startpoint, XYZ endpoint); + int checkcollide(XYZ startpoint, XYZ endpoint, int what); + int loading; + float talkdelay; + + void fireSound(int sound=fireendsound); + void setKeySelected(); + + int numboundaries; + XYZ boundary[360]; + + int whichlevel; + int oldenvironment; + int targetlevel; + float changedelay; + + float musicvolume[4]; + float oldmusicvolume[4]; + int musicselected; + int change; + Game(); + ~Game() { + for(int i=0;i<10;i++){ + if(Mainmenuitems[i])glDeleteTextures( 1, &Mainmenuitems[i] ); + } + glDeleteTextures( 1, &cursortexture ); + glDeleteTextures( 1, &Maparrowtexture ); + glDeleteTextures( 1, &Mapboxtexture ); + glDeleteTextures( 1, &Mapcircletexture ); + glDeleteTextures( 1, &terraintexture ); + glDeleteTextures( 1, &terraintexture2 ); + if(screentexture>0)glDeleteTextures( 1, &screentexture ); + if(screentexture2>0)glDeleteTextures( 1, &screentexture2 ); + glDeleteTextures( 1, &hawktexture ); + glDeleteTextures( 1, &logotexture ); + glDeleteTextures( 1, &loadscreentexture ); + + Dispose(); } - glDeleteTextures( 1, &cursortexture ); - glDeleteTextures( 1, &Maparrowtexture ); - glDeleteTextures( 1, &Mapboxtexture ); - glDeleteTextures( 1, &Mapcircletexture ); - glDeleteTextures( 1, &terraintexture ); - glDeleteTextures( 1, &terraintexture2 ); - if(screentexture>0)glDeleteTextures( 1, &screentexture ); - if(screentexture2>0)glDeleteTextures( 1, &screentexture2 ); - glDeleteTextures( 1, &hawktexture ); - glDeleteTextures( 1, &logotexture ); - glDeleteTextures( 1, &loadscreentexture ); - - Dispose(); - } - + bool isWaiting() { return waiting; }; + private: + void setKeySelected_thread(); + static int thread(void *data); + void inputText(char* str, int* charselected, int* nb_chars); + void flash(); + bool waiting; + bool mainmenutogglekeydown; + //int mainmenu; + Account* accountactive; }; #ifndef __forceinline diff --git a/Source/GameDraw.cpp b/Source/GameDraw.cpp index 288022d..97c2b66 100644 --- a/Source/GameDraw.cpp +++ b/Source/GameDraw.cpp @@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "Game.h" #include "openal_wrapper.h" +#include "Input.h" using namespace std; @@ -72,7 +73,6 @@ extern bool midweird; extern bool proportionweird; extern bool vertexweird[6]; extern bool velocityblur; -extern bool buttons[3]; extern bool debugmode; extern int mainmenu; extern int oldmainmenu; @@ -163,6 +163,13 @@ extern OPENAL_SAMPLE *samp[100]; extern int channels[100]; extern "C" void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused); +void Game::flash() { // shouldn't be that way, these should be attributes and Person class should not change rendering. + flashr=1; + flashg=0; + flashb=0; + flashamount=1; + flashdelay=1; +} /*********************> DrawGLScene() <*****/ long long Game::MD5_string (char *string){ char temp[256]=""; @@ -711,22 +718,22 @@ int Game::DrawGLScene(StereoSide side) sprintf (string3, " "); } if(tutorialstage==4){ - sprintf (string, "Try using the %s, %s, %s and %s keys to move around.",KeyToChar(forwardkey),KeyToChar(leftkey),KeyToChar(backkey),KeyToChar(rightkey)); + sprintf (string, "Try using the %s, %s, %s and %s keys to move around.",Input::keyToChar(forwardkey),Input::keyToChar(leftkey),Input::keyToChar(backkey),Input::keyToChar(rightkey)); sprintf (string2, "All movement is relative to the camera."); sprintf (string3, " "); } if(tutorialstage==5){ - sprintf (string, "Please press %s to jump.",KeyToChar(jumpkey)); + sprintf (string, "Please press %s to jump.",Input::keyToChar(jumpkey)); sprintf (string2, "You can hold it longer to jump higher."); sprintf (string3, " "); } if(tutorialstage==6){ - sprintf (string, "You can press %s to crouch.",KeyToChar(crouchkey)); + sprintf (string, "You can press %s to crouch.",Input::keyToChar(crouchkey)); sprintf (string2, "You can jump higher from a crouching position."); sprintf (string3, " "); } if(tutorialstage==7){ - sprintf (string, "While running, you can press %s to roll.",KeyToChar(crouchkey)); + sprintf (string, "While running, you can press %s to roll.",Input::keyToChar(crouchkey)); sprintf (string2, " "); sprintf (string3, " "); } @@ -746,12 +753,12 @@ int Game::DrawGLScene(StereoSide side) sprintf (string3, " "); } if(tutorialstage==11){ - sprintf (string, "When you jump at a wall, you can hold %s again",KeyToChar(jumpkey)); + sprintf (string, "When you jump at a wall, you can hold %s again",Input::keyToChar(jumpkey)); sprintf (string2, "during impact to perform a walljump."); sprintf (string3, "Be sure to use the movement keys to press against the wall"); } if(tutorialstage==12){ - sprintf (string, "While in the air, you can press crouch to flip.",KeyToChar(jumpkey)); + sprintf (string, "While in the air, you can press crouch to flip.",Input::keyToChar(jumpkey)); sprintf (string2, "Walljumps and flips confuse enemies and give you more control."); sprintf (string3, " "); } @@ -766,8 +773,8 @@ int Game::DrawGLScene(StereoSide side) sprintf (string3, " "); } if(tutorialstage==15){ - if(attackkey==MAC_MOUSEBUTTON1)sprintf (string, "Click to attack when you are near an enemy."); - else sprintf (string, "Press %s to attack when you are near an enemy.",KeyToChar(attackkey)); + if(attackkey==MOUSEBUTTON1)sprintf (string, "Click to attack when you are near an enemy."); + else sprintf (string, "Press %s to attack when you are near an enemy.",Input::keyToChar(attackkey)); sprintf (string2, "You can punch by standing still near an enemy and attacking."); sprintf (string3, " "); } @@ -793,9 +800,9 @@ int Game::DrawGLScene(StereoSide side) } if(tutorialstage==20){ sprintf (string, "Your most powerful individual attack is the rabbit kick."); - if(attackkey==MAC_MOUSEBUTTON1)sprintf (string2, "Run at the enemy while holding the mouse button, and press"); - else sprintf (string2, "Run at the enemy while holding %s, and press", KeyToChar(attackkey)); - sprintf (string3, "the jump key (%s) to attack.",KeyToChar(jumpkey)); + if(attackkey==MOUSEBUTTON1)sprintf (string2, "Run at the enemy while holding the mouse button, and press"); + else sprintf (string2, "Run at the enemy while holding %s, and press", Input::keyToChar(attackkey)); + sprintf (string3, "the jump key (%s) to attack.",Input::keyToChar(jumpkey)); } if(tutorialstage==21){ sprintf (string, "This attack is devastating if timed correctly."); @@ -815,8 +822,8 @@ int Game::DrawGLScene(StereoSide side) } if(tutorialstage==24){ sprintf (string, "You can tackle enemies by running at them animal-style"); - if(attackkey==MAC_MOUSEBUTTON1)sprintf (string2, "and pressing jump (%s) or attack(mouse button).",KeyToChar(jumpkey)); - else sprintf (string2, "and pressing jump (%s) or attack(%s).",KeyToChar(jumpkey),KeyToChar(attackkey)); + if(attackkey==MOUSEBUTTON1)sprintf (string2, "and pressing jump (%s) or attack(mouse button).",Input::keyToChar(jumpkey)); + else sprintf (string2, "and pressing jump (%s) or attack(%s).",Input::keyToChar(jumpkey),Input::keyToChar(attackkey)); sprintf (string3, "This is especially useful when they are running away."); } if(tutorialstage==25){ @@ -837,7 +844,7 @@ int Game::DrawGLScene(StereoSide side) if(tutorialstage==28){ sprintf (string, "If you attack, you will notice that the enemy now sometimes"); sprintf (string2, "catches your attack and uses it against you. Hold"); - sprintf (string3, "crouch (%s) after attacking to escape from reversals.",KeyToChar(crouchkey)); + sprintf (string3, "crouch (%s) after attacking to escape from reversals.",Input::keyToChar(crouchkey)); } if(tutorialstage==29){ sprintf (string, "Try escaping from two more reversals in a row."); @@ -850,7 +857,7 @@ int Game::DrawGLScene(StereoSide side) sprintf (string3, " "); } if(tutorialstage==31){ - sprintf (string, "To reverse an attack, you must tap crouch (%s) during the",KeyToChar(crouchkey)); + sprintf (string, "To reverse an attack, you must tap crouch (%s) during the",Input::keyToChar(crouchkey)); sprintf (string2, "enemy's attack. You must also be close to the enemy;"); sprintf (string3, "this is especially important against armed opponents."); } @@ -896,11 +903,11 @@ int Game::DrawGLScene(StereoSide side) } if(tutorialstage==40){ sprintf (string, "Stand, roll or handspring over the knife"); - sprintf (string2, "while pressing %s to pick it up.",KeyToChar(throwkey)); + sprintf (string2, "while pressing %s to pick it up.",Input::keyToChar(throwkey)); sprintf (string3, "You can crouch and press the same key to drop it again."); } if(tutorialstage==41){ - sprintf (string, "You can equip and unequip weapons using the %s key.",KeyToChar(drawkey)); + sprintf (string, "You can equip and unequip weapons using the %s key.",Input::keyToChar(drawkey)); sprintf (string2, "Sometimes it is best to keep them unequipped to"); sprintf (string3, "prevent enemies from taking them. "); } @@ -940,7 +947,7 @@ int Game::DrawGLScene(StereoSide side) sprintf (string3, "spin smash is slower and more powerful."); } if(tutorialstage==49){ - sprintf (string, "When facing an enemy, you can throw the knife with %s.",KeyToChar(throwkey)); + sprintf (string, "When facing an enemy, you can throw the knife with %s.",Input::keyToChar(throwkey)); sprintf (string2, "It is possible to throw the knife while flipping,"); sprintf (string3, "but it is very inaccurate."); } @@ -964,7 +971,7 @@ int Game::DrawGLScene(StereoSide side) text.glPrint(screenwidth/2-7.6*strlen(string2)*screenwidth/1024,screenheight/16+screenheight*4/5-20*screenwidth/1024,string2,1,1.5*screenwidth/1024,screenwidth,screenheight); text.glPrint(screenwidth/2-7.6*strlen(string3)*screenwidth/1024,screenheight/16+screenheight*4/5-40*screenwidth/1024,string3,1,1.5*screenwidth/1024,screenwidth,screenheight); - sprintf (string, "Press 'tab' to skip to the next item.",KeyToChar(jumpkey)); + sprintf (string, "Press 'tab' to skip to the next item.",Input::keyToChar(jumpkey)); sprintf (string2, "Press escape at any time to"); sprintf (string3, "pause or exit the tutorial."); @@ -2608,7 +2615,7 @@ int Game::DrawGLScene(StereoSide side) if(mainmenu==4){ nummenuitems=10; - if(keyselect!=0)sprintf (menustring[0], "Forwards: %s",KeyToChar(forwardkey)); + if(keyselect!=0)sprintf (menustring[0], "Forwards: %s",Input::keyToChar(forwardkey)); else sprintf (menustring[0], "Forwards: _"); startx[0]=10; starty[0]=400; @@ -2617,7 +2624,7 @@ int Game::DrawGLScene(StereoSide side) movex[0]=0; movey[0]=0; - if(keyselect!=1)sprintf (menustring[1], "Back: %s",KeyToChar(backkey)); + if(keyselect!=1)sprintf (menustring[1], "Back: %s",Input::keyToChar(backkey)); else sprintf (menustring[1], "Back: _"); startx[1]=10+40; starty[1]=360; @@ -2626,7 +2633,7 @@ int Game::DrawGLScene(StereoSide side) movex[1]=0; movey[1]=0; - if(keyselect!=2)sprintf (menustring[2], "Left: %s",KeyToChar(leftkey)); + if(keyselect!=2)sprintf (menustring[2], "Left: %s",Input::keyToChar(leftkey)); else sprintf (menustring[2], "Left: _"); startx[2]=10+40; starty[2]=320; @@ -2635,7 +2642,7 @@ int Game::DrawGLScene(StereoSide side) movex[2]=0; movey[2]=0; - if(keyselect!=3)sprintf (menustring[3], "Right: %s",KeyToChar(rightkey)); + if(keyselect!=3)sprintf (menustring[3], "Right: %s",Input::keyToChar(rightkey)); else sprintf (menustring[3], "Right: _"); startx[3]=10+30; starty[3]=280; @@ -2644,7 +2651,7 @@ int Game::DrawGLScene(StereoSide side) movex[3]=0; movey[3]=0; - if(keyselect!=4)sprintf (menustring[4], "Crouch: %s",KeyToChar(crouchkey)); + if(keyselect!=4)sprintf (menustring[4], "Crouch: %s",Input::keyToChar(crouchkey)); else sprintf (menustring[4], "Crouch: _"); startx[4]=10+20; starty[4]=240; @@ -2653,7 +2660,7 @@ int Game::DrawGLScene(StereoSide side) movex[4]=0; movey[4]=0; - if(keyselect!=5)sprintf (menustring[5], "Jump: %s",KeyToChar(jumpkey)); + if(keyselect!=5)sprintf (menustring[5], "Jump: %s",Input::keyToChar(jumpkey)); else sprintf (menustring[5], "Jump: _"); startx[5]=10+40; starty[5]=200; @@ -2662,7 +2669,7 @@ int Game::DrawGLScene(StereoSide side) movex[5]=0; movey[5]=0; - if(keyselect!=6)sprintf (menustring[6], "Draw: %s",KeyToChar(drawkey)); + if(keyselect!=6)sprintf (menustring[6], "Draw: %s",Input::keyToChar(drawkey)); else sprintf (menustring[6], "Draw: _"); startx[6]=10+40; starty[6]=160; @@ -2671,7 +2678,7 @@ int Game::DrawGLScene(StereoSide side) movex[6]=0; movey[6]=0; - if(keyselect!=7)sprintf (menustring[7], "Throw: %s",KeyToChar(throwkey)); + if(keyselect!=7)sprintf (menustring[7], "Throw: %s",Input::keyToChar(throwkey)); else sprintf (menustring[7], "Throw: _"); startx[7]=10+30; starty[7]=120; @@ -2680,7 +2687,7 @@ int Game::DrawGLScene(StereoSide side) movex[7]=0; movey[7]=0; - if(keyselect!=8)sprintf (menustring[8], "Attack: %s",KeyToChar(attackkey)); + if(keyselect!=8)sprintf (menustring[8], "Attack: %s",Input::keyToChar(attackkey)); else sprintf (menustring[8], "Attack: _"); startx[8]=10+20; starty[8]=80; @@ -3822,27 +3829,29 @@ int Game::DrawGLScene(StereoSide side) glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP ); glPopMatrix(); - glPushMatrix(); - glTranslatef(mousecoordh-screenwidth/2,mousecoordv*-1+screenheight/2,0); - glScalef((float)screenwidth/64,(float)screenwidth/64,1); - glTranslatef(1,-1,0); - glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); - glColor4f(1,1,1,1); - glBindTexture( GL_TEXTURE_2D, cursortexture); + if(!waiting) { // hide the cursor while waiting for a key glPushMatrix(); - //glScalef(.25,.25,.25); - glBegin(GL_QUADS); - glTexCoord2f(0,0); - glVertex3f(-1, -1, 0.0f); - glTexCoord2f(1,0); - glVertex3f(1, -1, 0.0f); - glTexCoord2f(1,1); - glVertex3f(1, 1, 0.0f); - glTexCoord2f(0,1); - glVertex3f(-1, 1, 0.0f); - glEnd(); + glTranslatef(mousecoordh-screenwidth/2,mousecoordv*-1+screenheight/2,0); + glScalef((float)screenwidth/64,(float)screenwidth/64,1); + glTranslatef(1,-1,0); + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + glColor4f(1,1,1,1); + glBindTexture( GL_TEXTURE_2D, cursortexture); + glPushMatrix(); + //glScalef(.25,.25,.25); + glBegin(GL_QUADS); + glTexCoord2f(0,0); + glVertex3f(-1, -1, 0.0f); + glTexCoord2f(1,0); + glVertex3f(1, -1, 0.0f); + glTexCoord2f(1,1); + glVertex3f(1, 1, 0.0f); + glTexCoord2f(0,1); + glVertex3f(-1, 1, 0.0f); + glEnd(); + glPopMatrix(); glPopMatrix(); - glPopMatrix(); + } glPopMatrix(); glMatrixMode(GL_PROJECTION); // Select The Projection Matrix glPopMatrix(); diff --git a/Source/GameInitDispose.cpp b/Source/GameInitDispose.cpp index 402c761..ea0d736 100644 --- a/Source/GameInitDispose.cpp +++ b/Source/GameInitDispose.cpp @@ -1688,200 +1688,3 @@ void Game::LoadStuff() visibleloading=0; } -Game::Game() -{ - terraintexture = 0; - terraintexture2 = 0; - terraintexture3 = 0; - screentexture = 0; - screentexture2 = 0; - logotexture = 0; - loadscreentexture = 0; - Maparrowtexture = 0; - Mapboxtexture = 0; - Mapcircletexture = 0; - cursortexture = 0; - - memset(Mainmenuitems, 0, sizeof(Mainmenuitems)); - - nummenuitems = 0; - - memset(startx, 0, sizeof(startx)); - memset(starty, 0, sizeof(starty)); - memset(endx, 0, sizeof(endx)); - memset(endy, 0, sizeof(endy)); - - memset(selectedlong, 0, sizeof(selectedlong)); - memset(offsetx, 0, sizeof(offsetx)); - memset(offsety, 0, sizeof(offsety)); - memset(movex, 0, sizeof(movex)); - memset(movey, 0, sizeof(movey)); - memset(endy, 0, sizeof(endy)); - - transition = 0; - anim = 0; - selected = 0; - loaddistrib = 0; - keyselect = 0; - indemo = 0; - - won = 0; - - entername = 0; - - memset(menustring, 0, sizeof(menustring)); - memset(registrationname, 0, sizeof(registrationname)); - registrationnumber = 0; - - newdetail = 0; - newscreenwidth = 0; - newscreenheight = 0; - - gameon = 0; - deltah = 0,deltav = 0; - mousecoordh = 0,mousecoordv = 0; - oldmousecoordh = 0,oldmousecoordv = 0; - rotation = 0,rotation2 = 0; - -// SkyBox skybox; - - cameramode = 0; - cameratogglekeydown = 0; - chattogglekeydown = 0; - olddrawmode = 0; - drawmode = 0; - drawmodetogglekeydown = 0; - explodetogglekeydown = 0; - detailtogglekeydown = 0; - firstload = 0; - oldbutton = 0; - - leveltime = 0; - loadtime = 0; - -// Model hawk; - -// XYZ hawkcoords; -// XYZ realhawkcoords; - - hawktexture = 0; - hawkrotation = 0; - hawkcalldelay = 0; -/* - Model eye; - Model iris; - Model cornea; -*/ - stealthloading = 0; - - campaignnumlevels = 0; - - memset(campaignmapname, 0, sizeof(campaignmapname)); - memset(campaigndescription, 0, sizeof(campaigndescription)); - memset(campaignchoosenext, 0, sizeof(campaignchoosenext)); - memset(campaignnumnext, 0, sizeof(campaignnumnext)); - memset(campaignnextlevel, 0, sizeof(campaignnextlevel)); - int campaignchoicesmade; - memset(campaignchoices, 0, sizeof(campaignchoices)); - memset(campaignlocationx, 0, sizeof(campaignlocationx)); - memset(campaignlocationy, 0, sizeof(campaignlocationy)); - memset(campaignlocationy, 0, sizeof(campaignlocationy)); - - campaignchoicenum = 0; - - memset(campaignchoicewhich, 0, sizeof(campaignchoicewhich)); - - whichchoice = 0; - - numlevelspassed = 0; - - memset(levelorder, 0, sizeof(levelorder)); - memset(levelvisible, 0, sizeof(levelvisible)); - memset(levelhighlight, 0, sizeof(levelhighlight)); - - minimap = 0; - - musictype = 0,oldmusictype = 0,oldoldmusictype = 0; - realthreat = 0; - -// Model rabbit; -// XYZ rabbitcoords; - -// XYZ mapcenter; - mapradius = 0; - -// Text text; - fps = 0; - -// XYZ cameraloc; - cameradist = 0; - - envtogglekeydown = 0; - slomotogglekeydown = 0; - texturesizetogglekeydown = 0; - freezetogglekeydown = 0; - drawtoggle = 0; - - editorenabled = 0; - editortype = 0; - editorsize = 0; - editorrotation = 0; - editorrotation2 = 0; - - brightness = 0; - - quit = 0; - tryquit = 0; - -// XYZ pathpoint[30]; - numpathpoints = 0; - memset(numpathpointconnect, 0, sizeof(numpathpointconnect)); - memset(pathpointconnect, 0, sizeof(pathpointconnect)); - pathpointselected = 0; - - endgame = 0; - scoreadded = 0; - numchallengelevels = 0; - - console = 0; - archiveselected = 0; - - memset(consoletext, 0, sizeof(consoletext)); - memset(consolechars, 0, sizeof(consolechars)); - chatting = 0; - memset(displaytext, 0, sizeof(displaytext)); - memset(displaychars, 0, sizeof(displaychars)); - memset(displaytime, 0, sizeof(displaytime)); - displayblinkdelay = 0; - displayblink = 0; - displayselected = 0; - consolekeydown = 0; - consoletogglekeydown = 0; - consoleblinkdelay = 0; - consoleblink = 0; - consoleselected = 0; - memset(togglekey, 0, sizeof(togglekey)); - memset(togglekeydelay, 0, sizeof(togglekeydelay)); - registernow = 0; - autocam = 0; - - crouchkey = 0,jumpkey = 0,forwardkey = 0,chatkey = 0,backkey = 0,leftkey = 0,rightkey = 0,drawkey = 0,throwkey = 0,attackkey = 0; - oldattackkey = 0; - - loading = 0; - talkdelay = 0; - - numboundaries = 0; -// XYZ boundary[360]; - - whichlevel = 0; - oldenvironment = 0; - targetlevel = 0; - changedelay = 0; - - memset(musicvolume, 0, sizeof(musicvolume)); - memset(oldmusicvolume, 0, sizeof(oldmusicvolume)); - musicselected = 0; - change = 0; -} - diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index 3115b43..b3114ed 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -31,6 +31,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "Game.h" #include "openal_wrapper.h" #include "Settings.h" +#include "Input.h" using namespace std; @@ -89,7 +90,6 @@ extern int netdatanew; extern bool loadingstuff; extern char mapname[256]; extern XYZ windvector; -extern bool buttons[3]; extern bool debugmode; static int music1; extern int mainmenu; @@ -149,7 +149,6 @@ extern float damagetaken; extern int maptype; extern int editoractive; extern int editorpathtype; -extern bool oldbuttons[3]; extern float hostiletime; @@ -2383,16 +2382,10 @@ void Game::Tick() displaytime[i]+=multiplier; } - static unsigned char theKeyMap[16]; - GetKeys( theKeyMap ); - keyboardfrozen=0; - - static bool mainmenutogglekeydown; - - if (IsKeyDown(theKeyMap, MAC_F6_KEY) && !freezetogglekeydown) { - if (IsKeyDown(theKeyMap, MAC_SHIFT_KEY)) { + if (Input::isKeyDown(SDLK_F6) && !freezetogglekeydown) { + if (Input::isKeyDown(SDLK_LSHIFT)) { stereoreverse=true; } else { stereoreverse=false; @@ -2406,8 +2399,8 @@ void Game::Tick() freezetogglekeydown=1; } - if (IsKeyDown(theKeyMap, MAC_F7_KEY)) { - if (IsKeyDown(theKeyMap, MAC_SHIFT_KEY)) { + if (Input::isKeyDown(SDLK_F7)) { + if (Input::isKeyDown(SDLK_LSHIFT)) { stereoseparation -= 0.001; } else { stereoseparation -= 0.010; @@ -2416,8 +2409,8 @@ void Game::Tick() printf("Stereo decreased increased to %f\n", stereoseparation); } - if (IsKeyDown(theKeyMap, MAC_F8_KEY)) { - if (IsKeyDown(theKeyMap, MAC_SHIFT_KEY)) { + if (Input::isKeyDown(SDLK_F8)) { + if (Input::isKeyDown(SDLK_LSHIFT)) { stereoseparation += 0.001; } else { stereoseparation += 0.010; @@ -2429,16 +2422,10 @@ void Game::Tick() if(!console){ if(mainmenu&&endgame==1)mainmenu=10; - if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)&&!mainmenutogglekeydown&&(mainmenu==7&&entername)){ - for(j=0;j<255;j++){ - displaytext[0][j]=' '; - } - displaychars[0]=0; - displayselected=0; - entername=0; - mainmenutogglekeydown=1; - } - if((IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)||(mainmenu==0&&((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY)||(campaign)))&&!oldjumpkeydown&&campaign&&winfreeze))&&!mainmenutogglekeydown&&(!mainmenu||gameon||mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||(mainmenu==7&&!entername)||mainmenu==9||mainmenu==11||mainmenu==13||mainmenu==17||mainmenu==10)){ + if( (Input::isKeyDown(SDLK_ESCAPE)||(mainmenu==0&&((Input::isKeyDown(jumpkey)||Input::isKeyDown(SDLK_SPACE)||(campaign)))&&!oldjumpkeydown&&campaign&&winfreeze)) + && !mainmenutogglekeydown + && (!mainmenu||gameon||mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||(mainmenu==7&&!entername)||mainmenu==9||mainmenu==11||mainmenu==13||mainmenu==17||mainmenu==10) + ) { // go back selected=-1; if(mainmenu==1||mainmenu==2||mainmenu==0){ if(mainmenu==0&&!winfreeze)mainmenu=2; @@ -2462,20 +2449,9 @@ void Game::Tick() } } if(mainmenu==3){ - float gLoc[3]={0,0,0}; - float vel[3]={0,0,0}; - OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); - PlaySoundEx( fireendsound, samp[fireendsound], NULL, true); - OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel); - OPENAL_SetVolume(channels[fireendsound], 256); - OPENAL_SetPaused(channels[fireendsound], false); - OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f); - - flashr=1; - flashg=0; - flashb=0; - flashamount=1; - flashdelay=1; + fireSound(); + + flash(); if(newdetail>2)newdetail=detail; if(newdetail<0)newdetail=detail; @@ -2485,20 +2461,9 @@ void Game::Tick() SaveSettings(*this); } if(mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==9||mainmenu==13||mainmenu==10||mainmenu==11||mainmenu==100){ - float gLoc[3]={0,0,0}; - float vel[3]={0,0,0}; - OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); - PlaySoundEx( fireendsound, samp[fireendsound], NULL, true); - OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel); - OPENAL_SetVolume(channels[fireendsound], 256); - OPENAL_SetPaused(channels[fireendsound], false); - OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f); - - flashr=1; - flashg=0; - flashb=0; - flashamount=1; - flashdelay=1; + fireSound(); + + flash(); } if(mainmenu==3&&gameon)mainmenu=2; if(mainmenu==3&&!gameon)mainmenu=1; @@ -2658,25 +2623,25 @@ void Game::Tick() } - if(Button()&&!oldbutton&&selected==1){ + if(Input::Button()&&!oldbutton&&selected==1){ newdetail++; if(newdetail>2)newdetail=0; } - if(Button()&&!oldbutton&&selected==2){ + if(Input::Button()&&!oldbutton&&selected==2){ bloodtoggle++; if(bloodtoggle>2)bloodtoggle=0; } - if(Button()&&!oldbutton&&selected==3){ + if(Input::Button()&&!oldbutton&&selected==3){ difficulty++; if(difficulty>2)difficulty=0; } - if(Button()&&!oldbutton&&selected==4){ + if(Input::Button()&&!oldbutton&&selected==4){ ismotionblur=1-ismotionblur; } - if(Button()&&!oldbutton&&selected==5){ + if(Input::Button()&&!oldbutton&&selected==5){ decals=1-decals; } - if(Button()&&!oldbutton&&selected==6){ + if(Input::Button()&&!oldbutton&&selected==6){ musictoggle=1-musictoggle; if(!musictoggle){ @@ -2696,68 +2661,43 @@ void Game::Tick() OPENAL_SetVolume(channels[stream_music3], 256); } } - if(Button()&&!oldbutton&&selected==9){ + if(Input::Button()&&!oldbutton&&selected==9){ invertmouse=1-invertmouse; } - if(Button()&&!oldbutton&&selected==10){ + if(Input::Button()&&!oldbutton&&selected==10){ usermousesensitivity+=.2; if(usermousesensitivity>2)usermousesensitivity=.2; } - if(Button()&&!oldbutton&&selected==11){ + if(Input::Button()&&!oldbutton&&selected==11){ volume+=.1f; if(volume>1.0001f)volume=0; OPENAL_SetSFXMasterVolume((int)(volume*255)); } - if(Button()&&!oldbutton&&selected==7){ - /*float gLoc[3]={0,0,0}; - float vel[3]={0,0,0}; - OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f); - PlaySoundEx( firestartsound, samp[firestartsound], NULL, true); - OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel); - OPENAL_SetVolume(channels[firestartsound], 256); - OPENAL_SetPaused(channels[firestartsound], false); - OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f); + if(Input::Button()&&!oldbutton&&selected==7){ + /*fireSound(); */ - flashr=1; - flashg=0; - flashb=0; - flashamount=1; - flashdelay=1; + flash(); //options mainmenu=4; + selected=-1; keyselect=-1; } - if(Button() && !oldbutton && selected == 12) { - flashr=1; - flashg=0; - flashb=0; - flashamount=1; - flashdelay=1; + if(Input::Button() && !oldbutton && selected == 12) { + flash(); newstereomode = stereomode; mainmenu=18; - keyselect = -1; + keyselect=-1; } - if(Button() && !oldbutton && selected == 13) { + if(Input::Button() && !oldbutton && selected == 13) { showdamagebar=!showdamagebar; } - if(Button()&&!oldbutton&&selected==8){ - float gLoc[3]={0,0,0}; - float vel[3]={0,0,0}; - OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); - PlaySoundEx( fireendsound, samp[fireendsound], NULL, true); - OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel); - OPENAL_SetVolume(channels[fireendsound], 256); - OPENAL_SetPaused(channels[fireendsound], false); - OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f); - - flashr=1; - flashg=0; - flashb=0; - flashamount=1; - flashdelay=1; + if(Input::Button()&&!oldbutton&&selected==8){ + fireSound(); + + flash(); if(newdetail>2)newdetail=detail; if(newdetail<0)newdetail=detail; @@ -2769,85 +2709,26 @@ void Game::Tick() if(mainmenu==3&&gameon)mainmenu=2; if(mainmenu==3&&!gameon)mainmenu=1; } - if(Button())oldbutton=1; - else oldbutton=0; } if(mainmenu==4){ - if(Button()&&!oldbutton&&selected!=-1&&keyselect==-1){ - float gLoc[3]={0,0,0}; - float vel[3]={0,0,0}; - OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f); - PlaySoundEx( firestartsound, samp[firestartsound], NULL, true); - OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel); - OPENAL_SetVolume(channels[firestartsound], 256); - OPENAL_SetPaused(channels[firestartsound], false); - OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f); - } - if(Button()&&!oldbutton&&selected<9&&keyselect==-1){ - keyselect=selected; - oldbuttons[0]=1; - oldbuttons[1]=1; - oldbuttons[2]=1; - } - if(keyselect!=-1){ - for(i=0;i<3;i++) - if(!buttons[i]&&!oldbutton&&!Button())oldbuttons[i]=0; - for(i=0;i<140;i++){ - if((IsKeyDown(theKeyMap, i)||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))&&keyselect!=-1){ - if(i!=MAC_ESCAPE_KEY&&(strcmp(KeyToChar(i),"unknown")||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))){ - float gLoc[3]={0,0,0}; - float vel[3]={0,0,0}; - OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); - PlaySoundEx( fireendsound, samp[fireendsound], NULL, true); - OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel); - OPENAL_SetVolume(channels[fireendsound], 256); - OPENAL_SetPaused(channels[fireendsound], false); - OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f); - - int keynum; - keynum=i; - if(buttons[0]&&!oldbuttons[0])keynum=MAC_MOUSEBUTTON1; - if(buttons[1]&&!oldbuttons[1])keynum=MAC_MOUSEBUTTON2; - - - - if(keyselect==0)forwardkey=keynum; - if(keyselect==1)backkey=keynum; - if(keyselect==2)leftkey=keynum; - if(keyselect==3)rightkey=keynum; - if(keyselect==4)crouchkey=keynum; - if(keyselect==5)jumpkey=keynum; - if(keyselect==6)drawkey=keynum; - if(keyselect==7)throwkey=keynum; - if(keyselect==8)attackkey=keynum; - keyselect=-1; - } - } - }} - if(Button()&&!oldbutton&&selected==9){ - float gLoc[3]={0,0,0}; - float vel[3]={0,0,0}; - OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); - PlaySoundEx( fireendsound, samp[fireendsound], NULL, true); - OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel); - OPENAL_SetVolume(channels[fireendsound], 256); - OPENAL_SetPaused(channels[fireendsound], false); - OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f); - - flashr=1; - flashg=0; - flashb=0; - flashamount=1; - flashdelay=1; + if(Input::Button()&&!oldbutton&&selected!=-1&&!waiting){ + fireSound(); + if(selected<9&&keyselect==-1) + keyselect=selected; + if(keyselect!=-1) + setKeySelected(); + if(selected==9){ + flash(); - mainmenu=3; + mainmenu=3; - if(newdetail>2)newdetail=detail; - if(newdetail<0)newdetail=detail; - if(newscreenwidth>3000)newscreenwidth=screenwidth; - if(newscreenwidth<0)newscreenwidth=screenwidth; - if(newscreenheight>3000)newscreenheight=screenheight; - if(newscreenheight<0)newscreenheight=screenheight; + if(newdetail>2)newdetail=detail; + if(newdetail<0)newdetail=detail; + if(newscreenwidth>3000)newscreenwidth=screenwidth; + if(newscreenwidth<0)newscreenwidth=screenwidth; + if(newscreenheight>3000)newscreenheight=screenheight; + if(newscreenheight<0)newscreenheight=screenheight; + } } } @@ -2858,21 +2739,10 @@ void Game::Tick() endgame=0; } - if(Button()&&!oldbutton&&selected==1){ - float gLoc[3]={0,0,0}; - float vel[3]={0,0,0}; - OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f); - PlaySoundEx( firestartsound, samp[firestartsound], NULL, true); - OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel); - OPENAL_SetVolume(channels[firestartsound], 256); - OPENAL_SetPaused(channels[firestartsound], false); - OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f); - - flashr=1; - flashg=0; - flashb=0; - flashamount=1; - flashdelay=1; + if(Input::Button()&&!oldbutton&&selected==1){ + fireSound(); + + flash(); startbonustotal=0; @@ -2889,21 +2759,10 @@ void Game::Tick() gameon=1; OPENAL_SetPaused(channels[stream_music3], true); } - if(Button()&&!oldbutton&&selected-7>=accountcampaignchoicesmade[accountactive]){//selected>=7&&(selected-7<=campaignnumchoices)){ - float gLoc[3]={0,0,0}; - float vel[3]={0,0,0}; - OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f); - PlaySoundEx( firestartsound, samp[firestartsound], NULL, true); - OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel); - OPENAL_SetVolume(channels[firestartsound], 256); - OPENAL_SetPaused(channels[firestartsound], false); - OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f); - - flashr=1; - flashg=0; - flashb=0; - flashamount=1; - flashdelay=1; + if(Input::Button()&&!oldbutton&&(selected-7>=accountactive->getCampaignChoicesMade())){//selected>=7&&(selected-7<=campaignnumchoices)){ + fireSound(); + + flash(); startbonustotal=0; @@ -2937,98 +2796,41 @@ void Game::Tick() gameon=1; OPENAL_SetPaused(channels[stream_music3], true); } - if(Button()&&!oldbutton&&selected==4){ - float gLoc[3]={0,0,0}; - float vel[3]={0,0,0}; - OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); - PlaySoundEx( fireendsound, samp[fireendsound], NULL, true); - OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel); - OPENAL_SetVolume(channels[fireendsound], 256); - OPENAL_SetPaused(channels[fireendsound], false); - OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f); - - flashr=1; - flashg=0; - flashb=0; - flashamount=1; - flashdelay=1; + if(Input::Button()&&!oldbutton&&selected==4){ + fireSound(); + + flash(); if(mainmenu==5&&gameon)mainmenu=2; if(mainmenu==5&&!gameon)mainmenu=1; } - if(Button()&&!oldbutton&&selected==5){ - float gLoc[3]={0,0,0}; - float vel[3]={0,0,0}; - OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); - PlaySoundEx( fireendsound, samp[fireendsound], NULL, true); - OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel); - OPENAL_SetVolume(channels[fireendsound], 256); - OPENAL_SetPaused(channels[fireendsound], false); - OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f); - - flashr=1; - flashg=0; - flashb=0; - flashamount=1; - flashdelay=1; + if(Input::Button()&&!oldbutton&&selected==5){ + fireSound(); + + flash(); mainmenu=7; } - if(Button()&&!oldbutton&&selected==3){ - float gLoc[3]={0,0,0}; - float vel[3]={0,0,0}; - OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f); - PlaySoundEx( firestartsound, samp[firestartsound], NULL, true); - OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel); - OPENAL_SetVolume(channels[firestartsound], 256); - OPENAL_SetPaused(channels[firestartsound], false); - OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f); - - flashr=1; - flashg=0; - flashb=0; - flashamount=1; - flashdelay=1; + if(Input::Button()&&!oldbutton&&selected==3){ + fireSound(); + + flash(); mainmenu=6; } - if(Button()&&!oldbutton&&selected==2){ - float gLoc[3]={0,0,0}; - float vel[3]={0,0,0}; - OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f); - PlaySoundEx( firestartsound, samp[firestartsound], NULL, true); - OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel); - OPENAL_SetVolume(channels[firestartsound], 256); - OPENAL_SetPaused(channels[firestartsound], false); - OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f); - - flashr=1; - flashg=0; - flashb=0; - flashamount=1; - flashdelay=1; + if(Input::Button()&&!oldbutton&&selected==2){ + fireSound(); + + flash(); mainmenu=9; } - if(Button())oldbutton=1; - else oldbutton=0; } if(mainmenu==9){ - if(Button()&&!oldbutton&&selected=0&&selected<=accountprogress[accountactive]){ - float gLoc[3]={0,0,0}; - float vel[3]={0,0,0}; - OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f); - PlaySoundEx( firestartsound, samp[firestartsound], NULL, true); - OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel); - OPENAL_SetVolume(channels[firestartsound], 256); - OPENAL_SetPaused(channels[firestartsound], false); - OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f); - - flashr=1; - flashg=0; - flashb=0; - flashamount=1; - flashdelay=1; + if(Input::Button()&&!oldbutton&&selected=0&&selected<=accountactive->getProgress()){ + fireSound(); + + flash(); startbonustotal=0; @@ -3046,43 +2848,19 @@ void Game::Tick() gameon=1; OPENAL_SetPaused(channels[stream_music3], true); } - if(Button()&&!oldbutton&&selected==numchallengelevels){ - float gLoc[3]={0,0,0}; - float vel[3]={0,0,0}; - OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); - PlaySoundEx( fireendsound, samp[fireendsound], NULL, true); - OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel); - OPENAL_SetVolume(channels[fireendsound], 256); - OPENAL_SetPaused(channels[fireendsound], false); - OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f); - - flashr=1; - flashg=0; - flashb=0; - flashamount=1; - flashdelay=1; + if(Input::Button()&&!oldbutton&&selected==numchallengelevels){ + fireSound(); + + flash(); mainmenu=5; } - if(Button())oldbutton=1; - else oldbutton=0; } if(mainmenu==11){ - if(Button()&&!oldbutton&&selected=0&&selected<=accountprogress[accountactive]){ - float gLoc[3]={0,0,0}; - float vel[3]={0,0,0}; - OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f); - PlaySoundEx( firestartsound, samp[firestartsound], NULL, true); - OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel); - OPENAL_SetVolume(channels[firestartsound], 256); - OPENAL_SetPaused(channels[firestartsound], false); - OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f); - - flashr=1; - flashg=0; - flashb=0; - flashamount=1; - flashdelay=1; + if(Input::Button()&&!oldbutton&&selected=0&&selected<=accountactive->getProgress()){ + fireSound(); + + flash(); startbonustotal=0; @@ -3100,49 +2878,23 @@ void Game::Tick() gameon=1; OPENAL_SetPaused(channels[stream_music3], true); } - if(Button()&&!oldbutton&&selected==numchallengelevels){ - float gLoc[3]={0,0,0}; - float vel[3]={0,0,0}; - OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); - PlaySoundEx( fireendsound, samp[fireendsound], NULL, true); - OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel); - OPENAL_SetVolume(channels[fireendsound], 256); - OPENAL_SetPaused(channels[fireendsound], false); - OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f); - - flashr=1; - flashg=0; - flashb=0; - flashamount=1; - flashdelay=1; + if(Input::Button()&&!oldbutton&&selected==numchallengelevels){ + fireSound(); + + flash(); mainmenu=5; } - if(Button())oldbutton=1; - else oldbutton=0; } if(mainmenu==10){ endgame=2; - if(Button()&&!oldbutton&&selected==3){ - float gLoc[3]={0,0,0}; - float vel[3]={0,0,0}; - OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); - PlaySoundEx( fireendsound, samp[fireendsound], NULL, true); - OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel); - OPENAL_SetVolume(channels[fireendsound], 256); - OPENAL_SetPaused(channels[fireendsound], false); - OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f); - - flashr=1; - flashg=0; - flashb=0; - flashamount=1; - flashdelay=1; + if(Input::Button()&&!oldbutton&&selected==3){ + fireSound(); + + flash(); mainmenu=5; } - if(Button())oldbutton=1; - else oldbutton=0; } if(mainmenu==6){ @@ -3159,8 +2911,6 @@ void Game::Tick() } } } - if(Button())oldbutton=1; - else oldbutton=0; } if(mainmenu==7){ if(Input::Button()&&!oldbutton) { @@ -3186,8 +2936,6 @@ void Game::Tick() } } } - if(Button())oldbutton=1; - else oldbutton=0; } if(mainmenu==8){ if(Input::Button()&&!oldbutton&&selected>-1){ @@ -3201,15 +2949,9 @@ void Game::Tick() flash(); } - if(Button())oldbutton=1; - else oldbutton=0; } - if (mainmenu==18) { - if(Button()&&!oldbutton) { - printf("Button %i pressed\n", selected); - } - - if(Button()&&!oldbutton&&selected==0) { + if (mainmenu==18) { + if(Input::Button()&&!oldbutton&&selected==0) { newstereomode = (StereoMode)(newstereomode + 1); while(!CanInitStereo(newstereomode)) { printf("Failed to initialize mode %s (%i)\n", StereoModeName(newstereomode), newstereomode); @@ -3220,39 +2962,32 @@ void Game::Tick() } } - if(buttons[0]&&!oldbutton&&selected==1) { + if(Input::isKeyDown(MOUSEBUTTON1)&&!oldbutton&&selected==1) { stereoseparation+=0.001; } - if(buttons[1]&&!oldbutton&&selected==1) { + if(Input::isKeyDown(MOUSEBUTTON2)&&!oldbutton&&selected==1) { stereoseparation-=0.001; } - if(Button()&&!oldbutton&&selected==2) { + if(Input::Button()&&!oldbutton&&selected==2) { stereoreverse =! stereoreverse; } - if(Button()&&!oldbutton&&selected==3) { - flashr=1; - flashg=0; - flashb=0; - flashamount=1; - flashdelay=1; + if(Input::Button()&&!oldbutton&&selected==3) { + flash(); stereomode = newstereomode; InitStereo(stereomode); mainmenu=3; } - - if(Button() || buttons[1])oldbutton=1; - else oldbutton=0; } - if(Button()||buttons[1])oldbutton=1; + if(Input::Button()||Input::isKeyDown(MOUSEBUTTON2))oldbutton=1; else oldbutton=0; - if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){ + if(Input::isKeyDown(SDLK_q)&&Input::isKeyDown(SDLK_LMETA)){ tryquit=1; if(mainmenu==3){ if(newdetail>2)newdetail=detail; @@ -3275,130 +3010,30 @@ void Game::Tick() } OPENAL_SetFrequency(channels[stream_music3], 22050); - if(entername){ - for(i=0;i<140;i++){ - if(IsKeyDown(theKeyMap, i)){ - togglekeydelay[i]+=multiplier; - if(togglekeydelay[i]>.4){ - togglekey[i]=0; - togglekeydelay[i]=.36; - } - if(!togglekey[i]){ - if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){ - for(j=255;j>=displayselected+1;j--){ - displaytext[0][j]=displaytext[0][j-1]; - } - displaytext[0][displayselected]=KeyToSingleChar(i); - if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]); - displayselected++; - displaychars[0]++; - } - if(i==MAC_DELETE_KEY&&displayselected!=0){ - for(j=displayselected-1;j<255;j++){ - displaytext[0][j]=displaytext[0][j+1]; - } - displaytext[0][255]=' '; - displayselected--; - displaychars[0]--; - } - if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){ - displayselected--; - } - if(i==MAC_ARROW_RIGHT_KEY&&displayselected.4){ - togglekey[i]=0; - togglekeydelay[i]=.36; - } - if(!togglekey[i]){ - if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){ - for(j=255;j>=displayselected+1;j--){ - displaytext[0][j]=displaytext[0][j-1]; - } - displaytext[0][displayselected]=KeyToSingleChar(i); - if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]); - displayselected++; - displaychars[0]++; - } - if(i==MAC_DELETE_KEY&&displayselected!=0){ - for(j=displayselected-1;j<255;j++){ - displaytext[0][j]=displaytext[0][j+1]; - } - displaytext[0][255]=' '; - displayselected--; - displaychars[0]--; - } - if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){ - displayselected--; - } - if(i==MAC_ARROW_RIGHT_KEY&&displayselected.4){ - togglekey[i]=0; - togglekeydelay[i]=.36; - } - if(!togglekey[i]){ - if(KeyToSingleChar(i)!='\0'&&consolechars[0]<255){ - for(j=255;j>=consoleselected+1;j--){ - consoletext[0][j]=consoletext[0][j-1]; - } - consoletext[0][consoleselected]=KeyToSingleChar(i); - if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))consoletext[0][consoleselected]=Shift(consoletext[0][consoleselected]); - consoleselected++; - consolechars[0]++; - } - else if(i==MAC_ENTER_KEY){ - for(j=255;j>=consoleselected+1;j--){ - consoletext[0][j]=consoletext[0][j-1]; - } - consoletext[0][consoleselected]='\n'; - consoleselected++; - consolechars[0]++; - } - if(i==MAC_DELETE_KEY&&consoleselected!=0){ - for(j=consoleselected-1;j<255;j++){ - consoletext[0][j]=consoletext[0][j+1]; - } - consoletext[0][255]=' '; - consoleselected--; - consolechars[0]--; - } - if(i==MAC_ARROW_UP_KEY){ - if(archiveselected<14)archiveselected++; - for(j=0;j<255;j++){ - consolechars[0]=consolechars[archiveselected]; - consoletext[0][j]=consoletext[archiveselected][j]; - consoleselected=consolechars[0]; - } - } - if(i==MAC_ARROW_DOWN_KEY){ - if(archiveselected>0)archiveselected--; - for(j=0;j<255;j++){ - consolechars[0]=consolechars[archiveselected]; - consoletext[0][j]=consoletext[archiveselected][j]; - consoleselected=consolechars[0]; - } - } - if(i==MAC_ARROW_LEFT_KEY&&consoleselected!=0){ - consoleselected--; - } - if(i==MAC_ARROW_RIGHT_KEY&&consoleselected0){ - for(k=14;k>=1;k--){ - for(j=0;j<255;j++){ - consoletext[k][j]=consoletext[k-1][j]; - } - consolechars[k]=consolechars[k-1]; - } - for(j=0;j<255;j++){ - consoletext[0][j]=' '; - } - consolechars[0]=0; - consoleselected=0; - } + if(console&&!Input::isKeyDown(SDLK_LMETA)){ + inputText(consoletext[0],&consoleselected,&consolechars[0]); + if(!waiting) { + archiveselected=0; + cmd_dispatch(this, consoletext[0]); + if(consolechars[0]>0){ + + for(k=14;k>=1;k--){ + for(j=0;j<255;j++){ + consoletext[k][j]=consoletext[k-1][j]; } + consolechars[k]=consolechars[k-1]; } - togglekey[i]=1; - } - else { - togglekey[i]=0; - togglekeydelay[i]=0; + for(j=0;j<255;j++){ + consoletext[0][j]=' '; + } + consolechars[0]=0; + consoleselected=0; } } @@ -3613,7 +3141,7 @@ void Game::Tick() } } - if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){ + if(Input::isKeyDown(SDLK_q)&&Input::isKeyDown(SDLK_LMETA)){ tryquit=1; if(mainmenu==3){ if(newdetail>2)newdetail=detail; @@ -3635,20 +3163,20 @@ void Game::Tick() if(winfreeze==0)oldwinfreeze=winfreeze; else oldwinfreeze++; - if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))&&!oldjumpkeydown&&!campaign){ + if((Input::isKeyDown(jumpkey)||Input::isKeyDown(SDLK_SPACE))&&!oldjumpkeydown&&!campaign){ if(winfreeze)winfreeze=0; oldjumpkeydown=1; } - if((IsKeyDown(theKeyMap, MAC_ESCAPE_KEY))&&!campaign&&gameon){ + if((Input::isKeyDown(SDLK_ESCAPE))&&!campaign&&gameon){ if(winfreeze){ mainmenu=9; gameon=0; } } - if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))){ + if((Input::isKeyDown(jumpkey)||Input::isKeyDown(SDLK_SPACE))){ oldjumpkeydown=1; } - if(!IsKeyDown(theKeyMap, jumpkey)&&!IsKeyDown(theKeyMap, MAC_SPACE_KEY))oldjumpkeydown=0; + if(!Input::isKeyDown(jumpkey)&&!Input::isKeyDown(SDLK_SPACE))oldjumpkeydown=0; if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){ @@ -3686,7 +3214,7 @@ void Game::Tick() realdialoguetype=dialoguetype[i]; special=0; } - if((!hostile||(dialoguetype[i]>40&&dialoguetype[i]<50))&&realdialoguetype0&&(dialoguegonethrough[i]==0||!special)&&(special||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue))){ + if((!hostile||(dialoguetype[i]>40&&dialoguetype[i]<50))&&realdialoguetype0&&(dialoguegonethrough[i]==0||!special)&&(special||(Input::isKeyDown(attackkey)&&!oldbuttondialogue))){ if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||player[realdialoguetype].howactive>=typedead1||(dialoguetype[i]>40&&dialoguetype[i]<50)){ whichdialogue=i; for(j=0;j=numdialogueboxes[whichdialogue]){ @@ -4875,9 +4403,9 @@ void Game::Tick() rotation=dialoguecamerarotation[whichdialogue][indialogue]; rotation2=dialoguecamerarotation2[whichdialogue][indialogue]; if(dialoguetime>0.5) - if((!endkeydown&&(IsKeyDown(theKeyMap, MAC_1_KEY)||IsKeyDown(theKeyMap, MAC_2_KEY)||IsKeyDown(theKeyMap, MAC_3_KEY)||IsKeyDown(theKeyMap, MAC_4_KEY)||IsKeyDown(theKeyMap, MAC_5_KEY) - ||IsKeyDown(theKeyMap, MAC_6_KEY)||IsKeyDown(theKeyMap, MAC_7_KEY)||IsKeyDown(theKeyMap, MAC_8_KEY)||IsKeyDown(theKeyMap, MAC_9_KEY)||IsKeyDown(theKeyMap, MAC_0_KEY) - ||IsKeyDown(theKeyMap, MAC_MINUS_KEY)))||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue)){ + if((!endkeydown&&(Input::isKeyDown(SDLK_1)||Input::isKeyDown(SDLK_2)||Input::isKeyDown(SDLK_3)||Input::isKeyDown(SDLK_4)||Input::isKeyDown(SDLK_5) + ||Input::isKeyDown(SDLK_6)||Input::isKeyDown(SDLK_7)||Input::isKeyDown(SDLK_8)||Input::isKeyDown(SDLK_9)||Input::isKeyDown(SDLK_0) + ||Input::isKeyDown(SDLK_MINUS)))||(Input::isKeyDown(attackkey)&&!oldbuttondialogue)){ indialogue++; endkeydown=1; if(indialogue=numdialogueboxes[whichdialogue]){ @@ -4967,7 +4495,7 @@ void Game::Tick() } } - if(!IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=0; + if(!Input::isKeyDown(attackkey))oldbuttondialogue=0; else oldbuttondialogue=1; static float keyrefreshdelay=0,bigrefreshdelay=0; @@ -5006,20 +4534,15 @@ void Game::Tick() static float temptexdetail; - if(IsKeyDown(theKeyMap, MAC_H_KEY)&&debugmode){ + if(Input::isKeyDown(SDLK_h)&&debugmode){ player[0].damagetolerance=200000; player[0].damage=0; player[0].burnt=0; player[0].permanentdamage=0; player[0].superpermanentdamage=0; - /* - int whichchar; - whichchar = abs(Random()%7); - registrationname[whichchar]+=1; - */ } - if(IsKeyDown(theKeyMap, MAC_J_KEY)&&!envtogglekeydown&&debugmode){ + if(Input::isKeyDown(SDLK_j)&&!envtogglekeydown&&debugmode){ environment++; if(environment>2)environment=0; Setenvironment(environment); @@ -5028,20 +4551,20 @@ void Game::Tick() } - if(!IsKeyDown(theKeyMap, MAC_J_KEY)){ + if(!Input::isKeyDown(SDLK_j)){ envtogglekeydown=0; } - if(IsKeyDown(theKeyMap, MAC_C_KEY)&&!cameratogglekeydown&&debugmode){ + if(Input::isKeyDown(SDLK_c)&&!cameratogglekeydown&&debugmode){ cameramode=1-cameramode; cameratogglekeydown=1; } - if(!IsKeyDown(theKeyMap, MAC_C_KEY)){ + if(!Input::isKeyDown(SDLK_c)){ cameratogglekeydown=0; } - if(IsKeyDown(theKeyMap, MAC_X_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){ + if(Input::isKeyDown(SDLK_x)&&!Input::isKeyDown(SDLK_LSHIFT)&&!detailtogglekeydown&&debugmode){ if(player[0].num_weapons>0){ if(weapons.type[player[0].weaponids[0]]==sword)weapons.type[player[0].weaponids[0]]=staff; else if(weapons.type[player[0].weaponids[0]]==staff)weapons.type[player[0].weaponids[0]]=knife; @@ -5066,7 +4589,7 @@ void Game::Tick() detailtogglekeydown=1; } - if(IsKeyDown(theKeyMap, MAC_X_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){ + if(Input::isKeyDown(SDLK_x)&&Input::isKeyDown(SDLK_LSHIFT)&&!detailtogglekeydown&&debugmode){ int closest=-1; float closestdist=-1; float distance; @@ -5123,7 +4646,7 @@ void Game::Tick() detailtogglekeydown=1; } - if(IsKeyDown(theKeyMap, MAC_U_KEY)&&debugmode){ + if(Input::isKeyDown(SDLK_u)&&debugmode){ int closest=-1; float closestdist=-1; float distance; @@ -5141,7 +4664,7 @@ void Game::Tick() } - if(IsKeyDown(theKeyMap, MAC_O_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){ + if(Input::isKeyDown(SDLK_o)&&!Input::isKeyDown(SDLK_LSHIFT)&&debugmode){ int closest=-1; float closestdist=-1; float distance; @@ -5153,7 +4676,7 @@ void Game::Tick() closest=i; } } - if(IsKeyDown(theKeyMap, MAC_CONTROL_KEY))closest=0; + if(Input::isKeyDown(SDLK_LCTRL))closest=0; if(closest!=-1){ player[closest].whichskin++; @@ -5177,7 +4700,7 @@ void Game::Tick() detailtogglekeydown=1; } - if(IsKeyDown(theKeyMap, MAC_O_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){ + if(Input::isKeyDown(SDLK_o)&&Input::isKeyDown(SDLK_LSHIFT)&&debugmode){ int closest=-1; float closestdist=-1; float distance; @@ -5258,18 +4781,18 @@ void Game::Tick() detailtogglekeydown=1; } - if(!IsKeyDown(theKeyMap, MAC_X_KEY)){ + if(!Input::isKeyDown(SDLK_x)){ detailtogglekeydown=0; } - if(IsKeyDown(theKeyMap, MAC_B_KEY)&&!slomotogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){ + if(Input::isKeyDown(SDLK_b)&&!slomotogglekeydown&&!Input::isKeyDown(SDLK_LSHIFT)&&debugmode){ slomo=1-slomo; slomodelay=1000; slomotogglekeydown=1; } - if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[1]*/)&&!explodetogglekeydown&&debugmode){ + if(((Input::isKeyDown(SDLK_i)&&!Input::isKeyDown(SDLK_LSHIFT)))&&!explodetogglekeydown&&debugmode){ int closest=-1; float closestdist=-1; float distance; @@ -5335,7 +4858,7 @@ void Game::Tick() explodetogglekeydown=1; } - if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[2]*/)&&!explodetogglekeydown&&debugmode){ + if(((Input::isKeyDown(SDLK_i)&&Input::isKeyDown(SDLK_LSHIFT)))&&!explodetogglekeydown&&debugmode){ int closest=-1; float closestdist=-1; float distance; @@ -5454,17 +4977,16 @@ void Game::Tick() explodetogglekeydown=1; } - if(!IsKeyDown(theKeyMap, MAC_I_KEY)){ + if(!Input::isKeyDown(SDLK_i)){ explodetogglekeydown=0; } - - if(!IsKeyDown(theKeyMap, MAC_B_KEY)&&!IsKeyDown(theKeyMap, MAC_F_KEY)&&!IsKeyDown(theKeyMap, MAC_K_KEY)&&!IsKeyDown(theKeyMap, MAC_S_KEY)){ + if(!Input::isKeyDown(SDLK_b)&&!Input::isKeyDown(SDLK_f)&&!Input::isKeyDown(SDLK_k)&&!Input::isKeyDown(SDLK_s)){ slomotogglekeydown=0; } - if(IsKeyDown(theKeyMap, MAC_F_KEY)&&!slomotogglekeydown&&debugmode){ + if(Input::isKeyDown(SDLK_f)&&!slomotogglekeydown&&debugmode){ player[0].onfire=1-player[0].onfire; if(player[0].onfire){ player[0].CatchFire(); @@ -5487,8 +5009,7 @@ void Game::Tick() slomotogglekeydown=1; } - - if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){ + if(Input::isKeyDown(SDLK_DELETE)&&editorenabled&&!drawmodetogglekeydown&&Input::isKeyDown(SDLK_LSHIFT)){ int closest=-1; float closestdist=-1; float distance; @@ -5508,7 +5029,7 @@ void Game::Tick() drawmodetogglekeydown=1; } - if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){ + if(Input::isKeyDown(SDLK_DELETE)&&editorenabled&&!drawmodetogglekeydown&&Input::isKeyDown(SDLK_LCTRL)){ int closest=-1; float closestdist=-1; float distance; @@ -5526,7 +5047,7 @@ void Game::Tick() drawmodetogglekeydown=1; } - if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled&&debugmode){ + if(Input::isKeyDown(SDLK_m)&&!drawmodetogglekeydown&&!Input::isKeyDown(SDLK_LSHIFT)&&editorenabled&&debugmode){ //drawmode++; //if(drawmode>2)drawmode=0; if(objects.numobjects=numpathpoints)pathpointselected=-1; drawmodetogglekeydown=1; } - if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){ + if(Input::isKeyDown(SDLK_COMMA)&&!Input::isKeyDown(SDLK_LSHIFT)&&!drawmodetogglekeydown&&editorenabled){ pathpointselected--; if(pathpointselected<=-2) pathpointselected=numpathpoints-1; drawmodetogglekeydown=1; } - if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){ + if(Input::isKeyDown(SDLK_COMMA)&&Input::isKeyDown(SDLK_LSHIFT)&&!drawmodetogglekeydown&&editorenabled){ if(pathpointselected!=-1){ numpathpoints--; pathpoint[pathpointselected]=pathpoint[numpathpoints]; @@ -5775,7 +5296,7 @@ void Game::Tick() drawmodetogglekeydown=1; } - if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){ + if(Input::isKeyDown(SDLK_m)&&!drawmodetogglekeydown&&Input::isKeyDown(SDLK_LSHIFT)&&debugmode){ editorenabled=1-editorenabled; if(editorenabled){ player[0].damagetolerance=100000; @@ -5790,59 +5311,59 @@ void Game::Tick() drawmodetogglekeydown=1; } - if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){ + if(Input::isKeyDown(SDLK_LEFT)&&!drawmodetogglekeydown&&editorenabled&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){ editortype--; if(editortype==treeleavestype||editortype==10)editortype--; if(editortype<0)editortype=firetype; drawmodetogglekeydown=1; } - if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){ + if(Input::isKeyDown(SDLK_RIGHT)&&!drawmodetogglekeydown&&editorenabled&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){ editortype++; if(editortype==treeleavestype||editortype==10)editortype++; if(editortype>firetype)editortype=0; drawmodetogglekeydown=1; } - if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){ + if(Input::isKeyDown(SDLK_LEFT)&&editorenabled&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){ editorrotation-=multiplier*100; if(editorrotation<-.01)editorrotation=-.01; drawmodetogglekeydown=1; } - if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){ + if(Input::isKeyDown(SDLK_RIGHT)&&editorenabled&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){ editorrotation+=multiplier*100; drawmodetogglekeydown=1; } - if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){ + if(Input::isKeyDown(SDLK_UP)&&editorenabled&&!Input::isKeyDown(SDLK_LCTRL)){ editorsize+=multiplier; drawmodetogglekeydown=1; } - if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){ + if(Input::isKeyDown(SDLK_DOWN)&&editorenabled&&!Input::isKeyDown(SDLK_LCTRL)){ editorsize-=multiplier; if(editorsize<.1)editorsize=.1; drawmodetogglekeydown=1; } - if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){ + if(Input::isKeyDown(SDLK_LEFT)&&!drawmodetogglekeydown&&editorenabled&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){ mapradius-=multiplier*10; } - if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){ + if(Input::isKeyDown(SDLK_RIGHT)&&!drawmodetogglekeydown&&editorenabled&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){ mapradius+=multiplier*10; } - if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){ + if(Input::isKeyDown(SDLK_UP)&&editorenabled&&Input::isKeyDown(SDLK_LCTRL)){ editorrotation2+=multiplier*100; } - if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){ + if(Input::isKeyDown(SDLK_DOWN)&&editorenabled&&Input::isKeyDown(SDLK_LCTRL)){ editorrotation2-=multiplier*100; if(editorrotation2<-.01)editorrotation2=-.01; } - if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&objects.numobjects&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){ + if(Input::isKeyDown(SDLK_DELETE)&&editorenabled&&objects.numobjects&&!drawmodetogglekeydown&&!Input::isKeyDown(SDLK_LSHIFT)){ int closest=-1; float closestdist=-1; float distance; @@ -5858,11 +5379,11 @@ void Game::Tick() } - if(!IsKeyDown(theKeyMap, MAC_M_KEY)&&!IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&!IsKeyDown(theKeyMap, MAC_PERIOD_KEY)&&!IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&!IsKeyDown(theKeyMap, MAC_P_KEY)){ + if(!Input::isKeyDown(SDLK_m)&&!Input::isKeyDown(SDLK_LEFT)&&!Input::isKeyDown(SDLK_COMMA)&&!Input::isKeyDown(SDLK_PERIOD)&&!Input::isKeyDown(SDLK_RIGHT)&&!Input::isKeyDown(SDLK_DELETE)&&!Input::isKeyDown(SDLK_p)){ drawmodetogglekeydown=0; } - if(IsKeyDown(theKeyMap, MAC_N_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){ + if(Input::isKeyDown(SDLK_n)&&!Input::isKeyDown(SDLK_LCTRL)&&!texturesizetogglekeydown&&debugmode){ //if(!player[0].skeleton.free)player[0].damage+=500; player[0].RagDoll(0); //player[0].spurt=1; @@ -5885,7 +5406,7 @@ void Game::Tick() texturesizetogglekeydown=1; } - if(IsKeyDown(theKeyMap, MAC_N_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){ + if(Input::isKeyDown(SDLK_n)&&Input::isKeyDown(SDLK_LCTRL)&&!texturesizetogglekeydown&&debugmode){ int closest=-1; float closestdist=-1; @@ -5903,13 +5424,13 @@ void Game::Tick() //Attack static bool playerrealattackkeydown=0; - if(!buttons[0])oldbutton=0; - if(!IsKeyDown(theKeyMap, attackkey))oldattackkey=0; + if(!Input::isKeyDown(MOUSEBUTTON1)&&!Input::isKeyDown(MOUSEBUTTON2))oldbutton=0; + if(!Input::isKeyDown(attackkey))oldattackkey=0; if(oldattackkey)player[0].attackkeydown=0; if(oldattackkey)playerrealattackkeydown=0; - if(!oldattackkey)playerrealattackkeydown=IsKeyDown(theKeyMap, attackkey); - if((player[0].parriedrecently<=0||player[0].weaponactive==-1)&&(!oldattackkey||(realthreat&&player[0].lastattack!=swordslashanim&&player[0].lastattack!=knifeslashstartanim&&player[0].lastattack!=staffhitanim&&player[0].lastattack!=staffspinhitanim)))player[0].attackkeydown=IsKeyDown(theKeyMap, attackkey); - if(IsKeyDown(theKeyMap, attackkey)&&!oldattackkey&&!player[0].backkeydown){ + if(!oldattackkey)playerrealattackkeydown=Input::isKeyDown(attackkey); + if((player[0].parriedrecently<=0||player[0].weaponactive==-1)&&(!oldattackkey||(realthreat&&player[0].lastattack!=swordslashanim&&player[0].lastattack!=knifeslashstartanim&&player[0].lastattack!=staffhitanim&&player[0].lastattack!=staffspinhitanim)))player[0].attackkeydown=Input::isKeyDown(attackkey); + if(Input::isKeyDown(attackkey)&&!oldattackkey&&!player[0].backkeydown){ for(k=0;knumchallengelevels-1)targetlevel=0; loading=1; @@ -8267,11 +7787,7 @@ void Game::Tick() OPENAL_SetPaused(channels[fireendsound], false); OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f); - flashr=1; - flashg=0; - flashb=0; - flashamount=1; - flashdelay=1; + flash(); } if(tutorialstage<51) if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){ @@ -8290,11 +7806,7 @@ void Game::Tick() player[0].coords=(oldtemp+oldtemp2)/2; - flashr=1; - flashg=1; - flashb=1; - flashamount=1; - flashdelay=1; + flash(); } if(tutorialstage>=14&&tutorialstage<50) if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){ @@ -8376,7 +7888,7 @@ void Game::Tick() } } - if(IsKeyDown(theKeyMap, MAC_F1_KEY)&&!freezetogglekeydown){ + if(Input::isKeyDown(SDLK_F1)&&!freezetogglekeydown){ Screenshot(); freezetogglekeydown=1; } @@ -8624,21 +8136,9 @@ void Game::TickOnceAfter(){ if(changedelay!=-999)changedelay-=multiplier/7; if(player[0].dead)targetlevel=whichlevel; if(loading==2&&!campaign){ - flashr=1; - flashg=0; - flashb=0; - flashamount=1; - flashdelay=1; - loadtime=0; + flash(); - float gLoc[3]={0,0,0}; - float vel[3]={0,0,0}; - OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f); - PlaySoundEx( firestartsound, samp[firestartsound], NULL, true); - OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel); - OPENAL_SetVolume(channels[firestartsound], 256); - OPENAL_SetPaused(channels[firestartsound], false); - OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f); + fireSound(firestartsound); if(!player[0].dead&&targetlevel!=whichlevel){ startbonustotal=bonustotal; @@ -8646,31 +8146,17 @@ void Game::TickOnceAfter(){ if(!player[0].dead)Loadlevel(targetlevel); if(player[0].dead)Loadlevel(whichlevel); - OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); - PlaySoundEx( fireendsound, samp[fireendsound], NULL, true); - OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel); - OPENAL_SetVolume(channels[fireendsound], 256); - OPENAL_SetPaused(channels[fireendsound], false); - OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f); + fireSound(); loading=3; } if(loading==2&&targetlevel==whichlevel){ - flashr=1; - flashg=0; - flashb=0; - flashamount=1; - flashdelay=1; + flash(); loadtime=0; float gLoc[3]={0,0,0}; float vel[3]={0,0,0}; - OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f); - PlaySoundEx( firestartsound, samp[firestartsound], NULL, true); - OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel); - OPENAL_SetVolume(channels[firestartsound], 256); - OPENAL_SetPaused(channels[firestartsound], false); - OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f); + fireSound(firestartsound); for(i=0;i<255;i++){ mapname[i]='\0'; @@ -8689,12 +8175,7 @@ void Game::TickOnceAfter(){ strcat(mapname,campaignmapname[levelorder[accountactive->getCampaignChoicesMade()]]);//[campaignchoicewhich[whichchoice]]); Loadlevel(mapname); - OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f); - PlaySoundEx( fireendsound, samp[fireendsound], NULL, true); - OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel); - OPENAL_SetVolume(channels[fireendsound], 256); - OPENAL_SetPaused(channels[fireendsound], false); - OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f); + fireSound(); loading=3; } @@ -8724,18 +8205,9 @@ void Game::TickOnceAfter(){ if(!stealthloading){ float gLoc[3]={0,0,0}; float vel[3]={0,0,0}; - OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f); - PlaySoundEx( firestartsound, samp[firestartsound], NULL, true); - OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel); - OPENAL_SetVolume(channels[firestartsound], 256); - OPENAL_SetPaused(channels[firestartsound], false); - OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f); - - flashr=1; - flashg=0; - flashb=0; - flashamount=1; - flashdelay=1; + fireSound(firestartsound); + + flash(); } startbonustotal=0; diff --git a/Source/Globals.cpp b/Source/Globals.cpp index f272cc9..d55167b 100644 --- a/Source/Globals.cpp +++ b/Source/Globals.cpp @@ -42,8 +42,7 @@ OPENAL_SAMPLE *samp[100] = {0}; OPENAL_STREAM * strm[20] = {0}; int channels[100] = {0}; -float volume = 0;bool buttons[3] = {0}; -bool oldbuttons[3] = {0}; +float volume = 0; bool ismotionblur = 0; float usermousesensitivity = 0; bool floatjump = 0; diff --git a/Source/Input.cpp b/Source/Input.cpp new file mode 100644 index 0000000..3cf1b1c --- /dev/null +++ b/Source/Input.cpp @@ -0,0 +1,68 @@ +/* +Copyright (C) 2003, 2010 - Wolfire Games +Copyright (C) 2010 - MCMic + +This file is part of Lugaru. + +Lugaru is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +/**> HEADER FILES <**/ +#include "Input.h" + +extern bool keyboardfrozen; + +bool Input::isKeyDown(int k) { + if(keyboardfrozen)return 0; // vraiment utile? à vérifier + Uint8 *keystate = SDL_GetKeyState(NULL); + if(k HEADER FILES <**/ +#include "SDL.h" +#include "Game.h" + +/**> CONSTANT DECLARATIONS <**/ +#define MOUSEBUTTON1 SDLK_LAST+SDL_BUTTON_LEFT +#define MOUSEBUTTON2 SDLK_LAST+SDL_BUTTON_RIGHT + +/**> FUNCTION PROTOTYPES <**/ +class Input { + public: + static bool isKeyDown(int k); + static const char* keyToChar(unsigned short which); + static void setKeyFor(Game* g); + static unsigned short CharToKey(const char* which); + static Boolean Button(); +}; + +#endif diff --git a/Source/OpenGL_Windows.cpp b/Source/OpenGL_Windows.cpp index ca05fb7..8a9b692 100644 --- a/Source/OpenGL_Windows.cpp +++ b/Source/OpenGL_Windows.cpp @@ -61,7 +61,6 @@ static bool save_png(const char * fname); #pragma comment(lib, "glaux.lib") #endif -extern bool buttons[3]; extern float multiplier; extern float sps; extern float realmultiplier; @@ -128,7 +127,6 @@ void DrawGL(Game & game); void CreateGLWindow (void); Boolean SetUp (Game & game); -void DoKey (SInt8 theKey, SInt8 theCode); void DoUpdate (Game & game); void DoEvent (void); @@ -288,128 +286,6 @@ void DrawGL (Game & game) } } - -static KeyMap g_theKeys; - -void SetKey( int key) -{ - g_theKeys[ key >> 3] |= (1 << (key & 7)); -} - -void ClearKey( int key) -{ - g_theKeys[ key >> 3] &= (0xff ^ (1 << (key & 7))); -} - -void GetKeys( unsigned char theKeys[16]) -{ - memcpy( theKeys, &g_theKeys, 16); -} - -Boolean Button() -{ - return g_button; -} - - -#define MAX_SDLKEYS SDLK_LAST -static unsigned short KeyTable[MAX_SDLKEYS]; - -static void initSDLKeyTable(void) -{ - memset(KeyTable, 0xFF, sizeof (KeyTable)); - KeyTable[SDLK_BACKSPACE] = MAC_DELETE_KEY; - KeyTable[SDLK_TAB] = MAC_TAB_KEY; - KeyTable[SDLK_RETURN] = MAC_RETURN_KEY; - KeyTable[SDLK_ESCAPE] = MAC_ESCAPE_KEY; - KeyTable[SDLK_SPACE] = MAC_SPACE_KEY; - KeyTable[SDLK_PAGEUP] = MAC_PAGE_UP_KEY; - KeyTable[SDLK_PAGEDOWN] = MAC_PAGE_DOWN_KEY; - KeyTable[SDLK_END] = MAC_END_KEY; - KeyTable[SDLK_HOME] = MAC_HOME_KEY; - KeyTable[SDLK_LEFT] = MAC_ARROW_LEFT_KEY; - KeyTable[SDLK_UP] = MAC_ARROW_UP_KEY; - KeyTable[SDLK_RIGHT] = MAC_ARROW_RIGHT_KEY; - KeyTable[SDLK_DOWN] = MAC_ARROW_DOWN_KEY; - KeyTable[SDLK_INSERT] = MAC_INSERT_KEY; - KeyTable[SDLK_DELETE] = MAC_DEL_KEY; - KeyTable[SDLK_0] = MAC_0_KEY; - KeyTable[SDLK_1] = MAC_1_KEY; - KeyTable[SDLK_2] = MAC_2_KEY; - KeyTable[SDLK_3] = MAC_3_KEY; - KeyTable[SDLK_4] = MAC_4_KEY; - KeyTable[SDLK_5] = MAC_5_KEY; - KeyTable[SDLK_6] = MAC_6_KEY; - KeyTable[SDLK_7] = MAC_7_KEY; - KeyTable[SDLK_8] = MAC_8_KEY; - KeyTable[SDLK_9] = MAC_9_KEY; - KeyTable[SDLK_a] = MAC_A_KEY; - KeyTable[SDLK_b] = MAC_B_KEY; - KeyTable[SDLK_c] = MAC_C_KEY; - KeyTable[SDLK_d] = MAC_D_KEY; - KeyTable[SDLK_e] = MAC_E_KEY; - KeyTable[SDLK_f] = MAC_F_KEY; - KeyTable[SDLK_g] = MAC_G_KEY; - KeyTable[SDLK_h] = MAC_H_KEY; - KeyTable[SDLK_i] = MAC_I_KEY; - KeyTable[SDLK_j] = MAC_J_KEY; - KeyTable[SDLK_k] = MAC_K_KEY; - KeyTable[SDLK_l] = MAC_L_KEY; - KeyTable[SDLK_m] = MAC_M_KEY; - KeyTable[SDLK_n] = MAC_N_KEY; - KeyTable[SDLK_o] = MAC_O_KEY; - KeyTable[SDLK_p] = MAC_P_KEY; - KeyTable[SDLK_q] = MAC_Q_KEY; - KeyTable[SDLK_r] = MAC_R_KEY; - KeyTable[SDLK_s] = MAC_S_KEY; - KeyTable[SDLK_t] = MAC_T_KEY; - KeyTable[SDLK_u] = MAC_U_KEY; - KeyTable[SDLK_v] = MAC_V_KEY; - KeyTable[SDLK_w] = MAC_W_KEY; - KeyTable[SDLK_x] = MAC_X_KEY; - KeyTable[SDLK_y] = MAC_Y_KEY; - KeyTable[SDLK_z] = MAC_Z_KEY; - KeyTable[SDLK_KP0] = MAC_NUMPAD_0_KEY; - KeyTable[SDLK_KP1] = MAC_NUMPAD_1_KEY; - KeyTable[SDLK_KP2] = MAC_NUMPAD_2_KEY; - KeyTable[SDLK_KP3] = MAC_NUMPAD_3_KEY; - KeyTable[SDLK_KP4] = MAC_NUMPAD_4_KEY; - KeyTable[SDLK_KP5] = MAC_NUMPAD_5_KEY; - KeyTable[SDLK_KP6] = MAC_NUMPAD_6_KEY; - KeyTable[SDLK_KP7] = MAC_NUMPAD_7_KEY; - KeyTable[SDLK_KP8] = MAC_NUMPAD_8_KEY; - KeyTable[SDLK_KP9] = MAC_NUMPAD_9_KEY; - KeyTable[SDLK_KP_MULTIPLY] = MAC_NUMPAD_ASTERISK_KEY; - KeyTable[SDLK_KP_PLUS] = MAC_NUMPAD_PLUS_KEY; - KeyTable[SDLK_KP_ENTER] = MAC_NUMPAD_ENTER_KEY; - KeyTable[SDLK_KP_MINUS] = MAC_NUMPAD_MINUS_KEY; - KeyTable[SDLK_KP_PERIOD] = MAC_NUMPAD_PERIOD_KEY; - KeyTable[SDLK_KP_DIVIDE] = MAC_NUMPAD_SLASH_KEY; - KeyTable[SDLK_F1] = MAC_F1_KEY; - KeyTable[SDLK_F2] = MAC_F2_KEY; - KeyTable[SDLK_F3] = MAC_F3_KEY; - KeyTable[SDLK_F4] = MAC_F4_KEY; - KeyTable[SDLK_F5] = MAC_F5_KEY; - KeyTable[SDLK_F6] = MAC_F6_KEY; - KeyTable[SDLK_F7] = MAC_F7_KEY; - KeyTable[SDLK_F8] = MAC_F8_KEY; - KeyTable[SDLK_F9] = MAC_F9_KEY; - KeyTable[SDLK_F10] = MAC_F10_KEY; - KeyTable[SDLK_F11] = MAC_F11_KEY; - KeyTable[SDLK_F12] = MAC_F12_KEY; - KeyTable[SDLK_SEMICOLON] = MAC_SEMICOLON_KEY; - KeyTable[SDLK_PLUS] = MAC_PLUS_KEY; - KeyTable[SDLK_COMMA] = MAC_COMMA_KEY; - KeyTable[SDLK_MINUS] = MAC_MINUS_KEY; - KeyTable[SDLK_PERIOD] = MAC_PERIOD_KEY; - KeyTable[SDLK_SLASH] = MAC_SLASH_KEY; - KeyTable[SDLK_BACKQUOTE] = MAC_TILDE_KEY; - KeyTable[SDLK_LEFTBRACKET] = MAC_LEFTBRACKET_KEY; - KeyTable[SDLK_BACKSLASH] = MAC_BACKSLASH_KEY; - KeyTable[SDLK_RIGHTBRACKET] = MAC_RIGHTBRACKET_KEY; - KeyTable[SDLK_QUOTE] = MAC_APOSTROPHE_KEY; -} - static inline int clamp_sdl_mouse_button(Uint8 button) { if (button == 2) // right mouse button is button 3 in SDL. @@ -425,7 +301,6 @@ static inline int clamp_sdl_mouse_button(Uint8 button) static void sdlEventProc(const SDL_Event &e, Game &game) { int val; - bool skipkey = false; SDLMod mod; switch(e.type) @@ -435,93 +310,17 @@ static void sdlEventProc(const SDL_Event &e, Game &game) game.deltav += e.motion.yrel; return; - case SDL_MOUSEBUTTONDOWN: - { - val = clamp_sdl_mouse_button(e.button.button); - if ((val >= 0) && (val <= 2)) - { - if (val == 0) - g_button = true; - buttons[val] = true; - } - } - return; - - case SDL_MOUSEBUTTONUP: - { - val = clamp_sdl_mouse_button(e.button.button); - if ((val >= 0) && (val <= 2)) - { - if (val == 0) - g_button = false; - buttons[val] = false; - } - } - return; - case SDL_KEYDOWN: - if (e.key.keysym.sym == SDLK_g) - { - if (e.key.keysym.mod & KMOD_CTRL) - { - skipkey = true; - SDL_GrabMode mode = SDL_GRAB_ON; - if ((SDL_GetVideoSurface()->flags & SDL_FULLSCREEN) == 0) - { - mode = SDL_WM_GrabInput(SDL_GRAB_QUERY); - mode = (mode==SDL_GRAB_ON) ? SDL_GRAB_OFF:SDL_GRAB_ON; - } - SDL_WM_GrabInput(mode); - } + if ((e.key.keysym.sym == SDLK_g) && + (e.key.keysym.mod & KMOD_CTRL) && + !(SDL_GetVideoSurface()->flags & SDL_FULLSCREEN) ) { + SDL_WM_GrabInput( ((SDL_WM_GrabInput(SDL_GRAB_QUERY)==SDL_GRAB_ON) ? SDL_GRAB_OFF:SDL_GRAB_ON) ); + } else if ( (e.key.keysym.sym == SDLK_RETURN) && (e.key.keysym.mod & KMOD_ALT) ) { + SDL_WM_ToggleFullScreen(SDL_GetVideoSurface()); } - - else if (e.key.keysym.sym == SDLK_RETURN) - { - if (e.key.keysym.mod & KMOD_ALT) - { - skipkey = true; - SDL_WM_ToggleFullScreen(SDL_GetVideoSurface()); - } - } - - if ((!skipkey) && (e.key.keysym.sym < SDLK_LAST)) - { - if (KeyTable[e.key.keysym.sym] != 0xffff) - SetKey(KeyTable[e.key.keysym.sym]); - } - - mod = SDL_GetModState(); - if (mod & KMOD_CTRL) - SetKey(MAC_CONTROL_KEY); - if (mod & KMOD_ALT) - SetKey(MAC_OPTION_KEY); - if (mod & KMOD_META) - SetKey(MAC_COMMAND_KEY); - if (mod & KMOD_SHIFT) - SetKey(MAC_SHIFT_KEY); - if (mod & KMOD_CAPS) - SetKey(MAC_CAPS_LOCK_KEY); - return; case SDL_KEYUP: - if (e.key.keysym.sym < SDLK_LAST) - { - if (KeyTable[e.key.keysym.sym] != 0xffff) - ClearKey(KeyTable[e.key.keysym.sym]); - } - - mod = SDL_GetModState(); - if ((mod & KMOD_CTRL) == 0) - ClearKey(MAC_CONTROL_KEY); - if ((mod & KMOD_ALT) == 0) - ClearKey(MAC_OPTION_KEY); - if ((mod & KMOD_META) == 0) - ClearKey(MAC_COMMAND_KEY); - if ((mod & KMOD_SHIFT) == 0) - ClearKey(MAC_SHIFT_KEY); - if ((mod & KMOD_CAPS) == 0) - ClearKey(MAC_CAPS_LOCK_KEY); return; } } @@ -740,19 +539,6 @@ static void DoMouse(Game & game) } - - -// -------------------------------------------------------------------------- - -void DoKey (SInt8 theKey, SInt8 theCode) -{ - // do nothing -} - -// -------------------------------------------------------------------------- - - - void DoFrameRate (int update) { static long frames = 0; @@ -1034,9 +820,9 @@ int main(int argc, char **argv) LOGFUNC; - memset( &g_theKeys, 0, sizeof( KeyMap)); + //memset( &g_theKeys, 0, sizeof( KeyMap)); - initSDLKeyTable(); + //initSDLKeyTable(); try { @@ -1064,17 +850,18 @@ int main(int argc, char **argv) game.deltah = 0; game.deltav = 0; SDL_Event e; - // message pump - while( SDL_PollEvent( &e ) ) - { - if( e.type == SDL_QUIT ) + if(!game.isWaiting()) { + // message pump + while( SDL_PollEvent( &e ) ) { - gDone=true; - break; + if( e.type == SDL_QUIT ) + { + gDone=true; + break; + } + sdlEventProc(e, game); } - sdlEventProc(e, game); } - // game DoUpdate(game); diff --git a/Source/Settings.cpp b/Source/Settings.cpp index b2c761d..7e62341 100644 --- a/Source/Settings.cpp +++ b/Source/Settings.cpp @@ -1,6 +1,6 @@ #include "Settings.h" #include "Game.h" - +#include "Input.h" void DefaultSettings(Game &game) { detail=1; @@ -31,16 +31,16 @@ void DefaultSettings(Game &game) { vblsync=0; debugmode=0; - game.crouchkey=MAC_SHIFT_KEY; - game.jumpkey=MAC_SPACE_KEY; - game.leftkey=MAC_A_KEY; - game.forwardkey=MAC_W_KEY; - game.backkey=MAC_S_KEY; - game.rightkey=MAC_D_KEY; - game.drawkey=MAC_E_KEY; - game.throwkey=MAC_Q_KEY; - game.attackkey=MAC_MOUSEBUTTON1; - game.chatkey=MAC_T_KEY; + game.crouchkey=SDLK_LSHIFT; + game.jumpkey=SDLK_SPACE; + game.leftkey=SDLK_a; + game.forwardkey=SDLK_w; + game.backkey=SDLK_s; + game.rightkey=SDLK_d; + game.drawkey=SDLK_e; + game.throwkey=SDLK_q; + game.attackkey=MOUSEBUTTON1; + game.chatkey=SDLK_t; } void SaveSettings(Game &game) { @@ -99,25 +99,25 @@ void SaveSettings(Game &game) { opstream << "\nVolume:\n"; opstream << volume; opstream << "\nForward key:\n"; - opstream << KeyToChar(game.forwardkey); + opstream << Input::keyToChar(game.forwardkey); opstream << "\nBack key:\n"; - opstream << KeyToChar(game.backkey); + opstream << Input::keyToChar(game.backkey); opstream << "\nLeft key:\n"; - opstream << KeyToChar(game.leftkey); + opstream << Input::keyToChar(game.leftkey); opstream << "\nRight key:\n"; - opstream << KeyToChar(game.rightkey); + opstream << Input::keyToChar(game.rightkey); opstream << "\nJump key:\n"; - opstream << KeyToChar(game.jumpkey); + opstream << Input::keyToChar(game.jumpkey); opstream << "\nCrouch key:\n"; - opstream << KeyToChar(game.crouchkey); + opstream << Input::keyToChar(game.crouchkey); opstream << "\nDraw key:\n"; - opstream << KeyToChar(game.drawkey); + opstream << Input::keyToChar(game.drawkey); opstream << "\nThrow key:\n"; - opstream << KeyToChar(game.throwkey); + opstream << Input::keyToChar(game.throwkey); opstream << "\nAttack key:\n"; - opstream << KeyToChar(game.attackkey); + opstream << Input::keyToChar(game.attackkey); opstream << "\nChat key:\n"; - opstream << KeyToChar(game.chatkey); + opstream << Input::keyToChar(game.chatkey); opstream << "\nDamage bar:\n"; opstream << showdamagebar; opstream << "\nStereoMode:\n"; @@ -213,35 +213,35 @@ bool LoadSettings(Game &game) { } else if ( !strncmp(setting, "Volume", 6) ) { ipstream >> volume; } else if ( !strncmp(setting, "Forward key", 11) ) { - ipstream >> string; - game.forwardkey = CharToKey(string); + ipstream.getline( string, sizeof(string) ); + game.forwardkey = Input::CharToKey(string); } else if ( !strncmp(setting, "Back key", 8) ) { - ipstream >> string; - game.backkey = CharToKey(string); + ipstream.getline( string, sizeof(string) ); + game.backkey = Input::CharToKey(string); } else if ( !strncmp(setting, "Left key", 8) ) { - ipstream >> string; - game.leftkey = CharToKey(string); + ipstream.getline( string, sizeof(string) ); + game.leftkey = Input::CharToKey(string); } else if ( !strncmp(setting, "Right key", 9) ) { - ipstream >> string; - game.rightkey = CharToKey(string); + ipstream.getline( string, sizeof(string) ); + game.rightkey = Input::CharToKey(string); } else if ( !strncmp(setting, "Jump key", 8) ) { - ipstream >> string; - game.jumpkey = CharToKey(string); + ipstream.getline( string, sizeof(string) ); + game.jumpkey = Input::CharToKey(string); } else if ( !strncmp(setting, "Crouch key", 10) ) { - ipstream >> string; - game.crouchkey = CharToKey(string); + ipstream.getline( string, sizeof(string) ); + game.crouchkey = Input::CharToKey(string); } else if ( !strncmp(setting, "Draw key", 8) ) { - ipstream >> string; - game.drawkey = CharToKey(string); + ipstream.getline( string, sizeof(string) ); + game.drawkey = Input::CharToKey(string); } else if ( !strncmp(setting, "Throw key", 9) ) { - ipstream >> string; - game.throwkey = CharToKey(string); + ipstream.getline( string, sizeof(string) ); + game.throwkey = Input::CharToKey(string); } else if ( !strncmp(setting, "Attack key", 10) ) { - ipstream >> string; - game.attackkey = CharToKey(string); + ipstream.getline( string, sizeof(string) ); + game.attackkey = Input::CharToKey(string); } else if ( !strncmp(setting, "Chat key", 8) ) { - ipstream >> string; - game.chatkey = CharToKey(string); + ipstream.getline( string, sizeof(string) ); + game.chatkey = Input::CharToKey(string); } else if ( !strncmp(setting, "Damage bar", 10) ) { ipstream >> showdamagebar; } else if ( !strncmp(setting, "StereoMode", 10) ) { diff --git a/Source/WinInput.cpp b/Source/WinInput.cpp deleted file mode 100644 index d42ae78..0000000 --- a/Source/WinInput.cpp +++ /dev/null @@ -1,1008 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -/**> HEADER FILES <**/ -#include "WinInput.h" - -#ifdef WIN32 -#include -#else -#include -#include -#include -#endif - -extern bool keyboardfrozen; -extern bool buttons[3]; -/********************> IsKeyDown() <*****/ -Boolean IsKeyDown( unsigned char *keyMap, unsigned short theKey ) -{ - if(keyboardfrozen)return 0; - if(theKey< 0x80 /*1000*/){ - static long keyMapIndex; - static Boolean isKeyDown; - static short bitToCheck; - - // Calculate the key map index - keyMapIndex = keyMap[theKey/8]; - - // Calculate the individual bit to check - bitToCheck = theKey%8; - - // Check the status of the key - isKeyDown = ( keyMapIndex >> bitToCheck ) & 0x01; - - // Return the status of the key - return isKeyDown; - } - else if(theKey==MAC_MOUSEBUTTON1) - return buttons[0]; - else if(theKey==MAC_MOUSEBUTTON2) - return buttons[1]; - - return 0; -} - -unsigned short CharToKey(const char* which) -{ - // alphabetic keys - if(!strcasecmp(which,"a")){ - return MAC_A_KEY; - } - if(!strcasecmp(which,"b")){ - return MAC_B_KEY; - } - if(!strcasecmp(which,"c")){ - return MAC_C_KEY; - } - if(!strcasecmp(which,"d")){ - return MAC_D_KEY; - } - if(!strcasecmp(which,"e")){ - return MAC_E_KEY; - } - if(!strcasecmp(which,"f")){ - return MAC_F_KEY; - } - if(!strcasecmp(which,"g")){ - return MAC_G_KEY; - } - if(!strcasecmp(which,"h")){ - return MAC_H_KEY; - } - if(!strcasecmp(which,"i")){ - return MAC_I_KEY; - } - if(!strcasecmp(which,"j")){ - return MAC_J_KEY; - } - if(!strcasecmp(which,"k")){ - return MAC_K_KEY; - } - if(!strcasecmp(which,"l")){ - return MAC_L_KEY; - } - if(!strcasecmp(which,"m")){ - return MAC_M_KEY; - } - if(!strcasecmp(which,"n")){ - return MAC_N_KEY; - } - if(!strcasecmp(which,"o")){ - return MAC_O_KEY; - } - if(!strcasecmp(which,"p")){ - return MAC_P_KEY; - } - if(!strcasecmp(which,"q")){ - return MAC_Q_KEY; - } - if(!strcasecmp(which,"r")){ - return MAC_R_KEY; - } - if(!strcasecmp(which,"s")){ - return MAC_S_KEY; - } - if(!strcasecmp(which,"t")){ - return MAC_T_KEY; - } - if(!strcasecmp(which,"u")){ - return MAC_U_KEY; - } - if(!strcasecmp(which,"v")){ - return MAC_V_KEY; - } - if(!strcasecmp(which,"w")){ - return MAC_W_KEY; - } - if(!strcasecmp(which,"x")){ - return MAC_X_KEY; - } - if(!strcasecmp(which,"y")){ - return MAC_Y_KEY; - } - if(!strcasecmp(which,"z")){ - return MAC_Z_KEY; - } - - // keypad keys - if(!strcasecmp(which,"KP0")){ - return MAC_NUMPAD_0_KEY; - } - if(!strcasecmp(which,"KP1")){ - return MAC_NUMPAD_1_KEY; - } - if(!strcasecmp(which,"KP2")){ - return MAC_NUMPAD_2_KEY; - } - if(!strcasecmp(which,"KP3")){ - return MAC_NUMPAD_3_KEY; - } - if(!strcasecmp(which,"KP4")){ - return MAC_NUMPAD_4_KEY; - } - if(!strcasecmp(which,"KP5")){ - return MAC_NUMPAD_5_KEY; - } - if(!strcasecmp(which,"KP6")){ - return MAC_NUMPAD_6_KEY; - } - if(!strcasecmp(which,"KP7")){ - return MAC_NUMPAD_7_KEY; - } - if(!strcasecmp(which,"KP8")){ - return MAC_NUMPAD_8_KEY; - } - if(!strcasecmp(which,"KP9")){ - return MAC_NUMPAD_9_KEY; - } - - // enter - if(!strcasecmp(which,"enter")){ - return MAC_ENTER_KEY; - } - - // number keys - if(!strcasecmp(which,"0")){ - return MAC_0_KEY; - } - if(!strcasecmp(which,"1")){ - return MAC_1_KEY; - } - if(!strcasecmp(which,"2")){ - return MAC_2_KEY; - } - if(!strcasecmp(which,"3")){ - return MAC_3_KEY; - } - if(!strcasecmp(which,"4")){ - return MAC_4_KEY; - } - if(!strcasecmp(which,"5")){ - return MAC_5_KEY; - } - if(!strcasecmp(which,"6")){ - return MAC_6_KEY; - } - if(!strcasecmp(which,"7")){ - return MAC_7_KEY; - } - if(!strcasecmp(which,"8")){ - return MAC_8_KEY; - } - if(!strcasecmp(which,"9")){ - return MAC_9_KEY; - } - - // function keys - if(!strcasecmp(which,"F1")){ - return MAC_F1_KEY; - } - if(!strcasecmp(which,"F2")){ - return MAC_F2_KEY; - } - if(!strcasecmp(which,"F3")){ - return MAC_F3_KEY; - } - if(!strcasecmp(which,"F4")){ - return MAC_F4_KEY; - } - if(!strcasecmp(which,"F5")){ - return MAC_F5_KEY; - } - if(!strcasecmp(which,"F6")){ - return MAC_F6_KEY; - } - if(!strcasecmp(which,"F7")){ - return MAC_F7_KEY; - } - if(!strcasecmp(which,"F8")){ - return MAC_F8_KEY; - } - if(!strcasecmp(which,"F9")){ - return MAC_F9_KEY; - } - if(!strcasecmp(which,"F10")){ - return MAC_F10_KEY; - } - if(!strcasecmp(which,"F11")){ - return MAC_F11_KEY; - } - if(!strcasecmp(which,"F12")){ - return MAC_F12_KEY; - } - - // escape - if(!strcasecmp(which,"escape")){ - return MAC_ESCAPE_KEY; - } - if(!strcasecmp(which,"backspace")){ - return MAC_DELETE_KEY; - } - if(!strcasecmp(which,"tab")){ - return MAC_TAB_KEY; - } - if(!strcasecmp(which,"`")){ - return MAC_TILDE_KEY; - } - if(!strcasecmp(which,"caps_lock")){ - return MAC_CAPS_LOCK_KEY; - } -// if(which==){ -// return ""; -// } - if(!strcasecmp(which,"command")){ - return MAC_COMMAND_KEY; - } - if(!strcasecmp(which,"option")){ - return MAC_OPTION_KEY; - } - if(!strcasecmp(which,"delete")){ - return MAC_DEL_KEY; - } - if(!strcasecmp(which,"insert")){ - return MAC_INSERT_KEY; - } - if(!strcasecmp(which,"home")){ - return MAC_HOME_KEY; - } - if(!strcasecmp(which,"end")){ - return MAC_END_KEY; - } - if(!strcasecmp(which,"page_up")){ - return MAC_PAGE_UP_KEY; - } - if(!strcasecmp(which,"page_down")){ - return MAC_PAGE_DOWN_KEY; - } - if(!strcasecmp(which,"clear")){ - return MAC_NUMPAD_CLEAR_KEY; - } - - if(!strcasecmp(which,"control")){ - return MAC_CONTROL_KEY; - } - if(!strcasecmp(which,"return")){ - return MAC_RETURN_KEY; - } - if(!strcasecmp(which,"space")){ - return MAC_SPACE_KEY; - } - if(!strcasecmp(which,"shift")){ - return MAC_SHIFT_KEY; - } - if(!strcasecmp(which,"uparrow")){ - return MAC_ARROW_UP_KEY; - } - if(!strcasecmp(which,"downarrow")){ - return MAC_ARROW_DOWN_KEY; - } - if(!strcasecmp(which,"leftarrow")){ - return MAC_ARROW_LEFT_KEY; - } - if(!strcasecmp(which,"rightarrow")){ - return MAC_ARROW_RIGHT_KEY; - } - if(!strcasecmp(which,"mouse1")){ - return MAC_MOUSEBUTTON1; - } - if(!strcasecmp(which,"mouse2")){ - return MAC_MOUSEBUTTON2; - } - if(!strcasecmp(which,"+")){ - return MAC_NUMPAD_PLUS_KEY; - } - if(!strcasecmp(which,"*")){ - return MAC_NUMPAD_ASTERISK_KEY; - } - if(!strcasecmp(which,"/")){ - return MAC_SLASH_KEY; - } - if(!strcasecmp(which,"\\")){ - return MAC_BACKSLASH_KEY; - } - if(!strcasecmp(which,"[")){ - return MAC_LEFTBRACKET_KEY; - } - if(!strcasecmp(which,"]")){ - return MAC_RIGHTBRACKET_KEY; - } - if(!strcasecmp(which,".")){ - return MAC_PERIOD_KEY; - } - if(!strcasecmp(which,",")){ - return MAC_COMMA_KEY; - } - if(!strcasecmp(which,"\"")){ - return MAC_APOSTROPHE_KEY; - } - if(!strcasecmp(which,";")){ - return MAC_SEMICOLON_KEY; - } - return UNKNOWN_KEY; -} - -const char* KeyToChar(unsigned short which) -{ - static int i; - - // alphabetic keys - if(which==MAC_A_KEY){ - return "a"; - } - if(which==MAC_B_KEY){ - return "b"; - } - if(which==MAC_C_KEY){ - return "c"; - } - if(which==MAC_D_KEY){ - return "d"; - } - if(which==MAC_E_KEY){ - return "e"; - } - if(which==MAC_F_KEY){ - return "f"; - } - if(which==MAC_G_KEY){ - return "g"; - } - if(which==MAC_H_KEY){ - return "h"; - } - if(which==MAC_I_KEY){ - return "i"; - } - if(which==MAC_J_KEY){ - return "j"; - } - if(which==MAC_K_KEY){ - return "k"; - } - if(which==MAC_L_KEY){ - return "l"; - } - if(which==MAC_M_KEY){ - return "m"; - } - if(which==MAC_N_KEY){ - return "n"; - } - if(which==MAC_O_KEY){ - return "o"; - } - if(which==MAC_P_KEY){ - return "p"; - } - if(which==MAC_Q_KEY){ - return "q"; - } - if(which==MAC_R_KEY){ - return "r"; - } - if(which==MAC_S_KEY){ - return "s"; - } - if(which==MAC_T_KEY){ - return "t"; - } - if(which==MAC_U_KEY){ - return "u"; - } - if(which==MAC_V_KEY){ - return "v"; - } - if(which==MAC_W_KEY){ - return "w"; - } - if(which==MAC_X_KEY){ - return "x"; - } - if(which==MAC_Y_KEY){ - return "y"; - } - if(which==MAC_Z_KEY){ - return "z"; - } - - // keypad keys - if(which==MAC_NUMPAD_1_KEY){ - return "KP1"; - } - if(which==MAC_NUMPAD_2_KEY){ - return "KP2"; - } - if(which==MAC_NUMPAD_3_KEY){ - return "KP3"; - } - if(which==MAC_NUMPAD_4_KEY){ - return "KP4"; - } - if(which==MAC_NUMPAD_5_KEY){ - return "KP5"; - } - if(which==MAC_NUMPAD_6_KEY){ - return "KP6"; - } - if(which==MAC_NUMPAD_7_KEY){ - return "KP7"; - } - if(which==MAC_NUMPAD_8_KEY){ - return "KP8"; - } - if(which==MAC_NUMPAD_9_KEY){ - return "KP9"; - } - if(which==MAC_NUMPAD_0_KEY){ - return "KP0"; - } - - // enter - if(which==MAC_ENTER_KEY){ - return "enter"; - } - - // number keys - if(which==MAC_1_KEY){ - return "1"; - } - if(which==MAC_2_KEY){ - return "2"; - } - if(which==MAC_3_KEY){ - return "3"; - } - if(which==MAC_4_KEY){ - return "4"; - } - if(which==MAC_5_KEY){ - return "5"; - } - if(which==MAC_6_KEY){ - return "6"; - } - if(which==MAC_7_KEY){ - return "7"; - } - if(which==MAC_8_KEY){ - return "8"; - } - if(which==MAC_9_KEY){ - return "9"; - } - if(which==MAC_0_KEY){ - return "0"; - } - - // function keys - if(which==MAC_F1_KEY){ - return "F1"; - } - if(which==MAC_F2_KEY){ - return "F2"; - } - if(which==MAC_F3_KEY){ - return "F3"; - } - if(which==MAC_F4_KEY){ - return "F4"; - } - if(which==MAC_F5_KEY){ - return "F5"; - } - if(which==MAC_F6_KEY){ - return "F6"; - } - if(which==MAC_F7_KEY){ - return "F7"; - } - if(which==MAC_F8_KEY){ - return "F8"; - } - if(which==MAC_F9_KEY){ - return "F9"; - } - if(which==MAC_F10_KEY){ - return "F10"; - } - if(which==MAC_F11_KEY){ - return "F11"; - } - if(which==MAC_F12_KEY){ - return "F12"; - } - - // escape - if(which==MAC_ESCAPE_KEY){ - return "escape"; - } - if(which==MAC_DELETE_KEY){ - return "backspace"; - } - if(which==MAC_TAB_KEY){ - return "tab"; - } - if(which==MAC_TILDE_KEY){ - return "`"; - } - if(which==MAC_CAPS_LOCK_KEY){ - return "caps_lock"; - } - if(which==MAC_COMMAND_KEY){ - return "command"; - } - if(which==MAC_OPTION_KEY){ - return "option"; - } - if(which==MAC_DEL_KEY){ - return "delete"; - } - if(which==MAC_INSERT_KEY){ - return "insert"; - } - if(which==MAC_HOME_KEY){ - return "home"; - } - if(which==MAC_END_KEY){ - return "end"; - } - if(which==MAC_PAGE_UP_KEY){ - return "page_up"; - } - if(which==MAC_PAGE_DOWN_KEY){ - return "page_down"; - } - if(which==MAC_NUMPAD_CLEAR_KEY){ - return "clear"; - } - if(which==MAC_CONTROL_KEY){ - return "control"; - } - if(which==MAC_SPACE_KEY){ - return "space"; - } - if(which==MAC_RETURN_KEY){ - return "return"; - } - if(which==MAC_SHIFT_KEY){ - return "shift"; - } - if(which==MAC_ARROW_UP_KEY){ - return "uparrow"; - } - if(which==MAC_ARROW_DOWN_KEY){ - return "downarrow"; - } - if(which==MAC_ARROW_LEFT_KEY){ - return "leftarrow"; - } - if(which==MAC_ARROW_RIGHT_KEY){ - return "rightarrow"; - } - if(which==MAC_MOUSEBUTTON1){ - return "mouse1"; - } - if(which==MAC_MOUSEBUTTON2){ - return "mouse2"; - } - if(which==MAC_ARROW_RIGHT_KEY){ - return "rightarrow"; - } - if(which==MAC_MINUS_KEY||which==MAC_NUMPAD_MINUS_KEY){ - return "-"; - } - if(which==MAC_PLUS_KEY||which==MAC_NUMPAD_EQUALS_KEY){ - return "="; - } - if(which==MAC_NUMPAD_PLUS_KEY){ - return "+"; - } - if(which==MAC_NUMPAD_ASTERISK_KEY){ - return "*"; - } - if(which==MAC_SLASH_KEY||which==MAC_NUMPAD_SLASH_KEY){ - return "/"; - } - if(which==MAC_BACKSLASH_KEY){ - return "\\"; - } - if(which==MAC_LEFTBRACKET_KEY){ - return "["; - } - if(which==MAC_RIGHTBRACKET_KEY){ - return "]"; - } - if(which==MAC_PERIOD_KEY||which==MAC_NUMPAD_PERIOD_KEY){ - return "."; - } - if(which==MAC_COMMA_KEY){ - return ","; - } - if(which==MAC_APOSTROPHE_KEY){ - return "\""; - } - if(which==MAC_SEMICOLON_KEY){ - return ";"; - } - return "unknown"; -} - -char KeyToSingleChar(unsigned short which) -{ - static int i; - - if(which==MAC_A_KEY){ - return 'a'; - } - if(which==MAC_B_KEY){ - return 'b'; - } - if(which==MAC_C_KEY){ - return 'c'; - } - if(which==MAC_D_KEY){ - return 'd'; - } - if(which==MAC_E_KEY){ - return 'e'; - } - if(which==MAC_F_KEY){ - return 'f'; - } - if(which==MAC_G_KEY){ - return 'g'; - } - if(which==MAC_H_KEY){ - return 'h'; - } - if(which==MAC_I_KEY){ - return 'i'; - } - if(which==MAC_J_KEY){ - return 'j'; - } - if(which==MAC_K_KEY){ - return 'k'; - } - if(which==MAC_L_KEY){ - return 'l'; - } - if(which==MAC_M_KEY){ - return 'm'; - } - if(which==MAC_N_KEY){ - return 'n'; - } - if(which==MAC_O_KEY){ - return 'o'; - } - if(which==MAC_P_KEY){ - return 'p'; - } - if(which==MAC_Q_KEY){ - return 'q'; - } - if(which==MAC_R_KEY){ - return 'r'; - } - if(which==MAC_S_KEY){ - return 's'; - } - if(which==MAC_T_KEY){ - return 't'; - } - if(which==MAC_U_KEY){ - return 'u'; - } - if(which==MAC_V_KEY){ - return 'v'; - } - if(which==MAC_W_KEY){ - return 'w'; - } - if(which==MAC_X_KEY){ - return 'x'; - } - if(which==MAC_Y_KEY){ - return 'y'; - } - if(which==MAC_Z_KEY){ - return 'z'; - } - if(which==MAC_NUMPAD_1_KEY){ - return '1'; - } - if(which==MAC_NUMPAD_2_KEY){ - return '2'; - } - if(which==MAC_NUMPAD_3_KEY){ - return '3'; - } - if(which==MAC_NUMPAD_4_KEY){ - return '4'; - } - if(which==MAC_NUMPAD_5_KEY){ - return '5'; - } - if(which==MAC_NUMPAD_6_KEY){ - return '6'; - } - if(which==MAC_NUMPAD_7_KEY){ - return '7'; - } - if(which==MAC_NUMPAD_8_KEY){ - return '8'; - } - if(which==MAC_NUMPAD_9_KEY){ - return '9'; - } - if(which==MAC_NUMPAD_0_KEY){ - return '0'; - } - if(which==MAC_1_KEY){ - return '1'; - } - if(which==MAC_2_KEY){ - return '2'; - } - if(which==MAC_3_KEY){ - return '3'; - } - if(which==MAC_4_KEY){ - return '4'; - } - if(which==MAC_5_KEY){ - return '5'; - } - if(which==MAC_6_KEY){ - return '6'; - } - if(which==MAC_7_KEY){ - return '7'; - } - if(which==MAC_8_KEY){ - return '8'; - } - if(which==MAC_9_KEY){ - return '9'; - } - if(which==MAC_0_KEY){ - return '0'; - } - if(which==MAC_SPACE_KEY){ - return ' '; - } - if(which==MAC_MINUS_KEY||which==MAC_NUMPAD_MINUS_KEY){ - return '-'; - } - if(which==MAC_PLUS_KEY||which==MAC_NUMPAD_EQUALS_KEY){ - return '='; - } - if(which==MAC_NUMPAD_PLUS_KEY){ - return '+'; - } - if(which==MAC_NUMPAD_ASTERISK_KEY){ - return '*'; - } - if(which==MAC_SLASH_KEY||which==MAC_NUMPAD_SLASH_KEY){ - return '/'; - } - if(which==MAC_BACKSLASH_KEY){ - return '\\'; - } - if(which==MAC_LEFTBRACKET_KEY){ - return '['; - } - if(which==MAC_RIGHTBRACKET_KEY){ - return ']'; - } - if(which==MAC_PERIOD_KEY||which==MAC_NUMPAD_PERIOD_KEY){ - return '.'; - } - if(which==MAC_COMMA_KEY){ - return ','; - } - if(which==MAC_APOSTROPHE_KEY){ - return '\''; - } - if(which==MAC_SEMICOLON_KEY){ - return ';'; - } - return '\0'; -} - -char Shift(char which) -{ - static int i; - - if(which=='a'){ - return 'A'; - } - if(which=='b'){ - return 'B'; - } - if(which=='c'){ - return 'C'; - } - if(which=='d'){ - return 'D'; - } - if(which=='e'){ - return 'E'; - } - if(which=='f'){ - return 'F'; - } - if(which=='g'){ - return 'G'; - } - if(which=='h'){ - return 'H'; - } - if(which=='e'){ - return 'E'; - } - if(which=='f'){ - return 'F'; - } - if(which=='g'){ - return 'G'; - } - if(which=='h'){ - return 'H'; - } - if(which=='i'){ - return 'I'; - } - if(which=='j'){ - return 'J'; - } - if(which=='k'){ - return 'K'; - } - if(which=='l'){ - return 'L'; - } - if(which=='m'){ - return 'M'; - } - if(which=='n'){ - return 'N'; - } - if(which=='o'){ - return 'O'; - } - if(which=='p'){ - return 'P'; - } - if(which=='q'){ - return 'Q'; - } - if(which=='r'){ - return 'R'; - } - if(which=='s'){ - return 'S'; - } - if(which=='t'){ - return 'T'; - } - if(which=='u'){ - return 'U'; - } - if(which=='v'){ - return 'V'; - } - if(which=='w'){ - return 'W'; - } - if(which=='x'){ - return 'X'; - } - if(which=='y'){ - return 'Y'; - } - if(which=='z'){ - return 'Z'; - } - if(which=='1'){ - return '!'; - } - if(which=='2'){ - return '@'; - } - if(which=='3'){ - return '#'; - } - if(which=='4'){ - return '$'; - } - if(which=='5'){ - return '%'; - } - if(which=='6'){ - return '^'; - } - if(which=='7'){ - return '&'; - } - if(which=='8'){ - return '*'; - } - if(which=='9'){ - return '('; - } - if(which=='0'){ - return ')'; - } - if(which=='-'){ - return '_'; - } - if(which=='='){ - return '+'; - } - if(which=='['){ - return '{'; - } - if(which==']'){ - return '}'; - } - if(which=='\\'){ - return '|'; - } - if(which=='.'){ - return '>'; - } - if(which==','){ - return '<'; - } - if(which=='/'){ - return '?'; - } - if(which==';'){ - return ':'; - } - if(which=='\''){ - return '\"'; - } - return which; -} diff --git a/Source/WinInput.h b/Source/WinInput.h deleted file mode 100644 index bbdf597..0000000 --- a/Source/WinInput.h +++ /dev/null @@ -1,156 +0,0 @@ -/* -Copyright (C) 2003, 2010 - Wolfire Games - -This file is part of Lugaru. - -Lugaru is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - -See the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#ifndef _WININPUT_H_ -#define _WININPUT_H_ - -/**> HEADER FILES <**/ -#include -#include -#include "MacCompatibility.h" - -/**> CONSTANT DECLARATIONS <**/ -// Mac Keyboard Codes -#define MAC_1_KEY 0x12 -#define MAC_2_KEY 0x13 -#define MAC_3_KEY 0x14 -#define MAC_4_KEY 0x15 -#define MAC_5_KEY 0x17 -#define MAC_6_KEY 0x16 -#define MAC_7_KEY 0x1A -#define MAC_8_KEY 0x1C -#define MAC_9_KEY 0x19 -#define MAC_0_KEY 0x1D -#define MAC_NUMPAD_1_KEY 0x53 -#define MAC_NUMPAD_2_KEY 0x54 -#define MAC_NUMPAD_3_KEY 0x55 -#define MAC_NUMPAD_4_KEY 0x56 -#define MAC_NUMPAD_5_KEY 0x57 -#define MAC_NUMPAD_6_KEY 0x58 -#define MAC_NUMPAD_7_KEY 0x59 -#define MAC_NUMPAD_8_KEY 0x5B -#define MAC_NUMPAD_9_KEY 0x5C -#define MAC_NUMPAD_0_KEY 0x52 -#define MAC_A_KEY 0x00 -#define MAC_B_KEY 0x0B -#define MAC_C_KEY 0x08 -#define MAC_D_KEY 0x02 -#define MAC_E_KEY 0x0E -#define MAC_F_KEY 0x03 -#define MAC_G_KEY 0x05 -#define MAC_H_KEY 0x04 -#define MAC_I_KEY 0x22 -#define MAC_J_KEY 0x26 -#define MAC_K_KEY 0x28 -#define MAC_L_KEY 0x25 -#define MAC_M_KEY 0x2E -#define MAC_N_KEY 0x2D -#define MAC_O_KEY 0x1F -#define MAC_P_KEY 0x23 -#define MAC_Q_KEY 0x0C -#define MAC_R_KEY 0x0F -#define MAC_S_KEY 0x01 -#define MAC_T_KEY 0x11 -#define MAC_U_KEY 0x20 -#define MAC_V_KEY 0x09 -#define MAC_W_KEY 0x0D -#define MAC_X_KEY 0x07 -#define MAC_Y_KEY 0x10 -#define MAC_Z_KEY 0x06 -#define MAC_F1_KEY 0x7A -#define MAC_F2_KEY 0x78 -#define MAC_F3_KEY 0x63 -#define MAC_F4_KEY 0x76 -#define MAC_F5_KEY 0x60 -#define MAC_F6_KEY 0x61 -#define MAC_F7_KEY 0x62 -#define MAC_F8_KEY 0x64 -#define MAC_F9_KEY 0x65 -#define MAC_F10_KEY 0x6D -#define MAC_F11_KEY 0x67 -#define MAC_F12_KEY 0x6F -#define MAC_RETURN_KEY 0x24 -#define MAC_ENTER_KEY 0x4C -#define MAC_TAB_KEY 0x30 -#define MAC_SPACE_KEY 0x31 -#define MAC_DELETE_KEY 0x33 -#define MAC_ESCAPE_KEY 0x35 -#define MAC_COMMAND_KEY 0x37 -#define MAC_SHIFT_KEY 0x38 -#define MAC_CAPS_LOCK_KEY 0x39 -#define MAC_OPTION_KEY 0x3A -#define MAC_CONTROL_KEY 0x3B -#define MAC_PAGE_UP_KEY 0x74 -#define MAC_PAGE_DOWN_KEY 0x79 -#define MAC_INSERT_KEY 0x72 -#define MAC_DEL_KEY 0x75 -#define MAC_HOME_KEY 0x73 -#define MAC_END_KEY 0x77 -#define MAC_LEFT_BRACKET_KEY 0x21 -#define MAC_RIGHT_BRACKET_KEY 0x1E -#define MAC_ARROW_UP_KEY 0x7E -#define MAC_ARROW_DOWN_KEY 0x7D -#define MAC_ARROW_LEFT_KEY 0x7B -#define MAC_ARROW_RIGHT_KEY 0x7C -#define MAC_TILDE_KEY 0x32 -#define MAC_MINUS_KEY 0x1B -#define MAC_PLUS_KEY 0x18 -#define MAC_SLASH_KEY 0x2C -#define MAC_PERIOD_KEY 0x2F -#define MAC_COMMA_KEY 0x2B -#define MAC_BACKSLASH_KEY 0x2A -#define MAC_LEFTBRACKET_KEY 0x21 -#define MAC_RIGHTBRACKET_KEY 0x1E -#define MAC_NUMPAD_CLEAR_KEY 0x47 -#define MAC_NUMPAD_MINUS_KEY 0x4E -#define MAC_NUMPAD_EQUALS_KEY 0x51 -#define MAC_NUMPAD_PLUS_KEY 0x45 -#define MAC_NUMPAD_SLASH_KEY 0x4B -#define MAC_NUMPAD_ASTERISK_KEY 0x43 -#define MAC_NUMPAD_ENTER_KEY 0x4C -#define MAC_NUMPAD_PERIOD_KEY 0x41 -#define MAC_SEMICOLON_KEY 0x29 -#define MAC_APOSTROPHE_KEY 0x27 -#define MAC_MOUSEBUTTON1 10000 -#define MAC_MOUSEBUTTON2 10001 - -#define UNKNOWN_KEY 0xFF - - -/**> FUNCTION PROTOTYPES <**/ -Boolean IsKeyDown( unsigned char *keyMap, unsigned short theKey ); -void InitMouse(); -void MoveMouse(int xcoord, int ycoord, Point *mouseloc); -void RefreshMouse(Point *mouseloc); -void DisposeMouse(); -unsigned short CharToKey(const char* which); -const char* KeyToChar(unsigned short which); -char KeyToSingleChar(unsigned short which); -char Shift(char which); - - -typedef unsigned char KeyMap[16]; -void GetKeys( unsigned char theKeys[16]); - -Boolean Button(); - - -#endif