fix bounds check for cellular sim

This commit is contained in:
austin 2024-12-06 19:28:05 -05:00
parent d3f545955f
commit 3436bfa457
5 changed files with 57 additions and 52 deletions

View File

@ -1,3 +1,3 @@
#maven.buildNumber.plugin properties file #maven.buildNumber.plugin properties file
#Fri Dec 06 19:03:01 EST 2024 #Fri Dec 06 19:27:15 EST 2024
buildNumber=558 buildNumber=569

View File

@ -6,18 +6,18 @@
#ifndef CHUNK_H #ifndef CHUNK_H
#define CHUNK_H #define CHUNK_H
#define MIN_VALUE 0 #define MIN_VALUE 0.0
#define MAX_VALUE 1 #define MAX_VALUE 1.0
/** /**
* Minimum value of bounds array for it to be considered a blocker * The cutoff value for the bounds array
*/ */
#define BOUND_MIN_VALUE 0 #define BOUND_CUTOFF_VALUE 0.0
/** /**
* Maximum value of bounds array for it to be considered a blocker * Maximum value of bounds array for it to be considered a blocker
*/ */
#define BOUND_MAX_VALUE 1 #define BOUND_MAX_VALUE 1.0
/** /**
* The dimension of a single chunk's array * The dimension of a single chunk's array

View File

@ -43,48 +43,49 @@ void updateMetadata(JNIEnv * env, int numChunks, Chunk ** passedInChunks, Enviro
} }
//get whether the chunk is currently homogenous or not //get whether the chunk is currently homogenous or not
int homogenous = sum <= 0 ? JNI_TRUE : JNI_FALSE; int homogenous = sum <= 0 ? JNI_TRUE : JNI_FALSE;
(*env)->SetBooleanField(env,jObj,environment->lookupTable.serverFluidChunkTable.homogenousId,homogenous); // (*env)->SetBooleanField(env,jObj,environment->lookupTable.serverFluidChunkTable.homogenousId,homogenous);
(*env)->SetBooleanField(env,jObj,environment->lookupTable.serverFluidChunkTable.homogenousId,JNI_FALSE);
//update total density //update total density
(*env)->SetFloatField(env,jObj,totalDensityId,sum); (*env)->SetFloatField(env,jObj,totalDensityId,sum);
//check if any neighbor is non-homogenous //check if any neighbor is non-homogenous
jobject neighborArr = (*env)->GetObjectField(env,jObj,environment->lookupTable.serverFluidChunkTable.neighborsId); // jobject neighborArr = (*env)->GetObjectField(env,jObj,environment->lookupTable.serverFluidChunkTable.neighborsId);
int nonHomogenousNeighbor = JNI_FALSE; // int nonHomogenousNeighbor = JNI_FALSE;
for(int j = 0; j < NEIGHBOR_ARRAY_COUNT; j++){ // for(int j = 0; j < NEIGHBOR_ARRAY_COUNT; j++){
if(j == CENTER_LOC){ // if(j == CENTER_LOC){
continue; // continue;
} // }
jobject neighborObj = (*env)->GetObjectArrayElement(env,neighborArr,j); // jobject neighborObj = (*env)->GetObjectArrayElement(env,neighborArr,j);
if(neighborObj != NULL){ // if(neighborObj != NULL){
int neighborHomogenous = (*env)->GetBooleanField(env,neighborObj,environment->lookupTable.serverFluidChunkTable.homogenousId); // int neighborHomogenous = (*env)->GetBooleanField(env,neighborObj,environment->lookupTable.serverFluidChunkTable.homogenousId);
if(neighborHomogenous == JNI_FALSE){ // if(neighborHomogenous == JNI_FALSE){
nonHomogenousNeighbor = JNI_TRUE; // nonHomogenousNeighbor = JNI_TRUE;
break; // break;
} // }
} // }
} // }
//figure out if this chunk should sleep or not //figure out if this chunk should sleep or not
int shouldSleep = JNI_TRUE; int shouldSleep = JNI_TRUE;
if(nonHomogenousNeighbor == JNI_TRUE || homogenous == JNI_FALSE){ // if(nonHomogenousNeighbor == JNI_TRUE || homogenous == JNI_FALSE){
shouldSleep = JNI_FALSE; shouldSleep = JNI_FALSE;
} // }
(*env)->SetBooleanField(env,jObj,environment->lookupTable.serverFluidChunkTable.asleepId,shouldSleep); (*env)->SetBooleanField(env,jObj,environment->lookupTable.serverFluidChunkTable.asleepId,shouldSleep);
//if this cell is awake AND non-homogenous, make sure all neighbors are awake //if this cell is awake AND non-homogenous, make sure all neighbors are awake
if(shouldSleep == JNI_FALSE && homogenous == JNI_FALSE){ // if(shouldSleep == JNI_FALSE && homogenous == JNI_FALSE){
(*env)->SetBooleanField(env,jObj,updatedId,JNI_TRUE); (*env)->SetBooleanField(env,jObj,updatedId,JNI_TRUE);
for(int j = 0; j < NEIGHBOR_ARRAY_COUNT; j++){ // for(int j = 0; j < NEIGHBOR_ARRAY_COUNT; j++){
if(j == CENTER_LOC){ // if(j == CENTER_LOC){
continue; // continue;
} // }
jobject neighborObj = (*env)->GetObjectArrayElement(env,neighborArr,j); // jobject neighborObj = (*env)->GetObjectArrayElement(env,neighborArr,j);
if(neighborObj != NULL){ // if(neighborObj != NULL){
(*env)->SetBooleanField(env,neighborObj,environment->lookupTable.serverFluidChunkTable.asleepId,JNI_FALSE); // (*env)->SetBooleanField(env,neighborObj,environment->lookupTable.serverFluidChunkTable.asleepId,JNI_FALSE);
} // }
} // }
} // }
} }
//alert java side to updated static values //alert java side to updated static values

View File

@ -29,10 +29,10 @@ LIBRARY_API void fluid_cellular_simulate(Environment * environment){
continue; continue;
} else { } else {
//transfer straight down //transfer straight down
if(bounds[IX(x,y-1,z)] < BOUND_MIN_VALUE){ if(bounds[IX(x,y-1,z)] <= BOUND_CUTOFF_VALUE){
int deltaLower = MAX_VALUE - d[IX(x,y-1,z)]; float deltaLower = MAX_VALUE - d[IX(x,y-1,z)];
if(deltaLower > 0){ if(deltaLower > 0){
int transferLower; float transferLower;
if(d[IX(x,y,z)] >= deltaLower){ if(d[IX(x,y,z)] >= deltaLower){
transferLower = deltaLower; transferLower = deltaLower;
} else { } else {
@ -49,16 +49,18 @@ LIBRARY_API void fluid_cellular_simulate(Environment * environment){
for(int i = 0; i < 4; i++){ for(int i = 0; i < 4; i++){
int nX = x + offsetX[i]; int nX = x + offsetX[i];
int nZ = z + offsetZ[i]; int nZ = z + offsetZ[i];
int deltaLateral = d[IX(x,y,z)] - d[IX(nX,y,nZ)]; if(bounds[IX(nX,y,nZ)] <= BOUND_CUTOFF_VALUE){
if(deltaLateral > 0){ float deltaLateral = d[IX(x,y,z)] - d[IX(nX,y,nZ)];
int transferLateral; if(deltaLateral > 0){
if(d[IX(nX,y,nZ)] >= deltaLateral){ float transferLateral;
transferLateral = deltaLateral; if(d[IX(x,y,z)] >= deltaLateral){
} else { transferLateral = deltaLateral;
transferLateral = d[IX(nX,y,nZ)]; } else {
transferLateral = d[IX(x,y,z)];
}
d[IX(x,y,z)] -= transferLateral;
d[IX(nX,y,nZ)] += transferLateral;
} }
d[IX(nX,y,nZ)] -= transferLateral;
d[IX(nX,y,nZ)] += transferLateral;
} }
} }
} }

View File

@ -74,11 +74,13 @@ public class ServerBehaviorTreeUtils {
public static void updateCell(Entity entity, ServerDataCell oldCell){ public static void updateCell(Entity entity, ServerDataCell oldCell){
Set<BehaviorTree> trees = entityBTreeMap.get(entity); Set<BehaviorTree> trees = entityBTreeMap.get(entity);
ServerDataCell newCell = DataCellSearchUtils.getEntityDataCell(entity); ServerDataCell newCell = DataCellSearchUtils.getEntityDataCell(entity);
for(BehaviorTree tree : trees){ if(trees != null){
if(oldCell != null){ for(BehaviorTree tree : trees){
oldCell.getScene().deregisterBehaviorTree(tree); if(oldCell != null){
oldCell.getScene().deregisterBehaviorTree(tree);
}
newCell.getScene().registerBehaviorTree(tree);
} }
newCell.getScene().registerBehaviorTree(tree);
} }
} }