Public Member Functions | |
| World (std::unique_ptr< ITerrainGenerator > gen, uint32_t genThreads=8) | |
| World (std::unique_ptr< ITerrainGenerator > gen, glm::ivec3 chunkDims, uint32_t genThreads=8) | |
| glm::ivec3 | chunkDims () const |
| Get the chunk dimensions for this world. | |
| virtual std::future< void > | loadChunks (const glm::ivec3 &from, const glm::ivec3 &to, bool unloadRest=false) |
| Loads chunks in the given range. | |
| virtual void | unloadChunks (const glm::ivec3 &from, const glm::ivec3 &to) |
| Unloads chunks in the given range. | |
| void | unloadAllChunks (const std::vector< ChunkID > &except={}) |
| Unloads all chunks except the given ones. | |
| void | unloadChunksFromMemory (const std::vector< ChunkID > &ids) |
| Unloads given chunks from memory. | |
| std::shared_ptr< Chunk > | getChunk (const ChunkID &id) |
| std::shared_ptr< const Chunk > | getChunk (const ChunkID &id) const |
| template<typename T > | |
| std::shared_ptr< T > | getChunkAs (const ChunkID &id) |
| template<typename T > | |
| std::shared_ptr< const T > | getChunkAs (const ChunkID &id) const |
| Gets a const chunk and casts it to the specified custom chunk type. | |
| const std::unordered_set< ChunkID > & | loadedChunks () const |
| void | checkAndUpdateSurroundingChunks (const ChunkID &chID, const glm::ivec3 &pos) |
| Checks if the surrounding chunks need to be updated due to a block change. | |
| BlockID | getBlockID (const ChunkID &chID, const glm::ivec3 &pos, bool fallbackToGenerator, BlockState **state=nullptr) |
| Gets the block ID at the given position. | |
| void | setBlock (const ChunkID &chID, const glm::ivec3 &pos, BlockID blockID, std::optional< BlockState > state=std::nullopt) |
| void | setBlock (const ChunkID &chID, const glm::ivec3 &pos, MultiBlock &&multiBlock) |
| MultiBlock * | getMultiBlock (const ChunkID &chID, const glm::ivec3 &pos) |
| void | setBlock (glm::ivec3 pos, BlockID blockID, std::optional< BlockState > state=std::nullopt) |
| void | setBlock (glm::ivec3 pos, MultiBlock &&multiBlock) |
| MultiBlock * | getMultiBlock (glm::ivec3 pos) |
| BlockID | getBlockID (glm::vec3 pos, bool fallbackToGenerator, BlockState **state=nullptr) |
| Gets the block ID at the given position. | |
| const ITerrainGenerator * | getGenerator () const |
| Gets the terrain generator for this world. | |
| const Material & | getMaterial () const |
| Skybox & | getSkybox () |
| virtual void | render (Engine &engine, const Camera *camera, int pass=0) override |
| Engine will call this method before rendering the object. You have to set at the very least the gl::Attributes instance and material. Model matrix is optional, but recommended. | |
| virtual void | update (float dt) override |
| virtual void | afterBlockSet (const glm::ivec3 &pos, BlockID blockID, BlockState *state=nullptr) |
Public Member Functions inherited from engine::EventSource | |
| void | subscribe (EventSite *site) |
| void | unsubscribe (EventSite *site) |
| template<typename TEventSite , typename TEvent > | |
| void | fireEvent (void(TEventSite::*fire)(TEvent *event), TEvent *event) |
Protected Member Functions | |
| virtual std::shared_ptr< Chunk > | createChunk (const ChunkID &id) |
| Factory method for creating chunks. Override this to provide custom Chunk subclasses. | |
| bool | canSeeFace (const Block &curBlock, glm::vec3 pos, glm::ivec3 dir) const |
| Checks if the face of current block facing given direction can be seen and thus should be rendered. | |
Protected Member Functions inherited from engine::LevelEventSource | |
| void | fireChunkUnloadEvent (ChunkUnloadEvent *pEvent) |
| void | fireChunkBeforeLoadEvent (ChunkBeforeLoadEvent *pEvent) |
Protected Attributes | |
| std::unordered_map< ChunkID, std::shared_ptr< Chunk > > | m_chunks |
| std::unordered_set< ChunkID > | m_loadedChunks |
| std::unique_ptr< ITerrainGenerator > | m_generator = nullptr |
| glm::ivec3 | m_chunkDims |
| Material | m_material |
| Skybox | m_skybox |
| ThreadPool | m_genPool |
Friends | |
| class | Chunk |
|
inlinevirtual |
|
protected |
Checks if the face of current block facing given direction can be seen and thus should be rendered.
| curBlock | The current block. |
| pos | The position of the current block. |
| dir | The direction from which the face is being checked. |
| void World::checkAndUpdateSurroundingChunks | ( | const ChunkID & | chID, |
| const glm::ivec3 & | pos | ||
| ) |
Checks if the surrounding chunks need to be updated due to a block change.
| chID | The chunk that was changed. |
| pos | The position of the block that was changed. |
|
inline |
Get the chunk dimensions for this world.
Factory method for creating chunks. Override this to provide custom Chunk subclasses.
| id | The chunk coordinates to create the chunk at. |
| BlockID World::getBlockID | ( | const ChunkID & | chID, |
| const glm::ivec3 & | pos, | ||
| bool | fallbackToGenerator, | ||
| BlockState ** | state = nullptr |
||
| ) |
Gets the block ID at the given position.
| chID | The chunk to query the block from |
| pos | The position of the block within the chunk (0 to Chunk::Dims) |
| fallbackToGenerator | If true, the generator will be used to get the block ID if the chunk is not generated |
| state | [out] The state of the block. If nullptr, the state will not be returned. |
| BlockID World::getBlockID | ( | glm::vec3 | pos, |
| bool | fallbackToGenerator, | ||
| BlockState ** | state = nullptr |
||
| ) |
Gets the block ID at the given position.
| pos | The position of the block in world space |
| fallbackToGenerator | If true, the generator will be used to get the block ID if the chunk is not generated |
| state | [out] The state of the block. If nullptr, the state will not be returned. |
| std::shared_ptr< const T > engine::World::getChunkAs | ( | const ChunkID & | id | ) | const |
Gets a const chunk and casts it to the specified custom chunk type.
| T | The custom chunk type (must inherit from Chunk). |
| id | The chunk ID to retrieve. |
|
inline |
Gets the terrain generator for this world.
|
virtual |
Engine will call this method before rendering the object. You have to set at the very least the gl::Attributes instance and material. Model matrix is optional, but recommended.
| Engine | The render engine to which you can push RenderContext to schedule rendering. |
| pass | Number indicating the pass, if you need multiple passes for rendering. |
Implements engine::Renderable.
| void World::unloadAllChunks | ( | const std::vector< ChunkID > & | except = {} | ) |
Unloads all chunks except the given ones.
| except | Chunks to keep loaded. |
|
virtual |
Unloads chunks in the given range.
| void World::unloadChunksFromMemory | ( | const std::vector< ChunkID > & | ids | ) |
Unloads given chunks from memory.
| ids | Chunks to unload. |
|
overridevirtual |
Implements engine::Updateable.