-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphysics_manager.cpp
More file actions
33 lines (32 loc) · 934 Bytes
/
Copy pathphysics_manager.cpp
File metadata and controls
33 lines (32 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "physics_manager.h"
#include "globals.h"
#include <QDebug>
PhysicsManager::PhysicsManager() : QObject(nullptr) {
delta = 1.0 / Consts::FPS;
timer = QObject::startTimer(1000 / Consts::FPS);
}
void PhysicsManager::addObject(PhysicsObject *object) {
//qDebug() << "add" << object;
objects.push_back(object);
}
void PhysicsManager::removeObject(PhysicsObject *object) {
int ind = objects.lastIndexOf(object);
if (ind == -1) {
qDebug("ERR: 不能删除不存在的 PhysicsObject!");
assert(ind != -1);
}
objects.erase(objects.begin() + ind);
}
void PhysicsManager::timerEvent(QTimerEvent *event) {
//qDebug() << "process~";
for (int i = 0; i < objects.length(); i++) {
PhysicsObject *object = objects[i];
if (object->isProcessEnabled()) {
object->process(delta);
//qDebug() << "调用人物 process";
}
}
}
PhysicsManager::~PhysicsManager() {
QObject::killTimer(timer);
}