mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-06-14 18:54:22 +00:00
Compare commits
18 Commits
windows-cl
...
ecs-experi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a36b611367 | ||
|
|
85eb5a7261 | ||
|
|
93dcfddac5 | ||
|
|
82f510c642 | ||
|
|
ae4d9c4bcb | ||
|
|
b9e4aa5344 | ||
|
|
eab57e4022 | ||
|
|
179f0cf32d | ||
|
|
427b7c1047 | ||
|
|
e1c20192f7 | ||
|
|
0f8c5b436d | ||
|
|
53242ad5d5 | ||
|
|
a8919c8c14 | ||
|
|
5ff121612e | ||
|
|
afc2966507 | ||
|
|
34618607c3 | ||
|
|
02b76adb7a | ||
|
|
3beb414b55 |
@@ -3,7 +3,7 @@ CLIENT_PATH=./client
|
||||
# Updates NET_VERSION in CMakeVariables.txt
|
||||
NET_VERSION=171022
|
||||
# make sure this is a long random string
|
||||
# grab a "SHA 256-bit Key" from here: https://keygen.io/
|
||||
# generate a "SHA 256-bit Key" from here: https://gchq.github.io/CyberChef/#recipe=Pseudo-Random_Number_Generator(256,'Hex')
|
||||
ACCOUNT_MANAGER_SECRET=
|
||||
# Should be the externally facing IP of your server host
|
||||
EXTERNAL_IP=localhost
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,6 +4,7 @@ RelWithDebInfo/
|
||||
docker/configs
|
||||
|
||||
# Third party libraries
|
||||
thirdparty/magic_enum
|
||||
thirdparty/mysql/
|
||||
thirdparty/mysql_linux/
|
||||
CMakeVariables.txt
|
||||
|
||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -14,6 +14,3 @@
|
||||
path = thirdparty/mariadb-connector-cpp
|
||||
url = https://github.com/mariadb-corporation/mariadb-connector-cpp.git
|
||||
ignore = dirty
|
||||
[submodule "thirdparty/magic_enum"]
|
||||
path = thirdparty/magic_enum
|
||||
url = https://github.com/Neargye/magic_enum.git
|
||||
|
||||
@@ -110,6 +110,23 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||
|
||||
find_package(MariaDB)
|
||||
|
||||
# Fetch third party dependencies
|
||||
set(DLU_THIRDPARTY_SOURCE_DIR ${CMAKE_SOURCE_DIR}/thirdparty)
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
magic_enum
|
||||
SYSTEM
|
||||
# SOURCE_DIR ${DLU_THIRDPARTY_SOURCE_DIR}/magic_enum
|
||||
GIT_REPOSITORY https://github.com/Neargye/magic_enum.git
|
||||
GIT_TAG v0.9.7
|
||||
)
|
||||
FetchContent_MakeAvailable(magic_enum)
|
||||
|
||||
include(CMakePrintHelpers)
|
||||
cmake_print_properties(TARGETS magic_enum::magic_enum PROPERTIES
|
||||
INTERFACE_INCLUDE_DIRECTORIES)
|
||||
|
||||
# Create a /resServer directory
|
||||
make_directory(${CMAKE_BINARY_DIR}/resServer)
|
||||
|
||||
@@ -252,7 +269,6 @@ include_directories(
|
||||
"tests/dGameTests/dComponentsTests"
|
||||
|
||||
SYSTEM
|
||||
"thirdparty/magic_enum/include/magic_enum"
|
||||
"thirdparty/raknet/Source"
|
||||
"thirdparty/tinyxml2"
|
||||
"thirdparty/recastnavigation"
|
||||
@@ -303,6 +319,7 @@ file(
|
||||
# Add our library subdirectories for creation of the library object
|
||||
add_subdirectory(dCommon)
|
||||
add_subdirectory(dDatabase)
|
||||
add_subdirectory(dECS)
|
||||
add_subdirectory(dChatFilter)
|
||||
add_subdirectory(dNet)
|
||||
add_subdirectory(dScripts) # Add for dGame to use
|
||||
@@ -313,7 +330,7 @@ add_subdirectory(dPhysics)
|
||||
add_subdirectory(dServer)
|
||||
|
||||
# Create a list of common libraries shared between all binaries
|
||||
set(COMMON_LIBRARIES "dCommon" "dDatabase" "dNet" "raknet" "magic_enum")
|
||||
set(COMMON_LIBRARIES "dCommon" "dDatabase" "dNet" "raknet" "magic_enum::magic_enum")
|
||||
|
||||
# Add platform specific common libraries
|
||||
if(UNIX)
|
||||
|
||||
@@ -371,7 +371,7 @@ at once. For that:
|
||||
- Download the [.env.example](.env.example) file and place it next to `client` with the file name `.env`
|
||||
- You may get warnings that this name starts with a dot, acknowledge those, this is intentional. Depending on your operating system, you may need to activate showing hidden files (e.g. Ctrl-H in Gnome on Linux) and/or file extensions ("File name extensions" in the "View" tab on Windows).
|
||||
- Update the `ACCOUNT_MANAGER_SECRET` and `MARIADB_PASSWORD` with strong random passwords.
|
||||
- Use a password generator like <https://keygen.io>
|
||||
- Use a password generator <https://gchq.github.io/CyberChef/#recipe=Pseudo-Random_Number_Generator(256,'Hex')>
|
||||
- Avoid `:` and `@` characters
|
||||
- Once the database user is created, changing the password will not update it, so the server will just fail to connect.
|
||||
- Set `EXTERNAL_IP` to your LAN IP or public IP if you want to host the game for friends & family
|
||||
|
||||
@@ -70,5 +70,6 @@ else ()
|
||||
endif ()
|
||||
|
||||
target_link_libraries(dCommon
|
||||
PUBLIC magic_enum::magic_enum
|
||||
PRIVATE ZLIB::ZLIB bcrypt tinyxml2
|
||||
INTERFACE dDatabase)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
#include "magic_enum.hpp"
|
||||
#include <magic_enum/magic_enum.hpp>
|
||||
|
||||
namespace MessageType {
|
||||
enum class Game : uint16_t {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
#include "magic_enum.hpp"
|
||||
#include <magic_enum/magic_enum.hpp>
|
||||
|
||||
namespace MessageType {
|
||||
enum class World : uint32_t {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define __STRINGIFIEDENUM_H__
|
||||
|
||||
#include <string>
|
||||
#include "magic_enum.hpp"
|
||||
#include <magic_enum/magic_enum.hpp>
|
||||
|
||||
namespace StringifiedEnum {
|
||||
template<typename T>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "magic_enum.hpp"
|
||||
#include <magic_enum/magic_enum.hpp>
|
||||
|
||||
static const uint8_t NUMBER_OF_INVENTORIES = 17;
|
||||
/**
|
||||
|
||||
@@ -2,12 +2,6 @@ add_subdirectory(CDClientDatabase)
|
||||
add_subdirectory(GameDatabase)
|
||||
|
||||
add_library(dDatabase STATIC "MigrationRunner.cpp")
|
||||
|
||||
add_custom_target(conncpp_dylib
|
||||
${CMAKE_COMMAND} -E copy $<TARGET_FILE:MariaDB::ConnCpp> ${PROJECT_BINARY_DIR})
|
||||
|
||||
add_dependencies(dDatabase conncpp_dylib)
|
||||
|
||||
target_include_directories(dDatabase PUBLIC ".")
|
||||
target_link_libraries(dDatabase
|
||||
PUBLIC dDatabaseCDClient dDatabaseGame)
|
||||
PUBLIC magic_enum::magic_enum dDatabaseCDClient dDatabaseGame)
|
||||
|
||||
15
dECS/CMakeLists.txt
Normal file
15
dECS/CMakeLists.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
set(gcc_like_cxx "$<COMPILE_LANG_AND_ID:CXX,ARMClang,AppleClang,Clang,GNU,LCC>")
|
||||
set(msvc_cxx "$<COMPILE_LANG_AND_ID:CXX,MSVC>")
|
||||
|
||||
add_library(dECS STATIC
|
||||
"Core.h"
|
||||
"Iter.h"
|
||||
"Core.cpp"
|
||||
"System.cpp"
|
||||
)
|
||||
target_include_directories(dECS PUBLIC .)
|
||||
target_link_libraries(dECS PRIVATE dCommon magic_enum::magic_enum)
|
||||
target_compile_options(dECS PRIVATE
|
||||
"$<${gcc_like_cxx}:$<BUILD_INTERFACE:-Wall;-Wextra>>"
|
||||
"$<${msvc_cxx}:$<BUILD_INTERFACE:/W3>>"
|
||||
)
|
||||
70
dECS/Core.cpp
Normal file
70
dECS/Core.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include <atomic>
|
||||
#include <magic_enum/magic_enum_containers.hpp>
|
||||
#include <eReplicaComponentType.h>
|
||||
#include "Core.h"
|
||||
|
||||
namespace dECS {
|
||||
struct WorldData {
|
||||
using CompSignature = magic_enum::containers::bitset<eReplicaComponentType>;
|
||||
using CompMap = std::unordered_map<LWOOBJID, CompSignature>;
|
||||
using CompStorage = std::unordered_map<eReplicaComponentType, std::unique_ptr<IStorage>>;
|
||||
|
||||
std::atomic<LWOOBJID> nextId = 1;
|
||||
CompMap map;
|
||||
CompStorage data;
|
||||
};
|
||||
|
||||
World::World() : m_World{ std::make_shared<WorldData>() } {};
|
||||
|
||||
Entity World::MakeEntity() {
|
||||
return Entity{ m_World->nextId.fetch_add(1, std::memory_order::relaxed),
|
||||
m_World };
|
||||
}
|
||||
|
||||
void* Entity::AddComponent(const eReplicaComponentType kind, const StorageConstructor storageConstructor) {
|
||||
if (auto w = m_World.lock()) {
|
||||
// Add to kind signature
|
||||
w->map[m_Id].set(kind, true);
|
||||
|
||||
// Get or add storage
|
||||
auto storageIt = w->data.find(kind);
|
||||
if (storageIt == w->data.cend()) {
|
||||
bool inserted = false;
|
||||
std::tie(storageIt, inserted) = w->data.try_emplace(kind, storageConstructor());
|
||||
if (!inserted) throw "storage emplacement failure";
|
||||
}
|
||||
auto& storage = *storageIt->second;
|
||||
|
||||
// Return reference if already mapped, otherwise add component
|
||||
auto compIt = storage.rowMap.find(m_Id);
|
||||
if (compIt == storage.rowMap.cend()) {
|
||||
const auto curSize = storage.rowMap.size();
|
||||
storage.rowMap.emplace(m_Id, curSize);
|
||||
return storage.emplace_back();
|
||||
}
|
||||
const auto row = compIt->second;
|
||||
return storage.at(row);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const void* Entity::GetComponent(const eReplicaComponentType kind) const {
|
||||
if (auto const w = m_World.lock()) {
|
||||
// Check that the entity has this component
|
||||
if (!w->map[m_Id].test(kind)) return nullptr;
|
||||
|
||||
// Get the location where it's stored
|
||||
const auto& storage = *w->data.at(kind);
|
||||
const auto it = storage.rowMap.find(m_Id);
|
||||
if (it == storage.rowMap.cend()) return nullptr;
|
||||
const auto row = it->second;
|
||||
return storage.at(row);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void* Entity::GetComponent(const eReplicaComponentType kind) {
|
||||
// Casting away const for this overload is safe, if not at all pretty
|
||||
return const_cast<void*>(std::as_const(*this).GetComponent(kind));
|
||||
}
|
||||
}
|
||||
180
dECS/Core.h
Normal file
180
dECS/Core.h
Normal file
@@ -0,0 +1,180 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string_view>
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
class Component;
|
||||
enum class eReplicaComponentType : uint32_t;
|
||||
using LWOOBJID = int64_t;
|
||||
|
||||
namespace dECS {
|
||||
// template <typename C>
|
||||
// concept IsComponent = std::derived_from<C, Component>;
|
||||
|
||||
// Data structures
|
||||
struct WorldData;
|
||||
class World;
|
||||
|
||||
template <typename... Cs>
|
||||
class System;
|
||||
|
||||
class Entity;
|
||||
struct IStorage;
|
||||
|
||||
template <typename C>
|
||||
class Storage;
|
||||
|
||||
using WorldPtr = std::shared_ptr<WorldData>;
|
||||
using WeakWorldPtr = std::weak_ptr<WorldData>;
|
||||
|
||||
class World {
|
||||
public:
|
||||
World();
|
||||
|
||||
[[nodiscard]]
|
||||
Entity MakeEntity();
|
||||
|
||||
template <typename... Cs>
|
||||
[[nodiscard]]
|
||||
System<Cs...> MakeSystem() {
|
||||
return System<Cs...>{};
|
||||
}
|
||||
|
||||
template <typename... Cs, typename S>
|
||||
[[nodiscard]]
|
||||
System<Cs...> MakeSystem(S&& name) {
|
||||
return System<Cs...>{ std::forward<S>(name) };
|
||||
}
|
||||
|
||||
private:
|
||||
WorldPtr m_World;
|
||||
};
|
||||
|
||||
template <typename... Cs>
|
||||
class System {
|
||||
public:
|
||||
friend System World::MakeSystem<Cs...>();
|
||||
|
||||
template <typename... Ts, typename S>
|
||||
friend System<Ts...> World::MakeSystem(S&&);
|
||||
|
||||
/*template <typename Fn>
|
||||
requires std::is_invocable_r_v<void, Fn(Cs...), ObjId, Cs...>
|
||||
void ForEach(Fn&& f) {
|
||||
for (ObjId i = 0; i < mT.size(); ++i) {
|
||||
auto& c = mT[i];
|
||||
f(i, std::get<Cs>(c)...);
|
||||
}
|
||||
}*/
|
||||
|
||||
template <typename Fn>
|
||||
requires std::is_invocable_r_v<void, Fn(Cs...), Cs...>
|
||||
void ForEach(Fn&& fn) {
|
||||
std::tuple<Cs...> comps; // some sort of iterator that returns a tuple each 'step?'
|
||||
for (size_t i = 0; i < 5; ++i) {
|
||||
fn(std::get<Cs>(comps)...);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
System() = default;
|
||||
|
||||
template <typename S>
|
||||
explicit System(S&& name)
|
||||
: m_name{ std::forward<S>(name) }
|
||||
{}
|
||||
|
||||
std::string m_name;
|
||||
};
|
||||
|
||||
class Entity {
|
||||
public:
|
||||
friend Entity World::MakeEntity();
|
||||
|
||||
using StorageConstructor = std::function<std::unique_ptr<IStorage>()>;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr LWOOBJID GetObjectID() const noexcept {
|
||||
return m_Id;
|
||||
}
|
||||
|
||||
[[maybe_unused]]
|
||||
void* AddComponent(eReplicaComponentType, StorageConstructor);
|
||||
|
||||
template <typename C>
|
||||
[[maybe_unused]]
|
||||
C* AddComponent() {
|
||||
return static_cast<C*>(AddComponent(C::ComponentType, std::make_unique<Storage<C>>));
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
const void* GetComponent(eReplicaComponentType) const;
|
||||
|
||||
[[nodiscard]]
|
||||
void* GetComponent(eReplicaComponentType);
|
||||
|
||||
template <typename C>
|
||||
[[nodiscard]]
|
||||
const C* GetComponent() const {
|
||||
return static_cast<const C*>(GetComponent(C::ComponentType));
|
||||
}
|
||||
|
||||
template <typename C>
|
||||
[[nodiscard]]
|
||||
C* GetComponent() {
|
||||
return static_cast<C*>(GetComponent(C::ComponentType));
|
||||
}
|
||||
|
||||
private:
|
||||
Entity(const LWOOBJID id, const WeakWorldPtr world)
|
||||
: m_Id{ id }
|
||||
, m_World { world }
|
||||
{}
|
||||
|
||||
LWOOBJID m_Id;
|
||||
|
||||
WeakWorldPtr m_World;
|
||||
};
|
||||
|
||||
struct IStorage {
|
||||
using RowMap = std::unordered_map<LWOOBJID, size_t>;
|
||||
|
||||
virtual ~IStorage() = default;
|
||||
|
||||
[[nodiscard]]
|
||||
virtual void* at(size_t) = 0;
|
||||
|
||||
[[nodiscard]]
|
||||
virtual const void* at(size_t) const = 0;
|
||||
|
||||
[[nodiscard]]
|
||||
virtual void* emplace_back() = 0;
|
||||
|
||||
RowMap rowMap;
|
||||
};
|
||||
|
||||
template <typename C>
|
||||
class Storage : public IStorage {
|
||||
public:
|
||||
[[nodiscard]]
|
||||
void* at(const size_t index) override {
|
||||
return static_cast<void*>(&m_Vec.at(index));
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
const void* at(const size_t index) const override {
|
||||
return static_cast<const void*>(&m_Vec.at(index));
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
void* emplace_back() override {
|
||||
return static_cast<void*>(&m_Vec.emplace_back());
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<C> m_Vec;
|
||||
};
|
||||
}
|
||||
12
dECS/Iter.h
Normal file
12
dECS/Iter.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "Core.h"
|
||||
|
||||
namespace dECS {
|
||||
class Iter {
|
||||
public:
|
||||
[[nodiscard]]
|
||||
bool Next();
|
||||
|
||||
private:
|
||||
WeakWorldPtr m_World;
|
||||
};
|
||||
}
|
||||
52
dECS/System.cpp
Normal file
52
dECS/System.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include "PetComponent.h"
|
||||
#include "MovementAIComponent.h"
|
||||
#include "MissionComponent.h"
|
||||
#include "eMissionState.h"
|
||||
|
||||
using Pet = PetComponent;
|
||||
using Mission = MissionComponent;
|
||||
using MovementAI = MovementAIComponent;
|
||||
|
||||
struct Position : NiPoint3 {};
|
||||
struct Treasure {};
|
||||
|
||||
namespace decs {
|
||||
template <typename... Cs>
|
||||
class System {
|
||||
public:
|
||||
template <typename Fn>
|
||||
void each(Fn&& fn) {
|
||||
fn();
|
||||
}
|
||||
};
|
||||
|
||||
class Scene {
|
||||
public:
|
||||
template <typename... Cs>
|
||||
System<Cs...> system() {
|
||||
return System<Cs...>{};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
void run() {
|
||||
auto scene = decs::Scene{};
|
||||
|
||||
scene.system<Pet>()
|
||||
.each([](Pet& pet) {
|
||||
|
||||
});
|
||||
|
||||
scene.system<Pet, MovementAI>()
|
||||
.each([](Pet& pet, MovementAI& move) {
|
||||
|
||||
});
|
||||
|
||||
scene.system<Pet, const Mission, const Position>()
|
||||
.each([](Pet& pet, Mission const& mission, Position const& pos) {
|
||||
auto const digUnlocked = mission.GetMissionState(842) == eMissionState::COMPLETE;
|
||||
auto const treasurePos = PetDigServer::GetClosestTreasure(pos);
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
@@ -97,6 +97,8 @@
|
||||
#include "CDSkillBehaviorTable.h"
|
||||
#include "CDZoneTableTable.h"
|
||||
|
||||
#include <ranges>
|
||||
|
||||
Observable<Entity*, const PositionUpdate&> Entity::OnPlayerPositionUpdate;
|
||||
|
||||
Entity::Entity(const LWOOBJID& objectID, EntityInfo info, User* parentUser, Entity* parentEntity) {
|
||||
@@ -286,8 +288,9 @@ void Entity::Initialize() {
|
||||
AddComponent<PropertyEntranceComponent>(propertyEntranceComponentID);
|
||||
}
|
||||
|
||||
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::CONTROLLABLE_PHYSICS) > 0) {
|
||||
auto* controllablePhysics = AddComponent<ControllablePhysicsComponent>();
|
||||
const int32_t controllablePhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::CONTROLLABLE_PHYSICS);
|
||||
if (controllablePhysicsComponentID > 0) {
|
||||
auto* controllablePhysics = AddComponent<ControllablePhysicsComponent>(controllablePhysicsComponentID);
|
||||
|
||||
if (m_Character) {
|
||||
controllablePhysics->LoadFromXml(m_Character->GetXMLDoc());
|
||||
@@ -330,16 +333,19 @@ void Entity::Initialize() {
|
||||
AddComponent<SimplePhysicsComponent>(simplePhysicsComponentID);
|
||||
}
|
||||
|
||||
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RIGID_BODY_PHANTOM_PHYSICS) > 0) {
|
||||
AddComponent<RigidbodyPhantomPhysicsComponent>();
|
||||
const int32_t rigidBodyPhantomPhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::RIGID_BODY_PHANTOM_PHYSICS);
|
||||
if (rigidBodyPhantomPhysicsComponentID > 0) {
|
||||
AddComponent<RigidbodyPhantomPhysicsComponent>(rigidBodyPhantomPhysicsComponentID);
|
||||
}
|
||||
|
||||
if (markedAsPhantom || compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PHANTOM_PHYSICS) > 0) {
|
||||
AddComponent<PhantomPhysicsComponent>()->SetPhysicsEffectActive(false);
|
||||
const int32_t phantomPhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::PHANTOM_PHYSICS);
|
||||
if (markedAsPhantom || phantomPhysicsComponentID > 0) {
|
||||
AddComponent<PhantomPhysicsComponent>(phantomPhysicsComponentID)->SetPhysicsEffectActive(false);
|
||||
}
|
||||
|
||||
if (compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::HAVOK_VEHICLE_PHYSICS) > 0) {
|
||||
auto* havokVehiclePhysicsComponent = AddComponent<HavokVehiclePhysicsComponent>();
|
||||
const int32_t havokVehiclePhysicsComponentID = compRegistryTable->GetByIDAndType(m_TemplateID, eReplicaComponentType::HAVOK_VEHICLE_PHYSICS);
|
||||
if (havokVehiclePhysicsComponentID > 0) {
|
||||
auto* havokVehiclePhysicsComponent = AddComponent<HavokVehiclePhysicsComponent>(havokVehiclePhysicsComponentID);
|
||||
havokVehiclePhysicsComponent->SetPosition(m_DefaultPosition);
|
||||
havokVehiclePhysicsComponent->SetRotation(m_DefaultRotation);
|
||||
}
|
||||
@@ -2161,7 +2167,19 @@ void Entity::SetRespawnPos(const NiPoint3& position) {
|
||||
auto* characterComponent = GetComponent<CharacterComponent>();
|
||||
if (characterComponent) characterComponent->SetRespawnPos(position);
|
||||
}
|
||||
|
||||
void Entity::SetRespawnRot(const NiQuaternion& rotation) {
|
||||
auto* characterComponent = GetComponent<CharacterComponent>();
|
||||
if (characterComponent) characterComponent->SetRespawnRot(rotation);
|
||||
}
|
||||
|
||||
int32_t Entity::GetCollisionGroup() const {
|
||||
for (const auto* component : m_Components | std::views::values) {
|
||||
auto* compToCheck = dynamic_cast<const PhysicsComponent*>(component);
|
||||
if (compToCheck) {
|
||||
return compToCheck->GetCollisionGroup();
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -107,6 +107,11 @@ public:
|
||||
|
||||
const SystemAddress& GetSystemAddress() const;
|
||||
|
||||
// Returns the collision group for this entity.
|
||||
// Because the collision group is stored on a base component, this will look for a physics component
|
||||
// then return the collision group from that.
|
||||
int32_t GetCollisionGroup() const;
|
||||
|
||||
/**
|
||||
* Setters
|
||||
*/
|
||||
|
||||
@@ -55,7 +55,7 @@ set(DGAME_DBEHAVIORS_SOURCES "AirMovementBehavior.cpp"
|
||||
"VerifyBehavior.cpp")
|
||||
|
||||
add_library(dBehaviors OBJECT ${DGAME_DBEHAVIORS_SOURCES})
|
||||
target_link_libraries(dBehaviors PUBLIC dDatabaseCDClient dPhysics)
|
||||
target_link_libraries(dBehaviors PUBLIC dDatabaseCDClient dPhysics magic_enum::magic_enum)
|
||||
target_include_directories(dBehaviors PUBLIC "."
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dGameMessages" # via BehaviorContext.h
|
||||
PRIVATE
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "DestroyableComponent.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <ranges>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
@@ -27,7 +28,7 @@
|
||||
#include "CDPhysicsComponentTable.h"
|
||||
#include "dNavMesh.h"
|
||||
|
||||
BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id): Component(parent) {
|
||||
BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id) : Component(parent) {
|
||||
m_Target = LWOOBJID_EMPTY;
|
||||
m_DirtyStateOrTarget = true;
|
||||
m_State = AiState::spawn;
|
||||
@@ -37,6 +38,7 @@ BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id):
|
||||
m_Disabled = false;
|
||||
m_SkillEntries = {};
|
||||
m_SoftTimer = 5.0f;
|
||||
m_ForcedTetherTime = 0.0f;
|
||||
|
||||
//Grab the aggro information from BaseCombatAI:
|
||||
auto componentQuery = CDClientDatabase::CreatePreppedStmt(
|
||||
@@ -170,6 +172,17 @@ void BaseCombatAIComponent::Update(const float deltaTime) {
|
||||
GameMessages::SendStopFXEffect(m_Parent, true, "tether");
|
||||
m_TetherEffectActive = false;
|
||||
}
|
||||
m_ForcedTetherTime -= deltaTime;
|
||||
if (m_ForcedTetherTime >= 0) return;
|
||||
}
|
||||
|
||||
for (auto entry = m_RemovedThreatList.begin(); entry != m_RemovedThreatList.end();) {
|
||||
entry->second -= deltaTime;
|
||||
if (entry->second <= 0.0f) {
|
||||
entry = m_RemovedThreatList.erase(entry);
|
||||
} else {
|
||||
++entry;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_SoftTimer <= 0.0f) {
|
||||
@@ -287,40 +300,7 @@ void BaseCombatAIComponent::CalculateCombat(const float deltaTime) {
|
||||
}
|
||||
|
||||
if (!m_TetherEffectActive && m_OutOfCombat && (m_OutOfCombatTime -= deltaTime) <= 0) {
|
||||
auto* destroyableComponent = m_Parent->GetComponent<DestroyableComponent>();
|
||||
|
||||
if (destroyableComponent != nullptr && destroyableComponent->HasFaction(4)) {
|
||||
auto serilizationRequired = false;
|
||||
|
||||
if (destroyableComponent->GetHealth() != destroyableComponent->GetMaxHealth()) {
|
||||
destroyableComponent->SetHealth(destroyableComponent->GetMaxHealth());
|
||||
|
||||
serilizationRequired = true;
|
||||
}
|
||||
|
||||
if (destroyableComponent->GetArmor() != destroyableComponent->GetMaxArmor()) {
|
||||
destroyableComponent->SetArmor(destroyableComponent->GetMaxArmor());
|
||||
|
||||
serilizationRequired = true;
|
||||
}
|
||||
|
||||
if (serilizationRequired) {
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
GameMessages::SendPlayFXEffect(m_Parent->GetObjectID(), 6270, u"tether", "tether");
|
||||
|
||||
m_TetherEffectActive = true;
|
||||
|
||||
m_TetherTime = 3.0f;
|
||||
}
|
||||
|
||||
// Speed towards start position
|
||||
if (m_MovementAI != nullptr) {
|
||||
m_MovementAI->SetHaltDistance(0);
|
||||
m_MovementAI->SetMaxSpeed(m_PursuitSpeed);
|
||||
m_MovementAI->SetDestination(m_StartPosition);
|
||||
}
|
||||
TetherLogic();
|
||||
|
||||
m_OutOfCombat = false;
|
||||
m_OutOfCombatTime = 0.0f;
|
||||
@@ -499,7 +479,7 @@ std::vector<LWOOBJID> BaseCombatAIComponent::GetTargetWithinAggroRange() const {
|
||||
|
||||
const auto distance = Vector3::DistanceSquared(m_Parent->GetPosition(), other->GetPosition());
|
||||
|
||||
if (distance > m_AggroRadius * m_AggroRadius) continue;
|
||||
if (distance > m_AggroRadius * m_AggroRadius || m_RemovedThreatList.contains(id)) continue;
|
||||
|
||||
targets.push_back(id);
|
||||
}
|
||||
@@ -626,6 +606,7 @@ const NiPoint3& BaseCombatAIComponent::GetStartPosition() const {
|
||||
|
||||
void BaseCombatAIComponent::ClearThreat() {
|
||||
m_ThreatEntries.clear();
|
||||
m_Target = LWOOBJID_EMPTY;
|
||||
|
||||
m_DirtyThreat = true;
|
||||
}
|
||||
@@ -806,3 +787,55 @@ void BaseCombatAIComponent::Wake() {
|
||||
m_dpEntity->SetSleeping(false);
|
||||
m_dpEntityEnemy->SetSleeping(false);
|
||||
}
|
||||
|
||||
void BaseCombatAIComponent::TetherLogic() {
|
||||
auto* destroyableComponent = m_Parent->GetComponent<DestroyableComponent>();
|
||||
|
||||
if (destroyableComponent != nullptr && destroyableComponent->HasFaction(4)) {
|
||||
auto serilizationRequired = false;
|
||||
|
||||
if (destroyableComponent->GetHealth() != destroyableComponent->GetMaxHealth()) {
|
||||
destroyableComponent->SetHealth(destroyableComponent->GetMaxHealth());
|
||||
|
||||
serilizationRequired = true;
|
||||
}
|
||||
|
||||
if (destroyableComponent->GetArmor() != destroyableComponent->GetMaxArmor()) {
|
||||
destroyableComponent->SetArmor(destroyableComponent->GetMaxArmor());
|
||||
|
||||
serilizationRequired = true;
|
||||
}
|
||||
|
||||
if (serilizationRequired) {
|
||||
Game::entityManager->SerializeEntity(m_Parent);
|
||||
}
|
||||
|
||||
GameMessages::SendPlayFXEffect(m_Parent->GetObjectID(), 6270, u"tether", "tether");
|
||||
|
||||
m_TetherEffectActive = true;
|
||||
|
||||
m_TetherTime = 3.0f;
|
||||
}
|
||||
|
||||
// Speed towards start position
|
||||
if (m_MovementAI != nullptr) {
|
||||
m_MovementAI->SetHaltDistance(0);
|
||||
m_MovementAI->SetMaxSpeed(m_PursuitSpeed);
|
||||
m_MovementAI->SetDestination(m_StartPosition);
|
||||
}
|
||||
}
|
||||
|
||||
void BaseCombatAIComponent::ForceTether() {
|
||||
SetTarget(LWOOBJID_EMPTY);
|
||||
m_ThreatEntries.clear();
|
||||
TetherLogic();
|
||||
m_ForcedTetherTime = m_TetherTime;
|
||||
|
||||
SetAiState(AiState::aggro);
|
||||
}
|
||||
|
||||
void BaseCombatAIComponent::IgnoreThreat(const LWOOBJID threat, const float value) {
|
||||
m_RemovedThreatList[threat] = value;
|
||||
SetThreat(threat, 0.0f);
|
||||
m_Target = LWOOBJID_EMPTY;
|
||||
}
|
||||
|
||||
@@ -224,6 +224,16 @@ public:
|
||||
*/
|
||||
void Wake();
|
||||
|
||||
// Force this entity to tether and ignore all other actions
|
||||
void ForceTether();
|
||||
|
||||
// heals the entity to full health and armor
|
||||
// and tethers them to their spawn point
|
||||
void TetherLogic();
|
||||
|
||||
// Ignore a threat for a certain amount of time
|
||||
void IgnoreThreat(const LWOOBJID target, const float time);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Returns the current target or the target that currently is the largest threat to this entity
|
||||
@@ -382,6 +392,12 @@ private:
|
||||
*/
|
||||
bool m_DirtyStateOrTarget = false;
|
||||
|
||||
// The amount of time the entity will be forced to tether for
|
||||
float m_ForcedTetherTime = 0.0f;
|
||||
|
||||
// The amount of time a removed threat will be ignored for.
|
||||
std::map<LWOOBJID, float> m_RemovedThreatList;
|
||||
|
||||
/**
|
||||
* Whether the current entity is a mech enemy, needed as mechs tether radius works differently
|
||||
* @return whether this entity is a mech
|
||||
|
||||
@@ -79,4 +79,4 @@ target_include_directories(dComponents PUBLIC "."
|
||||
)
|
||||
target_precompile_headers(dComponents REUSE_FROM dGameBase)
|
||||
|
||||
target_link_libraries(dComponents INTERFACE dBehaviors)
|
||||
target_link_libraries(dComponents PUBLIC magic_enum::magic_enum INTERFACE dBehaviors)
|
||||
|
||||
@@ -1,18 +1,5 @@
|
||||
#include "Component.h"
|
||||
|
||||
|
||||
Component::Component(Entity* parent) {
|
||||
m_Parent = parent;
|
||||
}
|
||||
|
||||
Component::~Component() {
|
||||
|
||||
}
|
||||
|
||||
Entity* Component::GetParent() const {
|
||||
return m_Parent;
|
||||
}
|
||||
|
||||
void Component::Update(float deltaTime) {
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
#include "tinyxml2.h"
|
||||
|
||||
namespace RakNet {
|
||||
class BitStream;
|
||||
};
|
||||
|
||||
class Entity;
|
||||
|
||||
/**
|
||||
@@ -9,14 +13,15 @@ class Entity;
|
||||
*/
|
||||
class Component {
|
||||
public:
|
||||
Component(Entity* parent);
|
||||
virtual ~Component();
|
||||
Component() = default;
|
||||
Component(Entity* parent) : m_Parent{ parent } {}
|
||||
virtual ~Component() = default;
|
||||
|
||||
/**
|
||||
* Gets the owner of this component
|
||||
* @return the owner of this component
|
||||
*/
|
||||
Entity* GetParent() const;
|
||||
Entity* GetParent() const { return m_Parent; }
|
||||
|
||||
/**
|
||||
* Updates the component in the game loop
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "LevelProgressionComponent.h"
|
||||
#include "eStateChangeType.h"
|
||||
|
||||
ControllablePhysicsComponent::ControllablePhysicsComponent(Entity* entity) : PhysicsComponent(entity) {
|
||||
ControllablePhysicsComponent::ControllablePhysicsComponent(Entity* entity, int32_t componentId) : PhysicsComponent(entity, componentId) {
|
||||
m_Velocity = {};
|
||||
m_AngularVelocity = {};
|
||||
m_InJetpackMode = false;
|
||||
|
||||
@@ -23,7 +23,7 @@ class ControllablePhysicsComponent : public PhysicsComponent {
|
||||
public:
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::CONTROLLABLE_PHYSICS;
|
||||
|
||||
ControllablePhysicsComponent(Entity* entity);
|
||||
ControllablePhysicsComponent(Entity* entity, int32_t componentId);
|
||||
~ControllablePhysicsComponent() override;
|
||||
|
||||
void Update(float deltaTime) override;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "HavokVehiclePhysicsComponent.h"
|
||||
#include "EntityManager.h"
|
||||
|
||||
HavokVehiclePhysicsComponent::HavokVehiclePhysicsComponent(Entity* parent) : PhysicsComponent(parent) {
|
||||
HavokVehiclePhysicsComponent::HavokVehiclePhysicsComponent(Entity* parent, int32_t componentId) : PhysicsComponent(parent, componentId) {
|
||||
m_Velocity = NiPoint3Constant::ZERO;
|
||||
m_AngularVelocity = NiPoint3Constant::ZERO;
|
||||
m_IsOnGround = true;
|
||||
|
||||
@@ -13,7 +13,7 @@ class HavokVehiclePhysicsComponent : public PhysicsComponent {
|
||||
public:
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::HAVOK_VEHICLE_PHYSICS;
|
||||
|
||||
HavokVehiclePhysicsComponent(Entity* parentEntity);
|
||||
HavokVehiclePhysicsComponent(Entity* parentEntity, int32_t componentId);
|
||||
|
||||
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
|
||||
@@ -1141,6 +1141,25 @@ void InventoryComponent::AddItemSkills(const LOT lot) {
|
||||
SetSkill(slot, skill);
|
||||
}
|
||||
|
||||
void InventoryComponent::FixInvisibleItems() {
|
||||
const auto numberItemsLoadedPerFrame = 12.0f;
|
||||
const auto callbackTime = 0.125f;
|
||||
const auto arbitaryInventorySize = 300.0f; // max in live + dlu is less than 300, seems like a good number.
|
||||
auto* const items = GetInventory(eInventoryType::ITEMS);
|
||||
if (!items) return;
|
||||
|
||||
// Add an extra update to make sure the client can see all the items.
|
||||
const auto something = static_cast<int32_t>(std::ceil(items->GetItems().size() / arbitaryInventorySize)) + 1;
|
||||
LOG_DEBUG("Fixing invisible items with %i updates", something);
|
||||
|
||||
for (int32_t i = 1; i < something + 1; i++) {
|
||||
// client loads 12 items every 1/8 seconds, we're adding a small hack to fix invisible inventory items due to closing the news screen too fast.
|
||||
m_Parent->AddCallbackTimer((arbitaryInventorySize / numberItemsLoadedPerFrame) * callbackTime * i, [this]() {
|
||||
GameMessages::SendUpdateInventoryUi(m_Parent->GetObjectID(), m_Parent->GetSystemAddress());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void InventoryComponent::RemoveItemSkills(const LOT lot) {
|
||||
const auto info = Inventory::FindItemComponent(lot);
|
||||
|
||||
|
||||
@@ -404,6 +404,8 @@ public:
|
||||
void UpdateGroup(const GroupUpdate& groupUpdate);
|
||||
void RemoveGroup(const std::string& groupId);
|
||||
|
||||
void FixInvisibleItems();
|
||||
|
||||
~InventoryComponent() override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include "dpShapeBox.h"
|
||||
#include "dpShapeSphere.h"
|
||||
|
||||
PhantomPhysicsComponent::PhantomPhysicsComponent(Entity* parent) : PhysicsComponent(parent) {
|
||||
PhantomPhysicsComponent::PhantomPhysicsComponent(Entity* parent, int32_t componentId) : PhysicsComponent(parent, componentId) {
|
||||
m_Position = m_Parent->GetDefaultPosition();
|
||||
m_Rotation = m_Parent->GetDefaultRotation();
|
||||
m_Scale = m_Parent->GetDefaultScale();
|
||||
|
||||
@@ -30,7 +30,7 @@ class PhantomPhysicsComponent final : public PhysicsComponent {
|
||||
public:
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::PHANTOM_PHYSICS;
|
||||
|
||||
PhantomPhysicsComponent(Entity* parent);
|
||||
PhantomPhysicsComponent(Entity* parent, int32_t componentId);
|
||||
~PhantomPhysicsComponent() override;
|
||||
void Update(float deltaTime) override;
|
||||
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
@@ -14,10 +14,21 @@
|
||||
|
||||
#include "EntityInfo.h"
|
||||
|
||||
PhysicsComponent::PhysicsComponent(Entity* parent) : Component(parent) {
|
||||
PhysicsComponent::PhysicsComponent(Entity* parent, int32_t componentId) : Component(parent) {
|
||||
m_Position = NiPoint3Constant::ZERO;
|
||||
m_Rotation = NiQuaternionConstant::IDENTITY;
|
||||
m_DirtyPosition = false;
|
||||
|
||||
CDPhysicsComponentTable* physicsComponentTable = CDClientManager::GetTable<CDPhysicsComponentTable>();
|
||||
|
||||
if (physicsComponentTable) {
|
||||
auto* info = physicsComponentTable->GetByID(componentId);
|
||||
if (info) {
|
||||
m_CollisionGroup = info->collisionGroup;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_Parent->HasVar(u"CollisionGroupID")) m_CollisionGroup = m_Parent->GetVar<int32_t>(u"CollisionGroupID");
|
||||
}
|
||||
|
||||
void PhysicsComponent::Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) {
|
||||
|
||||
@@ -15,7 +15,7 @@ class dpEntity;
|
||||
|
||||
class PhysicsComponent : public Component {
|
||||
public:
|
||||
PhysicsComponent(Entity* parent);
|
||||
PhysicsComponent(Entity* parent, int32_t componentId);
|
||||
virtual ~PhysicsComponent() = default;
|
||||
|
||||
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
|
||||
@@ -25,6 +25,9 @@ public:
|
||||
|
||||
const NiQuaternion& GetRotation() const { return m_Rotation; }
|
||||
virtual void SetRotation(const NiQuaternion& rot) { if (m_Rotation == rot) return; m_Rotation = rot; m_DirtyPosition = true; }
|
||||
|
||||
int32_t GetCollisionGroup() const noexcept { return m_CollisionGroup; }
|
||||
void SetCollisionGroup(int32_t group) noexcept { m_CollisionGroup = group; }
|
||||
protected:
|
||||
dpEntity* CreatePhysicsEntity(eReplicaComponentType type);
|
||||
|
||||
@@ -37,6 +40,8 @@ protected:
|
||||
NiQuaternion m_Rotation;
|
||||
|
||||
bool m_DirtyPosition;
|
||||
|
||||
int32_t m_CollisionGroup{};
|
||||
};
|
||||
|
||||
#endif //!__PHYSICSCOMPONENT__H__
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "dpShapeSphere.h"
|
||||
#include"EntityInfo.h"
|
||||
|
||||
RigidbodyPhantomPhysicsComponent::RigidbodyPhantomPhysicsComponent(Entity* parent) : PhysicsComponent(parent) {
|
||||
RigidbodyPhantomPhysicsComponent::RigidbodyPhantomPhysicsComponent(Entity* parent, int32_t componentId) : PhysicsComponent(parent, componentId) {
|
||||
m_Position = m_Parent->GetDefaultPosition();
|
||||
m_Rotation = m_Parent->GetDefaultRotation();
|
||||
m_Scale = m_Parent->GetDefaultScale();
|
||||
|
||||
@@ -21,7 +21,7 @@ class RigidbodyPhantomPhysicsComponent : public PhysicsComponent {
|
||||
public:
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::RIGID_BODY_PHANTOM_PHYSICS;
|
||||
|
||||
RigidbodyPhantomPhysicsComponent(Entity* parent);
|
||||
RigidbodyPhantomPhysicsComponent(Entity* parent, int32_t componentId);
|
||||
|
||||
void Update(const float deltaTime) override;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
#include "Entity.h"
|
||||
|
||||
SimplePhysicsComponent::SimplePhysicsComponent(Entity* parent, uint32_t componentID) : PhysicsComponent(parent) {
|
||||
SimplePhysicsComponent::SimplePhysicsComponent(Entity* parent, int32_t componentID) : PhysicsComponent(parent, componentID) {
|
||||
m_Position = m_Parent->GetDefaultPosition();
|
||||
m_Rotation = m_Parent->GetDefaultRotation();
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ class SimplePhysicsComponent : public PhysicsComponent {
|
||||
public:
|
||||
static constexpr eReplicaComponentType ComponentType = eReplicaComponentType::SIMPLE_PHYSICS;
|
||||
|
||||
SimplePhysicsComponent(Entity* parent, uint32_t componentID);
|
||||
SimplePhysicsComponent(Entity* parent, int32_t componentID);
|
||||
~SimplePhysicsComponent() override;
|
||||
|
||||
void Serialize(RakNet::BitStream& outBitStream, bool bIsInitialUpdate) override;
|
||||
|
||||
@@ -6,7 +6,7 @@ set(DGAME_DGAMEMESSAGES_SOURCES
|
||||
|
||||
add_library(dGameMessages OBJECT ${DGAME_DGAMEMESSAGES_SOURCES})
|
||||
target_link_libraries(dGameMessages
|
||||
PUBLIC dDatabase
|
||||
PUBLIC magic_enum::magic_enum dDatabase
|
||||
INTERFACE dGameBase # TradingManager
|
||||
)
|
||||
target_include_directories(dGameMessages PUBLIC "."
|
||||
|
||||
@@ -104,6 +104,18 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream& inStream, const System
|
||||
break;
|
||||
}
|
||||
|
||||
// Currently not actually used for our implementation, however its used right now to get around invisible inventory items in the client.
|
||||
case MessageType::Game::SELECT_SKILL: {
|
||||
auto var = entity->GetVar<bool>(u"dlu_first_time_load");
|
||||
if (var) {
|
||||
entity->SetVar<bool>(u"dlu_first_time_load", false);
|
||||
InventoryComponent* inventoryComponent = entity->GetComponent<InventoryComponent>();
|
||||
|
||||
if (inventoryComponent) inventoryComponent->FixInvisibleItems();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case MessageType::Game::PLAYER_LOADED: {
|
||||
GameMessages::SendRestoreToPostLoadStats(entity, sysAddr);
|
||||
entity->SetPlayerReadyForUpdates();
|
||||
|
||||
@@ -982,7 +982,7 @@ void GameMessages::SendResurrect(Entity* entity) {
|
||||
destroyableComponent->SetImagination(imaginationToRestore);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
CBITSTREAM;
|
||||
CMSGHEADER;
|
||||
@@ -5080,6 +5080,12 @@ void GameMessages::HandleSetFlag(RakNet::BitStream& inStream, Entity* entity) {
|
||||
|
||||
auto character = entity->GetCharacter();
|
||||
if (character) character->SetPlayerFlag(iFlagID, bFlag);
|
||||
|
||||
// This is always set the first time a player loads into a world from character select
|
||||
// and is used to know when to refresh the players inventory items so they show up.
|
||||
if (iFlagID == ePlayerFlag::IS_NEWS_SCREEN_VISIBLE && bFlag) {
|
||||
entity->SetVar<bool>(u"dlu_first_time_load", true);
|
||||
}
|
||||
}
|
||||
|
||||
void GameMessages::HandleRespondToMission(RakNet::BitStream& inStream, Entity* entity) {
|
||||
@@ -5147,12 +5153,12 @@ void GameMessages::HandleMissionDialogOK(RakNet::BitStream& inStream, Entity* en
|
||||
}
|
||||
|
||||
if (Game::config->GetValue("allow_players_to_skip_cinematics") != "1"
|
||||
|| !player->GetCharacter()
|
||||
|| !player->GetCharacter()->GetPlayerFlag(ePlayerFlag::DLU_SKIP_CINEMATICS)) return;
|
||||
|| !player->GetCharacter()
|
||||
|| !player->GetCharacter()->GetPlayerFlag(ePlayerFlag::DLU_SKIP_CINEMATICS)) return;
|
||||
player->AddCallbackTimer(0.5f, [player]() {
|
||||
if (!player) return;
|
||||
GameMessages::SendEndCinematic(player->GetObjectID(), u"", player->GetSystemAddress());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
void GameMessages::HandleRequestLinkedMission(RakNet::BitStream& inStream, Entity* entity) {
|
||||
@@ -6324,3 +6330,48 @@ void GameMessages::SendForceCameraTargetCycle(Entity* entity, bool bForceCycling
|
||||
auto sysAddr = entity->GetSystemAddress();
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
|
||||
void GameMessages::SendUpdateInventoryUi(LWOOBJID objectId, const SystemAddress& sysAddr) {
|
||||
CBITSTREAM;
|
||||
CMSGHEADER;
|
||||
|
||||
bitStream.Write(objectId);
|
||||
bitStream.Write(MessageType::Game::UPDATE_INVENTORY_UI);
|
||||
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
void GameMessages::DisplayTooltip::Send() const {
|
||||
CBITSTREAM;
|
||||
CMSGHEADER;
|
||||
|
||||
bitStream.Write(target);
|
||||
bitStream.Write(msgId);
|
||||
|
||||
bitStream.Write(doOrDie);
|
||||
bitStream.Write(noRepeat);
|
||||
bitStream.Write(noRevive);
|
||||
bitStream.Write(isPropertyTooltip);
|
||||
bitStream.Write(show);
|
||||
bitStream.Write(translate);
|
||||
bitStream.Write(time);
|
||||
bitStream.Write<int32_t>(id.size());
|
||||
bitStream.Write(id);
|
||||
|
||||
std::string toWrite;
|
||||
for (const auto* item : localizeParams) {
|
||||
toWrite += item->GetString() + "\n";
|
||||
}
|
||||
if (!toWrite.empty()) toWrite.pop_back();
|
||||
bitStream.Write<int32_t>(toWrite.size());
|
||||
bitStream.Write(GeneralUtils::ASCIIToUTF16(toWrite));
|
||||
if (!toWrite.empty()) bitStream.Write<uint16_t>(0x00); // Null Terminator
|
||||
|
||||
bitStream.Write<int32_t>(imageName.size());
|
||||
bitStream.Write(imageName);
|
||||
bitStream.Write<int32_t>(text.size());
|
||||
bitStream.Write(text);
|
||||
|
||||
SEND_PACKET;
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "eCyclingMode.h"
|
||||
#include "eLootSourceType.h"
|
||||
#include "Brick.h"
|
||||
#include "MessageType/Game.h"
|
||||
|
||||
class AMFBaseValue;
|
||||
class Entity;
|
||||
@@ -20,6 +21,7 @@ class User;
|
||||
class Leaderboard;
|
||||
class PropertySelectQueryProperty;
|
||||
class TradeItem;
|
||||
class LDFBaseData;
|
||||
|
||||
enum class eAnimationFlags : uint32_t;
|
||||
|
||||
@@ -47,6 +49,15 @@ enum class eCameraTargetCyclingMode : int32_t {
|
||||
};
|
||||
|
||||
namespace GameMessages {
|
||||
struct GameMsg {
|
||||
GameMsg(MessageType::Game gmId) : msgId{ gmId } {}
|
||||
virtual ~GameMsg() = default;
|
||||
virtual void Send() const {}
|
||||
MessageType::Game msgId;
|
||||
LWOOBJID target{ LWOOBJID_EMPTY };
|
||||
SystemAddress sysAddr{ UNASSIGNED_SYSTEM_ADDRESS };
|
||||
};
|
||||
|
||||
class PropertyDataMessage;
|
||||
void SendFireEventClientSide(const LWOOBJID& objectID, const SystemAddress& sysAddr, std::u16string args, const LWOOBJID& object, int64_t param1, int param2, const LWOOBJID& sender);
|
||||
void SendTeleport(const LWOOBJID& objectID, const NiPoint3& pos, const NiQuaternion& rot, const SystemAddress& sysAddr, bool bSetRotation = false);
|
||||
@@ -677,6 +688,25 @@ namespace GameMessages {
|
||||
void HandleUpdateInventoryGroup(RakNet::BitStream& inStream, Entity* entity, const SystemAddress& sysAddr);
|
||||
void HandleUpdateInventoryGroupContents(RakNet::BitStream& inStream, Entity* entity, const SystemAddress& sysAddr);
|
||||
void SendForceCameraTargetCycle(Entity* entity, bool bForceCycling, eCameraTargetCyclingMode cyclingMode, LWOOBJID optionalTargetID);
|
||||
|
||||
// This is a client gm however its default values are exactly what we need to get around the invisible inventory item issues.
|
||||
void SendUpdateInventoryUi(LWOOBJID objectId, const SystemAddress& sysAddr);
|
||||
|
||||
struct DisplayTooltip : public GameMsg {
|
||||
DisplayTooltip() : GameMsg(MessageType::Game::DISPLAY_TOOLTIP) {}
|
||||
bool doOrDie{};
|
||||
bool noRepeat{};
|
||||
bool noRevive{};
|
||||
bool isPropertyTooltip{};
|
||||
bool show{};
|
||||
bool translate{};
|
||||
int32_t time{};
|
||||
std::u16string id{};
|
||||
std::vector<LDFBaseData*> localizeParams{};
|
||||
std::u16string imageName{};
|
||||
std::u16string text{};
|
||||
void Send() const override;
|
||||
};
|
||||
};
|
||||
|
||||
#endif // GAMEMESSAGES_H
|
||||
|
||||
@@ -24,6 +24,7 @@ target_include_directories(dInventory PUBLIC "."
|
||||
"${PROJECT_SOURCE_DIR}/dGame/dMission" # via MissionComponent.h
|
||||
"${PROJECT_SOURCE_DIR}/dZoneManager" # via Item.cpp
|
||||
)
|
||||
target_link_libraries(dInventory PUBLIC magic_enum::magic_enum)
|
||||
target_precompile_headers(dInventory REUSE_FROM dGameBase)
|
||||
# Workaround for compiler bug where the optimized code could result in a memcpy of 0 bytes, even though that isnt possible.
|
||||
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97185
|
||||
|
||||
@@ -8,7 +8,6 @@ class AMFArrayValue;
|
||||
/**
|
||||
* @brief Sent when a player moves a Behavior A at position B to their inventory.
|
||||
*/
|
||||
#pragma warning("This Control Behavior Message does not have a test yet. Non-developers can ignore this warning.")
|
||||
class MoveToInventoryMessage : public BehaviorMessageBase {
|
||||
public:
|
||||
MoveToInventoryMessage(const AMFArrayValue& arguments);
|
||||
|
||||
@@ -137,7 +137,7 @@ bool Precondition::CheckValue(Entity* player, const uint32_t value, bool evaluat
|
||||
|
||||
return inventoryComponent->GetLotCount(value) >= count;
|
||||
case PreconditionType::DoesNotHaveItem:
|
||||
return inventoryComponent->IsEquipped(value) < count;
|
||||
return inventoryComponent->IsEquipped(value) && count > 0;
|
||||
case PreconditionType::HasAchievement:
|
||||
if (missionComponent == nullptr) return false;
|
||||
return missionComponent->GetMissionState(value) >= eMissionState::COMPLETE;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#define _VARIADIC_MAX 10
|
||||
#include "dCommonVars.h"
|
||||
#include "dNetCommon.h"
|
||||
#include "magic_enum.hpp"
|
||||
#include <magic_enum/magic_enum.hpp>
|
||||
|
||||
enum class ServerType : uint32_t;
|
||||
enum class eLoginResponse : uint8_t;
|
||||
|
||||
@@ -8,7 +8,7 @@ set(DNET_SOURCES "AuthPackets.cpp"
|
||||
"ZoneInstanceManager.cpp")
|
||||
|
||||
add_library(dNet STATIC ${DNET_SOURCES})
|
||||
target_link_libraries(dNet PRIVATE bcrypt MD5)
|
||||
target_link_libraries(dNet PUBLIC magic_enum::magic_enum PRIVATE bcrypt MD5)
|
||||
target_include_directories(dNet PRIVATE
|
||||
"${PROJECT_SOURCE_DIR}/dCommon"
|
||||
"${PROJECT_SOURCE_DIR}/dCommon/dEnums"
|
||||
|
||||
@@ -2,6 +2,7 @@ set(DSCRIPTS_SOURCES_02_SERVER_MAP_GENERAL
|
||||
"BankInteractServer.cpp"
|
||||
"BaseInteractDropLootServer.cpp"
|
||||
"Binoculars.cpp"
|
||||
"EnemyClearThreat.cpp"
|
||||
"ExplodingAsset.cpp"
|
||||
"FrictionVolumeServer.cpp"
|
||||
"ForceVolumeServer.cpp"
|
||||
|
||||
25
dScripts/02_server/Map/General/EnemyClearThreat.cpp
Normal file
25
dScripts/02_server/Map/General/EnemyClearThreat.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "EnemyClearThreat.h"
|
||||
|
||||
#include "BaseCombatAIComponent.h"
|
||||
#include "PhysicsComponent.h"
|
||||
|
||||
void EnemyClearThreat::OnCollisionPhantom(Entity* self, Entity* target) {
|
||||
if (!target) return;
|
||||
|
||||
const auto colGroup = target->GetCollisionGroup();
|
||||
if (colGroup == 12) { // enemy
|
||||
auto* const baseCombatAiComponent = target->GetComponent<BaseCombatAIComponent>();
|
||||
if (!baseCombatAiComponent) return;
|
||||
|
||||
baseCombatAiComponent->ClearThreat();
|
||||
baseCombatAiComponent->ForceTether();
|
||||
} else if (colGroup == 10) { // player
|
||||
const auto enemies = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::BASE_COMBAT_AI);
|
||||
for (const auto& enemy : enemies) {
|
||||
auto* const baseCombatAiComponent = enemy->GetComponent<BaseCombatAIComponent>();
|
||||
if (!baseCombatAiComponent) continue;
|
||||
|
||||
baseCombatAiComponent->IgnoreThreat(target->GetObjectID(), 3.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
11
dScripts/02_server/Map/General/EnemyClearThreat.h
Normal file
11
dScripts/02_server/Map/General/EnemyClearThreat.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef ENEMYCLEARTHREAT_H
|
||||
#define ENEMYCLEARTHREAT_H
|
||||
|
||||
#include "CppScripts.h"
|
||||
|
||||
class EnemyClearThreat : public CppScripts::Script {
|
||||
public:
|
||||
void OnCollisionPhantom(Entity* self, Entity* target) override;
|
||||
};
|
||||
|
||||
#endif //!ENEMYCLEARTHREAT_H
|
||||
@@ -327,6 +327,8 @@
|
||||
#include "VisToggleNotifierServer.h"
|
||||
#include "LupGenericInteract.h"
|
||||
#include "WblRobotCitizen.h"
|
||||
#include "EnemyClearThreat.h"
|
||||
#include "AgSpiderBossMessage.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
@@ -686,8 +688,22 @@ namespace {
|
||||
{"scripts\\zone\\LUPs\\RobotCity Intro\\WBL_RCIntro_RobotCitizenOrange.lua", []() {return new WblRobotCitizen();}},
|
||||
{"scripts\\zone\\LUPs\\RobotCity Intro\\WBL_RCIntro_RobotCitizenRed.lua", []() {return new WblRobotCitizen();}},
|
||||
{"scripts\\zone\\LUPs\\RobotCity Intro\\WBL_RCIntro_RobotCitizenYellow.lua", []() {return new WblRobotCitizen();}},
|
||||
{"scripts\\02_server\\Map\\General\\L_ENEMY_CLEAR_THREAT.lua", []() {return new EnemyClearThreat();}},
|
||||
{"scripts\\ai\\AG\\L_AG_SPIDER_BOSS_MESSAGE.lua", []() {return new AgSpiderBossMessage();}},
|
||||
|
||||
};
|
||||
|
||||
std::set<std::string> g_ExcludedScripts = {
|
||||
"scripts\\02_server\\Enemy\\General\\L_SUSPEND_LUA_AI.lua",
|
||||
"scripts\\02_server\\Enemy\\General\\L_BASE_ENEMY_SPIDERLING.lua",
|
||||
"scripts\\ai\\AG\\L_AG_SENTINEL_GUARD.lua",
|
||||
"scripts\\ai\\FV\\L_ACT_NINJA_STUDENT.lua",
|
||||
"scripts\\ai\\WILD\\L_WILD_GF_FROG.lua",
|
||||
"scripts\\empty.lua",
|
||||
"scripts\\zone\\AG\\L_ZONE_AG.lua",
|
||||
"scripts\\zone\\NS\\L_ZONE_NS.lua",
|
||||
"scripts\\zone\\GF\\L_ZONE_GF.lua",
|
||||
};
|
||||
};
|
||||
|
||||
CppScripts::Script* const CppScripts::GetScript(Entity* parent, const std::string& scriptName) {
|
||||
@@ -699,14 +715,8 @@ CppScripts::Script* const CppScripts::GetScript(Entity* parent, const std::strin
|
||||
const auto itrTernary = scriptLoader.find(scriptName);
|
||||
Script* script = itrTernary != scriptLoader.cend() ? itrTernary->second() : &InvalidToReturn;
|
||||
|
||||
if (script == &InvalidToReturn) {
|
||||
if ((scriptName.length() > 0) && !((scriptName == "scripts\\02_server\\Enemy\\General\\L_SUSPEND_LUA_AI.lua") ||
|
||||
(scriptName == "scripts\\02_server\\Enemy\\General\\L_BASE_ENEMY_SPIDERLING.lua") ||
|
||||
(scriptName == "scripts\\ai\\FV\\L_ACT_NINJA_STUDENT.lua") ||
|
||||
(scriptName == "scripts\\ai\\WILD\\L_WILD_GF_FROG.lua") ||
|
||||
(scriptName == "scripts\\empty.lua") ||
|
||||
(scriptName == "scripts\\ai\\AG\\L_AG_SENTINEL_GUARD.lua")
|
||||
)) LOG_DEBUG("LOT %i attempted to load CppScript for '%s', but returned InvalidScript.", parent->GetLOT(), scriptName.c_str());
|
||||
if (script == &InvalidToReturn && !scriptName.empty() && !g_ExcludedScripts.contains(scriptName)) {
|
||||
LOG_DEBUG("LOT %i attempted to load CppScript for '%s', but returned InvalidScript.", parent->GetLOT(), scriptName.c_str());
|
||||
}
|
||||
|
||||
g_Scripts[scriptName] = script;
|
||||
|
||||
81
dScripts/ai/AG/AgSpiderBossMessage.cpp
Normal file
81
dScripts/ai/AG/AgSpiderBossMessage.cpp
Normal file
@@ -0,0 +1,81 @@
|
||||
#include "AgSpiderBossMessage.h"
|
||||
|
||||
#include "Entity.h"
|
||||
#include "GameMessages.h"
|
||||
|
||||
#include "RenderComponent.h"
|
||||
|
||||
Box AgSpiderBossMessage::GetBox(Entity* self) const {
|
||||
return self->GetVar<Box>(u"box");
|
||||
}
|
||||
|
||||
void AgSpiderBossMessage::SetBox(Entity* self, const Box& box) const {
|
||||
self->SetVar(u"box", box);
|
||||
}
|
||||
|
||||
void AgSpiderBossMessage::MakeBox(Entity* self) const {
|
||||
auto box = GetBox(self);
|
||||
if (box.boxTarget == LWOOBJID_EMPTY || box.isDisplayed || box.boxSelf == LWOOBJID_EMPTY) return;
|
||||
|
||||
box.isDisplayed = true;
|
||||
SetBox(self, box);
|
||||
self->AddTimer("BoxTimer", box.boxTime);
|
||||
|
||||
const auto* const tgt = Game::entityManager->GetEntity(box.boxTarget);
|
||||
if (!tgt) return;
|
||||
GameMessages::DisplayTooltip tooltip;
|
||||
tooltip.target = tgt->GetObjectID();
|
||||
tooltip.sysAddr = tgt->GetSystemAddress();
|
||||
tooltip.show = true;
|
||||
tooltip.text = box.boxText;
|
||||
tooltip.time = box.boxTime * 1000; // to ms
|
||||
tooltip.Send();
|
||||
}
|
||||
|
||||
void AgSpiderBossMessage::OnCollisionPhantom(Entity* self, Entity* target) {
|
||||
if (!target || !target->IsPlayer()) return;
|
||||
|
||||
auto box = GetBox(self);
|
||||
// knockback the target
|
||||
auto forward = target->GetRotation().GetForwardVector();
|
||||
box.boxTarget = target->GetObjectID();
|
||||
GameMessages::SendPlayFXEffect(target->GetObjectID(), 1378, u"create", "pushBack");
|
||||
RenderComponent::PlayAnimation(target, "knockback-recovery");
|
||||
forward.y += 15;
|
||||
forward.x *= 100;
|
||||
forward.z *= 100;
|
||||
GameMessages::SendKnockback(target->GetObjectID(), self->GetObjectID(), self->GetObjectID(), 0, forward);
|
||||
|
||||
if (box.isTouch || box.isDisplayed) return;
|
||||
box.boxSelf = self->GetObjectID();
|
||||
box.isTouch = true;
|
||||
box.boxText = u"%[SPIDER_CAVE_MESSAGE]";
|
||||
SetBox(self, box);
|
||||
self->AddTimer("EventTimer", 0.1f);
|
||||
}
|
||||
|
||||
void AgSpiderBossMessage::OnOffCollisionPhantom(Entity* self, Entity* target) {
|
||||
if (!target) return;
|
||||
auto box = GetBox(self);
|
||||
box.isTouch = false;
|
||||
box.Reset();
|
||||
SetBox(self, box);
|
||||
}
|
||||
|
||||
void AgSpiderBossMessage::OnTimerDone(Entity* self, std::string timerName) {
|
||||
if (timerName == "BoxTimer") {
|
||||
auto box = GetBox(self);
|
||||
box.isDisplayed = false;
|
||||
SetBox(self, box);
|
||||
ResetBox(self);
|
||||
} else if (timerName == "EventTimer") {
|
||||
auto box = GetBox(self);
|
||||
MakeBox(self);
|
||||
}
|
||||
}
|
||||
|
||||
void AgSpiderBossMessage::ResetBox(Entity* self) const {
|
||||
auto box = GetBox(self);
|
||||
box.Reset();
|
||||
SetBox(self, box);
|
||||
}
|
||||
37
dScripts/ai/AG/AgSpiderBossMessage.h
Normal file
37
dScripts/ai/AG/AgSpiderBossMessage.h
Normal file
@@ -0,0 +1,37 @@
|
||||
#ifndef AGSPIDERBOSSMESSAGE_H
|
||||
#define AGSPIDERBOSSMESSAGE_H
|
||||
|
||||
#include "CppScripts.h"
|
||||
|
||||
struct Box {
|
||||
LWOOBJID boxTarget{};
|
||||
bool isDisplayed{};
|
||||
bool isTouch{};
|
||||
bool isFirst{};
|
||||
LWOOBJID boxSelf{};
|
||||
std::u16string boxText{};
|
||||
int32_t boxTime{ 1 };
|
||||
|
||||
void Reset() {
|
||||
boxTarget = LWOOBJID_EMPTY;
|
||||
isDisplayed = false;
|
||||
isTouch = false;
|
||||
isFirst = false;
|
||||
boxSelf = LWOOBJID_EMPTY;
|
||||
boxText.clear();
|
||||
boxTime = 1;
|
||||
}
|
||||
};
|
||||
|
||||
class AgSpiderBossMessage : public CppScripts::Script {
|
||||
public:
|
||||
Box GetBox(Entity* self) const;
|
||||
void SetBox(Entity* self, const Box& box) const;
|
||||
void MakeBox(Entity* self) const;
|
||||
void OnCollisionPhantom(Entity* self, Entity* target) override;
|
||||
void OnOffCollisionPhantom(Entity* self, Entity* target) override;
|
||||
void OnTimerDone(Entity* self, std::string timerName) override;
|
||||
void ResetBox(Entity* self) const;
|
||||
};
|
||||
|
||||
#endif //!AGSPIDERBOSSMESSAGE_H
|
||||
@@ -1,6 +1,7 @@
|
||||
set(DSCRIPTS_SOURCES_AI_AG
|
||||
"AgShipPlayerDeathTrigger.cpp"
|
||||
"AgSpaceStuff.cpp"
|
||||
"AgSpiderBossMessage.cpp"
|
||||
"AgShipShake.cpp"
|
||||
"AgShipPlayerShockServer.cpp"
|
||||
"AgImagSmashable.cpp"
|
||||
|
||||
@@ -13,7 +13,7 @@ target_include_directories(WorldServer PRIVATE
|
||||
"${PROJECT_SOURCE_DIR}/dServer" # BinaryPathFinder.h
|
||||
)
|
||||
|
||||
target_link_libraries(WorldServer ${COMMON_LIBRARIES}
|
||||
target_link_libraries(WorldServer PUBLIC ${COMMON_LIBRARIES}
|
||||
dScripts
|
||||
dGameBase
|
||||
dComponents
|
||||
|
||||
@@ -6,4 +6,5 @@ include(GoogleTest)
|
||||
|
||||
# Add the subdirectories
|
||||
add_subdirectory(dCommonTests)
|
||||
add_subdirectory(dECSTests)
|
||||
add_subdirectory(dGameTests)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "Game.h"
|
||||
#include "MessageType/Game.h"
|
||||
#include "MessageType/World.h"
|
||||
#include "magic_enum.hpp"
|
||||
#include <magic_enum/magic_enum.hpp>
|
||||
|
||||
#define ENUM_EQ(e, y, z)\
|
||||
LOG("%s %s", StringifiedEnum::ToString(static_cast<e>(y)).data(), #z);\
|
||||
|
||||
9
tests/dECSTests/CMakeLists.txt
Normal file
9
tests/dECSTests/CMakeLists.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
add_executable(dECSTests
|
||||
"TestECS.cpp"
|
||||
)
|
||||
|
||||
# Link needed libraries
|
||||
target_link_libraries(dECSTests PRIVATE dCommon dGame dECS GTest::gtest_main)
|
||||
|
||||
# Discover the tests
|
||||
gtest_discover_tests(dECSTests)
|
||||
220
tests/dECSTests/TestECS.cpp
Normal file
220
tests/dECSTests/TestECS.cpp
Normal file
@@ -0,0 +1,220 @@
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <span>
|
||||
#include <optional>
|
||||
#include <gtest/gtest.h>
|
||||
#include "Core.h"
|
||||
#include <dComponents/Component.h>
|
||||
#include <eReplicaComponentType.h>
|
||||
|
||||
using namespace dECS;
|
||||
|
||||
namespace TestECS {
|
||||
using LegacyComponent = ::Component;
|
||||
|
||||
namespace Component {
|
||||
using enum eReplicaComponentType;
|
||||
|
||||
void* NULL_PARENT = nullptr;
|
||||
|
||||
struct Legacy : public LegacyComponent {
|
||||
static constexpr eReplicaComponentType ComponentType = CHANGLING;
|
||||
|
||||
Legacy() = default;
|
||||
|
||||
void Update(float deltaTime) {
|
||||
std::printf("Legacy updated!\n");
|
||||
}
|
||||
};
|
||||
|
||||
struct Invalid {
|
||||
static constexpr eReplicaComponentType ComponentType = INVALID;
|
||||
|
||||
int value;
|
||||
};
|
||||
|
||||
struct Destroyable {
|
||||
static constexpr eReplicaComponentType ComponentType = DESTROYABLE;
|
||||
|
||||
using FactionId = int32_t;
|
||||
|
||||
float health;
|
||||
float maxHealth;
|
||||
float armor;
|
||||
float maxArmor;
|
||||
float imag;
|
||||
float maxImag;
|
||||
uint32_t damageToAbsorb;
|
||||
bool immune;
|
||||
bool gmImmune;
|
||||
bool shielded;
|
||||
float actualMaxHealth;
|
||||
float actualMaxArmor;
|
||||
float actualMaxImagination;
|
||||
std::vector<FactionId> factionIds;
|
||||
bool smashable;
|
||||
};
|
||||
}
|
||||
|
||||
struct IFakeSystem {
|
||||
virtual ~IFakeSystem() = default;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr virtual size_t Count() const noexcept = 0;
|
||||
|
||||
constexpr virtual void EmplaceBack() = 0;
|
||||
};
|
||||
|
||||
template <typename... Cs>
|
||||
struct FakeSystem : public IFakeSystem {
|
||||
template <typename C>
|
||||
using Storage = std::vector<std::remove_const_t<C>>;
|
||||
|
||||
std::tuple<Storage<Cs>...> data;
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr size_t Count() const noexcept override {
|
||||
return std::get<0>(data).size();
|
||||
}
|
||||
|
||||
constexpr void EmplaceBack() override {
|
||||
(std::get<Storage<Cs>>(data).emplace_back(), ...);
|
||||
}
|
||||
|
||||
template <typename C>
|
||||
requires std::disjunction_v<std::is_same<C, Cs>...>
|
||||
[[nodiscard]]
|
||||
std::span<C> Get() {
|
||||
return std::get<Storage<C>>(data);
|
||||
}
|
||||
|
||||
template <typename C>
|
||||
requires std::disjunction_v<std::is_same<C, Cs>...>
|
||||
[[nodiscard]]
|
||||
std::span<const C> Get() const {
|
||||
return std::get<Storage<C>>(data);
|
||||
}
|
||||
|
||||
template <typename Fn>
|
||||
requires std::is_invocable_r_v<void, Fn(Cs...), Cs...>
|
||||
void ForEach(Fn&& fn);
|
||||
};
|
||||
|
||||
class FakeIter {
|
||||
public:
|
||||
constexpr FakeIter(const IFakeSystem& fakeSys) noexcept
|
||||
: m_System{ fakeSys }
|
||||
{}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool Next() {
|
||||
return m_Count++ > m_System.Count();
|
||||
}
|
||||
|
||||
private:
|
||||
size_t m_Count;
|
||||
const IFakeSystem& m_System;
|
||||
};
|
||||
|
||||
template <typename... Cs>
|
||||
template <typename Fn>
|
||||
requires std::is_invocable_r_v<void, Fn(Cs...), Cs...>
|
||||
void FakeSystem<Cs...>::ForEach(Fn&& fn){
|
||||
for (size_t i = 0; i < Count(); ++i) {
|
||||
fn(Get<Cs>()[i]...);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Test that entity IDs increment correctly
|
||||
TEST(ECSTest, IncrementEntityIdsSingleThread) {
|
||||
auto w = World{};
|
||||
|
||||
auto ea = w.MakeEntity();
|
||||
ASSERT_EQ(ea.GetObjectID(), 1);
|
||||
|
||||
auto eb = w.MakeEntity();
|
||||
ASSERT_EQ(eb.GetObjectID(), 2);
|
||||
|
||||
auto ec = w.MakeEntity();
|
||||
ASSERT_EQ(ec.GetObjectID(), 3);
|
||||
}
|
||||
|
||||
// Test adding and getting components
|
||||
TEST(ECSTest, MakeOneEntityAndAddComponents) {
|
||||
using namespace TestECS::Component;
|
||||
|
||||
auto w = World{};
|
||||
auto e = w.MakeEntity();
|
||||
ASSERT_EQ(e.GetObjectID(), 1);
|
||||
|
||||
// add component
|
||||
auto* const testCompPtr = e.AddComponent<Invalid>();
|
||||
ASSERT_NE(testCompPtr, nullptr);
|
||||
ASSERT_EQ(testCompPtr->ComponentType, Invalid::ComponentType);
|
||||
ASSERT_EQ(testCompPtr->value, 0);
|
||||
testCompPtr->value = 15;
|
||||
|
||||
// try getting the same component we just added
|
||||
auto* const gotTestCompPtr = e.GetComponent<Invalid>();
|
||||
ASSERT_NE(gotTestCompPtr, nullptr);
|
||||
ASSERT_EQ(gotTestCompPtr, testCompPtr);
|
||||
ASSERT_NE(gotTestCompPtr->value, 0);
|
||||
ASSERT_EQ(gotTestCompPtr->value, 15);
|
||||
}
|
||||
|
||||
// Test world scoping
|
||||
TEST(ECSTest, WorldScope) {
|
||||
using namespace TestECS::Component;
|
||||
|
||||
auto e = std::optional<dECS::Entity>{};
|
||||
|
||||
{
|
||||
auto w = World{};
|
||||
e.emplace(w.MakeEntity());
|
||||
ASSERT_EQ(e->GetObjectID(), 1);
|
||||
|
||||
// add component within scope
|
||||
auto* const cPtr = e->AddComponent<Invalid>();
|
||||
ASSERT_NE(cPtr, nullptr);
|
||||
}
|
||||
|
||||
// Attempting to access this component should return nullptr
|
||||
// now that the world has gone out of scope
|
||||
ASSERT_EQ(e->GetComponent<Invalid>(), nullptr);
|
||||
}
|
||||
|
||||
// Create and iterate over a system
|
||||
TEST(ECSTest, CreateAndIterateOverSystem) {
|
||||
using namespace TestECS::Component;
|
||||
|
||||
auto w = World{};
|
||||
auto s = w.MakeSystem<Destroyable, const Invalid>("DestInvalid");
|
||||
|
||||
size_t count = 0;
|
||||
s.ForEach([&](Destroyable& d, const Invalid& i) {
|
||||
std::printf("i = %ld: d.health = %f\n", ++count, d.health);
|
||||
d.health += 1;
|
||||
});
|
||||
}
|
||||
|
||||
TEST(ECSTest, FakeIterationForTestingPurposes) {
|
||||
using namespace TestECS;
|
||||
using namespace TestECS::Component;
|
||||
|
||||
auto s = FakeSystem<Legacy, Destroyable>{};
|
||||
|
||||
auto const r = 2 + std::rand() % 8;
|
||||
for (size_t i = 0; i < r; ++i) {
|
||||
s.EmplaceBack();
|
||||
}
|
||||
|
||||
size_t count = 0;
|
||||
s.ForEach([&](Legacy& l, Destroyable& d) {
|
||||
l.Update(0.0f);
|
||||
std::printf("i = %ld: d.health = %f\n", ++count, d.health);
|
||||
d.health += 1;
|
||||
});
|
||||
std::printf("Total count = %ld\n", count);
|
||||
ASSERT_EQ(r, count);
|
||||
}
|
||||
3
thirdparty/CMakeLists.txt
vendored
3
thirdparty/CMakeLists.txt
vendored
@@ -34,9 +34,6 @@ target_include_directories(bcrypt PRIVATE "libbcrypt/src")
|
||||
# Source code for sqlite
|
||||
add_subdirectory(SQLite)
|
||||
|
||||
# Source code for magic_enum
|
||||
add_subdirectory(magic_enum)
|
||||
|
||||
# Create our third party library objects
|
||||
add_subdirectory(raknet)
|
||||
|
||||
|
||||
1
thirdparty/magic_enum
vendored
1
thirdparty/magic_enum
vendored
Submodule thirdparty/magic_enum deleted from e55b9b54d5
Reference in New Issue
Block a user