diff --git a/CMakeLists.txt b/CMakeLists.txt index 8495f8d3..982c2ac6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,16 +1,124 @@ -# Copyright (c) 2022 Dominic Masters +# Copyright (c) 2025 Dominic Masters # # This software is released under the MIT License. # https://opensource.org/licenses/MIT +# Setup cmake_minimum_required(VERSION 3.13) set(CMAKE_C_STANDARD 99) set(CMAKE_C_STANDARD_REQUIRED ON) -set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -add_library(dawn STATIC - src/funcs.c +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) + +if(NOT DEFINED DAWN_TARGET_SYSTEM) + set(DAWN_TARGET_SYSTEM "linux") + # set(DAWN_TARGET_SYSTEM "psp") +endif() + +# Prep cache +set(DAWN_CACHE_TARGET "dusk-target") + +# Build variables +set(DAWN_ROOT_DIR "${CMAKE_SOURCE_DIR}") +set(DAWN_BUILD_DIR "${CMAKE_BINARY_DIR}") +set(DAWN_SOURCES_DIR "${DAWN_ROOT_DIR}/src") +set(DAWN_TEMP_DIR "${DAWN_BUILD_DIR}/temp") +set(DAWN_TOOLS_DIR "${DAWN_ROOT_DIR}/tools") +set(DAWN_DATA_DIR "${DAWN_ROOT_DIR}/data") +set(DAWN_ASSETS_DIR "${DAWN_ROOT_DIR}/assets") +set(DAWN_BUILT_ASSETS_DIR "${DAWN_BUILD_DIR}/built_assets" CACHE INTERNAL ${DAWN_CACHE_TARGET}) +set(DAWN_GENERATED_HEADERS_DIR "${DAWN_BUILD_DIR}/generated") +set(DAWN_TARGET_NAME "Dusk" CACHE INTERNAL ${DAWN_CACHE_TARGET}) +set(DAWN_BUILD_BINARY ${DAWN_BUILD_DIR}/Dusk CACHE INTERNAL ${DAWN_CACHE_TARGET}) +set(DAWN_ASSETS "" CACHE INTERNAL ${DAWN_CACHE_TARGET}) + +# Create directories +file(MAKE_DIRECTORY ${DAWN_GENERATED_HEADERS_DIR}) + +# Find packages +find_package(Python3 COMPONENTS Interpreter REQUIRED) + +# Toolchains +if(DAWN_TARGET_SYSTEM STREQUAL "psp") + find_package(pspsdk REQUIRED) +endif() + +# Init Project +project(${DAWN_TARGET_NAME} + VERSION 1.0.0 + LANGUAGES C CXX ) -target_include_directories(dawn PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src) \ No newline at end of file +# Executable +add_executable(${DAWN_TARGET_NAME}) + +# Add tools +# add_subdirectory(tools) + +# Assets +# add_subdirectory(assets) + +# Add libraries +if(DAWN_TARGET_SYSTEM STREQUAL "linux") + find_package(SDL2 REQUIRED) + find_package(OpenGL REQUIRED) + target_link_libraries(${DAWN_TARGET_NAME} PRIVATE + SDL2 + OpenGL::GL + GL + ) + +elseif(DAWN_TARGET_SYSTEM STREQUAL "psp") + find_package(SDL2 REQUIRED) + find_package(OpenGL REQUIRED) + target_link_libraries(${DAWN_TARGET_NAME} PUBLIC + ${SDL2_LIBRARIES} + SDL2 + OpenGL::GL + zip + bz2 + z + mbedtls + mbedcrypto + lzma + ) + target_include_directories(${DAWN_TARGET_NAME} PRIVATE + ${SDL2_INCLUDE_DIRS} + ) +endif() + +# Add code +add_subdirectory(src) + +# Include generated headers +target_include_directories(${DAWN_TARGET_NAME} PUBLIC + ${DAWN_GENERATED_HEADERS_DIR} +) + +# # Build assets +# add_custom_target(DAWN_ASSETS_BUILT ALL +# COMMAND +# ${Python3_EXECUTABLE} ${DAWN_TOOLS_DIR}/assetstool/main.py +# --assets ${DAWN_ASSETS_DIR} +# --build-type wad +# --output-assets ${DAWN_BUILT_ASSETS_DIR} +# --output-file ${DAWN_BUILD_DIR}/dusk.dsk +# --output-headers ${DAWN_GENERATED_HEADERS_DIR}/asset/assetbundle.h +# --headers-dir ${DAWN_GENERATED_HEADERS_DIR} +# --input ${DAWN_ASSETS} +# ) +# add_dependencies(${DAWN_TARGET_NAME} DAWN_ASSETS_BUILT) + +# # Postbuild +# if(DAWN_TARGET_SYSTEM STREQUAL "psp") +# create_pbp_file( +# TARGET "${DAWN_TARGET_NAME}" +# ICON_PATH NULL +# BACKGROUND_PATH NULL +# PREVIEW_PATH NULL +# TITLE "${DAWN_TARGET_NAME}" +# VERSION 01.00 +# ) +# endif() \ No newline at end of file diff --git a/cmake/modules/Findglm.cmake b/cmake/modules/Findglm.cmake new file mode 100644 index 00000000..fa09627a --- /dev/null +++ b/cmake/modules/Findglm.cmake @@ -0,0 +1,14 @@ +# Copyright (c) 2025 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +include(FetchContent) +FetchContent_Declare( + glm + GIT_REPOSITORY https://github.com/g-truc/glm.git + GIT_TAG 1.0.1 +) + +FetchContent_MakeAvailable(glm) +set(glm_FOUND ON) \ No newline at end of file diff --git a/cmake/modules/Findpspsdk.cmake b/cmake/modules/Findpspsdk.cmake new file mode 100644 index 00000000..e98618d1 --- /dev/null +++ b/cmake/modules/Findpspsdk.cmake @@ -0,0 +1,106 @@ +# Copyright (c) 2025 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +if(NOT TARGET pspsdk) + message(STATUS "Looking for PSPSDK...") + + set(PSPSDK_FOUND FALSE CACHE INTERNAL "PSPSDK found") + set(PSPSDK_DOWNLOAD_DIR "${CMAKE_BINARY_DIR}/_pspsdk") + set(PSPSDK_SEARCH_ROOTS + "${PSPSDK_ROOT}" + "$ENV{PSPDEV}" + "$ENV{HOME}/pspdev" + "/usr/local/pspdev" + "/opt/pspdev" + "/usr/pspdev" + "${PSPSDK_DOWNLOAD_DIR}/pspdev" + ) + + foreach(root IN LISTS PSPSDK_SEARCH_ROOTS) + list(APPEND PSPSDK_BIN_HINTS "${root}/bin") + list(APPEND PSPSDK_INCLUDE_HINTS "${root}/include") + list(APPEND PSPSDK_LIB_HINTS "${root}/lib") + endforeach() + + # Find PSP GCC + find_program(PSPSDK_PSP_GCC NAMES psp-gcc HINTS ${PSPSDK_BIN_HINTS}) + + # If we did not find it, download it. + if(NOT PSPSDK_PSP_GCC) + message(STATUS "psp-gcc not found in system paths. Downloading PSPSDK tarball...") + file(DOWNLOAD + "https://github.com/pspdev/pspdev/releases/latest/download/pspdev-ubuntu-latest-x86_64.tar.gz" + "${CMAKE_BINARY_DIR}/pspsdk.tar.gz" + EXPECTED_HASH SHA256=2befe2ad83afd88934c106dbe98a72a7ad5ede8d272b7f1e79fda256a22f1062 + SHOW_PROGRESS + ) + + # Make output dir + file(MAKE_DIRECTORY "${PSPSDK_DOWNLOAD_DIR}") + + # Extract the tarball + execute_process( + COMMAND + ${CMAKE_COMMAND} -E tar xzf "${CMAKE_BINARY_DIR}/pspsdk.tar.gz" + WORKING_DIRECTORY + "${PSPSDK_DOWNLOAD_DIR}" + RESULT_VARIABLE + tar_result + ) + if(NOT tar_result EQUAL 0) + message(FATAL_ERROR "Failed to extract PSPSDK tarball") + endif() + + # Retry discovery with extracted fallback + find_program(PSPSDK_PSP_GCC NAMES psp-gcc HINTS ${PSPSDK_BIN_HINTS}) + endif() + + if(PSPSDK_PSP_GCC) + get_filename_component(PSPSDK_BIN_ROOT "${PSPSDK_PSP_GCC}" DIRECTORY) + get_filename_component(PSPSDK_ROOT "${PSPSDK_BIN_ROOT}" DIRECTORY) + set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) + set(ENV{PSPDEV} "${PSPSDK_ROOT}") + set(CMAKE_TOOLCHAIN_FILE "${PSPSDK_ROOT}/psp/share/pspdev.cmake") + set(BUILD_PRX ON CACHE BOOL "Build PRX modules") + + include("${PSPSDK_ROOT}/psp/share/pspdev.cmake") + set(CMAKE_C_COMPILER ${PSPSDK_BIN_ROOT}/psp-gcc) + set(CMAKE_CXX_COMPILER ${PSPSDK_BIN_ROOT}/psp-g++) + + if(NOT DEFINED PSP) + message(FATAL_ERROR "PSP environment variable is not set correctly.") + endif() + + add_library(pspsdk INTERFACE IMPORTED) + set_target_properties(pspsdk PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${PSPSDK_INCLUDE_DIR}" + INTERFACE_LINK_DIRECTORIES "${PSPSDK_LIB_DIR}" + ) + target_include_directories(pspsdk + INTERFACE + ${PSPDEV}/psp/include + ${PSPDEV}/psp/sdk/include + ) + target_link_directories(pspsdk + INTERFACE + ${PSPDEV}/lib + ${PSPDEV}/psp/lib + ${PSPDEV}/psp/sdk/lib + ) + target_link_libraries(pspsdk INTERFACE + pspdebug + pspdisplay + pspge + pspctrl + pspgu + pspaudio + pspaudiolib + psputility + pspvfpu + pspvram + psphprm + ) + endif() +endif() \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 00000000..20a056d4 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,33 @@ +# Copyright (c) 2025 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +find_package(glm REQUIRED) +find_package(libzip REQUIRED) + +# Libs +target_link_libraries(${DAWN_TARGET_NAME} + PUBLIC + m + glm + zip +) + +# Includes +target_include_directories(${DAWN_TARGET_NAME} + PRIVATE + ${CMAKE_CURRENT_LIST_DIR} +) + +# Sources +target_sources(${DAWN_TARGET_NAME} + PRIVATE + main.cpp +) + +# Subdirs +add_subdirectory(assert) +add_subdirectory(console) +add_subdirectory(engine) +add_subdirectory(time) \ No newline at end of file diff --git a/src/assert/Assert.cpp b/src/assert/Assert.cpp new file mode 100644 index 00000000..cc05dbc4 --- /dev/null +++ b/src/assert/Assert.cpp @@ -0,0 +1,85 @@ +/** + * Copyright (c) 2023 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#include "Assert.hpp" + +#ifndef ASSERTIONS_FAKED + void assertTrueImpl( + const char_t *file, + const int32_t line, + const bool_t x, + const char_t *message + ) { + if(x != true) { + fprintf( + stderr, + "Assertion Failed in %s:%i\n\n%s\n", + file, + line, + message + ); + abort(); + } + } + + void assertFalseImpl( + const char_t *file, + const int32_t line, + bool_t x, + const char_t *message + ) { + assertTrueImpl(file, line, !x, message); + } + + void assertUnreachableImpl( + const char_t *file, + const int32_t line, + const char_t *message + ) { + assertTrueImpl(file, line, false, message); + } + + void assertNotNullImpl( + const char_t *file, + const int32_t line, + const void *pointer, + const char_t *message + ) { + assertTrueImpl( + file, + line, + pointer != NULL, + message + ); + + // Ensure we can touch it + volatile char_t temp; + temp = *((char_t*)pointer); + } + + void assertNullImpl( + const char_t *file, + const int32_t line, + const void *pointer, + const char_t *message + ) { + assertTrueImpl( + file, + line, + pointer == NULL, + message + ); + } + + void assertDeprecatedImpl( + const char_t *file, + const int32_t line, + const char_t *message + ) { + assertUnreachableImpl(file, line, message); + } +#endif \ No newline at end of file diff --git a/src/assert/Assert.hpp b/src/assert/Assert.hpp new file mode 100644 index 00000000..a9a8ba17 --- /dev/null +++ b/src/assert/Assert.hpp @@ -0,0 +1,143 @@ +/** + * Copyright (c) 2023 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once +#include "dawn.hpp" + +#ifndef ASSERTIONS_FAKED + /** + * Assert a given value to be true. + * + * @param file File that the assertion is being made from. + * @param line Line that the assertion is being made from. + * @param x Value to assert as true. + * @param message Message to throw against assertion failure. + */ + void assertTrueImpl( + const char_t *file, + const int32_t line, + const bool_t x, + const char_t *message + ); + + /** + * Asserts a given statement to be false. + * + * @param file File that the assertion is being made from. + * @param line Line that the assertion is being made from. + * @param x Value to assert as false. + * @param message Message to throw against assertion failure. + */ + void assertFalseImpl( + const char_t *file, + const int32_t line, + const bool_t x, + const char_t *message + ); + + /** + * Asserts that a given line of code is unreachable. Essentially a forced + * assertion failure, good for "edge cases" + * + * @param file File that the assertion is being made from. + * @param line Line that the assertion is being made from. + * @param message Message to throw against assertion failure. + */ + void assertUnreachableImpl( + const char_t *file, + const int32_t line, + const char_t *message + ); + + /** + * Assert a given pointer to not point to a null pointer. + * + * @param file File that the assertion is being made from. + * @param line Line that the assertion is being made from. + * @param pointer Pointer to assert is not a null pointer. + * @param message Message to throw against assertion failure. + */ + void assertNotNullImpl( + const char_t *file, + const int32_t line, + const void *pointer, + const char_t *message + ); + + /** + * Asserts a given pointer to be a nullptr. + * + * @param file File that the assertion is being made from. + * @param line Line that the assertion is being made from. + * @param pointer Pointer to assert is nullptr. + * @param message Message to throw against assertion failure. + */ + void assertNullImpl( + const char_t *file, + const int32_t line, + const void *pointer, + const char_t *message + ); + + /** + * Asserts a function as being deprecated. + * + * @param file File that the assertion is being made from. + * @param line Line that the assertion is being made from. + * @param message Message to throw against assertion failure. + */ + void assertDeprecatedImpl( + const char_t *file, + const int32_t line, + const char_t *message + ); + + void assertMemoryRangeMatchesImpl( + const char_t *file, + const int32_t line, + const void *start, + const void *end, + const size_t size, + const char_t *message + ); + + #define assertTrue(x, message) \ + assertTrueImpl(__FILE__, __LINE__, x, message) + + #define assertFalse(x, message) \ + assertFalseImpl(__FILE__, __LINE__, x, message) + + #define assertUnreachable(message) \ + assertUnreachableImpl(__FILE__, __LINE__, message) + + #define assertNotNull(pointer, message) \ + assertNotNullImpl(__FILE__, __LINE__, pointer, message) + + #define assertNull(pointer, message) \ + assertNullImpl(__FILE__, __LINE__, pointer, message) + + #define assertDeprecated(message) \ + assertDeprecatedImpl(__FILE__, __LINE__, message) + + #define assertStrLenMax(str, len, message) \ + assertTrue(strlen(str) < len, message) + + #define assertStrLenMin(str, len, message) \ + assertTrue(strlen(str) >= len, message) + +#else + // If assertions are faked, we define the macros to do nothing. + #define assertTrue(x, message) ((void)0) + #define assertFalse(x, message) ((void)0) + #define assertUnreachable(message) ((void)0) + #define assertNotNull(pointer, message) ((void)0) + #define assertNull(pointer, message) ((void)0) + #define assertDeprecated(message) ((void)0) + #define assertStrLenMax(str, len, message) ((void)0) + #define assertStrLenMin(str, len, message) ((void)0) + +#endif \ No newline at end of file diff --git a/src/assert/CMakeLists.txt b/src/assert/CMakeLists.txt new file mode 100644 index 00000000..64aa4059 --- /dev/null +++ b/src/assert/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright (c) 2025 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Sources +target_sources(${DAWN_TARGET_NAME} + PRIVATE + Assert.cpp +) \ No newline at end of file diff --git a/src/console/CMakeLists.txt b/src/console/CMakeLists.txt new file mode 100644 index 00000000..8e236bde --- /dev/null +++ b/src/console/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright (c) 2025 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Sources +target_sources(${DUSK_TARGET_NAME} + PRIVATE + Console.cpp +) \ No newline at end of file diff --git a/src/console/Console.cpp b/src/console/Console.cpp new file mode 100644 index 00000000..c7730662 --- /dev/null +++ b/src/console/Console.cpp @@ -0,0 +1,146 @@ +// Copyright (c) 2025 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "Console.hpp" +#include "assert/Assert.hpp" + +using namespace Dawn; + +Console::Console(void) : + commands(), + variables(), + buffer() +{ +} + +void Console::registerCommand( + const std::string &cmd, + const std::function&)> &callback +) { + assertTrue(cmd.length() > 0, "cmd length must be > 0"); + assertTrue(callback != nullptr, "callback must not be null"); + + this->commands[cmd] = callback; +} + +template +void Console::registerVariable( + const std::string &var, + const std::function &getter, + const std::function &setter +) { + assertTrue(var.length() > 0, "var length must be > 0"); + assertTrue(getter != nullptr, "getter must not be null"); + assertTrue(setter != nullptr, "setter must not be null"); + + this->variables[var] = std::make_pair(getter, setter); +} + +void Console::update() { + enum class ParseState { FIND_CMD, FIND_ARG, COMMAND, ARG, ARG_QUOTED }; + + for (const auto &cmd : buffer) { + std::string cmdName; + std::vector args; + ParseState state = ParseState::FIND_CMD; + + std::string buff; + for(size_t i = 0; i < cmd.length(); i++) { + char_t c = cmd[i]; + + switch(state) { + case ParseState::FIND_CMD: + if(isspace(c)) continue; + state = ParseState::COMMAND; + buff += c; + break; + + case ParseState::FIND_ARG: + if(isspace(c)) continue; + if(c == '\"') { + state = ParseState::ARG_QUOTED; + break; + } + state = ParseState::ARG; + buff += c; + break; + + case ParseState::COMMAND: + if(isspace(c)) { + cmdName = buff; + buff.clear(); + state = ParseState::FIND_ARG; + break; + } + buff += c; + break; + + case ParseState::ARG: + if(isspace(c)) { + args.push_back(buff); + buff.clear(); + state = ParseState::FIND_ARG; + break; + } + buff += c; + break; + + case ParseState::ARG_QUOTED: + if(c == '\"') { + args.push_back(buff); + buff.clear(); + state = ParseState::FIND_ARG; + break; + } + buff += c; + break; + } + } + + if(buff.length() > 0) { + if(state == ParseState::COMMAND) { + cmdName = buff; + } else { + args.push_back(buff); + } + } + + // Find command + auto itCmd = commands.find(cmdName); + if(itCmd == commands.end()) { + // Find variable + auto itVar = variables.find(cmdName); + if(itVar == variables.end()) { + std::cout << "Console: Unknown command or variable '" << cmdName << "'" << std::endl; + continue; + } + + // Variable get/set + printf("Console: Variable '%s' ", cmdName.c_str()); + continue; + } + itCmd->second(args); + } + buffer.clear(); +} + +void Console::exec(const std::string &str) { + // Split strings by command seperator + std::istringstream iss(str); + std::string token; + while(std::getline(iss, token, COMMAND_SEPARATOR)) { + // Seperate by newlines too + std::istringstream lineIss(token); + std::string lineToken; + while(std::getline(lineIss, lineToken)) { + if(lineToken.length() == 0) continue; + buffer.push_back(lineToken); + } + } +} + +Console::~Console(void) { + +} \ No newline at end of file diff --git a/src/console/Console.hpp b/src/console/Console.hpp new file mode 100644 index 00000000..4ff0cdbf --- /dev/null +++ b/src/console/Console.hpp @@ -0,0 +1,72 @@ +// Copyright (c) 2025 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "dawn.hpp" + +namespace Dawn { + struct Console { + private: + std::map< + std::string, std::function&)> + > commands; + + std::map, std::function + >> variables; + + std::vector buffer; + + public: + static constexpr char_t COMMAND_SEPARATOR = ';'; + + /** + * Constructs the console. + */ + Console(void); + + /** + * Registers a command with the console. + * + * @param cmd The command string. + * @param callback The callback function for the command. + */ + void registerCommand( + const std::string &cmd, + const std::function&)> &callback + ); + + /** + * Registers a variable with the console. + * + * @param var The variable name. + * @param getter The getter function for the variable. + * @param setter The setter function for the variable. + */ + template + void registerVariable( + const std::string &var, + const std::function &getter, + const std::function &setter + ); + + /** + * Updates the console state, this will exec the command buffer. + */ + void update(); + + /** + * Executes a command string. + * + * @param str The command string to execute. + */ + void exec(const std::string &str); + + /** + * Destructs the console. + */ + ~Console(void); + }; +} \ No newline at end of file diff --git a/src/dawn.hpp b/src/dawn.hpp new file mode 100644 index 00000000..48c024cd --- /dev/null +++ b/src/dawn.hpp @@ -0,0 +1,48 @@ +/** + * Copyright (c) 2025 Dominic Masters + * + * This software is released under the MIT License. + * https://opensource.org/licenses/MIT + */ + +#pragma once + +extern "C" { + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + + // #include + // #include + // #include + + #if PSP + #include + #include + #include + #include + #include + #endif + + typedef bool bool_t; + typedef int int_t; + typedef float float_t; + typedef char char_t; +} + +#include +#include +#include +#include +#include +#include +#include +#include +#include \ No newline at end of file diff --git a/src/engine/CMakeLists.txt b/src/engine/CMakeLists.txt new file mode 100644 index 00000000..9970eefb --- /dev/null +++ b/src/engine/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright (c) 2025 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Sources +target_sources(${DUSK_TARGET_NAME} + PRIVATE + Engine.cpp +) \ No newline at end of file diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp new file mode 100644 index 00000000..494630c8 --- /dev/null +++ b/src/engine/Engine.cpp @@ -0,0 +1,32 @@ +// Copyright (c) 2025 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "Engine.hpp" + +using namespace Dawn; + +Engine::Engine() : + time(), + console() +{ + // console.registerCommand("echo", [](std::vector &args) { + // if(args.size() == 0) { + // std::cout << "Usage: echo " << std::endl; + // return; + // } + + // std::cout << args[0] << std::endl; + // }); + + // console.exec("echo"); +} + +void Engine::update(void) { + time.update(); + console.update(); +} + +Engine::~Engine() { +} \ No newline at end of file diff --git a/src/engine/Engine.hpp b/src/engine/Engine.hpp new file mode 100644 index 00000000..0717aa4e --- /dev/null +++ b/src/engine/Engine.hpp @@ -0,0 +1,31 @@ +// Copyright (c) 2025 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "time/Time.hpp" +#include "console/Console.hpp" + +namespace Dawn { + struct Engine { + public: + Time time; + Console console; + + /** + * Constructor for the Dawn engine. + */ + Engine(); + + /** + * Update the engine state. + */ + void update(void); + + /** + * Destructor for the Dawn engine. + */ + ~Engine(); + }; +} \ No newline at end of file diff --git a/src/funcs.c b/src/funcs.c deleted file mode 100644 index 73f18f9e..00000000 --- a/src/funcs.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "funcs.h" - -void doSomething(int32_t a, int32_t b) { - someNotImplementedFunction(a, b); -} - -void addNumbers(int32_t l, int32_t r) { - doSomething(l + r, 32); -} \ No newline at end of file diff --git a/src/funcs.h b/src/funcs.h deleted file mode 100644 index 6a178dd7..00000000 --- a/src/funcs.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef FUNC_H -#define FUNC_H - -typedef int int32_t; - -void doSomething(int32_t a, int32_t b); - -void someNotImplementedFunction(int32_t x, int32_t y); - -void addNumbers(int32_t l, int32_t r); - -void someHeaderImplementedFunction(int32_t a, int32_t b) { - doSomething(a, b); -} - -#endif // FUNC_H \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 00000000..d78253ee --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,23 @@ +// Copyright (c) 2025 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "dawn.hpp" +#include "engine/Engine.hpp" + +using namespace Dawn; + +static std::shared_ptr engine; + +int main(int argc, char **argv) { + engine = std::make_shared(); + + while(1) { + engine->update(); + break; + } + + engine = nullptr; + return 0; +} \ No newline at end of file diff --git a/src/time/CMakeLists.txt b/src/time/CMakeLists.txt new file mode 100644 index 00000000..8f4a724f --- /dev/null +++ b/src/time/CMakeLists.txt @@ -0,0 +1,10 @@ +# Copyright (c) 2025 Dominic Masters +# +# This software is released under the MIT License. +# https://opensource.org/licenses/MIT + +# Sources +target_sources(${DAWN_TARGET_NAME} + PRIVATE + Time.cpp +) \ No newline at end of file diff --git a/src/time/Time.cpp b/src/time/Time.cpp new file mode 100644 index 00000000..8e9e64e6 --- /dev/null +++ b/src/time/Time.cpp @@ -0,0 +1,41 @@ +// Copyright (c) 2025 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "Time.hpp" +#include "assert/Assert.hpp" + +using namespace Dawn; + +Time::Time(void) : + delta(Time::FIXED_STEP), + time(0.0f), + fixedDelta(Time::FIXED_STEP), + fixedTime(0.0f), + isFixedUpdate(false) +{ +} + +void Time::update(void) { + float_t delta; + + #if TIME_SDL2 + delta = (float_t)SDL_GetTicks() / 1000.0f - this->time; + #else + + #endif + + this->delta = delta; + assertTrue(this->delta >= 0.0f, "Delta time is negative"); + this->time += delta; + + this->isFixedUpdate = this->time - this->fixedTime >= Time::FIXED_STEP; + if (this->isFixedUpdate) { + this->fixedDelta = Time::FIXED_STEP; + this->fixedTime += this->fixedDelta; + } else { + this->fixedDelta = 0.0f; + this->fixedTime += this->fixedDelta; + } +} \ No newline at end of file diff --git a/src/time/Time.hpp b/src/time/Time.hpp new file mode 100644 index 00000000..f99ebeb9 --- /dev/null +++ b/src/time/Time.hpp @@ -0,0 +1,35 @@ +// Copyright (c) 2025 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#pragma once +#include "dawn.hpp" + +namespace Dawn { + struct Time { + private: + bool_t isFixedUpdate; + + public: + static constexpr float_t FIXED_STEP = 1.0f / 60.0f; + #if TIME_FIXED + static const float_t FIXED_PLATFORM_STEP = TIME_PLATFORM_STEP; + #endif + + float_t delta; + float_t time; + float_t fixedDelta; + float_t fixedTime; + + /** + * The time in seconds since the application started. + */ + Time(void); + + /** + * Update the time values. + */ + void update(void); + }; +} \ No newline at end of file