CARLA
 
载入中...
搜索中...
未找到
ActorWithRandomEngine.cpp
浏览该文件的文档.
1// Copyright (c) 2017 Computer Vision Center (CVC) at the Universitat Autonoma
2// de Barcelona (UAB).
3//
4// This work is licensed under the terms of the MIT license.
5// For a copy, see <https://opensource.org/licenses/MIT>.
6
7#include "Carla.h"
9
10#include "Util/RandomEngine.h"
11
12// 初始化 AActorWithRandomEngine 对象,并创建一个默认的随机引擎子对象
13AActorWithRandomEngine::AActorWithRandomEngine(const FObjectInitializer& ObjectInitializer) :
14 Super(ObjectInitializer)
15{
16 RandomEngine = CreateDefaultSubobject<URandomEngine>(TEXT("RandomEngine"));
17}
18
19// 确保随机引擎已初始化并设置种子值
20void AActorWithRandomEngine::OnConstruction(const FTransform &Transform)
21{
22 Super::OnConstruction(Transform);
23 check(RandomEngine != nullptr);
25}
26
27#if WITH_EDITOR
28// 编辑器中属性更改后调用:在属性修改后,检查是否需要生成新的随机种子并重新设置随机引擎的种子。
29void AActorWithRandomEngine::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
30{
31 Super::PostEditChangeProperty(PropertyChangedEvent);
32 if (PropertyChangedEvent.Property) {
35 bGenerateRandomSeed = false;
36 }
37 check(RandomEngine != nullptr);
39 }
40}
41#endif // WITH_EDITOR
42
43// 设置随机引擎的种子值
44void AActorWithRandomEngine::SetSeed(const int32 InSeed)
45{
46 check(RandomEngine != nullptr);
47 Seed = InSeed;
48 RandomEngine->Seed(InSeed);
49}
int32 Seed
Seed of the pseudo-random engine.
virtual void OnConstruction(const FTransform &Transform) override
AActorWithRandomEngine(const FObjectInitializer &ObjectInitializer)
bool bGenerateRandomSeed
Set a random seed.
void Seed(int32 InSeed)
播种随机引擎/初始化随机数生成器
static int32 GenerateRandomSeed()
生成一个非确定性随机数种子。