forked from littlebalup/Zelda3T
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
488 lines (420 loc) · 15.1 KB
/
main.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
/*
Zelda Time to Triumph
Copyright (C) 2007-2009 Vincent Jouillat
Please send bugreports with examples or suggestions to www.zeldaroth.fr
*/
#include <SDL/SDL.h>
#include <SDL/SDL_rotozoom.h>
#include "Lang.h"
#include <iostream>
#include <cstdlib>
#include <ctime>
#include "Keyboard.h"
#include "Generique.h"
#ifdef __vita__
#include <psp2/apputil.h>
#include <psp2/power.h>
#include <psp2/kernel/processmgr.h>
#include <psp2/io/fcntl.h>
#include <psp2/io/stat.h>
#include <vitaGL.h>
#include <imgui_vita.h>
int _newlib_heap_size_user = 192 * 1024 * 1024;
bool autohide = false;
bool visible = false;
bool fullscreen = false;
bool bilinear = true;
bool vflux_window = false;
bool credits_window = false;
bool vflux_enabled = false;
float vcolors[3];
uint16_t *vindices;
float *colors;
float *vertices;
uint64_t tick;
SDL_Shader shader = SDL_SHADER_NONE;
#endif
uint8_t language = LANG_EN;
SDL_Surface* init(bool* etire) { // initialise SDL
if(SDL_Init(SDL_INIT_VIDEO) == -1) {
printf("Could not load SDL : %s\n", SDL_GetError());
exit(-1);
}
atexit(SDL_Quit);
//if(SDL_InitSubSystem(SDL_INIT_AUDIO) == -1) *SOUND = false;
#ifndef __vita__
SDL_WM_SetCaption("Time to Triumph",NULL);
SDL_Surface* icon = SDL_LoadBMP("data/images/logos/ocarina.ico");
SDL_SetColorKey(icon,SDL_SRCCOLORKEY,SDL_MapRGB(icon->format,0,0,0));
SDL_WM_SetIcon(icon,NULL);
#endif
SDL_ShowCursor(SDL_DISABLE);
#ifdef __vita__
return SDL_SetVideoMode(320, 240, 16, SDL_HWSURFACE|SDL_DOUBLEBUF);
#else
SDL_Rect** modes;
int gBpp = 0;
modes = SDL_ListModes(NULL,SDL_FULLSCREEN|SDL_HWSURFACE);
if (modes == (SDL_Rect**)-1) gBpp = 1;
else {
for (int i = 0; modes[i]; ++i) {
if (modes[i]->w == 320 && modes[i]->h == 240) {
gBpp = 1; break;
}
}
}
if(!gBpp) {
*etire = true;
return SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN);
} else {
return SDL_SetVideoMode(320, 240, 32, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN);
}
#endif
}
int getLanguage(void)
{
return language;
}
void setLanguage(Jeu* gpJeu, int languageID)
{
if (languageID>MAX_LANG || languageID<MIN_LANG) language = DEFAULT_LANG;
else language = languageID;
gpJeu->setTextLanguage(language);
}
#ifdef __vita__
void LoadSettings() {
FILE *fp = fopen("ux0:data/z3t/imgui.cfg", "rb");
if (fp) {
fseek(fp, 0, SEEK_SET);
fread(&autohide, sizeof(bool), 1, fp);
fread(&fullscreen, sizeof(bool), 1, fp);
fread(&bilinear, sizeof(bool), 1, fp);
fread(&vflux_enabled, sizeof(bool), 1, fp);
fread(&vcolors, 3 * sizeof(float), 1, fp);
fread(&shader, sizeof(SDL_Shader), 1, fp);
fclose(fp);
}
}
void SaveSettings() {
FILE *fp = fopen("ux0:data/z3t/imgui.cfg", "wb");
if (fp) {
fseek(fp, 0, SEEK_SET);
fwrite(&autohide, sizeof(bool), 1, fp);
fwrite(&fullscreen, sizeof(bool), 1, fp);
fwrite(&bilinear, sizeof(bool), 1, fp);
fwrite(&vflux_enabled, sizeof(bool), 1, fp);
fwrite(&vcolors, 3 * sizeof(float), 1, fp);
fwrite(&shader, sizeof(SDL_Shader), 1, fp);
fclose(fp);
}
}
void SetSettings() {
if (fullscreen) {
SDL_SetVideoModeScaling(0, 0, 960, 544);
} else {
int sh = 544;
int sw = (float)320 * ((float)sh / (float)240);
int x = (960 - sw) / 2;
SDL_SetVideoModeScaling(x, 0, sw, sh);
}
SDL_SetVideoModeBilinear(bilinear);
SDL_SetVideoShader(shader);
if (vflux_enabled) {
memcpy(&colors[0], vcolors, sizeof(float) * 3);
memcpy(&colors[4], vcolors, sizeof(float) * 3);
memcpy(&colors[8], vcolors, sizeof(float) * 3);
memcpy(&colors[12], vcolors, sizeof(float) * 3);
float c;
SceDateTime time;
sceRtcGetCurrentClockLocalTime(&time);
if (time.hour < 6) // Night/Early Morning
c = 0.25f;
else if (time.hour < 10) // Morning/Early Day
c = 0.1f;
else if (time.hour < 15) // Mid day
c = 0.05f;
else if (time.hour < 19) // Late day
c = 0.15f;
else // Evening/Night
c = 0.2f;
colors[3] = colors[7] = colors[11] = colors[15] = c;
}
}
void ImGui_callback() {
ImGui_ImplVitaGL_NewFrame();
if ((!autohide || visible) && ImGui::BeginMainMenuBar()) {
if (ImGui::BeginMenu("File")) {
if (ImGui::MenuItem("Save config", nullptr, nullptr)) {
SaveSettings();
}
if (ImGui::MenuItem("Reload config", nullptr, nullptr)) {
LoadSettings();
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Graphics")) {
if (ImGui::MenuItem("Fullscreen", nullptr, fullscreen)) {
fullscreen = !fullscreen;
}
if (ImGui::MenuItem("Bilinear Filter", nullptr, bilinear)) {
bilinear = !bilinear;
}
if (ImGui::MenuItem("vFlux Config", nullptr, vflux_window)) {
vflux_window = !vflux_window;
}
if (ImGui::BeginMenu("Shaders")) {
if (ImGui::MenuItem("None", nullptr, shader == SDL_SHADER_NONE)) {
shader = SDL_SHADER_NONE;
}
if (ImGui::MenuItem("Sharp Bilinear", nullptr, shader == SDL_SHADER_SHARP_BILINEAR_SIMPLE)) {
shader = SDL_SHADER_SHARP_BILINEAR_SIMPLE;
}
if (ImGui::MenuItem("Sharp Bilinear (Scanlines)", nullptr, shader == SDL_SHADER_SHARP_BILINEAR)) {
shader = SDL_SHADER_SHARP_BILINEAR;
}
if (ImGui::MenuItem("LCD 3x", nullptr, shader == SDL_SHADER_LCD3X)) {
shader = SDL_SHADER_LCD3X;
}
if (ImGui::MenuItem("xBR x2", nullptr, shader == SDL_SHADER_XBR_2X_FAST)) {
shader = SDL_SHADER_XBR_2X_FAST;
}
ImGui::EndMenu();
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Options")) {
if (ImGui::MenuItem("Auto-hide menu bar", nullptr, autohide)) {
autohide = !autohide;
}
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Info")) {
if (ImGui::MenuItem("Credits", nullptr, credits_window)) {
credits_window = !credits_window;
}
ImGui::EndMenu();
}
if (vflux_window) {
ImGui::Begin("vFlux Configuration", &vflux_window);
ImGui::ColorPicker3("Filter Color", vcolors);
ImGui::Checkbox("Enable vFlux", &vflux_enabled);
ImGui::End();
}
if (credits_window) {
ImGui::Begin("Credits", &credits_window);
ImGui::TextColored(ImVec4(255, 255, 0, 255), "Zelda: Time to Triumph v1.3.2");
ImGui::Text("Game Creator: Vincent Jouillat");
ImGui::Text("Port Author: usineur");
ImGui::Separator();
ImGui::TextColored(ImVec4(255, 255, 0, 255), "Multilingual support");
ImGui::Text("French translation: NicolasR");
ImGui::Separator();
ImGui::TextColored(ImVec4(255, 255, 0, 255), "Special thanks to:");
ImGui::Text("Rinnegatamante: SDL 1.2 and imgui Vita ports");
ImGui::Text("littlebalup: several enhancements");
ImGui::End();
}
ImGui::SameLine();
ImGui::SetCursorPosX(870);
ImGui::Text("FPS: %.1f", ImGui::GetIO().Framerate);
ImGui::EndMainMenuBar();
}
SetSettings();
if (vflux_enabled) {
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
vglIndexPointerMapped(vindices);
vglVertexPointerMapped(vertices);
vglColorPointerMapped(GL_FLOAT, colors);
vglDrawObjects(GL_TRIANGLE_FAN, 4, true);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
}
ImGui::Render();
ImGui_ImplVitaGL_RenderDrawData(ImGui::GetDrawData());
SceTouchData touch;
sceTouchPeek(SCE_TOUCH_PORT_FRONT, &touch, 1);
uint64_t delta_touch = sceKernelGetProcessTimeWide() - tick;
if (touch.reportNum > 0) {
visible = true;
ImGui::GetIO().MouseDrawCursor = true;
tick = sceKernelGetProcessTimeWide();
} else if (delta_touch > 3000000) {
visible = false;
ImGui::GetIO().MouseDrawCursor = false;
}
}
#endif
int main(int argc, char** argv) {
#ifdef __vita__
sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG_WIDE);
sceTouchSetSamplingState(SCE_TOUCH_PORT_FRONT, SCE_TOUCH_SAMPLING_STATE_START);
sceKernelPowerTick(SCE_KERNEL_POWER_TICK_DISABLE_AUTO_SUSPEND);
scePowerSetArmClockFrequency(444);
sceIoMkdir("ux0:data/z3t", 0777);
sceIoMkdir("ux0:data/z3t/save", 0777);
#endif
if (argc && argv); //pour éviter un warning.....
std::srand(std::time(NULL));
SDL_Rect src;
SDL_Rect dst;
src.w=640; src.h=480; src.y=0;src.x=0;dst.x=0; dst.y=0;
SDL_Surface* gpScreen = NULL;
int mode = 2; //mode=1;
bool etire = false;
gpScreen = init(&etire);
SDL_Surface* gpScreen2 = SDL_CreateRGBSurface(SDL_HWSURFACE, 320, 240, 32, 0, 0, 0, 0);
SDL_Surface* gpScreen3 = NULL;
#ifdef __vita__
vindices = (uint16_t*)malloc(sizeof(uint16_t) * 4);
colors = (float*)malloc(sizeof(float) * 4 * 4);
vertices = (float*)malloc(sizeof(float) * 3 * 4);
LoadSettings();
SetSettings();
vertices[0] = 0.0f;
vertices[1] = 0.0f;
vertices[2] = 0.0f;
vertices[3] = 960.0f;
vertices[4] = 0.0f;
vertices[5] = 0.0f;
vertices[6] = 960.0f;
vertices[7] = 544.0f;
vertices[8] = 0.0f;
vertices[9] = 0.0f;
vertices[10]= 544.0f;
vertices[11]= 0.0f;
vindices[0] = 0;
vindices[1] = 1;
vindices[2] = 2;
vindices[3] = 3;
ImGui::CreateContext();
ImGui_ImplVitaGL_Init();
ImGui_ImplVitaGL_TouchUsage(true);
ImGui_ImplVitaGL_MouseStickUsage(false);
ImGui_ImplVitaGL_UseIndirectFrontTouch(true);
ImGui::StyleColorsDark();
ImGui::GetIO().MouseDrawCursor = false;
ImGui::GetIO().IniFilename = "ux0:data/z3t/imgui.ini";
SDL_SetVideoCallback(reinterpret_cast<void(*)(...)>(ImGui_callback));
#endif
Audio* gpAudio = new Audio();
Jeu* gpJeu = new Jeu(gpAudio);
#ifdef __vita__
// Init SceAppUtil
SceAppUtilInitParam init_param;
SceAppUtilBootParam boot_param;
memset(&init_param, 0, sizeof(SceAppUtilInitParam));
memset(&boot_param, 0, sizeof(SceAppUtilBootParam));
sceAppUtilInit(&init_param, &boot_param);
// Getting system language
int lang = 0;
sceAppUtilSystemParamGetInt(SCE_SYSTEM_PARAM_ID_LANG, &lang);
switch (lang){
case SCE_SYSTEM_PARAM_LANG_FRENCH:
language = LANG_FR;
break;
case SCE_SYSTEM_PARAM_LANG_SPANISH:
language = 5;
break;
case SCE_SYSTEM_PARAM_LANG_ITALIAN:
language = 4;
break;
default:
language = LANG_EN;
break;
}
setLanguage(gpJeu, language);
#else
setLanguage(gpJeu, DEFAULT_LANG);
#endif
Carte* gpCarte = new Carte(gpJeu);
Encyclopedie* gpEncyclopedie = new Encyclopedie(gpJeu);
Poissons* gpPoissons = new Poissons(gpJeu);
Keyboard* gpKeyboard = new Keyboard(gpJeu, gpCarte, gpEncyclopedie, gpPoissons,
gpScreen, mode, etire);
gpJeu->setKeyboard(gpKeyboard);
Generique* gpGenerique = new Generique(gpJeu);
gpJeu->setGenerique(gpGenerique);
gpGenerique->initLogo();
//gpJeu->init(0); //à virer
bool gLoop = true;
Uint32 lastAnimTime = SDL_GetTicks();
while (gLoop) {
if (gpKeyboard->gererClavier() == -1) {gLoop = false;}
switch (gpKeyboard->getMode()) {
case 0 : //jeu normal
gpJeu->draw(gpScreen2); break;
case 1 : //disclamer
case 2 : //logo
case 3 : //titre
case 14 : //générique score
case 17 : //menu d'aide 1
case 18 : //menu d'aide 2
case 24 : //menu d'aide 3
case 25 : //items de troc
case 28 : //image de fin
gpGenerique->draw(gpScreen2); break;
case 4 : //selection
gpGenerique->drawSelection(gpScreen2, gpKeyboard->getLigne(),
gpKeyboard->getColonne()); break;
case 6 : //options
gpGenerique->drawOption(gpScreen2, gpKeyboard->getLigneOption(),
gpKeyboard->getVolume()/8, gpKeyboard->getVolson()/8); break;
case 7 : //charger partie
gpGenerique->drawCharger(gpScreen2, gpKeyboard->getLigne(),
gpKeyboard->getLigneVal()); break;
case 8 : //générique intro
gpGenerique->drawIntro(gpScreen2, gpKeyboard->getIntro()); break;
case 9 : //effacer partie
gpGenerique->drawEffacerSave(gpScreen2, gpKeyboard->getLigne(),
gpKeyboard->getLigneVal()); break;
case 10 : //générique début chez link
gpGenerique->drawDebut(gpScreen2); break;
case 11 : //générique fin
gpGenerique->drawFin(gpScreen2); break;
case 12 : //carte
case 22 : //carte téléportation
gpCarte->draw(gpScreen2); break;
case 13 : //encyclopédie des monstres
gpEncyclopedie->draw(gpScreen2); break;
case 15 : //records
case 19 : //rang 100%
case 20 : //rang ultime
case 21 : //rang de rapidité
gpGenerique->drawRecord(gpScreen2, gpKeyboard->getLigneRecord(),
gpKeyboard->getColonneRecord()); break;
case 16 : //effacer record
gpGenerique->drawEffacer(gpScreen2, gpKeyboard->getLigneVal()); break;
case 23 : //encyclopédie des poissons
gpPoissons->draw(gpScreen2); break;
case 26 : //générique vers présent
case 27 : //générique vers passé
gpGenerique->drawToPresent(gpScreen2); break;
default : break;
}
if (etire || !gpKeyboard->isFullScreen()) {
SDL_FreeSurface(gpScreen3);
gpScreen3 = zoomSurface (gpScreen2, 2, 2, 0);
SDL_BlitSurface(gpScreen3, &src, gpScreen, &dst);
} else {
SDL_BlitSurface(gpScreen2, &src, gpScreen, &dst);
}
SDL_Flip(gpScreen);
if (SDL_GetTicks() < lastAnimTime + 20) SDL_Delay(lastAnimTime+20-SDL_GetTicks());
lastAnimTime = SDL_GetTicks();
}
SDL_FreeSurface(gpScreen2);
SDL_FreeSurface(gpScreen3);
delete gpPoissons;
delete gpEncyclopedie;
delete gpGenerique;
delete gpKeyboard;
delete gpCarte;
delete gpJeu;
delete gpAudio;
SDL_ShowCursor(SDL_ENABLE);
SDL_Quit();
exit(0);
return 0;
}