iw4x-client/src/Components/Modules/Script.hpp

70 lines
1.8 KiB
C++
Raw Normal View History

2017-01-20 08:36:52 -05:00
#pragma once
#include "Game/Structs.hpp"
2017-01-20 08:36:52 -05:00
2017-01-19 16:23:59 -05:00
namespace Components
{
class Script : public Component
{
public:
2017-05-14 14:14:52 -04:00
typedef void(Callback)();
class Function
{
public:
Function(std::string _name, Game::scr_function_t _callback, bool _dev) : name(_name), callback(_callback), dev(_dev) {}
const char* getName() const { return this->name.data(); }
bool isDev() const { return this->dev; }
Game::scr_function_t getFunction() const { return this->callback; }
private:
std::string name;
Game::scr_function_t callback;
bool dev;
};
2017-01-19 16:23:59 -05:00
Script();
~Script();
#if defined(DEBUG) || defined(FORCE_UNIT_TESTS)
2017-01-20 08:36:52 -05:00
const char* getName() override { return "Script"; };
2017-01-19 16:23:59 -05:00
#endif
static int LoadScriptAndLabel(std::string script, std::string label);
static void AddFunction(std::string name, Game::scr_function_t function, bool isDev = false);
2017-01-19 16:23:59 -05:00
2017-05-14 14:14:52 -04:00
static void OnVMShutdown(Utils::Slot<Callback> callback);
2017-01-19 16:23:59 -05:00
private:
static std::string ScriptName;
static std::vector<int> ScriptHandles;
static std::vector<Function> ScriptFunctions;
2017-01-19 16:23:59 -05:00
static std::vector<std::string> ScriptNameStack;
static unsigned short FunctionName;
2017-05-14 14:14:52 -04:00
static Utils::Signal<Callback> VMShutdownSignal;
2017-01-19 16:23:59 -05:00
static void CompileError(unsigned int offset, const char* message, ...);
static void PrintSourcePos(const char* filename, unsigned int offset);
static void FunctionError();
static void StoreFunctionNameStub();
static void StoreScriptName(const char* name);
static void StoreScriptNameStub();
static void RestoreScriptName();
static void RestoreScriptNameStub();
static void LoadGameType();
static void LoadGameTypeScript();
2017-04-29 17:08:41 -04:00
2017-05-14 14:14:52 -04:00
static Game::scr_function_t GetFunction(void* caller, const char** name, int* isDev);
static void GetFunctionStub();
2017-05-14 14:14:52 -04:00
static void ScrShutdownSystemStub(int);
2017-04-29 17:08:41 -04:00
static int SetExpFogStub();
2017-01-19 16:23:59 -05:00
};
}