From 3b3492843fe743c28dd1c5961977e449e8e4c638 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Sun, 16 Oct 2022 03:25:33 +0800 Subject: [PATCH 1/3] Added input class --- SHADE_Managed/src/Input/Input.cxx | 102 ++++++++++ SHADE_Managed/src/Input/Input.hxx | 325 ++++++++++++++++++++++++++++++ 2 files changed, 427 insertions(+) create mode 100644 SHADE_Managed/src/Input/Input.cxx create mode 100644 SHADE_Managed/src/Input/Input.hxx diff --git a/SHADE_Managed/src/Input/Input.cxx b/SHADE_Managed/src/Input/Input.cxx new file mode 100644 index 00000000..0a386f3a --- /dev/null +++ b/SHADE_Managed/src/Input/Input.cxx @@ -0,0 +1,102 @@ +/************************************************************************************//*! +\file Input.cxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Oct 16, 2022 +\brief Contains the definition of the managed Input static class. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +#include "SHpch.h" +#include "Input.hxx" +#include "Utility/Convert.hxx" + +namespace SHADE +{ + /*---------------------------------------------------------------------------------*/ + /* Properties */ + /*---------------------------------------------------------------------------------*/ + Vector3 Input::MousePosition::get() + { + int x, y; + SHInputManager::GetMouseWindowPosition(&x, &y); + return Vector3(static_cast(x), static_cast(y), 0.0f); + } + int Input::MouseScrollDelta::get() + { + return SHInputManager::GetMouseWheelVerticalDelta(); + } + + /*---------------------------------------------------------------------------------*/ + /* Usage Functions */ + /*---------------------------------------------------------------------------------*/ + bool Input::GetKey(KeyCode key) + { + return SHInputManager::GetKey(static_cast(key)); + } + + bool Input::GetKeyDown(KeyCode key) + { + return SHInputManager::GetKeyDown(static_cast(key)); + } + + bool Input::GetKeyUp(KeyCode key) + { + return SHInputManager::GetKeyUp(static_cast(key)); + } + + bool Input::GetMouseButton(MouseCode mouseButton) + { + return SHInputManager::GetKey(static_cast(mouseButton)); + } + + bool Input::GetMouseButtonDown(MouseCode mouseButton) + { + return SHInputManager::GetKeyDown(static_cast(mouseButton)); + } + + bool Input::GetMouseButtonUp(MouseCode mouseButton) + { + return SHInputManager::GetKeyUp(static_cast(mouseButton)); + } + + /*---------------------------------------------------------------------------------*/ + /* Cursor Functions */ + /*---------------------------------------------------------------------------------*/ + void Input::SetMousePosition(Vector2 pos) + { + SHInputManager::SetMouseWindowPosition + ( + static_cast(pos.x), + static_cast(pos.y) + ); + } + + /*---------------------------------------------------------------------------------*/ + /* Time Functions */ + /*---------------------------------------------------------------------------------*/ + double Input::GetKeyHeldTime(KeyCode key) + { + return SHInputManager::GetKeyHeldTime(static_cast(key)); + } + + double Input::GetKeyReleasedTime(KeyCode key) + { + return SHInputManager::GetKeyReleasedTime(static_cast(key)); + } + + double Input::GetMouseHeldTime(MouseCode key) + { + return SHInputManager::GetKeyHeldTime(static_cast(key)); + } + + double Input::GetMouseReleasedTime(MouseCode key) + { + return SHInputManager::GetKeyReleasedTime(static_cast(key)); + } + +} \ No newline at end of file diff --git a/SHADE_Managed/src/Input/Input.hxx b/SHADE_Managed/src/Input/Input.hxx new file mode 100644 index 00000000..f281e4c8 --- /dev/null +++ b/SHADE_Managed/src/Input/Input.hxx @@ -0,0 +1,325 @@ +/************************************************************************************//*! +\file Input.hxx +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Oct 16, 2022 +\brief Contains the definition of the managed Input static class. + + Note: This file is written in C++17/CLI. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +#pragma once + +#include "Input/SHInputManager.h" +#include "Math/Vector2.hxx" +#include "Math/Vector3.hxx" + +namespace SHADE +{ + /// + /// Static class responsible for providing access to Input-related functionality. + /// + public ref class Input abstract sealed + { + public: + /*-----------------------------------------------------------------------------*/ + /* Type Definitions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Represents the available supported keycodes that can be passed into the + /// key-based Input functions. + /// + enum class KeyCode : int + { + Space = static_cast(SHInputManager::SH_KEYCODE::SPACE), + //Apostrophe = static_cast(SHInputManager::SH_KEYCODE::APOSTROPHE), + Comma = static_cast(SHInputManager::SH_KEYCODE::OEM_COMMA), + Minus = static_cast(SHInputManager::SH_KEYCODE::OEM_MINUS), + Period = static_cast(SHInputManager::SH_KEYCODE::OEM_PERIOD), + //Slash = static_cast(SHInputManager::SH_KEYCODE::SLASH), + Key0 = static_cast(SHInputManager::SH_KEYCODE::NUMBER_0), + Key1 = static_cast(SHInputManager::SH_KEYCODE::NUMBER_1), + Key2 = static_cast(SHInputManager::SH_KEYCODE::NUMBER_2), + Key3 = static_cast(SHInputManager::SH_KEYCODE::NUMBER_3), + Key4 = static_cast(SHInputManager::SH_KEYCODE::NUMBER_4), + Key5 = static_cast(SHInputManager::SH_KEYCODE::NUMBER_5), + Key6 = static_cast(SHInputManager::SH_KEYCODE::NUMBER_6), + Key7 = static_cast(SHInputManager::SH_KEYCODE::NUMBER_7), + Key8 = static_cast(SHInputManager::SH_KEYCODE::NUMBER_8), + Key9 = static_cast(SHInputManager::SH_KEYCODE::NUMBER_9), + + //Semicolon = static_cast(SHInputManager::SH_KEYCODE::SEMICOLON), + //Equal = static_cast(SHInputManager::SH_KEYCODE::EQUAL), + + A = static_cast(SHInputManager::SH_KEYCODE::A), + B = static_cast(SHInputManager::SH_KEYCODE::B), + C = static_cast(SHInputManager::SH_KEYCODE::C), + D = static_cast(SHInputManager::SH_KEYCODE::D), + E = static_cast(SHInputManager::SH_KEYCODE::E), + F = static_cast(SHInputManager::SH_KEYCODE::F), + G = static_cast(SHInputManager::SH_KEYCODE::G), + H = static_cast(SHInputManager::SH_KEYCODE::H), + I = static_cast(SHInputManager::SH_KEYCODE::I), + J = static_cast(SHInputManager::SH_KEYCODE::J), + K = static_cast(SHInputManager::SH_KEYCODE::K), + L = static_cast(SHInputManager::SH_KEYCODE::L), + M = static_cast(SHInputManager::SH_KEYCODE::M), + N = static_cast(SHInputManager::SH_KEYCODE::N), + O = static_cast(SHInputManager::SH_KEYCODE::O), + P = static_cast(SHInputManager::SH_KEYCODE::P), + Q = static_cast(SHInputManager::SH_KEYCODE::Q), + R = static_cast(SHInputManager::SH_KEYCODE::R), + S = static_cast(SHInputManager::SH_KEYCODE::S), + T = static_cast(SHInputManager::SH_KEYCODE::T), + U = static_cast(SHInputManager::SH_KEYCODE::U), + V = static_cast(SHInputManager::SH_KEYCODE::V), + W = static_cast(SHInputManager::SH_KEYCODE::W), + X = static_cast(SHInputManager::SH_KEYCODE::X), + Y = static_cast(SHInputManager::SH_KEYCODE::Y), + Z = static_cast(SHInputManager::SH_KEYCODE::Z), + + //LeftBracket = static_cast(SHInputManager::SH_KEYCODE::LEFTBRACKET), + //BackSlash = static_cast(SHInputManager::SH_KEYCODE::BACKSLASH), + //RightBracket = static_cast(SHInputManager::SH_KEYCODE::RIGHTBRACKET), + //GraveAccent = static_cast(SHInputManager::SH_KEYCODE::GRAVEACCENT), + + //WORLD1 = static_cast(SHInputManager::SH_KEYCODE::WORLD1), + //WORLD2 = static_cast(SHInputManager::SH_KEYCODE::WORLD2), + + /* Function keys */ + Escape = static_cast(SHInputManager::SH_KEYCODE::ESCAPE), + Enter = static_cast(SHInputManager::SH_KEYCODE::ENTER), + Tab = static_cast(SHInputManager::SH_KEYCODE::TAB), + Backspace = static_cast(SHInputManager::SH_KEYCODE::BACKSPACE), + Insert = static_cast(SHInputManager::SH_KEYCODE::INSERT), + Delete = static_cast(SHInputManager::SH_KEYCODE::DEL), + Right = static_cast(SHInputManager::SH_KEYCODE::RIGHT_ARROW), + Left = static_cast(SHInputManager::SH_KEYCODE::LEFT_ARROW), + Down = static_cast(SHInputManager::SH_KEYCODE::DOWN_ARROW), + Up = static_cast(SHInputManager::SH_KEYCODE::UP_ARROW), + PageUp = static_cast(SHInputManager::SH_KEYCODE::PAGE_UP), + PageDown = static_cast(SHInputManager::SH_KEYCODE::PAGE_DOWN), + Home = static_cast(SHInputManager::SH_KEYCODE::HOME), + End = static_cast(SHInputManager::SH_KEYCODE::END), + CapsLock = static_cast(SHInputManager::SH_KEYCODE::CAPS_LOCK), + ScrollLock = static_cast(SHInputManager::SH_KEYCODE::SCROLL_LOCK), + NumLock = static_cast(SHInputManager::SH_KEYCODE::NUM_LOCK), + PrintScreen = static_cast(SHInputManager::SH_KEYCODE::PRINT_SCREEN), + Pause = static_cast(SHInputManager::SH_KEYCODE::PAUSE), + F1 = static_cast(SHInputManager::SH_KEYCODE::F1), + F2 = static_cast(SHInputManager::SH_KEYCODE::F2), + F3 = static_cast(SHInputManager::SH_KEYCODE::F3), + F4 = static_cast(SHInputManager::SH_KEYCODE::F4), + F5 = static_cast(SHInputManager::SH_KEYCODE::F5), + F6 = static_cast(SHInputManager::SH_KEYCODE::F6), + F7 = static_cast(SHInputManager::SH_KEYCODE::F7), + F8 = static_cast(SHInputManager::SH_KEYCODE::F8), + F9 = static_cast(SHInputManager::SH_KEYCODE::F9), + F10 = static_cast(SHInputManager::SH_KEYCODE::F10), + F11 = static_cast(SHInputManager::SH_KEYCODE::F11), + F12 = static_cast(SHInputManager::SH_KEYCODE::F12), + F13 = static_cast(SHInputManager::SH_KEYCODE::F13), + F14 = static_cast(SHInputManager::SH_KEYCODE::F14), + F15 = static_cast(SHInputManager::SH_KEYCODE::F15), + F16 = static_cast(SHInputManager::SH_KEYCODE::F16), + F17 = static_cast(SHInputManager::SH_KEYCODE::F17), + F18 = static_cast(SHInputManager::SH_KEYCODE::F18), + F19 = static_cast(SHInputManager::SH_KEYCODE::F19), + F20 = static_cast(SHInputManager::SH_KEYCODE::F20), + F21 = static_cast(SHInputManager::SH_KEYCODE::F21), + F22 = static_cast(SHInputManager::SH_KEYCODE::F22), + F23 = static_cast(SHInputManager::SH_KEYCODE::F23), + F24 = static_cast(SHInputManager::SH_KEYCODE::F24), + + /* Keypad */ + KeyPad0 = static_cast(SHInputManager::SH_KEYCODE::NUMPAD_0), + KeyPad1 = static_cast(SHInputManager::SH_KEYCODE::NUMPAD_1), + KeyPad2 = static_cast(SHInputManager::SH_KEYCODE::NUMPAD_2), + KeyPad3 = static_cast(SHInputManager::SH_KEYCODE::NUMPAD_3), + KeyPad4 = static_cast(SHInputManager::SH_KEYCODE::NUMPAD_4), + KeyPad5 = static_cast(SHInputManager::SH_KEYCODE::NUMPAD_5), + KeyPad6 = static_cast(SHInputManager::SH_KEYCODE::NUMPAD_6), + KeyPad7 = static_cast(SHInputManager::SH_KEYCODE::NUMPAD_7), + KeyPad8 = static_cast(SHInputManager::SH_KEYCODE::NUMPAD_8), + KeyPad9 = static_cast(SHInputManager::SH_KEYCODE::NUMPAD_9), + //KeyPadDecimal = static_cast(SHInputManager::SH_KEYCODE::KPDECIMAL), + //KeyPadDivide = static_cast(SHInputManager::SH_KEYCODE::KPDIVIDE), + //KeyPadMultiply = static_cast(SHInputManager::SH_KEYCODE::KPMULTIPLY), + //KeyPadSubtract = static_cast(SHInputManager::SH_KEYCODE::KPSUBTRACT), + //KeyPadAdd = static_cast(SHInputManager::SH_KEYCODE::KPADD), + //KeyPadEnter = static_cast(SHInputManager::SH_KEYCODE::KPENTER), + //KeyPadEqual = static_cast(SHInputManager::SH_KEYCODE::KEYPAD), + + Shift = static_cast(SHInputManager::SH_KEYCODE::SHIFT), + LeftControl = static_cast(SHInputManager::SH_KEYCODE::LEFT_CTRL), + LeftAlt = static_cast(SHInputManager::SH_KEYCODE::LEFT_ALT), + LeftSuper = static_cast(SHInputManager::SH_KEYCODE::LEFT_WINDOWS), + RightShift = static_cast(SHInputManager::SH_KEYCODE::RIGHT_SHIFT), + RightControl = static_cast(SHInputManager::SH_KEYCODE::RIGHT_CTRL), + RightAlt = static_cast(SHInputManager::SH_KEYCODE::RIGHT_ALT), + RightSuper = static_cast(SHInputManager::SH_KEYCODE::RIGHT_WINDOWS), + + /* Gamepad */ + JoystickA = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_A), + JoystickB = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_B), + JoystickX = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_X), + JoystickY = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_Y), + JoystickLeftBumper = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_LEFTSHOULDER), + JoystickRightBumper = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_RIGHTSHOULDER), + JoystickLeftTrigger = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_LEFTTRIGGER), + JoystickRightTrigger = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_RIGHTTRIGGER), + JoystickDPadUp = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_DPAD_UP), + JoystickDPadDown = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_DPAD_DOWN), + JoystickDPadLeft = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_DPAD_LEFT), + JoystickDPadRight = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_DPAD_RIGHT), + JoystickMenu = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_MENU), + JoystickView = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_VIEW), + JoystickLeftStick = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_LEFT_THUMBSTICK_BUTTON), + JoystickRightStick = static_cast(SHInputManager::SH_KEYCODE::GAMEPAD_RIGHT_THUMBSTICK_BUTTON), + + /* Unity Gamepad Mappings */ + JoystickButton0 = JoystickA, + JoystickButton1 = JoystickB, + JoystickButton2 = JoystickX, + JoystickButton3 = JoystickY, + JoystickButton4 = JoystickLeftBumper, + JoystickButton5 = JoystickRightBumper, + JoystickButton6 = JoystickView, + JoystickButton7 = JoystickMenu, + JoystickButton8 = JoystickLeftStick, + JoystickButton9 = JoystickRightStick + + }; + /// + /// Represents the available supported mouse keycodes that can be passed into the + /// mouse-button-based Input functions. + /// + enum class MouseCode : int + { + LeftButton = static_cast(SHInputManager::SH_KEYCODE::LMB), + RightButton = static_cast(SHInputManager::SH_KEYCODE::RMB), + MiddleButton = static_cast(SHInputManager::SH_KEYCODE::MMB), + Button3 = static_cast(SHInputManager::SH_KEYCODE::XMB1), + Button4 = static_cast(SHInputManager::SH_KEYCODE::XMB2) + }; + + /*-----------------------------------------------------------------------------*/ + /* Properites */ + /*-----------------------------------------------------------------------------*/ + /// + /// Mouse position in screen coordinates relative to the top left of the window. + /// This value is a Vector3 for compatibility with functions that have Vector3 + /// arguments. The z component of the Vector3 is always 0 + /// + static property Vector3 MousePosition + { + Vector3 get(); + } + /// + /// Amnount of vertical mouse scroll in this frame. + /// + static property int MouseScrollDelta + { + int get(); + } + + /*-----------------------------------------------------------------------------*/ + /* Usage Functions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Checks if a specified key is being held down. + /// This will also be true if GetKeyDown() is true. + /// + /// KeyCode of the key to check. + /// True while the user holds down the key specified. + static bool GetKey(KeyCode key); + /// + /// Checks if a specified key is pressed and was not pressed before. + /// + /// KeyCode of the key to check. + /// + /// True during the frame the user starts pressing down the key specified. + /// + static bool GetKeyDown(KeyCode key); + /// + /// Checks if a specified key is no longer pressed pressed and was pressed + /// before. + /// + /// KeyCode of the key to check. + /// + /// True during the frame the user releases the key identified by name. + /// + static bool GetKeyUp(KeyCode key); + /// + /// Checks if a specified mouse button is being held down. + /// This will also be true if GetMouseButtonDown() is true. + /// + /// MouseCode of the mouse button to check. + /// True while the user holds down the mouse button specified. + static bool GetMouseButton(MouseCode mouseButton); + /// + /// Checks if a specified mouse button is pressed and was not pressed before. + /// + /// MouseCode of the mouse button to check. + /// + /// True during the frame the user pressed the given mouse button. + /// + static bool GetMouseButtonDown(MouseCode mouseButton); + /// + /// Checks if a specified mouse button is no longer pressed and was pressed + /// before. + /// + /// MouseCode of the mouse button to check. + /// + /// True during the frame the user releases the given mouse button. + /// + static bool GetMouseButtonUp(MouseCode mouseButton); + + /*-----------------------------------------------------------------------------*/ + /* Cursor Functions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Sets the position of the mouse cursor relative to the top left corner of the + /// window. + /// + /// + /// Position of the mouse in window pixel coordinates to set. + /// + static void SetMousePosition(Vector2 pos); + + /*-----------------------------------------------------------------------------*/ + /* Timing Functions */ + /*-----------------------------------------------------------------------------*/ + /// + /// Retrieves the duration that the specified key has been held or was last held + /// for. + /// + /// The key to check. + /// Time in seconds that the key was held. + static double GetKeyHeldTime(KeyCode key); + /// + /// Retrieves the duration that the specified key has not been held or was last + /// not been held for. + /// + /// The key to check. + /// Time in seconds that the key was held. + static double GetKeyReleasedTime(KeyCode key); + /// + /// Retrieves the duration that the specified key has been held or was last held + /// for. + /// + /// The key to check. + /// Time in seconds that the key was held. + static double GetMouseHeldTime(MouseCode mouseButton); + /// + /// Retrieves the duration that the specified key has not been held or was last + /// not been held for. + /// + /// The key to check. + /// Time in seconds that the key was held. + static double GetMouseReleasedTime(MouseCode mouseButton); + }; +} \ No newline at end of file From b10f490e45381422cdd81ef68d99aaca2d67215b Mon Sep 17 00:00:00 2001 From: Xiao Qi Date: Sun, 16 Oct 2022 23:15:11 +0800 Subject: [PATCH 2/3] SP3-102 SP3-248 Saving of SHMETA files with asset IDs, retrieval of asset data under works, currently all assets are loaded into memory automatically --- Assets/Cube.003.shmesh.shmeta | 3 + Assets/Cube.012.shmesh.shmeta | 3 + .../RaccoonPreTexturedVer1_Base9.shtex.shmeta | 3 + .../src/Application/SBApplication.cpp | 7 +- .../src/Assets/Asset Types/SHTextureAsset.h | 1 + .../src/Assets/Libraries/SHMeshCompiler.cpp | 4 +- .../src/Assets/Libraries/SHMeshCompiler.h | 2 +- .../src/Assets/Libraries/SHMeshLoader.cpp | 3 +- .../src/Assets/Libraries/SHMeshLoader.h | 2 +- .../Assets/Libraries/SHTextureCompiler.cpp | 4 +- .../src/Assets/Libraries/SHTextureCompiler.h | 2 +- .../src/Assets/Libraries/SHTextureLoader.cpp | 1 + .../src/Assets/Libraries/SHTextureLoader.h | 2 +- SHADE_Engine/src/Assets/SHAssetMacros.h | 9 +- SHADE_Engine/src/Assets/SHAssetManager.cpp | 112 ++++++++++++------ .../src/Assets/SHAssetMetaHandler.cpp | 29 +++-- 16 files changed, 132 insertions(+), 55 deletions(-) create mode 100644 Assets/Cube.003.shmesh.shmeta create mode 100644 Assets/Cube.012.shmesh.shmeta create mode 100644 Assets/RaccoonPreTexturedVer1_Base9.shtex.shmeta diff --git a/Assets/Cube.003.shmesh.shmeta b/Assets/Cube.003.shmesh.shmeta new file mode 100644 index 00000000..d41be546 --- /dev/null +++ b/Assets/Cube.003.shmesh.shmeta @@ -0,0 +1,3 @@ +Name: Cube.003 +ID: 110152941 +Type:  diff --git a/Assets/Cube.012.shmesh.shmeta b/Assets/Cube.012.shmesh.shmeta new file mode 100644 index 00000000..d5cd1090 --- /dev/null +++ b/Assets/Cube.012.shmesh.shmeta @@ -0,0 +1,3 @@ +Name: Cube.012 +ID: 107348815 +Type:  diff --git a/Assets/RaccoonPreTexturedVer1_Base9.shtex.shmeta b/Assets/RaccoonPreTexturedVer1_Base9.shtex.shmeta new file mode 100644 index 00000000..f8c267d9 --- /dev/null +++ b/Assets/RaccoonPreTexturedVer1_Base9.shtex.shmeta @@ -0,0 +1,3 @@ +Name: RaccoonPreTexturedVer1_Base9 +ID: 91918845 +Type:  diff --git a/SHADE_Application/src/Application/SBApplication.cpp b/SHADE_Application/src/Application/SBApplication.cpp index 202a3852..5a265d39 100644 --- a/SHADE_Application/src/Application/SBApplication.cpp +++ b/SHADE_Application/src/Application/SBApplication.cpp @@ -104,10 +104,10 @@ namespace Sandbox //TODO: REMOVE AFTER PRESENTATION //SHAssetManager::LoadDataTemp("../../Assets/racoon.gltf"); - SHAssetManager::LoadDataTemp("../../Assets/Cube.012.shmesh"); + //SHAssetManager::LoadDataTemp("../../Assets/Cube.012.shmesh"); //SHAssetManager::LoadDataTemp("../../Assets/RaccoonBag_Color_Ver4.dds"); //SHAssetManager::LoadDataTemp("../../Assets/RaccoonPreTexturedVer1_Base9.dds"); - SHAssetManager::LoadDataTemp("../../Assets/RaccoonPreTexturedVer1_Base9.shtex"); + //SHAssetManager::LoadDataTemp("../../Assets/RaccoonPreTexturedVer1_Base9.shtex"); //TODO: REMOVE AFTER PRESENTATION @@ -125,6 +125,8 @@ namespace Sandbox SHSceneManager::InitSceneManager("TestScene"); SHFrameRateController::UpdateFRC(); + + SHAssetManager::Load(); } void SBApplication::Update(void) @@ -154,6 +156,7 @@ namespace Sandbox SHSceneManager::Exit(); SHSystemManager::Exit(); + SHAssetManager::Unload(); } } diff --git a/SHADE_Engine/src/Assets/Asset Types/SHTextureAsset.h b/SHADE_Engine/src/Assets/Asset Types/SHTextureAsset.h index 07cebea9..d24b6c02 100644 --- a/SHADE_Engine/src/Assets/Asset Types/SHTextureAsset.h +++ b/SHADE_Engine/src/Assets/Asset Types/SHTextureAsset.h @@ -9,6 +9,7 @@ namespace SHADE { bool compiled; + std::string name; uint32_t numBytes; uint32_t width; uint32_t height; diff --git a/SHADE_Engine/src/Assets/Libraries/SHMeshCompiler.cpp b/SHADE_Engine/src/Assets/Libraries/SHMeshCompiler.cpp index 12b2517e..8026f0e1 100644 --- a/SHADE_Engine/src/Assets/Libraries/SHMeshCompiler.cpp +++ b/SHADE_Engine/src/Assets/Libraries/SHMeshCompiler.cpp @@ -16,7 +16,7 @@ #include -void SHADE::SHMeshCompiler::CompileMeshBinary(SHMeshAsset const& asset, AssetPath path) noexcept +std::string SHADE::SHMeshCompiler::CompileMeshBinary(SHMeshAsset const& asset, AssetPath path) noexcept { std::string newPath{ path.string() }; newPath = newPath.substr(0, newPath.find_last_of('/') + 1); @@ -67,4 +67,6 @@ void SHADE::SHMeshCompiler::CompileMeshBinary(SHMeshAsset const& asset, AssetPat ); file.close(); + + return newPath; } diff --git a/SHADE_Engine/src/Assets/Libraries/SHMeshCompiler.h b/SHADE_Engine/src/Assets/Libraries/SHMeshCompiler.h index 6da00525..a8ce67be 100644 --- a/SHADE_Engine/src/Assets/Libraries/SHMeshCompiler.h +++ b/SHADE_Engine/src/Assets/Libraries/SHMeshCompiler.h @@ -21,6 +21,6 @@ namespace SHADE { private: public: - static void CompileMeshBinary(SHMeshAsset const& asset, AssetPath path) noexcept; + static std::string CompileMeshBinary(SHMeshAsset const& asset, AssetPath path) noexcept; }; } \ No newline at end of file diff --git a/SHADE_Engine/src/Assets/Libraries/SHMeshLoader.cpp b/SHADE_Engine/src/Assets/Libraries/SHMeshLoader.cpp index 3a5fb9ec..4bfa2d9b 100644 --- a/SHADE_Engine/src/Assets/Libraries/SHMeshLoader.cpp +++ b/SHADE_Engine/src/Assets/Libraries/SHMeshLoader.cpp @@ -142,8 +142,7 @@ namespace SHADE SHLOG_ERROR("Unable to open SHMesh File: {}", path.string()); } - std::string name{ path.filename().string() }; - name = name.substr(0, name.find_last_of('.')); + const std::string name{ path.stem().string() }; file.seekg(0); diff --git a/SHADE_Engine/src/Assets/Libraries/SHMeshLoader.h b/SHADE_Engine/src/Assets/Libraries/SHMeshLoader.h index 3e430aca..a27d63ea 100644 --- a/SHADE_Engine/src/Assets/Libraries/SHMeshLoader.h +++ b/SHADE_Engine/src/Assets/Libraries/SHMeshLoader.h @@ -29,8 +29,8 @@ namespace SHADE static void LoadExternal(std::vector& meshes, AssetPath path) noexcept; - static void LoadSHMesh(SHMeshAsset& meshes, AssetPath path) noexcept; public: static void LoadMesh(std::vector& meshes, AssetPath path) noexcept; + static void LoadSHMesh(SHMeshAsset& meshes, AssetPath path) noexcept; }; } \ No newline at end of file diff --git a/SHADE_Engine/src/Assets/Libraries/SHTextureCompiler.cpp b/SHADE_Engine/src/Assets/Libraries/SHTextureCompiler.cpp index 62af4da6..49de6b5c 100644 --- a/SHADE_Engine/src/Assets/Libraries/SHTextureCompiler.cpp +++ b/SHADE_Engine/src/Assets/Libraries/SHTextureCompiler.cpp @@ -17,7 +17,7 @@ namespace SHADE { - void SHTextureCompiler::CompileTextureBinary(SHTextureAsset const& asset, AssetPath path) + std::string SHTextureCompiler::CompileTextureBinary(SHTextureAsset const& asset, AssetPath path) { std::string newPath{ path.string() }; newPath = newPath.substr(0, newPath.find_last_of('.')); @@ -69,5 +69,7 @@ namespace SHADE ); file.close(); + + return newPath; } } diff --git a/SHADE_Engine/src/Assets/Libraries/SHTextureCompiler.h b/SHADE_Engine/src/Assets/Libraries/SHTextureCompiler.h index d8685795..52980084 100644 --- a/SHADE_Engine/src/Assets/Libraries/SHTextureCompiler.h +++ b/SHADE_Engine/src/Assets/Libraries/SHTextureCompiler.h @@ -19,6 +19,6 @@ namespace SHADE { struct SHTextureCompiler { - static void CompileTextureBinary(SHTextureAsset const& asset, AssetPath path); + static std::string CompileTextureBinary(SHTextureAsset const& asset, AssetPath path); }; } \ No newline at end of file diff --git a/SHADE_Engine/src/Assets/Libraries/SHTextureLoader.cpp b/SHADE_Engine/src/Assets/Libraries/SHTextureLoader.cpp index 47501d42..5147562a 100644 --- a/SHADE_Engine/src/Assets/Libraries/SHTextureLoader.cpp +++ b/SHADE_Engine/src/Assets/Libraries/SHTextureLoader.cpp @@ -93,6 +93,7 @@ namespace SHADE std::memcpy(pixel, file.GetImageData()->m_mem, totalBytes); //pixel = std::move(reinterpret_cast(file.GetDDSData())); + asset.name = path.stem().string(); asset.compiled = false; asset.numBytes = static_cast(totalBytes); asset.width = file.GetWidth(); diff --git a/SHADE_Engine/src/Assets/Libraries/SHTextureLoader.h b/SHADE_Engine/src/Assets/Libraries/SHTextureLoader.h index e84fe5cf..eb61ea91 100644 --- a/SHADE_Engine/src/Assets/Libraries/SHTextureLoader.h +++ b/SHADE_Engine/src/Assets/Libraries/SHTextureLoader.h @@ -26,8 +26,8 @@ namespace SHADE static void LoadTinyDDS(AssetPath path, SHTextureAsset& asset) noexcept; - static void LoadSHTexture(AssetPath path, SHTextureAsset& asset) noexcept; public: static void LoadImageAsset(AssetPath paths, SHTextureAsset& image); + static void LoadSHTexture(AssetPath path, SHTextureAsset& asset) noexcept; }; } diff --git a/SHADE_Engine/src/Assets/SHAssetMacros.h b/SHADE_Engine/src/Assets/SHAssetMacros.h index 8c462af7..61c5879d 100644 --- a/SHADE_Engine/src/Assets/SHAssetMacros.h +++ b/SHADE_Engine/src/Assets/SHAssetMacros.h @@ -40,7 +40,7 @@ typedef FMOD::Sound* SHSound; #define ASSET_META_VER "1.0" // Asset type enum -enum class AssetType : uint8_t +enum class AssetType : AssetTypeMeta { INVALID = 0, AUDIO = 1, @@ -57,7 +57,12 @@ enum class AssetType : uint8_t }; //Directory -#define ASSET_ROOT "./Assets/" +#ifdef _PUBLISH +#define ASSET_ROOT "Assets" +#else +#define ASSET_ROOT "../../Assets" +#endif + // ASSET EXTENSIONS #define META_EXTENSION ".shmeta" diff --git a/SHADE_Engine/src/Assets/SHAssetManager.cpp b/SHADE_Engine/src/Assets/SHAssetManager.cpp index 430b8c79..e3578f92 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.cpp +++ b/SHADE_Engine/src/Assets/SHAssetManager.cpp @@ -307,12 +307,22 @@ namespace SHADE for (auto const& mesh : meshes) { - meshCollection.emplace(GenerateAssetID(AssetType::MESH), mesh); + auto id{ GenerateAssetID(AssetType::MESH) }; + meshCollection.emplace(id, mesh); + AssetPath path; if (!mesh.compiled) { - SHMeshCompiler::CompileMeshBinary(mesh, asset.path); + path = SHMeshCompiler::CompileMeshBinary(mesh, asset.path); } + + assetCollection.emplace_back( + mesh.header.meshName, + id, + AssetType::MESH, + path, + 0 + ); } } @@ -322,11 +332,20 @@ namespace SHADE SHTextureLoader::LoadImageAsset(asset.path, image); - textureCollection.emplace(GenerateAssetID(AssetType::DDS), image); - if (!image.compiled) { - SHTextureCompiler::CompileTextureBinary(image, asset.path); + auto id{ GenerateAssetID(AssetType::TEXTURE) }; + textureCollection.emplace(id, image); + + auto path{ SHTextureCompiler::CompileTextureBinary(image, asset.path) }; + + assetCollection.emplace_back( + image.name, + id, + AssetType::TEXTURE, + path, + 0 + ); } } @@ -344,8 +363,24 @@ namespace SHADE ****************************************************************************/ void SHAssetManager::LoadAllData() noexcept { + //TODO Remove when on demand loading is done for (auto const& asset : assetCollection) { + switch (asset.type) + { + case AssetType::MESH: + meshCollection.emplace(asset.id, SHMeshAsset()); + SHMeshLoader::LoadSHMesh(meshCollection[asset.id], asset.path); + break; + + case AssetType::TEXTURE: + textureCollection.emplace(asset.id, SHTextureAsset()); + SHTextureLoader::LoadSHTexture(asset.path, textureCollection[asset.id]); + break; + + default: + void; + } } } @@ -362,40 +397,51 @@ namespace SHADE std::vector metaFiles; std::vector AssetFiles; - //TODO: Write new function for file manager to loop through all files - SHFileSystem::StartupFillDirectories(ASSET_ROOT); - FolderPointer rootFolder = SHFileSystem::GetRoot(); - - for (auto const& meta : metaFiles) + for (auto const dir : std::filesystem::recursive_directory_iterator(ASSET_ROOT)) { - for (std::vector::const_iterator it{ AssetFiles.cbegin() }; - it != AssetFiles.cend(); - ++it) + if (dir.path().extension().string() == META_EXTENSION) { - // Asset exists for meta file - std::string fileExtCheck{ it->filename().string() }; - fileExtCheck += META_EXTENSION; - if (meta.filename().string() == fileExtCheck) - { - RegisterAsset(meta, *it); - AssetFiles.erase(it); - break; - } + auto meta{ SHAssetMetaHandler::RetrieveMetaData(dir.path()) }; + + assetCollection.push_back(meta); + assetRegistry.emplace(meta.id, meta); } } + //TODO: Write new function for file manager to loop through all files + //SHFileSystem::StartupFillDirectories(ASSET_ROOT); + //FolderPointer rootFolder = SHFileSystem::GetRoot(); + + //for (auto const& meta : metaFiles) + //{ + // for (std::vector::const_iterator it{ AssetFiles.cbegin() }; + // it != AssetFiles.cend(); + // ++it) + // { + // // Asset exists for meta file + // std::string fileExtCheck{ it->filename().string() }; + // fileExtCheck += META_EXTENSION; + // if (meta.filename().string() == fileExtCheck) + // { + // RegisterAsset(meta, *it); + // AssetFiles.erase(it); + // break; + // } + // } + //} + //TODO: Handle if meta does not match all assets (if meta exist and asset doesnt, vice versa) - for (auto const& file : AssetFiles) - { - if (IsRecognised(file.extension().string().c_str())) - { - SHAssetMetaHandler::WriteMetaData(RegisterAssetNew(file)); - } - else - { - std::cout << "Unsupported File Format: " << file.filename() << "\n"; - } - } + //for (auto const& file : AssetFiles) + //{ + // if (IsRecognised(file.extension().string().c_str())) + // { + // SHAssetMetaHandler::WriteMetaData(RegisterAssetNew(file)); + // } + // else + // { + // std::cout << "Unsupported File Format: " << file.filename() << "\n"; + // } + //} } AssetID SHAssetManager::RetrieveAsset(char const* path) noexcept diff --git a/SHADE_Engine/src/Assets/SHAssetMetaHandler.cpp b/SHADE_Engine/src/Assets/SHAssetMetaHandler.cpp index 6554a3e4..442c3d96 100644 --- a/SHADE_Engine/src/Assets/SHAssetMetaHandler.cpp +++ b/SHADE_Engine/src/Assets/SHAssetMetaHandler.cpp @@ -72,6 +72,13 @@ namespace SHADE std::string line; SHAsset meta; + // Get resource name + GetFieldValue(metaFile, line); + std::stringstream nameStream{ line }; + AssetName name; + nameStream >> name; + meta.name = name; + // Get resource id GetFieldValue(metaFile, line); std::stringstream idStream{ line }; @@ -88,6 +95,8 @@ namespace SHADE metaFile.close(); + meta.path = path.parent_path().string() + "/" + path.stem().string(); + return meta; } @@ -103,7 +112,7 @@ namespace SHADE std::string path{ meta.path.string() }; path.append(META_EXTENSION); - std::ofstream metaFile{ path, std::ios_base::out }; + std::ofstream metaFile{ path, std::ios_base::out | std::ios_base::trunc }; if (!metaFile.is_open()) { @@ -113,17 +122,17 @@ namespace SHADE metaFile << "Name: " << meta.name << "\n"; metaFile << "ID: " << meta.id << "\n"; - metaFile << "Type: " << static_cast(meta.type) << std::endl; + metaFile << "Type: " << static_cast(meta.type) << std::endl; - //TODO Add in information that is specific to types like mesh - switch(meta.type) - { - case AssetType::MESH: - break; + ////TODO Add in information that is specific to types like mesh + //switch(meta.type) + //{ + //case AssetType::MESH: + // break; - default: - break; - } + //default: + // break; + //} metaFile.close(); } From 013bb713258fafbe46917380763ec0beaf76b05b Mon Sep 17 00:00:00 2001 From: Xiao Qi Date: Mon, 17 Oct 2022 15:04:38 +0800 Subject: [PATCH 3/3] Functions to retrieve mesh and texture data --- SHADE_Engine/src/Assets/SHAssetManager.cpp | 20 ++++++++++++++++++++ SHADE_Engine/src/Assets/SHAssetManager.h | 2 ++ 2 files changed, 22 insertions(+) diff --git a/SHADE_Engine/src/Assets/SHAssetManager.cpp b/SHADE_Engine/src/Assets/SHAssetManager.cpp index e3578f92..aa9772dd 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.cpp +++ b/SHADE_Engine/src/Assets/SHAssetManager.cpp @@ -255,6 +255,26 @@ namespace SHADE return result; } + SHMeshAsset const* SHAssetManager::GetMesh(AssetID id) noexcept + { + if (meshCollection.find(id) == meshCollection.end()) + { + return nullptr; + } + + return &meshCollection[id]; + } + + SHTextureAsset const* SHAssetManager::GetTexture(AssetID id) noexcept + { + if (textureCollection.find(id) == textureCollection.end()) + { + return nullptr; + } + + return &textureCollection[id]; + } + /**************************************************************************** * \param Path for meta data file * \param Path for asset file diff --git a/SHADE_Engine/src/Assets/SHAssetManager.h b/SHADE_Engine/src/Assets/SHAssetManager.h index 7064d63d..50549e01 100644 --- a/SHADE_Engine/src/Assets/SHAssetManager.h +++ b/SHADE_Engine/src/Assets/SHAssetManager.h @@ -75,6 +75,8 @@ namespace SHADE static std::vector GetAllMeshes() noexcept; static std::vector GetAllTextures() noexcept; + static SHMeshAsset const* GetMesh(AssetID id) noexcept; + static SHTextureAsset const* GetTexture(AssetID id) noexcept; private: /**************************************************************************** * \brief Load resource data into memory