From 669b3d69420e4c2a416fcca121d744d2a80326e9 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Mon, 15 Jan 2018 20:42:28 -1000 Subject: [PATCH] CWorldShadow OpenGL fixes; discord-rpc integration --- .gitmodules | 6 ++ CMakeLists.txt | 6 ++ Editor/CMakeLists.txt | 2 +- Editor/main.cpp | 7 +- Runtime/CStateManager.cpp | 5 +- Runtime/Graphics/CModel.hpp | 2 +- Runtime/Graphics/CModelBoo.cpp | 38 +++++--- .../Graphics/Shaders/CModelShadersGLSL.cpp | 5 +- .../Graphics/Shaders/CModelShadersMetal.cpp | 2 +- .../Graphics/Shaders/CWorldShadowShader.cpp | 3 +- Runtime/MP1/MP1.cpp | 88 +++++++++++++++++++ Runtime/MP1/MP1.hpp | 7 ++ Runtime/World/CPlayer.cpp | 4 +- Runtime/World/CWorldShadow.cpp | 15 ++-- Runtime/World/CWorldShadow.hpp | 6 +- discord-rpc | 1 + hecl | 2 +- hecl-gui | 2 +- rapidjson | 1 + 19 files changed, 175 insertions(+), 27 deletions(-) create mode 160000 discord-rpc create mode 160000 rapidjson diff --git a/.gitmodules b/.gitmodules index 9b64468ab..903eba43a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -28,3 +28,9 @@ [submodule "cotire"] path = cotire url = https://github.com/sakra/cotire.git +[submodule "discord-rpc"] + path = discord-rpc + url = https://github.com/discordapp/discord-rpc.git +[submodule "rapidjson"] + path = rapidjson + url = https://github.com/Tencent/rapidjson.git diff --git a/CMakeLists.txt b/CMakeLists.txt index bc306ab45..a0bb17b60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,6 +130,12 @@ if(USE_LD_GOLD AND ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_ endif() endif() +# Add discord-rpc here +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/rapidjson/include) +set(PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/discord-rpc) +add_subdirectory(discord-rpc/src) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/discord-rpc/include) + set(HECL_DLPACKAGE ${URDE_DLPACKAGE}) set(BOO_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/hecl/extern/boo/include) diff --git a/Editor/CMakeLists.txt b/Editor/CMakeLists.txt index 1cf30a829..1847acb65 100644 --- a/Editor/CMakeLists.txt +++ b/Editor/CMakeLists.txt @@ -102,7 +102,7 @@ target_link_libraries(urde hecl-full hecl-blender-addon athena-core nod logvisor athena-libyaml amuse boo ${PNG_LIB} libjpeg-turbo squish xxhash zeus - kabufuda jbus ${ZLIB_LIBRARIES} ${LZO_LIB} + kabufuda jbus discord-rpc ${ZLIB_LIBRARIES} ${LZO_LIB} ${BOO_SYS_LIBS}) if(COMMAND add_sanitizers) add_sanitizers(urde) diff --git a/Editor/main.cpp b/Editor/main.cpp index 32f13de4a..e40cf657e 100644 --- a/Editor/main.cpp +++ b/Editor/main.cpp @@ -143,6 +143,11 @@ struct Application : boo::IApplicationCallback return m_cvarCommons.getAnisotropy(); } + bool getDeepColor() const + { + return m_cvarCommons.getDeepColor(); + } + void quit(hecl::Console* con = nullptr, const std::vector& arg = std::vector()) { m_running = false; @@ -214,7 +219,7 @@ int main(int argc, const boo::SystemChar** argv) urde::Application appCb; int ret = boo::ApplicationRun(boo::IApplication::EPlatformType::Auto, appCb, _S("urde"), _S("URDE"), argc, argv, appCb.getGraphicsApi(), - appCb.getSamples(), appCb.getAnisotropy(), false); + appCb.getSamples(), appCb.getAnisotropy(), appCb.getDeepColor(), false); //printf("IM DYING!!\n"); return ret; } diff --git a/Runtime/CStateManager.cpp b/Runtime/CStateManager.cpp index 78708eb69..ba79521db 100644 --- a/Runtime/CStateManager.cpp +++ b/Runtime/CStateManager.cpp @@ -48,6 +48,7 @@ #include "World/CScriptWater.hpp" #include "World/CScriptDoor.hpp" #include "Input/ControlMapper.hpp" +#include "MP1/MP1.hpp" #include @@ -205,7 +206,7 @@ CStateManager::CStateManager(const std::weak_ptr& relayTracker, x90c_loaderFuncs[int(EScriptObjectType::ShadowProjector)] = ScriptLoader::LoadShadowProjector; x90c_loaderFuncs[int(EScriptObjectType::EnergyBall)] = ScriptLoader::LoadEnergyBall; - CGameCollision::InitCollision(); + //CGameCollision::InitCollision(); ControlMapper::ResetCommandFilters(); x8f0_shadowTex = g_SimplePool->GetObj("DefaultShadow"); } @@ -1837,6 +1838,8 @@ void CStateManager::UpdateGraphicsTiming(float dt) void CStateManager::Update(float dt) { + MP1::CMain::UpdateDiscordPresence(GetWorld()->IGetStringTableAssetId()); + CElementGen::SetGlobalSeed(x8d8_updateFrameIdx); CParticleElectric::SetGlobalSeed(x8d8_updateFrameIdx); CDecal::SetGlobalSeed(x8d8_updateFrameIdx); diff --git a/Runtime/Graphics/CModel.hpp b/Runtime/Graphics/CModel.hpp index 1aa48a07c..d3c806be2 100644 --- a/Runtime/Graphics/CModel.hpp +++ b/Runtime/Graphics/CModel.hpp @@ -125,7 +125,7 @@ public: private: CBooModel* m_next = nullptr; CBooModel* m_prev = nullptr; - size_t m_uniUpdateCount = 0; + int m_uniUpdateCount = 0; TToken m_modelTok; CModel* m_model; std::vector* x0_surfaces; diff --git a/Runtime/Graphics/CModelBoo.cpp b/Runtime/Graphics/CModelBoo.cpp index 3c586c7c6..21823b2c9 100644 --- a/Runtime/Graphics/CModelBoo.cpp +++ b/Runtime/Graphics/CModelBoo.cpp @@ -754,13 +754,13 @@ void CBooModel::UVAnimationBuffer::ProcessAnimation(u8*& bufOut, const UVAnimati case UVAnimation::Mode::HStrip: { float value = anim.vals[0] * anim.vals[2] * (anim.vals[3] + CGraphics::GetSecondsMod900()); - texMtxOut.vec[3].x = (float)(short)(float)(anim.vals[1] * fmod(value, 1.0f)) * anim.vals[2]; + texMtxOut.vec[3].x = (float)(short)(anim.vals[1] * fmod(value, 1.0f)) * anim.vals[2]; break; } case UVAnimation::Mode::VStrip: { float value = anim.vals[0] * anim.vals[2] * (anim.vals[3] + CGraphics::GetSecondsMod900()); - texMtxOut.vec[3].y = (float)(short)(float)(anim.vals[1] * fmod(value, 1.0f)) * anim.vals[2]; + texMtxOut.vec[3].y = (float)(short)(anim.vals[1] * fmod(value, 1.0f)) * anim.vals[2]; break; } case UVAnimation::Mode::Model: @@ -792,7 +792,7 @@ void CBooModel::UVAnimationBuffer::ProcessAnimation(u8*& bufOut, const UVAnimati postMtxOut = zeus::CTransform(zeus::CMatrix3f(halfA, 0.0, 0.0, 0.0, 0.0, halfA, 0.0, 0.0, 0.0), - zeus::CVector3f(xy, z, 1.0)).toMatrix4f(); + zeus::CVector3f(xy, z, 1.0)).toMatrix4f(); break; } default: break; @@ -997,15 +997,33 @@ boo::ObjToken CBooModel::UpdateUniformData(const CModelFl } const ModelInstance* inst; - if (m_instances.size() <= m_uniUpdateCount) + if (sharedLayoutBuf >= 0) { - inst = const_cast(this)->PushNewModelInstance(sharedLayoutBuf); - if (!inst) - return nullptr; + if (m_instances.size() <= sharedLayoutBuf) + { + do + { + inst = const_cast(this)->PushNewModelInstance(m_instances.size()); + if (!inst) + return nullptr; + } while (m_instances.size() <= sharedLayoutBuf); + } + else + inst = &m_instances[sharedLayoutBuf]; + const_cast(this)->m_uniUpdateCount = sharedLayoutBuf + 1; } else - inst = &m_instances[m_uniUpdateCount]; - ++const_cast(this)->m_uniUpdateCount; + { + if (m_instances.size() <= m_uniUpdateCount) + { + inst = const_cast(this)->PushNewModelInstance(sharedLayoutBuf); + if (!inst) + return nullptr; + } + else + inst = &m_instances[m_uniUpdateCount]; + ++const_cast(this)->m_uniUpdateCount; + } if (inst->m_geomUniformBuffer) m_geomLayout->Update(flags, cskr, pose, x4_matSet, inst->m_geomUniformBuffer); @@ -1139,7 +1157,7 @@ SShader::BuildShader(const hecl::HMDLMeta& meta, const MaterialSet::Material& ma reflectionType = hecl::Backend::ReflectionType::None; hecl::Runtime::ShaderTag tag(mat.heclIr, meta.colorCount, meta.uvCount, meta.weightCount, - meta.weightCount * 4, 8, boo::Primitive(meta.topology), + meta.weightCount * 4, boo::Primitive(meta.topology), reflectionType, true, true, true); return CModelShaders::g_ModelShaders->buildExtendedShader (tag, mat.heclIr, "CMDL", *CGraphics::g_BooFactory); diff --git a/Runtime/Graphics/Shaders/CModelShadersGLSL.cpp b/Runtime/Graphics/Shaders/CModelShadersGLSL.cpp index e1eb3b4b5..f86bc5c46 100644 --- a/Runtime/Graphics/Shaders/CModelShadersGLSL.cpp +++ b/Runtime/Graphics/Shaders/CModelShadersGLSL.cpp @@ -81,6 +81,9 @@ static const char* LightingShadowGLSL = "\n" "vec4 LightingShadowFunc(vec4 mvPosIn, vec4 mvNormIn)\n" "{\n" +" vec2 shadowUV = vtf.extTcgs[0];\n" +" shadowUV.y = 1.0 - shadowUV.y;\n" +" \n" " vec4 ret = ambient;\n" " \n" " vec3 delta = mvPosIn.xyz - lights[0].pos.xyz;\n" @@ -93,7 +96,7 @@ static const char* LightingShadowGLSL = " lights[0].angAtt[1] * angDot +\n" " lights[0].angAtt[0];\n" " ret += lights[0].color * clamp(angAtt, 0.0, 1.0) * att * clamp(dot(normalize(-delta), mvNormIn.xyz), 0.0, 1.0) *\n" -" texture(extTex7, vtf.extTcgs[0]).r;\n" +" texture(extTex7, shadowUV).r;\n" " \n" " for (int i=1 ; i<" _XSTR(URDE_MAX_LIGHTS) " ; ++i)\n" " {\n" diff --git a/Runtime/Graphics/Shaders/CModelShadersMetal.cpp b/Runtime/Graphics/Shaders/CModelShadersMetal.cpp index 1b5cf5b9d..d1b10662e 100644 --- a/Runtime/Graphics/Shaders/CModelShadersMetal.cpp +++ b/Runtime/Graphics/Shaders/CModelShadersMetal.cpp @@ -93,7 +93,7 @@ static const char* LightingShadowMetal = " lu.lights[0].angAtt[1] * angDot +\n" " lu.lights[0].angAtt[0];\n" " ret += lu.lights[0].color * saturate(angAtt) * att * saturate(dot(normalize(-delta), mvNormIn.xyz)) *\n" -" extTex7.sample(clampSamp, vtf.extTcgs0);\n" +" extTex7.sample(clampSamp, vtf.extTcgs0).r;\n" " \n" " for (int i=1 ; i<" _XSTR(URDE_MAX_LIGHTS) " ; ++i)\n" " {\n" diff --git a/Runtime/Graphics/Shaders/CWorldShadowShader.cpp b/Runtime/Graphics/Shaders/CWorldShadowShader.cpp index 6d57e6da9..35e0ec8de 100644 --- a/Runtime/Graphics/Shaders/CWorldShadowShader.cpp +++ b/Runtime/Graphics/Shaders/CWorldShadowShader.cpp @@ -48,7 +48,8 @@ void CWorldShadowShader::blendPreviousShadow() { if (!m_prevQuad) m_prevQuad.emplace(EFilterType::Blend, m_tex.get()); - m_prevQuad->draw({1.f, 0.85f}, 1.f); + zeus::CRectangle rect(0.f, 1.f, 1.f, -1.f); + m_prevQuad->draw({1.f, 0.85f}, 1.f, rect); } void CWorldShadowShader::resolveTexture() diff --git a/Runtime/MP1/MP1.cpp b/Runtime/MP1/MP1.cpp index 972ebb780..4563f50cc 100644 --- a/Runtime/MP1/MP1.cpp +++ b/Runtime/MP1/MP1.cpp @@ -54,6 +54,8 @@ #include "CDependencyGroup.hpp" #include "MP1OriginalIDs.hpp" +#include + namespace urde { URDE_DECL_SPECIALIZE_SHADER(CParticleSwooshShaders) @@ -437,12 +439,94 @@ void CMain::StreamNewGameState(CBitStreamReader& r, u32 idx) g_GameState->HintOptions().SetNextHintTime(); } +static logvisor::Module DiscordLog("Discord"); +static const char* DISCORD_APPLICATION_ID = "402571593815031819"; +static int64_t DiscordStartTime; +static CAssetId DiscordWorldSTRG; +static TLockedToken DiscordWorldSTRGObj; +static std::string DiscordWorldName; +static u32 DiscordItemPercent = 0xffffffff; +static std::string DiscordState; + +void CMain::InitializeDiscord() +{ + DiscordStartTime = time(0); + DiscordEventHandlers handlers = {}; + handlers.ready = HandleDiscordReady; + handlers.disconnected = HandleDiscordDisconnected; + handlers.errored = HandleDiscordErrored; + Discord_Initialize(DISCORD_APPLICATION_ID, &handlers, 1, nullptr); +} + +void CMain::ShutdownDiscord() +{ + DiscordWorldSTRGObj = TLockedToken(); + Discord_Shutdown(); +} + +void CMain::UpdateDiscordPresence(CAssetId worldSTRG) +{ + bool updated = false; + + if (worldSTRG != DiscordWorldSTRG) + { + DiscordWorldSTRG = worldSTRG; + DiscordWorldSTRGObj = g_SimplePool->GetObj(SObjectTag{FOURCC('STRG'), worldSTRG}); + } + if (DiscordWorldSTRGObj.IsLoaded()) + { + DiscordWorldName = hecl::Char16ToUTF8(DiscordWorldSTRGObj->GetString(0)); + DiscordWorldSTRGObj = TLockedToken(); + updated = true; + } + + if (g_GameState) + { + if (CPlayerState* pState = g_GameState->GetPlayerState().get()) + { + u32 itemPercent = u32(std::ceil(pState->CalculateItemCollectionRate() * 100.f / + pState->GetPickupTotal())); + if (DiscordItemPercent != itemPercent) + { + DiscordItemPercent = itemPercent; + DiscordState = hecl::Format("%d%%", itemPercent); + updated = true; + } + } + } + + if (updated) + { + DiscordRichPresence discordPresence = {}; + discordPresence.state = DiscordState.c_str(); + discordPresence.details = DiscordWorldName.c_str(); + discordPresence.startTimestamp = DiscordStartTime; + Discord_UpdatePresence(&discordPresence); + } +} + +void CMain::HandleDiscordReady() +{ + DiscordLog.report(logvisor::Info, "Discord Ready"); +} + +void CMain::HandleDiscordDisconnected(int errorCode, const char* message) +{ + DiscordLog.report(logvisor::Warning, "Discord Disconnected: %s", message); +} + +void CMain::HandleDiscordErrored(int errorCode, const char* message) +{ + DiscordLog.report(logvisor::Error, "Discord Error: %s", message); +} + void CMain::Init(const hecl::Runtime::FileStoreManager& storeMgr, hecl::CVarManager* cvarMgr, boo::IWindow* window, boo::IAudioVoiceEngine* voiceEngine, amuse::IBackendVoiceAllocator& backend) { + InitializeDiscord(); m_mainWindow = window; m_cvarMgr = cvarMgr; m_console = std::make_unique(m_cvarMgr); @@ -524,6 +608,9 @@ bool CMain::Proc() */ x160_24_finished = true; } + + Discord_RunCallbacks(); + return x160_24_finished; } @@ -606,6 +693,7 @@ void CMain::Shutdown() TMultiBlendShader::Shutdown(); CFluidPlaneShader::Shutdown(); CGraphics::ShutdownBoo(); + ShutdownDiscord(); } boo::IWindow* CMain::GetMainWindow() const diff --git a/Runtime/MP1/MP1.hpp b/Runtime/MP1/MP1.hpp index 31663c4d3..966aaa9b5 100644 --- a/Runtime/MP1/MP1.hpp +++ b/Runtime/MP1/MP1.hpp @@ -262,6 +262,11 @@ private: bool m_needsWarmupClear = false; void InitializeSubsystems(const hecl::Runtime::FileStoreManager& storeMgr); + static void InitializeDiscord(); + static void ShutdownDiscord(); + static void HandleDiscordReady(); + static void HandleDiscordDisconnected(int errorCode, const char* message); + static void HandleDiscordErrored(int errorCode, const char* message); public: CMain(IFactory* resFactory, CSimplePool* resStore, @@ -276,6 +281,8 @@ public: void SetMFGameBuilt(bool b) { x160_25_mfGameBuilt = b; } void SetScreenFading(bool b) { x160_26_screenFading = b; } + static void UpdateDiscordPresence(CAssetId worldSTRG = {}); + //int RsMain(int argc, const boo::SystemChar* argv[]); void Init(const hecl::Runtime::FileStoreManager& storeMgr, hecl::CVarManager* cvarManager, diff --git a/Runtime/World/CPlayer.cpp b/Runtime/World/CPlayer.cpp index 15bbbbbba..3d1757d01 100644 --- a/Runtime/World/CPlayer.cpp +++ b/Runtime/World/CPlayer.cpp @@ -2922,9 +2922,9 @@ void CPlayer::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CState CActor::AcceptScriptMsg(msg, sender, mgr); } -void CPlayer::SetVisorSteam(float f1, float f2, float f3, CAssetId txtr, bool affectsThermal) +void CPlayer::SetVisorSteam(float targetAlpha, float alphaInDur, float alphaOutDur, CAssetId txtr, bool affectsThermal) { - x7a0_visorSteam.SetSteam(f1, f2, f3, txtr, affectsThermal); + x7a0_visorSteam.SetSteam(targetAlpha, alphaInDur, alphaOutDur, txtr, affectsThermal); } static const u16 skLeftStepSounds[] = diff --git a/Runtime/World/CWorldShadow.cpp b/Runtime/World/CWorldShadow.cpp index 9ca8db0cf..26bf1f08c 100644 --- a/Runtime/World/CWorldShadow.cpp +++ b/Runtime/World/CWorldShadow.cpp @@ -18,6 +18,14 @@ void CWorldShadow::EnableModelProjectedShadow(const zeus::CTransform& pos, s32 l texTransform = (texTransform * zeus::CTransform::Scale(float(M_SQRT2) * x64_objHalfExtent * f1)).inverse(); texTransform = zeus::CTransform::Translate(0.5f, 0.f, 0.5f) * texTransform; CBooModel::EnableShadowMaps(m_shader.GetTexture().get(), texTransform); + +#if CWORLDSHADOW_FEEDBACK + if (!m_feedback) + m_feedback.emplace(EFilterType::Blend, m_shader.GetTexture().get()); + + zeus::CRectangle rect(0.4f, 0.4f, 0.2f, 0.2f); + m_feedback->draw(zeus::CColor::skWhite, 1.f, rect); +#endif } void CWorldShadow::DisableModelProjectedShadow() @@ -78,9 +86,6 @@ void CWorldShadow::BuildLightShadowTexture(const CStateManager& mgr, TAreaId aid x34_model = zeus::lookAt(centerPoint - zeus::CVector3f(0.f, 0.f, 0.1f), light.GetPosition()); CGraphics::SetModelMatrix(x34_model); - m_shadowViewProj = CGraphics::GetPerspectiveProjectionMatrix(false) * - CGraphics::g_CameraMatrix.toMatrix4f(); - float extent = float(M_SQRT2) * x64_objHalfExtent; /* Depth test and write */ /* Color white 100% alpha */ @@ -98,7 +103,7 @@ void CWorldShadow::BuildLightShadowTexture(const CStateManager& mgr, TAreaId aid CGraphics::SetModelMatrix(x34_model); /* No depth test or write */ /* Color white 25% alpha */ - //m_shader.lightenShadow(); + m_shader.lightenShadow(); } if (motionBlur && !x88_blurReset) @@ -106,7 +111,7 @@ void CWorldShadow::BuildLightShadowTexture(const CStateManager& mgr, TAreaId aid /* No depth test or write */ /* Color white 85% alpha */ /* Draw in shadow texture */ - //m_shader.blendPreviousShadow(); + m_shader.blendPreviousShadow(); } x88_blurReset = false; diff --git a/Runtime/World/CWorldShadow.hpp b/Runtime/World/CWorldShadow.hpp index e1e72c6bd..b76174d82 100644 --- a/Runtime/World/CWorldShadow.hpp +++ b/Runtime/World/CWorldShadow.hpp @@ -5,6 +5,8 @@ #include "zeus/CAABox.hpp" #include "Graphics/Shaders/CWorldShadowShader.hpp" +#define CWORLDSHADOW_FEEDBACK 0 + namespace urde { class CStateManager; @@ -20,7 +22,9 @@ class CWorldShadow TAreaId x80_aid; s32 x84_lightIdx = -1; bool x88_blurReset = true; - zeus::CMatrix4f m_shadowViewProj; +#if CWORLDSHADOW_FEEDBACK + std::experimental::optional m_feedback; +#endif public: CWorldShadow(u32 w, u32 h, bool rgba8); void EnableModelProjectedShadow(const zeus::CTransform& pos, s32 lightIdx, float f1); diff --git a/discord-rpc b/discord-rpc new file mode 160000 index 000000000..b85758ec1 --- /dev/null +++ b/discord-rpc @@ -0,0 +1 @@ +Subproject commit b85758ec19ab37a317662eb93d7208eaae129e84 diff --git a/hecl b/hecl index b9f410a2f..49cd88784 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit b9f410a2f87eb837ffc5937ed6a7cc637d91ac79 +Subproject commit 49cd887849d90aa17751d4388309c624aa6599a3 diff --git a/hecl-gui b/hecl-gui index b9a0bec10..3b70f8267 160000 --- a/hecl-gui +++ b/hecl-gui @@ -1 +1 @@ -Subproject commit b9a0bec10b812738cbfdaa14ebef2e570b8c800d +Subproject commit 3b70f8267645ba99f44e2f2a9f58a2fad7a27c36 diff --git a/rapidjson b/rapidjson new file mode 160000 index 000000000..2fb78f9ce --- /dev/null +++ b/rapidjson @@ -0,0 +1 @@ +Subproject commit 2fb78f9cee01996f020d5af7592b37c5a0693b31