rename c files
This commit is contained in:
2
build
2
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
|
||||
|
||||
|
||||
@@ -67,11 +67,12 @@ std::vector<uint64> 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<uint64> 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);
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
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);
|
||||
|
||||
#include "../KHR/khrplatform.h"
|
||||
#include "./khrplatform.h"
|
||||
typedef unsigned int GLenum;
|
||||
typedef unsigned char GLboolean;
|
||||
typedef unsigned int GLbitfield;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
@@ -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);
|
||||
|
||||
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