From 38ddc52d2883819686064a4dbfce32c895682b70 Mon Sep 17 00:00:00 2001 From: Zero Fanker Date: Mon, 20 May 2024 23:27:42 -0400 Subject: [PATCH] Introduced voxel render lib written by Thomas Sneddon . --- .gitmodules | 3 + 3rdParty/CncVxlRender | 1 + 3rdParty/xcc/misc/cc_file.h | 2 +- 3rdParty/xcc/misc/tmp_ts_file.h | 5 +- MissionEditor.sln | 65 ++++ MissionEditor/Loading.cpp | 304 ++++++------------ MissionEditor/MissionEditor.vcxproj | 4 +- MissionEditor/MissionEditor.vcxproj.filters | 6 + MissionEditor/PropertySheets/Common.props | 2 +- MissionEditor/PropertySheets/Debug.props | 3 +- .../PropertySheets/Distribution.props | 4 + MissionEditor/PropertySheets/Release.props | 3 +- MissionEditor/VoxelDrawer.cpp | 83 +++++ MissionEditor/VoxelDrawer.h | 27 ++ MissionEditorPackLib/MissionEditorPackLib.cpp | 29 ++ MissionEditorPackLib/MissionEditorPackLib.h | 3 + 16 files changed, 329 insertions(+), 215 deletions(-) create mode 160000 3rdParty/CncVxlRender create mode 100644 MissionEditor/VoxelDrawer.cpp create mode 100644 MissionEditor/VoxelDrawer.h diff --git a/.gitmodules b/.gitmodules index d49ab5c..e35d075 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "gtest-lib"] path = googletest url = ../gtest-lib.git +[submodule "3rdParty/CncVxlRender"] + path = 3rdParty/CncVxlRender + url = ../CncVxlRenderText.git diff --git a/3rdParty/CncVxlRender b/3rdParty/CncVxlRender new file mode 160000 index 0000000..ebea5a3 --- /dev/null +++ b/3rdParty/CncVxlRender @@ -0,0 +1 @@ +Subproject commit ebea5a3718f27be0a57e717fafa8cc2afbede0e1 diff --git a/3rdParty/xcc/misc/cc_file.h b/3rdParty/xcc/misc/cc_file.h index ef7e9b1..ba157d7 100644 --- a/3rdParty/xcc/misc/cc_file.h +++ b/3rdParty/xcc/misc/cc_file.h @@ -191,5 +191,5 @@ private: bool m_is_open = false; int64_t m_p; const bool m_read_on_open; - size_t m_size; + int64_t m_size; }; diff --git a/3rdParty/xcc/misc/tmp_ts_file.h b/3rdParty/xcc/misc/tmp_ts_file.h index 22358eb..2963b42 100644 --- a/3rdParty/xcc/misc/tmp_ts_file.h +++ b/3rdParty/xcc/misc/tmp_ts_file.h @@ -34,7 +34,10 @@ public: bool is_valid() const { const t_tmp_ts_header& h = header(); - auto const size = get_size(); + if (get_size() < 0) { + return false; + } + auto const size = static_cast(get_size()); if (sizeof(t_tmp_ts_header) > size || !h.cblocks_x || !h.cblocks_y || h.cx != 48 && h.cx != 60 || diff --git a/MissionEditor.sln b/MissionEditor.sln index 9993885..4197936 100644 --- a/MissionEditor.sln +++ b/MissionEditor.sln @@ -6,6 +6,7 @@ MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MissionEditor", "MissionEditor\MissionEditor.vcxproj", "{9326D29A-6547-42B9-A668-519F3C0720A9}" ProjectSection(ProjectDependencies) = postProject {5E445578-CB45-4D82-9A1C-FC7D3E8D866A} = {5E445578-CB45-4D82-9A1C-FC7D3E8D866A} + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63} = {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MissionEditorPackLib", "MissionEditorPackLib\MissionEditorPackLib.vcxproj", "{DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}" @@ -17,6 +18,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XCC Library", "3rdParty\xcc EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTest", "UnitTest\UnitTest.vcxproj", "{75E18879-7564-4A2C-8C00-393A5A17171F}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CncVxlRenderText", "3rdParty\CncVxlRender\CncVxlRenderText.vcxproj", "{BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -39,6 +42,8 @@ Global Template|x64 = Template|x64 Tests FinalAlertDebug YR|Win32 = Tests FinalAlertDebug YR|Win32 Tests FinalAlertDebug YR|x64 = Tests FinalAlertDebug YR|x64 + Tool|Win32 = Tool|Win32 + Tool|x64 = Tool|x64 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {9326D29A-6547-42B9-A668-519F3C0720A9}.Debug|Win32.ActiveCfg = Tests FinalAlertDebug YR|Win32 @@ -81,6 +86,10 @@ Global {9326D29A-6547-42B9-A668-519F3C0720A9}.Tests FinalAlertDebug YR|Win32.Build.0 = Tests FinalAlertDebug YR|Win32 {9326D29A-6547-42B9-A668-519F3C0720A9}.Tests FinalAlertDebug YR|x64.ActiveCfg = Tests FinalAlertDebug YR|x64 {9326D29A-6547-42B9-A668-519F3C0720A9}.Tests FinalAlertDebug YR|x64.Build.0 = Tests FinalAlertDebug YR|x64 + {9326D29A-6547-42B9-A668-519F3C0720A9}.Tool|Win32.ActiveCfg = Template|Win32 + {9326D29A-6547-42B9-A668-519F3C0720A9}.Tool|Win32.Build.0 = Template|Win32 + {9326D29A-6547-42B9-A668-519F3C0720A9}.Tool|x64.ActiveCfg = Template|x64 + {9326D29A-6547-42B9-A668-519F3C0720A9}.Tool|x64.Build.0 = Template|x64 {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Debug|Win32.ActiveCfg = Debug|Win32 {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Debug|Win32.Build.0 = Debug|Win32 {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Debug|x64.ActiveCfg = Debug|x64 @@ -121,6 +130,10 @@ Global {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Tests FinalAlertDebug YR|Win32.Build.0 = Debug|Win32 {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Tests FinalAlertDebug YR|x64.ActiveCfg = Debug|x64 {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Tests FinalAlertDebug YR|x64.Build.0 = Debug|x64 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Tool|Win32.ActiveCfg = Release|Win32 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Tool|Win32.Build.0 = Release|Win32 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Tool|x64.ActiveCfg = Release|x64 + {DEB40EF0-E215-4C2F-A0AD-3742E2E01A8C}.Tool|x64.Build.0 = Release|x64 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Debug|Win32.ActiveCfg = Debug|Win32 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Debug|Win32.Build.0 = Debug|Win32 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Debug|x64.ActiveCfg = Debug|x64 @@ -161,6 +174,10 @@ Global {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Tests FinalAlertDebug YR|Win32.Build.0 = DebugMinimal|Win32 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Tests FinalAlertDebug YR|x64.ActiveCfg = Debug|x64 {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Tests FinalAlertDebug YR|x64.Build.0 = Debug|x64 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Tool|Win32.ActiveCfg = Release|Win32 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Tool|Win32.Build.0 = Release|Win32 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Tool|x64.ActiveCfg = ReleaseMinimal|x64 + {5E445578-CB45-4D82-9A1C-FC7D3E8D866A}.Tool|x64.Build.0 = ReleaseMinimal|x64 {75E18879-7564-4A2C-8C00-393A5A17171F}.Debug|Win32.ActiveCfg = Debug|Win32 {75E18879-7564-4A2C-8C00-393A5A17171F}.Debug|Win32.Build.0 = Debug|Win32 {75E18879-7564-4A2C-8C00-393A5A17171F}.Debug|x64.ActiveCfg = Debug|x64 @@ -201,6 +218,54 @@ Global {75E18879-7564-4A2C-8C00-393A5A17171F}.Tests FinalAlertDebug YR|Win32.Build.0 = Debug|Win32 {75E18879-7564-4A2C-8C00-393A5A17171F}.Tests FinalAlertDebug YR|x64.ActiveCfg = Debug|x64 {75E18879-7564-4A2C-8C00-393A5A17171F}.Tests FinalAlertDebug YR|x64.Build.0 = Debug|x64 + {75E18879-7564-4A2C-8C00-393A5A17171F}.Tool|Win32.ActiveCfg = Release|Win32 + {75E18879-7564-4A2C-8C00-393A5A17171F}.Tool|Win32.Build.0 = Release|Win32 + {75E18879-7564-4A2C-8C00-393A5A17171F}.Tool|x64.ActiveCfg = Release|x64 + {75E18879-7564-4A2C-8C00-393A5A17171F}.Tool|x64.Build.0 = Release|x64 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.Debug|Win32.ActiveCfg = Debug|Win32 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.Debug|Win32.Build.0 = Debug|Win32 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.Debug|x64.ActiveCfg = Debug|x64 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.Debug|x64.Build.0 = Debug|x64 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.FinalAlertDebug YR|Win32.ActiveCfg = Debug|Win32 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.FinalAlertDebug YR|Win32.Build.0 = Debug|Win32 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.FinalAlertDebug YR|x64.ActiveCfg = Debug|x64 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.FinalAlertDebug YR|x64.Build.0 = Debug|x64 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.FinalAlertDebug|Win32.ActiveCfg = Debug|Win32 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.FinalAlertDebug|Win32.Build.0 = Debug|Win32 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.FinalAlertDebug|x64.ActiveCfg = Debug|x64 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.FinalAlertDebug|x64.Build.0 = Debug|x64 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.FinalAlertRelease YR|Win32.ActiveCfg = Release|Win32 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.FinalAlertRelease YR|Win32.Build.0 = Release|Win32 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.FinalAlertRelease YR|x64.ActiveCfg = Release|x64 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.FinalAlertRelease YR|x64.Build.0 = Release|x64 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.FinalAlertRelease|Win32.ActiveCfg = Release|Win32 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.FinalAlertRelease|Win32.Build.0 = Release|Win32 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.FinalAlertRelease|x64.ActiveCfg = Release|x64 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.FinalAlertRelease|x64.Build.0 = Release|x64 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.FinalSunDebug|Win32.ActiveCfg = Debug|Win32 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.FinalSunDebug|Win32.Build.0 = Debug|Win32 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.FinalSunDebug|x64.ActiveCfg = Debug|x64 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.FinalSunDebug|x64.Build.0 = Debug|x64 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.FinalSunRelease|Win32.ActiveCfg = Release|Win32 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.FinalSunRelease|Win32.Build.0 = Release|Win32 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.FinalSunRelease|x64.ActiveCfg = Release|x64 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.FinalSunRelease|x64.Build.0 = Release|x64 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.Release|Win32.ActiveCfg = Release|Win32 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.Release|Win32.Build.0 = Release|Win32 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.Release|x64.ActiveCfg = Release|x64 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.Release|x64.Build.0 = Release|x64 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.Template|Win32.ActiveCfg = Tool|Win32 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.Template|Win32.Build.0 = Tool|Win32 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.Template|x64.ActiveCfg = Tool|x64 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.Template|x64.Build.0 = Tool|x64 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.Tests FinalAlertDebug YR|Win32.ActiveCfg = Debug|Win32 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.Tests FinalAlertDebug YR|Win32.Build.0 = Debug|Win32 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.Tests FinalAlertDebug YR|x64.ActiveCfg = Debug|x64 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.Tests FinalAlertDebug YR|x64.Build.0 = Debug|x64 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.Tool|Win32.ActiveCfg = Tool|Win32 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.Tool|Win32.Build.0 = Tool|Win32 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.Tool|x64.ActiveCfg = Tool|x64 + {BAE32EF7-4F88-40D8-8984-A2EAF14C0A63}.Tool|x64.Build.0 = Tool|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/MissionEditor/Loading.cpp b/MissionEditor/Loading.cpp index f2dd2b7..ad95c86 100644 --- a/MissionEditor/Loading.cpp +++ b/MissionEditor/Loading.cpp @@ -40,6 +40,7 @@ #include "VoxelNormals.h" #include #include "IniMega.h" +#include "VoxelDrawer.h" #ifdef _DEBUG #define new DEBUG_NEW @@ -47,14 +48,6 @@ static char THIS_FILE[] = __FILE__; #endif -struct DrawRect -{ - int X{}; - int Y{}; - int Width{}; - int Height{}; -}; - ///////////////////////////////////////////////////////////////////////////// // Dialogfeld CLoading @@ -103,6 +96,7 @@ CLoading::CLoading(CWnd* pParent /*=NULL*/) : } VXL_Reset(); + VoxelDrawer::Initalize(); errstream << "CLoading::CLoading() called" << endl; errstream.flush(); @@ -1578,129 +1572,47 @@ void CLoading::LoadBuilding(const CString& ID) CString TurName = rules.GetStringOr(ID, "TurretAnim", ID + "tur"); CString BarlName = ID + "barl"; + auto finder = [this](LPCTSTR lpFilename, char* pTheaterChar) { + return this->FindFileInMix(lpFilename, reinterpret_cast(pTheaterChar)); + }; - //if (!DrawStuff::is_vpl_loaded()) { - // DrawStuff::load_vpl("voxels.vpl"); - //} + if (!VoxelDrawer::IsVPLLoaded()) { + VoxelDrawer::LoadVPLFile("voxels.vpl", finder); + } unsigned char* pTurImages[8]{ nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr }; unsigned char* pBarlImages[8]{ nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr,nullptr }; - DrawRect turrect[8] = { 0 }; - int barlrect[8][4] = { 0 }; + VoxelRectangle turrect[8] = { 0 }; + VoxelRectangle barlrect[8] = { 0 }; CString VXLName = BarlName + ".vxl"; CString HVAName = BarlName + ".hva"; - HMIXFILE hBarl = FindFileInMix(BarlName); - if (hBarl && FSunPackLib::SetCurrentVXL(VXLName, hBarl)) { - auto vnc = FSunPackLib::VoxelNormalClass::Unknown; - std::vector vxlColors[8]; - std::vector vxlLighting[8]; - // we assume the voxel normal class is always the same for the combined voxels - FSunPackLib::GetVXLSectionInfo(0, vnc); - for (int i = 0; i < 8; ++i) { - float r_x, r_y, r_z; - const int dir = i; - r_x = 300; - r_y = 0; - r_z = 45 * dir + 90; - - // convert - const double pi = 3.141592654; - const Vec3f rotation(r_x / 180.0f * pi, r_y / 180.0f * pi, r_z / 180.0f * pi); - RECT r; - int center_x, center_y; - if (!FSunPackLib::LoadVXLImage( - *m_voxelNormalTables, - lightDirection, - rotation, - 0, - vxlColors[i], - vxlLighting[i], - ¢er_x, ¢er_y, - 0, nullptr, nullptr, 0, 0, &r)) { - break; + if (VoxelDrawer::LoadVXLFile(VXLName, finder)) { + if (VoxelDrawer::LoadHVAFile(HVAName, finder)) { + for (int i = 0; i < 8; ++i) { + // (13 - i) % 8 for facing fix + bool result = VoxelDrawer::GetImageData((13 - i) % 8, pBarlImages[i], barlrect[i], turzadjust); + if (!result) + break; } - - auto const x = center_x; - auto const y = center_y; - auto const width = r.right - r.left; - auto const height = r.bottom - r.top; - - VXL_Add(vxlColors[i].data(), x, y, width, height); - VXL_Add(vxlLighting[i].data(), x, y, width, height); - VXL_GetAndClear(pTurImages[i], nullptr, nullptr); - barlrect[i] = { x, y, width, height }; } } - VXLName = TurName + ".vxl"; HVAName = TurName + ".hva"; - HMIXFILE hVXL = FindFileInMix(VXLName); - if (hVXL && FSunPackLib::SetCurrentVXL(VXLName, hVXL)) { - auto vnc = FSunPackLib::VoxelNormalClass::Unknown; - std::vector vxlColors[8]; - std::vector vxlLighting[8]; - // we assume the voxel normal class is always the same for the combined voxels - FSunPackLib::GetVXLSectionInfo(0, vnc); + if (VoxelDrawer::LoadVXLFile(VXLName, finder) && VoxelDrawer::LoadHVAFile(HVAName, finder)) { for (int i = 0; i < 8; ++i) { - float r_x, r_y, r_z; - const int dir = i; - r_x = 300; - r_y = 0; - r_z = 45 * dir + 90; - - // convert - const double pi = 3.141592654; - const Vec3f rotation(r_x / 180.0f * pi, r_y / 180.0f * pi, r_z / 180.0f * pi); - RECT r; - int center_x, center_y; - if (!FSunPackLib::LoadVXLImage( - *m_voxelNormalTables, - lightDirection, - rotation, - Vec3f{}, - vxlColors[i], - vxlLighting[i], - ¢er_x, ¢er_y, - 0, nullptr, nullptr, 0, 0, &r)) { + // (13 - i) % 8 for facing fix + bool result = VoxelDrawer::GetImageData((13 - i) % 8, pTurImages[i], turrect[i], pBarlImages[i] ? 0 : turzadjust); + if (!result) { break; } - - auto const x = center_x; - auto const y = center_y; - auto const width = r.right - r.left; - auto const height = r.bottom - r.top; - - //Blit_PalD(lpT[i], destRect, turretColors[i].data(), srcRect, ddsd.dwWidth, head.cx, ddsd.dwHeight, head.cy); - //Blit_PalD(lighting[i].data(), destRect, turretLighting[i].data(), srcRect, ddsd.dwWidth, head.cx, ddsd.dwHeight, head.cy, turretColors[i].data()); - //if (std::find_if(lighting[i].begin(), lighting[i].end(), [](const BYTE b) { return b != 255; }) != lighting[i].end()) - // p.lighting = std::shared_ptr>(new std::vector(std::move(lighting[i]))); - - UnionSHP_Add(vxlColors[i].data(), width, height); - UnionSHP_Add(vxlLighting[i].data(), width, height); - UnionSHP_GetAndClear(pTurImages[i], nullptr, nullptr, false); - //VXL_Add(vxlColors[i].data(), x, y, width, height); - //VXL_Add(vxlLighting[i].data(), x, y, width, height); - //VXL_GetAndClear(pTurImages[i], nullptr, nullptr); - turrect[i] = { x, y, width, height }; } } - //if (DrawStuff::load_vxl(VXLName) && DrawStuff::load_hva(HVAName)) { - // for (int i = 0; i < 8; ++i) { - // // (13 - i) % 8 for facing fix - // bool result = DrawStuff::get_to_image((13 - i) % 8, pTurImages[i], - // turrect[i][0], turrect[i][1], turrect[i][2], turrect[i][3], pBarlImages[i] ? 0 : turzadjust); - // if (!result) { - // break; - // } - // } - //} - for (int i = 0; i < 8; ++i) { auto pTempBuf = new(unsigned char[width * height]); memcpy_s(pTempBuf, width * height, pBuffer, width * height); @@ -1720,9 +1632,8 @@ void CLoading::LoadBuilding(const CString& ID) pKey.Format("%sY%d", ID, (15 - i) % 8); int turdeltaY = g_data.GetInteger("BuildingVoxelTurretsRA2", pKey); - //VXL_Add(pTurImages[i], turretRect.X + turdeltaX, turretRect.Y + turdeltaY, turretRect.Width, turretRect.Height); - UnionSHP_Add(pTurImages[i], turretRect.Width, turretRect.Height, turretRect.X + turdeltaX, turretRect.Y + turdeltaY); - //delete[] pTurImages[i]; + VXL_Add(pTurImages[i], turretRect.X + turdeltaX, turretRect.Y + turdeltaY, turretRect.W, turretRect.H); + delete[] pTurImages[i]; if (pBarlImages[i]) { pKey.Format("%sX%d", ID, (15 - i) % 8); @@ -1730,15 +1641,15 @@ void CLoading::LoadBuilding(const CString& ID) pKey.Format("%sY%d", ID, (15 - i) % 8); int barldeltaY = g_data.GetInteger("BuildingVoxelBarrelsRA2", pKey); - VXL_Add(pBarlImages[i], barlRect[2] + barldeltaX, barlRect[3] + barldeltaY, barlRect[0], barlRect[1]); + VXL_Add(pBarlImages[i], barlRect.X + barldeltaX, barlRect.Y + barldeltaY, barlRect.W, barlRect.H); delete[] pBarlImages[i]; } } - //int nW = 0x100, nH = 0x100; - //VXL_GetAndClear(pTurImages[i], &nW, &nH); + int nW = 0x100, nH = 0x100; + VXL_GetAndClear(pTurImages[i], &nW, &nH); - //UnionSHP_Add(pTurImages[i], 0x100, 0x100, deltaX, deltaY); + UnionSHP_Add(pTurImages[i], 0x100, 0x100, deltaX, deltaY); unsigned char* pImage; int width1, height1; @@ -1897,13 +1808,17 @@ void CLoading::LoadVehicleOrAircraft(const CString& ID) return; } + auto finder = [this](LPCTSTR lpFilename, char* pTheaterChar) { + return this->FindFileInMix(lpFilename, reinterpret_cast(pTheaterChar)); + }; + // As VXL CString FileName = ImageID + ".vxl"; CString HVAName = ImageID + ".hva"; - //if (!DrawStuff::is_vpl_loaded()) { - // DrawStuff::load_vpl("voxels.vpl"); - //} + if (!VoxelDrawer::IsVPLLoaded()) { + VoxelDrawer::LoadVPLFile("voxels.vpl", finder); + } CString PaletteName = art.GetStringOr(ArtID, "Palette", "unit"); GetFullPaletteName(PaletteName, cur_theat); @@ -1911,9 +1826,9 @@ void CLoading::LoadVehicleOrAircraft(const CString& ID) unsigned char* pImage[8]{ nullptr,nullptr ,nullptr ,nullptr ,nullptr ,nullptr ,nullptr ,nullptr }; unsigned char* pTurretImage[8]{ nullptr ,nullptr ,nullptr ,nullptr ,nullptr ,nullptr ,nullptr ,nullptr }; unsigned char* pBarrelImage[8]{ nullptr ,nullptr ,nullptr ,nullptr ,nullptr ,nullptr ,nullptr ,nullptr }; - DrawRect rect[8]; - DrawRect turretrect[8]; - DrawRect barrelrect[8]; + VoxelRectangle rect[8]; + VoxelRectangle turretrect[8]; + VoxelRectangle barrelrect[8]; int nMix = this->FindFileInMix(FileName); if (!nMix || !FSunPackLib::SetCurrentVXL(FileName, nMix)) { @@ -1923,52 +1838,18 @@ void CLoading::LoadVehicleOrAircraft(const CString& ID) std::vector vxlColors[8]; std::vector vxlLighting[8]; - //if (!DrawStuff::load_vxl(FileName)) { - // return; - //} - //if (!DrawStuff::load_hva(HVAName)) { - // return; - //} + if (!VoxelDrawer::LoadVXLFile(FileName, finder)) { + return; + } + if (!VoxelDrawer::LoadHVAFile(HVAName, finder)) { + return; + } for (int i = 0; i < 8; ++i) { // (i+6) % 8 to fix the facing - //bool result = DrawStuff::get_to_image((i + 6) % 8, pImage[i], - // rect[i][0], rect[i][1], rect[i][2], rect[i][3]); - //if (!result) { - // return; - //} - - float r_x, r_y, r_z; - const int dir = i; - r_x = 300; - r_y = 0; - r_z = 45 * dir + 90; - - // convert - const double pi = 3.141592654; - const Vec3f rotation(r_x / 180.0f * pi, r_y / 180.0f * pi, r_z / 180.0f * pi); - RECT r; - int center_x, center_y; - if (!FSunPackLib::LoadVXLImage( - *m_voxelNormalTables, - lightDirection, - rotation, - Vec3f{}, - vxlColors[i], - vxlLighting[i], - ¢er_x, ¢er_y, - 0, nullptr, nullptr, 0, 0, &r)) { - break; + bool result = VoxelDrawer::GetImageData((i + 6) % 8, pImage[i], rect[i]); + if (!result) { + return; } - - auto const x = center_x; - auto const y = center_y; - auto const width = r.right - r.left; - auto const height = r.bottom - r.top; - - VXL_Add(vxlColors[i].data(), x, y, width, height); - VXL_Add(vxlLighting[i].data(), x, y, width, height); - VXL_GetAndClear(pImage[i], nullptr, nullptr); - rect[i] = { x,y,width,height }; } if (!bHasTurret) { @@ -1979,7 +1860,7 @@ void CLoading::LoadVehicleOrAircraft(const CString& ID) unsigned char* outBuffer; int outW = 0x100, outH = 0x100; - VXL_Add(pImage[i], rect[i].X, rect[i].Y, rect[i].Width, rect[i].Height); + VXL_Add(pImage[i], rect[i].X, rect[i].Y, rect[i].W, rect[i].H); delete[] pImage[i]; VXL_GetAndClear(outBuffer, &outW, &outH); @@ -2000,38 +1881,42 @@ void CLoading::LoadVehicleOrAircraft(const CString& ID) CString turFileName = ImageID + "tur.vxl"; CString turHVAName = ImageID + "tur.hva"; - //if (DrawStuff::load_vxl(turFileName)) { - // return; - //} - //if (DrawStuff::load_hva(turHVAName)) { - // return; - //} + + if (VoxelDrawer::LoadVXLFile(turFileName, finder)) { + return; + } + if (VoxelDrawer::LoadHVAFile(turHVAName, finder)) { + return; + } + for (int i = 0; i < 8; ++i) { // (i+6) % 8 to fix the facing - //bool result = DrawStuff::get_to_image((i + 6) % 8, pTurretImage[i], - // turretrect[i][0], turretrect[i][1], turretrect[i][2], turretrect[i][3], F, L, H); + bool result = VoxelDrawer::GetImageData((i + 6) % 8, pTurretImage[i], + turretrect[i], F, L, H); - //if (!result) { - // break; - //} + if (!result) { + break; + } } CString barlFileName = ImageID + "barl.vxl"; CString barlHVAName = ImageID + "barl.hva"; - //if (!DrawStuff::load_vxl(barlFileName)) { - // return; - //} - //if (!DrawStuff::load_hva(barlHVAName)) { - // return; - //} + + if (!VoxelDrawer::LoadVXLFile(barlFileName, finder)) { + return; + } + if (!VoxelDrawer::LoadHVAFile(barlHVAName, finder)) { + return; + } + for (int i = 0; i < 8; ++i) { // (i+6) % 8 to fix the facing - //bool result = DrawStuff::get_to_image((i + 6) % 8, pBarrelImage[i], - // barrelrect[i][0], barrelrect[i][1], barrelrect[i][2], barrelrect[i][3], F, L, H); + bool result = VoxelDrawer::GetImageData((i + 6) % 8, pBarrelImage[i], + barrelrect[i], F, L, H); - //if (!result) { - // break; - //} + if (!result) { + break; + } } for (int i = 0; i < 8; ++i) { @@ -2042,7 +1927,7 @@ void CLoading::LoadVehicleOrAircraft(const CString& ID) int outW = 0x100, outH = 0x100; if (pImage[i]) { - VXL_Add(pImage[i], rect[i].X, rect[i].Y, rect[i].Width, rect[i].Height); + VXL_Add(pImage[i], rect[i].X, rect[i].Y, rect[i].W, rect[i].H); delete[] pImage[i]; } CString pKey; @@ -2051,7 +1936,7 @@ void CLoading::LoadVehicleOrAircraft(const CString& ID) int turdeltaX = g_data.GetInteger("VehicleVoxelTurretsRA2", pKey); pKey.Format("%sY%d", ID.operator LPCSTR(), i); int turdeltaY = g_data.GetInteger("VehicleVoxelTurretsRA2", pKey); - VXL_Add(pTurretImage[i], turretrect[i].X + turdeltaX, turretrect[i].Y + turdeltaY, turretrect[i].Width, turretrect[i].Height); + VXL_Add(pTurretImage[i], turretrect[i].X + turdeltaX, turretrect[i].Y + turdeltaY, turretrect[i].W, turretrect[i].H); delete[] pTurretImage[i]; if (pBarrelImage[i]) { @@ -2060,7 +1945,7 @@ void CLoading::LoadVehicleOrAircraft(const CString& ID) pKey.Format("%sY%d", ID.operator LPCSTR(), i); int barldeltaY = g_data.GetInteger("VehicleVoxelBarrelsRA2", pKey); - VXL_Add(pBarrelImage[i], barrelrect[i].X + barldeltaX, barrelrect[i].Y + barldeltaY, barrelrect[i].Width, barrelrect[i].Height); + VXL_Add(pBarrelImage[i], barrelrect[i].X + barldeltaX, barrelrect[i].Y + barldeltaY, barrelrect[i].W, barrelrect[i].H); delete[] pBarrelImage[i]; } } @@ -2522,6 +2407,7 @@ BOOL CLoading::InitMixFiles() CLoading::~CLoading() { Unload(); + VoxelDrawer::Finalize(); } void CLoading::Unload() @@ -3481,7 +3367,7 @@ void CLoading::LoadOverlayGraphic(const CString& lpOvrlName_, int iOvrlNum) FSunPackLib::SetTSPaletteEntry(hPalette, 0x10 + i, &rgbNew, &rgbOld[i]); } - } + } #endif FSunPackLib::LoadSHPImage(0, maxPics, lpT); @@ -3562,9 +3448,9 @@ void CLoading::LoadOverlayGraphic(const CString& lpOvrlName_, int iOvrlNum) delete[] lpT; - } + } -} + } int i; for (i = 0; i < 0xFF; i++) { @@ -3575,7 +3461,7 @@ void CLoading::LoadOverlayGraphic(const CString& lpOvrlName_, int iOvrlNum) } - } +} #endif void CLoading::OnDestroy() @@ -4043,21 +3929,21 @@ void CLoading::FreeAll() #endif i->second.pic = NULL; - } catch (...) { - CString err; - err = "Access violation while trying to release surface "; - char c[6]; - itoa(e, c, 10); - err += c; + } catch (...) { + CString err; + err = "Access violation while trying to release surface "; + char c[6]; + itoa(e, c, 10); + err += c; - err += "\n"; - OutputDebugString(err); - continue; - } - - i++; + err += "\n"; + OutputDebugString(err); + continue; } + i++; + } + try { @@ -4077,7 +3963,7 @@ void CLoading::FreeAll() } catch (...) { errstream << "Exception while freeing DirectDraw" << endl; } - } +} void CLoading::PostNcDestroy() { @@ -4346,7 +4232,7 @@ void CLoading::LoadStrings() //CCStrings[*rules.GetSectionName(i)].SetString=rul CCStrings[*rules.GetSectionName(i)].SetString((LPSTR)(LPCSTR)rules.GetSection(i)->values["Name"]); } -} + } #endif diff --git a/MissionEditor/MissionEditor.vcxproj b/MissionEditor/MissionEditor.vcxproj index ab01a2f..907abb3 100644 --- a/MissionEditor/MissionEditor.vcxproj +++ b/MissionEditor/MissionEditor.vcxproj @@ -348,7 +348,7 @@ NOMINMAX;RA2_MODE;YR_MODE;%(PreprocessorDefinitions) - ..\MissionEditorPackLib + ..\MissionEditorPackLib;..\3rdParty\CncVxlRender\inc RA2_MODE;YR_MODE;%(PreprocessorDefinitions) @@ -589,6 +589,7 @@ + @@ -691,6 +692,7 @@ + diff --git a/MissionEditor/MissionEditor.vcxproj.filters b/MissionEditor/MissionEditor.vcxproj.filters index 58193e5..59b1f8d 100644 --- a/MissionEditor/MissionEditor.vcxproj.filters +++ b/MissionEditor/MissionEditor.vcxproj.filters @@ -288,6 +288,9 @@ Source Files + + Source Files + @@ -586,6 +589,9 @@ Header Files + + Header Files + diff --git a/MissionEditor/PropertySheets/Common.props b/MissionEditor/PropertySheets/Common.props index cc6956b..1972aa8 100644 --- a/MissionEditor/PropertySheets/Common.props +++ b/MissionEditor/PropertySheets/Common.props @@ -30,7 +30,7 @@ true true - $(XccVcpkgDir)\lib + $(VxlLibDir);$(XccVcpkgDir)\lib Windows 11194304 11194304 diff --git a/MissionEditor/PropertySheets/Debug.props b/MissionEditor/PropertySheets/Debug.props index 3f12aa6..a0fb20e 100644 --- a/MissionEditor/PropertySheets/Debug.props +++ b/MissionEditor/PropertySheets/Debug.props @@ -6,6 +6,7 @@ $(XccDir)\vcpkg_installed\$(Platform)-windows\$(Platform)-windows $(XccVcpkgDirTriplet)\debug + $(SolutionDir)$(Platform)\Debug @@ -25,7 +26,7 @@ _DEBUG;%(PreprocessorDefinitions) - ddraw.lib;dxguid.lib;winmm.lib;gdiplus.lib;lzo2.lib;bz2d.lib;zlibd.lib;%(AdditionalDependencies) + CncVxlRenderText.lib;ddraw.lib;dxguid.lib;winmm.lib;gdiplus.lib;lzo2.lib;bz2d.lib;zlibd.lib;%(AdditionalDependencies) libcmt.lib diff --git a/MissionEditor/PropertySheets/Distribution.props b/MissionEditor/PropertySheets/Distribution.props index 65a9f22..358acad 100644 --- a/MissionEditor/PropertySheets/Distribution.props +++ b/MissionEditor/PropertySheets/Distribution.props @@ -15,6 +15,7 @@ + @@ -29,6 +30,9 @@ + + + diff --git a/MissionEditor/PropertySheets/Release.props b/MissionEditor/PropertySheets/Release.props index 6f1c942..f8f4f0f 100644 --- a/MissionEditor/PropertySheets/Release.props +++ b/MissionEditor/PropertySheets/Release.props @@ -6,6 +6,7 @@ $(XccDir)\vcpkg_installed\$(Platform)-windows\$(Platform)-windows $(XccVcpkgDirTriplet) + $(SolutionDir)$(Platform)\Release @@ -25,7 +26,7 @@ NDEBUG;_AFXDLL;%(PreprocessorDefinitions) - ddraw.lib;dxguid.lib;winmm.lib;gdiplus.lib;lzo2.lib;bz2.lib;zlib.lib;%(AdditionalDependencies) + CncVxlRenderText.lib;ddraw.lib;dxguid.lib;winmm.lib;gdiplus.lib;lzo2.lib;bz2.lib;zlib.lib;%(AdditionalDependencies) libcmt.lib; libcmtd.lib; msvcrtd.lib diff --git a/MissionEditor/VoxelDrawer.cpp b/MissionEditor/VoxelDrawer.cpp new file mode 100644 index 0000000..f5ec254 --- /dev/null +++ b/MissionEditor/VoxelDrawer.cpp @@ -0,0 +1,83 @@ +#include "stdafx.h" +#include "VoxelDrawer.h" +#include +#include "variables.h" +#include "MissionEditorPackLib.h" + +CString makeFullPath(const CString& name) +{ + return TSPath + name; +} + +std::pair readFile(const CString& name, HMIXFILE hMix) +{ + if (hMix == NULL) { + return FSunPackLib::LoadCCFile(makeFullPath(name), NULL); + } + return FSunPackLib::LoadCCFile(name, hMix); +} + +void VoxelDrawer::Initalize() +{ + CncImgCreate(); + CncImgSetMaxFacing(32); +} + +void VoxelDrawer::Finalize() +{ + CncImgRelease(); +} + +bool VoxelDrawer::LoadVPLFile(const CString& name, const FindFileInMixHandler& mixFindler) +{ + bool result = false; + auto const&& ret = readFile(name, mixFindler(name, nullptr)); + if (ret.second) { + result = CncImgLoadVPLFile(reinterpret_cast(ret.first.data())); + } + return result; +} + +bool VoxelDrawer::LoadVXLFile(const CString& name, const FindFileInMixHandler& mixFindler) +{ + bool result = false; + auto const&& ret = readFile(name, mixFindler(name, nullptr)); + if (ret.second) { + if (CncImgIsVXLLoaded()) { + CncImgClearCurrentVXL(); + } + result = CncImgLoadVXLFile(reinterpret_cast(ret.first.data())); + } + return result; +} + +bool VoxelDrawer::LoadHVAFile(const CString& name, const FindFileInMixHandler& mixFindler) +{ + bool result = false; + auto const&& ret = readFile(name, mixFindler(name, nullptr)); + if (ret.second) { + result = CncImgLoadHVAFile(reinterpret_cast(ret.first.data())); + } + return result; +} + +bool VoxelDrawer::GetImageData(unsigned int nFacing, unsigned char*& pBuffer, int& width, + int& height, int& x, int& y, const int F, const int L, const int H) +{ + const unsigned int nIndex = nFacing * 4; + CncImgPrepareVXLCache(nIndex, F, L, H); + CncImgGetImageFrame(nIndex, &width, &height, &x, &y); + if (width < 0 || height < 0) + return false; + return CncImgGetImageData(nIndex, &pBuffer); +} + +bool VoxelDrawer::GetImageData(unsigned int nFacing, unsigned char*& pBuffer, VoxelRectangle& rect, const int F, const int L, const int H) +{ + return GetImageData(nFacing, pBuffer, rect.W, rect.H, rect.X, rect.Y, F, L, H); +} + +bool VoxelDrawer::IsVPLLoaded() +{ + return CncImgIsVPLLoaded(); +} diff --git a/MissionEditor/VoxelDrawer.h b/MissionEditor/VoxelDrawer.h new file mode 100644 index 0000000..71418ba --- /dev/null +++ b/MissionEditor/VoxelDrawer.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include + +using HMIXFILE = DWORD; +using FindFileInMixHandler = std::function; + +struct VoxelRectangle +{ + int X, Y, W, H; +}; + +class VoxelDrawer +{ +public: + static void Initalize(); + static void Finalize(); + static bool LoadVPLFile(const CString& name, const FindFileInMixHandler& mixFindler); + static bool LoadVXLFile(const CString& name, const FindFileInMixHandler& mixFindler); + static bool LoadHVAFile(const CString& name, const FindFileInMixHandler& mixFindler); + static bool GetImageData(unsigned int nFacing, unsigned char*& pBuffer, + int& width, int& height, int& x, int& y, const int F = 0, const int L = 0, const int H = 0); + static bool GetImageData(unsigned int nFacing, unsigned char*& pBuffer, + VoxelRectangle& rect, const int F = 0, const int L = 0, const int H = 0); + static bool IsVPLLoaded(); +}; \ No newline at end of file diff --git a/MissionEditorPackLib/MissionEditorPackLib.cpp b/MissionEditorPackLib/MissionEditorPackLib.cpp index f4c0705..1723b0c 100644 --- a/MissionEditorPackLib/MissionEditorPackLib.cpp +++ b/MissionEditorPackLib/MissionEditorPackLib.cpp @@ -349,6 +349,35 @@ namespace FSunPackLib return pDDS->SetColorKey(DDCKEY_SRCBLT, &color_key); } + std::pair LoadCCFile(LPCTSTR filepath, HMIXFILE hMix) + { + MemoryBuffer buffer; + Ccc_file file(true); + + if (hMix != NULL) { + if (file.open(filepath, mixfiles[hMix - 1])) { + return {}; + } + } else { + if (file.open(filepath)) { + return {}; + } + } + + auto const size = file.get_size(); + + if (size < 0) { + return {}; + } + + buffer.resize(size); + + if (file.read(buffer.data(), size)) { + return {}; + } + return { std::move(buffer), true }; + } + BOOL XCC_Initialize(BOOL bLoadFromRegistry) { if (bLoadFromRegistry) diff --git a/MissionEditorPackLib/MissionEditorPackLib.h b/MissionEditorPackLib/MissionEditorPackLib.h index 842bde3..75ebccb 100644 --- a/MissionEditorPackLib/MissionEditorPackLib.h +++ b/MissionEditorPackLib/MissionEditorPackLib.h @@ -45,6 +45,8 @@ class VoxelNormalTables; typedef DWORD HMIXFILE; typedef DWORD HTSPALETTE; +using MemoryBuffer = std::vector; + struct SHPHEADER { __int16 zero;// type @@ -249,6 +251,7 @@ namespace FSunPackLib HRESULT SetColorKey(IDirectDrawSurface4* pDDS, COLORREF rgb); + std::pair LoadCCFile(LPCTSTR name, HMIXFILE hMix); }; #endif \ No newline at end of file