From c47d0f8c62dc18d49306f7ef2c4cd2ce8029a01d Mon Sep 17 00:00:00 2001 From: Lolbot Date: Tue, 23 Jul 2013 19:39:21 +0000 Subject: [PATCH] fixed 10 files out of 2754: - removed 386 CR characters - removed 4 trailing whitespaces - replaced 189 tabs with spaces --- demos/tutorial/07_input.cpp | 2 +- demos/tutorial/11_fractal.cpp | 2 +- src/input/controller.cpp | 148 +++++++++++++++---------------- src/input/controller.h | 86 +++++++++--------- src/input/inputdevice.h | 8 +- src/input/inputdevice_internal.h | 8 +- src/platform/d3d9/d3d9input.cpp | 28 +++--- src/platform/sdl/sdlapp.cpp | 10 +-- src/platform/sdl/sdlinput.cpp | 26 +++--- 9 files changed, 159 insertions(+), 159 deletions(-) diff --git a/demos/tutorial/07_input.cpp b/demos/tutorial/07_input.cpp index a3dc46fe..0df2c76b 100644 --- a/demos/tutorial/07_input.cpp +++ b/demos/tutorial/07_input.cpp @@ -215,7 +215,7 @@ int main(int argc, char **argv) new DebugFps(5, 5); new Cube(); - controller = new Controller(KEY_MAX, AXIS_MAX); + controller = new Controller(KEY_MAX, AXIS_MAX); controller->GetKey(KEY_MANUAL_ROTATION).Bind("Keyboard", "Space"); controller->GetKey(KEY_DRAG_MESH).Bind("Mouse", "ButtonLeft"); controller->GetAxis(AXIS_DRAG_PITCH).Bind("Mouse", "Y"); diff --git a/demos/tutorial/11_fractal.cpp b/demos/tutorial/11_fractal.cpp index e40b7272..75ce1c2d 100644 --- a/demos/tutorial/11_fractal.cpp +++ b/demos/tutorial/11_fractal.cpp @@ -175,7 +175,7 @@ public: rcmplx worldmouse = m_center + rcmplx(ScreenToWorldOffset(m_mousepos)); - uint32_t buttons = 0; + uint32_t buttons = 0; //uint32_t buttons = Input::GetMouseButtons(); #if !defined __CELLOS_LV2__ && !defined _XBOX if (buttons & 0x2) diff --git a/src/input/controller.cpp b/src/input/controller.cpp index abf91d26..d488c82c 100644 --- a/src/input/controller.cpp +++ b/src/input/controller.cpp @@ -24,19 +24,19 @@ namespace lol void KeyBinding::Bind(const char* device_name, const char* key_name) { - m_device = InputDevice::Get(device_name); - if (!m_device) - { - Log::Warn("Trying to bind controller to device %s which doesn't exist", device_name); - return; - } - - m_keyindex = m_device->GetKeyIndex(key_name); - - if (m_keyindex < 0) - { - Log::Warn("Trying to bind controller to key %s.%s which doesn't exist", device_name, key_name); - } + m_device = InputDevice::Get(device_name); + if (!m_device) + { + Log::Warn("Trying to bind controller to device %s which doesn't exist", device_name); + return; + } + + m_keyindex = m_device->GetKeyIndex(key_name); + + if (m_keyindex < 0) + { + Log::Warn("Trying to bind controller to key %s.%s which doesn't exist", device_name, key_name); + } } /////////////////////////////////////////////////////////////////////////////// @@ -44,19 +44,19 @@ void KeyBinding::Bind(const char* device_name, const char* key_name) void AxisBinding::Bind(const char* device_name, const char* axis_name) { - m_device = InputDevice::Get(device_name); - if (!m_device) - { - Log::Warn("Trying to bind controller to device %s which doesn't exist", device_name); - return; - } - - m_axisindex = m_device->GetAxisIndex(axis_name); - - if (m_axisindex < 0) - { - Log::Warn("Trying to bind controller to axis %s.%s which doesn't exist", device_name, axis_name); - } + m_device = InputDevice::Get(device_name); + if (!m_device) + { + Log::Warn("Trying to bind controller to device %s which doesn't exist", device_name); + return; + } + + m_axisindex = m_device->GetAxisIndex(axis_name); + + if (m_axisindex < 0) + { + Log::Warn("Trying to bind controller to axis %s.%s which doesn't exist", device_name, axis_name); + } } @@ -67,79 +67,79 @@ Array Controller::controllers; Controller::Controller(int nb_keys, int nb_axis) { - m_gamegroup = GAMEGROUP_BEFORE; - m_nb_keys = nb_keys; - m_nb_axis = nb_axis; - m_keys = new KeyBinding[m_nb_keys]; - m_axis = new AxisBinding[m_nb_axis]; - m_activate_nextframe = false; - m_deactivate_nextframe = false; - m_active = false; - controllers.Push(this); + m_gamegroup = GAMEGROUP_BEFORE; + m_nb_keys = nb_keys; + m_nb_axis = nb_axis; + m_keys = new KeyBinding[m_nb_keys]; + m_axis = new AxisBinding[m_nb_axis]; + m_activate_nextframe = false; + m_deactivate_nextframe = false; + m_active = false; + controllers.Push(this); } Controller::~Controller() { - for (int i = 0; i < controllers.Count(); ++i) - { - if (controllers[i] == this) - { - controllers.Remove(i); - break; - } - } + for (int i = 0; i < controllers.Count(); ++i) + { + if (controllers[i] == this) + { + controllers.Remove(i); + break; + } + } } void Controller::TickGame(float seconds) { - Entity::TickGame(seconds); + Entity::TickGame(seconds); - for (int i = 0; i < m_nb_keys; ++i) - { - m_keys[i].Update(); - } + for (int i = 0; i < m_nb_keys; ++i) + { + m_keys[i].Update(); + } - for (int i = 0; i < m_nb_axis; ++i) - { - m_axis[i].Update(); - } + for (int i = 0; i < m_nb_axis; ++i) + { + m_axis[i].Update(); + } - if (m_activate_nextframe) - m_active = true; + if (m_activate_nextframe) + m_active = true; - if (m_deactivate_nextframe) - m_active = false; + if (m_deactivate_nextframe) + m_active = false; - m_activate_nextframe = false; - m_deactivate_nextframe = false; + m_activate_nextframe = false; + m_deactivate_nextframe = false; } void Controller::Activate() { - m_activate_nextframe = true; - m_deactivate_nextframe = false; + m_activate_nextframe = true; + m_deactivate_nextframe = false; } void Controller::Deactivate() { - m_deactivate_nextframe = true; - m_activate_nextframe = false; + m_deactivate_nextframe = true; + m_activate_nextframe = false; } Array Controller::DeactivateAll() { - Array result; - - for (int i = 0; i < controllers.Count(); ++i) - { - if (controllers[i]->m_active || controllers[i]->m_activate_nextframe) - { - result.Push(controllers[i]); - controllers[i]->Deactivate(); - } - } - - return result; + Array result; + + for (int i = 0; i < controllers.Count(); ++i) + { + if (controllers[i]->m_active || controllers[i]->m_activate_nextframe) + { + result.Push(controllers[i]); + controllers[i]->Deactivate(); + } + } + + return result; } } /* namespace lol */ diff --git a/src/input/controller.h b/src/input/controller.h index 71cfe703..f7774b46 100644 --- a/src/input/controller.h +++ b/src/input/controller.h @@ -21,77 +21,77 @@ namespace lol class KeyBinding { public: - KeyBinding() : m_current(false), m_previous(false), m_device(nullptr) {} + KeyBinding() : m_current(false), m_previous(false), m_device(nullptr) {} - bool IsDown() const { return m_current; } - bool IsUp() const { return !m_current; } - bool IsPressed() const { return m_current && !m_previous; } - bool IsReleased() const { return !m_current && m_previous; } + bool IsDown() const { return m_current; } + bool IsUp() const { return !m_current; } + bool IsPressed() const { return m_current && !m_previous; } + bool IsReleased() const { return !m_current && m_previous; } - void Bind(const char* device_name, const char* key_name); + void Bind(const char* device_name, const char* key_name); protected: - void Update() { m_previous = m_current; m_current = m_device ? m_device->GetKey(m_keyindex) : false; } + void Update() { m_previous = m_current; m_current = m_device ? m_device->GetKey(m_keyindex) : false; } - const InputDevice* m_device; - int m_keyindex; - bool m_current; - bool m_previous; + const InputDevice* m_device; + int m_keyindex; + bool m_current; + bool m_previous; - friend class Controller; + friend class Controller; }; class AxisBinding { public: - AxisBinding() : m_current(0.0f), m_previous(0.0f), m_device(nullptr) {} + AxisBinding() : m_current(0.0f), m_previous(0.0f), m_device(nullptr) {} - float GetValue() const { return m_current; } - float GetDelta() const { return m_current - m_previous; } + float GetValue() const { return m_current; } + float GetDelta() const { return m_current - m_previous; } - void Bind(const char* device_name, const char* axis_name); + void Bind(const char* device_name, const char* axis_name); protected: - void Update() { m_previous = m_current; m_current = m_device ? m_device->GetAxis(m_axisindex) : 0.0f; } + void Update() { m_previous = m_current; m_current = m_device ? m_device->GetAxis(m_axisindex) : 0.0f; } - const InputDevice* m_device; - int m_axisindex; - float m_current; - float m_previous; + const InputDevice* m_device; + int m_axisindex; + float m_current; + float m_previous; - friend class Controller; + friend class Controller; }; class Controller : Entity { public: - Controller(int nb_keys, int nb_axis); - ~Controller(); + Controller(int nb_keys, int nb_axis); + ~Controller(); - virtual void TickGame(float seconds); + virtual void TickGame(float seconds); - /** Activate the controller on next frame */ - void Activate(); - /** Deactivate the controller on next frame */ - void Deactivate(); - /** Deactivate every active controller on next frame and return an array of deactivated (previously active) controllers */ - static Array DeactivateAll(); + /** Activate the controller on next frame */ + void Activate(); + /** Deactivate the controller on next frame */ + void Deactivate(); + /** Deactivate every active controller on next frame and return an array of deactivated (previously active) controllers */ + static Array DeactivateAll(); + + KeyBinding& GetKey(int index) { ASSERT(index >= 0 && index < m_nb_keys); return m_keys[index]; } + AxisBinding& GetAxis(int index) { ASSERT(index >= 0 && index < m_nb_axis); return m_axis[index]; } - KeyBinding& GetKey(int index) { ASSERT(index >= 0 && index < m_nb_keys); return m_keys[index]; } - AxisBinding& GetAxis(int index) { ASSERT(index >= 0 && index < m_nb_axis); return m_axis[index]; } - protected: - KeyBinding* m_keys; - AxisBinding* m_axis; - int m_nb_keys; - int m_nb_axis; - + KeyBinding* m_keys; + AxisBinding* m_axis; + int m_nb_keys; + int m_nb_axis; + private: - static Array controllers; - bool m_activate_nextframe; - bool m_deactivate_nextframe; - bool m_active; + static Array controllers; + bool m_activate_nextframe; + bool m_deactivate_nextframe; + bool m_active; }; } /* namespace lol */ diff --git a/src/input/inputdevice.h b/src/input/inputdevice.h index f382ef65..ab78d8c7 100644 --- a/src/input/inputdevice.h +++ b/src/input/inputdevice.h @@ -55,11 +55,11 @@ public: /** Get an input device by its name */ static InputDevice* Get(const char* name) { return GetDevice(name); } - /** Set whether the mouse cursor should be captured. */ - static void CaptureMouse(bool activated) { m_capturemouse = activated; } + /** Set whether the mouse cursor should be captured. */ + static void CaptureMouse(bool activated) { m_capturemouse = activated; } protected: - // TODO: hide all of this in a InputDeviceData? + // TODO: hide all of this in a InputDeviceData? String m_name; @@ -74,7 +74,7 @@ protected: /** cursor position */ Array m_cursors; - static bool m_capturemouse; + static bool m_capturemouse; InputDevice(const char* name) : m_name(name) { diff --git a/src/input/inputdevice_internal.h b/src/input/inputdevice_internal.h index b1b91e3c..2e47265c 100644 --- a/src/input/inputdevice_internal.h +++ b/src/input/inputdevice_internal.h @@ -29,12 +29,12 @@ public: void AddCursor(const char* name); void SetKey(int index, bool state) { m_keys[index] = state; } - void SetAxis(int index, float value) { m_axis[index].m1 = value; } - void SetCursor(int index, const vec2& position, const ivec2& pixel) { m_cursors[index].m1 = position; m_cursors[index].m2 = pixel; } + void SetAxis(int index, float value) { m_axis[index].m1 = value; } + void SetCursor(int index, const vec2& position, const ivec2& pixel) { m_cursors[index].m1 = position; m_cursors[index].m2 = pixel; } - static bool GetMouseCapture() { return m_capturemouse; } + static bool GetMouseCapture() { return m_capturemouse; } - static InputDeviceInternal* CreateStandardKeyboard(); + static InputDeviceInternal* CreateStandardKeyboard(); static InputDeviceInternal* CreateStandardMouse(); }; diff --git a/src/platform/d3d9/d3d9input.cpp b/src/platform/d3d9/d3d9input.cpp index 23d99dcc..17ef2ec3 100644 --- a/src/platform/d3d9/d3d9input.cpp +++ b/src/platform/d3d9/d3d9input.cpp @@ -59,14 +59,14 @@ D3d9Input::D3d9Input() if (XInputGetState(i, &state) != ERROR_SUCCESS) continue; #if defined LOL_INPUT_V2 - // TODO: we can put more friendly name here, such as LeftAxisX, ButtonX... - InputDeviceInternal* stick = new InputDeviceInternal(String::Printf("Joystick%d", i+1).C()); - for (int j = 0; j < 4; ++j) - stick->AddAxis(String::Printf("Axis%d", j+1).C()); - for (int j = 0; j < 16; ++j) - stick->AddKey(String::Printf("Button%d", j+1).C()); - - m_data->m_joysticks.Push(i, stick); + // TODO: we can put more friendly name here, such as LeftAxisX, ButtonX... + InputDeviceInternal* stick = new InputDeviceInternal(String::Printf("Joystick%d", i+1).C()); + for (int j = 0; j < 4; ++j) + stick->AddAxis(String::Printf("Axis%d", j+1).C()); + for (int j = 0; j < 16; ++j) + stick->AddKey(String::Printf("Button%d", j+1).C()); + + m_data->m_joysticks.Push(i, stick); #else Stick *stick = Input::CreateStick(); stick->SetAxisCount(4); @@ -86,11 +86,11 @@ D3d9Input::~D3d9Input() while (m_data->m_joysticks.Count()) { #if defined LOL_INPUT_V2 - delete m_data->m_joysticks[0].m2; + delete m_data->m_joysticks[0].m2; #else - Input::DestroyStick(m_data->m_joysticks[0].m2); + Input::DestroyStick(m_data->m_joysticks[0].m2); #endif // LOL_INPUT_V2 - m_data->m_joysticks.Remove(0); + m_data->m_joysticks.Remove(0); } #endif delete m_data; @@ -119,11 +119,11 @@ void D3d9Input::TickDraw(float seconds) for (int b = 0; b < 16; b++) #if defined LOL_INPUT_V2 - m_data->m_joysticks[i].m2->SetKey(b, ((uint16_t)(state.Gamepad.wButtons) >> b) & 1); + m_data->m_joysticks[i].m2->SetKey(b, ((uint16_t)(state.Gamepad.wButtons) >> b) & 1); #else - m_data->m_joysticks[i].m2->SetButton(b, ((uint16_t)(state.Gamepad.wButtons) >> b) & 1); + m_data->m_joysticks[i].m2->SetButton(b, ((uint16_t)(state.Gamepad.wButtons) >> b) & 1); #endif // LOL_INPUT_V2 - } + } #endif } diff --git a/src/platform/sdl/sdlapp.cpp b/src/platform/sdl/sdlapp.cpp index bbd93a00..c835b83f 100644 --- a/src/platform/sdl/sdlapp.cpp +++ b/src/platform/sdl/sdlapp.cpp @@ -67,9 +67,9 @@ SdlApp::SdlApp(char const *title, ivec2 res, float fps) : } # ifdef LOL_INPUT_V2 - const SDL_VideoInfo* vidinfo = SDL_GetVideoInfo(); - int screen_w = vidinfo->current_w; - int screen_h = vidinfo->current_h; + const SDL_VideoInfo* vidinfo = SDL_GetVideoInfo(); + int screen_w = vidinfo->current_w; + int screen_h = vidinfo->current_h; # endif # if defined USE_D3D9 @@ -84,7 +84,7 @@ SdlApp::SdlApp(char const *title, ivec2 res, float fps) : SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); # ifdef LOL_INPUT_V2 - // TODO: when implementing fullscreen, be sure to overwrite screen_w and screen_h with the value of vidinfo after the call to SDL_SetVideoMode + // TODO: when implementing fullscreen, be sure to overwrite screen_w and screen_h with the value of vidinfo after the call to SDL_SetVideoMode # endif SDL_Surface *video = SDL_SetVideoMode(res.x, res.y, 0, SDL_OPENGL); # endif @@ -112,7 +112,7 @@ SdlApp::SdlApp(char const *title, ivec2 res, float fps) : # ifdef LOL_INPUT_V2 new SdlInput(video->w, video->h, screen_w, screen_h); # else - new SdlInput(); + new SdlInput(); # endif #endif } diff --git a/src/platform/sdl/sdlinput.cpp b/src/platform/sdl/sdlinput.cpp index 4ea22d30..d88f17dd 100644 --- a/src/platform/sdl/sdlinput.cpp +++ b/src/platform/sdl/sdlinput.cpp @@ -53,7 +53,7 @@ private: SdlInputData(int app_w, int app_h, int screen_w, int screen_h) : m_prevmouse(ivec2(0)), m_app_w((float)app_w), - m_app_h((float)app_h), + m_app_h((float)app_h), m_screen_w((float)screen_w), m_screen_h((float)screen_h) { } @@ -239,7 +239,7 @@ void SdlInputData::Tick(float seconds) } # if !SDL_FORCE_POLL_JOYSTICK -# ifdef LOL_INPUT_V2 +# ifdef LOL_INPUT_V2 case SDL_JOYAXISMOTION: m_joysticks[event.jaxis.which].m2->SetAxis(event.jaxis.axis, (float)event.jaxis.value / 32768.f); break; @@ -248,7 +248,7 @@ void SdlInputData::Tick(float seconds) case SDL_JOYBUTTONDOWN: m_joysticks[event.jbutton.which].m2->SetKey(event.jbutton.button, event.jbutton.state); break; -# else // !LOL_INPUT_V2 +# else // !LOL_INPUT_V2 case SDL_JOYAXISMOTION: m_joysticks[event.jaxis.which].m2->SetAxis(event.jaxis.axis, (float)event.jaxis.value / 32768.f); break; @@ -257,7 +257,7 @@ void SdlInputData::Tick(float seconds) case SDL_JOYBUTTONDOWN: m_joysticks[event.jbutton.which].m2->SetButton(event.jbutton.button, event.jbutton.state); break; -# endif // LOL_INPUT_V2 +# endif // LOL_INPUT_V2 # endif } } @@ -290,7 +290,7 @@ void SdlInputData::Tick(float seconds) # else // !LOL_INPUT_V2 Input::SetMousePos(mouse); -# endif // LOL_INPUT_V2 +# endif // LOL_INPUT_V2 # if SDL_VERSION_ATLEAST(1,3,0) Uint8 *sdlstate = SDL_GetKeyboardState(nullptr); @@ -299,14 +299,14 @@ void SdlInputData::Tick(float seconds) # endif int keyindex = 0; -# ifdef LOL_INPUT_V2 -# define KEY_FUNC(name, index) m_keyboard->SetKey(keyindex++, sdlstate[index] != 0); -# if !defined SDLK_WORLD_0 -# define KEY_DISABLE_WORLD +# ifdef LOL_INPUT_V2 +# define KEY_FUNC(name, index) m_keyboard->SetKey(keyindex++, sdlstate[index] != 0); +# if !defined SDLK_WORLD_0 +# define KEY_DISABLE_WORLD # endif // !SDLK_WORLD_0 -# include "input/keys.h" -# undef KEY_FUNC -# else // !LOL_INPUT_V2 +# include "input/keys.h" +# undef KEY_FUNC +# else // !LOL_INPUT_V2 /* Send the whole keyboard state to the input system */ Array &lolstate = Input::GetKeyboardState(); @@ -554,7 +554,7 @@ void SdlInputData::Tick(float seconds) lolstate[Key::Undo] = sdlstate[SDLK_UNDO]; UNUSED(seconds); -# endif // LOL_INPUT_V2 +# endif // LOL_INPUT_V2 #endif // USE_SDL }