This repository has been archived by the owner on Jan 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
precache.cpp
105 lines (99 loc) · 2.81 KB
/
precache.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
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
#include "precache.h"
#include "engine.h"
#include "utils.h"
#include <iostream> // std::cout
#include <algorithm> // std::count
std::vector<_PrecacheInfo> precacheinf;
typedef struct {
char *name;
int type;
} PrecacheSpecs;
PrecacheSpecs precachinginfo[] = {
{"sound", TYPE_SND},
{"model", TYPE_MDL},
{"generic", TYPE_GENERIC},
{"event", TYPE_EVENT}
};
int Precache::IsItemOnPrecacheTable(const char* actualprecache) {
std::vector<_PrecacheInfo>::iterator it = precacheinf.begin();
_PrecacheInfo precache;
int i = 0;
while(it != precacheinf.end()) {
precache = *(it++);
if(strcmp(precache.precachename, actualprecache) == 0) {
return 1;
}
}
return 0;
}
int Precache::GetPrecacheID(const char* actualprecache) {
std::vector<_PrecacheInfo>::iterator it = precacheinf.begin();
_PrecacheInfo precache;
int i = 0;
while(it != precacheinf.end()) {
precache = *(it++);
if(strcmpi(precache.precachename, actualprecache) == 0) {
return i;
}
i++;
}
return 0;
}
void Precache::AddPrecacheToTable(int type, const char* actualprecache) {
_PrecacheInfo precache;
memset(&precache, 0, sizeof(PrecacheInfo));
if(!IsItemOnPrecacheTable(actualprecache)) {
Utils *utils = new Utils();
precache.precachetype = type;
sprintf(precache.precachename, "%s", actualprecache);
precacheinf.push_back(precache);
delete utils;
}
}
void Precache::RemoveAllPrecacheFromTable( void ) { //There's actually no point in this since you can't load them when the map is running..
for (int i=0; i<TotalPrecached(); i++) {
RemovePrecacheFromTable(i);
}
}
void Precache::PreloadCached( bool remove ) {
engineModule *engine = new engineModule;
if(remove) RemoveAllPrecacheFromTable(); //Remove everything first
for (std::vector<_PrecacheInfo>::iterator it = precacheinf.begin(); it != precacheinf.end(); it++) {
if(IsItemOnPrecacheTable(it->precachename)) {
engine->Precache(it->precachetype, it->precachename);
}
}
delete engine;
}
int Precache::TotalPrecached() {
engineModule *engine = new engineModule;
int i = 0;
for (std::vector<_PrecacheInfo>::iterator it = precacheinf.begin(); it != precacheinf.end(); it++) {
if(IsItemOnPrecacheTable(it->precachename)) {
i++;
}
}
return i;
delete engine;
}
void Precache::RemovePrecacheFromTable( int precacheid ) {
int i = 0;
engineModule *engine = new engineModule;
for (std::vector<_PrecacheInfo>::iterator it = precacheinf.begin(); it != precacheinf.end(); it++) {
if(i == precacheid) {
printf("Precache::RemovePrecacheFromTable: Removed %s (%d) from table!\n", it->precachename, i);
precacheinf.erase(it);
break;
}
i++;
}
delete engine;
}
int find_precachetype(const char *name) {
for(int i=0;i<sizeof(precachinginfo)/sizeof(PrecacheSpecs);i++) {
if(strcmpi(name,precachinginfo[i].name) == 0) {
return precachinginfo[i].type;
}
}
return NULL;
}