From 4351d77f73e4c6c5e4b4c86db543863669039334 Mon Sep 17 00:00:00 2001 From: Noel Berry Date: Sat, 20 Mar 2021 22:17:40 -0700 Subject: [PATCH] fixing various clang warnings --- include/blah/input/input.h | 9 ++---- src/containers/str.cpp | 2 +- src/drawing/spritefont.cpp | 2 +- src/graphics/mesh.cpp | 1 + src/images/font.cpp | 40 +++++++++++++++---------- src/input/input.cpp | 7 ++--- src/internal/graphics_backend_d3d11.cpp | 8 +++-- 7 files changed, 38 insertions(+), 31 deletions(-) diff --git a/include/blah/input/input.h b/include/blah/input/input.h index 3830e26..1d75d29 100644 --- a/include/blah/input/input.h +++ b/include/blah/input/input.h @@ -2,6 +2,7 @@ #include #include +#include // These are generally copied from the SDL2 Scancode Keys #define BLAH_KEY_DEFINITIONS \ @@ -255,12 +256,6 @@ namespace Blah // maximum number of keys the input will track constexpr int max_keyboard_keys = 512; - - // maximum length of text input that can be received per-frame - constexpr int max_text_input = 256; - - // maximum number of nodes within a virtual input device - constexpr int max_virtual_nodes = 32; } struct ControllerState @@ -314,7 +309,7 @@ namespace Blah bool down[Input::max_keyboard_keys]; bool released[Input::max_keyboard_keys]; u64 timestamp[Input::max_keyboard_keys]; - char text[Input::max_text_input]; + String text; }; struct MouseState diff --git a/src/containers/str.cpp b/src/containers/str.cpp index 74de5c5..da7929e 100644 --- a/src/containers/str.cpp +++ b/src/containers/str.cpp @@ -44,7 +44,7 @@ void Str::reserve(int size) { char* local = data(); m_buffer = new char[m_capacity]; - strncpy(m_buffer, local, m_local_size); + memcpy(m_buffer, local, m_local_size); m_buffer[m_local_size] = '\0'; } // expand from empty buffer diff --git a/src/drawing/spritefont.cpp b/src/drawing/spritefont.cpp index 25ecf86..817036f 100644 --- a/src/drawing/spritefont.cpp +++ b/src/drawing/spritefont.cpp @@ -79,7 +79,7 @@ float SpriteFont::width_of(const String& text) const float width = 0; float line_width = 0; - u32 last; + u32 last = 0; for (int i = 0; i < text.length(); i ++) { if (text[i] == '\n') diff --git a/src/graphics/mesh.cpp b/src/graphics/mesh.cpp index dc7832a..59fe7a1 100644 --- a/src/graphics/mesh.cpp +++ b/src/graphics/mesh.cpp @@ -22,6 +22,7 @@ VertexFormat::VertexFormat(std::initializer_list attributes, in { switch (it.type) { + case VertexType::None: break; case VertexType::Float: stride += 4; break; case VertexType::Float2: stride += 8; break; case VertexType::Float3: stride += 12; break; diff --git a/src/images/font.cpp b/src/images/font.cpp index 3d2a891..a92f571 100644 --- a/src/images/font.cpp +++ b/src/images/font.cpp @@ -5,28 +5,36 @@ using namespace Blah; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunused-function" + #define STBTT_STATIC #define STB_TRUETYPE_IMPLEMENTATION #include "../third_party/stb_truetype.h" -String GetName(stbtt_fontinfo* font, int nameId) +#pragma clang diagnostic pop + +namespace { - int length = 0; + String get_font_name(stbtt_fontinfo* font, int nameId) + { + int length = 0; - // get the name - const u16* ptr = (const u16*)stbtt_GetFontNameStr(font, &length, - STBTT_PLATFORM_ID_MICROSOFT, - STBTT_MS_EID_UNICODE_BMP, - STBTT_MS_LANG_ENGLISH, - nameId); + // get the name + const u16* ptr = (const u16*)stbtt_GetFontNameStr(font, &length, + STBTT_PLATFORM_ID_MICROSOFT, + STBTT_MS_EID_UNICODE_BMP, + STBTT_MS_LANG_ENGLISH, + nameId); - // we want the size in wide chars - length /= 2; + // we want the size in wide chars + length /= 2; - String str; - if (length > 0) - str.append_utf16(ptr, ptr + length, Calc::is_little_endian()); - return str; + String str; + if (length > 0) + str.append_utf16(ptr, ptr + length, Calc::is_little_endian()); + return str; + } } Font::Font() @@ -112,8 +120,8 @@ void Font::load(Stream& stream) m_font = new stbtt_fontinfo(); auto fn = (stbtt_fontinfo*)m_font; stbtt_InitFont(fn, m_data, 0); - m_family_name = GetName(fn, 1); - m_style_name = GetName(fn, 2); + m_family_name = get_font_name(fn, 1); + m_style_name = get_font_name(fn, 2); // properties stbtt_GetFontVMetrics(fn, &m_ascent, &m_descent, &m_line_gap); diff --git a/src/input/input.cpp b/src/input/input.cpp index e8edba0..034f53f 100644 --- a/src/input/input.cpp +++ b/src/input/input.cpp @@ -48,10 +48,9 @@ void InputBackend::frame() g_next_state.mouse.pressed[i] = false; g_next_state.mouse.released[i] = false; } - g_next_state.mouse.wheel = Point::zero; - for (int i = 0; i < Blah::Input::max_text_input; i++) - g_next_state.keyboard.text[i] = 0; + g_next_state.mouse.wheel = Point::zero; + g_next_state.keyboard.text.clear(); for (int i = 0; i < Blah::Input::max_controllers; i++) { @@ -139,7 +138,7 @@ void InputBackend::on_key_up(Key key) void InputBackend::on_text_utf8(const char* text) { - strncat(g_next_state.keyboard.text, text, Blah::Input::max_text_input); + g_next_state.keyboard.text += text; } void InputBackend::on_controller_connect(int index, const char* name, int is_gamepad, int button_count, int axis_count, u16 vendor, u16 product, u16 version) diff --git a/src/internal/graphics_backend_d3d11.cpp b/src/internal/graphics_backend_d3d11.cpp index 38cf389..2663476 100644 --- a/src/internal/graphics_backend_d3d11.cpp +++ b/src/internal/graphics_backend_d3d11.cpp @@ -145,6 +145,7 @@ namespace Blah m_size = width * height * 4; is_depth_stencil = true; break; + case TextureFormat::None: case TextureFormat::Count: break; } @@ -698,7 +699,7 @@ namespace Blah state.last_size = Point(App::draw_width(), App::draw_height()); // Define Swap Chain - DXGI_SWAP_CHAIN_DESC desc = { 0 }; + DXGI_SWAP_CHAIN_DESC desc; desc.BufferDesc.RefreshRate.Numerator = 0; desc.BufferDesc.RefreshRate.Denominator = 1; desc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; @@ -707,8 +708,9 @@ namespace Blah desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; desc.BufferCount = 1; desc.OutputWindow = (HWND)PlatformBackend::d3d11_get_hwnd(); - //desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD; desc.Windowed = true; + desc.Flags = 0; + desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; // Creation Flags UINT flags = D3D11_CREATE_DEVICE_SINGLETHREADED; @@ -1246,6 +1248,8 @@ namespace Blah switch (it.type) { case UniformType::None: break; + case UniformType::Texture2D: break; + case UniformType::Sampler2D: break; case UniformType::Float: size = 1; break; case UniformType::Float2: size = 2; break; case UniformType::Float3: size = 3; break;