2014-10-12 10:06:07 +03:00
|
|
|
#include "core/log.h"
|
|
|
|
#include "client_file/api.h"
|
|
|
|
#include "network/api.h"
|
|
|
|
#include "replicate/api.h"
|
2014-10-12 14:49:11 +03:00
|
|
|
#include "voxelworld/api.h"
|
2014-10-12 10:06:07 +03:00
|
|
|
#include "interface/module.h"
|
|
|
|
#include "interface/server.h"
|
|
|
|
#include "interface/event.h"
|
|
|
|
#include "interface/mesh.h"
|
|
|
|
#include "interface/voxel.h"
|
|
|
|
#include <Scene.h>
|
|
|
|
#include <RigidBody.h>
|
|
|
|
#include <CollisionShape.h>
|
|
|
|
#include <ResourceCache.h>
|
|
|
|
#include <Context.h>
|
|
|
|
#include <StaticModel.h>
|
|
|
|
#include <Model.h>
|
|
|
|
#include <Material.h>
|
|
|
|
#include <Texture2D.h>
|
|
|
|
#include <Technique.h>
|
|
|
|
#include <cereal/archives/portable_binary.hpp>
|
|
|
|
#include <cereal/types/unordered_map.hpp>
|
|
|
|
#include <cereal/types/vector.hpp>
|
|
|
|
|
|
|
|
namespace digger {
|
|
|
|
|
|
|
|
using interface::Event;
|
|
|
|
using namespace Urho3D;
|
|
|
|
namespace magic = Urho3D;
|
2014-10-12 14:49:11 +03:00
|
|
|
namespace pv = PolyVox;
|
2014-10-12 10:06:07 +03:00
|
|
|
|
|
|
|
struct Module: public interface::Module
|
|
|
|
{
|
|
|
|
interface::Server *m_server;
|
|
|
|
uint m_slow_count = 0;
|
|
|
|
sp_<interface::TextureAtlasRegistry> m_atlas_reg;
|
|
|
|
sp_<interface::VoxelRegistry> m_voxel_reg;
|
|
|
|
|
|
|
|
Module(interface::Server *server):
|
|
|
|
interface::Module("digger"),
|
|
|
|
m_server(server)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
~Module()
|
|
|
|
{}
|
|
|
|
|
|
|
|
void init()
|
|
|
|
{
|
|
|
|
m_server->sub_event(this, Event::t("core:start"));
|
|
|
|
m_server->sub_event(this, Event::t("core:continue"));
|
|
|
|
m_server->sub_event(this, Event::t("core:tick"));
|
|
|
|
m_server->sub_event(this, Event::t("client_file:files_transmitted"));
|
2014-10-12 14:49:11 +03:00
|
|
|
m_server->sub_event(this, Event::t("voxelworld:generation_request"));
|
2014-10-12 10:06:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void event(const Event::Type &type, const Event::Private *p)
|
|
|
|
{
|
|
|
|
EVENT_VOIDN("core:start", on_start)
|
|
|
|
EVENT_VOIDN("core:continue", on_continue)
|
|
|
|
EVENT_TYPEN("core:tick", on_tick, interface::TickEvent)
|
2014-10-12 14:49:11 +03:00
|
|
|
EVENT_TYPEN("client_file:files_transmitted",
|
|
|
|
on_files_transmitted, client_file::FilesTransmitted)
|
|
|
|
EVENT_TYPEN("voxelworld:generation_request",
|
|
|
|
on_generation_request, voxelworld::GenerationRequest)
|
2014-10-12 10:06:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void on_start()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void on_continue()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_scene()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void on_tick(const interface::TickEvent &event)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void on_files_transmitted(const client_file::FilesTransmitted &event)
|
|
|
|
{
|
|
|
|
network::access(m_server, [&](network::Interface *inetwork){
|
|
|
|
inetwork->send(event.recipient, "core:run_script",
|
|
|
|
"buildat.run_script_file(\"main/init.lua\")");
|
|
|
|
});
|
|
|
|
}
|
2014-10-12 14:49:11 +03:00
|
|
|
|
|
|
|
void on_generation_request(const voxelworld::GenerationRequest &event)
|
|
|
|
{
|
|
|
|
voxelworld::access(m_server, [&](voxelworld::Interface *ivoxelworld){
|
|
|
|
const pv::Vector3DInt16 §ion_p = event.section_p;
|
|
|
|
pv::Vector3DInt32 p0;
|
|
|
|
pv::Vector3DInt32 p1;
|
|
|
|
ivoxelworld->get_section_region(section_p, p0, p1);
|
|
|
|
|
|
|
|
ivoxelworld->set_voxel(p0, interface::VoxelInstance(3));
|
|
|
|
});
|
|
|
|
}
|
2014-10-12 10:06:07 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
BUILDAT_EXPORT void* createModule_main(interface::Server *server){
|
|
|
|
return (void*)(new Module(server));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// vim: set noet ts=4 sw=4:
|