PolycodePlayer.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. Copyright (C) 2011 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include <iostream>
  21. #include <fstream>
  22. #include "Polycode.h"
  23. #include "PolycodeLUA.h"
  24. #include "PolyGLSLShaderModule.h"
  25. #include "OSBasics.h"
  26. extern "C" {
  27. #include <stdio.h>
  28. #include "lua.h"
  29. #include "lualib.h"
  30. #include "lauxlib.h"
  31. // #include "lapi.h"
  32. using namespace Polycode;
  33. typedef struct {
  34. unsigned int lineNumber;
  35. char errorMessage[256];
  36. char fileName[256];
  37. unsigned int backTraceSize;
  38. } RemoteErrorData;
  39. typedef struct {
  40. unsigned int lineNumber;
  41. char fileName[256];
  42. } RemoteBacktraceData;
  43. class PolycodeRemoteDebuggerClient : public EventDispatcher {
  44. public:
  45. PolycodeRemoteDebuggerClient();
  46. ~PolycodeRemoteDebuggerClient();
  47. void handleEvent(Event *event);
  48. static const int EVENT_DEBUG_ERROR = 32;
  49. static const int EVENT_DEBUG_PRINT = 33;
  50. static const int EVENT_DEBUG_RESIZE = 34;
  51. static const int EVENT_DEBUG_REMOVE = 35;
  52. static const int EVENT_INJECT_CODE = 36;
  53. static const int EVENT_DEBUG_BACKTRACE_INFO = 37;
  54. Client *client;
  55. };
  56. class BackTraceEntry {
  57. public:
  58. String fileName;
  59. unsigned int lineNumber;
  60. };
  61. class PolycodeDebugEvent : public Event {
  62. public:
  63. PolycodeDebugEvent();
  64. ~PolycodeDebugEvent();
  65. int lineNumber;
  66. String errorString;
  67. String fileName;
  68. std::vector<BackTraceEntry> backTrace;
  69. int xRes;
  70. int yRes;
  71. static const int EVENT_ERROR = 0;
  72. static const int EVENT_PRINT = 1;
  73. static const int EVENT_RESIZE = 2;
  74. static const int EVENT_REMOVE = 3;
  75. };
  76. class PolycodePlayer : public EventDispatcher {
  77. public:
  78. PolycodePlayer(String fileName, bool knownArchive, bool useDebugger=false);
  79. virtual ~PolycodePlayer();
  80. void runPlayer();
  81. void loadFile(const char *fileName);
  82. void runFile(String fileName);
  83. int report (lua_State *L, int status);
  84. void handleEvent(Event *event);
  85. bool Update();
  86. virtual void createCore() = 0;
  87. Core *getCore() { return core; }
  88. int xRes;
  89. int yRes;
  90. int aaLevel;
  91. bool fullScreen;
  92. int frameRate;
  93. void *windowData;
  94. bool doneLoading;
  95. Core *core;
  96. String fullPath;
  97. protected:
  98. Timer *debuggerTimer;
  99. PolycodeRemoteDebuggerClient *remoteDebuggerClient;
  100. lua_State *L;
  101. bool useDebugger;
  102. bool doCodeInject;
  103. String injectCodeString;
  104. std::vector<String> loadedModules;
  105. bool _knownArchive;
  106. String fileToRun;
  107. };
  108. }