Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ static VertexSerializerRegistry instance() {
}

VertexSerializer get(VertexFormatDescription srcFormat, VertexFormatDescription dstFormat);

void register(VertexFormatDescription srcFormat, VertexFormatDescription dstFormat, VertexSerializer serializer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,27 @@ public VertexSerializer get(VertexFormatDescription srcFormat, VertexFormatDescr
return serializer;
}

@Override
public void register(VertexFormatDescription srcFormat, VertexFormatDescription dstFormat, VertexSerializer serializer) {
var identifier = createKey(srcFormat, dstFormat);

if (this.cache.containsKey(identifier)) {
throw new IllegalArgumentException("Serializer already exists for the given vertex formats: " + srcFormat + " -> " + dstFormat);
}

if (serializer == null) {
throw new NullPointerException("Serializer parameter is null.");
}

var stamp = this.lock.writeLock();

try {
this.cache.put(identifier, serializer);
} finally {
this.lock.unlockWrite(stamp);
}
}

private VertexSerializer create(long identifier, VertexFormatDescription srcFormat, VertexFormatDescription dstFormat) {
var serializer = createSerializer(srcFormat, dstFormat);
var stamp = this.lock.writeLock();
Expand Down