dedicated native fluid simulator
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2024-12-06 14:35:03 -05:00
parent a8b473fc24
commit 5c44d36f25
13 changed files with 118 additions and 10 deletions

View File

@ -31,6 +31,8 @@
"stdlib.h": "c", "stdlib.h": "c",
"chunk_test_utils.h": "c", "chunk_test_utils.h": "c",
"sparsesimulator.h": "c", "sparsesimulator.h": "c",
"environment.h": "c" "environment.h": "c",
"simulator.h": "c",
"dispatcher.h": "c"
} }
} }

View File

@ -1,3 +1,3 @@
#maven.buildNumber.plugin properties file #maven.buildNumber.plugin properties file
#Tue Dec 03 15:14:56 EST 2024 #Fri Dec 06 14:33:08 EST 2024
buildNumber=519 buildNumber=523

View File

@ -1252,6 +1252,7 @@ Refactoring fluid sim headers
Refactor native test code under src/test Refactor native test code under src/test
More test file refactoring More test file refactoring
Native fluid chunk dispatcher Native fluid chunk dispatcher
Dedicated native fluid simulator

View File

@ -23,4 +23,5 @@ cmake --build ${PWD}/out/build
#copy to expected folder #copy to expected folder
mkdir ${PWD}/shared-folder mkdir ${PWD}/shared-folder
rm ${PWD}/shared-folder/libStormEngine${LIB_ENDING}
cp ${PWD}/out/build/libStormEngine${LIB_ENDING} ${PWD}/shared-folder/ cp ${PWD}/out/build/libStormEngine${LIB_ENDING} ${PWD}/shared-folder/

View File

@ -49,15 +49,24 @@ typedef struct {
*/ */
typedef struct { typedef struct {
Chunk ** cellularQueue; Chunk ** cellularQueue;
Chunk ** gridQueue;
} FluidSimQueue; } FluidSimQueue;
/**
* Fluid sim consts provided by the host
*/
typedef struct {
float gravity;
float dt;
} FluidSimConsts;
/** /**
* Stores data about the simulation environment * Stores data about the simulation environment
*/ */
typedef struct { typedef struct {
JNILookupTable lookupTable; JNILookupTable lookupTable;
FluidSimQueue queue; FluidSimQueue queue;
float gravity; FluidSimConsts consts;
double existingDensity; double existingDensity;
double newDensity; double newDensity;
float normalizationRatio; float normalizationRatio;

View File

@ -11,6 +11,6 @@
* @param environment The environment data * @param environment The environment data
* @param timestep The timestep to simulate by * @param timestep The timestep to simulate by
*/ */
void simulate(int numChunks, Chunk ** passedInChunks, Environment * environment, float timestep); void fluid_grid_simulate(int numChunks, Chunk ** passedInChunks, Environment * environment, float timestep);
#endif #endif

View File

@ -0,0 +1,18 @@
#ifndef FLUID_SIMULATOR_H
#define FLUID_SIMULATOR_H
#include "public.h"
#include "fluid/env/environment.h"
/**
* Simulates the various chunk queues in the fluid environment
* @param environment The environment storing the simulation queues
*/
LIBRARY_API void fluid_simulate(Environment * environment);
#endif

View File

@ -14,10 +14,22 @@
*/ */
LIBRARY_API void fluid_dispatch(int numReadIn, Chunk ** chunkViewC, Environment * environment){ LIBRARY_API void fluid_dispatch(int numReadIn, Chunk ** chunkViewC, Environment * environment){
FluidSimQueue queue = environment->queue; FluidSimQueue queue = environment->queue;
//clear queues
int countCurrent;
countCurrent = stbds_arrlen(queue.cellularQueue);
if(countCurrent > 0){
stbds_arrdeln(queue.cellularQueue,0,countCurrent);
}
countCurrent = stbds_arrlen(queue.gridQueue);
if(countCurrent > 0){
stbds_arrdeln(queue.gridQueue,0,countCurrent);
}
//queue new chunks
for(int i = 0; i < numReadIn; i++){ for(int i = 0; i < numReadIn; i++){
Chunk * currentChunk = chunkViewC[i]; Chunk * currentChunk = chunkViewC[i];
//TODO: conditionally add to queues based on some values (ie lod, spatial loc, etc) //TODO: conditionally add to queues based on some values (ie lod, spatial loc, etc)
stbds_arrput(queue.cellularQueue,currentChunk); stbds_arrput(queue.gridQueue,currentChunk);
} }
} }

View File

@ -9,6 +9,8 @@
*/ */
LIBRARY_API Environment * fluid_environment_create(){ LIBRARY_API Environment * fluid_environment_create(){
Environment * rVal = (Environment *)malloc(sizeof(Environment)); Environment * rVal = (Environment *)malloc(sizeof(Environment));
rVal->queue.cellularQueue = NULL;
rVal->queue.gridQueue = NULL;
return rVal; return rVal;
} }

View File

@ -12,6 +12,7 @@
#include "fluid/env/environment.h" #include "fluid/env/environment.h"
#include "fluid/env/utilities.h" #include "fluid/env/utilities.h"
#include "fluid/sim/grid/simulation.h" #include "fluid/sim/grid/simulation.h"
#include "fluid/sim/simulator.h"
#include "fluid/dispatch/dispatcher.h" #include "fluid/dispatch/dispatcher.h"
@ -54,9 +55,10 @@ JNIEXPORT void JNICALL Java_electrosphere_server_fluid_simulator_FluidAccelerate
jobject chunkList, jobject chunkList,
jfloat dt jfloat dt
){ ){
environment->consts.dt = dt;
int numReadIn = readInChunks(env,chunkList,environment); int numReadIn = readInChunks(env,chunkList,environment);
fluid_dispatch(numReadIn,chunkViewC,environment); fluid_dispatch(numReadIn,chunkViewC,environment);
simulate(numReadIn,chunkViewC,environment,dt); fluid_simulate(environment);
updateMetadata(env,numReadIn,chunkViewC,environment); updateMetadata(env,numReadIn,chunkViewC,environment);
} }
@ -95,7 +97,7 @@ JNIEXPORT void JNICALL Java_electrosphere_server_fluid_simulator_FluidAccelerate
} }
//store variables from java side //store variables from java side
environment->gravity = gravity; environment->consts.gravity = gravity;
environment->existingDensity = 0; environment->existingDensity = 0;
environment->newDensity = 0; environment->newDensity = 0;
environment->normalizationRatio = 0; environment->normalizationRatio = 0;

View File

@ -33,7 +33,7 @@ static inline void saveStep(float * values, const char * name);
static inline void applyGravity(Chunk * currentChunk, Environment * environment); static inline void applyGravity(Chunk * currentChunk, Environment * environment);
static inline void clearArr(float ** d); static inline void clearArr(float ** d);
void simulate( void fluid_grid_simulate(
int numChunks, int numChunks,
Chunk ** passedInChunks, Chunk ** passedInChunks,
Environment * environment, Environment * environment,
@ -584,7 +584,7 @@ static inline void applyGravity(Chunk * currentChunk, Environment * environment)
for(int x = 0; x < DIM; x++){ for(int x = 0; x < DIM; x++){
for(int y = 0; y < DIM; y++){ for(int y = 0; y < DIM; y++){
for(int z = 0; z < DIM; z++){ for(int z = 0; z < DIM; z++){
GET_ARR_RAW(currentChunk->v0,CENTER_LOC)[IX(x,y,z)] = GET_ARR_RAW(currentChunk->v0,CENTER_LOC)[IX(x,y,z)] + GET_ARR_RAW(currentChunk->d,CENTER_LOC)[IX(x,y,z)] * environment->gravity; GET_ARR_RAW(currentChunk->v0,CENTER_LOC)[IX(x,y,z)] = GET_ARR_RAW(currentChunk->v0,CENTER_LOC)[IX(x,y,z)] + GET_ARR_RAW(currentChunk->d,CENTER_LOC)[IX(x,y,z)] * environment->consts.gravity;
} }
} }
} }

View File

@ -0,0 +1,33 @@
#include <stdlib.h>
#include "stb/stb_ds.h"
#include "fluid/dispatch/dispatcher.h"
#include "fluid/sim/simulator.h"
#include "fluid/sim/grid/simulation.h"
#include "fluid/queue/chunk.h"
#include "fluid/env/environment.h"
/**
* Simulates the various chunk queues in the fluid environment
* @param environment The environment storing the simulation queues
*/
LIBRARY_API void fluid_simulate(Environment * environment){
FluidSimQueue queue = environment->queue;
int currentCount, i;
//cellular sim
currentCount = stbds_arrlen(queue.cellularQueue);
for(i = 0; i < currentCount; i++){
Chunk * currentChunk = queue.cellularQueue[i];
//TODO: simulate here
}
//grid sim
{
currentCount = stbds_arrlen(queue.gridQueue);
fluid_grid_simulate(currentCount,queue.gridQueue,environment,environment->consts.dt);
}
}

View File

@ -0,0 +1,28 @@
#include <stdio.h>
#include <stdlib.h>
#include "fluid/queue/chunk.h"
#include "fluid/queue/sparse.h"
#include "fluid/queue/chunkmask.h"
#include "fluid/env/utilities.h"
#include "fluid/queue/islandsolver.h"
#include "fluid/dispatch/dispatcher.h"
#include "fluid/sim/simulator.h"
#include "../../util/test.h"
#include "../../util/chunk_test_utils.h"
int fluid_sim_simulator_tests(int argc, char **argv){
int rVal = 0;
Environment * env = fluid_environment_create();
int queueSize = 10;
Chunk ** queue = chunk_create_queue(queueSize);
fluid_dispatch(queueSize,queue,env);
fluid_simulate(env);
return rVal;
}