Compare commits

...

4 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
7 changed files with 34 additions and 23 deletions

View File

@@ -1,3 +1,10 @@
# 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)
@@ -12,8 +19,8 @@ include(GNUInstallDirs)
include_directories(headers)
add_library(${PROJECT_NAME} SHARED
"source/ECS/Component.cpp"
"source/ECS/World.cpp"
"source/Systems/ECS/Component.cpp"
"source/Systems/ECS/World.cpp"
"source/Systems/Logging.cpp"
"source/Systems/Random.cpp"
"source/Types/UUID.cpp")

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

@@ -31,7 +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

@@ -7,8 +7,8 @@
* obtain one at http://mozilla.org/MPL/2.0/.
*/
#include "../../headers/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 "../../headers/ECS.hpp"
#include "../../headers/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

@@ -18,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) {
@@ -43,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