mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-07-12 02:45:53 +00:00
Merge pull request #14 from lioncash/string
Connection: Replace std::string _writeStr overload with std::string_view
This commit is contained in:
commit
120ed20bfa
@ -710,8 +710,7 @@ class Connection {
|
|||||||
uint32_t _readStr(char* buf, uint32_t bufSz);
|
uint32_t _readStr(char* buf, uint32_t bufSz);
|
||||||
uint32_t _writeStr(const char* str, uint32_t len, int wpipe);
|
uint32_t _writeStr(const char* str, uint32_t len, int wpipe);
|
||||||
uint32_t _writeStr(const char* str, uint32_t len) { return _writeStr(str, len, m_writepipe[1]); }
|
uint32_t _writeStr(const char* str, uint32_t len) { return _writeStr(str, len, m_writepipe[1]); }
|
||||||
uint32_t _writeStr(const char* str) { return _writeStr(str, strlen(str)); }
|
uint32_t _writeStr(std::string_view view) { return _writeStr(view.data(), view.size()); }
|
||||||
uint32_t _writeStr(const std::string& str) { return _writeStr(str.c_str(), str.size()); }
|
|
||||||
size_t _readBuf(void* buf, size_t len);
|
size_t _readBuf(void* buf, size_t len);
|
||||||
size_t _writeBuf(const void* buf, size_t len);
|
size_t _writeBuf(const void* buf, size_t len);
|
||||||
void _closePipe();
|
void _closePipe();
|
||||||
|
@ -107,7 +107,7 @@ static int Write(int fd, const void* buf, size_t size) {
|
|||||||
|
|
||||||
uint32_t Connection::_readStr(char* buf, uint32_t bufSz) {
|
uint32_t Connection::_readStr(char* buf, uint32_t bufSz) {
|
||||||
uint32_t readLen;
|
uint32_t readLen;
|
||||||
int ret = Read(m_readpipe[0], &readLen, 4);
|
int ret = Read(m_readpipe[0], &readLen, sizeof(readLen));
|
||||||
if (ret < 4) {
|
if (ret < 4) {
|
||||||
BlenderLog.report(logvisor::Error, fmt("Pipe error {} {}"), ret, strerror(errno));
|
BlenderLog.report(logvisor::Error, fmt("Pipe error {} {}"), ret, strerror(errno));
|
||||||
_blenderDied();
|
_blenderDied();
|
||||||
@ -124,8 +124,11 @@ uint32_t Connection::_readStr(char* buf, uint32_t bufSz) {
|
|||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
BlenderLog.report(logvisor::Fatal, fmt("{}"), strerror(errno));
|
BlenderLog.report(logvisor::Fatal, fmt("{}"), strerror(errno));
|
||||||
return 0;
|
return 0;
|
||||||
} else if (readLen >= 9) {
|
}
|
||||||
if (!memcmp(buf, "EXCEPTION", std::min(readLen, uint32_t(9)))) {
|
|
||||||
|
constexpr std::string_view exception_str{"EXCEPTION"};
|
||||||
|
if (readLen >= exception_str.size()) {
|
||||||
|
if (exception_str.compare(0, exception_str.size(), buf) == 0) {
|
||||||
_blenderDied();
|
_blenderDied();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -136,54 +139,75 @@ uint32_t Connection::_readStr(char* buf, uint32_t bufSz) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Connection::_writeStr(const char* buf, uint32_t len, int wpipe) {
|
uint32_t Connection::_writeStr(const char* buf, uint32_t len, int wpipe) {
|
||||||
int ret, nlerr;
|
const auto error = [this] {
|
||||||
nlerr = Write(wpipe, &len, 4);
|
|
||||||
if (nlerr < 4)
|
|
||||||
goto err;
|
|
||||||
ret = Write(wpipe, buf, len);
|
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
|
||||||
return (uint32_t)ret;
|
|
||||||
err:
|
|
||||||
_blenderDied();
|
_blenderDied();
|
||||||
return 0;
|
return 0U;
|
||||||
|
};
|
||||||
|
|
||||||
|
const int nlerr = Write(wpipe, &len, 4);
|
||||||
|
if (nlerr < 4) {
|
||||||
|
return error();
|
||||||
|
}
|
||||||
|
|
||||||
|
const int ret = Write(wpipe, buf, len);
|
||||||
|
if (ret < 0) {
|
||||||
|
return error();
|
||||||
|
}
|
||||||
|
|
||||||
|
return static_cast<uint32_t>(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Connection::_readBuf(void* buf, size_t len) {
|
size_t Connection::_readBuf(void* buf, size_t len) {
|
||||||
uint8_t* cBuf = reinterpret_cast<uint8_t*>(buf);
|
const auto error = [this] {
|
||||||
size_t readLen = 0;
|
|
||||||
do {
|
|
||||||
int ret = Read(m_readpipe[0], cBuf, len);
|
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
|
||||||
if (len >= 9)
|
|
||||||
if (!memcmp((char*)cBuf, "EXCEPTION", std::min(len, size_t(9))))
|
|
||||||
_blenderDied();
|
_blenderDied();
|
||||||
|
return 0U;
|
||||||
|
};
|
||||||
|
|
||||||
|
auto* cBuf = static_cast<uint8_t*>(buf);
|
||||||
|
size_t readLen = 0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
const int ret = Read(m_readpipe[0], cBuf, len);
|
||||||
|
if (ret < 0) {
|
||||||
|
return error();
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr std::string_view exception_str{"EXCEPTION"};
|
||||||
|
if (len >= exception_str.size()) {
|
||||||
|
if (exception_str.compare(0, exception_str.size(), static_cast<char*>(buf)) == 0) {
|
||||||
|
_blenderDied();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
readLen += ret;
|
readLen += ret;
|
||||||
cBuf += ret;
|
cBuf += ret;
|
||||||
len -= ret;
|
len -= ret;
|
||||||
} while (len);
|
} while (len != 0);
|
||||||
|
|
||||||
return readLen;
|
return readLen;
|
||||||
err:
|
|
||||||
_blenderDied();
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Connection::_writeBuf(const void* buf, size_t len) {
|
size_t Connection::_writeBuf(const void* buf, size_t len) {
|
||||||
const uint8_t* cBuf = reinterpret_cast<const uint8_t*>(buf);
|
const auto error = [this] {
|
||||||
|
_blenderDied();
|
||||||
|
return 0U;
|
||||||
|
};
|
||||||
|
|
||||||
|
const auto* cBuf = static_cast<const uint8_t*>(buf);
|
||||||
size_t writeLen = 0;
|
size_t writeLen = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
int ret = Write(m_writepipe[1], cBuf, len);
|
const int ret = Write(m_writepipe[1], cBuf, len);
|
||||||
if (ret < 0)
|
if (ret < 0) {
|
||||||
goto err;
|
return error();
|
||||||
|
}
|
||||||
|
|
||||||
writeLen += ret;
|
writeLen += ret;
|
||||||
cBuf += ret;
|
cBuf += ret;
|
||||||
len -= ret;
|
len -= ret;
|
||||||
} while (len);
|
} while (len != 0);
|
||||||
|
|
||||||
return writeLen;
|
return writeLen;
|
||||||
err:
|
|
||||||
_blenderDied();
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connection::_closePipe() {
|
void Connection::_closePipe() {
|
||||||
@ -315,8 +339,8 @@ Connection::Connection(int verbosityLevel) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring cmdLine = fmt::format(fmt(L" --background -P \"{}\" -- {} {} {} \"{}\""),
|
std::wstring cmdLine = fmt::format(fmt(L" --background -P \"{}\" -- {} {} {} \"{}\""), blenderShellPath,
|
||||||
blenderShellPath, uintptr_t(writehandle), uintptr_t(readhandle), verbosityLevel, blenderAddonPath);
|
uintptr_t(writehandle), uintptr_t(readhandle), verbosityLevel, blenderAddonPath);
|
||||||
|
|
||||||
STARTUPINFO sinfo = {sizeof(STARTUPINFO)};
|
STARTUPINFO sinfo = {sizeof(STARTUPINFO)};
|
||||||
HANDLE nulHandle = CreateFileW(L"nul", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, &sattrs, OPEN_EXISTING,
|
HANDLE nulHandle = CreateFileW(L"nul", GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, &sattrs, OPEN_EXISTING,
|
||||||
@ -331,8 +355,8 @@ Connection::Connection(int verbosityLevel) {
|
|||||||
sinfo.hStdOutput = consoleOutWrite;
|
sinfo.hStdOutput = consoleOutWrite;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CreateProcessW(blenderBin, const_cast<wchar_t*>(cmdLine.c_str()), NULL, NULL, TRUE,
|
if (!CreateProcessW(blenderBin, const_cast<wchar_t*>(cmdLine.c_str()), NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS,
|
||||||
NORMAL_PRIORITY_CLASS, NULL, NULL, &sinfo, &m_pinfo)) {
|
NULL, NULL, &sinfo, &m_pinfo)) {
|
||||||
LPWSTR messageBuffer = nullptr;
|
LPWSTR messageBuffer = nullptr;
|
||||||
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
|
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
|
||||||
GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&messageBuffer, 0, NULL);
|
GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&messageBuffer, 0, NULL);
|
||||||
@ -396,8 +420,8 @@ Connection::Connection(int verbosityLevel) {
|
|||||||
|
|
||||||
/* Try user-specified blender first */
|
/* Try user-specified blender first */
|
||||||
if (blenderBin) {
|
if (blenderBin) {
|
||||||
execlp(blenderBin, blenderBin, "--background", "-P", blenderShellPath.c_str(), "--",
|
execlp(blenderBin, blenderBin, "--background", "-P", blenderShellPath.c_str(), "--", readfds.c_str(),
|
||||||
readfds.c_str(), writefds.c_str(), vLevel.c_str(), blenderAddonPath.c_str(), NULL);
|
writefds.c_str(), vLevel.c_str(), blenderAddonPath.c_str(), NULL);
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
errbuf = fmt::format(fmt("NOLAUNCH {}"), strerror(errno));
|
errbuf = fmt::format(fmt("NOLAUNCH {}"), strerror(errno));
|
||||||
_writeStr(errbuf.c_str(), errbuf.size(), m_readpipe[1]);
|
_writeStr(errbuf.c_str(), errbuf.size(), m_readpipe[1]);
|
||||||
@ -414,8 +438,8 @@ Connection::Connection(int verbosityLevel) {
|
|||||||
steamBlender += "/blender";
|
steamBlender += "/blender";
|
||||||
#endif
|
#endif
|
||||||
blenderBin = steamBlender.c_str();
|
blenderBin = steamBlender.c_str();
|
||||||
execlp(blenderBin, blenderBin, "--background", "-P", blenderShellPath.c_str(), "--",
|
execlp(blenderBin, blenderBin, "--background", "-P", blenderShellPath.c_str(), "--", readfds.c_str(),
|
||||||
readfds.c_str(), writefds.c_str(), vLevel.c_str(), blenderAddonPath.c_str(), NULL);
|
writefds.c_str(), vLevel.c_str(), blenderAddonPath.c_str(), NULL);
|
||||||
if (errno != ENOENT) {
|
if (errno != ENOENT) {
|
||||||
errbuf = fmt::format(fmt("NOLAUNCH {}"), strerror(errno));
|
errbuf = fmt::format(fmt("NOLAUNCH {}"), strerror(errno));
|
||||||
_writeStr(errbuf.c_str(), errbuf.size(), m_readpipe[1]);
|
_writeStr(errbuf.c_str(), errbuf.size(), m_readpipe[1]);
|
||||||
@ -446,8 +470,8 @@ Connection::Connection(int verbosityLevel) {
|
|||||||
m_errPath = hecl::SystemString(TMPDIR) +
|
m_errPath = hecl::SystemString(TMPDIR) +
|
||||||
fmt::format(fmt(_SYS_STR("/hecl_{:016X}.derp")), (unsigned long long)m_pinfo.dwProcessId);
|
fmt::format(fmt(_SYS_STR("/hecl_{:016X}.derp")), (unsigned long long)m_pinfo.dwProcessId);
|
||||||
#else
|
#else
|
||||||
m_errPath =
|
m_errPath = hecl::SystemString(TMPDIR) +
|
||||||
hecl::SystemString(TMPDIR) + fmt::format(fmt(_SYS_STR("/hecl_{:016X}.derp")), (unsigned long long)m_blenderProc);
|
fmt::format(fmt(_SYS_STR("/hecl_{:016X}.derp")), (unsigned long long)m_blenderProc);
|
||||||
#endif
|
#endif
|
||||||
hecl::Unlink(m_errPath.c_str());
|
hecl::Unlink(m_errPath.c_str());
|
||||||
|
|
||||||
@ -628,8 +652,7 @@ void PyOutStream::close() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PyOutStream::linkBlend(const char* target, const char* objName, bool link) {
|
void PyOutStream::linkBlend(const char* target, const char* objName, bool link) {
|
||||||
format(fmt(
|
format(fmt("if '{}' not in bpy.data.scenes:\n"
|
||||||
"if '{}' not in bpy.data.scenes:\n"
|
|
||||||
" with bpy.data.libraries.load('''{}''', link={}, relative=True) as (data_from, data_to):\n"
|
" with bpy.data.libraries.load('''{}''', link={}, relative=True) as (data_from, data_to):\n"
|
||||||
" data_to.scenes = data_from.scenes\n"
|
" data_to.scenes = data_from.scenes\n"
|
||||||
" obj_scene = None\n"
|
" obj_scene = None\n"
|
||||||
@ -651,8 +674,7 @@ void PyOutStream::linkBlend(const char* target, const char* objName, bool link)
|
|||||||
|
|
||||||
void PyOutStream::linkBackground(const char* target, const char* sceneName) {
|
void PyOutStream::linkBackground(const char* target, const char* sceneName) {
|
||||||
if (!sceneName) {
|
if (!sceneName) {
|
||||||
format(fmt(
|
format(fmt("with bpy.data.libraries.load('''{}''', link=True, relative=True) as (data_from, data_to):\n"
|
||||||
"with bpy.data.libraries.load('''{}''', link=True, relative=True) as (data_from, data_to):\n"
|
|
||||||
" data_to.scenes = data_from.scenes\n"
|
" data_to.scenes = data_from.scenes\n"
|
||||||
"obj_scene = None\n"
|
"obj_scene = None\n"
|
||||||
"for scene in data_to.scenes:\n"
|
"for scene in data_to.scenes:\n"
|
||||||
@ -664,8 +686,7 @@ void PyOutStream::linkBackground(const char* target, const char* sceneName) {
|
|||||||
"bpy.context.scene.background_set = obj_scene\n"),
|
"bpy.context.scene.background_set = obj_scene\n"),
|
||||||
target, target);
|
target, target);
|
||||||
} else {
|
} else {
|
||||||
format(fmt(
|
format(fmt("if '{}' not in bpy.data.scenes:\n"
|
||||||
"if '{}' not in bpy.data.scenes:\n"
|
|
||||||
" with bpy.data.libraries.load('''{}''', link=True, relative=True) as (data_from, data_to):\n"
|
" with bpy.data.libraries.load('''{}''', link=True, relative=True) as (data_from, data_to):\n"
|
||||||
" data_to.scenes = data_from.scenes\n"
|
" data_to.scenes = data_from.scenes\n"
|
||||||
" obj_scene = None\n"
|
" obj_scene = None\n"
|
||||||
@ -684,8 +705,7 @@ void PyOutStream::linkBackground(const char* target, const char* sceneName) {
|
|||||||
void PyOutStream::AABBToBMesh(const atVec3f& min, const atVec3f& max) {
|
void PyOutStream::AABBToBMesh(const atVec3f& min, const atVec3f& max) {
|
||||||
athena::simd_floats minf(min.simd);
|
athena::simd_floats minf(min.simd);
|
||||||
athena::simd_floats maxf(max.simd);
|
athena::simd_floats maxf(max.simd);
|
||||||
format(fmt(
|
format(fmt("bm = bmesh.new()\n"
|
||||||
"bm = bmesh.new()\n"
|
|
||||||
"bm.verts.new(({},{},{}))\n"
|
"bm.verts.new(({},{},{}))\n"
|
||||||
"bm.verts.new(({},{},{}))\n"
|
"bm.verts.new(({},{},{}))\n"
|
||||||
"bm.verts.new(({},{},{}))\n"
|
"bm.verts.new(({},{},{}))\n"
|
||||||
@ -1434,9 +1454,10 @@ Action::Action(Connection& conn) {
|
|||||||
subtypeAABBs.emplace_back();
|
subtypeAABBs.emplace_back();
|
||||||
subtypeAABBs.back().first.read(conn);
|
subtypeAABBs.back().first.read(conn);
|
||||||
subtypeAABBs.back().second.read(conn);
|
subtypeAABBs.back().second.read(conn);
|
||||||
//printf("AABB %s %d (%f %f %f) (%f %f %f)\n", name.c_str(), i,
|
// printf("AABB %s %d (%f %f %f) (%f %f %f)\n", name.c_str(), i,
|
||||||
// float(subtypeAABBs.back().first.val.simd[0]), float(subtypeAABBs.back().first.val.simd[1]), float(subtypeAABBs.back().first.val.simd[2]),
|
// float(subtypeAABBs.back().first.val.simd[0]), float(subtypeAABBs.back().first.val.simd[1]),
|
||||||
// float(subtypeAABBs.back().second.val.simd[0]), float(subtypeAABBs.back().second.val.simd[1]), float(subtypeAABBs.back().second.val.simd[2]));
|
// float(subtypeAABBs.back().first.val.simd[2]), float(subtypeAABBs.back().second.val.simd[0]),
|
||||||
|
// float(subtypeAABBs.back().second.val.simd[1]), float(subtypeAABBs.back().second.val.simd[2]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user