Skip to content
Open
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
42 changes: 34 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ if(MSVC)
endif()

# --- Build all vendor dependencies ---
add_subdirectory(vendors/freeglut)
add_subdirectory(vendors/SDL3)
add_subdirectory(vendors/spdlog)
add_subdirectory(vendors/json)
add_subdirectory(vendors/yaml-cpp)
add_subdirectory(vendors/assimp)
add_subdirectory(vendors/freeglut SYSTEM)
add_subdirectory(vendors/SDL3 SYSTEM)
add_subdirectory(vendors/spdlog SYSTEM)
add_subdirectory(vendors/json SYSTEM)
add_subdirectory(vendors/yaml-cpp SYSTEM)
add_subdirectory(vendors/assimp SYSTEM)

# --- Find system packages ---
find_package(OpenGL REQUIRED)
Expand Down Expand Up @@ -252,6 +252,21 @@ if(WIN32 OR USE_MINGW)
)
endif()

# --- Warnings, only on engine code and not on vendored sources built in ---
set(ENGINE_WARNING_SOURCES ${ENGINE_SOURCES})
list(REMOVE_ITEM ENGINE_WARNING_SOURCES
src/Assets/stb_image_impl.cpp
src/Graphics/OpenGL/glad.c
)
if(MSVC)
set(ENGINE_WARNING_FLAGS /W4)
else()
set(ENGINE_WARNING_FLAGS -Wall -Wextra -Wpedantic)
endif()
set_source_files_properties(${ENGINE_WARNING_SOURCES}
PROPERTIES COMPILE_OPTIONS "${ENGINE_WARNING_FLAGS}"
)

# --- Header files (for IDE source groups) ---
file(GLOB_RECURSE ENGINE_PUBLIC_HEADERS "include/public/*.hpp")
file(GLOB_RECURSE ENGINE_PRIVATE_HEADERS "include/private/*.hpp")
Expand Down Expand Up @@ -293,6 +308,13 @@ set_target_properties(Engine PROPERTIES
)
target_compile_features(Engine PUBLIC cxx_std_23)

# --- Only ENGINE_API symbols are exported, matching the Windows DLL ---
set_target_properties(Engine PROPERTIES
C_VISIBILITY_PRESET hidden
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON
)

# --- Generated version header ---
set(ENGINE_GENERATED_INCLUDE_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated/include)
configure_file(
Expand All @@ -311,12 +333,16 @@ target_include_directories(Engine
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/public>
$<BUILD_INTERFACE:${ENGINE_GENERATED_INCLUDE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/SleakEngine>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include/private
)
target_include_directories(Engine SYSTEM
PUBLIC
$<BUILD_INTERFACE:${VENDOR_DIR}/spdlog/include>
$<BUILD_INTERFACE:${VENDOR_DIR}/json/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/SleakEngine>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/SleakEngine/vendor>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include/private
${Vulkan_INCLUDE_DIR}
${OPENGL_INCLUDE_DIR}
${VENDOR_DIR}/imgui
Expand Down
4 changes: 2 additions & 2 deletions include/private/Graphics/Vulkan/VulkanRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
#include <backends/imgui_impl_vulkan.h>

namespace Sleak {
class ENGINE_API Window;
namespace RenderEngine {
class Window;
namespace RenderEngine {

struct QueueIndices {
uint32_t GraphicsIndex = UINT32_MAX;
Expand Down
57 changes: 29 additions & 28 deletions include/public/Core/File.hpp
Original file line number Diff line number Diff line change
@@ -1,51 +1,52 @@
#ifndef _FILE_H_
#define _FILE_H_

#include <Core/OSDef.hpp>
#include <fstream>
#include <string>
#include <vector>
#include <fstream>

namespace Sleak {

/// Thin wrapper over std::fstream for text/binary file I/O.
/// @ingroup filesystem
class File {
public:
// Constructor and Destructor
File();
~File();
class ENGINE_API File {
public:
// Constructor and Destructor
File();
~File();

// Opens a file with the specified mode
bool Open(const std::string& filename, const std::string& mode);
// Opens a file with the specified mode
bool Open(const std::string& filename, const std::string& mode);

// Closes the currently open file
void Close();
// Closes the currently open file
void Close();

// Reads all text from the file
std::string ReadAllText();
// Reads all text from the file
std::string ReadAllText();

// Reads all bytes from the file
std::vector<unsigned char> ReadAllBytes();
// Reads all bytes from the file
std::vector<unsigned char> ReadAllBytes();

// Writes all text to the file
bool WriteAllText(const std::string& content);
// Writes all text to the file
bool WriteAllText(const std::string& content);

// Writes all bytes to the file
bool WriteAllBytes(const std::vector<unsigned char>& data);
// Writes all bytes to the file
bool WriteAllBytes(const std::vector<unsigned char>& data);

// Checks if a file exists
static bool Exists(const std::string& filename);
// Checks if a file exists
static bool Exists(const std::string& filename);

private:
// File stream for reading and writing
std::fstream m_fileStream;
private:
// File stream for reading and writing
std::fstream m_fileStream;

// Current file mode
std::string m_mode;
// Current file mode
std::string m_mode;

// Platform-specific implementation for file existence check
static bool ExistsImpl(const std::string& filename);
};
// Platform-specific implementation for file existence check
static bool ExistsImpl(const std::string& filename);
};

} // namespace Sleak

Expand Down
15 changes: 8 additions & 7 deletions include/public/Core/OSDef.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,14 @@
#define PLATFORM_IOS
#define OS "ios"
#define WINDOW_SYSTEM "quartz"
#define SLEAK_API
#define ENGINE_API
#define SLEAK_API

/* Android devices (need to be defined before linux) */
#elif defined(__ANDROID__)
#define PLATFORM_ANDROID
#define OS "android"
#define WINDOW_SYSTEM "surfaceflinger"
#define SLEAK_API
#define ENGINE_API
#define WINDOW_SYSTEM "surfaceflinger"
#define SLEAK_API

/* Berkley Software Distribution */
#elif defined(__FreeBSD__)
Expand All @@ -49,14 +47,17 @@
#define PLATFORM_LINUX
#define OS "linux"
#define WINDOW_SYSTEM std::getenv("XDG_SESSION_TYPE")
#define SLEAK_API
#define ENGINE_API
#define SLEAK_API

#else
#error "Undefined OS"

#endif

#ifndef _WIN32
#define ENGINE_API __attribute__((visibility("default")))
#endif

#define MACRO_STR(macro) #macro

#define RESOURCE(path) R"(assets/textures/" path ")"
Expand Down
39 changes: 20 additions & 19 deletions include/public/Core/Object.hpp
Original file line number Diff line number Diff line change
@@ -1,38 +1,39 @@
#ifndef _OBJECT_H_
#define _OBJECT_H_

#include <Core/OSDef.hpp>
#include <atomic>
#include <cstdint>
#include <string>
#include <atomic>

namespace Sleak {
/// Base for anything needing a stable identity: a name and a
/// process-unique, atomically assigned ID.
/// @ingroup core
class Object {
public:
Object(const std::string& name = "Object")
: m_name(name),
m_uniqueID(s_nextUniqueID.fetch_add(1, std::memory_order_relaxed)) {}
class ENGINE_API Object {
public:
Object(const std::string& name = "Object")
: m_name(name),
m_uniqueID(s_nextUniqueID.fetch_add(1, std::memory_order_relaxed)) {}

virtual ~Object() = default;
virtual ~Object() = default;

uint64_t GetUniqueID() const { return m_uniqueID; }
uint64_t GetUniqueID() const { return m_uniqueID; }

const std::string& GetName() const { return m_name; }
const std::string& GetName() const { return m_name; }

/// Name plus unique ID, for logs where names can repeat.
std::string GetDebugName() const {
return m_name + "-" + std::to_string(m_uniqueID);
}
/// Name plus unique ID, for logs where names can repeat.
std::string GetDebugName() const {
return m_name + "-" + std::to_string(m_uniqueID);
}

inline void SetName(const std::string& value) { m_name = value; }
inline void SetName(const std::string& value) { m_name = value; }

private:
std::string m_name;
uint64_t m_uniqueID;
static inline std::atomic<uint64_t> s_nextUniqueID = 0;
};
private:
std::string m_name;
uint64_t m_uniqueID;
static inline std::atomic<uint64_t> s_nextUniqueID = 0;
};
}

#endif
21 changes: 11 additions & 10 deletions include/public/Core/Timer.hpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
#ifndef _TIMER_HPP_
#define _TIMER_HPP_

#include <Core/OSDef.hpp>
#include <chrono>

namespace Sleak {
/// Wall-clock stopwatch built on std::chrono. Application keeps one for
/// frame delta time.
/// @ingroup core
class Timer {
public:
Timer();
class ENGINE_API Timer {
public:
Timer();

/// Restarts the clock at zero.
void Reset();
/// Restarts the clock at zero.
void Reset();

/// Seconds since construction or the last Reset().
float Elapsed() const;
/// Seconds since construction or the last Reset().
float Elapsed() const;

private:
std::chrono::time_point<std::chrono::high_resolution_clock> startPoint;
};
private:
std::chrono::time_point<std::chrono::high_resolution_clock> startPoint;
};
};

#endif
20 changes: 11 additions & 9 deletions include/public/FileSystem/Serializable.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#ifndef _SERIALIZABLE_H_
#define _SERIALIZABLE_H_

#include <yaml-cpp/yaml.h>

#include <Core/OSDef.hpp>
#include <any>
#include <iostream>
#include <string>
#include <memory>
#include <unordered_map>
#include <any>
#include <stdexcept>
#include <nlohmann/json.hpp>
#include <yaml-cpp/yaml.h>
#include <stdexcept>
#include <string>
#include <unordered_map>

namespace Sleak {

Expand Down Expand Up @@ -48,8 +50,8 @@ namespace Sleak {
* @brief Base class for objects that can be serialized and deserialized.
* @ingroup filesystem
*/
class Serializable {
public:
class ENGINE_API Serializable {
public:
virtual ~Serializable() = default;

/**
Expand Down Expand Up @@ -82,8 +84,8 @@ namespace Sleak {
* @brief Detects file format and creates the appropriate serialization context.
* @ingroup filesystem
*/
class SerializationFactory {
public:
class ENGINE_API SerializationFactory {
public:
/// Picks a format from filePath's extension (.bin/.json/.yaml/.yml).
static SerializationFormat DetectFormat(const std::string& filePath);
/// Builds the context implementation matching format.
Expand Down
7 changes: 4 additions & 3 deletions include/public/Math/Color.hpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
#ifndef _COLOR_HPP_
#define _COLOR_HPP_

#include <Core/OSDef.hpp>
#include <Math/Math.hpp>
#include <Math/Vector.hpp>
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <sstream>
#include <string>
#include <Math/Math.hpp>
#include <Math/Vector.hpp>

namespace Sleak {
namespace Math {
/// 8-bit RGBA color. Value type, cheap to pass and store on vertices/UI.
/// @ingroup math
class Color {
class ENGINE_API Color {
public:
static const Color Red;
static const Color Green;
Expand Down
Loading
Loading