message object pooling work
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
This commit is contained in:
parent
08d21eb2a9
commit
5588827644
@ -9,11 +9,15 @@ import org.lwjgl.util.remotery.Remotery;
|
||||
*/
|
||||
public class Profiler {
|
||||
|
||||
//controls whether to profile or not
|
||||
//!!WARNING!!: when this is turned on, testing can behave weirdly!! IE GET STUCK!
|
||||
/**
|
||||
* Controls whether to profile or not
|
||||
* !!WARNING!!: when this is turned on, testing can behave weirdly!! IE GET STUCK!
|
||||
*/
|
||||
public static boolean PROFILE = false;
|
||||
|
||||
//pointer to the global instance
|
||||
/**
|
||||
* Pointer to the global instance
|
||||
*/
|
||||
long pointer = -1;
|
||||
|
||||
/**
|
||||
|
||||
@ -296,6 +296,7 @@ public class ClientGroundMovementTree implements BehaviorTree {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Globals.clientConnection.release(message);
|
||||
}
|
||||
|
||||
// System.out.println(movementVector + " " + velocity * Main.deltaTime);
|
||||
|
||||
@ -167,7 +167,6 @@ public class ClientNetworking implements Runnable {
|
||||
|
||||
//create parser
|
||||
parser = new NetworkParser(inputStream,outputStream);
|
||||
parser.getMessagePool().setAlwaysAllocate(true);
|
||||
|
||||
|
||||
|
||||
@ -321,6 +320,14 @@ public class ClientNetworking implements Runnable {
|
||||
parser.addOutgoingMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases a network message to the object pool
|
||||
* @param message The message
|
||||
*/
|
||||
public void release(NetworkMessage message){
|
||||
this.parser.release(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the message protocol
|
||||
* @return The message protocol inside this object
|
||||
|
||||
@ -68,7 +68,7 @@ public class EntityProtocol implements ClientProtocolTemplate<EntityMessage> {
|
||||
// SPAWNING STUFF IN
|
||||
//
|
||||
//
|
||||
case CREATE:
|
||||
case CREATE: {
|
||||
LoggerInterface.loggerNetworking.DEBUG(
|
||||
"Spawn ID " + message.getentityID() + " of type " + message.getentityCategory() + " subtype " + message.getentitySubtype() +
|
||||
" @ " + message.getpositionX() + " " + message.getpositionY() + " " + message.getpositionZ()
|
||||
@ -76,19 +76,20 @@ public class EntityProtocol implements ClientProtocolTemplate<EntityMessage> {
|
||||
EntityType type = EntityTypes.fromInt(message.getentityCategory());
|
||||
switch(type){
|
||||
case CREATURE: {
|
||||
spawnCreature(message);
|
||||
EntityProtocol.spawnCreature(message);
|
||||
} break;
|
||||
case ITEM: {
|
||||
spawnItem(message);
|
||||
EntityProtocol.spawnItem(message);
|
||||
} break;
|
||||
case FOLIAGE: {
|
||||
spawnFoliage(message);
|
||||
EntityProtocol.spawnFoliage(message);
|
||||
} break;
|
||||
case COMMON: {
|
||||
spawnCommon(message);
|
||||
EntityProtocol.spawnCommon(message);
|
||||
} break;
|
||||
}
|
||||
break;
|
||||
Globals.clientConnection.release(message);
|
||||
} break;
|
||||
|
||||
//
|
||||
//
|
||||
@ -98,12 +99,13 @@ public class EntityProtocol implements ClientProtocolTemplate<EntityMessage> {
|
||||
case SETPROPERTY: {
|
||||
if(Globals.clientSceneWrapper.serverToClientMapContainsId(message.getentityID())){
|
||||
if(message.getpropertyType() == 0){
|
||||
setPlayerEntity(message);
|
||||
EntityProtocol.setPlayerEntity(message);
|
||||
}
|
||||
} else {
|
||||
//TODO: bounce message
|
||||
LoggerInterface.loggerNetworking.WARNING("Received property packet for entity that does not exist on client!");
|
||||
}
|
||||
Globals.clientConnection.release(message);
|
||||
} break;
|
||||
case ATTACHENTITYTOENTITY: {
|
||||
Entity child = Globals.clientSceneWrapper.getEntityFromServerId(message.getentityID());
|
||||
@ -118,6 +120,7 @@ public class EntityProtocol implements ClientProtocolTemplate<EntityMessage> {
|
||||
new Quaterniond()
|
||||
);
|
||||
}
|
||||
Globals.clientConnection.release(message);
|
||||
} break;
|
||||
case MOVEUPDATE: {
|
||||
Entity target = Globals.clientSceneWrapper.getEntityFromServerId(message.getentityID());
|
||||
@ -147,6 +150,7 @@ public class EntityProtocol implements ClientProtocolTemplate<EntityMessage> {
|
||||
if(entity != null){
|
||||
ClientEntityUtils.destroyEntity(entity);
|
||||
}
|
||||
Globals.clientConnection.release(message);
|
||||
} break;
|
||||
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package electrosphere.net.parser.net.raw;
|
||||
|
||||
import electrosphere.net.parser.net.message.MessagePool;
|
||||
import electrosphere.net.parser.net.message.NetworkMessage;
|
||||
package electrosphere.net.parser.net.raw;
|
||||
|
||||
import electrosphere.net.parser.net.message.MessagePool;
|
||||
import electrosphere.net.parser.net.message.NetworkMessage;
|
||||
import io.github.studiorailgun.CircularByteBuffer;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
@ -129,7 +129,6 @@ public class ServerConnectionHandler implements Runnable {
|
||||
if(this.local){
|
||||
//run if serverconnectionHandler is created by passing in input/output streams
|
||||
networkParser = new NetworkParser(inputStream,outputStream);
|
||||
networkParser.getMessagePool().setAlwaysAllocate(true);
|
||||
messageProtocol = new MessageProtocol(this);
|
||||
} else {
|
||||
//run if ServerConnectionHandler is created by passing in a socket
|
||||
|
||||
@ -32,13 +32,19 @@ import electrosphere.net.synchronization.enums.FieldIdEnums;
|
||||
*/
|
||||
public class ClientSynchronizationManager {
|
||||
|
||||
//The list of messages to loop through
|
||||
/**
|
||||
* The list of messages to loop through
|
||||
*/
|
||||
List<SynchronizationMessage> messages = new CopyOnWriteArrayList<SynchronizationMessage>();
|
||||
|
||||
//Map that tracks the number of times a network message bounces
|
||||
/**
|
||||
* Map that tracks the number of times a network message bounces
|
||||
*/
|
||||
Map<SynchronizationMessage,Integer> messageBounceCount = new HashMap<SynchronizationMessage,Integer>();
|
||||
|
||||
//the count at which to warn about a message bouncing
|
||||
/**
|
||||
* The count at which to warn about a message bouncing
|
||||
*/
|
||||
static final int MESSAGE_BOUNCE_WARNING_COUNT = 10;
|
||||
|
||||
/**
|
||||
@ -77,13 +83,13 @@ public class ClientSynchronizationManager {
|
||||
int bTreeId = message.getbTreeId();
|
||||
int entityId = message.getentityId();
|
||||
Entity targetEntity = Globals.clientSceneWrapper.getEntityFromServerId(entityId);
|
||||
updateEntityState(targetEntity,bTreeId,message);
|
||||
this.updateEntityState(targetEntity,bTreeId,message);
|
||||
} break;
|
||||
case SERVERNOTIFYBTREETRANSITION: {
|
||||
int bTreeId = message.getbTreeId();
|
||||
int entityId = message.getentityId();
|
||||
Entity targetEntity = Globals.clientSceneWrapper.getEntityFromServerId(entityId);
|
||||
transitionBTree(targetEntity, bTreeId, message);
|
||||
this.transitionBTree(targetEntity, bTreeId, message);
|
||||
} break;
|
||||
case ATTACHTREE:{
|
||||
// int bTreeId = message.getbTreeId();
|
||||
@ -135,6 +141,7 @@ public class ClientSynchronizationManager {
|
||||
}
|
||||
for(SynchronizationMessage message : messagesToClear){
|
||||
messages.remove(message);
|
||||
Globals.clientConnection.release(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user