Skip to content

Commit

Permalink
EnTT Library ECS tests
Browse files Browse the repository at this point in the history
  • Loading branch information
The5-1 committed Jul 7, 2018
1 parent ba6531c commit 398683d
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 1 deletion.
22 changes: 21 additions & 1 deletion ECS_entt01/ECS_entt01.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,25 @@
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IncludePath>D:\Dev\Libraries\entt\src;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<IncludePath>D:\Dev\Libraries\entt\src;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<IncludePath>D:\Dev\Libraries\entt\src;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<IncludePath>D:\Dev\Libraries\entt\src;$(IncludePath)</IncludePath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<PreprocessToFile>false</PreprocessToFile>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand All @@ -84,6 +96,7 @@
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<PreprocessToFile>false</PreprocessToFile>
</ClCompile>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand All @@ -94,6 +107,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<PreprocessToFile>false</PreprocessToFile>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
Expand All @@ -108,13 +122,19 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<ConformanceMode>true</ConformanceMode>
<PreprocessToFile>false</PreprocessToFile>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="entt_test01.h" />
<ClInclude Include="utility_profiling.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
13 changes: 13 additions & 0 deletions ECS_entt01/ECS_entt01.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,17 @@
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="entt_test01.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="utility_profiling.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
84 changes: 84 additions & 0 deletions ECS_entt01/entt_test01.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#pragma once

#include <entt/entt.hpp>

#include <cstdint>
#include <iostream>

#include "utility_profiling.h"

namespace entt_test01 {


struct Position {
float x;
float y;
};

struct Velocity {
float dx;
float dy;
};

void update(entt::DefaultRegistry &registry) {
auto view = registry.view<Position, Velocity>();

for (auto entity : view) {
// gets only the components that are going to be used ...

auto &velocity = view.get<Velocity>(entity);

velocity.dx = 0.;
velocity.dy = 0.;

// ...
}
}

void update(std::uint64_t dt, entt::DefaultRegistry &registry) {
registry.view<Position, Velocity>().each([dt](auto entity, auto &position, auto &velocity) {
// gets all the components of the view at once ...

position.x += velocity.dx * dt;
position.y += velocity.dy * dt;

// ...
});
}

int test() {
entt::DefaultRegistry registry;
std::uint64_t dt = 16;

{
SCOPETIMER();

auto num = 1000000;
printf("Creating %i entities...", num);
for (auto i = 0; i < num; ++i) {
auto entity = registry.create();
registry.assign<Position>(entity, i * 1.f, i * 1.f);
if (i % 2 == 0) {
registry.assign<Velocity>(entity, i * .1f, i * .1f);
}
}
printf("done!\n");
// takes about 90ms in Release build
}

{
SCOPETIMERAVG(1000);
for (auto i = 0; i < 1000; i++)
{

update(dt, registry);
}
//takes about 3ms to update all entities
}

update(registry);


return 0;
}
}
14 changes: 14 additions & 0 deletions ECS_entt01/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <iostream>
#include <entt\entt.hpp>
#include <cstdint>

#include "entt_test01.h"

void main()
{
entt_test01::test();


printf("hello world!");

}
43 changes: 43 additions & 0 deletions ECS_entt01/utility_profiling.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#pragma once

#include <string>
#include <chrono>
#include <iostream>

namespace util {

class ScopeTimer {
public:
ScopeTimer(std::string text = "", unsigned int line = 0, unsigned int iterations = 0) :text(text), line(line), iterations(iterations)
{
start = std::chrono::high_resolution_clock::now();
}

~ScopeTimer()
{
auto end = std::chrono::high_resolution_clock::now();
auto dur = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
long long int ms = static_cast<long long int>(dur.count());

if (iterations > 2) ms /= iterations;

if (text.length() > 0) printf("%s ", text);
if (line > 0) printf("(Line %u) ", line);
if (iterations > 2) printf("(avg. %u) ", iterations);
if (text.length() > 0 || line > 0 || iterations > 2) printf(": ");
printf("%lldms", ms);
printf("\n");
}

protected:
unsigned int iterations;
std::string text;
unsigned int line;
std::chrono::time_point<std::chrono::high_resolution_clock> start;
};

#define SCOPETIMER() util::ScopeTimer t(__FUNCTION__, __LINE__, 0)
#define SCOPETIMERAVG(iterations) util::ScopeTimer t(__FUNCTION__, __LINE__,iterations)

}

0 comments on commit 398683d

Please sign in to comment.