client, builtin/entitysync, games/entitytest: Why doesn't this shit work
This commit is contained in:
parent
4d91f34d4e
commit
915d2a7957
@ -184,7 +184,7 @@ struct Module: public interface::Module, public entitysync::Interface
|
||||
// New node
|
||||
Node *n = scene->GetNode(node_id);
|
||||
if(n){
|
||||
sync_new_node(peer, n, nodes_to_process, scene, scene_state);
|
||||
sync_create_node(peer, n, nodes_to_process, scene, scene_state);
|
||||
} else {
|
||||
// Was already deleted
|
||||
log_w(MODULE, "New node was already deleted: %zu", node_id);
|
||||
@ -206,11 +206,11 @@ struct Module: public interface::Module, public entitysync::Interface
|
||||
}
|
||||
}
|
||||
|
||||
void sync_new_node(network::PeerInfo::Id peer, Node *node,
|
||||
void sync_create_node(network::PeerInfo::Id peer, Node *node,
|
||||
magic::HashSet<uint> &nodes_to_process,
|
||||
Scene *scene, magic::SceneReplicationState &scene_state)
|
||||
{
|
||||
log_v(MODULE, "sync_new_node(): %zu", node->GetID());
|
||||
log_v(MODULE, "sync_create_node(): %zu", node->GetID());
|
||||
auto &deps = node->GetDependencyNodes();
|
||||
for(auto it = deps.Begin(); it != deps.End(); ++it){
|
||||
uint node_id = (*it)->GetID();
|
||||
@ -229,8 +229,13 @@ struct Module: public interface::Module, public entitysync::Interface
|
||||
buf.WriteNetID(node->GetID());
|
||||
node->WriteInitialDeltaUpdate(buf);
|
||||
|
||||
// TODO: User variables (see Network/Connection.cpp)
|
||||
buf.WriteVLE(0);
|
||||
// User variables
|
||||
auto &vars = node->GetVars();
|
||||
buf.WriteVLE(vars.Size());
|
||||
for(auto it = vars.Begin(); it != vars.End(); ++it){
|
||||
buf.WriteStringHash(it->first_);
|
||||
buf.WriteVariant(it->second_);
|
||||
};
|
||||
|
||||
// Components
|
||||
buf.WriteVLE(node->GetNumNetworkComponents());
|
||||
@ -250,7 +255,7 @@ struct Module: public interface::Module, public entitysync::Interface
|
||||
component->WriteInitialDeltaUpdate(buf);
|
||||
}
|
||||
|
||||
send_to_peer(peer, "entitysync:new_node", buf);
|
||||
send_to_peer(peer, "entitysync:create_node", buf);
|
||||
|
||||
node_state.markedDirty_ = false;
|
||||
scene_state.dirtyNodes_.Erase(node->GetID());
|
||||
|
@ -31,3 +31,4 @@ Buildat TODO
|
||||
- Handle module load order properly in reloads (unload by popping from top,
|
||||
then reload everything until top)
|
||||
- Remove client/default.pak
|
||||
- Move path safety checking from buildat_guard to BuildatResourceRouter
|
||||
|
@ -13,6 +13,8 @@
|
||||
#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>
|
||||
@ -65,6 +67,14 @@ struct Module: public interface::Module
|
||||
{
|
||||
Context *context = scene->GetContext();
|
||||
ResourceCache* cache = context->GetSubsystem<ResourceCache>();
|
||||
auto *m = cache->GetResource<Material>("Materials/Stone.xml");
|
||||
m->SetTexture(TU_DIFFUSE,
|
||||
cache->GetResource<Texture2D>("main/green_texture.png"));
|
||||
/*Material *m = new Material(context);
|
||||
m->SetTexture(TU_DIFFUSE,
|
||||
cache->GetResource<Texture2D>("main/green_texture.png"));
|
||||
m->SetTechnique(0, cache->GetResource<Technique>(
|
||||
"Techniques/Diff.xml"));*/
|
||||
|
||||
{
|
||||
Node* node = scene->CreateChild("DirectionalLight");
|
||||
@ -82,8 +92,7 @@ struct Module: public interface::Module
|
||||
body->SetFriction(0.75f);
|
||||
StaticModel *object = n->CreateComponent<StaticModel>();
|
||||
object->SetModel(cache->GetResource<Model>("Models/Box.mdl"));
|
||||
object->SetMaterial(
|
||||
cache->GetResource<Material>("Materials/Stone.xml"));
|
||||
object->SetMaterial(m);
|
||||
}
|
||||
{
|
||||
Node *n = scene->CreateChild("Box");
|
||||
@ -98,8 +107,7 @@ struct Module: public interface::Module
|
||||
//body->SetGravityOverride(Vector3(0.0, -1.0, 0.0));
|
||||
StaticModel *object = n->CreateComponent<StaticModel>();
|
||||
object->SetModel(cache->GetResource<Model>("Models/Box.mdl"));
|
||||
object->SetMaterial(
|
||||
cache->GetResource<Material>("Materials/Stone.xml"));
|
||||
object->SetMaterial(m);
|
||||
}
|
||||
{
|
||||
Node *n = scene->CreateChild("Box2");
|
||||
@ -114,8 +122,7 @@ struct Module: public interface::Module
|
||||
//body->SetGravityOverride(Vector3(0.0, -1.0, 0.0));
|
||||
StaticModel *object = n->CreateComponent<StaticModel>();
|
||||
object->SetModel(cache->GetResource<Model>("Models/Box.mdl"));
|
||||
object->SetMaterial(
|
||||
cache->GetResource<Material>("Materials/Stone.xml"));
|
||||
object->SetMaterial(m);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -67,18 +67,18 @@ public:
|
||||
magic::String Route(const magic::String &name)
|
||||
{
|
||||
if(!m_client){
|
||||
log_w(MODULE, "Resource route access: %s (no routing)",
|
||||
log_w(MODULE, "Resource route access: %s (no client)",
|
||||
name.CString());
|
||||
return name;
|
||||
}
|
||||
ss_ path = m_client->get_file_path(name.CString());
|
||||
if(path == ""){
|
||||
log_w(MODULE, "Resource route access: %s (assuming local file)",
|
||||
log_v(MODULE, "Resource route access: %s (assuming local file)",
|
||||
name.CString());
|
||||
// TODO: Check that it is in a safe path
|
||||
return name;
|
||||
}
|
||||
log_w(MODULE, "Resource route access: %s -> %s",
|
||||
log_v(MODULE, "Resource route access: %s -> %s",
|
||||
name.CString(), cs(path));
|
||||
return path.c_str();
|
||||
}
|
||||
|
@ -296,7 +296,7 @@ void CState::setup_packet_handlers()
|
||||
m_app->file_updated_in_cache(file_name, file_hash, path);
|
||||
};
|
||||
|
||||
m_packet_handlers["entitysync:new_node"] =
|
||||
m_packet_handlers["entitysync:create_node"] =
|
||||
[this](const ss_ &packet_name, const ss_ &data)
|
||||
{
|
||||
// For a reference implementation of this kind of network
|
||||
@ -352,6 +352,12 @@ void CState::setup_packet_handlers()
|
||||
}
|
||||
};
|
||||
|
||||
m_packet_handlers["entitysync:create_component"] =
|
||||
[this](const ss_ &packet_name, const ss_ &data)
|
||||
{
|
||||
log_w("TODO: %s", cs(packet_name));
|
||||
};
|
||||
|
||||
m_packet_handlers["entitysync:latest_node_data"] =
|
||||
[this](const ss_ &packet_name, const ss_ &data)
|
||||
{
|
||||
@ -360,12 +366,53 @@ void CState::setup_packet_handlers()
|
||||
uint node_id = msg.ReadNetID();
|
||||
Node *node = scene->GetNode(node_id);
|
||||
if(node){
|
||||
log_v(MODULE, "Updating node %i", node_id);
|
||||
node->ReadLatestDataUpdate(msg);
|
||||
} else {
|
||||
log_w(MODULE, "Out-of-order node data ignored for %i", node_id);
|
||||
}
|
||||
};
|
||||
|
||||
m_packet_handlers["entitysync:latest_component_data"] =
|
||||
[this](const ss_ &packet_name, const ss_ &data)
|
||||
{
|
||||
magic::Scene *scene = m_app->get_scene();
|
||||
magic::MemoryBuffer msg(data.c_str(), data.size());
|
||||
uint c_id = msg.ReadNetID();
|
||||
Component *c = scene->GetComponent(c_id);
|
||||
if(c){
|
||||
log_v(MODULE, "Updating component %i", c_id);
|
||||
c->ReadLatestDataUpdate(msg);
|
||||
c->ApplyAttributes();
|
||||
} else {
|
||||
log_w(MODULE, "Out-of-order component data ignored for %i", c_id);
|
||||
}
|
||||
};
|
||||
|
||||
m_packet_handlers["entitysync:node_delta_update"] =
|
||||
[this](const ss_ &packet_name, const ss_ &data)
|
||||
{
|
||||
log_w("TODO: %s", cs(packet_name));
|
||||
};
|
||||
|
||||
m_packet_handlers["entitysync:component_delta_update"] =
|
||||
[this](const ss_ &packet_name, const ss_ &data)
|
||||
{
|
||||
log_w("TODO: %s", cs(packet_name));
|
||||
};
|
||||
|
||||
m_packet_handlers["entitysync:remove_node"] =
|
||||
[this](const ss_ &packet_name, const ss_ &data)
|
||||
{
|
||||
log_w("TODO: %s", cs(packet_name));
|
||||
};
|
||||
|
||||
m_packet_handlers["entitysync:remove_component"] =
|
||||
[this](const ss_ &packet_name, const ss_ &data)
|
||||
{
|
||||
log_w("TODO: %s", cs(packet_name));
|
||||
};
|
||||
|
||||
m_packet_handlers[""] =
|
||||
[this](const ss_ &packet_name, const ss_ &data)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user