main.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "PolycodeWindowsPlayer.h"
  2. #include <Polycode.h>
  3. #include "PolycodePlayerView.h"
  4. #include "windows.h"
  5. #include "resource.h"
  6. #define STANDALONE_MODE
  7. using namespace Polycode;
  8. extern Win32Core *core;
  9. void wtoc(char* Dest, TCHAR* Source, int SourceSize)
  10. {
  11. for(int i = 0; i < SourceSize; ++i)
  12. Dest[i] = (char)Source[i];
  13. }
  14. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  15. {
  16. String args = String(GetCommandLineW());
  17. String fileName;
  18. for(int i=0; i < args.length(); i++) {
  19. if(args[i] != '\"')
  20. fileName += args.substr(i, 1);
  21. if(args[i] == '\"' && i != args.length()-1)
  22. fileName = "";
  23. }
  24. if(fileName == " ")
  25. fileName = "";
  26. if(fileName.length() > 1) {
  27. fileName = fileName.replace(":", "");
  28. fileName = fileName.replace("\\", "/");
  29. fileName = fileName.substr(1, fileName.length() - 1);
  30. }
  31. char path[2049];
  32. TCHAR tpath[2049];
  33. GetModuleFileName(NULL, (LPWSTR)tpath, 2048);
  34. wtoc(path, tpath, 2048);
  35. String basePath = path;
  36. vector<String> cpts = basePath.split("\\");
  37. String installPath = "";
  38. for(int i=0; i < cpts.size() - 1; i++) {
  39. installPath = installPath + cpts[i];
  40. installPath += String("\\");
  41. }
  42. SetCurrentDirectory(installPath.wc_str());
  43. // fileName = "[" + fileName + "]";
  44. // MessageBox(NULL, fileName.wc_str(), L"", MB_OK);
  45. // fileName = L"/Documents and Settings/Administrator/Desktop/Workshop/HelloPolycodeLUA/ExampleProject.polyapp";
  46. #ifdef STANDALONE_MODE
  47. PolycodePlayerView *view = new PolycodePlayerView(true, hInstance, nCmdShow, L"");
  48. PolycodeWindowsPlayer *player = new PolycodeWindowsPlayer(view, "main.polyapp", false);
  49. #else
  50. PolycodePlayerView *view = new PolycodePlayerView(false, hInstance, nCmdShow, L"Polycode Player");
  51. PolycodeWindowsPlayer *player = new PolycodeWindowsPlayer(view, fileName.c_str(), false, true);
  52. #endif
  53. player->addEventListener(view, PolycodeDebugEvent::EVENT_ERROR);
  54. player->addEventListener(view, PolycodeDebugEvent::EVENT_PRINT);
  55. player->runPlayer();
  56. core = (Win32Core*)player->getCore();
  57. MSG Msg;
  58. do {
  59. while (PeekMessage(&Msg, NULL, 0, 0, PM_REMOVE)) {
  60. TranslateMessage(&Msg);
  61. DispatchMessage(&Msg);
  62. }
  63. } while(player->Update());
  64. return Msg.wParam;
  65. }