Closed sp00ktober closed 1 year ago
Player now gets spawned by the server but is in its "borken" or "template" state and needs to get initialised first. ebc8f4800737ddab45ac448b1a1ef6425b62205b
Now that we know how to add components to game objects from the server side we are able to create a nearly complete LocalPlayer
.
For now we partially do things "by hand" until we have a proper solution for struct representation on the server side and a protobuf implementation that works.
The process is rughly this:
Data
class object of the component you want to add and initialize it with some data (fill variables)ClientObject
pointer and a char*
buffer to hold the serialized data, then call Deserialize(componentId, Snapshot, buffer, bufferSize, &objPtr)
to deserialize the object in the games memory and receive a ref (int) to it.
https://github.com/sp00ktober/WorldsAdriftReborn/blob/f8a20d4546fb991115a7c87f36c918571315f48c/WorldsAdriftRebornCoreSdk/Connection.cpp#L74AddComponentOp
callback with an AddComponentOp
struct and set the EntityId
to the one of the object you want to add to, set ComponentId
again and add the ref to the object in games memoryThe first two steps are done by hand and we send a predefined byte array for now.
To call the Deserialize()
method we need to store the vtable
array the game offers when the initial SpatialOS connection is made.
Code for spawning the player and island as well as the code to add components to them needs to partially move to #24
This is now all done on the basic game server that we have, implemented in b19199ecbd9d01ee40df355a40681000573e3aee The player still seems to miss some stuff and always spawns nearly naked, but can walk and grapple around normally and the above procedure is now handled by the server.
The
LocalPlayer
holds a bunch of MonoBehaviours to enable interactions, render stuff (like the character, ui elements and more). So far this object is initialized locally from mod code for testing purposes, but it should be done upon instructions from the server (that means our SpatialOS replacement).