EnTT文档 - Crash Course: configuration

本文介绍了EnTT库的配置选项,包括如何通过定义特定宏来自定义库的行为,如禁用noexcept、支持原子操作、调整ID类型等。此外,还讨论了如何调整稀疏集的页面大小以优化内存使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Introduction

EnTT doesn’t offer many hooks for customization but it certainly offers
some.

EnTT并没有提供很多定制化的钩子,但它肯定提供了以下功能
一些。

In the vast majority of cases, users will have no interest in changing the
default parameters. For all other cases, the list of possible configurations
with which it’s possible to adjust the behavior of the library at runtime can be
found below.

EnTT并没有提供很多定制化的钩子,但它确实提供了一些。
在绝大多数情况下,用户对改变默认参数没有兴趣。对于所有其他情况,可以在下面的列表中找到可能的配置,通过这些配置可以在运行时调整库的行为。

Definitions

All options are intended as parameters to the compiler (or user-defined macros
within the compilation units, if preferred).

Each parameter can result in internal library definitions. It’s not recommended
to try to also modify these definitions, since there is no guarantee that they
will remain stable over time unlike the options below.

所有的选项都是编译器的参数(如果喜欢的话,也可以在编译单元中由用户定义宏)。
每个参数都可能导致内部库定义。不建议尝试修改这些定义,因为与下面的选项不同,不能保证它们会长期保持稳定。

ENTT_NOEXCEPT

The purpose of this parameter is to suppress the use of noexcept by this
library.

To do this, simply define the variable without assigning any value to it.

这个参数的目的是为了抑制这个库对noexcept的使用。
要做到这一点,只需定义变量,而不给它分配任何值。

ENTT_USE_ATOMIC

In general, EnTT doesn’t offer primitives to support multi-threading. Many of
the features can be split over multiple threads without any explicit control and
the user is the only one who knows if and when a synchronization point is
required.

一般来说,EnTT并没有提供支持多线程的基元。许多功能可以在没有任何显式控制的情况下被分割到多个线程上,只有用户知道是否以及何时需要同步点。

However, some features aren’t easily accessible to users and can be made
thread-safe by means of this definition.

但是,有些功能不容易被用户访问,可以通过这个定义来实现线程安全。

ENTT_ID_TYPE

entt::id_type is directly controlled by this definition and widely used within
the library.

entt::id_type由这个定义直接控制,并在库中广泛使用。

By default, its type is std::uint32_t. However, users can define a different
default type if necessary.

默认情况下,其类型为std::uint32_t。但是,如果需要的话,用户可以定义不同的默认类型

ENTT_PAGE_SIZE

As is known, the ECS module of EnTT is based on sparse sets. What is less
known perhaps is that these are paged to reduce memory consumption in some
corner cases.

众所周知,EnTT的ECS模块是基于稀疏集的。也许鲜为人知的是,在一些角落的情况下,这些都是分页的,以减少内存消耗。

The default size of a page is 32kB but users can adjust it if appropriate. In
all case, the chosen value must be a power of 2.

一个页面的默认大小是32kB,但用户可以根据情况进行调整。在所有情况下,所选的值必须是2的幂

ENTT_ASSERT

For performance reasons, EnTT doesn’t use exceptions or any other control
structures. In fact, it offers many features that result in undefined behavior
if not used correctly.

出于性能的考虑,EnTT不使用异常或任何其他控制结构。事实上,它提供了许多功能,如果不正确使用,会导致未定义的行为。

To get around this, the library relies on a lot of asserts for the purpose of
detecting errors in debug builds. By default, it uses assert internally, but
users are allowed to overwrite its behavior by setting this variable.

为了解决这个问题,该库依靠大量的断言来检测调试构建中的错误。默认情况下,它在内部使用断言,但用户可以通过设置这个变量来覆盖其行为。

ENTT_DISABLE_ASSERT

Assertions may in turn affect performance to an extent when enabled. Whether
ENTT_ASSERT is redefined or not, all asserts can be disabled at once by means
of this definition.

断言在启用后又会在一定程度上影响性能。无论ENTT_ASSERT是否被重新定义,都可以通过这个定义一次性禁用所有的断言。

Note that ENTT_DISABLE_ASSERT takes precedence over the redefinition of
ENTT_ASSERT and is therefore meant to disable all controls no matter what.

请注意,ENTT_DISABLE_ASSERT优先于ENTT_ASSERT的重新定义,因此无论如何都是为了禁用所有控制。

ENTT_NO_ETO

In order to reduce memory consumption and increase performance, empty types are
never stored by the ECS module of EnTT.

为了减少内存消耗并提高性能,EnTT的ECS模块从不存储空类型。

Use this variable to treat these types like all others and therefore to create a
dedicated storage for them.

使用该变量将这些类型与所有其他类型一样对待,从而为它们创建一个专用存储空间。

ENTT_STANDARD_CPP

EnTT mixes non-standard language features with others that are perfectly
compliant to offer some of its functionalities.

EnTT将非标准的语言特性与其他完全符合标准的语言特性混合在一起,以提供其部分功能。

This definition will prevent the library from using non-standard techniques,
that is, functionalities that aren’t fully compliant with the standard C++.

这个定义将防止该库使用非标准技术,也就是不完全符合标准C++的功能。

While there are no known portability issues at the time of this writing, this
should make the library fully portable anyway if needed.

虽然在写这篇文章的时候还没有已知的可移植性问题,但无论如何,如果需要的话,这应该会使该库具有完全的可移植性。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值