The map paging is functional
This commit is contained in:
+28
-18
@@ -90,7 +90,7 @@ InWorld::InWorld(ConfigUtility* const argConfig, UDPNetworkUtility* const argNet
|
|||||||
network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE);
|
network.Send(Channels::SERVER, buffer, PACKET_BUFFER_SIZE);
|
||||||
|
|
||||||
//debug
|
//debug
|
||||||
RequestRegion(0, 0);
|
// RequestRegion(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
InWorld::~InWorld() {
|
InWorld::~InWorld() {
|
||||||
@@ -143,9 +143,9 @@ void InWorld::RenderFrame() {
|
|||||||
|
|
||||||
void InWorld::Render(SDL_Surface* const screen) {
|
void InWorld::Render(SDL_Surface* const screen) {
|
||||||
//draw the map
|
//draw the map
|
||||||
ForNearbyRegions([&](Region* const region) {
|
for (auto it = mapPager.GetContainer()->begin(); it != mapPager.GetContainer()->end(); it++) {
|
||||||
tileSheet.DrawRegionTo(screen, region, camera.x, camera.y);
|
tileSheet.DrawRegionTo(screen, *it, camera.x, camera.y);
|
||||||
});
|
}
|
||||||
|
|
||||||
//draw characters
|
//draw characters
|
||||||
for (auto& it : playerCharacters) {
|
for (auto& it : playerCharacters) {
|
||||||
@@ -469,21 +469,31 @@ int InWorld::CheckBufferDistance(Region* const region) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void InWorld::UpdateMap() {
|
void InWorld::UpdateMap() {
|
||||||
//TODO
|
//prune distant regions
|
||||||
}
|
for (auto it = mapPager.GetContainer()->begin(); it != mapPager.GetContainer()->end(); /* EMPTY */) {
|
||||||
|
if (CheckBufferDistance(*it) > 2) {
|
||||||
|
//debugging
|
||||||
|
cout << "unloading: " << (*it)->GetX() << ", " << (*it)->GetY() << endl;
|
||||||
|
|
||||||
void InWorld::ForNearbyRegions(std::function<void (Region* const)> func) {
|
mapPager.UnloadRegion((*it)->GetX(), (*it)->GetY());
|
||||||
//TODO: switch this to "is nearby"
|
|
||||||
//this is ugly
|
//reset
|
||||||
for (int i = snapToBase(mapPager.GetRegionWidth() * tileSheet.GetTileW(), camera.x);
|
it = mapPager.GetContainer()->begin();
|
||||||
i < camera.x + camera.width;
|
continue;
|
||||||
i += mapPager.GetRegionWidth() * tileSheet.GetTileW()
|
}
|
||||||
) {
|
++it;
|
||||||
for (int j = snapToBase(mapPager.GetRegionHeight() * tileSheet.GetTileH(), camera.y);
|
}
|
||||||
j < camera.y + camera.height;
|
|
||||||
j += mapPager.GetRegionHeight() * tileSheet.GetTileH()
|
//TODO: make the region units official
|
||||||
) {
|
int regionUnitX = mapPager.GetRegionWidth() * tileSheet.GetTileW();
|
||||||
func(mapPager.GetRegion(i, j));
|
int regionUnitY = mapPager.GetRegionHeight() * tileSheet.GetTileH();
|
||||||
|
|
||||||
|
//request empty regions, including buffers (-1 & +1 region unit)
|
||||||
|
for (int i = snapToBase(regionUnitX, camera.x - regionUnitX); i <= snapToBase(regionUnitX, camera.x + camera.width + regionUnitX); i += regionUnitX) {
|
||||||
|
for (int j = snapToBase(regionUnitY, camera.y - regionUnitY); j <= snapToBase(regionUnitY, camera.y + camera.height + regionUnitY); j += regionUnitY) {
|
||||||
|
if (!mapPager.FindRegion(i, j)) {
|
||||||
|
RequestRegion(i, j);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -47,7 +47,6 @@
|
|||||||
#include "player_character.hpp"
|
#include "player_character.hpp"
|
||||||
|
|
||||||
//STL
|
//STL
|
||||||
#include <functional>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
class InWorld : public BaseScene {
|
class InWorld : public BaseScene {
|
||||||
@@ -89,7 +88,6 @@ protected:
|
|||||||
//utilities
|
//utilities
|
||||||
int CheckBufferDistance(Region* const);
|
int CheckBufferDistance(Region* const);
|
||||||
void UpdateMap();
|
void UpdateMap();
|
||||||
void ForNearbyRegions(std::function<void (Region* const)> func);
|
|
||||||
|
|
||||||
//globals
|
//globals
|
||||||
ConfigUtility& config;
|
ConfigUtility& config;
|
||||||
|
|||||||
@@ -58,6 +58,8 @@ public:
|
|||||||
int GetRegionWidth() const { return regionWidth; }
|
int GetRegionWidth() const { return regionWidth; }
|
||||||
int GetRegionHeight() const { return regionHeight; }
|
int GetRegionHeight() const { return regionHeight; }
|
||||||
int GetRegionDepth() const { return regionDepth; }
|
int GetRegionDepth() const { return regionDepth; }
|
||||||
|
|
||||||
|
std::list<Region*>* GetContainer() { return ®ionList; }
|
||||||
protected:
|
protected:
|
||||||
int regionWidth;
|
int regionWidth;
|
||||||
int regionHeight;
|
int regionHeight;
|
||||||
|
|||||||
Reference in New Issue
Block a user