From 7aeabf0d1413029d9491f705738dc2c3edb1e9e5 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 26 Apr 2015 02:14:26 +1000 Subject: [PATCH 1/6] Hunting a strange networking bug --- client/gameplay_scenes/world_logic.cpp | 7 ++++- client/gameplay_scenes/world_map.cpp | 38 ++++++++++++++++++++++++++ rsc/scripts/map_maker.lua | 6 ++++ rsc/scripts/map_saver.lua | 4 +-- rsc/scripts/setup_server.lua | 2 +- 5 files changed, 53 insertions(+), 4 deletions(-) diff --git a/client/gameplay_scenes/world_logic.cpp b/client/gameplay_scenes/world_logic.cpp index 4c724fb..694feb6 100644 --- a/client/gameplay_scenes/world_logic.cpp +++ b/client/gameplay_scenes/world_logic.cpp @@ -152,7 +152,7 @@ void World::FrameEnd() { } void World::RenderFrame() { -// SDL_FillRect(GetScreen(), 0, 0); + SDL_FillRect(GetScreen(), 0, 0); Render(GetScreen()); SDL_Flip(GetScreen()); fps.Calculate(); @@ -162,6 +162,11 @@ void World::Render(SDL_Surface* const screen) { //draw the map for (std::list::iterator it = regionPager.GetContainer()->begin(); it != regionPager.GetContainer()->end(); it++) { tileSheet.DrawRegionTo(screen, &(*it), camera.x, camera.y); + + //debugging + std::ostringstream msg; + msg << it->GetX() << ", " << it->GetY(); + font.DrawStringTo(msg.str(), screen, it->GetX() * tileSheet.GetImage()->GetClipW() - camera.x, it->GetY() * tileSheet.GetImage()->GetClipH() - camera.y); } //draw the entities diff --git a/client/gameplay_scenes/world_map.cpp b/client/gameplay_scenes/world_map.cpp index 592c8e9..77804f2 100644 --- a/client/gameplay_scenes/world_map.cpp +++ b/client/gameplay_scenes/world_map.cpp @@ -23,11 +23,16 @@ #include "channels.hpp" +#include + //------------------------- //map management //------------------------- void World::SendRegionRequest(int roomIndex, int x, int y) { + //debugging +// std::cout << "SendRegionRequest(" << roomIndex << ", " << x << ", " << y << ")" << std::endl; + RegionPacket packet; //pack the region's data @@ -40,6 +45,23 @@ void World::SendRegionRequest(int roomIndex, int x, int y) { } void World::hRegionContent(RegionPacket* const argPacket) { + //debugging + 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) { + std::cout << "Received checksum failed: " << argPacket->x << ", " << argPacket->y << std::endl; + } + //replace existing regions regionPager.UnloadIf([&](Region const& region) -> bool { return region.GetX() == argPacket->x && region.GetY() == argPacket->y; @@ -74,6 +96,22 @@ void World::UpdateMap() { if (!regionPager.FindRegion(i, j)) { 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) { + std::cout << "Existing checksum failed: " << roomIndex << ", " << i << ", " << j << std::endl; + } + } } } } \ No newline at end of file diff --git a/rsc/scripts/map_maker.lua b/rsc/scripts/map_maker.lua index dbcc2ec..d2a7f4e 100644 --- a/rsc/scripts/map_maker.lua +++ b/rsc/scripts/map_maker.lua @@ -65,6 +65,9 @@ end --custom generation systems here function mapMaker.DebugIsland(r) + --debug + io.write("map_maker:DebugIsland(", regionAPI.GetX(r), ", ", regionAPI.GetY(r), ")\n") + --basic distance check for each tile, placing an island around the world origin for i = 1, regionAPI.GetWidth(r) do for j = 1, regionAPI.GetHeight(r) do @@ -95,6 +98,9 @@ function mapMaker.DebugIsland(r) end function mapMaker.DebugGrassland(r) + --debug + io.write("map_maker:DebugGrassland(", regionAPI.GetX(r), ", ", regionAPI.GetY(r), ")\n") + --all dirt for i = 1, regionAPI.GetWidth(r) do for j = 1, regionAPI.GetHeight(r) do diff --git a/rsc/scripts/map_saver.lua b/rsc/scripts/map_saver.lua index b28d1bd..2ec8832 100644 --- a/rsc/scripts/map_saver.lua +++ b/rsc/scripts/map_saver.lua @@ -4,11 +4,11 @@ local mapSaver = {} function mapSaver.Load(r) --empty - io.write("map_saver:Load(", region.GetX(r), ", ", region.GetY(r), ")\n") +-- io.write("map_saver:Load(", region.GetX(r), ", ", region.GetY(r), ")\n") end function mapSaver.Save(r) --empty - io.write("map_saver:Save(", region.GetX(r), ", ", region.GetY(r), ")\n") +-- io.write("map_saver:Save(", region.GetX(r), ", ", region.GetY(r), ")\n") end --TODO: (3) create a flexible saving & loading system diff --git a/rsc/scripts/setup_server.lua b/rsc/scripts/setup_server.lua index 02f5059..c2a70de 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, 0, -64, underworld, 0, 0) +doorUtility.createDoorPair("pair 1", overworld, -64, -64, underworld, -64, -64) print("Finished the lua script") From 63e43945838c159ddc2a0d6fce0a2c15debe537c Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 26 Apr 2015 03:11:00 +1000 Subject: [PATCH 2/6] 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") From 0e149acc6265c0d570c814d44f86064eddc4ed12 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 26 Apr 2015 03:24:25 +1000 Subject: [PATCH 3/6] Pointless tweak --- common/map/region.cpp | 8 ++++++++ common/map/region.hpp | 1 + 2 files changed, 9 insertions(+) diff --git a/common/map/region.cpp b/common/map/region.cpp index 8a7f671..cf59b3f 100644 --- a/common/map/region.cpp +++ b/common/map/region.cpp @@ -42,6 +42,14 @@ 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 << "Copied: (" << x << ", " << y << "): " << int(***tiles) << ", " << int(***rhs.tiles) << std::endl; +} + +Region::Region(Region&& 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; } diff --git a/common/map/region.hpp b/common/map/region.hpp index fd8c461..0b48b13 100644 --- a/common/map/region.hpp +++ b/common/map/region.hpp @@ -39,6 +39,7 @@ public: Region() = delete; Region(int x, int y); Region(Region const&); + Region(Region&&); ~Region() = default; type_t SetTile(int x, int y, int z, type_t v); From 2a1ee4acbf52e94b5d15d0559b584fc992310f06 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 26 Apr 2015 03:29:33 +1000 Subject: [PATCH 4/6] tmp --- client/gameplay_scenes/world_map.cpp | 3 ++- common/map/region_pager_base.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/client/gameplay_scenes/world_map.cpp b/client/gameplay_scenes/world_map.cpp index 8366704..f0ec79a 100644 --- a/client/gameplay_scenes/world_map.cpp +++ b/client/gameplay_scenes/world_map.cpp @@ -85,7 +85,8 @@ void World::UpdateMap() { //request empty regions within this zone for (int i = xStart; i <= xEnd; i += REGION_WIDTH) { for (int j = yStart; j <= yEnd; j += REGION_HEIGHT) { - if (!regionPager.FindRegion(i, j)) { + Region* region = regionPager.FindRegion(i, j); + if (!region || debugRegionSum(region) == 0) { SendRegionRequest(roomIndex, i, j); } else { diff --git a/common/map/region_pager_base.cpp b/common/map/region_pager_base.cpp index 44c595e..601f984 100644 --- a/common/map/region_pager_base.cpp +++ b/common/map/region_pager_base.cpp @@ -74,7 +74,7 @@ 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())) { + if (debugRegionSum(®ionList.front()) == 0) { throw(std::runtime_error("Checksum fail; RegionPagerBase::PushRegion()")); } return ®ionList.front(); From 878d502b8b13246ce0a9e561f1936c52caa41794 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Mon, 27 Apr 2015 01:33:57 +1000 Subject: [PATCH 5/6] Looking for the bug --- client/gameplay_scenes/makefile | 2 +- client/gameplay_scenes/world_logic.cpp | 2 +- client/gameplay_scenes/world_map.cpp | 32 +++++++++++++++--------- common/debugging/makefile | 2 +- common/debugging/region_checksum.cpp | 34 -------------------------- common/debugging/region_checksum.hpp | 30 ----------------------- common/map/makefile | 2 +- common/map/region.cpp | 13 ---------- common/map/region.hpp | 1 - common/map/region_pager_base.cpp | 8 +++--- 10 files changed, 28 insertions(+), 98 deletions(-) delete mode 100644 common/debugging/region_checksum.cpp delete mode 100644 common/debugging/region_checksum.hpp diff --git a/client/gameplay_scenes/makefile b/client/gameplay_scenes/makefile index c75f6c9..c11a607 100644 --- a/client/gameplay_scenes/makefile +++ b/client/gameplay_scenes/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. .. ../client_utilities ../entities ../../common/debugging ../../common/gameplay ../../common/graphics ../../common/map ../../common/network ../../common/network/packet_types ../../common/ui ../../common/utilities +INCLUDES+=. .. ../client_utilities ../entities ../../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_logic.cpp b/client/gameplay_scenes/world_logic.cpp index 694feb6..bf91e98 100644 --- a/client/gameplay_scenes/world_logic.cpp +++ b/client/gameplay_scenes/world_logic.cpp @@ -152,7 +152,7 @@ void World::FrameEnd() { } void World::RenderFrame() { - SDL_FillRect(GetScreen(), 0, 0); +// SDL_FillRect(GetScreen(), 0, 0); Render(GetScreen()); SDL_Flip(GetScreen()); fps.Calculate(); diff --git a/client/gameplay_scenes/world_map.cpp b/client/gameplay_scenes/world_map.cpp index f0ec79a..e4819ab 100644 --- a/client/gameplay_scenes/world_map.cpp +++ b/client/gameplay_scenes/world_map.cpp @@ -22,18 +22,30 @@ #include "world.hpp" #include "channels.hpp" -#include "region_checksum.hpp" #include +//------------------------- +//static functions +//------------------------- + +static int regionChecksum(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; +} + //------------------------- //map management //------------------------- void World::SendRegionRequest(int roomIndex, int x, int y) { - //debugging -// std::cout << "SendRegionRequest(" << roomIndex << ", " << x << ", " << y << ")" << std::endl; - RegionPacket packet; //pack the region's data @@ -50,7 +62,7 @@ void World::hRegionContent(RegionPacket* const argPacket) { std::cout << "hRegionContent(" << roomIndex << ", " << argPacket->x << ", " << argPacket->y << ")" << std::endl; //checksum - if (debugRegionSum(argPacket->region) == 0) { + if (regionChecksum(argPacket->region) == 0) { std::cout << "Received checksum failed: " << argPacket->x << ", " << argPacket->y << std::endl; } @@ -86,14 +98,12 @@ void World::UpdateMap() { for (int i = xStart; i <= xEnd; i += REGION_WIDTH) { for (int j = yStart; j <= yEnd; j += REGION_HEIGHT) { Region* region = regionPager.FindRegion(i, j); - if (!region || debugRegionSum(region) == 0) { + if (!region) { SendRegionRequest(roomIndex, i, j); } - else { - //checksum - if (debugRegionSum(regionPager.FindRegion(i, j)) == 0) { - std::cout << "Existing checksum failed: " << roomIndex << ", " << i << ", " << j << std::endl; - } + else if (regionChecksum(region) == 0) { + std::cout << "Existing checksum failed: " << roomIndex << ", " << i << ", " << j << std::endl; + SendRegionRequest(roomIndex, i, j); } } } diff --git a/common/debugging/makefile b/common/debugging/makefile index afcde11..9013447 100644 --- a/common/debugging/makefile +++ b/common/debugging/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. ../map +INCLUDES+=. LIBS+= CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) diff --git a/common/debugging/region_checksum.cpp b/common/debugging/region_checksum.cpp deleted file mode 100644 index 1b46533..0000000 --- a/common/debugging/region_checksum.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* 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 deleted file mode 100644 index 4e63b82..0000000 --- a/common/debugging/region_checksum.hpp +++ /dev/null @@ -1,30 +0,0 @@ -/* 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 fc1133f..769709e 100644 --- a/common/map/makefile +++ b/common/map/makefile @@ -1,5 +1,5 @@ #config -INCLUDES+=. ../debugging ../utilities +INCLUDES+=. ../utilities LIBS+= CXXFLAGS+=-std=c++11 $(addprefix -I,$(INCLUDES)) diff --git a/common/map/region.cpp b/common/map/region.cpp index cf59b3f..1815d36 100644 --- a/common/map/region.cpp +++ b/common/map/region.cpp @@ -25,8 +25,6 @@ #include #include -#include - int snapToBase(int base, int x) { return floor((double)x / base) * base; } @@ -41,17 +39,6 @@ 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 << "Copied: (" << x << ", " << y << "): " << int(***tiles) << ", " << int(***rhs.tiles) << std::endl; -} - -Region::Region(Region&& 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.hpp b/common/map/region.hpp index 0b48b13..fd8c461 100644 --- a/common/map/region.hpp +++ b/common/map/region.hpp @@ -39,7 +39,6 @@ public: Region() = delete; Region(int x, int y); Region(Region const&); - Region(Region&&); ~Region() = default; type_t 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 601f984..1b25761 100644 --- a/common/map/region_pager_base.cpp +++ b/common/map/region_pager_base.cpp @@ -21,8 +21,6 @@ */ #include "region_pager_base.hpp" -#include "region_checksum.hpp" - #include #include @@ -74,9 +72,9 @@ 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()) == 0) { - throw(std::runtime_error("Checksum fail; RegionPagerBase::PushRegion()")); - } +// if (debugRegionSum(®ionList.front()) == 0) { +// throw(std::runtime_error("Checksum fail; RegionPagerBase::PushRegion()")); +// } return ®ionList.front(); } From 5c404c572e431ae7d6fb72a89d4035a877e49c74 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Tue, 28 Apr 2015 06:00:21 +1000 Subject: [PATCH 6/6] Patched bug #45 without resolving it --- README.md | 2 +- client/gameplay_scenes/world_logic.cpp | 18 +++++++++++++----- client/gameplay_scenes/world_map.cpp | 20 ++++++++++++++------ common/map/region_pager_base.cpp | 5 +---- server/rooms/room_data.cpp | 1 + 5 files changed, 30 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 2444399..1b97518 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## Outline -Tortuga is a 2D multiplayer JRPG featuring permadeath, with an emphasis on multiplayer cooperation, exploration and customization. The game runs on customizable public and private servers. +Tortuga is a 2D MMORPG featuring permadeath, with an emphasis on multiplayer cooperation, exploration and customization. The game runs on customizable public and private servers. This game is inspired by classic 2D RPGs (Final Fantasy, The Legend of Zelda), as well as more modern sandboxes amd MMOs (Minecraft, EVE Online). This project is currently independently created and funded, with the goal of creating a game that will engage the players and inspire a large community. diff --git a/client/gameplay_scenes/world_logic.cpp b/client/gameplay_scenes/world_logic.cpp index bf91e98..c0ff20e 100644 --- a/client/gameplay_scenes/world_logic.cpp +++ b/client/gameplay_scenes/world_logic.cpp @@ -125,8 +125,16 @@ void World::Update() { it.second.Update(); } - //update the map - UpdateMap(); + try { + //update the map + UpdateMap(); + } + catch(terminal_error& e) { + throw(e); + } + catch(std::exception& e) { + std::cerr << "UpdateMap Error: " << e.what() << std::endl; + } //skip the rest without a local character if (!localCharacter) { @@ -164,9 +172,9 @@ void World::Render(SDL_Surface* const screen) { tileSheet.DrawRegionTo(screen, &(*it), camera.x, camera.y); //debugging - std::ostringstream msg; - msg << it->GetX() << ", " << it->GetY(); - font.DrawStringTo(msg.str(), screen, it->GetX() * tileSheet.GetImage()->GetClipW() - camera.x, it->GetY() * tileSheet.GetImage()->GetClipH() - camera.y); +// std::ostringstream msg; +// msg << it->GetX() << ", " << it->GetY(); +// font.DrawStringTo(msg.str(), screen, it->GetX() * tileSheet.GetImage()->GetClipW() - camera.x, it->GetY() * tileSheet.GetImage()->GetClipH() - camera.y); } //draw the entities diff --git a/client/gameplay_scenes/world_map.cpp b/client/gameplay_scenes/world_map.cpp index e4819ab..1265281 100644 --- a/client/gameplay_scenes/world_map.cpp +++ b/client/gameplay_scenes/world_map.cpp @@ -23,7 +23,7 @@ #include "channels.hpp" -#include +#include //------------------------- //static functions @@ -58,12 +58,11 @@ void World::SendRegionRequest(int roomIndex, int x, int y) { } void World::hRegionContent(RegionPacket* const argPacket) { - //debugging - std::cout << "hRegionContent(" << roomIndex << ", " << argPacket->x << ", " << argPacket->y << ")" << std::endl; - //checksum if (regionChecksum(argPacket->region) == 0) { - std::cout << "Received checksum failed: " << argPacket->x << ", " << argPacket->y << std::endl; + std::ostringstream msg; + msg << "Received region checksum failed: " << argPacket->x << ", " << argPacket->y; + throw(std::runtime_error(msg.str())); } //replace existing regions @@ -99,11 +98,20 @@ void World::UpdateMap() { for (int j = yStart; j <= yEnd; j += REGION_HEIGHT) { Region* region = regionPager.FindRegion(i, j); if (!region) { + //request absent region SendRegionRequest(roomIndex, i, j); } else if (regionChecksum(region) == 0) { - std::cout << "Existing checksum failed: " << roomIndex << ", " << i << ", " << j << std::endl; + //checksum failed + //NOTE: this patches bug #45, but does not resolve it + regionPager.UnloadIf([region](Region const& ref) -> bool { + //remove the erroneous region + return region == &ref; + }); SendRegionRequest(roomIndex, i, j); + std::ostringstream msg; + msg << "Existing region checksum failed: " << roomIndex << ", " << i << ", " << j; + throw(std::runtime_error(msg.str())); } } } diff --git a/common/map/region_pager_base.cpp b/common/map/region_pager_base.cpp index 1b25761..857dabd 100644 --- a/common/map/region_pager_base.cpp +++ b/common/map/region_pager_base.cpp @@ -70,11 +70,8 @@ Region* RegionPagerBase::FindRegion(int x, int y) { } Region* RegionPagerBase::PushRegion(Region* const ptr) { - //BUG: Lists seem to not work properly + //BUG: #45 Some regions are occasionally losing their tile data regionList.push_front(*ptr); -// if (debugRegionSum(®ionList.front()) == 0) { -// throw(std::runtime_error("Checksum fail; RegionPagerBase::PushRegion()")); -// } return ®ionList.front(); } diff --git a/server/rooms/room_data.cpp b/server/rooms/room_data.cpp index fd0c7e7..dcb544c 100644 --- a/server/rooms/room_data.cpp +++ b/server/rooms/room_data.cpp @@ -26,6 +26,7 @@ #include #include +//TODO: (9) character collisions should be preformed client-side void RoomData::RunFrame() { //get the hook lua_rawgeti(lua, LUA_REGISTRYINDEX, tickRef);