Skip to content

Commit

Permalink
📜 Scripting: added Ogre::TexturePtr, updated ImGui::Draw()
Browse files Browse the repository at this point in the history
  • Loading branch information
ohlidalp authored and Petr Ohlídal committed Aug 31, 2021
1 parent d7fde3a commit c8fcec8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
6 changes: 3 additions & 3 deletions source/main/scripting/ImGuiAngelscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ void RoR::RegisterImGuiBindings(asIScriptEngine* engine)
return ImGui::SmallButton(n.c_str()); }, (const string&), bool), asCALL_CDECL);
engine->RegisterGlobalFunction("bool InvisibleButton(const string&in, vector2)", asFUNCTIONPR([](const string& id, Vector2 v) {
return ImGui::InvisibleButton(id.c_str(), ImVec2(v.x, v.y)); }, (const string&, Vector2), bool), asCALL_CDECL);
engine->RegisterGlobalFunction("void Image(uint, vector2)", asFUNCTIONPR([](unsigned u, Vector2 v) {
ImGui::Image((ImTextureID)u, ImVec2(v.x, v.y));
}, (unsigned, Vector2), void), asCALL_CDECL);
engine->RegisterGlobalFunction("void Image(const Ogre::TexturePtr&in, vector2)", asFUNCTIONPR([](Ogre::TexturePtr const& tex, Vector2 v) {
ImGui::Image((ImTextureID)tex->getHandle(), ImVec2(v.x, v.y));
}, (Ogre::TexturePtr const&, Vector2), void), asCALL_CDECL);
engine->RegisterGlobalFunction("bool Checkbox(const string&in, bool&inout)", asFUNCTIONPR([](const string& n, bool& v) {
return ImGui::Checkbox(n.c_str(), &v); }, (const string&, bool&), bool), asCALL_CDECL);
engine->RegisterGlobalFunction("bool CheckboxFlags(const string&in, uint&inout, uint)", asFUNCTIONPR([](const string& n, unsigned& f, unsigned v) {
Expand Down
53 changes: 53 additions & 0 deletions source/main/scripting/OgreAngelscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,34 @@ static void ColourValueCopyConstructor(const ColourValue& other, ColourValue* se
new(self) ColourValue(other.r, other.g, other.b, other.a);
}

/***TEXTURE***/
static void TexturePtrDefaultConstructor(TexturePtr* self)
{
new (self) TexturePtr();
}

static void TexturePtrCopyConstructor(const TexturePtr& other, TexturePtr* self)
{
new (self) TexturePtr(other);
}

static void TexturePtrDestructor(TexturePtr* self)
{
(self)->~TexturePtr();
}

static void TexturePtrAssignOperator(const TexturePtr& other, TexturePtr* self)
{
(self)->operator=(other);
}

// forward declarations, defined below
void registerOgreVector3(AngelScript::asIScriptEngine* engine);
void registerOgreVector2(AngelScript::asIScriptEngine* engine);
void registerOgreRadian(AngelScript::asIScriptEngine* engine);
void registerOgreDegree(AngelScript::asIScriptEngine* engine);
void registerOgreQuaternion(AngelScript::asIScriptEngine* engine);
void registerOgreTexture(AngelScript::asIScriptEngine* engine);

// main registration method
void RoR::RegisterOgreObjects(AngelScript::asIScriptEngine* engine)
Expand Down Expand Up @@ -238,6 +260,7 @@ void RoR::RegisterOgreObjects(AngelScript::asIScriptEngine* engine)
registerOgreVector3(engine);
registerOgreVector2(engine);
registerOgreQuaternion(engine);
registerOgreTexture(engine);
}

// register Ogre::Vector3
Expand Down Expand Up @@ -757,3 +780,33 @@ void registerOgreColourValue(AngelScript::asIScriptEngine* engine)
ROR_ASSERT( r >= 0 );
r = engine->RegisterObjectBehaviour("color", asBEHAVE_CONSTRUCT, "void f(const color &other)", asFUNCTION(QuaternionCopyConstructor), asCALL_CDECL_OBJLAST);
}

void registerOgreTexture(AngelScript::asIScriptEngine* engine)
{
engine->SetDefaultNamespace("Ogre");
engine->RegisterObjectType("TexturePtr", sizeof(TexturePtr), asOBJ_VALUE | asGetTypeTraits<TexturePtr>());
engine->RegisterObjectBehaviour("TexturePtr", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(TexturePtrDefaultConstructor), asCALL_CDECL_OBJLAST);
engine->RegisterObjectBehaviour("TexturePtr", asBEHAVE_CONSTRUCT, "void f(const TexturePtr&in)", asFUNCTION(TexturePtrCopyConstructor), asCALL_CDECL_OBJLAST);
engine->RegisterObjectBehaviour("TexturePtr", asBEHAVE_DESTRUCT, "void f()", asFUNCTION(TexturePtrDestructor), asCALL_CDECL_OBJLAST);
engine->RegisterObjectMethod("TexturePtr", "TexturePtr& opAssign(const TexturePtr&in)", asFUNCTION(TexturePtrAssignOperator), asCALL_CDECL_OBJLAST);

// Wrappers are inevitable, see https://www.gamedev.net/forums/topic/540419-custom-smartpointers-and-angelscript-/
engine->RegisterObjectMethod("TexturePtr", "uint getWidth()", asFUNCTIONPR([](TexturePtr const& self){
return (Ogre::uint32)self->getWidth();
}, (TexturePtr const&), Ogre::uint32), asCALL_CDECL_OBJFIRST);
engine->RegisterObjectMethod("TexturePtr", "uint getHeight()", asFUNCTIONPR([](TexturePtr const& self){
return (Ogre::uint32)self->getHeight();
}, (TexturePtr const&), Ogre::uint32), asCALL_CDECL_OBJFIRST);

engine->RegisterObjectType("TextureManager", sizeof(TextureManager), asOBJ_REF | asOBJ_NOCOUNT);
// Convenience wrapper to omit optional parameters
engine->RegisterObjectMethod("TextureManager", "TexturePtr load(string file, string rg)", asFUNCTIONPR([](TextureManager& mgr, std::string const& file, std::string const& rg){
return mgr.load(file, rg);
}, (TextureManager& mgr, std::string const& file, std::string const& rg), TexturePtr), asCALL_CDECL_OBJFIRST);


engine->SetDefaultNamespace("Ogre::TextureManager");
engine->RegisterGlobalFunction("TextureManager& getSingleton()", asFUNCTION(TextureManager::getSingleton), asCALL_CDECL);

engine->SetDefaultNamespace("");
}

0 comments on commit c8fcec8

Please # to comment.