mirror of https://github.com/auygun/kaliber.git
Use final and override appropriately
This commit is contained in:
parent
5ca5ed763a
commit
58cc270e24
|
@ -26,3 +26,4 @@ cd build/android
|
|||
[spirv-reflect](https://github.com/KhronosGroup/SPIRV-Reflect),
|
||||
[vma](https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator),
|
||||
[vulkan-sdk](https://vulkan.lunarg.com)
|
||||
[volk](https://github.com/zeux/volk)
|
||||
|
|
|
@ -18,20 +18,20 @@
|
|||
|
||||
// #define LOAD_TEST
|
||||
|
||||
class Demo : public eng::Game {
|
||||
class Demo final : public eng::Game {
|
||||
public:
|
||||
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);
|
||||
|
||||
|
|
|
@ -27,14 +27,14 @@ class SkyQuad : public eng::Animatable {
|
|||
void Update(float delta_time);
|
||||
|
||||
// Animatable interface.
|
||||
void SetFrame(size_t frame) override {}
|
||||
size_t GetFrame() const override { return 0; }
|
||||
size_t GetNumFrames() const override { return 0; }
|
||||
void SetColor(const base::Vector4f& color) override { nebula_color_ = color; }
|
||||
base::Vector4f GetColor() const override { return nebula_color_; }
|
||||
void SetFrame(size_t frame) final {}
|
||||
size_t GetFrame() const final { return 0; }
|
||||
size_t GetNumFrames() const final { return 0; }
|
||||
void SetColor(const base::Vector4f& color) final { nebula_color_ = color; }
|
||||
base::Vector4f GetColor() const final { return nebula_color_; }
|
||||
|
||||
// Drawable interface.
|
||||
void Draw(float frame_frac) override;
|
||||
void Draw(float frame_frac) final;
|
||||
|
||||
void ContextLost();
|
||||
|
||||
|
|
|
@ -25,17 +25,17 @@ class AudioOboe : public AudioBase {
|
|||
int GetHardwareSampleRate();
|
||||
|
||||
private:
|
||||
class StreamCallback : public oboe::AudioStreamCallback {
|
||||
class StreamCallback final : public oboe::AudioStreamCallback {
|
||||
public:
|
||||
StreamCallback(AudioOboe* audio);
|
||||
~StreamCallback() override;
|
||||
~StreamCallback() final;
|
||||
|
||||
oboe::DataCallbackResult onAudioReady(oboe::AudioStream* oboe_stream,
|
||||
void* audio_data,
|
||||
int32_t num_frames) override;
|
||||
int32_t num_frames) final;
|
||||
|
||||
void onErrorAfterClose(oboe::AudioStream* oboe_stream,
|
||||
oboe::Result error) override;
|
||||
oboe::Result error) final;
|
||||
|
||||
private:
|
||||
AudioOboe* audio_;
|
||||
|
|
|
@ -38,14 +38,14 @@ class GameFactoryBase {
|
|||
};
|
||||
|
||||
template <typename Type>
|
||||
class GameFactory : public GameFactoryBase {
|
||||
class GameFactory final : public GameFactoryBase {
|
||||
public:
|
||||
~GameFactory() override = default;
|
||||
~GameFactory() final = default;
|
||||
|
||||
private:
|
||||
using GameType = Type;
|
||||
|
||||
std::unique_ptr<Game> CreateGame() override {
|
||||
std::unique_ptr<Game> CreateGame() final {
|
||||
return std::make_unique<GameType>();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
#include "base/interpolation.h"
|
||||
#include "base/log.h"
|
||||
#include "base/misc.h"
|
||||
#include "third_party/texture_compressor/texture_compressor.h"
|
||||
#include "engine/engine.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
|
||||
// have to do the same.
|
||||
|
|
|
@ -14,10 +14,10 @@ namespace eng {
|
|||
class Shader;
|
||||
class Texture;
|
||||
|
||||
class ImageQuad : public Animatable {
|
||||
class ImageQuad final : public Animatable {
|
||||
public:
|
||||
ImageQuad();
|
||||
~ImageQuad() override;
|
||||
~ImageQuad() final;
|
||||
|
||||
void Create(const std::string& asset_name,
|
||||
std::array<int, 2> num_frames = {1, 1},
|
||||
|
@ -36,14 +36,14 @@ class ImageQuad : public Animatable {
|
|||
}
|
||||
|
||||
// Animatable interface.
|
||||
void SetFrame(size_t frame) override;
|
||||
size_t GetFrame() const override { return current_frame_; }
|
||||
size_t GetNumFrames() const override;
|
||||
void SetColor(const base::Vector4f& color) override { color_ = color; }
|
||||
base::Vector4f GetColor() const override { return color_; }
|
||||
void SetFrame(size_t frame) final;
|
||||
size_t GetFrame() const final { return current_frame_; }
|
||||
size_t GetNumFrames() const final;
|
||||
void SetColor(const base::Vector4f& color) final { color_ = color; }
|
||||
base::Vector4f GetColor() const final { return color_; }
|
||||
|
||||
// Drawable interface.
|
||||
void Draw(float frame_frac) override;
|
||||
void Draw(float frame_frac) final;
|
||||
|
||||
private:
|
||||
using UniformValue = std::variant<base::Vector2f,
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "base/log.h"
|
||||
#include "third_party/jsoncpp/json.h"
|
||||
#include "engine/engine.h"
|
||||
#include "engine/platform/asset_file.h"
|
||||
#include "third_party/jsoncpp/json.h"
|
||||
|
||||
namespace eng {
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
#include "engine/renderer/opengl/renderer_opengl.h"
|
||||
#include "engine/renderer/vulkan/renderer_vulkan.h"
|
||||
|
||||
#define VULKAN_RENDERER
|
||||
#define USE_VULKAN_RENDERER 1
|
||||
|
||||
using namespace base;
|
||||
|
||||
|
@ -31,7 +31,7 @@ void Platform::InitializeCommon() {
|
|||
throw internal_error;
|
||||
}
|
||||
|
||||
#if defined(VULKAN_RENDERER)
|
||||
#if (USE_VULKAN_RENDERER == 1)
|
||||
renderer_ = std::make_unique<RendererVulkan>();
|
||||
#else
|
||||
renderer_ = std::make_unique<RendererOpenGL>();
|
||||
|
|
|
@ -35,63 +35,60 @@ namespace eng {
|
|||
|
||||
struct RenderCommand;
|
||||
|
||||
class RendererOpenGL : public Renderer {
|
||||
class RendererOpenGL final : public Renderer {
|
||||
public:
|
||||
RendererOpenGL();
|
||||
~RendererOpenGL() override;
|
||||
~RendererOpenGL() final;
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
bool Initialize(ANativeWindow* window) override;
|
||||
bool Initialize(ANativeWindow* window) final;
|
||||
#elif defined(__linux__)
|
||||
bool Initialize(Display* display, Window window) override;
|
||||
bool Initialize(Display* display, Window window) final;
|
||||
#endif
|
||||
|
||||
void Shutdown() override;
|
||||
void Shutdown() final;
|
||||
|
||||
uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) override;
|
||||
void DestroyGeometry(uint64_t resource_id) override;
|
||||
void Draw(uint64_t resource_id) override;
|
||||
uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) final;
|
||||
void DestroyGeometry(uint64_t resource_id) final;
|
||||
void Draw(uint64_t resource_id) final;
|
||||
|
||||
uint64_t CreateTexture() override;
|
||||
void UpdateTexture(uint64_t resource_id,
|
||||
std::unique_ptr<Image> image) override;
|
||||
void DestroyTexture(uint64_t resource_id) override;
|
||||
void ActivateTexture(uint64_t resource_id) override;
|
||||
uint64_t CreateTexture() final;
|
||||
void UpdateTexture(uint64_t resource_id, std::unique_ptr<Image> image) final;
|
||||
void DestroyTexture(uint64_t resource_id) final;
|
||||
void ActivateTexture(uint64_t resource_id) final;
|
||||
|
||||
uint64_t CreateShader(std::unique_ptr<ShaderSource> source,
|
||||
const VertexDescripton& vertex_description,
|
||||
Primitive primitive,
|
||||
bool enable_depth_test) override;
|
||||
void DestroyShader(uint64_t resource_id) override;
|
||||
void ActivateShader(uint64_t resource_id) override;
|
||||
bool enable_depth_test) final;
|
||||
void DestroyShader(uint64_t resource_id) final;
|
||||
void ActivateShader(uint64_t resource_id) final;
|
||||
|
||||
void SetUniform(uint64_t resource_id,
|
||||
const std::string& name,
|
||||
const base::Vector2f& val) override;
|
||||
const base::Vector2f& val) final;
|
||||
void SetUniform(uint64_t resource_id,
|
||||
const std::string& name,
|
||||
const base::Vector3f& val) override;
|
||||
const base::Vector3f& val) final;
|
||||
void SetUniform(uint64_t resource_id,
|
||||
const std::string& name,
|
||||
const base::Vector4f& val) override;
|
||||
const base::Vector4f& val) final;
|
||||
void SetUniform(uint64_t resource_id,
|
||||
const std::string& name,
|
||||
const base::Matrix4f& val) override;
|
||||
const base::Matrix4f& val) final;
|
||||
void SetUniform(uint64_t resource_id,
|
||||
const std::string& name,
|
||||
float val) override;
|
||||
void SetUniform(uint64_t resource_id,
|
||||
const std::string& name,
|
||||
int val) override;
|
||||
void UploadUniforms(uint64_t resource_id) override {}
|
||||
float val) final;
|
||||
void SetUniform(uint64_t resource_id, const std::string& name, int val) final;
|
||||
void UploadUniforms(uint64_t resource_id) final {}
|
||||
|
||||
void PrepareForDrawing() override {}
|
||||
void Present() override;
|
||||
void PrepareForDrawing() final {}
|
||||
void Present() final;
|
||||
|
||||
size_t GetAndResetFPS() override;
|
||||
size_t GetAndResetFPS() final;
|
||||
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
XVisualInfo* GetXVisualInfo(Display* display) override;
|
||||
XVisualInfo* GetXVisualInfo(Display* display) final;
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
|
|
@ -466,13 +466,13 @@ void RendererVulkan::UpdateTexture(uint64_t resource_id,
|
|||
(it->second.width != image->GetWidth() ||
|
||||
it->second.height != image->GetHeight())) {
|
||||
// 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));
|
||||
it->second = {};
|
||||
}
|
||||
|
||||
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(),
|
||||
VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT,
|
||||
VMA_MEMORY_USAGE_GPU_ONLY);
|
||||
|
@ -514,7 +514,7 @@ void RendererVulkan::DestroyTexture(uint64_t resource_id) {
|
|||
if (it == textures_.end())
|
||||
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));
|
||||
textures_.erase(it);
|
||||
}
|
||||
|
@ -1458,7 +1458,7 @@ void RendererVulkan::BufferMemoryBarrier(VkBuffer buffer,
|
|||
&buffer_mem_barrier, 0, nullptr);
|
||||
}
|
||||
|
||||
bool RendererVulkan::CreateTexture(Buffer<VkImage>& image,
|
||||
bool RendererVulkan::AllocateImage(Buffer<VkImage>& image,
|
||||
VkImageView& view,
|
||||
DescSet& desc_set,
|
||||
VkFormat format,
|
||||
|
@ -1575,7 +1575,7 @@ bool RendererVulkan::CreateTexture(Buffer<VkImage>& image,
|
|||
return true;
|
||||
}
|
||||
|
||||
void RendererVulkan::FreeTexture(Buffer<VkImage> image,
|
||||
void RendererVulkan::FreeImage(Buffer<VkImage> image,
|
||||
VkImageView image_view,
|
||||
DescSet desc_set) {
|
||||
frames_[current_frame_].images_to_destroy.push_back(
|
||||
|
|
|
@ -20,63 +20,60 @@ namespace eng {
|
|||
|
||||
class Image;
|
||||
|
||||
class RendererVulkan : public Renderer {
|
||||
class RendererVulkan final : public Renderer {
|
||||
public:
|
||||
RendererVulkan();
|
||||
~RendererVulkan() override;
|
||||
~RendererVulkan() final;
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
bool Initialize(ANativeWindow* window) override;
|
||||
bool Initialize(ANativeWindow* window) final;
|
||||
#elif defined(__linux__)
|
||||
bool Initialize(Display* display, Window window) override;
|
||||
bool Initialize(Display* display, Window window) final;
|
||||
#endif
|
||||
|
||||
void Shutdown() override;
|
||||
void Shutdown() final;
|
||||
|
||||
uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) override;
|
||||
void DestroyGeometry(uint64_t resource_id) override;
|
||||
void Draw(uint64_t resource_id) override;
|
||||
uint64_t CreateGeometry(std::unique_ptr<Mesh> mesh) final;
|
||||
void DestroyGeometry(uint64_t resource_id) final;
|
||||
void Draw(uint64_t resource_id) final;
|
||||
|
||||
uint64_t CreateTexture() override;
|
||||
void UpdateTexture(uint64_t resource_id,
|
||||
std::unique_ptr<Image> image) override;
|
||||
void DestroyTexture(uint64_t resource_id) override;
|
||||
void ActivateTexture(uint64_t resource_id) override;
|
||||
uint64_t CreateTexture() final;
|
||||
void UpdateTexture(uint64_t resource_id, std::unique_ptr<Image> image) final;
|
||||
void DestroyTexture(uint64_t resource_id) final;
|
||||
void ActivateTexture(uint64_t resource_id) final;
|
||||
|
||||
uint64_t CreateShader(std::unique_ptr<ShaderSource> source,
|
||||
const VertexDescripton& vertex_description,
|
||||
Primitive primitive,
|
||||
bool enable_depth_test) override;
|
||||
void DestroyShader(uint64_t resource_id) override;
|
||||
void ActivateShader(uint64_t resource_id) override;
|
||||
bool enable_depth_test) final;
|
||||
void DestroyShader(uint64_t resource_id) final;
|
||||
void ActivateShader(uint64_t resource_id) final;
|
||||
|
||||
void SetUniform(uint64_t resource_id,
|
||||
const std::string& name,
|
||||
const base::Vector2f& val) override;
|
||||
const base::Vector2f& val) final;
|
||||
void SetUniform(uint64_t resource_id,
|
||||
const std::string& name,
|
||||
const base::Vector3f& val) override;
|
||||
const base::Vector3f& val) final;
|
||||
void SetUniform(uint64_t resource_id,
|
||||
const std::string& name,
|
||||
const base::Vector4f& val) override;
|
||||
const base::Vector4f& val) final;
|
||||
void SetUniform(uint64_t resource_id,
|
||||
const std::string& name,
|
||||
const base::Matrix4f& val) override;
|
||||
const base::Matrix4f& val) final;
|
||||
void SetUniform(uint64_t resource_id,
|
||||
const std::string& name,
|
||||
float val) override;
|
||||
void SetUniform(uint64_t resource_id,
|
||||
const std::string& name,
|
||||
int val) override;
|
||||
void UploadUniforms(uint64_t resource_id) override;
|
||||
float val) final;
|
||||
void SetUniform(uint64_t resource_id, const std::string& name, int val) final;
|
||||
void UploadUniforms(uint64_t resource_id) final;
|
||||
|
||||
void PrepareForDrawing() override;
|
||||
void Present() override;
|
||||
void PrepareForDrawing() final;
|
||||
void Present() final;
|
||||
|
||||
size_t GetAndResetFPS() override;
|
||||
size_t GetAndResetFPS() final;
|
||||
|
||||
#if defined(__linux__) && !defined(__ANDROID__)
|
||||
XVisualInfo* GetXVisualInfo(Display* display) override;
|
||||
XVisualInfo* GetXVisualInfo(Display* display) final;
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
@ -224,7 +221,7 @@ class RendererVulkan : public Renderer {
|
|||
VkAccessFlags src_access,
|
||||
VkAccessFlags dst_sccess);
|
||||
|
||||
bool CreateTexture(Buffer<VkImage>& image,
|
||||
bool AllocateImage(Buffer<VkImage>& image,
|
||||
VkImageView& view,
|
||||
DescSet& desc_set,
|
||||
VkFormat format,
|
||||
|
@ -232,7 +229,7 @@ class RendererVulkan : public Renderer {
|
|||
int height,
|
||||
VkImageUsageFlags usage,
|
||||
VmaMemoryUsage mapping);
|
||||
void FreeTexture(Buffer<VkImage> image,
|
||||
void FreeImage(Buffer<VkImage> image,
|
||||
VkImageView image_view,
|
||||
DescSet desc_set);
|
||||
void UpdateImage(VkImage image,
|
||||
|
|
|
@ -5,20 +5,20 @@
|
|||
|
||||
namespace eng {
|
||||
|
||||
class SolidQuad : public Animatable {
|
||||
class SolidQuad final : public Animatable {
|
||||
public:
|
||||
SolidQuad() = default;
|
||||
~SolidQuad() override = default;
|
||||
~SolidQuad() final = default;
|
||||
|
||||
// Animatable interface.
|
||||
void SetFrame(size_t frame) override {}
|
||||
size_t GetFrame() const override { return 0; }
|
||||
size_t GetNumFrames() const override { return 0; }
|
||||
void SetColor(const base::Vector4f& color) override { color_ = color; }
|
||||
base::Vector4f GetColor() const override { return color_; }
|
||||
void SetFrame(size_t frame) final {}
|
||||
size_t GetFrame() const final { return 0; }
|
||||
size_t GetNumFrames() const final { return 0; }
|
||||
void SetColor(const base::Vector4f& color) final { color_ = color; }
|
||||
base::Vector4f GetColor() const final { return color_; }
|
||||
|
||||
// Drawable interface.
|
||||
void Draw(float frame_frac) override;
|
||||
void Draw(float frame_frac) final;
|
||||
|
||||
private:
|
||||
base::Vector4f color_ = {1, 1, 1, 1};
|
||||
|
|
Loading…
Reference in New Issue