1 #include "3dc.h"
2 #include "module.h"
3 #include "platform.h"
4 #include "kshape.h"
5 #include "progress_bar.h"
6 #include "chnktexi.h"
7 #include "awtexld.h"
8 #include "ffstdio.h"
9 #include "inline.h"
10 #include "gamedef.h"
11 #include "psnd.h"
12 extern "C"
13 {
14 #include "language.h"
15 #include "avp_menus.h"
16 extern SCREENDESCRIPTORBLOCK ScreenDescriptorBlock;
17 extern int DebouncedGotAnyKey;
18
19 extern void MinimalNetCollectMessages(void);
20 extern void NetSendMessages(void);
21
22 extern void ThisFramesRenderingHasBegun(void);
23 extern void ThisFramesRenderingHasFinished(void);
24
25 extern int AAFontImageNumber;
26 extern int FadingGameInAfterLoading;
27
28 extern void InGameFlipBuffers();
29
30 extern void RenderStringCentred(char *stringPtr, int centreX, int y, int colour);
31
32 extern void BltImage(RECT *dest, DDSurface *image, RECT *src);
33 extern int CreateOGLTexture(D3DTexture *, unsigned char *);
34 extern int CreateIMGSurface(D3DTexture *, unsigned char *);
35 };
36
37 static const char* Loading_Bar_Empty_Image_Name="Menus\\Loadingbar_empty.rim";
38 static const char* Loading_Bar_Full_Image_Name="Menus\\Loadingbar_full.rim";
39
40 static DDSurface* LoadingBarEmpty;
41 static DDSurface* LoadingBarFull;
42 static RECT LoadingBarEmpty_DestRect;
43 static RECT LoadingBarEmpty_SrcRect;
44 static RECT LoadingBarFull_DestRect;
45 static RECT LoadingBarFull_SrcRect;
46
47 static int CurrentPosition=0;
48 static int LoadingInProgress=0;
49
Draw_Progress_Bar(void)50 static void Draw_Progress_Bar(void) {
51
52 ThisFramesRenderingHasBegun();
53
54 ColourFillBackBuffer(0);
55
56 if (LoadingInProgress != 0 && LoadingBarEmpty != NULL) {
57 BltImage(&LoadingBarEmpty_DestRect,LoadingBarEmpty,&LoadingBarEmpty_SrcRect);
58 }
59
60 if (LoadingBarFull != NULL) {
61 BltImage(&LoadingBarFull_DestRect,LoadingBarFull,&LoadingBarFull_SrcRect);
62 }
63
64 FlushD3DZBuffer();
65
66 RenderBriefingText(ScreenDescriptorBlock.SDB_Height/2, ONE_FIXED);
67
68 if (LoadingInProgress == 0) {
69 RenderStringCentred(GetTextString(TEXTSTRING_INGAME_PRESSANYKEYTOCONTINUE), ScreenDescriptorBlock.SDB_Width/2, (ScreenDescriptorBlock.SDB_Height*23)/24-9, 0xffffffff);
70 }
71
72 ThisFramesRenderingHasFinished();
73
74 InGameFlipBuffers();
75 }
76
Start_Progress_Bar()77 void Start_Progress_Bar()
78 {
79 LoadingBarEmpty = NULL;
80 LoadingBarFull = NULL;
81
82 AAFontImageNumber = CL_LoadImageOnce("Common\\aa_font.RIM",LIO_D3DTEXTURE|LIO_RELATIVEPATH|LIO_RESTORABLE);
83
84 /* load other graphics */
85 {
86 char buffer[100];
87 CL_GetImageFileName(buffer, 100,Loading_Bar_Empty_Image_Name, LIO_RELATIVEPATH);
88
89 //see if graphic can be found in fast file
90 size_t fastFileLength;
91 void const * pFastFileData = ffreadbuf(buffer,&fastFileLength);
92
93 if(pFastFileData)
94 {
95 //load from fast file
96 LoadingBarEmpty = AwCreateSurface
97 (
98 "pxf",
99 pFastFileData,
100 fastFileLength,
101 0
102 );
103 }
104 else
105 {
106 //load graphic from rim file
107 LoadingBarEmpty = AwCreateSurface
108 (
109 "sf",
110 buffer,
111 0
112 );
113 }
114 }
115 {
116 char buffer[100];
117 CL_GetImageFileName(buffer, 100,Loading_Bar_Full_Image_Name, LIO_RELATIVEPATH);
118
119 //see if graphic can be found in fast file
120 size_t fastFileLength;
121 void const * pFastFileData = ffreadbuf(buffer,&fastFileLength);
122
123 if(pFastFileData)
124 {
125 //load from fast file
126 LoadingBarFull = AwCreateSurface
127 (
128 "pxf",
129 pFastFileData,
130 fastFileLength,
131 0
132 );
133 }
134 else
135 {
136 //load graphic from rim file
137 LoadingBarFull = AwCreateSurface
138 (
139 "sf",
140 buffer,
141 0
142 );
143 }
144 }
145
146 CreateOGLTexture(LoadingBarEmpty, NULL);
147 CreateOGLTexture(LoadingBarFull, NULL);
148
149 //draw initial progress bar
150 LoadingBarEmpty_SrcRect.left=0;
151 LoadingBarEmpty_SrcRect.right=639;
152 LoadingBarEmpty_SrcRect.top=0;
153 LoadingBarEmpty_SrcRect.bottom=39;
154 LoadingBarEmpty_DestRect.left=0;
155 LoadingBarEmpty_DestRect.right=ScreenDescriptorBlock.SDB_Width-1;
156 LoadingBarEmpty_DestRect.top=(ScreenDescriptorBlock.SDB_Height *11)/12;
157 LoadingBarEmpty_DestRect.bottom=ScreenDescriptorBlock.SDB_Height-1;
158
159 LoadingBarFull_SrcRect.left=0;
160 LoadingBarFull_SrcRect.right=0;
161 LoadingBarFull_SrcRect.top=0;
162 LoadingBarFull_SrcRect.bottom=39;
163 LoadingBarFull_DestRect.left=0;
164 LoadingBarFull_DestRect.right=0;
165 LoadingBarFull_DestRect.top=(ScreenDescriptorBlock.SDB_Height *11)/12;
166 LoadingBarFull_DestRect.bottom=ScreenDescriptorBlock.SDB_Height-1;
167
168 CurrentPosition=0;
169 LoadingInProgress=1;
170
171 Draw_Progress_Bar();
172 }
173
Set_Progress_Bar_Position(int pos)174 void Set_Progress_Bar_Position(int pos)
175 {
176 int NewPosition = DIV_FIXED(pos,PBAR_LENGTH);
177 if(NewPosition>CurrentPosition)
178 {
179 CurrentPosition=NewPosition;
180 LoadingBarFull_SrcRect.left=0;
181 LoadingBarFull_SrcRect.right=MUL_FIXED(639,NewPosition);
182 LoadingBarFull_SrcRect.top=0;
183 LoadingBarFull_SrcRect.bottom=39;
184 LoadingBarFull_DestRect.left=0;
185 LoadingBarFull_DestRect.right=MUL_FIXED(ScreenDescriptorBlock.SDB_Width-1,NewPosition);
186 LoadingBarFull_DestRect.top=(ScreenDescriptorBlock.SDB_Height *11)/12;
187 LoadingBarFull_DestRect.bottom=ScreenDescriptorBlock.SDB_Height-1;
188
189 Draw_Progress_Bar();
190
191 /*
192 If this is a network game , then check the received network messages from
193 time to time (~every second).
194 Has nothing to do with the progress bar , but this is a convenient place to
195 do the check.
196 */
197
198 if(AvP.Network != I_No_Network)
199 {
200 static int LastSendTime;
201 int time=GetTickCount();
202 if(time-LastSendTime>1000 || time<LastSendTime)
203 {
204 //time to check our messages
205 LastSendTime=time;
206
207 MinimalNetCollectMessages();
208 //send messages , mainly needed so that the host will send the game description
209 //allowing people to join while the host is loading
210 NetSendMessages();
211 }
212 }
213
214 }
215 }
216
217 extern "C"
218 {
219
Game_Has_Loaded(void)220 void Game_Has_Loaded(void)
221 {
222 extern int NormalFrameTime;
223
224 SoundSys_StopAll();
225 SoundSys_Management();
226
227 LoadingInProgress = 0;
228
229 int f = 65536;
230 ResetFrameCounter();
231 #warning Game_Has_Loaded commented out a blocking loop
232 //do
233 {
234 CheckForWindowsMessages();
235 ReadUserInput();
236
237 ColourFillBackBufferQuad
238 (
239 0,
240 0,
241 (ScreenDescriptorBlock.SDB_Height*11)/12,
242 ScreenDescriptorBlock.SDB_Width-1,
243 ScreenDescriptorBlock.SDB_Height-1
244 );
245
246 if (f)
247 {
248 LoadingBarFull_SrcRect.left=0;
249 LoadingBarFull_SrcRect.right=639;
250 LoadingBarFull_SrcRect.top=0;
251 LoadingBarFull_SrcRect.bottom=39;
252 LoadingBarFull_DestRect.left=MUL_FIXED(ScreenDescriptorBlock.SDB_Width-1,(ONE_FIXED-f)/2);
253 LoadingBarFull_DestRect.right=MUL_FIXED(ScreenDescriptorBlock.SDB_Width-1,f)+LoadingBarFull_DestRect.left;
254
255 int h = MUL_FIXED((ScreenDescriptorBlock.SDB_Height)/24,ONE_FIXED-f);
256 LoadingBarFull_DestRect.top=(ScreenDescriptorBlock.SDB_Height *11)/12+h;
257 LoadingBarFull_DestRect.bottom=ScreenDescriptorBlock.SDB_Height-1-h;
258
259 f-=NormalFrameTime;
260 if (f<0) f=0;
261 } else {
262 LoadingBarFull_SrcRect.left=0;
263 LoadingBarFull_SrcRect.right=0;
264 LoadingBarFull_SrcRect.top=0;
265 LoadingBarFull_SrcRect.bottom=0;
266 LoadingBarFull_DestRect.left=0;
267 LoadingBarFull_DestRect.right=0;
268 LoadingBarFull_DestRect.top=0;
269 LoadingBarFull_DestRect.bottom=0;
270 }
271
272 Draw_Progress_Bar();
273
274 FrameCounterHandler();
275
276 /* If in a network game then we may as well check the network messages while waiting*/
277 if(AvP.Network != I_No_Network)
278 {
279 MinimalNetCollectMessages();
280
281 //send messages , mainly needed so that the host will send the game description
282 //allowing people to join while the host is loading
283 NetSendMessages();
284
285 }
286
287 }
288 // while(!DebouncedGotAnyKey);
289
290 FadingGameInAfterLoading=ONE_FIXED;
291
292 if (LoadingBarFull != NULL) {
293 ReleaseDDSurface(LoadingBarFull);
294 LoadingBarFull = NULL;
295 }
296
297 if (LoadingBarEmpty != NULL) {
298 ReleaseDDSurface(LoadingBarEmpty);
299 LoadingBarEmpty = NULL;
300 }
301 }
302
303 };
304