diff --git a/RM_Test/Asset.cpp b/RM_Test/Asset.cpp new file mode 100644 index 0000000..488497e --- /dev/null +++ b/RM_Test/Asset.cpp @@ -0,0 +1,10 @@ +#include "Asset.h" + +// Constructor implementation +Asset::Asset(const std::string& assetId) : id(assetId) {} + +// Virtual destructor implementation +Asset::~Asset() = default; + +// Getter implementation +std::string Asset::getId() const { return id; } diff --git a/RM_Test/Asset.h b/RM_Test/Asset.h new file mode 100644 index 0000000..8197784 --- /dev/null +++ b/RM_Test/Asset.h @@ -0,0 +1,21 @@ +#pragma once +#include + +class Asset { +protected: + // Unique identifier for the asset + std::string id; + +public: + // Constructor with an asset identifier + Asset(const std::string& assetId); + + // Virtual destructor to ensure proper cleanup in derived classes + virtual ~Asset(); + + // Pure virtual function for loading the asset + virtual void load() = 0; + + // Getter for the asset ID + std::string getId() const; +}; \ No newline at end of file diff --git a/RM_Test/GameLoop.cpp b/RM_Test/GameLoop.cpp new file mode 100644 index 0000000..deeef20 --- /dev/null +++ b/RM_Test/GameLoop.cpp @@ -0,0 +1,33 @@ +#include "GameLoop.h" +#include + +#include "SoundAsset.h" + +void GameLoop::initialize() { + std::cout << "Initializing game resources..." << std::endl; + resource_manager = new ResourceManager(); + resource_manager->loadResource("player_texture"); + resource_manager->loadResource("background_music"); +} + +void GameLoop::update() { + std::cout << "Updating game logic..." << std::endl; +} + +void GameLoop::render() { + std::cout << "Rendering game..." << std::endl; +} + +void GameLoop::shutdown() { + std::cout << "Shutting down the game..." << std::endl; + delete resource_manager; +} + +void GameLoop::run() { + while (isRunning) { + update(); + render(); + isRunning = false; // For now, we'll shut down after one iteration + } + shutdown(); +} diff --git a/RM_Test/GameLoop.h b/RM_Test/GameLoop.h new file mode 100644 index 0000000..43400d6 --- /dev/null +++ b/RM_Test/GameLoop.h @@ -0,0 +1,15 @@ +#pragma once +#include "ResourceManager.h" + +class GameLoop { +public: + void initialize(); + void update(); + void render(); + void shutdown(); + void run(); + +private: + ResourceManager* resource_manager = nullptr; + bool isRunning = true; +}; diff --git a/RM_Test/RM_Test.sln b/RM_Test/RM_Test.sln new file mode 100644 index 0000000..5dacbc1 --- /dev/null +++ b/RM_Test/RM_Test.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "RM_Test", "RM_Test.vcxproj", "{D9098475-14D1-4F6A-9665-A2513CE60411}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {D9098475-14D1-4F6A-9665-A2513CE60411}.Debug|Win32.ActiveCfg = Debug|Win32 + {D9098475-14D1-4F6A-9665-A2513CE60411}.Debug|Win32.Build.0 = Debug|Win32 + {D9098475-14D1-4F6A-9665-A2513CE60411}.Debug|x64.ActiveCfg = Debug|x64 + {D9098475-14D1-4F6A-9665-A2513CE60411}.Debug|x64.Build.0 = Debug|x64 + {D9098475-14D1-4F6A-9665-A2513CE60411}.Release|Win32.ActiveCfg = Release|Win32 + {D9098475-14D1-4F6A-9665-A2513CE60411}.Release|Win32.Build.0 = Release|Win32 + {D9098475-14D1-4F6A-9665-A2513CE60411}.Release|x64.ActiveCfg = Release|x64 + {D9098475-14D1-4F6A-9665-A2513CE60411}.Release|x64.Build.0 = Release|x64 + EndGlobalSection +EndGlobal diff --git a/RM_Test/RM_Test.vcxproj b/RM_Test/RM_Test.vcxproj new file mode 100644 index 0000000..2502ae7 --- /dev/null +++ b/RM_Test/RM_Test.vcxproj @@ -0,0 +1,175 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {D9098475-14D1-4F6A-9665-A2513CE60411} + Win32Proj + RM_Test + 10.0 + + + + x64 + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + NotUsing + Level3 + Disabled + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + pch.h + + + Console + true + + + + + NotUsing + Level3 + Disabled + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + pch.h + + + Console + true + + + + + NotUsing + Level3 + MaxSpeed + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + pch.h + + + Console + true + true + true + + + + + NotUsing + Level3 + MaxSpeed + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + pch.h + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/RM_Test/RM_Test.vcxproj.filters b/RM_Test/RM_Test.vcxproj.filters new file mode 100644 index 0000000..d5fffd7 --- /dev/null +++ b/RM_Test/RM_Test.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + \ No newline at end of file diff --git a/RM_Test/ResourceManager.cpp b/RM_Test/ResourceManager.cpp new file mode 100644 index 0000000..c1eccc7 --- /dev/null +++ b/RM_Test/ResourceManager.cpp @@ -0,0 +1,24 @@ +#include "ResourceManager.h" +#include + +// Destructor: Clean up all resources +ResourceManager::~ResourceManager() { unloadAllResources(); } + +// Unload a specific resource by its ID +void ResourceManager::unloadResource(const std::string& id) +{ + auto iterator = assets.find(id); + if (iterator != assets.end()) + { + delete iterator->second; // Delete the resource + assets.erase(iterator); // Remove it from the map + std::cout << "Resource " << id << " unloaded." << std::endl; + } +} + +// Unload all resources +void ResourceManager::unloadAllResources() +{ + assets.clear(); // Clear the map + std::cout << "All resources unloaded." << std::endl; +} diff --git a/RM_Test/ResourceManager.h b/RM_Test/ResourceManager.h new file mode 100644 index 0000000..b574c8e --- /dev/null +++ b/RM_Test/ResourceManager.h @@ -0,0 +1,27 @@ +#pragma once +#include +#include "TextureAsset.h" + +class ResourceManager { +private: + std::map assets; + +public: + ResourceManager() = default; + ~ResourceManager(); + + template + T* findResource(const std::string& id); + template + T* createResource(const std::string& id); + template + T* loadResource(const std::string& id); + template + T* getResource(const std::string& id); + + // Non-template methods for unloading resources + void unloadResource(const std::string& id); + void unloadAllResources(); +}; + +#include "ResourceManager.inl" \ No newline at end of file diff --git a/RM_Test/ResourceManager.inl b/RM_Test/ResourceManager.inl new file mode 100644 index 0000000..9fb5133 --- /dev/null +++ b/RM_Test/ResourceManager.inl @@ -0,0 +1,48 @@ +#pragma once +#include + +// Load a resource or create it if it doesn't exist +template +T* ResourceManager::loadResource(const std::string& id) +{ + // Check if the resource is already loaded + auto existingResource = findResource(id); + + if (existingResource) + return existingResource; // Return the already loaded resource + + // Create a new resource if not found + return createResource(id); +} + +// Public function to get an already loaded resource by id +template +T* ResourceManager::getResource(const std::string& id) +{ + auto resource = findResource(id); + + if (resource == nullptr) + std::cout << "Resource not found: " << id; // Resource doesn't exist + + return resource; +} + +// Find a resource in the map +template +T* ResourceManager::findResource(const std::string& id) { + auto iterator = assets.find(id); + if (iterator != assets.end()) { + // Use dynamic_cast to ensure type safety + return dynamic_cast(iterator->second); + } + return nullptr; +} + +// Create and store a new resource in the map +template +T* ResourceManager::createResource(const std::string& id) { + T* resource = new T(id); // Create the resource + resource->load(); // Assuming T has a load() function + assets[id] = resource; // Add the resource to the map + return resource; +} diff --git a/RM_Test/SoundAsset.cpp b/RM_Test/SoundAsset.cpp new file mode 100644 index 0000000..eb81c12 --- /dev/null +++ b/RM_Test/SoundAsset.cpp @@ -0,0 +1,11 @@ +#include "SoundAsset.h" +#include + +// Constructor implementation +SoundAsset::SoundAsset(const std::string& assetId) : Asset(assetId) {} + +// Implement the load function specific to sounds +void SoundAsset::load() { + std::cout << "Loading sound: " << id << std::endl; + // Simulate sound file loading +} \ No newline at end of file diff --git a/RM_Test/SoundAsset.h b/RM_Test/SoundAsset.h new file mode 100644 index 0000000..b312a6c --- /dev/null +++ b/RM_Test/SoundAsset.h @@ -0,0 +1,11 @@ +#pragma once +#include "Asset.h" + +class SoundAsset : public Asset { +public: + // Constructor + SoundAsset(const std::string& assetId); + + // Override the load function specific to sounds + void load() override; +}; \ No newline at end of file diff --git a/RM_Test/TextureAsset.cpp b/RM_Test/TextureAsset.cpp new file mode 100644 index 0000000..05be287 --- /dev/null +++ b/RM_Test/TextureAsset.cpp @@ -0,0 +1,11 @@ +#include "TextureAsset.h" +#include + +// Constructor implementation +TextureAsset::TextureAsset(const std::string& assetId) : Asset(assetId) {} + +// Implement the load function specific to textures +void TextureAsset::load() { + // Simulate texture loading from file + std::cout << "Loading texture: " << id << std::endl; +} \ No newline at end of file diff --git a/RM_Test/TextureAsset.h b/RM_Test/TextureAsset.h new file mode 100644 index 0000000..cec379b --- /dev/null +++ b/RM_Test/TextureAsset.h @@ -0,0 +1,11 @@ +#pragma once +#include "Asset.h" + +class TextureAsset : public Asset { +public: + // Constructor + TextureAsset(const std::string& assetId); + + // Override the load function specific to textures + void load() override; +}; \ No newline at end of file diff --git a/RM_Test/main.cpp b/RM_Test/main.cpp new file mode 100644 index 0000000..0d96ac6 --- /dev/null +++ b/RM_Test/main.cpp @@ -0,0 +1,8 @@ +#include "GameLoop.h" + +int main() { + GameLoop gameLoop; + gameLoop.initialize(); + gameLoop.run(); // Start the game loop + return 0; +}