mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 07:17:58 +01:00
Add synchronization to keep it from messing up
This commit is contained in:
parent
f8f60a8d3d
commit
b9015c9220
2 changed files with 25 additions and 19 deletions
|
@ -59,13 +59,15 @@ public class DataTracker {
|
|||
|
||||
Pair<T> pair = getPair(entry);
|
||||
if (!Objects.equals(pair.value, value)) {
|
||||
synchronized (this) {
|
||||
pair.value = value;
|
||||
dirtyIndices.add(entry.id());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
MsgTrackedValues.TrackerEntries getDirtyPairs() {
|
||||
synchronized MsgTrackedValues.TrackerEntries getDirtyPairs() {
|
||||
writethroughCallback.values().forEach(Runnable::run);
|
||||
|
||||
if (initial) {
|
||||
|
@ -88,7 +90,7 @@ public class DataTracker {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
void load(boolean wipe, List<Pair<?>> values) {
|
||||
synchronized void load(boolean wipe, List<Pair<?>> values) {
|
||||
if (wipe) {
|
||||
codecs.clear();
|
||||
codecs.addAll(values);
|
||||
|
|
|
@ -30,13 +30,13 @@ public class DataTrackerManager implements Tickable {
|
|||
return primaryTracker;
|
||||
}
|
||||
|
||||
public DataTracker checkoutTracker() {
|
||||
public synchronized DataTracker checkoutTracker() {
|
||||
DataTracker tracker = new DataTracker(this, nextId++);
|
||||
trackers.put(tracker.id, tracker);
|
||||
return tracker;
|
||||
}
|
||||
|
||||
void closeTracker(int id) {
|
||||
synchronized void closeTracker(int id) {
|
||||
if (id <= 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -53,6 +53,7 @@ public class DataTrackerManager implements Tickable {
|
|||
return;
|
||||
}
|
||||
|
||||
synchronized (this) {
|
||||
List<MsgTrackedValues.TrackerEntries> toTransmit = new ArrayList<>();
|
||||
|
||||
for (var entry : trackers.int2ObjectEntrySet()) {
|
||||
|
@ -68,16 +69,19 @@ public class DataTrackerManager implements Tickable {
|
|||
Channel.SERVER_TRACKED_ENTITY_DATA.sendToSurroundingPlayers(packet, entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void load(MsgTrackedValues packet) {
|
||||
synchronized void load(MsgTrackedValues packet) {
|
||||
for (int id : packet.removedTrackers()) {
|
||||
closeTracker(id);
|
||||
}
|
||||
for (var update : packet.updatedTrackers()) {
|
||||
DataTracker tracker = trackers.get(update.id());
|
||||
if (tracker != null) {
|
||||
if (tracker == null) {
|
||||
tracker = new DataTracker(this, update.id());
|
||||
trackers.put(update.id(), tracker);
|
||||
}
|
||||
tracker.load(update.wipe(), update.values());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue