Kukatz 3D  0.1
Török Attila szakdolgozata
projects/Kukatz 3D/src/statemanager.cpp
00001 /*
00002  * statemanager.cpp - Kukatz 3D
00003  * Copyright (c) 2010, 2011 - TÖRÖK Attila (torokati44@gmail.com)
00004  *
00005  * This software is provided 'as-is', without any express or implied
00006  * warranty. In no event will the authors be held liable for any damages
00007  * arising from the use of this software.
00008  *
00009  * Permission is granted to anyone to use this software for any purpose,
00010  * including commercial applications, and to alter it and redistribute it
00011  * freely, subject to the following restrictions:
00012  *
00013  *       1. The origin of this software must not be misrepresented; you must not
00014  *                      claim that you wrote the original software. If you use this software
00015  *                      in a product, an acknowledgment in the product documentation would be
00016  *                      appreciated but is not required.
00017  *
00018  *       2. Altered source versions must be plainly marked as such, and must not be
00019  *                      misrepresented as being the original software.
00020  *
00021  *       3. This notice may not be removed or altered from any source
00022  *                      distribution.
00023  */
00024 
00025 #include "statemanager.hpp"
00026 
00027 #include "statebase.hpp"
00028 #include "resourcemanager.hpp"
00029 
00030 StateManager::StateManager()
00031 {
00032         
00033 }
00034 
00035 void StateManager::resize_all(const sf::Vector2i& size)
00036 {
00037         for (size_t i = 0; i < state_stack.size(); ++i)
00038         {
00039                 state_stack[i]->resize(size);
00040         }
00041 }
00042 
00043 StateBase* StateManager::get_top_state()
00044 {
00045         if (state_stack.empty())
00046         {
00047                 return 0;
00048         }
00049         else
00050         {
00051                 return state_stack.back();
00052         }
00053 }
00054 
00055 void StateManager::push_state(StateBase* state)
00056 {
00057         if (state != 0)
00058         {
00059                 state_stack.push_back(state);
00060         }
00061 }
00062 
00063 void StateManager::clear()
00064 {
00065         while (!state_stack.empty())
00066         {
00067                 delete state_stack.back();
00068                 state_stack.pop_back();
00069         }
00070 }
00071 
00072 bool StateManager::is_empty()
00073 {
00074         return state_stack.empty();
00075 }
00076 
00077 void StateManager::process_events(std::vector< sf::Event >& events)
00078 {
00079         if (!state_stack.empty())
00080         {
00081                 state_stack.back()->process_events(events);
00082         }
00083 }
00084 
00085 void StateManager::update(float dt)
00086 {
00087         for(std::vector< StateBase* >::iterator i = state_stack.begin(); i < state_stack.end(); ++i)
00088         {
00089                 if ((*i)->should_pop())
00090                 {
00091                         delete (*i);
00092                         state_stack.erase(i);
00093                 }
00094         }
00095         
00096         if (!state_stack.empty())
00097         {
00098                 state_stack.back()->update(dt);
00099         }
00100 }
00101 
00102 void StateManager::render()
00103 {
00104         if (!state_stack.empty())
00105         {
00106                 state_stack.back()->render();
00107         }
00108 }
00109 
00110 StateManager::~StateManager()
00111 {
00112         clear();
00113 }
 Összes Osztályok