123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #include "World.h"
- World::World(IChunkProvider* chunks) : chunks(chunks)
- {
- }
- World::~World()
- {
-
- }
- void World::registerChunkListener(IChunkListener* listener)
- {
- chunkListener.add(listener);
- }
- void World::removeChunkListener(IChunkListener* listener)
- {
- chunkListener.remove(listener);
- }
- void World::updateDirtyChunks()
- {
- chunks->forEachLoadedChunk(this, [](Chunk& c, void* world)
- {
- if(c.isDirty())
- {
- ((World*) world)->updateChunk(c);
- }
- });
- }
- void World::updateChunk(Chunk& c)
- {
- int x = c.getChunkX();
- int z = c.getChunkZ();
-
- Chunk* north = chunks->getChunk(x + 1, z);
- Chunk* east = chunks->getChunk(x, z + 1);
- Chunk* south = chunks->getChunk(x - 1, z);
- Chunk* west = chunks->getChunk(x, z - 1);
-
- for(int i = 0; i < chunkListener.getSize(); i++)
- {
- chunkListener.get(i, nullptr)->updateChunk(c, north, east, south, west);
- }
- }
|