diff --git a/assets/Scenes/defaultLevel_2/scene.json b/assets/Scenes/defaultLevel_2/scene.json index 6edac4b8..8d501345 100644 --- a/assets/Scenes/defaultLevel_2/scene.json +++ b/assets/Scenes/defaultLevel_2/scene.json @@ -6,5 +6,6 @@ "type" : "gridded", "griddedRealmSize" : 2 }, - "createSaveInstance" : true + "createSaveInstance" : true, + "loadAllCells": true } \ No newline at end of file diff --git a/docs/src/progress/currenttarget.md b/docs/src/progress/currenttarget.md index 25a47f35..8283a5c4 100644 --- a/docs/src/progress/currenttarget.md +++ b/docs/src/progress/currenttarget.md @@ -7,7 +7,10 @@ review effects review combat code (lifestate, damage calculation, etc) audio fx for everything - fix rendering pipelines (black when looking at character from angle with item, shadows are not darker color, etc) - option to load all data cells in scene on initializing a scene (thereby loading spawn points into memory) + bug fixes + fix bug where synchronization packet for non-existant entity crashes engine + fix rendering pipelines (black when looking at character from angle with item, shadows are not darker color, etc) + fix items falling through floor + fix jump tree not applying force while movement tree is active + diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index f7973102..0a5119cc 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -475,6 +475,12 @@ Unify animation format data on disk Leverage animation masks to block while moving Remove Airplane movement system Fix client-attached models to viewmodel drawing on previous frame +Alignment work for human right hand + +(07/29/2024) +Option to load all cells on init scene file +Insidious Entity protocol bugfix on server + # TODO diff --git a/src/main/java/electrosphere/client/scene/ClientSceneWrapper.java b/src/main/java/electrosphere/client/scene/ClientSceneWrapper.java index dbaada87..6a6a7856 100644 --- a/src/main/java/electrosphere/client/scene/ClientSceneWrapper.java +++ b/src/main/java/electrosphere/client/scene/ClientSceneWrapper.java @@ -52,7 +52,7 @@ public class ClientSceneWrapper { * @param serverId The server's provided ID */ public void mapIdToId(int clientId, int serverId){ - LoggerInterface.loggerEngine.DEBUG("MapID: " + clientId + " <===> " + serverId); + LoggerInterface.loggerNetworking.DEBUG("MapID: " + clientId + " <===> " + serverId); clientToServerIdMap.put(clientId, serverId); serverToClientIdMap.put(serverId, clientId); } diff --git a/src/main/java/electrosphere/controls/ControlHandler.java b/src/main/java/electrosphere/controls/ControlHandler.java index 4e33e6b9..e236e312 100644 --- a/src/main/java/electrosphere/controls/ControlHandler.java +++ b/src/main/java/electrosphere/controls/ControlHandler.java @@ -87,11 +87,11 @@ import electrosphere.entity.state.attack.ShooterTree; import electrosphere.entity.state.equip.ClientEquipState; import electrosphere.entity.state.inventory.InventoryUtils; import electrosphere.entity.state.inventory.UnrelationalInventoryState; -import electrosphere.entity.state.movement.JumpTree; import electrosphere.entity.state.movement.SprintTree; import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree; import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree.MovementRelativeFacing; import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree.MovementTreeState; +import electrosphere.entity.state.movement.jump.JumpTree; import electrosphere.entity.types.camera.CameraEntityUtils; import electrosphere.entity.types.creature.CreatureUtils; import electrosphere.logger.LoggerInterface; diff --git a/src/main/java/electrosphere/entity/scene/SceneFile.java b/src/main/java/electrosphere/entity/scene/SceneFile.java index 55f3c800..0df5b530 100644 --- a/src/main/java/electrosphere/entity/scene/SceneFile.java +++ b/src/main/java/electrosphere/entity/scene/SceneFile.java @@ -33,6 +33,11 @@ public class SceneFile { */ boolean createSaveInstance; + /** + * Loads all cells on initialization + */ + boolean loadAllCells; + /** * Private constructor @@ -52,6 +57,7 @@ public class SceneFile { rVal.initScriptPath = null; rVal.realmDescriptor = new RealmDescriptor(); rVal.createSaveInstance = false; + rVal.loadAllCells = false; return rVal; } @@ -103,4 +109,12 @@ public class SceneFile { this.createSaveInstance = createSaveInstance; } + /** + * Gets whether the scene should load all cells on initialization or not + * @return true if should load all cells on init, false otherwise + */ + public boolean loadAllCells(){ + return loadAllCells; + } + } diff --git a/src/main/java/electrosphere/entity/scene/SceneGenerator.java b/src/main/java/electrosphere/entity/scene/SceneGenerator.java index e83e1f51..e36066a6 100644 --- a/src/main/java/electrosphere/entity/scene/SceneGenerator.java +++ b/src/main/java/electrosphere/entity/scene/SceneGenerator.java @@ -25,6 +25,7 @@ public class SceneGenerator { file.realmDescriptor.type = RealmDescriptor.REALM_DESCRIPTOR_PROCEDURAL; file.realmDescriptor.griddedRealmSize = GriddedDataCellManager.MAX_GRID_SIZE; file.createSaveInstance = true; //won't have a predefined scene to load, so must create one in the save + file.loadAllCells = false; // do not load all cells on init //create terrain ServerWorldData serverWorldData = ServerWorldData.createGriddedRealmWorldData(2000); diff --git a/src/main/java/electrosphere/entity/scene/SceneLoader.java b/src/main/java/electrosphere/entity/scene/SceneLoader.java index f562a22a..f2e19417 100644 --- a/src/main/java/electrosphere/entity/scene/SceneLoader.java +++ b/src/main/java/electrosphere/entity/scene/SceneLoader.java @@ -10,6 +10,7 @@ import electrosphere.entity.types.item.ItemUtils; import electrosphere.entity.types.object.ObjectUtils; import electrosphere.game.server.world.ServerWorldData; import electrosphere.server.content.ServerContentManager; +import electrosphere.server.datacell.GriddedDataCellManager; import electrosphere.server.datacell.Realm; import electrosphere.server.datacell.ServerDataCell; import electrosphere.util.FileUtils; @@ -66,6 +67,9 @@ public class SceneLoader { switch(file.realmDescriptor.getType()){ case RealmDescriptor.REALM_DESCRIPTOR_GRIDDED: { realm = Globals.realmManager.createGriddedRealm(serverWorldData,serverContentManager); + if(file.loadAllCells()){ + ((GriddedDataCellManager)realm.getDataCellManager()).loadAllCells(); + } } break; case RealmDescriptor.REALM_DESCRIPTOR_PROCEDURAL: { realm = Globals.realmManager.createRealm(); diff --git a/src/main/java/electrosphere/entity/state/gravity/ClientGravityTree.java b/src/main/java/electrosphere/entity/state/gravity/ClientGravityTree.java index 5268b7e8..e20afa98 100644 --- a/src/main/java/electrosphere/entity/state/gravity/ClientGravityTree.java +++ b/src/main/java/electrosphere/entity/state/gravity/ClientGravityTree.java @@ -20,7 +20,7 @@ import electrosphere.entity.btree.BehaviorTree; import electrosphere.entity.state.collidable.ClientCollidableTree; import electrosphere.entity.state.collidable.Impulse; import electrosphere.entity.state.movement.FallTree; -import electrosphere.entity.state.movement.JumpTree; +import electrosphere.entity.state.movement.jump.JumpTree; import electrosphere.net.parser.net.message.EntityMessage; import electrosphere.net.synchronization.annotation.SyncedField; import electrosphere.net.synchronization.annotation.SynchronizableEnum; diff --git a/src/main/java/electrosphere/entity/state/gravity/ServerGravityTree.java b/src/main/java/electrosphere/entity/state/gravity/ServerGravityTree.java index 8df55eb9..20afb87a 100644 --- a/src/main/java/electrosphere/entity/state/gravity/ServerGravityTree.java +++ b/src/main/java/electrosphere/entity/state/gravity/ServerGravityTree.java @@ -26,7 +26,7 @@ import electrosphere.entity.state.collidable.Impulse; import electrosphere.entity.state.collidable.ServerCollidableTree; import electrosphere.entity.state.gravity.ClientGravityTree.GravityTreeState; import electrosphere.entity.state.movement.ServerFallTree; -import electrosphere.entity.state.movement.ServerJumpTree; +import electrosphere.entity.state.movement.jump.ServerJumpTree; import electrosphere.net.parser.net.message.EntityMessage; import electrosphere.net.synchronization.annotation.SyncedField; import electrosphere.net.synchronization.annotation.SynchronizedBehaviorTree; diff --git a/src/main/java/electrosphere/entity/state/movement/FallTree.java b/src/main/java/electrosphere/entity/state/movement/FallTree.java index 8a8bbc2f..4e6c0b2c 100644 --- a/src/main/java/electrosphere/entity/state/movement/FallTree.java +++ b/src/main/java/electrosphere/entity/state/movement/FallTree.java @@ -9,6 +9,7 @@ import electrosphere.entity.btree.StateTransitionUtil; import electrosphere.entity.btree.StateTransitionUtil.StateTransitionUtilItem; import electrosphere.entity.state.AnimationPriorities; import electrosphere.entity.state.client.firstPerson.FirstPersonTree; +import electrosphere.entity.state.movement.jump.JumpTree; import electrosphere.game.data.creature.type.movement.FallMovementSystem; import electrosphere.renderer.actor.Actor; diff --git a/src/main/java/electrosphere/entity/state/movement/ServerFallTree.java b/src/main/java/electrosphere/entity/state/movement/ServerFallTree.java index c0aac64f..150ea960 100644 --- a/src/main/java/electrosphere/entity/state/movement/ServerFallTree.java +++ b/src/main/java/electrosphere/entity/state/movement/ServerFallTree.java @@ -5,6 +5,7 @@ import electrosphere.entity.EntityDataStrings; import electrosphere.entity.EntityUtils; import electrosphere.entity.btree.BehaviorTree; import electrosphere.entity.state.AnimationPriorities; +import electrosphere.entity.state.movement.jump.ServerJumpTree; import electrosphere.game.data.creature.type.movement.FallMovementSystem; import electrosphere.server.poseactor.PoseActor; diff --git a/src/main/java/electrosphere/entity/state/movement/groundmove/ClientGroundMovementTree.java b/src/main/java/electrosphere/entity/state/movement/groundmove/ClientGroundMovementTree.java index 8abd2068..6277d423 100644 --- a/src/main/java/electrosphere/entity/state/movement/groundmove/ClientGroundMovementTree.java +++ b/src/main/java/electrosphere/entity/state/movement/groundmove/ClientGroundMovementTree.java @@ -19,9 +19,9 @@ import electrosphere.entity.state.attack.ClientAttackTree; import electrosphere.entity.state.attack.ClientAttackTree.AttackTreeState; import electrosphere.entity.state.client.firstPerson.FirstPersonTree; import electrosphere.entity.state.movement.FallTree; -import electrosphere.entity.state.movement.JumpTree; import electrosphere.entity.state.movement.SprintTree; import electrosphere.entity.state.movement.SprintTree.SprintTreeState; +import electrosphere.entity.state.movement.jump.JumpTree; import electrosphere.net.parser.net.message.EntityMessage; import electrosphere.net.synchronization.annotation.SyncedField; import electrosphere.net.synchronization.annotation.SynchronizableEnum; diff --git a/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java b/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java index 63f545a9..dddee337 100644 --- a/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java +++ b/src/main/java/electrosphere/entity/state/movement/groundmove/ServerGroundMovementTree.java @@ -20,11 +20,11 @@ import electrosphere.entity.state.AnimationPriorities; import electrosphere.entity.state.attack.ClientAttackTree.AttackTreeState; import electrosphere.entity.state.attack.ServerAttackTree; import electrosphere.entity.state.movement.ServerFallTree; -import electrosphere.entity.state.movement.ServerJumpTree; import electrosphere.entity.state.movement.ServerSprintTree; import electrosphere.entity.state.movement.ServerSprintTree.SprintTreeState; import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree.MovementRelativeFacing; import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree.MovementTreeState; +import electrosphere.entity.state.movement.jump.ServerJumpTree; import electrosphere.net.parser.net.message.EntityMessage; import electrosphere.net.synchronization.annotation.SyncedField; import electrosphere.net.synchronization.annotation.SynchronizedBehaviorTree; diff --git a/src/main/java/electrosphere/entity/state/movement/JumpTree.java b/src/main/java/electrosphere/entity/state/movement/jump/JumpTree.java similarity index 98% rename from src/main/java/electrosphere/entity/state/movement/JumpTree.java rename to src/main/java/electrosphere/entity/state/movement/jump/JumpTree.java index f01dc659..e6d545eb 100644 --- a/src/main/java/electrosphere/entity/state/movement/JumpTree.java +++ b/src/main/java/electrosphere/entity/state/movement/jump/JumpTree.java @@ -1,4 +1,4 @@ -package electrosphere.entity.state.movement; +package electrosphere.entity.state.movement.jump; import org.ode4j.math.DVector3C; import org.ode4j.ode.DBody; diff --git a/src/main/java/electrosphere/entity/state/movement/ServerJumpTree.java b/src/main/java/electrosphere/entity/state/movement/jump/ServerJumpTree.java similarity index 98% rename from src/main/java/electrosphere/entity/state/movement/ServerJumpTree.java rename to src/main/java/electrosphere/entity/state/movement/jump/ServerJumpTree.java index c11734b8..bbf643d9 100644 --- a/src/main/java/electrosphere/entity/state/movement/ServerJumpTree.java +++ b/src/main/java/electrosphere/entity/state/movement/jump/ServerJumpTree.java @@ -1,4 +1,4 @@ -package electrosphere.entity.state.movement; +package electrosphere.entity.state.movement.jump; import org.ode4j.math.DVector3C; import org.ode4j.ode.DBody; diff --git a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java index df240522..c79c1402 100644 --- a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java +++ b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java @@ -34,13 +34,13 @@ import electrosphere.entity.state.inventory.UnrelationalInventoryState; import electrosphere.entity.state.life.ClientLifeTree; import electrosphere.entity.state.life.ServerLifeTree; import electrosphere.entity.state.movement.FallTree; -import electrosphere.entity.state.movement.JumpTree; import electrosphere.entity.state.movement.ServerFallTree; -import electrosphere.entity.state.movement.ServerJumpTree; import electrosphere.entity.state.movement.ServerSprintTree; import electrosphere.entity.state.movement.SprintTree; import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree; import electrosphere.entity.state.movement.groundmove.ServerGroundMovementTree; +import electrosphere.entity.state.movement.jump.JumpTree; +import electrosphere.entity.state.movement.jump.ServerJumpTree; import electrosphere.entity.state.rotator.RotatorHierarchyNode; import electrosphere.entity.state.rotator.RotatorTree; import electrosphere.entity.state.rotator.ServerRotatorTree; diff --git a/src/main/java/electrosphere/menu/mainmenu/MenuGeneratorsLevelEditor.java b/src/main/java/electrosphere/menu/mainmenu/MenuGeneratorsLevelEditor.java index efcc1a45..aa58f255 100644 --- a/src/main/java/electrosphere/menu/mainmenu/MenuGeneratorsLevelEditor.java +++ b/src/main/java/electrosphere/menu/mainmenu/MenuGeneratorsLevelEditor.java @@ -193,7 +193,6 @@ public class MenuGeneratorsLevelEditor { griddedRealmControls.addChild(InputMacros.createToggle("Create Scene File", false, (ValueChangeEvent event) -> { sceneFile.setCreateSaveInstance(event.getAsBoolean()); - System.out.println(sceneFile.getCreateSaveInstance()); })); } rVal.addChild(griddedRealmControls); diff --git a/src/main/java/electrosphere/net/client/ClientNetworking.java b/src/main/java/electrosphere/net/client/ClientNetworking.java index b72d7a74..cc354638 100644 --- a/src/main/java/electrosphere/net/client/ClientNetworking.java +++ b/src/main/java/electrosphere/net/client/ClientNetworking.java @@ -190,13 +190,13 @@ public class ClientNetworking implements Runnable{ (((ServerMessage)message).getMessageSubtype()) == ServerMessageType.PONG ){ if(this.echoPings == true){ - LoggerInterface.loggerNetworking.DEBUG("[CLIENT] New message " + message.getType()); + LoggerInterface.loggerNetworking.DEBUG_LOOP("[CLIENT] New message " + message.getType()); } } else { - LoggerInterface.loggerNetworking.DEBUG("[CLIENT] New message " + message.getType()); + LoggerInterface.loggerNetworking.DEBUG_LOOP("[CLIENT] New message " + message.getType()); } } else { - LoggerInterface.loggerNetworking.DEBUG("[CLIENT] New message " + message.getType()); + LoggerInterface.loggerNetworking.DEBUG_LOOP("[CLIENT] New message " + message.getType()); } } diff --git a/src/main/java/electrosphere/net/client/protocol/EntityProtocol.java b/src/main/java/electrosphere/net/client/protocol/EntityProtocol.java index f244d73a..32fd51a5 100644 --- a/src/main/java/electrosphere/net/client/protocol/EntityProtocol.java +++ b/src/main/java/electrosphere/net/client/protocol/EntityProtocol.java @@ -1,15 +1,16 @@ package electrosphere.net.client.protocol; +import java.util.Arrays; +import java.util.List; + import org.joml.Quaterniond; import org.joml.Vector3d; import electrosphere.engine.Globals; import electrosphere.entity.ClientEntityUtils; import electrosphere.entity.Entity; -import electrosphere.entity.EntityCreationUtils; import electrosphere.entity.EntityUtils; import electrosphere.entity.state.attack.ClientAttackTree; -import electrosphere.entity.state.client.firstPerson.FirstPersonTree; import electrosphere.entity.types.attach.AttachUtils; import electrosphere.entity.types.creature.CreatureTemplate; import electrosphere.entity.types.creature.CreatureUtils; @@ -20,12 +21,22 @@ import electrosphere.game.data.creature.type.CreatureData; import electrosphere.game.data.creature.type.ViewModelData; import electrosphere.logger.LoggerInterface; import electrosphere.net.parser.net.message.EntityMessage; +import electrosphere.net.parser.net.message.EntityMessage.EntityMessageType; import electrosphere.util.Utilities; /** * Client entity network protocol */ public class EntityProtocol { + + //Messages to ignore when complaining about messages that have nonexistant entity associated + static List spawnMessageTypes = Arrays.asList(new EntityMessageType[]{ + EntityMessageType.CREATE, + EntityMessageType.SPAWNCREATURE, + EntityMessageType.SPAWNFOLIAGESEED, + EntityMessageType.SPAWNITEM, + EntityMessageType.SPAWNOBJECT, + }); /** * Handles a single clientbound entity message @@ -33,7 +44,15 @@ public class EntityProtocol { */ protected static void handleEntityMessage(EntityMessage message){ Globals.profiler.beginCpuSample("EntityProtocol.handleEntityMessage"); - LoggerInterface.loggerNetworking.DEBUG("Parse entity message of type " + message.getMessageSubtype()); + LoggerInterface.loggerNetworking.DEBUG_LOOP("Parse entity message of type " + message.getMessageSubtype()); + + //error check + if(Globals.clientScene != null && Globals.clientSceneWrapper.getEntityFromServerId(message.getentityID()) == null && !spawnMessageTypes.contains(message.getMessageSubtype())){ + LoggerInterface.loggerNetworking.WARNING("Client received packet for entity that is not in the client scene!"); + Globals.clientSceneWrapper.dumpTranslationLayerStatus(); + Globals.clientSceneWrapper.dumpIdData(message.getentityID()); + } + Entity newlySpawnedEntity; switch(message.getMessageSubtype()){ @@ -110,6 +129,7 @@ public class EntityProtocol { } } else { //TODO: bounce message + LoggerInterface.loggerNetworking.WARNING("Received property packet for entity that does not exist on client!"); } } break; case ATTACHENTITYTOENTITY: { @@ -167,11 +187,13 @@ public class EntityProtocol { static void setPlayerEntity(EntityMessage message){ Entity target = Globals.clientSceneWrapper.getEntityFromServerId(message.getentityID()); if(target != null){ + LoggerInterface.loggerNetworking.DEBUG("Set player entity id for entity: " + target.getId() + " to player: " + message.getpropertyValue()); CreatureUtils.setControllerPlayerId(target, message.getpropertyValue()); String creatureTypeRaw = CreatureUtils.getType(target); CreatureData creatureType = Globals.gameConfigCurrent.getCreatureTypeLoader().getCreature(creatureTypeRaw); ViewModelData viewModelData = creatureType.getViewModelData(); if(Globals.clientPlayer != null && message.getpropertyValue() == Globals.clientPlayer.getId()){ + LoggerInterface.loggerNetworking.DEBUG("Set this player's entity id!"); Globals.clientCharacterID = message.getentityID(); Globals.playerEntity = target; if(viewModelData != null && viewModelData.getFirstPersonModelPath() != null){ @@ -180,7 +202,12 @@ public class EntityProtocol { null ); } + } else { + //setting player id on entity that is not this player's } + } else { + LoggerInterface.loggerNetworking.WARNING("Tried to set player entity property on an entity that doesn't exist!"); + Globals.clientSceneWrapper.dumpTranslationLayerStatus(); } } diff --git a/src/main/java/electrosphere/net/server/ServerConnectionHandler.java b/src/main/java/electrosphere/net/server/ServerConnectionHandler.java index 1c10eca9..8e0bce40 100644 --- a/src/main/java/electrosphere/net/server/ServerConnectionHandler.java +++ b/src/main/java/electrosphere/net/server/ServerConnectionHandler.java @@ -274,6 +274,7 @@ public class ServerConnectionHandler implements Runnable { } public void setPlayerEntityId(int id){ + LoggerInterface.loggerNetworking.DEBUG("Set player(" + this.playerID + ")'s entity ID to be " + id); playerEntityID = id; } diff --git a/src/main/java/electrosphere/net/server/protocol/EntityProtocol.java b/src/main/java/electrosphere/net/server/protocol/EntityProtocol.java index bd91a43c..f523d9c7 100644 --- a/src/main/java/electrosphere/net/server/protocol/EntityProtocol.java +++ b/src/main/java/electrosphere/net/server/protocol/EntityProtocol.java @@ -2,10 +2,12 @@ package electrosphere.net.server.protocol; import org.joml.Vector3d; +import electrosphere.engine.Globals; import electrosphere.entity.Entity; import electrosphere.entity.state.attack.ServerAttackTree; import electrosphere.entity.state.server.ServerPlayerViewDirTree; import electrosphere.entity.types.creature.CreatureUtils; +import electrosphere.logger.LoggerInterface; import electrosphere.net.parser.net.message.EntityMessage; import electrosphere.net.server.ServerConnectionHandler; import electrosphere.server.datacell.utils.EntityLookupUtils; @@ -13,28 +15,34 @@ import electrosphere.server.datacell.utils.EntityLookupUtils; public class EntityProtocol { protected static void handleEntityMessage(ServerConnectionHandler connectionHandler, EntityMessage message){ + //error check + if(Globals.clientScene != null && Globals.clientScene.getEntityFromId(message.getentityID()) != null){ + LoggerInterface.loggerNetworking.WARNING("Server received packet for entity that is in client scene wrapper!"); + } + + //parse message Entity targetEntity; switch(message.getMessageSubtype()){ case MOVEUPDATE: - targetEntity = EntityLookupUtils.getEntityById(message.getentityID()); + targetEntity = EntityLookupUtils.getEntityById(connectionHandler.getPlayerEntityId()); if(targetEntity != null){ CreatureUtils.serverAttachEntityMessageToMovementTree(targetEntity,message); } break; case ATTACKUPDATE: - targetEntity = EntityLookupUtils.getEntityById(message.getentityID()); + targetEntity = EntityLookupUtils.getEntityById(connectionHandler.getPlayerEntityId()); if(targetEntity != null){ ServerAttackTree.getServerAttackTree(targetEntity).addNetworkMessage(message); } break; case STARTATTACK: { - targetEntity = EntityLookupUtils.getEntityById(message.getentityID()); + targetEntity = EntityLookupUtils.getEntityById(connectionHandler.getPlayerEntityId()); if(targetEntity != null){ ServerAttackTree.getServerAttackTree(targetEntity).addNetworkMessage(message); } } break; case UPDATEENTITYVIEWDIR: { - targetEntity = EntityLookupUtils.getEntityById(message.getentityID()); + targetEntity = EntityLookupUtils.getEntityById(connectionHandler.getPlayerEntityId()); if(targetEntity != null && ServerPlayerViewDirTree.hasTree(targetEntity)){ ServerPlayerViewDirTree.getTree(targetEntity).setPlayerViewDir(new Vector3d(message.getpositionX(),message.getpositionY(),message.getpositionZ()),message.gettime()); } diff --git a/src/main/java/electrosphere/net/server/protocol/ServerProtocol.java b/src/main/java/electrosphere/net/server/protocol/ServerProtocol.java index 6d611cea..c0838355 100644 --- a/src/main/java/electrosphere/net/server/protocol/ServerProtocol.java +++ b/src/main/java/electrosphere/net/server/protocol/ServerProtocol.java @@ -152,13 +152,13 @@ public class ServerProtocol { (((ServerMessage)message).getMessageSubtype()) == ServerMessageType.PONG ){ if(this.echoPings == true){ - LoggerInterface.loggerNetworking.DEBUG("[Server] New message " + message.getType()); + LoggerInterface.loggerNetworking.DEBUG_LOOP("[Server] New message " + message.getType()); } } else { - LoggerInterface.loggerNetworking.DEBUG("[Server] New message " + message.getType()); + LoggerInterface.loggerNetworking.DEBUG_LOOP("[Server] New message " + message.getType()); } } else { - LoggerInterface.loggerNetworking.DEBUG("[Server] New message " + message.getType()); + LoggerInterface.loggerNetworking.DEBUG_LOOP("[Server] New message " + message.getType()); } } diff --git a/src/main/java/electrosphere/net/synchronization/ClientSynchronizationManager.java b/src/main/java/electrosphere/net/synchronization/ClientSynchronizationManager.java index 9c1ed466..88da7571 100644 --- a/src/main/java/electrosphere/net/synchronization/ClientSynchronizationManager.java +++ b/src/main/java/electrosphere/net/synchronization/ClientSynchronizationManager.java @@ -2,11 +2,9 @@ package electrosphere.net.synchronization; import electrosphere.entity.state.life.ClientLifeTree; -import electrosphere.net.synchronization.FieldIdEnums; import electrosphere.entity.state.block.ClientBlockTree; import electrosphere.entity.state.movement.groundmove.ClientGroundMovementTree; import electrosphere.logger.LoggerInterface; -import electrosphere.entity.state.equip.ClientEquipState; import electrosphere.entity.state.attack.ClientAttackTree; import electrosphere.entity.state.gravity.ClientGravityTree; import electrosphere.entity.state.idle.ClientIdleTree; @@ -83,6 +81,8 @@ public class ClientSynchronizationManager { int bTreeId = message.getbTreeId(); int entityId = message.getentityId(); } break; + case LOADSCENE: { + } break; } } else if(Globals.clientSceneWrapper.containsServerId(message.getentityId()) && Globals.clientSceneWrapper.getEntityFromServerId(message.getentityId()) == null){ String errorMessage = @@ -93,6 +93,14 @@ public class ClientSynchronizationManager { Globals.clientSceneWrapper.dumpTranslationLayerStatus(); Globals.clientSceneWrapper.dumpIdData(message.getentityId()); throw new IllegalStateException(errorMessage); + } else if(!Globals.clientSceneWrapper.containsServerId(message.getentityId())){ + String errorMessage = + "Client received synchronization packet for entity that does not exists on client!\n" + + "Entity id in network message: " + message.getentityId() + ; + Globals.clientSceneWrapper.dumpTranslationLayerStatus(); + Globals.clientSceneWrapper.dumpIdData(message.getentityId()); + throw new IllegalStateException(errorMessage); } //warn if a message has bounced a certain number of times diff --git a/src/main/java/electrosphere/server/character/PlayerCharacterCreation.java b/src/main/java/electrosphere/server/character/PlayerCharacterCreation.java index 1021522a..217e0504 100644 --- a/src/main/java/electrosphere/server/character/PlayerCharacterCreation.java +++ b/src/main/java/electrosphere/server/character/PlayerCharacterCreation.java @@ -8,6 +8,7 @@ import electrosphere.entity.Entity; import electrosphere.entity.state.server.ServerPlayerViewDirTree; import electrosphere.entity.types.creature.CreatureTemplate; import electrosphere.entity.types.creature.CreatureUtils; +import electrosphere.logger.LoggerInterface; import electrosphere.net.server.ServerConnectionHandler; import electrosphere.net.server.player.Player; import electrosphere.server.datacell.Realm; @@ -30,6 +31,7 @@ public class PlayerCharacterCreation { Realm realm = Globals.realmManager.getRealms().iterator().next(); Vector3d spawnPoint = realm.getSpawnPoint(); Entity newPlayerEntity = CreatureUtils.serverSpawnBasicCreature(realm,new Vector3d(spawnPoint.x,spawnPoint.y,spawnPoint.z),raceName,template); + LoggerInterface.loggerEngine.INFO("Spawned entity for player. Entity id: " + newPlayerEntity.getId() + " Player id: " + playerObject.getId()); int playerCharacterId = newPlayerEntity.getId(); connectionHandler.setPlayerEntityId(playerCharacterId); CreatureUtils.setControllerPlayerId(newPlayerEntity, connectionHandler.getPlayerId()); diff --git a/src/main/java/electrosphere/server/datacell/GriddedDataCellManager.java b/src/main/java/electrosphere/server/datacell/GriddedDataCellManager.java index 295bc1e0..1e645481 100644 --- a/src/main/java/electrosphere/server/datacell/GriddedDataCellManager.java +++ b/src/main/java/electrosphere/server/datacell/GriddedDataCellManager.java @@ -42,6 +42,11 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager */ public static final int MAX_GRID_SIZE = 10; + /** + * Tracks whether this manager has been flagged to unload cells or not + */ + boolean unloadCells = true; + //these are going to be the natural ground grid of data cells, but we're going to have more than this Map groundDataCells = new HashMap(); Map cellPositionMap = new HashMap(); @@ -257,38 +262,40 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager * Unloads all chunks that haven't had players in them for a set amount of time */ public void unloadPlayerlessChunks(){ - //TODO: improve to make have less performance impact - for(ServerDataCell cell : loadedCells){ - loadedCellsLock.acquireUninterruptibly(); - if(cell.getPlayers().size() < 1){ - int frameCount = cellPlayerlessFrameMap.get(cell) + 1; - cellPlayerlessFrameMap.put(cell,frameCount); - if(frameCount > UNLOAD_FRAME_THRESHOLD){ - toCleanQueue.add(cell); + if(this.unloadCells){ + //TODO: improve to make have less performance impact + for(ServerDataCell cell : loadedCells){ + loadedCellsLock.acquireUninterruptibly(); + if(cell.getPlayers().size() < 1){ + int frameCount = cellPlayerlessFrameMap.get(cell) + 1; + cellPlayerlessFrameMap.put(cell,frameCount); + if(frameCount > UNLOAD_FRAME_THRESHOLD){ + toCleanQueue.add(cell); + } + } else { + if(cellPlayerlessFrameMap.get(cell) > 0){ + cellPlayerlessFrameMap.put(cell, 0); + } } - } else { - if(cellPlayerlessFrameMap.get(cell) > 0){ - cellPlayerlessFrameMap.put(cell, 0); + loadedCellsLock.release(); + } + for(ServerDataCell cell : toCleanQueue){ + parent.deregisterCell(cell); + loadedCells.remove(cell); + Vector3i worldPos = getCellWorldPosition(cell); + String key = getServerDataCellKey(worldPos); + groundDataCells.remove(key); + //offload all entities in cell to chunk file + serverContentManager.saveContentToDisk(key, cell.getScene().getEntityList()); + //clear all entities in cell + for(Entity entity : cell.getScene().getEntityList()){ + EntityUtils.cleanUpEntity(entity); } + //save terrain to disk + serverTerrainManager.savePositionToDisk(worldPos); } - loadedCellsLock.release(); + toCleanQueue.clear(); } - for(ServerDataCell cell : toCleanQueue){ - parent.deregisterCell(cell); - loadedCells.remove(cell); - Vector3i worldPos = getCellWorldPosition(cell); - String key = getServerDataCellKey(worldPos); - groundDataCells.remove(key); - //offload all entities in cell to chunk file - serverContentManager.saveContentToDisk(key, cell.getScene().getEntityList()); - //clear all entities in cell - for(Entity entity : cell.getScene().getEntityList()){ - EntityUtils.cleanUpEntity(entity); - } - //save terrain to disk - serverTerrainManager.savePositionToDisk(worldPos); - } - toCleanQueue.clear(); } /** @@ -328,11 +335,20 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager int worldY = parent.getServerWorldData().convertRealToChunkSpace(point.y); int worldZ = parent.getServerWorldData().convertRealToChunkSpace(point.z); Vector3i worldPos = new Vector3i(worldX,worldY,worldZ); + return tryCreateCellAtPoint(worldPos); + } + + /** + * Tries to create a data cell at a given discrete point + * @param point The discrete point + * @return The data cell if created, null otherwise + */ + public ServerDataCell tryCreateCellAtPoint(Vector3i worldPos){ if( //in bounds of array - worldX >= 0 && worldX < this.serverWorldData.getWorldSizeDiscrete() && - worldY >= 0 && worldY < this.serverWorldData.getWorldSizeDiscrete() && - worldZ >= 0 && worldZ < this.serverWorldData.getWorldSizeDiscrete() && + worldPos.x >= 0 && worldPos.x < this.serverWorldData.getWorldSizeDiscrete() && + worldPos.y >= 0 && worldPos.y < this.serverWorldData.getWorldSizeDiscrete() && + worldPos.z >= 0 && worldPos.z < this.serverWorldData.getWorldSizeDiscrete() && //isn't null groundDataCells.get(getServerDataCellKey(worldPos)) == null ){ @@ -375,7 +391,9 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager public void simulate(){ loadedCellsLock.acquireUninterruptibly(); for(ServerDataCell cell : loadedCells){ - Globals.microSimulation.simulate(cell); + if(Globals.microSimulation != null && Globals.microSimulation.isReady()){ + Globals.microSimulation.simulate(cell); + } //simulate fluid Vector3i cellPos = this.getCellWorldPosition(cell); @@ -521,6 +539,20 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager return serverFluidManager.getChunk(worldPosition.x, worldPosition.y, worldPosition.z); } + /** + * Loads all cells + */ + public void loadAllCells(){ + this.unloadCells = false; + for(int x = 0; x < this.serverWorldData.getWorldSizeDiscrete(); x++){ + for(int y = 0; y < this.serverWorldData.getWorldSizeDiscrete(); y++){ + for(int z = 0; z < this.serverWorldData.getWorldSizeDiscrete(); z++){ + this.tryCreateCellAtPoint(new Vector3i(x,y,z)); + } + } + } + } + /** * Rebroadcasts the fluid cell at a given position * @param worldPosition the world position