Windows fixes

This commit is contained in:
Jack Andersen 2017-10-23 17:12:10 -10:00
parent 15d60493f2
commit 4ee4963aaf
17 changed files with 103 additions and 44 deletions

View File

@ -15,7 +15,13 @@ if(MSVC)
# Shaddup MSVC # Shaddup MSVC
add_definitions(-DUNICODE=1 -D_UNICODE=1 -D__SSE__=1 -D_CRT_SECURE_NO_WARNINGS=1 -DD_SCL_SECURE_NO_WARNINGS=1 add_definitions(-DUNICODE=1 -D_UNICODE=1 -D__SSE__=1 -D_CRT_SECURE_NO_WARNINGS=1 -DD_SCL_SECURE_NO_WARNINGS=1
/IGNORE:4221 /wd4018 /wd4800 /wd4005 /wd4311 /wd4267 /wd4244 /wd4200 /wd4305 /wd4067 /wd4146 ${VS_DEFINES}) -D_SCL_SECURE_NO_DEPRECATE=1 /IGNORE:4221 /wd4018 /wd4800 /wd4005 /wd4311 /wd4267 /wd4244 /wd4200 /wd4305
/wd4067 /wd4146 ${VS_DEFINES})
if(WINDOWS_STORE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /ZW")
add_definitions(-DWINAPI_FAMILY=WINAPI_FAMILY_PC_APP)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")

View File

@ -558,13 +558,18 @@ bool MREA::PCCook(const hecl::ProjectPath& outPath,
#if _WIN32 #if _WIN32
VisiGenPath += _S(".exe"); VisiGenPath += _S(".exe");
#endif #endif
char thrIdx[16]; hecl::SystemChar thrIdx[16];
snprintf(thrIdx, 16, "%d", hecl::ClientProcess::GetThreadWorkerIdx()); hecl::SNPrintf(thrIdx, 16, _S("%d"), hecl::ClientProcess::GetThreadWorkerIdx());
hecl::SystemChar parPid[32];
#if _WIN32
hecl::SNPrintf(parPid, 32, _S("%ullX"), reinterpret_cast<unsigned long long>(GetCurrentProcess()));
#else
hecl::SNPrintf(parPid, 32, _S("%ullX"), reinterpret_cast<unsigned long long>(getpid()));
#endif
const hecl::SystemChar* args[] = {VisiGenPath.c_str(), const hecl::SystemChar* args[] = {VisiGenPath.c_str(),
visiIntOut.getAbsolutePath().c_str(), visiIntOut.getAbsolutePath().c_str(),
visiIn.getAbsolutePath().c_str(), visiIn.getAbsolutePath().c_str(),
thrIdx, thrIdx, parPid, nullptr};
nullptr};
if (0 == hecl::RunProcess(VisiGenPath.c_str(), args)) if (0 == hecl::RunProcess(VisiGenPath.c_str(), args))
{ {
athena::io::FileReader r(visiIn.getAbsolutePath()); athena::io::FileReader r(visiIn.getAbsolutePath());

View File

@ -125,15 +125,20 @@ struct Application : boo::IApplicationCallback
static hecl::SystemChar CwdBuf[1024]; static hecl::SystemChar CwdBuf[1024];
hecl::SystemString ExeDir; hecl::SystemString ExeDir;
void SetupBasics()
{
logvisor::RegisterStandardExceptions();
logvisor::RegisterConsoleLogger();
atSetExceptionHandler(AthenaExc);
}
#if _WIN32 #if _WIN32
int wmain(int argc, const boo::SystemChar** argv) int wmain(int argc, const boo::SystemChar** argv)
#else #else
int main(int argc, const boo::SystemChar** argv) int main(int argc, const boo::SystemChar** argv)
#endif #endif
{ {
logvisor::RegisterStandardExceptions(); SetupBasics();
logvisor::RegisterConsoleLogger();
atSetExceptionHandler(AthenaExc);
if (hecl::SystemChar* cwd = hecl::Getcwd(CwdBuf, 1024)) if (hecl::SystemChar* cwd = hecl::Getcwd(CwdBuf, 1024))
{ {
@ -152,7 +157,20 @@ int main(int argc, const boo::SystemChar** argv)
return ret; return ret;
} }
#if _WIN32 #if WINAPI_FAMILY && !WINAPI_PARTITION_DESKTOP
using namespace Windows::ApplicationModel::Core;
[Platform::MTAThread]
int WINAPIV main(Platform::Array<Platform::String^>^ params)
{
SetupBasics();
urde::Application appCb;
auto viewProvider = ref new ViewProvider(appCb, _S("urde"), _S("URDE"), params, false);
CoreApplication::Run(viewProvider);
return 0;
}
#elif _WIN32
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR lpCmdLine, int) int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR lpCmdLine, int)
{ {
int argc = 0; int argc = 0;
@ -168,3 +186,4 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR lpCmdLine, int)
return wmain(argc+1, booArgv); return wmain(argc+1, booArgv);
} }
#endif #endif

View File

@ -258,7 +258,7 @@ class CModel
boo::IGraphicsBufferS* m_staticVbo = nullptr; boo::IGraphicsBufferS* m_staticVbo = nullptr;
hecl::HMDLMeta m_hmdlMeta; hecl::HMDLMeta m_hmdlMeta;
std::unique_ptr<uint8_t[]> m_dynamicVertexData; std::unique_ptr<uint8_t[]> m_dynamicVertexData;
boo::IGraphicsBufferS* m_ibo; boo::IGraphicsBufferS* m_ibo = nullptr;
public: public:
using MaterialSet = DataSpec::DNAMP1::HMDLMaterialSet; using MaterialSet = DataSpec::DNAMP1::HMDLMaterialSet;

View File

@ -1123,11 +1123,13 @@ CModel::CModel(std::unique_ptr<u8[]>&& in, u32 /* dataLen */, IObjectStore* stor
m_gfxToken = CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) -> bool m_gfxToken = CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) -> bool
{ {
/* Index buffer is always static */ /* Index buffer is always static */
if (m_hmdlMeta.indexCount)
m_ibo = ctx.newStaticBuffer(boo::BufferUse::Index, iboData, 4, m_hmdlMeta.indexCount); m_ibo = ctx.newStaticBuffer(boo::BufferUse::Index, iboData, 4, m_hmdlMeta.indexCount);
if (!m_hmdlMeta.bankCount) if (!m_hmdlMeta.bankCount)
{ {
/* Non-skinned models use static vertex buffers shared with CBooModel instances */ /* Non-skinned models use static vertex buffers shared with CBooModel instances */
if (m_hmdlMeta.vertCount)
m_staticVbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, vboData, m_staticVbo = ctx.newStaticBuffer(boo::BufferUse::Vertex, vboData,
m_hmdlMeta.vertStride, m_hmdlMeta.vertCount); m_hmdlMeta.vertStride, m_hmdlMeta.vertCount);
m_staticVtxFmt = hecl::Runtime::HMDLData::NewVertexFormat(ctx, m_hmdlMeta, m_staticVbo, m_ibo); m_staticVtxFmt = hecl::Runtime::HMDLData::NewVertexFormat(ctx, m_hmdlMeta, m_staticVbo, m_ibo);
@ -1136,9 +1138,12 @@ CModel::CModel(std::unique_ptr<u8[]>&& in, u32 /* dataLen */, IObjectStore* stor
{ {
/* Skinned models use per-instance dynamic buffers for vertex manipulation effects */ /* Skinned models use per-instance dynamic buffers for vertex manipulation effects */
size_t vboSz = m_hmdlMeta.vertStride * m_hmdlMeta.vertCount; size_t vboSz = m_hmdlMeta.vertStride * m_hmdlMeta.vertCount;
if (vboSz)
{
m_dynamicVertexData.reset(new uint8_t[vboSz]); m_dynamicVertexData.reset(new uint8_t[vboSz]);
memmove(m_dynamicVertexData.get(), vboData, vboSz); memmove(m_dynamicVertexData.get(), vboData, vboSz);
} }
}
return true; return true;
}); });

View File

@ -25,14 +25,12 @@ static const char* VS =
"VertToFrag main(in VertData v)\n" "VertToFrag main(in VertData v)\n"
"{\n" "{\n"
" VertToFrag vtf;\n" " VertToFrag vtf;\n"
" vtf.color = bu.color;\n" " vtf.color = color;\n"
" vtf.pos = bu.xf * vec4(v.posIn.xyz, 1.0);\n" " vtf.pos = mul(xf, float4(v.posIn.xyz, 1.0));\n"
" return vtf;\n" " return vtf;\n"
"}\n"; "}\n";
static const char* FS = static const char* FS =
"#include <metal_stdlib>\n"
"using namespace metal;\n"
"struct VertToFrag\n" "struct VertToFrag\n"
"{\n" "{\n"
" float4 pos : SV_Position;\n" " float4 pos : SV_Position;\n"

View File

@ -26,7 +26,7 @@ static const char* VS =
"{\n" "{\n"
" VertToFrag vtf;\n" " VertToFrag vtf;\n"
" vtf.color = color;\n" " vtf.color = color;\n"
" vtf.position = mul(xf * float4(v.posIn.xyz, 1.0));\n" " vtf.position = mul(xf, float4(v.posIn.xyz, 1.0));\n"
" return vtf;\n" " return vtf;\n"
"}\n"; "}\n";

View File

@ -104,13 +104,12 @@ static const char* BlurVS =
" float2 blurDir : BLURDIR;\n" " float2 blurDir : BLURDIR;\n"
"};\n" "};\n"
"\n" "\n"
"SBINDING(0) out VertToFrag vtf;\n"
"VertToFrag main(in VertData v)\n" "VertToFrag main(in VertData v)\n"
"{\n" "{\n"
" VertToFrag vtf;\n" " VertToFrag vtf;\n"
" vtf.uv = uvIn.xy;\n" " vtf.uv = v.uvIn.xy;\n"
" vtf.blurDir = blurDir.xy;\n" " vtf.blurDir = blurDir.xy;\n"
" vtf.position = float4(posIn.xyz, 1.0);\n" " vtf.position = float4(v.posIn.xyz, 1.0);\n"
" return vtf;\n" " return vtf;\n"
"}\n"; "}\n";

View File

@ -21,8 +21,8 @@ static const char* VS =
"struct VertToFrag\n" "struct VertToFrag\n"
"{\n" "{\n"
" float4 position : SV_Position;\n" " float4 position : SV_Position;\n"
" float4 color;\n" " float4 color : COLOR;\n"
" float2 uv;\n" " float2 uv : UV;\n"
"};\n" "};\n"
"\n" "\n"
"VertToFrag main(in VertData v, in uint vertId : SV_VertexID)\n" "VertToFrag main(in VertData v, in uint vertId : SV_VertexID)\n"
@ -30,7 +30,7 @@ static const char* VS =
" VertToFrag vtf;\n" " VertToFrag vtf;\n"
" vtf.color = v.colorIn;\n" " vtf.color = v.colorIn;\n"
" vtf.uv = v.uvIn[vertId].xy;\n" " vtf.uv = v.uvIn[vertId].xy;\n"
" vtf.position = xf * float4(v.posIn[vertId].xyz, 1.0);\n" " vtf.position = mul(xf, float4(v.posIn[vertId].xyz, 1.0));\n"
" return vtf;\n" " return vtf;\n"
"}\n"; "}\n";
@ -38,8 +38,8 @@ static const char* FS =
"struct VertToFrag\n" "struct VertToFrag\n"
"{\n" "{\n"
" float4 position : SV_Position;\n" " float4 position : SV_Position;\n"
" float4 color;\n" " float4 color : COLOR;\n"
" float2 uv;\n" " float2 uv : UV;\n"
"};\n" "};\n"
"\n" "\n"
"SamplerState samp : register(s0);\n" "SamplerState samp : register(s0);\n"

View File

@ -13,7 +13,7 @@ static const char* VS =
" float2 uvIn : UV;\n" " float2 uvIn : UV;\n"
"};\n" "};\n"
"\n" "\n"
"struct RandomStaticUniform\n" "cbuffer RandomStaticUniform : register(b0)\n"
"{\n" "{\n"
" float4 color;\n" " float4 color;\n"
" float randOff;\n" " float randOff;\n"
@ -32,10 +32,10 @@ static const char* VS =
"VertToFrag main(in VertData v)\n" "VertToFrag main(in VertData v)\n"
"{\n" "{\n"
" VertToFrag vtf;\n" " VertToFrag vtf;\n"
" vtf.color = su.color;\n" " vtf.color = color;\n"
" vtf.uv = v.uvIn.xy;\n" " vtf.uv = v.uvIn.xy;\n"
" vtf.randOff = su.randOff;\n" " vtf.randOff = randOff;\n"
" vtf.discardThres = su.discardThres;\n" " vtf.discardThres = discardThres;\n"
" vtf.pos = float4(v.posIn.xyz, 1.0);\n" " vtf.pos = float4(v.posIn.xyz, 1.0);\n"
" return vtf;\n" " return vtf;\n"
"}\n"; "}\n";

View File

@ -105,11 +105,15 @@ void CGuiFrame::DisableLights() const
void CGuiFrame::RemoveLight(CGuiLight* light) void CGuiFrame::RemoveLight(CGuiLight* light)
{ {
if (m_indexedLights.empty())
return;
m_indexedLights[light->GetLightId()] = nullptr; m_indexedLights[light->GetLightId()] = nullptr;
} }
void CGuiFrame::AddLight(CGuiLight* light) void CGuiFrame::AddLight(CGuiLight* light)
{ {
if (m_indexedLights.empty())
m_indexedLights.resize(8);
m_indexedLights[light->GetLightId()] = light; m_indexedLights[light->GetLightId()] = light;
} }

View File

@ -1187,7 +1187,7 @@ CGameArea::MREAHeader CGameArea::VerifyHeader() const
return {}; return {};
MREAHeader header; MREAHeader header;
athena::io::MemoryReader r(x110_mreaSecBufs[0].first.get() + 4, INT32_MAX); athena::io::MemoryReader r(x110_mreaSecBufs[0].first.get() + 4, x110_mreaSecBufs[0].second - 4);
u32 version = r.readUint32Big(); u32 version = r.readUint32Big();
if (!(version & 0x10000)) if (!(version & 0x10000))
Log.report(logvisor::Fatal, "Attempted to load non-URDE MREA"); Log.report(logvisor::Fatal, "Attempted to load non-URDE MREA");
@ -1208,10 +1208,6 @@ CGameArea::MREAHeader CGameArea::VerifyHeader() const
header.pathSecIdx = r.readUint32Big(); header.pathSecIdx = r.readUint32Big();
header.arotSecIdx = r.readUint32Big(); header.arotSecIdx = r.readUint32Big();
header.secSizes.reserve(header.secCount);
for (u32 i=0 ; i<header.secCount ; ++i)
header.secSizes.push_back(r.readUint32Big());
return header; return header;
} }

View File

@ -283,7 +283,6 @@ private:
u32 visiSecIdx; u32 visiSecIdx;
u32 pathSecIdx; u32 pathSecIdx;
u32 arotSecIdx; u32 arotSecIdx;
std::vector<u32> secSizes;
}; };
public: public:

2
hecl

@ -1 +1 @@
Subproject commit 84393676f125f87c443b770738b552015998228d Subproject commit 23a08dcf40456c59ff40710d12241a8a8735fe5e

View File

@ -313,7 +313,8 @@ std::vector<uint8_t> VISIBuilder::build(const zeus::CAABox& fullAabb,
const std::vector<VISIRenderer::Entity>& entities, const std::vector<VISIRenderer::Entity>& entities,
const std::vector<VISIRenderer::Light>& lights, const std::vector<VISIRenderer::Light>& lights,
size_t layer2LightCount, size_t layer2LightCount,
FPercent updatePercent) FPercent updatePercent,
ProcessType parentPid)
{ {
Log.report(logvisor::Info, "Started!"); Log.report(logvisor::Info, "Started!");
@ -321,8 +322,20 @@ std::vector<uint8_t> VISIBuilder::build(const zeus::CAABox& fullAabb,
renderCache.m_lightMetaBit = featureCount; renderCache.m_lightMetaBit = featureCount;
Progress prog(updatePercent); Progress prog(updatePercent);
pid_t parentPid = getppid(); #ifndef _WIN32
auto terminate = [this, parentPid]() { return renderCache.m_renderer.m_terminate || kill(parentPid, 0); }; auto terminate = [this, parentPid]()
{
return renderCache.m_renderer.m_terminate || (parentPid ? kill(parentPid, 0) : false);
};
#else
auto terminate = [this, parentPid]()
{
DWORD exitCode = 0;
if (!GetExitCodeProcess(parentPid, &exitCode))
return renderCache.m_renderer.m_terminate;
return renderCache.m_renderer.m_terminate || (parentPid ? exitCode != STILL_ACTIVE : false);
};
#endif
rootNode.buildChildren(0, 1, fullAabb, renderCache, prog, terminate); rootNode.buildChildren(0, 1, fullAabb, renderCache, prog, terminate);
if (terminate()) if (terminate())
return {}; return {};

View File

@ -7,6 +7,12 @@
#include "athena/MemoryWriter.hpp" #include "athena/MemoryWriter.hpp"
#include <unordered_map> #include <unordered_map>
#ifdef _WIN32
using ProcessType = HANDLE;
#else
using ProcessType = pid_t;
#endif
namespace std namespace std
{ {
template <> struct hash<zeus::CVector3f> template <> struct hash<zeus::CVector3f>
@ -122,7 +128,8 @@ struct VISIBuilder
const std::vector<VISIRenderer::Entity>& entities, const std::vector<VISIRenderer::Entity>& entities,
const std::vector<VISIRenderer::Light>& lights, const std::vector<VISIRenderer::Light>& lights,
size_t layer2LightCount, size_t layer2LightCount,
FPercent updatePercent); FPercent updatePercent,
ProcessType parentPid);
VISIBuilder(VISIRenderer& renderer) : renderCache(renderer) {} VISIBuilder(VISIRenderer& renderer) : renderCache(renderer) {}
}; };

View File

@ -503,6 +503,14 @@ void VISIRenderer::Run(FPercent updatePercent)
return; return;
} }
ProcessType parentPid = 0;
if (m_argc > 4)
#ifdef _WIN32
parentPid = ProcessType(wcstoull(m_argv[4], nullptr, 16));
#else
parentPid = ProcessType(strtoull(m_argv[4], nullptr, 16));
#endif
uint32_t layer2LightCount = 0; uint32_t layer2LightCount = 0;
{ {
athena::io::FileReader r(m_argv[1]); athena::io::FileReader r(m_argv[1]);
@ -579,7 +587,7 @@ void VISIRenderer::Run(FPercent updatePercent)
VISIBuilder builder(*this); VISIBuilder builder(*this);
std::vector<uint8_t> dataOut = builder.build(m_totalAABB, m_models.size(), std::vector<uint8_t> dataOut = builder.build(m_totalAABB, m_models.size(),
m_entities, m_lights, layer2LightCount, m_entities, m_lights, layer2LightCount,
m_updatePercent); m_updatePercent, parentPid);
if (dataOut.empty()) if (dataOut.empty())
{ {
m_return = 1; m_return = 1;