67 lines
1.6 KiB
C++
67 lines
1.6 KiB
C++
#ifndef STREAM_H_
|
|
#define STREAM_H_
|
|
#include <vector>
|
|
#include <unordered_map>
|
|
#include <tuple>
|
|
#include <algorithm>
|
|
#include <scene/3d/spatial.h>
|
|
class VoxelViewer;
|
|
class VoxelLodTerrain;
|
|
class StreamWorld : public Spatial {
|
|
GDCLASS(StreamWorld, Spatial)
|
|
private:
|
|
VoxelViewer *viewer;
|
|
VoxelLodTerrain *terrain;
|
|
Node *current_scene;
|
|
struct building {
|
|
String id;
|
|
Transform xform;
|
|
AABB aabb;
|
|
};
|
|
struct scene_data {
|
|
Ref<PackedScene> packed_scene;
|
|
String path;
|
|
Ref<ResourceInteractiveLoader> loader;
|
|
std::vector<int> buildings;
|
|
};
|
|
HashMap<String, struct scene_data> scenes;
|
|
HashMap<int, Node *> item_nodes;
|
|
using tile_key_t = std::tuple<int, int>;
|
|
struct tile_hash : public std::unary_function<key_t, std::size_t> {
|
|
std::size_t operator()(const tile_key_t &k) const
|
|
{
|
|
return std::get<0>(k) ^ std::get<1>(k);
|
|
}
|
|
};
|
|
using tile_map_t = std::unordered_map<const tile_key_t,
|
|
std::vector<int>, tile_hash>;
|
|
HashMap<String, String> building_data;
|
|
std::vector<struct building> buildings;
|
|
Vector3 eye;
|
|
tile_map_t tiles;
|
|
tile_map_t loaded_tiles;
|
|
int world_extent;
|
|
int tile_size;
|
|
int view_distance;
|
|
bool initialized;
|
|
int current_x, current_z;
|
|
void _notification(int which);
|
|
void read_buildings_json(const String &buildings_path);
|
|
void create_tilemap();
|
|
void update_view();
|
|
void viewer_dead();
|
|
void terrain_dead();
|
|
void load_tile(int tx, int ty);
|
|
void erase_tile(int tx, int ty);
|
|
void load_building(int id);
|
|
void unload_building(int id);
|
|
void request_item(int type, int item);
|
|
void update_items();
|
|
static void _bind_methods();
|
|
|
|
public:
|
|
StreamWorld();
|
|
~StreamWorld();
|
|
static void cleanup();
|
|
};
|
|
#endif |