Hello,
I am trying to be able to use “GameAssetManager@ AssetManager;” in angelscript for example including calling functions from it. I know how to register components but I’m not sure how to register it fully in the script engine. I’m starting off with this base code.
[code]void EngineEditorApp::Start()
{
// Start the app
EngineApp::Start();
// Register here
GameAssetManager::RegisterObject(context_);
// Get Resource path
ResourceCache * ResCache = g_pApp->GetConstantResCache();
m_bIsInit = true;
// Set Script file
String scriptFileName_ = String("Scripts/Editor.as");
String extension = GetExtension(scriptFileName_);
if (extension != ".lua" && extension != ".luc")
{
// Instantiate and register the AngelScript subsystem
context_->RegisterSubsystem(new Script(context_));
// Get Script engine
asIScriptEngine * ThisScriptEngine = GetSubsystem<Script>()->GetScriptEngine();
// Pass Engine
GameAssetManager::RegisterAPI(ThisScriptEngine);
// Hold a shared pointer to the script file to make sure it is not unloaded during runtime
scriptFile_= ResCache ->GetResource<ScriptFile>(scriptFileName_);
/// \hack If we are running the editor, also instantiate Lua subsystem to enable editing Lua ScriptInstances
// If script loading is successful, proceed to main loop
if (scriptFile_ && scriptFile_->Execute("void Start()"))
{
// Subscribe to script's reload event to allow live-reload of the application
SubscribeToEvent(scriptFile_, E_RELOADSTARTED, URHO3D_HANDLER(EngineEditorApp, HandleScriptReloadStarted));
SubscribeToEvent(scriptFile_, E_RELOADFINISHED, URHO3D_HANDLER(EngineEditorApp, HandleScriptReloadFinished));
SubscribeToEvent(scriptFile_, E_RELOADFAILED, URHO3D_HANDLER(EngineEditorApp, HandleScriptReloadFailed));
return;
}
}
}
[/code]
and
[code]#include “EngineStd.h”
#include
using namespace std;
#include “GameAsset.h”
#include “GameAssetRules.h”
#include “GameAssetManager.h”
#include “Urho3D/AngelScript/APITemplates.h”
// constructor - initialize set default
GameAssetManager::GameAssetManager(Context* context)
:LogicComponent(context)
,m_pGameAssetLibrary(NULL)
,m_pGameAssetRuleLibrary(NULL)
,m_pGameAssetResources(NULL)
{
// GameAssetLibrary
m_pGameAssetLibrary = new Vector<GameAsset*>();
m_pGameAssetRuleLibrary = new Vector<GameAssetRule*>();
}
// Register Subsystem
void GameAssetManager::RegisterObject(Context* context)
{
///context -> RegisterSubsystem(new GameAssetManager(context));
context->RegisterFactory<GameAssetManager>("EngineStd");
return;
}
void GameAssetManager::RegisterAPI(asIScriptEngine * engine)
{
engine->RegisterObjectType(“GameAssetManager”,0, asOBJ_REF); // asOBJ_REF because you wanted a reference call
engine->RegisterObjectBehaviour("GameAssetManager",asBEHAVE_ADDREF,"void f()",asFUNCTION(FakeAddRef),asCALL_CDECL_OBJLAST);
engine->RegisterObjectBehaviour("GameAssetManager",asBEHAVE_RELEASE,"void f()",asFUNCTION(FakeReleaseRef),asCALL_CDECL_OBJLAST);
}
// setup asset path
void GameAssetManager::Init(void)
{
// get file system
FileSystem* filesystem = GetSubsystem();
m_pGameAssetResources = new GameAssetData(context_);
// Set Data filename
m_pGameAssetResources->SetAddDataFile(String("GameData.pak"));
// initalize base assets
InitializeBaseGameAssets();
return;
}
// add game asset - base symbol
GameAsset * GameAssetManager::AddGameAsset(String GA_Name, String GA_Symbol,GameAssetType GA_Type, GameAssetState GA_State)
{
// if asset library is null
if(!m_pGameAssetLibrary)
{
return NULL;
}
// check valid
if(GA_Name.Empty() || GA_Symbol.Empty())
{
return NULL;
}
// check if state or type is valid
if(GA_Type == GAType_None || GA_State==GAState_None)
{
return NULL;
}
// create new game asset
GameAsset * newGameAsset;
newGameAsset = new GameAsset(context_);
newGameAsset ->SetSymbol(GA_Symbol);
newGameAsset ->SetTypeState(GA_Type, GA_State);
// add to library
m_pGameAssetLibrary->Push(newGameAsset);
return newGameAsset;
}
[/code]
In the header I defined RegisterObject and RegisterAPI as static void
When I run the editor it says GameAssetManager is not a valid name identifier in the global namespace and the rest of the .as script doesn’t compile. I modifed the code to the above.
I’m just get this when compiling.
||=== Build: EngineEditor in Urho3D (compiler: GNU GCC Compiler) ===|
rho3D-Hangars-Myfork-BuildEditor/include/Urho3D/ThirdParty/AngelScript/angelscript.h|421|error: cannot convert ?GameAssetManager::FakeAddRef? from type ?void (GameAssetManager::)(void*)? to type ?void (GameAssetManager::*)(void*)?|
rho3D-Hangars-MyForkEditor/Source/EngineStd/GameAssetManager/GameAssetManager.cpp|42|note: in expansion of macro ?asFUNCTION?|
Urho3D-Hangars-Myfork-BuildEditor/include/Urho3D/ThirdParty/AngelScript/angelscript.h|421|error: cannot convert ?GameAssetManager::FakeReleaseRef? from type ?void (GameAssetManager::)(void*)? to type ?void (GameAssetManager::*)(void*)?|
Urho3D-Hangars-MyForkEditor/Source/EngineStd/GameAssetManager/GameAssetManager.cpp|43|note: in expansion of macro ?asFUNCTION?|
Urho3D-Hangars-Myfork-BuildEditor/include/Urho3D/ThirdParty/AngelScript/angelscript.h||In instantiation of ?asSFuncPtr asFunctionPtr(T) [with T = void (GameAssetManager::*)(void*)]?:|
rho3D-Hangars-MyForkEditor/Source/EngineStd/GameAssetManager/GameAssetManager.cpp|42|required from here|
Urho3D-Hangars-Myfork-BuildEditor/include/Urho3D/ThirdParty/AngelScript/angelscript.h|1184|error: invalid cast from type ?void (GameAssetManager::*)(void*)? to type ?size_t {aka long unsigned int}?|
||=== Build failed: 3 error(s), 2 warning(s) (0 minute(s), 20 second(s)) ===|
Any help is appreciated.
Vivienne