-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCObjectCheckpointController.h
82 lines (62 loc) · 1.62 KB
/
CObjectCheckpointController.h
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef COBJECT_CHECKPOINT_CONTROLLER_H_INCL
#define COBJECT_CHECKPOINT_CONTROLLER_H_INCL
#include "CObject.h"
#include <vector>
// a checkpoint is a sphere
struct SCheckpoint
{
SCheckpoint() :
Radius(1)
{
}
SCheckpoint(const vec3& position, float radius) :
Position(position), Radius(radius)
{
}
vec3 Position;
float Radius;
};
// checkpoint tracker tracks current position for one object
struct SCheckpointTracker
{
SCheckpointTracker(CObject* object = 0, const std::string& name = "Default")
{
Object = object;
LapNum = 1;
CurrentCheckpoint = 0;
Name = name;
}
CObject* Object;
std::string Name;
uint LapNum;
uint CurrentCheckpoint;
};
struct SCheckpointTrackerComparator
{
bool operator() (const SCheckpointTracker& a, const SCheckpointTracker& b)
{
return a.LapNum > b.LapNum || (a.LapNum == b.LapNum && a.CurrentCheckpoint > b.CurrentCheckpoint);
}
};
// tracks checkpoints and progress for all objects
class CObjectCheckpointController : public CObject
{
public:
CObjectCheckpointController() : CObject(0, vec3(), vec3()) {}
virtual ~CObjectCheckpointController() {}
void addCheckpoint(const SCheckpoint& cp);
void addObjectTracker(CObject* object, const std::string& name = "Default");
uint getLapNum(CObject* object);
uint getCurrentCheckpoint(CObject* object);
SCheckpointTracker* getTracker(uint i);
SCheckpointTracker* getTracker(CObject* object);
SCheckpoint* getCheckpoint(uint i);
uint getNumberOfCheckpoints();
uint getNumberOfTrackers();
void sort();
virtual void animate(float dt);
private:
std::vector<SCheckpoint> Checkpoints;
std::vector<SCheckpointTracker> Trackers;
};
#endif