Hunting a strange networking bug
This commit is contained in:
@@ -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<Region>::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
|
||||
|
||||
@@ -23,11 +23,16 @@
|
||||
|
||||
#include "channels.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
//-------------------------
|
||||
//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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user