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.
This commit is contained in:
parent
e4bb607126
commit
080d52e93c
@ -30,17 +30,19 @@
|
||||
|
||||
#include "DebugNew.h"
|
||||
|
||||
Exception::Exception(const std::string& what) :
|
||||
Exception::Exception(const std::string& what, bool logError) :
|
||||
mWhat(what)
|
||||
{
|
||||
LOGERROR(what);
|
||||
if (logError)
|
||||
LOGERROR(what);
|
||||
}
|
||||
|
||||
#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);
|
||||
LOGERROR(mWhat);
|
||||
if (logError)
|
||||
LOGERROR(mWhat);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -44,12 +44,12 @@ class Exception : public std::exception
|
||||
{
|
||||
public:
|
||||
//! Construct with exception reason
|
||||
Exception(const std::string& what);
|
||||
Exception(const std::string& what, bool logError = true);
|
||||
//! Destruct
|
||||
virtual ~Exception() throw();
|
||||
#ifdef _DEBUG
|
||||
//! 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
|
||||
|
||||
//! Return exception reason
|
||||
|
@ -77,6 +77,8 @@ void Log::write(LogLevel level, const std::string& message)
|
||||
if ((mLevel > level) || (level == LOG_NONE))
|
||||
return;
|
||||
|
||||
mLastMessage = message;
|
||||
|
||||
static time_t sysTime;
|
||||
time(&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)
|
||||
{
|
||||
mLastMessage = message;
|
||||
|
||||
printf("%s", message.c_str());
|
||||
|
||||
if (mHandle)
|
||||
|
@ -72,12 +72,16 @@ public:
|
||||
|
||||
//! Return logging level
|
||||
LogLevel getLevel() const { return mLevel; }
|
||||
//! Return last log message
|
||||
const std::string& getLastMessage() const { return mLastMessage; }
|
||||
|
||||
private:
|
||||
//! Log file handle
|
||||
FILE* mHandle;
|
||||
//! Logging level
|
||||
LogLevel mLevel;
|
||||
//! Last log message
|
||||
std::string mLastMessage;
|
||||
//! Log listeners
|
||||
std::vector<LogListener*> mListeners;
|
||||
|
||||
|
@ -98,6 +98,30 @@ static void registerCamera(asIScriptEngine* engine)
|
||||
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)
|
||||
{
|
||||
try
|
||||
@ -417,6 +441,7 @@ static void registerModel(asIScriptEngine* engine)
|
||||
{
|
||||
registerResource<Model>(engine, "Model");
|
||||
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 getNumGeometryLodLevels(uint) const", asMETHOD(Model, getNumGeometryLodLevels), 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");
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
engine->RegisterObjectType("AnimationState", 0, asOBJ_REF);
|
||||
@ -991,6 +992,7 @@ static void registerOctree(asIScriptEngine* engine)
|
||||
void registerRendererLibrary(asIScriptEngine* engine)
|
||||
{
|
||||
registerCamera(engine);
|
||||
registerSkeleton(engine);
|
||||
registerTexture(engine);
|
||||
registerMaterial(engine);
|
||||
registerModel(engine);
|
||||
@ -1001,7 +1003,6 @@ void registerRendererLibrary(asIScriptEngine* engine)
|
||||
registerZone(engine);
|
||||
registerStaticModel(engine);
|
||||
registerSkybox(engine);
|
||||
registerSkeleton(engine);
|
||||
registerAnimatedModel(engine);
|
||||
registerBillboardSet(engine);
|
||||
registerInstancedModel(engine);
|
||||
|
@ -96,6 +96,8 @@ void Application::init()
|
||||
|
||||
// Execute the rest of initialization, including scene creation, in script
|
||||
mScriptFile = mCache->getResource<ScriptFile>(scriptFileName);
|
||||
if (!mScriptFile)
|
||||
throw Exception(getLog()->getLastMessage(), false);
|
||||
if (!mScriptFile->execute("void start()"))
|
||||
EXCEPTION("Failed to execute the start() function");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user