From e8bb8c0b64b435b9759b910e59fa6dc167a31abb Mon Sep 17 00:00:00 2001 From: Anselme Date: Wed, 14 Dec 2016 12:22:36 +0100 Subject: [PATCH] add escape key for quitting, fixed shell input toggle key, fixel no de-indexing when removeChild is called on a GraphicalContainerNode --- src/engine.cpp | 22 +++++++++++++++++++++- src/engine.h | 8 +++++++- src/scene/graphicalcontainernode.cpp | 1 + src/sparrowshell/sparrowshell.cpp | 4 +--- src/test/main.cpp | 11 +++++++---- 5 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/engine.cpp b/src/engine.cpp index ec82f35..c694c4a 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -17,7 +17,9 @@ Engine::Engine() : m_input(nullptr), m_world(nullptr), m_physicsDebugNode(nullptr), - m_togglePhysicsDebugAction(NO_ACTION) + m_togglePhysicsDebugAction(NO_ACTION), + m_toggleShellAction(NO_ACTION), + m_exitGameAction(NO_ACTION) { m_clock = new sf::Clock(); m_clock->restart(); @@ -161,6 +163,16 @@ void Engine::setTogglePhysicsDebugAction(int action) m_togglePhysicsDebugAction = action; } +void Engine::setToggleShellAction(int action) +{ + m_toggleShellAction = action; +} + +void Engine::setExitGameAction(int action) +{ + m_exitGameAction = action; +} + void Engine::outputShell(std::string str) const { m_sparrowshell->out(str); @@ -177,6 +189,14 @@ void Engine::checkSpecialInputs() else disablePhysicsDebug(); } + else if(action == m_toggleShellAction) + { + m_sparrowshell->toggleShell(); + } + else if(action == m_exitGameAction) + { + m_running = false; + } } } diff --git a/src/engine.h b/src/engine.h index e197f9c..c0e2389 100644 --- a/src/engine.h +++ b/src/engine.h @@ -31,7 +31,11 @@ public: void enablePhysicsDebug(); void disablePhysicsDebug(); + + // special inputs void setTogglePhysicsDebugAction(int action); + void setToggleShellAction(int action); + void setExitGameAction(int action); void start(); void stop(); @@ -61,11 +65,13 @@ private: SparrowShell* m_sparrowshell; btDiscreteDynamicsWorld* m_world; PhysicsDebugNode *m_physicsDebugNode; - int m_togglePhysicsDebugAction; SparrowRenderer* m_renderer; void update(); + int m_togglePhysicsDebugAction; + int m_toggleShellAction; + int m_exitGameAction; void checkSpecialInputs(); }; diff --git a/src/scene/graphicalcontainernode.cpp b/src/scene/graphicalcontainernode.cpp index 848e6d5..a6e500f 100644 --- a/src/scene/graphicalcontainernode.cpp +++ b/src/scene/graphicalcontainernode.cpp @@ -50,6 +50,7 @@ void GraphicalContainerNode::removeChild(GraphicalNode *node) { m_children.erase(it); node->m_parent = nullptr; + node->setSceneTree(nullptr); } } } diff --git a/src/sparrowshell/sparrowshell.cpp b/src/sparrowshell/sparrowshell.cpp index 8266314..ae94985 100644 --- a/src/sparrowshell/sparrowshell.cpp +++ b/src/sparrowshell/sparrowshell.cpp @@ -98,9 +98,7 @@ void SparrowShell::update(){ m_indexMoved = false; auto input = getEngine().getInput(); for(auto action : input->getActions()){ - if(action == 15){ - toggleShell(); - }else if(action == 6){ + if(action == 6){ out("Plop"); } } diff --git a/src/test/main.cpp b/src/test/main.cpp index 2d9e316..9527c05 100644 --- a/src/test/main.cpp +++ b/src/test/main.cpp @@ -31,7 +31,7 @@ class myKeysMap : public IKeysMap{ public: - enum{MAIN_ACTION, SECONDARY_ACTION, MOVE_FORWARD, MOVE_BACKWARD, STRAFE_LEFT, STRAFE_RIGHT, TOGGLE_NOCLIP, TOGGLE_PHYSICS_DEBUG, TOGGLE_CONSOLE = 15}; + enum{MAIN_ACTION, SECONDARY_ACTION, MOVE_FORWARD, MOVE_BACKWARD, STRAFE_LEFT, STRAFE_RIGHT, TOGGLE_NOCLIP, TOGGLE_PHYSICS_DEBUG, TOGGLE_CONSOLE, EXIT_GAME}; myKeysMap(){ keys.push_back( {MAIN_ACTION, sf::Keyboard::KeyCount + sf::Mouse::Left, IKeysMap::PRESSED} ); @@ -43,11 +43,12 @@ public: keys.push_back( {TOGGLE_NOCLIP, sf::Keyboard::G, IKeysMap::PRESSED} ); keys.push_back( {TOGGLE_PHYSICS_DEBUG, sf::Keyboard::P, IKeysMap::PRESSED} ); keys.push_back( {TOGGLE_CONSOLE, sf::Keyboard::F3, IKeysMap::PRESSED} ); + keys.push_back( {EXIT_GAME, sf::Keyboard::Escape, IKeysMap::PRESSED} ); } static std::vector getMap() { - return {MAIN_ACTION, SECONDARY_ACTION, MOVE_FORWARD, MOVE_BACKWARD, STRAFE_LEFT, STRAFE_RIGHT, TOGGLE_NOCLIP, TOGGLE_PHYSICS_DEBUG, TOGGLE_CONSOLE}; + return {MAIN_ACTION, SECONDARY_ACTION, MOVE_FORWARD, MOVE_BACKWARD, STRAFE_LEFT, STRAFE_RIGHT, TOGGLE_NOCLIP, TOGGLE_PHYSICS_DEBUG, TOGGLE_CONSOLE, EXIT_GAME}; } }; @@ -128,7 +129,7 @@ int main(){ // this creates the opengl context // the opengl context must exist before any opengl class is used (texture, pipeline, etc..) - engine.createWindow("Sparrow Engine Testing Environment"); + engine.createWindow("Sparrow Engine Testing Environment", 1920, 1080, false); // setting up SparrowEngine engine.initPhysics(); @@ -142,6 +143,8 @@ int main(){ input->setCurrentContext("default"); input->updateKeyBindings(); engine.setTogglePhysicsDebugAction(myKeysMap::TOGGLE_PHYSICS_DEBUG); + engine.setToggleShellAction(myKeysMap::TOGGLE_CONSOLE); + engine.setExitGameAction(myKeysMap::EXIT_GAME); /* // trackball camera @@ -169,7 +172,7 @@ int main(){ scene->getRootObject()->addChild(sunLight); // terrain - //generateTerrain(scene, engine.getPhysics()); + generateTerrain(scene, engine.getPhysics()); // shell output tests engine.outputShell("Hello World!");