From 86b27557c9fef37c37d68b6ff97518add938e1a4 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Wed, 25 Dec 2024 13:58:39 +0800 Subject: [PATCH] feat: add 4 new added classes in Unvirt. - fix a fatal issue that make the output message from CKContext is empty. - fix argument type error for CKCamera::GetAspect and CKCamera::SetAspect. - add enums annotation and struct diaplay function in Unvirt for showing 4 new added classes. --- LibCmo/CK2/CKContext.cpp | 3 +- LibCmo/CK2/ObjImpls/CKCamera.cpp | 4 +- LibCmo/CK2/ObjImpls/CKCamera.hpp | 4 +- Unvirt/AccessibleValue.cpp | 10 ++++ Unvirt/AccessibleValue.hpp | 2 + Unvirt/StructFormatter.cpp | 78 +++++++++++++++++++++++++++++++- 6 files changed, 94 insertions(+), 7 deletions(-) diff --git a/LibCmo/CK2/CKContext.cpp b/LibCmo/CK2/CKContext.cpp index a1eab2c..cf30fa9 100644 --- a/LibCmo/CK2/CKContext.cpp +++ b/LibCmo/CK2/CKContext.cpp @@ -264,8 +264,7 @@ namespace LibCmo::CK2 { va_list argptr; va_start(argptr, fmt); - XContainer::XString result; - YYCC::StringHelper::VPrintf(fmt, argptr); + XContainer::XString result(YYCC::StringHelper::VPrintf(fmt, argptr)); va_end(argptr); // use c_str(), not XContainer::NSXString::ToCKSTRING because we want make sure this paramter is not nullptr. diff --git a/LibCmo/CK2/ObjImpls/CKCamera.cpp b/LibCmo/CK2/ObjImpls/CKCamera.cpp index 946b065..0a73031 100644 --- a/LibCmo/CK2/ObjImpls/CKCamera.cpp +++ b/LibCmo/CK2/ObjImpls/CKCamera.cpp @@ -117,11 +117,11 @@ SetObjectFlags(obj_flags); \ REMOVE_UPTODATE_FLAG; } - void CKCamera::GetAspectRatio(int& width, int& height) const { + void CKCamera::GetAspectRatio(CKDWORD& width, CKDWORD& height) const { width = m_Width; height = m_Height; } - void CKCamera::SetAspectRatio(int width, int height) { + void CKCamera::SetAspectRatio(CKDWORD width, CKDWORD height) { m_Width = width; m_Height = height; REMOVE_UPTODATE_FLAG; diff --git a/LibCmo/CK2/ObjImpls/CKCamera.hpp b/LibCmo/CK2/ObjImpls/CKCamera.hpp index f4bbd6d..747d368 100644 --- a/LibCmo/CK2/ObjImpls/CKCamera.hpp +++ b/LibCmo/CK2/ObjImpls/CKCamera.hpp @@ -33,8 +33,8 @@ namespace LibCmo::CK2::ObjImpls { void SetBackPlane(CKFLOAT back); void SetFov(CKFLOAT fov); - void GetAspectRatio(int& width, int& height) const; - void SetAspectRatio(int width, int height); + void GetAspectRatio(CKDWORD& width, CKDWORD& height) const; + void SetAspectRatio(CKDWORD width, CKDWORD height); void ComputeProjectionMatrix(VxMath::VxMatrix& mat) const; diff --git a/Unvirt/AccessibleValue.cpp b/Unvirt/AccessibleValue.cpp index 0a01769..1f618df 100644 --- a/Unvirt/AccessibleValue.cpp +++ b/Unvirt/AccessibleValue.cpp @@ -383,6 +383,10 @@ namespace Unvirt::AccessibleValue { { LibCmo::CK2::CK_BITMAPDATA_FLAGS::CKBITMAPDATA_FREEVIDEOMEMORY, { u8"CKBITMAPDATA_FREEVIDEOMEMORY" } }, { LibCmo::CK2::CK_BITMAPDATA_FLAGS::CKBITMAPDATA_DYNAMIC, { u8"CKBITMAPDATA_DYNAMIC" } }, }; + const GeneralReflectionArray CK_CAMERA_PROJECTION { + { LibCmo::CK2::CK_CAMERA_PROJECTION::CK_PERSPECTIVEPROJECTION, { u8"CK_PERSPECTIVEPROJECTION" } }, + { LibCmo::CK2::CK_CAMERA_PROJECTION::CK_ORTHOGRAPHICPROJECTION, { u8"CK_ORTHOGRAPHICPROJECTION" } }, + }; const GeneralReflectionArray VX_PIXELFORMAT { { LibCmo::VxMath::VX_PIXELFORMAT::UNKNOWN_PF, { u8"UNKNOWN_PF" } }, @@ -418,6 +422,12 @@ namespace Unvirt::AccessibleValue { { LibCmo::VxMath::VX_PIXELFORMAT::_4_ABGR8888_CLUT, { u8"_4_ABGR8888_CLUT" } }, { LibCmo::VxMath::VX_PIXELFORMAT::_4_ARGB8888_CLUT, { u8"_4_ARGB8888_CLUT" } }, }; + const GeneralReflectionArray VXLIGHT_TYPE { + { LibCmo::VxMath::VXLIGHT_TYPE::VX_LIGHTPOINT, { u8"VX_LIGHTPOINT" } }, + { LibCmo::VxMath::VXLIGHT_TYPE::VX_LIGHTSPOT, { u8"VX_LIGHTSPOT" } }, + { LibCmo::VxMath::VXLIGHT_TYPE::VX_LIGHTDIREC, { u8"VX_LIGHTDIREC" } }, + { LibCmo::VxMath::VXLIGHT_TYPE::VX_LIGHTPARA, { u8"VX_LIGHTPARA" } }, + }; const GeneralReflectionArray VXTEXTURE_BLENDMODE { { LibCmo::VxMath::VXTEXTURE_BLENDMODE::VXTEXTUREBLEND_DECAL, { u8"VXTEXTUREBLEND_DECAL" } }, { LibCmo::VxMath::VXTEXTURE_BLENDMODE::VXTEXTUREBLEND_MODULATE, { u8"VXTEXTUREBLEND_MODULATE" } }, diff --git a/Unvirt/AccessibleValue.hpp b/Unvirt/AccessibleValue.hpp index 0f4abe2..0d025bd 100644 --- a/Unvirt/AccessibleValue.hpp +++ b/Unvirt/AccessibleValue.hpp @@ -102,8 +102,10 @@ namespace Unvirt { extern const GeneralReflectionArray CK_3DENTITY_FLAGS; extern const GeneralReflectionArray CK_TEXTURE_SAVEOPTIONS; extern const GeneralReflectionArray CK_BITMAPDATA_FLAGS; + extern const GeneralReflectionArray CK_CAMERA_PROJECTION; extern const GeneralReflectionArray VX_PIXELFORMAT; + extern const GeneralReflectionArray VXLIGHT_TYPE; extern const GeneralReflectionArray VXTEXTURE_BLENDMODE; extern const GeneralReflectionArray VXTEXTURE_FILTERMODE; extern const GeneralReflectionArray VXBLEND_MODE; diff --git a/Unvirt/StructFormatter.cpp b/Unvirt/StructFormatter.cpp index 07733bf..dab85fa 100644 --- a/Unvirt/StructFormatter.cpp +++ b/Unvirt/StructFormatter.cpp @@ -165,7 +165,7 @@ namespace Unvirt::StructFormatter { // print current mesh { auto curmesh = obj->GetCurrentMesh(); - Console::Format(u8"->\t%s\t%s", + Console::FormatLine(u8"->\t%s\t%s", PrintPointer(curmesh).c_str(), (curmesh != nullptr ? PrintCKSTRING(curmesh->GetName()).c_str() : u8"") ); @@ -181,6 +181,70 @@ namespace Unvirt::StructFormatter { } } + + static void PrintCKLightDetail(LibCmo::CK2::ObjImpls::CKLight* obj) { + PrintCK3dEntityDetail(obj); + Console::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"CKLight")); + + Console::WriteLine(u8"== Basics =="); + Console::FormatLine(u8"Type: %s", AccessibleValue::GetEnumName(obj->GetType(), AccessibleValue::EnumDesc::VXLIGHT_TYPE).c_str()); + Console::FormatLine(u8"Color: %s", PrintColor(obj->GetColor()).c_str()); + Console::FormatLine(u8"Light Power: %.2" PRIfCKFLOAT, obj->GetLightPower()); + + Console::WriteLine(u8"== Switches =="); + Console::FormatLine(u8"Activity: %s", PrintBool(obj->GetActivity()).c_str()); + Console::FormatLine(u8"Specular Flag: %s", PrintBool(obj->GetSpecularFlag()).c_str()); + + Console::WriteLine(u8"== Attenuation =="); + Console::FormatLine(u8"Constant Attenuation: %.2" PRIfCKFLOAT, obj->GetConstantAttenuation()); + Console::FormatLine(u8"Linear Attenuation: %.2" PRIfCKFLOAT, obj->GetLinearAttenuation()); + Console::FormatLine(u8"Quadratic Attenuation: %.2" PRIfCKFLOAT, obj->GetQuadraticAttenuation()); + + Console::WriteLine(u8"== Spot Cone =="); + Console::FormatLine(u8"Range: %.2" PRIfCKFLOAT, obj->GetRange()); + Console::FormatLine(u8"Hot Spot: %.2" PRIfCKFLOAT, obj->GetHotSpot()); + Console::FormatLine(u8"Falloff: %.2" PRIfCKFLOAT, obj->GetFalloff()); + Console::FormatLine(u8"Falloff Shape: %.2" PRIfCKFLOAT, obj->GetFalloffShape()); + + Console::WriteLine(u8"== Target =="); + auto thistarget = obj->GetTarget(); + Console::FormatLine(u8"Target Address: %s", PrintPointer(thistarget).c_str()); + if (thistarget != nullptr) + Console::FormatLine(u8"Target Name: %s", PrintCKSTRING(thistarget->GetName()).c_str()); + } + + static void PrintCKTargetLightDetail(LibCmo::CK2::ObjImpls::CKTargetLight* obj) { + PrintCKLightDetail(obj); + Console::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"CKTargetLight")); + Console::WriteLine(YYCC_COLOR_LIGHT_RED(u8"No Data")); + } + + static void PrintCKCameraDetail(LibCmo::CK2::ObjImpls::CKCamera* obj) { + PrintCK3dEntityDetail(obj); + Console::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"CKCamera")); + + Console::WriteLine(u8"== Basics =="); + Console::FormatLine(u8"Projection Type: %s", AccessibleValue::GetEnumName(obj->GetProjectionType(), AccessibleValue::EnumDesc::CK_CAMERA_PROJECTION).c_str()); + Console::FormatLine(u8"Orthographic Zoom: %.2" PRIfCKFLOAT, obj->GetOrthographicZoom()); + Console::FormatLine(u8"Front Plane: %.2" PRIfCKFLOAT, obj->GetFrontPlane()); + Console::FormatLine(u8"Back Plane: %.2" PRIfCKFLOAT, obj->GetBackPlane()); + Console::FormatLine(u8"Fov: %.2" PRIfCKFLOAT, obj->GetFov()); + LibCmo::CKDWORD width, height; + obj->GetAspectRatio(width, height); + Console::FormatLine(u8"Aspect Ratio: %" PRIuCKDWORD " : %" PRIuCKDWORD, width, height); + + Console::WriteLine(u8"== Target =="); + auto thistarget = obj->GetTarget(); + Console::FormatLine(u8"Target Address: %s", PrintPointer(thistarget).c_str()); + if (thistarget != nullptr) + Console::FormatLine(u8"Target Name: %s", PrintCKSTRING(thistarget->GetName()).c_str()); + } + + static void PrintCKTargetCameraDetail(LibCmo::CK2::ObjImpls::CKTargetCamera* obj) { + PrintCKCameraDetail(obj); + Console::WriteLine(YYCC_COLOR_LIGHT_YELLOW(u8"CKTargetCamera")); + Console::WriteLine(YYCC_COLOR_LIGHT_RED(u8"No Data")); + } static void PrintCK3dObjectDetail(LibCmo::CK2::ObjImpls::CK3dObject* obj) { PrintCK3dEntityDetail(obj); @@ -560,6 +624,18 @@ namespace Unvirt::StructFormatter { case LibCmo::CK2::CK_CLASSID::CKCID_3DENTITY: PrintCK3dEntityDetail(static_cast(mobj)); break; + case LibCmo::CK2::CK_CLASSID::CKCID_LIGHT: + PrintCKLightDetail(static_cast(mobj)); + break; + case LibCmo::CK2::CK_CLASSID::CKCID_TARGETLIGHT: + PrintCKTargetLightDetail(static_cast(mobj)); + break; + case LibCmo::CK2::CK_CLASSID::CKCID_CAMERA: + PrintCKCameraDetail(static_cast(mobj)); + break; + case LibCmo::CK2::CK_CLASSID::CKCID_TARGETCAMERA: + PrintCKTargetCameraDetail(static_cast(mobj)); + break; case LibCmo::CK2::CK_CLASSID::CKCID_3DOBJECT: PrintCK3dObjectDetail(static_cast(mobj)); break;