comparison Engine/MMT.cpp @ 2499:68cdef6879a0

engine folder
author Ritor1
date Fri, 19 Sep 2014 02:57:42 +0600
parents
children a77c34acdbc9
comparison
equal deleted inserted replaced
2498:92eeeb5200f2 2499:68cdef6879a0
1 #define _CRTDBG_MAP_ALLOC
2 #include <stdlib.h>
3 #include <crtdbg.h>
4
5 #define _CRT_SECURE_NO_WARNINGS
6
7 #include "MMT.h"
8 #include "GUIWindow.h"
9
10 #include "mm7_data.h"
11 #include "AudioPlayer.h"
12 #include "Mouse.h"
13 #include "LOD.h"
14 #include "Engine/Graphics/Render.h"
15 #include "GUIFont.h"
16 #include "lib/libpng/png.h"
17 #include "Engine/ErrorHandling.h"
18 #include "Bink_Smacker.h"
19 #include "Game.h"
20 #include "Log.h"
21
22
23 void ShowLogoVideo()
24 {
25 RGBTexture tex; // [sp+Ch] [bp-30h]@1
26 unsigned int uTrackStartMS; // [sp+34h] [bp-8h]@8
27 unsigned int uTrackEndMS; // [sp+38h] [bp-4h]@8
28
29 pMediaPlayer->bStopBeforeSchedule = false;
30
31 // pMediaPlayer->pResetflag = 0;
32 bGameoverLoop = 1;
33 if (!bNoVideo)
34 {
35 pRenderer->PresentBlackScreen();
36 pMediaPlayer->PlayFullscreenMovie(MOVIE_3DOLogo, true);
37 if ( !pMediaPlayer->bStopBeforeSchedule )
38 {
39 pMediaPlayer->PlayFullscreenMovie(MOVIE_NWCLogo, true);
40 if ( !pMediaPlayer->bStopBeforeSchedule )
41 {
42
43 if (for_refactoring)
44 {
45 MessageBoxA(nullptr, "Ritor1: MOVIE_JVC crash", "", 0);
46 __debugbreak();
47 }
48
49 //pMediaPlayer->PlayFullscreenMovie(MOVIE_JVC, true);
50 //if ( !pMediaPlayer->bStopBeforeSchedule )
51 if (!use_MMT)
52 pMediaPlayer->PlayFullscreenMovie(MOVIE_Intro, true);
53 }
54 }
55 }
56 char pContainerName[64];
57
58 if (use_MMT)
59 {
60 sprintf(pContainerName, "data\\New_Icons/%s", "MMTTITLE.pcx");
61 tex.LoadPCXFile(pContainerName, 0);
62 }
63 else
64 tex.Load("mm6title.pcx", 2);
65
66 pRenderer->BeginScene();
67 pRenderer->DrawTextureRGB(0, 0, &tex);
68 free(tex.pPixels);
69 tex.pPixels = 0;
70 MainMenuUI_LoadFontsAndSomeStuff();
71
72 if (use_MMT)
73 DrawMMTCopyrightWindow();//Text message in ÌÌÒ menu
74 else
75 DrawMM7CopyrightWindow();
76
77 pRenderer->EndScene();
78 pRenderer->Present();
79
80 #ifndef _DEBUG
81 Sleep(1500); // let the copyright window stay for a while
82 #endif
83 if (!use_MMT)
84 {
85 if (!bNoSound && pAudioPlayer->hAILRedbook )
86 {
87 pAudioPlayer->SetMusicVolume((signed __int64)(pSoundVolumeLevels[uMusicVolimeMultiplier] * 64.0));
88 AIL_redbook_stop(pAudioPlayer->hAILRedbook);
89 AIL_redbook_track_info(pAudioPlayer->hAILRedbook, 14, &uTrackStartMS, &uTrackEndMS);
90 AIL_redbook_play(pAudioPlayer->hAILRedbook, uTrackStartMS + 1, uTrackEndMS);
91 }
92 }
93 bGameoverLoop = 0;
94 }
95
96 void abort_(const char * s, ...)
97 {
98 va_list args;
99 va_start(args, s);
100 vfprintf(stderr, s, args);
101 fprintf(stderr, "\n");
102 va_end(args);
103 abort();
104 }
105
106 Texture *LoadPNG(const char *name)
107 {
108 int x, y;
109 int width, height;
110 png_byte color_type;
111 png_byte bit_depth;
112 png_structp png_ptr;
113 png_infop info_ptr;
114 int number_of_passes;
115 png_bytep * row_pointers;
116 uint i = 0;
117 Texture *tex;
118
119 char header[8]; // 8 is the maximum size that can be checked
120
121 /* open file and test for it being a png */
122 FILE *fp = fopen(name, "rb");
123 if (!fp)
124 abort_("[read_png_file] File %s could not be opened for reading", name);
125 fread(header, 1, 8, fp);
126 if (png_sig_cmp((png_bytep)header, 0, 8))
127 abort_("[read_png_file] File %s is not recognized as a PNG file", name);
128 /* initialize stuff */
129 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
130
131 if (!png_ptr)
132 abort_("[read_png_file] png_create_read_struct failed");
133 info_ptr = png_create_info_struct(png_ptr);
134 if (!info_ptr)
135 abort_("[read_png_file] png_create_info_struct failed");
136
137 if (setjmp(png_jmpbuf(png_ptr)))
138 abort_("[read_png_file] Error during init_io");
139
140 png_init_io(png_ptr, fp);
141 png_set_sig_bytes(png_ptr, 8);
142
143 png_read_info(png_ptr, info_ptr);
144
145 width = png_get_image_width(png_ptr, info_ptr);
146 height = png_get_image_height(png_ptr, info_ptr);
147 color_type = png_get_color_type(png_ptr, info_ptr);
148 bit_depth = png_get_bit_depth(png_ptr, info_ptr);
149
150 number_of_passes = png_set_interlace_handling(png_ptr);
151 png_read_update_info(png_ptr, info_ptr);
152
153 /* read file */
154 if (setjmp(png_jmpbuf(png_ptr)))
155 abort_("[read_png_file] Error during read_image");
156 row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * height);
157 for (y=0; y<height; y++)
158 row_pointers[y] = (png_byte*) malloc(png_get_rowbytes(png_ptr,info_ptr));
159
160 png_read_image(png_ptr, row_pointers);
161
162 fclose(fp);
163
164 tex = new Texture;
165 tex->uTextureHeight = height;
166 tex->uTextureWidth = width;
167 tex->uSizeOfMaxLevelOfDetail = png_get_rowbytes(png_ptr, info_ptr);
168 tex->uTextureSize = png_get_rowbytes(png_ptr, info_ptr);
169 tex->uDecompressedSize = png_get_rowbytes(png_ptr, info_ptr);
170 tex->pPalette16 = (unsigned __int16 *) malloc(sizeof(unsigned __int16) * width * height);
171 tex->pLevelOfDetail0_prolly_alpha_mask = (unsigned __int8 *) malloc(sizeof(unsigned __int8) * width * height);
172
173 for (y=0; y<height; y++)
174 {
175 png_byte* row = row_pointers[y];
176 for (x=0; x<width; x++)
177 {
178 png_byte* ptr = &(row[x*4]);
179 //Log::Warning(L"Pixel at position [ %d - %d ] has RGBA values: %d - %d - %d - %d\n",
180 // x, y, ptr[0], ptr[1], ptr[2], ptr[3]);
181 png_byte tmp = ptr[2];
182 ptr[2] = ptr[0];
183 ptr[0] = ptr[3];
184 //ptr[3] = 255 - ptr[3]; // alpha mask gradient
185 ptr[3] = 255 - tmp;
186 tex->pPalette16[i] = Color16(ptr[0], ptr[1], ptr[2]);
187 tex->pLevelOfDetail0_prolly_alpha_mask[i] = ptr[3];
188 i++;
189 }
190 }
191 //Ritor1: temporarily stopped, needed change RGBTexture structure
192 /*for (int i = 0; i < width * height; ++i)
193 tex->pPalette16[i] = 0x7FF;
194 memset(tex->pLevelOfDetail0_prolly_alpha_mask, 1, sizeof(unsigned __int8) * width * height);*/
195 return tex;
196 }
197
198 void MMT_MainMenu_Loop()
199 {
200 GUIButton *pButton; // eax@27
201 unsigned int pControlParam; // ecx@35
202 unsigned int pX;
203 unsigned int pY; // [sp-18h] [bp-54h]@39
204 Texture *pTexture; // [sp-14h] [bp-50h]@39
205 char pContainerName[64];
206 MSG msg;
207
208 pCurrentScreen = SCREEN_GAME;
209
210 pGUIWindow2 = 0;
211 pAudioPlayer->StopChannels(-1, -1);
212
213 //if (!bNoSound )
214 //PlayAudio(L"Sounds\\New_Sounds/Stronghold_Theme.mp3");
215 //if (!bNoVideo )
216 //pVideoPlayer->PlayMovie(L"Anims\\New_Video/3DOLOGO.smk");
217
218 pMouse->RemoveHoldingItem();
219
220 pIcons_LOD->_inlined_sub2();
221
222 //Create new window
223 //WINDOW_MainMenu included in GUIWindow.h
224 pWindow_MMT_MainMenu = GUIWindow::Create(0, 0, window->GetWidth(), window->GetHeight(), WINDOW_MainMenu, 0, 0);
225
226 //load buttons
227 //Texture* MMT_MM6 = pIcons_LOD->LoadTexturePtr("title_new", TEXTURE_16BIT_PALETTE);
228
229 sprintf(pContainerName, "data\\New_Icons/%s", "mm6_button_oval.png");
230 Texture* MMT_MM6 = LoadPNG(pContainerName);
231
232 Texture* MMT_MM7 = pIcons_LOD->LoadTexturePtr("title_load", TEXTURE_16BIT_PALETTE);
233 Texture* MMT_MM8 = pIcons_LOD->LoadTexturePtr("title_cred", TEXTURE_16BIT_PALETTE);
234 Texture* MMT_Continue = pIcons_LOD->LoadTexturePtr("title_exit", TEXTURE_16BIT_PALETTE);
235 Texture* MMT_Exit = pIcons_LOD->LoadTexturePtr("title_exit", TEXTURE_16BIT_PALETTE);
236
237 pMMT_MainMenu_BtnMM6 = pWindow_MMT_MainMenu->CreateButton(0, 0, MMT_MM6->uTextureWidth, MMT_MM6->uTextureHeight, 1, 0, UIMSG_MMT_MainMenu_MM6, 0, 0, "", MMT_MM6, 0);
238 pMMT_MainMenu_BtnMM7 = pWindow_MMT_MainMenu->CreateButton(window->GetWidth() - (window->GetWidth() / 4), window->GetHeight() / 4, MMT_MM7->uTextureWidth, MMT_MM7->uTextureHeight, 1, 0, UIMSG_MMT_MainMenu_MM7, 1, 0, "", MMT_MM7, 0);
239 pMMT_MainMenu_BtnMM8 = pWindow_MMT_MainMenu->CreateButton(window->GetWidth() - (window->GetWidth() / 4), window->GetHeight() - ((window->GetHeight() / 4) + 50), MMT_MM8->uTextureWidth, MMT_MM8->uTextureHeight, 1, 0, UIMSG_MMT_MainMenu_MM8, 2, 0, "", MMT_MM8, 0);
240 pMMT_MainMenu_BtnContinue = pWindow_MMT_MainMenu->CreateButton((window->GetWidth() / 4) - 100, window->GetHeight() - ((window->GetHeight() / 4) + 50), MMT_Continue->uTextureWidth, MMT_Continue->uTextureHeight, 1, 0, UIMSG_MMT_MainMenu_Continue, 3, 0, "", MMT_Continue, 0);
241 pMMT_MainMenu_BtnExit = pWindow_MMT_MainMenu->CreateButton(window->GetWidth() - 130, window->GetHeight() - 35, MMT_Exit->uTextureWidth, MMT_Exit->uTextureHeight, 1, 0, UIMSG_ExitToWindows, 4, 0, "", MMT_Exit, 0);
242
243 pTexture_PCX.Release();
244
245 sprintf(pContainerName, "data\\New_Icons/%s", "MMTTITLE.pcx");
246 if (pTexture_PCX.LoadPCXFile(pContainerName, 0) == 1)
247 Error("File not found: %s", pContainerName);
248
249 SetCurrentMenuID(MENU_MMT_MAIN_MENU);//included in enum MENU_STATE in GUIWindows.h
250 SetForegroundWindow(window->GetApiHandle());
251 SendMessageW(window->GetApiHandle(), WM_ACTIVATEAPP, 1, 0);
252 while (GetCurrentMenuID() == MENU_MMT_MAIN_MENU )
253 {
254 POINT cursor;
255 pMouse->GetCursorPos(&cursor);
256
257 while (PeekMessageW(&msg, 0, 0, 0, PM_REMOVE))
258 {
259 if (msg.message == WM_QUIT)
260 Game_DeinitializeAndTerminate(0);
261 TranslateMessage(&msg);
262 DispatchMessageW(&msg);
263 }
264
265 if (dword_6BE364_game_settings_1 & GAME_SETTINGS_APP_INACTIVE)
266 {
267 WaitMessage();
268 continue;
269 }
270
271 pRenderer->BeginScene();
272 pRenderer->DrawTextureRGB(0, 0, &pTexture_PCX);
273
274 MMT_MenuMessageProc();//for ÌÌÒ menu
275 GUI_UpdateWindows();
276
277 if ( !pModalWindow )// ???
278 {
279 pButton = pWindow_MMT_MainMenu->pControlsHead;
280 for ( pButton = pWindow_MMT_MainMenu->pControlsHead; pButton; pButton = pButton->pNext )
281 {
282 if ( cursor.x >= (signed int)pButton->uX && cursor.x <= (signed int)pButton->uZ
283 && cursor.y >= (signed int)pButton->uY && cursor.y <= (signed int)pButton->uW )
284 {
285 pControlParam = pButton->msg_param;
286 switch (pControlParam) // backlight for buttons
287 {
288 case 0:
289 pTexture = MMT_MM6;
290 pX = 0;
291 pY = 0;
292 break;
293 case 1:
294 pTexture = MMT_MM7;
295 pX = window->GetWidth() - (window->GetWidth() / 4);
296 pY = window->GetHeight() / 4;
297 break;
298 case 2:
299 pTexture = MMT_MM8;
300 pX = window->GetWidth() - (window->GetWidth() / 4);
301 pY = window->GetHeight() - ((window->GetHeight() / 4) + 50);
302 break;
303 case 3:
304 pTexture = MMT_Continue;
305 pX = (window->GetWidth() / 4) - 100;
306 pY = window->GetHeight() - ((window->GetHeight() / 4) + 50);
307 break;
308 case 4:
309 pTexture = MMT_Exit;
310 pX = window->GetWidth() - 130;
311 pY = window->GetHeight() - 35;
312 break;
313 }
314 pRenderer->DrawTextureIndexed(pX, pY, pTexture);
315 }
316 }
317 }
318 //}
319 pRenderer->EndScene();
320 pRenderer->Present();
321 }
322 MMT_MenuMessageProc();
323 pRenderer->BeginScene();
324 GUI_UpdateWindows();
325 pRenderer->EndScene();
326 pRenderer->Present();
327
328 //remove resource
329 pTexture_PCX.Release();
330 if ( pGUIWindow2 )
331 {
332 pGUIWindow2->Release();
333 pGUIWindow2 = 0;
334 }
335 pWindow_MMT_MainMenu->Release();
336 pIcons_LOD->RemoveTexturesPackFromTextureList();
337 }
338
339 void MMT_MenuMessageProc()
340 {
341 int pParam;
342 int pParam2;
343 UIMessageType pUIMessageType;
344
345 if ( pMessageQueue_50CBD0->uNumMessages )
346 {
347 do
348 {
349
350 pMessageQueue_50CBD0->PopMessage(&pUIMessageType, &pParam, &pParam2);
351
352 switch (pUIMessageType)
353 {
354 case UIMSG_MMT_MainMenu_MM6:
355 //video
356 //SetCurrentMenuID(MENU_MAIN_MM6);
357 pAudioPlayer->PlaySound((SoundID)27, 0, 0, -1, 0, 0, 0, 0);//temporarily
358 break;
359 case UIMSG_MMT_MainMenu_MM7: //new button for ÌÌ7
360 //GUIWindow::Create(495, 172, 0, 0, WINDOW_PressedButton2, (int)pMainMenu_BtnNew, 0);
361 alSourceStop(mSourceID);
362 pMediaPlayer->ShowMM7IntroVideo_and_LoadingScreen();
363 SetCurrentMenuID(MENU_MAIN);
364 break;
365 case UIMSG_MMT_MainMenu_MM8:
366 //video
367 //SetCurrentMenuID(MENU_MAIN_MM8);
368 pAudioPlayer->PlaySound((SoundID)27, 0, 0, -1, 0, 0, 0, 0);//temporarily
369 break;
370 case UIMSG_MMT_MainMenu_Continue:
371 //video
372 //SetCurrentMenuID(MENU_MAIN_Continue);
373 pAudioPlayer->PlaySound((SoundID)27, 0, 0, -1, 0, 0, 0, 0);//temporarily
374 break;
375 case UIMSG_ExitToWindows:
376 GUIWindow::Create(495, 337, 0, 0, WINDOW_PressedButton2, (int)pMainMenu_BtnExit, 0);
377 SetCurrentMenuID(MENU_EXIT_GAME);
378
379 default:
380 break;
381 }
382 }
383 while ( pMessageQueue_50CBD0->uNumMessages );
384 }
385 }
386 void DrawMMTCopyrightWindow()
387 {
388 GUIWindow Dst; // [sp+8h] [bp-54h]@1
389
390 memset(&Dst, 0, 0x54u);
391 Dst.uFrameWidth = 624;
392 Dst.uFrameHeight = 256;
393 Dst.uFrameX = 8;
394 Dst.uFrameY = 30;
395 Dst.uFrameHeight = pFontSmallnum->CalcTextHeight("Text Verification: Here we can write an explanation of the project", &Dst, 24, 0)
396 + 2 * LOBYTE(pFontSmallnum->uFontHeight)
397 + 24;
398 Dst.uFrameY = 470 - Dst.uFrameHeight;
399 Dst.uFrameZ = Dst.uFrameX + Dst.uFrameWidth - 1;
400 Dst.uFrameW = 469;
401 //Dst.Hint = "abcagfdsgsg ljsrengvlkjesnfkjwnef";
402 Dst.DrawMessageBox(0);
403
404 Dst.uFrameWidth -= 24;
405 Dst.uFrameX += 12;
406 Dst.uFrameY += 12;
407 Dst.uFrameHeight -= 12;
408 Dst.uFrameZ = Dst.uFrameX + Dst.uFrameWidth - 1;
409 Dst.uFrameW = Dst.uFrameY + Dst.uFrameHeight - 1;
410 Dst.DrawTitleText(pFontSmallnum, 0, 0xCu, ui_mainmenu_copyright_color, "Text Verification: Here we can write an explanation of the project", 3);
411 }