Compare commits
4 Commits
31ebef777b
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| dda6e25bf9 | |||
| 518995ddd1 | |||
| e8498f9e66 | |||
| 88f5d02b6a |
@@ -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")
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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; }
|
||||
@@ -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] =
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user