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 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599
|
// ==============================================================
// This file is part of MegaGlest (www.glest.org)
//
// Copyright (C) 2011 - by Mark Vejvoda <mark_vejvoda@hotmail.com>
//
// You can redistribute this code and/or modify it under
// the terms of the GNU General Public License as published
// by the Free Software Foundation; either version 2 of the
// License, or (at your option) any later version
// ==============================================================
#include "main.h"
#include <stdexcept>
#include "model_gl.h"
#include "graphics_interface.h"
#include "util.h"
#include "conversion.h"
#include "platform_common.h"
#include "xml_parser.h"
#include <iostream>
#include <wx/event.h>
#include "config.h"
#include "game_constants.h"
#include <wx/stdpaths.h>
#include <platform_util.h>
#include "common_scoped_ptr.h"
#ifndef WIN32
#include <errno.h>
#endif
#ifndef WIN32
#define stricmp strcasecmp
#define strnicmp strncasecmp
#define _strnicmp strncasecmp
#endif
using namespace Shared::Platform;
using namespace Shared::PlatformCommon;
using namespace Shared::Graphics;
using namespace Shared::Graphics::Gl;
using namespace Shared::Util;
using namespace Shared::Xml;
using namespace std;
using namespace Glest::Game;
#ifdef _WIN32
const char *folderDelimiter = "\\";
#else
const char *folderDelimiter = "/";
#endif
//int GameConstants::updateFps= 40;
//int GameConstants::cameraFps= 100;
const string g3dviewerVersionString= "v3.13.0";
// Because g3d should always support alpha transparency
string fileFormat = "png";
namespace Glest { namespace Game {
string getGameReadWritePath(string lookupKey) {
string path = "";
if(path == "" && getenv("GLESTHOME") != NULL) {
path = safeCharPtrCopy(getenv("GLESTHOME"),8096);
if(path != "" && EndsWith(path, "/") == false && EndsWith(path, "\\") == false) {
path += "/";
}
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path to be used for read/write files [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str());
}
return path;
}
}}
namespace Shared{ namespace G3dViewer{
// ===============================================
// class Global functions
// ===============================================
wxString ToUnicode(const char* str) {
return wxString(str, wxConvUTF8);
}
wxString ToUnicode(const string& str) {
return wxString(str.c_str(), wxConvUTF8);
}
const wxChar *GAME_ARGS[] = {
wxT("--help"),
wxT("--auto-screenshot"),
wxT("--load-unit"),
wxT("--load-model"),
wxT("--load-model-animation-value"),
wxT("--load-particle"),
wxT("--load-projectile-particle"),
wxT("--load-splash-particle"),
wxT("--load-particle-loop-value"),
wxT("--zoom-value"),
wxT("--rotate-x-value"),
wxT("--rotate-y-value"),
wxT("--screenshot-format"),
wxT("--verbose"),
};
enum GAME_ARG_TYPE {
GAME_ARG_HELP = 0,
GAME_ARG_AUTO_SCREENSHOT,
GAME_ARG_LOAD_UNIT,
GAME_ARG_LOAD_MODEL,
GAME_ARG_LOAD_MODEL_ANIMATION_VALUE,
GAME_ARG_LOAD_PARTICLE,
GAME_ARG_LOAD_PARTICLE_PROJECTILE,
GAME_ARG_LOAD_PARTICLE_SPLASH,
GAME_ARG_LOAD_PARTICLE_LOOP_VALUE,
GAME_ARG_ZOOM_VALUE,
GAME_ARG_ROTATE_X_VALUE,
GAME_ARG_ROTATE_Y_VALUE,
GAME_ARG_SCREENSHOT_FORMAT,
GAME_ARG_VERBOSE,
};
bool hasCommandArgument(int argc, wxChar** argv,const string &argName,
int *foundIndex=NULL, int startLookupIndex=1,
bool useArgParamLen=false) {
bool result = false;
if(foundIndex != NULL) {
*foundIndex = -1;
}
size_t compareLen = strlen(argName.c_str());
for(int idx = startLookupIndex; idx < argc; idx++) {
const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(argv[idx]);
//printf("tmp_buf [%s]\n",(const char *)tmp_buf);
if(useArgParamLen == true) {
compareLen = strlen(tmp_buf);
}
if(_strnicmp(argName.c_str(),tmp_buf,compareLen) == 0) {
result = true;
if(foundIndex != NULL) {
*foundIndex = idx;
}
break;
}
}
return result;
}
void printParameterHelp(const char *argv0, bool foundInvalidArgs) {
if(foundInvalidArgs == true) {
printf("\n");
}
// "================================================================================"
printf("\n%s %s, [Using %s] usage:\n",extractFileFromDirectoryPath(argv0).c_str(),g3dviewerVersionString.c_str(),(const char *)wxConvCurrent->cWX2MB(wxVERSION_STRING));
printf("\n%s [G3D FILE]\n\n",extractFileFromDirectoryPath(argv0).c_str());
printf("Displays glest 3D-models and unit/projectile/splash particle systems.\n");
printf("rotate with left mouse button, zoom with right mouse button or mousewheel.\n");
printf("Use ctrl to load more than one particle system.\n");
printf("Press R to restart particles, this also reloads all files if they are changed.\n\n");
printf("optionally you may use any of the following:\n");
printf("Parameter:\t\t\tDescription:");
printf("\n----------------------\t\t------------");
printf("\n%s\t\t\t\tdisplays this help text.",(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_HELP]));
// "================================================================================"
printf("\n%s=x",(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_UNIT]));
printf("\n \t\tAuto load the unit / skill information specified");
printf("\n \t\tin path/filename x");
printf("\n \t\tWhere x is a g3d filename to load separated with a");
printf("\n \t\tcomma and one or more skill names to try loading:");
printf("\n \t\texample:");
printf("\n %s\n %s=techs/megapack/factions/tech/units/battle_machine,attack_skill,stop_skill",extractFileFromDirectoryPath(argv0).c_str(),(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_UNIT]));
printf("\n%s=x\t\t\tAuto load the model specified in path/filename x",(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_MODEL]));
printf("\n \t\tWhere x is a g3d filename to load:");
printf("\n \t\texample:");
printf("\n %s\n %s=techs/megapack/factions/tech/units/battle_machine/models/battle_machine_dying.g3d",extractFileFromDirectoryPath(argv0).c_str(),(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_MODEL]));
printf("\n%s=x\tAnimation value when loading a model",(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_MODEL_ANIMATION_VALUE]));
printf("\n \t\tWhere x is a decimal value from -1.0 to 1.0:");
printf("\n \t\texample:");
printf("\n %s %s=0.5",extractFileFromDirectoryPath(argv0).c_str(),(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_MODEL_ANIMATION_VALUE]));
// "================================================================================"
printf("\n%s=x",(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_AUTO_SCREENSHOT]));
printf("\n \t\tAutomatically takes a screenshot of the items you");
printf("\n \t\tare loading.");
printf("\n \t\tWhere x is a comma-delimited list of one or more");
printf("\n \t\t of the optional settings:");
printf("\n \t\ttransparent, enable_grid, enable_wireframe,");
printf("\n \t\tenable_normals, disable_grid, disable_wireframe,");
printf("\n \t\tdisable_normals, saveas-<filename>, resize-wxh");
printf("\n \t\texample:");
printf("\n %s\n %s=transparent,disable_grid,saveas-test.png,resize-800x600\n %s=techs/megapack/factions/tech/units/battle_machine/models/battle_machine_dying.g3d",extractFileFromDirectoryPath(argv0).c_str(),(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_AUTO_SCREENSHOT]),(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_MODEL]));
// "================================================================================"
printf("\n%s=x",(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_PARTICLE]));
printf("\n \t\tAuto load the particle specified in path/filename x");
printf("\n \t\tWhere x is a Particle XML filename to load:");
printf("\n \t\texample:");
printf("\n %s\n %s=techs/megapack/factions/persian/units/genie/glow_particles.xml",extractFileFromDirectoryPath(argv0).c_str(),(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_PARTICLE]));
printf("\n%s=x",(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_PARTICLE_PROJECTILE]));
printf("\n \t\tAuto load the projectile particle specified in");
printf("\n \t\tpath/filename x");
printf("\n \t\tWhere x is a Projectile Particle Definition XML");
printf("\n \t\t filename to load:");
printf("\n \t\texample:");
printf("\n %s\n %s=techs/megapack/factions/persian/units/genie/particle_proj.xml",extractFileFromDirectoryPath(argv0).c_str(),(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_PARTICLE_PROJECTILE]));
printf("\n%s=x",(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_PARTICLE_SPLASH]));
printf("\n \t\tAuto load the splash particle specified in");
printf("\n \t\tpath/filename x");
printf("\n \t\tWhere x is a Splash Particle Definition XML");
printf("\n \t\t filename to load:");
printf("\n \t\texample:");
printf("\n %s\n %s=techs/megapack/factions/persian/units/genie/particle_splash.xml",extractFileFromDirectoryPath(argv0).c_str(),(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_PARTICLE_SPLASH]));
printf("\n%s=x",(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_PARTICLE_LOOP_VALUE]));
printf("\n \t\tParticle loop value when loading one or more");
printf("\n \t\tparticles");
printf("\n \t\tWhere x is an integer value from 1 to particle count:");
printf("\n \t\texample:");
printf("\n %s %s=25",extractFileFromDirectoryPath(argv0).c_str(),(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_PARTICLE_LOOP_VALUE]));
printf("\n%s=x\t\t\tZoom value when loading a model",(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_ZOOM_VALUE]));
printf("\n \t\tWhere x is a decimal value from 0.1 to 10.0:");
printf("\n \t\texample:");
printf("\n %s %s=4.2",extractFileFromDirectoryPath(argv0).c_str(),(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_ZOOM_VALUE]));
printf("\n%s=x\t\tX Coordinate Rotation value when loading a model",(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_ROTATE_X_VALUE]));
printf("\n \t\tWhere x is a decimal value from -10.0 to 10.0:");
printf("\n \t\texample:");
printf("\n %s %s=2.2",extractFileFromDirectoryPath(argv0).c_str(),(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_ROTATE_X_VALUE]));
printf("\n%s=x\t\tY Coordinate Rotation value when loading a model",(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_ROTATE_Y_VALUE]));
printf("\n \t\tWhere x is a decimal value from -10.0 to 10.0:");
printf("\n \t\texample:");
printf("\n %s %s=2.2",extractFileFromDirectoryPath(argv0).c_str(),(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_ROTATE_Y_VALUE]));
printf("\n%s=x\t\tSpecify which image format to use for screenshots.",(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_SCREENSHOT_FORMAT]));
printf("\n \t\tWhere x is one of the following supported formats");
printf("\n \t\tpng,jpg,tga,bmp");
printf("\n \t\t*NOTE: png is the default (and supports transparency)");
printf("\n \t\texample:");
printf("\n %s %s=jpg",extractFileFromDirectoryPath(argv0).c_str(),(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_SCREENSHOT_FORMAT]));
printf("\n\n");
}
bool autoScreenShotAndExit = false;
vector<string> autoScreenShotParams;
std::pair<int,int> overrideSize(0,0);
// ===============================================
// class MainWindow
// ===============================================
const string MainWindow::winHeader= "G3D viewer " + g3dviewerVersionString;
const float defaultspeed = 0.025f;
MainWindow::MainWindow( std::pair<string,vector<string> > unitToLoad,
const string modelPath,
const string particlePath,
const string projectileParticlePath,
const string splashParticlePath,
float defaultAnimation,
int defaultParticleLoopStart,
float defaultZoom,float defaultXRot, float defaultYRot,
string appPath)
: wxFrame(NULL, -1, ToUnicode(winHeader),
wxPoint(Renderer::windowX, Renderer::windowY),
wxSize(Renderer::windowW, Renderer::windowH)),
glCanvas(NULL),
renderer(NULL),
timer(NULL),
menu(NULL),
fileDialog(NULL),
colorPicker(NULL),
model(NULL),
initTextureManager(true),
startupSettingsInited(false)
{
this->appPath = appPath;
Properties::setApplicationPath(executable_path(appPath));
lastanim = 0;
model= NULL;
Config &config = Config::getInstance();
isControlKeyPressed = false;
initGlCanvas();
#if wxCHECK_VERSION(2, 9, 1)
#else
glCanvas->SetCurrent();
#endif
unitPath = unitToLoad;
if(modelPath != "") {
this->modelPathList.push_back(modelPath);
printf("Startup Adding model [%s] list size " MG_SIZE_T_SPECIFIER "\n",modelPath.c_str(),this->modelPathList.size());
}
if(particlePath != "") {
this->particlePathList.push_back(particlePath);
}
if(projectileParticlePath != "") {
this->particleProjectilePathList.push_back(projectileParticlePath);
}
if(splashParticlePath != "") {
this->particleSplashPathList.push_back(splashParticlePath);
}
resetAnimation = false;
anim = defaultAnimation;
particleLoopStart = defaultParticleLoopStart;
resetAnim = anim;
resetParticleLoopStart = particleLoopStart;
rotX= defaultXRot;
rotY= defaultYRot;
zoom= defaultZoom;
playerColor= Renderer::pcRed;
speed= defaultspeed;
//getGlPlatformExtensions();
menu= new wxMenuBar();
//menu
menuFile= new wxMenu();
menuFile->Append(miFileLoad, wxT("&Load G3d model\tCtrl+L"), wxT("Load 3D model"));
menuFile->Append(miFileLoadParticleXML, wxT("Load &Particle XML\tCtrl+P"), wxT("Press ctrl before menu for keeping current particles"));
menuFile->Append(miFileLoadProjectileParticleXML, wxT("Load Pro&jectile Particle XML\tCtrl+J"), wxT("Press ctrl before menu for keeping current projectile particles"));
menuFile->Append(miFileLoadSplashParticleXML, wxT("Load &Splash Particle XML\tCtrl+S"), wxT("Press ctrl before menu for keeping current splash particles"));
menuFile->Append(miFileClearAll, wxT("&Clear All\tCtrl+C"));
menuFile->AppendCheckItem(miFileToggleScreenshotTransparent, wxT("&Transparent Screenshots\tCtrl+T"));
menuFile->Append(miFileSaveScreenshot, wxT("Sa&ve a Screenshot\tCtrl+V"));
menuFile->AppendSeparator();
menuFile->Append(wxID_EXIT);
menu->Append(menuFile, wxT("&File"));
//mode
menuMode= new wxMenu();
menuMode->AppendCheckItem(miModeNormals, wxT("&Normals"));
menuMode->AppendCheckItem(miModeWireframe, wxT("&Wireframe"));
menuMode->AppendCheckItem(miModeGrid, wxT("&Grid"));
menu->Append(menuMode, wxT("&Mode"));
//mode
menuSpeed= new wxMenu();
menuSpeed->Append(miSpeedSlower, wxT("&Slower\t-"));
menuSpeed->Append(miSpeedFaster, wxT("&Faster\t+"));
menuSpeed->AppendSeparator();
menuSpeed->Append(miRestart, wxT("&Restart particles\tR"), wxT("Restart particle animations, this also reloads model and particle files if they are changed"));
menu->Append(menuSpeed, wxT("&Speed"));
//custom color
menuCustomColor= new wxMenu();
menuCustomColor->Append(miChangeBackgroundColor, wxT("Change Background Color"));
menuCustomColor->AppendCheckItem(miColorRed, wxT("&Red\t0"));
menuCustomColor->AppendCheckItem(miColorBlue, wxT("&Blue\t1"));
menuCustomColor->AppendCheckItem(miColorGreen, wxT("&Green\t2"));
menuCustomColor->AppendCheckItem(miColorYellow, wxT("&Yellow\t3"));
menuCustomColor->AppendCheckItem(miColorWhite, wxT("&White\t4"));
menuCustomColor->AppendCheckItem(miColorCyan, wxT("&Cyan\t5"));
menuCustomColor->AppendCheckItem(miColorOrange, wxT("&Orange\t6"));
menuCustomColor->AppendCheckItem(miColorMagenta, wxT("&Pink\t7")); // it is called Pink everywhere else so...
menu->Append(menuCustomColor, wxT("&Custom Color"));
menuMode->Check(miModeGrid, true);
menuCustomColor->Check(miColorRed, true);
SetMenuBar(menu);
//misc
backBrightness= 0.3f;
gridBrightness= 1.0f;
lightBrightness= 0.3f;
lastX= 0;
lastY= 0;
statusbarText="";
CreateStatusBar();
this->Layout();
wxInitAllImageHandlers();
#ifdef WIN32
#if defined(__MINGW32__)
wxIcon icon(ToUnicode("IDI_ICON1"));
#else
wxIcon icon(L"IDI_ICON1");
#endif
#else
wxIcon icon;
string iniFilePath = extractDirectoryPathFromFile(config.getFileName(false));
string icon_file = iniFilePath + "g3dviewer.ico";
std::ifstream testFile(icon_file.c_str());
if(testFile.good()) {
testFile.close();
icon.LoadFile(ToUnicode(icon_file.c_str()),wxBITMAP_TYPE_ICO);
}
#endif
SetIcon(icon);
fileDialog = new wxFileDialog(this);
if(modelPath != "") {
fileDialog->SetPath(ToUnicode(modelPath));
}
string userData = config.getString("UserData_Root","");
if(userData != "") {
endPathWithSlash(userData);
}
string defaultPath = userData + "techs/";
fileDialog->SetDirectory(ToUnicode(defaultPath.c_str()));
if(glCanvas != NULL) {
glCanvas->SetFocus();
}
// For windows register g3d file extension to launch this app
#if defined(WIN32) && !defined(__MINGW32__)
// example from: http://stackoverflow.com/questions/1387769/create-registry-entry-to-associate-file-extension-with-application-in-c
//[HKEY_CURRENT_USER\Software\Classes\blergcorp.blergapp.v1\shell\open\command]
//@="c:\path\to\app.exe \"%1\""
//[HKEY_CURRENT_USER\Software\Classes\.blerg]
//@="blergcorp.blergapp.v1"
//Open the registry key.
wstring subKey = L"Software\\Classes\\megaglest.g3d\\shell\\open\\command";
HKEY keyHandle;
DWORD dwDisposition;
RegCreateKeyEx(HKEY_CURRENT_USER,subKey.c_str(),0, NULL, 0, KEY_ALL_ACCESS, NULL, &keyHandle, &dwDisposition);
//Set the value.
auto_ptr<wchar_t> wstr(Ansi2WideString(appPath.c_str()));
wstring launchApp = wstring(wstr.get()) + L" \"%1\"";
DWORD len = (launchApp.size() + 1) * sizeof(wchar_t);
RegSetValueEx(keyHandle, NULL, 0, REG_SZ, (PBYTE)launchApp.c_str(), len);
RegCloseKey(keyHandle);
subKey = L"Software\\Classes\\.g3d";
RegCreateKeyEx(HKEY_CURRENT_USER,subKey.c_str(),0, NULL, 0, KEY_ALL_ACCESS, NULL, &keyHandle, &dwDisposition);
//Set the value.
launchApp = L"megaglest.g3d";
len = (launchApp.size() + 1) * sizeof(wchar_t);
RegSetValueEx(keyHandle, NULL, 0, REG_SZ, (PBYTE)launchApp.c_str(), len);
RegCloseKey(keyHandle);
#endif
}
void MainWindow::setupTimer() {
timer = new wxTimer(this);
timer->Start(100);
}
void MainWindow::setupStartupSettings() {
//printf("In setupStartupSettings #1\n");
if(glCanvas == NULL) {
initGlCanvas();
#if wxCHECK_VERSION(2, 9, 1)
#else
glCanvas->SetCurrent();
#endif
}
glCanvas->setCurrentGLContext();
//printf("In setupStartupSettings #2\n");
GLuint err = glewInit();
if (GLEW_OK != err) {
fprintf(stderr, "Error [main]: glewInit failed: %s\n", glewGetErrorString(err));
//return 1;
throw std::runtime_error((char *)glewGetErrorString(err));
}
renderer= Renderer::getInstance();
for(unsigned int i = 0; i < autoScreenShotParams.size(); ++i) {
if(autoScreenShotParams[i] == "transparent") {
printf("Screenshot option [%s]\n",autoScreenShotParams[i].c_str());
menuFile->Check(miFileToggleScreenshotTransparent,true);
float alpha = 0.0f;
renderer->setAlphaColor(alpha);
}
if(autoScreenShotParams[i] == "enable_grid") {
printf("Screenshot option [%s]\n",autoScreenShotParams[i].c_str());
menuMode->Check(miModeGrid,true);
if(renderer->getGrid() == false) {
renderer->toggleGrid();
}
}
if(autoScreenShotParams[i] == "enable_wireframe") {
printf("Screenshot option [%s]\n",autoScreenShotParams[i].c_str());
menuMode->Check(miModeWireframe,true);
if(renderer->getWireframe() == false) {
renderer->toggleWireframe();
}
}
if(autoScreenShotParams[i] == "enable_normals") {
printf("Screenshot option [%s]\n",autoScreenShotParams[i].c_str());
menuMode->Check(miModeNormals,true);
if(renderer->getNormals() == false) {
renderer->toggleNormals();
}
}
if(autoScreenShotParams[i] == "disable_grid") {
printf("Screenshot option [%s]\n",autoScreenShotParams[i].c_str());
menuMode->Check(miModeGrid,false);
if(renderer->getGrid() == true) {
renderer->toggleGrid();
}
}
if(autoScreenShotParams[i] == "enable_wireframe") {
printf("Screenshot option [%s]\n",autoScreenShotParams[i].c_str());
menuMode->Check(miModeWireframe,false);
if(renderer->getWireframe() == true) {
renderer->toggleWireframe();
}
}
if(autoScreenShotParams[i] == "enable_normals") {
printf("Screenshot option [%s]\n",autoScreenShotParams[i].c_str());
menuMode->Check(miModeNormals,false);
if(renderer->getNormals() == true) {
renderer->toggleNormals();
}
}
}
renderer->init();
wxCommandEvent event;
onMenuRestartNoEvent();
}
MainWindow::~MainWindow(){
delete timer;
timer = NULL;
delete fileDialog;
fileDialog = NULL;
//delete model;
//model = NULL;
if(renderer) renderer->end();
delete renderer;
renderer = NULL;
if(glCanvas) {
glCanvas->Destroy();
}
glCanvas = NULL;
}
void MainWindow::initGlCanvas(){
if(glCanvas == NULL) {
int args[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_MIN_ALPHA, 8, 0 }; // to prevent flicker
glCanvas = new GlCanvas(this, args);
}
}
void MainWindow::init() {
#if wxCHECK_VERSION(2, 9, 3)
#elif wxCHECK_VERSION(2, 9, 1)
#else
glCanvas->SetCurrent();
//printf("setcurrent #2\n");
#endif
}
void MainWindow::onPaint(wxPaintEvent &event) {
if(!IsShown()) {
event.Skip();
return;
}
onPaintNoEvent( );
}
void MainWindow::onPaintNoEvent( ) {
bool isFirstWindowShownEvent = !startupSettingsInited ;
if(startupSettingsInited == false) {
startupSettingsInited = true;
setupStartupSettings();
}
glCanvas->setCurrentGLContext();
static float autoScreenshotRender = -1;
if(autoScreenShotAndExit == true && autoScreenshotRender >= 0) {
anim = autoScreenshotRender;
}
// notice that we use GetSize() here and not GetClientSize() because
// the latter doesn't return correct results for the minimized windows
// (at least not under Windows)
int viewportW = GetClientSize().x;
int viewportH = GetClientSize().y;
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("%d x %d\n",viewportW,viewportH);
if(viewportW == 0 && viewportH == 0) {
printf("#1 %d x %d\n",viewportW,viewportH);
viewportW = GetSize().x;
viewportH = GetSize().y;
if(viewportH > 0) {
//viewportH -= menu->GetSize().y;
viewportH -= 22;
}
printf("#2 %d x %d\n",viewportW,viewportH);
}
#if defined(WIN32)
renderer->reset(viewportW, viewportH, playerColor);
#else
renderer->reset(viewportW, viewportH, playerColor);
#endif
renderer->transform(rotX, rotY, zoom);
renderer->renderGrid();
//printf("anim [%f] particleLoopStart [%d]\n",anim,particleLoopStart);
string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " anim value: " + floatToStr(anim) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY);
GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str()));
renderer->renderTheModel(model, anim);
int updateLoops = particleLoopStart;
particleLoopStart = 1;
if(resetAnimation == true || ((anim - lastanim) >= defaultspeed*2)) {
//printf("anim [%f] [%f] [%f]\n",anim,lastanim,speed);
for(int i=0; i< updateLoops; ++i) {
renderer->updateParticleManager();
}
}
renderer->renderParticleManager();
if(isFirstWindowShownEvent) {
this->Refresh();
glCanvas->Refresh();
glCanvas->SetFocus();
}
bool haveLoadedParticles = (particleProjectilePathList.empty() == false || particleSplashPathList.empty() == false);
if(autoScreenShotAndExit == true && viewportW > 0 && viewportH > 0) {
printf("Auto exiting app...\n");
fflush(stdout);
autoScreenShotAndExit = false;
saveScreenshot();
Close();
return;
}
glCanvas->SwapBuffers();
if(autoScreenShotAndExit == true && viewportW == 0 && viewportH == 0) {
autoScreenshotRender = anim;
printf("Auto exiting desired but waiting for w x h > 0...\n");
return;
}
if((modelPathList.empty() == false) && resetAnimation && haveLoadedParticles) {
if(anim >= resetAnim && resetAnim > 0) {
printf("RESETTING EVERYTHING [%f][%f]...\n",anim,resetAnim);
fflush(stdout);
resetAnimation = false;
particleLoopStart = resetParticleLoopStart;
if(unitPath.first != "") {
//onMenuFileClearAll(event);
modelPathList.clear();
particlePathList.clear();
particleProjectilePathList.clear();
particleSplashPathList.clear(); // as above
}
onMenuRestartNoEvent();
}
}
else if(modelPathList.empty() == true && haveLoadedParticles) {
if(renderer->hasActiveParticleSystem(ParticleSystem::pst_ProjectileParticleSystem) == false &&
renderer->hasActiveParticleSystem(ParticleSystem::pst_SplashParticleSystem) == false) {
printf("RESETTING PARTICLES...\n");
fflush(stdout);
resetAnimation = false;
anim = 0.f;
particleLoopStart = resetParticleLoopStart;
wxCommandEvent event;
onMenuRestartNoEvent();
}
}
lastanim = anim;
}
void MainWindow::onClose(wxCloseEvent &event){
// release memory first (from onMenuFileClearAll)
//printf("OnClose START\n");
//fflush(stdout);
modelPathList.clear();
particlePathList.clear();
particleProjectilePathList.clear();
particleSplashPathList.clear(); // as above
if(timer) timer->Stop();
unitParticleSystems.clear();
unitParticleSystemTypes.clear();
projectileParticleSystems.clear();
projectileParticleSystemTypes.clear();
splashParticleSystems.clear(); // as above
splashParticleSystemTypes.clear();
//delete model;
//model = NULL;
if(renderer) renderer->end();
//printf("OnClose about to END\n");
//fflush(stdout);
delete timer;
timer = NULL;
//delete model;
//model = NULL;
delete renderer;
renderer = NULL;
//delete glCanvas;
if(glCanvas) {
glCanvas->Destroy();
}
glCanvas = NULL;
this->Destroy();
}
// for the mousewheel
void MainWindow::onMouseWheelDown(wxMouseEvent &event) {
try {
zoom*= 1.1f;
zoom= clamp(zoom, 0.1f, 10.0f);
string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " anim value: " + floatToStr(anim) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY);
GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str()));
onPaintNoEvent();
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMouseWheelUp(wxMouseEvent &event) {
try {
zoom*= 0.90909f;
zoom= clamp(zoom, 0.1f, 10.0f);
string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " anim value: " + floatToStr(anim) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY);
GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str()));
onPaintNoEvent();
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMouseMove(wxMouseEvent &event){
try {
int x= event.GetX();
int y= event.GetY();
if(event.LeftIsDown()){
rotX+= clamp(lastX-x, -10, 10);
rotY+= clamp(lastY-y, -10, 10);
string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " anim value: " + floatToStr(anim) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY);
GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str()));
onPaintNoEvent();
}
else if(event.RightIsDown()){
zoom*= 1.0f+(lastX-x+lastY-y)/100.0f;
zoom= clamp(zoom, 0.1f, 10.0f);
string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " anim value: " + floatToStr(anim) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY);
GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str()));
onPaintNoEvent();
}
lastX= x;
lastY= y;
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuFileLoad(wxCommandEvent &event){
try {
//string fileName;
fileDialog->SetWildcard(wxT("G3D files (*.g3d)|*.g3d;*.G3D"));
fileDialog->SetMessage(wxT("Selecting Glest Model for current view."));
if(fileDialog->ShowModal()==wxID_OK){
modelPathList.clear();
string file;
#ifdef WIN32
const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(fileDialog->GetPath());
file = tmp_buf;
auto_ptr<wchar_t> wstr(Ansi2WideString(file.c_str()));
file = utf8_encode(wstr.get());
#else
file = (const char*)wxFNCONV(fileDialog->GetPath().c_str());
#endif
//loadModel((const char*)wxFNCONV(fileDialog->GetPath().c_str()));
loadModel(file);
}
isControlKeyPressed = false;
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuFileLoadParticleXML(wxCommandEvent &event){
try {
//string fileName;
fileDialog->SetWildcard(wxT("XML files (*.xml)|*.xml"));
if(isControlKeyPressed == true) {
fileDialog->SetMessage(wxT("Adding Mega-Glest particle to current view."));
}
else {
fileDialog->SetMessage(wxT("Selecting Mega-Glest particle for current view."));
}
if(fileDialog->ShowModal()==wxID_OK){
//string path = (const char*)wxFNCONV(fileDialog->GetPath().c_str());
string file;
#ifdef WIN32
const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(fileDialog->GetPath());
file = tmp_buf;
auto_ptr<wchar_t> wstr(Ansi2WideString(file.c_str()));
file = utf8_encode(wstr.get());
#else
file = (const char*)wxFNCONV(fileDialog->GetPath().c_str());
#endif
loadParticle(file);
}
isControlKeyPressed = false;
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuFileLoadProjectileParticleXML(wxCommandEvent &event){
try {
//string fileName;
fileDialog->SetWildcard(wxT("XML files (*.xml)|*.xml"));
if(isControlKeyPressed == true) {
fileDialog->SetMessage(wxT("Adding Mega-Glest projectile particle to current view."));
}
else {
fileDialog->SetMessage(wxT("Selecting Mega-Glest projectile particle for current view."));
}
if(fileDialog->ShowModal()==wxID_OK){
//string path = (const char*)wxFNCONV(fileDialog->GetPath().c_str());
string file;
#ifdef WIN32
const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(fileDialog->GetPath());
file = tmp_buf;
auto_ptr<wchar_t> wstr(Ansi2WideString(file.c_str()));
file = utf8_encode(wstr.get());
#else
file = (const char*)wxFNCONV(fileDialog->GetPath().c_str());
#endif
loadProjectileParticle(file);
}
isControlKeyPressed = false;
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuFileLoadSplashParticleXML(wxCommandEvent &event){
try {
//string fileName;
fileDialog->SetWildcard(wxT("XML files (*.xml)|*.xml"));
if(isControlKeyPressed == true) {
fileDialog->SetMessage(wxT("Adding Mega-Glest splash particle to current view."));
}
else {
fileDialog->SetMessage(wxT("Selecting Mega-Glest splash particle for current view."));
}
if(fileDialog->ShowModal()==wxID_OK){
//string path = (const char*)wxFNCONV(fileDialog->GetPath().c_str());
string file;
#ifdef WIN32
const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(fileDialog->GetPath());
file = tmp_buf;
auto_ptr<wchar_t> wstr(Ansi2WideString(file.c_str()));
file = utf8_encode(wstr.get());
#else
file = (const char*)wxFNCONV(fileDialog->GetPath().c_str());
#endif
loadSplashParticle(file);
}
isControlKeyPressed = false;
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
} // is it possible to join loadParticle(), loadProjectileParticle() and loadSplashParticle() to one method?
void MainWindow::OnChangeColor(wxCommandEvent &event) {
try {
//wxColour color = colorPicker->GetColour();
wxColourData data;
data.SetChooseFull(true);
for (int i = 0; i < 16; i++)
{
wxColour colour(i*16, i*16, i*16);
data.SetCustomColour(i, colour);
}
wxColourDialog dialog(this, &data);
if (dialog.ShowModal() == wxID_OK)
{
wxColourData retData = dialog.GetColourData();
wxColour col = retData.GetColour();
renderer->setBackgroundColor(col.Red()/255.0f, col.Green()/255.0f, col.Blue()/255.0f);
}
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenumFileToggleScreenshotTransparent(wxCommandEvent &event) {
try {
float alpha = (event.IsChecked() == true ? 0.0f : 1.0f);
renderer->setAlphaColor(alpha);
//printf("alpha = %f\n",alpha);
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::saveScreenshot() {
try {
int autoSaveScreenshotIndex = -1;
for(unsigned int i = 0; i < autoScreenShotParams.size(); ++i) {
if(_strnicmp(autoScreenShotParams[i].c_str(),"saveas-",7) == 0) {
printf("Screenshot option [%s]\n",autoScreenShotParams[i].c_str());
autoSaveScreenshotIndex = i;
break;
}
}
if(autoSaveScreenshotIndex >= 0) {
string saveAsFilename = autoScreenShotParams[autoSaveScreenshotIndex];
saveAsFilename.erase(0,7);
#ifdef WIN32
FILE*f = _wfopen(utf8_decode(saveAsFilename).c_str(), L"rb");
#else
FILE *f= fopen(saveAsFilename.c_str(), "rb");
#endif
if(f == NULL) {
renderer->saveScreen(saveAsFilename.c_str(),&overrideSize);
}
else {
if(f) {
fclose(f);
}
}
}
else {
//string screenShotsPath = extractDirectoryPathFromFile(appPath) + string("screens/");
string userData = Config::getInstance().getString("UserData_Root","");
if(userData != "") {
endPathWithSlash(userData);
}
string screenShotsPath = userData + string("screens/");
printf("screenShotsPath [%s]\n",screenShotsPath.c_str());
if(isdir(screenShotsPath.c_str()) == false) {
createDirectoryPaths(screenShotsPath);
}
string path = screenShotsPath;
if(isdir(path.c_str()) == true) {
//Config &config= Config::getInstance();
//string fileFormat = config.getString("ScreenShotFileType","jpg");
for(int i=0; i < 5000; ++i) {
path = screenShotsPath;
path += string("screen") + intToStr(i) + string(".") + fileFormat;
#ifdef WIN32
FILE*f= _wfopen(utf8_decode(path).c_str(), L"rb");
#else
FILE *f= fopen(path.c_str(), "rb");
#endif
if(f == NULL) {
renderer->saveScreen(path,&overrideSize);
break;
}
else {
if(f) {
fclose(f);
}
}
}
}
}
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuFileSaveScreenshot(wxCommandEvent &event) {
saveScreenshot();
}
void MainWindow::onMenuFileClearAll(wxCommandEvent &event) {
try {
//printf("Start onMenuFileClearAll\n");
//fflush(stdout);
modelPathList.clear();
particlePathList.clear();
particleProjectilePathList.clear();
particleSplashPathList.clear(); // as above
if(timer) timer->Stop();
if(renderer) renderer->end();
unitParticleSystems.clear();
unitParticleSystemTypes.clear();
projectileParticleSystems.clear();
projectileParticleSystemTypes.clear();
splashParticleSystems.clear(); // as above
splashParticleSystemTypes.clear();
//delete model;
//model = NULL;
if(model != NULL && renderer != NULL) renderer->endModel(rsGlobal, model);
model = NULL;
loadUnit("","");
loadModel("");
loadParticle("");
loadProjectileParticle("");
loadSplashParticle(""); // as above
GetStatusBar()->SetStatusText(ToUnicode(statusbarText.c_str()));
isControlKeyPressed = false;
//printf("END onMenuFileClearAll\n");
//fflush(stdout);
if(timer) timer->Start(100);
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuFileExit(wxCommandEvent &event) {
Close();
}
void MainWindow::loadUnit(string path, string skillName) {
if(path != "" && fileExists(path) == true) {
// std::cout << "Clearing list..." << std::endl;
this->unitPath.first = path;
this->unitPath.second.push_back(skillName);
}
try{
if(this->unitPath.first != "") {
if(timer) timer->Stop();
if(renderer) renderer->end();
string titlestring = winHeader;
string unitPath = this->unitPath.first;
string dir = unitPath;
string name= lastDir(dir);
string path= dir + "/" + name + ".xml";
titlestring = unitPath + " - "+ titlestring;
std::string unitXML = path;
string skillModelFile = "";
string skillParticleFile = "";
string skillParticleProjectileFile = "";
string skillParticleSplashFile = "";
bool fileFound = fileExists(unitXML);
printf("Loading unit from file [%s] fileFound = %d\n",unitXML.c_str(),fileFound);
if(fileFound == true) {
XmlTree xmlTree;
xmlTree.load(unitXML,Properties::getTagReplacementValues());
const XmlNode *unitNode= xmlTree.getRootNode();
bool foundSkillName = false;
for(unsigned int skillIdx = 0; foundSkillName == false && skillIdx < this->unitPath.second.size(); ++skillIdx) {
string lookipForSkillName = this->unitPath.second[skillIdx];
const XmlNode *skillsNode= unitNode->getChild("skills");
for(unsigned int i = 0; foundSkillName == false && i < skillsNode->getChildCount(); ++i) {
const XmlNode *sn= skillsNode->getChild("skill", i);
//const XmlNode *typeNode= sn->getChild("type");
const XmlNode *nameNode= sn->getChild("name");
string skillXmlName = nameNode->getAttribute("value")->getRestrictedValue();
if(skillXmlName == lookipForSkillName) {
printf("Found skill [%s]\n",lookipForSkillName.c_str());
foundSkillName = true;
if(sn->getChild("animation") != NULL) {
skillModelFile = sn->getChild("animation")->getAttribute("path")->getRestrictedValue(unitPath + '/');
printf("Found skill model [%s]\n",skillModelFile.c_str());
}
if(sn->hasChild("particles") == true) {
const XmlNode *particlesNode= sn->getChild("particles");
//for(int j = 0; particlesNode != NULL && particlesNode->getAttribute("value")->getRestrictedValue() == "true" &&
// j < particlesNode->getChildCount(); ++j) {
if(particlesNode != NULL && particlesNode->getAttribute("value")->getRestrictedValue() == "true" &&
particlesNode->hasChild("particle-file") == true) {
const XmlNode *pf= particlesNode->getChild("particle-file");
if(pf != NULL) {
skillParticleFile = unitPath + '/' + pf->getAttribute("path")->getRestrictedValue();
printf("Found skill particle [%s]\n",skillParticleFile.c_str());
}
}
}
if(sn->hasChild("projectile") == true) {
const XmlNode *particlesProjectileNode= sn->getChild("projectile");
//for(int j = 0; particlesProjectileNode != NULL && particlesProjectileNode->getAttribute("value")->getRestrictedValue() == "true" &&
// j < particlesProjectileNode->getChildCount(); ++j) {
if(particlesProjectileNode != NULL && particlesProjectileNode->getAttribute("value")->getRestrictedValue() == "true" &&
particlesProjectileNode->hasChild("particle") == true) {
const XmlNode *pf= particlesProjectileNode->getChild("particle");
if(pf != NULL && pf->getAttribute("value")->getRestrictedValue() == "true") {
skillParticleProjectileFile = unitPath + '/' + pf->getAttribute("path")->getRestrictedValue();
printf("Found skill skill projectile particle [%s]\n",skillParticleProjectileFile.c_str());
}
}
}
if(sn->hasChild("splash") == true) {
const XmlNode *particlesSplashNode= sn->getChild("splash");
//for(int j = 0; particlesSplashNode != NULL && particlesSplashNode->getAttribute("value")->getRestrictedValue() == "true" &&
// j < particlesSplashNode->getChildCount(); ++j) {
if(particlesSplashNode != NULL && particlesSplashNode->getAttribute("value")->getRestrictedValue() == "true" &&
particlesSplashNode->hasChild("particle") == true) {
const XmlNode *pf= particlesSplashNode->getChild("particle");
if(pf != NULL && pf->getAttribute("value")->getRestrictedValue() == "true") {
skillParticleSplashFile = unitPath + '/' + pf->getAttribute("path")->getRestrictedValue();
printf("Found skill skill splash particle [%s]\n",skillParticleSplashFile.c_str());
}
}
}
}
}
}
if(skillModelFile != "") {
this->modelPathList.push_back(skillModelFile);
printf("Added skill model [%s]\n",skillModelFile.c_str());
}
if(skillParticleFile != "") {
this->particlePathList.push_back(skillParticleFile);
printf("Added skill particle [%s]\n",skillParticleFile.c_str());
}
if(skillParticleProjectileFile != "") {
this->particleProjectilePathList.push_back(skillParticleProjectileFile);
printf("Added skill projectile particle [%s]\n",skillParticleProjectileFile.c_str());
}
if(skillParticleSplashFile != "") {
this->particleSplashPathList.push_back(skillParticleSplashFile);
printf("Added skill splash particle [%s]\n",skillParticleSplashFile.c_str());
}
}
SetTitle(ToUnicode(titlestring));
}
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Not a Mega-Glest particle XML file, or broken"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::loadModel(string path) {
try {
if(path != "" && fileExists(path) == true) {
this->modelPathList.push_back(path);
printf("Adding model [%s] list size " MG_SIZE_T_SPECIFIER "\n",path.c_str(),this->modelPathList.size());
}
string titlestring=winHeader;
for(unsigned int idx =0; idx < this->modelPathList.size(); idx++) {
string modelPath = this->modelPathList[idx];
//printf("Loading model [%s] %u of " MG_SIZE_T_SPECIFIER "\n",modelPath.c_str(),idx, this->modelPathList.size());
if(timer) timer->Stop();
//delete model;
if(model != NULL && renderer != NULL) renderer->endModel(rsGlobal, model);
model = NULL;
model = renderer? renderer->newModel(rsGlobal, modelPath): NULL;
statusbarText = getModelInfo();
string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " anim value: " + floatToStr(anim) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY);
GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str()));
if(timer) timer->Start(100);
titlestring = extractFileFromDirectoryPath(modelPath) + " - "+ titlestring;
}
SetTitle(ToUnicode(titlestring));
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::loadParticle(string path) {
if(timer) timer->Stop();
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] about to load [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str());
if(path != "" && fileExists(path) == true) {
renderer->end();
unitParticleSystems.clear();
unitParticleSystemTypes.clear();
if(isControlKeyPressed == true) {
// std::cout << "Adding to list..." << std::endl;
this->particlePathList.push_back(path);
}
else {
// std::cout << "Clearing list..." << std::endl;
this->particlePathList.clear();
this->particlePathList.push_back(path);
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] added file [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str());
}
try {
if(this->particlePathList.empty() == false) {
string titlestring=winHeader;
for(unsigned int idx = 0; idx < this->particlePathList.size(); idx++) {
string particlePath = this->particlePathList[idx];
string dir= extractDirectoryPathFromFile(particlePath);
size_t pos = dir.find_last_of(folderDelimiter);
if(pos == dir.length() - 1 && dir.length() > 0) {
dir.erase(dir.length() -1);
}
particlePath= extractFileFromDirectoryPath(particlePath);
titlestring = particlePath + " - "+ titlestring;
std::string unitXML = dir + folderDelimiter + extractFileFromDirectoryPath(dir) + ".xml";
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] looking for unit XML [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,unitXML.c_str());
//int size = -1;
//int height = -1;
int size = 0;
int height= 0;
if(fileExists(unitXML) == true) {
{
XmlTree xmlTree;
xmlTree.load(unitXML,Properties::getTagReplacementValues());
const XmlNode *unitNode= xmlTree.getRootNode();
const XmlNode *parametersNode= unitNode->getChild("parameters");
//size
size= parametersNode->getChild("size")->getAttribute("value")->getIntValue();
//height
height= parametersNode->getChild("height")->getAttribute("value")->getIntValue();
}
// std::cout << "About to load [" << particlePath << "] from [" << dir << "] unit [" << unitXML << "]" << std::endl;
}
else {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] unit XML NOT FOUND [%s] using default position values\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,unitXML.c_str());
size = 1;
height= 1;
}
std::map<string,vector<pair<string, string> > > loadedFileList;
UnitParticleSystemType *unitParticleSystemType = new UnitParticleSystemType();
unitParticleSystemType->load(NULL, dir, dir + folderDelimiter + particlePath, //### if we knew which particle it was, we could be more accurate
renderer,loadedFileList,"g3dviewer","");
unitParticleSystemTypes.push_back(unitParticleSystemType);
for(std::vector<UnitParticleSystemType *>::const_iterator it= unitParticleSystemTypes.begin(); it != unitParticleSystemTypes.end(); ++it) {
UnitParticleSystem *ups= new UnitParticleSystem(200);
ups->setParticleType((*it));
(*it)->setValues(ups);
if(size > 0) {
//getCurrVectorFlat() + Vec3f(0.f, type->getHeight()/2.f, 0.f);
Vec3f vec = Vec3f(0.f, height / 2.f, 0.f);
ups->setPos(vec);
}
//ups->setFactionColor(getFaction()->getTexture()->getPixmap()->getPixel3f(0,0));
ups->setFactionColor(renderer->getPlayerColorTexture(playerColor)->getPixmap()->getPixel3f(0,0));
unitParticleSystems.push_back(ups);
renderer->manageParticleSystem(ups);
ups->setVisible(true);
}
if(path != "" && fileExists(path) == true) {
renderer->initModelManager();
if(initTextureManager) {
renderer->initTextureManager();
}
}
}
SetTitle(ToUnicode(titlestring));
}
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Not a Mega-Glest particle XML file, or broken"), wxOK | wxICON_ERROR).ShowModal();
}
if(timer) timer->Start(100);
}
void MainWindow::loadProjectileParticle(string path) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] about to load [%s] particleProjectilePathList.size() = " MG_SIZE_T_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str(),this->particleProjectilePathList.size());
if(timer) timer->Stop();
if(path != "" && fileExists(path) == true) {
renderer->end();
projectileParticleSystems.clear();
projectileParticleSystemTypes.clear();
if(isControlKeyPressed == true) {
// std::cout << "Adding to list..." << std::endl;
this->particleProjectilePathList.push_back(path);
}
else {
// std::cout << "Clearing list..." << std::endl;
this->particleProjectilePathList.clear();
this->particleProjectilePathList.push_back(path);
}
}
try {
if(this->particleProjectilePathList.empty() == false) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("this->particleProjectilePathList.size() = " MG_SIZE_T_SPECIFIER "\n",this->particleProjectilePathList.size());
string titlestring=winHeader;
for(unsigned int idx = 0; idx < this->particleProjectilePathList.size(); idx++) {
string particlePath = this->particleProjectilePathList[idx];
string dir= extractDirectoryPathFromFile(particlePath);
size_t pos = dir.find_last_of(folderDelimiter);
if(pos == dir.length()-1) {
dir.erase(dir.length() -1);
}
particlePath= extractFileFromDirectoryPath(particlePath);
titlestring = particlePath + " - "+ titlestring;
std::string unitXML = dir + folderDelimiter + extractFileFromDirectoryPath(dir) + ".xml";
int size = 1;
int height = 1;
if(fileExists(unitXML) == true) {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] loading [%s] idx = %u\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,unitXML.c_str(),idx);
XmlTree xmlTree;
xmlTree.load(unitXML,Properties::getTagReplacementValues());
const XmlNode *unitNode= xmlTree.getRootNode();
const XmlNode *parametersNode= unitNode->getChild("parameters");
//size
size= parametersNode->getChild("size")->getAttribute("value")->getIntValue();
//height
height= parametersNode->getChild("height")->getAttribute("value")->getIntValue();
}
// std::cout << "About to load [" << particlePath << "] from [" << dir << "] unit [" << unitXML << "]" << std::endl;
string particleFile = dir + folderDelimiter + particlePath;
{
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] loading [%s] idx = %u\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,particleFile.c_str(),idx);
XmlTree xmlTree;
xmlTree.load(particleFile,Properties::getTagReplacementValues());
//const XmlNode *particleSystemNode= xmlTree.getRootNode();
// std::cout << "Loaded successfully, loading values..." << std::endl;
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] loading [%s] idx = %u\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,particleFile.c_str(),idx);
std::map<string,vector<pair<string, string> > > loadedFileList;
ParticleSystemTypeProjectile *projectileParticleSystemType= new ParticleSystemTypeProjectile();
projectileParticleSystemType->load(NULL, dir, //### we don't know if there are overrides in the unit XML
particleFile,renderer, loadedFileList,
"g3dviewer","");
// std::cout << "Values loaded, about to read..." << std::endl;
projectileParticleSystemTypes.push_back(projectileParticleSystemType);
for(std::vector<ParticleSystemTypeProjectile *>::const_iterator it= projectileParticleSystemTypes.begin();
it != projectileParticleSystemTypes.end(); ++it) {
ProjectileParticleSystem *ps = (*it)->create(NULL);
if(size > 0) {
Vec3f vec = Vec3f(0.f, height / 2.f, 0.f);
//ps->setPos(vec);
Vec3f vec2 = Vec3f(size * 2.f, height * 2.f, height * 2.f);
ps->setPath(vec, vec2);
}
ps->setFactionColor(renderer->getPlayerColorTexture(playerColor)->getPixmap()->getPixel3f(0,0));
projectileParticleSystems.push_back(ps);
ps->setVisible(true);
renderer->manageParticleSystem(ps);
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] loaded [%s] idx = %u\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,particleFile.c_str(),idx);
}
SetTitle(ToUnicode(titlestring));
if(path != "" && fileExists(path) == true) {
renderer->initModelManager();
if(initTextureManager) {
renderer->initTextureManager();
}
}
}
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Not a Mega-Glest projectile particle XML file, or broken"), wxOK | wxICON_ERROR).ShowModal();
}
if(timer) timer->Start(100);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] after load [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str());
}
void MainWindow::loadSplashParticle(string path) { // uses ParticleSystemTypeSplash::load (and own list...)
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] about to load [%s] particleSplashPathList.size() = " MG_SIZE_T_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str(),this->particleSplashPathList.size());
if(timer) timer->Stop();
if(path != "" && fileExists(path) == true) {
renderer->end();
splashParticleSystems.clear();
splashParticleSystemTypes.clear();
if(isControlKeyPressed == true) {
// std::cout << "Adding to list..." << std::endl;
this->particleSplashPathList.push_back(path);
}
else {
// std::cout << "Clearing list..." << std::endl;
this->particleSplashPathList.clear();
this->particleSplashPathList.push_back(path);
}
}
try {
if(this->particleSplashPathList.empty() == false) {
string titlestring=winHeader;
for(unsigned int idx = 0; idx < this->particleSplashPathList.size(); idx++) {
string particlePath = this->particleSplashPathList[idx];
string dir= extractDirectoryPathFromFile(particlePath);
size_t pos = dir.find_last_of(folderDelimiter);
if(pos == dir.length()-1) {
dir.erase(dir.length() -1);
}
particlePath= extractFileFromDirectoryPath(particlePath);
titlestring = particlePath + " - "+ titlestring;
std::string unitXML = dir + folderDelimiter + extractFileFromDirectoryPath(dir) + ".xml";
int size = 1;
//int height = 1;
if(fileExists(unitXML) == true) {
XmlTree xmlTree;
xmlTree.load(unitXML,Properties::getTagReplacementValues());
const XmlNode *unitNode= xmlTree.getRootNode();
const XmlNode *parametersNode= unitNode->getChild("parameters");
//size
size= parametersNode->getChild("size")->getAttribute("value")->getIntValue();
//height
//height= parametersNode->getChild("height")->getAttribute("value")->getIntValue();
}
// std::cout << "About to load [" << particlePath << "] from [" << dir << "] unit [" << unitXML << "]" << std::endl;
{
XmlTree xmlTree;
xmlTree.load(dir + folderDelimiter + particlePath,Properties::getTagReplacementValues());
//const XmlNode *particleSystemNode= xmlTree.getRootNode();
// std::cout << "Loaded successfully, loading values..." << std::endl;
}
std::map<string,vector<pair<string, string> > > loadedFileList;
ParticleSystemTypeSplash *splashParticleSystemType= new ParticleSystemTypeSplash();
splashParticleSystemType->load(NULL, dir, dir + folderDelimiter + particlePath,renderer, //### we don't know if there are overrides in the unit XML
loadedFileList,"g3dviewer",""); // <---- only that must be splash...
// std::cout << "Values loaded, about to read..." << std::endl;
splashParticleSystemTypes.push_back(splashParticleSystemType);
//ParticleSystemTypeSplash
for(std::vector<ParticleSystemTypeSplash *>::const_iterator it= splashParticleSystemTypes.begin(); it != splashParticleSystemTypes.end(); ++it) {
SplashParticleSystem *ps = (*it)->create(NULL);
if(size > 0) {
//Vec3f vec = Vec3f(0.f, height / 2.f, 0.f);
//ps->setPos(vec);
//Vec3f vec2 = Vec3f(size * 2.f, height * 2.f, height * 2.f); // <------- removed relative projectile
//ps->setPath(vec, vec2); // <------- removed relative projectile
}
ps->setFactionColor(renderer->getPlayerColorTexture(playerColor)->getPixmap()->getPixel3f(0,0));
splashParticleSystems.push_back(ps);
ps->setVisible(true);
renderer->manageParticleSystem(ps);
}
}
SetTitle(ToUnicode(titlestring));
if(path != "" && fileExists(path) == true) {
renderer->initModelManager();
if(initTextureManager) {
renderer->initTextureManager();
}
}
}
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Not a Mega-Glest projectile particle XML file, or broken"), wxOK | wxICON_ERROR).ShowModal();
}
if(timer) timer->Start(100);
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] after load [%s] particleSplashPathList.size() = " MG_SIZE_T_SPECIFIER "\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str(),this->particleSplashPathList.size());
}
void MainWindow::onMenuModeNormals(wxCommandEvent &event){
try {
renderer->toggleNormals();
menuMode->Check(miModeNormals, renderer->getNormals());
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuModeWireframe(wxCommandEvent &event){
try {
renderer->toggleWireframe();
menuMode->Check(miModeWireframe, renderer->getWireframe());
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuModeGrid(wxCommandEvent &event){
try {
renderer->toggleGrid();
menuMode->Check(miModeGrid, renderer->getGrid());
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuSpeedSlower(wxCommandEvent &event){
try {
speed /= 1.5f;
if(speed < 0) {
speed = 0;
}
string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " anim value: " + floatToStr(anim) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY);
GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str()));
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuSpeedFaster(wxCommandEvent &event){
try {
speed *= 1.5f;
if(speed > 1) {
speed = 1;
}
string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0 ) + " anim value: " + floatToStr(anim) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY);
GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str()));
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
// set menu checkboxes to what player color is used
void MainWindow::onMenuColorRed(wxCommandEvent &event) {
try {
playerColor= Renderer::pcRed;
menuCustomColor->Check(miColorRed, true);
menuCustomColor->Check(miColorBlue, false);
menuCustomColor->Check(miColorGreen, false);
menuCustomColor->Check(miColorYellow, false);
menuCustomColor->Check(miColorWhite, false);
menuCustomColor->Check(miColorCyan, false);
menuCustomColor->Check(miColorOrange, false);
menuCustomColor->Check(miColorMagenta, false);
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuColorBlue(wxCommandEvent &event) {
try {
playerColor= Renderer::pcBlue;
menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorBlue, true);
menuCustomColor->Check(miColorGreen, false);
menuCustomColor->Check(miColorYellow, false);
menuCustomColor->Check(miColorWhite, false);
menuCustomColor->Check(miColorCyan, false);
menuCustomColor->Check(miColorOrange, false);
menuCustomColor->Check(miColorMagenta, false);
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuColorGreen(wxCommandEvent &event) {
try {
playerColor= Renderer::pcGreen;
menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorBlue, false);
menuCustomColor->Check(miColorGreen, true);
menuCustomColor->Check(miColorYellow, false);
menuCustomColor->Check(miColorWhite, false);
menuCustomColor->Check(miColorCyan, false);
menuCustomColor->Check(miColorOrange, false);
menuCustomColor->Check(miColorMagenta, false);
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuColorYellow(wxCommandEvent &event) {
try {
playerColor= Renderer::pcYellow;
menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorBlue, false);
menuCustomColor->Check(miColorGreen, false);
menuCustomColor->Check(miColorYellow, true);
menuCustomColor->Check(miColorWhite, false);
menuCustomColor->Check(miColorCyan, false);
menuCustomColor->Check(miColorOrange, false);
menuCustomColor->Check(miColorMagenta, false);
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuColorWhite(wxCommandEvent &event) {
try {
playerColor= Renderer::pcWhite;
menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorBlue, false);
menuCustomColor->Check(miColorGreen, false);
menuCustomColor->Check(miColorYellow, false);
menuCustomColor->Check(miColorWhite, true);
menuCustomColor->Check(miColorCyan, false);
menuCustomColor->Check(miColorOrange, false);
menuCustomColor->Check(miColorMagenta, false);
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuColorCyan(wxCommandEvent &event) {
try {
playerColor= Renderer::pcCyan;
menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorBlue, false);
menuCustomColor->Check(miColorGreen, false);
menuCustomColor->Check(miColorYellow, false);
menuCustomColor->Check(miColorWhite, false);
menuCustomColor->Check(miColorCyan, true);
menuCustomColor->Check(miColorOrange, false);
menuCustomColor->Check(miColorMagenta, false);
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuColorOrange(wxCommandEvent &event) {
try {
playerColor= Renderer::pcOrange;
menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorBlue, false);
menuCustomColor->Check(miColorGreen, false);
menuCustomColor->Check(miColorYellow, false);
menuCustomColor->Check(miColorWhite, false);
menuCustomColor->Check(miColorCyan, false);
menuCustomColor->Check(miColorOrange, true);
menuCustomColor->Check(miColorMagenta, false);
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuColorMagenta(wxCommandEvent &event) {
try {
playerColor= Renderer::pcMagenta;
menuCustomColor->Check(miColorRed, false);
menuCustomColor->Check(miColorBlue, false);
menuCustomColor->Check(miColorGreen, false);
menuCustomColor->Check(miColorYellow, false);
menuCustomColor->Check(miColorWhite, false);
menuCustomColor->Check(miColorCyan, false);
menuCustomColor->Check(miColorOrange, false);
menuCustomColor->Check(miColorMagenta, true);
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onTimer(wxTimerEvent &event) {
anim = anim + speed;
if(anim > 1.0f){
anim -= 1.f;
resetAnimation = true;
}
onPaintNoEvent();
}
string MainWindow::getModelInfo() {
string str;
if(model != NULL) {
str+= "Meshes: "+intToStr(model->getMeshCount());
str+= ", Vertices: "+intToStr(model->getVertexCount());
str+= ", Triangles: "+intToStr(model->getTriangleCount());
str+= ", Version: "+intToStr(model->getFileVersion());
}
return str;
}
void MainWindow::onKeyDown(wxKeyEvent &e) {
try {
// std::cout << "e.ControlDown() = " << e.ControlDown() << " e.GetKeyCode() = " << e.GetKeyCode() << " isCtrl = " << (e.GetKeyCode() == WXK_CONTROL) << std::endl;
// Note: This ctrl-key handling is buggy since it never resets when ctrl is released later, so I reset it at end of loadcommands for now.
if(e.ControlDown() == true || e.GetKeyCode() == WXK_CONTROL) {
isControlKeyPressed = true;
}
else {
isControlKeyPressed = false;
}
// std::cout << "isControlKeyPressed = " << isControlKeyPressed << std::endl;
// here also because + and - hotkeys don't work for numpad automaticly
if (e.GetKeyCode() == 388) {
speed *= 1.5f; //numpad+
if(speed > 1.0) {
speed = 1.0;
}
string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " anim value: " + floatToStr(anim) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY);
GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str()));
}
else if (e.GetKeyCode() == 390) {
speed /= 1.5f; //numpad-
if(speed < 0) {
speed = 0;
}
string statusTextValue = statusbarText + " animation speed: " + floatToStr(speed * 1000.0) + " anim value: " + floatToStr(anim) + " zoom: " + floatToStr(zoom) + " rotX: " + floatToStr(rotX) + " rotY: " + floatToStr(rotY);
GetStatusBar()->SetStatusText(ToUnicode(statusTextValue.c_str()));
}
else if (e.GetKeyCode() == 'W') {
glClearColor(0.6f, 0.6f, 0.6f, 1.0f); //w key //backgroundcolor constant 0.3 -> 0.6
}
// some posibility to adjust brightness:
/*
else if (e.GetKeyCode() == 322) { // Ins - Grid
gridBrightness += 0.1f; if (gridBrightness >1.0) gridBrightness =1.0;
}
else if (e.GetKeyCode() == 127) { // Del
gridBrightness -= 0.1f; if (gridBrightness <0) gridBrightness =0;
}
*/
else if (e.GetKeyCode() == 313) { // Home - Background
backBrightness += 0.1f; if (backBrightness >1.0) backBrightness=1.0;
glClearColor(backBrightness, backBrightness, backBrightness, 1.0f);
}
else if (e.GetKeyCode() == 312) { // End
backBrightness -= 0.1f; if (backBrightness<0) backBrightness=0;
glClearColor(backBrightness, backBrightness, backBrightness, 1.0f);
}
else if (e.GetKeyCode() == 366) { // PgUp - Lightning of model
lightBrightness += 0.1f; if (lightBrightness >1.0) lightBrightness =1.0;
Vec4f ambientNEW= Vec4f(lightBrightness, lightBrightness, lightBrightness, 1.0f);
glLightfv(GL_LIGHT0,GL_AMBIENT, ambientNEW.ptr());
}
else if (e.GetKeyCode() == 367) { // pgDn
lightBrightness -= 0.1f; if (lightBrightness <0) lightBrightness =0;
Vec4f ambientNEW= Vec4f(lightBrightness, lightBrightness, lightBrightness, 1.0f);
glLightfv(GL_LIGHT0,GL_AMBIENT, ambientNEW.ptr());
}
std::cout << "pressed " << e.GetKeyCode() << std::endl;
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
void MainWindow::onMenuRestart(wxCommandEvent &event) {
onMenuRestartNoEvent();
}
void MainWindow::onMenuRestartNoEvent() {
try {
// std::cout << "pressed R (restart particle animation)" << std::endl;
if(timer) timer->Stop();
if(renderer) renderer->end();
unitParticleSystems.clear();
unitParticleSystemTypes.clear();
projectileParticleSystems.clear();
projectileParticleSystemTypes.clear();
splashParticleSystems.clear(); // as above
splashParticleSystemTypes.clear();
loadUnit("", "");
loadModel("");
loadParticle("");
loadProjectileParticle("");
loadSplashParticle(""); // as above
renderer->initModelManager();
if(initTextureManager) {
renderer->initTextureManager();
}
if(timer) timer->Start(100);
}
catch(std::runtime_error &e) {
std::cout << e.what() << std::endl;
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Error"), wxOK | wxICON_ERROR).ShowModal();
}
}
BEGIN_EVENT_TABLE(MainWindow, wxFrame)
EVT_TIMER(-1, MainWindow::onTimer)
EVT_CLOSE(MainWindow::onClose)
EVT_MENU(miFileLoad, MainWindow::onMenuFileLoad)
EVT_MENU(miFileLoadParticleXML, MainWindow::onMenuFileLoadParticleXML)
EVT_MENU(miFileLoadProjectileParticleXML, MainWindow::onMenuFileLoadProjectileParticleXML)
EVT_MENU(miFileLoadSplashParticleXML, MainWindow::onMenuFileLoadSplashParticleXML)
EVT_MENU(miFileClearAll, MainWindow::onMenuFileClearAll)
EVT_MENU(miFileToggleScreenshotTransparent, MainWindow::onMenumFileToggleScreenshotTransparent)
EVT_MENU(miFileSaveScreenshot, MainWindow::onMenuFileSaveScreenshot)
EVT_MENU(wxID_EXIT, MainWindow::onMenuFileExit)
EVT_MENU(miModeWireframe, MainWindow::onMenuModeWireframe)
EVT_MENU(miModeNormals, MainWindow::onMenuModeNormals)
EVT_MENU(miModeGrid, MainWindow::onMenuModeGrid)
EVT_MENU(miSpeedFaster, MainWindow::onMenuSpeedFaster)
EVT_MENU(miSpeedSlower, MainWindow::onMenuSpeedSlower)
EVT_MENU(miRestart, MainWindow::onMenuRestart)
EVT_MENU(miColorRed, MainWindow::onMenuColorRed)
EVT_MENU(miColorBlue, MainWindow::onMenuColorBlue)
EVT_MENU(miColorGreen, MainWindow::onMenuColorGreen)
EVT_MENU(miColorYellow, MainWindow::onMenuColorYellow)
EVT_MENU(miColorWhite, MainWindow::onMenuColorWhite)
EVT_MENU(miColorCyan, MainWindow::onMenuColorCyan)
EVT_MENU(miColorOrange, MainWindow::onMenuColorOrange)
EVT_MENU(miColorMagenta, MainWindow::onMenuColorMagenta)
EVT_MENU(miChangeBackgroundColor, MainWindow::OnChangeColor)
END_EVENT_TABLE()
// =====================================================
// class GlCanvas
// =====================================================
void translateCoords(wxWindow *wnd, int &x, int &y) {
#ifdef WIN32
int cx, cy;
wnd->GetPosition(&cx, &cy);
x += cx;
y += cy;
#endif
}
// to prevent flicker
GlCanvas::GlCanvas(MainWindow * mainWindow, int *args)
#if wxCHECK_VERSION(2, 9, 1)
: wxGLCanvas(mainWindow, wxID_ANY, args, wxDefaultPosition, mainWindow->GetClientSize(), wxFULL_REPAINT_ON_RESIZE, wxT("GLCanvas")) {
this->context = new wxGLContext(this);
#else
: wxGLCanvas(mainWindow, -1, wxDefaultPosition, wxDefaultSize, 0, wxT("GLCanvas"), args) {
this->context = NULL;
#endif
this->mainWindow = mainWindow;
}
GlCanvas::~GlCanvas() {
if(this->context) {
delete this->context;
}
this->context = NULL;
}
void GlCanvas::setCurrentGLContext() {
#ifndef __APPLE__
#if wxCHECK_VERSION(3, 0, 0)
//printf("Setting glcontext 3x!\n");
//if(!IsShown()) {}
if(this->context == NULL) {
//printf("Make new ctx!\n");
this->context = new wxGLContext(this);
//printf("Set ctx [%p]\n",this->context);
}
#elif wxCHECK_VERSION(2, 9, 1)
//printf("Setting glcontext 29x!\n");
//if(!IsShown()) {}
if(this->context == NULL) {
this->context = new wxGLContext(this);
//printf("Set ctx [%p]\n",this->context);
}
#endif
//printf("Set ctx [%p]\n",this->context);
if(this->context) {
wxGLCanvas::SetCurrent(*this->context);
//printf("Set ctx2 [%p]\n",this->context);
}
#else
this->SetCurrent();
#endif
}
// for the mousewheel
void GlCanvas::onMouseWheel(wxMouseEvent &event) {
if(event.GetWheelRotation()>0) mainWindow->onMouseWheelDown(event);
else mainWindow->onMouseWheelUp(event);
}
void GlCanvas::onMouseMove(wxMouseEvent &event){
mainWindow->onMouseMove(event);
}
void GlCanvas::onKeyDown(wxKeyEvent &event) {
int x, y;
event.GetPosition(&x, &y);
translateCoords(this, x, y);
mainWindow->onKeyDown(event);
}
void GlCanvas::OnSize(wxSizeEvent&event) {
//printf("OnSize %dx%d\n",event.m_size.GetWidth(),event.m_size.GetHeight());
Update();
}
// EVT_SPIN_DOWN(GlCanvas::onMouseDown)
// EVT_SPIN_UP(GlCanvas::onMouseDown)
// EVT_MIDDLE_DOWN(GlCanvas::onMouseWheel)
// EVT_MIDDLE_UP(GlCanvas::onMouseWheel)
BEGIN_EVENT_TABLE(GlCanvas, wxGLCanvas)
EVT_MOUSEWHEEL(GlCanvas::onMouseWheel)
EVT_MOTION(GlCanvas::onMouseMove)
EVT_KEY_DOWN(GlCanvas::onKeyDown)
EVT_SIZE(GlCanvas::OnSize)
END_EVENT_TABLE()
// ===============================================
// class App
// ===============================================
bool App::OnInit() {
SystemFlags::VERBOSE_MODE_ENABLED = false;
#if defined(wxMAJOR_VERSION) && defined(wxMINOR_VERSION) && defined(wxRELEASE_NUMBER) && defined(wxSUBRELEASE_NUMBER)
printf("Using wxWidgets version [%d.%d.%d.%d]\n",wxMAJOR_VERSION,wxMINOR_VERSION,wxRELEASE_NUMBER,wxSUBRELEASE_NUMBER);
#endif
string modelPath="";
string particlePath="";
string projectileParticlePath="";
string splashParticlePath="";
bool foundInvalidArgs = false;
const int knownArgCount = sizeof(GAME_ARGS) / sizeof(GAME_ARGS[0]);
for(int idx = 1; idx < argc; ++idx) {
const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(argv[idx]);
if( hasCommandArgument(knownArgCount, (wxChar**)&GAME_ARGS[0], (const char *)tmp_buf, NULL, 0, true) == false &&
argv[idx][0] == '-') {
foundInvalidArgs = true;
printf("\nInvalid argument: %s",(const char*)tmp_buf);
}
}
if(foundInvalidArgs == true ||
hasCommandArgument(argc, argv,(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_HELP])) == true) {
printParameterHelp(wxConvCurrent->cWX2MB(argv[0]),foundInvalidArgs);
return false;
}
if(hasCommandArgument(argc, argv,(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_VERBOSE])) == true) {
SystemFlags::VERBOSE_MODE_ENABLED = true;
}
if(hasCommandArgument(argc, argv,(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_AUTO_SCREENSHOT])) == true) {
autoScreenShotAndExit = true;
const wxWX2MBbuf param = (const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_AUTO_SCREENSHOT]);
//printf("param = [%s]\n",(const char*)param);
int foundParamIndIndex = -1;
hasCommandArgument(argc, argv,string((const char*)param) + string("="),&foundParamIndIndex);
if(foundParamIndIndex < 0) {
hasCommandArgument(argc, argv,(const char*)param,&foundParamIndIndex);
}
//printf("foundParamIndIndex = %d\n",foundParamIndIndex);
string options = (const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]);
vector<string> paramPartTokens;
Tokenize(options,paramPartTokens,"=");
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
string optionsValue = paramPartTokens[1];
autoScreenShotParams.clear();
Tokenize(optionsValue,autoScreenShotParams,",");
for(unsigned int i = 0; i < autoScreenShotParams.size(); ++i) {
#ifdef WIN32
auto_ptr<wchar_t> wstr(Ansi2WideString(autoScreenShotParams[i].c_str()));
autoScreenShotParams[i] = utf8_encode(wstr.get());
#endif
if(_strnicmp(autoScreenShotParams[i].c_str(),"resize-",7) == 0) {
printf("Screenshot option [%s]\n",autoScreenShotParams[i].c_str());
string resize = autoScreenShotParams[i];
resize = resize.erase(0,7);
vector<string> values;
Tokenize(resize,values,"x");
overrideSize.first = strToInt(values[0]);
overrideSize.second = strToInt(values[1]);
Renderer::windowX= 0;
Renderer::windowY= 0;
Renderer::windowW = overrideSize.first;
Renderer::windowH = overrideSize.second + 25;
}
}
}
}
std::pair<string,vector<string> > unitToLoad;
if(hasCommandArgument(argc, argv,(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_UNIT])) == true) {
const wxWX2MBbuf param = (const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_UNIT]);
//printf("param = [%s]\n",(const char*)param);
int foundParamIndIndex = -1;
hasCommandArgument(argc, argv,string((const char*)param) + string("="),&foundParamIndIndex);
if(foundParamIndIndex < 0) {
hasCommandArgument(argc, argv,(const char*)param,&foundParamIndIndex);
}
//printf("foundParamIndIndex = %d\n",foundParamIndIndex);
string customPath = (const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]);
vector<string> paramPartTokens;
Tokenize(customPath,paramPartTokens,"=");
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
string customPathValue = paramPartTokens[1];
std::vector<string> delimitedList;
Tokenize(customPathValue,delimitedList,",");
if(delimitedList.size() >= 2) {
unitToLoad.first = delimitedList[0];
#ifdef WIN32
auto_ptr<wchar_t> wstr(Ansi2WideString(unitToLoad.first.c_str()));
unitToLoad.first = utf8_encode(wstr.get());
#endif
for(unsigned int i = 1; i < delimitedList.size(); ++i) {
string value = delimitedList[i];
#ifdef WIN32
auto_ptr<wchar_t> wstr(Ansi2WideString(value.c_str()));
value = utf8_encode(wstr.get());
#endif
unitToLoad.second.push_back(value);
}
}
else {
printf("\nInvalid path specified on commandline [%s] value [%s]\n\n",(const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]),(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
printParameterHelp(wxConvCurrent->cWX2MB(argv[0]),false);
return false;
}
}
else {
printf("\nInvalid path specified on commandline [%s] value [%s]\n\n",(const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]),(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
printParameterHelp(wxConvCurrent->cWX2MB(argv[0]),false);
return false;
}
}
if(hasCommandArgument(argc, argv,(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_MODEL])) == true &&
hasCommandArgument(argc, argv,(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_MODEL_ANIMATION_VALUE])) == false) {
const wxWX2MBbuf param = (const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_MODEL]);
//printf("param = [%s]\n",(const char*)param);
int foundParamIndIndex = -1;
hasCommandArgument(argc, argv,string((const char*)param) + string("="),&foundParamIndIndex);
if(foundParamIndIndex < 0) {
hasCommandArgument(argc, argv,(const char*)param,&foundParamIndIndex);
}
//printf("foundParamIndIndex = %d\n",foundParamIndIndex);
string customPath = (const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]);
vector<string> paramPartTokens;
Tokenize(customPath,paramPartTokens,"=");
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
string customPathValue = paramPartTokens[1];
modelPath = customPathValue;
#ifdef WIN32
auto_ptr<wchar_t> wstr(Ansi2WideString(modelPath.c_str()));
modelPath = utf8_encode(wstr.get());
#endif
}
else {
printf("\nInvalid path specified on commandline [%s] value [%s]\n\n",(const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]),(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
printParameterHelp(wxConvCurrent->cWX2MB(argv[0]),false);
return false;
}
}
if(hasCommandArgument(argc, argv,(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_PARTICLE])) == true &&
hasCommandArgument(argc, argv,(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_PARTICLE_LOOP_VALUE])) == false) {
const wxWX2MBbuf param = (const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_PARTICLE]);
//printf("param = [%s]\n",(const char*)param);
int foundParamIndIndex = -1;
hasCommandArgument(argc, argv,string((const char*)param) + string("="),&foundParamIndIndex);
if(foundParamIndIndex < 0) {
hasCommandArgument(argc, argv,(const char*)param,&foundParamIndIndex);
}
//printf("foundParamIndIndex = %d\n",foundParamIndIndex);
string customPath = (const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]);
vector<string> paramPartTokens;
Tokenize(customPath,paramPartTokens,"=");
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
string customPathValue = paramPartTokens[1];
particlePath = customPathValue;
#ifdef WIN32
auto_ptr<wchar_t> wstr(Ansi2WideString(particlePath.c_str()));
particlePath = utf8_encode(wstr.get());
#endif
}
else {
printf("\nInvalid path specified on commandline [%s] value [%s]\n\n",(const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]),(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
printParameterHelp(wxConvCurrent->cWX2MB(argv[0]),false);
return false;
}
}
if(hasCommandArgument(argc, argv,(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_PARTICLE_PROJECTILE])) == true) {
const wxWX2MBbuf param = (const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_PARTICLE_PROJECTILE]);
//printf("param = [%s]\n",(const char*)param);
int foundParamIndIndex = -1;
hasCommandArgument(argc, argv,string((const char*)param) + string("="),&foundParamIndIndex);
if(foundParamIndIndex < 0) {
hasCommandArgument(argc, argv,(const char*)param,&foundParamIndIndex);
}
//printf("foundParamIndIndex = %d\n",foundParamIndIndex);
string customPath = (const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]);
vector<string> paramPartTokens;
Tokenize(customPath,paramPartTokens,"=");
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
string customPathValue = paramPartTokens[1];
projectileParticlePath = customPathValue;
#ifdef WIN32
auto_ptr<wchar_t> wstr(Ansi2WideString(projectileParticlePath.c_str()));
projectileParticlePath = utf8_encode(wstr.get());
#endif
}
else {
printf("\nInvalid path specified on commandline [%s] value [%s]\n\n",(const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]),(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
printParameterHelp(wxConvCurrent->cWX2MB(argv[0]),false);
return false;
}
}
if(hasCommandArgument(argc, argv,(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_PARTICLE_SPLASH])) == true) {
const wxWX2MBbuf param = (const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_PARTICLE_SPLASH]);
//printf("param = [%s]\n",(const char*)param);
int foundParamIndIndex = -1;
hasCommandArgument(argc, argv,string((const char*)param) + string("="),&foundParamIndIndex);
if(foundParamIndIndex < 0) {
hasCommandArgument(argc, argv,(const char*)param,&foundParamIndIndex);
}
//printf("foundParamIndIndex = %d\n",foundParamIndIndex);
string customPath = (const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]);
vector<string> paramPartTokens;
Tokenize(customPath,paramPartTokens,"=");
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
string customPathValue = paramPartTokens[1];
splashParticlePath = customPathValue;
#ifdef WIN32
auto_ptr<wchar_t> wstr(Ansi2WideString(splashParticlePath.c_str()));
splashParticlePath = utf8_encode(wstr.get());
#endif
}
else {
printf("\nInvalid path specified on commandline [%s] value [%s]\n\n",(const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]),(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
printParameterHelp(wxConvCurrent->cWX2MB(argv[0]),false);
return false;
}
}
float newAnimValue = 0.0f;
if(hasCommandArgument(argc, argv,(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_MODEL_ANIMATION_VALUE])) == true) {
const wxWX2MBbuf param = (const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_MODEL_ANIMATION_VALUE]);
int foundParamIndIndex = -1;
hasCommandArgument(argc, argv,string((const char*)param) + string("="),&foundParamIndIndex);
if(foundParamIndIndex < 0) {
hasCommandArgument(argc, argv,(const char*)param,&foundParamIndIndex);
}
//printf("foundParamIndIndex = %d\n",foundParamIndIndex);
string value = (const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]);
vector<string> paramPartTokens;
Tokenize(value,paramPartTokens,"=");
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
newAnimValue = strToFloat(paramPartTokens[1]);
printf("newAnimValue = %f\n",newAnimValue);
}
else {
printf("\nInvalid path specified on commandline [%s] value [%s]\n\n",(const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]),(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
printParameterHelp(wxConvCurrent->cWX2MB(argv[0]),false);
return false;
}
}
int newParticleLoopValue = 1;
if(hasCommandArgument(argc, argv,(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_PARTICLE_LOOP_VALUE])) == true) {
const wxWX2MBbuf param = (const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_LOAD_PARTICLE_LOOP_VALUE]);
int foundParamIndIndex = -1;
hasCommandArgument(argc, argv,string((const char*)param) + string("="),&foundParamIndIndex);
if(foundParamIndIndex < 0) {
hasCommandArgument(argc, argv,(const char*)param,&foundParamIndIndex);
}
//printf("foundParamIndIndex = %d\n",foundParamIndIndex);
string value = (const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]);
vector<string> paramPartTokens;
Tokenize(value,paramPartTokens,"=");
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
newParticleLoopValue = strToInt(paramPartTokens[1]);
//printf("newParticleLoopValue = %d\n",newParticleLoopValue);
}
else {
printf("\nInvalid path specified on commandline [%s] value [%s]\n\n",(const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]),(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
printParameterHelp(wxConvCurrent->cWX2MB(argv[0]),false);
return false;
}
}
float newZoomValue = 1.0f;
if(hasCommandArgument(argc, argv,(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_ZOOM_VALUE])) == true) {
const wxWX2MBbuf param = (const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_ZOOM_VALUE]);
int foundParamIndIndex = -1;
hasCommandArgument(argc, argv,string((const char*)param) + string("="),&foundParamIndIndex);
if(foundParamIndIndex < 0) {
hasCommandArgument(argc, argv,(const char*)param,&foundParamIndIndex);
}
//printf("foundParamIndIndex = %d\n",foundParamIndIndex);
string value = (const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]);
vector<string> paramPartTokens;
Tokenize(value,paramPartTokens,"=");
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
newZoomValue = strToFloat(paramPartTokens[1]);
//printf("newAnimValue = %f\n",newAnimValue);
}
else {
printf("\nInvalid path specified on commandline [%s] value [%s]\n\n",(const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]),(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
printParameterHelp(wxConvCurrent->cWX2MB(argv[0]),false);
return false;
}
}
float newXRotValue = 0.0f;
if(hasCommandArgument(argc, argv,(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_ROTATE_X_VALUE])) == true) {
const wxWX2MBbuf param = (const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_ROTATE_X_VALUE]);
int foundParamIndIndex = -1;
hasCommandArgument(argc, argv,string((const char*)param) + string("="),&foundParamIndIndex);
if(foundParamIndIndex < 0) {
hasCommandArgument(argc, argv,(const char*)param,&foundParamIndIndex);
}
//printf("foundParamIndIndex = %d\n",foundParamIndIndex);
string value = (const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]);
vector<string> paramPartTokens;
Tokenize(value,paramPartTokens,"=");
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
newXRotValue = strToFloat(paramPartTokens[1]);
//printf("newAnimValue = %f\n",newAnimValue);
}
else {
printf("\nInvalid path specified on commandline [%s] value [%s]\n\n",(const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]),(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
printParameterHelp(wxConvCurrent->cWX2MB(argv[0]),false);
return false;
}
}
float newYRotValue = 0.0f;
if(hasCommandArgument(argc, argv,(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_ROTATE_Y_VALUE])) == true) {
const wxWX2MBbuf param = (const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_ROTATE_Y_VALUE]);
int foundParamIndIndex = -1;
hasCommandArgument(argc, argv,string((const char*)param) + string("="),&foundParamIndIndex);
if(foundParamIndIndex < 0) {
hasCommandArgument(argc, argv,(const char*)param,&foundParamIndIndex);
}
//printf("foundParamIndIndex = %d\n",foundParamIndIndex);
string value = (const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]);
vector<string> paramPartTokens;
Tokenize(value,paramPartTokens,"=");
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
newYRotValue = strToFloat(paramPartTokens[1]);
//printf("newAnimValue = %f\n",newAnimValue);
}
else {
printf("\nInvalid path specified on commandline [%s] value [%s]\n\n",(const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]),(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
printParameterHelp(wxConvCurrent->cWX2MB(argv[0]),false);
return false;
}
}
if(hasCommandArgument(argc, argv,(const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_SCREENSHOT_FORMAT])) == true) {
const wxWX2MBbuf param = (const char *)wxConvCurrent->cWX2MB(GAME_ARGS[GAME_ARG_SCREENSHOT_FORMAT]);
int foundParamIndIndex = -1;
hasCommandArgument(argc, argv,string((const char*)param) + string("="),&foundParamIndIndex);
if(foundParamIndIndex < 0) {
hasCommandArgument(argc, argv,(const char*)param,&foundParamIndIndex);
}
//printf("foundParamIndIndex = %d\n",foundParamIndIndex);
string value = (const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]);
vector<string> paramPartTokens;
Tokenize(value,paramPartTokens,"=");
if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) {
fileFormat = paramPartTokens[1];
}
else {
printf("\nInvalid value specified on commandline [%s] value [%s]\n\n",(const char *)wxConvCurrent->cWX2MB(argv[foundParamIndIndex]),(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
printParameterHelp(wxConvCurrent->cWX2MB(argv[0]),false);
return false;
}
}
if(argc == 2 && argv[1][0] != '-') {
//#if defined(__MINGW32__)
#ifdef WIN32
const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(argv[1]));
modelPath = tmp_buf;
auto_ptr<wchar_t> wstr(Ansi2WideString(modelPath.c_str()));
modelPath = utf8_encode(wstr.get());
#else
modelPath = wxFNCONV(argv[1]);
#endif
//#else
// modelPath = wxFNCONV(argv[1]);
//#endif
}
//#if defined(__MINGW32__)
// const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(argv[0]));
// appPath = tmp_buf;
//#else
// appPath = wxFNCONV(argv[0]);
//#endif
// printf("appPath [%s]\n",argv[0]);
wxString exe_path = wxStandardPaths::Get().GetExecutablePath();
//wxString path_separator = wxFileName::GetPathSeparator();
//exe_path = exe_path.BeforeLast(path_separator[0]);
//exe_path += path_separator;
//#if defined(__MINGW32__)
#ifdef WIN32
const wxWX2MBbuf tmp_buf = wxConvCurrent->cWX2MB(wxFNCONV(exe_path));
string appPath = tmp_buf;
auto_ptr<wchar_t> wstr(Ansi2WideString(appPath.c_str()));
appPath = utf8_encode(wstr.get());
#else
string appPath(wxFNCONV(exe_path));
#endif
//#else
// appPath = wxFNCONV(exe_path);
//#endif
// printf("#2 appPath [%s]\n",appPath.c_str());
mainWindow= new MainWindow( unitToLoad,
modelPath,
particlePath,
projectileParticlePath,
splashParticlePath,
newAnimValue,
newParticleLoopValue,
newZoomValue,
newXRotValue,
newYRotValue,
appPath);
if(autoScreenShotAndExit == true) {
#if !defined(WIN32)
mainWindow->Iconize(true);
#endif
}
mainWindow->Show();
mainWindow->init();
mainWindow->Update();
mainWindow->setupTimer();
return true;
}
int App::MainLoop(){
try{
return wxApp::MainLoop();
}
catch(const exception &e){
wxMessageDialog(NULL, ToUnicode(e.what()), ToUnicode("Exception"), wxOK | wxICON_ERROR).ShowModal();
return 1;
}
return 0;
}
int App::OnExit(){
SystemFlags::Close();
SystemFlags::SHUTDOWN_PROGRAM_MODE=true;
return 0;
}
}}//end namespace
IMPLEMENT_APP_CONSOLE(Shared::G3dViewer::App)
|