-
Notifications
You must be signed in to change notification settings - Fork 0
/
EfectModel.cpp
53 lines (44 loc) · 1.22 KB
/
EfectModel.cpp
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "EfectModel.h"
EfectModel::EfectModel(const string& _path, sf::Sprite *_connectedTo,
bool _updateRotation, bool _updatePosition, bool _update,
float _reloadDelay)
: path(_path), EfectUpdateModel( nullptr, _connectedTo, _updatePosition, _updateRotation),
timerReload(_reloadDelay), update(_update), stream(nullptr)
{
}
EfectModel::EfectModel(istream& file, sf::Sprite *_connectedTo,
bool _updateRotation, bool _updatePosition, bool _update,
float _reloadDelay)
: stream(&file), EfectUpdateModel(nullptr, _connectedTo, _updatePosition, _updateRotation),
timerReload(_reloadDelay), update(_update)
{
}
void EfectModel::onInit()
{
Efect::onInit();
EfectUpdateModel::model = &model;
reloadModel();
}
void EfectModel::onDisplay(Camera& cam)
{
Efect::onDisplay(cam);
model.draw(cam, connectedTo == nullptr ? sf::Sprite() : *connectedTo );
}
void EfectModel::onUpdate(float dt)
{
if (update)
EfectUpdateModel::onUpdate(dt);
else
Efect::onUpdate(dt);
if (timerReload.time_wait > 0 && timerReload.isReady())
reloadModel();
}
void EfectModel::reloadModel()
{
if (stream != nullptr)
{
model.deserialize(*stream);
}
else if (path != "")
model.deserialize(path);
}