Theres one big issue im running into. Their update packet size and the garbage it creates. I ran a test where 180 enemys were spawned next to the player. All in his AOI.
Each enemy has the following attributes : "id (long), type (string), x(float), y(float), rx(float), ry(float), hp(float), maxHP(float)". I update all the enemys with a server tic of 30. So the server runs at 30 fps and i only send enemy attributes which changed. Most of the enemys are walking around, which changes their "x,y,rx,ry" value every frame. So im forced to update those four MMO-Variables every single tick. And it seems like MMOItems cant handle floats, just doubles. Which doubles the packet size.
Sending these amounts of updates and packets is no problem for the server... but for the client receiving them. Those huge blue spikes are caused by smartfoxServer.ProcessEvents(); ( Aka. ConnectionManager.Update() ) on the client where i receive the packets.
As you can see... this creates about 250KB of incoming updates every 0.032 seconds ( 30 tick ). Which is a lot for unitys gc alloc and makes the game stuttering. But the worst is the packet size itself. We are updating 4 variables ( mentioned above ) each frame. Those are handled as ( i assume ) doubles, which results in an update size of "4*16 ( Boxed Double) = 64 Bytes" per entity and in total "64 * 180 = 11520 Bytes (11,52KB)".
Probably my calculation is wrong... but i should never, ever receive packets in such a huge size. Where do the other ~240KB coming from ?
This is my code which produces those high amounts of data, if someone is interessted on how i "update" my MMOItems. I see nothing wrong here, its actually highly optimized because i only update MMOitems which changed.
Code: Select all
/**
* Gets called every 0.032 ms for updating MMOItems on the client
* @param i entity
*/
@Override
protected void process(int i) {
var identity = identities.get(i);
var transform = transforms.get(i);
var moving = movings.has(i);
var mmo = mmos.get(i);
// Check which variables require an update
for(var tuple : mmo.variables){
if(mmo.item != null) {
var variable = mmo.item.getVariable(tuple.key);
if (variable != null && Utils.sameValue(tuple.value, variable.getValue())) continue;
}
// Update requires
vars.add(new MMOItemVariable(tuple.key, tuple.value));
}
// Create and update variables
if (mmo.item == null) mmo.item = createMMOItem(identity, transform, vars);
else if(!vars.isEmpty()) mmoApi.setMMOItemVariables(mmo.item, vars, !playerQuery.getEntities().isEmpty());
// Update position of the item
if(moving)
mmoApi.setMMOItemPosition(mmo.item, new Vec3D(transform.position.x, transform.position.y, 0), room);
// Dispose
vars.clear();
mmo.variables.clear();
}
Im glad for any help on this topic ! Thanks !