fix grass not moving with player
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2024-04-30 19:41:05 -04:00
parent 0d26c404ee
commit f7ac8d908e
4 changed files with 87 additions and 8 deletions

View File

@ -245,15 +245,25 @@ Physics Tweaks
Fix controls not repeating Fix controls not repeating
(04/22/2024)
Data Cleanup
- Clean up audio
- Fix ui audio effects having play times that are wayyyy too long
(04/30/2024)
Fix grass not generating for closest tiles
- There is no distance check in the ClientFoliageManager
# TODO # TODO
Ground Texture Atlas system
Character movement in particular feels off Character movement in particular feels off
- Bring back strafing - Bring back strafing
- Fix interaction with networking - Fix interaction with networking
- Potentially facing vector on server misaligned with client facing vector? - Nope! They're perfectly aligned
Fix grass not generating for closest tiles - May be in the ground move tree itself the hard setting velocity instead of applying a force is causing weirdness
Fix being able to walk off far side of the world (ie in level editor) Fix being able to walk off far side of the world (ie in level editor)
@ -266,8 +276,6 @@ Data Cleanup
- Clean up textures - Clean up textures
- Move model textures into models - Move model textures into models
- Recursive model transform data - Recursive model transform data
- Clean up audio
- Fix ui audio effects having play times that are wayyyy too long
More Debug menus More Debug menus
- Screen that shows the overall status of draw cell manager - Screen that shows the overall status of draw cell manager

View File

@ -6,6 +6,7 @@ import java.nio.FloatBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random; import java.util.Random;
@ -52,7 +53,7 @@ public class ClientFoliageManager {
//map of position-based key to foliage cell at the position //map of position-based key to foliage cell at the position
Map<String,FoliageCell> locationCellMap = new HashMap<String,FoliageCell>(); Map<String,FoliageCell> locationCellMap = new HashMap<String,FoliageCell>();
//The maximum distance a cell can be away from the player before being destroyed //The maximum distance a cell can be away from the player before being destroyed
static final float CELL_DISTANCE_MAX = 5f; static final float CELL_DISTANCE_MAX = 15f;
//The maximum number of foliage cells //The maximum number of foliage cells
@ -136,7 +137,30 @@ public class ClientFoliageManager {
public void update(){ public void update(){
Globals.profiler.beginCpuSample("ClientFoliageManager.update"); Globals.profiler.beginCpuSample("ClientFoliageManager.update");
if(ready){ if(ready){
Vector3d playerPosition = null;
if(Globals.playerEntity != null){
playerPosition = EntityUtils.getPosition(Globals.playerEntity);
}
Globals.profiler.beginCpuSample("ClientFoliageManager.update (talley invalid cells)");
//flip through all valid cells and see if you can invalidate any
List<FoliageCell> invalidationList = new LinkedList<FoliageCell>();
for(FoliageCell cell : activeCells){
if(
playerPosition != null &&
playerPosition.distance(cell.realPosition) > CELL_DISTANCE_MAX
){
invalidationList.add(cell);
}
}
Globals.profiler.endCpuSample();
Globals.profiler.beginCpuSample("ClientFoliageManager.update (actually invalidate cells)");
for(FoliageCell cell : invalidationList){
invalidateCell(cell);
}
Globals.profiler.endCpuSample();
invalidationList.clear();
//for each invalid cell, see if can be revalidated //for each invalid cell, see if can be revalidated
Globals.profiler.beginCpuSample("ClientFoliageManager.update (revalidate cells)");
for(String key : locationEvaluationCooldownMap.keySet()){ for(String key : locationEvaluationCooldownMap.keySet()){
int cooldownTime = locationEvaluationCooldownMap.get(key); int cooldownTime = locationEvaluationCooldownMap.get(key);
cooldownTime--; cooldownTime--;
@ -144,21 +168,27 @@ public class ClientFoliageManager {
String split[] = key.split("_"); String split[] = key.split("_");
Vector3i worldPos = new Vector3i(Integer.parseInt(split[0]),Integer.parseInt(split[1]),Integer.parseInt(split[2])); Vector3i worldPos = new Vector3i(Integer.parseInt(split[0]),Integer.parseInt(split[1]),Integer.parseInt(split[2]));
Vector3i voxelPos = new Vector3i(Integer.parseInt(split[3]),Integer.parseInt(split[4]),Integer.parseInt(split[5])); Vector3i voxelPos = new Vector3i(Integer.parseInt(split[3]),Integer.parseInt(split[4]),Integer.parseInt(split[5]));
Vector3d realPos = Globals.clientWorldData.convertWorldToRealSpace(worldPos).add(voxelPos.x,voxelPos.y,voxelPos.z);
ChunkData data = Globals.clientTerrainManager.getChunkDataAtWorldPoint(worldPos); ChunkData data = Globals.clientTerrainManager.getChunkDataAtWorldPoint(worldPos);
//evaluate //evaluate
if( if(
data != null &&
data.getWeight(voxelPos) > 0 && data.getWeight(voxelPos) > 0 &&
data.getWeight(new Vector3i(voxelPos.x,voxelPos.y + 1,voxelPos.z)) < 0 && data.getWeight(new Vector3i(voxelPos.x,voxelPos.y + 1,voxelPos.z)) < 0 &&
typeSupportsFoliage(data.getType(voxelPos)) typeSupportsFoliage(data.getType(voxelPos)) &&
playerPosition.distance(realPos) < CELL_DISTANCE_MAX
){ ){
//create foliage cell //create foliage cell
createFoliageCell(worldPos,voxelPos,0); createFoliageCell(worldPos,voxelPos,1);
}
locationEvaluationCooldownMap.remove(key); locationEvaluationCooldownMap.remove(key);
} else {
locationEvaluationCooldownMap.put(key, EVALUATION_COOLDOWN);
}
} else { } else {
locationEvaluationCooldownMap.put(key, cooldownTime); locationEvaluationCooldownMap.put(key, cooldownTime);
} }
} }
Globals.profiler.endCpuSample();
//invalidate foliage cells that have had their voxel changed //invalidate foliage cells that have had their voxel changed
invalidateModifiedPositions(); invalidateModifiedPositions();
} }
@ -495,6 +525,22 @@ public class ClientFoliageManager {
} }
} }
/**
* Invalidates a cell by direct reference
* @param cell The cell to invalidate
*/
private void invalidateCell(FoliageCell cell){
String key = getFoliageCellKey(cell.worldPosition, cell.voxelPosition);
if(!locationEvaluationCooldownMap.containsKey(key)){
locationEvaluationCooldownMap.put(key,EVALUATION_COOLDOWN);
}
//destroy
FoliageCell toDestroy = locationCellMap.get(key);
toDestroy.destroy();
activeCells.remove(toDestroy);
locationCellMap.remove(key);
}
/** /**
* Invalidates the foliage cells for all modified chunks * Invalidates the foliage cells for all modified chunks
*/ */

View File

@ -66,6 +66,25 @@ public class CameraEntityUtils {
return rVal; return rVal;
} }
/**
* Spawns a first person camera that tracks the player
* @param center the center of the camera
* @param eye the eye of the camera
* @return the camera
*/
public static Entity spawnPlayerEntityTrackingCameraFirstPersonEntity(Vector3f center, Vector3f eye){
Entity rVal = EntityCreationUtils.createClientSpatialEntity();
rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_TYPE, EntityDataStrings.DATA_STRING_CAMERA_TYPE_ORBIT);
rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_CENTER, center);
rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_EYE, eye);
rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_ORBIT_DISTANCE, 0.01f);
rVal.putData(EntityDataStrings.CAMERA_ORBIT_RADIAL_OFFSET, new Vector3f(0,0.8f,0));
rVal.putData(EntityDataStrings.CAMERA_PITCH, 0.0f);
rVal.putData(EntityDataStrings.CAMERA_YAW, 0.0f);
Globals.cameraHandler.setTrackPlayerEntity(true);
return rVal;
}
public static Entity spawnPlayerEntityAirplaneTrackingCameraEntity(Vector3f center, Vector3f eye){ public static Entity spawnPlayerEntityAirplaneTrackingCameraEntity(Vector3f center, Vector3f eye){
Entity rVal = EntityCreationUtils.createClientSpatialEntity(); Entity rVal = EntityCreationUtils.createClientSpatialEntity();
rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_TYPE, EntityDataStrings.DATA_STRING_CAMERA_TYPE_ORBIT); rVal.putData(EntityDataStrings.DATA_STRING_CAMERA_TYPE, EntityDataStrings.DATA_STRING_CAMERA_TYPE_ORBIT);

View File

@ -8,12 +8,15 @@ import org.ode4j.ode.DBody;
import electrosphere.audio.VirtualAudioSource; import electrosphere.audio.VirtualAudioSource;
import electrosphere.collision.PhysicsEntityUtils; import electrosphere.collision.PhysicsEntityUtils;
import electrosphere.engine.Globals; import electrosphere.engine.Globals;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityUtils; import electrosphere.entity.EntityUtils;
import electrosphere.entity.types.creature.CreatureUtils;
import electrosphere.renderer.RenderingEngine; import electrosphere.renderer.RenderingEngine;
import electrosphere.renderer.ui.imgui.ImGuiLinePlot; import electrosphere.renderer.ui.imgui.ImGuiLinePlot;
import electrosphere.renderer.ui.imgui.ImGuiWindow; import electrosphere.renderer.ui.imgui.ImGuiWindow;
import electrosphere.renderer.ui.imgui.ImGuiLinePlot.ImGuiLinePlotDataset; import electrosphere.renderer.ui.imgui.ImGuiLinePlot.ImGuiLinePlotDataset;
import electrosphere.renderer.ui.imgui.ImGuiWindow.ImGuiWindowCallback; import electrosphere.renderer.ui.imgui.ImGuiWindow.ImGuiWindowCallback;
import electrosphere.server.datacell.utils.EntityLookupUtils;
import imgui.ImGui; import imgui.ImGui;
/** /**
@ -175,6 +178,9 @@ public class ImGuiWindowMacros {
ImGui.text("Force: " + body.getForce()); ImGui.text("Force: " + body.getForce());
ImGui.text("Angular Velocity: " + body.getAngularVel()); ImGui.text("Angular Velocity: " + body.getAngularVel());
ImGui.text("Torque: " + body.getTorque()); ImGui.text("Torque: " + body.getTorque());
ImGui.text("Move Vector: " + CreatureUtils.getFacingVector(Globals.playerEntity));
Entity serverEntity = EntityLookupUtils.getEntityById(Globals.clientSceneWrapper.mapClientToServerId(Globals.playerEntity.getId()));
ImGui.text("Move Vector (Server): " + CreatureUtils.getFacingVector(serverEntity));
} }
} }
if(ImGui.button("Toggle Player Camera Lock")){ if(ImGui.button("Toggle Player Camera Lock")){