fixed it!!!!
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
.cache
|
.cache
|
||||||
.vscode
|
.vscode
|
||||||
/target
|
/target
|
||||||
|
perf.data
|
||||||
|
|||||||
10
build
10
build
@@ -1,6 +1,14 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
LIB_INCLUDE="-lglfw -lGL -lm"
|
LIB_INCLUDE="-lglfw -lGL -lm"
|
||||||
gcc -g -g2 -DOS_LINUX=1 -DDJSTDLIB_DEBUG=1 -xc -std=c99 ./src/main.c -o ./target/somaesque $LIB_INCLUDE
|
|
||||||
|
echo [Building target]
|
||||||
|
if [ $DEBUG ]; then
|
||||||
|
time clang -O0 -g -g2 -DOS_LINUX=1 -DDJSTDLIB_DEBUG=1 -xc -std=c99 ./src/main.c -o ./target/somaesque $LIB_INCLUDE
|
||||||
|
else
|
||||||
|
time clang -O2 -DOS_LINUX=1 -xc -std=c99 ./src/main.c -o ./target/somaesque $LIB_INCLUDE
|
||||||
|
fi
|
||||||
|
echo [Target built]
|
||||||
./target/somaesque
|
./target/somaesque
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -74,8 +74,6 @@ struct Solver {
|
|||||||
SomaSolutionList *solutions;
|
SomaSolutionList *solutions;
|
||||||
};
|
};
|
||||||
|
|
||||||
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) {
|
||||||
size_t num_inputs = offsets->size() - 1;
|
size_t num_inputs = offsets->size() - 1;
|
||||||
@@ -161,7 +159,7 @@ SomaSolutionList getSolutionRotations(Arena *arena, SomaSolution *solution, int
|
|||||||
result.data[i] = PushList(arena, SomaSolution, solution->length);
|
result.data[i] = PushList(arena, SomaSolution, solution->length);
|
||||||
}
|
}
|
||||||
for (int piece_i = 0; piece_i < solution->length; piece_i++) {
|
for (int piece_i = 0; piece_i < solution->length; piece_i++) {
|
||||||
Space space = {
|
VoxelSpace space = {
|
||||||
solution->data[piece_i],
|
solution->data[piece_i],
|
||||||
dims[0],
|
dims[0],
|
||||||
dims[1],
|
dims[1],
|
||||||
@@ -222,15 +220,15 @@ uint64 factorial(int n) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
SomaSolutionList solve(uint64 *reprs_in, uint32 reprs_in_count, int dims[3]) {
|
SomaSolutionList solve(VoxelSpaceReprList reprsInput, int dims[3]) {
|
||||||
Arena *arena = arenaAlloc(Megabytes(64));
|
Arena *arena = arenaAlloc(Megabytes(64));
|
||||||
Arena *permsArena = arenaAlloc(Megabytes(128));
|
Arena *permsArena = arenaAlloc(Megabytes(128));
|
||||||
|
|
||||||
OffsetList offsets = PushList(arena, OffsetList, reprs_in_count + 1);
|
OffsetList offsets = PushList(arena, OffsetList, reprsInput.length + 1);
|
||||||
|
|
||||||
VoxelSpaceReprList polycubes = PushList(arena, VoxelSpaceReprList, 0);
|
VoxelSpaceReprList polycubes = PushList(arena, VoxelSpaceReprList, 0);
|
||||||
|
|
||||||
Space empty_voxel_space = {
|
VoxelSpace emptyVoxelSpace = {
|
||||||
0,
|
0,
|
||||||
dims[0],
|
dims[0],
|
||||||
dims[1],
|
dims[1],
|
||||||
@@ -242,10 +240,10 @@ SomaSolutionList solve(uint64 *reprs_in, uint32 reprs_in_count, int dims[3]) {
|
|||||||
uint64 possibleCombos = 0;
|
uint64 possibleCombos = 0;
|
||||||
|
|
||||||
{
|
{
|
||||||
Space space = empty_voxel_space;
|
VoxelSpace voxelSpace = emptyVoxelSpace;
|
||||||
space.space = reprs_in[0];
|
voxelSpace.space = reprsInput.data[0];
|
||||||
cullEmptySpace(&space);
|
cullEmptySpace(&voxelSpace);
|
||||||
VoxelSpaceReprList positions = getAllPositionsInPrism(permsArena, &space, dims);
|
VoxelSpaceReprList positions = getAllPositionsInPrism(permsArena, &voxelSpace, dims);
|
||||||
possibleCombos += positions.length;
|
possibleCombos += positions.length;
|
||||||
VoxelSpaceReprList_underlying *insertion = PushArray(arena, uint64, positions.capacity);
|
VoxelSpaceReprList_underlying *insertion = PushArray(arena, uint64, positions.capacity);
|
||||||
polycubes.capacity += positions.capacity;
|
polycubes.capacity += positions.capacity;
|
||||||
@@ -253,10 +251,10 @@ SomaSolutionList solve(uint64 *reprs_in, uint32 reprs_in_count, int dims[3]) {
|
|||||||
memcpy(insertion, positions.data, positions.capacity * ListElementSize(VoxelSpaceReprList));
|
memcpy(insertion, positions.data, positions.capacity * ListElementSize(VoxelSpaceReprList));
|
||||||
};
|
};
|
||||||
|
|
||||||
for (size_t i = 1; i < reprs_in_count; i++) {
|
for (size_t i = 1; i < reprsInput.length; i++) {
|
||||||
AppendList(&offsets, polycubes.capacity);
|
AppendList(&offsets, polycubes.capacity);
|
||||||
Space space = empty_voxel_space;
|
VoxelSpace space = emptyVoxelSpace;
|
||||||
space.space = reprs_in[i];
|
space.space = reprsInput.data[i];
|
||||||
cullEmptySpace(&space);
|
cullEmptySpace(&space);
|
||||||
VoxelSpaceReprList perms = getAllPermutationsInPrism(permsArena, &space, dims);
|
VoxelSpaceReprList perms = getAllPermutationsInPrism(permsArena, &space, dims);
|
||||||
possibleCombos *= perms.length;
|
possibleCombos *= perms.length;
|
||||||
@@ -269,7 +267,7 @@ SomaSolutionList solve(uint64 *reprs_in, uint32 reprs_in_count, int dims[3]) {
|
|||||||
AppendList(&offsets, polycubes.length);
|
AppendList(&offsets, polycubes.length);
|
||||||
|
|
||||||
SomaSolutionList solutions = PushList(permsArena, SomaSolutionList, (size_t)floor(sqrt(possibleCombos)));
|
SomaSolutionList solutions = PushList(permsArena, SomaSolutionList, (size_t)floor(sqrt(possibleCombos)));
|
||||||
AppendList(&solutions, PushFullList(permsArena, SomaSolution, reprs_in_count));
|
AppendList(&solutions, PushFullList(permsArena, SomaSolution, reprsInput.length));
|
||||||
|
|
||||||
Solver solver = {
|
Solver solver = {
|
||||||
&polycubes,
|
&polycubes,
|
||||||
@@ -282,12 +280,11 @@ SomaSolutionList solve(uint64 *reprs_in, uint32 reprs_in_count, int dims[3]) {
|
|||||||
return filterUnique(permsArena, solver.solutions, dims);
|
return filterUnique(permsArena, solver.solutions, dims);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void interactiveCmdLineSolveSoma() {
|
void interactiveCmdLineSolveSoma() {
|
||||||
//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), (int[]){ 3, 3, 3 });
|
SomaSolutionList solutions = solve(AsList(VoxelSpaceReprList, STD_SOMA), (int[]){ 3, 3, 3 });
|
||||||
print("%zu solutions found.\n", solutions.length);
|
print("%zu solutions found.\n", solutions.length);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#include "VoxelSpace.h"
|
#include "VoxelSpace.h"
|
||||||
#include "lib/djstdlib/core.h"
|
#include "lib/djstdlib/core.h"
|
||||||
|
|
||||||
extern uint64 STD_SOMA[];
|
#define STD_SOMA { 23ul, 30ul, 15ul, 1043ul, 24594ul, 12306ul, 11ul }
|
||||||
typedef VoxelSpaceReprList SomaSolution;
|
typedef VoxelSpaceReprList SomaSolution;
|
||||||
DefineList(SomaSolution, SomaSolution);
|
DefineList(SomaSolution, SomaSolution);
|
||||||
|
|
||||||
SomaSolutionList solve(uint64 *reprs_in, uint32 reprs_in_length, int dims[3]);
|
SomaSolutionList solve(VoxelSpaceReprList reprs_in, int dims[3]);
|
||||||
void interactive_cmd_line_solve_soma();
|
void interactive_cmd_line_solve_soma();
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ int index(int dim_y, int dim_z, int x, int y, int z) {
|
|||||||
// │ 0, 0, -1 │ * │ y │ = │-z │
|
// │ 0, 0, -1 │ * │ y │ = │-z │
|
||||||
// │ 0, 1, 0 │ │ z │ │ y │
|
// │ 0, 1, 0 │ │ z │ │ y │
|
||||||
// └ ┘ └ ┘ └ ┘
|
// └ ┘ └ ┘ └ ┘
|
||||||
int newIndexRotX(Space *space, int x, int y, int z) {
|
int newIndexRotX(VoxelSpace *space, int x, int y, int z) {
|
||||||
return space->dim_z * space->dim_y * x + space->dim_y * (space->dim_z - 1 - z) + y;
|
return space->dim_z * space->dim_y * x + space->dim_y * (space->dim_z - 1 - z) + y;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ int newIndexRotX(Space *space, int x, int y, int z) {
|
|||||||
// │ 0, 1, 0 │ * │ y │ = │-y │
|
// │ 0, 1, 0 │ * │ y │ = │-y │
|
||||||
// │ -1, 0, 0 │ │ z │ │ x │
|
// │ -1, 0, 0 │ │ z │ │ x │
|
||||||
// └ ┘ └ ┘ └ ┘
|
// └ ┘ └ ┘ └ ┘
|
||||||
int newIndexRotY(Space *space, int x, int y, int z) {
|
int newIndexRotY(VoxelSpace *space, int x, int y, int z) {
|
||||||
return space->dim_y * space->dim_x * z + space->dim_x * y + (space->dim_x - 1 - x);
|
return space->dim_y * space->dim_x * z + space->dim_x * y + (space->dim_x - 1 - x);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ int newIndexRotY(Space *space, int x, int y, int z) {
|
|||||||
// │ 1, 0, 0 │ * │ y │ = │ x │
|
// │ 1, 0, 0 │ * │ y │ = │ x │
|
||||||
// │ 0, 0, 1 │ │ z │ │ z │
|
// │ 0, 0, 1 │ │ z │ │ z │
|
||||||
// └ ┘ └ ┘ └ ┘
|
// └ ┘ └ ┘ └ ┘
|
||||||
int newIndexRotZ(Space *space, int x, int y, int z) {
|
int newIndexRotZ(VoxelSpace *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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,18 +50,12 @@ inline bool collides(uint64 a, uint64 b) {
|
|||||||
return (a | b) != (a ^ b);
|
return (a | b) != (a ^ b);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
inline bool filledAt(VoxelSpace *space, int x, int y, int z) {
|
||||||
bool collides(Space *a, Space *b) {
|
|
||||||
return (a->space | b->space) != (a->space ^ b->space);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
bool filledAt(Space *space, int x, int y, int z) {
|
|
||||||
uint64 mask = 1ull << (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) != 0ull;
|
return (space->space & mask) != 0ull;
|
||||||
}
|
}
|
||||||
|
|
||||||
Extrema getExtrema(Space *space) {
|
Extrema getExtrema(VoxelSpace *space) {
|
||||||
Extrema extrema = {
|
Extrema extrema = {
|
||||||
0,
|
0,
|
||||||
space->dim_x,
|
space->dim_x,
|
||||||
@@ -89,7 +83,7 @@ Extrema getExtrema(Space *space) {
|
|||||||
return extrema;
|
return extrema;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cullEmptySpace(Space *space) {
|
void cullEmptySpace(VoxelSpace *space) {
|
||||||
Extrema extrema = getExtrema(space);
|
Extrema extrema = getExtrema(space);
|
||||||
int space_index = 0;
|
int space_index = 0;
|
||||||
uint64 newSpace = 0ull;
|
uint64 newSpace = 0ull;
|
||||||
@@ -109,7 +103,7 @@ void cullEmptySpace(Space *space) {
|
|||||||
space->space = newSpace;
|
space->space = newSpace;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rotate90X(Space *space) {
|
void rotate90X(VoxelSpace *space) {
|
||||||
uint64 new_space = 0;
|
uint64 new_space = 0;
|
||||||
for (int x = 0; x < space->dim_x; x++) {
|
for (int x = 0; x < space->dim_x; x++) {
|
||||||
for (int y = 0; y < space->dim_y; y++) {
|
for (int y = 0; y < space->dim_y; y++) {
|
||||||
@@ -126,7 +120,7 @@ void rotate90X(Space *space) {
|
|||||||
space->space = new_space;
|
space->space = new_space;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rotate90Y(Space *space) {
|
void rotate90Y(VoxelSpace *space) {
|
||||||
uint64 new_space = 0;
|
uint64 new_space = 0;
|
||||||
for (int x = 0; x < space->dim_x; x++) {
|
for (int x = 0; x < space->dim_x; x++) {
|
||||||
for (int y = 0; y < space->dim_y; y++) {
|
for (int y = 0; y < space->dim_y; y++) {
|
||||||
@@ -143,7 +137,7 @@ void rotate90Y(Space *space) {
|
|||||||
space->space = new_space;
|
space->space = new_space;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rotate90Z(Space *space) {
|
void rotate90Z(VoxelSpace *space) {
|
||||||
uint64 new_space = 0;
|
uint64 new_space = 0;
|
||||||
for (int x = 0; x < space->dim_x; x++) {
|
for (int x = 0; x < space->dim_x; x++) {
|
||||||
for (int y = 0; y < space->dim_y; y++) {
|
for (int y = 0; y < space->dim_y; y++) {
|
||||||
@@ -160,15 +154,15 @@ void rotate90Z(Space *space) {
|
|||||||
space->space = new_space;
|
space->space = new_space;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isMatch(Space *a, Space *b) {
|
bool isMatch(VoxelSpace *a, VoxelSpace *b) {
|
||||||
return a->space == b->space
|
return a->space == b->space
|
||||||
&& a->dim_x == b->dim_x
|
&& a->dim_x == b->dim_x
|
||||||
&& a->dim_y == b->dim_y
|
&& a->dim_y == b->dim_y
|
||||||
&& a->dim_z == b->dim_z;
|
&& a->dim_z == b->dim_z;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pushNewUniqueSpins(VoxelSpaceList *existingSpaces, Space* spaceToSpin) {
|
void pushNewUniqueSpins(VoxelSpaceList *existingSpaces, VoxelSpace* spaceToSpin) {
|
||||||
Space spins[4] = {};
|
VoxelSpace spins[4] = {};
|
||||||
spins[0] = *spaceToSpin;
|
spins[0] = *spaceToSpin;
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
spins[i + 1] = spins[i];
|
spins[i + 1] = spins[i];
|
||||||
@@ -188,17 +182,17 @@ void pushNewUniqueSpins(VoxelSpaceList *existingSpaces, Space* spaceToSpin) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void pushXAxisSpins(Arena *arena, VoxelSpaceList *existingSpaces, Space* spaceToSpin) {
|
void pushXAxisSpins(Arena *arena, VoxelSpaceList *existingSpaces, VoxelSpace* spaceToSpin) {
|
||||||
Space refSpace = *spaceToSpin;
|
VoxelSpace refSpace = *spaceToSpin;
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
rotate90X(&refSpace);
|
rotate90X(&refSpace);
|
||||||
AppendList(existingSpaces, refSpace);
|
AppendList(existingSpaces, refSpace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VoxelSpaceList getUniqueRotations(Arena *arena, Space *space) {
|
VoxelSpaceList getUniqueRotations(Arena *arena, VoxelSpace *space) {
|
||||||
VoxelSpaceList rotations = PushList(arena, VoxelSpaceList, 24);
|
VoxelSpaceList rotations = PushList(arena, VoxelSpaceList, 24);
|
||||||
Space refSpace = *space;
|
VoxelSpace refSpace = *space;
|
||||||
cullEmptySpace(&refSpace);
|
cullEmptySpace(&refSpace);
|
||||||
pushNewUniqueSpins(&rotations, &refSpace);
|
pushNewUniqueSpins(&rotations, &refSpace);
|
||||||
rotate90Y(&refSpace);
|
rotate90Y(&refSpace);
|
||||||
@@ -217,9 +211,9 @@ VoxelSpaceList getUniqueRotations(Arena *arena, Space *space) {
|
|||||||
return rotations;
|
return rotations;
|
||||||
}
|
}
|
||||||
|
|
||||||
VoxelSpaceList getAllRotations(Arena *arena, Space *space) {
|
VoxelSpaceList getAllRotations(Arena *arena, VoxelSpace *space) {
|
||||||
VoxelSpaceList rotations = PushList(arena, VoxelSpaceList, 24);
|
VoxelSpaceList rotations = PushList(arena, VoxelSpaceList, 24);
|
||||||
Space refSpace = *space;
|
VoxelSpace refSpace = *space;
|
||||||
pushXAxisSpins(arena, &rotations, &refSpace);
|
pushXAxisSpins(arena, &rotations, &refSpace);
|
||||||
rotate90Y(&refSpace);
|
rotate90Y(&refSpace);
|
||||||
pushXAxisSpins(arena, &rotations, &refSpace);
|
pushXAxisSpins(arena, &rotations, &refSpace);
|
||||||
@@ -235,7 +229,7 @@ VoxelSpaceList getAllRotations(Arena *arena, Space *space) {
|
|||||||
return rotations;
|
return rotations;
|
||||||
}
|
}
|
||||||
|
|
||||||
VoxelSpaceReprList getAllPositionsInPrism(Arena *arena, Space *space, int prism_dims[3]) {
|
VoxelSpaceReprList getAllPositionsInPrism(Arena *arena, VoxelSpace *space, int prism_dims[3]) {
|
||||||
if (space->dim_x > prism_dims[0] || space->dim_y > prism_dims[1] || space->dim_z > prism_dims[2]) {
|
if (space->dim_x > prism_dims[0] || space->dim_y > prism_dims[1] || space->dim_z > prism_dims[2]) {
|
||||||
return (VoxelSpaceReprList)EmptyList();
|
return (VoxelSpaceReprList)EmptyList();
|
||||||
}
|
}
|
||||||
@@ -272,7 +266,7 @@ VoxelSpaceReprList getAllPositionsInPrism(Arena *arena, Space *space, int prism_
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
VoxelSpaceReprList getAllPermutationsInPrism(Arena *arena, Space *space, int prism_dims[3]) {
|
VoxelSpaceReprList getAllPermutationsInPrism(Arena *arena, VoxelSpace *space, int prism_dims[3]) {
|
||||||
Scratch temp = scratchStart(&arena, 1);
|
Scratch temp = scratchStart(&arena, 1);
|
||||||
|
|
||||||
VoxelSpaceList rotations = getUniqueRotations(temp.arena, space);
|
VoxelSpaceList rotations = getUniqueRotations(temp.arena, space);
|
||||||
@@ -299,17 +293,17 @@ int size(uint64 space) {
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool spaceValueAt(Space *space, int x, int y, int z) {
|
bool spaceValueAt(VoxelSpace *space, int x, int y, int z) {
|
||||||
uint64 mask = 1 << (space->dim_y * space->dim_z * x + space->dim_z * y + z);
|
uint64 mask = 1 << (space->dim_y * space->dim_z * x + space->dim_z * y + z);
|
||||||
return (space->space & mask) != 0;
|
return (space->space & mask) != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spaceToggle(Space *space, int x, int y, int z) {
|
void spaceToggle(VoxelSpace *space, int x, int y, int z) {
|
||||||
uint64 mask = 1 << (space->dim_y * space->dim_z * x + space->dim_z * y + z);
|
uint64 mask = 1 << (space->dim_y * space->dim_z * x + space->dim_z * y + z);
|
||||||
space->space ^= mask;
|
space->space ^= mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
void spaceSet(Space *space, bool val, int x, int y, int z) {
|
void spaceSet(VoxelSpace *space, bool val, int x, int y, int z) {
|
||||||
uint64 mask = 1 << (space->dim_y * space->dim_z * x + space->dim_z * y + z);
|
uint64 mask = 1 << (space->dim_y * space->dim_z * x + space->dim_z * y + z);
|
||||||
if (val) {
|
if (val) {
|
||||||
space->space |= mask;
|
space->space |= mask;
|
||||||
|
|||||||
@@ -15,62 +15,62 @@ struct Extrema {
|
|||||||
int zMin;
|
int zMin;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct Space Space;
|
typedef struct VoxelSpace VoxelSpace;
|
||||||
struct Space {
|
struct VoxelSpace {
|
||||||
uint64 space;
|
uint64 space;
|
||||||
int dim_x;
|
int dim_x;
|
||||||
int dim_y;
|
int dim_y;
|
||||||
int dim_z;
|
int dim_z;
|
||||||
};
|
};
|
||||||
|
|
||||||
DefineList(Space, VoxelSpace);
|
DefineList(VoxelSpace, VoxelSpace);
|
||||||
DefineList(uint64, VoxelSpaceRepr);
|
DefineList(uint64, VoxelSpaceRepr);
|
||||||
|
|
||||||
int newIndexRotX(Space *space, int x, int y, int z);
|
int newIndexRotX(VoxelSpace *space, int x, int y, int z);
|
||||||
|
|
||||||
int newIndexRotY(Space *space, int x, int y, int z);
|
int newIndexRotY(VoxelSpace *space, int x, int y, int z);
|
||||||
|
|
||||||
int newIndexRotZ(Space *space, int x, int y, int z);
|
int newIndexRotZ(VoxelSpace *space, int x, int y, int z);
|
||||||
|
|
||||||
uint64 toggle(uint64 space, int index);
|
uint64 toggle(uint64 space, int index);
|
||||||
|
|
||||||
uint64 set(uint64 space, int index, bool val);
|
uint64 set(uint64 space, int index, bool val);
|
||||||
|
|
||||||
//bool collides(Space *a, Space *b);
|
//bool collides(VoxelSpace *a, VoxelSpace *b);
|
||||||
bool collides(uint64 a, uint64 b);
|
bool collides(uint64 a, uint64 b);
|
||||||
|
|
||||||
Space add(Space *a, Space *b);
|
VoxelSpace add(VoxelSpace *a, VoxelSpace *b);
|
||||||
|
|
||||||
bool filledAt(Space *space, int x, int y, int z);
|
bool filledAt(VoxelSpace *space, int x, int y, int z);
|
||||||
|
|
||||||
Extrema getExtrema(Space *space);
|
Extrema getExtrema(VoxelSpace *space);
|
||||||
|
|
||||||
void cullEmptySpace(Space *space);
|
void cullEmptySpace(VoxelSpace *space);
|
||||||
|
|
||||||
bool isMatch(Space *a, Space *b);
|
bool isMatch(VoxelSpace *a, VoxelSpace *b);
|
||||||
|
|
||||||
void rotate90X(Space *space);
|
void rotate90X(VoxelSpace *space);
|
||||||
|
|
||||||
void rotate90Y(Space *space);
|
void rotate90Y(VoxelSpace *space);
|
||||||
|
|
||||||
void rotate90Z(Space *space);
|
void rotate90Z(VoxelSpace *space);
|
||||||
|
|
||||||
void pushNewUniqueSpins(VoxelSpaceList *existingSpaces, Space* spaceToSpin);
|
void pushNewUniqueSpins(VoxelSpaceList *existingVoxelSpaces, VoxelSpace* spaceToSpin);
|
||||||
|
|
||||||
VoxelSpaceList getUniqueRotations(Arena *arena, Space *space);
|
VoxelSpaceList getUniqueRotations(Arena *arena, VoxelSpace *space);
|
||||||
|
|
||||||
VoxelSpaceList getAllRotations(Arena *arena, Space *space);
|
VoxelSpaceList getAllRotations(Arena *arena, VoxelSpace *space);
|
||||||
|
|
||||||
VoxelSpaceReprList getAllPositionsInPrism(Arena *arena, Space *space, int prism_dims[3]);
|
VoxelSpaceReprList getAllPositionsInPrism(Arena *arena, VoxelSpace *space, int prism_dims[3]);
|
||||||
|
|
||||||
VoxelSpaceReprList getAllPermutationsInPrism(Arena *arena, Space *space, int prism_dims[3]);
|
VoxelSpaceReprList getAllPermutationsInPrism(Arena *arena, VoxelSpace *space, int prism_dims[3]);
|
||||||
|
|
||||||
int size(uint64 space);
|
int size(uint64 space);
|
||||||
|
|
||||||
bool spaceValueAt(Space *space, int x, int y, int z);
|
bool spaceValueAt(VoxelSpace *space, int x, int y, int z);
|
||||||
|
|
||||||
void spaceToggle(Space *space, int x, int y, int z);
|
void spaceToggle(VoxelSpace *space, int x, int y, int z);
|
||||||
|
|
||||||
void spaceSet(Space *space, bool val, int x, int y, int z);
|
void spaceSet(VoxelSpace *space, bool val, int x, int y, int z);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
14
src/main.c
14
src/main.c
@@ -79,7 +79,7 @@ struct Frame {
|
|||||||
typedef struct Polycube Polycube;
|
typedef struct Polycube Polycube;
|
||||||
struct Polycube {
|
struct Polycube {
|
||||||
uint32 entityHandle;
|
uint32 entityHandle;
|
||||||
Space repr;
|
VoxelSpace repr;
|
||||||
RLVector4 color;
|
RLVector4 color;
|
||||||
};
|
};
|
||||||
DefineList(Polycube, Polycube);
|
DefineList(Polycube, Polycube);
|
||||||
@@ -145,7 +145,7 @@ struct Renderer {
|
|||||||
|
|
||||||
typedef struct PolycubeInput PolycubeInput;
|
typedef struct PolycubeInput PolycubeInput;
|
||||||
struct PolycubeInput {
|
struct PolycubeInput {
|
||||||
Space repr;
|
VoxelSpace repr;
|
||||||
RLVector4 color;
|
RLVector4 color;
|
||||||
};
|
};
|
||||||
DefineList(PolycubeInput, PolycubeInput);
|
DefineList(PolycubeInput, PolycubeInput);
|
||||||
@@ -371,7 +371,7 @@ void processInput(Soma *soma) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Polycube createPolycubeFromRepr(Arena *arena, Scene *s, Space *repr, RLVector4 color) {
|
Polycube createPolycubeFromRepr(Arena *arena, Scene *s, VoxelSpace *repr, RLVector4 color) {
|
||||||
uint32 polycubeMainEntityHandle = createEntity(arena, s);
|
uint32 polycubeMainEntityHandle = createEntity(arena, s);
|
||||||
Entity *polycubeMainEntity = getEntity(s, polycubeMainEntityHandle);
|
Entity *polycubeMainEntity = getEntity(s, polycubeMainEntityHandle);
|
||||||
for (int x = 0; x < repr->dim_x; x++) {
|
for (int x = 0; x < repr->dim_x; x++) {
|
||||||
@@ -673,8 +673,9 @@ int mainGfx() {
|
|||||||
cubeMesh = createMesh("./assets/models/cube.obj");
|
cubeMesh = createMesh("./assets/models/cube.obj");
|
||||||
wallTex = createTexture("./assets/textures/brick-wall.jpg");
|
wallTex = createTexture("./assets/textures/brick-wall.jpg");
|
||||||
|
|
||||||
for (EachInArray(STD_SOMA, i)) {
|
VoxelSpaceReprList stdSoma = AsList(VoxelSpaceReprList, STD_SOMA);
|
||||||
Space voxelSpace = { STD_SOMA[i], 3, 3, 3 };
|
for (EachIn(stdSoma, i)) {
|
||||||
|
VoxelSpace voxelSpace = { stdSoma.data[i], 3, 3, 3 };
|
||||||
RLVector4 color = colorFromIndex(i);
|
RLVector4 color = colorFromIndex(i);
|
||||||
PolycubeInput input = (PolycubeInput){ voxelSpace, color };
|
PolycubeInput input = (PolycubeInput){ voxelSpace, color };
|
||||||
AppendList(&soma.state.polycubeInput, input);
|
AppendList(&soma.state.polycubeInput, input);
|
||||||
@@ -713,7 +714,7 @@ int mainGfx() {
|
|||||||
Polycube *currentPolycube = &soma.state.polycubes.data[soma.state.currentPolycube];
|
Polycube *currentPolycube = &soma.state.polycubes.data[soma.state.currentPolycube];
|
||||||
PolycubeInput *pinput = &soma.state.polycubeInput.data[soma.state.currentPolycube];
|
PolycubeInput *pinput = &soma.state.polycubeInput.data[soma.state.currentPolycube];
|
||||||
removeEntity(soma.scene, currentPolycube->entityHandle);
|
removeEntity(soma.scene, currentPolycube->entityHandle);
|
||||||
Space culledRepr = pinput->repr;
|
VoxelSpace culledRepr = pinput->repr;
|
||||||
cullEmptySpace(&culledRepr);
|
cullEmptySpace(&culledRepr);
|
||||||
Polycube newPolycube = createPolycubeFromRepr(arena, soma.scene, &culledRepr, pinput->color);
|
Polycube newPolycube = createPolycubeFromRepr(arena, soma.scene, &culledRepr, pinput->color);
|
||||||
SceneGraphNode *graphNode = getSceneGraphNodeForEntity(soma.scene, newPolycube.entityHandle);
|
SceneGraphNode *graphNode = getSceneGraphNodeForEntity(soma.scene, newPolycube.entityHandle);
|
||||||
@@ -758,7 +759,6 @@ int mainGfx() {
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
initialiseDjStdCore();
|
initialiseDjStdCore();
|
||||||
test();
|
|
||||||
return mainCmd();
|
return mainCmd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
22
src/tests.c
22
src/tests.c
@@ -11,7 +11,7 @@ DefineList(MismatchData, MismatchData);
|
|||||||
|
|
||||||
void test() {
|
void test() {
|
||||||
{
|
{
|
||||||
Space space = {};
|
VoxelSpace space = {};
|
||||||
space.space=23ull;
|
space.space=23ull;
|
||||||
space.dim_x=3;
|
space.dim_x=3;
|
||||||
space.dim_y=3;
|
space.dim_y=3;
|
||||||
@@ -50,7 +50,7 @@ void test() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
Space space1 = {};
|
VoxelSpace space1 = {};
|
||||||
space1.space=172ull;
|
space1.space=172ull;
|
||||||
space1.dim_x=3;
|
space1.dim_x=3;
|
||||||
space1.dim_y=3;
|
space1.dim_y=3;
|
||||||
@@ -68,14 +68,14 @@ void test() {
|
|||||||
|
|
||||||
{
|
{
|
||||||
Arena *arena = arenaAlloc(Megabytes(64));
|
Arena *arena = arenaAlloc(Megabytes(64));
|
||||||
Space space1 = {};
|
VoxelSpace space1 = {};
|
||||||
space1.space=30ull;
|
space1.space=30ull;
|
||||||
space1.dim_x=3;
|
space1.dim_x=3;
|
||||||
space1.dim_y=3;
|
space1.dim_y=3;
|
||||||
space1.dim_z=3;
|
space1.dim_z=3;
|
||||||
|
|
||||||
VoxelSpaceList rotations = getUniqueRotations(arena, &space1);
|
VoxelSpaceList rotations = getUniqueRotations(arena, &space1);
|
||||||
Space expected_rots[] = {
|
VoxelSpace expected_rots[] = {
|
||||||
{ 30ull, 1, 2, 3 },
|
{ 30ull, 1, 2, 3 },
|
||||||
{ 45ull, 1, 3, 2 },
|
{ 45ull, 1, 3, 2 },
|
||||||
{ 30ull, 3, 2, 1 },
|
{ 30ull, 3, 2, 1 },
|
||||||
@@ -104,7 +104,7 @@ void test() {
|
|||||||
{
|
{
|
||||||
Arena *arena = arenaAlloc(Megabytes(64));
|
Arena *arena = arenaAlloc(Megabytes(64));
|
||||||
|
|
||||||
Space space1 = {};
|
VoxelSpace space1 = {};
|
||||||
space1.space=30ul;
|
space1.space=30ul;
|
||||||
space1.dim_x=3;
|
space1.dim_x=3;
|
||||||
space1.dim_y=3;
|
space1.dim_y=3;
|
||||||
@@ -199,19 +199,19 @@ void test() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
Space space1 = {};
|
VoxelSpace space1 = {};
|
||||||
space1.space=30ull;
|
space1.space=30ull;
|
||||||
space1.dim_x=3;
|
space1.dim_x=3;
|
||||||
space1.dim_y=3;
|
space1.dim_y=3;
|
||||||
space1.dim_z=3;
|
space1.dim_z=3;
|
||||||
|
|
||||||
Space space2 = {};
|
VoxelSpace space2 = {};
|
||||||
space2.space=30ull;
|
space2.space=30ull;
|
||||||
space2.dim_x=3;
|
space2.dim_x=3;
|
||||||
space2.dim_y=3;
|
space2.dim_y=3;
|
||||||
space2.dim_z=3;
|
space2.dim_z=3;
|
||||||
|
|
||||||
Space space3 = {};
|
VoxelSpace space3 = {};
|
||||||
space3.space=30ull;
|
space3.space=30ull;
|
||||||
space3.dim_x=3;
|
space3.dim_x=3;
|
||||||
space3.dim_y=3;
|
space3.dim_y=3;
|
||||||
@@ -230,7 +230,7 @@ void test() {
|
|||||||
|
|
||||||
int dims[] = {3, 3, 3};
|
int dims[] = {3, 3, 3};
|
||||||
|
|
||||||
Space space1 = {};
|
VoxelSpace space1 = {};
|
||||||
space1.space=30ull;
|
space1.space=30ull;
|
||||||
space1.dim_x=3;
|
space1.dim_x=3;
|
||||||
space1.dim_y=3;
|
space1.dim_y=3;
|
||||||
@@ -246,7 +246,7 @@ void test() {
|
|||||||
62914560ull,
|
62914560ull,
|
||||||
};
|
};
|
||||||
|
|
||||||
Space space2 = {};
|
VoxelSpace space2 = {};
|
||||||
space2.space=23ul;
|
space2.space=23ul;
|
||||||
space2.dim_x=3;
|
space2.dim_x=3;
|
||||||
space2.dim_y=3;
|
space2.dim_y=3;
|
||||||
@@ -262,7 +262,7 @@ void test() {
|
|||||||
48234496ull,
|
48234496ull,
|
||||||
};
|
};
|
||||||
|
|
||||||
Space space3 = {};
|
VoxelSpace space3 = {};
|
||||||
space3.space=15ull;
|
space3.space=15ull;
|
||||||
space3.dim_x=3;
|
space3.dim_x=3;
|
||||||
space3.dim_y=3;
|
space3.dim_y=3;
|
||||||
|
|||||||
Reference in New Issue
Block a user