dedicated native fluid simulator
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
This commit is contained in:
parent
a8b473fc24
commit
5c44d36f25
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
@ -31,6 +31,8 @@
|
||||
"stdlib.h": "c",
|
||||
"chunk_test_utils.h": "c",
|
||||
"sparsesimulator.h": "c",
|
||||
"environment.h": "c"
|
||||
"environment.h": "c",
|
||||
"simulator.h": "c",
|
||||
"dispatcher.h": "c"
|
||||
}
|
||||
}
|
||||
@ -1,3 +1,3 @@
|
||||
#maven.buildNumber.plugin properties file
|
||||
#Tue Dec 03 15:14:56 EST 2024
|
||||
buildNumber=519
|
||||
#Fri Dec 06 14:33:08 EST 2024
|
||||
buildNumber=523
|
||||
|
||||
@ -1252,6 +1252,7 @@ Refactoring fluid sim headers
|
||||
Refactor native test code under src/test
|
||||
More test file refactoring
|
||||
Native fluid chunk dispatcher
|
||||
Dedicated native fluid simulator
|
||||
|
||||
|
||||
|
||||
|
||||
@ -23,4 +23,5 @@ cmake --build ${PWD}/out/build
|
||||
|
||||
#copy to expected folder
|
||||
mkdir ${PWD}/shared-folder
|
||||
rm ${PWD}/shared-folder/libStormEngine${LIB_ENDING}
|
||||
cp ${PWD}/out/build/libStormEngine${LIB_ENDING} ${PWD}/shared-folder/
|
||||
|
||||
11
src/main/c/includes/fluid/env/environment.h
vendored
11
src/main/c/includes/fluid/env/environment.h
vendored
@ -49,15 +49,24 @@ typedef struct {
|
||||
*/
|
||||
typedef struct {
|
||||
Chunk ** cellularQueue;
|
||||
Chunk ** gridQueue;
|
||||
} FluidSimQueue;
|
||||
|
||||
/**
|
||||
* Fluid sim consts provided by the host
|
||||
*/
|
||||
typedef struct {
|
||||
float gravity;
|
||||
float dt;
|
||||
} FluidSimConsts;
|
||||
|
||||
/**
|
||||
* Stores data about the simulation environment
|
||||
*/
|
||||
typedef struct {
|
||||
JNILookupTable lookupTable;
|
||||
FluidSimQueue queue;
|
||||
float gravity;
|
||||
FluidSimConsts consts;
|
||||
double existingDensity;
|
||||
double newDensity;
|
||||
float normalizationRatio;
|
||||
|
||||
@ -11,6 +11,6 @@
|
||||
* @param environment The environment data
|
||||
* @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
|
||||
18
src/main/c/includes/fluid/sim/simulator.h
Normal file
18
src/main/c/includes/fluid/sim/simulator.h
Normal 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
|
||||
@ -14,10 +14,22 @@
|
||||
*/
|
||||
LIBRARY_API void fluid_dispatch(int numReadIn, Chunk ** chunkViewC, Environment * environment){
|
||||
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++){
|
||||
Chunk * currentChunk = chunkViewC[i];
|
||||
//TODO: conditionally add to queues based on some values (ie lod, spatial loc, etc)
|
||||
stbds_arrput(queue.cellularQueue,currentChunk);
|
||||
stbds_arrput(queue.gridQueue,currentChunk);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
2
src/main/c/src/fluid/env/environment.c
vendored
2
src/main/c/src/fluid/env/environment.c
vendored
@ -9,6 +9,8 @@
|
||||
*/
|
||||
LIBRARY_API Environment * fluid_environment_create(){
|
||||
Environment * rVal = (Environment *)malloc(sizeof(Environment));
|
||||
rVal->queue.cellularQueue = NULL;
|
||||
rVal->queue.gridQueue = NULL;
|
||||
return rVal;
|
||||
}
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
#include "fluid/env/environment.h"
|
||||
#include "fluid/env/utilities.h"
|
||||
#include "fluid/sim/grid/simulation.h"
|
||||
#include "fluid/sim/simulator.h"
|
||||
#include "fluid/dispatch/dispatcher.h"
|
||||
|
||||
|
||||
@ -54,9 +55,10 @@ JNIEXPORT void JNICALL Java_electrosphere_server_fluid_simulator_FluidAccelerate
|
||||
jobject chunkList,
|
||||
jfloat dt
|
||||
){
|
||||
environment->consts.dt = dt;
|
||||
int numReadIn = readInChunks(env,chunkList,environment);
|
||||
fluid_dispatch(numReadIn,chunkViewC,environment);
|
||||
simulate(numReadIn,chunkViewC,environment,dt);
|
||||
fluid_simulate(environment);
|
||||
updateMetadata(env,numReadIn,chunkViewC,environment);
|
||||
}
|
||||
|
||||
@ -95,7 +97,7 @@ JNIEXPORT void JNICALL Java_electrosphere_server_fluid_simulator_FluidAccelerate
|
||||
}
|
||||
|
||||
//store variables from java side
|
||||
environment->gravity = gravity;
|
||||
environment->consts.gravity = gravity;
|
||||
environment->existingDensity = 0;
|
||||
environment->newDensity = 0;
|
||||
environment->normalizationRatio = 0;
|
||||
|
||||
@ -33,7 +33,7 @@ static inline void saveStep(float * values, const char * name);
|
||||
static inline void applyGravity(Chunk * currentChunk, Environment * environment);
|
||||
static inline void clearArr(float ** d);
|
||||
|
||||
void simulate(
|
||||
void fluid_grid_simulate(
|
||||
int numChunks,
|
||||
Chunk ** passedInChunks,
|
||||
Environment * environment,
|
||||
@ -584,7 +584,7 @@ static inline void applyGravity(Chunk * currentChunk, Environment * environment)
|
||||
for(int x = 0; x < DIM; x++){
|
||||
for(int y = 0; y < DIM; y++){
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
33
src/main/c/src/fluid/sim/simulator.c
Normal file
33
src/main/c/src/fluid/sim/simulator.c
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
28
src/test/c/fluid/sim/simulator_tests.c
Normal file
28
src/test/c/fluid/sim/simulator_tests.c
Normal 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;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user