You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
2.0 KiB
104 lines
2.0 KiB
#pragma once
|
|
#include <SFML/System/Vector3.hpp>
|
|
#include <SFML/System/Vector2.hpp>
|
|
#include <SFML/Graphics/Color.hpp>
|
|
#include <iostream>
|
|
#include <list>
|
|
#include <random>
|
|
#include <iostream>
|
|
#include <functional>
|
|
#include <cmath>
|
|
#include "util.hpp"
|
|
#include <deque>
|
|
#include <unordered_map>
|
|
|
|
#define _USE_MATH_DEFINES
|
|
#include <math.h>
|
|
|
|
#define CHUNK_DIM 32
|
|
#define OCT_DIM 64
|
|
|
|
struct KeyHasher {
|
|
std::size_t operator()(const sf::Vector3i& k) const {
|
|
|
|
return ((std::hash<int>()(k.x)
|
|
^ (std::hash<int>()(k.y) << 1)) >> 1)
|
|
^ (std::hash<int>()(k.z) << 1);
|
|
}
|
|
};
|
|
|
|
struct Chunk {
|
|
Chunk(int type) { voxel_data = new int[CHUNK_DIM * CHUNK_DIM * CHUNK_DIM]; set(type); };
|
|
Chunk() { };
|
|
void set(int type);
|
|
~Chunk() { voxel_data = nullptr; };
|
|
int* voxel_data;
|
|
};
|
|
|
|
class Allocator {
|
|
|
|
public:
|
|
uint64_t dat[10000];
|
|
int dat_pos = 0;
|
|
Allocator() {};
|
|
~Allocator() {};
|
|
void reserve(int presidence, std::vector<uint64_t> cps) {
|
|
memcpy(&dat[dat_pos], cps.data(), cps.size() * sizeof(uint64_t));
|
|
dat_pos += cps.size();
|
|
}
|
|
|
|
};
|
|
|
|
|
|
class Map {
|
|
public:
|
|
|
|
Map(sf::Vector3i dim);
|
|
void generate_octree();
|
|
|
|
void load_unload(sf::Vector3i world_position);
|
|
void load_single(sf::Vector3i world_position);
|
|
|
|
sf::Vector3i getDimensions();
|
|
char *list;
|
|
//sf::Vector3i dimensions;
|
|
|
|
void setVoxel(sf::Vector3i position, int val);
|
|
|
|
void moveLight(sf::Vector2f in);
|
|
sf::Vector3f global_light;
|
|
|
|
Allocator a;
|
|
|
|
protected:
|
|
|
|
private:
|
|
|
|
|
|
uint64_t generate_children(sf::Vector3i pos, int dim);
|
|
int cycle_counter = 0;
|
|
|
|
uint64_t block[1024];
|
|
int stack_position = 0;
|
|
char getVoxel(sf::Vector3i pos);
|
|
char* voxel_data = new char[OCT_DIM * OCT_DIM * OCT_DIM];
|
|
|
|
|
|
std::unordered_map<sf::Vector3i, Chunk, KeyHasher> chunk_map;
|
|
|
|
double* height_map;
|
|
|
|
// 2^k
|
|
int chunk_radius = 6;
|
|
|
|
sf::Vector3i world_to_chunk(sf::Vector3i world_coords) {
|
|
return sf::Vector3i(
|
|
world_coords.x / CHUNK_DIM + 1,
|
|
world_coords.y / CHUNK_DIM + 1,
|
|
world_coords.z / CHUNK_DIM + 1
|
|
);
|
|
}
|
|
};
|
|
|
|
|