From 63e43945838c159ddc2a0d6fce0a2c15debe537c Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 26 Apr 2015 03:11:00 +1000 Subject: [PATCH] I can't seem to pinpoint the cause --- client/gameplay_scenes/makefile | 2 +- client/gameplay_scenes/world_map.cpp | 26 ++++----------------- common/debugging/makefile | 2 +- common/debugging/region_checksum.cpp | 34 ++++++++++++++++++++++++++++ common/debugging/region_checksum.hpp | 30 ++++++++++++++++++++++++ common/map/makefile | 2 +- common/map/region.cpp | 5 ++++ common/map/region_pager_base.cpp | 6 +++++ rsc/scripts/setup_server.lua | 2 +- 9 files changed, 83 insertions(+), 26 deletions(-) create mode 100644 common/debugging/region_checksum.cpp create mode 100644 common/debugging/region_checksum.hpp diff --git a/client/gameplay_scenes/makefile b/client/gameplay_scenes/makefile index c11a607..c75f6c9 100644 --- a/client/gameplay_scenes/makefile +++ b/client/gameplay_scenes/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. .. ../client_utilities ../entities ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/network/packet_types ../../common/ui ../../common/utilities +INCLUDES+=. .. ../client_utilities ../entities ../../common/debugging ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/network/packet_types ../../common/ui ../../common/utilities LIBS+= CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) diff --git a/client/gameplay_scenes/world_map.cpp b/client/gameplay_scenes/world_map.cpp index 77804f2..8366704 100644 --- a/client/gameplay_scenes/world_map.cpp +++ b/client/gameplay_scenes/world_map.cpp @@ -22,6 +22,7 @@ #include "world.hpp" #include "channels.hpp" +#include "region_checksum.hpp" #include @@ -49,16 +50,7 @@ void World::hRegionContent(RegionPacket* const argPacket) { std::cout << "hRegionContent(" << roomIndex << ", " << argPacket->x << ", " << argPacket->y << ")" << std::endl; //checksum - int checksum = 0; - for(int i = 0; i < REGION_WIDTH; i++) { - for (int j = 0; j < REGION_HEIGHT; j++) { - for (int k = 0; k < REGION_DEPTH; k++) { - checksum += argPacket->region->GetTile(i, j, k); - } - } - } - - if (checksum == 0) { + if (debugRegionSum(argPacket->region) == 0) { std::cout << "Received checksum failed: " << argPacket->x << ", " << argPacket->y << std::endl; } @@ -97,18 +89,8 @@ void World::UpdateMap() { SendRegionRequest(roomIndex, i, j); } else { - Region* region = regionPager.FindRegion(i, j); - - int checksum = 0; - for(int x = 0; x < REGION_WIDTH; x++) { - for (int y = 0; y < REGION_HEIGHT; y++) { - for (int z = 0; z < REGION_DEPTH; z++) { - checksum += region->GetTile(x, y, z); - } - } - } - - if (checksum == 0) { + //checksum + if (debugRegionSum(regionPager.FindRegion(i, j)) == 0) { std::cout << "Existing checksum failed: " << roomIndex << ", " << i << ", " << j << std::endl; } } diff --git a/common/debugging/makefile b/common/debugging/makefile index 9013447..afcde11 100644 --- a/common/debugging/makefile +++ b/common/debugging/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. +INCLUDES+=. ../map LIBS+= CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) diff --git a/common/debugging/region_checksum.cpp b/common/debugging/region_checksum.cpp new file mode 100644 index 0000000..1b46533 --- /dev/null +++ b/common/debugging/region_checksum.cpp @@ -0,0 +1,34 @@ +/* Copyright: (c) Kayne Ruse 2013-2015 + * + * 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. +*/ +#include "region_checksum.hpp" + +int debugRegionSum(Region* const region) { + int sum = 0; + for(int i = 0; i < REGION_WIDTH; i++) { + for (int j = 0; j < REGION_HEIGHT; j++) { + for (int k = 0; k < REGION_DEPTH; k++) { + sum += region->GetTile(i, j, k); + } + } + } + return sum; +} \ No newline at end of file diff --git a/common/debugging/region_checksum.hpp b/common/debugging/region_checksum.hpp new file mode 100644 index 0000000..4e63b82 --- /dev/null +++ b/common/debugging/region_checksum.hpp @@ -0,0 +1,30 @@ +/* Copyright: (c) Kayne Ruse 2013-2015 + * + * 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. +*/ +#ifndef REGIONCHECKSUM_HPP_ +#define REGIONCHECKSUM_HPP_ + +#include "region.hpp" + +//fails if the result is 0 +int debugRegionSum(Region* const); + +#endif \ No newline at end of file diff --git a/common/map/makefile b/common/map/makefile index 769709e..fc1133f 100644 --- a/common/map/makefile +++ b/common/map/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. ../utilities +INCLUDES+=. ../debugging ../utilities LIBS+= CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) diff --git a/common/map/region.cpp b/common/map/region.cpp index 1815d36..8a7f671 100644 --- a/common/map/region.cpp +++ b/common/map/region.cpp @@ -25,6 +25,8 @@ #include #include +#include + int snapToBase(int base, int x) { return floor((double)x / base) * base; } @@ -39,6 +41,9 @@ Region::Region(int argX, int argY): x(argX), y(argY) { Region::Region(Region const& rhs): x(rhs.x), y(rhs.y) { memcpy(tiles, rhs.tiles, REGION_WIDTH*REGION_HEIGHT*REGION_DEPTH*sizeof(type_t)); solid = rhs.solid; + + //debugging + std::cout << "Moved: (" << x << ", " << y << "): " << int(***tiles) << ", " << int(***rhs.tiles) << std::endl; } Region::type_t Region::SetTile(int x, int y, int z, type_t v) { diff --git a/common/map/region_pager_base.cpp b/common/map/region_pager_base.cpp index 1df6864..44c595e 100644 --- a/common/map/region_pager_base.cpp +++ b/common/map/region_pager_base.cpp @@ -21,6 +21,8 @@ */ #include "region_pager_base.hpp" +#include "region_checksum.hpp" + #include #include @@ -70,7 +72,11 @@ Region* RegionPagerBase::FindRegion(int x, int y) { } Region* RegionPagerBase::PushRegion(Region* const ptr) { + //BUG: Lists seem to not work properly regionList.push_front(*ptr); + if (debugRegionSum(®ionList.front())) { + throw(std::runtime_error("Checksum fail; RegionPagerBase::PushRegion()")); + } return ®ionList.front(); } diff --git a/rsc/scripts/setup_server.lua b/rsc/scripts/setup_server.lua index c2a70de..5c55900 100644 --- a/rsc/scripts/setup_server.lua +++ b/rsc/scripts/setup_server.lua @@ -31,6 +31,6 @@ local underworld, uidTwo = roomManagerAPI.CreateRoom("underworld", "overworld.bm roomAPI.Initialize(underworld, mapSaver.Load, mapSaver.Save, mapMaker.DebugGrassland, mapSaver.Save) --call the monstrosity -doorUtility.createDoorPair("pair 1", overworld, -64, -64, underworld, -64, -64) +doorUtility.createDoorPair("pair 1", overworld, -64, -64, underworld, 64, 64) print("Finished the lua script")