102 lines
2.5 KiB
C
Raw Normal View History

// http://www.apache.org/licenses/LICENSE-2.0
// Copyright 2014 Perttu Ahola <celeron55@gmail.com>
#pragma once
#include "interface/event.h"
#include "interface/server.h"
#include "interface/module.h"
2014-10-12 14:26:19 +03:00
#include "interface/voxel.h"
#include <PolyVoxCore/Vector.h>
2014-10-12 16:54:04 +03:00
#include <PolyVoxCore/Region.h>
#include <PolyVoxCore/RawVolume.h>
#include <functional>
namespace Urho3D
{
class Context;
class Scene;
2014-10-20 11:12:30 +03:00
class Node;
}
namespace voxelworld
{
namespace magic = Urho3D;
2014-10-12 14:26:19 +03:00
namespace pv = PolyVox;
using interface::VoxelInstance;
2014-10-12 14:26:19 +03:00
struct GenerationRequest: public interface::Event::Private
{
pv::Vector3DInt16 section_p;
GenerationRequest(const pv::Vector3DInt16 &section_p):
2014-10-17 13:49:55 +03:00
section_p(section_p)
2014-10-12 14:26:19 +03:00
{}
};
struct NodeVoxelDataUpdatedEvent: public interface::Event::Private
{
uint node_id;
NodeVoxelDataUpdatedEvent(uint node_id): node_id(node_id){}
};
2014-10-20 11:12:30 +03:00
struct Interface;
struct CommitHook
{
virtual ~CommitHook(){}
virtual void in_thread(voxelworld::Interface *ivoxelworld,
const pv::Vector3DInt32 &chunk_p,
sp_<pv::RawVolume<VoxelInstance>> volume){}
virtual void in_scene(voxelworld::Interface *ivoxelworld,
const pv::Vector3DInt32 &chunk_p, magic::Node *n){}
};
struct Interface
{
2014-10-20 11:12:30 +03:00
virtual interface::VoxelRegistry* get_voxel_reg() = 0;
virtual void add_commit_hook(up_<CommitHook> hook) = 0;
2014-10-12 14:26:19 +03:00
2014-10-20 14:05:58 +03:00
virtual pv::Vector3DInt16 get_section_size_voxels() = 0;
virtual pv::Region get_section_region_voxels(
2014-10-12 16:54:04 +03:00
const pv::Vector3DInt16 &section_p) = 0;
2014-10-12 14:26:19 +03:00
2014-10-20 11:12:30 +03:00
virtual const pv::Vector3DInt16& get_chunk_size_voxels() = 0;
virtual pv::Region get_chunk_region_voxels(
const pv::Vector3DInt32 &chunk_p) = 0;
virtual void load_or_generate_section(
const pv::Vector3DInt16 &section_p) = 0;
2014-10-12 14:26:19 +03:00
virtual void set_voxel(const pv::Vector3DInt32 &p,
const VoxelInstance &v,
bool disable_warnings = false) = 0;
virtual size_t num_buffers_loaded() = 0;
2014-10-12 14:49:11 +03:00
virtual void commit() = 0;
virtual VoxelInstance get_voxel(const pv::Vector3DInt32 &p,
bool disable_warnings = false) = 0;
// NOTE: There is no interface in here for directly accessing chunk
// volumes of static nodes, because it is so much more hassly and was
// tested to improve speed only by 53% compared to the current very
// robust interface.
};
inline bool access(interface::Server *server,
std::function<void(voxelworld::Interface*)> cb)
{
return server->access_module("voxelworld", [&](interface::Module *module){
2014-10-12 14:49:11 +03:00
auto *iface = (voxelworld::Interface*)module->check_interface();
cb(iface);
iface->commit();
});
}
}
// vim: set noet ts=4 sw=4: