From 2d9531d3d70bb938e9b7fd5d21a1860e230c34ec Mon Sep 17 00:00:00 2001 From: Webster Sheets Date: Mon, 31 Aug 2020 21:06:04 -0400 Subject: [PATCH 1/2] Add more profiling points Better profile the startup phase, add profiling to Sound.cpp --- CMakeLists.txt | 15 +++++++++------ src/BaseSphere.cpp | 1 + src/NavLights.cpp | 1 + src/Sfx.cpp | 1 + src/Shields.cpp | 1 + src/galaxy/GalaxyGenerator.cpp | 1 + src/graphics/TextureBuilder.cpp | 7 ++++++- src/gui/Gui.cpp | 1 + src/sound/Sound.cpp | 3 +++ 9 files changed, 24 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ddaf93bed3..4b4a6c06b7d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,14 +53,17 @@ if (CMAKE_COMPILER_IS_GNUCXX) if (NOT IS_TRAVIS) add_compile_options( -fdiagnostics-color - -Wall - -Wextra - -Wno-unused-parameter - -Wno-unused-but-set-parameter - -Wno-implicit-fallthrough ) - endif() + endif() + add_compile_options( + -Wall + -Wextra + -Wno-unused-parameter + -Wno-unused-but-set-parameter + -Wno-implicit-fallthrough + ) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive") + set(CMAKE_CXX_FLAGS_DEBUG "-g -Og") endif (CMAKE_COMPILER_IS_GNUCXX) include(CheckSymbolExists) diff --git a/src/BaseSphere.cpp b/src/BaseSphere.cpp index 8ba2f53dd25..46d626fea80 100644 --- a/src/BaseSphere.cpp +++ b/src/BaseSphere.cpp @@ -18,6 +18,7 @@ BaseSphere::~BaseSphere() {} //static void BaseSphere::Init() { + PROFILE_SCOPED() GeoSphere::Init(); GasGiant::Init(); } diff --git a/src/NavLights.cpp b/src/NavLights.cpp index b3f405b20e4..f0225517824 100644 --- a/src/NavLights.cpp +++ b/src/NavLights.cpp @@ -48,6 +48,7 @@ NavLights::LightBulb::LightBulb(Uint8 _group, Uint8 _mask, Uint8 _color, SceneGr void NavLights::Init(Graphics::Renderer *renderer) { + PROFILE_SCOPED() assert(!g_initted); IniConfig cfg; diff --git a/src/Sfx.cpp b/src/Sfx.cpp index d5f1556091d..34416433d2d 100644 --- a/src/Sfx.cpp +++ b/src/Sfx.cpp @@ -360,6 +360,7 @@ bool SfxManager::SplitMaterialData(const std::string &spec, MaterialData &output void SfxManager::Init(Graphics::Renderer *r) { + PROFILE_SCOPED() IniConfig cfg; // set defaults in case they're missing from the file cfg.SetString("damageFile", "textures/smoke.png"); diff --git a/src/Shields.cpp b/src/Shields.cpp index 4585fa4ed45..4baf85c7464 100644 --- a/src/Shields.cpp +++ b/src/Shields.cpp @@ -73,6 +73,7 @@ Shields::Hits::Hits(const vector3d &_pos, const Uint32 _start, const Uint32 _end void Shields::Init(Graphics::Renderer *renderer) { + PROFILE_SCOPED() assert(!s_initialised); // create our global shield material diff --git a/src/galaxy/GalaxyGenerator.cpp b/src/galaxy/GalaxyGenerator.cpp index 4f57b68472b..be13d522e95 100644 --- a/src/galaxy/GalaxyGenerator.cpp +++ b/src/galaxy/GalaxyGenerator.cpp @@ -19,6 +19,7 @@ RefCountedPtr GalaxyGenerator::s_galaxy; //static void GalaxyGenerator::Init(const std::string &name, Version version) { + PROFILE_SCOPED() s_defaultGenerator = name; s_defaultVersion = (version == LAST_VERSION) ? GetLastVersion(name) : version; GalaxyGenerator::Create(); // This will set s_galaxy diff --git a/src/graphics/TextureBuilder.cpp b/src/graphics/TextureBuilder.cpp index 93e38ed81f4..3bd6ae56e43 100644 --- a/src/graphics/TextureBuilder.cpp +++ b/src/graphics/TextureBuilder.cpp @@ -3,6 +3,7 @@ #include "TextureBuilder.h" #include "FileSystem.h" +#include "profiler/Profiler.h" #include "utils.h" #include #include @@ -140,7 +141,9 @@ namespace Graphics { } TextureFormat targetTextureFormat; - unsigned int virtualWidth, actualWidth, virtualHeight, actualHeight, numberOfMipMaps = 0, numberOfImages = 1; + // initialize actualWidth to 1 to avoid divide-by-zero in case we fail to set the values somehow + uint32_t virtualWidth = 0, actualWidth = 1, virtualHeight = 0, actualHeight = 1; + uint32_t numberOfMipMaps = 0, numberOfImages = 1; if (m_surface) { SDL_PixelFormat *targetPixelFormat; bool needConvert = !GetTargetFormat(m_surface->format, &targetTextureFormat, &targetPixelFormat, m_forceRGBA); @@ -265,6 +268,7 @@ namespace Graphics { void TextureBuilder::LoadSurface() { + PROFILE_SCOPED() assert(!m_surface); SDLSurfacePtr s; @@ -286,6 +290,7 @@ namespace Graphics { void TextureBuilder::LoadDDS() { + PROFILE_SCOPED() assert(!m_surface); assert(!m_dds.headerdone_); if(m_textureType != TEXTURE_2D_ARRAY) diff --git a/src/gui/Gui.cpp b/src/gui/Gui.cpp index 96699546722..996eecbe8d5 100644 --- a/src/gui/Gui.cpp +++ b/src/gui/Gui.cpp @@ -115,6 +115,7 @@ namespace Gui { void Init(Graphics::Renderer *renderer, int screen_width, int screen_height, int ui_width, int ui_height) { + PROFILE_SCOPED() Screen::Init(renderer, screen_width, screen_height, ui_width, ui_height); } diff --git a/src/sound/Sound.cpp b/src/sound/Sound.cpp index 7321cb39f7d..1e16de6b285 100644 --- a/src/sound/Sound.cpp +++ b/src/sound/Sound.cpp @@ -470,6 +470,7 @@ namespace Sound { static void load_sound(const std::string &basename, const std::string &path, bool is_music) { + PROFILE_SCOPED() if (!ends_with_ci(basename, ".ogg")) return; Sample sample; @@ -538,6 +539,7 @@ namespace Sound { bool Init(bool automaticallyOpenDevice) { + PROFILE_SCOPED() if (m_audioDevice) { DestroyAllEvents(); return true; @@ -633,6 +635,7 @@ namespace Sound { void UpdateAudioDevices() { + PROFILE_SCOPED() audioDeviceNames.clear(); for (int idx = 0; idx < SDL_GetNumAudioDevices(0); idx++) { const char *name = SDL_GetAudioDeviceName(idx, 0); From 753b36a9b2271fe0dacd1a2c951edbeae4c6f27f Mon Sep 17 00:00:00 2001 From: Webster Sheets Date: Mon, 31 Aug 2020 22:03:42 -0400 Subject: [PATCH 2/2] Apply clang-format changes --- src/BaseSphere.cpp | 2 +- src/galaxy/GalaxyGenerator.cpp | 2 +- src/graphics/TextureBuilder.cpp | 79 ++++++++++++++++----------------- src/gui/Gui.cpp | 2 +- 4 files changed, 41 insertions(+), 44 deletions(-) diff --git a/src/BaseSphere.cpp b/src/BaseSphere.cpp index 46d626fea80..a1efc28293f 100644 --- a/src/BaseSphere.cpp +++ b/src/BaseSphere.cpp @@ -6,8 +6,8 @@ #include "GasGiant.h" #include "GeoSphere.h" -#include "graphics/Renderer.h" #include "graphics/Drawables.h" +#include "graphics/Renderer.h" BaseSphere::BaseSphere(const SystemBody *body) : m_sbody(body), diff --git a/src/galaxy/GalaxyGenerator.cpp b/src/galaxy/GalaxyGenerator.cpp index be13d522e95..61049e4545c 100644 --- a/src/galaxy/GalaxyGenerator.cpp +++ b/src/galaxy/GalaxyGenerator.cpp @@ -122,7 +122,7 @@ void GalaxyGenerator::ToJson(Json &jsonObj, RefCountedPtr galaxy) sysgen->ToJson(starSystemStageArrayEl, galaxy); starSystemStageArray.push_back(starSystemStageArrayEl); // Append system stage object to array. } - galaxyGenObj["sector_stage"] = sectorStageArray; // Add sector stage array to galaxy generator object. + galaxyGenObj["sector_stage"] = sectorStageArray; // Add sector stage array to galaxy generator object. galaxyGenObj["star_system_stage"] = starSystemStageArray; // Add system stage array to galaxy generator object. jsonObj["galaxy_generator"] = galaxyGenObj; // Add galaxy generator object to supplied object. diff --git a/src/graphics/TextureBuilder.cpp b/src/graphics/TextureBuilder.cpp index 3bd6ae56e43..ecb0d378f21 100644 --- a/src/graphics/TextureBuilder.cpp +++ b/src/graphics/TextureBuilder.cpp @@ -7,8 +7,8 @@ #include "utils.h" #include #include -#include #include +#include namespace Graphics { @@ -73,29 +73,29 @@ namespace Graphics { #error "SDL surface pixel formats are endian-specific" #endif static SDL_PixelFormat pixelFormatRGBA = { - 0, // format# - 0, // palette - 32, // bits per pixel - 4, // bytes per pixel - { 0, 0 }, // padding + 0, // format# + 0, // palette + 32, // bits per pixel + 4, // bytes per pixel + { 0, 0 }, // padding 0xff, 0xff00, 0xff0000, 0xff000000, // RGBA mask - 0, 0, 0, 0, // RGBA loss - 24, 16, 8, 0, // RGBA shift - 0, // colour key - 0 // alpha + 0, 0, 0, 0, // RGBA loss + 24, 16, 8, 0, // RGBA shift + 0, // colour key + 0 // alpha }; static SDL_PixelFormat pixelFormatRGB = { - 0, // format# - 0, // palette - 24, // bits per pixel - 3, // bytes per pixel - { 0, 0 }, // padding + 0, // format# + 0, // palette + 24, // bits per pixel + 3, // bytes per pixel + { 0, 0 }, // padding 0xff, 0xff00, 0xff0000, 0, // RGBA mask - 0, 0, 0, 0, // RGBA loss - 16, 8, 0, 0, // RGBA shift - 0, // colour key - 0 // alpha + 0, 0, 0, 0, // RGBA loss + 16, 8, 0, 0, // RGBA shift + 0, // colour key + 0 // alpha }; static inline bool GetTargetFormat(const SDL_PixelFormat *sourcePixelFormat, TextureFormat *targetTextureFormat, SDL_PixelFormat **targetPixelFormat, bool forceRGBA) @@ -201,7 +201,7 @@ namespace Graphics { Output("WARNING: texture '%s' is not power-of-two and may not display correctly\n", m_filenames.front().c_str()); } } else { - if(m_textureType != TEXTURE_2D_ARRAY) { + if (m_textureType != TEXTURE_2D_ARRAY) { switch (m_dds.GetTextureFormat()) { case PicoDDS::FORMAT_DXT1: targetTextureFormat = TEXTURE_DXT1; break; case PicoDDS::FORMAT_DXT5: targetTextureFormat = TEXTURE_DXT5; break; @@ -219,10 +219,10 @@ namespace Graphics { // Cube map must be fully defined (6 images) to be used correctly assert(numberOfImages == 6); } - } else if(m_textureType == TEXTURE_2D_ARRAY) { + } else if (m_textureType == TEXTURE_2D_ARRAY) { assert(m_ddsarray.size() == m_layers); - assert(m_layers>0); - switch(m_ddsarray[0].GetTextureFormat()) { + assert(m_layers > 0); + switch (m_ddsarray[0].GetTextureFormat()) { case PicoDDS::FORMAT_DXT1: targetTextureFormat = TEXTURE_DXT1; break; case PicoDDS::FORMAT_DXT5: targetTextureFormat = TEXTURE_DXT5; break; default: @@ -230,14 +230,14 @@ namespace Graphics { assert(false); return; } - for(size_t i=0; iGetDescriptor().type == TEXTURE_2D && m_textureType == TEXTURE_2D) { - texture->Update(m_surface->pixels, vector3f(m_surface->w,m_surface->h,0.0f), m_descriptor.format, 0); + texture->Update(m_surface->pixels, vector3f(m_surface->w, m_surface->h, 0.0f), m_descriptor.format, 0); } else if (texture->GetDescriptor().type == TEXTURE_CUBE_MAP && m_textureType == TEXTURE_CUBE_MAP) { assert(m_cubemap.size() == 6); TextureCubeData tcd; @@ -329,16 +326,16 @@ namespace Graphics { tcd.negY = m_cubemap[3]->pixels; tcd.posZ = m_cubemap[4]->pixels; tcd.negZ = m_cubemap[5]->pixels; - texture->Update(tcd, vector3f(m_cubemap[0]->w, m_cubemap[0]->h,0.0f), m_descriptor.format, 0); + texture->Update(tcd, vector3f(m_cubemap[0]->w, m_cubemap[0]->h, 0.0f), m_descriptor.format, 0); } else { // Given texture and current texture don't have the same type! assert(0); } - } else if( m_dds.headerdone_ ) { + } else if (m_dds.headerdone_) { assert(m_dds.headerdone_); assert(m_descriptor.format == TEXTURE_DXT1 || m_descriptor.format == TEXTURE_DXT5); if (texture->GetDescriptor().type == TEXTURE_2D && m_textureType == TEXTURE_2D) { - texture->Update(m_dds.imgdata_.imgData, vector3f(m_dds.imgdata_.width,m_dds.imgdata_.height,0.0f), m_descriptor.format, m_dds.imgdata_.numMipMaps); + texture->Update(m_dds.imgdata_.imgData, vector3f(m_dds.imgdata_.width, m_dds.imgdata_.height, 0.0f), m_descriptor.format, m_dds.imgdata_.numMipMaps); } else if (texture->GetDescriptor().type == TEXTURE_CUBE_MAP && m_textureType == TEXTURE_CUBE_MAP) { TextureCubeData tcd; // Size in bytes of each cube map face @@ -350,20 +347,20 @@ namespace Graphics { tcd.negY = static_cast(m_dds.imgdata_.imgData + (3 * face_size)); tcd.posZ = static_cast(m_dds.imgdata_.imgData + (4 * face_size)); tcd.negZ = static_cast(m_dds.imgdata_.imgData + (5 * face_size)); - texture->Update(tcd, vector3f(m_dds.imgdata_.width, m_dds.imgdata_.height,0.0f), m_descriptor.format, m_dds.imgdata_.numMipMaps); + texture->Update(tcd, vector3f(m_dds.imgdata_.width, m_dds.imgdata_.height, 0.0f), m_descriptor.format, m_dds.imgdata_.numMipMaps); } else { // Given texture and current texture don't have the same type! assert(0); } - } else if( !m_ddsarray.empty() ) { + } else if (!m_ddsarray.empty()) { // texture array assert(m_textureType == TEXTURE_2D_ARRAY); const TextureDescriptor &desc = texture->GetDescriptor(); // virtual void Update(const vecDataPtr &data, const vector3f &dataSize, const TextureFormat format, const unsigned int numMips = 0) = 0; Texture::vecDataPtr dataPtrs; dataPtrs.reserve(m_layers); - for(size_t i=0; iUpdate(dataPtrs, desc.dataSize, desc.format, desc.numberOfMipMaps); } diff --git a/src/gui/Gui.cpp b/src/gui/Gui.cpp index 996eecbe8d5..86592fd699c 100644 --- a/src/gui/Gui.cpp +++ b/src/gui/Gui.cpp @@ -3,8 +3,8 @@ #include "Gui.h" #include "graphics/Graphics.h" -#include "graphics/Renderer.h" #include "graphics/RenderState.h" +#include "graphics/Renderer.h" #include "libs.h" namespace Gui {