THIS IS NOT A GENERIC NETWORKCODE, THIS IS KINDA SPECIFIC, AND SIMILAR TO THE SOURCE ENGINE NETWORK SYSTEM!!
Well, I'm around 2/3 done with a JME3 network synchronisation system.
There are still some empty functions that needed to be filled with code,
The Serverside player calss needs pseudophysic added,
The Physicsystem from JME3 needs to be properly integgrated for the serverside collision detection and physic calculation.
I think it's however time to show some simple examples and aska bout opinions:
Basically ith as the SEntity and the CEntity class, wich represents the Serverside and the Clientside part of each given object.
A Simple static world entity:
public class SSacredPlace extends SEntity {
public SSacredPlace(){
this.SetAlwaysTransmitted(false);
this.SetName("Test");
this.SetArmor(-1);
this.SetTransmitRange(500f);
this.SetCollisionType(CollisionTypeEnum.Physics);
this.SetHealth(-1);
this.SetMoveType(MoveTypeEnum.None);
this.SetModel("place");
this.SetConstantUpdate(false);
this.Activate();
}
}
This creates a Serverside entity:
with the model place.meshxml
infinite armor,health (no damage)
physical collisione (loaded from file place_phys.meshxml)
static, no movement
Tells it that it is not always needed to be transfered,
setting the distance it exists on the clients to 500 jme units (if nearer server sends object data, if further it's removed on client)
Setting it to a reliable update only on change events mode (other option is to have updates every tick but unreliable aka player movement,ect)
Clientside must exist a Class with the exact same name but first letter replaced witha C , so CSacredPlace then, this can be overriden in the networkconstructor creation, the player class does this to distigueish between the own player and other:
@Override
protected String getClientName(String string,boolean isOwner) {
if(isOwner){
return "de.empirephoenix.entitys.player.LPlayer";
}
return "de.empirephoenix.entitys.player.CPlayer";
}
It is very simpel due to the class based concept to create classes doing various stuff.
All data is serilaized in a own system directly to a bytearray wich then is send via UDP, all Message objects implementing the Reliable interface, are automatically resent, untill the recival is confirmed, however most won't need to work so low in the system.
package de.empirephoenix.messages;
import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;
import com.jme3.math.Vector3f;
import de.empirephoenix.network.shared.BinarySerializeable;
public class Vector3fWrapper implements BinarySerializeable {
private Vector3f vector;
public Vector3fWrapper() {
vector = new Vector3f();
}
public Vector3fWrapper(Vector3f vector){
this.vector = vector;
}
@Override
public BinarySerializeable newObject() {
return new Vector3fWrapper();
}
@Override
public void readData(DataInput readfrom) throws IOException {
vector.x = readfrom.readFloat();
vector.y = readfrom.readFloat();
vector.z = readfrom.readFloat();
}
@Override
public void writeData(DataOutputStream writeto) throws IOException {
writeto.writeFloat(vector.x);
writeto.writeFloat(vector.y);
writeto.writeFloat(vector.z);
}
public Vector3f getVector(){
return vector;
}
}
The serverside player, handles everything in terms ov transmit range, updating,removing,adding entitys.
The CEntity, handles clientside model loading ina background thread, making sure that it will not lag the game (like tons of shitte free mmorpgs do when models are loaded, or the source engine ,ect the only engine I know that is capable of this is the UT3 engine so far)
Then SEntity has methots for the most default settings, wich are all autoamtically synchronized:
SetModel
DropToFloor
SetName
SetHealth
FreeLineOfSightTo(Vector3f target)
EmitSound
SetColor(ColorRGBA color)
GetForward
GetRight
GetUp
SetLocalPosition
SetOwner
SetParent
GibClient
GibServer
SetArmor
IsOnGround
IsVehicle
IsUseable
IsPlayer
IsValid
IsWorld
LocalToWorld
Remove
SetLocalRotation
SetAnimation
SetMoveType
SetCollisionType
SetVelocity
WorldToLocal
SetAlwaysTransmitted
SetScale
SetTransmitRange
SetConstantUpdate
SetDatabaseId
SetDatabaseConfigValue //onyl a placeholder you need to implement this yoursel fif you need this
Collided
I hope to present a demo in the next two weeks, but wanted to show the whole concept already, so if you have any questions, fell free to ask them :) I hope after this library is done and working that the whole network system can be integrated in the jme3 source kinda like the jbullet system is.