Skip to content
Draft
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
28 changes: 23 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,43 @@ jobs:
strategy:
fail-fast: true
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
# os: [windows-latest, ubuntu-latest, macos-latest] // TODO:
os: [windows-latest, ubuntu-24.04]
build-variant: [Debug, Release]
steps:
- uses: actions/checkout@v4

# TODO: Install GCC without using a script.
- if: matrix.os == 'ubuntu-latest'
- if: matrix.os == 'ubuntu-24.04'
name: Installing GCC
uses: egor-tensin/setup-gcc@v1
with:
version: 12
version: 14

- if: matrix.os == 'ubuntu-latest'
# - if: matrix.os == 'ubuntu-24.04'
# name: Installing GCC
# run: |
# sudo apt-get install gcc-14.2.0 g++-14.2.0
# echo "gcc=$gcc" >> $env:GITHUB_OUTPUT
# echo "gxx=$gxx" >> $env:GITHUB_OUTPUT
- if: matrix.os == 'ubuntu-24.04'
name: Setup Ninja
uses: ashutoshvarma/setup-ninja@master
with:
version: 1.12.1

- if: matrix.os == 'ubuntu-24.04'
name: Installing Linux dependencies
run: |
sudo apt update
sudo apt-get install -y libx11-dev libxkbcommon-x11-dev libx11-xcb-dev

- name: Configuring
- if: matrix.os == 'ubuntu-24.04'
name: Configuring
run: cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=${{matrix.build-variant}} -DCORE_BUILD_UNITY=OFF # TODO: Re-enable unity build.

- if: matrix.os != 'ubuntu-24.04'
name: Configuring
run: cmake -B build -DCMAKE_BUILD_TYPE=${{matrix.build-variant}} -DCORE_BUILD_UNITY=OFF # TODO: Re-enable unity build.

- name: Building
Expand Down
7 changes: 5 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.28.2)

project(core VERSION 0.0.1)

Expand All @@ -18,6 +18,7 @@ set(CMAKE_PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/$<CONFIG>")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/$<CONFIG>")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/$<CONFIG>")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin/$<CONFIG>")
set(PREBUILT_MODULE_PATH "${CMAKE_BINARY_DIR}/bin/$<CONFIG>")

# Global compile definitions.
set(GLOBAL_COMPILE_DEFINITIONS
Expand All @@ -34,9 +35,11 @@ set(GLOBAL_COMPILE_DEFINITIONS
$<$<PLATFORM_ID:Darwin>:PLATFORM_MACOS=1>
)

set(CMAKE_CXX_STANDARD 20)

# Global compile options.
if(MSVC)
set(GLOBAL_COMPILE_OPTIONS -W4 -WX -std:c++20 -Zc:preprocessor -wd5105)
set(GLOBAL_COMPILE_OPTIONS -W4 -WX -std:c++20 -Zc:preprocessor -wd5105 -wd4273)
else()
# TODO: -Wno-deprecated-declarations is due to doctest.h sprintf() function.
set(GLOBAL_COMPILE_OPTIONS -Wall -Wextra -pedantic -Werror -std=c++2b -fno-exceptions -Wno-invalid-offsetof -Wno-nested-anon-types -Wno-c++11-narrowing -Wno-gnu-zero-variadic-macro-arguments -Wno-deprecated-declarations -Wno-enum-constexpr-conversion -Wno-unknown-warning-option
Expand Down
16 changes: 12 additions & 4 deletions core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
set(HEADER_FILES
base64.h
defer.h
defines.h
ecs.h
formatter.h
hash.h
json.h
Expand All @@ -26,8 +24,6 @@ set(HEADER_FILES
)

set(SOURCE_FILES
base64.cpp
ecs.cpp
formatter.cpp
json.cpp
log.cpp
Expand Down Expand Up @@ -76,6 +72,18 @@ if(${CORE_BUILD_STATIC})
set(BUILD_TYPE STATIC)
endif()
add_library(core ${BUILD_TYPE} ${HEADER_FILES} ${SOURCE_FILES})

# TODO:
target_sources(core
PUBLIC
FILE_SET all_my_modules TYPE CXX_MODULES
BASE_DIRS
${PROJECT_SOURCE_DIR}
FILES
base64.cppm
ecs.cppm
)

target_link_libraries(core PUBLIC ${LIBS})
target_compile_options(core PRIVATE ${GLOBAL_COMPILE_OPTIONS})
target_compile_definitions(core PRIVATE ${GLOBAL_COMPILE_DEFINITIONS})
Expand Down
54 changes: 49 additions & 5 deletions core/base64.cpp → core/base64.cppm
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
#include "core/base64.h"
module;

#include "core/export.h"
#include "core/defines.h"
#include "core/export.h"
#include "core/memory/memory.h"
#include "core/containers/string.h"

export module base64;

/*
TODO:
- [ ] Should decode return a String or an Array<u8>?
- [ ] Should use Result<T>?
*/

inline static constexpr const char *BASE64_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

String
base64_encode(const u8 *data, u64 size, memory::Allocator *allocator)
export CORE_API String
base64_encode(const u8 *data, u64 size, memory::Allocator *allocator = memory::heap_allocator())
{
String out = string_init(allocator);

Expand All @@ -30,8 +44,8 @@ base64_encode(const u8 *data, u64 size, memory::Allocator *allocator)
return out;
}

String
base64_decode(const String &data, memory::Allocator *allocator)
export CORE_API String
base64_decode(const String &data, memory::Allocator *allocator = memory::heap_allocator())
{
constexpr auto index = [](const String &data, char c) -> u8 {
for (u8 i = 0; i < data.count; ++i)
Expand Down Expand Up @@ -81,4 +95,34 @@ base64_decode(const String &data, memory::Allocator *allocator)
}

return out;
}

export inline String
base64_encode(const Block &data, memory::Allocator *allocator = memory::heap_allocator())
{
return base64_encode((const u8 *)data.data, data.size, allocator);
}

export inline String
base64_encode(const Array<u8> &data, memory::Allocator *allocator = memory::heap_allocator())
{
return base64_encode(data.data, data.count, allocator);
}

export inline String
base64_encode(const String &data, memory::Allocator *allocator = memory::heap_allocator())
{
return base64_encode((const u8 *)data.data, data.count, allocator);
}

export inline String
base64_encode(const char *data, memory::Allocator *allocator = memory::heap_allocator())
{
return base64_encode(string_literal(data), allocator);
}

export inline String
base64_decode(const char *data, memory::Allocator *allocator = memory::heap_allocator())
{
return base64_decode(string_literal(data), allocator);
}
48 changes: 0 additions & 48 deletions core/base64.h

This file was deleted.

13 changes: 0 additions & 13 deletions core/ecs.cpp

This file was deleted.

51 changes: 30 additions & 21 deletions core/ecs.h → core/ecs.cppm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once
module;

#include "core/export.h"
#include "core/defines.h"
Expand All @@ -8,10 +8,13 @@
#include <type_traits>
#include <typeinfo>
#include <concepts>
#include <atomic>

export module ecs;

namespace ecs
{
struct Entity
export struct Entity
{
u64 id = U64_MAX;

Expand All @@ -28,9 +31,6 @@ namespace ecs
}
};

CORE_API Entity
entity_new();

typedef u64 Component_Hash;

struct IComponent_Table
Expand Down Expand Up @@ -121,7 +121,7 @@ namespace ecs
}
};

struct ECS
export struct ECS
{
Hash_Table<Component_Hash, IComponent_Table *> component_tables;

Expand Down Expand Up @@ -186,13 +186,13 @@ namespace ecs
}
};

inline static ECS
export inline ECS
ecs_new()
{
return {hash_table_init<Component_Hash, IComponent_Table *>()};
}

inline static void
export inline void
ecs_free(ECS &self)
{
for (auto &[_, v] : self.component_tables)
Expand All @@ -201,50 +201,59 @@ namespace ecs
hash_table_deinit(self.component_tables);
}

template <typename T>
inline static void
export template <typename T>
inline void
ecs_add_table(ECS &self)
{
hash_table_insert(self.component_tables, (u64)typeid(T).hash_code(), (IComponent_Table *)memory::allocate_and_call_constructor<Component_Table<T>>());
const std::type_info &info = typeid(T);
hash_table_insert(self.component_tables, (u64)info.hash_code(), (IComponent_Table *)memory::allocate_and_call_constructor<Component_Table<T>>());
}

template <Component_Type T>
inline static const T *
export template <Component_Type T>
inline const T *
ecs_component_read(ECS &self, Entity e)
{
return self.read<T>(e);
}

template <Component_Type T>
inline static T *
export template <Component_Type T>
inline T *
ecs_component_write(ECS &self, Entity e)
{
return self.write<T>(e);
}

template <Component_Type T>
inline static void
export template <Component_Type T>
inline void
ecs_component_remove(ECS &self, Entity e)
{
self.remove<T>(e);
}

template <Component_Type ...TArgs>
inline static Array<Entity>
export template <Component_Type ...TArgs>
inline Array<Entity>
ecs_entity_list(ECS &self)
{
return self.list<TArgs...>();
}

// TODO: Test this.
inline static void
export inline void
ecs_reload(ECS &self)
{
self.reload();
}

export CORE_API Entity
entity_new()
{
static std::atomic<u64> id = 0;
return Entity{id.fetch_add(1)};
}

// TODO: Rename this to ecs_entity_remove()?
inline static void
// TODO: Should set the id of the removed entity to U64_MAX?
export inline void
ecs_entity_free(ECS &self, Entity e)
{
self.entity_free(e);
Expand Down
Loading