Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
data locality - fast example
//https://www.youtube.com/watch?v=TJHgp1ugKGM //g++ 5.4.0 #include <iostream> #include <vector> class AIComponent { public: void update() { /* Work with and modify state... */ } private: // Goals, mood, etc. ... }; class PhysicsComponent { public: void update() { /* Work with and modify state... */ } private: // Rigid body, velocity, mass, etc. ... }; class RenderComponent { public: void render() { /* Work with and modify state... */ } private: // Mesh, textures, shaders, etc. ... }; class GameEntity { public: GameEntity(AIComponent* ai, PhysicsComponent* physics, RenderComponent* render) : ai_(ai), physics_(physics), render_(render) {} AIComponent* ai() { return ai_; } PhysicsComponent* physics() { return physics_; } RenderComponent* render() { return render_; } private: AIComponent* ai_; PhysicsComponent* physics_; RenderComponent* render_; }; int main() { std::vector<AIComponent> ais; std::vector<PhysicsComponent> ps; std::vector<RenderComponent> rs; int total = 10000000; for(int i=0; i<total; i++) { AIComponent ai; ais.push_back(ai); PhysicsComponent pc; ps.push_back(pc); RenderComponent rc; rs.push_back(rc); } for(auto& e: ais) { e.update(); } for(auto& e: ps) { e.update(); } for(auto& e: rs) { e.render(); } }
run
|
edit
|
history
|
help
0
Zadanie Kolokwium_2011_z4
Finding the first digit of a number
Wuninitialized
BOOST_ENABLE_ASSERT_HANDLER defined
thread
bitmap with pairs
MyStringv2
2015(M2)Mod.
Fungsi
Tree