project64/Source/Project64/UserInterface/Debugger/ScriptSystem.h

104 lines
3.3 KiB
C
Raw Normal View History

#include <windows.h>
#include <fstream>
#include <map>
2017-08-18 05:08:22 +00:00
#include "ScriptTypes.h"
#include "debugger.h"
2017-08-18 05:08:22 +00:00
#pragma once
2017-08-18 05:08:22 +00:00
#define SCRIPTSYS_SCRIPTS_DIR "Scripts\\"
#define SCRIPTSYS_MODULES_DIR "Scripts\\modules\\"
2017-08-18 05:08:22 +00:00
class CScriptSystem
{
typedef std::map<JSInstanceName, CScriptInstance*> JSInstanceMap;
typedef std::map<JSAppCallbackID, JSAppCallback> JSAppCallbackMap;
typedef std::map<JSAppHookID, JSAppCallbackMap> JSAppHookMap;
typedef std::map<JSInstanceName, JSInstanceStatus> JSInstanceStatusMap;
typedef std::vector<JSSysCommand> JSSysCommandQueue;
2017-08-18 05:08:22 +00:00
HANDLE m_hThread;
2017-08-18 05:08:22 +00:00
CriticalSection m_CmdQueueCS;
JSSysCommandQueue m_CmdQueue;
HANDLE m_hCmdEvent;
2017-08-18 05:08:22 +00:00
CriticalSection m_InstancesCS;
JSInstanceMap m_Instances;
JSAppHookMap m_AppCallbackHooks;
JSAppCallbackID m_NextAppCallbackId;
size_t m_AppCallbackCount;
2017-08-18 05:08:22 +00:00
CriticalSection m_UIStateCS;
JSInstanceStatusMap m_UIInstanceStatus;
stdstr m_UILog;
2017-08-18 05:08:22 +00:00
CDebuggerUI* m_Debugger;
2017-08-18 05:08:22 +00:00
std::set<std::string> m_AutorunList;
2017-08-18 05:08:22 +00:00
stdstr m_InstallDirFullPath;
stdstr m_ScriptsDirFullPath;
stdstr m_ModulesDirFullPath;
2017-08-18 05:08:22 +00:00
public:
CScriptSystem(CDebuggerUI* debugger);
~CScriptSystem();
CDebuggerUI* Debugger();
void StartScript(const char* instanceName, const char* path);
void StopScript(const char* instanceName);
void Input(const char* instanceName, const char* code);
stdstr InstallDirPath();
stdstr ScriptsDirPath();
stdstr ModulesDirPath();
JSInstanceStatus GetStatus(const char* instanceName);
void NotifyStatus(const char* instanceName, JSInstanceStatus status);
void ConsoleLog(const char* format, ...);
void ConsolePrint(const char* format, ...);
void ConsoleClear();
stdstr GetConsoleBuffer();
void PostCMethodCall(const char* instanceName, void* dukThisHeapPtr, duk_c_function func,
JSDukArgSetupFunc argSetupFunc = nullptr,
void* argSetupParam = nullptr,
size_t argSetupParamSize = 0);
bool HaveAppCallbacks(JSAppHookID hookId);
void InvokeAppCallbacks(JSAppHookID hookId, void* env = nullptr);
void DoMouseEvent(JSAppHookID hookId, int x, int y, DWORD uMsg = (DWORD)-1);
JSAppCallbackID RawAddAppCallback(JSAppHookID hookId, JSAppCallback& callback);
bool RawRemoveAppCallback(JSAppHookID hookId, JSAppCallbackID callbackId);
void ExecAutorunList();
std::set<std::string>& AutorunList();
void LoadAutorunList();
void SaveAutorunList();
private:
void InitDirectories();
2017-08-18 05:08:22 +00:00
void PostCommand(JSSysCommandID id, stdstr paramA = "", stdstr paramB = "", void* paramC = nullptr);
static DWORD WINAPI ThreadProc(void* _this);
void ThreadProc();
2017-08-18 05:08:22 +00:00
bool ProcessCommand(JSSysCommand& cmd);
bool ProcessCommandQueue(std::vector<JSSysCommand>& queue);
void PullCommands(JSSysCommandID id, std::vector<JSSysCommand>& out);
2017-08-18 05:08:22 +00:00
void OnStartScript(const char* name, const char* path);
void OnStopScript(const char* name);
void OnInput(const char* name, const char* code);
void OnCMethodCall(const char* name, JSSysCMethodCall* methodCall);
void OnSweep(bool bIfDone);
2017-08-18 05:08:22 +00:00
bool RawRemoveInstance(const char* key);
static stdstr FixStringReturns(const char* str);
};