Changeset 1342
- Timestamp:
- May 6, 2012, 2:49:16 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 8 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/deushax/debugsprite.cpp
r1310 r1342 49 49 Entity::TickGame(seconds); 50 50 51 vec3 move = seconds * vec3( Input::GetAxis(0),0.0f);51 vec3 move = seconds * vec3(0.0f); 52 52 data->pos += move * vec3(100.f * sqrtf(2.0f), 100.f, 100.f); 53 53 } -
trunk/src/Makefile.am
r1307 r1342 7 7 map.cpp map.h entity.cpp entity.h ticker.cpp ticker.h lolgl.h \ 8 8 tileset.cpp tileset.h forge.cpp forge.h video.cpp video.h log.cpp log.h \ 9 timer.cpp timer.h bitfield.h profiler.cpp profiler.h input.h input.cpp\9 timer.cpp timer.h bitfield.h profiler.cpp profiler.h \ 10 10 world.cpp world.h sample.cpp sample.h sampler.cpp sampler.h \ 11 11 text.cpp text.h emitter.cpp emitter.h numeric.h hash.cpp hash.h \ … … 28 28 \ 29 29 math/vector.cpp math/real.cpp math/half.cpp math/trig.cpp math/trig.h \ 30 \ 31 input/input.cpp input/input.h \ 32 input/stick.cpp input/stick.h \ 30 33 \ 31 34 gpu/shader.cpp gpu/shader.h \ -
trunk/src/camera.cpp
r1336 r1342 58 58 WorldEntity::TickGame(seconds); 59 59 60 int updown = Input::GetButtonState(273 /*SDLK_UP*/) 61 - Input::GetButtonState(274 /*SDLK_DOWN*/); 62 int rightleft = Input::GetButtonState(275 /*SDLK_RIGHT*/) 63 - Input::GetButtonState(276 /*SDLK_LEFT*/); 64 int pgupdown = Input::GetButtonState(280 /*SDLK_PAGEUP*/) 65 - Input::GetButtonState(281 /*SDLK_PAGEDOWN*/); 60 /* Hackish keyboard support */ 61 float updown = Input::GetButtonState(273 /*SDLK_UP*/) 62 - Input::GetButtonState(274 /*SDLK_DOWN*/); 63 float rightleft = Input::GetButtonState(275 /*SDLK_RIGHT*/) 64 - Input::GetButtonState(276 /*SDLK_LEFT*/); 65 float pgupdown = Input::GetButtonState(280 /*SDLK_PAGEUP*/) 66 - Input::GetButtonState(281 /*SDLK_PAGEDOWN*/); 67 68 /* Hackish stick support */ 69 static Stick *stick = NULL; 70 if (!stick) 71 stick = Input::TrackStick(); 72 if (stick && stick->GetAxisCount() >= 2) 73 { 74 rightleft = 2.f * stick->GetAxis(0) * std::abs(stick->GetAxis(0)); 75 updown = -2.f * stick->GetAxis(1) * std::abs(stick->GetAxis(1)); 76 } 66 77 67 78 m_position += vec3(rightleft, pgupdown, -updown) * 200.f * seconds; -
trunk/src/core.h
r1307 r1342 79 79 #include "audio.h" 80 80 #include "scene.h" 81 #include "input.h" 81 #include "input/input.h" 82 #include "input/stick.h" 82 83 #include "profiler.h" 83 84 -
trunk/src/input/input.cpp
r1341 r1342 2 2 // Lol Engine 3 3 // 4 // Copyright: (c) 2010-201 1Sam Hocevar <sam@hocevar.net>4 // Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net> 5 5 // This program is free software; you can redistribute it and/or 6 6 // modify it under the terms of the Do What The Fuck You Want To … … 49 49 int nentities; 50 50 WorldEntity *lastfocus; 51 52 Array<Stick *> m_sticks; 51 53 } 52 54 inputdata; … … 58 60 */ 59 61 62 #if 0 60 63 vec2 Input::GetAxis(int axis) 61 64 { … … 81 84 return ret; 82 85 } 86 #endif 83 87 84 88 ivec2 Input::GetMousePos() … … 195 199 } 196 200 201 Stick *Input::CreateStick() 202 { 203 Stick *stick = new Stick(); 204 Ticker::Ref(stick); 205 data->m_sticks.Push(stick); 206 return stick; 207 } 208 209 void Input::DestroyStick(Stick *stick) 210 { 211 for (int i = 0; i < data->m_sticks.Count(); i++) 212 if (data->m_sticks[i] == stick) 213 data->m_sticks.Remove(i); 214 Ticker::Unref(stick); 215 } 216 217 Stick *Input::TrackStick() 218 { 219 /* FIXME: add the possibility to choose amongst sticks */ 220 if (!data->m_sticks.Count()) 221 return NULL; 222 Ticker::Ref(data->m_sticks[0]); 223 return data->m_sticks[0]; 224 } 225 226 void Input::UntrackStick(Stick *stick) 227 { 228 Ticker::Unref(stick); 229 } 230 197 231 } /* namespace lol */ 198 232 -
trunk/src/input/input.h
r1341 r1342 14 14 // 15 15 16 #if !defined __LOL_INPUT_ H__17 #define __LOL_INPUT_ H__16 #if !defined __LOL_INPUT_INPUT_H__ 17 #define __LOL_INPUT_INPUT_H__ 18 18 19 19 #include "lol/math/vector.h" 20 #include "input/stick.h" 20 21 21 22 namespace lol … … 28 29 public: 29 30 /* These methods are general queries */ 30 static vec2 GetAxis(int axis);31 31 static ivec2 GetMousePos(); 32 32 static ivec3 GetMouseButtons(); … … 42 42 static void SetMouseButton(int index); 43 43 static void UnsetMouseButton(int index); 44 45 /* 46 * Joystick handling 47 */ 48 49 static Stick *CreateStick(); 50 static void DestroyStick(Stick *stick); 51 52 static Stick *TrackStick(); 53 static void UntrackStick(Stick *stick); 44 54 }; 45 55 46 56 } /* namespace lol */ 47 57 48 #endif // __LOL_INPUT_ H__58 #endif // __LOL_INPUT_INPUT_H__ 49 59 -
trunk/src/platform/sdl/sdlinput.cpp
r1310 r1342 35 35 36 36 static ivec2 GetMousePos(); 37 #if defined USE_SDL 38 Array<SDL_Joystick *, Stick *> m_joysticks; 39 #endif 37 40 }; 38 41 … … 42 45 43 46 SdlInput::SdlInput() 44 : data(new SdlInputData())47 : m_data(new SdlInputData()) 45 48 { 46 49 #if defined USE_SDL 47 SDL_Init(SDL_INIT_TIMER); 50 SDL_Init(SDL_INIT_TIMER | SDL_INIT_JOYSTICK); 51 52 /* Register all the joysticks we can find, and let the input 53 * system decide what it wants to track. */ 54 SDL_JoystickEventState(SDL_ENABLE); 55 for (int i = 0; i < SDL_NumJoysticks(); i++) 56 { 57 SDL_Joystick *sdlstick = SDL_JoystickOpen(i); 58 Stick *stick = Input::CreateStick(); 59 stick->SetAxisCount(SDL_JoystickNumAxes(sdlstick)); 60 stick->SetButtonCount(SDL_JoystickNumButtons(sdlstick)); 61 m_data->m_joysticks.Push(sdlstick, stick); 62 } 48 63 #endif 49 64 50 65 m_gamegroup = GAMEGROUP_BEFORE; 66 } 67 68 SdlInput::~SdlInput() 69 { 70 #if defined USE_SDL 71 /* Unregister all the joysticks we added */ 72 while (m_data->m_joysticks.Count()) 73 { 74 SDL_JoystickClose(m_data->m_joysticks[0].m1); 75 Input::DestroyStick(m_data->m_joysticks[0].m2); 76 m_data->m_joysticks.Remove(0); 77 } 78 #endif 79 delete m_data; 51 80 } 52 81 … … 56 85 57 86 #if !defined _WIN32 58 data->Tick(seconds);87 m_data->Tick(seconds); 59 88 #endif 60 89 } … … 65 94 66 95 #if defined _WIN32 67 data->Tick(seconds);96 m_data->Tick(seconds); 68 97 #endif 69 98 } … … 102 131 break; 103 132 } 133 134 case SDL_JOYAXISMOTION: 135 m_joysticks[event.jaxis.which].m2->SetAxis(event.jaxis.axis, (float)event.jaxis.value / 32768.f); 136 break; 137 138 case SDL_JOYBUTTONUP: 139 case SDL_JOYBUTTONDOWN: 140 m_joysticks[event.jbutton.which].m2->SetButton(event.jbutton.button, event.jbutton.state); 141 break; 104 142 } 105 143 } … … 113 151 #endif 114 152 #endif 115 }116 117 SdlInput::~SdlInput()118 {119 delete data;120 153 } 121 154 -
trunk/src/platform/sdl/sdlinput.h
r1310 r1342 35 35 36 36 private: 37 SdlInputData * data;37 SdlInputData *m_data; 38 38 }; 39 39 -
trunk/win32/lolcore.vcxproj
r1307 r1342 99 99 <ClCompile Include="..\src\image\codec\sdl-image.cpp" /> 100 100 <ClCompile Include="..\src\image\image.cpp" /> 101 <ClCompile Include="..\src\input.cpp" /> 101 <ClCompile Include="..\src\input\input.cpp" /> 102 <ClCompile Include="..\src\input\stick.cpp" /> 102 103 <ClCompile Include="..\src\layer.cpp" /> 103 104 <ClCompile Include="..\src\log.cpp" /> … … 150 151 <ClInclude Include="..\src\image\image-private.h" /> 151 152 <ClInclude Include="..\src\image\image.h" /> 152 <ClInclude Include="..\src\input.h" /> 153 <ClInclude Include="..\src\input\input.h" /> 154 <ClInclude Include="..\src\input\stick.h" /> 153 155 <ClInclude Include="..\src\layer.h" /> 154 156 <ClInclude Include="..\src\log.h" /> -
trunk/win32/lolcore.vcxproj.filters
r1313 r1342 42 42 <UniqueIdentifier>{317cb5cc-5dcc-4e14-be90-40a125a2e2ec}</UniqueIdentifier> 43 43 </Filter> 44 <Filter Include="src\input"> 45 <UniqueIdentifier>{94992c0e-ebc5-4185-b766-323b06547dcf}</UniqueIdentifier> 46 </Filter> 44 47 </ItemGroup> 45 48 <ItemGroup> … … 101 104 <Filter>src</Filter> 102 105 </ClCompile> 103 <ClCompile Include="..\src\input.cpp">104 <Filter>src</Filter>105 </ClCompile>106 106 <ClCompile Include="..\src\layer.cpp"> 107 107 <Filter>src</Filter> … … 196 196 <ClCompile Include="..\src\gpu\indexbuffer.cpp"> 197 197 <Filter>src\gpu</Filter> 198 </ClCompile> 199 <ClCompile Include="..\src\input\input.cpp"> 200 <Filter>src\input</Filter> 201 </ClCompile> 202 <ClCompile Include="..\src\input\stick.cpp"> 203 <Filter>src\input</Filter> 198 204 </ClCompile> 199 205 </ItemGroup> … … 259 265 <Filter>src</Filter> 260 266 </ClInclude> 261 <ClInclude Include="..\src\input.h">262 <Filter>src</Filter>263 </ClInclude>264 267 <ClInclude Include="..\src\layer.h"> 265 268 <Filter>src</Filter> … … 373 376 <Filter>src\lol</Filter> 374 377 </ClInclude> 378 <ClInclude Include="..\src\input\input.h"> 379 <Filter>src\input</Filter> 380 </ClInclude> 381 <ClInclude Include="..\src\input\stick.h"> 382 <Filter>src\input</Filter> 383 </ClInclude> 375 384 </ItemGroup> 376 385 </Project>
Note: See TracChangeset
for help on using the changeset viewer.