From 4d9047d8cf5cfe13fcc58889f484344ae18517de Mon Sep 17 00:00:00 2001 From: austin Date: Tue, 19 Nov 2024 11:45:35 -0500 Subject: [PATCH] bugfixes --- docs/src/progress/renderertodo.md | 7 +++++++ .../client/terrain/cells/DrawCell.java | 9 +++++++-- .../collision/CollisionEngine.java | 7 ++++--- .../collision/PhysicsEntityUtils.java | 17 +++++++++++------ .../entity/types/terrain/TerrainChunk.java | 2 +- .../java/electrosphere/net/server/Server.java | 6 ++++++ .../server/datacell/GriddedDataCellManager.java | 14 ++++---------- .../datacell/physics/PhysicsDataCell.java | 2 +- .../TestGenerationChunkGenerator.java | 8 +++++++- 9 files changed, 48 insertions(+), 24 deletions(-) diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index df8fe157..13597fd8 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1075,6 +1075,13 @@ Voxel and Heightmap generators based on noise functions in files Set all client terrain rigid bodies are kinematic Add caves Tweaking test2 noise definition +Add sleep to server socket thread + +(11/19/2024) +Fix draw cells not deleting once all children have reported generation +Fix server data cells unloading before ready state +Fix terrain chunk generation trying to generate rigid body for no-vertex cell +Fix server homogenous chunk check on generation with variadic weights diff --git a/src/main/java/electrosphere/client/terrain/cells/DrawCell.java b/src/main/java/electrosphere/client/terrain/cells/DrawCell.java index c22f3183..59bd988e 100644 --- a/src/main/java/electrosphere/client/terrain/cells/DrawCell.java +++ b/src/main/java/electrosphere/client/terrain/cells/DrawCell.java @@ -26,7 +26,12 @@ public class DrawCell { /** * Number of frames to wait before destroying the chunk entity */ - public static final int FRAMES_TO_WAIT_BEFORE_DESTRUCTION = 15; + public static final int FRAMES_TO_WAIT_BEFORE_DESTRUCTION = 25; + + /** + * Number of child cells per parent cell + */ + static final int CHILD_CELLS_PER_PARENT = 8; /** * Enum for the different faces of a draw cell -- used when filling in data for higher LOD faces @@ -215,7 +220,7 @@ public class DrawCell { */ public void alertToGeneration(){ this.generationAlertCount++; - if(this.generationAlertCount > 8){ + if(this.generationAlertCount >= CHILD_CELLS_PER_PARENT){ this.destroy(); } } diff --git a/src/main/java/electrosphere/collision/CollisionEngine.java b/src/main/java/electrosphere/collision/CollisionEngine.java index b58ace98..f68e39d0 100644 --- a/src/main/java/electrosphere/collision/CollisionEngine.java +++ b/src/main/java/electrosphere/collision/CollisionEngine.java @@ -759,11 +759,12 @@ public class CollisionEngine { //make uncollidable if(PhysicsEntityUtils.containsDBody(e)){ DBody rigidBody = PhysicsEntityUtils.getDBody(e); + if(rigidBody == null){ + throw new Error("DBody key set to null rigid body! " + rigidBody); + } this.deregisterCollisionObject(rigidBody,PhysicsEntityUtils.getCollidable(e)); e.removeData(EntityDataStrings.PHYSICS_COLLISION_BODY); - if(rigidBody != null){ - this.destroyDBody(rigidBody); - } + this.destroyDBody(rigidBody); } if(ServerPhysicsSyncTree.hasTree(e)){ ServerPhysicsSyncTree.detachTree(e, ServerPhysicsSyncTree.getTree(e)); diff --git a/src/main/java/electrosphere/collision/PhysicsEntityUtils.java b/src/main/java/electrosphere/collision/PhysicsEntityUtils.java index 332c4150..cb6db27f 100644 --- a/src/main/java/electrosphere/collision/PhysicsEntityUtils.java +++ b/src/main/java/electrosphere/collision/PhysicsEntityUtils.java @@ -483,10 +483,10 @@ public class PhysicsEntityUtils { */ public static void clientAttachTerrainChunkRigidBody(Entity terrain, TerrainChunkData data){ DBody terrainBody = CollisionBodyCreation.generateBodyFromTerrainData(Globals.clientSceneWrapper.getCollisionEngine(), data, Collidable.TYPE_STATIC_BIT); - if(terrainBody != null){ - Globals.clientSceneWrapper.getCollisionEngine().registerCollisionObject(terrainBody, new Collidable(terrain,Collidable.TYPE_TERRAIN, false)); - PhysicsEntityUtils.setDBody(terrain,terrainBody); - } + Collidable collidable = new Collidable(terrain,Collidable.TYPE_TERRAIN, false); + Globals.clientSceneWrapper.getCollisionEngine().registerCollisionObject(terrainBody, collidable); + PhysicsEntityUtils.setDBody(terrain,terrainBody); + terrain.putData(EntityDataStrings.PHYSICS_COLLIDABLE, collidable); } @@ -512,10 +512,12 @@ public class PhysicsEntityUtils { */ public static void serverRepositionEntities(CollisionEngine collisionEngine){ List toReposition = new LinkedList(); - if(collisionEngine.getCollidables() == null){ + List collidableList = collisionEngine.getCollidables(); + if(collidableList == null){ + collisionEngine.getCollidables(); throw new Error("Collision engine collidables are null!"); } - for(Collidable collidable : collisionEngine.getCollidables()){ + for(Collidable collidable : collidableList){ Entity entity = collidable.getParent(); DBody body = PhysicsEntityUtils.getDBody(entity); if(body != null && body.isEnabled() && !body.isKinematic()){ @@ -551,6 +553,9 @@ public class PhysicsEntityUtils { * @param body The body */ public static void setDBody(Entity entity, DBody body){ + if(body == null){ + throw new Error("Trying to set null DBody!"); + } entity.putData(EntityDataStrings.PHYSICS_COLLISION_BODY, body); } diff --git a/src/main/java/electrosphere/entity/types/terrain/TerrainChunk.java b/src/main/java/electrosphere/entity/types/terrain/TerrainChunk.java index 2ad98d26..b4334f3c 100644 --- a/src/main/java/electrosphere/entity/types/terrain/TerrainChunk.java +++ b/src/main/java/electrosphere/entity/types/terrain/TerrainChunk.java @@ -65,7 +65,7 @@ public class TerrainChunk { if(Globals.clientScene.containsEntity(rVal)){ String modelPath = ClientTerrainManager.queueTerrainGridGeneration(data, atlas, notifyTarget, toDelete); EntityCreationUtils.makeEntityDrawablePreexistingModel(rVal, modelPath); - if(levelOfDetail == ClientDrawCellManager.FULL_RES_LOD){ + if(levelOfDetail == ClientDrawCellManager.FULL_RES_LOD && data.faceElements.size() > 0){ PhysicsEntityUtils.clientAttachTerrainChunkRigidBody(rVal, data); CollisionObjUtils.clientPositionCharacter(rVal, new Vector3d(EntityUtils.getPosition(rVal)), new Quaterniond()); } else { diff --git a/src/main/java/electrosphere/net/server/Server.java b/src/main/java/electrosphere/net/server/Server.java index fb4228b6..c6e297d6 100644 --- a/src/main/java/electrosphere/net/server/Server.java +++ b/src/main/java/electrosphere/net/server/Server.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; /** * Lowest level networking class for the server @@ -96,6 +97,11 @@ public class Server implements Runnable { } catch (IOException ex) { LoggerInterface.loggerNetworking.ERROR("Socket error on client socket!",ex); } + try { + TimeUnit.MILLISECONDS.sleep(1); + } catch (InterruptedException e) { + LoggerInterface.loggerEngine.DEBUG("Failed to sleep", e); + } } this.isOpen = false; LoggerInterface.loggerNetworking.INFO("Server socket thread ended"); diff --git a/src/main/java/electrosphere/server/datacell/GriddedDataCellManager.java b/src/main/java/electrosphere/server/datacell/GriddedDataCellManager.java index e39fae3a..4d71be48 100644 --- a/src/main/java/electrosphere/server/datacell/GriddedDataCellManager.java +++ b/src/main/java/electrosphere/server/datacell/GriddedDataCellManager.java @@ -54,7 +54,7 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager /** * The number of frames without players that must pass before a server data cell is unloaded */ - static final int UNLOAD_FRAME_THRESHOLD = 500; + static final int UNLOAD_FRAME_THRESHOLD = 100; /** * Tracks whether this manager has been flagged to unload cells or not @@ -173,8 +173,6 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager LoggerInterface.loggerEngine.DEBUG("Creating new cell @ " + x + " " + y + " " + z); //create data cell this.createServerDataCell(targetPos); - ///generates physics for the cell in a dedicated thread then finally registers - this.runPhysicsGenerationThread(targetPos); //add to loaded cells cellPlayerlessFrameMap.put(groundDataCells.get(getServerDataCellKey(targetPos)),0); //add player @@ -224,8 +222,6 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager loadedCellsLock.acquireUninterruptibly(); //create data cell createServerDataCell(targetPos); - //generates physics for the cell in a dedicated thread then finally registers - runPhysicsGenerationThread(targetPos); //add to loaded cells cellPlayerlessFrameMap.put(groundDataCells.get(getServerDataCellKey(targetPos)),0); //add player @@ -344,8 +340,6 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager loadedCellsLock.acquireUninterruptibly(); //create data cell this.createServerDataCell(targetPos); - //generates physics for the cell in a dedicated thread then finally registers - this.runPhysicsGenerationThread(targetPos); //add to loaded cells cellPlayerlessFrameMap.put(groundDataCells.get(this.getServerDataCellKey(targetPos)),0); //add player @@ -370,7 +364,7 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager //TODO: improve to make have less performance impact loadedCellsLock.acquireUninterruptibly(); for(ServerDataCell cell : this.groundDataCells.values()){ - if(cell.getPlayers().size() < 1){ + if(cell.isReady() && cell.getPlayers().size() < 1){ int frameCount = cellPlayerlessFrameMap.get(cell) + 1; cellPlayerlessFrameMap.put(cell,frameCount); if(frameCount > UNLOAD_FRAME_THRESHOLD){ @@ -501,8 +495,6 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager loadedCellsLock.acquireUninterruptibly(); //create data cell this.createServerDataCell(worldPos); - //generates physics for the cell in a dedicated thread then finally registers - this.runPhysicsGenerationThread(worldPos); //add to loaded cells cellPlayerlessFrameMap.put(groundDataCells.get(this.getServerDataCellKey(worldPos)),0); loadedCellsLock.release(); @@ -614,6 +606,8 @@ public class GriddedDataCellManager implements DataCellManager, VoxelCellManager LoggerInterface.loggerEngine.DEBUG("Create server data cell with key " + cellKey); cellPositionMap.put(rVal,new Vector3i(worldPos)); serverContentManager.generateContentForDataCell(parent, worldPos, rVal, cellKey); + //generates physics for the cell in a dedicated thread then finally registers + this.runPhysicsGenerationThread(worldPos); return rVal; } diff --git a/src/main/java/electrosphere/server/datacell/physics/PhysicsDataCell.java b/src/main/java/electrosphere/server/datacell/physics/PhysicsDataCell.java index b82194d4..0bcdb034 100644 --- a/src/main/java/electrosphere/server/datacell/physics/PhysicsDataCell.java +++ b/src/main/java/electrosphere/server/datacell/physics/PhysicsDataCell.java @@ -71,7 +71,7 @@ public class PhysicsDataCell { // //fill in weights and types maps // - fillInData(); + this.fillInData(); Vector3d realPos = new Vector3d( worldPos.x * ServerTerrainChunk.CHUNK_PLACEMENT_OFFSET, diff --git a/src/main/java/electrosphere/server/terrain/generation/TestGenerationChunkGenerator.java b/src/main/java/electrosphere/server/terrain/generation/TestGenerationChunkGenerator.java index 0f93ff86..b8827761 100644 --- a/src/main/java/electrosphere/server/terrain/generation/TestGenerationChunkGenerator.java +++ b/src/main/java/electrosphere/server/terrain/generation/TestGenerationChunkGenerator.java @@ -223,7 +223,13 @@ public class TestGenerationChunkGenerator implements ChunkGenerator { } if(firstType == -2){ firstType = values[x][y][z]; - } else if(homogenous && firstType != values[x][y][z]){ + } else if( + homogenous && + ( + firstType != values[x][y][z] || + (weights[x][y][z] > -1.0f && weights[x][y][z] < 1.0f) + ) + ){ homogenous = false; } }