port from perforce

This commit is contained in:
2026-04-18 22:31:51 +02:00
commit 8d0ab5b7cc
8409 changed files with 3972376 additions and 0 deletions

View File

@@ -0,0 +1,302 @@
#include "stdafx.h"
#include "ResourceFactory.h"
#include <algorithm>
ResourceFactory::ResourceFactory(IEngine& argEngine)
: m_Engine(argEngine)
, m_LastCallCreatedResource(false)
{
}
ResourceFactory::~ResourceFactory()
{
this->ClearInternal(m_Windows);
this->ClearInternal(m_RenderCommandNodes);
this->ClearInternal(m_ShaderPool);
this->ClearInternal(m_InternalShaderPool);
this->ClearInternal(m_GeometryBufferPool);
this->ClearInternal(m_SwapChainPool);
this->ClearInternal(m_RenderTargetTexturePool);
this->ClearInternal(m_TransformationPool);
this->ClearInternal(m_PerspectiveCameraPool);
this->ClearInternal(m_OrthographicCameraPool);
this->ClearInternal(m_BonePool);
this->ClearInternal(m_BoneControllerPool);
this->ClearInternal(m_ShaderParameterCollectionPool);
}
ITransformationAnimation& ResourceFactory::CreateTransformationAnimation()
{
ITransformationAnimation* var = new TransformationAnimation(m_Engine);
m_TransformationAnimations.push_back(var);
return *var;
}
void ResourceFactory::DeleteTransformationAnimation(ITransformationAnimation& argValue, bool argRemoveOnly)
{
std::vector<ITransformationAnimation*>::iterator iter = std::find(m_TransformationAnimations.begin(), m_TransformationAnimations.end(), &argValue);
if (iter != m_TransformationAnimations.end())
{
m_TransformationAnimations.erase(iter);
if (!argRemoveOnly)
delete &argValue;
}
}
IWindow& ResourceFactory::CreateSwapChainWindow()
{
IWindow* window = new Window(m_Engine);
m_Windows.push_back(window);
return *window;
}
void ResourceFactory::DeleteSwapChainWindow(IWindow& argValue, bool argRemoveOnly)
{
std::vector<IWindow*>::iterator iter = std::find(m_Windows.begin(), m_Windows.end(), &argValue);
if (iter != m_Windows.end())
{
m_Windows.erase(iter);
if (!argRemoveOnly)
delete &argValue;
}
}
IRenderCommandNode& ResourceFactory::CreateRenderCommandNode()
{
IRenderCommandNode* node = new RenderCommandNode(m_Engine);
m_RenderCommandNodes.push_back(node);
return *node;
}
void ResourceFactory::DeleteRenderCommandNode(IRenderCommandNode& argValue, bool argRemoveOnly)
{
std::vector<IRenderCommandNode*>::iterator iter = std::find(m_RenderCommandNodes.begin(), m_RenderCommandNodes.end(), &argValue);
if (iter != m_RenderCommandNodes.end())
{
m_RenderCommandNodes.erase(iter);
if (!argRemoveOnly)
delete &argValue;
}
}
IShader* ResourceFactory::FindShader(const string8& argId)
{
return this->FindInternal(m_ShaderPool, argId);
}
IShader& ResourceFactory::CreateOrFindShader(const string8& argId)
{
return *this->CreateOrFindInternal(m_ShaderPool, argId);
}
void ResourceFactory::DeleteShader(IShader& argValue, bool argRemoveOnly)
{
this->DeleteInternal(m_ShaderPool, argValue, argRemoveOnly);
}
IInternalShader* ResourceFactory::FindInternalShader(const string8& argId)
{
return this->FindInternal(m_InternalShaderPool, argId);
}
IInternalShader& ResourceFactory::CreateOrFindInternalShader(const string8& argId)
{
return *this->CreateOrFindInternal(m_InternalShaderPool, argId);
}
void ResourceFactory::DeleteInternalShader(IInternalShader& argValue, bool argRemoveOnly)
{
this->DeleteInternal(m_InternalShaderPool, argValue, argRemoveOnly);
}
ISwapChain* ResourceFactory::FindSwapChain(const string8& argId)
{
return this->FindInternal(m_SwapChainPool, argId);
}
ISwapChain& ResourceFactory::CreateOrFindSwapChain(const string8& argId)
{
return *this->CreateOrFindInternal(m_SwapChainPool, argId);
}
void ResourceFactory::DeleteSwapChain(ISwapChain& argValue, bool argRemoveOnly)
{
this->DeleteInternal(m_SwapChainPool, argValue, argRemoveOnly);
}
IRenderTargetTexture* ResourceFactory::FindRenderTargetTexture(const string8& argId)
{
return this->FindInternal(m_RenderTargetTexturePool, argId);
}
IRenderTargetTexture& ResourceFactory::CreateOrFindRenderTargetTexture(const string8& argId)
{
return *this->CreateOrFindInternal(m_RenderTargetTexturePool, argId);
}
void ResourceFactory::DeleteRenderTargetTexture(IRenderTargetTexture& argValue, bool argRemoveOnly)
{
this->DeleteInternal(m_RenderTargetTexturePool, argValue, argRemoveOnly);
}
IGeometryBuffer* ResourceFactory::FindGeometryBuffer(const string8& argId)
{
return this->FindInternal(m_GeometryBufferPool, argId);
}
IGeometryBuffer& ResourceFactory::CreateOrFindGeometryBuffer(const string8& argId)
{
return *this->CreateOrFindInternal(m_GeometryBufferPool, argId);
}
void ResourceFactory::DeleteGeometryBuffer(IGeometryBuffer& argValue, bool argRemoveOnly)
{
this->DeleteInternal(m_GeometryBufferPool, argValue, argRemoveOnly);
}
IShaderParameterCollection* ResourceFactory::FindShaderParameterCollection(const string8& argId)
{
return this->FindInternal(m_ShaderParameterCollectionPool, argId);
}
IShaderParameterCollection& ResourceFactory::CreateOrFindShaderParameterCollection(const string8& argId)
{
return *this->CreateOrFindInternal(m_ShaderParameterCollectionPool, argId);
}
void ResourceFactory::DeleteShaderParameterCollection(IShaderParameterCollection& argValue, bool argRemoveOnly)
{
this->DeleteInternal(m_ShaderParameterCollectionPool, argValue, argRemoveOnly);
}
ITexture* ResourceFactory::FindTexture(const string8& argId)
{
return this->FindInternal(m_TexturePool, argId);
}
ITexture& ResourceFactory::CreateOrFindTexture(const string8& argId)
{
return *this->CreateOrFindInternal(m_TexturePool, argId);
}
void ResourceFactory::DeleteTexture(ITexture& argValue, bool argRemoveOnly)
{
this->DeleteInternal(m_TexturePool, argValue, argRemoveOnly);
}
ITransformation* ResourceFactory::FindTransformation(const string8& argId)
{
return this->FindInternal(m_TransformationPool, argId);
}
ITransformation& ResourceFactory::CreateOrFindTransformation(const string8& argId)
{
return *this->CreateOrFindInternal(m_TransformationPool, argId);
}
void ResourceFactory::DeleteTransformation(ITransformation& argValue, bool argRemoveOnly)
{
this->DeleteInternal(m_TransformationPool, argValue, argRemoveOnly);
}
IPerspectiveCamera* ResourceFactory::FindPerspectiveCamera(const string8& argId)
{
return this->FindInternal(m_PerspectiveCameraPool, argId);
}
IPerspectiveCamera& ResourceFactory::CreateOrFindPerspectiveCamera(const string8& argId)
{
return *this->CreateOrFindInternal(m_PerspectiveCameraPool, argId);
}
void ResourceFactory::DeletePerspectiveCamera(IPerspectiveCamera& argValue, bool argRemoveOnly)
{
this->DeleteInternal(m_PerspectiveCameraPool, argValue, argRemoveOnly);
}
IOrthographicCamera* ResourceFactory::FindOrthographicCamera(const string8& argId)
{
return this->FindInternal(m_OrthographicCameraPool, argId);
}
IOrthographicCamera& ResourceFactory::CreateOrFindOrthographicCamera(const string8& argId)
{
return *this->CreateOrFindInternal(m_OrthographicCameraPool, argId);
}
void ResourceFactory::DeleteOrthographicCamera(IOrthographicCamera& argValue, bool argRemoveOnly)
{
this->DeleteInternal(m_OrthographicCameraPool, argValue, argRemoveOnly);
}
IBone* ResourceFactory::FindBone(const string8& argId)
{
return this->FindInternal(m_BonePool, argId);
}
IBone& ResourceFactory::CreateOrFindBone(const string8& argId)
{
return *this->CreateOrFindInternal(m_BonePool, argId);
}
void ResourceFactory::DeleteBone(IBone& argValue, bool argRemoveOnly)
{
this->DeleteInternal(m_BonePool, argValue, argRemoveOnly);
}
IBoneController* ResourceFactory::FindBoneController(const string8& argId)
{
return this->FindInternal(m_BoneControllerPool, argId);
}
IBoneController& ResourceFactory::CreateOrFindBoneController(const string8& argId)
{
return *this->CreateOrFindInternal(m_BoneControllerPool, argId);
}
void ResourceFactory::DeleteBoneController(IBoneController& argValue, bool argRemoveOnly)
{
this->DeleteInternal(m_BoneControllerPool, argValue, argRemoveOnly);
}

View File

@@ -0,0 +1,200 @@
#pragma once
#include <sstream>
#include "IEngine.h"
#include "IResourceFactory.h"
#include "../Resources/RenderTarget/SwapChain/SwapChain.h"
#include "../Resources/RenderTarget/RenderTargetTexture/RenderTargetTexture.h"
#include "../Resources/GeometryBuffer/GeometryBuffer.h"
#include "../Resources/Shader/Shader.h"
#include "../Resources/Shader/InternalShader.h"
#include "../Resources/RenderCommandNode/RenderCommandNode.h"
#include "../Resources/ShaderParameterCollection/ShaderParameterCollection.h"
#include "../Resources/Texture/Texture.h"
#include "../Resources/Transformation/Transformation.h"
#include "../Resources/TransformationAnimation/TransformationAnimation.h"
#include "../Resources/Camera/OrthographicCamera.h"
#include "../Resources/Camera/PerspectiveCamera.h"
#include "../Resources/Bone/Bone.h"
#include "../Resources/Bone/BoneController.h"
#include "../Window/Window.h"
class ResourceFactory
: public IResourceFactory
{
public:
ResourceFactory(IEngine& argEngine);
virtual ~ResourceFactory();
virtual ITransformationAnimation& CreateTransformationAnimation();
virtual void DeleteTransformationAnimation(ITransformationAnimation& argValue, bool argRemoveOnly = false);
virtual IWindow& CreateSwapChainWindow();
virtual void DeleteSwapChainWindow(IWindow& argValue, bool argRemoveOnly = false);
virtual IRenderCommandNode& CreateRenderCommandNode();
virtual void DeleteRenderCommandNode(IRenderCommandNode& argValue, bool argRemoveOnly = false);
virtual IShader* FindShader(const string8& argId);
virtual IShader& CreateOrFindShader(const string8& argId = "");
virtual void DeleteShader(IShader& argValue, bool argRemoveOnly = false);
virtual IInternalShader* FindInternalShader(const string8& argId);
virtual IInternalShader& CreateOrFindInternalShader(const string8& argId = "");
virtual void DeleteInternalShader(IInternalShader& argValue, bool argRemoveOnly = false);
virtual ISwapChain* FindSwapChain(const string8& argId);
virtual ISwapChain& CreateOrFindSwapChain(const string8& argId = "");
virtual void DeleteSwapChain(ISwapChain& argValue, bool argRemoveOnly = false);
virtual IRenderTargetTexture* FindRenderTargetTexture(const string8& argId);
virtual IRenderTargetTexture& CreateOrFindRenderTargetTexture(const string8& argId = "");
virtual void DeleteRenderTargetTexture(IRenderTargetTexture& argValue, bool argRemoveOnly = false);
virtual IGeometryBuffer* FindGeometryBuffer(const string8& argId);
virtual IGeometryBuffer& CreateOrFindGeometryBuffer(const string8& argId = "");
virtual void DeleteGeometryBuffer(IGeometryBuffer& argValue, bool argRemoveOnly = false);
virtual IShaderParameterCollection* FindShaderParameterCollection(const string8& argId);
virtual IShaderParameterCollection& CreateOrFindShaderParameterCollection(const string8& argId = "");
virtual void DeleteShaderParameterCollection(IShaderParameterCollection& argValue, bool argRemoveOnly = false);
virtual ITexture* FindTexture(const string8& argId);
virtual ITexture& CreateOrFindTexture(const string8& argId = "");
virtual void DeleteTexture(ITexture& argValue, bool argRemoveOnly = false);
virtual ITransformation* FindTransformation(const string8& argId);
virtual ITransformation& CreateOrFindTransformation(const string8& argId = "");
virtual void DeleteTransformation(ITransformation& argValue, bool argRemoveOnly = false);
virtual IPerspectiveCamera* FindPerspectiveCamera(const string8& argId);
virtual IPerspectiveCamera& CreateOrFindPerspectiveCamera(const string8& argId = "");
virtual void DeletePerspectiveCamera(IPerspectiveCamera& argValue, bool argRemoveOnly = false);
virtual IOrthographicCamera* FindOrthographicCamera(const string8& argId);
virtual IOrthographicCamera& CreateOrFindOrthographicCamera(const string8& argId = "");
virtual void DeleteOrthographicCamera(IOrthographicCamera& argValue, bool argRemoveOnly = false);
virtual IBone* FindBone(const string8& argId);
virtual IBone& CreateOrFindBone(const string8& argId = "");
virtual void DeleteBone(IBone& argValue, bool argRemoveOnly = false);
virtual IBoneController* FindBoneController(const string8& argId);
virtual IBoneController& CreateOrFindBoneController(const string8& argId = "");
virtual void DeleteBoneController(IBoneController& argValue, bool argRemoveOnly = false);
virtual bool HasCreatedResource() { return m_LastCallCreatedResource; }
protected:
template<typename A, typename B> void DeleteInternal(std::map<string8, A*>& argPool, B& argWhich, bool argRemoveOnly)
{
A* valueA = dynamic_cast<A*>(&argWhich);
for (std::map<string8, A*>::iterator iter = argPool.begin(); iter != argPool.end(); ++iter)
if (iter->second == valueA)
{
ICommandUser* commandUser = dynamic_cast<ICommandUser*>(iter->second);
if (commandUser != NULL)
std::cout << "Deleting \"" << std::green << iter->first << std::white << "\" [" << commandUser->get_UserName() << "]" << std::endl;
argPool.erase(iter);
if (!argRemoveOnly)
delete valueA;
return;
}
}
template<typename T> void ClearInternal(std::map<string8, T*>& argPool)
{
while (!argPool.empty())
{
ICommandUser* commandUser = dynamic_cast<ICommandUser*>(argPool.begin()->second);
if (commandUser != NULL)
std::cout << "Deleting \"" << std::green << argPool.begin()->first << std::white << "\" [" << commandUser->get_UserName() << "]" << std::endl;
T* valueA = argPool.begin()->second;
argPool.erase(argPool.begin());
delete valueA;
}
}
template<typename T> void ClearInternal(std::vector<T*>& argPool)
{
while (!argPool.empty())
{
delete *argPool.begin();
argPool.erase(argPool.begin());
}
}
template<typename T> T* FindInternal(std::map<string8, T*>& argPool, const string8& argId)
{
m_LastCallCreatedResource = false;
if (argPool.find(argId) == argPool.end())
return NULL;
return argPool[argId];
}
template<typename T> string8 CreateUniqueName(std::map<string8, T*>& argPool, const string8& argPrefix = "")
{
int NameIndex = argPool.size();
std::stringstream CurrentName;
do
{
CurrentName.flush();
CurrentName << argPrefix << NameIndex++;
}
while (FindInternal(argPool, CurrentName.str()) != NULL);
return CurrentName.str();
}
template<typename T> T* CreateOrFindInternal(std::map<string8, T*>& argPool, const string8& argId)
{
std::string currentId = argId;
if (currentId.empty())
currentId = CreateUniqueName(argPool);
T* instance = this->FindInternal(argPool, currentId);
if (instance != NULL)
return instance;
m_LastCallCreatedResource = true;
instance = new T(m_Engine);
ICommandUser* commandUser = dynamic_cast<ICommandUser*>(instance);
if (commandUser != NULL)
std::cout << "Creating \"" << std::green << currentId << std::white << "\" [" << commandUser->get_UserName() << "]" << std::endl;
argPool[currentId] = instance;
return instance;
}
private:
IEngine& m_Engine;
std::map<string8, InternalShader*> m_InternalShaderPool;
std::map<string8, Shader*> m_ShaderPool;
std::map<string8, GeometryBuffer*> m_GeometryBufferPool;
std::map<string8, SwapChain*> m_SwapChainPool;
std::map<string8, RenderTargetTexture*> m_RenderTargetTexturePool;
std::map<string8, ShaderParameterCollection*> m_ShaderParameterCollectionPool;
std::map<string8, Texture*> m_TexturePool;
std::map<string8, Transformation*> m_TransformationPool;
std::map<string8, OrthographicCamera*> m_OrthographicCameraPool;
std::map<string8, PerspectiveCamera*> m_PerspectiveCameraPool;
std::map<string8, Bone*> m_BonePool;
std::map<string8, BoneController*> m_BoneControllerPool;
std::vector<IRenderCommandNode*> m_RenderCommandNodes;
std::vector<IWindow*> m_Windows;
std::vector<ITransformationAnimation*> m_TransformationAnimations;
bool m_LastCallCreatedResource;
};