From 2264562c5b186a1d4e7044ae0878f63c995f273f Mon Sep 17 00:00:00 2001 From: rafa-br34 <111343658+rafa-br34@users.noreply.github.com> Date: Fri, 11 Oct 2024 21:52:15 -0300 Subject: [PATCH] Readme improvements --- CMakeLists.txt | 4 ++-- README.md | 14 +++++++++++--- SOURCE/Direct.cpp | 10 +++++++--- SOURCE/Encoding.h | 10 +++++----- SOURCE/{Entry.cpp => Interface.cpp} | 0 5 files changed, 25 insertions(+), 13 deletions(-) rename SOURCE/{Entry.cpp => Interface.cpp} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4628b8e..5642eec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,5 +26,5 @@ else() add_compile_options(-Wall -Wextra -Wpedantic) endif() -add_executable(${PROJECT_NAME}-CLI SOURCE/Entry.cpp ${COMMON_SOURCES}) -add_executable(${PROJECT_NAME}-CPP SOURCE/Direct.cpp ${COMMON_SOURCES}) \ No newline at end of file +add_executable(Interface SOURCE/Interface.cpp ${COMMON_SOURCES}) +add_executable(Direct SOURCE/Direct.cpp ${COMMON_SOURCES}) \ No newline at end of file diff --git a/README.md b/README.md index 087907f..ec2d882 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,8 @@ The web version can be found [here](https://rafa-br34.github.io/LangtonsAnt) - [Implementation notes](#implementation-notes) - [Usage](#usage) - [Web version](#web-version) - - [C++ version](#c-version) + - [C++ versions](#c-versions) + - [`Direct.cpp` VS `Interface.cpp`](#directcpp-vs-interfacecpp) - [Building](#building) - [Arguments](#arguments) - [`-x` \& `-y`](#-x---y) @@ -25,7 +26,7 @@ The web version can be found [here](https://rafa-br34.github.io/LangtonsAnt) # Implementation notes -Both the C++ ([Ant.h](https://github.com/rafa-br34/LangtonsAnt/blob/master/SOURCE/Types/Ant.h)) and JavaScript ([Ant.js](https://github.com/rafa-br34/LangtonsAnt/blob/master/WEBSITE/Scripts/Ant.js)) version share the same implementation concept. +The JavaScript ([Ant.js](https://github.com/rafa-br34/LangtonsAnt/blob/master/WEBSITE/Scripts/Ant.js)) version is basically a line by line rewrite of the C++ ([Ant.h](https://github.com/rafa-br34/LangtonsAnt/blob/master/SOURCE/Types/Ant.h)) version (in the future this may change). There's support for 8 possible operations, which are: - R45/L45 @@ -40,10 +41,17 @@ There's support for 8 possible operations, which are: Placeholder -## C++ version +## C++ versions + +### `Direct.cpp` VS `Interface.cpp` + +The `Direct.cpp` file is an example implementation of how you can use this repo to implement your own Langton's ant simulation. +The `Interface.cpp` file on the other hand is a simple CLI that allows you to mess around without prior C/C++ knowledge. ### Building +The following works for both Linux and Windows. + ```bash git clone --recursive https://github.com/rafa-br34/LangtonsAnt.git cd LangtonsAnt diff --git a/SOURCE/Direct.cpp b/SOURCE/Direct.cpp index 6814fd8..89ce2b1 100644 --- a/SOURCE/Direct.cpp +++ b/SOURCE/Direct.cpp @@ -65,10 +65,14 @@ int main() { for (size_t i = 0; i < Frames; i++) { size_t Result = Simulation.Simulate(CaptureDelta); - - printf("Frame: %lu Iters: %lu/%lu Threads: %lu\n", i, Result, CaptureDelta, Encoder.Threads.ActiveThreads()); - Encoder.EncodeAsync(Simulation, [&, i](const std::vector& ImageData, const Vector2&, unsigned int) { + std::cout + << "Frame: " << i + << " Iters: " << Result << '/' << CaptureDelta + << " Active threads: " << Encoder.Threads.ActiveThreads() + << '\n'; + + Encoder.EncodeAsync(Simulation, [&, i](const std::vector& ImageData, const Vector2&, unsigned int) { lodepng::save_file(ImageData, "frames/" + std::to_string(i) + ".png"); }); } diff --git a/SOURCE/Encoding.h b/SOURCE/Encoding.h index 1e14d22..c60882d 100644 --- a/SOURCE/Encoding.h +++ b/SOURCE/Encoding.h @@ -62,22 +62,22 @@ namespace Encoding { m_Palette.push_back(ColoringProcedure(s)); } - INLINE size_t GetSize() const { + inline size_t GetSize() const { return m_Palette.size(); } - INLINE RGBA32 GetColor(size_t Index) { + inline RGBA32 GetColor(size_t Index) { if (Index + 1 > m_Palette.size()) ResizePalette(Index + 1); return m_Palette[Index]; } - INLINE RGBA32* GetData() { + inline RGBA32* GetData() { return m_Palette.data(); } - INLINE RGBA32 operator[](size_t Index) { + inline RGBA32 operator[](size_t Index) { return m_Palette[Index]; } }; @@ -177,7 +177,7 @@ namespace Encoding { ASSERT_MSG(Result == 0, "lodepng::encode -> %d\n", Result); - Callback(ImageData, Vector2(Size.X, Size.Y), Result); + Callback(ImageData, Vector2(Size.X, Size.Y), Result); } public: diff --git a/SOURCE/Entry.cpp b/SOURCE/Interface.cpp similarity index 100% rename from SOURCE/Entry.cpp rename to SOURCE/Interface.cpp