message object pooling work
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2025-03-29 16:46:57 -04:00
parent 08d21eb2a9
commit 5588827644
7 changed files with 43 additions and 21 deletions

View File

@ -9,11 +9,15 @@ import org.lwjgl.util.remotery.Remotery;
*/ */
public class Profiler { 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; public static boolean PROFILE = false;
//pointer to the global instance /**
* Pointer to the global instance
*/
long pointer = -1; long pointer = -1;
/** /**

View File

@ -296,6 +296,7 @@ public class ClientGroundMovementTree implements BehaviorTree {
default: default:
break; break;
} }
Globals.clientConnection.release(message);
} }
// System.out.println(movementVector + " " + velocity * Main.deltaTime); // System.out.println(movementVector + " " + velocity * Main.deltaTime);

View File

@ -167,7 +167,6 @@ public class ClientNetworking implements Runnable {
//create parser //create parser
parser = new NetworkParser(inputStream,outputStream); parser = new NetworkParser(inputStream,outputStream);
parser.getMessagePool().setAlwaysAllocate(true);
@ -321,6 +320,14 @@ public class ClientNetworking implements Runnable {
parser.addOutgoingMessage(message); 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 * Gets the message protocol
* @return The message protocol inside this object * @return The message protocol inside this object

View File

@ -68,7 +68,7 @@ public class EntityProtocol implements ClientProtocolTemplate<EntityMessage> {
// SPAWNING STUFF IN // SPAWNING STUFF IN
// //
// //
case CREATE: case CREATE: {
LoggerInterface.loggerNetworking.DEBUG( LoggerInterface.loggerNetworking.DEBUG(
"Spawn ID " + message.getentityID() + " of type " + message.getentityCategory() + " subtype " + message.getentitySubtype() + "Spawn ID " + message.getentityID() + " of type " + message.getentityCategory() + " subtype " + message.getentitySubtype() +
" @ " + message.getpositionX() + " " + message.getpositionY() + " " + message.getpositionZ() " @ " + message.getpositionX() + " " + message.getpositionY() + " " + message.getpositionZ()
@ -76,19 +76,20 @@ public class EntityProtocol implements ClientProtocolTemplate<EntityMessage> {
EntityType type = EntityTypes.fromInt(message.getentityCategory()); EntityType type = EntityTypes.fromInt(message.getentityCategory());
switch(type){ switch(type){
case CREATURE: { case CREATURE: {
spawnCreature(message); EntityProtocol.spawnCreature(message);
} break; } break;
case ITEM: { case ITEM: {
spawnItem(message); EntityProtocol.spawnItem(message);
} break; } break;
case FOLIAGE: { case FOLIAGE: {
spawnFoliage(message); EntityProtocol.spawnFoliage(message);
} break; } break;
case COMMON: { case COMMON: {
spawnCommon(message); EntityProtocol.spawnCommon(message);
} break; } break;
} }
break; Globals.clientConnection.release(message);
} break;
// //
// //
@ -98,12 +99,13 @@ public class EntityProtocol implements ClientProtocolTemplate<EntityMessage> {
case SETPROPERTY: { case SETPROPERTY: {
if(Globals.clientSceneWrapper.serverToClientMapContainsId(message.getentityID())){ if(Globals.clientSceneWrapper.serverToClientMapContainsId(message.getentityID())){
if(message.getpropertyType() == 0){ if(message.getpropertyType() == 0){
setPlayerEntity(message); EntityProtocol.setPlayerEntity(message);
} }
} else { } else {
//TODO: bounce message //TODO: bounce message
LoggerInterface.loggerNetworking.WARNING("Received property packet for entity that does not exist on client!"); LoggerInterface.loggerNetworking.WARNING("Received property packet for entity that does not exist on client!");
} }
Globals.clientConnection.release(message);
} break; } break;
case ATTACHENTITYTOENTITY: { case ATTACHENTITYTOENTITY: {
Entity child = Globals.clientSceneWrapper.getEntityFromServerId(message.getentityID()); Entity child = Globals.clientSceneWrapper.getEntityFromServerId(message.getentityID());
@ -118,6 +120,7 @@ public class EntityProtocol implements ClientProtocolTemplate<EntityMessage> {
new Quaterniond() new Quaterniond()
); );
} }
Globals.clientConnection.release(message);
} break; } break;
case MOVEUPDATE: { case MOVEUPDATE: {
Entity target = Globals.clientSceneWrapper.getEntityFromServerId(message.getentityID()); Entity target = Globals.clientSceneWrapper.getEntityFromServerId(message.getentityID());
@ -147,6 +150,7 @@ public class EntityProtocol implements ClientProtocolTemplate<EntityMessage> {
if(entity != null){ if(entity != null){
ClientEntityUtils.destroyEntity(entity); ClientEntityUtils.destroyEntity(entity);
} }
Globals.clientConnection.release(message);
} break; } break;

View File

@ -1,7 +1,7 @@
package electrosphere.net.parser.net.raw; package electrosphere.net.parser.net.raw;
import electrosphere.net.parser.net.message.MessagePool; import electrosphere.net.parser.net.message.MessagePool;
import electrosphere.net.parser.net.message.NetworkMessage; import electrosphere.net.parser.net.message.NetworkMessage;
import io.github.studiorailgun.CircularByteBuffer; import io.github.studiorailgun.CircularByteBuffer;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;

View File

@ -129,7 +129,6 @@ public class ServerConnectionHandler implements Runnable {
if(this.local){ if(this.local){
//run if serverconnectionHandler is created by passing in input/output streams //run if serverconnectionHandler is created by passing in input/output streams
networkParser = new NetworkParser(inputStream,outputStream); networkParser = new NetworkParser(inputStream,outputStream);
networkParser.getMessagePool().setAlwaysAllocate(true);
messageProtocol = new MessageProtocol(this); messageProtocol = new MessageProtocol(this);
} else { } else {
//run if ServerConnectionHandler is created by passing in a socket //run if ServerConnectionHandler is created by passing in a socket

View File

@ -32,13 +32,19 @@ import electrosphere.net.synchronization.enums.FieldIdEnums;
*/ */
public class ClientSynchronizationManager { public class ClientSynchronizationManager {
//The list of messages to loop through /**
* The list of messages to loop through
*/
List<SynchronizationMessage> messages = new CopyOnWriteArrayList<SynchronizationMessage>(); 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>(); 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; static final int MESSAGE_BOUNCE_WARNING_COUNT = 10;
/** /**
@ -77,13 +83,13 @@ public class ClientSynchronizationManager {
int bTreeId = message.getbTreeId(); int bTreeId = message.getbTreeId();
int entityId = message.getentityId(); int entityId = message.getentityId();
Entity targetEntity = Globals.clientSceneWrapper.getEntityFromServerId(entityId); Entity targetEntity = Globals.clientSceneWrapper.getEntityFromServerId(entityId);
updateEntityState(targetEntity,bTreeId,message); this.updateEntityState(targetEntity,bTreeId,message);
} break; } break;
case SERVERNOTIFYBTREETRANSITION: { case SERVERNOTIFYBTREETRANSITION: {
int bTreeId = message.getbTreeId(); int bTreeId = message.getbTreeId();
int entityId = message.getentityId(); int entityId = message.getentityId();
Entity targetEntity = Globals.clientSceneWrapper.getEntityFromServerId(entityId); Entity targetEntity = Globals.clientSceneWrapper.getEntityFromServerId(entityId);
transitionBTree(targetEntity, bTreeId, message); this.transitionBTree(targetEntity, bTreeId, message);
} break; } break;
case ATTACHTREE:{ case ATTACHTREE:{
// int bTreeId = message.getbTreeId(); // int bTreeId = message.getbTreeId();
@ -135,6 +141,7 @@ public class ClientSynchronizationManager {
} }
for(SynchronizationMessage message : messagesToClear){ for(SynchronizationMessage message : messagesToClear){
messages.remove(message); messages.remove(message);
Globals.clientConnection.release(message);
} }
} }