Resolve clang-tidy issues & update config

This commit is contained in:
Luke Street 2021-05-27 11:52:05 -04:00
parent 8176f9db38
commit 0910863842
4 changed files with 67 additions and 43 deletions

View File

@ -1 +1,27 @@
Checks: '*,-misc-unused-parameters,-modernize-use-trailing-return-type,-readability-named-parameter,-readability-convert-member-functions-to-static,-readability-uppercase-literal-suffix,-readability-magic-numbers,-hicpp-uppercase-literal-suffix,-hicpp-signed-bitwise,-cppcoreguidelines-avoid-magic-numbers,-cppcoreguidelines-pro-type-static-cast-downcast,-cppcoreguidelines-pro-bounds-constant-array-index,-cppcoreguidelines-owning-memory,-cppcoreguidelines-pro-type-union-access,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cppcoreguidelines-non-private-member-variables-in-classes,-fuchsia-*,-google-runtime-references,-llvmlibc-*,-llvm-header-guard'
Checks: >
*,
-altera-*,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-avoid-non-const-global-variables,
-cppcoreguidelines-owning-memory,
-cppcoreguidelines-pro-bounds-constant-array-index,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-type-reinterpret-cast,
-cppcoreguidelines-pro-type-static-cast-downcast,
-cppcoreguidelines-pro-type-union-access,
-cppcoreguidelines-pro-type-vararg,
-fuchsia-*,
-google-runtime-references,
-hicpp-*,
-llvm-header-guard,
-llvmlibc-*,
-misc-unused-parameters,
-modernize-use-trailing-return-type,
-readability-convert-member-functions-to-static,
-readability-function-cognitive-complexity,
-readability-magic-numbers,
-readability-named-parameter,
-readability-uppercase-literal-suffix,
CheckOptions:
- key: misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic
value: '1'

View File

@ -1,10 +1,10 @@
#include "ImGuiConsole.hpp"
#include "../version.h"
#include "MP1/MP1.hpp"
#include "Runtime/CStateManager.hpp"
#include "Runtime/GameGlobalObjects.hpp"
#include "Runtime/World/CPlayer.hpp"
#include "MP1/MP1.hpp"
#include "../version.h"
#include "ImGuiEngine.hpp"
@ -19,7 +19,7 @@ void ImGuiStringViewText(std::string_view text) { ImGui::TextUnformatted(text.be
void ImGuiTextCenter(std::string_view text) {
ImGui::NewLine();
float fontSize = ImGui::GetFontSize() * text.size() / 2;
float fontSize = ImGui::GetFontSize() * float(text.size()) / 2;
ImGui::SameLine(ImGui::GetWindowSize().x / 2 - fontSize + fontSize / 2);
ImGuiStringViewText(text);
}
@ -34,7 +34,7 @@ static bool ContainsCaseInsensitive(std::string_view str, std::string_view val)
[](char ch1, char ch2) { return std::toupper(ch1) == std::toupper(ch2); }) != str.end();
}
static const std::vector<std::pair<std::string, CAssetId>> ListWorlds() {
static std::vector<std::pair<std::string, CAssetId>> ListWorlds() {
std::vector<std::pair<std::string, CAssetId>> worlds;
for (const auto& pak : g_ResFactory->GetResLoader()->GetPaks()) {
if (!pak->IsWorldPak()) {
@ -61,7 +61,7 @@ static const std::vector<std::pair<std::string, CAssetId>> ListWorlds() {
return worlds;
}
static const std::vector<std::pair<std::string, TAreaId>> ListAreas(CAssetId worldId) {
static std::vector<std::pair<std::string, TAreaId>> ListAreas(CAssetId worldId) {
std::vector<std::pair<std::string, TAreaId>> areas;
const auto& world = dummyWorlds[worldId];
for (int i = 0; i < world->IGetAreaCount(); ++i) {
@ -93,7 +93,7 @@ static void Warp(const CAssetId worldId, TAreaId aId) {
g_StateManager->SetWarping(true);
g_StateManager->SetShouldQuitGame(true);
} else {
// TODO warp from menu?
// TODO(encounter): warp from menu?
}
}
@ -419,10 +419,10 @@ void ImGuiConsole::ShowDebugOverlay() {
ImVec2 windowPos;
ImVec2 windowPosPivot;
constexpr float padding = 10.0f;
windowPos.x = (m_debugOverlayCorner & 1) ? (workPos.x + workSize.x - padding) : (workPos.x + padding);
windowPos.y = (m_debugOverlayCorner & 2) ? (workPos.y + workSize.y - padding) : (workPos.y + padding);
windowPosPivot.x = (m_debugOverlayCorner & 1) ? 1.0f : 0.0f;
windowPosPivot.y = (m_debugOverlayCorner & 2) ? 1.0f : 0.0f;
windowPos.x = (m_debugOverlayCorner & 1) != 0 ? (workPos.x + workSize.x - padding) : (workPos.x + padding);
windowPos.y = (m_debugOverlayCorner & 2) != 0 ? (workPos.y + workSize.y - padding) : (workPos.y + padding);
windowPosPivot.x = (m_debugOverlayCorner & 1) != 0 ? 1.0f : 0.0f;
windowPosPivot.y = (m_debugOverlayCorner & 2) != 0 ? 1.0f : 0.0f;
ImGui::SetNextWindowPos(windowPos, ImGuiCond_Always, windowPosPivot);
windowFlags |= ImGuiWindowFlags_NoMove;
}
@ -446,7 +446,7 @@ void ImGuiConsole::ShowDebugOverlay() {
}
double igt = g_GameState->GetTotalPlayTime();
u32 ms = u64(igt * 1000) % 1000;
auto pt = std::div(igt, 3600);
auto pt = std::div(int(igt), 3600);
ImGuiStringViewText(
fmt::format(FMT_STRING("Play Time: {:02d}:{:02d}:{:02d}.{:03d}\n"), pt.quot, pt.rem / 60, pt.rem % 60, ms));
hasPrevious = true;
@ -511,7 +511,7 @@ void ImGuiConsole::ShowDebugOverlay() {
const auto& layerStates = g_GameState->CurrentWorldState().GetLayerState();
std::string layerBits;
u32 totalActive = 0;
for (u32 i = 0; i < layerStates->GetAreaLayerCount(aId); ++i) {
for (int i = 0; i < layerStates->GetAreaLayerCount(aId); ++i) {
if (layerStates->IsLayerActive(aId, i)) {
++totalActive;
layerBits += "1";

View File

@ -26,12 +26,7 @@ struct ImGuiEntityEntry {
ImGuiEntityEntry(TUniqueId uid, CEntity* ent, std::string_view type, std::string_view name, bool active)
: uid(uid), ent(ent), type(type), name(name), active(active) {}
[[nodiscard]] CActor* AsActor() const {
if (isActor) {
return static_cast<CActor*>(ent);
}
return nullptr;
}
[[nodiscard]] CActor* AsActor() const { return isActor ? static_cast<CActor*>(ent) : nullptr; }
};
class ImGuiConsole {

View File

@ -44,7 +44,7 @@ const char* getClipboardText(void* userData) {
static ImVector<char> ClipboardBuf;
size_t sz = 0;
const auto data = static_cast<boo::IWindow*>(userData)->clipboardPaste(boo::EClipboardType::String, sz);
ClipboardBuf.resize(sz);
ClipboardBuf.resize(int(sz));
strncpy(ClipboardBuf.Data, reinterpret_cast<const char*>(data.get()), sz);
return ClipboardBuf.Data;
}
@ -93,24 +93,27 @@ void ImGuiEngine::Initialize(boo::IGraphicsDataFactory* factory, boo::IWindow* w
io.KeyMap[ImGuiKey_Z] = 'z'; // for text edit CTRL+Z: undo
auto* fontData = new uint8_t[NOTO_MONO_FONT_DECOMPRESSED_SZ];
athena::io::Compression::decompressZlib(NOTO_MONO_FONT, NOTO_MONO_FONT_SZ, fontData, NOTO_MONO_FONT_DECOMPRESSED_SZ);
athena::io::Compression::decompressZlib(static_cast<const atUint8*>(NOTO_MONO_FONT), atUint32(NOTO_MONO_FONT_SZ),
fontData, NOTO_MONO_FONT_DECOMPRESSED_SZ);
int iconWidth = 0, iconHeight = 0;
auto* metaforceIcon = stbi_load_from_memory(METAFORCE_ICON, METAFORCE_ICON_SZ, &iconWidth, &iconHeight, nullptr, 4);
int iconWidth = 0;
int iconHeight = 0;
auto* metaforceIcon = stbi_load_from_memory(static_cast<const stbi_uc*>(METAFORCE_ICON), int(METAFORCE_ICON_SZ),
&iconWidth, &iconHeight, nullptr, 4);
int width = 0;
int height = 0;
unsigned char* pixels = nullptr;
ImFontConfig fontConfig{};
fontConfig.FontData = fontData;
fontConfig.FontDataSize = NOTO_MONO_FONT_DECOMPRESSED_SZ;
fontConfig.FontDataSize = int(NOTO_MONO_FONT_DECOMPRESSED_SZ);
fontConfig.SizePixels = std::floor(14.f * scale);
snprintf(fontConfig.Name, sizeof(fontConfig.Name), "Noto Mono Regular, %dpx",
snprintf(static_cast<char*>(fontConfig.Name), sizeof(fontConfig.Name), "Noto Mono Regular, %dpx",
static_cast<int>(fontConfig.SizePixels));
fontNormal = io.Fonts->AddFont(&fontConfig);
fontConfig.FontDataOwnedByAtlas = false; // first one took ownership
fontConfig.SizePixels = std::floor(24.f * scale);
snprintf(fontConfig.Name, sizeof(fontConfig.Name), "Noto Mono Regular, %dpx",
snprintf(static_cast<char*>(fontConfig.Name), sizeof(fontConfig.Name), "Noto Mono Regular, %dpx",
static_cast<int>(fontConfig.SizePixels));
fontLarge = io.Fonts->AddFont(&fontConfig);
@ -144,30 +147,29 @@ void ImGuiEngine::Shutdown() {
void ImGuiEngine::Begin(float dt, float scale) {
ImGuiIO& io = ImGui::GetIO();
io.DeltaTime = dt;
io.DisplaySize.x = static_cast<float>(WindowRect.size[0]);
io.DisplaySize.y = static_cast<float>(WindowRect.size[1]);
io.DisplaySize.x = float(WindowRect.size[0]);
io.DisplaySize.y = float(WindowRect.size[1]);
io.DisplayFramebufferScale = ImVec2{scale, scale};
if (Input.m_mouseIn) {
io.MousePos = ImVec2{static_cast<float>(Input.m_mousePos.pixel[0]),
static_cast<float>(WindowRect.size[1] - Input.m_mousePos.pixel[1])};
io.MousePos = ImVec2{float(Input.m_mousePos.pixel[0]), float(WindowRect.size[1] - Input.m_mousePos.pixel[1])};
} else {
io.MousePos = ImVec2{-FLT_MAX, -FLT_MAX};
}
memcpy(io.MouseDown, Input.m_mouseButtons.data(), sizeof(io.MouseDown));
float scrollDelta = Input.m_scrollDelta.delta[1] / scale;
float scrollDeltaH = Input.m_scrollDelta.delta[0] / scale;
memcpy(static_cast<bool*>(io.MouseDown), Input.m_mouseButtons.data(), sizeof(io.MouseDown));
float scrollDelta = float(Input.m_scrollDelta.delta[1]) / scale;
float scrollDeltaH = float(Input.m_scrollDelta.delta[0]) / scale;
if (Input.m_scrollDelta.isAccelerated) {
scrollDelta /= 10.f;
scrollDeltaH /= 10.f;
}
io.MouseWheel = static_cast<float>(scrollDelta);
io.MouseWheelH = static_cast<float>(scrollDeltaH);
io.MouseWheel = scrollDelta;
io.MouseWheelH = scrollDeltaH;
Input.m_scrollDelta.zeroOut();
io.KeyCtrl = True(Input.m_modifiers & boo::EModifierKey::Ctrl);
io.KeyShift = True(Input.m_modifiers & boo::EModifierKey::Shift);
io.KeyAlt = True(Input.m_modifiers & boo::EModifierKey::Alt);
io.KeySuper = True(Input.m_modifiers & boo::EModifierKey::Command);
memcpy(io.KeysDown, Input.m_keys.data(), sizeof(io.KeysDown));
memcpy(static_cast<bool*>(io.KeysDown), Input.m_keys.data(), sizeof(io.KeysDown));
for (const auto c : ImGuiEngine::Input.m_charCodes) {
io.AddInputCharacter(c);
@ -310,14 +312,15 @@ void ImGuiEngine::Draw(boo::IGraphicsCommandQueue* gfxQ) {
}
void ImGuiEngine::BuildShaderDataBindings(boo::IGraphicsDataFactory::Context& ctx) {
boo::ObjToken<boo::IGraphicsBuffer> uniforms[] = {UniformBuffer.get()};
boo::PipelineStage unistages[] = {boo::PipelineStage::Vertex};
size_t unioffs[] = {0};
size_t unisizes[] = {sizeof(Uniform)};
std::array<boo::ObjToken<boo::IGraphicsBuffer>, 1> uniforms = {UniformBuffer.get()};
std::array<boo::PipelineStage, uniforms.size()> unistages = {boo::PipelineStage::Vertex};
std::array<size_t, uniforms.size()> unioffs{0};
std::array<size_t, uniforms.size()> unisizes{sizeof(Uniform)};
for (int i = 0; i < ImGuiUserTextureID_MAX; ++i) {
boo::ObjToken<boo::ITexture> texs[] = {Textures[i].get()};
ShaderDataBindings[i] = ctx.newShaderDataBinding(ShaderPipeline, VertexBuffer.get(), nullptr, IndexBuffer.get(), 1,
uniforms, unistages, unioffs, unisizes, 1, texs, nullptr, nullptr);
std::array<boo::ObjToken<boo::ITexture>, 1> texs{Textures[i].get()};
ShaderDataBindings[i] = ctx.newShaderDataBinding(ShaderPipeline, VertexBuffer.get(), nullptr, IndexBuffer.get(),
uniforms.size(), uniforms.data(), unistages.data(), unioffs.data(),
unisizes.data(), texs.size(), texs.data(), nullptr, nullptr);
}
}