2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-08-11 18:19:07 +00:00

Addon updates

This commit is contained in:
Jack Andersen 2015-08-16 13:01:35 -10:00
parent 4c6a934ada
commit fb75130d91
5 changed files with 51 additions and 25 deletions

View File

@ -314,8 +314,7 @@ BlenderConnection::~BlenderConnection()
bool BlenderConnection::createBlend(const SystemString& path) bool BlenderConnection::createBlend(const SystemString& path)
{ {
std::unique_lock<std::mutex> lk(m_lock, std::try_to_lock); if (m_lock)
if (!lk)
{ {
BlenderLog.report(LogVisor::FatalError, BlenderLog.report(LogVisor::FatalError,
"BlenderConnection::createBlend() musn't be called with stream active"); "BlenderConnection::createBlend() musn't be called with stream active");
@ -335,8 +334,7 @@ bool BlenderConnection::createBlend(const SystemString& path)
bool BlenderConnection::openBlend(const SystemString& path) bool BlenderConnection::openBlend(const SystemString& path)
{ {
std::unique_lock<std::mutex> lk(m_lock, std::try_to_lock); if (m_lock)
if (!lk)
{ {
BlenderLog.report(LogVisor::FatalError, BlenderLog.report(LogVisor::FatalError,
"BlenderConnection::openBlend() musn't be called with stream active"); "BlenderConnection::openBlend() musn't be called with stream active");
@ -356,8 +354,7 @@ bool BlenderConnection::openBlend(const SystemString& path)
bool BlenderConnection::saveBlend() bool BlenderConnection::saveBlend()
{ {
std::unique_lock<std::mutex> lk(m_lock, std::try_to_lock); if (m_lock)
if (!lk)
{ {
BlenderLog.report(LogVisor::FatalError, BlenderLog.report(LogVisor::FatalError,
"BlenderConnection::saveBlend() musn't be called with stream active"); "BlenderConnection::saveBlend() musn't be called with stream active");
@ -376,6 +373,7 @@ void BlenderConnection::deleteBlend()
if (m_loadedBlend.size()) if (m_loadedBlend.size())
{ {
HECL::Unlink(m_loadedBlend.c_str()); HECL::Unlink(m_loadedBlend.c_str());
BlenderLog.report(LogVisor::Info, "Deleted '%s'", m_loadedBlend.c_str());
m_loadedBlend.clear(); m_loadedBlend.clear();
} }
} }

View File

@ -12,7 +12,6 @@
#include <stdio.h> #include <stdio.h>
#include <string> #include <string>
#include <functional> #include <functional>
#include <mutex>
#include "HECL/HECL.hpp" #include "HECL/HECL.hpp"
@ -24,7 +23,7 @@ extern class BlenderConnection* SharedBlenderConnection;
class BlenderConnection class BlenderConnection
{ {
std::mutex m_lock; bool m_lock;
#if _WIN32 #if _WIN32
HANDLE m_blenderProc; HANDLE m_blenderProc;
HANDLE m_readpipe[2]; HANDLE m_readpipe[2];
@ -61,7 +60,6 @@ public:
class PyOutStream : public std::ostream class PyOutStream : public std::ostream
{ {
friend class BlenderConnection; friend class BlenderConnection;
std::unique_lock<std::mutex> m_lk;
BlenderConnection* m_parent; BlenderConnection* m_parent;
bool m_deleteOnError; bool m_deleteOnError;
struct StreamBuf : std::streambuf struct StreamBuf : std::streambuf
@ -75,7 +73,7 @@ public:
StreamBuf(StreamBuf&& other) = default; StreamBuf(StreamBuf&& other) = default;
int_type overflow(int_type ch) int_type overflow(int_type ch)
{ {
if (!m_parent.m_lk) if (!m_parent.m_parent || !m_parent.m_parent->m_lock)
BlenderLog.report(LogVisor::FatalError, "lock not held for PyOutStream writing"); BlenderLog.report(LogVisor::FatalError, "lock not held for PyOutStream writing");
if (ch != traits_type::eof() && ch != '\n') if (ch != traits_type::eof() && ch != '\n')
{ {
@ -96,11 +94,12 @@ public:
} }
} m_sbuf; } m_sbuf;
PyOutStream(BlenderConnection* parent, bool deleteOnError) PyOutStream(BlenderConnection* parent, bool deleteOnError)
: m_lk(parent->m_lock), m_parent(parent), : m_parent(parent),
m_sbuf(*this, deleteOnError), m_sbuf(*this, deleteOnError),
m_deleteOnError(deleteOnError), m_deleteOnError(deleteOnError),
std::ostream(&m_sbuf) std::ostream(&m_sbuf)
{ {
m_parent->m_lock = true;
m_parent->_writeLine("PYBEGIN"); m_parent->_writeLine("PYBEGIN");
char readBuf[16]; char readBuf[16];
m_parent->_readLine(readBuf, 16); m_parent->_readLine(readBuf, 16);
@ -110,27 +109,24 @@ public:
public: public:
PyOutStream(const PyOutStream& other) = delete; PyOutStream(const PyOutStream& other) = delete;
PyOutStream(PyOutStream&& other) PyOutStream(PyOutStream&& other)
: m_lk(std::move(other.m_lk)), m_parent(other.m_parent), m_sbuf(std::move(other.m_sbuf)) : m_parent(other.m_parent), m_sbuf(std::move(other.m_sbuf))
{other.m_parent = nullptr;} {other.m_parent = nullptr;}
~PyOutStream() {close();} ~PyOutStream() {close();}
void close() void close()
{ {
if (m_lk) if (m_parent && m_parent->m_lock)
{ {
if (m_parent) m_parent->_writeLine("PYEND");
{ char readBuf[16];
m_parent->_writeLine("PYEND"); m_parent->_readLine(readBuf, 16);
char readBuf[16]; if (strcmp(readBuf, "DONE"))
m_parent->_readLine(readBuf, 16); BlenderLog.report(LogVisor::FatalError, "unable to close PyOutStream with blender");
if (strcmp(readBuf, "DONE")) m_parent->m_lock = false;
BlenderLog.report(LogVisor::FatalError, "unable to close PyOutStream with blender");
}
m_lk.unlock();
} }
} }
void format(const char* fmt, ...) void format(const char* fmt, ...)
{ {
if (!m_lk) if (!m_parent || !m_parent->m_lock)
BlenderLog.report(LogVisor::FatalError, "lock not held for PyOutStream::format()"); BlenderLog.report(LogVisor::FatalError, "lock not held for PyOutStream::format()");
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
@ -145,6 +141,8 @@ public:
}; };
inline PyOutStream beginPythonOut(bool deleteOnError=false) inline PyOutStream beginPythonOut(bool deleteOnError=false)
{ {
if (m_lock)
BlenderLog.report(LogVisor::FatalError, "lock already held for BlenderConnection::beginPythonOut()");
return PyOutStream(this, deleteOnError); return PyOutStream(this, deleteOnError);
} }
@ -157,10 +155,24 @@ public:
return *SharedBlenderConnection; return *SharedBlenderConnection;
} }
inline void closeStream()
{
if (m_lock)
deleteBlend();
}
static inline void Shutdown() static inline void Shutdown()
{ {
delete SharedBlenderConnection; if (SharedBlenderConnection)
{
SharedBlenderConnection->closeStream();
SharedBlenderConnection->quitBlender();
delete SharedBlenderConnection;
SharedBlenderConnection = nullptr;
BlenderLog.report(LogVisor::Info, "BlenderConnection Shutdown Successful");
}
} }
}; };
} }

View File

@ -148,6 +148,12 @@ class SACTAction_load(bpy.types.Operator):
# Set single action into armature # Set single action into armature
if subtype.linked_armature in bpy.data.objects: if subtype.linked_armature in bpy.data.objects:
armature_obj = bpy.data.objects[subtype.linked_armature] armature_obj = bpy.data.objects[subtype.linked_armature]
for bone in armature_obj.pose.bones:
bone.location = (0,0,0)
bone.rotation_quaternion = (1,0,0,0)
bone.scale = (1,1,1)
if action_data.name in bpy.data.actions: if action_data.name in bpy.data.actions:
action_obj =\ action_obj =\
bpy.data.actions[action_data.name] bpy.data.actions[action_data.name]

View File

@ -6,6 +6,7 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <signal.h>
#include <regex> #include <regex>
#include <list> #include <list>
#include "HECL/Database.hpp" #include "HECL/Database.hpp"
@ -65,6 +66,13 @@ static const HECL::SystemRegex regOPEN(_S("-o([^\"]*|\\S*)"), std::regex::ECMASc
static const HECL::SystemRegex regVERBOSE(_S("-v(v*)"), std::regex::ECMAScript|std::regex::optimize); static const HECL::SystemRegex regVERBOSE(_S("-v(v*)"), std::regex::ECMAScript|std::regex::optimize);
static const HECL::SystemRegex regFORCE(_S("-f"), std::regex::ECMAScript|std::regex::optimize); static const HECL::SystemRegex regFORCE(_S("-f"), std::regex::ECMAScript|std::regex::optimize);
/* SIGINT will gracefully close blender connections and delete blends in progress */
static void SIGINTHandler(int sig)
{
HECL::BlenderConnection::Shutdown();
exit(1);
}
static LogVisor::LogModule AthenaLog("Athena"); static LogVisor::LogModule AthenaLog("Athena");
static void AthenaExc(const Athena::error::Level& level, const char* file, static void AthenaExc(const Athena::error::Level& level, const char* file,
const char*, int line, const char* fmt, ...) const char*, int line, const char* fmt, ...)
@ -86,6 +94,8 @@ int main(int argc, const char** argv)
if (term && !strncmp(term, "xterm", 5)) if (term && !strncmp(term, "xterm", 5))
XTERM_COLOR = true; XTERM_COLOR = true;
signal(SIGINT, SIGINTHandler);
LogVisor::RegisterConsoleLogger(); LogVisor::RegisterConsoleLogger();
atSetExceptionHandler(AthenaExc); atSetExceptionHandler(AthenaExc);

@ -1 +1 @@
Subproject commit 0da7ab7e01a305f0ecb7ec71d843b652002845f2 Subproject commit 53256dea15ba37595b2958ed49249ddf370071ba