Kaynağa Gözat

Place proper type check for StaticModel vs. AnimatedModel SetModel() into AngelScript API instead of StaticModel C++ code logging a warning and redirecting. Add a porting note related to this.

Lasse Öörni 8 yıl önce
ebeveyn
işleme
1b725367fc

+ 1 - 0
Docs/Urho3D.dox

@@ -1072,6 +1072,7 @@ From 1.6 to master:
 - Rendertargets have gained the ability to have automatically regenerated mipmaps. Screen buffers received from the Renderer subsystem have mipmaps off, but for manually created rendertargets the default is mipmaps on, like for ordinary textures. Use SetNumLevels(1) to disable.
 - Rendertargets have gained the ability to have automatically regenerated mipmaps. Screen buffers received from the Renderer subsystem have mipmaps off, but for manually created rendertargets the default is mipmaps on, like for ordinary textures. Use SetNumLevels(1) to disable.
 - The shader function GetWorldTangent() now returns a 4-component vector.
 - The shader function GetWorldTangent() now returns a 4-component vector.
 - Build system - the "Urho3D-CMake-common.cmake" file is now renamed to "UrhoCommon.cmake".
 - Build system - the "Urho3D-CMake-common.cmake" file is now renamed to "UrhoCommon.cmake".
+- StaticModel::SetModel() will no longer warn and redirect to AnimatedModel::SetModel() if the wrong function is called from C++ code. The AngelScript API will instead redirect properly without producing a warning.
 */
 */
 
 
 }
 }

+ 11 - 1
Source/Urho3D/AngelScript/GraphicsAPI.cpp

@@ -1292,13 +1292,23 @@ static void RegisterZone(asIScriptEngine* engine)
     engine->RegisterObjectMethod("Zone", "Texture@+ get_zoneTexture() const", asMETHOD(Zone, GetZoneTexture), asCALL_THISCALL);
     engine->RegisterObjectMethod("Zone", "Texture@+ get_zoneTexture() const", asMETHOD(Zone, GetZoneTexture), asCALL_THISCALL);
 }
 }
 
 
+static void StaticModelSetModel(Model* model, StaticModel* ptr)
+{
+    // Check type here to allow operating on both AnimatedModel and StaticModel without calling the wrong function,
+    // as AnimatedModel can be cast to StaticModel
+    if (ptr->GetType() == AnimatedModel::GetTypeStatic())
+        static_cast<AnimatedModel*>(ptr)->SetModel(model);
+    else
+        ptr->SetModel(model);
+}
+
 static void RegisterStaticModel(asIScriptEngine* engine)
 static void RegisterStaticModel(asIScriptEngine* engine)
 {
 {
     RegisterDrawable<StaticModel>(engine, "StaticModel");
     RegisterDrawable<StaticModel>(engine, "StaticModel");
     engine->RegisterObjectMethod("StaticModel", "void ApplyMaterialList(const String&in fileName = String())", asMETHOD(StaticModel, ApplyMaterialList), asCALL_THISCALL);
     engine->RegisterObjectMethod("StaticModel", "void ApplyMaterialList(const String&in fileName = String())", asMETHOD(StaticModel, ApplyMaterialList), asCALL_THISCALL);
     engine->RegisterObjectMethod("StaticModel", "bool IsInside(const Vector3&in) const", asMETHOD(StaticModel, IsInside), asCALL_THISCALL);
     engine->RegisterObjectMethod("StaticModel", "bool IsInside(const Vector3&in) const", asMETHOD(StaticModel, IsInside), asCALL_THISCALL);
     engine->RegisterObjectMethod("StaticModel", "bool IsInsideLocal(const Vector3&in) const", asMETHOD(StaticModel, IsInsideLocal), asCALL_THISCALL);
     engine->RegisterObjectMethod("StaticModel", "bool IsInsideLocal(const Vector3&in) const", asMETHOD(StaticModel, IsInsideLocal), asCALL_THISCALL);
-    engine->RegisterObjectMethod("StaticModel", "void set_model(Model@+)", asMETHOD(StaticModel, SetModel), asCALL_THISCALL);
+    engine->RegisterObjectMethod("StaticModel", "void set_model(Model@+)", asFUNCTION(StaticModelSetModel), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod("StaticModel", "Model@+ get_model() const", asMETHOD(StaticModel, GetModel), asCALL_THISCALL);
     engine->RegisterObjectMethod("StaticModel", "Model@+ get_model() const", asMETHOD(StaticModel, GetModel), asCALL_THISCALL);
     engine->RegisterObjectMethod("StaticModel", "void set_material(Material@+)", asMETHODPR(StaticModel, SetMaterial, (Material*), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("StaticModel", "void set_material(Material@+)", asMETHODPR(StaticModel, SetMaterial, (Material*), void), asCALL_THISCALL);
     engine->RegisterObjectMethod("StaticModel", "bool set_materials(uint, Material@+)", asMETHODPR(StaticModel, SetMaterial, (unsigned, Material*), bool), asCALL_THISCALL);
     engine->RegisterObjectMethod("StaticModel", "bool set_materials(uint, Material@+)", asMETHODPR(StaticModel, SetMaterial, (unsigned, Material*), bool), asCALL_THISCALL);

+ 0 - 9
Source/Urho3D/Graphics/StaticModel.cpp

@@ -234,15 +234,6 @@ void StaticModel::SetModel(Model* model)
     if (model == model_)
     if (model == model_)
         return;
         return;
 
 
-    // If script erroneously calls StaticModel::SetModel on an AnimatedModel, warn and redirect
-    if (GetType() == AnimatedModel::GetTypeStatic())
-    {
-        URHO3D_LOGWARNING("StaticModel::SetModel() called on AnimatedModel. Redirecting to AnimatedModel::SetModel()");
-        AnimatedModel* animatedModel = static_cast<AnimatedModel*>(this);
-        animatedModel->SetModel(model);
-        return;
-    }
-
     if (!node_)
     if (!node_)
     {
     {
         URHO3D_LOGERROR("Can not set model while model component is not attached to a scene node");
         URHO3D_LOGERROR("Can not set model while model component is not attached to a scene node");