diff --git a/client/entities/entity.cpp b/client/entities/entity.cpp index 1853b7d..4de48c7 100644 --- a/client/entities/entity.cpp +++ b/client/entities/entity.cpp @@ -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; } \ No newline at end of file diff --git a/client/entities/entity.hpp b/client/entities/entity.hpp index 8263943..379bb6b 100644 --- a/client/entities/entity.hpp +++ b/client/entities/entity.hpp @@ -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; diff --git a/client/scenes/world.cpp b/client/scenes/world.cpp index a31d75e..9b086c0 100644 --- a/client/scenes/world.cpp +++ b/client/scenes/world.cpp @@ -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::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 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::iterator creatureIt = creatureMap.find(argPacket->creatureIndex); if (creatureIt != creatureMap.end()) { //update the origin and motion, if there's a difference diff --git a/common/gameplay/culling_defines.hpp b/common/gameplay/culling_defines.hpp new file mode 100644 index 0000000..29da60b --- /dev/null +++ b/common/gameplay/culling_defines.hpp @@ -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; \ No newline at end of file diff --git a/rsc/scripts/setup_server.lua b/rsc/scripts/setup_server.lua index 8390155..c2dab02 100644 --- a/rsc/scripts/setup_server.lua +++ b/rsc/scripts/setup_server.lua @@ -57,7 +57,7 @@ local function bunnySquare(creature) --is it time to change direction? - if os.time() - tonumber(timestamp) > 3 then + if os.time() - tonumber(timestamp) >= 1 then -- print("changing directions") if string.match("south", direction) then diff --git a/server/rooms/room_data.cpp b/server/rooms/room_data.cpp index f66270e..6a22c45 100644 --- a/server/rooms/room_data.cpp +++ b/server/rooms/room_data.cpp @@ -21,6 +21,7 @@ */ #include "room_data.hpp" +#include "culling_defines.hpp" #include "serial_packet.hpp" #include "server_utilities.hpp" @@ -110,7 +111,8 @@ void RoomData::RunFrame() { CreaturePacket packet; copyCreatureToPacket(&packet, it.second, it.first); packet.type = SerialPacketType::CREATURE_UPDATE; - pumpPacketProximity(reinterpret_cast(&packet), roomIndex, it.second->GetOrigin(), 320); + packet.roomIndex = roomIndex; + pumpPacketProximity(reinterpret_cast(&packet), roomIndex, it.second->GetOrigin(), INFLUENCE_RADIUS); } //TODO: creature/character collisions