diff --git a/build b/build index bda4a80..b6ce346 100755 --- a/build +++ b/build @@ -1,6 +1,6 @@ #!/bin/bash LIB_INCLUDE="-lglfw -lGL -lm" -g++ -g -g3 -DOS_LINUX=1 -DENABLE_ASSERT=1 -xc -std=c99 ./src/main.cpp -o ./target/somaesque $LIB_INCLUDE +g++ -g -g2 -DOS_LINUX=1 -DDJSTDLIB_DEBUG=1 -xc -std=c99 ./src/main.c -o ./target/somaesque $LIB_INCLUDE ./target/somaesque diff --git a/src/SomaSolve.cpp b/src/SomaSolve.c similarity index 92% rename from src/SomaSolve.cpp rename to src/SomaSolve.c index 1d7d6fb..b0ccafd 100644 --- a/src/SomaSolve.cpp +++ b/src/SomaSolve.c @@ -67,11 +67,12 @@ std::vector get_reprs_input(int units_required) { DefineList(size_t, Offset); -typedef struct Solver { +typedef struct Solver Solver; +struct Solver { VoxelSpaceReprList *input; OffsetList *offsets; SomaSolutionList *solutions; -} Solver; +}; uint64 STD_SOMA[] = { 23ul, 30ul, 15ul, 1043ul, 24594ul, 12306ul, 11ul }; @@ -179,18 +180,15 @@ SomaSolutionList filterUnique(Arena *arena, SomaSolutionList *solutions, int dim return (SomaSolutionList)EmptyList(); } SomaSolutionList uniqueSolns = PushList(arena, SomaSolutionList, solutions->length); - for (EachIn(*solutions, i)) { - SomaSolution solution = solutions->data[i]; + for (EachEl(*solutions, SomaSolution, solution)) { bool foundMatch = false; Scratch temp = scratchStart(&arena, 1); - SomaSolutionList rots = getSolutionRotations(temp.arena, &solution, dims); - for (EachIn(rots, j)) { - SomaSolution rotation = rots.data[j]; - for (EachIn(uniqueSolns, k)) { - SomaSolution unique_soln = uniqueSolns.data[k]; + SomaSolutionList rots = getSolutionRotations(temp.arena, solution, dims); + for (EachEl(rots, SomaSolution, rotation)) { + for (EachEl(uniqueSolns, SomaSolution, unique_soln)) { bool isMatch = true; - for (EachIn(unique_soln, piece_i)) { - if (rotation.data[piece_i] != unique_soln.data[piece_i]) { + for (EachIn(*unique_soln, piece_i)) { + if (rotation->data[piece_i] != unique_soln->data[piece_i]) { isMatch = false; break; } @@ -206,10 +204,10 @@ SomaSolutionList filterUnique(Arena *arena, SomaSolutionList *solutions, int dim } scratchEnd(temp); if (!foundMatch) { - SomaSolution solutionCopy = PushList(arena, SomaSolution, solution.length); - solutionCopy.capacity = solution.length; - solutionCopy.length = solution.length; - memcpy(solutionCopy.data, solution.data, ListElementSize(SomaSolutionList) * solution.length); + SomaSolution solutionCopy = PushList(arena, SomaSolution, solution->length); + solutionCopy.capacity = solution->length; + solutionCopy.length = solution->length; + memcpy(solutionCopy.data, solution->data, ListElementSize(SomaSolutionList) * solution->length); AppendList(&uniqueSolns, solutionCopy); } } @@ -287,12 +285,11 @@ SomaSolutionList solve(uint64 *reprs_in, uint32 reprs_in_count, int dims[3]) { } -void interactive_cmd_line_solve_soma() { - int dims[3] = { 3, 3, 3 }; +void interactiveCmdLineSolveSoma() { //get_dims_input(dims); //std::cout << '\n'; //std::vector reprs = get_reprs_input(dims[0]*dims[1]*dims[2]); print("Great. Calculating solutions...\n"); - SomaSolutionList solutions = solve(STD_SOMA, ArrayCount(STD_SOMA), dims); + SomaSolutionList solutions = solve(STD_SOMA, ArrayCount(STD_SOMA), (int[]){ 3, 3, 3 }); print("%zu solutions found.\n", solutions.length); } diff --git a/src/VoxelSpace.cpp b/src/VoxelSpace.c similarity index 100% rename from src/VoxelSpace.cpp rename to src/VoxelSpace.c diff --git a/src/VoxelSpace.h b/src/VoxelSpace.h index 50d020d..21c24bb 100644 --- a/src/VoxelSpace.h +++ b/src/VoxelSpace.h @@ -5,21 +5,23 @@ #define NUM_ROTS_3D 24 -typedef struct Extrema { +typedef struct Extrema Extrema; +struct Extrema { int xMax; int xMin; int yMax; int yMin; int zMax; int zMin; -} Extrema; +}; -typedef struct Space { +typedef struct Space Space; +struct Space { uint64 space; int dim_x; int dim_y; int dim_z; -} Space; +}; DefineList(Space, VoxelSpace); DefineList(uint64, VoxelSpaceRepr); diff --git a/src/gfx/Color.cpp b/src/gfx/Color.c similarity index 100% rename from src/gfx/Color.cpp rename to src/gfx/Color.c diff --git a/src/gfx/Mesh.cpp b/src/gfx/Mesh.c similarity index 100% rename from src/gfx/Mesh.cpp rename to src/gfx/Mesh.c diff --git a/src/gfx/Shader.cpp b/src/gfx/Shader.c similarity index 100% rename from src/gfx/Shader.cpp rename to src/gfx/Shader.c diff --git a/src/gfx/Texture.cpp b/src/gfx/Texture.c similarity index 100% rename from src/gfx/Texture.cpp rename to src/gfx/Texture.c diff --git a/src/gfx/geometry.cpp b/src/gfx/geometry.c similarity index 100% rename from src/gfx/geometry.cpp rename to src/gfx/geometry.c diff --git a/src/gfx/gfx.c b/src/gfx/gfx.c new file mode 100644 index 0000000..2d04e91 --- /dev/null +++ b/src/gfx/gfx.c @@ -0,0 +1,5 @@ +#include "Mesh.c" +#include "Shader.c" +#include "Texture.c" +#include "geometry.c" +#include "Color.c" diff --git a/src/gfx/gfx.cpp b/src/gfx/gfx.cpp deleted file mode 100644 index 3cab65f..0000000 --- a/src/gfx/gfx.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "Mesh.cpp" -#include "Shader.cpp" -#include "Texture.cpp" -#include "geometry.cpp" -#include "Color.cpp" diff --git a/src/lib/glad/glad.h b/src/lib/glad/glad.h index b8109f3..748bbb9 100644 --- a/src/lib/glad/glad.h +++ b/src/lib/glad/glad.h @@ -86,7 +86,7 @@ GLAPI int gladLoadGL(void); GLAPI int gladLoadGLLoader(GLADloadproc); -#include "../KHR/khrplatform.h" +#include "./khrplatform.h" typedef unsigned int GLenum; typedef unsigned char GLboolean; typedef unsigned int GLbitfield; diff --git a/src/lib/KHR/khrplatform.h b/src/lib/glad/khrplatform.h similarity index 100% rename from src/lib/KHR/khrplatform.h rename to src/lib/glad/khrplatform.h diff --git a/src/main.cpp b/src/main.c similarity index 95% rename from src/main.cpp rename to src/main.c index 3ff25c4..382f942 100644 --- a/src/main.cpp +++ b/src/main.c @@ -4,11 +4,11 @@ #define TINYOBJ_LOADER_C_IMPLEMENTATION // Project -#include "SomaSolve.cpp" -#include "gfx/gfx.cpp" -#include "world/world.cpp" -#include "VoxelSpace.cpp" -#include "./tests.cpp" +#include "SomaSolve.c" +#include "gfx/gfx.c" +#include "world/world.c" +#include "VoxelSpace.c" +#include "./tests.c" #include "lib/djstdlib/core.c" // Graphics bindings and libs @@ -16,10 +16,6 @@ #include "lib/glad/glad.c" #include "GLFW/glfw3.h" -#ifdef inline -#undef inline -#endif - void printRLVec3(RLVector3* vector) { RLVector3 vec = *vector; print( @@ -44,13 +40,14 @@ void printMatrix(Matrix* matrix) { mat.m12, mat.m13, mat.m14, mat.m15); } -typedef struct { +typedef struct Camera Camera; +struct Camera { Matrix view; Matrix proj; RLVector3 pos; RLVector3 up; RLVector3 target; -} Camera; +}; Camera *createCamera(Arena *arena, real32 aspect_ratio) { Camera *result = PushStruct(arena, Camera); @@ -70,26 +67,29 @@ void cameraSetUp(Camera *c, real32 up_x, real32 up_y, real32 up_z) { c->up = (RLVector3){up_x, up_y, up_z}; } -typedef struct { +typedef struct Frame Frame; +struct Frame { uint32 width; uint32 height; int32 x; int32 y; Camera* cam; -} Frame; +}; -typedef struct { +typedef struct Polycube Polycube; +struct Polycube { uint32 entityHandle; Space repr; RLVector4 color; -} Polycube; +}; DefineList(Polycube, Polycube); DefineList(RLVector2, RLVec2); DefineList(RLVector4, RLVec4); DefineList(real32, Float); -typedef struct { +typedef struct RenderObjects_Rectangle RenderObjects_Rectangle; +struct RenderObjects_Rectangle { uint32 vao; uint64 count; @@ -110,9 +110,10 @@ typedef struct { FloatList edgeSoftness; uint32 edgeSoftnessBufferId; -} RenderObjects_Rectangle; +}; -typedef struct { +typedef struct Input Input; +struct Input { struct { bool escape; bool enter; @@ -134,20 +135,23 @@ typedef struct { bool btnRight; bool btnMiddle; } mouse; -} Input; +}; -typedef struct { +typedef struct Renderer Renderer; +struct Renderer { Scene *scene; RenderObjects_Rectangle rects; -} Renderer; +}; -typedef struct { +typedef struct PolycubeInput PolycubeInput; +struct PolycubeInput { Space repr; RLVector4 color; -} PolycubeInput; +}; DefineList(PolycubeInput, PolycubeInput); -typedef struct { +typedef struct SomaState SomaState; +struct SomaState { bool wireframe; bool polycubeDirty; uint32 currentPolycube; @@ -158,9 +162,10 @@ typedef struct { RLVector3 rotAxisX; RLVector3 rotAxisY; PolycubeInputList polycubeInput; -} SomaState; +}; -typedef struct { +typedef struct Soma Soma; +struct Soma { Scene *scene; Renderer *renderer; SomaState state; @@ -171,7 +176,7 @@ typedef struct { uint32 width; uint32 height; } window; -} Soma; +}; void showEntity(Scene *scene, uint32 entityHandle) { SceneGraphNode *node = getSceneGraphNodeForEntity(scene, entityHandle); @@ -225,7 +230,16 @@ GLFWwindow *initWindowAndGL(uint32 windowWidth, uint32 windowHeight) { glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); - GLFWwindow *window = glfwCreateWindow(windowWidth, windowHeight, "Somaesque", NULL, NULL); + GLFWwindow *window = glfwCreateWindow( + windowWidth, + windowHeight, +#ifdef DJSTDLIB_DEBUG + "Somaesque (djstdlib_debug)", +#else + "Somaesque", +#endif + NULL, + NULL); if (window == NULL) { print("Failed to create GLFW window\n"); glfwTerminate(); @@ -250,21 +264,23 @@ void updateViewportFromFrame(uint32 windowWidth, uint32 windowHeight, Frame* fra glViewport(frame->x, windowHeight - frame->y - frame->height, frame->width, frame->height); } -typedef struct { +typedef struct UI_Context UI_Context; +struct UI_Context { Renderer *renderer; Input *prevInput; Input *input; bool cursorIsPointer; -} UI_Context; +}; -typedef struct { +typedef struct UI_Rect UI_Rect; +struct UI_Rect { real32 x; real32 y; real32 width; real32 height; real32 borderRadius; RLVector4 color; -} UI_Rect; +}; Mesh cubeMesh = {0}; Texture wallTex = {0}; @@ -583,12 +599,12 @@ void uiPass(Soma *soma, UI_Context *ui, Renderer *renderer) { for (int z = 0; z < currentPolycube->repr.dim_z; z++) { bool cellActive = filledAt(¤tPolycube->repr, x, y, z); UI_Rect rect = { - currX, - currY, - boxSize, - boxSize, - 0, - currentPolycube->color, + .x = currX, + .y = currY, + .width = boxSize, + .height = boxSize, + .borderRadius = 0, + .color = currentPolycube->color, }; if (ui_checkboxRect(ui, &cellActive, rect)) { soma->state.polycubeDirty = true; @@ -603,7 +619,7 @@ void uiPass(Soma *soma, UI_Context *ui, Renderer *renderer) { } int mainCmd() { - interactive_cmd_line_solve_soma(); + interactiveCmdLineSolveSoma(); return 0; } diff --git a/src/tests.cpp b/src/tests.c similarity index 99% rename from src/tests.cpp rename to src/tests.c index adeeddf..25e94a0 100644 --- a/src/tests.cpp +++ b/src/tests.c @@ -1,11 +1,12 @@ #include "VoxelSpace.h" #include "lib/djstdlib/core.h" -typedef struct MismatchData { +typedef struct MismatchData MismatchData; +struct MismatchData { int i; uint64 actual; uint64 expected; -} MismatchData; +}; DefineList(MismatchData, MismatchData); void test() { diff --git a/src/world/scene.cpp b/src/world/scene.c similarity index 100% rename from src/world/scene.cpp rename to src/world/scene.c diff --git a/src/world/scene.h b/src/world/scene.h index a4f96bd..3d83d3b 100644 --- a/src/world/scene.h +++ b/src/world/scene.h @@ -9,15 +9,17 @@ enum EntityFlags { EntityFlags_Render=1<<2, }; -typedef struct { +typedef struct Entity Entity; +struct Entity { Mesh *mesh; Texture *tex; uint32 graphNodeHandle; uint64 flags; -} Entity; +}; DefineList(Entity, Entity); -typedef struct { +typedef struct SceneGraphNode SceneGraphNode; +struct SceneGraphNode { Matrix local; Matrix world; RLVector3 translation; @@ -26,14 +28,15 @@ typedef struct { HandleList children; uint32 entityHandle; uint32 parentHandle; -} SceneGraphNode; +}; DefineList(SceneGraphNode, SceneGraphNode); -typedef struct { +typedef struct Scene Scene; +struct Scene { uint32 sceneRoot; EntityList entities; SceneGraphNodeList graphNodes; -} Scene; +}; uint32 createEntity(Arena *arena, Scene *s); Entity *getEntity(Scene *s, uint32 id); diff --git a/src/world/world.c b/src/world/world.c new file mode 100644 index 0000000..9484efa --- /dev/null +++ b/src/world/world.c @@ -0,0 +1 @@ +#include "scene.c" diff --git a/src/world/world.cpp b/src/world/world.cpp deleted file mode 100644 index f00cc77..0000000 --- a/src/world/world.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "scene.cpp"