Additions to BlenderConnection

This commit is contained in:
Jack Andersen 2015-07-25 13:01:02 -10:00
parent 62ce25b8b6
commit 21b4fe88f7
5 changed files with 59 additions and 1 deletions

View File

@ -1,3 +1,11 @@
/* Include this file once in the main translation unit of any executable file
* using HECL's database functionality (see driver/main.cpp)
*/
#ifdef DATA_SPEC_REGISTRY_HPP
#error DataSpecRegistry.hpp may only be included once
#endif
#define DATA_SPEC_REGISTRY_HPP
#include "HECL/Database.hpp"
namespace HECL
@ -17,6 +25,8 @@ namespace Retro
extern HECL::Database::DataSpecEntry SpecEntMP3;
}
/* An overzealous optimizing compiler may not init the specs if
* there's no in-code reference.. this is a simple hack to solve that */
extern "C" void HECLDataSpecs()
{
HECL::Printf(Retro::SpecEntMP1.m_name);

View File

@ -11,9 +11,11 @@
#include <stdint.h>
#include <string>
#include <functional>
#include <mutex>
class BlenderConnection
{
std::mutex m_lock;
#if _WIN32
HANDLE m_blenderProc;
HANDLE m_readpipe[2];
@ -43,6 +45,49 @@ public:
const std::string& expectedType,
const std::string& platform,
bool bigEndian=false);
class PyOutStream : public std::ostream
{
friend class BlenderConnection;
std::unique_lock<std::mutex> m_lk;
BlenderConnection* m_parent;
struct StreamBuf : std::streambuf
{
BlenderConnection* m_parent;
StreamBuf(BlenderConnection* parent) : m_parent(parent) {}
StreamBuf(const StreamBuf& other) = delete;
StreamBuf(StreamBuf&& other) = default;
int_type overflow(int_type ch)
{
if (ch != traits_type::eof())
{
char_type chi = ch;
m_parent->_writeBuf(&chi, 1);
}
return ch;
}
} m_sbuf;
PyOutStream(BlenderConnection* parent)
: m_lk(parent->m_lock), m_parent(parent), m_sbuf(parent), std::ostream(&m_sbuf)
{
m_parent->_writeBuf("\033PYBEGIN\n", 9);
}
public:
PyOutStream(const PyOutStream& other) = delete;
PyOutStream(PyOutStream&& other)
: m_lk(std::move(other.m_lk)), m_parent(other.m_parent), m_sbuf(std::move(other.m_sbuf))
{other.m_parent = nullptr;}
~PyOutStream()
{
if (m_parent)
m_parent->_writeBuf("\033PYEND\n", 7);
}
};
inline PyOutStream beginPythonOut()
{
return PyOutStream(this);
}
void quitBlender();
};

View File

@ -14,6 +14,7 @@ add_executable(hecl main.cpp
ToolAdd.hpp
ToolRemove.hpp
ToolSpec.hpp
../DataSpecRegistry.hpp
)
list(APPEND DATA_SPEC_LIBS

View File

@ -25,6 +25,8 @@ LogVisor::LogModule LogModule("HECLDriver");
#include "ToolPackage.hpp"
#include "ToolHelp.hpp"
/* Static reference to dataspec additions
* (used by MSVC to definitively link DataSpecs) */
#include "../DataSpecRegistry.hpp"
bool XTERM_COLOR = false;

@ -1 +1 @@
Subproject commit fb0abb652a9149b369540d787fc3a5dacca8912a
Subproject commit c526c7df855ddc1e403d70ae98d5e3d6f4d5a095