-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFastSchedule.h
153 lines (139 loc) · 2.58 KB
/
FastSchedule.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#pragma once
#include <windows.h>
#include <new>
#include <vector>
namespace AwpSoftGameModule
{
template <class T> class FastSchedule
{
protected:
std::vector<T*> ScheduleList;
int Length, Pos, Occupied, Save;
public:
FastSchedule(int len);
~FastSchedule();
std::vector<T*>& getScheduleListReference();
int getLength();
bool full();
T* gotoNextPos();
int gotoNextNullPos();
T* getCurrentObject();
void clearAll();
void saveCurrentPos();
void loadSavedPos();
void clearCurrentObject();
int takeOverObject(T* ptr);
T* takeOutCurrentObject();
};
template<class T>
inline FastSchedule<T>::FastSchedule(int len)
{
if (len < 0x10) len = 0x10;
Length = len;
Pos = Length - 1;
Occupied = 0;
Save = 0;
ScheduleList = std::move(std::vector<T*>(len, nullptr));
}
template<class T>
inline FastSchedule<T>::~FastSchedule()
{
if (!ScheduleList.empty()) clearAll();
}
template<class T>
std::vector<T*>& FastSchedule<T>::getScheduleListReference()
{
return ScheduleList;
}
template<class T>
inline int FastSchedule<T>::getLength()
{
return Length;
}
template<class T>
inline bool FastSchedule<T>::full()
{
return Occupied == Length;
}
template<class T>
inline T * FastSchedule<T>::gotoNextPos()
{
if (Pos + 1 >= Length)
{
Pos = 0;
}
else
{
Pos++;
}
return ScheduleList[Pos];
}
template<class T>
inline int FastSchedule<T>::gotoNextNullPos()
{
if (Length - Occupied == 0) return -1;
for (int i = 1; i <= Length; i++)
{
gotoNextPos();
if (ScheduleList[Pos] == nullptr) return Pos;
}
return -1;
}
template<class T>
inline T * FastSchedule<T>::getCurrentObject()
{
return ScheduleList[Pos];
}
template<class T>
inline void FastSchedule<T>::clearCurrentObject()
{
if (ScheduleList[Pos])
{
delete ScheduleList[Pos];
ScheduleList[Pos] = nullptr;
Occupied--;
}
}
template<class T>
inline void FastSchedule<T>::clearAll()
{
for (T*& r : ScheduleList)
{
if (r) delete r;
r = nullptr;
}
Occupied = 0;
}
template<class T>
inline int FastSchedule<T>::takeOverObject(T* ptr)
{
if (full())
{
if (ptr) delete ptr;
return -1;
}
if (!ptr) return Pos;
Occupied++;
ScheduleList[Pos] = ptr;
gotoNextNullPos();
return Pos;
}
template<class T>
inline T* FastSchedule<T>::takeOutCurrentObject()
{
T* temp = ScheduleList[Pos];
ScheduleList[Pos] = nullptr;
if(temp) Occupied--;
return temp;
}
template<class T>
inline void FastSchedule<T>::saveCurrentPos()
{
Save = Pos;
}
template<class T>
inline void FastSchedule<T>::loadSavedPos()
{
Pos = Save;
}
};