Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

77 lines (60 sloc) 1.401 kb
#pragma once
#include "State.h"
#include "StateIdentifiers.h"
#include "ResourceIdentifiers.h"
#include <SFML/System/NonCopyable.hpp>
#include <SFML/System/Time.hpp>
#include <vector>
#include <utility>
#include <functional>
#include <map>
namespace sf
{
class Event;
class RenderWindow;
}
class StateStack : private sf::NonCopyable
{
public:
enum Action
{
Push,
Pop,
Clear,
};
public:
explicit StateStack(State::Context context);
template <typename T>
void registerState(States::ID stateID);
void update(sf::Time deltaTime);
void draw();
void handleEvent(const sf::Event& event);
void pushState(States::ID stateID);
void popState();
void clearStates();
bool isEmpty() const;
private:
State::Ptr createState(States::ID stateID);
void applyPendingChanges();
private:
// TODO: Add stuff to pending change struct
struct PendingChange
{
PendingChange(Action action, States::ID stateID = States::ID::None);
Action action;
States::ID stateID;
};
private:
std::vector<State::Ptr> stack;
std::vector<PendingChange> pendingList;
State::Context context;
std::map<States::ID, std::function<State::Ptr()>> factories;
};
template <typename T>
void StateStack::registerState(States::ID stateID)
{
factories[stateID] = [this] ()
{
return State::Ptr(new T(*this, context));
};
}
Jump to Line
Something went wrong with that request. Please try again.