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
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
|
#if defined RW_GL3 && !defined LIBRW_SDL2
#ifdef _WIN32
#include <windows.h>
#include <mmsystem.h>
#include <shellapi.h>
#include <windowsx.h>
#include <basetsd.h>
#include <regstr.h>
#include <shlobj.h>
#endif
#define WITHWINDOWS
#include "common.h"
#pragma warning( push )
#pragma warning( disable : 4005)
#pragma warning( pop )
#if (defined(_MSC_VER))
#include <tchar.h>
#endif /* (defined(_MSC_VER)) */
#include <stdio.h>
#include "rwcore.h"
#include "skeleton.h"
#include "platform.h"
#include "crossplatform.h"
#include "main.h"
#include "FileMgr.h"
#include "Text.h"
#include "Pad.h"
#include "Timer.h"
#include "DMAudio.h"
#include "ControllerConfig.h"
#include "Frontend.h"
#include "Game.h"
#include "PCSave.h"
#include "MemoryCard.h"
#include "Sprite2d.h"
#include "AnimViewer.h"
#include "Font.h"
#include "MemoryMgr.h"
#define MAX_SUBSYSTEMS (16)
rw::EngineOpenParams openParams;
static RwBool ForegroundApp = TRUE;
static RwBool RwInitialised = FALSE;
static RwSubSystemInfo GsubSysInfo[MAX_SUBSYSTEMS];
static RwInt32 GnumSubSystems = 0;
static RwInt32 GcurSel = 0, GcurSelVM = 0;
static RwBool useDefault;
// What is that for anyway?
#ifndef IMPROVED_VIDEOMODE
static RwBool defaultFullscreenRes = TRUE;
#else
static RwBool defaultFullscreenRes = FALSE;
static RwInt32 bestWndMode = -1;
#endif
static psGlobalType PsGlobal;
#define PSGLOBAL(var) (((psGlobalType *)(RsGlobal.ps))->var)
#undef MAKEPOINTS
#define MAKEPOINTS(l) (*((POINTS /*FAR*/ *)&(l)))
size_t _dwMemAvailPhys;
RwUInt32 gGameState;
#ifdef _WIN32
DWORD _dwOperatingSystemVersion;
#include "resource.h"
#else
long _dwOperatingSystemVersion;
#ifndef __APPLE__
#include <sys/sysinfo.h>
#else
#include <mach/mach_host.h>
#include <sys/sysctl.h>
#endif
#include <stddef.h>
#include <locale.h>
#include <signal.h>
#include <errno.h>
#endif
#ifdef DONT_TRUST_RECOGNIZED_JOYSTICKS
char gSelectedJoystickName[128] = "";
#endif
/*
*****************************************************************************
*/
void _psCreateFolder(const char *path)
{
#ifdef _WIN32
HANDLE hfle = CreateFile(path, GENERIC_READ,
FILE_SHARE_READ,
nil,
OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS | FILE_ATTRIBUTE_NORMAL,
nil);
if ( hfle == INVALID_HANDLE_VALUE )
CreateDirectory(path, nil);
else
CloseHandle(hfle);
#else
struct stat info;
char fullpath[PATH_MAX];
realpath(path, fullpath);
if (lstat(fullpath, &info) != 0) {
if (errno == ENOENT || (errno != EACCES && !S_ISDIR(info.st_mode))) {
mkdir(fullpath, 0755);
}
}
#endif
}
/*
*****************************************************************************
*/
const char *_psGetUserFilesFolder()
{
#if defined USE_MY_DOCUMENTS && defined _WIN32
HKEY hKey = NULL;
static CHAR szUserFiles[256];
if ( RegOpenKeyEx(HKEY_CURRENT_USER,
REGSTR_PATH_SPECIAL_FOLDERS,
REG_OPTION_RESERVED,
KEY_READ,
&hKey) == ERROR_SUCCESS )
{
DWORD KeyType;
DWORD KeycbData = sizeof(szUserFiles);
if ( RegQueryValueEx(hKey,
"Personal",
NULL,
&KeyType,
(LPBYTE)szUserFiles,
&KeycbData) == ERROR_SUCCESS )
{
RegCloseKey(hKey);
strcat(szUserFiles, "\\GTA3 User Files");
_psCreateFolder(szUserFiles);
return szUserFiles;
}
RegCloseKey(hKey);
}
strcpy(szUserFiles, "data");
return szUserFiles;
#else
static char szUserFiles[256];
strcpy(szUserFiles, "userfiles");
_psCreateFolder(szUserFiles);
return szUserFiles;
#endif
}
/*
*****************************************************************************
*/
RwBool
psCameraBeginUpdate(RwCamera *camera)
{
if ( !RwCameraBeginUpdate(Scene.camera) )
{
ForegroundApp = FALSE;
RsEventHandler(rsACTIVATE, (void *)FALSE);
return FALSE;
}
return TRUE;
}
/*
*****************************************************************************
*/
void
psCameraShowRaster(RwCamera *camera)
{
if (CMenuManager::m_PrefsVsync)
RwCameraShowRaster(camera, PSGLOBAL(window), rwRASTERFLIPWAITVSYNC);
else
RwCameraShowRaster(camera, PSGLOBAL(window), rwRASTERFLIPDONTWAIT);
return;
}
/*
*****************************************************************************
*/
RwImage *
psGrabScreen(RwCamera *pCamera)
{
#ifndef LIBRW
RwRaster *pRaster = RwCameraGetRaster(pCamera);
if (RwImage *pImage = RwImageCreate(pRaster->width, pRaster->height, 32)) {
RwImageAllocatePixels(pImage);
RwImageSetFromRaster(pImage, pRaster);
return pImage;
}
#endif
return nil;
}
/*
*****************************************************************************
*/
#ifdef _WIN32
#pragma comment( lib, "Winmm.lib" ) // Needed for time
RwUInt32
psTimer(void)
{
RwUInt32 time;
TIMECAPS TimeCaps;
timeGetDevCaps(&TimeCaps, sizeof(TIMECAPS));
timeBeginPeriod(TimeCaps.wPeriodMin);
time = (RwUInt32) timeGetTime();
timeEndPeriod(TimeCaps.wPeriodMin);
return time;
}
#else
double
psTimer(void)
{
struct timespec start;
#if defined(CLOCK_MONOTONIC_RAW)
clock_gettime(CLOCK_MONOTONIC_RAW, &start);
#elif defined(CLOCK_MONOTONIC_FAST)
clock_gettime(CLOCK_MONOTONIC_FAST, &start);
#else
clock_gettime(CLOCK_MONOTONIC, &start);
#endif
return start.tv_sec * 1000.0 + start.tv_nsec/1000000.0;
}
#endif
/*
*****************************************************************************
*/
void
psMouseSetPos(RwV2d *pos)
{
glfwSetCursorPos(PSGLOBAL(window), pos->x, pos->y);
PSGLOBAL(lastMousePos.x) = (RwInt32)pos->x;
PSGLOBAL(lastMousePos.y) = (RwInt32)pos->y;
return;
}
/*
*****************************************************************************
*/
RwMemoryFunctions*
psGetMemoryFunctions(void)
{
#ifdef USE_CUSTOM_ALLOCATOR
return &memFuncs;
#else
return nil;
#endif
}
/*
*****************************************************************************
*/
RwBool
psInstallFileSystem(void)
{
return (TRUE);
}
/*
*****************************************************************************
*/
RwBool
psNativeTextureSupport(void)
{
return true;
}
/*
*****************************************************************************
*/
#ifdef UNDER_CE
#define CMDSTR LPWSTR
#else
#define CMDSTR LPSTR
#endif
/*
*****************************************************************************
*/
RwBool
psInitialize(void)
{
PsGlobal.lastMousePos.x = PsGlobal.lastMousePos.y = 0.0f;
RsGlobal.ps = &PsGlobal;
PsGlobal.fullScreen = FALSE;
PsGlobal.cursorIsInWindow = TRUE;
PsGlobal.joy1id = -1;
PsGlobal.joy2id = -1;
CFileMgr::Initialise();
#ifdef PS2_MENU
CPad::Initialise();
CPad::GetPad(0)->Mode = 0;
CGame::frenchGame = false;
CGame::germanGame = false;
CGame::nastyGame = true;
CMenuManager::m_PrefsAllowNastyGame = true;
#ifndef _WIN32
// Mandatory for Linux(Unix? Posix?) to set lang. to environment lang.
setlocale(LC_ALL, "");
char *systemLang, *keyboardLang;
systemLang = setlocale (LC_ALL, NULL);
keyboardLang = setlocale (LC_CTYPE, NULL);
short lang;
lang = !strncmp(systemLang, "fr_",3) ? LANG_FRENCH :
!strncmp(systemLang, "de_",3) ? LANG_GERMAN :
!strncmp(systemLang, "en_",3) ? LANG_ENGLISH :
!strncmp(systemLang, "it_",3) ? LANG_ITALIAN :
!strncmp(systemLang, "es_",3) ? LANG_SPANISH :
LANG_OTHER;
#else
WORD lang = PRIMARYLANGID(GetSystemDefaultLCID());
#endif
if ( lang == LANG_ITALIAN )
CMenuManager::m_PrefsLanguage = CMenuManager::LANGUAGE_ITALIAN;
else if ( lang == LANG_SPANISH )
CMenuManager::m_PrefsLanguage = CMenuManager::LANGUAGE_SPANISH;
else if ( lang == LANG_GERMAN )
{
CGame::germanGame = true;
CGame::nastyGame = false;
CMenuManager::m_PrefsAllowNastyGame = false;
CMenuManager::m_PrefsLanguage = CMenuManager::LANGUAGE_GERMAN;
}
else if ( lang == LANG_FRENCH )
{
CGame::frenchGame = true;
CGame::nastyGame = false;
CMenuManager::m_PrefsAllowNastyGame = false;
CMenuManager::m_PrefsLanguage = CMenuManager::LANGUAGE_FRENCH;
}
else
CMenuManager::m_PrefsLanguage = CMenuManager::LANGUAGE_AMERICAN;
FrontEndMenuManager.InitialiseMenuContentsAfterLoadingGame();
TheMemoryCard.Init();
#else
C_PcSave::SetSaveDirectory(_psGetUserFilesFolder());
InitialiseLanguage();
#if GTA_VERSION < GTA3_PC_11
FrontEndMenuManager.LoadSettings();
#endif
#endif
gGameState = GS_START_UP;
TRACE("gGameState = GS_START_UP");
#ifdef _WIN32
OSVERSIONINFO verInfo;
verInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&verInfo);
_dwOperatingSystemVersion = OS_WIN95;
if ( verInfo.dwPlatformId == VER_PLATFORM_WIN32_NT )
{
if ( verInfo.dwMajorVersion == 4 )
{
debug("Operating System is WinNT\n");
_dwOperatingSystemVersion = OS_WINNT;
}
else if ( verInfo.dwMajorVersion == 5 )
{
debug("Operating System is Win2000\n");
_dwOperatingSystemVersion = OS_WIN2000;
}
else if ( verInfo.dwMajorVersion > 5 )
{
debug("Operating System is WinXP or greater\n");
_dwOperatingSystemVersion = OS_WINXP;
}
}
else if ( verInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS )
{
if ( verInfo.dwMajorVersion > 4 || verInfo.dwMajorVersion == 4 && verInfo.dwMinorVersion != 0 )
{
debug("Operating System is Win98\n");
_dwOperatingSystemVersion = OS_WIN98;
}
else
{
debug("Operating System is Win95\n");
_dwOperatingSystemVersion = OS_WIN95;
}
}
#else
_dwOperatingSystemVersion = OS_WINXP; // To fool other classes
#endif
#ifndef PS2_MENU
#if GTA_VERSION >= GTA3_PC_11
FrontEndMenuManager.LoadSettings();
#endif
#endif
#ifdef _WIN32
MEMORYSTATUS memstats;
GlobalMemoryStatus(&memstats);
_dwMemAvailPhys = memstats.dwAvailPhys;
debug("Physical memory size %u\n", memstats.dwTotalPhys);
debug("Available physical memory %u\n", memstats.dwAvailPhys);
#elif defined (__APPLE__)
uint64_t size = 0;
uint64_t page_size = 0;
size_t uint64_len = sizeof(uint64_t);
size_t ull_len = sizeof(unsigned long long);
sysctl((int[]){CTL_HW, HW_PAGESIZE}, 2, &page_size, &ull_len, NULL, 0);
sysctl((int[]){CTL_HW, HW_MEMSIZE}, 2, &size, &uint64_len, NULL, 0);
vm_statistics_data_t vm_stat;
mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vm_stat, &count);
_dwMemAvailPhys = (uint64_t)(vm_stat.free_count * page_size);
debug("Physical memory size %llu\n", _dwMemAvailPhys);
debug("Available physical memory %llu\n", size);
#else
struct sysinfo systemInfo;
sysinfo(&systemInfo);
_dwMemAvailPhys = systemInfo.freeram;
debug("Physical memory size %u\n", systemInfo.totalram);
debug("Available physical memory %u\n", systemInfo.freeram);
#endif
TheText.Unload();
return TRUE;
}
/*
*****************************************************************************
*/
void
psTerminate(void)
{
return;
}
/*
*****************************************************************************
*/
static RwChar **_VMList;
RwInt32 _psGetNumVideModes()
{
return RwEngineGetNumVideoModes();
}
/*
*****************************************************************************
*/
RwBool _psFreeVideoModeList()
{
RwInt32 numModes;
RwInt32 i;
numModes = _psGetNumVideModes();
if ( _VMList == nil )
return TRUE;
for ( i = 0; i < numModes; i++ )
{
RwFree(_VMList[i]);
}
RwFree(_VMList);
_VMList = nil;
return TRUE;
}
/*
*****************************************************************************
*/
RwChar **_psGetVideoModeList()
{
RwInt32 numModes;
RwInt32 i;
if ( _VMList != nil )
{
return _VMList;
}
numModes = RwEngineGetNumVideoModes();
_VMList = (RwChar **)RwCalloc(numModes, sizeof(RwChar*));
for ( i = 0; i < numModes; i++ )
{
RwVideoMode vm;
RwEngineGetVideoModeInfo(&vm, i);
if ( vm.flags & rwVIDEOMODEEXCLUSIVE )
{
_VMList[i] = (RwChar*)RwCalloc(100, sizeof(RwChar));
rwsprintf(_VMList[i],"%d X %d X %d", vm.width, vm.height, vm.depth);
}
else
_VMList[i] = nil;
}
return _VMList;
}
/*
*****************************************************************************
*/
void _psSelectScreenVM(RwInt32 videoMode)
{
RwTexDictionarySetCurrent( nil );
FrontEndMenuManager.UnloadTextures();
if (!_psSetVideoMode(RwEngineGetCurrentSubSystem(), videoMode))
{
RsGlobal.quit = TRUE;
printf("ERROR: Failed to select new screen resolution\n");
}
else
FrontEndMenuManager.LoadAllTextures();
}
/*
*****************************************************************************
*/
RwBool IsForegroundApp()
{
return !!ForegroundApp;
}
/*
UINT GetBestRefreshRate(UINT width, UINT height, UINT depth)
{
LPDIRECT3D8 d3d = Direct3DCreate8(D3D_SDK_VERSION);
ASSERT(d3d != nil);
UINT refreshRate = INT_MAX;
D3DFORMAT format;
if ( depth == 32 )
format = D3DFMT_X8R8G8B8;
else if ( depth == 24 )
format = D3DFMT_R8G8B8;
else
format = D3DFMT_R5G6B5;
UINT modeCount = d3d->GetAdapterModeCount(GcurSel);
for ( UINT i = 0; i < modeCount; i++ )
{
D3DDISPLAYMODE mode;
d3d->EnumAdapterModes(GcurSel, i, &mode);
if ( mode.Width == width && mode.Height == height && mode.Format == format )
{
if ( mode.RefreshRate == 0 )
return 0;
if ( mode.RefreshRate < refreshRate && mode.RefreshRate >= 60 )
refreshRate = mode.RefreshRate;
}
}
#ifdef FIX_BUGS
d3d->Release();
#endif
if ( refreshRate == -1 )
return -1;
return refreshRate;
}
*/
/*
*****************************************************************************
*/
RwBool
psSelectDevice()
{
RwVideoMode vm;
RwInt32 subSysNum;
RwInt32 AutoRenderer = 0;
RwBool modeFound = FALSE;
if ( !useDefault )
{
GnumSubSystems = RwEngineGetNumSubSystems();
if ( !GnumSubSystems )
{
return FALSE;
}
/* Just to be sure ... */
GnumSubSystems = (GnumSubSystems > MAX_SUBSYSTEMS) ? MAX_SUBSYSTEMS : GnumSubSystems;
/* Get the names of all the sub systems */
for (subSysNum = 0; subSysNum < GnumSubSystems; subSysNum++)
{
RwEngineGetSubSystemInfo(&GsubSysInfo[subSysNum], subSysNum);
}
/* Get the default selection */
GcurSel = RwEngineGetCurrentSubSystem();
#ifdef IMPROVED_VIDEOMODE
if(FrontEndMenuManager.m_nPrefsSubsystem < GnumSubSystems)
GcurSel = FrontEndMenuManager.m_nPrefsSubsystem;
#endif
}
/* Set the driver to use the correct sub system */
if (!RwEngineSetSubSystem(GcurSel))
{
return FALSE;
}
#ifdef IMPROVED_VIDEOMODE
FrontEndMenuManager.m_nPrefsSubsystem = GcurSel;
#endif
#ifndef IMPROVED_VIDEOMODE
if ( !useDefault )
{
if ( _psGetVideoModeList()[FrontEndMenuManager.m_nDisplayVideoMode] && FrontEndMenuManager.m_nDisplayVideoMode )
{
FrontEndMenuManager.m_nPrefsVideoMode = FrontEndMenuManager.m_nDisplayVideoMode;
GcurSelVM = FrontEndMenuManager.m_nDisplayVideoMode;
}
else
{
#ifdef DEFAULT_NATIVE_RESOLUTION
// get the native video mode
HDC hDevice = GetDC(NULL);
int w = GetDeviceCaps(hDevice, HORZRES);
int h = GetDeviceCaps(hDevice, VERTRES);
int d = GetDeviceCaps(hDevice, BITSPIXEL);
#else
const int w = 640;
const int h = 480;
const int d = 16;
#endif
while ( !modeFound && GcurSelVM < RwEngineGetNumVideoModes() )
{
RwEngineGetVideoModeInfo(&vm, GcurSelVM);
if ( defaultFullscreenRes && vm.width != w
|| vm.height != h
|| vm.depth != d
|| !(vm.flags & rwVIDEOMODEEXCLUSIVE) )
++GcurSelVM;
else
modeFound = TRUE;
}
if ( !modeFound )
{
#ifdef DEFAULT_NATIVE_RESOLUTION
GcurSelVM = 1;
#else
printf("WARNING: Cannot find 640x480 video mode, selecting device cancelled\n");
return FALSE;
#endif
}
}
}
#else
if ( !useDefault )
{
if(FrontEndMenuManager.m_nPrefsWidth == 0 ||
FrontEndMenuManager.m_nPrefsHeight == 0 ||
FrontEndMenuManager.m_nPrefsDepth == 0){
// Defaults if nothing specified
const GLFWvidmode *mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
FrontEndMenuManager.m_nPrefsWidth = mode->width;
FrontEndMenuManager.m_nPrefsHeight = mode->height;
FrontEndMenuManager.m_nPrefsDepth = 32;
FrontEndMenuManager.m_nPrefsWindowed = 0;
}
// Find the videomode that best fits what we got from the settings file
RwInt32 bestFsMode = -1;
RwInt32 bestWidth = -1;
RwInt32 bestHeight = -1;
RwInt32 bestDepth = -1;
for(GcurSelVM = 0; GcurSelVM < RwEngineGetNumVideoModes(); GcurSelVM++){
RwEngineGetVideoModeInfo(&vm, GcurSelVM);
if (!(vm.flags & rwVIDEOMODEEXCLUSIVE)){
bestWndMode = GcurSelVM;
} else {
// try the largest one that isn't larger than what we wanted
if(vm.width >= bestWidth && vm.width <= FrontEndMenuManager.m_nPrefsWidth &&
vm.height >= bestHeight && vm.height <= FrontEndMenuManager.m_nPrefsHeight &&
vm.depth >= bestDepth && vm.depth <= FrontEndMenuManager.m_nPrefsDepth){
bestWidth = vm.width;
bestHeight = vm.height;
bestDepth = vm.depth;
bestFsMode = GcurSelVM;
}
}
}
if(bestFsMode < 0){
printf("WARNING: Cannot find desired video mode, selecting device cancelled\n");
return FALSE;
}
GcurSelVM = bestFsMode;
FrontEndMenuManager.m_nDisplayVideoMode = GcurSelVM;
FrontEndMenuManager.m_nPrefsVideoMode = FrontEndMenuManager.m_nDisplayVideoMode;
FrontEndMenuManager.m_nSelectedScreenMode = FrontEndMenuManager.m_nPrefsWindowed;
}
#endif
RwEngineGetVideoModeInfo(&vm, GcurSelVM);
#ifdef IMPROVED_VIDEOMODE
if (FrontEndMenuManager.m_nPrefsWindowed)
GcurSelVM = bestWndMode;
// Now GcurSelVM is 0 but vm has sizes(and fullscreen flag) of the video mode we want, that's why we changed the rwVIDEOMODEEXCLUSIVE conditions below
FrontEndMenuManager.m_nPrefsWidth = vm.width;
FrontEndMenuManager.m_nPrefsHeight = vm.height;
FrontEndMenuManager.m_nPrefsDepth = vm.depth;
#endif
#ifndef PS2_MENU
FrontEndMenuManager.m_nCurrOption = 0;
#endif
/* Set up the video mode and set the apps window
* dimensions to match */
if (!RwEngineSetVideoMode(GcurSelVM))
{
return FALSE;
}
/*
TODO
if (vm.flags & rwVIDEOMODEEXCLUSIVE)
{
debug("%dx%dx%d", vm.width, vm.height, vm.depth);
UINT refresh = GetBestRefreshRate(vm.width, vm.height, vm.depth);
if ( refresh != (UINT)-1 )
{
debug("refresh %d", refresh);
RwD3D8EngineSetRefreshRate((RwUInt32)refresh);
}
}
*/
#ifndef IMPROVED_VIDEOMODE
if (vm.flags & rwVIDEOMODEEXCLUSIVE)
{
RsGlobal.maximumWidth = vm.width;
RsGlobal.maximumHeight = vm.height;
RsGlobal.width = vm.width;
RsGlobal.height = vm.height;
PSGLOBAL(fullScreen) = TRUE;
}
#else
RsGlobal.maximumWidth = FrontEndMenuManager.m_nPrefsWidth;
RsGlobal.maximumHeight = FrontEndMenuManager.m_nPrefsHeight;
RsGlobal.width = FrontEndMenuManager.m_nPrefsWidth;
RsGlobal.height = FrontEndMenuManager.m_nPrefsHeight;
PSGLOBAL(fullScreen) = !FrontEndMenuManager.m_nPrefsWindowed;
#endif
#ifdef MULTISAMPLING
RwD3D8EngineSetMultiSamplingLevels(1 << FrontEndMenuManager.m_nPrefsMSAALevel);
#endif
return TRUE;
}
void keypressCB(GLFWwindow* window, int key, int scancode, int action, int mods);
void resizeCB(GLFWwindow* window, int width, int height);
void scrollCB(GLFWwindow* window, double xoffset, double yoffset);
void cursorCB(GLFWwindow* window, double xpos, double ypos);
void cursorEnterCB(GLFWwindow* window, int entered);
void joysChangeCB(int jid, int event);
bool IsThisJoystickBlacklisted(int i)
{
#ifndef DONT_TRUST_RECOGNIZED_JOYSTICKS
return false;
#else
if (glfwJoystickIsGamepad(i))
return false;
const char* joyname = glfwGetJoystickName(i);
if (gSelectedJoystickName[0] != '\0' &&
strncmp(joyname, gSelectedJoystickName, strlen(gSelectedJoystickName)) == 0)
return false;
return true;
#endif
}
void _InputInitialiseJoys()
{
PSGLOBAL(joy1id) = -1;
PSGLOBAL(joy2id) = -1;
for (int i = 0; i <= GLFW_JOYSTICK_LAST; i++) {
if (glfwJoystickPresent(i) && !IsThisJoystickBlacklisted(i)) {
if (PSGLOBAL(joy1id) == -1)
PSGLOBAL(joy1id) = i;
else if (PSGLOBAL(joy2id) == -1)
PSGLOBAL(joy2id) = i;
else
break;
}
}
if (PSGLOBAL(joy1id) != -1) {
int count;
glfwGetJoystickButtons(PSGLOBAL(joy1id), &count);
#ifdef DONT_TRUST_RECOGNIZED_JOYSTICKS
strcpy(gSelectedJoystickName, glfwGetJoystickName(PSGLOBAL(joy1id)));
#endif
ControlsManager.InitDefaultControlConfigJoyPad(count);
}
}
long _InputInitialiseMouse()
{
glfwSetInputMode(PSGLOBAL(window), GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
return 0;
}
void psPostRWinit(void)
{
RwVideoMode vm;
RwEngineGetVideoModeInfo(&vm, GcurSelVM);
glfwSetKeyCallback(PSGLOBAL(window), keypressCB);
glfwSetFramebufferSizeCallback(PSGLOBAL(window), resizeCB);
glfwSetScrollCallback(PSGLOBAL(window), scrollCB);
glfwSetCursorPosCallback(PSGLOBAL(window), cursorCB);
glfwSetCursorEnterCallback(PSGLOBAL(window), cursorEnterCB);
glfwSetJoystickCallback(joysChangeCB);
_InputInitialiseJoys();
_InputInitialiseMouse();
if(!(vm.flags & rwVIDEOMODEEXCLUSIVE))
glfwSetWindowSize(PSGLOBAL(window), RsGlobal.maximumWidth, RsGlobal.maximumHeight);
// Make sure all keys are released
CPad::GetPad(0)->Clear(true);
CPad::GetPad(1)->Clear(true);
}
/*
*****************************************************************************
*/
RwBool _psSetVideoMode(RwInt32 subSystem, RwInt32 videoMode)
{
RwInitialised = FALSE;
RsEventHandler(rsRWTERMINATE, nil);
GcurSel = subSystem;
GcurSelVM = videoMode;
useDefault = TRUE;
if ( RsEventHandler(rsRWINITIALIZE, &openParams) == rsEVENTERROR )
return FALSE;
RwInitialised = TRUE;
useDefault = FALSE;
RwRect r;
r.x = 0;
r.y = 0;
r.w = RsGlobal.maximumWidth;
r.h = RsGlobal.maximumHeight;
RsEventHandler(rsCAMERASIZE, &r);
psPostRWinit();
return TRUE;
}
/*
*****************************************************************************
*/
static RwChar **
CommandLineToArgv(RwChar *cmdLine, RwInt32 *argCount)
{
RwInt32 numArgs = 0;
RwBool inArg, inString;
RwInt32 i, len;
RwChar *res, *str, **aptr;
len = strlen(cmdLine);
/*
* Count the number of arguments...
*/
inString = FALSE;
inArg = FALSE;
for(i=0; i<=len; i++)
{
if( cmdLine[i] == '"' )
{
inString = !inString;
}
if( (cmdLine[i] <= ' ' && !inString) || i == len )
{
if( inArg )
{
inArg = FALSE;
numArgs++;
}
}
else if( !inArg )
{
inArg = TRUE;
}
}
/*
* Allocate memory for result...
*/
res = (RwChar *)malloc(sizeof(RwChar *) * numArgs + len + 1);
str = res + sizeof(RwChar *) * numArgs;
aptr = (RwChar **)res;
strcpy(str, cmdLine);
/*
* Walk through cmdLine again this time setting pointer to each arg...
*/
inArg = FALSE;
inString = FALSE;
for(i=0; i<=len; i++)
{
if( cmdLine[i] == '"' )
{
inString = !inString;
}
if( (cmdLine[i] <= ' ' && !inString) || i == len )
{
if( inArg )
{
if( str[i-1] == '"' )
{
str[i-1] = '\0';
}
else
{
str[i] = '\0';
}
inArg = FALSE;
}
}
else if( !inArg && cmdLine[i] != '"' )
{
inArg = TRUE;
*aptr++ = &str[i];
}
}
*argCount = numArgs;
return (RwChar **)res;
}
/*
*****************************************************************************
*/
void InitialiseLanguage()
{
#ifndef _WIN32
// Mandatory for Linux(Unix? Posix?) to set lang. to environment lang.
setlocale(LC_ALL, "");
char *systemLang, *keyboardLang;
systemLang = setlocale (LC_ALL, NULL);
keyboardLang = setlocale (LC_CTYPE, NULL);
short primUserLCID, primSystemLCID;
primUserLCID = primSystemLCID = !strncmp(systemLang, "fr_",3) ? LANG_FRENCH :
!strncmp(systemLang, "de_",3) ? LANG_GERMAN :
!strncmp(systemLang, "en_",3) ? LANG_ENGLISH :
!strncmp(systemLang, "it_",3) ? LANG_ITALIAN :
!strncmp(systemLang, "es_",3) ? LANG_SPANISH :
LANG_OTHER;
short primLayout = !strncmp(keyboardLang, "fr_",3) ? LANG_FRENCH : (!strncmp(keyboardLang, "de_",3) ? LANG_GERMAN : LANG_ENGLISH);
short subUserLCID, subSystemLCID;
subUserLCID = subSystemLCID = !strncmp(systemLang, "en_AU",5) ? SUBLANG_ENGLISH_AUS : SUBLANG_OTHER;
short subLayout = !strncmp(keyboardLang, "en_AU",5) ? SUBLANG_ENGLISH_AUS : SUBLANG_OTHER;
#else
WORD primUserLCID = PRIMARYLANGID(GetSystemDefaultLCID());
WORD primSystemLCID = PRIMARYLANGID(GetUserDefaultLCID());
WORD primLayout = PRIMARYLANGID((DWORD)GetKeyboardLayout(0));
WORD subUserLCID = SUBLANGID(GetSystemDefaultLCID());
WORD subSystemLCID = SUBLANGID(GetUserDefaultLCID());
WORD subLayout = SUBLANGID((DWORD)GetKeyboardLayout(0));
#endif
if ( primUserLCID == LANG_GERMAN
|| primSystemLCID == LANG_GERMAN
|| primLayout == LANG_GERMAN )
{
CGame::nastyGame = false;
CMenuManager::m_PrefsAllowNastyGame = false;
CGame::germanGame = true;
}
if ( primUserLCID == LANG_FRENCH
|| primSystemLCID == LANG_FRENCH
|| primLayout == LANG_FRENCH )
{
CGame::nastyGame = false;
CMenuManager::m_PrefsAllowNastyGame = false;
CGame::frenchGame = true;
}
if ( subUserLCID == SUBLANG_ENGLISH_AUS
|| subSystemLCID == SUBLANG_ENGLISH_AUS
|| subLayout == SUBLANG_ENGLISH_AUS )
CGame::noProstitutes = true;
#ifdef NASTY_GAME
CGame::nastyGame = true;
CMenuManager::m_PrefsAllowNastyGame = true;
CGame::noProstitutes = false;
#endif
int32 lang;
switch ( primSystemLCID )
{
case LANG_GERMAN:
{
lang = LANG_GERMAN;
break;
}
case LANG_FRENCH:
{
lang = LANG_FRENCH;
break;
}
case LANG_SPANISH:
{
lang = LANG_SPANISH;
break;
}
case LANG_ITALIAN:
{
lang = LANG_ITALIAN;
break;
}
default:
{
lang = ( subSystemLCID == SUBLANG_ENGLISH_AUS ) ? -99 : LANG_ENGLISH;
break;
}
}
CMenuManager::OS_Language = primUserLCID;
switch ( lang )
{
case LANG_GERMAN:
{
CMenuManager::m_PrefsLanguage = CMenuManager::LANGUAGE_GERMAN;
break;
}
case LANG_SPANISH:
{
CMenuManager::m_PrefsLanguage = CMenuManager::LANGUAGE_SPANISH;
break;
}
case LANG_FRENCH:
{
CMenuManager::m_PrefsLanguage = CMenuManager::LANGUAGE_FRENCH;
break;
}
case LANG_ITALIAN:
{
CMenuManager::m_PrefsLanguage = CMenuManager::LANGUAGE_ITALIAN;
break;
}
default:
{
CMenuManager::m_PrefsLanguage = CMenuManager::LANGUAGE_AMERICAN;
break;
}
}
TheText.Unload();
TheText.Load();
#ifndef _WIN32
// TODO this is needed for strcasecmp to work correctly across all languages, but can these cause other problems??
setlocale(LC_CTYPE, "C");
setlocale(LC_COLLATE, "C");
setlocale(LC_NUMERIC, "C");
#endif
}
/*
*****************************************************************************
*/
void HandleExit()
{
#ifdef _WIN32
MSG message;
while ( PeekMessage(&message, nil, 0U, 0U, PM_REMOVE|PM_NOYIELD) )
{
if( message.message == WM_QUIT )
{
RsGlobal.quit = TRUE;
}
else
{
TranslateMessage(&message);
DispatchMessage(&message);
}
}
#else
// We now handle terminate message always, why handle on some cases?
return;
#endif
}
#ifndef _WIN32
void terminateHandler(int sig, siginfo_t *info, void *ucontext) {
RsGlobal.quit = TRUE;
}
void dummyHandler(int sig){
// Don't kill the app pls
}
#endif
void resizeCB(GLFWwindow* window, int width, int height) {
/*
* Handle event to ensure window contents are displayed during re-size
* as this can be disabled by the user, then if there is not enough
* memory things don't work.
*/
/* redraw window */
#ifndef MASTER
if (RwInitialised && (gGameState == GS_PLAYING_GAME || gGameState == GS_ANIMVIEWER))
{
RsEventHandler((gGameState == GS_PLAYING_GAME ? rsIDLE : rsANIMVIEWER), (void *)TRUE);
}
#else
if (RwInitialised && gGameState == GS_PLAYING_GAME)
{
RsEventHandler(rsIDLE, (void *)TRUE);
}
#endif
if (RwInitialised && height > 0 && width > 0) {
RwRect r;
// TODO fix artifacts of resizing with mouse
RsGlobal.maximumHeight = height;
RsGlobal.maximumWidth = width;
r.x = 0;
r.y = 0;
r.w = width;
r.h = height;
RsEventHandler(rsCAMERASIZE, &r);
}
// glfwSetWindowPos(window, 0, 0);
}
void scrollCB(GLFWwindow* window, double xoffset, double yoffset) {
PSGLOBAL(mouseWheel) = yoffset;
}
int keymap[GLFW_KEY_LAST + 1];
static void
initkeymap(void)
{
int i;
for (i = 0; i < GLFW_KEY_LAST + 1; i++)
keymap[i] = rsNULL;
keymap[GLFW_KEY_SPACE] = ' ';
keymap[GLFW_KEY_APOSTROPHE] = '\'';
keymap[GLFW_KEY_COMMA] = ',';
keymap[GLFW_KEY_MINUS] = '-';
keymap[GLFW_KEY_PERIOD] = '.';
keymap[GLFW_KEY_SLASH] = '/';
keymap[GLFW_KEY_0] = '0';
keymap[GLFW_KEY_1] = '1';
keymap[GLFW_KEY_2] = '2';
keymap[GLFW_KEY_3] = '3';
keymap[GLFW_KEY_4] = '4';
keymap[GLFW_KEY_5] = '5';
keymap[GLFW_KEY_6] = '6';
keymap[GLFW_KEY_7] = '7';
keymap[GLFW_KEY_8] = '8';
keymap[GLFW_KEY_9] = '9';
keymap[GLFW_KEY_SEMICOLON] = ';';
keymap[GLFW_KEY_EQUAL] = '=';
keymap[GLFW_KEY_A] = 'A';
keymap[GLFW_KEY_B] = 'B';
keymap[GLFW_KEY_C] = 'C';
keymap[GLFW_KEY_D] = 'D';
keymap[GLFW_KEY_E] = 'E';
keymap[GLFW_KEY_F] = 'F';
keymap[GLFW_KEY_G] = 'G';
keymap[GLFW_KEY_H] = 'H';
keymap[GLFW_KEY_I] = 'I';
keymap[GLFW_KEY_J] = 'J';
keymap[GLFW_KEY_K] = 'K';
keymap[GLFW_KEY_L] = 'L';
keymap[GLFW_KEY_M] = 'M';
keymap[GLFW_KEY_N] = 'N';
keymap[GLFW_KEY_O] = 'O';
keymap[GLFW_KEY_P] = 'P';
keymap[GLFW_KEY_Q] = 'Q';
keymap[GLFW_KEY_R] = 'R';
keymap[GLFW_KEY_S] = 'S';
keymap[GLFW_KEY_T] = 'T';
keymap[GLFW_KEY_U] = 'U';
keymap[GLFW_KEY_V] = 'V';
keymap[GLFW_KEY_W] = 'W';
keymap[GLFW_KEY_X] = 'X';
keymap[GLFW_KEY_Y] = 'Y';
keymap[GLFW_KEY_Z] = 'Z';
keymap[GLFW_KEY_LEFT_BRACKET] = '[';
keymap[GLFW_KEY_BACKSLASH] = '\\';
keymap[GLFW_KEY_RIGHT_BRACKET] = ']';
keymap[GLFW_KEY_GRAVE_ACCENT] = '`';
keymap[GLFW_KEY_ESCAPE] = rsESC;
keymap[GLFW_KEY_ENTER] = rsENTER;
keymap[GLFW_KEY_TAB] = rsTAB;
keymap[GLFW_KEY_BACKSPACE] = rsBACKSP;
keymap[GLFW_KEY_INSERT] = rsINS;
keymap[GLFW_KEY_DELETE] = rsDEL;
keymap[GLFW_KEY_RIGHT] = rsRIGHT;
keymap[GLFW_KEY_LEFT] = rsLEFT;
keymap[GLFW_KEY_DOWN] = rsDOWN;
keymap[GLFW_KEY_UP] = rsUP;
keymap[GLFW_KEY_PAGE_UP] = rsPGUP;
keymap[GLFW_KEY_PAGE_DOWN] = rsPGDN;
keymap[GLFW_KEY_HOME] = rsHOME;
keymap[GLFW_KEY_END] = rsEND;
keymap[GLFW_KEY_CAPS_LOCK] = rsCAPSLK;
keymap[GLFW_KEY_SCROLL_LOCK] = rsSCROLL;
keymap[GLFW_KEY_NUM_LOCK] = rsNUMLOCK;
keymap[GLFW_KEY_PRINT_SCREEN] = rsNULL;
keymap[GLFW_KEY_PAUSE] = rsPAUSE;
keymap[GLFW_KEY_F1] = rsF1;
keymap[GLFW_KEY_F2] = rsF2;
keymap[GLFW_KEY_F3] = rsF3;
keymap[GLFW_KEY_F4] = rsF4;
keymap[GLFW_KEY_F5] = rsF5;
keymap[GLFW_KEY_F6] = rsF6;
keymap[GLFW_KEY_F7] = rsF7;
keymap[GLFW_KEY_F8] = rsF8;
keymap[GLFW_KEY_F9] = rsF9;
keymap[GLFW_KEY_F10] = rsF10;
keymap[GLFW_KEY_F11] = rsF11;
keymap[GLFW_KEY_F12] = rsF12;
keymap[GLFW_KEY_F13] = rsNULL;
keymap[GLFW_KEY_F14] = rsNULL;
keymap[GLFW_KEY_F15] = rsNULL;
keymap[GLFW_KEY_F16] = rsNULL;
keymap[GLFW_KEY_F17] = rsNULL;
keymap[GLFW_KEY_F18] = rsNULL;
keymap[GLFW_KEY_F19] = rsNULL;
keymap[GLFW_KEY_F20] = rsNULL;
keymap[GLFW_KEY_F21] = rsNULL;
keymap[GLFW_KEY_F22] = rsNULL;
keymap[GLFW_KEY_F23] = rsNULL;
keymap[GLFW_KEY_F24] = rsNULL;
keymap[GLFW_KEY_F25] = rsNULL;
keymap[GLFW_KEY_KP_0] = rsPADINS;
keymap[GLFW_KEY_KP_1] = rsPADEND;
keymap[GLFW_KEY_KP_2] = rsPADDOWN;
keymap[GLFW_KEY_KP_3] = rsPADPGDN;
keymap[GLFW_KEY_KP_4] = rsPADLEFT;
keymap[GLFW_KEY_KP_5] = rsPAD5;
keymap[GLFW_KEY_KP_6] = rsPADRIGHT;
keymap[GLFW_KEY_KP_7] = rsPADHOME;
keymap[GLFW_KEY_KP_8] = rsPADUP;
keymap[GLFW_KEY_KP_9] = rsPADPGUP;
keymap[GLFW_KEY_KP_DECIMAL] = rsPADDEL;
keymap[GLFW_KEY_KP_DIVIDE] = rsDIVIDE;
keymap[GLFW_KEY_KP_MULTIPLY] = rsTIMES;
keymap[GLFW_KEY_KP_SUBTRACT] = rsMINUS;
keymap[GLFW_KEY_KP_ADD] = rsPLUS;
keymap[GLFW_KEY_KP_ENTER] = rsPADENTER;
keymap[GLFW_KEY_KP_EQUAL] = rsNULL;
keymap[GLFW_KEY_LEFT_SHIFT] = rsLSHIFT;
keymap[GLFW_KEY_LEFT_CONTROL] = rsLCTRL;
keymap[GLFW_KEY_LEFT_ALT] = rsLALT;
keymap[GLFW_KEY_LEFT_SUPER] = rsLWIN;
keymap[GLFW_KEY_RIGHT_SHIFT] = rsRSHIFT;
keymap[GLFW_KEY_RIGHT_CONTROL] = rsRCTRL;
keymap[GLFW_KEY_RIGHT_ALT] = rsRALT;
keymap[GLFW_KEY_RIGHT_SUPER] = rsRWIN;
keymap[GLFW_KEY_MENU] = rsNULL;
}
bool lshiftStatus = false;
bool rshiftStatus = false;
void
keypressCB(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if (key >= 0 && key <= GLFW_KEY_LAST) {
RsKeyCodes ks = (RsKeyCodes)keymap[key];
if (key == GLFW_KEY_LEFT_SHIFT)
lshiftStatus = action != GLFW_RELEASE;
if (key == GLFW_KEY_RIGHT_SHIFT)
rshiftStatus = action != GLFW_RELEASE;
if (action == GLFW_RELEASE) RsKeyboardEventHandler(rsKEYUP, &ks);
else if (action == GLFW_PRESS) RsKeyboardEventHandler(rsKEYDOWN, &ks);
else if (action == GLFW_REPEAT) RsKeyboardEventHandler(rsKEYDOWN, &ks);
}
}
// R* calls that in ControllerConfig, idk why
void
_InputTranslateShiftKeyUpDown(RsKeyCodes *rs) {
RsKeyboardEventHandler(lshiftStatus ? rsKEYDOWN : rsKEYUP, &(*rs = rsLSHIFT));
RsKeyboardEventHandler(rshiftStatus ? rsKEYDOWN : rsKEYUP, &(*rs = rsRSHIFT));
}
// TODO this only works in frontend(and luckily only frontend use this). Fun fact: if I get pos manually in game, glfw reports that it's > 32000
void
cursorCB(GLFWwindow* window, double xpos, double ypos) {
if (!FrontEndMenuManager.m_bMenuActive)
return;
int winw, winh;
glfwGetWindowSize(PSGLOBAL(window), &winw, &winh);
FrontEndMenuManager.m_nMouseTempPosX = xpos * (RsGlobal.maximumWidth / winw);
FrontEndMenuManager.m_nMouseTempPosY = ypos * (RsGlobal.maximumHeight / winh);
}
void
cursorEnterCB(GLFWwindow* window, int entered) {
PSGLOBAL(cursorIsInWindow) = !!entered;
}
/*
*****************************************************************************
*/
#ifdef _WIN32
int PASCAL
WinMain(HINSTANCE instance,
HINSTANCE prevInstance __RWUNUSED__,
CMDSTR cmdLine,
int cmdShow)
{
RwInt32 argc;
RwChar** argv;
SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, nil, SPIF_SENDCHANGE);
#if 0
// TODO: make this an option somewhere
AllocConsole();
freopen("CONIN$", "r", stdin);
freopen("CONOUT$", "w", stdout);
freopen("CONOUT$", "w", stderr);
#endif
#else
int
main(int argc, char *argv[])
{
#endif
RwV2d pos;
RwInt32 i;
#ifdef USE_CUSTOM_ALLOCATOR
InitMemoryMgr();
#endif
#ifndef _WIN32
struct sigaction act;
act.sa_sigaction = terminateHandler;
act.sa_flags = SA_SIGINFO;
sigaction(SIGTERM, &act, NULL);
struct sigaction sa;
sigemptyset(&sa.sa_mask);
sa.sa_handler = dummyHandler;
sa.sa_flags = 0;
sigaction(SIGUSR1, &sa, NULL); // Needed for CdStreamPosix
#endif
/*
* Initialize the platform independent data.
* This will in turn initialize the platform specific data...
*/
if( RsEventHandler(rsINITIALIZE, nil) == rsEVENTERROR )
{
return FALSE;
}
#ifdef _WIN32
/*
* Get proper command line params, cmdLine passed to us does not
* work properly under all circumstances...
*/
cmdLine = GetCommandLine();
/*
* Parse command line into standard (argv, argc) parameters...
*/
argv = CommandLineToArgv(cmdLine, &argc);
/*
* Parse command line parameters (except program name) one at
* a time BEFORE RenderWare initialization...
*/
#endif
for(i=1; i<argc; i++)
{
RsEventHandler(rsPREINITCOMMANDLINE, argv[i]);
}
/*
* Parameters to be used in RwEngineOpen / rsRWINITIALISE event
*/
openParams.width = RsGlobal.maximumWidth;
openParams.height = RsGlobal.maximumHeight;
openParams.windowtitle = RsGlobal.appName;
openParams.window = &PSGLOBAL(window);
ControlsManager.MakeControllerActionsBlank();
ControlsManager.InitDefaultControlConfiguration();
/*
* Initialize the 3D (RenderWare) components of the app...
*/
if( rsEVENTERROR == RsEventHandler(rsRWINITIALIZE, &openParams) )
{
RsEventHandler(rsTERMINATE, nil);
return 0;
}
psPostRWinit();
ControlsManager.InitDefaultControlConfigMouse(MousePointerStateHelper.GetMouseSetUp());
// glfwSetWindowPos(PSGLOBAL(window), 0, 0);
/*
* Parse command line parameters (except program name) one at
* a time AFTER RenderWare initialization...
*/
for(i=1; i<argc; i++)
{
RsEventHandler(rsCOMMANDLINE, argv[i]);
}
/*
* Force a camera resize event...
*/
{
RwRect r;
r.x = 0;
r.y = 0;
r.w = RsGlobal.maximumWidth;
r.h = RsGlobal.maximumHeight;
RsEventHandler(rsCAMERASIZE, &r);
}
#ifdef _WIN32
SystemParametersInfo(SPI_SETPOWEROFFACTIVE, FALSE, nil, SPIF_SENDCHANGE);
SystemParametersInfo(SPI_SETLOWPOWERACTIVE, FALSE, nil, SPIF_SENDCHANGE);
STICKYKEYS SavedStickyKeys;
SavedStickyKeys.cbSize = sizeof(STICKYKEYS);
SystemParametersInfo(SPI_GETSTICKYKEYS, sizeof(STICKYKEYS), &SavedStickyKeys, SPIF_SENDCHANGE);
STICKYKEYS NewStickyKeys;
NewStickyKeys.cbSize = sizeof(STICKYKEYS);
NewStickyKeys.dwFlags = SKF_TWOKEYSOFF;
SystemParametersInfo(SPI_SETSTICKYKEYS, sizeof(STICKYKEYS), &NewStickyKeys, SPIF_SENDCHANGE);
#endif
{
CFileMgr::SetDirMyDocuments();
int32 gta3set = CFileMgr::OpenFile("gta3.set", "r");
if ( gta3set )
{
ControlsManager.LoadSettings(gta3set);
CFileMgr::CloseFile(gta3set);
}
CFileMgr::SetDir("");
}
#ifdef _WIN32
SetErrorMode(SEM_FAILCRITICALERRORS);
#endif
#ifdef PS2_MENU
int32 r = TheMemoryCard.CheckCardStateAtGameStartUp(CARD_ONE);
if ( r == CMemoryCard::ERR_DIRNOENTRY || r == CMemoryCard::ERR_NOFORMAT
&& r != CMemoryCard::ERR_OPENNOENTRY && r != CMemoryCard::ERR_NONE )
{
LoadingScreen(nil, nil, "loadsc0");
TheText.Unload();
TheText.Load();
CFont::Initialise();
FrontEndMenuManager.DrawMemoryCardStartUpMenus();
}
#endif
if (TurnOnAnimViewer)
{
#ifndef MASTER
CAnimViewer::Initialise();
#ifndef PS2_MENU
FrontEndMenuManager.m_bGameNotLoaded = false;
#endif
gGameState = GS_ANIMVIEWER;
TurnOnAnimViewer = false;
#endif
}
initkeymap();
while ( TRUE )
{
RwInitialised = TRUE;
/*
* Set the initial mouse position...
*/
pos.x = RsGlobal.maximumWidth * 0.5f;
pos.y = RsGlobal.maximumHeight * 0.5f;
RsMouseSetPos(&pos);
/*
* Enter the message processing loop...
*/
#ifdef PS2_MENU
if (TheMemoryCard.m_bWantToLoad)
LoadSplash(GetLevelSplashScreen(CGame::currLevel));
TheMemoryCard.m_bWantToLoad = false;
CTimer::Update();
while( !RsGlobal.quit && !(FrontEndMenuManager.m_bWantToRestart || TheMemoryCard.b_FoundRecentSavedGameWantToLoad) && !glfwWindowShouldClose(PSGLOBAL(window)) )
#else
while( !RsGlobal.quit && !FrontEndMenuManager.m_bWantToRestart && !glfwWindowShouldClose(PSGLOBAL(window)))
#endif
{
glfwPollEvents();
if( ForegroundApp )
{
switch ( gGameState )
{
case GS_START_UP:
{
#ifdef NO_MOVIES
gGameState = GS_INIT_ONCE;
#else
gGameState = GS_INIT_LOGO_MPEG;
#endif
TRACE("gGameState = GS_INIT_ONCE");
break;
}
case GS_INIT_LOGO_MPEG:
{
//if (!startupDeactivate)
// PlayMovieInWindow(cmdShow, "movies\\Logo.mpg");
gGameState = GS_LOGO_MPEG;
TRACE("gGameState = GS_LOGO_MPEG;");
break;
}
case GS_LOGO_MPEG:
{
// CPad::UpdatePads();
// if (startupDeactivate || ControlsManager.GetJoyButtonJustDown() != 0)
++gGameState;
// else if (CPad::GetPad(0)->GetLeftMouseJustDown())
// ++gGameState;
// else if (CPad::GetPad(0)->GetEnterJustDown())
// ++gGameState;
// else if (CPad::GetPad(0)->GetCharJustDown(' '))
// ++gGameState;
// else if (CPad::GetPad(0)->GetAltJustDown())
// ++gGameState;
// else if (CPad::GetPad(0)->GetTabJustDown())
// ++gGameState;
break;
}
case GS_INIT_INTRO_MPEG:
{
//#ifndef NO_MOVIES
// CloseClip();
// CoUninitialize();
//#endif
//
// if (CMenuManager::OS_Language == LANG_FRENCH || CMenuManager::OS_Language == LANG_GERMAN)
// PlayMovieInWindow(cmdShow, "movies\\GTAtitlesGER.mpg");
// else
// PlayMovieInWindow(cmdShow, "movies\\GTAtitles.mpg");
gGameState = GS_INTRO_MPEG;
TRACE("gGameState = GS_INTRO_MPEG;");
break;
}
case GS_INTRO_MPEG:
{
// CPad::UpdatePads();
//
// if (startupDeactivate || ControlsManager.GetJoyButtonJustDown() != 0)
++gGameState;
// else if (CPad::GetPad(0)->GetLeftMouseJustDown())
// ++gGameState;
// else if (CPad::GetPad(0)->GetEnterJustDown())
// ++gGameState;
// else if (CPad::GetPad(0)->GetCharJustDown(' '))
// ++gGameState;
// else if (CPad::GetPad(0)->GetAltJustDown())
// ++gGameState;
// else if (CPad::GetPad(0)->GetTabJustDown())
// ++gGameState;
break;
}
case GS_INIT_ONCE:
{
//CoUninitialize();
#ifdef PS2_MENU
extern char version_name[64];
if ( CGame::frenchGame || CGame::germanGame )
LoadingScreen(NULL, version_name, "loadsc24");
else
LoadingScreen(NULL, version_name, "loadsc0");
printf("Into TheGame!!!\n");
#else
LoadingScreen(nil, nil, "loadsc0");
#endif
if ( !CGame::InitialiseOnceAfterRW() )
RsGlobal.quit = TRUE;
#ifdef PS2_MENU
gGameState = GS_INIT_PLAYING_GAME;
#else
gGameState = GS_INIT_FRONTEND;
TRACE("gGameState = GS_INIT_FRONTEND;");
#endif
break;
}
#ifndef PS2_MENU
case GS_INIT_FRONTEND:
{
LoadingScreen(nil, nil, "loadsc0");
FrontEndMenuManager.m_bGameNotLoaded = true;
CMenuManager::m_bStartUpFrontEndRequested = true;
if ( defaultFullscreenRes )
{
defaultFullscreenRes = FALSE;
FrontEndMenuManager.m_nPrefsVideoMode = GcurSelVM;
FrontEndMenuManager.m_nDisplayVideoMode = GcurSelVM;
}
gGameState = GS_FRONTEND;
TRACE("gGameState = GS_FRONTEND;");
break;
}
case GS_FRONTEND:
{
if(!glfwGetWindowAttrib(PSGLOBAL(window), GLFW_ICONIFIED))
RsEventHandler(rsFRONTENDIDLE, nil);
#ifdef PS2_MENU
if ( !FrontEndMenuManager.m_bMenuActive || TheMemoryCard.m_bWantToLoad )
#else
if ( !FrontEndMenuManager.m_bMenuActive || FrontEndMenuManager.m_bWantToLoad )
#endif
{
gGameState = GS_INIT_PLAYING_GAME;
TRACE("gGameState = GS_INIT_PLAYING_GAME;");
}
#ifdef PS2_MENU
if (TheMemoryCard.m_bWantToLoad )
#else
if ( FrontEndMenuManager.m_bWantToLoad )
#endif
{
InitialiseGame();
FrontEndMenuManager.m_bGameNotLoaded = false;
gGameState = GS_PLAYING_GAME;
TRACE("gGameState = GS_PLAYING_GAME;");
}
break;
}
#endif
case GS_INIT_PLAYING_GAME:
{
#ifdef PS2_MENU
CGame::Initialise("DATA\\GTA3.DAT");
//LoadingScreen("Starting Game", NULL, GetRandomSplashScreen());
if ( TheMemoryCard.CheckCardInserted(CARD_ONE) == CMemoryCard::NO_ERR_SUCCESS
&& TheMemoryCard.ChangeDirectory(CARD_ONE, TheMemoryCard.Cards[CARD_ONE].dir)
&& TheMemoryCard.FindMostRecentFileName(CARD_ONE, TheMemoryCard.MostRecentFile) == true
&& TheMemoryCard.CheckDataNotCorrupt(TheMemoryCard.MostRecentFile))
{
strcpy(TheMemoryCard.LoadFileName, TheMemoryCard.MostRecentFile);
TheMemoryCard.b_FoundRecentSavedGameWantToLoad = true;
if (CMenuManager::m_PrefsLanguage != TheMemoryCard.GetLanguageToLoad())
{
CMenuManager::m_PrefsLanguage = TheMemoryCard.GetLanguageToLoad();
TheText.Unload();
TheText.Load();
}
CGame::currLevel = (eLevelName)TheMemoryCard.GetLevelToLoad();
}
#else
InitialiseGame();
FrontEndMenuManager.m_bGameNotLoaded = false;
#endif
gGameState = GS_PLAYING_GAME;
TRACE("gGameState = GS_PLAYING_GAME;");
break;
}
case GS_PLAYING_GAME:
{
float ms = (float)CTimer::GetCurrentTimeInCycles() / (float)CTimer::GetCyclesPerMillisecond();
if ( RwInitialised )
{
if (!CMenuManager::m_PrefsFrameLimiter || (1000.0f / (float)RsGlobal.maxFPS) < ms)
RsEventHandler(rsIDLE, (void *)TRUE);
}
break;
}
#ifndef MASTER
case GS_ANIMVIEWER:
{
float ms = (float)CTimer::GetCurrentTimeInCycles() / (float)CTimer::GetCyclesPerMillisecond();
if (RwInitialised)
{
if (!CMenuManager::m_PrefsFrameLimiter || (1000.0f / (float)RsGlobal.maxFPS) < ms)
RsEventHandler(rsANIMVIEWER, (void*)TRUE);
}
break;
}
#endif
}
}
else
{
if ( RwCameraBeginUpdate(Scene.camera) )
{
RwCameraEndUpdate(Scene.camera);
ForegroundApp = TRUE;
RsEventHandler(rsACTIVATE, (void *)TRUE);
}
}
}
/*
* About to shut down - block resize events again...
*/
RwInitialised = FALSE;
FrontEndMenuManager.UnloadTextures();
#ifdef PS2_MENU
if ( !(FrontEndMenuManager.m_bWantToRestart || TheMemoryCard.b_FoundRecentSavedGameWantToLoad))
break;
#else
if ( !FrontEndMenuManager.m_bWantToRestart )
break;
#endif
CPad::ResetCheats();
CPad::StopPadsShaking();
DMAudio.ChangeMusicMode(MUSICMODE_DISABLE);
#ifdef PS2_MENU
CGame::ShutDownForRestart();
#endif
CTimer::Stop();
#ifdef PS2_MENU
if (FrontEndMenuManager.m_bWantToRestart || TheMemoryCard.b_FoundRecentSavedGameWantToLoad)
{
if (TheMemoryCard.b_FoundRecentSavedGameWantToLoad)
{
FrontEndMenuManager.m_bWantToRestart = true;
TheMemoryCard.m_bWantToLoad = true;
}
CGame::InitialiseWhenRestarting();
DMAudio.ChangeMusicMode(MUSICMODE_GAME);
FrontEndMenuManager.m_bWantToRestart = false;
continue;
}
CGame::ShutDown();
CTimer::Stop();
break;
#else
if ( FrontEndMenuManager.m_bWantToLoad )
{
CGame::ShutDownForRestart();
CGame::InitialiseWhenRestarting();
DMAudio.ChangeMusicMode(MUSICMODE_GAME);
LoadSplash(GetLevelSplashScreen(CGame::currLevel));
FrontEndMenuManager.m_bWantToLoad = false;
}
else
{
if ( gGameState == GS_PLAYING_GAME )
CGame::ShutDown();
#ifndef MASTER
else if ( gGameState == GS_ANIMVIEWER )
CAnimViewer::Shutdown();
#endif
CTimer::Stop();
if ( FrontEndMenuManager.m_bFirstTime == true )
{
gGameState = GS_INIT_FRONTEND;
TRACE("gGameState = GS_INIT_FRONTEND;");
}
else
{
gGameState = GS_INIT_PLAYING_GAME;
TRACE("gGameState = GS_INIT_PLAYING_GAME;");
}
}
FrontEndMenuManager.m_bFirstTime = false;
FrontEndMenuManager.m_bWantToRestart = false;
#endif
}
if ( gGameState == GS_PLAYING_GAME )
CGame::ShutDown();
#ifndef MASTER
else if ( gGameState == GS_ANIMVIEWER )
CAnimViewer::Shutdown();
#endif
DMAudio.Terminate();
_psFreeVideoModeList();
/*
* Tidy up the 3D (RenderWare) components of the application...
*/
RsEventHandler(rsRWTERMINATE, nil);
/*
* Free the platform dependent data...
*/
RsEventHandler(rsTERMINATE, nil);
#ifdef _WIN32
/*
* Free the argv strings...
*/
free(argv);
SystemParametersInfo(SPI_SETSTICKYKEYS, sizeof(STICKYKEYS), &SavedStickyKeys, SPIF_SENDCHANGE);
SystemParametersInfo(SPI_SETPOWEROFFACTIVE, TRUE, nil, SPIF_SENDCHANGE);
SystemParametersInfo(SPI_SETLOWPOWERACTIVE, TRUE, nil, SPIF_SENDCHANGE);
SetErrorMode(0);
#endif
return 0;
}
/*
*****************************************************************************
*/
RwV2d leftStickPos;
RwV2d rightStickPos;
void CapturePad(RwInt32 padID)
{
int8 glfwPad = -1;
if( padID == 0 )
glfwPad = PSGLOBAL(joy1id);
else if( padID == 1)
glfwPad = PSGLOBAL(joy2id);
else
assert("invalid padID");
if ( glfwPad == -1 )
return;
int numButtons, numAxes;
const uint8 *buttons = glfwGetJoystickButtons(glfwPad, &numButtons);
const float *axes = glfwGetJoystickAxes(glfwPad, &numAxes);
GLFWgamepadstate gamepadState;
if (ControlsManager.m_bFirstCapture == false)
{
memcpy(&ControlsManager.m_OldState, &ControlsManager.m_NewState, sizeof(ControlsManager.m_NewState));
}
ControlsManager.m_NewState.buttons = (uint8*)buttons;
ControlsManager.m_NewState.numButtons = numButtons;
ControlsManager.m_NewState.id = glfwPad;
ControlsManager.m_NewState.isGamepad = glfwJoystickIsGamepad(glfwPad);
if (ControlsManager.m_NewState.isGamepad) {
glfwGetGamepadState(glfwPad, &gamepadState);
memcpy(&ControlsManager.m_NewState.mappedButtons, gamepadState.buttons, sizeof(gamepadState.buttons));
ControlsManager.m_NewState.mappedButtons[15] = gamepadState.axes[4] > -0.8f;
ControlsManager.m_NewState.mappedButtons[16] = gamepadState.axes[5] > -0.8f;
}
// TODO I'm not sure how to find/what to do with L2-R2, if joystick isn't registered in SDL database.
if (ControlsManager.m_bFirstCapture == true) {
memcpy(&ControlsManager.m_OldState, &ControlsManager.m_NewState, sizeof(ControlsManager.m_NewState));
ControlsManager.m_bFirstCapture = false;
}
RsPadButtonStatus bs;
bs.padID = padID;
RsPadEventHandler(rsPADBUTTONUP, (void *)&bs);
// Gamepad axes are guaranteed to return 0.0f if that particular gamepad doesn't have that axis.
if ( glfwPad != -1 ) {
leftStickPos.x = ControlsManager.m_NewState.isGamepad ? gamepadState.axes[0] : numAxes >= 1 ? axes[0] : 0.0f;
leftStickPos.y = ControlsManager.m_NewState.isGamepad ? gamepadState.axes[1] : numAxes >= 2 ? axes[1] : 0.0f;
rightStickPos.x = ControlsManager.m_NewState.isGamepad ? gamepadState.axes[2] : numAxes >= 3 ? axes[2] : 0.0f;
rightStickPos.y = ControlsManager.m_NewState.isGamepad ? gamepadState.axes[3] : numAxes >= 4 ? axes[3] : 0.0f;
}
{
if (CPad::m_bMapPadOneToPadTwo)
bs.padID = 1;
RsPadEventHandler(rsPADBUTTONUP, (void *)&bs);
RsPadEventHandler(rsPADBUTTONDOWN, (void *)&bs);
}
{
if (CPad::m_bMapPadOneToPadTwo)
bs.padID = 1;
CPad *pad = CPad::GetPad(bs.padID);
if ( Abs(leftStickPos.x) > 0.3f )
pad->PCTempJoyState.LeftStickX = (int32)(leftStickPos.x * 128.0f);
if ( Abs(leftStickPos.y) > 0.3f )
pad->PCTempJoyState.LeftStickY = (int32)(leftStickPos.y * 128.0f);
if ( Abs(rightStickPos.x) > 0.3f )
pad->PCTempJoyState.RightStickX = (int32)(rightStickPos.x * 128.0f);
if ( Abs(rightStickPos.y) > 0.3f )
pad->PCTempJoyState.RightStickY = (int32)(rightStickPos.y * 128.0f);
}
return;
}
void joysChangeCB(int jid, int event)
{
if (event == GLFW_CONNECTED && !IsThisJoystickBlacklisted(jid)) {
if (PSGLOBAL(joy1id) == -1) {
PSGLOBAL(joy1id) = jid;
#ifdef DONT_TRUST_RECOGNIZED_JOYSTICKS
strcpy(gSelectedJoystickName, glfwGetJoystickName(jid));
#endif
} else if (PSGLOBAL(joy2id) == -1)
PSGLOBAL(joy2id) = jid;
} else if (event == GLFW_DISCONNECTED) {
if (PSGLOBAL(joy1id) == jid) {
PSGLOBAL(joy1id) = -1;
} else if (PSGLOBAL(joy2id) == jid)
PSGLOBAL(joy2id) = -1;
}
}
#if (defined(_MSC_VER))
int strcasecmp(const char* str1, const char* str2)
{
return _strcmpi(str1, str2);
}
#endif
#endif
|