add escape key for quitting, fixed shell input toggle key, fixel no de-indexing when removeChild is called on a GraphicalContainerNode

This commit is contained in:
Anselme 2016-12-14 12:22:36 +01:00
parent 80b213a062
commit e8bb8c0b64
5 changed files with 37 additions and 9 deletions

View File

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

View File

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

View File

@ -50,6 +50,7 @@ void GraphicalContainerNode::removeChild(GraphicalNode *node)
{
m_children.erase(it);
node->m_parent = nullptr;
node->setSceneTree(nullptr);
}
}
}

View File

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

View File

@ -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<int> 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!");