From dc03d60e08bdc0b97ea7b07e8973ed42450c9482 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20BERNIGAUD?= Date: Fri, 4 Jun 2010 21:45:46 +0200 Subject: [PATCH] Some clean up. No more WinInput.{h,cpp}. --- CMakeLists.txt | 2 - Source/Account.cpp | 8 +- Source/Game.h | 4 +- Source/GameTick.cpp | 329 ++++++++++++++++++-------------------- Source/Input.cpp | 19 +++ Source/Input.h | 7 + Source/OpenGL_Windows.cpp | 23 --- Source/Settings.cpp | 20 +-- Source/WinInput.cpp | 50 ------ Source/WinInput.h | 44 ----- 10 files changed, 193 insertions(+), 313 deletions(-) delete mode 100644 Source/WinInput.cpp delete mode 100644 Source/WinInput.h diff --git a/CMakeLists.txt b/CMakeLists.txt index aa0374f..e09a149 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,7 +78,6 @@ 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 @@ -105,7 +104,6 @@ set(LUGARU_H ${SRCDIR}/Terrain.h ${SRCDIR}/Text.h ${SRCDIR}/Weapons.h - ${SRCDIR}/WinInput.h ${SRCDIR}/Input.h ${SRCDIR}/alstubs.h ${SRCDIR}/binio.h diff --git a/Source/Account.cpp b/Source/Account.cpp index 31e99af..90b585a 100644 --- a/Source/Account.cpp +++ b/Source/Account.cpp @@ -37,15 +37,15 @@ Account::Account(string n) { difficulty = 0; progress = 0; points = 0; - for(int i=0;i<50;highscore[i++] = 0); - for(int i=0;i<50;fasttime[i++] = 0); - for(int i=0;i<60;unlocked[i++] = 0); + memset(highscore, 0, sizeof(highscore)); + memset(fasttime, 0, sizeof(fasttime)); + memset(unlocked, 0, sizeof(unlocked)); campaignhighscore = 0; campaignfasttime = 0; campaignscore = 0; campaigntime = 0; campaignchoicesmade = 0; - for(int i=0;i<5000;campaignchoices[i++] = 0); + memset(campaignchoices, 0, sizeof(campaignchoices)); } Account* Account::add(string name) { diff --git a/Source/Game.h b/Source/Game.h index fab60c8..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 diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index e1ea043..b3114ed 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -213,14 +213,6 @@ extern bool campaign; extern float oldgamespeed; -extern float accountcampaignhighscore[10]; -extern float accountcampaignfasttime[10]; -extern float accountcampaignscore[10]; -extern float accountcampaigntime[10]; - -extern int accountcampaignchoicesmade[10]; -extern int accountcampaignchoices[10][5000]; - static const char *rabbitskin[] = { ":Data:Textures:Fur3.jpg", ":Data:Textures:Fur.jpg", @@ -322,142 +314,131 @@ static void ch_save(Game *game, const char *args) fpackf(tfile, "Bi Bi", player[0].whichskin, player[0].creature); fpackf(tfile, "Bi", numdialogues); - if(numdialogues) - for(k=0;k1&&numplayers0&&player[j].num_weapons<5) - for(k=0;knumpathpoints); - if(game->numpathpoints) - for(j=0;jnumpathpoints;j++){ - fpackf(tfile, "Bf Bf Bf Bi", game->pathpoint[j].x, game->pathpoint[j].y, game->pathpoint[j].z, game->numpathpointconnect[j]); - for(k=0;knumpathpointconnect[j];k++){ - fpackf(tfile, "Bi", game->pathpointconnect[j][k]); - } - } + for(j=0;jnumpathpoints;j++){ + fpackf(tfile, "Bf Bf Bf Bi", game->pathpoint[j].x, game->pathpoint[j].y, game->pathpoint[j].z, game->numpathpointconnect[j]); + for(k=0;knumpathpointconnect[j];k++){ + fpackf(tfile, "Bi", game->pathpointconnect[j][k]); + } + } fpackf(tfile, "Bf Bf Bf Bf", game->mapcenter.x, game->mapcenter.y, game->mapcenter.z, game->mapradius); @@ -544,9 +525,7 @@ static void set_proportion(int pnum, const char *args) player[pnum].proportionbody=1.1*bodyprop; player[pnum].proportionarms=1.1*armprop; player[pnum].proportionlegs=1.1*legprop; - } - - if(player[pnum].creature==rabbittype){ + } else if(player[pnum].creature==rabbittype){ player[pnum].proportionhead=1.2*headprop; player[pnum].proportionbody=1.05*bodyprop; player[pnum].proportionarms=1.00*armprop; @@ -818,23 +797,21 @@ static void ch_notindemo(Game *game, const char *args) static void ch_type(Game *game, const char *args) { int i, n = sizeof(editortypenames) / sizeof(editortypenames[0]); - for (i = 0; i < n; i++) - if (stripfx(args, editortypenames[i])) - { - editoractive = i; - break; - } + for (i = 0; i < n; i++) + if (stripfx(args, editortypenames[i])) { + editoractive = i; + break; + } } static void ch_path(Game *game, const char *args) { int i, n = sizeof(pathtypenames) / sizeof(pathtypenames[0]); for (i = 0; i < n; i++) - if (stripfx(args, pathtypenames[i])) - { - editorpathtype = i; - break; - } + if (stripfx(args, pathtypenames[i])) { + editorpathtype = i; + break; + } } static void ch_hs(Game *game, const char *args) @@ -1003,9 +980,7 @@ static void ch_default(Game *game, const char *args) player[0].proportionbody=1.1; player[0].proportionarms=1.1; player[0].proportionlegs=1.1; - } - - if(player[0].creature==rabbittype){ + } else if(player[0].creature==rabbittype){ player[0].proportionhead=1.2; player[0].proportionbody=1.05; player[0].proportionarms=1.00; @@ -2539,7 +2514,7 @@ void Game::Tick() if(mainmenu){ //menu buttons if(mainmenu==1||mainmenu==2){ - if(Button()&&!oldbutton&&selected==1){ + if(Input::Button()&&!oldbutton&&selected==1){ if(!gameon){ fireSound(firestartsound); @@ -2562,7 +2537,7 @@ void Game::Tick() } } - if(Button()&&!oldbutton&&selected==2){ + if(Input::Button()&&!oldbutton&&selected==2){ fireSound(); flash(); @@ -2579,7 +2554,7 @@ void Game::Tick() if(newscreenheight<0)newscreenheight=screenheight; } - if(Button()&&!oldbutton&&selected==3){ + if(Input::Button()&&!oldbutton&&selected==3){ fireSound(); flash(); @@ -2597,10 +2572,10 @@ void Game::Tick() } } if(mainmenu==3){ - if(Button()&&!oldbutton&&selected!=-1){ + if(Input::Button()&&!oldbutton&&selected!=-1){ fireSound(); } - if(Button()&&!oldbutton&&selected==0){ + if(Input::Button()&&!oldbutton&&selected==0){ extern SDL_Rect **resolutions; bool isCustomResolution = true; @@ -2648,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){ @@ -2686,19 +2661,19 @@ 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){ + if(Input::Button()&&!oldbutton&&selected==7){ /*fireSound(); */ flash(); @@ -2709,17 +2684,17 @@ void Game::Tick() selected=-1; keyselect=-1; } - if(Button() && !oldbutton && selected == 12) { + if(Input::Button() && !oldbutton && selected == 12) { flash(); newstereomode = stereomode; mainmenu=18; keyselect=-1; } - if(Button() && !oldbutton && selected == 13) { + if(Input::Button() && !oldbutton && selected == 13) { showdamagebar=!showdamagebar; } - if(Button()&&!oldbutton&&selected==8){ + if(Input::Button()&&!oldbutton&&selected==8){ fireSound(); flash(); @@ -2736,7 +2711,7 @@ void Game::Tick() } } if(mainmenu==4){ - if(Button()&&!oldbutton&&selected!=-1&&!waiting){ + if(Input::Button()&&!oldbutton&&selected!=-1&&!waiting){ fireSound(); if(selected<9&&keyselect==-1) keyselect=selected; @@ -2764,7 +2739,7 @@ void Game::Tick() endgame=0; } - if(Button()&&!oldbutton&&selected==1){ + if(Input::Button()&&!oldbutton&&selected==1){ fireSound(); flash(); @@ -2784,7 +2759,7 @@ void Game::Tick() gameon=1; OPENAL_SetPaused(channels[stream_music3], true); } - if(Button()&&!oldbutton&&(selected-7>=accountactive->getCampaignChoicesMade())){//selected>=7&&(selected-7<=campaignnumchoices)){ + if(Input::Button()&&!oldbutton&&(selected-7>=accountactive->getCampaignChoicesMade())){//selected>=7&&(selected-7<=campaignnumchoices)){ fireSound(); flash(); @@ -2821,7 +2796,7 @@ void Game::Tick() gameon=1; OPENAL_SetPaused(channels[stream_music3], true); } - if(Button()&&!oldbutton&&selected==4){ + if(Input::Button()&&!oldbutton&&selected==4){ fireSound(); flash(); @@ -2829,21 +2804,21 @@ void Game::Tick() if(mainmenu==5&&gameon)mainmenu=2; if(mainmenu==5&&!gameon)mainmenu=1; } - if(Button()&&!oldbutton&&selected==5){ + if(Input::Button()&&!oldbutton&&selected==5){ fireSound(); flash(); mainmenu=7; } - if(Button()&&!oldbutton&&selected==3){ + if(Input::Button()&&!oldbutton&&selected==3){ fireSound(); flash(); mainmenu=6; } - if(Button()&&!oldbutton&&selected==2){ + if(Input::Button()&&!oldbutton&&selected==2){ fireSound(); flash(); @@ -2852,7 +2827,7 @@ void Game::Tick() } } if(mainmenu==9){ - if(Button()&&!oldbutton&&selected=0&&selected<=accountactive->getProgress()){ + if(Input::Button()&&!oldbutton&&selected=0&&selected<=accountactive->getProgress()){ fireSound(); flash(); @@ -2873,7 +2848,7 @@ void Game::Tick() gameon=1; OPENAL_SetPaused(channels[stream_music3], true); } - if(Button()&&!oldbutton&&selected==numchallengelevels){ + if(Input::Button()&&!oldbutton&&selected==numchallengelevels){ fireSound(); flash(); @@ -2882,7 +2857,7 @@ void Game::Tick() } } if(mainmenu==11){ - if(Button()&&!oldbutton&&selected=0&&selected<=accountactive->getProgress()){ + if(Input::Button()&&!oldbutton&&selected=0&&selected<=accountactive->getProgress()){ fireSound(); flash(); @@ -2903,7 +2878,7 @@ void Game::Tick() gameon=1; OPENAL_SetPaused(channels[stream_music3], true); } - if(Button()&&!oldbutton&&selected==numchallengelevels){ + if(Input::Button()&&!oldbutton&&selected==numchallengelevels){ fireSound(); flash(); @@ -2913,7 +2888,7 @@ void Game::Tick() } if(mainmenu==10){ endgame=2; - if(Button()&&!oldbutton&&selected==3){ + if(Input::Button()&&!oldbutton&&selected==3){ fireSound(); flash(); @@ -2923,7 +2898,7 @@ void Game::Tick() } if(mainmenu==6){ - if(Button()&&!oldbutton) { + if(Input::Button()&&!oldbutton) { if(selected>-1){ fireSound(); if(selected==1) { @@ -2938,7 +2913,7 @@ void Game::Tick() } } if(mainmenu==7){ - if(Button()&&!oldbutton) { + if(Input::Button()&&!oldbutton) { if(selected!=-1){ fireSound(); if(selected==0&&Account::getNbAccounts()<8){ @@ -2963,7 +2938,7 @@ void Game::Tick() } } if(mainmenu==8){ - if(Button()&&!oldbutton&&selected>-1){ + if(Input::Button()&&!oldbutton&&selected>-1){ fireSound(); if(selected<=2) @@ -2976,7 +2951,7 @@ void Game::Tick() } } if (mainmenu==18) { - if(Button()&&!oldbutton&&selected==0) { + if(Input::Button()&&!oldbutton&&selected==0) { newstereomode = (StereoMode)(newstereomode + 1); while(!CanInitStereo(newstereomode)) { printf("Failed to initialize mode %s (%i)\n", StereoModeName(newstereomode), newstereomode); @@ -2994,11 +2969,11 @@ void Game::Tick() stereoseparation-=0.001; } - if(Button()&&!oldbutton&&selected==2) { + if(Input::Button()&&!oldbutton&&selected==2) { stereoreverse =! stereoreverse; } - if(Button()&&!oldbutton&&selected==3) { + if(Input::Button()&&!oldbutton&&selected==3) { flash(); stereomode = newstereomode; @@ -3009,7 +2984,7 @@ void Game::Tick() } - if(Button()||Input::isKeyDown(MOUSEBUTTON2))oldbutton=1; + if(Input::Button()||Input::isKeyDown(MOUSEBUTTON2))oldbutton=1; else oldbutton=0; if(Input::isKeyDown(SDLK_q)&&Input::isKeyDown(SDLK_LMETA)){ diff --git a/Source/Input.cpp b/Source/Input.cpp index 41229e3..3cf1b1c 100644 --- a/Source/Input.cpp +++ b/Source/Input.cpp @@ -47,3 +47,22 @@ const char* Input::keyToChar(unsigned short i) { return "unknown"; } +unsigned short Input::CharToKey(const char* which) +{ + for(unsigned short i=0;i 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 16b8c82..7e32f0b 100644 --- a/Source/OpenGL_Windows.cpp +++ b/Source/OpenGL_Windows.cpp @@ -286,29 +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 SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(SDL_BUTTON_LEFT); -} - static inline int clamp_sdl_mouse_button(Uint8 button) { if (button == 2) // right mouse button is button 3 in SDL. diff --git a/Source/Settings.cpp b/Source/Settings.cpp index 9642cb9..7e62341 100644 --- a/Source/Settings.cpp +++ b/Source/Settings.cpp @@ -214,34 +214,34 @@ bool LoadSettings(Game &game) { ipstream >> volume; } else if ( !strncmp(setting, "Forward key", 11) ) { ipstream.getline( string, sizeof(string) ); - game.forwardkey = CharToKey(string); + game.forwardkey = Input::CharToKey(string); } else if ( !strncmp(setting, "Back key", 8) ) { ipstream.getline( string, sizeof(string) ); - game.backkey = CharToKey(string); + game.backkey = Input::CharToKey(string); } else if ( !strncmp(setting, "Left key", 8) ) { ipstream.getline( string, sizeof(string) ); - game.leftkey = CharToKey(string); + game.leftkey = Input::CharToKey(string); } else if ( !strncmp(setting, "Right key", 9) ) { ipstream.getline( string, sizeof(string) ); - game.rightkey = CharToKey(string); + game.rightkey = Input::CharToKey(string); } else if ( !strncmp(setting, "Jump key", 8) ) { ipstream.getline( string, sizeof(string) ); - game.jumpkey = CharToKey(string); + game.jumpkey = Input::CharToKey(string); } else if ( !strncmp(setting, "Crouch key", 10) ) { ipstream.getline( string, sizeof(string) ); - game.crouchkey = CharToKey(string); + game.crouchkey = Input::CharToKey(string); } else if ( !strncmp(setting, "Draw key", 8) ) { ipstream.getline( string, sizeof(string) ); - game.drawkey = CharToKey(string); + game.drawkey = Input::CharToKey(string); } else if ( !strncmp(setting, "Throw key", 9) ) { ipstream.getline( string, sizeof(string) ); - game.throwkey = CharToKey(string); + game.throwkey = Input::CharToKey(string); } else if ( !strncmp(setting, "Attack key", 10) ) { ipstream.getline( string, sizeof(string) ); - game.attackkey = CharToKey(string); + game.attackkey = Input::CharToKey(string); } else if ( !strncmp(setting, "Chat key", 8) ) { ipstream.getline( string, sizeof(string) ); - game.chatkey = CharToKey(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 8726854..0000000 --- a/Source/WinInput.cpp +++ /dev/null @@ -1,50 +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" -#include "SDL.h" - -#ifdef WIN32 -#include -#else -#include -#include -#include -#endif - -extern bool keyboardfrozen; -/********************> IsKeyDown() <*****/ - -unsigned short CharToKey(const char* which) -{ - for(unsigned short i=0;i HEADER FILES <**/ -#include -#include -#include "MacCompatibility.h" -#include "SDL.h" - -/**> CONSTANT DECLARATIONS <**/ -#define MOUSEBUTTON1 SDLK_LAST+SDL_BUTTON_LEFT -#define MOUSEBUTTON2 SDLK_LAST+SDL_BUTTON_RIGHT - -/**> FUNCTION PROTOTYPES <**/ -void InitMouse(); -void MoveMouse(int xcoord, int ycoord, Point *mouseloc); -void RefreshMouse(Point *mouseloc); -void DisposeMouse(); -unsigned short CharToKey(const char* which); - -Boolean Button(); - -#endif -- 2.39.2