Enable extra warnings for all but third-party

This commit is contained in:
Attila Uygun 2023-05-04 23:21:32 +02:00
parent 653c283758
commit 4bab472ed1
12 changed files with 4749 additions and 4705 deletions

View File

@ -32,8 +32,8 @@ LDFLAGS = -lX11 -lGL -pthread -lasound -ldl
# Always enable debug information.
CFLAGS += -g
# Make all warnings into errors.
CFLAGS += -Werror
# Enable extra warnings and make all warnings into errors.
CFLAGS += -Wextra -Werror
# Flags to generate dependency information.
CFLAGS += -MD -MP -MT $@
@ -75,15 +75,26 @@ app_exe = $(OUTPUT_DIR)/$(1)_$(ARCH)_$(BUILD)
objs_from_src = $(patsubst $(SRC_ROOT)/%, $(BUILD_DIR)/%.o, $(basename $(1)))
objs_from_src_in = $(call objs_from_src, $(shell find $(1) -name "*.cc" -o -name "*.cpp" -o -name "*.c"))
# --- Engine ---
# --- Base ---
ENGINE_SRC := \
BASE_SRC := \
$(SRC_ROOT)/base/collusion_test.cc \
$(SRC_ROOT)/base/log.cc \
$(SRC_ROOT)/base/sinc_resampler.cc \
$(SRC_ROOT)/base/task_runner.cc \
$(SRC_ROOT)/base/thread_pool.cc \
$(SRC_ROOT)/base/timer.cc \
$(SRC_ROOT)/base/timer.cc
BASE_LIB := $(BUILD_DIR)/libengine.a
BASE_OBJS := $(call objs_from_src, $(BASE_SRC))
LIBS += $(BASE_LIB)
OBJS += $(BASE_OBJS)
$(BASE_LIB): $(BASE_OBJS)
# --- Engine ---
ENGINE_SRC := \
$(SRC_ROOT)/engine/animatable.cc \
$(SRC_ROOT)/engine/animator.cc \
$(SRC_ROOT)/engine/audio/audio_alsa.cc \
@ -113,7 +124,25 @@ ENGINE_SRC := \
$(SRC_ROOT)/engine/shader_source.cc \
$(SRC_ROOT)/engine/solid_quad.cc \
$(SRC_ROOT)/engine/sound_player.cc \
$(SRC_ROOT)/engine/sound.cc \
$(SRC_ROOT)/engine/sound.cc
ENGINE_LIB := $(BUILD_DIR)/libengine.a
ENGINE_OBJS := $(call objs_from_src, $(ENGINE_SRC))
LIBS += $(ENGINE_LIB)
OBJS += $(ENGINE_OBJS)
$(ENGINE_LIB): $(ENGINE_OBJS)
# --- Third-party ---
# Ignore warnings.
THIRD_PARTY_CFLAGS = $(CFLAGS)
THIRD_PARTY_CFLAGS := $(filter-out -Wextra -Werror, $(THIRD_PARTY_CFLAGS))
THIRD_PARTY_CXXFLAGS = $(CXXFLAGS)
THIRD_PARTY_CXXFLAGS := $(filter-out -Wextra -Werror, $(THIRD_PARTY_CXXFLAGS))
THIRD_PARTY_SRC := \
$(SRC_ROOT)/third_party/glew/glew.c \
$(SRC_ROOT)/third_party/glslang/glslang/CInterface/glslang_c_interface.cpp \
$(SRC_ROOT)/third_party/glslang/glslang/GenericCodeGen/CodeGen.cpp \
@ -160,6 +189,7 @@ ENGINE_SRC := \
$(SRC_ROOT)/third_party/glslang/StandAlone/ResourceLimits.cpp \
$(SRC_ROOT)/third_party/jsoncpp/jsoncpp.cpp \
$(SRC_ROOT)/third_party/spirv-reflect/spirv_reflect.c \
$(SRC_ROOT)/third_party/stb/stb_image.c \
$(SRC_ROOT)/third_party/texture_compressor/dxt_encoder_internals.cc \
$(SRC_ROOT)/third_party/texture_compressor/dxt_encoder.cc \
$(SRC_ROOT)/third_party/texture_compressor/texture_compressor_etc1.cc \
@ -176,12 +206,24 @@ ENGINE_SRC := \
$(SRC_ROOT)/third_party/vulkan/loader/unknown_ext_chain.c \
$(SRC_ROOT)/third_party/vulkan/loader/wsi.c
ENGINE_LIB := $(BUILD_DIR)/libengine.a
ENGINE_OBJS := $(call objs_from_src, $(ENGINE_SRC))
LIBS += $(ENGINE_LIB)
OBJS += $(ENGINE_OBJS)
$(BUILD_DIR)/third_party/%.o: $(SRC_ROOT)/third_party/%.c
@mkdir -p $(@D)
$(HUSH_COMPILE) $(CC) -c $(THIRD_PARTY_CFLAGS) -o $@ $<
$(ENGINE_LIB): $(ENGINE_OBJS)
$(BUILD_DIR)/third_party/%.o: $(SRC_ROOT)/third_party/%.cc
@mkdir -p $(@D)
$(HUSH_COMPILE) $(CXX) -c $(THIRD_PARTY_CXXFLAGS) -o $@ $<
$(BUILD_DIR)/third_party/%.o: $(SRC_ROOT)/third_party/%.cpp
@mkdir -p $(@D)
$(HUSH_COMPILE) $(CXX) -c $(THIRD_PARTY_CXXFLAGS) -o $@ $<
THIRD_PARTY_LIB := $(BUILD_DIR)/libthirdparty.a
THIRD_PARTY_OBJS := $(call objs_from_src, $(THIRD_PARTY_SRC))
LIBS += $(THIRD_PARTY_LIB)
OBJS += $(THIRD_PARTY_OBJS)
$(THIRD_PARTY_LIB): $(THIRD_PARTY_OBJS)
# --- demo application ---

View File

@ -127,7 +127,7 @@ class Menu {
Button toggle_music_;
Button toggle_vibration_;
int high_score_value_ = 0;
size_t high_score_value_ = 0;
eng::ImageQuad high_score_;
eng::Animator high_score_animator_;

View File

@ -206,7 +206,7 @@ class Engine {
PersistentData replay_data_;
bool recording_ = false;
bool replaying_ = false;
int replay_index_ = 0;
unsigned int replay_index_ = 0;
base::Randomf random_;

View File

@ -120,8 +120,8 @@ bool Image::CreateMip(const Image& other) {
} else {
const uint32_t* s = reinterpret_cast<const uint32_t*>(other.buffer_.get());
uint32_t* d = reinterpret_cast<uint32_t*>(buffer_.get());
for (size_t y = 0; y < height_; ++y) {
for (size_t x = 0; x < width_; ++x) {
for (int y = 0; y < height_; ++y) {
for (int x = 0; x < width_; ++x) {
*d++ = Mix4(s[0], s[1], s[other.width_], s[other.width_ + 1]);
s += 2;
}

View File

@ -107,7 +107,7 @@ float ImageQuad::GetFrameHeight() const {
}
// Return the uv offset for the given frame.
Vector2f ImageQuad::GetUVOffset(int frame) const {
Vector2f ImageQuad::GetUVOffset(size_t frame) const {
DCHECK(frame < GetNumFrames())
<< "asset: " << asset_name_ << " frame: " << frame;
return {(float)(frame % num_frames_[0]), (float)(frame / num_frames_[0])};

View File

@ -70,7 +70,7 @@ class ImageQuad : public Animatable {
float GetFrameWidth() const;
float GetFrameHeight() const;
base::Vector2f GetUVOffset(int frame) const;
base::Vector2f GetUVOffset(size_t frame) const;
};
} // namespace eng

View File

@ -106,7 +106,7 @@ bool Mesh::Load(const std::string& file_name) {
vertices_ = std::make_unique<char[]>(vertex_buffer_size);
char* dst = vertices_.get();
int i = 0;
unsigned int i = 0;
while (i < vertices.size()) {
for (auto& attr : vertex_description_) {
auto [attrib_type, data_type, num_elements, type_size] = attr;

View File

@ -619,7 +619,7 @@ void RendererVulkan::ActivateShader(uint64_t resource_id) {
vkCmdBindPipeline(frames_[current_frame_].draw_command_buffer,
VK_PIPELINE_BIND_POINT_GRAPHICS, it->second.pipeline);
}
for (int i = 0; i < it->second.desc_set_count; ++i) {
for (size_t i = 0; i < it->second.desc_set_count; ++i) {
if (active_descriptor_sets_[i] != penging_descriptor_sets_[i]) {
active_descriptor_sets_[i] = penging_descriptor_sets_[i];
vkCmdBindDescriptorSets(frames_[current_frame_].draw_command_buffer,
@ -735,7 +735,7 @@ bool RendererVulkan::InitializeInternal() {
allocator_info.instance = context_.GetInstance();
vmaCreateAllocator(&allocator_info, &allocator_);
for (int i = 0; i < frames_.size(); i++) {
for (size_t i = 0; i < frames_.size(); i++) {
// Create command pool, one per frame is recommended.
VkCommandPoolCreateInfo cmd_pool_info;
cmd_pool_info.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
@ -872,7 +872,7 @@ void RendererVulkan::Shutdown() {
vkDeviceWaitIdle(device_);
for (int i = 0; i < frames_.size(); ++i) {
for (size_t i = 0; i < frames_.size(); ++i) {
FreePendingResources(i);
vkDestroyCommandPool(device_, frames_[i].setup_command_pool, nullptr);
vkDestroyCommandPool(device_, frames_[i].draw_command_pool, nullptr);
@ -1081,7 +1081,7 @@ bool RendererVulkan::AllocateStagingBuffer(uint32_t amount,
FlushSetupBuffer();
// Clear the whole staging buffer.
for (int i = 0; i < staging_buffers_.size(); i++) {
for (size_t i = 0; i < staging_buffers_.size(); i++) {
staging_buffers_[i].frame_used = 0;
staging_buffers_[i].fill_amount = 0;
}
@ -1115,9 +1115,9 @@ bool RendererVulkan::AllocateStagingBuffer(uint32_t amount,
// executed.
vkDeviceWaitIdle(device_);
for (int i = 0; i < staging_buffers_.size(); i++) {
for (size_t i = 0; i < staging_buffers_.size(); i++) {
// Clear all blocks but the ones from this frame.
int block_idx =
size_t block_idx =
(i + current_staging_buffer_) % staging_buffers_.size();
if (staging_buffers_[block_idx].frame_used == frames_drawn_) {
break; // We reached something from this frame, abort.
@ -1621,7 +1621,7 @@ bool RendererVulkan::CreatePipelineLayout(
break;
}
for (int i = 0; i < binding_count; ++i) {
for (size_t i = 0; i < binding_count; ++i) {
const SpvReflectDescriptorBinding& binding = *bindings[i];
DLOG << __func__ << " name: " << binding.name
@ -1735,7 +1735,7 @@ bool RendererVulkan::CreatePipelineLayout(
// Use the same layout for all decriptor sets.
std::vector<VkDescriptorSetLayout> desc_set_layouts;
for (int i = 0; i < binding_count; ++i)
for (size_t i = 0; i < binding_count; ++i)
desc_set_layouts.push_back(descriptor_set_layout_);
VkPipelineLayoutCreateInfo pipeline_layout_create_info;
@ -1884,7 +1884,7 @@ void RendererVulkan::SetupThreadMain(int preallocate) {
task_runner_.SingleConsumerRun();
}
for (int i = 0; i < staging_buffers_.size(); i++) {
for (size_t i = 0; i < staging_buffers_.size(); i++) {
auto [buffer, allocation] = staging_buffers_[i].buffer;
vmaDestroyBuffer(allocator_, buffer, allocation);
}

View File

@ -113,7 +113,7 @@ class RendererVulkan : public Renderer {
std::unique_ptr<char[]> push_constants;
size_t push_constants_size = 0;
std::vector<std::string> sampler_uniform_names;
int desc_set_count = 0;
size_t desc_set_count = 0;
VkPipelineLayout pipeline_layout = VK_NULL_HANDLE;
VkPipeline pipeline = VK_NULL_HANDLE;
};

View File

@ -39,7 +39,7 @@ std::array<std::unique_ptr<T[]>, 2> Deinterleave(size_t num_channels,
// Deinterleave into separate channels.
channels[0] = std::make_unique<T[]>(num_samples);
channels[1] = std::make_unique<T[]>(num_samples);
for (int i = 0, j = 0; i < num_samples * 2; i += 2) {
for (size_t i = 0, j = 0; i < num_samples * 2; i += 2) {
channels[0].get()[j] = static_cast<T>(input_buffer[i]);
channels[1].get()[j++] = static_cast<T>(input_buffer[i + 1]);
}
@ -230,7 +230,7 @@ void Sound::Preprocess(std::unique_ptr<float[]> input_buffer,
} else {
size_t num_resampled_samples = resampler_[0]->ChunkSize();
DCHECK(num_resampled_samples ==
(int)(((float)hw_sample_rate_ / (float)sample_rate_) *
(size_t)(((float)hw_sample_rate_ / (float)sample_rate_) *
samples_per_channel));
if (!back_buffer_[0]) {
@ -243,7 +243,7 @@ void Sound::Preprocess(std::unique_ptr<float[]> input_buffer,
num_samples_back_ = num_resampled_samples;
// Resample to match the system sample rate.
for (int i = 0; i < num_channels_; ++i) {
for (size_t i = 0; i < num_channels_; ++i) {
resampler_[i]->Resample(num_resampled_samples, back_buffer_[i].get(),
[&](int frames, float* destination) {
memcpy(destination, channels[i].get(),

4673
src/third_party/stb/stb_image.c vendored Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff