games: Fix everything
This commit is contained in:
parent
7bfdb549ed
commit
13b72276c8
@ -65,5 +65,3 @@ Buildat TODO
|
||||
- Make some kind of an ace of spades clone (or less of a clone); something that
|
||||
requires the game to control the creation and deletion of the world anyway,
|
||||
and implement the required interfaces
|
||||
- Fix everything in /games/
|
||||
- Use builtin/main_context
|
||||
|
@ -433,7 +433,7 @@ struct Module: public interface::Module
|
||||
// TODO: Store main scene reference
|
||||
// Just do this for now
|
||||
main_context::access(m_server, [&](main_context::Interface *imc){
|
||||
m_main_scene = imc->create_scene();
|
||||
imc->delete_scene(m_main_scene);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "client_file/api.h"
|
||||
#include "network/api.h"
|
||||
#include "replicate/api.h"
|
||||
#include "main_context/api.h"
|
||||
#include "interface/module.h"
|
||||
#include "interface/server.h"
|
||||
#include "interface/event.h"
|
||||
@ -22,14 +23,18 @@
|
||||
|
||||
namespace entitytest {
|
||||
|
||||
using interface::Event;
|
||||
using namespace Urho3D;
|
||||
|
||||
using interface::Event;
|
||||
using main_context::SceneReference;
|
||||
|
||||
struct Module: public interface::Module
|
||||
{
|
||||
interface::Server *m_server;
|
||||
uint m_slow_count = 0;
|
||||
|
||||
SceneReference m_main_scene;
|
||||
|
||||
Module(interface::Server *server):
|
||||
interface::Module(MODULE),
|
||||
m_server(server)
|
||||
@ -66,8 +71,10 @@ struct Module: public interface::Module
|
||||
|
||||
void on_start()
|
||||
{
|
||||
m_server->access_scene([&](Scene *scene)
|
||||
{
|
||||
main_context::access(m_server, [&](main_context::Interface *imc){
|
||||
m_main_scene = imc->create_scene();
|
||||
|
||||
Scene *scene = imc->get_scene(m_main_scene);
|
||||
Context *context = scene->GetContext();
|
||||
ResourceCache *cache = context->GetSubsystem<ResourceCache>();
|
||||
auto *m = cache->GetResource<Material>("Materials/Stone.xml");
|
||||
@ -137,7 +144,8 @@ struct Module: public interface::Module
|
||||
log_d(MODULE, "entitytest::on_tick");
|
||||
static uint a = 0;
|
||||
if(((a++) % 100) == 0){
|
||||
m_server->access_scene([&](Scene *scene){
|
||||
main_context::access(m_server, [&](main_context::Interface *imc){
|
||||
Scene *scene = imc->get_scene(m_main_scene);
|
||||
Node *n = scene->GetChild("Box");
|
||||
n->SetPosition(Vector3(0.0f, 6.0f, 0.0f));
|
||||
n->SetRotation(Quaternion(30, 60, 90));
|
||||
@ -159,7 +167,8 @@ struct Module: public interface::Module
|
||||
});
|
||||
return;
|
||||
}
|
||||
m_server->access_scene([&](Scene *scene){
|
||||
main_context::access(m_server, [&](main_context::Interface *imc){
|
||||
Scene *scene = imc->get_scene(m_main_scene);
|
||||
Node *n = scene->GetChild("Box");
|
||||
//n->Translate(Vector3(0.1f, 0, 0));
|
||||
Vector3 p = n->GetPosition();
|
||||
@ -183,6 +192,9 @@ struct Module: public interface::Module
|
||||
{
|
||||
log_v(MODULE, "on_files_transmitted(): recipient=%zu", event.recipient);
|
||||
|
||||
replicate::access(m_server, [&](replicate::Interface *ireplicate){
|
||||
ireplicate->assign_scene_to_peer(m_main_scene, event.recipient);
|
||||
});
|
||||
network::access(m_server, [&](network::Interface *inetwork){
|
||||
inetwork->send(event.recipient, "core:run_script",
|
||||
"buildat.run_script_file(\"main/init.lua\")");
|
||||
|
@ -3,6 +3,7 @@
|
||||
{"module": "network"},
|
||||
{"module": "client_lua"},
|
||||
{"module": "client_data"},
|
||||
{"module": "main_context"},
|
||||
{"module": "replicate"}
|
||||
]
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "client_file/api.h"
|
||||
#include "network/api.h"
|
||||
#include "replicate/api.h"
|
||||
#include "main_context/api.h"
|
||||
#include "interface/module.h"
|
||||
#include "interface/server.h"
|
||||
#include "interface/event.h"
|
||||
@ -23,14 +24,18 @@
|
||||
|
||||
namespace geometry {
|
||||
|
||||
using interface::Event;
|
||||
using namespace Urho3D;
|
||||
|
||||
using interface::Event;
|
||||
using main_context::SceneReference;
|
||||
|
||||
struct Module: public interface::Module
|
||||
{
|
||||
interface::Server *m_server;
|
||||
uint m_slow_count = 0;
|
||||
|
||||
SceneReference m_main_scene;
|
||||
|
||||
Module(interface::Server *server):
|
||||
interface::Module(MODULE),
|
||||
m_server(server)
|
||||
@ -58,8 +63,10 @@ struct Module: public interface::Module
|
||||
|
||||
void on_start()
|
||||
{
|
||||
m_server->access_scene([&](Scene *scene)
|
||||
{
|
||||
main_context::access(m_server, [&](main_context::Interface *imc){
|
||||
m_main_scene = imc->create_scene();
|
||||
|
||||
Scene *scene = imc->get_scene(m_main_scene);
|
||||
Context *context = scene->GetContext();
|
||||
ResourceCache *cache = context->GetSubsystem<ResourceCache>();
|
||||
|
||||
@ -116,8 +123,8 @@ struct Module: public interface::Module
|
||||
|
||||
void update_scene()
|
||||
{
|
||||
m_server->access_scene([&](Scene *scene)
|
||||
{
|
||||
main_context::access(m_server, [&](main_context::Interface *imc){
|
||||
Scene *scene = imc->get_scene(m_main_scene);
|
||||
Context *context = scene->GetContext();
|
||||
ResourceCache *cache = context->GetSubsystem<ResourceCache>();
|
||||
|
||||
@ -170,7 +177,8 @@ struct Module: public interface::Module
|
||||
float rx = (float)rand() / RAND_MAX * 180;
|
||||
float ry = (float)rand() / RAND_MAX * 180;
|
||||
float rz = (float)rand() / RAND_MAX * 180;
|
||||
m_server->access_scene([&](Scene *scene){
|
||||
main_context::access(m_server, [&](main_context::Interface *imc){
|
||||
Scene *scene = imc->get_scene(m_main_scene);
|
||||
Node *n = scene->GetChild("Testbox");
|
||||
n->SetRotation(Quaternion(rx, ry, rz));
|
||||
n->SetPosition(Vector3(-0.5f, 8.0f, 0.0f));
|
||||
@ -181,6 +189,9 @@ struct Module: public interface::Module
|
||||
|
||||
void on_files_transmitted(const client_file::FilesTransmitted &event)
|
||||
{
|
||||
replicate::access(m_server, [&](replicate::Interface *ireplicate){
|
||||
ireplicate->assign_scene_to_peer(m_main_scene, event.recipient);
|
||||
});
|
||||
network::access(m_server, [&](network::Interface *inetwork){
|
||||
inetwork->send(event.recipient, "core:run_script",
|
||||
"buildat.run_script_file(\"main/init.lua\")");
|
||||
|
@ -3,6 +3,7 @@
|
||||
{"module": "network"},
|
||||
{"module": "client_lua"},
|
||||
{"module": "client_data"},
|
||||
{"module": "main_context"},
|
||||
{"module": "replicate"}
|
||||
]
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "client_file/api.h"
|
||||
#include "network/api.h"
|
||||
#include "replicate/api.h"
|
||||
#include "main_context/api.h"
|
||||
#include "interface/module.h"
|
||||
#include "interface/server.h"
|
||||
#include "interface/event.h"
|
||||
@ -24,9 +25,10 @@
|
||||
|
||||
namespace geometry {
|
||||
|
||||
using interface::Event;
|
||||
using namespace Urho3D;
|
||||
namespace magic = Urho3D;
|
||||
using namespace Urho3D;
|
||||
using interface::Event;
|
||||
using main_context::SceneReference;
|
||||
|
||||
struct Module: public interface::Module
|
||||
{
|
||||
@ -35,6 +37,8 @@ struct Module: public interface::Module
|
||||
sp_<interface::AtlasRegistry> m_atlas_reg;
|
||||
sp_<interface::VoxelRegistry> m_voxel_reg;
|
||||
|
||||
SceneReference m_main_scene;
|
||||
|
||||
Module(interface::Server *server):
|
||||
interface::Module(MODULE),
|
||||
m_server(server)
|
||||
@ -52,8 +56,10 @@ struct Module: public interface::Module
|
||||
m_server->sub_event(this, Event::t("core:tick"));
|
||||
m_server->sub_event(this, Event::t("client_file:files_transmitted"));
|
||||
|
||||
m_server->access_scene([&](Scene *scene)
|
||||
{
|
||||
main_context::access(m_server, [&](main_context::Interface *imc){
|
||||
m_main_scene = imc->create_scene();
|
||||
|
||||
Scene *scene = imc->get_scene(m_main_scene);
|
||||
Context *context = scene->GetContext();
|
||||
m_atlas_reg.reset(interface::createAtlasRegistry(context));
|
||||
{
|
||||
@ -126,8 +132,9 @@ struct Module: public interface::Module
|
||||
|
||||
void on_start()
|
||||
{
|
||||
m_server->access_scene([&](Scene *scene)
|
||||
main_context::access(m_server, [&](main_context::Interface *imc)
|
||||
{
|
||||
Scene *scene = imc->get_scene(m_main_scene);
|
||||
Context *context = scene->GetContext();
|
||||
ResourceCache *cache = context->GetSubsystem<ResourceCache>();
|
||||
|
||||
@ -192,8 +199,9 @@ struct Module: public interface::Module
|
||||
|
||||
void update_scene()
|
||||
{
|
||||
m_server->access_scene([&](Scene *scene)
|
||||
main_context::access(m_server, [&](main_context::Interface *imc)
|
||||
{
|
||||
Scene *scene = imc->get_scene(m_main_scene);
|
||||
Context *context = scene->GetContext();
|
||||
ResourceCache *cache = context->GetSubsystem<ResourceCache>();
|
||||
|
||||
@ -251,7 +259,8 @@ struct Module: public interface::Module
|
||||
{
|
||||
static uint a = 0;
|
||||
if(((a++) % 100) == 0){
|
||||
m_server->access_scene([&](Scene *scene){
|
||||
main_context::access(m_server, [&](main_context::Interface *imc){
|
||||
Scene *scene = imc->get_scene(m_main_scene);
|
||||
Node *n = scene->GetChild("Testbox");
|
||||
//n->SetPosition(Vector3(0.0f, 8.0f, 0.0f));
|
||||
n->SetRotation(Quaternion(30, 60, 90));
|
||||
@ -265,6 +274,9 @@ struct Module: public interface::Module
|
||||
|
||||
void on_files_transmitted(const client_file::FilesTransmitted &event)
|
||||
{
|
||||
replicate::access(m_server, [&](replicate::Interface *ireplicate){
|
||||
ireplicate->assign_scene_to_peer(m_main_scene, event.recipient);
|
||||
});
|
||||
network::access(m_server, [&](network::Interface *inetwork){
|
||||
inetwork->send(event.recipient, "core:run_script",
|
||||
"buildat.run_script_file(\"main/init.lua\")");
|
||||
|
@ -3,6 +3,7 @@
|
||||
{"module": "network"},
|
||||
{"module": "client_lua"},
|
||||
{"module": "client_data"},
|
||||
{"module": "main_context"},
|
||||
{"module": "replicate"}
|
||||
]
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "core/log.h"
|
||||
#include <cereal/archives/portable_binary.hpp>
|
||||
#include <cereal/types/vector.hpp>
|
||||
#define MODULE "test1"
|
||||
|
||||
using interface::Event;
|
||||
|
||||
@ -19,7 +20,7 @@ struct Module: public interface::Module
|
||||
Event::Type m_EventType_test1_thing; // You can cache these for more speed
|
||||
|
||||
Module(interface::Server *server):
|
||||
interface::Module("test1"),
|
||||
interface::Module(MODULE),
|
||||
m_server(server),
|
||||
m_EventType_test1_thing(Event::t("test1:thing"))
|
||||
{
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "interface/event.h"
|
||||
#include "test1/api.h"
|
||||
#include "core/log.h"
|
||||
#define MODULE "test2"
|
||||
|
||||
using interface::Event;
|
||||
|
||||
@ -14,7 +15,7 @@ struct Module: public interface::Module
|
||||
Event::Type m_EventType_core_start;
|
||||
|
||||
Module(interface::Server *server):
|
||||
interface::Module("test2"),
|
||||
interface::Module(MODULE),
|
||||
m_server(server),
|
||||
m_EventType_core_start(Event::t("core:start"))
|
||||
{
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "interface/event.h"
|
||||
#include "network/api.h"
|
||||
#include "client_file/api.h"
|
||||
#define MODULE "main"
|
||||
|
||||
using interface::Event;
|
||||
|
||||
@ -14,7 +15,7 @@ struct Module: public interface::Module
|
||||
interface::Server *m_server;
|
||||
|
||||
Module(interface::Server *server):
|
||||
interface::Module("main"),
|
||||
interface::Module(MODULE),
|
||||
m_server(server)
|
||||
{
|
||||
log_v(MODULE, "main construct");
|
||||
|
Loading…
x
Reference in New Issue
Block a user