Skip to content

Commit

Permalink
Linux support
Browse files Browse the repository at this point in the history
  • Loading branch information
rafa-br34 committed Oct 12, 2024
1 parent 3a32c3d commit afde884
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 22 deletions.
13 changes: 2 additions & 11 deletions SOURCE/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <stdint.h>

using CellType = uint8_t;
using SizeType = int;
using SizeType = int64_t;

#define FLATTEN_2D(X, Y, Width) ((Width) * (Y) + (X))
#define XOR_SHIFT32(S) S ^= (S << 13); S ^= (S >> 17); S ^= (S << 5);
Expand All @@ -13,32 +13,23 @@ using SizeType = int;

#define ASSERTION_MESSAGE(Condition) "Assertion failed " #Condition " on file: " __FILE__ " at line: " MAKE_STRING(__LINE__)


#ifdef _MSC_VER
#define FORCE_INLINE __forceinline
#elif __GNUC__
#define FORCE_INLINE __attribute__((always_inline))
#endif

#ifdef NDEBUG
#define DEBUG_BUILD 0
#else
#define DEBUG_BUILD 1
#endif

#if DEBUG_BUILD == 0
#define INLINE FORCE_INLINE
#define CONSTEXPR constexpr

#define DEBUG_PRINT(Format, ...)
#define ASSERT(Condition)
#define ASSERT_MSG(Condition, Format, ...)
#else
#define INLINE
#define CONSTEXPR

#include <stdio.h>
#define DEBUG_PRINT(Format, ...) std::printf(Format, __VA_ARGS__)
#define DEBUG_PRINT(Format, ...) std::printf(Format, ##__VA_ARGS__)
#define ASSERT(Condition) ON_FAIL(Condition, std::printf(ASSERTION_MESSAGE(Condition) "\n"))
#define ASSERT_MSG(Condition, Format, ...) ON_FAIL(Condition, std::printf(ASSERTION_MESSAGE(Condition) " " Format, __VA_ARGS__))
#endif
10 changes: 5 additions & 5 deletions SOURCE/Direct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ int main() {
RLRRLRRLRRLR & RLC When initializing both ants at the center (+/- 1 pixel tolerance on the y axis) with the same direction a prism with complex patterns is made
*/

Vector2<int> CanvasSize(30720, 30720);
Vector2<SizeType> CanvasSize(65535, 65535);
auto Center = CanvasSize / Vector2(2, 2);

SimulationState Simulation = {};
Expand All @@ -41,7 +41,7 @@ int main() {
Simulation.Reset();
Palette.ResizePalette(Simulation.PossibleStates);

Encoder.Threads.ThreadCount = 1;
Encoder.Threads.ThreadCount = 32;
Encoder.Format = Encoding::ImageFormat::PNG_PALETTE;

// ffmpeg -r 60 -i "Frames/%d.png" -b:v 5M -c:v libx264 -preset veryslow -qp 0 output.mp4
Expand All @@ -56,8 +56,8 @@ int main() {
std::cout << '\t' << StateMachineToString(Ant.StateMachine) << '\n';


size_t Iterations = 2ull * 1000000000ull;
double FrameRate = 10.0; // Video frame rate
size_t Iterations = 32ull * 1000000000ull;
double FrameRate = 128.0; // Video frame rate
double Time = 1.0; // Video time
size_t Frames = size_t(Time * FrameRate);

Expand All @@ -66,7 +66,7 @@ int main() {
for (size_t i = 0; i < Frames; i++) {
size_t Result = Simulation.Simulate(CaptureDelta);

printf("Frame: %llu Iters: %llu/%llu\n", i, Result, CaptureDelta);
printf("Frame: %lu Iters: %lu/%lu Threads: %lu\n", i, Result, CaptureDelta, Encoder.Threads.ActiveThreads());

Encoder.EncodeAsync(Simulation, [&, i](const std::vector<uint8_t>& ImageData, const Vector2<int>&, unsigned int) {
lodepng::save_file(ImageData, "frames/" + std::to_string(i) + ".png");
Expand Down
12 changes: 6 additions & 6 deletions SOURCE/Types/Ant.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Ant {

std::vector<DirectionEnum> StateMachine = {};

INLINE void Rotate(int8_t Rotation) {
inline void Rotate(int8_t Rotation) {
// Decode direction vector into direction index by flattening it (adding 4 as getting -4 is possible) and indexing a lookup table,
// add the new rotation + 8 (rotation can be negative), and then mod 8
int8_t CurrentDirection = (c_VectorLookup[(3 * Direction.Y + Direction.X) + 4] + Rotation + 8) % 8;
Expand All @@ -80,21 +80,21 @@ class Ant {
Direction.Y = c_DirectionsY[CurrentDirection];
}

INLINE bool ValidatePosition(const Vector2<SizeType>& GridSize) {
inline bool ValidatePosition(const Vector2<SizeType>& GridSize) {
// Check if the last update has landed us in a invalid position
// Positive out of bounds checks go first since a overflow will also trigger them
return Position.X < GridSize.X && Position.Y < GridSize.Y && Position.X >= 0 && Position.Y >= 0;
}

INLINE void WrapPosition(const Vector2<SizeType>& GridSize) {
inline void WrapPosition(const Vector2<SizeType>& GridSize) {
if (Position.X >= GridSize.X) Position.X = 0;
if (Position.Y >= GridSize.Y) Position.Y = 0;
if (Position.X < 0) Position.X = GridSize.X - 1;
if (Position.Y < 0) Position.Y = GridSize.Y - 1;
}

// Single step update (used for a single ant)
INLINE uint8_t Update(CellType* Grid, const Vector2<SizeType>& GridSize) {
inline uint8_t Update(CellType* Grid, const Vector2<SizeType>& GridSize) {
auto& Dir = Direction;
auto& Pos = Position;

Expand All @@ -112,7 +112,7 @@ class Ant {
}

// Double step update (used for multiple ants)
INLINE void UpdatePosition(const CellType* Grid, const Vector2<SizeType>& GridSize) {
inline void UpdatePosition(const CellType* Grid, const Vector2<SizeType>& GridSize) {
auto& Last = LastPosition;
auto& Dir = Direction;
auto& Pos = Position;
Expand All @@ -124,7 +124,7 @@ class Ant {
if (Wrap) WrapPosition(GridSize);
}

INLINE uint8_t UpdateCell(CellType* Grid, const Vector2<SizeType>& GridSize) {
inline uint8_t UpdateCell(CellType* Grid, const Vector2<SizeType>& GridSize) {
auto& Last = LastPosition;

if (!ValidatePosition(GridSize)) return 0;
Expand Down
1 change: 1 addition & 0 deletions SOURCE/Types/SimulationState.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <algorithm>
#include <cstdint>
#include <cstring>
#include <vector>

#include <lodepng.h>
Expand Down

0 comments on commit afde884

Please sign in to comment.