bounds array allocation
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2024-12-06 16:11:34 -05:00
parent 7f09be679f
commit 53a9a1b383
9 changed files with 61 additions and 11 deletions

View File

@ -1,3 +1,3 @@
#maven.buildNumber.plugin properties file
#Fri Dec 06 15:47:19 EST 2024
buildNumber=529
#Fri Dec 06 16:10:07 EST 2024
buildNumber=534

View File

@ -1255,6 +1255,7 @@ Native fluid chunk dispatcher
Dedicated native fluid simulator
Define cellular simulator
Fix fluid dispatcher array deref
Bounds array allocation

View File

@ -26,6 +26,7 @@ typedef struct {
jfieldID u0JId;
jfieldID v0JId;
jfieldID w0JId;
jfieldID boundsId;
jfieldID neighborsId;
jfieldID chunkmaskJId;
jfieldID updatedId;

View File

@ -9,6 +9,11 @@
#define MIN_VALUE 0
#define MAX_VALUE 1
/**
* Minimum value of bounds array for it to be considered a blocker
*/
#define BOUND_MIN_VALUE 0
/**
* The dimension of a single chunk's array
*/
@ -26,6 +31,7 @@ typedef struct {
float * u0[27];
float * v0[27];
float * w0[27];
float * bounds[27];
int chunkMask;
jobject chunkJRaw;

View File

@ -119,6 +119,7 @@ JNIEXPORT void JNICALL Java_electrosphere_server_fluid_simulator_FluidAccelerate
environment->lookupTable.serverFluidChunkTable.u0JId = (*env)->GetFieldID(env,fluidSimStorageClass,"b0VelocityX","[Ljava/nio/ByteBuffer;");
environment->lookupTable.serverFluidChunkTable.v0JId = (*env)->GetFieldID(env,fluidSimStorageClass,"b0VelocityY","[Ljava/nio/ByteBuffer;");
environment->lookupTable.serverFluidChunkTable.w0JId = (*env)->GetFieldID(env,fluidSimStorageClass,"b0VelocityZ","[Ljava/nio/ByteBuffer;");
environment->lookupTable.serverFluidChunkTable.boundsId = (*env)->GetFieldID(env,fluidSimStorageClass,"bBounds","[Ljava/nio/ByteBuffer;");
environment->lookupTable.serverFluidChunkTable.neighborsId = (*env)->GetFieldID(env,fluidSimStorageClass,"neighbors","[Lelectrosphere/server/fluid/manager/ServerFluidChunk;");
environment->lookupTable.serverFluidChunkTable.chunkmaskJId = (*env)->GetFieldID(env,fluidSimStorageClass,"chunkMask","I");
environment->lookupTable.serverFluidChunkTable.totalDensityId = (*env)->GetFieldID(env,fluidSimStorageClass,"totalDensity","F");
@ -149,6 +150,7 @@ int readInChunks(JNIEnv * env, jobject chunkList, Environment * environment){
jfieldID u0JId = environment->lookupTable.serverFluidChunkTable.u0JId;
jfieldID v0JId = environment->lookupTable.serverFluidChunkTable.v0JId;
jfieldID w0JId = environment->lookupTable.serverFluidChunkTable.w0JId;
jfieldID boundsId = environment->lookupTable.serverFluidChunkTable.boundsId;
jfieldID chunkmaskJId = environment->lookupTable.serverFluidChunkTable.chunkmaskJId;
jfieldID asleepId = environment->lookupTable.serverFluidChunkTable.asleepId;
@ -166,6 +168,7 @@ int readInChunks(JNIEnv * env, jobject chunkList, Environment * environment){
jobjectArray u0;
jobjectArray v0;
jobjectArray w0;
jobjectArray bounds;
int chunkMask;
//solve chunk mask
@ -211,6 +214,7 @@ int readInChunks(JNIEnv * env, jobject chunkList, Environment * environment){
u0 = (*env)->GetObjectField(env,chunkJRaw,u0JId);
v0 = (*env)->GetObjectField(env,chunkJRaw,v0JId);
w0 = (*env)->GetObjectField(env,chunkJRaw,w0JId);
bounds = (*env)->GetObjectField(env,chunkJRaw,boundsId);
newChunk->chunkMask = chunkMask;
newChunk->chunkJRaw = chunkJRaw;
for(int j = 0; j < 27; j++){
@ -223,6 +227,7 @@ int readInChunks(JNIEnv * env, jobject chunkList, Environment * environment){
newChunk->u0[j] = getArray(env,u0,j);
newChunk->v0[j] = getArray(env,v0,j);
newChunk->w0[j] = getArray(env,w0,j);
newChunk->bounds[j] = getArray(env,bounds,j);
}
}
}

View File

@ -20,6 +20,7 @@ LIBRARY_API void fluid_cellular_simulate(Environment * environment){
//simulate here
float * d = currentChunk->d[CENTER_LOC];
float * bounds = currentChunk->bounds[CENTER_LOC];
for(int x = 1; x < DIM-1; x++){
for(int y = 1; y < DIM-1; y++){
@ -27,16 +28,38 @@ LIBRARY_API void fluid_cellular_simulate(Environment * environment){
if(d[IX(x,y,z)] <= 0){
continue;
} else {
int deltaLower = MAX_VALUE - d[IX(x,y-1,z)];
if(deltaLower > 0){
int transferLower;
if(d[IX(x,y,z)] >= deltaLower){
transferLower = deltaLower;
} else {
transferLower = d[IX(x,y,z)];
//transfer straight down
if(bounds[IX(x,y-1,z)] <= BOUND_MIN_VALUE){
int deltaLower = MAX_VALUE - d[IX(x,y-1,z)];
if(deltaLower > 0){
int transferLower;
if(d[IX(x,y,z)] >= deltaLower){
transferLower = deltaLower;
} else {
transferLower = d[IX(x,y,z)];
}
d[IX(x,y,z)] -= transferLower;
d[IX(x,y-1,z)] += transferLower;
}
}
//transfer laterally if available
//propagate sideways
int offsetX[5] = {-1,1,0,0};
int offsetZ[5] = {0,0,-1,1};
for(int i = 0; i < 4; i++){
int nX = x + offsetX[i];
int nZ = z + offsetZ[i];
int deltaLateral = d[IX(x,y,z)] - d[IX(nX,y,nZ)];
if(deltaLateral > 0){
int transferLateral;
if(d[IX(nX,y,nZ)] >= deltaLateral){
transferLateral = deltaLateral;
} else {
transferLateral = d[IX(nX,y,nZ)];
}
d[IX(nX,y,nZ)] -= transferLateral;
d[IX(nX,y,nZ)] += transferLateral;
}
d[IX(x,y,z)] -= transferLower;
d[IX(x,y-1,z)] += transferLower;
}
}
}

View File

@ -76,6 +76,7 @@ JNIEXPORT void JNICALL Java_electrosphere_server_fluid_manager_ServerFluidChunk_
jfieldID u0Id = (*env)->GetFieldID(env,serverFluidChunkClass,"b0VelocityX","[Ljava/nio/ByteBuffer;");
jfieldID v0Id = (*env)->GetFieldID(env,serverFluidChunkClass,"b0VelocityY","[Ljava/nio/ByteBuffer;");
jfieldID w0Id = (*env)->GetFieldID(env,serverFluidChunkClass,"b0VelocityZ","[Ljava/nio/ByteBuffer;");
jfieldID boundsId = (*env)->GetFieldID(env,serverFluidChunkClass,"bBounds","[Ljava/nio/ByteBuffer;");
allocateCenterField(env,fluidObj,dId);
allocateCenterField(env,fluidObj,d0Id);
allocateCenterField(env,fluidObj,uId);
@ -84,6 +85,7 @@ JNIEXPORT void JNICALL Java_electrosphere_server_fluid_manager_ServerFluidChunk_
allocateCenterField(env,fluidObj,u0Id);
allocateCenterField(env,fluidObj,v0Id);
allocateCenterField(env,fluidObj,w0Id);
allocateCenterField(env,fluidObj,boundsId);
}
/**
@ -133,6 +135,7 @@ JNIEXPORT void JNICALL Java_electrosphere_server_fluid_manager_ServerFluidChunk_
jfieldID u0Id = (*env)->GetFieldID(env,serverFluidChunkClass,"b0VelocityX","[Ljava/nio/ByteBuffer;");
jfieldID v0Id = (*env)->GetFieldID(env,serverFluidChunkClass,"b0VelocityY","[Ljava/nio/ByteBuffer;");
jfieldID w0Id = (*env)->GetFieldID(env,serverFluidChunkClass,"b0VelocityZ","[Ljava/nio/ByteBuffer;");
jfieldID boundsId = (*env)->GetFieldID(env,serverFluidChunkClass,"bBounds","[Ljava/nio/ByteBuffer;");
freeCenterField(env,fluidObj,dId);
freeCenterField(env,fluidObj,d0Id);
freeCenterField(env,fluidObj,uId);
@ -141,6 +144,7 @@ JNIEXPORT void JNICALL Java_electrosphere_server_fluid_manager_ServerFluidChunk_
freeCenterField(env,fluidObj,u0Id);
freeCenterField(env,fluidObj,v0Id);
freeCenterField(env,fluidObj,w0Id);
freeCenterField(env,fluidObj,boundsId);
}
/**

View File

@ -141,6 +141,11 @@ public class ServerFluidChunk {
*/
public ByteBuffer[] b0VelocityZ = new ByteBuffer[ARRAY_CT];
/**
* The array storing bounds data
*/
public ByteBuffer[] bBounds = new ByteBuffer[ARRAY_CT];
/**
* The array of pointers to neighboring chunks
*/
@ -209,6 +214,7 @@ public class ServerFluidChunk {
this.b0VelocityX[CENTER_BUFF].order(ByteOrder.LITTLE_ENDIAN);
this.b0VelocityY[CENTER_BUFF].order(ByteOrder.LITTLE_ENDIAN);
this.b0VelocityZ[CENTER_BUFF].order(ByteOrder.LITTLE_ENDIAN);
this.bBounds[CENTER_BUFF].order(ByteOrder.LITTLE_ENDIAN);
//get float view
this.weights = this.bWeights[CENTER_BUFF].asFloatBuffer();
@ -493,6 +499,7 @@ public class ServerFluidChunk {
b0VelocityX[index] = null;
b0VelocityY[index] = null;
b0VelocityZ[index] = null;
bBounds[index] = null;
neighbors[index] = null;
} else {
bWeights[index] = neighbor.bWeights[CENTER_BUFF];
@ -503,6 +510,8 @@ public class ServerFluidChunk {
b0VelocityX[index] = neighbor.b0VelocityX[CENTER_BUFF];
b0VelocityY[index] = neighbor.b0VelocityY[CENTER_BUFF];
b0VelocityZ[index] = neighbor.b0VelocityZ[CENTER_BUFF];
b0VelocityZ[index] = neighbor.b0VelocityZ[CENTER_BUFF];
bBounds[index] = neighbor.bBounds[CENTER_BUFF];
neighbors[index] = neighbor;
}
}

View File

@ -17,6 +17,7 @@ Chunk * chunk_create(int x, int y, int z){
chunk1->u0[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float));
chunk1->v0[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float));
chunk1->w0[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float));
chunk1->bounds[CENTER_LOC] = (float *)malloc(DIM * DIM * DIM * sizeof(float));
chunk1->x = x;
chunk1->y = y;
chunk1->z = z;