Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
Mostly android related
  • Loading branch information
SaschaWillems committed Feb 28, 2025
1 parent 42fc441 commit 1fd4564
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
32 changes: 13 additions & 19 deletions base/vulkanexamplebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ VkResult VulkanExampleBase::createInstance()
#endif

// Enabled requested instance extensions
if (enabledInstanceExtensions.size() > 0)
if (!enabledInstanceExtensions.empty())
{
for (const char * enabledExtension : enabledInstanceExtensions)
{
Expand Down Expand Up @@ -120,7 +120,7 @@ VkResult VulkanExampleBase::createInstance()
instanceExtensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
}

if (instanceExtensions.size() > 0) {
if (!instanceExtensions.empty()) {
instanceCreateInfo.enabledExtensionCount = (uint32_t)instanceExtensions.size();
instanceCreateInfo.ppEnabledExtensionNames = instanceExtensions.data();
}
Expand Down Expand Up @@ -316,7 +316,7 @@ void VulkanExampleBase::renderLoop()

benchmark.run([=] { render(); }, vulkanDevice->properties);
vkDeviceWaitIdle(device);
if (benchmark.filename != "") {
if (!benchmark.filename.empty()) {
benchmark.saveResults();
}
return;
Expand Down Expand Up @@ -344,7 +344,7 @@ void VulkanExampleBase::renderLoop()
}
}
#elif defined(VK_USE_PLATFORM_ANDROID_KHR)
while (1)
while (true)
{
int ident;
int events;
Expand All @@ -353,9 +353,9 @@ void VulkanExampleBase::renderLoop()

focused = true;

while ((ident = ALooper_pollOnce(focused ? 0 : -1, NULL, &events, (void**)&source)) > ALOOPER_POLL_TIMEOUT)
while ((ident = ALooper_pollOnce(focused ? 0 : -1, nullptr, &events, (void**)&source)) > ALOOPER_POLL_TIMEOUT)
{
if (source != NULL)
if (source != nullptr)
{
source->process(androidApp, source);
}
Expand Down Expand Up @@ -404,8 +404,6 @@ void VulkanExampleBase::renderLoop()

updateOverlay();

bool updateView = false;

// Check touch state (for movement)
if (touchDown) {
touchTimer += frameTimer;
Expand All @@ -422,23 +420,20 @@ void VulkanExampleBase::renderLoop()
if (std::abs(gamePadState.axisLeft.x) > deadZone)
{
camera.rotate(glm::vec3(0.0f, gamePadState.axisLeft.x * 0.5f, 0.0f));
updateView = true;
}
if (std::abs(gamePadState.axisLeft.y) > deadZone)
{
camera.rotate(glm::vec3(gamePadState.axisLeft.y * 0.5f, 0.0f, 0.0f));
updateView = true;
}
// Zoom
if (std::abs(gamePadState.axisRight.y) > deadZone)
{
camera.translate(glm::vec3(0.0f, 0.0f, gamePadState.axisRight.y * 0.01f));
updateView = true;
}
}
else
{
updateView = camera.updatePad(gamePadState.axisLeft, gamePadState.axisRight, frameTimer);
camera.updatePad(gamePadState.axisLeft, gamePadState.axisRight, frameTimer);
}
}
}
Expand Down Expand Up @@ -915,9 +910,9 @@ VulkanExampleBase::~VulkanExampleBase()
{
vkDestroyRenderPass(device, renderPass, nullptr);
}
for (uint32_t i = 0; i < frameBuffers.size(); i++)
for (auto& frameBuffer : frameBuffers)
{
vkDestroyFramebuffer(device, frameBuffers[i], nullptr);
vkDestroyFramebuffer(device, frameBuffer, nullptr);
}

for (auto& shaderModule : shaderModules)
Expand Down Expand Up @@ -1509,7 +1504,6 @@ int32_t VulkanExampleBase::handleAppInput(struct android_app* app, AInputEvent*
{
int32_t keyCode = AKeyEvent_getKeyCode((const AInputEvent*)event);
int32_t action = AKeyEvent_getAction((const AInputEvent*)event);
int32_t button = 0;

if (action == AKEY_EVENT_ACTION_UP)
return 0;
Expand Down Expand Up @@ -1554,7 +1548,7 @@ int32_t VulkanExampleBase::handleAppInput(struct android_app* app, AInputEvent*

void VulkanExampleBase::handleAppCommand(android_app * app, int32_t cmd)
{
assert(app->userData != NULL);
assert(app->userData != nullptr);
VulkanExampleBase* vulkanExample = reinterpret_cast<VulkanExampleBase*>(app->userData);
switch (cmd)
{
Expand All @@ -1568,7 +1562,7 @@ void VulkanExampleBase::handleAppCommand(android_app * app, int32_t cmd)
break;
case APP_CMD_INIT_WINDOW:
LOGD("APP_CMD_INIT_WINDOW");
if (androidApp->window != NULL)
if (androidApp->window != nullptr)
{
if (vulkanExample->initVulkan()) {
vulkanExample->prepare();
Expand Down Expand Up @@ -3195,8 +3189,8 @@ void VulkanExampleBase::windowResize()
vkDestroyImage(device, depthStencil.image, nullptr);
vkFreeMemory(device, depthStencil.memory, nullptr);
setupDepthStencil();
for (uint32_t i = 0; i < frameBuffers.size(); i++) {
vkDestroyFramebuffer(device, frameBuffers[i], nullptr);
for (auto& frameBuffer : frameBuffers) {
vkDestroyFramebuffer(device, frameBuffer, nullptr);
}
setupFrameBuffer();

Expand Down
14 changes: 7 additions & 7 deletions base/vulkanexamplebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class VulkanExampleBase
{
private:
std::string getWindowTitle() const;
uint32_t destWidth;
uint32_t destHeight;
uint32_t destWidth{};
uint32_t destHeight{};
bool resizing = false;
void handleMouseMove(int32_t x, int32_t y);
void nextFrame();
Expand Down Expand Up @@ -122,13 +122,13 @@ class VulkanExampleBase
// Handle to the device graphics queue that command buffers are submitted to
VkQueue queue{ VK_NULL_HANDLE };
// Depth buffer format (selected during Vulkan initialization)
VkFormat depthFormat;
VkFormat depthFormat{VK_FORMAT_UNDEFINED};
// Command buffer pool
VkCommandPool cmdPool{ VK_NULL_HANDLE };
/** @brief Pipeline stages used to wait at for graphics queue submissions */
VkPipelineStageFlags submitPipelineStages = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
// Contains command buffers and semaphores to be presented to the queue
VkSubmitInfo submitInfo;
VkSubmitInfo submitInfo{};
// Command buffers used for rendering
std::vector<VkCommandBuffer> drawCmdBuffers;
// Global render pass for frame buffer writes
Expand All @@ -151,7 +151,7 @@ class VulkanExampleBase
VkSemaphore presentComplete;
// Command buffer submission and execution
VkSemaphore renderComplete;
} semaphores;
} semaphores{};
std::vector<VkFence> waitFences;
bool requiresStencil{ false };
public:
Expand All @@ -170,7 +170,7 @@ class VulkanExampleBase
vks::Benchmark benchmark;

/** @brief Encapsulated physical and logical vulkan device */
vks::VulkanDevice *vulkanDevice;
vks::VulkanDevice *vulkanDevice{};

/** @brief Example settings that can be changed e.g. by command line arguments */
struct Settings {
Expand Down Expand Up @@ -234,7 +234,7 @@ class VulkanExampleBase
struct TouchPos {
int32_t x;
int32_t y;
} touchPos;
} touchPos{};
bool touchDown = false;
double touchTimer = 0.0;
int64_t lastTapTime = 0;
Expand Down

0 comments on commit 1fd4564

Please sign in to comment.