Skip to content

Commit

Permalink
[ECS][Sys] moved alignment-constants to sysdefs + modified ECS Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gabekz committed Jul 25, 2023
1 parent aaa593c commit 02b2a1a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
10 changes: 2 additions & 8 deletions src/entity/__generated__/components_gen.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/entity/component/__tests__/component-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ TEST_F(ComponentLoaderTest, Maps_To_C_Struct)
// p->MapFromExisting(cStruct, *m_Layouts["ComponentSingle"]);

// Check size of C Struct against generated component
#if 1
#if 0 // Needs alignment
ASSERT_EQ((size_t)sizeof(C_ComponentSingle),
m_Layouts["ComponentSingle"]->getSizeReq());
#endif
Expand Down
19 changes: 11 additions & 8 deletions src/entity/component/__tests__/component_c_map-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
#include <entity/component/ecs_component_layout_loader.hpp>

#include <util/maths.h>
#include <util/sysdefs.h>

#ifndef CACHE_LINE
#define CACHE_LINE ECS_COMPONENTS_ALIGN_BYTES
#endif // CACHE_LINE

using namespace entity;

Expand All @@ -38,16 +43,14 @@ struct ComponentCMapTest : testing::Test

std::map<std::string, ECSComponentLayout *> m_Layouts;

#define CACHE_LINE ECS_COMPONENTS_ALIGN_BYTES
// #define CACHE_ALIGN __declspec(align(CACHE_LINE))
typedef struct CmpTransform
{
ui16 hasParent;
mat4 model;
vec3 orientation;
void *parent;
vec3 position;
vec3 scale;
CACHE_ALIGN(ui16 hasParent);
CACHE_ALIGN(mat4 model);
CACHE_ALIGN(vec3 orientation);
CACHE_ALIGN(void *parent);
CACHE_ALIGN(vec3 position);
CACHE_ALIGN(vec3 scale);
} CmpTransform;

ComponentCMapTest()
Expand Down
14 changes: 14 additions & 0 deletions src/util/sysdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#define SYS_ENV_UNIX
#define _GNU_SOURCE_

#define CACHE_LINE 16

#if defined(__x86_64__) || defined(__ppc64__)
#define SYS_ENV_64
#else
Expand All @@ -42,6 +44,8 @@
#undef OK
#undef CONNECT_DEFERRED // override from Windows SDK, clashes with Object enum

#define CACHE_LINE 16

#endif // SYS_ENV_WIN

// -- C Specific boolean definitions //
Expand Down Expand Up @@ -74,6 +78,16 @@
#define SYS_DEBUG SYS_DISABLED
#endif

// Cache/Memory Alignment
#if defined(SYS_ENV_WIN)
#define CACHE_ALIGN(...) __declspec(align(CACHE_LINE)) __VA_ARGS__
#elif defined(SYS_ENV_UNIX)
#define CACHE_ALIGN(...) __VA_ARGS__ __attribute__((aligned(CACHE_LINE)))
#else
#define CACHE_ALIGN void
#pragma warning Unknown dynamic link import / export semantics.
#endif

// -- Types //

#if defined(SYS_ENV_64)
Expand Down

0 comments on commit 02b2a1a

Please sign in to comment.