Skip to content

Commit 1fd4564

Browse files
committed
Code cleanup
Mostly android related
1 parent 42fc441 commit 1fd4564

File tree

2 files changed

+20
-26
lines changed

2 files changed

+20
-26
lines changed

base/vulkanexamplebase.cpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ VkResult VulkanExampleBase::createInstance()
7676
#endif
7777

7878
// Enabled requested instance extensions
79-
if (enabledInstanceExtensions.size() > 0)
79+
if (!enabledInstanceExtensions.empty())
8080
{
8181
for (const char * enabledExtension : enabledInstanceExtensions)
8282
{
@@ -120,7 +120,7 @@ VkResult VulkanExampleBase::createInstance()
120120
instanceExtensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
121121
}
122122

123-
if (instanceExtensions.size() > 0) {
123+
if (!instanceExtensions.empty()) {
124124
instanceCreateInfo.enabledExtensionCount = (uint32_t)instanceExtensions.size();
125125
instanceCreateInfo.ppEnabledExtensionNames = instanceExtensions.data();
126126
}
@@ -316,7 +316,7 @@ void VulkanExampleBase::renderLoop()
316316

317317
benchmark.run([=] { render(); }, vulkanDevice->properties);
318318
vkDeviceWaitIdle(device);
319-
if (benchmark.filename != "") {
319+
if (!benchmark.filename.empty()) {
320320
benchmark.saveResults();
321321
}
322322
return;
@@ -344,7 +344,7 @@ void VulkanExampleBase::renderLoop()
344344
}
345345
}
346346
#elif defined(VK_USE_PLATFORM_ANDROID_KHR)
347-
while (1)
347+
while (true)
348348
{
349349
int ident;
350350
int events;
@@ -353,9 +353,9 @@ void VulkanExampleBase::renderLoop()
353353

354354
focused = true;
355355

356-
while ((ident = ALooper_pollOnce(focused ? 0 : -1, NULL, &events, (void**)&source)) > ALOOPER_POLL_TIMEOUT)
356+
while ((ident = ALooper_pollOnce(focused ? 0 : -1, nullptr, &events, (void**)&source)) > ALOOPER_POLL_TIMEOUT)
357357
{
358-
if (source != NULL)
358+
if (source != nullptr)
359359
{
360360
source->process(androidApp, source);
361361
}
@@ -404,8 +404,6 @@ void VulkanExampleBase::renderLoop()
404404

405405
updateOverlay();
406406

407-
bool updateView = false;
408-
409407
// Check touch state (for movement)
410408
if (touchDown) {
411409
touchTimer += frameTimer;
@@ -422,23 +420,20 @@ void VulkanExampleBase::renderLoop()
422420
if (std::abs(gamePadState.axisLeft.x) > deadZone)
423421
{
424422
camera.rotate(glm::vec3(0.0f, gamePadState.axisLeft.x * 0.5f, 0.0f));
425-
updateView = true;
426423
}
427424
if (std::abs(gamePadState.axisLeft.y) > deadZone)
428425
{
429426
camera.rotate(glm::vec3(gamePadState.axisLeft.y * 0.5f, 0.0f, 0.0f));
430-
updateView = true;
431427
}
432428
// Zoom
433429
if (std::abs(gamePadState.axisRight.y) > deadZone)
434430
{
435431
camera.translate(glm::vec3(0.0f, 0.0f, gamePadState.axisRight.y * 0.01f));
436-
updateView = true;
437432
}
438433
}
439434
else
440435
{
441-
updateView = camera.updatePad(gamePadState.axisLeft, gamePadState.axisRight, frameTimer);
436+
camera.updatePad(gamePadState.axisLeft, gamePadState.axisRight, frameTimer);
442437
}
443438
}
444439
}
@@ -915,9 +910,9 @@ VulkanExampleBase::~VulkanExampleBase()
915910
{
916911
vkDestroyRenderPass(device, renderPass, nullptr);
917912
}
918-
for (uint32_t i = 0; i < frameBuffers.size(); i++)
913+
for (auto& frameBuffer : frameBuffers)
919914
{
920-
vkDestroyFramebuffer(device, frameBuffers[i], nullptr);
915+
vkDestroyFramebuffer(device, frameBuffer, nullptr);
921916
}
922917

923918
for (auto& shaderModule : shaderModules)
@@ -1509,7 +1504,6 @@ int32_t VulkanExampleBase::handleAppInput(struct android_app* app, AInputEvent*
15091504
{
15101505
int32_t keyCode = AKeyEvent_getKeyCode((const AInputEvent*)event);
15111506
int32_t action = AKeyEvent_getAction((const AInputEvent*)event);
1512-
int32_t button = 0;
15131507

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

15551549
void VulkanExampleBase::handleAppCommand(android_app * app, int32_t cmd)
15561550
{
1557-
assert(app->userData != NULL);
1551+
assert(app->userData != nullptr);
15581552
VulkanExampleBase* vulkanExample = reinterpret_cast<VulkanExampleBase*>(app->userData);
15591553
switch (cmd)
15601554
{
@@ -1568,7 +1562,7 @@ void VulkanExampleBase::handleAppCommand(android_app * app, int32_t cmd)
15681562
break;
15691563
case APP_CMD_INIT_WINDOW:
15701564
LOGD("APP_CMD_INIT_WINDOW");
1571-
if (androidApp->window != NULL)
1565+
if (androidApp->window != nullptr)
15721566
{
15731567
if (vulkanExample->initVulkan()) {
15741568
vulkanExample->prepare();
@@ -3195,8 +3189,8 @@ void VulkanExampleBase::windowResize()
31953189
vkDestroyImage(device, depthStencil.image, nullptr);
31963190
vkFreeMemory(device, depthStencil.memory, nullptr);
31973191
setupDepthStencil();
3198-
for (uint32_t i = 0; i < frameBuffers.size(); i++) {
3199-
vkDestroyFramebuffer(device, frameBuffers[i], nullptr);
3192+
for (auto& frameBuffer : frameBuffers) {
3193+
vkDestroyFramebuffer(device, frameBuffer, nullptr);
32003194
}
32013195
setupFrameBuffer();
32023196

base/vulkanexamplebase.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ class VulkanExampleBase
7777
{
7878
private:
7979
std::string getWindowTitle() const;
80-
uint32_t destWidth;
81-
uint32_t destHeight;
80+
uint32_t destWidth{};
81+
uint32_t destHeight{};
8282
bool resizing = false;
8383
void handleMouseMove(int32_t x, int32_t y);
8484
void nextFrame();
@@ -122,13 +122,13 @@ class VulkanExampleBase
122122
// Handle to the device graphics queue that command buffers are submitted to
123123
VkQueue queue{ VK_NULL_HANDLE };
124124
// Depth buffer format (selected during Vulkan initialization)
125-
VkFormat depthFormat;
125+
VkFormat depthFormat{VK_FORMAT_UNDEFINED};
126126
// Command buffer pool
127127
VkCommandPool cmdPool{ VK_NULL_HANDLE };
128128
/** @brief Pipeline stages used to wait at for graphics queue submissions */
129129
VkPipelineStageFlags submitPipelineStages = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
130130
// Contains command buffers and semaphores to be presented to the queue
131-
VkSubmitInfo submitInfo;
131+
VkSubmitInfo submitInfo{};
132132
// Command buffers used for rendering
133133
std::vector<VkCommandBuffer> drawCmdBuffers;
134134
// Global render pass for frame buffer writes
@@ -151,7 +151,7 @@ class VulkanExampleBase
151151
VkSemaphore presentComplete;
152152
// Command buffer submission and execution
153153
VkSemaphore renderComplete;
154-
} semaphores;
154+
} semaphores{};
155155
std::vector<VkFence> waitFences;
156156
bool requiresStencil{ false };
157157
public:
@@ -170,7 +170,7 @@ class VulkanExampleBase
170170
vks::Benchmark benchmark;
171171

172172
/** @brief Encapsulated physical and logical vulkan device */
173-
vks::VulkanDevice *vulkanDevice;
173+
vks::VulkanDevice *vulkanDevice{};
174174

175175
/** @brief Example settings that can be changed e.g. by command line arguments */
176176
struct Settings {
@@ -234,7 +234,7 @@ class VulkanExampleBase
234234
struct TouchPos {
235235
int32_t x;
236236
int32_t y;
237-
} touchPos;
237+
} touchPos{};
238238
bool touchDown = false;
239239
double touchTimer = 0.0;
240240
int64_t lastTapTime = 0;

0 commit comments

Comments
 (0)