update
This commit is contained in:
4
.clangd
4
.clangd
@@ -1,4 +1,4 @@
|
|||||||
CompileFlags:
|
CompileFlags:
|
||||||
Add:
|
Add:
|
||||||
- -DOS_LINUX
|
- -DOS_WINDOWS
|
||||||
- -I ./
|
- "-IC:\\source\\libs\\include"
|
||||||
|
|||||||
12
build.bat
12
build.bat
@@ -2,14 +2,16 @@
|
|||||||
|
|
||||||
if NOT EXIST .\target mkdir .\target
|
if NOT EXIST .\target mkdir .\target
|
||||||
|
|
||||||
set commonLinkerFlags=-opt:ref
|
set LIBRARIES_ROOT="C:\source\libs"
|
||||||
set commonCompilerFlags=^
|
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 =%^
|
-MT %= Make sure the C runtime library is statically linked =%^
|
||||||
-Gm- %= Turns off incremental building =%^
|
-Gm- %= Turns off incremental building =%^
|
||||||
-nologo %= No one cares you made the compiler Microsoft =%^
|
-nologo %= No one cares you made the compiler Microsoft =%^
|
||||||
-Oi %= Always use intrinsics =%^
|
-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 =%^
|
-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 =%^
|
-DAPP_DEBUG=0 -DENABLE_ASSERT=1 -DOS_WINDOWS=1 %= Custom #defines =%^
|
||||||
-D_CRT_SECURE_NO_WARNINGS=1^
|
-D_CRT_SECURE_NO_WARNINGS=1^
|
||||||
@@ -17,7 +19,7 @@ set commonCompilerFlags=^
|
|||||||
-Zi %= Generate debugger info =%
|
-Zi %= Generate debugger info =%
|
||||||
|
|
||||||
pushd .\target
|
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
|
popd
|
||||||
|
|
||||||
exit /b
|
exit /b
|
||||||
|
|||||||
@@ -45,9 +45,9 @@ std::vector<uint64> get_reprs_input(int units_required) {
|
|||||||
uint64 bit_repr = 0;
|
uint64 bit_repr = 0;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
bool good_repr = true;
|
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') {
|
if (*it == '1') {
|
||||||
bit_repr |= 1 << i;
|
bit_repr |= 1ull << i;
|
||||||
total_units++;
|
total_units++;
|
||||||
} else if (*it != '0' || i >= 64) {
|
} else if (*it != '0' || i >= 64) {
|
||||||
std::cout << "Input invalid. Enter a binary string only with max 64 bits." << '\n';
|
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 };
|
uint64 STD_SOMA[] = { 23ul, 30ul, 15ul, 1043ul, 24594ul, 12306ul, 11ul };
|
||||||
|
|
||||||
void backtrack_solve_iter(std::vector<uint64> *polycube_input, std::vector<int> *offsets) {
|
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>();
|
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<uint64> *input = solver->input;
|
||||||
list<size_t> *offsets = solver->offsets;
|
list<size_t> *offsets = solver->offsets;
|
||||||
std::vector<SomaSolution> *solutions = solver->solutions;
|
std::vector<SomaSolution> *solutions = solver->solutions;
|
||||||
int start = offsets->data[curr_piece];
|
size_t start = offsets->data[curr_piece];
|
||||||
int end = offsets->data[curr_piece + 1];
|
size_t end = offsets->data[curr_piece + 1];
|
||||||
size_t num_pieces = offsets->length - 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]);
|
bool successful_fuse = !collides(working_solution, input->data[i]);
|
||||||
if (successful_fuse) {
|
if (successful_fuse) {
|
||||||
uint64 new_working_solution = working_solution | input->data[i];
|
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);
|
list<uint64> polycubes = PushList(arena, uint64, 0);
|
||||||
|
|
||||||
Space model_space = {
|
Space empty_voxel_space = {
|
||||||
{},
|
{},
|
||||||
dims[0],
|
dims[0],
|
||||||
dims[1],
|
dims[1],
|
||||||
dims[2],
|
dims[2],
|
||||||
};
|
};
|
||||||
|
|
||||||
appendList(&offsets, 0ul);
|
appendList(&offsets, (size_t)0);
|
||||||
Space space = model_space;
|
|
||||||
|
list<uint64> positions = {};
|
||||||
|
{
|
||||||
|
Space space = empty_voxel_space;
|
||||||
space.space = reprs_in[0];
|
space.space = reprs_in[0];
|
||||||
cullEmptySpace(&space);
|
cullEmptySpace(&space);
|
||||||
list<uint64> positions = getAllPositionsInPrism(arena, &space, dims);
|
positions = getAllPositionsInPrism(arena, &space, dims);
|
||||||
polycubes.length += positions.length;
|
polycubes.length += positions.length;
|
||||||
polycubes.head += positions.head;
|
polycubes.head += positions.head;
|
||||||
memcpy(polycubes.data, positions.data, positions.length / sizeof(uint64));
|
memcpy(polycubes.data, positions.data, positions.length / sizeof(uint64));
|
||||||
|
};
|
||||||
|
|
||||||
for (int i = 1; i < reprs_in_count; i++) {
|
for (size_t i = 1; i < reprs_in_count; i++) {
|
||||||
appendList(&offsets, polycubes.length);
|
appendList(&offsets, polycubes.length);
|
||||||
Space space = model_space;
|
Space space = empty_voxel_space;
|
||||||
space.space = reprs_in[i];
|
space.space = reprs_in[i];
|
||||||
cullEmptySpace(&space);
|
cullEmptySpace(&space);
|
||||||
list<uint64> perms = getAllPermutationsInPrism(permsArena, &space, dims);
|
list<uint64> perms = getAllPermutationsInPrism(permsArena, &space, dims);
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <iostream>
|
|
||||||
#include <ostream>
|
|
||||||
#include "VoxelSpace.h"
|
#include "VoxelSpace.h"
|
||||||
#include "lib/djstdlib/core.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;
|
return space->dim_x * space->dim_z * (space->dim_y - 1 - y) + space->dim_z * x + z;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64 toggle(uint64_t space, int index) {
|
uint64 toggle(uint64 space, int index) {
|
||||||
space ^= 1ul << index;
|
space ^= 1ull << index;
|
||||||
return space;
|
return space;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64 set(uint64_t space, int index, bool val) {
|
uint64 set(uint64 space, int index, bool val) {
|
||||||
if (val) {
|
if (val) {
|
||||||
space |= 1ul << index;
|
space |= 1ull << index;
|
||||||
} else {
|
} else {
|
||||||
space &= ~(1ul << index);
|
space &= ~(1ull << index);
|
||||||
}
|
}
|
||||||
return space;
|
return space;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool collides(uint64_t a, uint64_t b) {
|
bool collides(uint64 a, uint64 b) {
|
||||||
return (a | b) != (a ^ 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) {
|
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);
|
uint64 mask = 1ull << (space->dim_y * space->dim_z * x + space->dim_z * y + z);
|
||||||
return (space->space & mask) != 0ul;
|
return (space->space & mask) != 0ull;
|
||||||
}
|
}
|
||||||
|
|
||||||
Extrema getExtrema(Space *space) {
|
Extrema getExtrema(Space *space) {
|
||||||
@@ -94,12 +92,12 @@ Extrema getExtrema(Space *space) {
|
|||||||
void cullEmptySpace(Space *space) {
|
void cullEmptySpace(Space *space) {
|
||||||
Extrema extrema = getExtrema(space);
|
Extrema extrema = getExtrema(space);
|
||||||
int space_index = 0;
|
int space_index = 0;
|
||||||
uint64 newSpace = 0ul;
|
uint64 newSpace = 0ull;
|
||||||
for (int x = extrema.xMin; x <= extrema.xMax; x++) {
|
for (int x = extrema.xMin; x <= extrema.xMax; x++) {
|
||||||
for (int y = extrema.yMin; y <= extrema.yMax; y++) {
|
for (int y = extrema.yMin; y <= extrema.yMax; y++) {
|
||||||
for (int z = extrema.zMin; z <= extrema.zMax; z++) {
|
for (int z = extrema.zMin; z <= extrema.zMax; z++) {
|
||||||
if (filledAt(space, x, y, z)) {
|
if (filledAt(space, x, y, z)) {
|
||||||
newSpace |= 1ul << space_index;
|
newSpace |= 1ull << space_index;
|
||||||
}
|
}
|
||||||
space_index++;
|
space_index++;
|
||||||
}
|
}
|
||||||
@@ -117,7 +115,7 @@ void rotate90X(Space *space) {
|
|||||||
for (int y = 0; y < space->dim_y; y++) {
|
for (int y = 0; y < space->dim_y; y++) {
|
||||||
for (int z = 0; z < space->dim_z; z++) {
|
for (int z = 0; z < space->dim_z; z++) {
|
||||||
if (filledAt(space, x, y, 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 y = 0; y < space->dim_y; y++) {
|
||||||
for (int z = 0; z < space->dim_z; z++) {
|
for (int z = 0; z < space->dim_z; z++) {
|
||||||
if (filledAt(space, x, y, 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 y = 0; y < space->dim_y; y++) {
|
||||||
for (int z = 0; z < space->dim_z; z++) {
|
for (int z = 0; z < space->dim_z; z++) {
|
||||||
if (filledAt(space, x, y, 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++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
bool matchFound = false;
|
bool matchFound = false;
|
||||||
for (EachIn(*existingSpaces, i)) {
|
for (EachIn(*existingSpaces, j)) {
|
||||||
if (isMatch(&existingSpaces->data[i], &spins[i])) {
|
if (isMatch(&existingSpaces->data[j], &spins[i])) {
|
||||||
matchFound = true;
|
matchFound = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -286,10 +284,10 @@ list<uint64> getAllPermutationsInPrism(Arena *arena, Space *space, int prism_dim
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int size(uint64_t space) {
|
int size(uint64 space) {
|
||||||
int size = 0;
|
int size = 0;
|
||||||
for (int i = 0; i < 64; i++) {
|
for (int i = 0; i < 64; i++) {
|
||||||
if ((space & (1ul << i)) != 0) {
|
if ((space & (1ull << i)) != 0) {
|
||||||
size++;
|
size++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,16 @@
|
|||||||
#define LEDDA_MESH_H
|
#define LEDDA_MESH_H
|
||||||
|
|
||||||
#include "../lib/glad/glad.h"
|
#include "../lib/glad/glad.h"
|
||||||
|
#include "../lib/djstdlib/core.h"
|
||||||
#include "geometry.h"
|
#include "geometry.h"
|
||||||
|
|
||||||
struct Mesh {
|
struct Mesh {
|
||||||
unsigned int vao;
|
uint32 vao;
|
||||||
unsigned int vbo_xyz;
|
uint32 vbo_xyz;
|
||||||
unsigned int vbo_uv;
|
uint32 vbo_uv;
|
||||||
unsigned int vbo_norm;
|
uint32 vbo_norm;
|
||||||
unsigned int ebo;
|
uint32 ebo;
|
||||||
unsigned int num_indices;
|
uint64 num_indices;
|
||||||
};
|
};
|
||||||
|
|
||||||
Mesh createMesh(const char* obj_file);
|
Mesh createMesh(const char* obj_file);
|
||||||
|
|||||||
@@ -83,28 +83,28 @@ uint32 square_indices[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const Shape TRIANGLE = {
|
const Shape TRIANGLE = {
|
||||||
.indices = triangle_indices,
|
triangle_indices,
|
||||||
.indices_size = ArrayCount(triangle_indices),
|
ArrayCount(triangle_indices),
|
||||||
.uv = triangle_vertices,
|
triangle_vertices,
|
||||||
.uv_size = ArrayCount(triangle_vertices),
|
ArrayCount(triangle_vertices),
|
||||||
.xyz = triangle_vertices,
|
triangle_vertices,
|
||||||
.xyz_size = ArrayCount(triangle_vertices),
|
ArrayCount(triangle_vertices),
|
||||||
};
|
};
|
||||||
|
|
||||||
const Shape SQUARE = {
|
const Shape SQUARE = {
|
||||||
.indices = square_indices,
|
square_indices,
|
||||||
.indices_size = ArrayCount(square_indices),
|
ArrayCount(square_indices),
|
||||||
.uv = square_uv,
|
square_uv,
|
||||||
.uv_size = ArrayCount(square_uv),
|
ArrayCount(square_uv),
|
||||||
.xyz = square_xyz,
|
square_xyz,
|
||||||
.xyz_size = ArrayCount(square_xyz),
|
ArrayCount(square_xyz),
|
||||||
};
|
};
|
||||||
|
|
||||||
const Shape CUBE = {
|
const Shape CUBE = {
|
||||||
.indices = cube_indices,
|
cube_indices,
|
||||||
.indices_size = ArrayCount(cube_indices),
|
ArrayCount(cube_indices),
|
||||||
.uv = triangle_vertices,
|
triangle_vertices,
|
||||||
.uv_size = ArrayCount(triangle_vertices),
|
ArrayCount(triangle_vertices),
|
||||||
.xyz = triangle_vertices,
|
triangle_vertices,
|
||||||
.xyz_size = ArrayCount(triangle_vertices),
|
ArrayCount(triangle_vertices),
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
#include <unistd.h> // TODO(djledda): get outta here
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
@@ -93,7 +92,7 @@ void zeroList(list<T> *list) {
|
|||||||
memset(list->data, 0, list->head * sizeof(T));
|
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 {
|
return {
|
||||||
(char *)cstrLiteral,
|
(char *)cstrLiteral,
|
||||||
length,
|
length,
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ struct string {
|
|||||||
|
|
||||||
#define strlit(lit) (string{(char *)(lit), sizeof(lit) - 1})
|
#define strlit(lit) (string{(char *)(lit), sizeof(lit) - 1})
|
||||||
#define PushString(arena, length) (string{ (char *)pushSize(arena, length), (length) })
|
#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
|
// C Strings
|
||||||
const char *cstring(Arena *arena, list<char> buf);
|
const char *cstring(Arena *arena, list<char> buf);
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ GLAPI int gladLoadGL(void);
|
|||||||
|
|
||||||
GLAPI int gladLoadGLLoader(GLADloadproc);
|
GLAPI int gladLoadGLLoader(GLADloadproc);
|
||||||
|
|
||||||
#include <KHR/khrplatform.h>
|
#include "../KHR/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;
|
||||||
|
|||||||
65
src/main.cpp
65
src/main.cpp
@@ -1,11 +1,11 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <optional>
|
|
||||||
|
|
||||||
#include "lib/djstdlib/core.h"
|
|
||||||
#include "lib/glad/glad.c"
|
#include "lib/glad/glad.c"
|
||||||
|
#include "lib/djstdlib/core.h"
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
#define GLM_ENABLE_EXPERIMENTAL
|
||||||
#include <glm/ext/matrix_transform.hpp>
|
#include <glm/ext/matrix_transform.hpp>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtx/quaternion.hpp>
|
#include <glm/gtx/quaternion.hpp>
|
||||||
@@ -23,10 +23,10 @@
|
|||||||
struct Entity;
|
struct Entity;
|
||||||
struct Polycube;
|
struct Polycube;
|
||||||
struct SceneGraphNode;
|
struct SceneGraphNode;
|
||||||
int new_entity();
|
uint32 new_entity();
|
||||||
Entity *get_entity(int id);
|
Entity *get_entity(int id);
|
||||||
SceneGraphNode *get_scene_graph_node(int id);
|
SceneGraphNode *get_scene_graph_node(int id);
|
||||||
int new_graph_node();
|
uint32 new_graph_node();
|
||||||
|
|
||||||
void print_mat(glm::mat4* matrix) {
|
void print_mat(glm::mat4* matrix) {
|
||||||
glm::mat4 mat = *matrix;
|
glm::mat4 mat = *matrix;
|
||||||
@@ -70,7 +70,7 @@ struct GlobalAppState {
|
|||||||
std::vector<Polycube> polycubes;
|
std::vector<Polycube> polycubes;
|
||||||
};
|
};
|
||||||
|
|
||||||
GlobalAppState app_state;
|
GlobalAppState app_state = {};
|
||||||
|
|
||||||
struct WindowDims {
|
struct WindowDims {
|
||||||
uint32 width;
|
uint32 width;
|
||||||
@@ -91,7 +91,7 @@ struct SceneGraphNode {
|
|||||||
glm::quat rotation;
|
glm::quat rotation;
|
||||||
glm::vec3 scale;
|
glm::vec3 scale;
|
||||||
std::vector<uint32> children;
|
std::vector<uint32> children;
|
||||||
std::optional<uint32> entity;
|
uint32 entity;
|
||||||
};
|
};
|
||||||
|
|
||||||
void init_sg_node(SceneGraphNode *n) {
|
void init_sg_node(SceneGraphNode *n) {
|
||||||
@@ -120,9 +120,9 @@ struct Polycube {
|
|||||||
void show_polycube(Polycube *p) {
|
void show_polycube(Polycube *p) {
|
||||||
SceneGraphNode *node = get_scene_graph_node(p->graph_node);
|
SceneGraphNode *node = get_scene_graph_node(p->graph_node);
|
||||||
for (uint32 &child : node->children) {
|
for (uint32 &child : node->children) {
|
||||||
SceneGraphNode *node = get_scene_graph_node(child);
|
SceneGraphNode *subNode = get_scene_graph_node(child);
|
||||||
if (node->entity) {
|
if (subNode->entity) {
|
||||||
get_entity(*node->entity)->visible = true;
|
get_entity(subNode->entity)->visible = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -130,9 +130,9 @@ void show_polycube(Polycube *p) {
|
|||||||
void hide_polycube(Polycube *p) {
|
void hide_polycube(Polycube *p) {
|
||||||
SceneGraphNode *node = get_scene_graph_node(p->graph_node);
|
SceneGraphNode *node = get_scene_graph_node(p->graph_node);
|
||||||
for (uint32 &child : node->children) {
|
for (uint32 &child : node->children) {
|
||||||
SceneGraphNode *node = get_scene_graph_node(child);
|
SceneGraphNode *subNode = get_scene_graph_node(child);
|
||||||
if (node->entity) {
|
if (subNode->entity) {
|
||||||
get_entity(*node->entity)->visible = false;
|
get_entity(subNode->entity)->visible = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,7 +154,7 @@ struct Frame {
|
|||||||
Camera* cam;
|
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};
|
Frame result = {0};
|
||||||
result.width = width;
|
result.width = width;
|
||||||
result.height = height;
|
result.height = height;
|
||||||
@@ -231,12 +231,12 @@ void process_input(GLFWwindow *window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int new_entity() {
|
uint32 new_entity() {
|
||||||
entities.emplace_back();
|
entities.emplace_back();
|
||||||
scene_graph_nodes.emplace_back();
|
scene_graph_nodes.emplace_back();
|
||||||
entities.back().scene_graph_node = scene_graph_nodes.size();
|
entities.back().scene_graph_node = (uint32)scene_graph_nodes.size();
|
||||||
scene_graph_nodes.back().entity = entities.size();
|
scene_graph_nodes.back().entity = (uint32)entities.size();
|
||||||
return entities.size();
|
return (uint32)entities.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity *get_entity(int id) {
|
Entity *get_entity(int id) {
|
||||||
@@ -247,13 +247,13 @@ SceneGraphNode *get_scene_graph_node(int id) {
|
|||||||
return &scene_graph_nodes[id - 1];
|
return &scene_graph_nodes[id - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
int new_graph_node() {
|
uint32 new_graph_node() {
|
||||||
scene_graph_nodes.emplace_back();
|
scene_graph_nodes.emplace_back();
|
||||||
return scene_graph_nodes.size();
|
return (uint32)scene_graph_nodes.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
Polycube create_polycube_from_repr(Space *repr) {
|
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));
|
init_sg_node(get_scene_graph_node(polycube_id));
|
||||||
for (int x = 0; x < repr->dim_x; x++) {
|
for (int x = 0; x < repr->dim_x; x++) {
|
||||||
for (int y = 0; y < repr->dim_y; y++) {
|
for (int y = 0; y < repr->dim_y; y++) {
|
||||||
@@ -275,10 +275,9 @@ Polycube create_polycube_from_repr(Space *repr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Polycube result = {
|
Polycube result = {};
|
||||||
.graph_node=polycube_id,
|
result.graph_node = polycube_id;
|
||||||
.color=glm::vec3(1.0f),
|
result.color = glm::vec3(1.0f);
|
||||||
};
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,12 +307,10 @@ int main_gfx() {
|
|||||||
|
|
||||||
Arena *arena = arenaAlloc(Megabytes(128));
|
Arena *arena = arenaAlloc(Megabytes(128));
|
||||||
|
|
||||||
app_state = {
|
app_state.current_polycube=0;
|
||||||
.current_polycube=0,
|
app_state.last_polycube_visible=6;
|
||||||
.last_polycube_visible=6,
|
app_state.active_shader=0;
|
||||||
.active_shader=0,
|
app_state.polycubes={};
|
||||||
.polycubes={},
|
|
||||||
};
|
|
||||||
|
|
||||||
Shader phong_shader = createShader("../assets/shaders/phong-solid.vertex.glsl", "../assets/shaders/phong-solid.fragment.glsl");
|
Shader phong_shader = createShader("../assets/shaders/phong-solid.vertex.glsl", "../assets/shaders/phong-solid.fragment.glsl");
|
||||||
app_state.active_shader = &phong_shader;
|
app_state.active_shader = &phong_shader;
|
||||||
@@ -353,8 +350,8 @@ int main_gfx() {
|
|||||||
glGetUniformLocation(app_state.active_shader->prog_id, "view"),
|
glGetUniformLocation(app_state.active_shader->prog_id, "view"),
|
||||||
1, GL_FALSE, glm::value_ptr(big_frame.cam->view));
|
1, GL_FALSE, glm::value_ptr(big_frame.cam->view));
|
||||||
|
|
||||||
real32 last_frame = glfwGetTime();
|
real64 last_frame = glfwGetTime();
|
||||||
real32 time_delta = 1.0f/60.0f;
|
real64 time_delta = 1.0f/60.0f;
|
||||||
while (!glfwWindowShouldClose(window)) {
|
while (!glfwWindowShouldClose(window)) {
|
||||||
time_delta = glfwGetTime() - last_frame;
|
time_delta = glfwGetTime() - last_frame;
|
||||||
process_input(window);
|
process_input(window);
|
||||||
@@ -383,7 +380,7 @@ int main_gfx() {
|
|||||||
if (entity.visible) {
|
if (entity.visible) {
|
||||||
glUniformMatrix4fv(model_uniform_loc, 1, GL_FALSE, glm::value_ptr(get_scene_graph_node(entity.scene_graph_node)->world));
|
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);
|
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);
|
//glDrawElements(GL_TRIANGLES, entity->mesh->num_indices, GL_UNSIGNED_INT, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -398,6 +395,6 @@ int main_gfx() {
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
initialiseCore();
|
initialiseCore();
|
||||||
return main_cmd();
|
return main_gfx();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user