native fluid chunk dispatcher
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
7740672e2c
commit
a8b473fc24
@ -1251,6 +1251,7 @@ Refactoring fluid sim code
|
|||||||
Refactoring fluid sim headers
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
21
src/main/c/includes/fluid/dispatch/dispatcher.h
Normal file
21
src/main/c/includes/fluid/dispatch/dispatcher.h
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#ifndef FLUID_DISPATCH_H
|
||||||
|
#define FLUID_DISPATCH_H
|
||||||
|
|
||||||
|
#include "public.h"
|
||||||
|
#include "fluid/queue/chunk.h"
|
||||||
|
#include "fluid/env/environment.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispatches chunks to different simulation queues based on the chunk's properties
|
||||||
|
* @param numReadIn The number of chunks
|
||||||
|
* @param chunkViewC The array of chunks
|
||||||
|
* @param environment The environment storing the simulation queues
|
||||||
|
*/
|
||||||
|
LIBRARY_API void fluid_dispatch(int numReadIn, Chunk ** chunkViewC, Environment * environment);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
25
src/main/c/includes/fluid/env/environment.h
vendored
25
src/main/c/includes/fluid/env/environment.h
vendored
@ -1,8 +1,10 @@
|
|||||||
#include <jni.h>
|
|
||||||
|
|
||||||
#ifndef ENVIRONMENT_H
|
#ifndef ENVIRONMENT_H
|
||||||
#define ENVIRONMENT_H
|
#define ENVIRONMENT_H
|
||||||
|
|
||||||
|
#include <jni.h>
|
||||||
|
#include "public.h"
|
||||||
|
#include "fluid/queue/chunk.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The List lookup table
|
* The List lookup table
|
||||||
*/
|
*/
|
||||||
@ -42,15 +44,34 @@ typedef struct {
|
|||||||
jclass serverFluidChunkClass;
|
jclass serverFluidChunkClass;
|
||||||
} JNILookupTable;
|
} JNILookupTable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores the different queues of cells to simulate
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
Chunk ** cellularQueue;
|
||||||
|
} FluidSimQueue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores data about the simulation environment
|
* Stores data about the simulation environment
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
JNILookupTable lookupTable;
|
JNILookupTable lookupTable;
|
||||||
|
FluidSimQueue queue;
|
||||||
float gravity;
|
float gravity;
|
||||||
double existingDensity;
|
double existingDensity;
|
||||||
double newDensity;
|
double newDensity;
|
||||||
float normalizationRatio;
|
float normalizationRatio;
|
||||||
} Environment;
|
} Environment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an environment
|
||||||
|
*/
|
||||||
|
LIBRARY_API Environment * fluid_environment_create();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frees an environment
|
||||||
|
* @param environment The environment to free
|
||||||
|
*/
|
||||||
|
LIBRARY_API void fluid_environment_free(Environment * environment);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
23
src/main/c/src/fluid/dispatch/dispatcher.c
Normal file
23
src/main/c/src/fluid/dispatch/dispatcher.c
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "stb/stb_ds.h"
|
||||||
|
|
||||||
|
#include "fluid/dispatch/dispatcher.h"
|
||||||
|
#include "fluid/queue/chunk.h"
|
||||||
|
#include "fluid/env/environment.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dispatches chunks to different simulation queues based on the chunk's properties
|
||||||
|
* @param numReadIn The number of chunks
|
||||||
|
* @param chunkViewC The array of chunks
|
||||||
|
* @param environment The environment storing the simulation queues
|
||||||
|
*/
|
||||||
|
LIBRARY_API void fluid_dispatch(int numReadIn, Chunk ** chunkViewC, Environment * environment){
|
||||||
|
FluidSimQueue queue = environment->queue;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
20
src/main/c/src/fluid/env/environment.c
vendored
Normal file
20
src/main/c/src/fluid/env/environment.c
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "public.h"
|
||||||
|
#include "fluid/env/environment.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an environment
|
||||||
|
*/
|
||||||
|
LIBRARY_API Environment * fluid_environment_create(){
|
||||||
|
Environment * rVal = (Environment *)malloc(sizeof(Environment));
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Frees an environment
|
||||||
|
*/
|
||||||
|
LIBRARY_API void fluid_environment_free(Environment * environment){
|
||||||
|
free(environment);
|
||||||
|
}
|
||||||
@ -8,9 +8,11 @@
|
|||||||
//local includes
|
//local includes
|
||||||
#include "fluid/queue/chunk.h"
|
#include "fluid/queue/chunk.h"
|
||||||
#include "fluid/queue/chunkmask.h"
|
#include "fluid/queue/chunkmask.h"
|
||||||
|
#include "fluid/queue/metadatacalc.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/queue/metadatacalc.h"
|
#include "fluid/dispatch/dispatcher.h"
|
||||||
|
|
||||||
|
|
||||||
//defines
|
//defines
|
||||||
@ -53,6 +55,7 @@ JNIEXPORT void JNICALL Java_electrosphere_server_fluid_simulator_FluidAccelerate
|
|||||||
jfloat dt
|
jfloat dt
|
||||||
){
|
){
|
||||||
int numReadIn = readInChunks(env,chunkList,environment);
|
int numReadIn = readInChunks(env,chunkList,environment);
|
||||||
|
fluid_dispatch(numReadIn,chunkViewC,environment);
|
||||||
simulate(numReadIn,chunkViewC,environment,dt);
|
simulate(numReadIn,chunkViewC,environment,dt);
|
||||||
updateMetadata(env,numReadIn,chunkViewC,environment);
|
updateMetadata(env,numReadIn,chunkViewC,environment);
|
||||||
}
|
}
|
||||||
@ -88,7 +91,7 @@ JNIEXPORT void JNICALL Java_electrosphere_server_fluid_simulator_FluidAccelerate
|
|||||||
|
|
||||||
//allocate if unallocated
|
//allocate if unallocated
|
||||||
if(environment == NULL){
|
if(environment == NULL){
|
||||||
environment = (Environment *)malloc(sizeof(Environment));
|
environment = fluid_environment_create();
|
||||||
}
|
}
|
||||||
|
|
||||||
//store variables from java side
|
//store variables from java side
|
||||||
|
|||||||
@ -1,5 +1,10 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
//library includes
|
||||||
|
//include stb ds
|
||||||
|
#define STB_DS_IMPLEMENTATION
|
||||||
|
#include "stb/stb_ds.h"
|
||||||
|
|
||||||
int StormEngineTests(int argc, char **argv){
|
int StormEngineTests(int argc, char **argv){
|
||||||
printf("it lives\n");
|
printf("it lives\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
17
src/test/c/fluid/dispatch/dispatcher_tests.c
Normal file
17
src/test/c/fluid/dispatch/dispatcher_tests.c
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
#include "fluid/dispatch/dispatcher.h"
|
||||||
|
#include "fluid/env/environment.h"
|
||||||
|
|
||||||
|
#include "../../util/chunk_test_utils.h"
|
||||||
|
|
||||||
|
int fluid_dispatch_dispatcher_tests(){
|
||||||
|
int rVal = 0;
|
||||||
|
|
||||||
|
Environment * env = fluid_environment_create();
|
||||||
|
|
||||||
|
int queueSize = 10;
|
||||||
|
Chunk ** queue = chunk_create_queue(queueSize);
|
||||||
|
fluid_dispatch(queueSize,queue,env);
|
||||||
|
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
@ -1,5 +1,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "stb/stb_ds.h"
|
||||||
#include "fluid/queue/chunk.h"
|
#include "fluid/queue/chunk.h"
|
||||||
#include "fluid/queue/chunkmask.h"
|
#include "fluid/queue/chunkmask.h"
|
||||||
|
|
||||||
@ -37,6 +38,19 @@ void chunk_free(Chunk * chunk){
|
|||||||
free(chunk);
|
free(chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a chunk queue
|
||||||
|
* @param size The size of the queue to create
|
||||||
|
*/
|
||||||
|
Chunk ** chunk_create_queue(int size){
|
||||||
|
Chunk ** rVal = NULL;
|
||||||
|
for(int i = 0; i < size; i++){
|
||||||
|
Chunk * chunk = chunk_create(i,i,i);
|
||||||
|
stbds_arrput(rVal,chunk);
|
||||||
|
}
|
||||||
|
return rVal;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Empty test launcher
|
* Empty test launcher
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -65,4 +65,10 @@ void chunk_free(Chunk * chunk);
|
|||||||
*/
|
*/
|
||||||
void chunk_set_val(Chunk * chunk, int i, int arr);
|
void chunk_set_val(Chunk * chunk, int i, int arr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a chunk queue
|
||||||
|
* @param size The size of the queue to create
|
||||||
|
*/
|
||||||
|
Chunk ** chunk_create_queue(int size);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Loading…
Reference in New Issue
Block a user