114 lines
3.3 KiB
C++
114 lines
3.3 KiB
C++
#pragma once
|
|
#include "DeerCore/Tools/Memory.h"
|
|
#include "DeerCore/Tools/Path.h"
|
|
#include "DeerCore/Tools/TypeDefs.h"
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
class asIScriptEngine;
|
|
class asIScriptObject;
|
|
class asIScriptFunction;
|
|
class asITypeInfo;
|
|
class asIScriptContext;
|
|
class asIScriptModule;
|
|
|
|
namespace Deer {
|
|
class ScriptEnvironment;
|
|
class ScriptSystem;
|
|
class ScriptEnvironmentContextData;
|
|
class World;
|
|
|
|
namespace Scripting {
|
|
// The event type is necessary to know wich parameters to put
|
|
enum class EventType {
|
|
void_event // Defines a event with void as return and no parameter
|
|
};
|
|
|
|
struct SystemEvent {
|
|
EventType eventType;
|
|
std::string eventName;
|
|
SystemEvent(const std::string _name, EventType _type) : eventName(_name), eventType(_type) {}
|
|
};
|
|
|
|
struct SystemDescription {
|
|
std::string baseTypeName;
|
|
std::string moduleName;
|
|
std::vector<SystemEvent> events;
|
|
SystemDescription(const std::string& _baseTypeName, const std::string& _moduleName, const std::vector<SystemEvent>& _events = {}) : baseTypeName(_baseTypeName), moduleName(_moduleName), events(_events) {}
|
|
};
|
|
|
|
// Functions called by Engine
|
|
void init();
|
|
void shutdown();
|
|
|
|
void registerInterface(const char* name);
|
|
void registerInterfaceFunction(const char* name, const char* funcName, EventType funcType);
|
|
|
|
asIScriptEngine* getScriptEngine();
|
|
void compileFiles(const Path&, const char* moduleName);
|
|
|
|
Scope<ScriptEnvironment> createScriptEnvironment(const SystemDescription& systemDescription);
|
|
} // namespace Scripting
|
|
|
|
struct ScriptObjectGroup {
|
|
public:
|
|
// returns false if the object already existed
|
|
bool createScriptObject(size_t systemIndex);
|
|
|
|
void executeOnGroup_voidEvent(size_t eventIndex);
|
|
void executeOnObject_voidEvent(size_t systemIndex, size_t eventIndex);
|
|
|
|
private:
|
|
ScriptObjectGroup(ScriptEnvironment* env);
|
|
|
|
Scope<asIScriptObject*[]> systemInstances;
|
|
ScriptEnvironment* environment;
|
|
friend ScriptSystem;
|
|
friend ScriptEnvironment;
|
|
};
|
|
|
|
class ScriptSystem {
|
|
public:
|
|
const char* getSystemName();
|
|
|
|
private:
|
|
ScriptSystem(const Scripting::SystemDescription& desc, asITypeInfo* type);
|
|
|
|
asITypeInfo* systemType;
|
|
Scope<asIScriptFunction*[]> environmentFunctions;
|
|
|
|
friend ScriptEnvironment;
|
|
friend ScriptObjectGroup;
|
|
};
|
|
|
|
// Script Environment is based of one angelscript interface, the clas analizes all the classes that derives from that
|
|
// interface and calls them systems, I extract the functions as defined from system description and then the user can tell me to create a
|
|
// system group, a system group can have each system created or not
|
|
class ScriptEnvironment {
|
|
public:
|
|
~ScriptEnvironment();
|
|
|
|
ScriptObjectGroup* createGroupWithAllSystems();
|
|
ScriptObjectGroup* createEmptyGroup();
|
|
|
|
size_t getSystemCount();
|
|
ScriptSystem* getSystemByIndex(size_t index);
|
|
|
|
void tieWorld(World* world);
|
|
|
|
private:
|
|
Scripting::SystemDescription systemDescription;
|
|
asIScriptContext* context;
|
|
asIScriptModule* module;
|
|
asITypeInfo* baseType;
|
|
|
|
std::vector<Scope<ScriptSystem>> systems;
|
|
std::vector<Scope<ScriptObjectGroup>> systemGroups;
|
|
Scope<ScriptEnvironmentContextData> environmentContext;
|
|
|
|
ScriptEnvironment(const Scripting::SystemDescription&);
|
|
friend Scope<ScriptEnvironment> Scripting::createScriptEnvironment(const Scripting::SystemDescription& systemDescription);
|
|
friend ScriptObjectGroup;
|
|
};
|
|
} // namespace Deer
|