Skip to content

Commit

Permalink
ADDED method to check for presence of object at certain location
Browse files Browse the repository at this point in the history
  • Loading branch information
ksterker committed Jan 15, 2010
1 parent f7ed07e commit 6b1e47c
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
37 changes: 37 additions & 0 deletions src/world/chunk.cc
Expand Up @@ -93,6 +93,19 @@ void chunk::add (entity * object, const coordinates & pos)
add (chunk_info (object, pos, max));
}

// check if object exists at given position
bool chunk::exists (entity *object, const coordinates & pos)
{
// calculate axis-aligned bbox for object
const placeable *p = object->get_object();
vector3<s_int32> max (pos.x() + p->max_length(),
pos.y() + p->max_width(),
pos.z() + p->max_height());

return exists (chunk_info (object, pos, max));
}

// remove object from chunk
world::entity * chunk::remove (entity * object, const coordinates & pos)
{
// calculate axis-aligned bbox for object
Expand Down Expand Up @@ -196,6 +209,30 @@ void chunk::add (const chunk_info & ci)
}
}

// check if object exists at given position
bool chunk::exists (const chunk_info & ci)
{
if (!is_leaf())
{
s_int8 chunks[8];
const u_int8 num = find_chunks (chunks, ci.Min, ci.Max);
if (num == 1)
{
chunk *c = Children[chunks[0]];
if (c != NULL && c->exists (ci)) return true;
}
}

std::list<chunk_info>::iterator it = find (Objects.begin(), Objects.end(), ci);
if (it != Objects.end())
{
return true;
}

return false;
}

// remove object from chunk
world::entity * chunk::remove (const chunk_info & ci)
{
entity *removed = NULL;
Expand Down
13 changes: 13 additions & 0 deletions src/world/chunk.h
Expand Up @@ -77,6 +77,19 @@ namespace world
*/
void add (const chunk_info & ci);

/**
* Check if given object is present at given position.
* @param object entity which presence to check.
* @param coordinates location of the entity.
*/
bool exists (entity * object, const coordinates & pos);

/**
* Check if given object is present at given position.
* @param object entity which presence to check.
*/
bool exists (const chunk_info & ci);

/**
* Remove object at given coordinates.
* @param object entity to remove from the world.
Expand Down
3 changes: 0 additions & 3 deletions test/path/path-world.xml
Expand Up @@ -52,7 +52,6 @@
<string id="p3d">[200, 80, 0]</string>
<string id="p3d">[200, 40, 0]</string>
<string id="p3d">[240, 200, 0]</string>
<string id="p3d">[240, 200, 0]</string>
<string id="p3d">[240, 160, 0]</string>
<string id="p3d">[240, 80, 0]</string>
<string id="p3d">[240, 40, 0]</string>
Expand All @@ -66,7 +65,6 @@
<string id="p3d">[320, 120, 0]</string>
<string id="p3d">[320, 160, 0]</string>
<string id="p3d">[360, 160, 0]</string>
<string id="p3d">[360, 160, 0]</string>
<string id="p3d">[360, 200, 0]</string>
<string id="p3d">[320, 200, 0]</string>
<string id="p3d">[560, 200, 0]</string>
Expand Down Expand Up @@ -126,7 +124,6 @@
<string id="p3d">[360, 280, 0]</string>
<string id="p3d">[320, 280, 0]</string>
<string id="p3d">[320, 320, 0]</string>
<string id="p3d">[320, 320, 0]</string>
<string id="p3d">[360, 320, 0]</string>
<string id="p3d">[400, 320, 0]</string>
<string id="p3d">[440, 320, 0]</string>
Expand Down

0 comments on commit 6b1e47c

Please sign in to comment.