Added distance based creature culling
This commit is contained in:
@@ -50,14 +50,14 @@ BoundingBox Entity::SetBounds(BoundingBox b) {
|
||||
return bounds = b;
|
||||
}
|
||||
|
||||
Vector2 Entity::GetOrigin() {
|
||||
Vector2 Entity::GetOrigin() const {
|
||||
return origin;
|
||||
}
|
||||
|
||||
Vector2 Entity::GetMotion() {
|
||||
Vector2 Entity::GetMotion() const {
|
||||
return motion;
|
||||
}
|
||||
|
||||
BoundingBox Entity::GetBounds() {
|
||||
BoundingBox Entity::GetBounds() const {
|
||||
return bounds;
|
||||
}
|
||||
@@ -39,9 +39,9 @@ public:
|
||||
Vector2 SetMotion(Vector2 v);
|
||||
BoundingBox SetBounds(BoundingBox b);
|
||||
|
||||
Vector2 GetOrigin();
|
||||
Vector2 GetMotion();
|
||||
BoundingBox GetBounds();
|
||||
Vector2 GetOrigin() const;
|
||||
Vector2 GetMotion() const;
|
||||
BoundingBox GetBounds() const;
|
||||
|
||||
protected:
|
||||
Entity() = default;
|
||||
|
||||
+20
-3
@@ -22,6 +22,7 @@
|
||||
#include "world.hpp"
|
||||
|
||||
#include "channels.hpp"
|
||||
#include "culling_defines.hpp"
|
||||
#include "ip_operators.hpp"
|
||||
#include "fatal_error.hpp"
|
||||
|
||||
@@ -163,6 +164,17 @@ void World::Update() {
|
||||
return;
|
||||
}
|
||||
|
||||
//TODO: (1) regular query interval
|
||||
//cull creatures
|
||||
for (std::map<int, BaseCreature>::iterator it = creatureMap.begin(); it != creatureMap.end(); /* */) {
|
||||
if ( (localCharacter->GetOrigin() - it->second.GetOrigin()).Length() > INFLUENCE_RADIUS) {
|
||||
creatureMap.erase(it++);
|
||||
}
|
||||
else {
|
||||
it++;
|
||||
}
|
||||
}
|
||||
|
||||
//get the collidable boxes
|
||||
std::list<BoundingBox> boxList = GenerateCollisionGrid(localCharacter, tileSheet.GetTileW(), tileSheet.GetTileH());
|
||||
|
||||
@@ -779,10 +791,15 @@ void World::hCharacterMovement(CharacterPacket* const argPacket) {
|
||||
//-------------------------
|
||||
|
||||
void World::hCreatureUpdate(CreaturePacket* const argPacket) {
|
||||
std::cout << "hCreatureUpdate" << std::endl;
|
||||
//TODO: (1) Authentication
|
||||
//Cull creatures that are too far away
|
||||
if ( (localCharacter->GetOrigin() - argPacket->origin).Length() > INFLUENCE_RADIUS) {
|
||||
//ignore beyond 1000 units
|
||||
return;
|
||||
}
|
||||
|
||||
//check that this character exists
|
||||
std::cout << "hCreatureUpdate" << std::endl;
|
||||
|
||||
//check if this creature exists
|
||||
std::map<int, BaseCreature>::iterator creatureIt = creatureMap.find(argPacket->creatureIndex);
|
||||
if (creatureIt != creatureMap.end()) {
|
||||
//update the origin and motion, if there's a difference
|
||||
|
||||
Reference in New Issue
Block a user