|
Rehti MMORPG
1.0.0
Rehti MMORPG is a free and open source MMORPG game.
|
#include <RehtiGraphics.hpp>

Public Member Functions | |
| void | startMainLoop () |
| Starts a rendering loop until the window is closed. More... | |
| RehtiGraphics (uint32_t width=1200, uint32_t height=900, glm::vec3 cameraLocation=glm::vec3(0.f)) | |
| Initializes the graphics backend. More... | |
| ~RehtiGraphics () | |
| Cleans up all the resources used by vulkan. More... | |
| bool | addCharacterObject (int characterID, std::vector< CharacterVertex > vertices, std::vector< uint32_t > indices, ImageData texture, std::array< Animation, ANIMATION_TYPE_COUNT > animations, std::vector< BoneNode > bones, std::vector< glm::mat4 > transformations, glm::vec3 location=glm::vec3(0.f), float rotation=0.f, bool isPlayer=false) |
| Adds a character object with the given id to the graphics backend. Also creates a bounding box for the object. More... | |
| bool | removeCharacterObject (int characterID) |
| Removes a character object with the given id from the graphics backend. More... | |
| bool | addGameObject (int objectID, std::vector< Vertex > vertices, std::vector< uint32_t > indices, ImageData texture, glm::vec3 location=glm::vec3(0.f), float rotation=0.f) |
| Adds a game object with the given id to the graphics backend. Also creates a bounding box for the object. More... | |
| bool | removeGameObject (int objectID) |
| Removes a game object with the given id from the graphics backend. More... | |
| bool | doesGameObjectExist (int objectID) |
| Checks if a game object with the given id exists. More... | |
| bool | doesCharacterExist (int characterID) |
| Checks if a characterwith the given id exists. More... | |
| void | moveGameObject (int objectID, glm::vec3 location, float timeInSeconds) |
| Moves a game object to the given location in the given time. More... | |
| void | rotateGameObject (int objectID, float radians, float timeInSeconds) |
| Rotates a game object by given radian angle in the given time frame. More... | |
| void | forceGameObjectMove (int objectID, glm::vec3 location) |
| Forces the game object to move to the given location, quitting any remaining movement callbacks. More... | |
| void | forceGameObjectRotate (int objectID, float radians) |
| Forces game object rotation to the given angle, quitting any remaining rotation callbacks. More... | |
| void | movePlayer (int playerID, glm::vec3 location, float timeInSeconds) |
| Moves the player smoothly (without animation) to the given location in the given time. More... | |
| void | playAnimation (int characterID, AnimationConfig cfg) |
| Plays an animation for the given character. More... | |
| void | forcePlayerMove (int playerID, glm::vec3 location) |
| Forces player to move to the location given, cancelling any remaining movement callbacks and animations. More... | |
| void | moveCharacter (int characterID, glm::vec3 location, float timeInSeconds) |
| Moves character smoothly (without animation) to the given location in the given time. More... | |
| void | forceCharacterMove (int characterID, glm::vec3 location) |
| Forces character to the given location, cancelling any remaining movement callbacks and animations. More... | |
| bool | addArea (std::vector< Vertex > vertices, std::vector< uint32_t > indices, std::array< ImageData, 6 > textures) |
| Adds an area to the game. More... | |
| void | transformTestObject (int id, glm::mat4 transformation) |
| Transforms object with the given id. More... | |
| void | addMapBoundingBox (const MapAABBData &mapAABBData) |
| Adds a bounding box for the world map. More... | |
| Hit | traceClick () |
| Traces a ray against all bounding boxes, starting with objects, then characters and lastly the map. More... | |
| void | setEngineFlags (EngineFlags flags) |
| Sets flags for engine. Flags can only be set by this interface, not unset. More... | |
| void | addMouseClickCallback (std::function< void(const Hit &)> callback) |
| Adds a mouse click callback. More... | |
| std::shared_ptr< RehtiGui > | getGui () |
Private Member Functions | |
| void | initWindow () |
| Initializes the window. More... | |
| void | initVulkan () |
| Initializes vulkan instance. More... | |
| void | populateDebugMessengerCreateInfo (VkDebugUtilsMessengerCreateInfoEXT &createInfo) |
| Populates the debug messenger info. More... | |
| void | setupDebugMessenger () |
| Setups the debug messenger. More... | |
| void | pickPhysicalDevice () |
| Chooses an appropriate gpu. More... | |
| void | createLogicalDevice () |
| Creates the interactable logical device. More... | |
| void | createObjectManager () |
| Creates the graphics object manager. More... | |
| void | createSwapChain () |
| Creates the swapchain. More... | |
| void | recreateSwapChain () |
| Recreates the swapchain. More... | |
| void | cleanupSwapChain () |
| Cleans up swapchain related resources. This function is used for easier recreation of the swap chain. More... | |
| void | createImageViews () |
| Creates the image views. More... | |
| void | createRenderPass () |
| Creates the render pass. More... | |
| void | createGraphicsPipeline () |
| Creates the graphics pipeline. More... | |
| void | createFramebuffers () |
| Creates the framebuffers. More... | |
| void | createCommandPool () |
| Creates the command pool. More... | |
| void | createCommandBuffers () |
| Creates the command buffers. More... | |
| void | recordCommandBuffer (VkCommandBuffer cmdBuffer, uint32_t imageIndex) |
| Records the command buffer. More... | |
| void | createSynchronization () |
| Initializes the appropriate semaphores and fences. More... | |
| void | drawFrame () |
| Draws a frame and records the previous frame time. More... | |
| void | mainLoop () |
| Loops, polls events and draws frames. More... | |
| void | cleanup () |
| Cleans up used resources. More... | |
| void | createInstance () |
| Creates vulkan instance. More... | |
| void | createSurface () |
| Creates a surface to draw on. More... | |
| void | createTextureSampler () |
| Creates a texture sampler. More... | |
| void | createDepthResources () |
| Creates resources required for a depth buffer. More... | |
| void | createGui () |
| Creates RehtiGui member and initializes it. More... | |
| bool | checkDeviceExtensionSupport (VkPhysicalDevice device) |
| Checks whether the given device supports the required extensions. More... | |
| bool | checkValidationLayerSupport () |
| Checks whether the given device supports the required layers. More... | |
| bool | isDeviceSuitable (VkPhysicalDevice device) |
| Checks whether the given device supports the required features. More... | |
| bool | bbHit (const glm::vec3 min, const glm::vec3 max, const glm::vec3 rayOrig, const glm::vec3 dirInv, float &t) |
| Checks whether the given bounding box is hit by the given ray. More... | |
| bool | trace (const glm::vec3 orig, const glm::vec3 dirInv, const AABB *pBoxNode, AABB &boxHit, float &t) |
| Traces a given ray against a given bounding box. More... | |
| int | rateDevice (VkPhysicalDevice device) |
| Rates the given gpu. More... | |
| QueueFamilyIndices | findQueueFamilies (VkPhysicalDevice device) |
| Looks for queue families. More... | |
| SwapChainSupportDetails | querySwapChainSupport (VkPhysicalDevice device) |
| Looks for swapchain support. More... | |
| std::vector< const char * > | getRequiredExtensions () |
| Returns the required extensions as c strings. More... | |
| VkSurfaceFormatKHR | chooseSwapSurfaceFormat (const std::vector< VkSurfaceFormatKHR > availableFormats) |
| Chooses a surface format. More... | |
| VkPresentModeKHR | chooseSwapPresentMode (const std::vector< VkPresentModeKHR > availableModes) |
| Chooses a present mode. More... | |
| VkExtent2D | chooseSwapExtent (const VkSurfaceCapabilitiesKHR &capabilities) |
| Chooses a swap extent based on the provided capabilities. More... | |
| VkPushConstantRange | getCameraRange () |
| Returns the size of the camera matrix. More... | |
| VkFormat | findSupportedFormat (const std::vector< VkFormat > &candidates, VkImageTiling tiling, VkFormatFeatureFlags features) |
| Looks for a suitable format from given candidates. More... | |
| size_t | getNextFrame () |
| Returns the index of the next frame. More... | |
| void | moveBoundingBox (int objectID, ObjectType objType, glm::vec3 location) |
| Helper function to move a bounding box. More... | |
| void | debugMatrix (glm::mat4 matrix) |
| Prints out a matrix. More... | |
| void | debugAABB (const AABB &aabb, int level) |
| Prints out the given aabb. More... | |
| void | fillAABB (std::vector< Vertex > vertices, AABB &box) |
| Fills the min and max of the given bounding box. More... | |
Static Private Member Functions | |
| static VKAPI_ATTR VkBool32 VKAPI_CALL | debugCallback (VkDebugUtilsMessageSeverityFlagBitsEXT messageSeverity, VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT *pCallbackData, void *pUserData) |
| static VkResult | CreateDebugUtilsMessengerEXT (VkInstance instance, const VkDebugUtilsMessengerCreateInfoEXT *pCreateInfo, const VkAllocationCallbacks *pAllocator, VkDebugUtilsMessengerEXT *pDebugMessenger) |
| static void | DestroyDebugUtilsMessengerEXT (VkInstance instance, VkDebugUtilsMessengerEXT debugMessenger, const VkAllocationCallbacks *pAllocator) |
| static void | frameBufferResizeCallback (GLFWwindow *window, int width, int height) |
Private Attributes | |
| GLFWwindow * | pWindowM |
| VkInstance | instanceM |
| VkDebugUtilsMessengerEXT | debugMessengerM |
| VkSurfaceKHR | surfaceM |
| Camera | cameraM |
| VkPhysicalDevice | gpuM |
| VkDevice | logDeviceM |
| std::shared_ptr< GraphicsObjectManager > | pObjectManagerM |
| std::shared_ptr< RehtiGui > | pGuiM |
| std::shared_mutex | graphicsQueueMutexM |
| VkQueue | graphicsQueueM |
| VkQueue | presentQueueM |
| VkSwapchainKHR | swapChainM |
| std::vector< VkImage > | swapChainImagesM |
| VkFormat | swapChainImageFormatM |
| VkExtent2D | swapChainExtentM |
| std::vector< VkImageView > | swapChainImageViewsM |
| std::vector< VkFramebuffer > | swapChainFramebuffersM |
| AllocatedImage | depthImageM |
| VkImageView | depthImageViewM |
| VkFormat | depthFormatM |
| VkSampler | textureSamplerM |
| VkRenderPass | renderPassM |
| std::array< VkPipelineLayout, OBJECT_TYPE_COUNT > | pipelineLayoutsM |
| std::array< VkPipeline, OBJECT_TYPE_COUNT > | pipelinesM |
| VkCommandPool | commandPoolM |
| std::vector< VkCommandBuffer > | commandBuffersM |
| std::vector< VkSemaphore > | imagesReadyM |
| std::vector< VkSemaphore > | rendersFinishedM |
| std::vector< VkFence > | frameFencesM |
| std::function< void(const Hit &)> | mouseClickCallbackM |
| uint32_t | widthM |
| uint32_t | heightM |
| float | anisotropyM |
| EngineFlags | engineFlagsM = EngineFlags::NO_FLAGS |
| EngineStatistics | statsM |
| std::shared_mutex | dataMutexM |
| Mutex that must be acquired before modifying the data structures below (timer has its own mutex) More... | |
| std::array< std::map< int, AABB >, OBJECT_TYPE_COUNT > | boundingBoxesM |
| std::map< int, GfxOrientation > | gameObjectOrientationsM |
| std::map< int, CharacterData > | characterOrientationsM |
| DirectionalLight | sunM |
| TimerCallbackSystem | timersM |
| const int | kConcurrentFramesM = 2 |
| size_t | currentFrameM = 0 |
| bool | validationLayersEnabledM = false |
| const std::vector< const char * > | kValidationlayersM |
| const std::vector< const char * > | kDeviceExtensionsM |
| const bool | enableValidationLayers = true |
| RehtiGraphics::RehtiGraphics | ( | uint32_t | width = 1200, |
| uint32_t | height = 900, |
||
| glm::vec3 | cameraLocation = glm::vec3(0.f) |
||
| ) |
Initializes the graphics backend.
| width | of the window |
| height | of the window |
| RehtiGraphics::~RehtiGraphics | ( | ) |
Cleans up all the resources used by vulkan.

| bool RehtiGraphics::addArea | ( | std::vector< Vertex > | vertices, |
| std::vector< uint32_t > | indices, | ||
| std::array< ImageData, 6 > | textures | ||
| ) |
Adds an area to the game.
| vertices | are the vertices of the area. They are expected to be moved to their corresponding area coordinates before calling this function. |
| indices | of the triangles. |
| textures | of the area. Areas support 5 textures with a blendmap: Order is: blendmap (0), black (1), red (2), green (3), blue (4), alpha (5). |

| bool RehtiGraphics::addCharacterObject | ( | int | characterID, |
| std::vector< CharacterVertex > | vertices, | ||
| std::vector< uint32_t > | indices, | ||
| ImageData | texture, | ||
| std::array< Animation, ANIMATION_TYPE_COUNT > | animations, | ||
| std::vector< BoneNode > | bones, | ||
| std::vector< glm::mat4 > | transformations, | ||
| glm::vec3 | location = glm::vec3(0.f), |
||
| float | rotation = 0.f, |
||
| bool | isPlayer = false |
||
| ) |
Adds a character object with the given id to the graphics backend. Also creates a bounding box for the object.
| characterID | of the character object. |
| vertices | of the model |
| indices | of the triangles of the model |
| texture | of the model |
| animations | list of Animation structs for the character |
| bones | list of BoneNode structs for the character |
| transformations | list of transformation matrices for the character. IMPORTANT: THE FIRST MATRIX IS THE GLOBAL INVERSE TRANSFORMATION MATRIX. So the transformations start from the second matrix. |
| location | of the character to be placed |
| rotation | of the character to be placed |


| bool RehtiGraphics::addGameObject | ( | int | objectID, |
| std::vector< Vertex > | vertices, | ||
| std::vector< uint32_t > | indices, | ||
| ImageData | texture, | ||
| glm::vec3 | location = glm::vec3(0.f), |
||
| float | rotation = 0.f |
||
| ) |
Adds a game object with the given id to the graphics backend. Also creates a bounding box for the object.
| objectID | |
| vertices | of the model |
| indices | of the triangles of the model |
| texture | of the model |
| location | is the location of the model |
| rotation | is the rotation around y axis clockwise |


| void RehtiGraphics::addMapBoundingBox | ( | const MapAABBData & | mapAABBData | ) |
Adds a bounding box for the world map.
| mapAABBData | see mapAABBData |


| void RehtiGraphics::addMouseClickCallback | ( | std::function< void(const Hit &)> | callback | ) |
Adds a mouse click callback.
| callback | function after a mouse click has happened |


|
private |
Checks whether the given bounding box is hit by the given ray.
| min | is the smaller coordinate of the bounding box. |
| max | is the larger coordinate of the bounding box. |
| rayOrig | is the origin of the ray. |
| dirInv | is the coordinate-wise inverse of the direction of the ray. |
| t | is the distance to the hit point. |

|
private |
Checks whether the given device supports the required extensions.
| device | to check. |

|
private |
Checks whether the given device supports the required layers.

|
private |
Chooses a swap extent based on the provided capabilities.
| capabilities | of the surface in use. |

|
private |
Chooses a present mode.
| availableModes | to choose from. |

|
private |
Chooses a surface format.
| availableFormats | to choose from. |

|
private |
Cleans up used resources.


|
private |
Cleans up swapchain related resources. This function is used for easier recreation of the swap chain.

|
private |
Creates the command buffers.

|
private |
Creates the command pool.


|
staticprivate |

|
private |
Creates resources required for a depth buffer.


|
private |
Creates the framebuffers.

|
private |
Creates the graphics pipeline.


|
private |
Creates RehtiGui member and initializes it.


|
private |
Creates the image views.

|
private |
Creates vulkan instance.


|
private |
Creates the interactable logical device.


|
private |
Creates the graphics object manager.


|
private |
Creates the render pass.

|
private |
Creates a surface to draw on.

|
private |
Creates the swapchain.


|
private |
Initializes the appropriate semaphores and fences.

|
private |
Creates a texture sampler.

|
private |
Prints out the given aabb.
| aabb |

|
staticprivate |

|
private |
Prints out a matrix.
| matrix | to print |
|
staticprivate |

| bool RehtiGraphics::doesCharacterExist | ( | int | characterID | ) |
Checks if a characterwith the given id exists.
| characterID |
| bool RehtiGraphics::doesGameObjectExist | ( | int | objectID | ) |
Checks if a game object with the given id exists.
| objectID |
|
private |
Draws a frame and records the previous frame time.


Fills the min and max of the given bounding box.
| vertices | to create a bounding box for. |
| box | to fill. |
|
private |
Looks for queue families.
| device | to look queues for. |


|
private |
Looks for a suitable format from given candidates.
| candidates | |
| tiling | |
| features |

| void RehtiGraphics::forceCharacterMove | ( | int | characterID, |
| glm::vec3 | location | ||
| ) |
Forces character to the given location, cancelling any remaining movement callbacks and animations.
| characterID | |
| location |


| void RehtiGraphics::forceGameObjectMove | ( | int | objectID, |
| glm::vec3 | location | ||
| ) |
Forces the game object to move to the given location, quitting any remaining movement callbacks.
| objectID | of the object to move. |
| location | to move the object to. |

| void RehtiGraphics::forceGameObjectRotate | ( | int | objectID, |
| float | radians | ||
| ) |
Forces game object rotation to the given angle, quitting any remaining rotation callbacks.
| objectID | of the object to rotate. |
| radians | to rotate the object by. |

| void RehtiGraphics::forcePlayerMove | ( | int | playerID, |
| glm::vec3 | location | ||
| ) |
Forces player to move to the location given, cancelling any remaining movement callbacks and animations.
| playerID | of the player to move. |
| location | to move the player to. |

|
staticprivate |


|
private |
Returns the size of the camera matrix.


| std::shared_ptr< RehtiGui > RehtiGraphics::getGui | ( | ) |

|
private |
Returns the index of the next frame.

|
private |
Returns the required extensions as c strings.

|
private |
Initializes vulkan instance.

|
private |
Initializes the window.

|
private |
Checks whether the given device supports the required features.
| device | to check. |


|
private |
Loops, polls events and draws frames.


|
private |
Helper function to move a bounding box.
| objectID | of the object |
| objType | of the object |
| location | that the object is to be moved to |

| void RehtiGraphics::moveCharacter | ( | int | characterID, |
| glm::vec3 | location, | ||
| float | timeInSeconds | ||
| ) |
Moves character smoothly (without animation) to the given location in the given time.
| characterID | to move |
| location | to move the character into |
| timeInSeconds | that this action takes. |


| void RehtiGraphics::moveGameObject | ( | int | objectID, |
| glm::vec3 | location, | ||
| float | timeInSeconds | ||
| ) |
Moves a game object to the given location in the given time.
| objectID | of the object to move. |
| location | to move the object to. |
| timeInSeconds | that it takes to move the object. |

| void RehtiGraphics::movePlayer | ( | int | playerID, |
| glm::vec3 | location, | ||
| float | timeInSeconds | ||
| ) |
Moves the player smoothly (without animation) to the given location in the given time.
| playerID | of the player to move. |
| location | to move the player to. |
| timeInSeconds | it takes for the player to move to that location. |


|
private |
Chooses an appropriate gpu.


| void RehtiGraphics::playAnimation | ( | int | characterID, |
| AnimationConfig | cfg | ||
| ) |
Plays an animation for the given character.
| characterID | |
| cfg |


|
private |
Populates the debug messenger info.
| createInfo |


|
private |
Looks for swapchain support.
| device | to look support for. |

|
private |
Rates the given gpu.
| device | to rate. |
|
private |
Records the command buffer.
| cmdBuffer | to record to. |
| imageIndex | of the swapchain image. |


|
private |
Recreates the swapchain.


| bool RehtiGraphics::removeCharacterObject | ( | int | characterID | ) |
Removes a character object with the given id from the graphics backend.
| characterID | of the character object. |

| bool RehtiGraphics::removeGameObject | ( | int | objectID | ) |
Removes a game object with the given id from the graphics backend.
| objectID | of the game object. |

| void RehtiGraphics::rotateGameObject | ( | int | objectID, |
| float | radians, | ||
| float | timeInSeconds | ||
| ) |
Rotates a game object by given radian angle in the given time frame.
| objectID | of the object to rotate. |
| radians | to rotate the object by. |
| timeInSeconds | that it takes to rotate the object. |

| void RehtiGraphics::setEngineFlags | ( | EngineFlags | flags | ) |
Sets flags for engine. Flags can only be set by this interface, not unset.
| flags | to be set |

|
private |
Setups the debug messenger.


| void RehtiGraphics::startMainLoop | ( | ) |
Starts a rendering loop until the window is closed.


|
private |
Traces a given ray against a given bounding box.
| orig | is the origin of the ray. |
| dirInv | is the inverse of the direction of the ray. |
| boxNode | is the bounding box to trace against. |
| boxHit | is the bounding box that was hit. |


| Hit RehtiGraphics::traceClick | ( | ) |
Traces a ray against all bounding boxes, starting with objects, then characters and lastly the map.


| void RehtiGraphics::transformTestObject | ( | int | id, |
| glm::mat4 | transformation | ||
| ) |
Transforms object with the given id.
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
Mutex that must be acquired before modifying the data structures below (timer has its own mutex)
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |