diff options
author | Paweł Redman <pawel.redman@gmail.com> | 2017-12-16 19:34:01 +0100 |
---|---|---|
committer | Paweł Redman <pawel.redman@gmail.com> | 2017-12-16 19:34:01 +0100 |
commit | ec38926a517e9c1cfab41cf9da1e334688d006a5 (patch) | |
tree | 5e7a61efd3708bbe57bb3d5d17e0e3559d1df876 | |
parent | da4e3c6509fa6e00f5bbcb3a34607dd966650d1a (diff) |
Start refactoring decos.
-rw-r--r-- | src/game/decos.cpp | 22 | ||||
-rw-r--r-- | src/game/game.hpp | 10 | ||||
-rw-r--r-- | src/game/worldgen.cpp | 9 |
3 files changed, 20 insertions, 21 deletions
diff --git a/src/game/decos.cpp b/src/game/decos.cpp index ae103ef..7f81bbb 100644 --- a/src/game/decos.cpp +++ b/src/game/decos.cpp @@ -31,27 +31,17 @@ static const struct { } }; -deco_t::deco_t(game::state_t *game_, deco_type_t type_) : entity_t(ET_DECO) +deco_t::deco_t(game::state_t *game_, deco_type_t type_) : game::entity_t(game_, ET_DECO) { - game = game_; type = type_; -} - -void deco_t::spawn(world::world_t *world, v2f_t x) -{ - v2f_t center, offset; - offset[0] = world->perlin.get(x, 0.17331f); - offset[1] = world->perlin.get(x, 0.19571f); - center = x + v2f_t(0.5f, 0.5f) + offset.norm() * 0.1; - - cmodel.bounds[0] = center + decos[type].mins; - cmodel.bounds[1] = center + decos[type].maxs; + size[0] = decos[type].mins; + size[1] = decos[type].maxs; + render_size[0] = decos[type].render_mins; + render_size[1] = decos[type].render_maxs; cmodel.cflags = decos[type].cflags; - render_bounds[0] = center + decos[type].render_mins; - render_bounds[1] = center + decos[type].render_maxs; - link(world); } + void deco_t::render_to(render::state_t *render) { render->render(game->now * decos[type].fps + phase_shift, diff --git a/src/game/game.hpp b/src/game/game.hpp index 04380be..c17de64 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -201,13 +201,17 @@ namespace game { DECO_NEST } deco_type_t; - class deco_t : public world::entity_t { - game::state_t *game; + class deco_t : public game::entity_t { deco_type_t type; + public: double phase_shift; + deco_t(game::state_t *game, deco_type_t type_); - void spawn(world::world_t *world, v2f_t x); void render_to(render::state_t *render); + + void on_think(void) {}; + void on_spawn(void) {}; + void on_wake(void) {}; }; }; diff --git a/src/game/worldgen.cpp b/src/game/worldgen.cpp index 01b05ca..e5f19c8 100644 --- a/src/game/worldgen.cpp +++ b/src/game/worldgen.cpp @@ -8,6 +8,7 @@ void add_decoration(world_t *world, state_t *game, v2f_t x, float noise) { deco_t *deco; deco_type_t type; + v2f_t center, offset; if (noise < 0.3) return; @@ -21,9 +22,13 @@ void add_decoration(world_t *world, state_t *game, v2f_t x, float noise) else type = DECO_STONE_SMALL; + offset[0] = world->perlin.get(x, 0.17331f); + offset[1] = world->perlin.get(x, 0.19571f); + center = x + v2f_t(0.5f, 0.5f) + offset.norm() * 0.1; + deco = new deco_t(game, type); - deco->spawn(world, x); - deco->phase_shift = noise * 500.0; + deco->phase_shift = offset[0] * 500.0; + deco->place(world, x); } void worldgen(world_t *world, sector_index_t index, sector_t *sector, void *data) |