mirror of
https://github.com/SpartanJ/eepp.git
synced 2026-06-02 03:26:29 +03:00
Added Unload to the object loaders and resource loader.
This commit is contained in:
@@ -27,6 +27,8 @@ class EE_API tSoundLoader : public cObjectLoader {
|
||||
|
||||
void Update();
|
||||
|
||||
void Unload();
|
||||
|
||||
const T& Id() const;
|
||||
protected:
|
||||
Uint32 mLoadType;
|
||||
@@ -159,6 +161,15 @@ const T& tSoundLoader<T>::Id() const {
|
||||
return mId;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void tSoundLoader<T>::Unload() {
|
||||
if ( mLoaded ) {
|
||||
mSndMngr->Remove( mId );
|
||||
|
||||
Reset();
|
||||
}
|
||||
}
|
||||
|
||||
typedef tSoundLoader<std::string> cSoundLoader;
|
||||
|
||||
}}
|
||||
|
||||
@@ -4,10 +4,7 @@
|
||||
#include <cstdlib>
|
||||
#include <climits>
|
||||
#include <cmath>
|
||||
#include <cwchar>
|
||||
#include <cstdarg>
|
||||
#include <ctime>
|
||||
#include <cctype>
|
||||
#include <cassert>
|
||||
|
||||
#include <iostream>
|
||||
@@ -16,12 +13,12 @@
|
||||
|
||||
#include <memory>
|
||||
#include <algorithm>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <deque>
|
||||
#include <queue>
|
||||
#include <list>
|
||||
#include <set>
|
||||
#include <stack>
|
||||
|
||||
|
||||
5
src/ee.h
5
src/ee.h
@@ -25,8 +25,11 @@
|
||||
@TODO Check for endianness problems, and make EEPP endianness agnostic.
|
||||
@TODO Add backend for SDL 1.3 ( support for Android ). And may be SFML backend ( just for fun ).
|
||||
@TODO Support for Android and iOS.
|
||||
@TODO Support color cursors - Imposible with SDL 1.2. Allegro 5 have this implemented ( could implement this for the Allegro backend at least - DONE ).
|
||||
@TODO Support color cursors \n
|
||||
SDL 1.2 Not even posible ( win32 and x11 backends for this ready ) \n
|
||||
Allegro 5 DONE
|
||||
@TODO Add Scripting support ( squirrel or python ).
|
||||
@TODO Fix classes bad padding, optimize memory consumption.
|
||||
*/
|
||||
|
||||
// General includes and declarations
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "ctexturefontloader.hpp"
|
||||
#include "cfontmanager.hpp"
|
||||
|
||||
namespace EE { namespace Graphics {
|
||||
|
||||
@@ -131,4 +132,21 @@ cFont * cTextureFontLoader::Font() const {
|
||||
return mFont;
|
||||
}
|
||||
|
||||
void cTextureFontLoader::Unload() {
|
||||
if ( mLoaded ) {
|
||||
mTexLoader->Unload();
|
||||
|
||||
cFontManager::instance()->Remove( mFont );
|
||||
|
||||
Reset();
|
||||
}
|
||||
}
|
||||
|
||||
void cTextureFontLoader::Reset() {
|
||||
cObjectLoader::Reset();
|
||||
|
||||
mTexLoaded = false;
|
||||
mFontLoaded = false;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -28,13 +28,15 @@ class EE_API cTextureFontLoader : public cObjectLoader {
|
||||
|
||||
void Update();
|
||||
|
||||
const std::string& Id() const;
|
||||
void Unload();
|
||||
|
||||
const std::string& Id() const;
|
||||
|
||||
cFont * Font() const;
|
||||
protected:
|
||||
Uint32 mLoadType; // From memory, from path, from pack
|
||||
|
||||
cTextureFont * mFont;
|
||||
cTextureFont * mFont;
|
||||
|
||||
std::string mFontName;
|
||||
cTextureLoader * mTexLoader;
|
||||
@@ -54,6 +56,8 @@ class EE_API cTextureFontLoader : public cObjectLoader {
|
||||
Uint32 mDataSize;
|
||||
|
||||
void Start();
|
||||
|
||||
void Reset();
|
||||
private:
|
||||
bool mTexLoaded;
|
||||
bool mFontLoaded;
|
||||
|
||||
@@ -277,5 +277,29 @@ cTexture * cTextureLoader::GetTexture() const {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void cTextureLoader::Unload() {
|
||||
if ( mLoaded ) {
|
||||
cTextureFactory::instance()->Remove( mTexId );
|
||||
|
||||
Reset();
|
||||
}
|
||||
}
|
||||
|
||||
void cTextureLoader::Reset() {
|
||||
cObjectLoader::Reset();
|
||||
|
||||
mPixels = NULL;
|
||||
mTexId = 0;
|
||||
mImgWidth = 0;
|
||||
mImgHeight = 0;
|
||||
mWidth = 0;
|
||||
mHeight = 0;
|
||||
mChannels = 0;
|
||||
mSize = 0;
|
||||
mTexLoaded = false;
|
||||
mIsDDS = false;
|
||||
mIsDDSCompressed = 0;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
|
||||
@@ -29,6 +29,8 @@ class EE_API cTextureLoader : public cObjectLoader {
|
||||
|
||||
void Update();
|
||||
|
||||
void Unload();
|
||||
|
||||
const std::string& Filepath() const;
|
||||
|
||||
const Uint32& Id() const;
|
||||
@@ -57,6 +59,8 @@ class EE_API cTextureLoader : public cObjectLoader {
|
||||
eeColor * mColorKey;
|
||||
|
||||
void Start();
|
||||
|
||||
void Reset();
|
||||
private:
|
||||
bool mTexLoaded;
|
||||
bool mIsDDS;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "cttffontloader.hpp"
|
||||
#include "cfontmanager.hpp"
|
||||
|
||||
namespace EE { namespace Graphics {
|
||||
|
||||
@@ -111,4 +112,18 @@ cFont * cTTFFontLoader::Font() const {
|
||||
return mFont;
|
||||
}
|
||||
|
||||
void cTTFFontLoader::Unload() {
|
||||
if ( mLoaded ) {
|
||||
cFontManager::instance()->Remove( mFont );
|
||||
|
||||
Reset();
|
||||
}
|
||||
}
|
||||
|
||||
void cTTFFontLoader::Reset() {
|
||||
cObjectLoader::Reset();
|
||||
|
||||
mFontLoaded = false;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -24,7 +24,9 @@ class EE_API cTTFFontLoader : public cObjectLoader {
|
||||
|
||||
void Update();
|
||||
|
||||
const std::string& Id() const;
|
||||
void Unload();
|
||||
|
||||
const std::string& Id() const;
|
||||
|
||||
cFont * Font() const;
|
||||
protected:
|
||||
@@ -47,6 +49,8 @@ class EE_API cTTFFontLoader : public cObjectLoader {
|
||||
eeUint mDataSize;
|
||||
|
||||
void Start();
|
||||
|
||||
void Reset();
|
||||
private:
|
||||
bool mFontLoaded;
|
||||
|
||||
|
||||
@@ -81,4 +81,9 @@ const Uint32& cObjectLoader::Type() const {
|
||||
return mObjType;
|
||||
}
|
||||
|
||||
void cObjectLoader::Reset() {
|
||||
mLoaded = false;
|
||||
mLoading = false;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -26,6 +26,8 @@ class EE_API cObjectLoader : cThread {
|
||||
|
||||
void Load( ObjLoadCallback Cb );
|
||||
|
||||
virtual void Unload() = 0;
|
||||
|
||||
virtual void Update();
|
||||
|
||||
void Launch();
|
||||
@@ -50,6 +52,8 @@ class EE_API cObjectLoader : cThread {
|
||||
virtual void Start();
|
||||
|
||||
virtual void SetLoaded();
|
||||
|
||||
virtual void Reset();
|
||||
private:
|
||||
virtual void Run();
|
||||
};
|
||||
|
||||
@@ -130,6 +130,18 @@ void cResourceLoader::Update() {
|
||||
Load();
|
||||
}
|
||||
|
||||
void cResourceLoader::Unload() {
|
||||
if ( mLoaded ) {
|
||||
std::list<cObjectLoader *>::iterator it;
|
||||
|
||||
for ( it = mObjs.begin(); it != mObjs.end(); it++ ) {
|
||||
(*it)->Unload();
|
||||
}
|
||||
|
||||
mLoaded = false;
|
||||
}
|
||||
}
|
||||
|
||||
bool cResourceLoader::IsLoaded() {
|
||||
return mLoaded;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ class EE_API cResourceLoader {
|
||||
|
||||
void Load();
|
||||
|
||||
void Unload();
|
||||
|
||||
virtual void Update();
|
||||
|
||||
virtual bool IsLoaded();
|
||||
|
||||
@@ -9,77 +9,84 @@ cPerlinNoise::cPerlinNoise() {
|
||||
cPerlinNoise::~cPerlinNoise() {}
|
||||
|
||||
void cPerlinNoise::Init() {
|
||||
mPersistence = 0.25f;
|
||||
mOctaves = 4;
|
||||
mFrequency = 0.015f;
|
||||
mAmplitude = 1;
|
||||
mFreqOctaveDep = false;
|
||||
mAmpOctaveDep = false;
|
||||
mPersistence = 0.25f;
|
||||
mOctaves = 4;
|
||||
mFrequency = 0.015f;
|
||||
mAmplitude = 1;
|
||||
mFreqOctaveDep = false;
|
||||
mAmpOctaveDep = false;
|
||||
}
|
||||
|
||||
eeFloat cPerlinNoise::PerlinNoise2D(eeFloat x, eeFloat y) {
|
||||
eeFloat total = 0;
|
||||
eeFloat p = mPersistence;
|
||||
eeFloat n = (eeFloat)mOctaves - 1;
|
||||
eeFloat total = 0;
|
||||
eeFloat p = mPersistence;
|
||||
eeFloat n = static_cast<eeFloat>( mOctaves - 1 );
|
||||
eeFloat tmpFreq = mFrequency;
|
||||
eeFloat amp = mAmplitude;
|
||||
eeFloat amp = mAmplitude;
|
||||
mCurrSeed = 1;
|
||||
|
||||
mCurrSeed = 1;
|
||||
|
||||
for (Int32 i=0; i <= n; i++) {
|
||||
if (mFreqOctaveDep)
|
||||
for ( Int32 i = 0; i <= n; i++ ) {
|
||||
if ( mFreqOctaveDep ) {
|
||||
tmpFreq *= 2;
|
||||
if (mAmpOctaveDep)
|
||||
amp *= p;
|
||||
}
|
||||
|
||||
total = total + InterpolatedNoise2D(x * tmpFreq, y * tmpFreq) * amp;
|
||||
if ( mAmpOctaveDep ) {
|
||||
amp *= p;
|
||||
}
|
||||
|
||||
total = total + InterpolatedNoise2D( x * tmpFreq, y * tmpFreq ) * amp;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
eeFloat cPerlinNoise::Noise2D(Int32 x, Int32 y) {
|
||||
Int32 n;
|
||||
n = x + y * 57;
|
||||
n = (n<<13) ^ n;
|
||||
eeFloat res = (eeFloat)( 1.0 - ( (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff ) / 1073741824.0);
|
||||
return res;
|
||||
eeFloat cPerlinNoise::Noise2D( Int32 x, Int32 y ) {
|
||||
Int32 n = x + y * 57;
|
||||
|
||||
n = ( n << 13 ) ^ n;
|
||||
|
||||
n = ( (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff );
|
||||
|
||||
return static_cast<eeFloat>( 1.0 - static_cast<eeFloat>( n ) / 1073741824.0);
|
||||
}
|
||||
|
||||
eeFloat cPerlinNoise::SmoothedNoise2D(eeFloat x, eeFloat y) {
|
||||
eeFloat corners = ( Noise2D( (Int32)(x-1), (Int32)(y-1) ) + Noise2D( (Int32)(x+1), (Int32)(y-1) )+Noise2D( (Int32)(x-1), (Int32)(y+1) ) + Noise2D( (Int32)(x+1), (Int32)(y+1) ) ) / 16;
|
||||
eeFloat sides = ( Noise2D( (Int32)(x-1), (Int32)y) + Noise2D((Int32)x+1, (Int32)y) + Noise2D( (Int32)x, (Int32)(y-1) ) + Noise2D( (Int32)x, (Int32)(y+1) ) ) / 8;
|
||||
eeFloat center = Noise2D((Int32)x, (Int32)y) / 4;
|
||||
register Int32 tx = static_cast<Int32>( x );
|
||||
register Int32 ty = static_cast<Int32>( y );
|
||||
|
||||
eeFloat corners = ( Noise2D( tx - 1, ty - 1 ) + Noise2D( tx + 1, ty - 1 ) + Noise2D( tx - 1 , ty + 1 ) + Noise2D( tx + 1, ty + 1 ) ) / 16;
|
||||
eeFloat sides = ( Noise2D( tx - 1, ty ) + Noise2D( tx + 1, ty ) + Noise2D( tx , ty - 1 ) + Noise2D( tx , ty + 1 ) ) / 8;
|
||||
eeFloat center = Noise2D( tx, ty ) / 4;
|
||||
|
||||
return corners + sides + center;
|
||||
}
|
||||
|
||||
eeFloat cPerlinNoise::Interpolate(eeFloat a, eeFloat b, eeFloat x) {
|
||||
eeFloat fac1 = 3*eepow(1-x, 2) - 2*eepow(1-x,3);
|
||||
eeFloat fac2 = 3*eepow(x, 2) - 2*eepow(x, 3);
|
||||
|
||||
return a*fac1 + b*fac2; //add the weighted factors
|
||||
eeFloat cPerlinNoise::Interpolate( eeFloat a, eeFloat b, eeFloat x ) {
|
||||
eeFloat fac1 = 3 * eepow( 1 - x, 2 ) - 2 * eepow( 1 - x, 3 );
|
||||
eeFloat fac2 = 3 * eepow( x, 2 ) - 2 * eepow( x, 3 );
|
||||
|
||||
return a * fac1 + b * fac2; //add the weighted factors
|
||||
}
|
||||
|
||||
eeFloat cPerlinNoise::InterpolatedNoise2D(eeFloat x, eeFloat y) {
|
||||
Int32 Int32eger_X = Int32(x);
|
||||
eeFloat fractional_X = x - Int32eger_X;
|
||||
Int32 eger_X = static_cast<Int32>( x );
|
||||
Int32 eger_Y = static_cast<Int32>( y );
|
||||
|
||||
Int32 Int32eger_Y = Int32(y);
|
||||
eeFloat fractional_Y = y - Int32eger_Y;
|
||||
eeFloat fractional_X = x - eger_X;
|
||||
eeFloat fractional_Y = y - eger_Y;
|
||||
|
||||
eeFloat feger_X = (eeFloat)Int32eger_X;
|
||||
eeFloat feger_Y = (eeFloat)Int32eger_Y;
|
||||
eeFloat feger_X = static_cast<eeFloat> ( eger_X );
|
||||
eeFloat feger_Y = static_cast<eeFloat> ( eger_Y );
|
||||
|
||||
eeFloat v1 = SmoothedNoise2D(feger_X, feger_Y);
|
||||
eeFloat v2 = SmoothedNoise2D(feger_X + 1.f, feger_Y);
|
||||
eeFloat v3 = SmoothedNoise2D(feger_X, feger_Y + 1.f);
|
||||
eeFloat v4 = SmoothedNoise2D(feger_X + 1.f, feger_Y + 1.f);
|
||||
eeFloat v1 = SmoothedNoise2D( feger_X , feger_Y );
|
||||
eeFloat v2 = SmoothedNoise2D( feger_X + 1.f , feger_Y );
|
||||
eeFloat v3 = SmoothedNoise2D( feger_X , feger_Y + 1.f );
|
||||
eeFloat v4 = SmoothedNoise2D( feger_X + 1.f , feger_Y + 1.f );
|
||||
|
||||
eeFloat i1 = Interpolate(v1 , v2 , fractional_X);
|
||||
eeFloat i2 = Interpolate(v3 , v4 , fractional_X);
|
||||
eeFloat i1 = Interpolate( v1 , v2 , fractional_X );
|
||||
eeFloat i2 = Interpolate( v3 , v4 , fractional_X );
|
||||
|
||||
return Interpolate(i1 , i2 , fractional_Y);
|
||||
return Interpolate( i1 , i2 , fractional_Y );
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user