RegionPager can now be instanciated with template parameters

* Fixed Region::GetX() and Region::GetY()
* Replaced calls to std::find_if with regular for loops
* Changed typing of RegionPager::regionList
** regionList now holds pointers rather than the objects themselves
* Added vestigial classes MapFileFormat and MapGenerator
** MapGenerator creates and destroys the region objects
* I'm leaving in the debugging code for now
** This includes trace statements and a basterdized main() function in
/editor/main.cpp
This commit is contained in:
Kayne Ruse
2014-02-24 00:27:23 +11:00
parent 37b02352e2
commit 639c0c70e3
8 changed files with 195 additions and 52 deletions
+12 -21
View File
@@ -23,7 +23,7 @@
#include "utility.hpp"
#include <algorithm>
#include <iostream>
RegionPagerBase::RegionPagerBase(int argWidth, int argHeight, int argDepth):
regionWidth(argWidth),
@@ -34,6 +34,7 @@ RegionPagerBase::RegionPagerBase(int argWidth, int argHeight, int argDepth):
}
RegionPagerBase::~RegionPagerBase() {
std::cout << "final size: " << regionList.size() << std::endl;
//EMPTY
}
@@ -52,29 +53,19 @@ Region* RegionPagerBase::GetRegion(int x, int y) {
x = snapToBase(regionWidth, x);
y = snapToBase(regionHeight, y);
Region* ptr = nullptr;
//find the loaded region
auto iter = std::find_if(regionList.begin(), regionList.end(), [x,y](Region& it) {
return it.GetX() == x && it.GetY() == y;
});
if (iter != regionList.end()) { //ugly hack
ptr = &(*iter);
//find the region
for (std::list<Region*>::iterator it = regionList.begin(); it != regionList.end(); it++) {
if ((*it)->GetX() == x && (*it)->GetY() == y) {
return *it;
}
}
//or load the region
if (!ptr) {
ptr = LoadRegion(x, y);
}
//or create the region
if (!ptr) {
ptr = CreateRegion(x, y);
}
return ptr;
//get the region by other means
Region* ptr = LoadRegion(x, y);
if (ptr) return ptr;
return CreateRegion(x, y);
}
void RegionPagerBase::Update() {
//TODO
}
}