From 7aeabf0d1413029d9491f705738dc2c3edb1e9e5 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sun, 26 Apr 2015 02:14:26 +1000 Subject: [PATCH] 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")