Use final and override appropriately

This commit is contained in:
Attila Uygun 2023-05-12 23:22:18 +02:00
parent 5ca5ed763a
commit 58cc270e24
13 changed files with 106 additions and 111 deletions

View File

@ -26,3 +26,4 @@ cd build/android
[spirv-reflect](https://github.com/KhronosGroup/SPIRV-Reflect), [spirv-reflect](https://github.com/KhronosGroup/SPIRV-Reflect),
[vma](https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator), [vma](https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator),
[vulkan-sdk](https://vulkan.lunarg.com) [vulkan-sdk](https://vulkan.lunarg.com)
[volk](https://github.com/zeux/volk)

View File

@ -18,20 +18,20 @@
// #define LOAD_TEST // #define LOAD_TEST
class Demo : public eng::Game { class Demo final : public eng::Game {
public: public:
Demo(); Demo();
~Demo() override; ~Demo() final;
bool Initialize() override; bool Initialize() final;
void Update(float delta_time) override; void Update(float delta_time) final;
void ContextLost() override; void ContextLost() final;
void LostFocus() override; void LostFocus() final;
void GainedFocus(bool from_interstitial_ad) override; void GainedFocus(bool from_interstitial_ad) final;
void AddScore(size_t score); void AddScore(size_t score);

View File

@ -27,14 +27,14 @@ class SkyQuad : public eng::Animatable {
void Update(float delta_time); void Update(float delta_time);
// Animatable interface. // Animatable interface.
void SetFrame(size_t frame) override {} void SetFrame(size_t frame) final {}
size_t GetFrame() const override { return 0; } size_t GetFrame() const final { return 0; }
size_t GetNumFrames() const override { return 0; } size_t GetNumFrames() const final { return 0; }
void SetColor(const base::Vector4f& color) override { nebula_color_ = color; } void SetColor(const base::Vector4f& color) final { nebula_color_ = color; }
base::Vector4f GetColor() const override { return nebula_color_; } base::Vector4f GetColor() const final { return nebula_color_; }
// Drawable interface. // Drawable interface.
void Draw(float frame_frac) override; void Draw(float frame_frac) final;
void ContextLost(); void ContextLost();

View File

@ -25,17 +25,17 @@ class AudioOboe : public AudioBase {
int GetHardwareSampleRate(); int GetHardwareSampleRate();
private: private:
class StreamCallback : public oboe::AudioStreamCallback { class StreamCallback final : public oboe::AudioStreamCallback {
public: public:
StreamCallback(AudioOboe* audio); StreamCallback(AudioOboe* audio);
~StreamCallback() override; ~StreamCallback() final;
oboe::DataCallbackResult onAudioReady(oboe::AudioStream* oboe_stream, oboe::DataCallbackResult onAudioReady(oboe::AudioStream* oboe_stream,
void* audio_data, void* audio_data,
int32_t num_frames) override; int32_t num_frames) final;
void onErrorAfterClose(oboe::AudioStream* oboe_stream, void onErrorAfterClose(oboe::AudioStream* oboe_stream,
oboe::Result error) override; oboe::Result error) final;
private: private:
AudioOboe* audio_; AudioOboe* audio_;

View File

@ -38,14 +38,14 @@ class GameFactoryBase {
}; };
template <typename Type> template <typename Type>
class GameFactory : public GameFactoryBase { class GameFactory final : public GameFactoryBase {
public: public:
~GameFactory() override = default; ~GameFactory() final = default;
private: private:
using GameType = Type; using GameType = Type;
std::unique_ptr<Game> CreateGame() override { std::unique_ptr<Game> CreateGame() final {
return std::make_unique<GameType>(); return std::make_unique<GameType>();
} }
}; };

View File

@ -6,9 +6,9 @@
#include "base/interpolation.h" #include "base/interpolation.h"
#include "base/log.h" #include "base/log.h"
#include "base/misc.h" #include "base/misc.h"
#include "third_party/texture_compressor/texture_compressor.h"
#include "engine/engine.h" #include "engine/engine.h"
#include "engine/platform/asset_file.h" #include "engine/platform/asset_file.h"
#include "third_party/texture_compressor/texture_compressor.h"
// This 3rd party library is written in C and uses malloc, which means that we // This 3rd party library is written in C and uses malloc, which means that we
// have to do the same. // have to do the same.

View File

@ -14,10 +14,10 @@ namespace eng {
class Shader; class Shader;
class Texture; class Texture;
class ImageQuad : public Animatable { class ImageQuad final : public Animatable {
public: public:
ImageQuad(); ImageQuad();
~ImageQuad() override; ~ImageQuad() final;
void Create(const std::string& asset_name, void Create(const std::string& asset_name,
std::array<int, 2> num_frames = {1, 1}, std::array<int, 2> num_frames = {1, 1},
@ -36,14 +36,14 @@ class ImageQuad : public Animatable {
} }
// Animatable interface. // Animatable interface.
void SetFrame(size_t frame) override; void SetFrame(size_t frame) final;
size_t GetFrame() const override { return current_frame_; } size_t GetFrame() const final { return current_frame_; }
size_t GetNumFrames() const override; size_t GetNumFrames() const final;
void SetColor(const base::Vector4f& color) override { color_ = color; } void SetColor(const base::Vector4f& color) final { color_ = color; }
base::Vector4f GetColor() const override { return color_; } base::Vector4f GetColor() const final { return color_; }
// Drawable interface. // Drawable interface.
void Draw(float frame_frac) override; void Draw(float frame_frac) final;
private: private:
using UniformValue = std::variant<base::Vector2f, using UniformValue = std::variant<base::Vector2f,

View File

@ -3,9 +3,9 @@
#include <string.h> #include <string.h>
#include "base/log.h" #include "base/log.h"
#include "third_party/jsoncpp/json.h"
#include "engine/engine.h" #include "engine/engine.h"
#include "engine/platform/asset_file.h" #include "engine/platform/asset_file.h"
#include "third_party/jsoncpp/json.h"
namespace eng { namespace eng {

View File

@ -7,7 +7,7 @@
#include "engine/renderer/opengl/renderer_opengl.h" #include "engine/renderer/opengl/renderer_opengl.h"
#include "engine/renderer/vulkan/renderer_vulkan.h" #include "engine/renderer/vulkan/renderer_vulkan.h"
#define VULKAN_RENDERER #define USE_VULKAN_RENDERER 1
using namespace base; using namespace base;
@ -31,7 +31,7 @@ void Platform::InitializeCommon() {
throw internal_error; throw internal_error;
} }
#if defined(VULKAN_RENDERER) #if (USE_VULKAN_RENDERER == 1)
renderer_ = std::make_unique<RendererVulkan>(); renderer_ = std::make_unique<RendererVulkan>();
#else #else
renderer_ = std::make_unique<RendererOpenGL>(); renderer_ = std::make_unique<RendererOpenGL>();

View File

@ -35,63 +35,60 @@ namespace eng {
struct RenderCommand; struct RenderCommand;
class RendererOpenGL : public Renderer { class RendererOpenGL final : public Renderer {
public: public:
RendererOpenGL(); RendererOpenGL();
~RendererOpenGL() override; ~RendererOpenGL() final;
#if defined(__ANDROID__) #if defined(__ANDROID__)
bool Initialize(ANativeWindow* window) override; bool Initialize(ANativeWindow* window) final;
#elif defined(__linux__) #elif defined(__linux__)
bool Initialize(Display* display, Window window) override; bool Initialize(Display* display, Window window) final;
#endif #endif
void Shutdown() override; void Shutdown() final;
uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) override; uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) final;
void DestroyGeometry(uint64_t resource_id) override; void DestroyGeometry(uint64_t resource_id) final;
void Draw(uint64_t resource_id) override; void Draw(uint64_t resource_id) final;
uint64_t CreateTexture() override; uint64_t CreateTexture() final;
void UpdateTexture(uint64_t resource_id, void UpdateTexture(uint64_t resource_id, std::unique_ptr<Image> image) final;
std::unique_ptr<Image> image) override; void DestroyTexture(uint64_t resource_id) final;
void DestroyTexture(uint64_t resource_id) override; void ActivateTexture(uint64_t resource_id) final;
void ActivateTexture(uint64_t resource_id) override;
uint64_t CreateShader(std::unique_ptr<ShaderSource> source, uint64_t CreateShader(std::unique_ptr<ShaderSource> source,
const VertexDescripton& vertex_description, const VertexDescripton& vertex_description,
Primitive primitive, Primitive primitive,
bool enable_depth_test) override; bool enable_depth_test) final;
void DestroyShader(uint64_t resource_id) override; void DestroyShader(uint64_t resource_id) final;
void ActivateShader(uint64_t resource_id) override; void ActivateShader(uint64_t resource_id) final;
void SetUniform(uint64_t resource_id, void SetUniform(uint64_t resource_id,
const std::string& name, const std::string& name,
const base::Vector2f& val) override; const base::Vector2f& val) final;
void SetUniform(uint64_t resource_id, void SetUniform(uint64_t resource_id,
const std::string& name, const std::string& name,
const base::Vector3f& val) override; const base::Vector3f& val) final;
void SetUniform(uint64_t resource_id, void SetUniform(uint64_t resource_id,
const std::string& name, const std::string& name,
const base::Vector4f& val) override; const base::Vector4f& val) final;
void SetUniform(uint64_t resource_id, void SetUniform(uint64_t resource_id,
const std::string& name, const std::string& name,
const base::Matrix4f& val) override; const base::Matrix4f& val) final;
void SetUniform(uint64_t resource_id, void SetUniform(uint64_t resource_id,
const std::string& name, const std::string& name,
float val) override; float val) final;
void SetUniform(uint64_t resource_id, void SetUniform(uint64_t resource_id, const std::string& name, int val) final;
const std::string& name, void UploadUniforms(uint64_t resource_id) final {}
int val) override;
void UploadUniforms(uint64_t resource_id) override {}
void PrepareForDrawing() override {} void PrepareForDrawing() final {}
void Present() override; void Present() final;
size_t GetAndResetFPS() override; size_t GetAndResetFPS() final;
#if defined(__linux__) && !defined(__ANDROID__) #if defined(__linux__) && !defined(__ANDROID__)
XVisualInfo* GetXVisualInfo(Display* display) override; XVisualInfo* GetXVisualInfo(Display* display) final;
#endif #endif
private: private:

View File

@ -466,13 +466,13 @@ void RendererVulkan::UpdateTexture(uint64_t resource_id,
(it->second.width != image->GetWidth() || (it->second.width != image->GetWidth() ||
it->second.height != image->GetHeight())) { it->second.height != image->GetHeight())) {
// Size mismatch. Recreate the texture. // Size mismatch. Recreate the texture.
FreeTexture(std::move(it->second.image), it->second.view, FreeImage(std::move(it->second.image), it->second.view,
std::move(it->second.desc_set)); std::move(it->second.desc_set));
it->second = {}; it->second = {};
} }
if (it->second.view == VK_NULL_HANDLE) { if (it->second.view == VK_NULL_HANDLE) {
CreateTexture(it->second.image, it->second.view, it->second.desc_set, AllocateImage(it->second.image, it->second.view, it->second.desc_set,
format, image->GetWidth(), image->GetHeight(), format, image->GetWidth(), image->GetHeight(),
VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT, VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
VMA_MEMORY_USAGE_GPU_ONLY); VMA_MEMORY_USAGE_GPU_ONLY);
@ -514,8 +514,8 @@ void RendererVulkan::DestroyTexture(uint64_t resource_id) {
if (it == textures_.end()) if (it == textures_.end())
return; return;
FreeTexture(std::move(it->second.image), it->second.view, FreeImage(std::move(it->second.image), it->second.view,
std::move(it->second.desc_set)); std::move(it->second.desc_set));
textures_.erase(it); textures_.erase(it);
} }
@ -1458,7 +1458,7 @@ void RendererVulkan::BufferMemoryBarrier(VkBuffer buffer,
&buffer_mem_barrier, 0, nullptr); &buffer_mem_barrier, 0, nullptr);
} }
bool RendererVulkan::CreateTexture(Buffer<VkImage>& image, bool RendererVulkan::AllocateImage(Buffer<VkImage>& image,
VkImageView& view, VkImageView& view,
DescSet& desc_set, DescSet& desc_set,
VkFormat format, VkFormat format,
@ -1575,9 +1575,9 @@ bool RendererVulkan::CreateTexture(Buffer<VkImage>& image,
return true; return true;
} }
void RendererVulkan::FreeTexture(Buffer<VkImage> image, void RendererVulkan::FreeImage(Buffer<VkImage> image,
VkImageView image_view, VkImageView image_view,
DescSet desc_set) { DescSet desc_set) {
frames_[current_frame_].images_to_destroy.push_back( frames_[current_frame_].images_to_destroy.push_back(
std::make_tuple(std::move(image), image_view)); std::make_tuple(std::move(image), image_view));
frames_[current_frame_].desc_sets_to_destroy.push_back(std::move(desc_set)); frames_[current_frame_].desc_sets_to_destroy.push_back(std::move(desc_set));

View File

@ -20,63 +20,60 @@ namespace eng {
class Image; class Image;
class RendererVulkan : public Renderer { class RendererVulkan final : public Renderer {
public: public:
RendererVulkan(); RendererVulkan();
~RendererVulkan() override; ~RendererVulkan() final;
#if defined(__ANDROID__) #if defined(__ANDROID__)
bool Initialize(ANativeWindow* window) override; bool Initialize(ANativeWindow* window) final;
#elif defined(__linux__) #elif defined(__linux__)
bool Initialize(Display* display, Window window) override; bool Initialize(Display* display, Window window) final;
#endif #endif
void Shutdown() override; void Shutdown() final;
uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) override; uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) final;
void DestroyGeometry(uint64_t resource_id) override; void DestroyGeometry(uint64_t resource_id) final;
void Draw(uint64_t resource_id) override; void Draw(uint64_t resource_id) final;
uint64_t CreateTexture() override; uint64_t CreateTexture() final;
void UpdateTexture(uint64_t resource_id, void UpdateTexture(uint64_t resource_id, std::unique_ptr<Image> image) final;
std::unique_ptr<Image> image) override; void DestroyTexture(uint64_t resource_id) final;
void DestroyTexture(uint64_t resource_id) override; void ActivateTexture(uint64_t resource_id) final;
void ActivateTexture(uint64_t resource_id) override;
uint64_t CreateShader(std::unique_ptr<ShaderSource> source, uint64_t CreateShader(std::unique_ptr<ShaderSource> source,
const VertexDescripton& vertex_description, const VertexDescripton& vertex_description,
Primitive primitive, Primitive primitive,
bool enable_depth_test) override; bool enable_depth_test) final;
void DestroyShader(uint64_t resource_id) override; void DestroyShader(uint64_t resource_id) final;
void ActivateShader(uint64_t resource_id) override; void ActivateShader(uint64_t resource_id) final;
void SetUniform(uint64_t resource_id, void SetUniform(uint64_t resource_id,
const std::string& name, const std::string& name,
const base::Vector2f& val) override; const base::Vector2f& val) final;
void SetUniform(uint64_t resource_id, void SetUniform(uint64_t resource_id,
const std::string& name, const std::string& name,
const base::Vector3f& val) override; const base::Vector3f& val) final;
void SetUniform(uint64_t resource_id, void SetUniform(uint64_t resource_id,
const std::string& name, const std::string& name,
const base::Vector4f& val) override; const base::Vector4f& val) final;
void SetUniform(uint64_t resource_id, void SetUniform(uint64_t resource_id,
const std::string& name, const std::string& name,
const base::Matrix4f& val) override; const base::Matrix4f& val) final;
void SetUniform(uint64_t resource_id, void SetUniform(uint64_t resource_id,
const std::string& name, const std::string& name,
float val) override; float val) final;
void SetUniform(uint64_t resource_id, void SetUniform(uint64_t resource_id, const std::string& name, int val) final;
const std::string& name, void UploadUniforms(uint64_t resource_id) final;
int val) override;
void UploadUniforms(uint64_t resource_id) override;
void PrepareForDrawing() override; void PrepareForDrawing() final;
void Present() override; void Present() final;
size_t GetAndResetFPS() override; size_t GetAndResetFPS() final;
#if defined(__linux__) && !defined(__ANDROID__) #if defined(__linux__) && !defined(__ANDROID__)
XVisualInfo* GetXVisualInfo(Display* display) override; XVisualInfo* GetXVisualInfo(Display* display) final;
#endif #endif
private: private:
@ -224,7 +221,7 @@ class RendererVulkan : public Renderer {
VkAccessFlags src_access, VkAccessFlags src_access,
VkAccessFlags dst_sccess); VkAccessFlags dst_sccess);
bool CreateTexture(Buffer<VkImage>& image, bool AllocateImage(Buffer<VkImage>& image,
VkImageView& view, VkImageView& view,
DescSet& desc_set, DescSet& desc_set,
VkFormat format, VkFormat format,
@ -232,9 +229,9 @@ class RendererVulkan : public Renderer {
int height, int height,
VkImageUsageFlags usage, VkImageUsageFlags usage,
VmaMemoryUsage mapping); VmaMemoryUsage mapping);
void FreeTexture(Buffer<VkImage> image, void FreeImage(Buffer<VkImage> image,
VkImageView image_view, VkImageView image_view,
DescSet desc_set); DescSet desc_set);
void UpdateImage(VkImage image, void UpdateImage(VkImage image,
VkFormat format, VkFormat format,
const uint8_t* data, const uint8_t* data,

View File

@ -5,20 +5,20 @@
namespace eng { namespace eng {
class SolidQuad : public Animatable { class SolidQuad final : public Animatable {
public: public:
SolidQuad() = default; SolidQuad() = default;
~SolidQuad() override = default; ~SolidQuad() final = default;
// Animatable interface. // Animatable interface.
void SetFrame(size_t frame) override {} void SetFrame(size_t frame) final {}
size_t GetFrame() const override { return 0; } size_t GetFrame() const final { return 0; }
size_t GetNumFrames() const override { return 0; } size_t GetNumFrames() const final { return 0; }
void SetColor(const base::Vector4f& color) override { color_ = color; } void SetColor(const base::Vector4f& color) final { color_ = color; }
base::Vector4f GetColor() const override { return color_; } base::Vector4f GetColor() const final { return color_; }
// Drawable interface. // Drawable interface.
void Draw(float frame_frac) override; void Draw(float frame_frac) final;
private: private:
base::Vector4f color_ = {1, 1, 1, 1}; base::Vector4f color_ = {1, 1, 1, 1};