Index: vulkan-game.cpp
===================================================================
--- vulkan-game.cpp	(revision 2ba5617346eb7058fde4f0035cce4db10bdb801f)
+++ vulkan-game.cpp	(revision 4994692c43ddba22f532c23a33d0e66fa41c6ece)
@@ -12,17 +12,19 @@
 using namespace std;
 
+// TODO: Update all occurances of instance variables to use this->
+
 VulkanGame::VulkanGame(int maxFramesInFlight) : MAX_FRAMES_IN_FLIGHT(maxFramesInFlight) {
-   gui = nullptr;
-   window = nullptr;
-   font = nullptr;
-   fontSDLTexture = nullptr;
-   imageSDLTexture = nullptr;
-
-   currentFrame = 0;
-   framebufferResized = false;
-
-   object_VP_mats = {};
-   ship_VP_mats = {};
-   asteroid_VP_mats = {};
+   this->gui = nullptr;
+   this->window = nullptr;
+   this->font = nullptr;
+   this->fontSDLTexture = nullptr;
+   this->imageSDLTexture = nullptr;
+
+   this->currentFrame = 0;
+   this->framebufferResized = false;
+
+   this->object_VP_mats = {};
+   this->ship_VP_mats = {};
+   this->asteroid_VP_mats = {};
 }
 
@@ -226,10 +228,11 @@
    modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
       VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_modelPipeline);
-   modelPipeline.addStorageDescriptor();
-
+   modelPipeline.addStorageDescriptor(VK_SHADER_STAGE_VERTEX_BIT);
    modelPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
       VK_SHADER_STAGE_FRAGMENT_BIT, &floorTextureImageDescriptor);
 
-   addObject(modelObjects, modelPipeline,
+   SceneObject<ModelVertex, SSBO_ModelObject>* texturedSquare = nullptr;
+
+   texturedSquare = &addObject(modelObjects, modelPipeline,
       addObjectIndex<ModelVertex>(modelObjects.size(), {
          {{-0.5f, -0.5f,  0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}},
@@ -243,10 +246,9 @@
       }, false);
 
-   modelObjects.back().model_base =
+   texturedSquare->model_base =
       translate(mat4(1.0f), vec3(0.0f, 0.0f, -2.0f));
-
    updateObject(modelObjects, modelPipeline, modelObjects.size() - 1);
 
-   addObject(modelObjects, modelPipeline,
+   texturedSquare = &addObject(modelObjects, modelPipeline,
       addObjectIndex<ModelVertex>(modelObjects.size(), {
          {{-0.5f, -0.5f,  0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}},
@@ -260,7 +262,6 @@
       }, false);
 
-   modelObjects.back().model_base =
+   texturedSquare->model_base =
       translate(mat4(1.0f), vec3(0.0f, 0.0f, -1.5f));
-
    updateObject(modelObjects, modelPipeline, modelObjects.size() - 1);
 
@@ -280,9 +281,9 @@
    shipPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
       VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_shipPipeline);
-   shipPipeline.addStorageDescriptor();
+   shipPipeline.addStorageDescriptor(VK_SHADER_STAGE_VERTEX_BIT);
 
    // TODO: With the normals, indexing basically becomes pointless since no vertices will have exactly
    // the same data. Add an option to make some pipelines not use indexing
-   addObject(shipObjects, shipPipeline,
+   SceneObject<ShipVertex, SSBO_ModelObject>& ship = addObject(shipObjects, shipPipeline,
       addObjectIndex<ShipVertex>(shipObjects.size(),
       addVertexNormals<ShipVertex>({
@@ -532,5 +533,5 @@
    asteroidPipeline.addDescriptorInfo(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
       VK_SHADER_STAGE_VERTEX_BIT, &uniformBufferInfoList_asteroidPipeline);
-   asteroidPipeline.addStorageDescriptor();
+   asteroidPipeline.addStorageDescriptor(VK_SHADER_STAGE_VERTEX_BIT);
 
    asteroidPipeline.createDescriptorSetLayout();
@@ -545,8 +546,7 @@
    createSyncObjects();
 
-   shipObjects[0].model_base =
+   ship.model_base =
       translate(mat4(1.0f), vec3(0.0f, -1.2f, 1.65f)) *
       scale(mat4(1.0f), vec3(0.1f, 0.1f, 0.1f));
-
    updateObject(shipObjects, shipPipeline, 0);
 }
@@ -568,5 +568,5 @@
 // TODO: Maybe changes the name to initScene() or something similar
 void VulkanGame::initMatrices() {
-   cam_pos = vec3(0.0f, 0.0f, 2.0f);
+   this->cam_pos = vec3(0.0f, 0.0f, 2.0f);
 
    float cam_yaw = 0.0f;
@@ -577,5 +577,5 @@
 
    mat4 R_view = pitch_mat * yaw_mat;
-   mat4 T_view = translate(mat4(1.0f), vec3(-cam_pos.x, -cam_pos.y, -cam_pos.z));
+   mat4 T_view = translate(mat4(1.0f), vec3(-this->cam_pos.x, -this->cam_pos.y, -this->cam_pos.z));
    viewMat = R_view * T_view;
 
@@ -625,4 +625,8 @@
                break;
             case UI_EVENT_KEYDOWN:
+               if (e.key.repeat) {
+                  break;
+               }
+
                if (e.key.keycode == SDL_SCANCODE_ESCAPE) {
                   quit = true;
@@ -631,19 +635,19 @@
                   float zOffset = -2.0f + (0.5f * modelObjects.size());
 
-                  addObject(modelObjects, modelPipeline,
-                     addObjectIndex<ModelVertex>(modelObjects.size(), {
-                        {{-0.5f, -0.5f,  0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}},
-                        {{ 0.5f, -0.5f,  0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}},
-                        {{ 0.5f,  0.5f,  0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
-                        {{-0.5f,  0.5f,  0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}
-                     }), {
-                        0, 1, 2, 2, 3, 0
-                     }, {
-                        mat4(1.0f)
-                     }, true);
-
-                  modelObjects.back().model_base =
+                  SceneObject<ModelVertex, SSBO_ModelObject>& texturedSquare =
+                     addObject(modelObjects, modelPipeline,
+                        addObjectIndex<ModelVertex>(modelObjects.size(), {
+                           {{-0.5f, -0.5f,  0.0f}, {1.0f, 0.0f, 0.0f}, {0.0f, 1.0f}},
+                           {{ 0.5f, -0.5f,  0.0f}, {0.0f, 1.0f, 0.0f}, {1.0f, 1.0f}},
+                           {{ 0.5f,  0.5f,  0.0f}, {0.0f, 0.0f, 1.0f}, {1.0f, 0.0f}},
+                           {{-0.5f,  0.5f,  0.0f}, {1.0f, 1.0f, 1.0f}, {0.0f, 0.0f}}
+                        }), {
+                           0, 1, 2, 2, 3, 0
+                        }, {
+                           mat4(1.0f)
+                        }, true);
+
+                  texturedSquare.model_base =
                      translate(mat4(1.0f), vec3(0.0f, 0.0f, zOffset));
-
                   updateObject(modelObjects, modelPipeline, modelObjects.size() - 1);
                } else {
@@ -671,11 +675,17 @@
       // Check which keys are held down
 
+      SceneObject<ShipVertex, SSBO_ModelObject>& ship = shipObjects[0];
+
       if (gui->keyPressed(SDL_SCANCODE_LEFT)) {
-         shipObjects[0].model_transform = translate(mat4(1.0f), vec3(-this->shipSpeed * this->elapsedTime, 0.0f, 0.0f))
+         float distance = -this->shipSpeed * this->elapsedTime;
+
+         ship.model_transform = translate(mat4(1.0f), vec3(distance, 0.0f, 0.0f))
             * shipObjects[0].model_transform;
 
          updateObject(shipObjects, shipPipeline, 0);
       } else if (gui->keyPressed(SDL_SCANCODE_RIGHT)) {
-         shipObjects[0].model_transform = translate(mat4(1.0f), vec3(this->shipSpeed * this->elapsedTime, 0.0f, 0.0f))
+         float distance = this->shipSpeed * this->elapsedTime;
+
+         ship.model_transform = translate(mat4(1.0f), vec3(distance, 0.0f, 0.0f))
             * shipObjects[0].model_transform;
 
@@ -721,5 +731,6 @@
       this->lastSpawn_asteroid = this->curTime;
 
-      addObject(asteroidObjects, asteroidPipeline,
+      SceneObject<AsteroidVertex, SSBO_Asteroid>& asteroid = addObject(
+         asteroidObjects, asteroidPipeline,
          addObjectIndex<AsteroidVertex>(asteroidObjects.size(),
             addVertexNormals<AsteroidVertex>({
@@ -782,5 +793,5 @@
             mat4(1.0f),
             10.0f,
-            0
+            false
          }, true);
 
@@ -790,7 +801,7 @@
       // TODO: Figure out the best way to take scaling into account when calculating the radius
       // Keep in mind that the main complicating factor is the currently poor radius calculation
-      asteroidObjects.back().radius /= 8.0f;
-
-      asteroidObjects.back().model_base =
+      asteroid.radius /= 8.0f;
+
+      asteroid.model_base =
          translate(mat4(1.0f), vec3(getRandomNum(-1.3f, 1.3f), -1.2f, getRandomNum(-5.5f, -4.5f))) *
          rotate(mat4(1.0f), radians(60.0f), vec3(1.0f, 1.0f, -1.0f)) *
@@ -900,6 +911,6 @@
    cleanupSwapChain();
 
+   VulkanUtils::destroyVulkanImage(device, sdlOverlayImage);
    VulkanUtils::destroyVulkanImage(device, floorTextureImage);
-   VulkanUtils::destroyVulkanImage(device, sdlOverlayImage);
 
    vkDestroySampler(device, textureSampler, nullptr);
@@ -1282,4 +1293,13 @@
    createTextureSampler();
 
+   // TODO: Move all images/textures somewhere into the assets folder
+
+   VulkanUtils::createVulkanImageFromSDLTexture(device, physicalDevice, uiOverlay, sdlOverlayImage);
+
+   sdlOverlayImageDescriptor = {};
+   sdlOverlayImageDescriptor.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
+   sdlOverlayImageDescriptor.imageView = sdlOverlayImage.imageView;
+   sdlOverlayImageDescriptor.sampler = textureSampler;
+
    VulkanUtils::createVulkanImageFromFile(device, physicalDevice, commandPool, "textures/texture.jpg",
       floorTextureImage, graphicsQueue);
@@ -1289,11 +1309,4 @@
    floorTextureImageDescriptor.imageView = floorTextureImage.imageView;
    floorTextureImageDescriptor.sampler = textureSampler;
-
-   VulkanUtils::createVulkanImageFromSDLTexture(device, physicalDevice, uiOverlay, sdlOverlayImage);
-
-   sdlOverlayImageDescriptor = {};
-   sdlOverlayImageDescriptor.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
-   sdlOverlayImageDescriptor.imageView = sdlOverlayImage.imageView;
-   sdlOverlayImageDescriptor.sampler = textureSampler;
 }
 
