Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Reduce/remove entity pointers as means of addressing entities #1406

Draft
wants to merge 91 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
94eb15b
remove entity pointer component member
jadebenn Jan 10, 2024
b4ac098
added highly experimental component archetype class code
jadebenn Jan 11, 2024
d270dc7
assorted class changes
jadebenn Jan 13, 2024
3804eff
allow usage of NiPoint3 and NiQuaternion in constexpr context
jadebenn Jan 13, 2024
600b3c4
Merge branch 'main' into RemoveEntityPointers
jadebenn Jan 13, 2024
3d300e0
removed .cpp files entirely
jadebenn Jan 13, 2024
0767d16
moving circular dependency circumvention stuff to an .inl file
jadebenn Jan 13, 2024
691a439
real world usage!!!!!
jadebenn Jan 13, 2024
99c4c61
reverting weird branch cross-pollination
jadebenn Jan 13, 2024
d53a808
removing more weird branch cross-pollination
jadebenn Jan 13, 2024
5732237
remove comment
jadebenn Jan 13, 2024
f1bf19b
Merge branch 'ConstexprNiTypes' into RemoveEntityPointers
jadebenn Jan 13, 2024
2b2001a
more pointer conversions
jadebenn Jan 13, 2024
e7c5a41
added inverse header guard to inl file
jadebenn Jan 13, 2024
c5d25d1
Update NiPoint3.inl
jadebenn Jan 13, 2024
977c502
trying different constructor syntax
jadebenn Jan 13, 2024
3df109f
Merge branch 'ConstexprNiTypes' into RemoveEntityPointers
jadebenn Jan 13, 2024
9c576e0
tweaking constructors
jadebenn Jan 13, 2024
9c3ebf0
removed entity pointers from component constructors
jadebenn Jan 14, 2024
bbba90b
HasComponent functionality working
jadebenn Jan 15, 2024
ef047ff
reorganize experimental code
jadebenn Jan 16, 2024
a53f641
reorg
jadebenn Jan 16, 2024
3b9d3cc
further conceptualization of archetype system
jadebenn Jan 18, 2024
1638b07
self-documenting code
jadebenn Jan 18, 2024
1353ac5
create interface class for archetypes
jadebenn Jan 19, 2024
d758477
EntitySystem updates
jadebenn Jan 20, 2024
174846c
Update RenderComponent.cpp to fix unique_ptr usage
jadebenn Jan 20, 2024
75ef01e
emplace instead of insert
jadebenn Jan 20, 2024
63628de
Merge branch 'RemoveEntityPointers' of https://github.com/jadebenn/Da…
jadebenn Jan 20, 2024
c0cb759
Update BaseCombatAIComponent.cpp
jadebenn Jan 20, 2024
4017203
add to workflows
jadebenn Jan 20, 2024
6c423f1
workflows
jadebenn Jan 20, 2024
398a32e
workflows tinkering
jadebenn Jan 20, 2024
2efbb00
remove consteval
jadebenn Jan 20, 2024
ae43159
Fix nipoint issues
jadebenn Jan 20, 2024
81cb9fe
enable concepts
jadebenn Jan 20, 2024
247aabc
fix concepts (try 2)
jadebenn Jan 20, 2024
b29bac5
OS change test
jadebenn Jan 20, 2024
9007ee0
update OS presets
jadebenn Jan 20, 2024
f169eed
cmake flag test
jadebenn Jan 20, 2024
de751d1
run ci with 'consteval' again
jadebenn Jan 20, 2024
e461fda
updating components
jadebenn Jan 20, 2024
50b7341
Merge branch 'main' into RemoveEntityPointers
jadebenn Jan 20, 2024
f97185e
implemented visitor pattern
jadebenn Jan 21, 2024
64fd032
safety additions
jadebenn Jan 21, 2024
00f411d
attribute tags
jadebenn Jan 21, 2024
006add0
trial and error for the macos issue
jadebenn Jan 21, 2024
bf29103
macos fix try 2
jadebenn Jan 21, 2024
e54f4d3
Merge branch 'main' into RemoveEntityPointers
jadebenn Jan 21, 2024
80c9548
make function again
jadebenn Jan 21, 2024
f454c97
try fold expression
jadebenn Jan 21, 2024
d69bb25
improve safety
jadebenn Jan 21, 2024
7b17793
improved safety and hopefully fixed the macos issue
jadebenn Jan 21, 2024
b802c13
Testing range-based iteration of components
jadebenn Jan 22, 2024
5fb6f75
CI build test
jadebenn Jan 22, 2024
ff60255
link options CI test
jadebenn Jan 22, 2024
0107076
More iteration testing
jadebenn Jan 22, 2024
a6cba14
macos try again
jadebenn Jan 22, 2024
63a57f7
try manually specifying c++20
jadebenn Jan 22, 2024
e6e3007
try updating macos
jadebenn Jan 22, 2024
e0514f4
more macos tests
jadebenn Jan 22, 2024
d66e2cd
one last macos try for tonight
jadebenn Jan 22, 2024
e7ca6d5
bout to pull a pro gamer move (this is a terrible idea)
jadebenn Jan 22, 2024
19a414a
continuing the string of genius moves
jadebenn Jan 22, 2024
ed935c6
pro gamer mlg
jadebenn Jan 22, 2024
c7f280d
tired
jadebenn Jan 22, 2024
040d420
force xcode upgrade
jadebenn Jan 22, 2024
38b8d50
aaaaaaaah
jadebenn Jan 22, 2024
a94f642
Try macos without certain size flags
jadebenn Jan 22, 2024
a52f459
try fix for macos
jadebenn Jan 22, 2024
008aec5
fix definition to match declaration
jadebenn Jan 22, 2024
21d8187
Update build-and-test.yml
jadebenn Jan 23, 2024
a7fe978
Update build-and-test.yml
jadebenn Jan 23, 2024
1d6e51f
update cmake for macos
jadebenn Jan 23, 2024
8489149
Try returning void to suppress MacOS warning
jadebenn Jan 23, 2024
0a2fb6b
Re-enable werror for MacOS
jadebenn Jan 23, 2024
b4cfbe4
Try 2 at void return
jadebenn Jan 23, 2024
0c4fa4f
3rd try
jadebenn Jan 23, 2024
7610162
Move MD5.cpp to thirdparty
jadebenn Jan 23, 2024
3da0142
Move MD5.h to thirdparty
jadebenn Jan 23, 2024
e5faeef
Rename thirdparty/MD5.cpp to thirdparty/MD5/MD5.cpp
jadebenn Jan 23, 2024
78f0ad6
Rename thirdparty/MD5.h to thirdparty/MD5/MD5.h
jadebenn Jan 23, 2024
3f48da0
Create CMakeLists.txt
jadebenn Jan 23, 2024
25bbe7b
Update CMakeLists.txt
jadebenn Jan 23, 2024
8b2e145
Update CMakeLists.txt
jadebenn Jan 23, 2024
4ff5812
Revert "Try returning void to suppress MacOS warning"
jadebenn Jan 24, 2024
55e1e95
Revert "Update CMakeLists.txt"
jadebenn Jan 25, 2024
3845ddf
Revert "Revert "Try returning void to suppress MacOS warning""
jadebenn Jan 25, 2024
6a07aaf
Revert "Revert "Update CMakeLists.txt""
jadebenn Jan 25, 2024
1fc570f
Revert "Revert "Revert "Try returning void to suppress MacOS warning"""
jadebenn Jan 25, 2024
6d1d7fc
variadic inheritance (yes, really)
jadebenn Jan 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
push:
branches: [ main ]
branches: [ main, RemoveEntityPointers ]
pull_request:
branches: [ main ]
branches: [ main, RemoveEntityPointers ]

jobs:
build-and-test:
Expand All @@ -13,7 +13,7 @@ jobs:
continue-on-error: true
strategy:
matrix:
os: [ windows-2022, ubuntu-22.04, macos-11 ]
os: [ windows-2022, ubuntu-22.04, macos-13 ]

steps:
- uses: actions/checkout@v3
Expand All @@ -25,9 +25,12 @@ jobs:
with:
vs-version: '[17,18)'
msbuild-architecture: x64
- name: Install libssl (Mac Only)
if: ${{ matrix.os == 'macos-11' }}
run: brew install openssl@3
- name: Install libssl and switch to XCode 15.2 (Mac Only)
if: ${{ matrix.os == 'macos-13' }}
run: |
brew install openssl@3
sudo xcode-select -s /Applications/Xcode_15.2.app/Contents/Developer

- name: cmake
uses: lukka/run-cmake@v10
with:
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ project(Darkflame)
include(CTest)

set(CMAKE_CXX_STANDARD 20)
set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

# Read variables from file
Expand Down
11 changes: 6 additions & 5 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
"inherits": "default"
},
{
"name": "ci-macos-11",
"name": "ci-macos-13",
"displayName": "CI configure step for MacOS",
"description": "Same as default, Used in GitHub actions workflow",
"inherits": "default"

},
{
"name": "ci-windows-2022",
Expand Down Expand Up @@ -74,8 +75,8 @@
"jobs": 2
},
{
"name": "ci-macos-11",
"configurePreset": "ci-macos-11",
"name": "ci-macos-13",
"configurePreset": "ci-macos-13",
"displayName": "MacOS CI Build",
"description": "This preset is used by the CI build on MacOS",
"jobs": 2
Expand All @@ -95,8 +96,8 @@
}
},
{
"name": "ci-macos-11",
"configurePreset": "ci-macos-11",
"name": "ci-macos-13",
"configurePreset": "ci-macos-13",
"displayName": "CI Tests on MacOS",
"description": "Runs all tests on a Mac configuration",
"execution": {
Expand Down
232 changes: 6 additions & 226 deletions dCommon/NiPoint3.cpp
Original file line number Diff line number Diff line change
@@ -1,210 +1,24 @@
#include "NiPoint3.h"
#include "NiQuaternion.h"

// C++
#include <cmath>

// Static Variables
const NiPoint3 NiPoint3::ZERO(0.0f, 0.0f, 0.0f);
const NiPoint3 NiPoint3::UNIT_X(1.0f, 0.0f, 0.0f);
const NiPoint3 NiPoint3::UNIT_Y(0.0f, 1.0f, 0.0f);
const NiPoint3 NiPoint3::UNIT_Z(0.0f, 0.0f, 1.0f);
const NiPoint3 NiPoint3::UNIT_ALL(1.0f, 1.0f, 1.0f);

//! Initializer
NiPoint3::NiPoint3(void) {
this->x = 0;
this->y = 0;
this->z = 0;
}

//! Initializer
NiPoint3::NiPoint3(float x, float y, float z) {
this->x = x;
this->y = y;
this->z = z;
}

//! Copy Constructor
NiPoint3::NiPoint3(const NiPoint3& point) {
this->x = point.x;
this->y = point.y;
this->z = point.z;
}

//! Destructor
NiPoint3::~NiPoint3(void) {}

// MARK: Getters / Setters

//! Gets the X coordinate
float NiPoint3::GetX(void) const {
return this->x;
}

//! Sets the X coordinate
void NiPoint3::SetX(float x) {
this->x = x;
}

//! Gets the Y coordinate
float NiPoint3::GetY(void) const {
return this->y;
}

//! Sets the Y coordinate
void NiPoint3::SetY(float y) {
this->y = y;
}

//! Gets the Z coordinate
float NiPoint3::GetZ(void) const {
return this->z;
}

//! Sets the Z coordinate
void NiPoint3::SetZ(float z) {
this->z = z;
}

// MARK: Functions
// MARK: Member Functions

//! Gets the length of the vector
float NiPoint3::Length(void) const {
return sqrt(x * x + y * y + z * z);
}

//! Gets the squared length of a vector
float NiPoint3::SquaredLength(void) const {
return (x * x + y * y + z * z);
}

//! Returns the dot product of the vector dotted with another vector
float NiPoint3::DotProduct(const Vector3& vec) const {
return ((this->x * vec.x) + (this->y * vec.y) + (this->z * vec.z));
}

//! Returns the cross product of the vector crossed with another vector
Vector3 NiPoint3::CrossProduct(const Vector3& vec) const {
return Vector3(((this->y * vec.z) - (this->z * vec.y)),
((this->z * vec.x) - (this->x * vec.z)),
((this->x * vec.y) - (this->y * vec.x)));
float NiPoint3::Length() const {
return std::sqrt(x * x + y * y + z * z);
}

//! Unitize the vector
NiPoint3 NiPoint3::Unitize(void) const {
NiPoint3 NiPoint3::Unitize() const {
float length = this->Length();

return length != 0 ? *this / length : NiPoint3::ZERO;
return length != 0 ? *this / length : NiPoint3Constant::ZERO;
}


// MARK: Operators

//! Operator to check for equality
bool NiPoint3::operator==(const NiPoint3& point) const {
return point.x == this->x && point.y == this->y && point.z == this->z;
}

//! Operator to check for inequality
bool NiPoint3::operator!=(const NiPoint3& point) const {
return !(*this == point);
}

//! Operator for subscripting
float& NiPoint3::operator[](int i) {
float* base = &x;
return base[i];
}

//! Operator for subscripting
const float& NiPoint3::operator[](int i) const {
const float* base = &x;
return base[i];
}

//! Operator for addition of vectors
NiPoint3 NiPoint3::operator+(const NiPoint3& point) const {
return NiPoint3(this->x + point.x, this->y + point.y, this->z + point.z);
}

//! Operator for addition of vectors
NiPoint3& NiPoint3::operator+=(const NiPoint3& point) {
this->x += point.x;
this->y += point.y;
this->z += point.z;
return *this;
}

NiPoint3& NiPoint3::operator*=(const float scalar) {
this->x *= scalar;
this->y *= scalar;
this->z *= scalar;
return *this;
}

//! Operator for subtraction of vectors
NiPoint3 NiPoint3::operator-(const NiPoint3& point) const {
return NiPoint3(this->x - point.x, this->y - point.y, this->z - point.z);
}

//! Operator for addition of a scalar on all vector components
NiPoint3 NiPoint3::operator+(float fScalar) const {
return NiPoint3(this->x + fScalar, this->y + fScalar, this->z + fScalar);
}

//! Operator for subtraction of a scalar on all vector components
NiPoint3 NiPoint3::operator-(float fScalar) const {
return NiPoint3(this->x - fScalar, this->y - fScalar, this->z - fScalar);
}

//! Operator for scalar multiplication of a vector
NiPoint3 NiPoint3::operator*(float fScalar) const {
return NiPoint3(this->x * fScalar, this->y * fScalar, this->z * fScalar);
}

//! Operator for scalar division of a vector
NiPoint3 NiPoint3::operator/(float fScalar) const {
float retX = this->x != 0 ? this->x / fScalar : 0;
float retY = this->y != 0 ? this->y / fScalar : 0;
float retZ = this->z != 0 ? this->z / fScalar : 0;
return NiPoint3(retX, retY, retZ);
}


// MARK: Helper Functions

//! Checks to see if the point (or vector) is with an Axis-Aligned Bounding Box
bool NiPoint3::IsWithinAxisAlignedBox(const NiPoint3& minPoint, const NiPoint3& maxPoint) {
if (this->x < minPoint.x) return false;
if (this->x > maxPoint.x) return false;
if (this->y < minPoint.y) return false;
if (this->y > maxPoint.y) return false;

return (this->z < maxPoint.z && this->z > minPoint.z);
}

//! Checks to see if the point (or vector) is within a sphere
bool NiPoint3::IsWithinSpehere(const NiPoint3& sphereCenter, float radius) {
Vector3 diffVec = Vector3(x - sphereCenter.GetX(), y - sphereCenter.GetY(), z - sphereCenter.GetZ());
return (diffVec.SquaredLength() <= (radius * radius));
}

NiPoint3 NiPoint3::ClosestPointOnLine(const NiPoint3& a, const NiPoint3& b, const NiPoint3& p) {
if (a == b) return a;

const auto pa = p - a;
const auto ab = b - a;

const auto t = pa.DotProduct(ab) / ab.SquaredLength();

if (t <= 0.0f) return a;

if (t >= 1.0f) return b;

return a + ab * t;
}

float NiPoint3::Angle(const NiPoint3& a, const NiPoint3& b) {
const auto dot = a.DotProduct(b);
const auto lenA = a.SquaredLength();
Expand All @@ -220,15 +34,7 @@ float NiPoint3::Distance(const NiPoint3& a, const NiPoint3& b) {
return std::sqrt(dx * dx + dy * dy + dz * dz);
}

float NiPoint3::DistanceSquared(const NiPoint3& a, const NiPoint3& b) {
const auto dx = a.x - b.x;
const auto dy = a.y - b.y;
const auto dz = a.z - b.z;

return dx * dx + dy * dy + dz * dz;
}

NiPoint3 NiPoint3::MoveTowards(const NiPoint3& current, const NiPoint3& target, float maxDistanceDelta) {
NiPoint3 NiPoint3::MoveTowards(const NiPoint3& current, const NiPoint3& target, const float maxDistanceDelta) {
float dx = target.x - current.x;
float dy = target.y - current.y;
float dz = target.z - current.z;
Expand All @@ -249,29 +55,3 @@ NiPoint3 NiPoint3::MoveTowards(const NiPoint3& current, const NiPoint3& target,
float length = std::sqrt(lengthSquared);
return NiPoint3(current.x + dx / length * maxDistanceDelta, current.y + dy / length * maxDistanceDelta, current.z + dz / length * maxDistanceDelta);
}

//This code is yoinked from the MS XNA code, so it should be right, even if it's horrible.
NiPoint3 NiPoint3::RotateByQuaternion(const NiQuaternion& rotation) {
Vector3 vector;
float num12 = rotation.x + rotation.x;
float num2 = rotation.y + rotation.y;
float num = rotation.z + rotation.z;
float num11 = rotation.w * num12;
float num10 = rotation.w * num2;
float num9 = rotation.w * num;
float num8 = rotation.x * num12;
float num7 = rotation.x * num2;
float num6 = rotation.x * num;
float num5 = rotation.y * num2;
float num4 = rotation.y * num;
float num3 = rotation.z * num;

NiPoint3 value = *this;
float num15 = ((value.x * ((1.0f - num5) - num3)) + (value.y * (num7 - num9))) + (value.z * (num6 + num10));
float num14 = ((value.x * (num7 + num9)) + (value.y * ((1.0f - num8) - num3))) + (value.z * (num4 - num11));
float num13 = ((value.x * (num6 - num10)) + (value.y * (num4 + num11))) + (value.z * ((1.0f - num8) - num5));
vector.x = num15;
vector.y = num14;
vector.z = num13;
return vector;
}
Loading