From fcbf59a968d90149867d94b2494b673a4f1a00d8 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sun, 26 Feb 2017 15:42:46 -0500 Subject: initial commit --- entitiesBenchmark.h | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 entitiesBenchmark.h (limited to 'entitiesBenchmark.h') diff --git a/entitiesBenchmark.h b/entitiesBenchmark.h new file mode 100644 index 0000000..dcf22f1 --- /dev/null +++ b/entitiesBenchmark.h @@ -0,0 +1,140 @@ +#ifndef ENTITIESBENCHMARK_H_ +#define ENTITIESBENCHMARK_H_ + +#include +#include +#include +#include +#include +#include + +#include "entities.hpp" + +class EntitiesBenchmark { + public: + + struct PositionComponent : public Component { + float x = 0.0f; + float y = 0.0f; + }; + + struct VelocityComponent : public Component { + float x = 0.0f; + float y = 0.0f; + }; + + struct ComflabulationComponent : public Component { + float thingy = 0.0; + int dingy = 0; + bool mingy = false; + std::string stringy; + }; + + class MovementSystem : public System { + public: + MovementSystem() = default; + + void update(EntityManager &es, DeltaTime dt) { + es.each( + [dt](Entity e) { + auto& pos = *e.component(); + auto& vel = *e.component(); + pos.x = vel.x * dt; + pos.y = vel.y * dt; + } + ); + } + }; + + class ComflabSystem : public System { + public: + ComflabSystem() = default; + + void update(EntityManager &es, DeltaTime dt) { + es.each( + [dt](Entity e) { + auto comflab = e.component(); + comflab->thingy *= 1.000001f; + comflab->mingy = !comflab->mingy; + comflab->dingy++; + //comflab.stringy = std::to_string(comflab.dingy); + } + ); + } + }; + + #ifdef USE_MORECOMPLEX_SYSTEM + class MoreComplexSystem : public System { + private: + int random(int min, int max){ + // Seed with a real random value, if available + static std::random_device r; + + // Choose a random mean between min and max + static std::default_random_engine e1(r()); + + std::uniform_int_distribution uniform_dist(min, max); + + return uniform_dist(e1); + } + + public: + MoreComplexSystem() = default; + + void update(EntityManager &es, DeltaTime dt) { + es.each( + [dt](Entity e) { + auto comflab = e.component(); + if(comflab) { + std::vector vec; + for(size_t i = 0; i < comflab->dingy && i < 100; i++) + vec.push_back(i * comflab0>thingy); + int sum = std::accumulate(vec.begin(), vec.end(), 0); + int product = std::accumulate(vec.begin(), vec.end(), + 1, std::multiplies()); + comflab->stringy = std::to_string(comflab->dingy); + + auto pos = e.component(); + auto vel = e.component(); + if (pos && vel && comflab->dingy % 10000 == 0) { + if (pos->x > pos->y) { + vel->x = random(0, 5); + vel->y = random(0, 10); + } else { + vel->x = random(0, 10); + vel->y = random(0, 5); + } + } + } + } + ); + } + }; + #endif + + class Application { + public: + EntityManager em; + SystemManager sm; + + Application() : sm(em) { + sm.add(); + sm.add(); + #ifdef USE_MORECOMPLEX_SYSTEM + sm.add(); + #endif + } + + void update(DeltaTime dt) { + sm.update(dt); + sm.update(dt); + #ifdef USE_MORECOMPLEX_SYSTEM + sm.update(dt); + #endif + } + }; + + static constexpr double fakeDeltaTime = 1.0 / 60; +}; + +#endif // ENTITIESBENCHMARK_H_ -- cgit v1.2.3