Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,22 @@ jobs:
build:
strategy:
matrix:
os: [windows-latest, ubuntu-latest] # Testing on both Windows and Linux
os: [windows-2025, ubuntu-latest] # Testing on both Windows and Linux

runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0 # Important for getting full submodule history

- name: Ensure submodules are up-to-date
run: git submodule update --init --recursive

- name: Check submodulesversions
run: git submodule status

- name: Install dependencies (Linux)
if: runner.os == 'Linux'
run: sudo apt update && sudo apt install -y cmake g++ make xorg-dev libgl1-mesa-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-dev
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "third-party/SDL"]
path = third-party/SDL
url = https://github.com/libsdl-org/SDL.git
108 changes: 41 additions & 67 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,39 +1,25 @@
cmake_minimum_required(VERSION 3.10)

# Project Name
project(WeirdEngine)

# Set C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Define ENGINE_PATH to the local path
# add_definitions(-DENGINE_PATH="${CMAKE_CURRENT_SOURCE_DIR}")

message(STATUS "WeirdEngine path: ${CMAKE_CURRENT_SOURCE_DIR}")

# Ensure we use the Multi-threaded DLL runtime library
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")

# Collect source files
file(GLOB_RECURSE SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/*.vert" "${CMAKE_CURRENT_SOURCE_DIR}/src/*.frag")

# Collect header files
file(GLOB_RECURSE HEADERS "${CMAKE_CURRENT_SOURCE_DIR}/include/*.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp")

# Create a static library (Explicitly add headers)
add_library(${PROJECT_NAME} STATIC ${SOURCES} ${HEADERS})

# Add glad library as static
add_library(glad STATIC third-party/glad/glad.c)

# Public interface include directories
target_include_directories(${PROJECT_NAME}
target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/third-party>
$<INSTALL_INTERFACE:third-party>
)

target_include_directories(glad
Expand All @@ -42,80 +28,68 @@ target_include_directories(glad
$<INSTALL_INTERFACE:third-party>
)

# Link glad into WeirdEngine
target_link_libraries(${PROJECT_NAME} PUBLIC glad)

# Fetch and build GLFW
include(FetchContent)
FetchContent_Declare(
glfw
GIT_REPOSITORY https://github.com/glfw/glfw.git
GIT_TAG 3.3.8 # Change to the latest stable version if needed
)

# Disable tests and examples before fetching
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)

FetchContent_MakeAvailable(glfw)
set_target_properties(glfw PROPERTIES POSITION_INDEPENDENT_CODE ON)

# Link GLFW dynamically into WeirdEngine
target_link_libraries(${PROJECT_NAME} PUBLIC glfw)
# SDL3 setup
# Add dependencies
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/third-party/SDL)
# add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/third-party/SDL_image)
# add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/third-party/SDL_mixer)
# add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/third-party/SDL_net)
# add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/third-party/SDL_ttf)

# This is where we fix things.
# Replace all your old target_include_directories calls with this block.

# Define ENGINE_PATH
target_compile_definitions(${PROJECT_NAME} PUBLIC ENGINE_PATH="${CMAKE_CURRENT_SOURCE_DIR}")
target_include_directories(${PROJECT_NAME}
PUBLIC
# Anyone using WeirdEngine needs access to its public headers.
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
# The line below is for when you create an installable package later.
$<INSTALL_INTERFACE:include>

# Define SHADERS_PATH
target_compile_definitions(${PROJECT_NAME} PUBLIC SHADERS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/src/weird-renderer/shaders/")
PRIVATE
# Only WeirdEngine's own .cpp files need the SDL headers directly.
# The consumer (WeirdSamples) will get them via the public headers above.
${CMAKE_CURRENT_SOURCE_DIR}/third-party/SDL/include
)

# Optional: Specify the output directory for the static library
set_target_properties(${PROJECT_NAME} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib
target_include_directories(glad
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/third-party>
$<INSTALL_INTERFACE:third-party>
)

# Export both targets: WeirdEngine, glad, and glfw
export(TARGETS ${PROJECT_NAME} glad glfw FILE ${CMAKE_BINARY_DIR}/WeirdEngineConfig.cmake)
# This command links glad and SDL3 to your engine.
# Because you are linking to the TARGETS (glad and SDL3::SDL3), CMake automatically
# handles their include paths and other properties for you.
target_link_libraries(${PROJECT_NAME} PUBLIC glad)
target_link_libraries(${PROJECT_NAME} PUBLIC SDL3::SDL3)


# Shaders
target_compile_definitions(${PROJECT_NAME} PUBLIC
ENGINE_PATH="${CMAKE_CURRENT_SOURCE_DIR}"
SHADERS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/src/weird-renderer/shaders/"
)

# Install targets
install(TARGETS ${PROJECT_NAME} glad EXPORT WeirdEngineConfig
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
#
set_target_properties(${PROJECT_NAME} PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/lib
)

# Install public header directories
install(DIRECTORY include/ DESTINATION include)
install(DIRECTORY third-party DESTINATION third-party)

# Export the CMake configuration for consumers
install(EXPORT WeirdEngineConfig
FILE WeirdEngineConfig.cmake
NAMESPACE WeirdEngine::
DESTINATION lib/cmake/WeirdEngine
)

# ----------------------------------------------------------
# Helper function to assign source groups based on folder structure.
function(assign_source_groups TARGET)
foreach(source_file IN LISTS ARGN)
# Get the full path to the file's directory.
get_filename_component(FILE_PATH "${source_file}" PATH)
# Compute the path relative to the project's root.
file(RELATIVE_PATH REL_PATH "${CMAKE_CURRENT_SOURCE_DIR}" "${FILE_PATH}")
# Replace forward slashes with backslashes for Visual Studio filter naming.
string(REPLACE "/" "\\" FILTER_PATH "${REL_PATH}")

if(FILTER_PATH STREQUAL "")
set(FILTER_PATH "Root")
endif()

# Assign the file to the computed filter.
source_group("${FILTER_PATH}" FILES "${source_file}")
endforeach()
endfunction()

# Assign source groups for all your files.
assign_source_groups(${PROJECT_NAME} ${SOURCES} ${HEADERS})
assign_source_groups(${PROJECT_NAME} ${SOURCES} ${HEADERS})
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,14 @@ sudo apt install build-essential libx11-dev libxcursor-dev libxi-dev libgl1-mesa
```
#### Fedora
```
sudo dnf install libXext-devel libXrandr-devel libXinerama-devel libXcursor-devel libXi-devel
sudo dnf builddep SDL3
```
### Issues downloading SDL submodule
```
git rm --cached third-party/SDL
rm -rf .git/modules/third-party/SDL
rm -rf third-party/SDL

git submodule add https://github.com/libsdl-org/SDL.git third-party/SDL
git submodule update --init --recursive
```
48 changes: 30 additions & 18 deletions include/weird-engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
#define ENGINE_PATH "../weird-engine"
#endif // !ENGINE_PATH


#include "weird-engine/Utils.h"
#include "weird-engine/Input.h"
#include "weird-engine/SceneManager.h"
#include "weird-engine/Utils.h"
#include "weird-renderer/Renderer.h"

#ifdef _WIN32
Expand All @@ -16,26 +15,24 @@
#define EXPORT
#endif

extern "C" {
extern "C"
{
EXPORT unsigned long NvOptimusEnablement = 0x00000001;
}



//int start(const char* projectPath);
//int main() {
// int start(const char* projectPath);
// int main() {
// const char* projectPath = "SampleProject/";
// start(projectPath);
//}
//
// }
//

namespace WeirdEngine
{
using namespace WeirdRenderer;
void start(SceneManager& sceneManager)
{


// Window resolution
const unsigned int width = 800;
const unsigned int height = 800;
Expand All @@ -45,19 +42,21 @@ namespace WeirdEngine
// Scenes
sceneManager.loadScene(0);


// Time
double time = glfwGetTime();
double time = SDL_GetTicks() / 1000.0;
double prevTime = time;
double delta = 0;
double timeDiff = 0;
unsigned int frameCounter = 0;

// Main while loop
while (!renderer.checkWindowClosed())
bool quit = false;
while (!quit)
{
// Meassure time
time = glfwGetTime();
// --- UNIFIED EVENT LOOP ---

// --- UPDATE ---
// // Meassure time
time = SDL_GetTicks() / 1000.0;
delta = time - prevTime;
timeDiff += delta;
prevTime = time;
Expand All @@ -77,7 +76,20 @@ namespace WeirdEngine
}

// Capture window input
Input::update(renderer.getWindow(), width, height);
Input::update(renderer.getWindow());

SDL_Event event;
while (SDL_PollEvent(&event))
{
if (event.type == SDL_EVENT_QUIT)
{
quit = true;
}
else
{
Input::handleEvent(event);
}
}

// Load next scene
if (Input::GetKeyDown(Input::Q))
Expand All @@ -91,7 +103,7 @@ namespace WeirdEngine
scene->update(delta, time);

// Clear input
Input::clear();
// Input::clear();

// Render scene
renderer.render(*scene, time);
Expand Down
Loading