Working on the client side map code (read more)

I've also added in some debug code to the map classes, because I was
hunting down a std::bad_alloc beingthrown. Turns out I forgot to set the
map sizes in the client's InWorld constructor. I'm committing the fix, and
the debug code.
This commit is contained in:
Kayne Ruse
2014-04-06 02:25:55 +11:00
parent 962f3f5dd0
commit 27bda5dc28
7 changed files with 113 additions and 24 deletions
+41 -5
View File
@@ -23,6 +23,11 @@
#include "utility.hpp"
#include <stdexcept>
#include <iostream>
using namespace std;
RegionPagerBase::RegionPagerBase(int argWidth, int argHeight, int argDepth):
regionWidth(argWidth),
regionHeight(argHeight),
@@ -50,15 +55,46 @@ Region* RegionPagerBase::GetRegion(int x, int y) {
x = snapToBase(regionWidth, x);
y = snapToBase(regionHeight, y);
//get the region by various means
//TODO: revert this try/catch point
Region* ptr = nullptr;
try {
ptr = FindRegion(x, y);
if (ptr) return ptr;
}
catch(exception& e) {
cerr << "FindRegion Error: " << e.what() << endl;
}
try {
ptr = LoadRegion(x, y);
if (ptr) return ptr;
}
catch(exception& e) {
cerr << "LoadRegion Error: " << e.what() << endl;
}
try {
return CreateRegion(x, y);
}
catch(exception& e) {
cerr << "CreateRegion Error: " << e.what() << endl;
}
return nullptr;
}
Region* RegionPagerBase::FindRegion(int x, int y) {
//find the region
for (std::list<Region*>::iterator it = regionList.begin(); it != regionList.end(); it++) {
if ((*it)->GetX() == x && (*it)->GetY() == y) {
return *it;
}
}
//get the region by other means
Region* ptr = LoadRegion(x, y);
if (ptr) return ptr;
return CreateRegion(x, y);
return nullptr;
}
Region* RegionPagerBase::PushRegion(Region* ptr) {
regionList.push_front(ptr);
return regionList.front();
}