This commit is contained in:
2025-01-05 12:51:17 +00:00
parent 2daee71548
commit 595259b2cc
10 changed files with 106 additions and 105 deletions

View File

@@ -1,4 +1,4 @@
CompileFlags:
Add:
- -DOS_LINUX
- -I ./
- -DOS_WINDOWS
- "-IC:\\source\\libs\\include"

View File

@@ -2,14 +2,16 @@
if NOT EXIST .\target mkdir .\target
set commonLinkerFlags=-opt:ref
set commonCompilerFlags=^
set LIBRARIES_ROOT="C:\source\libs"
set INCLUDE_ROOT="C:\source\libs\include"
set LINK_LIBRARIES=".\glfw\glfw3.lib" "user32.lib" "gdi32.lib" "opengl32.lib" "shell32.lib" "kernel32.lib"
set COMMON_LINKER_FLAGS=-opt:ref /LIBPATH:%LIBRARIES_ROOT% /NODEFAULTLIB:libcmt.lib
set COMMON_COMPILER_FLAGS=^
-MT %= Make sure the C runtime library is statically linked =%^
-Gm- %= Turns off incremental building =%^
-nologo %= No one cares you made the compiler Microsoft =%^
-Oi %= Always use intrinsics =%^
-EHa- %= Disable exception handling =%^
-GR- %= Never use runtime type info from C++ =%^
-WX -W4 -wd4201 -wd4100 -wd4189 -wd4505 %= Compiler warnings, -WX warnings as errors, -W4 warning level 4, -wdXXXX disable warning XXXX =%^
-DAPP_DEBUG=0 -DENABLE_ASSERT=1 -DOS_WINDOWS=1 %= Custom #defines =%^
-D_CRT_SECURE_NO_WARNINGS=1^
@@ -17,7 +19,7 @@ set commonCompilerFlags=^
-Zi %= Generate debugger info =%
pushd .\target
cl %commonCompilerFlags% -Fe:.\app.exe ..\app.cpp /link -incremental:no %commonLinkerFlags%
cl %COMMON_COMPILER_FLAGS% /EHsc /I %INCLUDE_ROOT% -Fe:.\somaesque.exe ..\src\main.cpp /link -incremental:no %COMMON_LINKER_FLAGS% %LINK_LIBRARIES%
popd
exit /b

View File

@@ -45,9 +45,9 @@ std::vector<uint64> get_reprs_input(int units_required) {
uint64 bit_repr = 0;
int i = 0;
bool good_repr = true;
for (std::reverse_iterator it = input.rbegin(); it < input.rend(); it++, i++) {
for (auto it = input.rbegin(); it < input.rend(); it++, i++) {
if (*it == '1') {
bit_repr |= 1 << i;
bit_repr |= 1ull << i;
total_units++;
} else if (*it != '0' || i >= 64) {
std::cout << "Input invalid. Enter a binary string only with max 64 bits." << '\n';
@@ -73,7 +73,7 @@ struct Solver {
uint64 STD_SOMA[] = { 23ul, 30ul, 15ul, 1043ul, 24594ul, 12306ul, 11ul };
void backtrack_solve_iter(std::vector<uint64> *polycube_input, std::vector<int> *offsets) {
int num_inputs = offsets->size() - 1;
size_t num_inputs = offsets->size() - 1;
std::vector<int> solns = std::vector<int>();
@@ -124,10 +124,10 @@ void backtrack_solve(Solver *solver, uint64 working_solution = 0, size_t curr_pi
list<uint64> *input = solver->input;
list<size_t> *offsets = solver->offsets;
std::vector<SomaSolution> *solutions = solver->solutions;
int start = offsets->data[curr_piece];
int end = offsets->data[curr_piece + 1];
size_t start = offsets->data[curr_piece];
size_t end = offsets->data[curr_piece + 1];
size_t num_pieces = offsets->length - 1;
for (int i = start; i < end; i++) {
for (size_t i = start; i < end; i++) {
bool successful_fuse = !collides(working_solution, input->data[i]);
if (successful_fuse) {
uint64 new_working_solution = working_solution | input->data[i];
@@ -206,25 +206,29 @@ std::vector<SomaSolution> solve(uint64 *reprs_in, uint32 reprs_in_count, int dim
list<uint64> polycubes = PushList(arena, uint64, 0);
Space model_space = {
Space empty_voxel_space = {
{},
dims[0],
dims[1],
dims[2],
};
appendList(&offsets, 0ul);
Space space = model_space;
space.space = reprs_in[0];
cullEmptySpace(&space);
list<uint64> positions = getAllPositionsInPrism(arena, &space, dims);
polycubes.length += positions.length;
polycubes.head += positions.head;
memcpy(polycubes.data, positions.data, positions.length / sizeof(uint64));
appendList(&offsets, (size_t)0);
for (int i = 1; i < reprs_in_count; i++) {
list<uint64> positions = {};
{
Space space = empty_voxel_space;
space.space = reprs_in[0];
cullEmptySpace(&space);
positions = getAllPositionsInPrism(arena, &space, dims);
polycubes.length += positions.length;
polycubes.head += positions.head;
memcpy(polycubes.data, positions.data, positions.length / sizeof(uint64));
};
for (size_t i = 1; i < reprs_in_count; i++) {
appendList(&offsets, polycubes.length);
Space space = model_space;
Space space = empty_voxel_space;
space.space = reprs_in[i];
cullEmptySpace(&space);
list<uint64> perms = getAllPermutationsInPrism(permsArena, &space, dims);

View File

@@ -1,7 +1,5 @@
#include <cstring>
#include <cstdint>
#include <iostream>
#include <ostream>
#include "VoxelSpace.h"
#include "lib/djstdlib/core.h"
@@ -36,21 +34,21 @@ int newIndexRotZ(Space *space, int x, int y, int z) {
return space->dim_x * space->dim_z * (space->dim_y - 1 - y) + space->dim_z * x + z;
}
uint64 toggle(uint64_t space, int index) {
space ^= 1ul << index;
uint64 toggle(uint64 space, int index) {
space ^= 1ull << index;
return space;
}
uint64 set(uint64_t space, int index, bool val) {
uint64 set(uint64 space, int index, bool val) {
if (val) {
space |= 1ul << index;
space |= 1ull << index;
} else {
space &= ~(1ul << index);
space &= ~(1ull << index);
}
return space;
}
bool collides(uint64_t a, uint64_t b) {
bool collides(uint64 a, uint64 b) {
return (a | b) != (a ^ b);
}
@@ -59,8 +57,8 @@ bool collides(Space *a, Space *b) {
}
bool filledAt(Space *space, int x, int y, int z) {
uint64 mask = 1ul << (space->dim_y * space->dim_z * x + space->dim_z * y + z);
return (space->space & mask) != 0ul;
uint64 mask = 1ull << (space->dim_y * space->dim_z * x + space->dim_z * y + z);
return (space->space & mask) != 0ull;
}
Extrema getExtrema(Space *space) {
@@ -94,12 +92,12 @@ Extrema getExtrema(Space *space) {
void cullEmptySpace(Space *space) {
Extrema extrema = getExtrema(space);
int space_index = 0;
uint64 newSpace = 0ul;
uint64 newSpace = 0ull;
for (int x = extrema.xMin; x <= extrema.xMax; x++) {
for (int y = extrema.yMin; y <= extrema.yMax; y++) {
for (int z = extrema.zMin; z <= extrema.zMax; z++) {
if (filledAt(space, x, y, z)) {
newSpace |= 1ul << space_index;
newSpace |= 1ull << space_index;
}
space_index++;
}
@@ -117,7 +115,7 @@ void rotate90X(Space *space) {
for (int y = 0; y < space->dim_y; y++) {
for (int z = 0; z < space->dim_z; z++) {
if (filledAt(space, x, y, z)) {
new_space |= 1 << newIndexRotX(space, x, y, z);
new_space |= 1ull << newIndexRotX(space, x, y, z);
}
}
}
@@ -134,7 +132,7 @@ void rotate90Y(Space *space) {
for (int y = 0; y < space->dim_y; y++) {
for (int z = 0; z < space->dim_z; z++) {
if (filledAt(space, x, y, z)) {
new_space |= 1 << newIndexRotY(space, x, y, z);
new_space |= 1ull << newIndexRotY(space, x, y, z);
}
}
}
@@ -151,7 +149,7 @@ void rotate90Z(Space *space) {
for (int y = 0; y < space->dim_y; y++) {
for (int z = 0; z < space->dim_z; z++) {
if (filledAt(space, x, y, z)) {
new_space |= 1 << newIndexRotZ(space, x, y, z);
new_space |= 1ull << newIndexRotZ(space, x, y, z);
}
}
}
@@ -178,8 +176,8 @@ void pushNewUniqueSpins(list<Space> *existingSpaces, Space* spaceToSpin) {
}
for (int i = 0; i < 4; i++) {
bool matchFound = false;
for (EachIn(*existingSpaces, i)) {
if (isMatch(&existingSpaces->data[i], &spins[i])) {
for (EachIn(*existingSpaces, j)) {
if (isMatch(&existingSpaces->data[j], &spins[i])) {
matchFound = true;
break;
}
@@ -286,10 +284,10 @@ list<uint64> getAllPermutationsInPrism(Arena *arena, Space *space, int prism_dim
return result;
}
int size(uint64_t space) {
int size(uint64 space) {
int size = 0;
for (int i = 0; i < 64; i++) {
if ((space & (1ul << i)) != 0) {
if ((space & (1ull << i)) != 0) {
size++;
}
}

View File

@@ -2,15 +2,16 @@
#define LEDDA_MESH_H
#include "../lib/glad/glad.h"
#include "../lib/djstdlib/core.h"
#include "geometry.h"
struct Mesh {
unsigned int vao;
unsigned int vbo_xyz;
unsigned int vbo_uv;
unsigned int vbo_norm;
unsigned int ebo;
unsigned int num_indices;
uint32 vao;
uint32 vbo_xyz;
uint32 vbo_uv;
uint32 vbo_norm;
uint32 ebo;
uint64 num_indices;
};
Mesh createMesh(const char* obj_file);

View File

@@ -83,28 +83,28 @@ uint32 square_indices[] = {
};
const Shape TRIANGLE = {
.indices = triangle_indices,
.indices_size = ArrayCount(triangle_indices),
.uv = triangle_vertices,
.uv_size = ArrayCount(triangle_vertices),
.xyz = triangle_vertices,
.xyz_size = ArrayCount(triangle_vertices),
triangle_indices,
ArrayCount(triangle_indices),
triangle_vertices,
ArrayCount(triangle_vertices),
triangle_vertices,
ArrayCount(triangle_vertices),
};
const Shape SQUARE = {
.indices = square_indices,
.indices_size = ArrayCount(square_indices),
.uv = square_uv,
.uv_size = ArrayCount(square_uv),
.xyz = square_xyz,
.xyz_size = ArrayCount(square_xyz),
square_indices,
ArrayCount(square_indices),
square_uv,
ArrayCount(square_uv),
square_xyz,
ArrayCount(square_xyz),
};
const Shape CUBE = {
.indices = cube_indices,
.indices_size = ArrayCount(cube_indices),
.uv = triangle_vertices,
.uv_size = ArrayCount(triangle_vertices),
.xyz = triangle_vertices,
.xyz_size = ArrayCount(triangle_vertices),
cube_indices,
ArrayCount(cube_indices),
triangle_vertices,
ArrayCount(triangle_vertices),
triangle_vertices,
ArrayCount(triangle_vertices),
};

View File

@@ -1,6 +1,5 @@
#include <iostream>
#include <ostream>
#include <unistd.h> // TODO(djledda): get outta here
#include <math.h>
#include <string.h>
#include "core.h"
@@ -93,7 +92,7 @@ void zeroList(list<T> *list) {
memset(list->data, 0, list->head * sizeof(T));
}
inline string operator""_s(const char *cstrLiteral, unsigned long length) {
inline string operator""_s(const char *cstrLiteral, size_t length) {
return {
(char *)cstrLiteral,
length,

View File

@@ -151,7 +151,7 @@ struct string {
#define strlit(lit) (string{(char *)(lit), sizeof(lit) - 1})
#define PushString(arena, length) (string{ (char *)pushSize(arena, length), (length) })
string operator""_s(const char *cstrLiteral, unsigned long length);
string operator""_s(const char *cstrLiteral, size_t length);
// C Strings
const char *cstring(Arena *arena, list<char> buf);

View File

@@ -86,7 +86,7 @@ GLAPI int gladLoadGL(void);
GLAPI int gladLoadGLLoader(GLADloadproc);
#include <KHR/khrplatform.h>
#include "../KHR/khrplatform.h"
typedef unsigned int GLenum;
typedef unsigned char GLboolean;
typedef unsigned int GLbitfield;

View File

@@ -1,11 +1,11 @@
#include <iostream>
#include <vector>
#include <optional>
#include "lib/djstdlib/core.h"
#include "lib/glad/glad.c"
#include "lib/djstdlib/core.h"
#include <GLFW/glfw3.h>
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/ext/matrix_transform.hpp>
#include <glm/glm.hpp>
#include <glm/gtx/quaternion.hpp>
@@ -23,10 +23,10 @@
struct Entity;
struct Polycube;
struct SceneGraphNode;
int new_entity();
uint32 new_entity();
Entity *get_entity(int id);
SceneGraphNode *get_scene_graph_node(int id);
int new_graph_node();
uint32 new_graph_node();
void print_mat(glm::mat4* matrix) {
glm::mat4 mat = *matrix;
@@ -70,7 +70,7 @@ struct GlobalAppState {
std::vector<Polycube> polycubes;
};
GlobalAppState app_state;
GlobalAppState app_state = {};
struct WindowDims {
uint32 width;
@@ -91,7 +91,7 @@ struct SceneGraphNode {
glm::quat rotation;
glm::vec3 scale;
std::vector<uint32> children;
std::optional<uint32> entity;
uint32 entity;
};
void init_sg_node(SceneGraphNode *n) {
@@ -120,9 +120,9 @@ struct Polycube {
void show_polycube(Polycube *p) {
SceneGraphNode *node = get_scene_graph_node(p->graph_node);
for (uint32 &child : node->children) {
SceneGraphNode *node = get_scene_graph_node(child);
if (node->entity) {
get_entity(*node->entity)->visible = true;
SceneGraphNode *subNode = get_scene_graph_node(child);
if (subNode->entity) {
get_entity(subNode->entity)->visible = true;
}
}
}
@@ -130,9 +130,9 @@ void show_polycube(Polycube *p) {
void hide_polycube(Polycube *p) {
SceneGraphNode *node = get_scene_graph_node(p->graph_node);
for (uint32 &child : node->children) {
SceneGraphNode *node = get_scene_graph_node(child);
if (node->entity) {
get_entity(*node->entity)->visible = false;
SceneGraphNode *subNode = get_scene_graph_node(child);
if (subNode->entity) {
get_entity(subNode->entity)->visible = false;
}
}
}
@@ -154,7 +154,7 @@ struct Frame {
Camera* cam;
};
Frame createFrame(Arena *arena, uint32 width, uint32 height, real32 x, real32 y) {
Frame createFrame(Arena *arena, uint32 width, uint32 height, uint32 x, uint32 y) {
Frame result = {0};
result.width = width;
result.height = height;
@@ -231,12 +231,12 @@ void process_input(GLFWwindow *window) {
}
int new_entity() {
uint32 new_entity() {
entities.emplace_back();
scene_graph_nodes.emplace_back();
entities.back().scene_graph_node = scene_graph_nodes.size();
scene_graph_nodes.back().entity = entities.size();
return entities.size();
entities.back().scene_graph_node = (uint32)scene_graph_nodes.size();
scene_graph_nodes.back().entity = (uint32)entities.size();
return (uint32)entities.size();
}
Entity *get_entity(int id) {
@@ -247,13 +247,13 @@ SceneGraphNode *get_scene_graph_node(int id) {
return &scene_graph_nodes[id - 1];
}
int new_graph_node() {
uint32 new_graph_node() {
scene_graph_nodes.emplace_back();
return scene_graph_nodes.size();
return (uint32)scene_graph_nodes.size();
}
Polycube create_polycube_from_repr(Space *repr) {
int polycube_id = new_graph_node();
uint32 polycube_id = new_graph_node();
init_sg_node(get_scene_graph_node(polycube_id));
for (int x = 0; x < repr->dim_x; x++) {
for (int y = 0; y < repr->dim_y; y++) {
@@ -275,10 +275,9 @@ Polycube create_polycube_from_repr(Space *repr) {
}
}
}
Polycube result = {
.graph_node=polycube_id,
.color=glm::vec3(1.0f),
};
Polycube result = {};
result.graph_node = polycube_id;
result.color = glm::vec3(1.0f);
return result;
}
@@ -308,12 +307,10 @@ int main_gfx() {
Arena *arena = arenaAlloc(Megabytes(128));
app_state = {
.current_polycube=0,
.last_polycube_visible=6,
.active_shader=0,
.polycubes={},
};
app_state.current_polycube=0;
app_state.last_polycube_visible=6;
app_state.active_shader=0;
app_state.polycubes={};
Shader phong_shader = createShader("../assets/shaders/phong-solid.vertex.glsl", "../assets/shaders/phong-solid.fragment.glsl");
app_state.active_shader = &phong_shader;
@@ -353,8 +350,8 @@ int main_gfx() {
glGetUniformLocation(app_state.active_shader->prog_id, "view"),
1, GL_FALSE, glm::value_ptr(big_frame.cam->view));
real32 last_frame = glfwGetTime();
real32 time_delta = 1.0f/60.0f;
real64 last_frame = glfwGetTime();
real64 time_delta = 1.0f/60.0f;
while (!glfwWindowShouldClose(window)) {
time_delta = glfwGetTime() - last_frame;
process_input(window);
@@ -383,7 +380,7 @@ int main_gfx() {
if (entity.visible) {
glUniformMatrix4fv(model_uniform_loc, 1, GL_FALSE, glm::value_ptr(get_scene_graph_node(entity.scene_graph_node)->world));
glBindTexture(GL_TEXTURE_2D, entity.tex->tex_id);
glDrawArrays(GL_TRIANGLES, 0, entity.mesh->num_indices);
glDrawArrays(GL_TRIANGLES, 0, (GLsizei)entity.mesh->num_indices);
//glDrawElements(GL_TRIANGLES, entity->mesh->num_indices, GL_UNSIGNED_INT, 0);
}
}
@@ -398,6 +395,6 @@ int main_gfx() {
int main() {
initialiseCore();
return main_cmd();
return main_gfx();
}