Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
wip simpleCollideLineWithRoomSystem
  • Loading branch information
ligfx committed May 11, 2021
1 parent 447af2b commit 969d5fa
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
8 changes: 2 additions & 6 deletions src/Agent.cpp
Expand Up @@ -583,12 +583,8 @@ bool Agent::validInRoomSystem(Point p, float w, float h, int testperm) {
if (!ourRoom)
return false;

unsigned int dir;
Line wall;
Point newsrc = src;
bool collision = world.map->collideLineWithRoomSystem(src, dest, ourRoom, newsrc, wall, dir, testperm);

if (collision && newsrc != dest)
Point newsrc = world.map->simpleCollideLineWithRoomSystem(src, dest, ourRoom, testperm);
if (newsrc != dest)
return false;
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/AgentHelpers.cpp
Expand Up @@ -52,12 +52,8 @@ bool agentIsVisible(Agent* seeing, Agent* a, float ownerx, float ownery, MetaRoo

// do the actual visibiltiy check using a line between centers
Point src(ownerx, ownery), dest(thisx, thisy);
Line dummywall;
unsigned int dummydir;
std::shared_ptr<Room> newroom = ownerroom;
Point where = src;
bool collision = world.map->collideLineWithRoomSystem(src, dest, newroom, where, dummywall, dummydir, seeing->perm);
if (collision && where != dest)
Point where = world.map->simpleCollideLineWithRoomSystem(src, dest, ownerroom, seeing->perm);
if (where != dest)
return false;

return true;
Expand Down
8 changes: 8 additions & 0 deletions src/Map.cpp
Expand Up @@ -160,6 +160,14 @@ std::vector<std::shared_ptr<Room>> Map::roomsAt(float _x, float _y) {
return m->roomsAt(_x, _y);
}

Point Map::simpleCollideLineWithRoomSystem(Point src, Point dest, std::shared_ptr<Room> room, int perm) {
Point where;
Line dummywall;
unsigned int dummywalldir;
collideLineWithRoomSystem(src, dest, room, where, dummywall, dummywalldir, perm);
return where;
}

bool Map::collideLineWithRoomSystem(Point src, Point dest, std::shared_ptr<Room>& room, Point& where, Line& wall, unsigned int& walldir, int perm) {
std::shared_ptr<Room> newRoom;

Expand Down
5 changes: 5 additions & 0 deletions src/Map.h
Expand Up @@ -71,6 +71,11 @@ class Map {
std::shared_ptr<Room> roomAt(float, float);
std::vector<std::shared_ptr<Room>> roomsAt(float, float);

// Return the point where a line from src to dest either (1) collides with a wall (2) collides
// with a door of incompatible perm (3) gets to dest without any collisions. `room` is usually
// the room containing the src point.
Point simpleCollideLineWithRoomSystem(Point src, Point dest, std::shared_ptr<Room> room, int perm);

bool collideLineWithRoomSystem(Point src, Point dest, std::shared_ptr<Room>& room, Point& where, Line& wall, unsigned int& walldir, int perm);
bool collideLineWithRoomBoundaries(Point src, Point dest, std::shared_ptr<Room> room, std::shared_ptr<Room>& newroom, Point& where, Line& wall, unsigned int& walldir, int perm);

Expand Down
8 changes: 2 additions & 6 deletions src/caos/caosVM_motion.cpp
Expand Up @@ -176,12 +176,8 @@ void v_OBST(caosVM* vm) {
return;
}

unsigned int dummy1;
Line dummy2;
Point point;
bool collided = world.map->collideLineWithRoomSystem(src, dest, ourRoom, point, dummy2, dummy1, vm->targ->perm);
// TODO: do something with collided?
(void)collided;
// TODO: do we care if the line collided or made it to dest?
Point point = world.map->simpleCollideLineWithRoomSystem(src, dest, ourRoom, vm->targ->perm);

switch (direction) {
case 0: vm->result.setFloat(src.x - point.x); break;
Expand Down

0 comments on commit 969d5fa

Please sign in to comment.