Make debug checks and prints optional, related to #1

This commit is contained in:
nsubiron 2017-04-04 12:28:41 +02:00
parent 70980119aa
commit 948a10fe27
13 changed files with 38 additions and 32 deletions

View File

@ -11,6 +11,12 @@
DECLARE_LOG_CATEGORY_EXTERN(LogCarla, Log, All);
DECLARE_LOG_CATEGORY_EXTERN(LogCarlaServer, Log, All);
// Options to compile with extra debug options.
#ifdef WITH_EDITOR
// #define CARLA_ROAD_GENERATOR_PRINT_OUT /// @todo #1 Crashes in Linux.
// #define CARLA_SERVER_CHECK_IMAGES
#endif // WITH_EDITOR
class FCarlaModule : public IModuleInterface
{
public:

View File

@ -7,9 +7,9 @@
#include <algorithm>
#ifdef WITH_EDITOR
#ifdef CARLA_ROAD_GENERATOR_PRINT_OUT
#include <sstream>
#endif
#endif // CARLA_ROAD_GENERATOR_PRINT_OUT
// =============================================================================
// -- Constructor and destructor -----------------------------------------------
@ -38,7 +38,7 @@ void ACityMapGenerator::PostEditChangeProperty(FPropertyChangedEvent& PropertyCh
UpdateMap();
}
}
#endif
#endif // WITH_EDITOR
void ACityMapGenerator::UpdateMap() {
UpdateSeeds();
@ -66,10 +66,10 @@ void ACityMapGenerator::GenerateGraph() {
MapSizeY = 5u;
UE_LOG(LogCarla, Warning, TEXT("Map size changed, was too small"));
}
#ifdef WITH_EDITOR
#ifdef CARLA_ROAD_GENERATOR_PRINT_OUT
// Delete the dcel before the new one is created so indices are restored.
Dcel.Reset(nullptr);
#endif // WITH_EDITOR
#endif // CARLA_ROAD_GENERATOR_PRINT_OUT
Dcel = MapGen::GraphGenerator::Generate(MapSizeX, MapSizeY, RoadPlanningSeed);
UE_LOG(LogCarla, Log,
TEXT("Generated DCEL with: { %d vertices, %d half-edges, %d faces }"),
@ -77,7 +77,7 @@ void ACityMapGenerator::GenerateGraph() {
Dcel->CountHalfEdges(),
Dcel->CountFaces());
DcelParser = MakeUnique<MapGen::GraphParser>(*Dcel);
#ifdef WITH_EDITOR
#ifdef CARLA_ROAD_GENERATOR_PRINT_OUT
{ // print the results of the parser.
std::wstringstream sout;
sout << "\nGenerated " << DcelParser->CityAreaCount() << " city areas: ";
@ -100,7 +100,7 @@ void ACityMapGenerator::GenerateGraph() {
}
UE_LOG(LogCarla, Log, TEXT("\n%s"), sout.str().c_str());
}
#endif // WITH_EDITOR
#endif // CARLA_ROAD_GENERATOR_PRINT_OUT
}
void ACityMapGenerator::GenerateRoads() {

View File

@ -38,7 +38,7 @@ protected:
#if WITH_EDITOR
/// Called after a property change in editor.
virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
#endif
#endif // WITH_EDITOR
private:

View File

@ -48,7 +48,7 @@ static void Set(std::vector<carla::Color> &cImage, const TArray<FColor> &BitMap)
// -- Other static methods -----------------------------------------------------
// =============================================================================
#ifdef WITH_EDITOR
#ifdef CARLA_SERVER_CHECK_IMAGES
static bool CheckImage(
const FString &Tag,
@ -76,7 +76,7 @@ static bool CheckImageValidity(const ACarlaPlayerState &Player, const carla::Rew
CheckImage("ImageDepth1", Player.GetImage(CPS::ImageDepth1), Reward.image_depth_1, SizeX, SizeY);
}
#endif // WITH_EDITOR
#endif // CARLA_SERVER_CHECK_IMAGES
// Wait for the scene init to be sent, return false if we need to restart the
// server.
@ -166,9 +166,9 @@ static bool SendReward(
Set(reward->image_depth_1, PlayerState.GetImage(CPS::ImageDepth1).BitMap);
}
}
#ifdef WITH_EDITOR
#ifdef CARLA_SERVER_CHECK_IMAGES
check(CheckImageValidity(PlayerState, *reward));
#endif // WITH_EDITOR
#endif // CARLA_SERVER_CHECK_IMAGES
UE_LOG(LogCarlaServer, Log, TEXT("Sending reward"));
return Server.sendReward(reward.release());
}

View File

@ -52,7 +52,7 @@ void ACityMapMeshHolder::PostEditChangeProperty(FPropertyChangedEvent& PropertyC
UpdateMapScale();
}
}
#endif
#endif // WITH_EDITOR
// =============================================================================
// -- Other protected methods --------------------------------------------------

View File

@ -31,7 +31,7 @@ protected:
#if WITH_EDITOR
/// Clears and updates the instantiators.
virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
#endif
#endif // WITH_EDITOR
// ===========================================================================
// -- Other protected methods ------------------------------------------------

View File

@ -6,9 +6,9 @@
#include <cmath>
#include <map>
#ifdef WITH_EDITOR
#ifdef CARLA_ROAD_GENERATOR_PRINT_OUT
#include <sstream>
#endif // WITH_EDITOR
#endif // CARLA_ROAD_GENERATOR_PRINT_OUT
namespace MapGen {
@ -16,7 +16,7 @@ namespace MapGen {
// -- Local static methods ---------------------------------------------------
// ===========================================================================
#ifdef WITH_EDITOR
#ifdef CARLA_ROAD_GENERATOR_PRINT_OUT
static void ResetIndices() {
GraphNode::ResetIndex();
@ -24,7 +24,7 @@ namespace MapGen {
GraphFace::ResetIndex();
}
#endif // WITH_EDITOR
#endif // CARLA_ROAD_GENERATOR_PRINT_OUT
/// Return the pair {prev, next}, where prev/next is the previous/next edge
/// counterclockwise around edge's source node. I.e., edge's position is in
@ -97,9 +97,9 @@ namespace MapGen {
DoublyConnectedEdgeList::~DoublyConnectedEdgeList()
{
#ifdef WITH_EDITOR
#ifdef CARLA_ROAD_GENERATOR_PRINT_OUT
ResetIndices();
#endif // WITH_EDITOR
#endif // CARLA_ROAD_GENERATOR_PRINT_OUT
}
// ===========================================================================
@ -250,7 +250,7 @@ namespace MapGen {
return std::atan2(static_cast<double>(dir.y), static_cast<double>(dir.x));
}
#ifdef WITH_EDITOR
#ifdef CARLA_ROAD_GENERATOR_PRINT_OUT
void DoublyConnectedEdgeList::PrintToLog() const
{
@ -311,6 +311,6 @@ namespace MapGen {
UE_LOG(LogCarla, Log, TEXT("\n%s"), sout.str().c_str());
}
#endif // WITH_EDITOR
#endif // CARLA_ROAD_GENERATOR_PRINT_OUT
} // namespace MapGen

View File

@ -311,9 +311,9 @@ namespace MapGen {
/// Return the angle [-pi, pi] of the half-edge.
static float GetAngle(const HalfEdge &halfEdge);
#ifdef WITH_EDITOR
#ifdef CARLA_ROAD_GENERATOR_PRINT_OUT
void PrintToLog() const;
#endif
#endif // CARLA_ROAD_GENERATOR_PRINT_OUT
/// @}
// =========================================================================

View File

@ -80,9 +80,9 @@ namespace MapGen {
Graph::Face *face = &*(++graph.GetFaces().begin());
do {
face = splitFace(graph, *face, random);
#ifdef WITH_EDITOR
#ifdef CARLA_ROAD_GENERATOR_PRINT_OUT
graph.PrintToLog();
#endif // WITH_EDITOR
#endif // CARLA_ROAD_GENERATOR_PRINT_OUT
} while (face != nullptr);
}

View File

@ -5,12 +5,12 @@
namespace MapGen {
#ifdef WITH_EDITOR
#ifdef CARLA_ROAD_GENERATOR_PRINT_OUT
template <> uint32 DataIndex<'n'>::NEXT_INDEX = 0u;
template <> uint32 DataIndex<'e'>::NEXT_INDEX = 0u;
template <> uint32 DataIndex<'f'>::NEXT_INDEX = 0u;
#endif // WITH_EDITOR
#endif // CARLA_ROAD_GENERATOR_PRINT_OUT
} // namespace MapGen

View File

@ -8,7 +8,7 @@
namespace MapGen {
#ifdef WITH_EDITOR
#ifdef CARLA_ROAD_GENERATOR_PRINT_OUT
/// For debug only purposes.
template <char C>
@ -37,7 +37,7 @@ namespace MapGen {
# define INHERIT_GRAPH_TYPE_BASE_CLASS(c) : public DataIndex<c>
#else
# define INHERIT_GRAPH_TYPE_BASE_CLASS(c) : private NonCopyable
#endif // WITH_EDITOR
#endif // CARLA_ROAD_GENERATOR_PRINT_OUT
struct GraphNode INHERIT_GRAPH_TYPE_BASE_CLASS('n')
{

View File

@ -59,7 +59,7 @@ void ASceneCaptureCamera::PostActorCreated()
}
}
}
#endif
#endif // WITH_EDITOR
// Sync component with CameraActor frustum settings.
UpdateDrawFrustum();

View File

@ -104,7 +104,7 @@ void ASceneCaptureToDiskCamera::PostActorCreated()
}
}
}
#endif
#endif // WITH_EDITOR
// Sync component with CameraActor frustum settings.
UpdateDrawFrustum();