Skip to content

Commit

Permalink
Small code style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadelessFox committed Dec 18, 2024
1 parent 90ad21a commit f46f034
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import static com.shade.decima.game.hfw.rtti.HorizonForbiddenWest.RTTIRefObject;

public class HFWTypeReader extends AbstractTypeReader {
public record ObjectInfo(@NotNull RTTIRefObject object, @NotNull ClassTypeInfo info) {}
public record ObjectInfo(@NotNull ClassTypeInfo type, @NotNull RTTIRefObject object) {}

@NotNull
public static <T> T readCompound(@NotNull Class<T> cls, @NotNull BinaryReader reader, @NotNull TypeFactory factory) throws IOException {
Expand All @@ -43,7 +43,7 @@ public ObjectInfo readObject(@NotNull BinaryReader reader, @NotNull TypeFactory
throw new IllegalStateException("Expected RTTIRefObject, got " + type.name());
}

return new ObjectInfo(refObject, type);
return new ObjectInfo(type, refObject);
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.shade.decima.game.hfw.storage;

import com.shade.decima.game.hfw.rtti.HorizonForbiddenWest.StreamingDataSource;
import com.shade.util.NotNull;

import java.io.IOException;

import static com.shade.decima.game.hfw.rtti.HorizonForbiddenWest.StreamingDataSourceLocator;

public final class ObjectStreamingSystem {
/**
* Represents the result of reading a link from the link table.
Expand All @@ -27,8 +26,13 @@ public ObjectStreamingSystem(@NotNull StorageReadDevice device, @NotNull Streami
}

@NotNull
public byte[] getDataSourceData(@NotNull StreamingDataSourceLocator locator, int offset, int length) throws IOException {
return getFileData((int) (locator.data() & 0xffffff), Math.addExact(locator.data() >>> 24, offset), length);
public byte[] getDataSourceData(@NotNull StreamingDataSource dataSource) throws IOException {
return getDataSourceData(dataSource, dataSource.offset(), dataSource.length());
}

@NotNull
public byte[] getDataSourceData(@NotNull StreamingDataSource dataSource, int offset, int length) throws IOException {
return getFileData((int) (dataSource.locator() & 0xffffff), Math.addExact(dataSource.locator() >>> 24, offset), length);
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public GroupInfo readGroup(int id, @NotNull List<GroupInfo> groups) throws IOExc
for (int i = 0; i < group.numObjects(); i++) {
var type = graph.types().get(group.typeStart() + objects.size());
var object = (RTTIRefObject) type.newInstance();
objects.add(new ObjectInfo(object, type));
objects.add(new ObjectInfo(type, object));
}

var result = new GroupInfo(group, objects);
Expand All @@ -132,7 +132,7 @@ public GroupInfo readGroup(int id, @NotNull List<GroupInfo> groups) throws IOExc
var object = objects.get(j++);

if (DEBUG) {
log.debug("{}Reading \033[33m{}\033[0m at offset \033[34m{}\033[0m in \033[33m{}\033[0m", " ".repeat(depth), object.info(), span.offset() + reader.position(), getSpanFile(span));
log.debug("{}Reading \033[33m{}\033[0m at offset \033[34m{}\033[0m in \033[33m{}\033[0m", " ".repeat(depth), object.type(), span.offset() + reader.position(), getSpanFile(span));
}

fillCompound(object, reader);
Expand All @@ -146,7 +146,7 @@ public GroupInfo readGroup(int id, @NotNull List<GroupInfo> groups) throws IOExc

private void fillCompound(@NotNull ObjectInfo info, @NotNull BinaryReader reader) throws IOException {
var object = info.object();
for (ClassAttrInfo attr : info.info().serializableAttrs()) {
for (ClassAttrInfo attr : info.type().serializableAttrs()) {
attr.set(object, read(attr.type().get(), reader, factory));
}
if (object instanceof ExtraBinaryDataHolder holder) {
Expand Down Expand Up @@ -227,7 +227,7 @@ private void resolveLink(@NotNull PointerTypeInfo info, @NotNull Ref<?> ref) {
linkIndex,
linkGroup,
group.group.groupID(),
object.info(),
object.type(),
matches ? "\033[32mtrue\033[0m" : "\033[31mfalse\033[0m"
);
}
Expand Down

0 comments on commit f46f034

Please sign in to comment.