From 3b2c0dc00115a29c241340900637ae32caa86a22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Mon, 9 Feb 2015 20:12:46 -0800 Subject: [PATCH] Fixed static initializer order. --- examples/common/entry/cmd.cpp | 18 ++++++++-- examples/common/entry/cmd.h | 9 +++++ examples/common/entry/entry.cpp | 7 ++++ examples/common/entry/input.cpp | 61 +++++++++++++++++++-------------- examples/common/entry/input.h | 6 ++++ 5 files changed, 73 insertions(+), 28 deletions(-) diff --git a/examples/common/entry/cmd.cpp b/examples/common/entry/cmd.cpp index b31642dcc..6d58aebf0 100644 --- a/examples/common/entry/cmd.cpp +++ b/examples/common/entry/cmd.cpp @@ -7,6 +7,8 @@ #include #include // size_t #include // strlen + +#include #include #include @@ -90,14 +92,24 @@ struct CmdContext CmdLookup m_lookup; }; -static CmdContext s_cmdContext; +static CmdContext* s_cmdContext; + +void cmdInit() +{ + s_cmdContext = BX_NEW(entry::getAllocator(), CmdContext); +} + +void cmdShutdown() +{ + BX_DELETE(entry::getAllocator(), s_cmdContext); +} void cmdAdd(const char* _name, ConsoleFn _fn, void* _userData) { - s_cmdContext.add(_name, _fn, _userData); + s_cmdContext->add(_name, _fn, _userData); } void cmdExec(const char* _cmd) { - s_cmdContext.exec(_cmd); + s_cmdContext->exec(_cmd); } diff --git a/examples/common/entry/cmd.h b/examples/common/entry/cmd.h index e1b2cbad2..7873d1aed 100644 --- a/examples/common/entry/cmd.h +++ b/examples/common/entry/cmd.h @@ -9,7 +9,16 @@ struct CmdContext; typedef int (*ConsoleFn)(CmdContext* _context, void* _userData, int _argc, char const* const* _argv); +/// +void cmdInit(); + +/// +void cmdShutdown(); + +/// void cmdAdd(const char* _name, ConsoleFn _fn, void* _userData = NULL); + +/// void cmdExec(const char* _cmd); #endif // CMD_H_HEADER_GUARD diff --git a/examples/common/entry/entry.cpp b/examples/common/entry/entry.cpp index 06ac35109..232d610f5 100644 --- a/examples/common/entry/entry.cpp +++ b/examples/common/entry/entry.cpp @@ -137,10 +137,12 @@ namespace entry s_fileWriter = new bx::CrtFileWriter; #endif // BX_CONFIG_CRT_FILE_READER_WRITER + cmdInit(); cmdAdd("mouselock", cmdMouseLock); cmdAdd("graphics", cmdGraphics ); cmdAdd("exit", cmdExit ); + inputInit(); inputAddBindings("bindings", s_bindings); entry::WindowHandle defaultWindow = { 0 }; @@ -148,6 +150,11 @@ namespace entry int32_t result = ::_main_(_argc, _argv); + inputRemoveBindings("bindings"); + inputShutdown(); + + cmdShutdown(); + #if BX_CONFIG_CRT_FILE_READER_WRITER delete s_fileReader; s_fileReader = NULL; diff --git a/examples/common/entry/input.cpp b/examples/common/entry/input.cpp index 851f22643..871bc96ea 100644 --- a/examples/common/entry/input.cpp +++ b/examples/common/entry/input.cpp @@ -8,6 +8,7 @@ #include "entry_p.h" #include "input.h" +#include #include #include #include @@ -249,95 +250,105 @@ struct Input Gamepad m_gamepad[ENTRY_CONFIG_MAX_GAMEPADS]; }; -static Input s_input; +static Input* s_input; + +void inputInit() +{ + s_input = BX_NEW(entry::getAllocator(), Input); +} + +void inputShutdown() +{ + BX_DELETE(entry::getAllocator(), s_input); +} void inputAddBindings(const char* _name, const InputBinding* _bindings) { - s_input.addBindings(_name, _bindings); + s_input->addBindings(_name, _bindings); } void inputRemoveBindings(const char* _name) { - s_input.removeBindings(_name); + s_input->removeBindings(_name); } void inputProcess() { - s_input.process(); + s_input->process(); } void inputSetMouseResolution(uint16_t _width, uint16_t _height) { - s_input.m_mouse.setResolution(_width, _height); + s_input->m_mouse.setResolution(_width, _height); } void inputSetKeyState(entry::Key::Enum _key, uint8_t _modifiers, bool _down) { - s_input.m_keyboard.setKeyState(_key, _modifiers, _down); + s_input->m_keyboard.setKeyState(_key, _modifiers, _down); } void inputChar(uint8_t _len, const uint8_t _char[4]) { - s_input.m_keyboard.pushChar(_len, _char); + s_input->m_keyboard.pushChar(_len, _char); } const uint8_t* inputGetChar() { - return s_input.m_keyboard.popChar(); + return s_input->m_keyboard.popChar(); } void inputCharFlush() { - s_input.m_keyboard.charFlush(); + s_input->m_keyboard.charFlush(); } void inputSetMousePos(int32_t _mx, int32_t _my, int32_t _mz) { - s_input.m_mouse.setPos(_mx, _my, _mz); + s_input->m_mouse.setPos(_mx, _my, _mz); } void inputSetMouseButtonState(entry::MouseButton::Enum _button, uint8_t _state) { - s_input.m_mouse.setButtonState(_button, _state); + s_input->m_mouse.setButtonState(_button, _state); } void inputGetMouse(float _mouse[3]) { - _mouse[0] = s_input.m_mouse.m_norm[0]; - _mouse[1] = s_input.m_mouse.m_norm[1]; - _mouse[2] = s_input.m_mouse.m_norm[2]; - s_input.m_mouse.m_norm[0] = 0.0f; - s_input.m_mouse.m_norm[1] = 0.0f; - s_input.m_mouse.m_norm[2] = 0.0f; + _mouse[0] = s_input->m_mouse.m_norm[0]; + _mouse[1] = s_input->m_mouse.m_norm[1]; + _mouse[2] = s_input->m_mouse.m_norm[2]; + s_input->m_mouse.m_norm[0] = 0.0f; + s_input->m_mouse.m_norm[1] = 0.0f; + s_input->m_mouse.m_norm[2] = 0.0f; } bool inputIsMouseLocked() { - return s_input.m_mouse.m_lock; + return s_input->m_mouse.m_lock; } void inputSetMouseLock(bool _lock) { - if (s_input.m_mouse.m_lock != _lock) + if (s_input->m_mouse.m_lock != _lock) { - s_input.m_mouse.m_lock = _lock; + s_input->m_mouse.m_lock = _lock; entry::WindowHandle defaultWindow = { 0 }; entry::setMouseLock(defaultWindow, _lock); if (_lock) { - s_input.m_mouse.m_norm[0] = 0.0f; - s_input.m_mouse.m_norm[1] = 0.0f; - s_input.m_mouse.m_norm[2] = 0.0f; + s_input->m_mouse.m_norm[0] = 0.0f; + s_input->m_mouse.m_norm[1] = 0.0f; + s_input->m_mouse.m_norm[2] = 0.0f; } } } void inputSetGamepadAxis(entry::GamepadHandle _handle, entry::GamepadAxis::Enum _axis, int32_t _value) { - s_input.m_gamepad[_handle.idx].setAxis(_axis, _value); + s_input->m_gamepad[_handle.idx].setAxis(_axis, _value); } int32_t inputGetGamepadAxis(entry::GamepadHandle _handle, entry::GamepadAxis::Enum _axis) { - return s_input.m_gamepad[_handle.idx].getAxis(_axis); + return s_input->m_gamepad[_handle.idx].getAxis(_axis); } diff --git a/examples/common/entry/input.h b/examples/common/entry/input.h index 12d830ccc..c3f7ef182 100644 --- a/examples/common/entry/input.h +++ b/examples/common/entry/input.h @@ -21,6 +21,12 @@ struct InputBinding #define INPUT_BINDING_END { entry::Key::None, entry::Modifier::None, 0, NULL, NULL } +/// +void inputInit(); + +/// +void inputShutdown(); + /// void inputAddBindings(const char* _name, const InputBinding* _bindings);