minor optimizations + MAX_WORK_PER_FRAME increased
This commit is contained in:
@@ -19,15 +19,15 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
const uint MAX_WORK_PER_FRAME = 64;
|
const uint MAX_WORK_PER_FRAME = 128;
|
||||||
const uint MIN_SURROUNDING = 9;
|
const uint MIN_SURROUNDING = 9;
|
||||||
|
|
||||||
ChunksController::ChunksController(Level* level, uint padding)
|
ChunksController::ChunksController(Level* level, uint padding)
|
||||||
: level(level),
|
: level(level),
|
||||||
chunks(level->chunks.get()),
|
chunks(level->chunks.get()),
|
||||||
lighting(level->lighting.get()),
|
lighting(level->lighting.get()),
|
||||||
padding(padding),
|
padding(padding),
|
||||||
generator(WorldGenerators::createGenerator(level->getWorld()->getGenerator(), level->content)) {
|
generator(WorldGenerators::createGenerator(level->getWorld()->getGenerator(), level->content)) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ChunksController::~ChunksController(){
|
ChunksController::~ChunksController(){
|
||||||
@@ -59,7 +59,7 @@ bool ChunksController::loadVisible(){
|
|||||||
for (uint z = padding; z < d-padding; z++){
|
for (uint z = padding; z < d-padding; z++){
|
||||||
for (uint x = padding; x < w-padding; x++){
|
for (uint x = padding; x < w-padding; x++){
|
||||||
int index = z * w + x;
|
int index = z * w + x;
|
||||||
auto chunk = chunks->chunks[index];
|
auto& chunk = chunks->chunks[index];
|
||||||
if (chunk != nullptr){
|
if (chunk != nullptr){
|
||||||
if (chunk->isLoaded() && !chunk->isLighted()) {
|
if (chunk->isLoaded() && !chunk->isLighted()) {
|
||||||
if (buildLights(chunk)) {
|
if (buildLights(chunk)) {
|
||||||
@@ -79,7 +79,7 @@ bool ChunksController::loadVisible(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto chunk = chunks->chunks[nearZ * w + nearX];
|
const auto& chunk = chunks->chunks[nearZ * w + nearX];
|
||||||
if (chunk != nullptr) {
|
if (chunk != nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
+38
-36
@@ -19,53 +19,55 @@ class LevelEvents;
|
|||||||
|
|
||||||
/* Player-centred chunks matrix */
|
/* Player-centred chunks matrix */
|
||||||
class Chunks {
|
class Chunks {
|
||||||
const ContentIndices* const contentIds;
|
const ContentIndices* const contentIds;
|
||||||
public:
|
public:
|
||||||
std::vector<std::shared_ptr<Chunk>> chunks;
|
std::vector<std::shared_ptr<Chunk>> chunks;
|
||||||
std::vector<std::shared_ptr<Chunk>> chunksSecond;
|
std::vector<std::shared_ptr<Chunk>> chunksSecond;
|
||||||
size_t volume;
|
size_t volume;
|
||||||
size_t chunksCount;
|
size_t chunksCount;
|
||||||
size_t visible = 0;
|
size_t visible = 0;
|
||||||
uint32_t w, d;
|
uint32_t w, d;
|
||||||
int32_t ox, oz;
|
int32_t ox, oz;
|
||||||
WorldFiles* worldFiles;
|
WorldFiles* worldFiles;
|
||||||
LevelEvents* events;
|
LevelEvents* events;
|
||||||
|
|
||||||
Chunks(uint32_t w, uint32_t d, int32_t ox, int32_t oz,
|
Chunks(uint32_t w, uint32_t d, int32_t ox, int32_t oz,
|
||||||
WorldFiles* worldFiles, LevelEvents* events, const Content* content);
|
WorldFiles* worldFiles, LevelEvents* events, const Content* content);
|
||||||
~Chunks() = default;
|
~Chunks() = default;
|
||||||
|
|
||||||
bool putChunk(std::shared_ptr<Chunk> chunk);
|
bool putChunk(std::shared_ptr<Chunk> chunk);
|
||||||
|
|
||||||
Chunk* getChunk(int32_t x, int32_t z);
|
Chunk* getChunk(int32_t x, int32_t z);
|
||||||
Chunk* getChunkByVoxel(int32_t x, int32_t y, int32_t z);
|
Chunk* getChunkByVoxel(int32_t x, int32_t y, int32_t z);
|
||||||
voxel* get(int32_t x, int32_t y, int32_t z);
|
voxel* get(int32_t x, int32_t y, int32_t z);
|
||||||
light_t getLight(int32_t x, int32_t y, int32_t z);
|
light_t getLight(int32_t x, int32_t y, int32_t z);
|
||||||
ubyte getLight(int32_t x, int32_t y, int32_t z, int channel);
|
ubyte getLight(int32_t x, int32_t y, int32_t z, int channel);
|
||||||
void set(int32_t x, int32_t y, int32_t z, uint32_t id, uint8_t states);
|
void set(int32_t x, int32_t y, int32_t z, uint32_t id, uint8_t states);
|
||||||
|
|
||||||
voxel* rayCast(glm::vec3 start,
|
voxel* rayCast(
|
||||||
glm::vec3 dir,
|
glm::vec3 start,
|
||||||
float maxLength,
|
glm::vec3 dir,
|
||||||
glm::vec3& end,
|
float maxLength,
|
||||||
glm::ivec3& norm,
|
glm::vec3& end,
|
||||||
glm::ivec3& iend);
|
glm::ivec3& norm,
|
||||||
|
glm::ivec3& iend
|
||||||
|
);
|
||||||
|
|
||||||
glm::vec3 rayCastToObstacle(glm::vec3 start, glm::vec3 dir, float maxDist);
|
glm::vec3 rayCastToObstacle(glm::vec3 start, glm::vec3 dir, float maxDist);
|
||||||
|
|
||||||
const AABB* isObstacleAt(float x, float y, float z);
|
const AABB* isObstacleAt(float x, float y, float z);
|
||||||
bool isSolidBlock(int32_t x, int32_t y, int32_t z);
|
bool isSolidBlock(int32_t x, int32_t y, int32_t z);
|
||||||
bool isReplaceableBlock(int32_t x, int32_t y, int32_t z);
|
bool isReplaceableBlock(int32_t x, int32_t y, int32_t z);
|
||||||
bool isObstacleBlock(int32_t x, int32_t y, int32_t z);
|
bool isObstacleBlock(int32_t x, int32_t y, int32_t z);
|
||||||
|
|
||||||
// does not move chunks inside
|
// does not move chunks inside
|
||||||
void _setOffset(int32_t x, int32_t z);
|
void _setOffset(int32_t x, int32_t z);
|
||||||
|
|
||||||
void setCenter(int32_t x, int32_t z);
|
void setCenter(int32_t x, int32_t z);
|
||||||
void translate(int32_t x, int32_t z);
|
void translate(int32_t x, int32_t z);
|
||||||
void resize(uint32_t newW, uint32_t newD);
|
void resize(uint32_t newW, uint32_t newD);
|
||||||
|
|
||||||
void saveAndClear();
|
void saveAndClear();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* VOXELS_CHUNKS_HPP_ */
|
#endif // VOXELS_CHUNKS_HPP_
|
||||||
|
|||||||
Reference in New Issue
Block a user