You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
/*
|
|
|
|
* Copyright (C) 2022 Riyyi
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ruc/meta/assert.h"
|
|
|
|
|
|
|
|
#include "inferno/script/nativescript.h"
|
|
|
|
|
|
|
|
namespace Inferno {
|
|
|
|
|
|
|
|
struct NativeScriptComponent {
|
|
|
|
NativeScript* instance { nullptr };
|
|
|
|
|
|
|
|
NativeScript* (*initialize)();
|
|
|
|
|
|
|
|
// Dont allow manually setting instance during construction
|
|
|
|
NativeScriptComponent() {}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void bind()
|
|
|
|
{
|
|
|
|
VERIFY(instance == nullptr, "NativeScript already bound");
|
|
|
|
initialize = []() { return static_cast<NativeScript*>(new T()); };
|
|
|
|
}
|
|
|
|
|
|
|
|
void destroy()
|
|
|
|
{
|
|
|
|
VERIFY(instance, "Attempting to destroy an uninitialized NativeScript");
|
|
|
|
delete instance;
|
|
|
|
instance = nullptr;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Inferno
|