Esempio n. 1
0
void MInputManager::Update()
{
    MEngine* engine = MEngine::getInstance();
    
    if(MInputContext* input = engine->getInputContext())
    {
	for(commandVecIter iCommand = m_Commands.begin(); 
	    iCommand != m_Commands.end(); 
	    iCommand++)
	{
	    commandDef::commandState state = (*iCommand)->state;
	    if(input->isKeyPressed((*iCommand)->command->GetKeyName()))
	    {
		switch(state)
		{
		case commandDef::eUp:
		case commandDef::eReleased:
		    (*iCommand)->command->OnKeyPressed();
		    (*iCommand)->state = commandDef::ePressed;
		    break;
		case commandDef::ePressed:
		case commandDef::eDown:
		    (*iCommand)->state = commandDef::eDown;
		    break;
		}
	    }
	    else
	    {
		switch(state)
		{
		case commandDef::eUp:
		case commandDef::eReleased:
		    (*iCommand)->state = commandDef::eUp;
		    break;
		case commandDef::ePressed:
		case commandDef::eDown:
		    (*iCommand)->command->OnKeyReleased();
		    (*iCommand)->state = commandDef::eReleased;
		    break;
		}
	    }
	}
    }
}
Esempio n. 2
0
void MGame::update(void)
{
	MEngine * engine = MEngine::getInstance();

	// run script
	if(engine->getScriptContext())
		engine->getScriptContext()->callFunction("onSceneUpdate");

	// get level
	MLevel * level = MEngine::getInstance()->getLevel();
	if(! level)
		return;

	// get current scene
	MScene * scene = level->getCurrentScene();
	if(! scene)
		return;

	// update behaviors
	unsigned int i;
	unsigned int oSize = scene->getObjectsNumber();
	for(i=0; i<oSize; i++)
	{
		MObject3d * object = scene->getObjectByIndex(i);
		if(! object->isActive())
			continue;
			
		object->updateBehaviors();
	}

	// update scene
	scene->update();

	// update physics
	scene->updatePhysics();

	// update objects matrices
	scene->updateObjectsMatrices();

	// flush input
	engine->getInputContext()->flush();
}