summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common.hpp17
-rw-r--r--src/game.cpp7
-rw-r--r--src/path_finder.cpp12
-rw-r--r--src/render.cpp2
-rw-r--r--src/world.cpp10
5 files changed, 31 insertions, 17 deletions
diff --git a/src/common.hpp b/src/common.hpp
index fde9bc8..0785a79 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -77,6 +77,13 @@ namespace world {
tile_t tiles[SECTOR_SIZE * SECTOR_SIZE];
};
+ typedef int cflags_t;
+
+ typedef struct {
+ cflags_t cflags;
+ rectf_t bounds;
+ } cmodel_t;
+
class world_t {
procgen::prng_t prng;
procgen::perlin_noise_t perlin;
@@ -99,7 +106,7 @@ namespace world {
sector_t *get_sector(sector_index_t index, bool partial = false);
tile_t *get_tile(tile_index_t index, bool partial = false);
- bool find_path(v2f_t src, v2f_t dst, rectf_t size, entity_t *ignore, std::list<v2f_t> *path);
+ bool find_path(v2f_t src, v2f_t dst, cmodel_t *cmodel, entity_t *ignore, std::list<v2f_t> *path);
// FIXME: iterators instead of returning std::lists
std::list<sector_t*> get_sectors(rectf_t rect);
@@ -120,7 +127,8 @@ namespace world {
size_t cookie = 0;
public:
- rectf_t bounds, render_bounds;
+ cmodel_t cmodel;
+ rectf_t render_bounds;
void link(world_t *world);
void unlink();
@@ -136,6 +144,7 @@ namespace world {
class path_finder_t {
public:
v2f_t src, dst, tile_center;
+ cflags_t cflags;
path_node_t *nodes;
size_t width, height;
tile_index_t base;
@@ -144,8 +153,8 @@ namespace world {
std::deque<tile_index_t> path, shortest_path;
~path_finder_t();
- void setup_nodes(v2f_t src_, v2f_t dst_);
- void eliminate_nodes(rectf_t bounds);
+ void setup_nodes(v2f_t src_, v2f_t dst_, cflags_t cflags_);
+ void eliminate_nodes(cmodel_t cmodel);
void find_r(tile_index_t index, float dist, float limit);
bool find(void);
void export_path(std::list<v2f_t> *list);
diff --git a/src/game.cpp b/src/game.cpp
index 2694350..91cf4d2 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -7,8 +7,8 @@ class unit_t : public world::entity_t {
void compute_bounds()
{
- bounds[0] = x + size[0];
- bounds[1] = x + size[1];
+ cmodel.bounds[0] = x + size[0];
+ cmodel.bounds[1] = x + size[1];
render_bounds[0] = x + render_size[0];
render_bounds[1] = x + render_size[1];
}
@@ -30,6 +30,7 @@ public:
world = world_;
x = x_;
move.moving = false;
+ cmodel.cflags = 1;
unlink();
compute_bounds();
@@ -82,7 +83,7 @@ public:
move.dst = dst_;
move.path.clear();
- if (world->find_path(x, move.dst, size, this, &move.path))
+ if (world->find_path(x, move.dst, &cmodel, this, &move.path))
move.moving = true;
else
move.moving = false;
diff --git a/src/path_finder.cpp b/src/path_finder.cpp
index 4ace89d..3d97df7 100644
--- a/src/path_finder.cpp
+++ b/src/path_finder.cpp
@@ -13,13 +13,14 @@ path_finder_t::~path_finder_t()
delete nodes;
}
-void path_finder_t::setup_nodes(v2f_t src_, v2f_t dst_)
+void path_finder_t::setup_nodes(v2f_t src_, v2f_t dst_, cflags_t cflags_)
{
rectf_t src_margin, dst_margin, bounds;
tile_index_t end;
src = src_;
dst = dst_;
+ cflags = cflags_;
tile_center = v2f_t(0.5, 0.5);
shortest_dist = INFINITY;
@@ -41,13 +42,16 @@ void path_finder_t::setup_nodes(v2f_t src_, v2f_t dst_)
nodes[i].dist = INFINITY;
}
-void path_finder_t::eliminate_nodes(rectf_t bounds)
+void path_finder_t::eliminate_nodes(cmodel_t cmodel)
{
rect_t<coord_t, 2> index_bounds;
tile_index_t index;
- index_bounds[0] = tile_index_t(bounds[0].floor()) - base;
- index_bounds[1] = tile_index_t(bounds[1].ceil()) - base;
+ if (!(cmodel.cflags & cflags))
+ return;
+
+ index_bounds[0] = tile_index_t(cmodel.bounds[0].floor()) - base;
+ index_bounds[1] = tile_index_t(cmodel.bounds[1].ceil()) - base;
for (index[1] = index_bounds[0][1]; index[1] <= index_bounds[1][1]; index[1]++)
for (index[0] = index_bounds[0][0]; index[0] <= index_bounds[1][0]; index[0]++) {
diff --git a/src/render.cpp b/src/render.cpp
index a6cc6b5..7b38989 100644
--- a/src/render.cpp
+++ b/src/render.cpp
@@ -93,7 +93,7 @@ void state_t::render(game::state_t *game)
ents.sort(
[](const world::entity_t *x, const world::entity_t *y) -> bool
{
- return x->bounds[1][0] < y->bounds[1][0];
+ return x->render_bounds[1][0] < y->render_bounds[1][0];
});
for (world::entity_t *ent : ents)
diff --git a/src/world.cpp b/src/world.cpp
index 9a504c3..d9789ad 100644
--- a/src/world.cpp
+++ b/src/world.cpp
@@ -80,13 +80,13 @@ void world_t::generate(sector_t *sector, sector_index_t index, bool partial)
}
}
-bool world_t::find_path(v2f_t src, v2f_t dst, rectf_t size, entity_t *ignore,
+bool world_t::find_path(v2f_t src, v2f_t dst, cmodel_t *cmodel, entity_t *ignore,
std::list<v2f_t> *path)
{
path_finder_t finder;
rectf_t bounds;
- finder.setup_nodes(src, dst);
+ finder.setup_nodes(src, dst, cmodel->cflags);
for (size_t y = 0; y < finder.height; y++)
for (size_t x = 0; x < finder.width; x++) {
@@ -101,7 +101,7 @@ bool world_t::find_path(v2f_t src, v2f_t dst, rectf_t size, entity_t *ignore,
for (entity_t *ent : get_entities(bounds))
if (ent != ignore)
- finder.eliminate_nodes(ent->bounds);
+ finder.eliminate_nodes(ent->cmodel);
if (!finder.find())
return false;
@@ -181,7 +181,7 @@ std::list<entity_t*> world_t::get_entities(rectf_t rect)
if (ent->cookie == cookie)
continue;
- if (!(rect && ent->bounds))
+ if (!(rect && ent->cmodel.bounds))
continue;
ent->cookie = cookie;
@@ -235,7 +235,7 @@ void entity_t::link(world_t *world)
float xlip, ylip;
size_t xsecs, ysecs;
- total_bounds = bounds | render_bounds;
+ total_bounds = cmodel.bounds | render_bounds;
fx = floor(total_bounds[0][0]);
fy = floor(total_bounds[0][1]);