mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 02:51:49 +00:00
A lot of changes in almost all files
This commit is contained in:
parent
cd3e737385
commit
bc9d29cf68
28 changed files with 3485 additions and 476 deletions
64
src/voxels/ChunksLoader.cpp
Normal file
64
src/voxels/ChunksLoader.cpp
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
#include "ChunksLoader.h"
|
||||
#include <chrono>
|
||||
|
||||
#include "Chunk.h"
|
||||
#include "Chunks.h"
|
||||
#include "WorldGenerator.h"
|
||||
#include "../lighting/Lighting.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
void ChunksLoader::_thread(){
|
||||
Chunks chunks(3,3,3, -1,-1,-1);
|
||||
Lighting lighting(&chunks);
|
||||
while (working){
|
||||
if (current == nullptr){
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
continue;
|
||||
}
|
||||
Chunk* chunk = current;
|
||||
//std::cout << "LOADER: received chunk " << chunk->x << " " << chunk->y << " " << chunk->z << std::endl;
|
||||
|
||||
chunks._setOffset(chunk->x-1, chunk->y-1, chunk->z-1);
|
||||
|
||||
if (!chunk->generated){
|
||||
WorldGenerator::generate(chunk->voxels, chunk->x, chunk->y, chunk->z);
|
||||
//std::cout << "LOADER: generated chunk" << std::endl;
|
||||
}
|
||||
|
||||
/*for (int i = 0; i < 27; i++){
|
||||
Chunk* other = closes[i];
|
||||
if (other == nullptr)
|
||||
continue;
|
||||
chunks.putChunk(other);
|
||||
}*/
|
||||
chunks.putChunk(chunk);
|
||||
lighting.onChunkLoaded(chunk->x, chunk->y, chunk->z, true);
|
||||
chunks.clear(false);
|
||||
for (int i = 0; i < 27; i++){
|
||||
Chunk* other = closes[i];
|
||||
delete other;
|
||||
}
|
||||
chunk->ready = true;
|
||||
current = nullptr;
|
||||
//std::cout << "LOADER: success" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void ChunksLoader::perform(Chunk* chunk, const Chunk** cs){
|
||||
if (isBusy()){
|
||||
std::cerr << "performing while busy" << std::endl;
|
||||
return;
|
||||
}
|
||||
if (closes == nullptr){
|
||||
closes = new Chunk*[27];
|
||||
}
|
||||
for (int i = 0; i < 27; i++){
|
||||
const Chunk* other = cs[i];
|
||||
if (other == nullptr)
|
||||
closes[i] = nullptr;
|
||||
else
|
||||
closes[i] = other->clone();
|
||||
}
|
||||
current = chunk;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue