summaryrefslogtreecommitdiffstats
path: root/src/core/templates.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/templates.h')
-rw-r--r--src/core/templates.h19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/core/templates.h b/src/core/templates.h
index 3a5b314f..19881219 100644
--- a/src/core/templates.h
+++ b/src/core/templates.h
@@ -44,17 +44,16 @@ class CPool
int32 m_allocPtr;
public:
- CPool(int32 size){
+ CPool(int32 size, const char *name){
m_entries = (U*)new uint8[sizeof(U)*size];
m_flags = (Flags*)new uint8[sizeof(Flags)*size];
m_size = size;
- m_allocPtr = 0;
+ m_allocPtr = -1;
for(int i = 0; i < size; i++){
m_flags[i].id = 0;
m_flags[i].free = 1;
}
}
-
~CPool() {
Flush();
}
@@ -122,21 +121,22 @@ public:
return m_flags[handle>>8].u == (handle & 0xFF) ?
(T*)&m_entries[handle >> 8] : nil;
}
- int32 GetIndex(T *entry){
+ int32 GetIndex(T* entry) {
int i = GetJustIndex_NoFreeAssert(entry);
- return m_flags[i].u + (i<<8);
+ return m_flags[i].u + (i << 8);
}
- int32 GetJustIndex(T *entry){
+ int32 GetJustIndex(T* entry) {
int index = GetJustIndex_NoFreeAssert(entry);
+ assert((U*)entry == (U*)&m_entries[index]); // cast is unsafe - check required
assert(!IsFreeSlot(index));
return index;
}
- int32 GetJustIndex_NoFreeAssert(T* entry){
+ int32 GetJustIndex_NoFreeAssert(T* entry) {
int index = ((U*)entry - m_entries);
- assert((U*)entry == (U*)&m_entries[index]); // cast is unsafe - check required
+ // Please don't add unsafe assert here, because at least one func. use this to check if entity is ped or vehicle.
return index;
}
- int32 GetNoOfUsedSpaces(void) const{
+ int32 GetNoOfUsedSpaces(void) const {
int i;
int n = 0;
for(i = 0; i < m_size; i++)
@@ -167,6 +167,7 @@ public:
memcpy(entries, m_entries, sizeof(U)*m_size);
debug("Stored:%d (/%d)\n", GetNoOfUsedSpaces(), m_size); /* Assumed inlining */
}
+ int32 GetNoOfFreeSpaces() const { return GetSize() - GetNoOfUsedSpaces(); }
};
template<typename T>