summaryrefslogtreecommitdiff
path: root/src/common.hpp
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2018-04-21 18:20:49 +0200
committerPaweł Redman <pawel.redman@gmail.com>2018-04-21 18:20:49 +0200
commit4cfe1361fff6223d11a25cefd74af7a51b7d57bd (patch)
treed1ca7dca22567ec15be3f97d34b44766ad5dc7f4 /src/common.hpp
parent076f69f12ba4000a9c307e803e05827d037d1ff6 (diff)
Hide game and interface behind a pimpl.
Diffstat (limited to 'src/common.hpp')
-rw-r--r--src/common.hpp155
1 files changed, 22 insertions, 133 deletions
diff --git a/src/common.hpp b/src/common.hpp
index 0064c2e..9535305 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -270,137 +270,6 @@ namespace world {
};
}
-namespace interface {
- class state_t;
-
- typedef struct {
- std::string label;
- int action;
-
- float r0, r1;
- float t0, t1;
- } pie_item_t;
-}
-
-namespace game {
- bool load_assets(void);
-
- class entity_t;
- class unit_t;
- class effect_t;
-
- 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);
- };
-}
-
-namespace interface {
- 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 {
- 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
-
- state_t(sf::RenderWindow *window_, game::state_t *game);
- void tick(double dt);
- void render_to(render::state_t *render);
-
- void print(std::string str);
- };
-}
-
namespace render {
class animated_texture_t {
friend state_t;
@@ -452,7 +321,7 @@ namespace render {
sf::RenderWindow *window;
void render_tile(world::world_t *world, v2f_t tx, world::tile_t *tile);
- void render_layer(game::state_t *game, rect_t<world::coord_t, 2> &sectors, std::list<world::entity_t*> &ents, layer_t layer);
+ void render_layer(world::world_t *world, rect_t<world::coord_t, 2> &sectors, std::list<world::entity_t*> &ents, layer_t layer);
void drender_text(rectf_t rect, std::string str);
void drender_entity(world::entity_t *ent);
public:
@@ -467,7 +336,7 @@ namespace render {
void begin_frame(ntime_t time_, double dt);
void end_frame(void);
- void render(game::state_t *game);
+ void render(world::world_t *world);
void render(double phase, animated_texture_t *anim, rectf_t bounds, sf::Color color = sf::Color::White, bool mirror = false);
void render(double phase, oriented_sprite_t *sprite, rectf_t bounds, float angle);
@@ -510,6 +379,26 @@ namespace audio {
};
}
+namespace game {
+ class state_t;
+
+ class pseudostate_t {
+ state_t *pimpl;
+
+ public:
+ pseudostate_t(sf::RenderWindow *window_);
+ ~pseudostate_t(void);
+
+ void start(void);
+ void stop(void);
+ void tick(ntime_t time, double dt);
+ world::world_t *get_world(void);
+ void render_interface_to(render::state_t *render);
+ };
+
+ bool load_assets(void);
+}
+
extern render::state_t *debug_render;
// Divide and round to minus infinity.