Compare commits

...

7 Commits

Author SHA1 Message Date
cat
dda6e25bf9 Added MPL-2.0 to CMakeLists.txt 2026-01-09 01:01:19 +02:00
cat
518995ddd1 Restructuring 2026-01-09 00:23:37 +02:00
cat
e8498f9e66 Added colours to logging by default 2026-01-08 21:47:10 +02:00
cat
88f5d02b6a Minor tweaks on the general codebase 2026-01-06 04:10:58 +02:00
cat
31ebef777b Added a basic CMAKE script (no find library or pkg-config yet!) 2026-01-06 03:10:55 +02:00
cat
cb9005bf80 Tweaked Xoshiro.h to fix a warn 2026-01-06 03:10:34 +02:00
cat
b457ecce47 Restructing on the project 2026-01-06 03:10:27 +02:00
11 changed files with 74 additions and 26 deletions

39
CMakeLists.txt Normal file
View File

@@ -0,0 +1,39 @@
# SPDX-FileCopyrightText: Dora "cat" <cat@thenight.club>
# SPDX-License-Identifier: MPL-2.0
#
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at http://mozilla.org/MPL/2.0/.
cmake_minimum_required(VERSION 3.10)
project(Tourmaline VERSION 1)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=address")
endif()
include(GNUInstallDirs)
include_directories(headers)
add_library(${PROJECT_NAME} SHARED
"source/Systems/ECS/Component.cpp"
"source/Systems/ECS/World.cpp"
"source/Systems/Logging.cpp"
"source/Systems/Random.cpp"
"source/Types/UUID.cpp")
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION})
# Nothing to link right now
target_link_libraries(${PROJECT_NAME})
install(
TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin)
install(DIRECTORY headers/ DESTINATION include/${PROJECT_NAME})

View File

@@ -15,10 +15,10 @@
#include <unordered_map>
#include <utility>
#include "Systems/Logging.hpp"
#include "Types.hpp"
#include "../Types.hpp"
#include "Logging.hpp"
namespace Tourmaline::ECS {
namespace Tourmaline::Systems::ECS {
using Entity = Tourmaline::Type::UUID;
class World;
@@ -49,7 +49,6 @@ public:
// Components
template <Component T, typename... Args>
T &AddComponent(const Entity &entity, Args &&...constructionArguments) {
// Insert to entity list
auto entityIter = GetEntityIterator(
entity,
std::format(
@@ -143,5 +142,5 @@ private:
Tourmaline::Systems::Logging::LogLevel severity =
Systems::Logging::LogLevel::Warning);
};
} // namespace Tourmaline::ECS
} // namespace Tourmaline::Systems::ECS
#endif

View File

@@ -6,7 +6,8 @@
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef GUARD_TOURMALINE_LOGGING_H
#define GUARD_TOURMALINE_LOGGING_H
#include <array>
#include <fstream>
#include <string>
@@ -30,6 +31,8 @@ public:
private:
static std::fstream File;
static std::array<const std::string, 6> LogLevelToString;
static std::array<std::pair<const std::string, const std::string>, 6>
LogLevelToString;
};
} // namespace Tourmaline::Systems
#endif

View File

@@ -41,10 +41,8 @@ namespace std {
template <> struct hash<Tourmaline::Type::UUID> {
size_t operator()(const Tourmaline::Type::UUID &uuid) const noexcept {
const auto data = uuid.data.get();
size_t h1 = std::hash<uint64_t>{}(data[0]);
size_t h2 = std::hash<uint64_t>{}(data[1]);
// Combine the two hashes
size_t h1 = std::hash<uint64_t>{}(data[0]),
h2 = std::hash<uint64_t>{}(data[1]);
return h1 ^ (h2 << 1);
}
};

View File

@@ -73,7 +73,7 @@ static inline void jump_state(const int_t jump_table[4], rng_t &rng)
int_t s3 = 0;
for (int i = 0; i < 4; i++)
{
for (int b = 0; b < 8*sizeof(int_t); b++)
for (int b = 0; b < static_cast<int>(8*sizeof(int_t)); b++) // static_cast has been added by Tourmaline Engine!
{
if (jump_table[i] & ((int_t)1) << b)
{

View File

@@ -7,8 +7,8 @@
* obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "../ECS.hpp"
#include "../../../headers/Systems/ECS.hpp"
using namespace Tourmaline::ECS;
using namespace Tourmaline::Systems::ECS;
const Entity &BaseComponent::GetOwner() { return *this->owner; }

View File

@@ -7,10 +7,10 @@
* obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "../ECS.hpp"
#include "../Systems/Random.hpp"
#include "../../../headers/Systems/ECS.hpp"
#include "../../../headers/Systems/Random.hpp"
using namespace Tourmaline::ECS;
using namespace Tourmaline::Systems::ECS;
Entity World::CreateEntity() {
auto [iterator, success] =

View File

@@ -7,7 +7,8 @@
* obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "../Logging.hpp"
#include "../../headers/Systems/Logging.hpp"
#include <cerrno>
#include <chrono>
#include <cstddef>
@@ -17,13 +18,19 @@
#include <print>
#include <stdexcept>
#include <string>
#include <utility>
using namespace Tourmaline::Systems;
// This is what happens when it takes you 50 years to implement
// reflections to a language
std::array<const std::string, 6> Logging::LogLevelToString{
"Critical", "Error", "Warning", "Info", "Debug", "Trace"};
std::array<std::pair<const std::string, const std::string>, 6>
Logging::LogLevelToString{std::pair{"Critical", "[0;31m"},
{"Error", "[0;91m"},
{"Warning", "[0;33m"},
{"Info", "[0;37m"},
{"Debug", "[0;92m"},
{"Trace", "[0;36m"}};
std::fstream Logging::File;
void Logging::LogToFile(std::string File) {
@@ -42,12 +49,12 @@ void Logging::LogToFile(std::string File) {
void Logging::Log(const std::string &message, const std::string &position,
Logging::LogLevel severity, bool assertion) {
if (assertion) [[likely]] {
auto loglevelData =
Logging::LogLevelToString[static_cast<size_t>(severity)];
std::string output =
std::format("[{}@{}] {}\n",
Logging::LogLevelToString[static_cast<size_t>(severity)],
position, message);
std::format("[{}@{}] {}\n", loglevelData.first, position, message);
std::print("{}", output);
std::print("\033{} {}\033[0m", loglevelData.second, output);
if (Logging::File.is_open()) {
Logging::File.write(output.c_str(), output.size());
Logging::File.flush(); // Terrible but necessary sadly

View File

@@ -6,7 +6,8 @@
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "../Random.hpp"
#include "../../headers/Systems/Random.hpp"
#include <bit>
#include <cstdint>
#include <ctime>

View File

@@ -7,7 +7,8 @@
* obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "../Types.hpp"
#include "../../headers/Types.hpp"
#include <charconv>
#include <cstdint>
#include <cstring>