Skip to content

Commit

Permalink
Add clang-tidy recommendations.
Browse files Browse the repository at this point in the history
  • Loading branch information
heinezen committed Oct 22, 2023
1 parent 4168974 commit a99cd80
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 47 deletions.
4 changes: 2 additions & 2 deletions libopenage/gamestate/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class Player {

// players can't be copied to prevent duplicate IDs
Player(const Player &) = delete;
Player(Player &&) = default;
Player(Player &&) = delete;

Player &operator=(const Player &) = delete;
Player &operator=(Player &&) = default;
Player &operator=(Player &&) = delete;

~Player() = default;

Expand Down
55 changes: 28 additions & 27 deletions libopenage/gui/guisys/link/gui_item_link.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2015-2016 the openage authors. See copying.md for legal info.
// Copyright 2015-2023 the openage authors. See copying.md for legal info.

#pragma once

#include <type_traits>
#include <utility>

#include "qtsdl_checked_static_cast.h"

Expand All @@ -22,75 +23,75 @@ class GuiItemLink {
/**
* If the core 'MyClass' has a shell 'MyClassLink' then 'Wrap<MyClass>' must have a 'using Type = MyClassLink'
*/
template<typename U>
template <typename U>
struct Wrap {
};

/**
* If the core 'MyClass' has a shell 'MyClassLink' then 'Unwrap<MyClassLink>' must have a 'using Type = MyClass'
*/
template<typename T>
template <typename T>
struct Unwrap {
};

template<typename T>
typename Unwrap<T>::Type* unwrap(T *t) {
template <typename T>
typename Unwrap<T>::Type *unwrap(T *t) {
return t ? t->template get<typename Unwrap<T>::Type>() : nullptr;
}

template<typename T>
const typename Unwrap<T>::Type* unwrap(const T *t) {
template <typename T>
const typename Unwrap<T>::Type *unwrap(const T *t) {
return t ? t->template get<typename Unwrap<T>::Type>() : nullptr;
}

template<typename U>
const typename Wrap<U>::Type* wrap(const U *u) {
return checked_static_cast<typename Wrap<U>::Type*>(u->gui_link);
template <typename U>
const typename Wrap<U>::Type *wrap(const U *u) {
return checked_static_cast<typename Wrap<U>::Type *>(u->gui_link);
}

/**
* QML singletons should be unwrapped differently because several QML singletons can point to one C++ singleton/object. But not implementing that for now.
*/
class GuiSingletonItem;

template<typename U>
typename Wrap<U>::Type* wrap(U *u, typename std::enable_if<!std::is_base_of<GuiSingletonItem, typename Wrap<U>::Type>::value>::type* = nullptr) {
return u ? checked_static_cast<typename Wrap<U>::Type*>(u->gui_link) : nullptr;
template <typename U>
typename Wrap<U>::Type *wrap(U *u, typename std::enable_if<!std::is_base_of<GuiSingletonItem, typename Wrap<U>::Type>::value>::type * = nullptr) {
return u ? checked_static_cast<typename Wrap<U>::Type *>(u->gui_link) : nullptr;
}

template<typename U>
typename Wrap<U>::Type* wrap(U *u, typename std::enable_if<std::is_base_of<GuiSingletonItem, typename Wrap<U>::Type>::value>::type* = nullptr) {
return u ? checked_static_cast<typename Wrap<U>::Type*>(u->gui_link) : nullptr;
template <typename U>
typename Wrap<U>::Type *wrap(U *u, typename std::enable_if<std::is_base_of<GuiSingletonItem, typename Wrap<U>::Type>::value>::type * = nullptr) {
return u ? checked_static_cast<typename Wrap<U>::Type *>(u->gui_link) : nullptr;
}

template<typename P>
constexpr P&& wrap_if_can(typename std::remove_reference<P>::type&& p) noexcept {
template <typename P>
constexpr P &&wrap_if_can(typename std::remove_reference<P>::type &&p) noexcept {
return std::forward<P>(p);
}

template<typename T>
template <typename T>
T wrap_if_can(typename Unwrap<typename std::remove_pointer<T>::type>::Type *u) {
return wrap(u);
}

template<typename P>
P unwrap_if_can(P& p) {
template <typename P>
P unwrap_if_can(P &p) {
return p;
}

template<typename T, typename Unwrap<T>::Type* = nullptr>
typename Unwrap<T>::Type* unwrap_if_can(T *t) {
template <typename T, typename Unwrap<T>::Type * = nullptr>
typename Unwrap<T>::Type *unwrap_if_can(T *t) {
return unwrap(t);
}

/**
* Checking that callable can be called with given argument types.
*/
struct can_call_test {
template<typename F, typename ... Args>
template <typename F, typename... Args>
static decltype(std::declval<F>()(std::declval<Args>()...), std::true_type()) f(int);

template<typename F, typename ... Args>
template <typename F, typename... Args>
static std::false_type f(...);
};

Expand All @@ -100,7 +101,7 @@ struct can_call_test {
* @tparam F callable
* @tparam A arguments to test against the callable
*/
template<typename F, typename ... Args>
template <typename F, typename... Args>
struct can_call : decltype(can_call_test::f<F, Args...>(0)) {
};

Expand All @@ -113,7 +114,7 @@ struct can_call : decltype(can_call_test::f<F, Args...>(0)) {
* @tparam F callable
* @tparam A arguments to test against the callable
*/
template<typename F, typename ... Args>
template <typename F, typename... Args>
constexpr void static_assert_about_unwrapping() {
static_assert(can_call<F, Args...>{}, "One of possible causes: if you're passing SomethingLink*, then don't forget to #include \"something_link.h\".");
}
Expand Down
8 changes: 6 additions & 2 deletions libopenage/renderer/vulkan/render_target.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
#pragma once

#include <algorithm>
#include <limits>

#include "../renderer.h"
#include <vulkan/vulkan.h>

#include "graphics_device.h"
#include "log/log.h"

#include "renderer/renderer.h"
#include "renderer/vulkan/graphics_device.h"


namespace openage {
Expand Down
40 changes: 25 additions & 15 deletions libopenage/renderer/vulkan/shader_program.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
// Copyright 2017-2018 the openage authors. See copying.md for legal info.
// Copyright 2017-2023 the openage authors. See copying.md for legal info.

#pragma once

#include "../../error/error.h"
#include "../../log/log.h"
#include "error/error.h"
#include "log/log.h"

#include "../resources/shader_source.h"
#include "../shader_program.h"
#include <vulkan/vulkan.h>

#include "renderer/resources/shader_source.h"
#include "renderer/shader_program.h"


namespace openage {
Expand All @@ -15,12 +17,18 @@ namespace vulkan {

static VkShaderStageFlagBits vk_shader_stage(resources::shader_stage_t stage) {
switch (stage) {
case resources::shader_stage_t::vertex: return VK_SHADER_STAGE_VERTEX_BIT;
case resources::shader_stage_t::geometry: return VK_SHADER_STAGE_GEOMETRY_BIT;
case resources::shader_stage_t::tesselation_control: return VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
case resources::shader_stage_t::tesselation_evaluation: return VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
case resources::shader_stage_t::fragment: return VK_SHADER_STAGE_FRAGMENT_BIT;
default: throw Error(MSG(err) << "Unknown shader stage.");
case resources::shader_stage_t::vertex:
return VK_SHADER_STAGE_VERTEX_BIT;
case resources::shader_stage_t::geometry:
return VK_SHADER_STAGE_GEOMETRY_BIT;
case resources::shader_stage_t::tesselation_control:
return VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT;
case resources::shader_stage_t::tesselation_evaluation:
return VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT;
case resources::shader_stage_t::fragment:
return VK_SHADER_STAGE_FRAGMENT_BIT;
default:
throw Error(MSG(err) << "Unknown shader stage.");
}
}

Expand All @@ -29,19 +37,19 @@ class VlkShaderProgram /* final : public ShaderProgram */ {
std::vector<VkShaderModule> modules;
std::vector<VkPipelineShaderStageCreateInfo> pipeline_stage_infos;

explicit VlkShaderProgram(VkDevice dev, std::vector<resources::ShaderSource> const& srcs) {
explicit VlkShaderProgram(VkDevice dev, std::vector<resources::ShaderSource> const &srcs) {
// TODO reflect with spirv-cross
// TODO if glsl, compile to spirv with libshaderc

for (auto const& src : srcs) {
for (auto const &src : srcs) {
if (src.get_lang() != resources::shader_lang_t::spirv) {
throw Error(MSG(err) << "Unsupported shader language in Vulkan shader.");
}

VkShaderModuleCreateInfo cr_shdr = {};
cr_shdr.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
cr_shdr.codeSize = src.get_source().size();
cr_shdr.pCode = reinterpret_cast<uint32_t const*>(src.get_source().data());
cr_shdr.pCode = reinterpret_cast<uint32_t const *>(src.get_source().data());

VkShaderModule mod;
VK_CALL_CHECKED(vkCreateShaderModule, dev, &cr_shdr, nullptr, &mod);
Expand All @@ -61,4 +69,6 @@ class VlkShaderProgram /* final : public ShaderProgram */ {
}
};

}}} // openage::renderer::vulkan
} // namespace vulkan
} // namespace renderer
} // namespace openage
6 changes: 5 additions & 1 deletion libopenage/rng/global_rng.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright 2015-2016 the openage authors. See copying.md for legal info.
// Copyright 2015-2023 the openage authors. See copying.md for legal info.

#pragma once

#include <cstdint>


/** @file
* This file contains functions for the global random number generator.
*
Expand Down

0 comments on commit a99cd80

Please sign in to comment.