Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 7 additions & 2 deletions .github/workflows/ci-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
# Windows with MSVC
- name: "Windows MSVC"
compiler: msvc
cmake-generator: 'Visual Studio 17 2022'
cmake-generator: ''
cmake-options: '-DGAMECOE_USE_TESTCOE=ON'

# Windows with MinGW (GCC)
Expand Down Expand Up @@ -47,7 +47,12 @@ jobs:

- name: Configure CMake
run: |
cmake -B build -G "${{ matrix.cmake-generator }}" ${{ matrix.cmake-options }}
if [ -n "${{ matrix.cmake-generator }}" ]; then
cmake -B build -G "${{ matrix.cmake-generator }}" ${{ matrix.cmake-options }}
else
cmake -B build ${{ matrix.cmake-options }}
fi
shell: bash

- name: Build
run: |
Expand Down
28 changes: 28 additions & 0 deletions include/gamecoe/component/parent_child.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <gamecoe/entity/entity.hpp>
#include <vector>
#include <type_traits>

namespace gamecoe
{
namespace components
{
struct parent
{
entity handle = entity::invalid();

bool has_parent() const { return handle != entity::invalid(); }
};

struct children
{
std::vector<entity> handles;

bool has_children() const { return !handles.empty(); }
};

static_assert(std::is_standard_layout_v<parent>);
static_assert(std::is_standard_layout_v<children>);
} // namespace components
} // namespace gamecoe
44 changes: 44 additions & 0 deletions include/gamecoe/component/transform.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once

#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <type_traits>

namespace gamecoe
{
namespace components
{
struct transform
{
glm::vec3 position{0.0f};
glm::quat rotation{1.0f, 0.0f, 0.0f, 0.0f};
glm::vec3 scale{1.0f};

glm::mat4 translation_matrix() const { return glm::translate(glm::mat4(1.0f), position); }
glm::mat4 rotation_matrix() const { return glm::mat4_cast(rotation); }
glm::mat4 scale_matrix() const { return glm::scale(glm::mat4(1.0f), scale); }
glm::mat4 local_matrix() const
{
glm::mat4 m = glm::mat4_cast(rotation);
m[0] *= scale.x;
m[1] *= scale.y;
m[2] *= scale.z;
m[3] = glm::vec4(position, 1.0f);
return m;
}

glm::vec3 forward() const { return glm::normalize(rotation * glm::vec3(0.0f, 0.0f, -1.0f)); }
glm::vec3 right() const { return glm::normalize(rotation * glm::vec3(1.0f, 0.0f, 0.0f)); }
glm::vec3 up() const { return glm::normalize(rotation * glm::vec3(0.0f, 1.0f, 0.0f)); }

glm::vec3 euler_rotation() const { return glm::eulerAngles(rotation); }

void translate(glm::vec3 offset) { position += offset; }
void rotate(glm::vec3 euler_offset) { rotation = glm::quat(euler_offset) * rotation; }
void rotate_around(glm::vec3 axis, float angle) { rotation = rotation * glm::angleAxis(angle, glm::normalize(axis)); }
};

static_assert(std::is_standard_layout_v<transform>);
} // namespace components
} // namespace gamecoe
18 changes: 18 additions & 0 deletions include/gamecoe/component/velocity.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <glm/glm.hpp>
#include <type_traits>

namespace gamecoe
{
namespace components
{
struct velocity
{
glm::vec3 linear{0.0f};
glm::vec3 angular{0.0f};
};

static_assert(std::is_standard_layout_v<velocity>);
} // namespace components
} // namespace gamecoe
2 changes: 2 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ add_executable(gamecoe_tests
entity/component_pool_tests.cpp
entity/entities_tests.cpp
entity/extraction_tests.cpp
component/transform_tests.cpp
component/parent_child_tests.cpp
)

target_link_libraries(gamecoe_tests
Expand Down
93 changes: 93 additions & 0 deletions tests/component/parent_child_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#include <gtest/gtest.h>
#include <gamecoe/component/parent_child.hpp>

using namespace gamecoe;

//==============================================================================
// ParentTests - parent component tests
//==============================================================================

class ParentTests : public ::testing::Test
{
protected:
components::parent p;
};

//==============================================================================
// Default State
//==============================================================================

TEST_F(ParentTests, DefaultState)
{
// Test 1: Default-constructed parent has no parent entity
{
EXPECT_EQ(p.handle, entity::invalid());
EXPECT_FALSE(p.has_parent());
}
}

//==============================================================================
// Assigning a Parent
//==============================================================================

TEST_F(ParentTests, AssignParent)
{
// Test 1: Setting parent to a valid entity updates has_parent()
{
entity e = entity::create(5, 0);
p.handle = e;

EXPECT_TRUE(p.has_parent());
EXPECT_EQ(p.handle, e);
}
}

//==============================================================================
// ChildrenTests - children component tests
//==============================================================================

class ChildrenTests : public ::testing::Test
{
protected:
components::children c;
};

//==============================================================================
// Default State
//==============================================================================

TEST_F(ChildrenTests, DefaultState)
{
// Test 1: Default-constructed children has an empty list
{
EXPECT_TRUE(c.handles.empty());
EXPECT_FALSE(c.has_children());
}
}

//==============================================================================
// Populating Children
//==============================================================================

TEST_F(ChildrenTests, PopulateChildren)
{
entity e1 = entity::create(1, 0);
entity e2 = entity::create(2, 0);

// Test 1: Adding a single child updates has_children()
{
c.handles.push_back(e1);

EXPECT_TRUE(c.has_children());
EXPECT_EQ(c.handles.size(), 1);
}

// Test 2: Adding a second child preserves both entities, in order
{
c.handles.push_back(e2);

EXPECT_EQ(c.handles.size(), 2);
EXPECT_EQ(c.handles[0], e1);
EXPECT_EQ(c.handles[1], e2);
}
}
Loading
Loading