diff --git a/gale/context/Context.cpp b/gale/context/Context.cpp index c2b2b60..665c569 100644 --- a/gale/context/Context.cpp +++ b/gale/context/Context.cpp @@ -76,39 +76,6 @@ void gale::Context::unLockContext() { mutexInterface().unlock(); } - -namespace gale { - class eSystemMessage { - public : - // can not set a union ... - enum gale::context::clipBoard::clipboardListe clipboardID; - // InputId - enum gale::key::type inputType; - int32_t inputId; - // generic dimentions - vec2 dimention; - // keyboard events : - bool repeateKey; //!< special flag for the repeating key on the PC interface - bool stateIsDown; - char32_t keyboardChar; - enum gale::key::keyboard keyboardMove; - gale::key::Special keyboardSpecial; - - eSystemMessage() : - clipboardID(gale::context::clipBoard::clipboardStd), - inputType(gale::key::type_unknow), - inputId(-1), - dimention(0,0), - repeateKey(false), - stateIsDown(false), - keyboardChar(0), - keyboardMove(gale::key::keyboard_unknow) - { - - } - }; -}; - #if 0 void gale::Context::inputEventTransfertWidget(std::shared_ptr _source, std::shared_ptr _destination) { @@ -128,25 +95,21 @@ void gale::Context::inputEventUnGrabPointer() { void gale::Context::processEvents() { int32_t nbEvent = 0; //GALE_DEBUG(" ******** Event"); - gale::eSystemMessage* data = nullptr; + std::shared_ptr data; while (m_msgSystem.count()>0) { nbEvent++; - if (data != nullptr) { - delete(data); - data = nullptr; - } m_msgSystem.wait(data); - //GALE_DEBUG("EVENT"); - switch (data->TypeMessage) { - case eSystemMessage::msgClipboardArrive: - { - std::shared_ptr appl = m_application; - if (appl != nullptr) { - appl->onClipboardEvent(data->clipboardID); - } - } - break; + if (data == nullptr) { + continue; } + if (m_imulationActive == true) { + std::string dataExecuted = data->createString(); + m_simulationFile.filePuts(dataExecuted); + m_simulationFile.filePuts("\n"); + GALE_VERBOSE("plop: " + dataExecuted); + } + data->doAction(*this); + data.reset(); } } @@ -178,6 +141,8 @@ void gale::Context::setArchiveDir(int _mode, const char* _str) { gale::Context::Context(gale::Application* _application, int32_t _argc, const char* _argv[]) : //m_application(std::make_shared(_application)), m_application(_application), + m_imulationActive(false), + m_simulationFile("gale.gsim"), //m_objectManager(*this), m_previousDisplayTime(0), // TODO : m_input(*this), @@ -211,9 +176,9 @@ gale::Context::Context(gale::Application* _application, int32_t _argc, const cha if (m_commandLine.get(iii) == "--gale-fps") { m_displayFps=true; } else if (etk::start_with(m_commandLine.get(iii), "--gale-simulation-file=") == true) { - + m_simulationFile.setName(std::string(m_commandLine.get(iii).begin()+23, m_commandLine.get(iii).end()) ); } else if (etk::start_with(m_commandLine.get(iii), "--gale-simulation-mode=") == true) { - + m_imulationActive = true; } else if (m_commandLine.get(iii) == "--gale-simulation-stop") { #ifdef GALE_SIMULATION_OPENGL_AVAILLABLE @@ -226,7 +191,7 @@ gale::Context::Context(gale::Application* _application, int32_t _argc, const cha GALE_PRINT("gale - help : "); GALE_PRINT(" " << etk::getApplicationName() << " [options]"); GALE_PRINT(" --gale-simulation-file=XXX.gsim"); - GALE_PRINT(" Enable the simulation mode of the gale IO, parameter: file (default:simulation Gale.gsim)"); + GALE_PRINT(" Enable the simulation mode of the gale IO, parameter: file (default:simulation gale.gsim)"); GALE_PRINT(" --gale-simulation-mode=XXX"); GALE_PRINT(" Mode of the simulation"); GALE_PRINT(" - record Record all input of the playing element (default)"); @@ -273,6 +238,10 @@ gale::Context::Context(gale::Application* _application, int32_t _argc, const cha #else forceOrientation(gale::orientation_screenAuto); #endif + if (m_imulationActive == true) { + // in simulation case: + m_simulationFile.fileOpenWrite(); + } // release the curent interface : unLockContext(); GALE_INFO(" == > Gale system init (END)"); @@ -305,6 +274,10 @@ gale::Context::~Context() { // release the curent interface : unLockContext(); GALE_INFO(" == > Gale system Un-Init (END)"); + if (m_imulationActive == true) { + // in simulation case: + m_simulationFile.fileClose(); + } } void gale::Context::requestUpdateSize() { @@ -366,7 +339,7 @@ void gale::Context::OS_SetKeyboard(gale::key::Special& _special, state = gale::key::status_upRepeate; } } - m_msgSystem.post(std::make_shared(_special + m_msgSystem.post(std::make_shared(_special, gale::key::keyboard_char, state, _myChar)); @@ -384,7 +357,7 @@ void gale::Context::OS_SetKeyboardMove(gale::key::Special& _special, state = gale::key::status_upRepeate; } } - m_msgSystem.post(std::make_shared(_special + m_msgSystem.post(std::make_shared(_special, _move, state)); } @@ -399,14 +372,7 @@ void gale::Context::OS_Show() { void gale::Context::OS_ClipBoardArrive(enum gale::context::clipBoard::clipboardListe _clipboardID) { - gale::eSystemMessage *data = new gale::eSystemMessage(); - if (data == nullptr) { - GALE_ERROR("allocationerror of message"); - return; - } - data->TypeMessage = eSystemMessage::msgClipboardArrive; - data->clipboardID = _clipboardID; - m_msgSystem.post(data); + m_msgSystem.post(std::make_shared(_clipboardID)); } void gale::Context::clipBoardGet(enum gale::context::clipBoard::clipboardListe _clipboardID) { diff --git a/gale/context/Context.h b/gale/context/Context.h index 807d5fb..4905cc9 100644 --- a/gale/context/Context.h +++ b/gale/context/Context.h @@ -10,6 +10,7 @@ #define __GALE_CONTEXT_H__ #include +#include #include #include #include @@ -22,15 +23,13 @@ #include #include #include +#include #define MAX_MANAGE_INPUT (15) namespace gale { - /** - * @not-in-doc - */ - class eSystemMessage; class Context/* : private gale::object::RemoveEvent */{ + friend gale::context::LoopActionResize; private: std::shared_ptr m_application; //!< Application handle public: @@ -63,10 +62,14 @@ namespace gale { * @note this un-lock the main mutex */ void unLockContext(); + private: + // simulation area: + bool m_imulationActive; + etk::FSNode m_simulationFile; private: int64_t m_previousDisplayTime; // this is to limit framerate ... in case... // TODO : gale::context::InputManager m_input; - etk::Fifo m_msgSystem; + etk::Fifo > m_msgSystem; bool m_displayFps; gale::context::Fps m_FpsSystemEvent; gale::context::Fps m_FpsSystemContext; diff --git a/gale/context/LoopAction.cpp b/gale/context/LoopAction.cpp index f656ff8..2e2e5c1 100644 --- a/gale/context/LoopAction.cpp +++ b/gale/context/LoopAction.cpp @@ -6,6 +6,24 @@ * @license APACHE v2.0 (see license file) */ +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + etk::Hash(const std::string&)> >& getList() { static etk::Hash(const std::string&)> > list; return list; @@ -30,7 +48,7 @@ void gale::context::addFactory(const std::string& _type, const std::function appl = _context.getApplication(); // this is due to the openGL context - if (_context.m_application == nullptr) { + if (appl == nullptr) { return; } - _context.m_application->onCreate(*this); - _context.m_application->onStart(*this); - _context.m_application->onResume(*this); + appl->onCreate(_context); + appl->onStart(_context); + appl->onResume(_context); } +std::string gale::context::LoopActionInit::createString() { + return etk::to_string(m_timestamp) + ":INIT"; +} + +///////////////////////////////////////////////////////////////////////////////////////// gale::context::LoopActionResize::LoopActionResize(const vec2& _size) : m_size(_size) { @@ -72,10 +96,35 @@ void gale::context::LoopActionResize::doAction(gale::Context& _context) { _context.forceRedrawAll(); } +std::string gale::context::LoopActionResize::createString() { + return etk::to_string(m_timestamp) + ":RESIZE:" + etk::to_string(m_size); +} + +///////////////////////////////////////////////////////////////////////////////////////// +gale::context::LoopActionView::LoopActionView(bool _show) : + m_show(_show) { + +} + +void gale::context::LoopActionView::doAction(gale::Context& _context) { + GALE_TODO("kjhkjhkhkjh"); +} + +std::string gale::context::LoopActionView::createString() { + return etk::to_string(m_timestamp) + ":VIEW:" + etk::to_string(m_show); +} + +///////////////////////////////////////////////////////////////////////////////////////// + void gale::context::LoopActionRecalculateSize::doAction(gale::Context& _context) { _context.forceRedrawAll(); } +std::string gale::context::LoopActionRecalculateSize::createString() { + return etk::to_string(m_timestamp) + ":RECALCULATE_SIZE"; +} + +///////////////////////////////////////////////////////////////////////////////////////// gale::context::LoopActionInput::LoopActionInput(enum gale::key::type _type, enum gale::key::status _status, int32_t _pointerID, @@ -88,15 +137,22 @@ gale::context::LoopActionInput::LoopActionInput(enum gale::key::type _type, } void gale::context::LoopActionInput::doAction(gale::Context& _context) { - if (_context.m_application == nullptr) { + std::shared_ptr appl = _context.getApplication(); + if (appl == nullptr) { return; } - _context.m_application->onPointer(m_type, - m_pointerID, - m_pos, - m_status); + appl->onPointer(m_type, + m_pointerID, + m_pos, + m_status); } +std::string gale::context::LoopActionInput::createString() { + return etk::to_string(m_timestamp) + ":INPUT:" + etk::to_string(m_type) + ":" + etk::to_string(m_status) + ":" + etk::to_string(m_pointerID) + ":" + etk::to_string(m_pos); +} + +///////////////////////////////////////////////////////////////////////////////////////// + gale::context::LoopActionKeyboard::LoopActionKeyboard(const gale::key::Special& _special, enum gale::key::keyboard _type, enum gale::key::status _state, @@ -109,11 +165,38 @@ gale::context::LoopActionKeyboard::LoopActionKeyboard(const gale::key::Special& } void gale::context::LoopActionKeyboard::doAction(gale::Context& _context) { - if (_context.m_application == nullptr) { + std::shared_ptr appl = _context.getApplication(); + if (appl == nullptr) { return; } - _context.m_application->onKeyboard(m_special, - m_type, - m_char, - m_state); + appl->onKeyboard(m_special, + m_type, + m_char, + m_state); } + +std::string gale::context::LoopActionKeyboard::createString() { + return etk::to_string(m_timestamp) + ":KEYBOARD:" + etk::to_string(m_special) + ":" + etk::to_string(m_type) + ":" + etk::to_string(m_state) + ":" + etk::to_string(uint64_t(m_char)); +} + +///////////////////////////////////////////////////////////////////////////////////////// + +gale::context::LoopActionClipboardArrive::LoopActionClipboardArrive(enum gale::context::clipBoard::clipboardListe _id) : + m_id(_id) { + +} + +void gale::context::LoopActionClipboardArrive::doAction(gale::Context& _context) { + std::shared_ptr appl = _context.getApplication(); + if (appl != nullptr) { + appl->onClipboardEvent(m_id); + } +} + +std::string gale::context::LoopActionClipboardArrive::createString() { + return etk::to_string(m_timestamp) + ":CLIPBOARD_ARRIVE:" + etk::to_string(m_id); +} + +///////////////////////////////////////////////////////////////////////////////////////// + + diff --git a/gale/context/LoopAction.h b/gale/context/LoopAction.h index c99b8d8..47d8b9a 100644 --- a/gale/context/LoopAction.h +++ b/gale/context/LoopAction.h @@ -14,25 +14,10 @@ #include #include #include -m_timestamp #define MAX_MANAGE_INPUT (15) namespace gale { namespace context { - /** - * @brief Create action from the simulation string line - * @param[in] _lineToParse Simulation string line - * @return Created action. - */ - std::shared_ptr createAction(const std::string& _lineToParse); - - /** - * @brief Add a factory to create an event from a specific type - * @param[in] _type Type of the action - * @param[in] _func function to call to create - * @return Created action. - */ - void addFactory(const std::string& _type, const std::function(const std::string&)>& _func); class LoopAction : public std::enable_shared_from_this { protected: @@ -41,35 +26,66 @@ namespace gale { LoopAction(); virtual ~LoopAction(); virtual void doAction(gale::Context& _context) = 0; - virtual std::string createString() { return "" }; - } + virtual std::string createString() = 0; + }; + /** + * @brief Create action from the simulation string line + * @param[in] _lineToParse Simulation string line + * @return Created action. + */ + std::shared_ptr createAction(const std::string& _lineToParse); + /** + * @brief Add a factory to create an event from a specific type + * @param[in] _type Type of the action + * @param[in] _func function to call to create + * @return Created action. + */ + void addFactory(const std::string& _type, const std::function(const std::string&)>& _func); + class LoopActionInit : public LoopAction { public: LoopActionInit() {}; virtual void doAction(gale::Context& _context); - } + virtual std::string createString(); + }; + class LoopActionResize : public LoopAction { protected: vec2 m_size; public: LoopActionResize(const vec2& _size); virtual void doAction(gale::Context& _context); - } + virtual std::string createString(); + }; + + class LoopActionView : public LoopAction { + protected: + bool m_show; + public: + LoopActionView(bool _show); + virtual void doAction(gale::Context& _context); + virtual std::string createString(); + }; + class LoopActionRecalculateSize : public LoopAction { public: LoopActionRecalculateSize() {}; virtual void doAction(gale::Context& _context); - } + virtual std::string createString(); + }; + class LoopActionInput : public LoopAction { private: enum gale::key::type m_type; - enum gale::key::status m_statusm + enum gale::key::status m_status; int32_t m_pointerID; const vec2& m_pos; public: LoopActionInput(enum gale::key::type _type, enum gale::key::status _status, int32_t _pointerID, const vec2& _pos); virtual void doAction(gale::Context& _context); - } + virtual std::string createString(); + }; + class LoopActionKeyboard : public LoopAction { private: gale::key::Special m_special; @@ -79,7 +95,17 @@ namespace gale { public: LoopActionKeyboard(const gale::key::Special& _special, enum gale::key::keyboard _type, enum gale::key::status _state, char32_t _char=u32char::Null); virtual void doAction(gale::Context& _context); - } + virtual std::string createString(); + }; + + class LoopActionClipboardArrive : public LoopAction { + private: + enum gale::context::clipBoard::clipboardListe m_id; + public: + LoopActionClipboardArrive(enum gale::context::clipBoard::clipboardListe _id); + virtual void doAction(gale::Context& _context); + virtual std::string createString(); + }; } } diff --git a/gale/context/clipBoard.cpp b/gale/context/clipBoard.cpp index 3de0a89..8edb30b 100644 --- a/gale/context/clipBoard.cpp +++ b/gale/context/clipBoard.cpp @@ -50,6 +50,11 @@ std::ostream& gale::operator <<(std::ostream& _os, const enum gale::context::cli return _os; } +namespace etk { + template<> std::string to_string(const enum gale::context::clipBoard::clipboardListe& _obj) { + return clipboardDescriptionString[_obj]; + } +} void gale::context::clipBoard::init() { GALE_INFO("Initialyse ClipBoards"); diff --git a/gale/key/Special.cpp b/gale/key/Special.cpp index 00f5b61..766cc1d 100644 --- a/gale/key/Special.cpp +++ b/gale/key/Special.cpp @@ -201,7 +201,7 @@ void gale::key::Special::setInsert(bool _value) { } } -std::ostream& gale::key::operator <<(std::ostream& _os, const gale::key::Special _obj) { +std::ostream& gale::key::operator <<(std::ostream& _os, const gale::key::Special& _obj) { _os << " capLock=" << _obj.getCapsLock(); _os << " shift=" << _obj.getShift(); _os << " ctrl=" << _obj.getCtrl(); @@ -212,3 +212,55 @@ std::ostream& gale::key::operator <<(std::ostream& _os, const gale::key::Special _os << " insert=" << _obj.getInsert(); return _os; } + +namespace etk { + template<> std::string to_string(const gale::key::Special& _obj) { + std::string out; + if (_obj.getCapsLock() == true) { + out = "CAPS"; + } + if (_obj.getShift() == true) { + if (out.size() > 0) { + out += "|"; + } + out = "SHIFT"; + } + if (_obj.getCtrl() == true) { + if (out.size() > 0) { + out += "|"; + } + out = "CTRL"; + } + if (_obj.getMeta() == true) { + if (out.size() > 0) { + out += "|"; + } + out = "META"; + } + if (_obj.getAlt() == true) { + if (out.size() > 0) { + out += "|"; + } + out = "ALT"; + } + if (_obj.getAltGr() == true) { + if (out.size() > 0) { + out += "|"; + } + out = "ALTGR"; + } + if (_obj.getNumLock() == true) { + if (out.size() > 0) { + out += "|"; + } + out = "NUM_LOCK"; + } + if (_obj.getInsert() == true) { + if (out.size() > 0) { + out += "|"; + } + out = "INSERT"; + } + return out; + } +} \ No newline at end of file diff --git a/gale/key/Special.h b/gale/key/Special.h index dc020f9..b524e29 100644 --- a/gale/key/Special.h +++ b/gale/key/Special.h @@ -112,7 +112,7 @@ namespace gale { */ void update(enum gale::key::keyboard _move, bool _isDown); }; - std::ostream& operator <<(std::ostream& _os, const gale::key::Special _obj); + std::ostream& operator <<(std::ostream& _os, const gale::key::Special& _obj); }; }; diff --git a/gale/key/keyboard.cpp b/gale/key/keyboard.cpp index 25c7353..cac8be4 100644 --- a/gale/key/keyboard.cpp +++ b/gale/key/keyboard.cpp @@ -60,3 +60,10 @@ std::ostream& gale::key::operator <<(std::ostream& _os, const enum gale::key::ke _os << keyboardDescriptionString[_obj]; return _os; } + +namespace etk { + template<> std::string to_string(const enum gale::key::keyboard& _obj) { + return keyboardDescriptionString[_obj]; + } +} + diff --git a/gale/key/status.cpp b/gale/key/status.cpp index 2a02e99..e885903 100644 --- a/gale/key/status.cpp +++ b/gale/key/status.cpp @@ -32,4 +32,9 @@ std::ostream& gale::key::operator <<(std::ostream& _os, const enum gale::key::st return _os; } +namespace etk { + template<> std::string to_string(const enum gale::key::status& _obj) { + return statusDescriptionString[_obj]; + } +} diff --git a/gale/key/type.cpp b/gale/key/type.cpp index 8187d00..3df9bf0 100644 --- a/gale/key/type.cpp +++ b/gale/key/type.cpp @@ -21,3 +21,8 @@ std::ostream& gale::operator <<(std::ostream& _os, const enum gale::key::type _o return _os; } +namespace etk { + template<> std::string to_string(const enum gale::key::type& _obj) { + return typeDescriptionString[_obj]; + } +} diff --git a/gale/renderer/openGL/openGL.cpp b/gale/renderer/openGL/openGL.cpp index 43a9b9d..3d11745 100644 --- a/gale/renderer/openGL/openGL.cpp +++ b/gale/renderer/openGL/openGL.cpp @@ -947,7 +947,7 @@ int32_t gale::openGL::program::getUniformLocation(int64_t _prog, const std::stri #ifdef GALE_SIMULATION_OPENGL_AVAILLABLE if (s_simulationMode == false) { #endif - GLint val = glGetUniformLocation(GLuint(_prog), _name.c_str()); + val = glGetUniformLocation(GLuint(_prog), _name.c_str()); if (val < 0) { checkGlError("glGetUniformLocation", __LINE__); GALE_WARNING("glGetUniformLocation(\"" << _name << "\") = " << val); diff --git a/lutin_gale.py b/lutin_gale.py index 4dbb36f..703d8ae 100644 --- a/lutin_gale.py +++ b/lutin_gale.py @@ -32,6 +32,7 @@ def create(target): 'gale/context/commandLine.cpp', 'gale/context/Context.cpp', 'gale/context/cursor.cpp', + 'gale/context/LoopAction.cpp', #'gale/context/InputManager.cpp' ]) if target.name=="Linux": diff --git a/sample/lutin_gale-sample-basic.pyc b/sample/lutin_gale-sample-basic.pyc deleted file mode 100644 index 74cff67..0000000 Binary files a/sample/lutin_gale-sample-basic.pyc and /dev/null differ