Merge branch 'MiscBranch' of https://github.com/dean11/Danbias into Graphics
This commit is contained in:
commit
205c58430f
|
@ -69,21 +69,29 @@
|
|||
<OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
|
||||
<IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
|
||||
<IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>C:\Program Files %28x86%29\Visual Leak Detector\lib\Win32;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
|
||||
<IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>C:\Program Files %28x86%29\Visual Leak Detector\lib\Win64;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<OutDir>$(SolutionDir)..\External\Lib\$(ProjectName)\</OutDir>
|
||||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
|
||||
<IncludePath>C:\Program Files %28x86%29\Visual Leak Detector\include;$(IncludePath)</IncludePath>
|
||||
<LibraryPath>C:\Program Files %28x86%29\Visual Leak Detector\lib\Win64;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
|
@ -138,10 +146,16 @@
|
|||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Resource\Loaders\Textloader.cpp" />
|
||||
<ClCompile Include="Resource\OResourceHandler.cpp" />
|
||||
<ClCompile Include="Resource\OResource.cpp" />
|
||||
<ClCompile Include="Utilities.cpp" />
|
||||
<ClCompile Include="WinTimer.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Resource\OResourceHandler.h" />
|
||||
<ClInclude Include="Resource\OysterResource.h" />
|
||||
<ClInclude Include="Resource\OResource.h" />
|
||||
<ClInclude Include="Utilities-InlineImpl.h" />
|
||||
<ClInclude Include="Utilities.h" />
|
||||
<ClInclude Include="WinTimer.h" />
|
||||
|
|
|
@ -21,6 +21,15 @@
|
|||
<ClCompile Include="WinTimer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Resource\Loaders\Textloader.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Resource\OResource.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Resource\OResourceHandler.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Utilities.h">
|
||||
|
@ -32,5 +41,14 @@
|
|||
<ClInclude Include="Utilities-InlineImpl.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Resource\OysterResource.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Resource\OResource.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Resource\OResourceHandler.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,156 @@
|
|||
|
||||
#include "..\OResource.h"
|
||||
#include "..\..\Utilities.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
using namespace Oyster::Resource;
|
||||
bool readANSI = false;
|
||||
|
||||
|
||||
|
||||
bool ReadFromFile(const wchar_t fileName[], const wchar_t openFlag[], std::wstring& outData, size_t elemSize)
|
||||
{
|
||||
size_t bytesTotal = 0;
|
||||
size_t bytesRead = 0;
|
||||
FILE *stream;
|
||||
|
||||
if( _wfopen_s( &stream, fileName, openFlag ) == 0 )
|
||||
{
|
||||
//Get size of the file
|
||||
fseek(stream, 0L, SEEK_END);
|
||||
bytesTotal = ftell(stream);
|
||||
fseek(stream, 0L, SEEK_SET);
|
||||
|
||||
//Sanity check
|
||||
if(bytesTotal == 0) return false;
|
||||
|
||||
//Create the new byte buffer
|
||||
wchar_t *buff = new wchar_t[bytesTotal + 1];
|
||||
|
||||
//Read the bytes to the end
|
||||
bytesRead = fread_s( buff, bytesTotal, elemSize, bytesTotal ,stream );
|
||||
fclose( stream );
|
||||
|
||||
//Did we read enough bytes
|
||||
if(!readANSI && bytesRead != bytesTotal) return false;
|
||||
|
||||
//Add delimiter
|
||||
buff[bytesRead] = L'\0';
|
||||
|
||||
outData.resize(bytesTotal);
|
||||
outData = buff;
|
||||
|
||||
delete [] buff;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::wstring msg = L"Failed to open file: \n";
|
||||
msg.append(fileName);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
bool ReadFromFile(const wchar_t fileName[], const char openFlag[], std::string& outData, size_t elemSize)
|
||||
{
|
||||
std::string sFilename;
|
||||
std::wstring wsFile = fileName;
|
||||
::Utility::String::WStringToString(wsFile, sFilename);
|
||||
size_t bytesTotal = 0;
|
||||
size_t bytesRead = 0;
|
||||
FILE *stream;
|
||||
|
||||
if( fopen_s( &stream, sFilename.c_str(), openFlag ) == 0 )
|
||||
{
|
||||
//Get size of the file
|
||||
fseek(stream, 0L, SEEK_END);
|
||||
bytesTotal = ftell(stream);
|
||||
fseek(stream, 0L, SEEK_SET);
|
||||
fflush(stream);
|
||||
|
||||
//Sanity check
|
||||
if(bytesTotal == 0) return false;
|
||||
|
||||
//Create the new byte buffer
|
||||
char *buff = new char[bytesTotal + 1];
|
||||
|
||||
//Read the bytes to the end
|
||||
bytesRead = fread_s( buff, bytesTotal, elemSize, bytesTotal ,stream );
|
||||
fclose( stream );
|
||||
|
||||
//Did we read enough bytes (Get the bytes if we read with ANSI since the hidden characters is ignored)
|
||||
if(!readANSI && bytesRead != bytesTotal) return false;
|
||||
|
||||
buff[bytesRead + 1];
|
||||
|
||||
outData.clear();
|
||||
outData.resize(bytesRead);
|
||||
memcpy(&outData[0], &buff[0], bytesRead);
|
||||
|
||||
delete [] buff;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string msg = "Failed to open file: \n";
|
||||
msg.append(sFilename.c_str());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
OResource* OResource::ByteLoader(const wchar_t filename[], ResourceType type)
|
||||
{
|
||||
OResource *resource = 0;
|
||||
std::wstring wOut;
|
||||
std::string sOut;
|
||||
bool success = false;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case Oyster::Resource::ResourceType_UNKNOWN:
|
||||
case Oyster::Resource::ResourceType_Byte_Raw:
|
||||
success = ReadFromFile(filename, "rb", sOut, sizeof(char));
|
||||
break;
|
||||
|
||||
case Oyster::Resource::ResourceType_Byte_ANSI:
|
||||
readANSI = true;
|
||||
success = ReadFromFile(filename, "r", sOut, sizeof(char));
|
||||
readANSI = false;
|
||||
break;
|
||||
|
||||
case Oyster::Resource::ResourceType_Byte_UTF8:
|
||||
success = ReadFromFile(filename, "r, ccs=UTF-8", sOut, sizeof(char));
|
||||
break;
|
||||
|
||||
case Oyster::Resource::ResourceType_Byte_UNICODE:
|
||||
success = ReadFromFile(filename, "r, ccs=UNICODE", sOut, sizeof(char));
|
||||
break;
|
||||
|
||||
case Oyster::Resource::ResourceType_Byte_UTF16LE:
|
||||
success = ReadFromFile(filename, "r, ccs=UTF-16LE", sOut, sizeof(char));
|
||||
break;
|
||||
}
|
||||
|
||||
if(!success) return 0;
|
||||
if(wOut.size())
|
||||
{
|
||||
//const wchar_t *data = new wchar_t[wOut.size()];
|
||||
//resource = new OResource((void*)data, type, (sizeof(wchar_t) * wOut.size()), sizeof(wchar_t), filename);
|
||||
}
|
||||
else if(sOut.size())
|
||||
{
|
||||
char *data = new char[sOut.size()+1];
|
||||
data[sOut.size()] = '\0';
|
||||
memcpy(&data[0], &sOut[0], sOut.size());
|
||||
resource = new OResource((OHRESOURCE)data, type, (sizeof(char) * sOut.size()), sizeof(char), filename);
|
||||
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
#include "OResource.h"
|
||||
|
||||
using namespace Oyster::Resource;
|
||||
|
||||
OResource::OResource(OHRESOURCE handle, ResourceType type, size_t resourceSize, size_t elementSize, ::std::wstring filename)
|
||||
: resourceData (handle)
|
||||
, resourceFilename (filename)
|
||||
, resourceSize (resourceSize)
|
||||
, resourceElementSize (elementSize)
|
||||
, resourceType (type)
|
||||
{
|
||||
|
||||
}
|
||||
OResource::~OResource()
|
||||
{}
|
||||
|
||||
bool OResource::Release()
|
||||
{
|
||||
if(this->resourceRef.Decref() == 0)
|
||||
{
|
||||
Remove(this->resourceType, this->resourceData);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void OResource::Remove(ResourceType t, OHRESOURCE& r)
|
||||
{
|
||||
switch (t)
|
||||
{
|
||||
case Oyster::Resource::ResourceType_Texture_PNG:
|
||||
case Oyster::Resource::ResourceType_Texture_DDS:
|
||||
case Oyster::Resource::ResourceType_Texture_JPG:
|
||||
|
||||
break;
|
||||
|
||||
case Oyster::Resource::ResourceType_Mesh_VertexData:
|
||||
case Oyster::Resource::ResourceType_Mesh_AnimationData:
|
||||
|
||||
break;
|
||||
|
||||
case Oyster::Resource::ResourceType_Audio_mp3:
|
||||
|
||||
break;
|
||||
|
||||
case Oyster::Resource::ResourceType_Shader_Vertex:
|
||||
case Oyster::Resource::ResourceType_Shader_Hull:
|
||||
case Oyster::Resource::ResourceType_Shader_Domain:
|
||||
case Oyster::Resource::ResourceType_Shader_Geometry:
|
||||
case Oyster::Resource::ResourceType_Shader_Pixel:
|
||||
case Oyster::Resource::ResourceType_Shader_Compute:
|
||||
|
||||
break;
|
||||
|
||||
case Oyster::Resource::ResourceType_UNKNOWN:
|
||||
case Oyster::Resource::ResourceType_Byte_Raw:
|
||||
case Oyster::Resource::ResourceType_Byte_ANSI:
|
||||
case Oyster::Resource::ResourceType_Byte_UTF8:
|
||||
case Oyster::Resource::ResourceType_Byte_UNICODE:
|
||||
case Oyster::Resource::ResourceType_Byte_UTF16LE:
|
||||
delete ((char*)r);
|
||||
break;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/////////////////////////////////////////////////////////////////////
|
||||
// Created by [Dennis Andersen] [2013]
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef MISC_O_RESOURCE_H
|
||||
#define MISC_O_RESOURCE_H
|
||||
|
||||
#include "..\Utilities.h"
|
||||
#include "OysterResource.h"
|
||||
#include <string>
|
||||
|
||||
namespace Oyster
|
||||
{
|
||||
namespace Resource
|
||||
{
|
||||
class OResource
|
||||
{
|
||||
public:
|
||||
OResource(OHRESOURCE handle, ResourceType type, size_t size, size_t elementSize, ::std::wstring resourceFilename);
|
||||
virtual~ OResource();
|
||||
bool Release();
|
||||
|
||||
inline ResourceType GetResourceType() const
|
||||
{ return this->resourceType; }
|
||||
inline const wchar_t* GetResourceFilename() const
|
||||
{ return this->resourceFilename.c_str(); }
|
||||
inline OHRESOURCE GetResourceHandle() const
|
||||
{ return this->resourceData; }
|
||||
inline unsigned long long GetResourceSize() const
|
||||
{ return this->resourceSize; }
|
||||
inline unsigned long long GetResourceElementSize() const
|
||||
{ return this->resourceElementSize; }
|
||||
inline unsigned int GetResourceID() const
|
||||
{ return this->resourceID; }
|
||||
inline void SetResourceID(unsigned int id)
|
||||
{ this->resourceID = id; }
|
||||
|
||||
public:
|
||||
static OResource* TextureLoader (const wchar_t filename[], ResourceType type) {return 0;}
|
||||
static OResource* MeshLoader (const wchar_t filename[], ResourceType type) {return 0;};
|
||||
static OResource* AudioLoader (const wchar_t filename[], ResourceType type) {return 0;};
|
||||
static OResource* ShaderLoader (const wchar_t filename[], ResourceType type) {return 0;};
|
||||
static OResource* ByteLoader (const wchar_t filename[], ResourceType type);
|
||||
|
||||
Utility::DynamicMemory::RefCount resourceRef;
|
||||
|
||||
private:
|
||||
static void Remove (ResourceType t, OHRESOURCE& r);
|
||||
|
||||
OHRESOURCE resourceData;
|
||||
ResourceType resourceType;
|
||||
size_t resourceSize;
|
||||
size_t resourceElementSize;
|
||||
::std::wstring resourceFilename;
|
||||
unsigned int resourceID;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,182 @@
|
|||
/////////////////////////////////////////////////////////////////////
|
||||
// Created by [Dennis Andersen] [2013]
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#include "OysterResource.h"
|
||||
#include "OResource.h"
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
using namespace Oyster::Resource;
|
||||
|
||||
class ResourcePrivate
|
||||
{
|
||||
public:
|
||||
|
||||
std::map<std::wstring, OResource*> resources;
|
||||
|
||||
OResource* FindResource(const OHRESOURCE& h) const;
|
||||
OResource* FindResource(const wchar_t c[]) const;
|
||||
void SaveResource(OResource* r, bool addNew = true);
|
||||
|
||||
} resourcePrivate;
|
||||
|
||||
|
||||
void IResourceHandler::Release()
|
||||
{
|
||||
IResourceHandler::Clean();
|
||||
}
|
||||
void IResourceHandler::Clean()
|
||||
{
|
||||
auto i = resourcePrivate.resources.begin();
|
||||
auto last = resourcePrivate.resources.end();
|
||||
|
||||
for (i; i != last; i++)
|
||||
{
|
||||
if(i->second->Release())
|
||||
{
|
||||
const wchar_t* temp = i->second->GetResourceFilename();
|
||||
delete resourcePrivate.resources[temp];
|
||||
resourcePrivate.resources.erase(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
OHRESOURCE IResourceHandler::LoadResource(const wchar_t* filename, ResourceType type, bool force)
|
||||
{
|
||||
OResource *resourceData = resourcePrivate.FindResource(filename);
|
||||
if(resourceData)
|
||||
{
|
||||
resourcePrivate.SaveResource(resourceData, false);
|
||||
return resourceData->GetResourceHandle();
|
||||
}
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case Oyster::Resource::ResourceType_Texture_PNG:
|
||||
case Oyster::Resource::ResourceType_Texture_DDS:
|
||||
case Oyster::Resource::ResourceType_Texture_JPG:
|
||||
resourceData = OResource::TextureLoader(filename, type);
|
||||
break;
|
||||
|
||||
case Oyster::Resource::ResourceType_Mesh_VertexData:
|
||||
case Oyster::Resource::ResourceType_Mesh_AnimationData:
|
||||
resourceData = OResource::MeshLoader(filename, type);
|
||||
break;
|
||||
|
||||
case Oyster::Resource::ResourceType_Audio_mp3:
|
||||
resourceData = OResource::AudioLoader(filename, type);
|
||||
break;
|
||||
|
||||
case Oyster::Resource::ResourceType_Shader_Vertex:
|
||||
case Oyster::Resource::ResourceType_Shader_Hull:
|
||||
case Oyster::Resource::ResourceType_Shader_Domain:
|
||||
case Oyster::Resource::ResourceType_Shader_Geometry:
|
||||
case Oyster::Resource::ResourceType_Shader_Pixel:
|
||||
case Oyster::Resource::ResourceType_Shader_Compute:
|
||||
resourceData = OResource::ShaderLoader(filename, type);
|
||||
break;
|
||||
|
||||
case Oyster::Resource::ResourceType_UNKNOWN:
|
||||
case Oyster::Resource::ResourceType_Byte_Raw:
|
||||
case Oyster::Resource::ResourceType_Byte_ANSI:
|
||||
case Oyster::Resource::ResourceType_Byte_UTF8:
|
||||
case Oyster::Resource::ResourceType_Byte_UNICODE:
|
||||
case Oyster::Resource::ResourceType_Byte_UTF16LE:
|
||||
resourceData = OResource::ByteLoader(filename, type);
|
||||
break;
|
||||
|
||||
default:
|
||||
//The format is not supported.
|
||||
printf("(%i) is not a resourceData type or it is currently not supported!", type);
|
||||
break;
|
||||
}
|
||||
|
||||
//Resource exists! It's a miracle =D.
|
||||
resourcePrivate.SaveResource(resourceData);
|
||||
|
||||
return resourceData->GetResourceHandle();
|
||||
}
|
||||
void IResourceHandler::ReleaseResource(const OHRESOURCE& resourceData)
|
||||
{
|
||||
OResource* t = resourcePrivate.FindResource(resourceData);
|
||||
if(t)
|
||||
{
|
||||
if(t->Release())
|
||||
{
|
||||
const wchar_t* temp = t->GetResourceFilename();
|
||||
delete resourcePrivate.resources[temp];
|
||||
resourcePrivate.resources.erase(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
void IResourceHandler::SetResourceId (const OHRESOURCE& resourceData, unsigned int id)
|
||||
{
|
||||
OResource* t = resourcePrivate.FindResource(resourceData);
|
||||
|
||||
if(t) t->SetResourceID(id);
|
||||
}
|
||||
ResourceType IResourceHandler::GetResourceType (const OHRESOURCE& resourceData)
|
||||
{
|
||||
OResource* t = resourcePrivate.FindResource(resourceData);
|
||||
|
||||
if(t) return t->GetResourceType();
|
||||
|
||||
return ResourceType_UNKNOWN;
|
||||
}
|
||||
const wchar_t* IResourceHandler::GetResourceFilename (const OHRESOURCE& resourceData)
|
||||
{
|
||||
OResource* t = resourcePrivate.FindResource(resourceData);
|
||||
|
||||
if(t) return t->GetResourceFilename();
|
||||
|
||||
return 0;
|
||||
}
|
||||
unsigned int IResourceHandler::GetResourceId (const OHRESOURCE& resourceData)
|
||||
{
|
||||
OResource* t = resourcePrivate.FindResource(resourceData);
|
||||
|
||||
if(t) return t->GetResourceID();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
OResource* ResourcePrivate::FindResource(const OHRESOURCE& h) const
|
||||
{
|
||||
for (auto i = this->resources.begin(); i != this->resources.end() ; i++)
|
||||
{
|
||||
if(i->second->GetResourceHandle() == h)
|
||||
{
|
||||
return i->second;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
OResource* ResourcePrivate::FindResource(const wchar_t c[]) const
|
||||
{
|
||||
std::wstring temp = c;
|
||||
auto t = this->resources.find(c);
|
||||
if(t == this->resources.end()) return 0;
|
||||
|
||||
return t->second;
|
||||
}
|
||||
void ResourcePrivate::SaveResource( OResource* r, bool addNew )
|
||||
{
|
||||
if(!r) return;
|
||||
|
||||
if(!addNew)
|
||||
{
|
||||
r->resourceRef.Incref();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->resources[r->GetResourceFilename()] = r;
|
||||
r->resourceRef.Incref();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
#ifndef MISC_O_RESOURCE_HANLDER_H
|
||||
#define MISC_O_RESOURCE_HANLDER_H
|
||||
|
||||
|
||||
#include "OysterResource.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// Created by [Dennis Andersen] [2013]
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
|
||||
namespace Oyster
|
||||
{
|
||||
namespace Resource
|
||||
{
|
||||
class OResourceHandler :public IResourceHandler
|
||||
{
|
||||
public:
|
||||
OResourceHandler ();
|
||||
virtual~ OResourceHandler ();
|
||||
void Release () override;
|
||||
void Clean () override;
|
||||
OHRESOURCE LoadResource (const wchar_t filename[], ResourceType type, bool force) override;
|
||||
void ReleaseResource (const OHRESOURCE& resource) override;
|
||||
void SetResourceId (const OHRESOURCE& resource, unsigned int id) override;
|
||||
ResourceType GetResourceType (const OHRESOURCE& resource) const override;
|
||||
const wchar_t* GetResourceFilename (const OHRESOURCE& resource) const override;
|
||||
unsigned int GetResourceId (const OHRESOURCE& resource) const override;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,115 @@
|
|||
/////////////////////////////////////////////////////////////////////
|
||||
// Created by [Dennis Andersen] [2013]
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef MISC_OYSTER_RESOURCE_H
|
||||
#define MISC_OYSTER_RESOURCE_H
|
||||
|
||||
|
||||
namespace Oyster
|
||||
{
|
||||
namespace Resource
|
||||
{
|
||||
/** A Resource handle representing various resources */
|
||||
typedef unsigned long OHRESOURCE;
|
||||
|
||||
/** An enum class representing all avalible resources that is supported. */
|
||||
enum ResourceType
|
||||
{
|
||||
//Texture
|
||||
ResourceType_Texture_PNG, /**< Handle can be interpeted as ID3D11ShaderResourceView */
|
||||
ResourceType_Texture_DDS, /**< Handle can be interpeted as ID3D11ShaderResourceView */
|
||||
ResourceType_Texture_JPG, /**< Handle can be interpeted as ID3D11ShaderResourceView */
|
||||
|
||||
//Mesh
|
||||
ResourceType_Mesh_AllInOne, /**< Handle can be interpeted as ? */
|
||||
ResourceType_Mesh_VertexData, /**< Handle can be interpeted as ? */
|
||||
ResourceType_Mesh_AnimationData, /**< Handle can be interpeted as ? */
|
||||
|
||||
//Audio
|
||||
ResourceType_Audio_mp3, /**< Handle can be interpeted as ? */
|
||||
|
||||
//Shaders
|
||||
ResourceType_Shader_Vertex, /**< Handle can be interpeted as ? */
|
||||
ResourceType_Shader_VertexBLOB, /**< Handle can be interpeted as ID3Blob */
|
||||
ResourceType_Shader_Hull, /**< Handle can be interpeted as ? */
|
||||
ResourceType_Shader_Domain, /**< Handle can be interpeted as ? */
|
||||
ResourceType_Shader_Geometry, /**< Handle can be interpeted as ? */
|
||||
ResourceType_Shader_Pixel, /**< Handle can be interpeted as ? */
|
||||
ResourceType_Shader_Compute, /**< Handle can be interpeted as ? */
|
||||
|
||||
//Byte
|
||||
ResourceType_Byte_Raw, /**< Handle can be interpeted as char[] or char* */
|
||||
ResourceType_Byte_ANSI, /**< Handle can be interpeted as char[] or char* */
|
||||
ResourceType_Byte_UTF8, /**< Handle can be interpeted as char[] or char* */
|
||||
ResourceType_Byte_UNICODE, /**< Handle can be interpeted as char[] or char* */
|
||||
ResourceType_Byte_UTF16LE, /**< Handle can be interpeted as char[] or char* */
|
||||
|
||||
ResourceType_COUNT, /**< Handle can be interpeted as ? */
|
||||
ResourceType_UNKNOWN = -1 /**< Handle can be interpeted as char[] or char* */
|
||||
};
|
||||
|
||||
/** A resource handler interface to interact with when loading resources.
|
||||
* The resource handler uses the filename to make resources unuiqe.
|
||||
*/
|
||||
class IResourceHandler
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Release the resource handle, wich in turn releases every resource loaded with this instance.
|
||||
* @return Nothing.
|
||||
*/
|
||||
static void Release();
|
||||
|
||||
/**
|
||||
* Load a resource given a type.
|
||||
* @param filename The path to the resource.
|
||||
* @param type The resource type to load.
|
||||
* @param force If set to true, the resource will be reloaded if it already exists. If it does not, nothing happens.
|
||||
* @return If function suceeds, a handle to the resource will be returned. If failed 0 is returned.
|
||||
*/
|
||||
static OHRESOURCE LoadResource(const wchar_t filename[], ResourceType type, bool force = false);
|
||||
|
||||
/**
|
||||
* Releases all resources loaded by the resource handler.
|
||||
* @return Nothing
|
||||
*/
|
||||
static void Clean();
|
||||
|
||||
/**
|
||||
* Release a reference to the resource handle
|
||||
* @param resource The handle to release.
|
||||
* @return Nothing
|
||||
*/
|
||||
static void ReleaseResource(const OHRESOURCE& resource);
|
||||
|
||||
/** Set a user defined ID
|
||||
* @param resource A handle to accociate the id with.
|
||||
* @param id A user defined identifier that the resource handler does not touch.
|
||||
*/
|
||||
static void SetResourceId(const OHRESOURCE& resource, unsigned int id);
|
||||
|
||||
/** Get a resource type given a OHRESOURCE handle
|
||||
* @param resource The handle to check
|
||||
* @return Returns the resource type of the handle
|
||||
*/
|
||||
static ResourceType GetResourceType(const OHRESOURCE& resource);
|
||||
|
||||
/** Get a resource filename given a OHRESOURCE handle
|
||||
* @param resource The handle to check
|
||||
* @return Returns the accociated filename
|
||||
*/
|
||||
static const wchar_t* GetResourceFilename(const OHRESOURCE& resource);
|
||||
|
||||
/** Get a user defined ID accociated with a handle
|
||||
* @param resource The handle to check
|
||||
* @return Returns the accociated ID
|
||||
*/
|
||||
static unsigned int GetResourceId(const OHRESOURCE& resource);
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -281,6 +281,53 @@ namespace Utility
|
|||
return output;
|
||||
}
|
||||
|
||||
::std::wstring & wToLowerCase( ::std::wstring &output, const ::std::wstring &str )
|
||||
{
|
||||
int length = (int)str.length();
|
||||
output.resize( length );
|
||||
for( int i = 0; i < length; ++i )
|
||||
output[i] = ::std::tolower( str[i], ::std::locale() );
|
||||
return output;
|
||||
}
|
||||
|
||||
::std::wstring & wToLowerCase( ::std::wstring &str )
|
||||
{
|
||||
int length = (int)str.length();
|
||||
for( int i = 0; i < length; ++i )
|
||||
str[i] = ::std::tolower( str[i], ::std::locale() );
|
||||
return str;
|
||||
}
|
||||
|
||||
//To wstring
|
||||
|
||||
::std::wstring & StringToWString( const ::std::string &str, ::std::wstring &wstr )
|
||||
{
|
||||
const char *orig = str.c_str();
|
||||
|
||||
// Convert to a wchar_t*
|
||||
size_t origsize = strlen(orig) + 1;
|
||||
const size_t newsize = 255;
|
||||
size_t convertedChars = 0;
|
||||
wchar_t wcstring[newsize];
|
||||
mbstowcs_s(&convertedChars, wcstring, origsize, orig, _TRUNCATE);
|
||||
wstr = wcstring;
|
||||
//wcscat_s(wcstring, L" (wchar_t *)");
|
||||
return wstr;
|
||||
}
|
||||
|
||||
::std::string & WStringToString( const ::std::wstring &wstr, ::std::string &str )
|
||||
{
|
||||
const wchar_t* orig = wstr.c_str();
|
||||
// Convert to a char*
|
||||
size_t origsize = wcslen(orig) + 1;
|
||||
const size_t newsize = 255;
|
||||
size_t convertedChars = 0;
|
||||
char nstring[newsize];
|
||||
wcstombs_s(&convertedChars, nstring, origsize, orig, _TRUNCATE);
|
||||
str = nstring;
|
||||
//strcat_s(nstring, " (char *)");
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
// STREAM ////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -105,6 +105,19 @@ namespace Utility
|
|||
private:
|
||||
mutable Type *ownedArray;
|
||||
};
|
||||
|
||||
struct RefCount
|
||||
{
|
||||
private:
|
||||
int count;
|
||||
|
||||
public:
|
||||
RefCount() :count(0) { }
|
||||
void Incref() { this->count++; }
|
||||
void Incref(int c) { this->count += c; }
|
||||
int Decref() { return --this->count;}
|
||||
void Reset() { this->count = 0; }
|
||||
};
|
||||
}
|
||||
|
||||
namespace String
|
||||
|
@ -128,6 +141,13 @@ namespace Utility
|
|||
::std::vector<::std::wstring> & Split( ::std::vector<::std::wstring> &output, const ::std::wstring &str, char delim, ::std::wstring::size_type offset = 0 );
|
||||
::std::vector<::std::wstring> & Split( ::std::vector<::std::wstring> &output, const ::std::wstring &str, const ::std::wstring &delim, ::std::wstring::size_type offset = 0 );
|
||||
::std::vector<::std::wstring> & Split( ::std::vector<::std::wstring> &output, const ::std::wstring &str, const ::std::vector<::std::wstring> &delim, ::std::wstring::size_type offset = 0 );
|
||||
::std::wstring & wToLowerCase( ::std::wstring &output, const ::std::wstring &str );
|
||||
::std::wstring & wToLowerCase( ::std::wstring &str );
|
||||
|
||||
//To wstring
|
||||
|
||||
::std::wstring & StringToWstring( const ::std::string &str, ::std::wstring &wstr );
|
||||
::std::string & WStringToString( const ::std::wstring &wstr, ::std::string &str );
|
||||
}
|
||||
|
||||
namespace Stream
|
||||
|
|
|
@ -69,18 +69,26 @@
|
|||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||
<OutDir>$(SolutionDir)..\Bin\Executable\$(ProjectName)\</OutDir>
|
||||
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||
<OutDir>$(SolutionDir)..\Bin\Executable\$(ProjectName)\</OutDir>
|
||||
<TargetName>$(ProjectName)_$(PlatformShortName)D</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||
<OutDir>$(SolutionDir)..\Bin\Executable\$(ProjectName)\</OutDir>
|
||||
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<IntDir>$(SolutionDir)..\Obj\$(ProjectName)\$(PlatformShortName)\$(Configuration)\</IntDir>
|
||||
<OutDir>$(SolutionDir)..\Bin\Executable\$(ProjectName)\</OutDir>
|
||||
<TargetName>$(ProjectName)_$(PlatformShortName)</TargetName>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
|
|
Loading…
Reference in New Issue