|
@@ -7,8 +7,6 @@
|
|
|
|
|
|
using namespace Framework;
|
|
|
|
|
|
-#define MAX_VIEW_DISTANCE CHUNK_SIZE * 8
|
|
|
-
|
|
|
Dimension::Dimension()
|
|
|
: chunks(new Trie<Chunk>()),
|
|
|
entities(new RCArray<Entity>())
|
|
@@ -67,6 +65,19 @@ void Dimension::api(char* message)
|
|
|
b->api(message + 13);
|
|
|
break;
|
|
|
}
|
|
|
+ case 4: // add new chunck
|
|
|
+ {
|
|
|
+ Punkt center;
|
|
|
+ center.x = *(int*)(message + 1);
|
|
|
+ center.y = *(int*)(message + 5);
|
|
|
+ ByteArrayReader reader(message + 9, INT_MAX, 0);
|
|
|
+ std::cout << "downloading chunk " << center.x << ", " << center.y << "\n";
|
|
|
+ Chunk* chunk = new Chunk(center);
|
|
|
+ chunk->load(&reader);
|
|
|
+ setChunk(chunk, center);
|
|
|
+ currentGame->onChunkAdded(center);
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -106,7 +117,7 @@ void Dimension::addEntity(Entity* entity)
|
|
|
currentGame->setVisibility(entity, 1);
|
|
|
}
|
|
|
|
|
|
-void Dimension::setChunk(Chunk* chunk, Punkt center, World* zWorld)
|
|
|
+void Dimension::setChunk(Chunk* chunk, Punkt center)
|
|
|
{
|
|
|
char addr[8];
|
|
|
getAddrOfWorld(center, addr);
|
|
@@ -114,7 +125,7 @@ void Dimension::setChunk(Chunk* chunk, Punkt center, World* zWorld)
|
|
|
cs.lock();
|
|
|
if (old)
|
|
|
{
|
|
|
- zWorld->setVisibility(old, 0);
|
|
|
+ currentGame->setVisibility(old, 0);
|
|
|
int index = 0;
|
|
|
for (auto iterator = chunkList.begin(); iterator; ++iterator, ++index)
|
|
|
{
|
|
@@ -133,7 +144,7 @@ void Dimension::setChunk(Chunk* chunk, Punkt center, World* zWorld)
|
|
|
chunks->set(addr, 8, chunk);
|
|
|
if (chunk)
|
|
|
{
|
|
|
- zWorld->setVisibility(chunk, 1);
|
|
|
+ currentGame->setVisibility(chunk, 1);
|
|
|
}
|
|
|
cs.unlock();
|
|
|
}
|
|
@@ -143,21 +154,21 @@ bool Dimension::hasChunck(int x, int y) const
|
|
|
return zChunk(Punkt(x, y));
|
|
|
}
|
|
|
|
|
|
-void Dimension::removeDistantChunks(Punkt wPos, World* zWorld)
|
|
|
+void Dimension::removeDistantChunks(Punkt wPos)
|
|
|
{
|
|
|
Array<int> removed;
|
|
|
int index = 0;
|
|
|
for (Chunk* chunk : chunkList)
|
|
|
{
|
|
|
- if ((chunk->getCenter() - wPos).getLength() > MAX_VIEW_DISTANCE)
|
|
|
+ if ((chunk->getCenter() - wPos).getLength() > MAX_VIEW_DISTANCE * 2)
|
|
|
removed.add(index, 0);
|
|
|
index++;
|
|
|
}
|
|
|
for (int i : removed)
|
|
|
{
|
|
|
Chunk* chunk = chunkList.get(i);
|
|
|
- zWorld->setVisibility(chunk, 0);
|
|
|
- setChunk(0, chunk->getCenter(), zWorld);
|
|
|
+ currentGame->setVisibility(chunk, 0);
|
|
|
+ setChunk(0, chunk->getCenter());
|
|
|
}
|
|
|
}
|
|
|
|