The components that you want to send over the wire (probably most/all of them) will need to be marked with the SpiderMonkey @Serializable annotation. Those classes will also have to be registered with the Serializer.
You listen for messages in the conventional way. You can register a MessageListener as needed on the Client or the Server. None of this has anything to do with Monkey Zone which isnāt Zay-ES related at all.
Messages that you need to send will have to be @Serializable as above and you will have to send and receive them. Often with Zay-ES Net you wonāt need to if you are clever about how you use your entities. Often, a proper ES design avoids a lot of these messages. (some will always be required)
If you havenāt already, you can look at MonkeyTrap which is the example I created for developing Zay-ES Net. It sends a minimal number of non-ES messages. All of the ES messaging is done automatically for you.
More detailed answers may depend on the type of game that you are writing.
First thank you for the fast response. I made a little mistake in my Question all the Monkey Zone should be SpiderMonkey xD
ok thats clear, thx allot.
of course Monkey Zone has nothing to do with this sorry , so I use the normal MessageListener of SpiderMonkey to catch Components or entites?
Ok that point is not so clear for me.
I understand how i can automatically sync server and client with the RemoteEntityData and the HostedEntityData but as far as i can see this just syncs all the entities from Server to Client. When my Player now moves, how do i change the entity on the server now? Is there a way to automatically sync the client to the server? Or is this just done with a normale Message with SpiderMonkey?
@linardschwendener10 said:
First thank you for the fast response. I made a little mistake in my Question :P all the Monkey Zone should be SpiderMonkey xD
ok thats clear, thx allot.
of course Monkey Zone has nothing to do with this sorry , so I use the normal MessageListener of SpiderMonkey to catch Components or entites?
No. The components are transferred automatically.
@linardschwendener10 said:
1) Ok that point is not so clear for me.
I understand how i can automatically sync server and client with the RemoteEntityData and the HostedEntityData but as far as i can see this just syncs all the entities from Server to Client. When my Player now moves, how do i change the entity on the server now? Is there a way to automatically sync the client to the server? Or is this just done with a normale Message with SpiderMonkey?
Ah, yes. The client will have to send messages to the server. These are usually higher level commands since you never want the client directly manipulating the entities. So if itās an RPG like game, you might send a MovePlayer() message or AttackThisThing() message. The server will receive those and do whatever is appropriate to manipulate the entities and make that happen.
ā¦this is where itās difficult to provide more specific advice without knowing what kind of game it is. Turn-based RTS, RPG, real-time FPS, etc⦠these will all be handled a little differently.
it schould be something like rpg (little diffrent but to explain thats ok)
So i understand now how to update the Entitys on the Server, but one question is still in my mind.
In many games i know, as an example WoW if you disconnect, you can still move around an the player moves himself, so there must be a kind of entity in the client wich gets moved.
How would you do this? or would you not allow this?
My Problem with it ist, I could Copy the RemoteEntityData and just Display the Copy, and āmanipulateā the copy and in the Same Time send an command to the server that the player wants to move. Then i could update the āLocalā Data with the Remote data sometimes. But iām not sure if this is a good idea, because with that the hole RemoteEntityData System gets a little unusfull. A other problem wich appears in my head is that often if the āLocalā data gets updatet the Player will move a little back, because the remote would be never on the same state due of the fact that the whole information has get updatet to the server and from there back to the client.
If the view can move regardless of what the real data is doing then (aside from the fact that Iād call that a bug) I would not consider that part of the entity system at all. It speaks more to how they predictively handle input.
For example, if could be that player/camera movement is allowed to run independent of what the entity system is saying and then get reconciled later. Itās one way to deal with lag. This is not really an entity system problem The entity system is still saying āgo hereā periodically but you are just choosing to do something different with that information.
I donāt know if Iām making sense. I definitely wouldnāt try to saddle the ES with representing fake state, though. Too complicated.
Class has not been registered:class com.simsilica.es.net.GetEntitySetMessage
I Think this is because i have to āmoveā some Files to SpiderMonkey, (thats written in the ClassSerializer and ClassFieldSerializer) But i have no idea what āNeeds to be moved to SpiderMonkey.ā exactly means. Do i have to replace files? could you explain what i have to do with them?
How should i store the Geometrys in the Client? If a entity has a Gemotery there must be a connection between them, i would use the ID of the Entity, but how do i store them so i can easy find the Geom with ⦠Id? I tought about Arrays, like
geoms[entityId.inInt()] but because of the fakt that the IDs are Random and could get verry large (if i dindt missunderstand something) then this is not very clever. Whats your advice to store them?
Class has not been registered:class com.simsilica.es.net.GetEntitySetMessage
I Think this is because i have to āmoveā some Files to SpiderMonkey, (thats written in the ClassSerializer and ClassFieldSerializer) But i have no idea what āNeeds to be moved to SpiderMonkey.ā exactly means. Do i have to replace files? could you explain what i have to do with them?
Somewhere in both your client and your server you need to call EntitySerializers.initialize(). In MonkeyTrap you can see this in ConnectionState on the client and in GameServer on the server.
@linardschwendener10 said:
2. How should i store the Geometrys in the Client? If a entity has a Gemotery there must be a connection between them, i would use the ID of the Entity, but how do i store them so i can easy find the Geom with ... Id? I tought about Arrays, like
geoms[entityId.inInt()] but because of the fakt that the IDs are Random and could get verry large (if i dindt missunderstand something) then this is not very clever. Whats your advice to store them?
Thanks
A HashMap<EntityId, Geometry> I guess. Are you familiar with the java collections classes?
The RemoteEntityData gets updated when a Entity is added on the Server but is not updatet when the server delets a entity.
Example
Entity 1 gets added on Server, Client gets it
Entity 2 gets added on Server, Client gets it
Entity 1 gets deleted on Server, Client says the Entity 1 is still in RemoteEntityData.
If i connect with a second Client to the Server he just gets Entity 2 in the RemoteEntityData.
How can this be?? do i need to set a special listener for delted Entitys?
The RemoteEntityData gets updated when a Entity is added on the Server but is not updatet when the server delets a entity.
Example
Entity 1 gets added on Server, Client gets it
Entity 2 gets added on Server, Client gets it
Entity 1 gets deleted on Server, Client says the Entity 1 is still in RemoteEntityData.
If i connect with a second Client to the Server he just gets Entity 2 in the RemoteEntityData.
How can this be?? do i need to set a special listener for delted Entitys?
Sorry i have no idea what the problem is there :S
āClient says the Entity 1 is still in the RemoteEntityDataā⦠what does this mean exactly?
Is it part of an EntitySet? Did you update the EntitySet? Did you check for removed objects on the EntitySet?
@pspeed said:
"Client says the Entity 1 is still in the RemoteEntityData".... what does this mean exactly?
Is it part of an EntitySet? Did you update the EntitySet? Did you check for removed objects on the EntitySet?
I have a com.simsilica.es.server.EntityDataHostService on the server
and a com.simsilica.es.client.RemoteEntityData on the client.
if i add a entity to the EntityData wich is connected to the EntityDataHostService on the server and sendUpdates() then the added Entity alsow appears in the RemoteEntityData on the client.
But if i delete a entity int the EntityData on the Server and then sendUpdates() the RemoteEntityData on the client still contains the Entity. (i was using a EntitySet on the client but when i saw that EntityRemoved wasnt called i was looking where the āproblemā appears, and yes i used applyChanges() then i checked if the entity is still in the RemoteEntityData and it was)
I have no idea why the automatic Client Server connection of Zay-ES-Net can add but cant remove Entitys :S
Entities can never be āremovedā because they never exist except as a number. The number 6 can still exist after the entityās components are removed, for example.
Deleting an entity removes all of its components. Those component removals should have been sent to the client if that client had an EntitySet containing the entity.
Hmm ok i see, you are right entity is still there, but if i try to get the Components i get a NullPointerException.
But why is the getRemovedEntities() empty then? Here are some code pieces:
In the SimpleInitApp:
[java]remoteEntityData = new RemoteEntityData(myClient, 0);
playersSet = remoteEntityData.getEntities(CPosition.class, CClient.class);[/java]
In the SimpleUpdate:
[java]if(playersSet.applyChanges()) {
createPlayer(playersSet.getAddedEntities());
updatePlayer(playersSet.getChangedEntities());
removePlayer(playersSet.getRemovedEntities());
}[/java]
getAddedEntites() gives back the added Entities so it cant be the server connection or the Entity Set, and the CClient and the CPosition Components are 100% deleted. So why does getRemovedEntities() gives nothing back ?
@linardschwendener10 said:
Hmm ok i see, you are right entity is still there, but if i try to get the Components i get a NullPointerException.
But why is the getRemovedEntities() empty then? Here are some code pieces:
In the SimpleInitApp:
[java]remoteEntityData = new RemoteEntityData(myClient, 0);
playersSet = remoteEntityData.getEntities(CPosition.class, CClient.class);[/java]
In the SimpleUpdate:
[java]if(playersSet.applyChanges()) {
createPlayer(playersSet.getAddedEntities());
updatePlayer(playersSet.getChangedEntities());
removePlayer(playersSet.getRemovedEntities());
}[/java]
getAddedEntites() gives back the added Entities so it cant be the server connection or the Entity Set, and the CClient and the CPosition Components are 100% deleted. So why does getRemovedEntities() gives nothing back ?
I donāt know. I do this exact same sort of thing in the networked version of Monkey Trap and it seems to work fine and I see the deletions.
[java] private void removePlayer(Set<Entity> entitySet) {
Iterator<Entity> iterator = entitySet.iterator();
while(iterator.hasNext()) {
System.out.println(āTestā);
Entity temp = iterator.next();
gameObjects.get(temp.getId().getId()).remove();
gameObjects.remove(temp.getId().getId());
System.out.println("Removed ID: "+iterator.next().getId().getId());
}
}[/java]
The while gets never executed :S
BTW:
iām not totally sure if im using some Methods correctly.
EntityData.getEntity(EntityId, XXXXXXXXXXXXXXX)
What am i supposed to write instead of the X? i know its a class but wich and why? The class of a component of this entity?
Same thing with:
EntityData.findEntity(Filter, XXXX)
is X the class wich is given as the parameter at evaluate() in the Filter?
At the moment, it works but im unsure if that could cause any trouble :S
BTW:
iām not totally sure if im using some Methods correctly.
EntityData.getEntity(EntityId, XXXXXXXXXXXXXXX)
What am i supposed to write instead of the X? i know its a class but wich and why? The class of a component of this entity?
Same thing with:
EntityData.findEntity(Filter, XXXX)
is X the class wich is given as the parameter at evaluate() in the Filter?
At the moment, it works but im unsure if that could cause any trouble :S
Regarding your first issue, Iām still not sure whatās happening. It (apparently) works in Monkey Trap or at least did the last time I ran it.
Regarding the other stuffā¦
First some clarification on terms.
āentityā (with a little āeā) is a concept. Itās an ID and a bunch of components.
Entity (with a big āeā) is the class Entity which is a view of a subset of an entityās components. A snapshot of when it was requested or last updated.
So EntityData.getEntity(EntityId, XXXXXXXXXXXXXXX)
ā¦the XXXXX should be the components you want to get in the entity view: Entity
Find is similar. I should probably see about changing the parameter list to Class<? extends EntityComponent> or something to make that clearer.
Ok then i used them correct.
One little other question
[java]playersSet = remoteEntityData.getEntities(CPosition.class, CClient.class);[/java]
Is this a AND or a OR connection at the Parameter? Does that mean that Cposition and CClient must be a componnent of the entity, or that just one of them, so itās part of the EntitySet? (i tought it was AND :S)
For the problem iām experiencing, could i have the uncompiled EntitySet class so i can debug where the problem is? :S
Thanks again for your great and extremly fast help