Пример #1
0
int Update()
{
	//处理事件
	SDL_Event sdlEvent;
	while(SDL_PollEvent(&sdlEvent))
	{
		if(HandleEvent(sdlEvent))
			return -1;
	}
	if(!gamePause)
	{
		IN_UpdateInput(); //处理输入
		if(theWorld!=NULL)
		{
			WorldUpdate(theWorld); //更新世界
		}
	}
	Gui_Update(theWorld); //更新界面
	return 0;
}
Пример #2
0
void Game_Frame(btScalar time)
{
    static btScalar game_logic_time  = 0.0;
                    game_logic_time += time;

    const bool is_character  = (engine_world.character != NULL);

    // GUI and controls should be updated at all times!

    Controls_PollSDLInput();
    Gui_Update();

    ///@FIXME: I have no idea what's happening here! - Lwmte

    if(!ConsoleInfo::instance().isVisible() && control_states.gui_inventory && main_inventory_manager)
    {
        if((is_character) &&
           (main_inventory_manager->getCurrentState() == gui_InventoryManager::INVENTORY_DISABLED))
        {
            main_inventory_manager->setInventory(&engine_world.character->m_inventory);
            main_inventory_manager->send(gui_InventoryManager::INVENTORY_OPEN);
        }
        if(main_inventory_manager->getCurrentState() == gui_InventoryManager::INVENTORY_IDLE)
        {
            main_inventory_manager->send(gui_InventoryManager::INVENTORY_CLOSE);
        }
    }

    // If console or inventory is active, only thing to update is audio.
    if(ConsoleInfo::instance().isVisible() || main_inventory_manager->getCurrentState() != gui_InventoryManager::INVENTORY_DISABLED)
    {
        if(game_logic_time >= GAME_LOGIC_REFRESH_INTERVAL)
        {
            Audio_Update();
            Game_Tick(&game_logic_time);
        }
        return;
    }


    // We're going to update main logic with a fixed step.
    // This allows to conserve CPU resources and keep everything in sync!

    if(game_logic_time >= GAME_LOGIC_REFRESH_INTERVAL)
    {
        btScalar dt = Game_Tick(&game_logic_time);
        lua_DoTasks(engine_lua, dt);
        Game_UpdateAI();
        Audio_Update();

        if(is_character)
        {
            engine_world.character->processSector();
            engine_world.character->updateParams();
            engine_world.character->checkCollisionCallbacks();   ///@FIXME: Must do it for ALL interactive entities!
        }

        Game_LoopEntities(engine_world.entity_tree);
    }


    // This must be called EVERY frame to max out smoothness.
    // Includes animations, camera movement, and so on.

    Game_ApplyControls(engine_world.character);

    if(is_character)
    {
        if(engine_world.character->m_typeFlags & ENTITY_TYPE_DYNAMIC)
        {
            engine_world.character->updateRigidBody(false);
        }
        if(!control_states.noclip && !control_states.free_look)
        {
            engine_world.character->applyCommands();
            engine_world.character->frame(engine_frame_time);
            Cam_FollowEntity(renderer.camera(), engine_world.character, 16.0, 128.0);
        }
    }

    Game_UpdateCharacters();

    Game_UpdateAllEntities(engine_world.entity_tree);

    bt_engine_dynamicsWorld->stepSimulation(time / 2.0, 0);
    bt_engine_dynamicsWorld->stepSimulation(time / 2.0, 0);

    Controls_RefreshStates();
    engine_world.updateAnimTextures();
}