MCPcopy Create free account
hub / github.com/Open-GD/OpenGD / update

Method update

Source/MoveAction.cpp:59–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57}
58
59void MoveAction::update(float time)
60{
61#if AX_ENABLE_STACKABLE_ACTIONS
62 size_t i = 0;
63 auto bgl = BaseGameLayer::getInstance();
64 auto sectionObjects = &bgl->_sectionObjects;
65 int sectionSize = sectionObjects->size();
66 ax::Vec2 currentPos, diff, newPos;
67 float posx, posy;
68 ax::Vec2 cool;
69 for (auto obj : _group->_objects)
70 {
71 obj->getPosition(&posx, &posy);
72 currentPos = {posx, posy};
73 if (i == 0)
74 {
75 diff = currentPos - _prevPositions[i];
76 _startPositions[i] = _startPositions[i] + diff;
77 newPos = _startPositions[i] + (_posDelta * time);
78 obj->setPosition(newPos);
79 _prevPositions[i] = newPos;
80 cool = newPos - currentPos;
81 }
82 else
83 {
84 newPos = currentPos + cool;
85 obj->setPosition(newPos);
86 }
87 auto section = BaseGameLayer::sectionForPos(newPos.x);
88 section = section - 1 < 0 ? 0 : section - 1;
89 if (obj->_section != section)
90 {
91 auto vec = &(*sectionObjects)[obj->_section];
92 auto newEnd = std::partition(vec->begin(), vec->end(), [&](GameObject* a) { return a != obj; });
93 vec->resize(newEnd - vec->begin());
94 while (section >= sectionSize)
95 {
96 std::vector<GameObject*> vec;
97 bgl->_sectionObjects.push_back(vec);
98 sectionSize++;
99 }
100 (*sectionObjects)[section].push_back(obj);
101 obj->_section = section;
102 }
103 ++i;
104 }
105#else
106 for (auto obj : _group->_objects)
107 _obj->setPosition3D(_startPosition + _positionDelta * t);
108#endif // AX_ENABLE_STACKABLE_ACTIONS
109}
110
111void MoveAction::stop()
112{

Callers

nothing calls this directly

Calls 4

sizeMethod · 0.80
setPositionMethod · 0.80
beginMethod · 0.80
endMethod · 0.80

Tested by

no test coverage detected