-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
175 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ®istry) { | ||
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 ®istry) { | ||
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} | ||
|