[DEV] rework to record event in the main loop

This commit is contained in:
Edouard DUPIN 2015-08-31 15:53:48 +02:00
parent 5c5a3d7dee
commit 718b0b0964
13 changed files with 261 additions and 108 deletions

View File

@ -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<gale::Widget> _source,
std::shared_ptr<gale::Widget> _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<gale::context::LoopAction> 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<gale::Application> 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<gale::Application>(_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<gale::context::LoopActionKeyboard>(_special
m_msgSystem.post(std::make_shared<gale::context::LoopActionKeyboard>(_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<gale::context::LoopActionKeyboard>(_special
m_msgSystem.post(std::make_shared<gale::context::LoopActionKeyboard>(_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<gale::context::LoopActionClipboardArrive>(_clipboardID));
}
void gale::Context::clipBoardGet(enum gale::context::clipBoard::clipboardListe _clipboardID) {

View File

@ -10,6 +10,7 @@
#define __GALE_CONTEXT_H__
#include <etk/os/Fifo.h>
#include <etk/os/FSNode.h>
#include <gale/debug.h>
#include <gale/gale.h>
#include <gale/key/key.h>
@ -22,15 +23,13 @@
#include <memory>
#include <gale/orientation.h>
#include <gale/context/clipBoard.h>
#include <gale/context/LoopAction.h>
#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<gale::Application> 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<gale::eSystemMessage*> m_msgSystem;
etk::Fifo<std::shared_ptr<gale::context::LoopAction> > m_msgSystem;
bool m_displayFps;
gale::context::Fps m_FpsSystemEvent;
gale::context::Fps m_FpsSystemContext;

View File

@ -6,6 +6,24 @@
* @license APACHE v2.0 (see license file)
*/
#include <unistd.h>
#include <etk/types.h>
#include <etk/etk.h>
#include <etk/tool.h>
#include <etk/os/Fifo.h>
#include <etk/Hash.h>
#include <etk/thread/tools.h>
#include <mutex>
#include <date/date.h>
#include <gale/gale.h>
#include <gale/Dimension.h>
#include <gale/debug.h>
#include <gale/context/LoopAction.h>
#include <gale/context/Context.h>
etk::Hash<std::function<std::shared_ptr<gale::context::LoopAction>(const std::string&)> >& getList() {
static etk::Hash<std::function<std::shared_ptr<gale::context::LoopAction>(const std::string&)> > list;
return list;
@ -30,7 +48,7 @@ void gale::context::addFactory(const std::string& _type, const std::function<std
return;
}
//Keep name in lower case :
std::string nameLower = etk::tolower(_name);
std::string nameLower = etk::tolower(_type);
if (true == getList().exist(nameLower)) {
GALE_WARNING("Replace Creator of a loop action : " << nameLower);
getList()[nameLower] = _func;
@ -48,18 +66,24 @@ gale::context::LoopAction::~LoopAction() {
}
/////////////////////////////////////////////////////////////////////////////////////////
void gale::context::LoopActionInit::doAction(gale::Context& _context) {
std::shared_ptr<gale::Application> 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<gale::Application> 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<gale::Application> 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<gale::Application> 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);
}
/////////////////////////////////////////////////////////////////////////////////////////

View File

@ -14,25 +14,10 @@
#include <gale/gale.h>
#include <gale/key/key.h>
#include <memory>
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<LoopAction> 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<std::shared_ptr<LoopAction>(const std::string&)>& _func);
class LoopAction : public std::enable_shared_from_this<LoopAction> {
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<LoopAction> 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<std::shared_ptr<LoopAction>(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();
};
}
}

View File

@ -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<enum gale::context::clipBoard::clipboardListe>(const enum gale::context::clipBoard::clipboardListe& _obj) {
return clipboardDescriptionString[_obj];
}
}
void gale::context::clipBoard::init() {
GALE_INFO("Initialyse ClipBoards");

View File

@ -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<gale::key::Special>(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;
}
}

View File

@ -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);
};
};

View File

@ -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<enum gale::key::keyboard>(const enum gale::key::keyboard& _obj) {
return keyboardDescriptionString[_obj];
}
}

View File

@ -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<enum gale::key::status>(const enum gale::key::status& _obj) {
return statusDescriptionString[_obj];
}
}

View File

@ -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<enum gale::key::type>(const enum gale::key::type& _obj) {
return typeDescriptionString[_obj];
}
}

View File

@ -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);

View File

@ -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":

Binary file not shown.