/************************************************************************************//*!
\file ECS.hxx
\author Tng Kah Wei, kahwei.tng, 390009620
\par email: kahwei.tng\@digipen.edu
\date Oct 28, 2021
\brief Contains the definitions of the GameObject managed class which define an
abstraction for working with Entities in managed code.
Note: This file is written in C++17/CLI.
Copyright (C) 2021 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent
of DigiPen Institute of Technology is prohibited.
*//*************************************************************************************/
#pragma once
// External Dependencies
#include "ECS_Base/Managers/SHComponentManager.h"
// Project Includes
#include "Components/Component.hxx"
namespace SHADE
{
///
/// Static class which contains functions that map Pls::ECS's Component manipulation
/// functions to managed generic functions.
///
private ref class ECS abstract sealed
{
public:
/*-----------------------------------------------------------------------------*/
/* Component Manipulation Functions */
/*-----------------------------------------------------------------------------*/
///
/// Adds a Component to the specified Entity.
///
/// Type of the Component to add.
///
/// Entity object that should have the specified Component added to.
///
/// Reference to the Component that was added.
generic where T : BaseComponent
static T AddComponent(EntityID entity);
///
/// Gets a Component from the specified Entity.
///
/// Type of the Component to get.
/// Entity object to get the Component from.
///
/// Reference to the Component or null if the Entity does not have the
/// specified Component.
///
generic where T : BaseComponent
static T GetComponent(EntityID entity);
///
/// Retrieves the first Component from the specified GameObjectt's children that
/// matches the specified type.
///
/// Type of the Component to get.
/// Entity object to get the Component from.
///
/// Reference to the Component or null if the Entity does not have the
/// specified Component.
///
generic where T : BaseComponent
static T GetComponentInChildren(EntityID entity);
///
/// Ensures a Component on the specified Entity.
///
/// Type of the Component to ensure.
/// Entity object to ensure the Component on.
/// Reference to the Component.
generic where T : BaseComponent
static T EnsureComponent(EntityID entity);
///
/// Checks if the specified Entity has the specified Component.
///
/// Type of the Component to check for.
/// Entity object to check for the Component.
///
/// True if the specified Entity has the specified Component. False otherwise.
///
generic where T : BaseComponent
static bool HasComponent(EntityID entity);
///
/// Removes a Component from the specified Entity.
///
/// Type of the Component to remove.
///
/// Entity object that should have the specified Component removed from/
///
generic where T : BaseComponent
static void RemoveComponent(EntityID entity);
internal:
/*-----------------------------------------------------------------------------*/
/* Type Definitions */
/*-----------------------------------------------------------------------------*/
///
/// Pointer to a function for Component manipulation operations.
///
using ComponentFunc = void(*)(EntityID) noexcept;
using ComponentHasFunc = bool(*)(EntityID) noexcept;
///
/// Contains a set of Component related data used for resolving operations for
/// each Component.
///
value struct ComponentSet
{
public:
System::Type^ Type;
ComponentFunc AddFunction;
ComponentHasFunc HasFunction;
ComponentFunc RemoveFunction;
};
/*-----------------------------------------------------------------------------*/
/* Static Functions */
/*-----------------------------------------------------------------------------*/
///
/// Retrieves a pointer to the native unmanaged component of the specified
/// Entity.
///
///
/// Pointer to the native component. Will be nullptr if it does not exist.
///
///
/// Thrown if the Entity specified is invalid.
///
///
/// Thrown if an attempt to retrieve the native component fails.
///
template
static NativeComponent* GetNativeComponent(Entity entity);
private:
/*-----------------------------------------------------------------------------*/
/* Constructors */
/*-----------------------------------------------------------------------------*/
///
/// Static constructor to initialize static data
///
static ECS();
/*-----------------------------------------------------------------------------*/
/* Static Data Members */
/*-----------------------------------------------------------------------------*/
static System::Collections::Generic::List componentMap;
/*-----------------------------------------------------------------------------*/
/* Helper Functions */
/*-----------------------------------------------------------------------------*/
///
/// Creates a ComponentSet for a pair of Native and Managed Components.
///
/// Type of the Native Component.
/// Type of the Managed Component.
/// ComponentSet for the parameters specified.
template
static ComponentSet createComponentSet();
///
/// Creates an instance of the Managed representation of a Component with a
/// native Entity.
///
/// Type of Component to create.
/// Native Entity that this Component is tied to.
/// The created Managed representation of the Component.
generic where T : BaseComponent
static T createManagedComponent(EntityID entity);
};
}
#include "ECS.h++"