Skip to content

Commit

Permalink
Release persistence API to master
Browse files Browse the repository at this point in the history
  • Loading branch information
MadMartian committed Oct 29, 2021
1 parent 40c66a4 commit abddf5c
Show file tree
Hide file tree
Showing 32 changed files with 174 additions and 98 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositories {

group 'com.extollit.gaming'
description = "An iterative A* path-finding engine designed for blocky sandbox games having entities with differing path requirements"
version '1.7.1-SNAPSHOT'
version '1.7.1'

apply plugin: 'java'
apply plugin: 'signing'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.extollit.gaming.ai.path;

import com.extollit.gaming.ai.path.model.*;
import com.extollit.gaming.ai.path.persistence.*;
import com.extollit.gaming.ai.path.persistence.internal.*;
import com.extollit.linalg.immutable.AxisAlignedBBox;
import com.extollit.linalg.immutable.Vec3i;
import com.extollit.linalg.mutable.Vec3d;
Expand Down Expand Up @@ -1218,7 +1218,7 @@ public void writeLinkages(HydrazinePathFinder object, ReferableObjectOutput<Node
}

@Override
public void writeVersioned(byte version, Persistence.ReaderWriters readerWriters, ObjectOutput out) throws IOException {
public void writeVersioned(byte version, ReaderWriters readerWriters, ObjectOutput out) throws IOException {
final IdentityMapper<Node, Node.ReaderWriter> identities = new IdentityMapper<Node, Node.ReaderWriter>(Node.ReaderWriter.INSTANCE);

out.writeByte(this.unreachableFromSource.size());
Expand Down Expand Up @@ -1253,7 +1253,7 @@ public void writeVersioned(byte version, Persistence.ReaderWriters readerWriters
}

@Override
public void readVersioned(byte version, Persistence.ReaderWriters readerWriters, ObjectInput in) throws IOException {
public void readVersioned(byte version, ReaderWriters readerWriters, ObjectInput in) throws IOException {
final IdentityMapper<Node, Node.ReaderWriter> identities = new IdentityMapper<Node, Node.ReaderWriter>(Node.ReaderWriter.INSTANCE);

byte count = in.readByte();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/extollit/gaming/ai/path/model/Node.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.extollit.gaming.ai.path.model;

import com.extollit.gaming.ai.path.persistence.*;
import com.extollit.gaming.ai.path.persistence.internal.*;
import com.extollit.linalg.immutable.Vec3i;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.extollit.gaming.ai.path.model;

import com.extollit.collect.SparseSpatialMap;
import com.extollit.gaming.ai.path.persistence.*;
import com.extollit.gaming.ai.path.persistence.internal.*;
import com.extollit.linalg.immutable.Vec3i;

import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.extollit.gaming.ai.path.model;

import com.extollit.gaming.ai.path.IConfigModel;
import com.extollit.gaming.ai.path.persistence.*;
import com.extollit.gaming.ai.path.persistence.internal.*;
import com.extollit.linalg.immutable.Vec3i;
import com.extollit.linalg.mutable.Vec3d;
import com.extollit.num.FloatRange;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.extollit.gaming.ai.path.model;

import com.extollit.gaming.ai.path.persistence.LinkableReader;
import com.extollit.gaming.ai.path.persistence.LinkableWriter;
import com.extollit.gaming.ai.path.persistence.ReferableObjectInput;
import com.extollit.gaming.ai.path.persistence.ReferableObjectOutput;
import com.extollit.gaming.ai.path.persistence.internal.LinkableReader;
import com.extollit.gaming.ai.path.persistence.internal.LinkableWriter;
import com.extollit.gaming.ai.path.persistence.internal.ReferableObjectInput;
import com.extollit.gaming.ai.path.persistence.internal.ReferableObjectOutput;
import com.extollit.linalg.immutable.Vec3i;

import java.io.IOException;
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.extollit.gaming.ai.path.HydrazinePathFinder;
import com.extollit.gaming.ai.path.model.IInstanceSpace;
import com.extollit.gaming.ai.path.persistence.internal.DummyPathingEntity;
import com.extollit.gaming.ai.path.persistence.internal.ReaderWriters;

import java.io.*;

Expand Down Expand Up @@ -29,7 +31,7 @@ public class Persistence {
* @see #restore(ObjectInput, IInstanceSpace)
*/
public static void persist(HydrazinePathFinder pathFinder, ObjectOutput out) throws IOException {
final Persistence.ReaderWriters readerWriters = Persistence.ReaderWriters.forVersion(VERSION);
final ReaderWriters readerWriters = ReaderWriters.forVersion(VERSION);

out.writeUTF(TAG);
out.writeByte(VERSION);
Expand Down Expand Up @@ -58,7 +60,7 @@ public static HydrazinePathFinder restore(ObjectInput in, IInstanceSpace instanc
if (ver > VERSION)
throw new IOException("Unsupported version: " + ver);

final Persistence.ReaderWriters readerWriters = Persistence.ReaderWriters.forVersion(ver);
final ReaderWriters readerWriters = ReaderWriters.forVersion(ver);

final DummyPathingEntity pathingEntity = readerWriters.dpe.readPartialObject(in);
final HydrazinePathFinder pathFinder = new HydrazinePathFinder(pathingEntity, instanceSpace);
Expand Down Expand Up @@ -165,30 +167,4 @@ public static HydrazinePathFinder restore(InputStream in, IInstanceSpace instanc
return restore((ObjectInput) new ObjectInputStream(in), instanceSpace);
}

public static final class ReaderWriters {
public static final ReaderWriters
legacy = new ReaderWriters(Vec3dReaderWriter.INSTANCEz, MutableVec3dReaderWriter.INSTANCEz, Vec3iReaderWriter.INSTANCEz),
v4 = new ReaderWriters(NullableVec3dReaderWriter.INSTANCE, NullableMutableVec3dReaderWriter.INSTANCE, NullableVec3iReaderWriter.INSTANCE);

public final Vec3dReaderWriter v3d;
public final MutableVec3dReaderWriter mv3d;
public final Vec3iReaderWriter v3i;
public final DummyDynamicMovableObject.ReaderWriter ddmo;
public final DummyPathingEntity.ReaderWriter dpe;

public ReaderWriters(Vec3dReaderWriter v3d, MutableVec3dReaderWriter mv3d, Vec3iReaderWriter v3i) {
this.v3d = v3d;
this.mv3d = mv3d;
this.v3i = v3i;
this.ddmo = new DummyDynamicMovableObject.ReaderWriter(v3d);
this.dpe = new DummyPathingEntity.ReaderWriter(mv3d, v3d);
}

public static ReaderWriters forVersion(byte version) {
if (version < 4)
return legacy;
else
return v4;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.extollit.gaming.ai.path.persistence;
package com.extollit.gaming.ai.path.persistence.internal;

import com.extollit.gaming.ai.path.model.IDynamicMovableObject;
import com.extollit.linalg.immutable.Vec3d;
Expand All @@ -11,7 +11,7 @@ final class DummyDynamicMovableObject implements IDynamicMovableObject {
public static final class ReaderWriter implements PartialObjectWriter<IDynamicMovableObject>, PartialObjectReader<DummyDynamicMovableObject> {
private final Vec3dReaderWriter vec3dReaderWriter;

public ReaderWriter(Vec3dReaderWriter vec3dReaderWriter) {
ReaderWriter(Vec3dReaderWriter vec3dReaderWriter) {
this.vec3dReaderWriter = vec3dReaderWriter;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.extollit.gaming.ai.path.persistence;
package com.extollit.gaming.ai.path.persistence.internal;

import com.extollit.gaming.ai.path.model.Gravitation;
import com.extollit.gaming.ai.path.model.IPathingEntity;
Expand All @@ -9,7 +9,11 @@
import java.io.ObjectInput;
import java.io.ObjectOutput;

class DummyPathingEntity implements IPathingEntity, IPathingEntity.Capabilities {
/**
* Internal API, do not use this directly
* @see com.extollit.gaming.ai.path.persistence.Persistence
*/
public class DummyPathingEntity implements IPathingEntity, IPathingEntity.Capabilities {
public static final class ReaderWriter implements PartialObjectWriter<IPathingEntity>, PartialObjectReader<DummyPathingEntity> {
private final MutableVec3dReaderWriter mutableVec3dReaderWriter;
private final Vec3dReaderWriter vec3dReaderWriter;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.extollit.gaming.ai.path.persistence.internal;

import java.io.IOException;
import java.io.ObjectInput;

/**
* Internal API, do not use this directly
* @see com.extollit.gaming.ai.path.persistence.Persistence
*/
public interface IVersionedReadable {
void readVersioned(byte version, ReaderWriters readerWriters, ObjectInput input) throws IOException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.extollit.gaming.ai.path.persistence.internal;

import java.io.IOException;
import java.io.ObjectOutput;

/**
* Internal API, do not use this directly
* @see com.extollit.gaming.ai.path.persistence.Persistence
*/
public interface IVersionedWriteable {
void writeVersioned(byte version, ReaderWriters readerWriters, ObjectOutput output) throws IOException;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.extollit.gaming.ai.path.persistence;
package com.extollit.gaming.ai.path.persistence.internal;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.text.MessageFormat;
import java.util.*;

/**
* Internal API, do not use this directly
* @see com.extollit.gaming.ai.path.persistence.Persistence
*/
public class IdentityMapper<T, RW extends PartialObjectReader<T> & PartialObjectWriter<T>> {
private final Map<T, Short> reverseMap = new IdentityHashMap<>();
private final List<T> map = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.extollit.gaming.ai.path.persistence.internal;

import java.io.IOException;

/**
* Internal API, do not use this directly
* @see com.extollit.gaming.ai.path.persistence.Persistence
*/
public interface LinkableReader<A, B> {
void readLinkages(A object, ReferableObjectInput<B> in) throws IOException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.extollit.gaming.ai.path.persistence.internal;

import java.io.IOException;

/**
* Internal API, do not use this directly
* @see com.extollit.gaming.ai.path.persistence.Persistence
*/
public interface LinkableWriter<A, B> {
void writeLinkages(A object, ReferableObjectOutput<B> out) throws IOException;
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.extollit.gaming.ai.path.persistence;
package com.extollit.gaming.ai.path.persistence.internal;

import com.extollit.linalg.mutable.Vec3d;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

/**
* Internal API, do not use this directly
* @see com.extollit.gaming.ai.path.persistence.Persistence
*/
public class MutableVec3dReaderWriter implements PartialObjectReader<Vec3d>, PartialObjectWriter<Vec3d> {
public static final MutableVec3dReaderWriter INSTANCEz = new MutableVec3dReaderWriter();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.extollit.gaming.ai.path.persistence;
package com.extollit.gaming.ai.path.persistence.internal;

import com.extollit.linalg.mutable.Vec3d;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

/**
* Internal API, do not use this directly
* @see com.extollit.gaming.ai.path.persistence.Persistence
*/
public class NullableMutableVec3dReaderWriter extends MutableVec3dReaderWriter {
public static final NullableMutableVec3dReaderWriter INSTANCE = new NullableMutableVec3dReaderWriter();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.extollit.gaming.ai.path.persistence;
package com.extollit.gaming.ai.path.persistence.internal;

import com.extollit.linalg.immutable.Vec3d;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

/**
* Internal API, do not use this directly
* @see com.extollit.gaming.ai.path.persistence.Persistence
*/
public class NullableVec3dReaderWriter extends Vec3dReaderWriter {
public static final NullableVec3dReaderWriter INSTANCE = new NullableVec3dReaderWriter();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.extollit.gaming.ai.path.persistence;
package com.extollit.gaming.ai.path.persistence.internal;

import com.extollit.linalg.immutable.Vec3i;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

/**
* Internal API, do not use this directly
* @see com.extollit.gaming.ai.path.persistence.Persistence
*/
public class NullableVec3iReaderWriter extends Vec3iReaderWriter {
public static final NullableVec3iReaderWriter INSTANCE = new NullableVec3iReaderWriter();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.extollit.gaming.ai.path.persistence.internal;

import java.io.IOException;
import java.io.ObjectInput;

/**
* Internal API, do not use this directly
* @see com.extollit.gaming.ai.path.persistence.Persistence
*/
public interface PartialObjectReader<T> {
T readPartialObject(ObjectInput in) throws IOException;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.extollit.gaming.ai.path.persistence;
package com.extollit.gaming.ai.path.persistence.internal;

import java.io.IOException;
import java.io.ObjectOutput;

/**
* Internal API, do not use this directly
* @see com.extollit.gaming.ai.path.persistence.Persistence
*/
public interface PartialObjectWriter<T> {
void writePartialObject(T object, ObjectOutput out) throws IOException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.extollit.gaming.ai.path.persistence.internal;

/**
* Internal API, do not use this directly
* @see com.extollit.gaming.ai.path.persistence.Persistence
*/
public enum PathType {
none,
complete,
incomplete
}
Loading

0 comments on commit abddf5c

Please sign in to comment.