Compare commits
1 Commits
main
...
959722686f
| Author | SHA1 | Date | |
|---|---|---|---|
| 959722686f |
@@ -1,39 +0,0 @@
|
||||
# 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})
|
||||
@@ -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 < static_cast<int>(8*sizeof(int_t)); b++) // static_cast has been added by Tourmaline Engine!
|
||||
for (int b = 0; b < 8*sizeof(int_t); b++)
|
||||
{
|
||||
if (jump_table[i] & ((int_t)1) << b)
|
||||
{
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
|
||||
#include "../Types.hpp"
|
||||
#include "Logging.hpp"
|
||||
#include "Systems/Logging.hpp"
|
||||
#include "Types.hpp"
|
||||
|
||||
namespace Tourmaline::Systems::ECS {
|
||||
namespace Tourmaline::ECS {
|
||||
using Entity = Tourmaline::Type::UUID;
|
||||
class World;
|
||||
|
||||
@@ -41,14 +41,15 @@ public:
|
||||
// Entity
|
||||
Entity CreateEntity();
|
||||
bool EntityExists(const Entity &entity) noexcept;
|
||||
[[nodiscard("It is not guaranteed that an entity can always be destroyed, "
|
||||
"please make "
|
||||
"sure by checking the returned bool")]]
|
||||
[[nodiscard(
|
||||
"It is not guranteed that an entity can always be destroyed, please make "
|
||||
"sure by checking the returned bool")]]
|
||||
bool DestroyEntity(Entity entity);
|
||||
|
||||
// Components
|
||||
template <Component T, typename... Args>
|
||||
T &AddComponent(const Entity &entity, Args &&...constructionArguments) {
|
||||
// Insert to entity list
|
||||
auto entityIter = GetEntityIterator(
|
||||
entity,
|
||||
std::format(
|
||||
@@ -104,9 +105,9 @@ public:
|
||||
}
|
||||
|
||||
template <Component T>
|
||||
[[nodiscard("It is not guaranteed that a component can always be removed, "
|
||||
"please make "
|
||||
"sure by checking the returned bool")]]
|
||||
[[nodiscard(
|
||||
"It is not guranteed that a component can always be removed, please make "
|
||||
"sure by checking the returned bool")]]
|
||||
bool RemoveComponent(const Entity &entity) {
|
||||
auto entityIter = GetEntityIterator(
|
||||
entity,
|
||||
@@ -142,5 +143,5 @@ private:
|
||||
Tourmaline::Systems::Logging::LogLevel severity =
|
||||
Systems::Logging::LogLevel::Warning);
|
||||
};
|
||||
} // namespace Tourmaline::Systems::ECS
|
||||
} // namespace Tourmaline::ECS
|
||||
#endif
|
||||
@@ -7,8 +7,8 @@
|
||||
* obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "../../../headers/Systems/ECS.hpp"
|
||||
#include "../ECS.hpp"
|
||||
|
||||
using namespace Tourmaline::Systems::ECS;
|
||||
using namespace Tourmaline::ECS;
|
||||
|
||||
const Entity &BaseComponent::GetOwner() { return *this->owner; }
|
||||
@@ -7,10 +7,10 @@
|
||||
* obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "../../../headers/Systems/ECS.hpp"
|
||||
#include "../../../headers/Systems/Random.hpp"
|
||||
#include "../ECS.hpp"
|
||||
#include "../Systems/Random.hpp"
|
||||
|
||||
using namespace Tourmaline::Systems::ECS;
|
||||
using namespace Tourmaline::ECS;
|
||||
|
||||
Entity World::CreateEntity() {
|
||||
auto [iterator, success] =
|
||||
@@ -7,8 +7,7 @@
|
||||
* obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "../../headers/Systems/Logging.hpp"
|
||||
|
||||
#include "../Logging.hpp"
|
||||
#include <cerrno>
|
||||
#include <chrono>
|
||||
#include <cstddef>
|
||||
@@ -18,19 +17,13 @@
|
||||
#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<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::array<const std::string, 6> Logging::LogLevelToString{
|
||||
"Critical", "Error", "Warning", "Info", "Debug", "Trace"};
|
||||
std::fstream Logging::File;
|
||||
|
||||
void Logging::LogToFile(std::string File) {
|
||||
@@ -49,12 +42,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", loglevelData.first, position, message);
|
||||
std::format("[{}@{}] {}\n",
|
||||
Logging::LogLevelToString[static_cast<size_t>(severity)],
|
||||
position, message);
|
||||
|
||||
std::print("\033{} {}\033[0m", loglevelData.second, output);
|
||||
std::print("{}", output);
|
||||
if (Logging::File.is_open()) {
|
||||
Logging::File.write(output.c_str(), output.size());
|
||||
Logging::File.flush(); // Terrible but necessary sadly
|
||||
@@ -6,8 +6,7 @@
|
||||
* 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 "../../headers/Systems/Random.hpp"
|
||||
|
||||
#include "../Random.hpp"
|
||||
#include <bit>
|
||||
#include <cstdint>
|
||||
#include <ctime>
|
||||
@@ -6,8 +6,7 @@
|
||||
* 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>
|
||||
@@ -31,8 +30,6 @@ public:
|
||||
|
||||
private:
|
||||
static std::fstream File;
|
||||
static std::array<std::pair<const std::string, const std::string>, 6>
|
||||
LogLevelToString;
|
||||
static std::array<const std::string, 6> LogLevelToString;
|
||||
};
|
||||
} // namespace Tourmaline::Systems
|
||||
#endif
|
||||
@@ -41,8 +41,10 @@ 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]),
|
||||
h2 = std::hash<uint64_t>{}(data[1]);
|
||||
size_t h1 = std::hash<uint64_t>{}(data[0]);
|
||||
size_t h2 = std::hash<uint64_t>{}(data[1]);
|
||||
|
||||
// Combine the two hashes
|
||||
return h1 ^ (h2 << 1);
|
||||
}
|
||||
};
|
||||
@@ -7,8 +7,7 @@
|
||||
* obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "../../headers/Types.hpp"
|
||||
|
||||
#include "../Types.hpp"
|
||||
#include <charconv>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
Reference in New Issue
Block a user