Changeset View
Changeset View
Standalone View
Standalone View
source/simulation2/system/IComponent.h
/* Copyright (C) 2021 Wildfire Games. | /* Copyright (C) 2022 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 18 Lines | |||||
class CMessage; | class CMessage; | ||||
class ISerializer; | class ISerializer; | ||||
class IDeserializer; | class IDeserializer; | ||||
class IComponent | class IComponent | ||||
{ | { | ||||
public: | public: | ||||
// Component allocation types | // Component allocation types | ||||
using AllocFunc = IComponent* (*)(const ScriptInterface& scriptInterface, JS::HandleValue ctor); | using AllocFunc = IComponent* (*)(void* slot, const ScriptInterface& scriptInterface, JS::HandleValue ctor); | ||||
using DeallocFunc = void (*)(IComponent*); | using DeallocFunc = void (*)(IComponent*); | ||||
virtual ~IComponent(); | virtual ~IComponent(); | ||||
static std::string GetSchema(); | static std::string GetSchema(); | ||||
static void RegisterComponentType(CComponentManager& mgr, EInterfaceId iid, EComponentTypeId cid, AllocFunc alloc, DeallocFunc dealloc, const char* name, const std::string& schema); | static void RegisterComponentType(CComponentManager& mgr, EInterfaceId iid, EComponentTypeId cid, AllocFunc alloc, DeallocFunc dealloc, size_t size, size_t align, const char* name, const std::string& schema); | ||||
static void RegisterComponentTypeScriptWrapper(CComponentManager& mgr, EInterfaceId iid, EComponentTypeId cid, AllocFunc alloc, DeallocFunc dealloc, const char* name, const std::string& schema); | static void RegisterComponentTypeScriptWrapper(CComponentManager& mgr, EInterfaceId iid, EComponentTypeId cid, AllocFunc alloc, DeallocFunc dealloc, size_t size, size_t align, const char* name, const std::string& schema); | ||||
virtual void Init(const CParamNode& paramNode) = 0; | virtual void Init(const CParamNode& paramNode) = 0; | ||||
virtual void Deinit() = 0; | virtual void Deinit() = 0; | ||||
virtual void HandleMessage(const CMessage& msg, bool global); | virtual void HandleMessage(const CMessage& msg, bool global); | ||||
CEntityHandle GetEntityHandle() const { return m_EntityHandle; } | CEntityHandle GetEntityHandle() const { return m_EntityHandle; } | ||||
void SetEntityHandle(CEntityHandle ent) { m_EntityHandle = ent; } | void SetEntityHandle(CEntityHandle ent) { m_EntityHandle = ent; } | ||||
Show All 11 Lines | public: | ||||
/** | /** | ||||
* Returns false by default, indicating that a scripted wrapper of this IComponent is not supported. | * Returns false by default, indicating that a scripted wrapper of this IComponent is not supported. | ||||
* Derrived classes should return true if they implement such a wrapper. | * Derrived classes should return true if they implement such a wrapper. | ||||
*/ | */ | ||||
virtual bool NewJSObject(const ScriptInterface& scriptInterface, JS::MutableHandleObject out) const; | virtual bool NewJSObject(const ScriptInterface& scriptInterface, JS::MutableHandleObject out) const; | ||||
virtual JS::Value GetJSInstance() const; | virtual JS::Value GetJSInstance() const; | ||||
virtual int GetComponentTypeId() const = 0; | virtual int GetComponentTypeId() const = 0; | ||||
void SetInvalid() { m_EntityHandle.SetInvalid(); } | |||||
bool IsValid() const { return GetEntityId() != INVALID_ENTITY; } | |||||
private: | private: | ||||
CEntityHandle m_EntityHandle; | CEntityHandle m_EntityHandle; | ||||
const CSimContext* m_SimContext; | const CSimContext* m_SimContext; | ||||
}; | }; | ||||
#endif // INCLUDED_ICOMPONENT | #endif // INCLUDED_ICOMPONENT |
Wildfire Games · Phabricator