Procházet zdrojové kódy

Exposed Model::getSkeleton() to script.
Added possibility to throw an exception without logging an error.
Added function to retrieve the last log message.
Added check for ScriptFile loading successfully in the Urho3D Shell.

Lasse Öörni před 15 roky
rodič
revize
080d52e93c

+ 6 - 4
Engine/Common/Exception.cpp

@@ -30,17 +30,19 @@
 
 
 #include "DebugNew.h"
 #include "DebugNew.h"
 
 
-Exception::Exception(const std::string& what) :
+Exception::Exception(const std::string& what, bool logError) :
     mWhat(what)
     mWhat(what)
 {
 {
-    LOGERROR(what);
+    if (logError)
+        LOGERROR(what);
 }
 }
 
 
 #ifdef _DEBUG
 #ifdef _DEBUG
-Exception::Exception(const std::string& what, const char* file, int line)
+Exception::Exception(const std::string& what, const char* file, int line, bool logError)
 {
 {
     mWhat = what + std::string(" at ") + std::string(file) + std::string(", line ") + toString(line);
     mWhat = what + std::string(" at ") + std::string(file) + std::string(", line ") + toString(line);
-    LOGERROR(mWhat);
+    if (logError)
+        LOGERROR(mWhat);
 }
 }
 #endif
 #endif
 
 

+ 2 - 2
Engine/Common/Exception.h

@@ -44,12 +44,12 @@ class Exception : public std::exception
 {
 {
 public:
 public:
     //! Construct with exception reason
     //! Construct with exception reason
-    Exception(const std::string& what);
+    Exception(const std::string& what, bool logError = true);
     //! Destruct
     //! Destruct
     virtual ~Exception() throw();
     virtual ~Exception() throw();
     #ifdef _DEBUG
     #ifdef _DEBUG
     //! Construct with exception reason and location information
     //! Construct with exception reason and location information
-    Exception(const std::string& what, const char* file, int line);
+    Exception(const std::string& what, const char* file, int line, bool logError = true);
     #endif
     #endif
     
     
     //! Return exception reason
     //! Return exception reason

+ 4 - 0
Engine/Common/Log.cpp

@@ -77,6 +77,8 @@ void Log::write(LogLevel level, const std::string& message)
     if ((mLevel > level) || (level == LOG_NONE))
     if ((mLevel > level) || (level == LOG_NONE))
         return;
         return;
     
     
+    mLastMessage = message;
+    
     static time_t sysTime;
     static time_t sysTime;
     time(&sysTime);
     time(&sysTime);
     const char* dateTime = ctime(&sysTime);
     const char* dateTime = ctime(&sysTime);
@@ -97,6 +99,8 @@ void Log::write(LogLevel level, const std::string& message)
 
 
 void Log::writeRaw(const std::string& message)
 void Log::writeRaw(const std::string& message)
 {
 {
+    mLastMessage = message;
+    
     printf("%s", message.c_str());
     printf("%s", message.c_str());
     
     
     if (mHandle)
     if (mHandle)

+ 4 - 0
Engine/Common/Log.h

@@ -72,12 +72,16 @@ public:
     
     
     //! Return logging level
     //! Return logging level
     LogLevel getLevel() const { return mLevel; }
     LogLevel getLevel() const { return mLevel; }
+    //! Return last log message
+    const std::string& getLastMessage() const { return mLastMessage; }
     
     
 private:
 private:
     //! Log file handle
     //! Log file handle
     FILE* mHandle;
     FILE* mHandle;
     //! Logging level
     //! Logging level
     LogLevel mLevel;
     LogLevel mLevel;
+    //! Last log message
+    std::string mLastMessage;
     //! Log listeners
     //! Log listeners
     std::vector<LogListener*> mListeners;
     std::vector<LogListener*> mListeners;
     
     

+ 26 - 25
Engine/Engine/RegisterRenderer.cpp

@@ -98,6 +98,30 @@ static void registerCamera(asIScriptEngine* engine)
     registerRefCasts<Node, Camera>(engine, "Node", "Camera");
     registerRefCasts<Node, Camera>(engine, "Node", "Camera");
 }
 }
 
 
+static void registerSkeleton(asIScriptEngine* engine)
+{
+    registerNode<Bone>(engine, "Bone");
+    engine->RegisterObjectMethod("Bone", "void setAnimationEnabled(bool)", asMETHOD(Bone, setAnimationEnabled), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Bone", "void setRadius(float)", asMETHOD(Bone, setRadius), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Bone", "void setBoundingBox(const BoundingBox& in)", asMETHOD(Bone, setBoundingBox), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Bone", "void reset(bool)", asMETHOD(Bone, reset), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Bone", "Bone@+ getRootBone()", asMETHOD(Bone, getRootBone), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Bone", "float getRadius() const", asMETHOD(Bone, getRadius), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Bone", "const BoundingBox& getBoundingBox() const", asMETHOD(Bone, getBoundingBox), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Bone", "bool isAnimationEnabled() const", asMETHOD(Bone, isAnimationEnabled), asCALL_THISCALL);
+    registerRefCasts<Component, Bone>(engine, "Component", "Bone");
+    registerRefCasts<Node, Bone>(engine, "Node", "Bone");
+    
+    engine->RegisterObjectType("Skeleton", 0, asOBJ_REF);
+    engine->RegisterObjectBehaviour("Skeleton", asBEHAVE_ADDREF, "void f()", asFUNCTION(FakeAddRef), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectBehaviour("Skeleton", asBEHAVE_RELEASE, "void f()", asFUNCTION(FakeReleaseRef), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod("Skeleton", "void reset(bool)", asMETHOD(Skeleton, reset), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Skeleton", "Bone@+ getRootBone() const", asMETHOD(Skeleton, getRootBone), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Skeleton", "uint getNumBones() const", asMETHOD(Skeleton, getNumBones), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Skeleton", "Bone@+ getBone(uint) const", asMETHODPR(Skeleton, getBone, (unsigned) const, Bone*), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Skeleton", "Bone@+ getBone(const string& in) const", asMETHODPR(Skeleton, getBone, (const std::string&) const, Bone*), asCALL_THISCALL);
+}
+
 static Texture2D* ConstructTexture2D(TextureUsage usage, const std::string& name)
 static Texture2D* ConstructTexture2D(TextureUsage usage, const std::string& name)
 {
 {
     try
     try
@@ -417,6 +441,7 @@ static void registerModel(asIScriptEngine* engine)
 {
 {
     registerResource<Model>(engine, "Model");
     registerResource<Model>(engine, "Model");
     engine->RegisterObjectMethod("Model", "const BoundingBox& getBoundingBox() const", asMETHOD(Model, getBoundingBox), asCALL_THISCALL);
     engine->RegisterObjectMethod("Model", "const BoundingBox& getBoundingBox() const", asMETHOD(Model, getBoundingBox), asCALL_THISCALL);
+    engine->RegisterObjectMethod("Model", "Skeleton@+ getSkeleton() const", asMETHOD(Model, getSkeleton), asCALL_THISCALL);
     engine->RegisterObjectMethod("Model", "uint getNumGeometries() const", asMETHOD(Model, getNumGeometries), asCALL_THISCALL);
     engine->RegisterObjectMethod("Model", "uint getNumGeometries() const", asMETHOD(Model, getNumGeometries), asCALL_THISCALL);
     engine->RegisterObjectMethod("Model", "uint getNumGeometryLodLevels(uint) const", asMETHOD(Model, getNumGeometryLodLevels), asCALL_THISCALL);
     engine->RegisterObjectMethod("Model", "uint getNumGeometryLodLevels(uint) const", asMETHOD(Model, getNumGeometryLodLevels), asCALL_THISCALL);
     engine->RegisterObjectMethod("Model", "uint getNumMorphs() const", asMETHOD(Model, getNumMorphs), asCALL_THISCALL);
     engine->RegisterObjectMethod("Model", "uint getNumMorphs() const", asMETHOD(Model, getNumMorphs), asCALL_THISCALL);
@@ -614,30 +639,6 @@ static void registerSkybox(asIScriptEngine* engine)
     registerRefCasts<Node, Skybox>(engine, "Node", "Skybox");
     registerRefCasts<Node, Skybox>(engine, "Node", "Skybox");
 }
 }
 
 
-static void registerSkeleton(asIScriptEngine* engine)
-{
-    registerNode<Bone>(engine, "Bone");
-    engine->RegisterObjectMethod("Bone", "void setAnimationEnabled(bool)", asMETHOD(Bone, setAnimationEnabled), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Bone", "void setRadius(float)", asMETHOD(Bone, setRadius), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Bone", "void setBoundingBox(const BoundingBox& in)", asMETHOD(Bone, setBoundingBox), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Bone", "void reset(bool)", asMETHOD(Bone, reset), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Bone", "Bone@+ getRootBone()", asMETHOD(Bone, getRootBone), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Bone", "float getRadius() const", asMETHOD(Bone, getRadius), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Bone", "const BoundingBox& getBoundingBox() const", asMETHOD(Bone, getBoundingBox), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Bone", "bool isAnimationEnabled() const", asMETHOD(Bone, isAnimationEnabled), asCALL_THISCALL);
-    registerRefCasts<Component, Bone>(engine, "Component", "Bone");
-    registerRefCasts<Node, Bone>(engine, "Node", "Bone");
-    
-    engine->RegisterObjectType("Skeleton", 0, asOBJ_REF);
-    engine->RegisterObjectBehaviour("Skeleton", asBEHAVE_ADDREF, "void f()", asFUNCTION(FakeAddRef), asCALL_CDECL_OBJLAST);
-    engine->RegisterObjectBehaviour("Skeleton", asBEHAVE_RELEASE, "void f()", asFUNCTION(FakeReleaseRef), asCALL_CDECL_OBJLAST);
-    engine->RegisterObjectMethod("Skeleton", "void reset(bool)", asMETHOD(Skeleton, reset), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Skeleton", "Bone@+ getRootBone() const", asMETHOD(Skeleton, getRootBone), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Skeleton", "uint getNumBones() const", asMETHOD(Skeleton, getNumBones), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Skeleton", "Bone@+ getBone(uint) const", asMETHODPR(Skeleton, getBone, (unsigned) const, Bone*), asCALL_THISCALL);
-    engine->RegisterObjectMethod("Skeleton", "Bone@+ getBone(const string& in) const", asMETHODPR(Skeleton, getBone, (const std::string&) const, Bone*), asCALL_THISCALL);
-}
-
 static void registerAnimatedModel(asIScriptEngine* engine)
 static void registerAnimatedModel(asIScriptEngine* engine)
 {
 {
     engine->RegisterObjectType("AnimationState", 0, asOBJ_REF);
     engine->RegisterObjectType("AnimationState", 0, asOBJ_REF);
@@ -991,6 +992,7 @@ static void registerOctree(asIScriptEngine* engine)
 void registerRendererLibrary(asIScriptEngine* engine)
 void registerRendererLibrary(asIScriptEngine* engine)
 {
 {
     registerCamera(engine);
     registerCamera(engine);
+    registerSkeleton(engine);
     registerTexture(engine);
     registerTexture(engine);
     registerMaterial(engine);
     registerMaterial(engine);
     registerModel(engine);
     registerModel(engine);
@@ -1001,7 +1003,6 @@ void registerRendererLibrary(asIScriptEngine* engine)
     registerZone(engine);
     registerZone(engine);
     registerStaticModel(engine);
     registerStaticModel(engine);
     registerSkybox(engine);
     registerSkybox(engine);
-    registerSkeleton(engine);
     registerAnimatedModel(engine);
     registerAnimatedModel(engine);
     registerBillboardSet(engine);
     registerBillboardSet(engine);
     registerInstancedModel(engine);
     registerInstancedModel(engine);

+ 2 - 0
Examples/Urho3D/Application.cpp

@@ -96,6 +96,8 @@ void Application::init()
     
     
     // Execute the rest of initialization, including scene creation, in script
     // Execute the rest of initialization, including scene creation, in script
     mScriptFile = mCache->getResource<ScriptFile>(scriptFileName);
     mScriptFile = mCache->getResource<ScriptFile>(scriptFileName);
+    if (!mScriptFile)
+        throw Exception(getLog()->getLastMessage(), false);
     if (!mScriptFile->execute("void start()"))
     if (!mScriptFile->execute("void start()"))
         EXCEPTION("Failed to execute the start() function");
         EXCEPTION("Failed to execute the start() function");
 }
 }