Merge remote-tracking branch 'origin/ReWindow-Integration'

This commit is contained in:
mathsDOTearth
2025-01-13 21:58:20 +00:00
5 changed files with 133 additions and 5 deletions

47
CMakeLists.txt Normal file
View File

@@ -0,0 +1,47 @@
# Define what CMake versions this project targets.
cmake_minimum_required(VERSION 3.18..3.29)
# Define our project.
project(ReWalker
VERSION 1.0
LANGUAGES CXX)
# Prevent building in main directory, it generates lots of clutter!
if (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
message(FATAL_ERROR "In-source builds are not allowed")
endif()
# Set C++ version
set(CMAKE_CXX_STANDARD 20)
# Set optimization level
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
# Include addon scripts from the 'cmake' directory
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# Include CMake Package Manager
include(cmake/CPM.cmake)
# Automatically clone, compile and link the ReWindow library.
# You specify the release name to target against. See the link below for releases:
# https://git.redacted.cc/Redacted/ReWindow/releases
CPMAddPackage(
NAME ReWindow
URL URL https://git.redacted.cc/Redacted/ReWindow/archive/Prerelease-31.zip
)
add_executable(ReWalkerApp main.cpp)
target_include_directories(ReWalkerApp PUBLIC ${ReWindow_SOURCE_DIR}/include ${J3ML_SOURCE_DIR}/include)
target_link_libraries(ReWalkerApp PUBLIC J3ML ReWindowLibrary)
# simple window test
add_executable(TestWindowApp test.cpp)
target_include_directories(TestWindowApp PUBLIC ${ReWindow_SOURCE_DIR}/include ${J3ML_SOURCE_DIR}/include)
target_link_libraries(TestWindowApp PUBLIC J3ML ReWindowLibrary)

View File

@@ -1,9 +1,9 @@
eWalker is a simple random walker program that uses ReWindow to handle windowing and mouse operations.
ReWalker is a simple random walker program that uses ReWindow to handle windowing and mouse operations.
This is a simple random walker that has a little twist that if the user clicks the mouse over the window it "blows" the walker away from the mouse pointer.
I have not got to grips with setting up a ReWindow project yet, so, clone ReWindow and then replace main.cpp with the main.cpp code from here.
test.cpp builds to TestWindowApp as a test to help me understand how ReWindow works.
Hopefully soon I can set this up properly as an independant project.
main.cpp builds to ReWalkerApp which is the main random walker program.
I have also included a simple test program to open a window as well called test.cpp.
Thanks to Bill, Josh and Maxine for sorting the correct ReWindow Integration.

24
cmake/CPM.cmake Normal file
View File

@@ -0,0 +1,24 @@
# SPDX-License-Identifier: MIT
#
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors
set(CPM_DOWNLOAD_VERSION 0.38.7)
set(CPM_HASH_SUM "83e5eb71b2bbb8b1f2ad38f1950287a057624e385c238f6087f94cdfc44af9c5")
if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()
# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_DOWNLOAD_LOCATION ${CPM_DOWNLOAD_LOCATION} ABSOLUTE)
file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION} EXPECTED_HASH SHA256=${CPM_HASH_SUM}
)
include(${CPM_DOWNLOAD_LOCATION})

57
main.cpp Normal file
View File

@@ -0,0 +1,57 @@
// ReWalker
// A random walker that moves around the screen
// Written using Redacted ReWindow https://git.redacted.cc/Redacted/ReWindow
// Written by Rich
// With help from (and thanks to) from Maxine, Josh and Bill
#include <rewindow/types/window.h>
#include <rewindow/logger/logger.h>
#include <GL/gl.h>
// define window size and dot size (dot size should be odd)
#define WIDTH 800
#define HEIGHT 600
#define DOT_SIZE 5
struct Walker {
float x, y;
Walker() : x(WIDTH / 2.0f), y(HEIGHT / 2.0f) {}
void step() {
float angle = static_cast<float>(rand()) / RAND_MAX * 360.0f;
angle = angle * M_PI / 180.0f;
float dx = std::cos(angle);
float dy = std::sin(angle);
x = std::clamp(x + dx, 0.0f, static_cast<float>(WIDTH - 1));
y = std::clamp(y + dy, 0.0f, static_cast<float>(HEIGHT - 1));
}
};
class RandomWalkerWindow : public ReWindow::RWindow {
public:
RandomWalkerWindow(const std::string& title, int width, int height)
: ReWindow::RWindow(title, width, height) {}
void OnRefresh(float elapsed) override {
glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Clear with white
glClear(GL_COLOR_BUFFER_BIT);
GLSwapBuffers();
}
};
int main() {
std::unique_ptr<RandomWalkerWindow> window =
std::make_unique<RandomWalkerWindow>("Random Walker with ReWindow", WIDTH, HEIGHT);
window->SetRenderer(RenderingAPI::OPENGL);
window->Open();
while (!window->IsClosing()) {
window->ManagedRefresh();
}
return 0;
}

View File

@@ -34,4 +34,4 @@ int main() {
}
return 0;
}
}