CARLA
 
载入中...
搜索中...
未找到
Carla.cpp
浏览该文件的文档.
1// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
2
3#include "Carla.h"
4#include "Developer/Settings/Public/ISettingsModule.h"
5#include "Developer/Settings/Public/ISettingsSection.h"
6#include "Developer/Settings/Public/ISettingsContainer.h"
8
9#define LOCTEXT_NAMESPACE "FCarlaModule"
10
12DEFINE_LOG_CATEGORY(LogCarlaServer);
13
19
21{
22 #if defined(WITH_CHRONO) && PLATFORM_WINDOWS
23 const FString BaseDir = FPaths::Combine(*FPaths::ProjectPluginsDir(), TEXT("Carla"));
24 const FString DllDir = FPaths::Combine(*BaseDir, TEXT("CarlaDependencies"), TEXT("dll"));
25 FString ChronoEngineDll = FPaths::Combine(*DllDir, TEXT("ChronoEngine.dll"));
26 FString ChronoVehicleDll = FPaths::Combine(*DllDir, TEXT("ChronoEngine_vehicle.dll"));
27 FString ChronoModelsDll = FPaths::Combine(*DllDir, TEXT("ChronoModels_vehicle.dll"));
28 FString ChronoRobotDll = FPaths::Combine(*DllDir, TEXT("ChronoModels_robot.dll"));
29 UE_LOG(LogCarla, Log, TEXT("Loading Dlls from: %s"), *DllDir);
30 auto ChronoEngineHandle = FPlatformProcess::GetDllHandle(*ChronoEngineDll);
31 if (!ChronoEngineHandle)
32 {
33 UE_LOG(LogCarla, Warning, TEXT("Error: ChronoEngine.dll could not be loaded"));
34 }
35 auto ChronoVehicleHandle = FPlatformProcess::GetDllHandle(*ChronoVehicleDll);
36 if (!ChronoVehicleHandle)
37 {
38 UE_LOG(LogCarla, Warning, TEXT("Error: ChronoEngine_vehicle.dll could not be loaded"));
39 }
40 auto ChronoModelsHandle = FPlatformProcess::GetDllHandle(*ChronoModelsDll);
41 if (!ChronoModelsHandle)
42 {
43 UE_LOG(LogCarla, Warning, TEXT("Error: ChronoModels_vehicle.dll could not be loaded"));
44 }
45 auto ChronoRobotHandle = FPlatformProcess::GetDllHandle(*ChronoRobotDll);
46 if (!ChronoRobotHandle)
47 {
48 UE_LOG(LogCarla, Warning, TEXT("Error: ChronoModels_robot.dll could not be loaded"));
49 }
50 #endif
51}
52
54{
55 if (UObjectInitialized())
56 {
58 }
59}
60
62{
63 // Registering some settings is just a matter of exposing the default UObject of
64 // your desired class, add here all those settings you want to expose
65 // to your LDs or artists.
66
67 if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
68 {
69 // Create the new category
70 ISettingsContainerPtr SettingsContainer = SettingsModule->GetContainer("Project");
71
72 SettingsContainer->DescribeCategory("CARLASettings",
73 LOCTEXT("RuntimeWDCategoryName", "CARLA Settings"),
74 LOCTEXT("RuntimeWDCategoryDescription", "CARLA plugin settings"));
75
76 // Register the settings
77 ISettingsSectionPtr SettingsSection = SettingsModule->RegisterSettings("Project", "CARLASettings", "General",
78 LOCTEXT("RuntimeGeneralSettingsName", "General"),
79 LOCTEXT("RuntimeGeneralSettingsDescription", "General configuration for the CARLA plugin"),
80 GetMutableDefault<UCarlaSettings>()
81 );
82
83 // Register the save handler to your settings, you might want to use it to
84 // validate those or just act to settings changes.
85 if (SettingsSection.IsValid())
86 {
87 SettingsSection->OnModified().BindRaw(this, &FCarlaModule::HandleSettingsSaved);
88 }
89 }
90}
91
93{
94 // Ensure to unregister all of your registered settings here, hot-reload would
95 // otherwise yield unexpected results.
96
97 if (ISettingsModule* SettingsModule = FModuleManager::GetModulePtr<ISettingsModule>("Settings"))
98 {
99 SettingsModule->UnregisterSettings("Project", "CustomSettings", "General");
100 }
101}
102
104{
105 UCarlaSettings* Settings = GetMutableDefault<UCarlaSettings>();
106 bool ResaveSettings = false;
107
108 // Put any validation code in here and resave the settings in case an invalid
109 // value has been entered
110
111 if (ResaveSettings)
112 {
113 Settings->SaveConfig();
114 }
115
116 return true;
117}
118
119#undef LOCTEXT_NAMESPACE
120
121IMPLEMENT_MODULE(FCarlaModule, Carla)
122
123// =============================================================================
124// -- Implement carla throw_exception ------------------------------------------
125// =============================================================================
126
127#include <compiler/disable-ue4-macros.h>
128#include <carla/Exception.h>
130
131#include <exception>
132
133namespace carla {
134
135 void throw_exception(const std::exception &e) {
136 UE_LOG(LogCarla, Fatal, TEXT("Exception thrown: %s"), UTF8_TO_TCHAR(e.what()));
137 // It should never reach this part.
138 std::terminate();
139 }
140
141} // namespace carla
DEFINE_LOG_CATEGORY(LogCarla)
void RegisterSettings()
Definition Carla.cpp:61
void UnregisterSettings()
Definition Carla.cpp:92
virtual void ShutdownModule() override
Definition Carla.cpp:53
void LoadChronoDll()
Definition Carla.cpp:20
virtual void StartupModule() override
IModuleInterface implementation
Definition Carla.cpp:14
bool HandleSettingsSaved()
Definition Carla.cpp:103
Global settings for CARLA.
This file contains definitions of common data structures used in traffic manager.
Definition Carla.cpp:133
void throw_exception(const std::exception &e)
Definition Carla.cpp:135