-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGlobalData.cpp
executable file
·143 lines (127 loc) · 3.16 KB
/
GlobalData.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
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
#include <list>
using namespace std;
#include "stdafx.h"
#include "resource.h"
#include "ddutil.h"
#include "dxutil.h"
#include "dsutil.h"
#include "sprite.h"
#include "sounds.h"
#include "scene.h"
#include "Weapon.h"
#include "physicalobject.h"
#include "gameevents.h"
#include "GlobalData.h"
#include "DataFilePro.h"
#define GLOBAL_GRAPHIC_MUZZLEFLASH 800
extern CDisplay TheDisplay;
extern CSoundManager SoundManager;
Sprite** GlobalGraphics;
ASound** GlobalSounds;
int NumGlobalGraphics = 0;
int NumGlobalSounds = 0;
#define LINESPERSOUND 2
#define LINESPERSPRITE 8
bool InitGlobalData()
{
if(!InitGlobalSounds())
return false;
if(!InitGlobalSprites())
return false;
return true;
}
bool InitGlobalSprites()
{
int* stateframes = NULL;
char* temp;
int w;
int h;
int fw;
int fh;
int ns;
DataFilePro* DFP = DFPOpenDataFile("sprites.dat", DFP_FILE_READONLY);
if(!DFP)
return false;
int NumLines = DFP->GetNumLines(); //FIRST INTEGER IS NUMBER OF SPRITES HERE.
if(NumLines % LINESPERSPRITE){
DFPCloseDataFile(DFP);
return false;
}
NumGlobalGraphics = NumLines / LINESPERSPRITE;
GlobalGraphics = new Sprite*[NumGlobalGraphics];
for(int i = 0; i < NumGlobalGraphics; i++)
{
GlobalGraphics[i] = new Sprite;
(GlobalGraphics[i])->SetGlobalIndex(DFP->t_GetInteger()); //THE GLOBAL INDEX;
DFP->t_GetUnboundedString(&temp); //WE HAVE THE NAME.
w = DFP->t_GetInteger(); //WIDTH
h = DFP->t_GetInteger(); //HEIGHT
fw = DFP->t_GetInteger(); //FRAME WIDTH
fh = DFP->t_GetInteger(); //FRAME HEIGHT
ns = DFP->t_GetInteger(); //NUM STATES
stateframes = new int[ns];
DFP->ChangeDelimiter(',');
for(int k = 0; k < ns; k++)
{
stateframes[k] = DFP->t_GetInteger(); //FRAMES PER STATE
}
(GlobalGraphics[i])->Initialize(TheDisplay, temp, w, h, fw, fh, ns, stateframes);
DFP->ChangeDelimiter('\n');
DFP->t_GetChar(); //TO POLISH OFF LINE.
}
DFPCloseDataFile(DFP);
return true;
}
bool InitGlobalSounds()
{
int id;
char* temp;
DataFilePro* DFP = DFPOpenDataFile("sounds.dat", DFP_FILE_READONLY);
if(!DFP)
return false;
int NumLines = DFP->GetNumLines();
if(NumLines % LINESPERSOUND){
DFPCloseDataFile(DFP);
return false;
}
NumGlobalSounds = NumLines / LINESPERSOUND;
GlobalSounds = new ASound*[NumGlobalSounds];
for(int i = 0; i < NumGlobalSounds; i++)
{
id = DFP->t_GetInteger();
DFP->t_GetUnboundedString(&temp);
GlobalSounds[i] = new ASound(temp, 0, id);
delete [] temp;
}
DFPCloseDataFile(DFP);
return true;
}
void DestroyGlobalData()
{
for(int i = 0; i < NumGlobalGraphics; i++)
delete GlobalGraphics[i];
delete [] GlobalGraphics;
for(i = 0; i < NumGlobalSounds; i++)
delete GlobalSounds[i];
delete [] GlobalSounds;
}
ASound* GetGlobalSoundData(int Index)
{
for(int i = 0; i < NumGlobalSounds; i++)
{
if(GlobalSounds[i]->GetIndex() == Index){
return GlobalSounds[i];
}
}
return NULL;
}
Sprite* GetGlobalSpriteData(int Index)
{
for(int i = 0; i < NumGlobalGraphics; i++)
{
if(GlobalGraphics[i]->GetGlobalIndex() == Index){
return GlobalGraphics[i];
}
}
return NULL;
}