diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2018-04-21 18:20:49 +0200 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2018-04-21 18:20:49 +0200 |
commit | 4cfe1361fff6223d11a25cefd74af7a51b7d57bd (patch) | |
tree | d1ca7dca22567ec15be3f97d34b44766ad5dc7f4 /src/game/game.hpp | |
parent | 076f69f12ba4000a9c307e803e05827d037d1ff6 (diff) |
Hide game and interface behind a pimpl.
Diffstat (limited to 'src/game/game.hpp')
-rw-r--r-- | src/game/game.hpp | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/src/game/game.hpp b/src/game/game.hpp index e35f156..e4fdba2 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -18,6 +18,136 @@ along with Minitrem. If not, see <http://www.gnu.org/licenses/>. #include "../common.hpp" namespace game { + class state_t; + class entity_t; + class unit_t; + class effect_t; +} + +namespace interface { + class state_t; + + typedef struct { + std::string label; + int action; + + float r0, r1; + float t0, t1; + } pie_item_t; + + class pie_menu_t { + v2f_t x, x_world; + float radius; + pie_item_t *selected = nullptr; + + protected: + friend state_t; + std::vector<pie_item_t> items; + + public: + bool is_open = false; + + void open(v2f_t wmouse, v2f_t mouse); + void close(game::state_t *game); + void update(v2f_t mouse); + void render_to(render::state_t *render); + }; + + class state_t { + protected: + friend game::pseudostate_t; + + sf::RenderWindow *window; + game::state_t *game; + + float em; + + struct { + v2f_t zero_point_s = v2f_t(0, 0); + v2f_t center = v2f_t(0, 0); + + int zoom = 3; + float zoom_s = 3.0f; + + bool panning = false; + sf::Vector2f pan_ref; + + bool following = true; + } camera; + + struct { + bool selecting = false; + int type; + rectf_t rect; + } select; + + pie_menu_t pie_menu; + + typedef struct { + double time; + std::string text; + } log_entry_t; + + std::list<log_entry_t> log; + + void start_following(void); + void stop_following(void); + + public: + v3f_t camera_3d; // for audio + + void tick(double dt); + void render_to(render::state_t *render); + + void print(std::string str); + }; +} + +namespace game { + enum { + SELECT_NEW, + SELECT_OR, + SELECT_XOR + }; + + class state_t { + void group_say(std::string text); + bool select_unit(unit_t *unit, int type); + + public: + world::world_t world; + interface::state_t interface; + procgen::prng_t prng; + std::unordered_set<entity_t*> awake_entities; + std::unordered_set<unit_t*> selected_units; + // Some deletes have to be deferred to the next frame. + std::unordered_set<entity_t*> deletion_list; + + ntime_t time = 1; // game time + double now, dt; // FIXME: refactor the code, use ntime_t everywhere + + // frame timing data (game runs at a different frequency than the renderer) + bool paused; + ntime_t t0; + size_t frames = 0, frames_since_t0, frames_behind = 0; + + void start(void); + void stop(void); + void tick(ntime_t time); + void compute_ambience(render::state_t *render); + void pause(void); + void resume(void); + + void wake_area(v2f_t x); + void explosion(v2f_t x); + void hivemind_alert(v2f_t x, float r, bool do_move, v2f_t move_to); + + // These are called by the interface. + void select(rectf_t rect, int type); + bool populate_pie_menu(std::vector<interface::pie_item_t> &items); + void command(v2f_t x, int number); + }; + enum { ET_NONE, ET_UNIT, |