GameLogic - Merge with util fixed

This commit is contained in:
dean11 2013-12-12 14:29:56 +01:00
commit 42fa756866
3 changed files with 93 additions and 87 deletions

View File

@ -1,73 +0,0 @@
/////////////////////////////////////////////////////////////////////
// Created by [Dennis Andersen] [2013]
/////////////////////////////////////////////////////////////////////
#include "..\OResource.h"
#include "..\..\Utilities.h"
#include <fstream>
using namespace Oyster::Resource;
OResource* OResource::CustomLoader(const wchar_t filename[], CustomLoadFunction fnc)
{
<<<<<<< HEAD
CustomData &data = fnc(filename);
if(!data.loadedData) return 0;
if(!data.resourceUnloadFnc) return 0;
OHRESOURCE n = (OHRESOURCE)data.loadedData;
OResource *resource = new OResource(n, ResourceType_UNKNOWN, 0, 0, filename);
resource->customData = new CustomResourceData();
resource->customData->unloadingFunction = data.resourceUnloadFnc;
//resource->resourceData = (OHRESOURCE)data.loadedData;
=======
CustomData data;
memset(&data, 0, sizeof(CustomData));
fnc(filename, data);
if(!data.loadedData)
{
return 0;
}
if(!data.resourceUnloadFnc)
{
return 0;
}
/** For some wierd reason that i don't understand when trying to send data.loadedData directly as a
* parameter to OResource constructor, the value is changed when it arrives in the constructor.
* Doing it like this, storing in a temporary variable, the value stays correct. (What the fuck! I must be overloking something...)*/
//OHRESOURCE temp = data.loadedData;
OResource *resource = new OResource(data.loadedData, ResourceType_UNKNOWN, 0, 0, filename);
resource->customData = new CustomResourceData();
resource->customData->unloadingFunction = data.resourceUnloadFnc;
>>>>>>> d08644e8e1ecc56f4d9dfa6a9aa33df94d9e655a
resource->customData->loadingFunction = fnc;
return resource;
}
void OResource::CustomUnloader()
{
this->customData->unloadingFunction(this->resourceData);
}
OResource* OResource::CustomReloader()
{
CustomUnloader();
CustomData data;
memset(&data, 0, sizeof(CustomData));
this->customData->loadingFunction(this->resourceFilename.c_str(), data);
this->resourceData = (OHRESOURCE)data.loadedData;
if(data.resourceUnloadFnc)
{
this->customData->unloadingFunction = data.resourceUnloadFnc;
}
return this;
}

View File

@ -208,6 +208,12 @@ namespace Utility
template<typename T> SmartPointer<T>::SmartPointer()
:_rc(0), _ptr(0)
{ }
template<typename T> SmartPointer<T>::SmartPointer(UniquePointer<T>& p)
:_ptr(p.Release())
{
this->_rc = new ReferenceCount();
this->_rc->Incref();
}
template<typename T> SmartPointer<T>::SmartPointer(T* p)
:_ptr(p)
{
@ -222,10 +228,7 @@ namespace Utility
}
template<typename T> SmartPointer<T>::~SmartPointer()
{
if (this->_rc && this->_rc->Decref() == 0)
{
Destroy();
}
this->Release();
}
template<typename T> SmartPointer<T>& SmartPointer<T>::operator= (const SmartPointer<T>& p)
{
@ -244,6 +247,30 @@ namespace Utility
}
return *this;
}
template<typename T> SmartPointer<T>& SmartPointer<T>::operator= (UniquePointer<T>& p)
{
//Last to go?
if(this->_rc)
{
if(this->_rc->Decref() == 0)
{
//Call child specific
Destroy();
this->_rc = new ReferenceCount();
}
}
else
{
if(p) this->_rc = new ReferenceCount();
}
if(this->_rc)
this->_rc->Incref();
this->_ptr = p.Release();
return *this;
}
template<typename T> SmartPointer<T>& SmartPointer<T>::operator= (T* p)
{
if (this->_ptr != p)
@ -266,27 +293,51 @@ namespace Utility
}
return *this;
}
template<typename T> inline bool SmartPointer<T>::operator== (const SmartPointer<T>& d)
template<typename T> inline bool SmartPointer<T>::operator== (const SmartPointer<T>& d) const
{
return d._ptr == this->_ptr;
}
template<typename T> inline bool SmartPointer<T>::operator== (const T& p)
template<typename T> inline bool SmartPointer<T>::operator== (const T& p) const
{
return &p == this->_ptr;
}
template<typename T> inline bool SmartPointer<T>::operator!= (const SmartPointer<T>& d) const
{
return d._ptr != this->_ptr;
}
template<typename T> inline bool SmartPointer<T>::operator!= (const T& p) const
{
return &p != this->_ptr;
}
template<typename T> inline T& SmartPointer<T>::operator* ()
{
return *this->_ptr;
}
template<typename T> inline const T& SmartPointer<T>::operator* () const
{
return *this->_ptr;
}
template<typename T> inline T* SmartPointer<T>::operator-> ()
{
return this->_ptr;
}
template<typename T> inline SmartPointer<T>::operator T* ()
template<typename T> inline const T* SmartPointer<T>::operator-> () const
{
return this->_ptr;
}
template<typename T> inline SmartPointer<T>::operator bool()
template<typename T> inline SmartPointer<T>::operator T* () const
{
return this->_ptr;
}
template<typename T> inline SmartPointer<T>::operator const T* () const
{
return this->_ptr;
}
template<typename T> inline SmartPointer<T>::operator T& () const
{
return *this->_ptr;
}
template<typename T> inline SmartPointer<T>::operator bool() const
{
return (this->_ptr != 0);
}
@ -294,7 +345,21 @@ namespace Utility
{
return this->_ptr;
}
template<typename T> inline bool SmartPointer<T>::IsValid()
template<typename T> inline T* SmartPointer<T>::Get() const
{
return this->_ptr;
}
template<typename T> int SmartPointer<T>::Release()
{
int returnVal = 0;
if(this->_rc && ((returnVal = this->_rc->Decref()) == 0))
{
Destroy();
}
return returnVal;
}
template<typename T> inline bool SmartPointer<T>::IsValid() const
{
return (this->_ptr != NULL) ? true : false;
}

View File

@ -205,27 +205,41 @@ namespace Utility
public:
SmartPointer();
SmartPointer(UniquePointer<T>& up);
SmartPointer(T* p);
SmartPointer(const SmartPointer& d);
virtual~SmartPointer();
SmartPointer<T>& operator= (const SmartPointer<T>& p);
SmartPointer<T>& operator= (UniquePointer<T>& p);
SmartPointer<T>& operator= (T* p);
bool operator== (const SmartPointer<T>& d);
bool operator== (const T& p);
bool operator== (const SmartPointer<T>& d) const;
bool operator== (const T& p) const;
bool operator!= (const SmartPointer<T>& d) const;
bool operator!= (const T& p) const;
T& operator* ();
const T& operator* () const;
T* operator-> ();
operator T* ();
operator bool();
const T* operator-> () const;
operator T* () const;
operator const T* () const;
operator T& () const;
operator bool() const;
/**
* Returns the connected pointer
*/
T* Get();
T* Get() const;
/**
* Releases one reference of the pointer and set value to null, making the current SmartPointer invalid.
*/
int Release();
/** Checks if the pointer is valid (not NULL)
* Returns true for valid, else false.
*/
bool IsValid();
bool IsValid() const;
};
}