Added distance based creature culling
This commit is contained in:
@@ -50,14 +50,14 @@ BoundingBox Entity::SetBounds(BoundingBox b) {
|
|||||||
return bounds = b;
|
return bounds = b;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Entity::GetOrigin() {
|
Vector2 Entity::GetOrigin() const {
|
||||||
return origin;
|
return origin;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 Entity::GetMotion() {
|
Vector2 Entity::GetMotion() const {
|
||||||
return motion;
|
return motion;
|
||||||
}
|
}
|
||||||
|
|
||||||
BoundingBox Entity::GetBounds() {
|
BoundingBox Entity::GetBounds() const {
|
||||||
return bounds;
|
return bounds;
|
||||||
}
|
}
|
||||||
@@ -39,9 +39,9 @@ public:
|
|||||||
Vector2 SetMotion(Vector2 v);
|
Vector2 SetMotion(Vector2 v);
|
||||||
BoundingBox SetBounds(BoundingBox b);
|
BoundingBox SetBounds(BoundingBox b);
|
||||||
|
|
||||||
Vector2 GetOrigin();
|
Vector2 GetOrigin() const;
|
||||||
Vector2 GetMotion();
|
Vector2 GetMotion() const;
|
||||||
BoundingBox GetBounds();
|
BoundingBox GetBounds() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Entity() = default;
|
Entity() = default;
|
||||||
|
|||||||
+20
-3
@@ -22,6 +22,7 @@
|
|||||||
#include "world.hpp"
|
#include "world.hpp"
|
||||||
|
|
||||||
#include "channels.hpp"
|
#include "channels.hpp"
|
||||||
|
#include "culling_defines.hpp"
|
||||||
#include "ip_operators.hpp"
|
#include "ip_operators.hpp"
|
||||||
#include "fatal_error.hpp"
|
#include "fatal_error.hpp"
|
||||||
|
|
||||||
@@ -163,6 +164,17 @@ void World::Update() {
|
|||||||
return;
|
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
|
//get the collidable boxes
|
||||||
std::list<BoundingBox> boxList = GenerateCollisionGrid(localCharacter, tileSheet.GetTileW(), tileSheet.GetTileH());
|
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) {
|
void World::hCreatureUpdate(CreaturePacket* const argPacket) {
|
||||||
std::cout << "hCreatureUpdate" << std::endl;
|
//Cull creatures that are too far away
|
||||||
//TODO: (1) Authentication
|
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);
|
std::map<int, BaseCreature>::iterator creatureIt = creatureMap.find(argPacket->creatureIndex);
|
||||||
if (creatureIt != creatureMap.end()) {
|
if (creatureIt != creatureMap.end()) {
|
||||||
//update the origin and motion, if there's a difference
|
//update the origin and motion, if there's a difference
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/* Copyright: (c) Kayne Ruse 2013-2016
|
||||||
|
*
|
||||||
|
* This software is provided 'as-is', without any express or implied
|
||||||
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
|
* arising from the use of this software.
|
||||||
|
*
|
||||||
|
* Permission is granted to anyone to use this software for any purpose,
|
||||||
|
* including commercial applications, and to alter it and redistribute it
|
||||||
|
* freely, subject to the following restrictions:
|
||||||
|
*
|
||||||
|
* 1. The origin of this software must not be misrepresented; you must not
|
||||||
|
* claim that you wrote the original software. If you use this software
|
||||||
|
* in a product, an acknowledgment in the product documentation would be
|
||||||
|
* appreciated but is not required.
|
||||||
|
*
|
||||||
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||||
|
* misrepresented as being the original software.
|
||||||
|
*
|
||||||
|
* 3. This notice may not be removed or altered from any source
|
||||||
|
* distribution.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
constexpr int INFLUENCE_RADIUS = 1000;
|
||||||
@@ -57,7 +57,7 @@ local function bunnySquare(creature)
|
|||||||
|
|
||||||
|
|
||||||
--is it time to change direction?
|
--is it time to change direction?
|
||||||
if os.time() - tonumber(timestamp) > 3 then
|
if os.time() - tonumber(timestamp) >= 1 then
|
||||||
-- print("changing directions")
|
-- print("changing directions")
|
||||||
|
|
||||||
if string.match("south", direction) then
|
if string.match("south", direction) then
|
||||||
|
|||||||
@@ -21,6 +21,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "room_data.hpp"
|
#include "room_data.hpp"
|
||||||
|
|
||||||
|
#include "culling_defines.hpp"
|
||||||
#include "serial_packet.hpp"
|
#include "serial_packet.hpp"
|
||||||
#include "server_utilities.hpp"
|
#include "server_utilities.hpp"
|
||||||
|
|
||||||
@@ -110,7 +111,8 @@ void RoomData::RunFrame() {
|
|||||||
CreaturePacket packet;
|
CreaturePacket packet;
|
||||||
copyCreatureToPacket(&packet, it.second, it.first);
|
copyCreatureToPacket(&packet, it.second, it.first);
|
||||||
packet.type = SerialPacketType::CREATURE_UPDATE;
|
packet.type = SerialPacketType::CREATURE_UPDATE;
|
||||||
pumpPacketProximity(reinterpret_cast<SerialPacket*>(&packet), roomIndex, it.second->GetOrigin(), 320);
|
packet.roomIndex = roomIndex;
|
||||||
|
pumpPacketProximity(reinterpret_cast<SerialPacket*>(&packet), roomIndex, it.second->GetOrigin(), INFLUENCE_RADIUS);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: creature/character collisions
|
//TODO: creature/character collisions
|
||||||
|
|||||||
Reference in New Issue
Block a user