From c18ff8f2e31218103755dbc8d5b21488c461076d Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Tue, 31 Dec 2024 17:43:39 +0800 Subject: [PATCH] fix: fix various issues. - fix convertion loss in CKCamera. - bump up version to 0.3.0 - use CMake to generate version info header. - fix annotation about Dassault ComputeCRC error. - change member field initialization value in CKLight. --- .gitignore | 3 +++ CMake/VTVersion.hpp.in | 6 ++++++ CMakeLists.txt | 2 +- LibCmo/CK2/CKFileReader.cpp | 21 ++++++++++++--------- LibCmo/CK2/ObjImpls/CKCamera.cpp | 2 +- LibCmo/CK2/ObjImpls/CKLight.cpp | 5 +++-- LibCmo/CMakeLists.txt | 8 ++++++++ LibCmo/VTInternal.hpp | 2 ++ Unvirt/CmdHelper.hpp | 4 ++-- Unvirt/UnvirtContext.cpp | 2 +- 10 files changed, 39 insertions(+), 16 deletions(-) create mode 100644 CMake/VTVersion.hpp.in diff --git a/.gitignore b/.gitignore index 00bcbac..d58fc50 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,9 @@ *.nms *.vmo +# Ignore CMake generated version header +LibCmo/VTVersion.hpp + # Ignore temporary Visual Studio files and folders temp/ out/ diff --git a/CMake/VTVersion.hpp.in b/CMake/VTVersion.hpp.in new file mode 100644 index 0000000..aed5e99 --- /dev/null +++ b/CMake/VTVersion.hpp.in @@ -0,0 +1,6 @@ +#pragma once + +#define LIBCMO_VER_MAJOR @PROJECT_VERSION_MAJOR@ +#define LIBCMO_VER_MINOR @PROJECT_VERSION_MINOR@ +#define LIBCMO_VER_PATCH @PROJECT_VERSION_PATCH@ +#define LIBCMO_VER_STR "@PROJECT_VERSION_MAJOR@.@PROJECT_VERSION_MINOR@.@PROJECT_VERSION_PATCH@" diff --git a/CMakeLists.txt b/CMakeLists.txt index 19e68d8..fdfe974 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.23) project(NeMo - VERSION 0.2.0 + VERSION 0.3.0 LANGUAGES CXX ) diff --git a/LibCmo/CK2/CKFileReader.cpp b/LibCmo/CK2/CKFileReader.cpp index b847c70..2ae809a 100644 --- a/LibCmo/CK2/CKFileReader.cpp +++ b/LibCmo/CK2/CKFileReader.cpp @@ -102,24 +102,27 @@ namespace LibCmo::CK2 { // This is a patch for Dassault stupid programmer. // // After Virtools 4.0, Dassault use a new way to compute the CRC of file. - // Dassault introduce a new class called CKMemoryBufferWriter which use file and memory map to handle big file properly. + // Dassault introduces a new class called CKMemoryBufferWriter which use file and memory map to handle big file properly. + // This algorithm splits the whole data body into 8 MB chunks and calculate them one by one to avoid instantaneous memory occupation. // However, there is a bug in virtual function CKMemoryBufferWriter::ComputeCRC. - // It takes `PreviousCRC` as argument but never use it in function. In this function, the start value of CRC compution is hardcoded 0. + // It takes `PreviousCRC` as argument but never use it in function. + // In this function, the start value of CRC compution is hardcoded 0. // So, although Dassault programmer try to compute CRC for file header, header part and daat part in code, it actually only compute CRC for data part! - // I 100% sure this is the mistake of Dassault stupid programmer and this bug cause horrible result. + // I 100% sure this is the mistake of Dassault stupid programmer and this bug cause more horrible result. // // In Virtools 2.1, engine will check CRC of file first. If no matched CRC, engine will reject loading file. // So the obvious result is that we can not load file saved by Virtools 4.0 in Virtools 2.1. // But this is not the point which makes me indignant. - // The real weird point is that we can use Virtools 3.5 to open file saved by Virtools 4.0 but why? - // After some research, I found that the programmer of Dassault totally removed CRC check when loading file since some version which I don't know! + // The real weird point is that we can use Virtools 3.5 to open file saved by Virtools 4.0, but why? + // After some researches, I found that the programmer of Dassault totally removed CRC check when loading file, since some version which I don't know, to suppress this bug! // This is totally cheat and commercial-oriented behavior! - // I guess Dassault programmer also find that they can not load new created file in old Virtools. - // But they entirely don't know how to resolve it. So they just directly remove the whole of CRC checker! - // That's the point which makes me indignant. + // I guess Dassault programmer also found that they can not load new created file in old Virtools. + // But they didn't find out what cause this bug, and just directly remove the whole of CRC checker to resolve this bug! + // I can't believe that this thing happens on such official software. + // This is the point which makes me indignant. gotten_crc = CKComputeDataCRC(parser->GetPtr(), this->m_FileInfo.DataPackSize, 0u); - // Both CRC compute methods are failed, this file may be really broken. + // Both CRC compute methods are failed. This file may be really broken. // Report exception directly. if (gotten_crc != this->m_FileInfo.Crc) { this->m_Ctx->OutputToConsole(u8"Virtools file CRC error."); diff --git a/LibCmo/CK2/ObjImpls/CKCamera.cpp b/LibCmo/CK2/ObjImpls/CKCamera.cpp index 0a73031..888fd70 100644 --- a/LibCmo/CK2/ObjImpls/CKCamera.cpp +++ b/LibCmo/CK2/ObjImpls/CKCamera.cpp @@ -128,7 +128,7 @@ SetObjectFlags(obj_flags); \ } void CKCamera::ComputeProjectionMatrix(VxMath::VxMatrix& mat) const { - CKFLOAT aspect = m_Width / m_Height; + CKFLOAT aspect = static_cast(m_Width) / m_Height; if (m_ProjectType == CK_CAMERA_PROJECTION::CK_PERSPECTIVEPROJECTION) { mat.Perspective(m_Fov, aspect, m_FrontPlane, m_BackPlane); } else { diff --git a/LibCmo/CK2/ObjImpls/CKLight.cpp b/LibCmo/CK2/ObjImpls/CKLight.cpp index 7dd3e83..e8fedb9 100644 --- a/LibCmo/CK2/ObjImpls/CKLight.cpp +++ b/LibCmo/CK2/ObjImpls/CKLight.cpp @@ -1,5 +1,6 @@ #include "CKLight.hpp" #include "../CKStateChunk.hpp" +#include namespace LibCmo::CK2::ObjImpls { @@ -16,8 +17,8 @@ namespace LibCmo::CK2::ObjImpls { m_LightData.m_Attenuation0 = 1.0f; m_LightData.m_Attenuation1 = 0.0f; m_LightData.m_Attenuation2 = 0.0f; - m_LightData.m_InnerSpotCone = 0.69813174f; // MARK: Perhaps 40 deg in rad. - m_LightData.m_OuterSpotCone = 0.78539819f; // MARK: Perhaps 45 deg in rad. + m_LightData.m_InnerSpotCone = 40.0f / 180.0f * std::numbers::pi_v; // MARK: Original value is 0.69813174f. Perhaps 40 deg in rad. + m_LightData.m_OuterSpotCone = 45.0f / 180.0f * std::numbers::pi_v; // MARK: Original value is 0.78539819f. Perhaps 45 deg in rad. } CKLight::~CKLight() {} diff --git a/LibCmo/CMakeLists.txt b/LibCmo/CMakeLists.txt index 7a65020..bb9ad8f 100644 --- a/LibCmo/CMakeLists.txt +++ b/LibCmo/CMakeLists.txt @@ -1,3 +1,10 @@ +# Configure version file +configure_file( + ${CMAKE_CURRENT_LIST_DIR}/../CMake/VTVersion.hpp.in + ${CMAKE_CURRENT_LIST_DIR}/VTVersion.hpp + @ONLY +) + # Create static library add_library(LibCmo STATIC "") # Setup static library sources @@ -47,6 +54,7 @@ PUBLIC FILE_SET HEADERS FILES # Asststant header files + VTVersion.hpp VTInternal.hpp VTEncoding.hpp VTUtils.hpp diff --git a/LibCmo/VTInternal.hpp b/LibCmo/VTInternal.hpp index 6e9ef15..826f274 100644 --- a/LibCmo/VTInternal.hpp +++ b/LibCmo/VTInternal.hpp @@ -20,6 +20,8 @@ * They should use Virtools type anywhere, except that Virtools type can not fulfill their requirements. */ +// The version info header of LibCmo +#include "VTVersion.hpp" // The base header of LibCmo. // It provides various convenient stuff, for example: // - General LibCmo specific custom exception. diff --git a/Unvirt/CmdHelper.hpp b/Unvirt/CmdHelper.hpp index 356b766..9012a9a 100644 --- a/Unvirt/CmdHelper.hpp +++ b/Unvirt/CmdHelper.hpp @@ -362,8 +362,8 @@ namespace Unvirt::CmdHelper { throw std::invalid_argument("root node should not be inserted as child node."); // check conflict const auto& new_node_set = new_node_ptr->GetConflictSet(); - for (auto& node : m_Nodes) { - const auto& node_set = node->GetConflictSet(); + for (auto& child_node : m_Nodes) { + const auto& node_set = child_node->GetConflictSet(); if (new_node_set.IsConflictWith(node_set)) throw std::invalid_argument("try to add a conflict node. please check your code."); } diff --git a/Unvirt/UnvirtContext.cpp b/Unvirt/UnvirtContext.cpp index f143636..3d22c64 100644 --- a/Unvirt/UnvirtContext.cpp +++ b/Unvirt/UnvirtContext.cpp @@ -281,7 +281,7 @@ namespace Unvirt::Context { YYCC::ConsoleHelper::EnableColorfulConsole(); // Show banner - YYCC::ConsoleHelper::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"Unvirt 0.2.0") " built at " __DATE__ " " __TIME__); + YYCC::ConsoleHelper::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"Unvirt") " (based on LibCmo " LIBCMO_VER_STR ") built at " __DATE__ " " __TIME__); YYCC::ConsoleHelper::WriteLine(u8"Type 'help' for more infomation. Type 'exit' to quit."); // start process loop