MCPcopy Create free account
hub / github.com/RavEngine/RavEngine / tick

Method tick

src/World.cpp:22–95  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20const float RavEngine::World::evalNormal = 60;
21
22void RavEngine::World::tick() {
23
24 //setup framerate scaling for next frame
25 auto now = clocktype::now();
26 deltaTimeMicroseconds = duration_cast<timeDiff>((now-lastFrameTime));
27
28 float deltaSeconds = deltaTimeMicroseconds.count() / 1000.0 / 1000;
29 float scale = deltaSeconds * evalNormal;
30 pretick(scale);
31
32 //spawn entities that are pending spawn
33 for (auto& e : PendingSpawn){
34 Entities.insert(e);
35 e->SetWorld(this);
36
37 //start all scripts
38 e->Start();
39 auto coms = e->Components().GetAllComponentsOfSubclass<ScriptComponent>();
40 for (auto& c : coms) {
41 c->Start();
42 }
43
44 //make the render engine and the physics system aware of this entity
45 Solver->Spawn(e);
46 Renderer->Spawn(e);
47
48 //for each type of component (pair of type : list), make it available to the World
49 allcomponents.AddComponentsFrom(e->Components());
50 }
51 PendingSpawn.clear();
52
53 //Tick the game code
54 tick(scale);
55
56 //process component add and removal on spawned entities
57 while (!component_addremove.empty()) {
58 auto& op = component_addremove.front();
59 if (op.add) {
60 allcomponents.AddComponentsFrom(op.store);
61 }
62 else {
63 allcomponents.RemoveComponentsInOtherFromThis(op.store);
64 }
65 component_addremove.pop();
66 }
67
68 //destroy objects that are pending removal
69 for( auto& e : PendingDestruction){
70 //stop all scripts
71 auto coms = e->Components().GetAllComponentsOfSubclass<ScriptComponent>();
72 for (auto& c : coms) {
73 c->Stop();
74 }
75 e->Stop();
76
77 e->SetWorld(nullptr);
78 //also remove its components
79 allcomponents.RemoveComponentsInOtherFromThis(e->Components());

Callers 1

runMethod · 0.45

Calls 15

ceilFunction · 0.85
SetWorldMethod · 0.80
AddComponentsFromMethod · 0.80
getOwnerMethod · 0.80
enqueueMethod · 0.80
countMethod · 0.45
insertMethod · 0.45
StartMethod · 0.45
SpawnMethod · 0.45
clearMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected