<2021SC@SDUSC> 开源游戏引擎 Overload 代码模块分析 之 OvTools(四)—— Utils(上)

2021SC@SDUSC
开源游戏引擎 Overload 代码模块分析 之 OvTools(四)—— Utils(上)

前言

本篇是开源游戏引擎 Overload 模块 OvTools 的第四篇分析,想大致了解 Overload 可前往这篇文章,想看其他相关文章请前往笔者的 Overload 专栏自主选择。

本篇将探究 OvTools 的最后一个小模块:Utils,我们先来大致了解其文件有哪些并计划一下探究进程吧!

Utils 模块概述与探究计划

Utils 模块是多种工具(例如随机数生成、系统调用等)的集合,其包含文件如下:
Utils list1
Utils list2
显然,该小模块包括了 PathParser、Random、ReferenceOrValue、SizeConverter、String、SystemCalls 六个部分。笔者快速浏览了一下代码长度与复杂度,计划分为三篇文章进行探究。本篇我们将先探究前两个部分:PathParser 与 Random

分析

1、PathParser

1.1 PathParser.h

1.1.1 头文件

该文件仅包含了一个 string 头文件,不多赘述:

#include <string>
1.1.2 主体代码

该文件的主体代码是一个 PathParser 类及其函数定义,该类的作用是提供一些工具来获得给出路径的相关信息,代码如下:

class PathParser
	{
   
	public:
		enum class EFileType
		{
   
			UNKNOWN,
			MODEL,
			TEXTURE,
			SHADER,
			MATERIAL,
			SOUND,
			SCENE,
			SCRIPT,
			FONT
		};

		/**
		* Disabled constructor
		*/
		PathParser() = delete;

		/**
		* Returns the windows style version of the given path ('/' replaced by '\')
		* @param p_path
		*/
		static std::string MakeWindowsStyle(const std::string& p_path);

		/**
		* Returns the non-windows style version of the given path ('\' replaced by '/')
		* @param p_path
		*/
		static std::string MakeNonWindowsStyle(const std::string& p_path);

		/**
		* Returns the containing folder of the file or folder identified by the given path
		* @param p_path
		*/
		static std::string GetContainingFolder(const std::string& p_path);

		/**
		* Returns the name of the file or folder identified by the given path
		* @param p_path
		*/
		static std::string GetElementName(const std::string& p_path);

		/**
		* Returns the extension of the file or folder identified by the given path
		* @param p_path
		*/
		static std::string GetExtension(const std::string& p_path);

		/**
		* Convert the EFileType value to a string
		* @param p_fileType
		*/
		static std::string FileTypeToString(EFileType p_fileType);

		/**
		* Returns the file type of the file identified by the given path
		* @param p_path
		*/
		static EFileType GetFileType(const std::string& p_path);
	};

构造函数默认删除,之前的文章已讲述过;其他函数的作用已有英文注释,不多赘述;代码定义了 enum 限定的枚举类变量 EFileType,内含以文件功能分类的文件类型名(如模型 MODEL、纹理 TEXTURE 等),所以函数操作仅能从类内给出的这些值中选择返回。

由此可以看出,该类可以处理判断路径指向文件的功能类型或以需求的方式(例如更改为 Windows 格式等)输出等,具体实现方式让我们看看 PathParser.cpp 文件:

1.2 PathParser.cpp

1.2.1 头文件
#include <algorithm>
#include "OvTools/Utils/PathParser.h"

除了 PathParser.h 外,该文件还包含了 algorithm。该头文件属于 C++ 标准库,能提供多

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值