补强注释
This commit is contained in:
@@ -1,4 +1,9 @@
|
||||
#include "stdafx.h"
|
||||
/**
|
||||
* @file TetrisRenderAssets.cpp
|
||||
* @brief 实现 GDI+ 初始化以及背景图、致谢页图片的加载与缓存。
|
||||
*/
|
||||
|
||||
#include "TetrisRenderInternal.h"
|
||||
#include "TetrisAssets.h"
|
||||
#include <objidl.h>
|
||||
@@ -10,6 +15,8 @@ using namespace Gdiplus;
|
||||
|
||||
/**
|
||||
* @brief 尝试从指定路径加载 GDI+ 位图。
|
||||
* @param path 图片文件路径。
|
||||
* @return 加载成功返回位图指针,失败返回 nullptr。
|
||||
*/
|
||||
static Bitmap* TryLoadBitmap(const std::wstring& path)
|
||||
{
|
||||
@@ -30,6 +37,7 @@ static Bitmap* TryLoadBitmap(const std::wstring& path)
|
||||
|
||||
/**
|
||||
* @brief 确保 GDI+ 已初始化,返回初始化是否成功。
|
||||
* @return GDI+ 可用返回 true,否则返回 false。
|
||||
*/
|
||||
static bool EnsureGdiplusStarted()
|
||||
{
|
||||
@@ -39,6 +47,7 @@ static bool EnsureGdiplusStarted()
|
||||
|
||||
if (!attempted)
|
||||
{
|
||||
// GDI+ 只需要初始化一次,静态标记避免重复启动。
|
||||
attempted = true;
|
||||
GdiplusStartupInput startupInput;
|
||||
started = GdiplusStartup(&gdiplusToken, &startupInput, nullptr) == Ok;
|
||||
@@ -49,6 +58,7 @@ static bool EnsureGdiplusStarted()
|
||||
|
||||
/**
|
||||
* @brief 加载并缓存主背景图片。
|
||||
* @return 成功时返回缓存位图指针,失败时返回 nullptr。
|
||||
*/
|
||||
Bitmap* LoadBackgroundImage()
|
||||
{
|
||||
@@ -69,6 +79,7 @@ Bitmap* LoadBackgroundImage()
|
||||
BuildWorkingDirAssetPath(L"assets\\images\\background.bmp")
|
||||
};
|
||||
|
||||
// 同时支持构建目录运行和项目根目录运行两种启动方式。
|
||||
for (const std::wstring& candidate : candidates)
|
||||
{
|
||||
backgroundImage = TryLoadBitmap(candidate);
|
||||
@@ -85,6 +96,8 @@ Bitmap* LoadBackgroundImage()
|
||||
|
||||
/**
|
||||
* @brief 按序号加载并缓存致谢页图片。
|
||||
* @param index 致谢页图片序号。
|
||||
* @return 成功时返回缓存位图指针,失败或越界时返回 nullptr。
|
||||
*/
|
||||
Bitmap* LoadCreditImage(int index)
|
||||
{
|
||||
@@ -123,6 +136,7 @@ Bitmap* LoadCreditImage(int index)
|
||||
};
|
||||
int candidateCount = (index == 3) ? 8 : 2;
|
||||
|
||||
// 第四张致谢图历史上有多种扩展名,这里保留兼容查找。
|
||||
for (int i = 0; i < candidateCount; i++)
|
||||
{
|
||||
creditImages[index] = TryLoadBitmap(creditExtraCandidates[i]);
|
||||
|
||||
Reference in New Issue
Block a user