Added streaming system
This commit is contained in:
80
src/modules/stream/stream.h
Normal file
80
src/modules/stream/stream.h
Normal file
@@ -0,0 +1,80 @@
|
||||
#ifndef STREAM_H_
|
||||
#define STREAM_H_
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <tuple>
|
||||
#include <algorithm>
|
||||
#include <scene/3d/spatial.h>
|
||||
#include <scene/3d/visual_instance.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();
|
||||
};
|
||||
class RoadDebug : public VisualInstance {
|
||||
GDCLASS(RoadDebug, VisualInstance)
|
||||
protected:
|
||||
RID imm;
|
||||
Ref<SpatialMaterial> material;
|
||||
void _notification(int which);
|
||||
AABB aabb;
|
||||
|
||||
public:
|
||||
RoadDebug();
|
||||
~RoadDebug();
|
||||
virtual AABB get_aabb() const;
|
||||
virtual PoolVector<Face3> get_faces(uint32_t p_usage_flags) const;
|
||||
};
|
||||
#endif
|
||||
Reference in New Issue
Block a user