rename c files
This commit is contained in:
2
build
2
build
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
LIB_INCLUDE="-lglfw -lGL -lm"
|
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
|
./target/somaesque
|
||||||
|
|
||||||
|
|||||||
@@ -67,11 +67,12 @@ std::vector<uint64> get_reprs_input(int units_required) {
|
|||||||
|
|
||||||
DefineList(size_t, Offset);
|
DefineList(size_t, Offset);
|
||||||
|
|
||||||
typedef struct Solver {
|
typedef struct Solver Solver;
|
||||||
|
struct Solver {
|
||||||
VoxelSpaceReprList *input;
|
VoxelSpaceReprList *input;
|
||||||
OffsetList *offsets;
|
OffsetList *offsets;
|
||||||
SomaSolutionList *solutions;
|
SomaSolutionList *solutions;
|
||||||
} Solver;
|
};
|
||||||
|
|
||||||
uint64 STD_SOMA[] = { 23ul, 30ul, 15ul, 1043ul, 24594ul, 12306ul, 11ul };
|
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();
|
return (SomaSolutionList)EmptyList();
|
||||||
}
|
}
|
||||||
SomaSolutionList uniqueSolns = PushList(arena, SomaSolutionList, solutions->length);
|
SomaSolutionList uniqueSolns = PushList(arena, SomaSolutionList, solutions->length);
|
||||||
for (EachIn(*solutions, i)) {
|
for (EachEl(*solutions, SomaSolution, solution)) {
|
||||||
SomaSolution solution = solutions->data[i];
|
|
||||||
bool foundMatch = false;
|
bool foundMatch = false;
|
||||||
Scratch temp = scratchStart(&arena, 1);
|
Scratch temp = scratchStart(&arena, 1);
|
||||||
SomaSolutionList rots = getSolutionRotations(temp.arena, &solution, dims);
|
SomaSolutionList rots = getSolutionRotations(temp.arena, solution, dims);
|
||||||
for (EachIn(rots, j)) {
|
for (EachEl(rots, SomaSolution, rotation)) {
|
||||||
SomaSolution rotation = rots.data[j];
|
for (EachEl(uniqueSolns, SomaSolution, unique_soln)) {
|
||||||
for (EachIn(uniqueSolns, k)) {
|
|
||||||
SomaSolution unique_soln = uniqueSolns.data[k];
|
|
||||||
bool isMatch = true;
|
bool isMatch = true;
|
||||||
for (EachIn(unique_soln, piece_i)) {
|
for (EachIn(*unique_soln, piece_i)) {
|
||||||
if (rotation.data[piece_i] != unique_soln.data[piece_i]) {
|
if (rotation->data[piece_i] != unique_soln->data[piece_i]) {
|
||||||
isMatch = false;
|
isMatch = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -206,10 +204,10 @@ SomaSolutionList filterUnique(Arena *arena, SomaSolutionList *solutions, int dim
|
|||||||
}
|
}
|
||||||
scratchEnd(temp);
|
scratchEnd(temp);
|
||||||
if (!foundMatch) {
|
if (!foundMatch) {
|
||||||
SomaSolution solutionCopy = PushList(arena, SomaSolution, solution.length);
|
SomaSolution solutionCopy = PushList(arena, SomaSolution, solution->length);
|
||||||
solutionCopy.capacity = solution.length;
|
solutionCopy.capacity = solution->length;
|
||||||
solutionCopy.length = solution.length;
|
solutionCopy.length = solution->length;
|
||||||
memcpy(solutionCopy.data, solution.data, ListElementSize(SomaSolutionList) * solution.length);
|
memcpy(solutionCopy.data, solution->data, ListElementSize(SomaSolutionList) * solution->length);
|
||||||
AppendList(&uniqueSolns, solutionCopy);
|
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() {
|
void interactiveCmdLineSolveSoma() {
|
||||||
int dims[3] = { 3, 3, 3 };
|
|
||||||
//get_dims_input(dims);
|
//get_dims_input(dims);
|
||||||
//std::cout << '\n';
|
//std::cout << '\n';
|
||||||
//std::vector<uint64> reprs = get_reprs_input(dims[0]*dims[1]*dims[2]);
|
//std::vector<uint64> reprs = get_reprs_input(dims[0]*dims[1]*dims[2]);
|
||||||
print("Great. Calculating solutions...\n");
|
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);
|
print("%zu solutions found.\n", solutions.length);
|
||||||
}
|
}
|
||||||
@@ -5,21 +5,23 @@
|
|||||||
|
|
||||||
#define NUM_ROTS_3D 24
|
#define NUM_ROTS_3D 24
|
||||||
|
|
||||||
typedef struct Extrema {
|
typedef struct Extrema Extrema;
|
||||||
|
struct Extrema {
|
||||||
int xMax;
|
int xMax;
|
||||||
int xMin;
|
int xMin;
|
||||||
int yMax;
|
int yMax;
|
||||||
int yMin;
|
int yMin;
|
||||||
int zMax;
|
int zMax;
|
||||||
int zMin;
|
int zMin;
|
||||||
} Extrema;
|
};
|
||||||
|
|
||||||
typedef struct Space {
|
typedef struct Space Space;
|
||||||
|
struct Space {
|
||||||
uint64 space;
|
uint64 space;
|
||||||
int dim_x;
|
int dim_x;
|
||||||
int dim_y;
|
int dim_y;
|
||||||
int dim_z;
|
int dim_z;
|
||||||
} Space;
|
};
|
||||||
|
|
||||||
DefineList(Space, VoxelSpace);
|
DefineList(Space, VoxelSpace);
|
||||||
DefineList(uint64, VoxelSpaceRepr);
|
DefineList(uint64, VoxelSpaceRepr);
|
||||||
|
|||||||
5
src/gfx/gfx.c
Normal file
5
src/gfx/gfx.c
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#include "Mesh.c"
|
||||||
|
#include "Shader.c"
|
||||||
|
#include "Texture.c"
|
||||||
|
#include "geometry.c"
|
||||||
|
#include "Color.c"
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
#include "Mesh.cpp"
|
|
||||||
#include "Shader.cpp"
|
|
||||||
#include "Texture.cpp"
|
|
||||||
#include "geometry.cpp"
|
|
||||||
#include "Color.cpp"
|
|
||||||
@@ -86,7 +86,7 @@ GLAPI int gladLoadGL(void);
|
|||||||
|
|
||||||
GLAPI int gladLoadGLLoader(GLADloadproc);
|
GLAPI int gladLoadGLLoader(GLADloadproc);
|
||||||
|
|
||||||
#include "../KHR/khrplatform.h"
|
#include "./khrplatform.h"
|
||||||
typedef unsigned int GLenum;
|
typedef unsigned int GLenum;
|
||||||
typedef unsigned char GLboolean;
|
typedef unsigned char GLboolean;
|
||||||
typedef unsigned int GLbitfield;
|
typedef unsigned int GLbitfield;
|
||||||
|
|||||||
@@ -4,11 +4,11 @@
|
|||||||
#define TINYOBJ_LOADER_C_IMPLEMENTATION
|
#define TINYOBJ_LOADER_C_IMPLEMENTATION
|
||||||
|
|
||||||
// Project
|
// Project
|
||||||
#include "SomaSolve.cpp"
|
#include "SomaSolve.c"
|
||||||
#include "gfx/gfx.cpp"
|
#include "gfx/gfx.c"
|
||||||
#include "world/world.cpp"
|
#include "world/world.c"
|
||||||
#include "VoxelSpace.cpp"
|
#include "VoxelSpace.c"
|
||||||
#include "./tests.cpp"
|
#include "./tests.c"
|
||||||
#include "lib/djstdlib/core.c"
|
#include "lib/djstdlib/core.c"
|
||||||
|
|
||||||
// Graphics bindings and libs
|
// Graphics bindings and libs
|
||||||
@@ -16,10 +16,6 @@
|
|||||||
#include "lib/glad/glad.c"
|
#include "lib/glad/glad.c"
|
||||||
#include "GLFW/glfw3.h"
|
#include "GLFW/glfw3.h"
|
||||||
|
|
||||||
#ifdef inline
|
|
||||||
#undef inline
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void printRLVec3(RLVector3* vector) {
|
void printRLVec3(RLVector3* vector) {
|
||||||
RLVector3 vec = *vector;
|
RLVector3 vec = *vector;
|
||||||
print(
|
print(
|
||||||
@@ -44,13 +40,14 @@ void printMatrix(Matrix* matrix) {
|
|||||||
mat.m12, mat.m13, mat.m14, mat.m15);
|
mat.m12, mat.m13, mat.m14, mat.m15);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct Camera Camera;
|
||||||
|
struct Camera {
|
||||||
Matrix view;
|
Matrix view;
|
||||||
Matrix proj;
|
Matrix proj;
|
||||||
RLVector3 pos;
|
RLVector3 pos;
|
||||||
RLVector3 up;
|
RLVector3 up;
|
||||||
RLVector3 target;
|
RLVector3 target;
|
||||||
} Camera;
|
};
|
||||||
|
|
||||||
Camera *createCamera(Arena *arena, real32 aspect_ratio) {
|
Camera *createCamera(Arena *arena, real32 aspect_ratio) {
|
||||||
Camera *result = PushStruct(arena, Camera);
|
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};
|
c->up = (RLVector3){up_x, up_y, up_z};
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct Frame Frame;
|
||||||
|
struct Frame {
|
||||||
uint32 width;
|
uint32 width;
|
||||||
uint32 height;
|
uint32 height;
|
||||||
int32 x;
|
int32 x;
|
||||||
int32 y;
|
int32 y;
|
||||||
Camera* cam;
|
Camera* cam;
|
||||||
} Frame;
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct Polycube Polycube;
|
||||||
|
struct Polycube {
|
||||||
uint32 entityHandle;
|
uint32 entityHandle;
|
||||||
Space repr;
|
Space repr;
|
||||||
RLVector4 color;
|
RLVector4 color;
|
||||||
} Polycube;
|
};
|
||||||
DefineList(Polycube, Polycube);
|
DefineList(Polycube, Polycube);
|
||||||
|
|
||||||
DefineList(RLVector2, RLVec2);
|
DefineList(RLVector2, RLVec2);
|
||||||
DefineList(RLVector4, RLVec4);
|
DefineList(RLVector4, RLVec4);
|
||||||
DefineList(real32, Float);
|
DefineList(real32, Float);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct RenderObjects_Rectangle RenderObjects_Rectangle;
|
||||||
|
struct RenderObjects_Rectangle {
|
||||||
uint32 vao;
|
uint32 vao;
|
||||||
uint64 count;
|
uint64 count;
|
||||||
|
|
||||||
@@ -110,9 +110,10 @@ typedef struct {
|
|||||||
|
|
||||||
FloatList edgeSoftness;
|
FloatList edgeSoftness;
|
||||||
uint32 edgeSoftnessBufferId;
|
uint32 edgeSoftnessBufferId;
|
||||||
} RenderObjects_Rectangle;
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct Input Input;
|
||||||
|
struct Input {
|
||||||
struct {
|
struct {
|
||||||
bool escape;
|
bool escape;
|
||||||
bool enter;
|
bool enter;
|
||||||
@@ -134,20 +135,23 @@ typedef struct {
|
|||||||
bool btnRight;
|
bool btnRight;
|
||||||
bool btnMiddle;
|
bool btnMiddle;
|
||||||
} mouse;
|
} mouse;
|
||||||
} Input;
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct Renderer Renderer;
|
||||||
|
struct Renderer {
|
||||||
Scene *scene;
|
Scene *scene;
|
||||||
RenderObjects_Rectangle rects;
|
RenderObjects_Rectangle rects;
|
||||||
} Renderer;
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct PolycubeInput PolycubeInput;
|
||||||
|
struct PolycubeInput {
|
||||||
Space repr;
|
Space repr;
|
||||||
RLVector4 color;
|
RLVector4 color;
|
||||||
} PolycubeInput;
|
};
|
||||||
DefineList(PolycubeInput, PolycubeInput);
|
DefineList(PolycubeInput, PolycubeInput);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct SomaState SomaState;
|
||||||
|
struct SomaState {
|
||||||
bool wireframe;
|
bool wireframe;
|
||||||
bool polycubeDirty;
|
bool polycubeDirty;
|
||||||
uint32 currentPolycube;
|
uint32 currentPolycube;
|
||||||
@@ -158,9 +162,10 @@ typedef struct {
|
|||||||
RLVector3 rotAxisX;
|
RLVector3 rotAxisX;
|
||||||
RLVector3 rotAxisY;
|
RLVector3 rotAxisY;
|
||||||
PolycubeInputList polycubeInput;
|
PolycubeInputList polycubeInput;
|
||||||
} SomaState;
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct Soma Soma;
|
||||||
|
struct Soma {
|
||||||
Scene *scene;
|
Scene *scene;
|
||||||
Renderer *renderer;
|
Renderer *renderer;
|
||||||
SomaState state;
|
SomaState state;
|
||||||
@@ -171,7 +176,7 @@ typedef struct {
|
|||||||
uint32 width;
|
uint32 width;
|
||||||
uint32 height;
|
uint32 height;
|
||||||
} window;
|
} window;
|
||||||
} Soma;
|
};
|
||||||
|
|
||||||
void showEntity(Scene *scene, uint32 entityHandle) {
|
void showEntity(Scene *scene, uint32 entityHandle) {
|
||||||
SceneGraphNode *node = getSceneGraphNodeForEntity(scene, 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_MAJOR, 4);
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
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) {
|
if (window == NULL) {
|
||||||
print("Failed to create GLFW window\n");
|
print("Failed to create GLFW window\n");
|
||||||
glfwTerminate();
|
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);
|
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;
|
Renderer *renderer;
|
||||||
Input *prevInput;
|
Input *prevInput;
|
||||||
Input *input;
|
Input *input;
|
||||||
bool cursorIsPointer;
|
bool cursorIsPointer;
|
||||||
} UI_Context;
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct UI_Rect UI_Rect;
|
||||||
|
struct UI_Rect {
|
||||||
real32 x;
|
real32 x;
|
||||||
real32 y;
|
real32 y;
|
||||||
real32 width;
|
real32 width;
|
||||||
real32 height;
|
real32 height;
|
||||||
real32 borderRadius;
|
real32 borderRadius;
|
||||||
RLVector4 color;
|
RLVector4 color;
|
||||||
} UI_Rect;
|
};
|
||||||
|
|
||||||
Mesh cubeMesh = {0};
|
Mesh cubeMesh = {0};
|
||||||
Texture wallTex = {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++) {
|
for (int z = 0; z < currentPolycube->repr.dim_z; z++) {
|
||||||
bool cellActive = filledAt(¤tPolycube->repr, x, y, z);
|
bool cellActive = filledAt(¤tPolycube->repr, x, y, z);
|
||||||
UI_Rect rect = {
|
UI_Rect rect = {
|
||||||
currX,
|
.x = currX,
|
||||||
currY,
|
.y = currY,
|
||||||
boxSize,
|
.width = boxSize,
|
||||||
boxSize,
|
.height = boxSize,
|
||||||
0,
|
.borderRadius = 0,
|
||||||
currentPolycube->color,
|
.color = currentPolycube->color,
|
||||||
};
|
};
|
||||||
if (ui_checkboxRect(ui, &cellActive, rect)) {
|
if (ui_checkboxRect(ui, &cellActive, rect)) {
|
||||||
soma->state.polycubeDirty = true;
|
soma->state.polycubeDirty = true;
|
||||||
@@ -603,7 +619,7 @@ void uiPass(Soma *soma, UI_Context *ui, Renderer *renderer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int mainCmd() {
|
int mainCmd() {
|
||||||
interactive_cmd_line_solve_soma();
|
interactiveCmdLineSolveSoma();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
#include "VoxelSpace.h"
|
#include "VoxelSpace.h"
|
||||||
#include "lib/djstdlib/core.h"
|
#include "lib/djstdlib/core.h"
|
||||||
|
|
||||||
typedef struct MismatchData {
|
typedef struct MismatchData MismatchData;
|
||||||
|
struct MismatchData {
|
||||||
int i;
|
int i;
|
||||||
uint64 actual;
|
uint64 actual;
|
||||||
uint64 expected;
|
uint64 expected;
|
||||||
} MismatchData;
|
};
|
||||||
DefineList(MismatchData, MismatchData);
|
DefineList(MismatchData, MismatchData);
|
||||||
|
|
||||||
void test() {
|
void test() {
|
||||||
@@ -9,15 +9,17 @@ enum EntityFlags {
|
|||||||
EntityFlags_Render=1<<2,
|
EntityFlags_Render=1<<2,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
typedef struct Entity Entity;
|
||||||
|
struct Entity {
|
||||||
Mesh *mesh;
|
Mesh *mesh;
|
||||||
Texture *tex;
|
Texture *tex;
|
||||||
uint32 graphNodeHandle;
|
uint32 graphNodeHandle;
|
||||||
uint64 flags;
|
uint64 flags;
|
||||||
} Entity;
|
};
|
||||||
DefineList(Entity, Entity);
|
DefineList(Entity, Entity);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct SceneGraphNode SceneGraphNode;
|
||||||
|
struct SceneGraphNode {
|
||||||
Matrix local;
|
Matrix local;
|
||||||
Matrix world;
|
Matrix world;
|
||||||
RLVector3 translation;
|
RLVector3 translation;
|
||||||
@@ -26,14 +28,15 @@ typedef struct {
|
|||||||
HandleList children;
|
HandleList children;
|
||||||
uint32 entityHandle;
|
uint32 entityHandle;
|
||||||
uint32 parentHandle;
|
uint32 parentHandle;
|
||||||
} SceneGraphNode;
|
};
|
||||||
DefineList(SceneGraphNode, SceneGraphNode);
|
DefineList(SceneGraphNode, SceneGraphNode);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct Scene Scene;
|
||||||
|
struct Scene {
|
||||||
uint32 sceneRoot;
|
uint32 sceneRoot;
|
||||||
EntityList entities;
|
EntityList entities;
|
||||||
SceneGraphNodeList graphNodes;
|
SceneGraphNodeList graphNodes;
|
||||||
} Scene;
|
};
|
||||||
|
|
||||||
uint32 createEntity(Arena *arena, Scene *s);
|
uint32 createEntity(Arena *arena, Scene *s);
|
||||||
Entity *getEntity(Scene *s, uint32 id);
|
Entity *getEntity(Scene *s, uint32 id);
|
||||||
|
|||||||
1
src/world/world.c
Normal file
1
src/world/world.c
Normal file
@@ -0,0 +1 @@
|
|||||||
|
#include "scene.c"
|
||||||
@@ -1 +0,0 @@
|
|||||||
#include "scene.cpp"
|
|
||||||
Reference in New Issue
Block a user