sync change for memory
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2025-06-05 13:23:38 -04:00
parent d650d223a8
commit 483ff9b8d1
2 changed files with 12 additions and 2 deletions

View File

@ -2123,6 +2123,7 @@ Physics work
Debug rendering for facing vectors Debug rendering for facing vectors
Fix progressive pathfinding iteration Fix progressive pathfinding iteration
Non-body ground movement animation work Non-body ground movement animation work
Synchronization change for memory pressure

View File

@ -26,7 +26,7 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.locks.ReentrantLock;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.entity.Entity; import electrosphere.entity.Entity;
@ -53,7 +53,7 @@ public class ClientSynchronizationManager {
/** /**
* The list of messages to loop through * The list of messages to loop through
*/ */
private List<SynchronizationMessage> messages = new CopyOnWriteArrayList<SynchronizationMessage>(); private List<SynchronizationMessage> messages = new LinkedList<SynchronizationMessage>();
/** /**
* Map that tracks the number of times a network message bounces * Map that tracks the number of times a network message bounces
@ -65,18 +65,26 @@ public class ClientSynchronizationManager {
*/ */
private Map<Integer,Integer> deletedEntityIds = new HashMap<Integer,Integer>(); private Map<Integer,Integer> deletedEntityIds = new HashMap<Integer,Integer>();
/**
* Lock for thread-safeing the manager
*/
private ReentrantLock lock = new ReentrantLock();
/** /**
* Pushes a message into the queue to be processed * Pushes a message into the queue to be processed
* @param message The message * @param message The message
*/ */
public void pushMessage(SynchronizationMessage message){ public void pushMessage(SynchronizationMessage message){
lock.lock();
this.messages.add(message); this.messages.add(message);
lock.unlock();
} }
/** /**
* Processes all messages in the queue and then clears the queue * Processes all messages in the queue and then clears the queue
*/ */
public void processMessages(){ public void processMessages(){
lock.lock();
List<SynchronizationMessage> messagesToClear = new LinkedList<SynchronizationMessage>(); List<SynchronizationMessage> messagesToClear = new LinkedList<SynchronizationMessage>();
for(SynchronizationMessage message : messages){ for(SynchronizationMessage message : messages){
@ -197,6 +205,7 @@ public class ClientSynchronizationManager {
this.deletedEntityIds.remove(key); this.deletedEntityIds.remove(key);
} }
} }
lock.unlock();
} }
/** /**