From 328913afab8ad5c1afa721cbe1ec07666f96f5a3 Mon Sep 17 00:00:00 2001 From: Andrew Delph Date: Wed, 11 Oct 2023 23:17:14 -0400 Subject: [PATCH] create custom pair class --- .vscode/settings.json | 3 + build.gradle | 3 + .../core/chunk/world/CreateBodyCallable.java | 2 +- .../core/chunk/world/EntityBodyBuilder.java | 27 +++--- core/src/core/chunk/world/WorldWrapper.java | 5 +- core/src/core/common/CommonFactory.java | 40 ++++---- core/src/core/common/Pair.java | 37 ++++++++ core/src/core/entity/Entity.java | 21 ++-- core/src/core/entity/block/EmptyBlock.java | 2 +- core/src/core/entity/block/SolidBlock.java | 2 +- core/src/core/entity/misc/Ladder.java | 2 +- core/src/core/entity/misc/Orb.java | 10 +- core/src/core/entity/misc/Projectile.java | 2 +- core/src/core/entity/misc/Sand.java | 2 +- core/src/core/entity/misc/Turret.java | 2 +- core/src/core/entity/misc/water/Water.java | 2 +- .../core/entity/misc/water/WaterPosition.java | 5 +- .../client/ClientNetworkHandle.java | 88 +++++++++-------- .../translation/NetworkDataDeserializer.java | 95 ++++++++++++------- 19 files changed, 214 insertions(+), 136 deletions(-) create mode 100644 .vscode/settings.json create mode 100644 core/src/core/common/Pair.java diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..c5f3f6b9 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "interactive" +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index b47fcfec..f1b39528 100644 --- a/build.gradle +++ b/build.gradle @@ -26,6 +26,8 @@ plugins { // } //} + + scmVersion { useHighestVersion = true tag { @@ -111,6 +113,7 @@ project(":core") { api "com.badlogicgames.gdx:gdx-box2d:$gdxVersion" implementation 'junit:junit:4.12' implementation 'io.grpc:grpc-netty:1.32.1' + implementation 'org.apache.commons:commons-lang3:3.13.0' implementation 'io.grpc:grpc-okhttp:1.32.1' implementation 'io.grpc:grpc-protobuf:1.32.1' implementation 'io.grpc:grpc-stub:1.32.1' diff --git a/core/src/core/chunk/world/CreateBodyCallable.java b/core/src/core/chunk/world/CreateBodyCallable.java index 542da797..3901e297 100644 --- a/core/src/core/chunk/world/CreateBodyCallable.java +++ b/core/src/core/chunk/world/CreateBodyCallable.java @@ -2,7 +2,7 @@ import com.badlogic.gdx.physics.box2d.Body; import com.badlogic.gdx.physics.box2d.World; -import com.sun.tools.javac.util.Pair; +import core.common.Pair; import java.util.UUID; public abstract class CreateBodyCallable { diff --git a/core/src/core/chunk/world/EntityBodyBuilder.java b/core/src/core/chunk/world/EntityBodyBuilder.java index 6a6a0db6..05428807 100644 --- a/core/src/core/chunk/world/EntityBodyBuilder.java +++ b/core/src/core/chunk/world/EntityBodyBuilder.java @@ -10,9 +10,10 @@ import com.badlogic.gdx.physics.box2d.FixtureDef; import com.badlogic.gdx.physics.box2d.PolygonShape; import com.badlogic.gdx.physics.box2d.World; -import com.sun.tools.javac.util.Pair; + import core.common.ChunkRange; import core.common.GameSettings; +import core.common.Pair; import core.entity.Entity; import core.entity.block.Block; import core.entity.collision.EntitySensor; @@ -31,10 +32,8 @@ public class EntityBodyBuilder { public static Pair createEntityBody( World world, ChunkRange chunkRange, Entity entity) { - float center_x = - -(GameSettings.PHYSICS_SCALE - (Entity.staticWidth * GameSettings.PHYSICS_SCALE)) / 2f; - float center_y = - -(GameSettings.PHYSICS_SCALE - (Entity.staticHeight * GameSettings.PHYSICS_SCALE)) / 2f; + float center_x = -(GameSettings.PHYSICS_SCALE - (Entity.staticWidth * GameSettings.PHYSICS_SCALE)) / 2f; + float center_y = -(GameSettings.PHYSICS_SCALE - (Entity.staticHeight * GameSettings.PHYSICS_SCALE)) / 2f; Body theBody; BodyDef bodyDef = new BodyDef(); @@ -134,8 +133,8 @@ public static Pair createEntityBody( rightFixture.setUserData(new RightSensor(entity, chunkRange)); rightFixture.setFilterData(entityFilter()); - // theBody.setLinearDamping(1f); - // theBody.setAngularDamping(0.1f); + // theBody.setLinearDamping(1f); + // theBody.setAngularDamping(0.1f); return new Pair<>(entity.getUuid(), theBody); } @@ -164,7 +163,7 @@ public static Pair createStaticBlockBody( blockFixture.setFilterData(blockFilter()); blockFixture.setUserData(new GroundSensor(entity, chunkRange)); - // theBody.resetMassData(); + // theBody.resetMassData(); return new Pair<>(entity.getUuid(), theBody); } @@ -252,7 +251,7 @@ public static Pair createTurretBody( Fixture blockFixture = theBody.createFixture(fixtureDef); blockFixture.setFilterData(ladderFilter()); - // blockFixture.setUserData(new LadderSensor(entity, chunkRange)); + // blockFixture.setUserData(new LadderSensor(entity, chunkRange)); return new Pair<>(entity.getUuid(), theBody); } @@ -275,7 +274,7 @@ public static Pair createOrb(World world, ChunkRange chunkRange, Ent blockingFixtureDef.shape = blockingShape; blockingFixtureDef.density = 1f; blockingFixtureDef.restitution = 1; - // fixtureDef.isSensor = true; + // fixtureDef.isSensor = true; Fixture orbFixture = theBody.createFixture(blockingFixtureDef); orbFixture.setFilterData(entityFilter()); @@ -373,14 +372,14 @@ public static Pair createSand(World world, ChunkRange chunkRange, En FixtureDef blockingFixtureDef = new FixtureDef(); blockingFixtureDef.shape = blockingShape; blockingFixtureDef.density = 1f; - // blockingFixtureDef.restitution = 1; - // fixtureDef.isSensor = true; + // blockingFixtureDef.restitution = 1; + // fixtureDef.isSensor = true; Fixture blockFixture = theBody.createFixture(blockingFixtureDef); blockFixture.setFilterData(blockFilter()); blockFixture.setUserData(new GroundSensor(entity, chunkRange)); - // theBody.setLinearDamping(0.1f); - // theBody.setAngularDamping(0.1f); + // theBody.setLinearDamping(0.1f); + // theBody.setAngularDamping(0.1f); return new Pair<>(entity.getUuid(), theBody); } diff --git a/core/src/core/chunk/world/WorldWrapper.java b/core/src/core/chunk/world/WorldWrapper.java index 1ac5da62..b30cbd62 100644 --- a/core/src/core/chunk/world/WorldWrapper.java +++ b/core/src/core/chunk/world/WorldWrapper.java @@ -3,7 +3,7 @@ import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.physics.box2d.Body; import com.badlogic.gdx.physics.box2d.World; -import com.sun.tools.javac.util.Pair; +import core.common.Pair; import core.chunk.world.exceptions.BodyNotFound; import core.chunk.world.exceptions.DestroyBodyException; import core.common.ChunkRange; @@ -32,7 +32,8 @@ public synchronized void tick() { public synchronized void addEntity(CreateBodyCallable createBodyCallable) { Pair pair = createBodyCallable.addWorld(world); - if (pair == null) return; + if (pair == null) + return; uuidBodyMap.put(pair.fst, pair.snd); } diff --git a/core/src/core/common/CommonFactory.java b/core/src/core/common/CommonFactory.java index a5181c0f..52dbb3f7 100644 --- a/core/src/core/common/CommonFactory.java +++ b/core/src/core/common/CommonFactory.java @@ -4,33 +4,31 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; -import com.sun.tools.javac.util.Pair; +import core.common.Pair; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import networking.NetworkObjects; public class CommonFactory { - static LoadingCache, Coordinates> coordinatesCache = - CacheBuilder.newBuilder() - .maximumSize(1000) - .expireAfterWrite(10, TimeUnit.SECONDS) - .build( - new CacheLoader, Coordinates>() { - public Coordinates load(Pair pair) { - return new Coordinates(pair.fst, pair.snd); - } - }); + static LoadingCache, Coordinates> coordinatesCache = CacheBuilder.newBuilder() + .maximumSize(1000) + .expireAfterWrite(10, TimeUnit.SECONDS) + .build( + new CacheLoader, Coordinates>() { + public Coordinates load(Pair pair) { + return new Coordinates(pair.fst, pair.snd); + } + }); - static LoadingCache chunkRangeCache = - CacheBuilder.newBuilder() - .maximumSize(1000) - .expireAfterWrite(10, TimeUnit.MINUTES) - .build( - new CacheLoader() { - public ChunkRange load(Coordinates coordinates) { - return new ChunkRange(coordinates); - } - }); + static LoadingCache chunkRangeCache = CacheBuilder.newBuilder() + .maximumSize(1000) + .expireAfterWrite(10, TimeUnit.MINUTES) + .build( + new CacheLoader() { + public ChunkRange load(Coordinates coordinates) { + return new ChunkRange(coordinates); + } + }); public static Coordinates createCoordinates(float x, float y) { try { diff --git a/core/src/core/common/Pair.java b/core/src/core/common/Pair.java new file mode 100644 index 00000000..178ca803 --- /dev/null +++ b/core/src/core/common/Pair.java @@ -0,0 +1,37 @@ +package core.common; + +public class Pair { + + public final L fst; + public final R snd; + + public Pair(L left, R right) { + assert left != null; + assert right != null; + + this.fst = left; + this.snd = right; + } + + public L getFst() { + return fst; + } + + public R getSnd() { + return snd; + } + + @Override + public int hashCode() { + return fst.hashCode() ^ snd.hashCode(); + } + + @Override + public boolean equals(Object o) { + if (!(o instanceof Pair)) + return false; + Pair pairo = (Pair) o; + return this.fst.equals(pairo.getFst()) && + this.snd.equals(pairo.getSnd()); + } +} diff --git a/core/src/core/entity/Entity.java b/core/src/core/entity/Entity.java index 9641a1b4..5c3a2ef5 100644 --- a/core/src/core/entity/Entity.java +++ b/core/src/core/entity/Entity.java @@ -8,7 +8,7 @@ import com.badlogic.gdx.physics.box2d.Body; import com.badlogic.gdx.physics.box2d.World; import com.google.common.base.Objects; -import com.sun.tools.javac.util.Pair; +import core.common.Pair; import core.app.screen.assets.BaseAssetManager; import core.app.screen.assets.animations.AnimationManager; import core.app.screen.assets.animations.AnimationState; @@ -48,15 +48,14 @@ public class Entity implements SerializeNetworkData { public static float staticWidth = 0.8f; private final Clock clock; private final InventoryBag bag; - // public Coordinates coordinates; + // public Coordinates coordinates; public int zindex = 3; public EntityBodyBuilder entityBodyBuilder; public Sprite sprite; public Health health; protected BaseAssetManager baseAssetManager; float stateTime; - private EntityStateMachine entityStateMachine = - new EntityStateMachine(this, new HashMap<>(), new HashMap<>()); + private EntityStateMachine entityStateMachine = new EntityStateMachine(this, new HashMap<>(), new HashMap<>()); private DirectionWrapper directionWrapper = new DirectionWrapper(Direction.RIGHT); private CoordinatesWrapper coordinatesWrapper; private UUID uuid; @@ -64,8 +63,7 @@ public class Entity implements SerializeNetworkData { private EntityController entityController; private int width; private int height; - private AnimationStateWrapper animationStateWrapper = - new AnimationStateWrapper(AnimationState.DEFAULT); + private AnimationStateWrapper animationStateWrapper = new AnimationStateWrapper(AnimationState.DEFAULT); public Entity( Clock clock, @@ -77,7 +75,7 @@ public Entity( this.clock = clock; this.baseAssetManager = baseAssetManager; this.entityBodyBuilder = entityBodyBuilder; - // this.coordinates = coordinates; + // this.coordinates = coordinates; this.coordinatesWrapper = new CoordinatesWrapper(coordinates); this.uuid = UUID.randomUUID(); this.health = new Health(100); @@ -146,7 +144,8 @@ public void setCoordinatesWrapper(CoordinatesWrapper coordinatesWrapper) { public Chunk getChunk() throws ChunkNotFound { Chunk toReturn = chunk; - if (toReturn == null) throw new ChunkNotFound(this.toString()); + if (toReturn == null) + throw new ChunkNotFound(this.toString()); return toReturn; } @@ -192,7 +191,7 @@ protected Pair addWorld(World world) { } public void render(AnimationManager animationManager, SpriteBatch batch) { - // entityStateMachine.callAnimation(); + // entityStateMachine.callAnimation(); stateTime += Gdx.graphics.getDeltaTime(); Vector2 v2 = this.getCoordinatesWrapper().getCoordinates().toRenderVector2(); @@ -268,8 +267,8 @@ public boolean equals(Object o) { } Entity entity = (Entity) o; return Objects.equal( - this.getCoordinatesWrapper().getCoordinates(), - entity.getCoordinatesWrapper().getCoordinates()) + this.getCoordinatesWrapper().getCoordinates(), + entity.getCoordinatesWrapper().getCoordinates()) && Objects.equal(health, entity.health) && Objects.equal(uuid, entity.uuid) && Objects.equal(bag, entity.bag) diff --git a/core/src/core/entity/block/EmptyBlock.java b/core/src/core/entity/block/EmptyBlock.java index 1def0625..fcd65841 100644 --- a/core/src/core/entity/block/EmptyBlock.java +++ b/core/src/core/entity/block/EmptyBlock.java @@ -2,7 +2,7 @@ import com.badlogic.gdx.physics.box2d.Body; import com.badlogic.gdx.physics.box2d.World; -import com.sun.tools.javac.util.Pair; +import core.common.Pair; import core.app.screen.assets.BaseAssetManager; import core.chunk.Chunk; import core.chunk.world.CreateBodyCallable; diff --git a/core/src/core/entity/block/SolidBlock.java b/core/src/core/entity/block/SolidBlock.java index 6351e1c8..6a503a1c 100644 --- a/core/src/core/entity/block/SolidBlock.java +++ b/core/src/core/entity/block/SolidBlock.java @@ -2,7 +2,7 @@ import com.badlogic.gdx.physics.box2d.Body; import com.badlogic.gdx.physics.box2d.World; -import com.sun.tools.javac.util.Pair; +import core.common.Pair; import core.app.screen.assets.BaseAssetManager; import core.chunk.Chunk; import core.chunk.world.CreateBodyCallable; diff --git a/core/src/core/entity/misc/Ladder.java b/core/src/core/entity/misc/Ladder.java index df449ec7..254f52bf 100644 --- a/core/src/core/entity/misc/Ladder.java +++ b/core/src/core/entity/misc/Ladder.java @@ -2,7 +2,7 @@ import com.badlogic.gdx.physics.box2d.Body; import com.badlogic.gdx.physics.box2d.World; -import com.sun.tools.javac.util.Pair; +import core.common.Pair; import core.app.screen.assets.BaseAssetManager; import core.chunk.Chunk; import core.chunk.world.CreateBodyCallable; diff --git a/core/src/core/entity/misc/Orb.java b/core/src/core/entity/misc/Orb.java index b477d020..ca58badb 100644 --- a/core/src/core/entity/misc/Orb.java +++ b/core/src/core/entity/misc/Orb.java @@ -2,7 +2,7 @@ import com.badlogic.gdx.physics.box2d.Body; import com.badlogic.gdx.physics.box2d.World; -import com.sun.tools.javac.util.Pair; +import core.common.Pair; import core.app.screen.assets.BaseAssetManager; import core.chunk.Chunk; import core.chunk.world.CreateBodyCallable; @@ -35,10 +35,10 @@ public void needsUpdate() { @Override public synchronized int getUpdateTimeout() { - // if (isLive) { - // isLive = false; - // return 1; - // } + // if (isLive) { + // isLive = false; + // return 1; + // } return Integer.MAX_VALUE; } diff --git a/core/src/core/entity/misc/Projectile.java b/core/src/core/entity/misc/Projectile.java index 6861d79f..a496fe47 100644 --- a/core/src/core/entity/misc/Projectile.java +++ b/core/src/core/entity/misc/Projectile.java @@ -2,7 +2,7 @@ import com.badlogic.gdx.physics.box2d.Body; import com.badlogic.gdx.physics.box2d.World; -import com.sun.tools.javac.util.Pair; +import core.common.Pair; import core.app.screen.assets.BaseAssetManager; import core.chunk.Chunk; import core.chunk.world.CreateBodyCallable; diff --git a/core/src/core/entity/misc/Sand.java b/core/src/core/entity/misc/Sand.java index 1862e75e..c72c0c40 100644 --- a/core/src/core/entity/misc/Sand.java +++ b/core/src/core/entity/misc/Sand.java @@ -2,7 +2,7 @@ import com.badlogic.gdx.physics.box2d.Body; import com.badlogic.gdx.physics.box2d.World; -import com.sun.tools.javac.util.Pair; +import core.common.Pair; import core.app.screen.assets.BaseAssetManager; import core.chunk.Chunk; import core.chunk.world.CreateBodyCallable; diff --git a/core/src/core/entity/misc/Turret.java b/core/src/core/entity/misc/Turret.java index b34275c7..3205e0eb 100644 --- a/core/src/core/entity/misc/Turret.java +++ b/core/src/core/entity/misc/Turret.java @@ -2,7 +2,7 @@ import com.badlogic.gdx.physics.box2d.Body; import com.badlogic.gdx.physics.box2d.World; -import com.sun.tools.javac.util.Pair; +import core.common.Pair; import core.app.screen.assets.BaseAssetManager; import core.chunk.Chunk; import core.chunk.world.CreateBodyCallable; diff --git a/core/src/core/entity/misc/water/Water.java b/core/src/core/entity/misc/water/Water.java index abd3a697..f416bfa5 100644 --- a/core/src/core/entity/misc/water/Water.java +++ b/core/src/core/entity/misc/water/Water.java @@ -4,7 +4,7 @@ import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.physics.box2d.Body; import com.badlogic.gdx.physics.box2d.World; -import com.sun.tools.javac.util.Pair; +import core.common.Pair; import core.app.screen.assets.BaseAssetManager; import core.chunk.Chunk; import core.chunk.world.CreateBodyCallable; diff --git a/core/src/core/entity/misc/water/WaterPosition.java b/core/src/core/entity/misc/water/WaterPosition.java index 1d1a3455..59462675 100644 --- a/core/src/core/entity/misc/water/WaterPosition.java +++ b/core/src/core/entity/misc/water/WaterPosition.java @@ -3,7 +3,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.physics.box2d.Body; import com.badlogic.gdx.physics.box2d.World; -import com.sun.tools.javac.util.Pair; +import core.common.Pair; import core.app.screen.assets.BaseAssetManager; import core.app.screen.assets.animations.AnimationManager; import core.chunk.Chunk; @@ -26,7 +26,8 @@ public WaterPosition( } @Override - public void render(AnimationManager animationManager, SpriteBatch batch) {} + public void render(AnimationManager animationManager, SpriteBatch batch) { + } @Override public synchronized int getUpdateTimeout() { diff --git a/core/src/core/networking/client/ClientNetworkHandle.java b/core/src/core/networking/client/ClientNetworkHandle.java index d7da3b26..e32d7813 100644 --- a/core/src/core/networking/client/ClientNetworkHandle.java +++ b/core/src/core/networking/client/ClientNetworkHandle.java @@ -3,7 +3,7 @@ import com.badlogic.gdx.Gdx; import com.google.inject.Inject; import com.google.protobuf.Empty; -import com.sun.tools.javac.util.Pair; +import core.common.Pair; import core.app.user.User; import core.chunk.Chunk; import core.chunk.ChunkFactory; @@ -40,22 +40,33 @@ public class ClientNetworkHandle { public final CountDownLatch authLatch = new CountDownLatch(1); RequestNetworkEventObserver requestNetworkEventObserver; - @Inject ObserverFactory observerFactory; - @Inject EventTypeFactory eventTypeFactory; - @Inject NetworkDataDeserializer entitySerializationConverter; - @Inject GameStore gameStore; - @Inject ChunkFactory chunkFactory; - @Inject User user; - @Inject GameSettings gameSettings; - @Inject PingService pingService; - @Inject SyncService syncService; - @Inject NetworkDataDeserializer networkDataDeserializer; + @Inject + ObserverFactory observerFactory; + @Inject + EventTypeFactory eventTypeFactory; + @Inject + NetworkDataDeserializer entitySerializationConverter; + @Inject + GameStore gameStore; + @Inject + ChunkFactory chunkFactory; + @Inject + User user; + @Inject + GameSettings gameSettings; + @Inject + PingService pingService; + @Inject + SyncService syncService; + @Inject + NetworkDataDeserializer networkDataDeserializer; private ManagedChannel channel; private NetworkObjectServiceGrpc.NetworkObjectServiceStub asyncStub; private NetworkObjectServiceGrpc.NetworkObjectServiceBlockingStub blockStub; @Inject - public ClientNetworkHandle() {} + public ClientNetworkHandle() { + } public void connect() throws InterruptedException, WrongVersion { @@ -78,13 +89,12 @@ public void connect() throws InterruptedException, WrongVersion { this.asyncStub = NetworkObjectServiceGrpc.newStub(channel); this.blockStub = NetworkObjectServiceGrpc.newBlockingStub(channel); requestNetworkEventObserver = observerFactory.create(); - requestNetworkEventObserver.responseObserver = - this.asyncStub.networkObjectStream(requestNetworkEventObserver); + requestNetworkEventObserver.responseObserver = this.asyncStub.networkObjectStream(requestNetworkEventObserver); this.checkVersion(); - NetworkObjects.NetworkEvent authenticationEvent = - NetworkObjects.NetworkEvent.newBuilder().setEvent(DataTranslationEnum.AUTH).build(); + NetworkObjects.NetworkEvent authenticationEvent = NetworkObjects.NetworkEvent.newBuilder() + .setEvent(DataTranslationEnum.AUTH).build(); this.send(authenticationEvent); if (!authLatch.await(5, TimeUnit.SECONDS)) { throw new InterruptedException("did not receive auth information"); @@ -93,11 +103,10 @@ public void connect() throws InterruptedException, WrongVersion { } public synchronized void send(NetworkObjects.NetworkEvent networkEvent) { - networkEvent = - networkEvent.toBuilder() - .setUser(this.user.toString()) - .setTime(Clock.getCurrentTime()) - .build(); + networkEvent = networkEvent.toBuilder() + .setUser(this.user.toString()) + .setTime(Clock.getCurrentTime()) + .build(); requestNetworkEventObserver.responseObserver.onNext(networkEvent); } @@ -113,13 +122,12 @@ public Chunk requestChunkBlocking(ChunkRange chunkRange) throws SerializationDat } } - GetChunkOutgoingEventType outgoing = - eventTypeFactory.createGetChunkOutgoingEventType(chunkRange, this.user.getUserID()); - NetworkObjects.NetworkEvent retrievedNetworkEvent = - this.blockStub.getChunk(outgoing.toNetworkEvent()); + GetChunkOutgoingEventType outgoing = eventTypeFactory.createGetChunkOutgoingEventType(chunkRange, + this.user.getUserID()); + NetworkObjects.NetworkEvent retrievedNetworkEvent = this.blockStub.getChunk(outgoing.toNetworkEvent()); - Pair> chunkData = - entitySerializationConverter.createChunkData(retrievedNetworkEvent.getData()); + Pair> chunkData = entitySerializationConverter + .createChunkData(retrievedNetworkEvent.getData()); for (Entity toAdd : chunkData.snd) { try { @@ -146,9 +154,8 @@ public boolean requestChunkAsync(ChunkRange requestedChunkRange) { } } - GetChunkOutgoingEventType outgoing = - eventTypeFactory.createGetChunkOutgoingEventType( - requestedChunkRange, this.user.getUserID()); + GetChunkOutgoingEventType outgoing = eventTypeFactory.createGetChunkOutgoingEventType( + requestedChunkRange, this.user.getUserID()); // make the async request // at the end of the request remove the lock asyncStub.getChunk( @@ -159,8 +166,8 @@ public boolean requestChunkAsync(ChunkRange requestedChunkRange) { public void onNext(NetworkObjects.NetworkEvent networkEvent) { // calls data received try { - Pair> chunkData = - entitySerializationConverter.createChunkData(networkEvent.getData()); + Pair> chunkData = entitySerializationConverter + .createChunkData(networkEvent.getData()); for (Entity toAdd : chunkData.snd) { try { gameStore.addEntity(toAdd); @@ -181,7 +188,8 @@ public void onError(Throwable t) { } @Override - public void onCompleted() {} + public void onCompleted() { + } }); // in the observer. at the end return true; @@ -204,19 +212,17 @@ public synchronized void initHandshake(ChunkRange chunkRange) { return; } syncService.lockHandshake(user.getUserID(), chunkRange, GameSettings.HANDSHAKE_TIMEOUT); - HandshakeOutgoingEventType handshakeOutgoing = - EventTypeFactory.createHandshakeOutgoingEventType(chunkRange); + HandshakeOutgoingEventType handshakeOutgoing = EventTypeFactory.createHandshakeOutgoingEventType(chunkRange); this.send(handshakeOutgoing.toNetworkEvent()); Gdx.app.log(GameSettings.LOG_TAG, "CLIENT INIT HANDSHAKE " + chunkRange); } public Entity getEntity(Coordinates coordinates) throws SerializationDataMissing, ChunkNotFound { - NetworkEvent entityNetworkEvent = - this.blockStub.getEntity( - NetworkObjects.NetworkEvent.newBuilder() - .setUser(user.getUserID().toString()) - .setData(coordinates.toNetworkData()) - .build()); + NetworkEvent entityNetworkEvent = this.blockStub.getEntity( + NetworkObjects.NetworkEvent.newBuilder() + .setUser(user.getUserID().toString()) + .setData(coordinates.toNetworkData()) + .build()); Entity requestedEntity = networkDataDeserializer.createEntity(entityNetworkEvent.getData()); diff --git a/core/src/core/networking/translation/NetworkDataDeserializer.java b/core/src/core/networking/translation/NetworkDataDeserializer.java index 41a36a48..ff27a47f 100644 --- a/core/src/core/networking/translation/NetworkDataDeserializer.java +++ b/core/src/core/networking/translation/NetworkDataDeserializer.java @@ -3,7 +3,7 @@ import static core.networking.translation.DataTranslationEnum.COORDINATES; import com.google.inject.Inject; -import com.sun.tools.javac.util.Pair; +import core.common.Pair; import core.app.screen.assets.animations.AnimationState; import core.app.user.UserID; import core.chunk.Chunk; @@ -57,11 +57,16 @@ import networking.NetworkObjects.NetworkData; public class NetworkDataDeserializer { - @Inject EntityFactory entityFactory; - @Inject BlockFactory blockFactory; - @Inject ChunkFactory chunkFactory; - @Inject GameStore gameStore; - @Inject EntityControllerFactory entityControllerFactory; + @Inject + EntityFactory entityFactory; + @Inject + BlockFactory blockFactory; + @Inject + ChunkFactory chunkFactory; + @Inject + GameStore gameStore; + @Inject + EntityControllerFactory entityControllerFactory; public static ChunkRange createChunkRange(NetworkObjects.NetworkData networkData) { // TODO put in translations @@ -149,8 +154,10 @@ public static UpdateEntityIncomingEventType createUpdateEntityIncomingEvent( // it will be another attribute } } - if (chunkRange == null) throw new SerializationDataMissing("Missing chunkRange"); - if (uuid == null) throw new SerializationDataMissing("Missing uuid"); + if (chunkRange == null) + throw new SerializationDataMissing("Missing chunkRange"); + if (uuid == null) + throw new SerializationDataMissing("Missing uuid"); return EventTypeFactory.createUpdateEntityIncomingEvent(user, attributeList, chunkRange, uuid); } @@ -182,7 +189,8 @@ public static EmptyInventoryItem createEmptyItem(NetworkData networkData) index = Integer.valueOf(child.getValue()); } } - if (index == null) throw new SerializationDataMissing("Missing index"); + if (index == null) + throw new SerializationDataMissing("Missing index"); return new EmptyInventoryItem(index); } @@ -194,7 +202,8 @@ public static OrbInventoryItem createOrbItem(NetworkData networkData) index = Integer.valueOf(child.getValue()); } } - if (index == null) throw new SerializationDataMissing("Missing index"); + if (index == null) + throw new SerializationDataMissing("Missing index"); return new OrbInventoryItem(index); } @@ -206,7 +215,8 @@ public static SwordInventoryItem createSwordItem(NetworkData networkData) index = Integer.valueOf(child.getValue()); } } - if (index == null) throw new SerializationDataMissing("Missing index"); + if (index == null) + throw new SerializationDataMissing("Missing index"); return new SwordInventoryItem(index); } @@ -221,8 +231,10 @@ public static ItemActionEventType createItemActionEventType( controleeUUID = createUUID(child); } } - if (controleeUUID == null) throw new SerializationDataMissing("Missing controleeUUID"); - if (itemActionType == null) throw new SerializationDataMissing("Missing itemActionType"); + if (controleeUUID == null) + throw new SerializationDataMissing("Missing controleeUUID"); + if (itemActionType == null) + throw new SerializationDataMissing("Missing itemActionType"); return new ItemActionEventType(itemActionType, controleeUUID); } @@ -243,8 +255,10 @@ public static CreateEntityIncomingEventType createCreateEntityIncomingEventType( networkData = child; } } - if (chunkRange == null) throw new SerializationDataMissing("Missing chunkRange"); - if (networkData == null) throw new SerializationDataMissing("Missing networkData"); + if (chunkRange == null) + throw new SerializationDataMissing("Missing chunkRange"); + if (networkData == null) + throw new SerializationDataMissing("Missing networkData"); return EventTypeFactory.createCreateEntityIncomingEvent(userID, networkData, chunkRange); } @@ -267,8 +281,10 @@ public static RemoveEntityIncomingEventType createRemoveEntityIncomingEventType( break; } } - if (chunkRange == null) throw new SerializationDataMissing("Missing chunkRange"); - if (target == null) throw new SerializationDataMissing("Missing target"); + if (chunkRange == null) + throw new SerializationDataMissing("Missing chunkRange"); + if (target == null) + throw new SerializationDataMissing("Missing target"); return EventTypeFactory.createRemoveEntityIncomingEvent(user, chunkRange, target); } @@ -303,8 +319,10 @@ public static CreateAIEntityEventType createCreateAIEntityEventType( break; } } - if (target == null) throw new SerializationDataMissing("Missing target uuid"); - if (coordinates == null) throw new SerializationDataMissing("Missing coordinates"); + if (target == null) + throw new SerializationDataMissing("Missing target uuid"); + if (coordinates == null) + throw new SerializationDataMissing("Missing coordinates"); return EventTypeFactory.createAIEntityEventType(coordinates, target); } @@ -328,9 +346,12 @@ public static ChunkSwapIncomingEventType createChunkSwapIncomingEventType( break; } } - if (target == null) throw new SerializationDataMissing("Missing target uuid"); - if (from == null) throw new SerializationDataMissing("Missing from"); - if (to == null) throw new SerializationDataMissing("Missing to"); + if (target == null) + throw new SerializationDataMissing("Missing target uuid"); + if (from == null) + throw new SerializationDataMissing("Missing from"); + if (to == null) + throw new SerializationDataMissing("Missing to"); return EventTypeFactory.createChunkSwapIncomingEventType(target, from, to); } @@ -352,7 +373,8 @@ public static PingRequestIncomingEventType createPingRequestIncomingEventType( } } - if (pingID == null) throw new SerializationDataMissing("Missing pingID"); + if (pingID == null) + throw new SerializationDataMissing("Missing pingID"); return EventTypeFactory.createPingRequestIncomingEventType(user, pingID); } @@ -377,7 +399,8 @@ public static PingResponseIncomingEventType createPingResponseIncomingEventType( } } - if (pingID == null) throw new SerializationDataMissing("Missing pingID"); + if (pingID == null) + throw new SerializationDataMissing("Missing pingID"); return EventTypeFactory.createPingResponseIncomingEventType(user, pingID, time); } @@ -396,8 +419,10 @@ public static CreateTurretEventType createCreateTurretEventType( break; } } - if (coordinates == null) throw new SerializationDataMissing("Missing coordinates"); - if (uuid == null) throw new SerializationDataMissing("Missing uuid"); + if (coordinates == null) + throw new SerializationDataMissing("Missing coordinates"); + if (uuid == null) + throw new SerializationDataMissing("Missing uuid"); return EventTypeFactory.createTurretEventType(uuid, coordinates); } @@ -475,9 +500,12 @@ public Entity createEntity(NetworkObjects.NetworkData networkData) } } - if (uuid == null) throw new SerializationDataMissing("Missing UUID"); - if (coordinates == null) throw new SerializationDataMissing("Missing coordinates"); - if (health == null) throw new SerializationDataMissing("Missing health"); + if (uuid == null) + throw new SerializationDataMissing("Missing UUID"); + if (coordinates == null) + throw new SerializationDataMissing("Missing coordinates"); + if (health == null) + throw new SerializationDataMissing("Missing health"); entity.setUuid(uuid); entity.setCoordinatesWrapper(new CoordinatesWrapper(coordinates)); entity.health = health; @@ -515,9 +543,12 @@ public ReplaceBlockIncomingEventType createReplaceBlockIncomingEventType( break; } } - if (target == null) throw new SerializationDataMissing("Missing target uuid"); - if (chunkRange == null) throw new SerializationDataMissing("Missing chunkRange"); - if (replacementBlock == null) throw new SerializationDataMissing("Missing replacementBlock"); + if (target == null) + throw new SerializationDataMissing("Missing target uuid"); + if (chunkRange == null) + throw new SerializationDataMissing("Missing chunkRange"); + if (replacementBlock == null) + throw new SerializationDataMissing("Missing replacementBlock"); return EventTypeFactory.createReplaceBlockIncomingEvent( user, target, (Block) replacementBlock, chunkRange);