#include "DeerRender/Voxels/VoxelWorldRenderData.h"
#include "Deer/Voxels/Chunk.h"
#include "DeerRender/VoxelWorld.h"

namespace Deer {
	namespace VoxelWorld {
		// Chunk render data
		Scope<ChunkRender[]> chunksRender;
		ChunkUpdateQueue chunkQueue;

		// Voxel creation data
		std::vector<uint32_t> indices;
		std::vector<SolidVoxelVertexData> vertexData;
		std::queue<VoxelCordinates> ambientLightPropagation;
		std::queue<VoxelCordinates> voxelLightPropagation;
		std::vector<VoxelCordinates> tmp_voxelLightSource;
	} // namespace VoxelWorld

	void VoxelWorld::clearRenderVars() {
		chunksRender.reset();
		chunkQueue.reset();

		indices.clear();
		vertexData.clear();

		while (!ambientLightPropagation.empty()) {
			ambientLightPropagation.pop();
		}
		while (!voxelLightPropagation.empty()) {
			voxelLightPropagation.pop();
		}

		tmp_voxelLightSource.clear();
	}

	void VoxelWorld::initializeRenderVars(const VoxelWorldProps& props) {
		chunksRender = MakeScope<ChunkRender[]>(props.getChunkCount());
	}
} // namespace Deer