|
From: <cn...@us...> - 2010-01-10 22:27:09
|
Revision: 648
http://hgengine.svn.sourceforge.net/hgengine/?rev=648&view=rev
Author: cnlohr
Date: 2010-01-10 22:27:01 +0000 (Sun, 10 Jan 2010)
Log Message:
-----------
fix warnings
Modified Paths:
--------------
Mercury2/src/GLHelpers.cpp
Mercury2/src/MercuryAsset.cpp
Mercury2/src/MercuryBacktrace.c
Mercury2/src/MercuryFileDriverDirect.cpp
Mercury2/src/MercuryLog.cpp
Mercury2/src/MercurySoundDriverALSA.cpp
Mercury2/src/MercurySoundSourceRAM.cpp
Mercury2/src/MercurySoundSourceVorbis.cpp
Mercury2/src/MercuryUtil.cpp
Mercury2/src/StateChanger.cpp
Modified: Mercury2/src/GLHelpers.cpp
===================================================================
--- Mercury2/src/GLHelpers.cpp 2010-01-10 22:13:44 UTC (rev 647)
+++ Mercury2/src/GLHelpers.cpp 2010-01-10 22:27:01 UTC (rev 648)
@@ -59,7 +59,7 @@
MercuryVertex pointFromScreenLoc(int screen_x, int screen_y, float fForceDepth)
{
- GLfloat winX, winY, winZ;
+ GLfloat winX, winY;
GLdouble mouseX = 0, mouseY = 0, mouseZ = 0;
GLint viewport[4];
GLdouble modelview[16];
@@ -93,7 +93,7 @@
void CameraPointAndRay(int screen_x, int screen_y, MercuryVertex & p, MercuryVertex & r)
{
- GLfloat winX, winY, winZ;
+ GLfloat winX, winY;
GLdouble dox = 0, doy = 0, doz = 0;
GLint viewport[4];
GLdouble modelview[16];
Modified: Mercury2/src/MercuryAsset.cpp
===================================================================
--- Mercury2/src/MercuryAsset.cpp 2010-01-10 22:13:44 UTC (rev 647)
+++ Mercury2/src/MercuryAsset.cpp 2010-01-10 22:27:01 UTC (rev 648)
@@ -6,8 +6,7 @@
extern bool DOOCCLUSIONCULL;
MercuryAsset::MercuryAsset( const MString & key, bool bInstanced )
- :m_isInstanced(bInstanced), m_boundingVolume(NULL),
- m_path( key ), m_loadState(NONE), m_ignoreCull(false), m_iPasses( DEFAULT_PASSES ), slType( 0 )
+ :slType( 0 ), m_isInstanced(bInstanced), m_boundingVolume(NULL), m_path( key ), m_loadState(NONE), m_ignoreCull(false), m_iPasses( DEFAULT_PASSES )
{
}
Modified: Mercury2/src/MercuryBacktrace.c
===================================================================
--- Mercury2/src/MercuryBacktrace.c 2010-01-10 22:13:44 UTC (rev 647)
+++ Mercury2/src/MercuryBacktrace.c 2010-01-10 22:27:01 UTC (rev 648)
@@ -208,7 +208,11 @@
#else
sprintf( execline, "addr2line -fC -e %s 0x%lx 1>&%d", file, (unsigned long)offset, fds[1] );
#endif
- system( execline );
+ if( system( execline ) != 0 )
+ {
+ printf( "Failed to execute backtrace app. Command line:\"%s\".", execline );
+ return 0;
+ }
readbytes = read( fds[0], buffer, 1024 );
if( readbytes + 1 >= maxlen )
@@ -336,7 +340,10 @@
if( DBGSetup )
return;
DBGSetup = 1;
- pipe( fds );
+ if( pipe( fds ) != 0 )
+ {
+ printf( "Warning: Could not pipe for backtrace.\n" );
+ }
#ifdef _CMAC
sprintf( execline, "atos 2>&%d", fds[0] );
Modified: Mercury2/src/MercuryFileDriverDirect.cpp
===================================================================
--- Mercury2/src/MercuryFileDriverDirect.cpp 2010-01-10 22:13:44 UTC (rev 647)
+++ Mercury2/src/MercuryFileDriverDirect.cpp 2010-01-10 22:27:01 UTC (rev 648)
@@ -237,7 +237,10 @@
return;
}
*path_end = 0;
- chdir( buffer );
+ if( chdir( buffer ) != 0 )
+ {
+ fprintf( stderr, "WARNING: Could not change path of executable to \"%s\"\n", buffer );
+ }
#endif
#endif
}
Modified: Mercury2/src/MercuryLog.cpp
===================================================================
--- Mercury2/src/MercuryLog.cpp 2010-01-10 22:13:44 UTC (rev 647)
+++ Mercury2/src/MercuryLog.cpp 2010-01-10 22:27:01 UTC (rev 648)
@@ -13,6 +13,7 @@
log->WriteQueue();
msleep(100); //10x/sec
}
+ return 0;
}
MercuryLog::MercuryLog()
Modified: Mercury2/src/MercurySoundDriverALSA.cpp
===================================================================
--- Mercury2/src/MercurySoundDriverALSA.cpp 2010-01-10 22:13:44 UTC (rev 647)
+++ Mercury2/src/MercurySoundDriverALSA.cpp 2010-01-10 22:27:01 UTC (rev 648)
@@ -207,7 +207,7 @@
SOUNDMAN->FillBuffer( ibuf, nrframes );
- for( unsigned i = 0; i < nrframes; ++i )
+ for( int i = 0; i < nrframes; ++i )
{
float fi = ibuf[i*2+0];
float fb = ibuf[i*2+1];
Modified: Mercury2/src/MercurySoundSourceRAM.cpp
===================================================================
--- Mercury2/src/MercurySoundSourceRAM.cpp 2010-01-10 22:13:44 UTC (rev 647)
+++ Mercury2/src/MercurySoundSourceRAM.cpp 2010-01-10 22:27:01 UTC (rev 648)
@@ -6,8 +6,6 @@
void MercurySoundSourceRAM::FillBuffer( float * cBufferToFill, int iCount )
{
- int i;
-
int iOffset = 0;
if( m_iSampleHold > 0 )
@@ -28,7 +26,7 @@
int placeBytes = m_iSoundPlace* MercurySoundManager::iChannels;
- for( unsigned i = iOffset; i < iCopyFrames * MercurySoundManager::iChannels; i++ )
+ for( int i = iOffset; i < iCopyFrames * MercurySoundManager::iChannels; i++ )
{
cBufferToFill[i] = m_Sound->fSound[placeBytes+i];
}
Modified: Mercury2/src/MercurySoundSourceVorbis.cpp
===================================================================
--- Mercury2/src/MercurySoundSourceVorbis.cpp 2010-01-10 22:13:44 UTC (rev 647)
+++ Mercury2/src/MercurySoundSourceVorbis.cpp 2010-01-10 22:27:01 UTC (rev 648)
@@ -118,7 +118,7 @@
REGISTER_SOUND_SOURCE( MercurySoundSourceVorbis, "Vorbis" );
MercurySoundSourceVorbis::MercurySoundSourceVorbis( MercurySoundSource * chain ) :
- MercurySoundSource( chain ), iBufferSize( 32768 ), iBufferLoad(1), iBufferPlay(0)
+ MercurySoundSource( chain ), iBufferSize( 32768 ), iBufferPlay(0), iBufferLoad(1)
{
iBuffer = (short*)malloc( sizeof( short ) * iBufferSize * 2 );
}
@@ -134,7 +134,7 @@
bool MercurySoundSourceVorbis::Load( const MString & sDescriptor )
{
MAutoPtr< HGRawSound > r;
- MAutoPtr< HGRawSound > * g;
+// MAutoPtr< HGRawSound > * g;
m_File = FILEMAN.Open( sDescriptor );
@@ -148,12 +148,13 @@
ov_open_callbacks( m_File, vorbisFile, NULL, 0, vorbisCallbacks );
- vorbis_info* info = ov_info(vorbisFile, -1);
+// vorbis_info* info = ov_info(vorbisFile, -1);
// unsigned VorbisChannels = info->channels;
// unsigned VorbisSamplerate = info->rate;
+
unsigned VorbisSamples = ov_pcm_total( vorbisFile, 0 );
- unsigned Vorbisbytes_read;
+// unsigned Vorbisbytes_read;
if( VorbisSamples <= 0 )
{
@@ -169,7 +170,7 @@
void MercurySoundSourceVorbis::FillBuffer( float * cBufferToFill, int iCount )
{
//Don't worry our circular queue is threadsafe.
- for( unsigned i = 0; i < iCount; i++ )
+ for( int i = 0; i < iCount; i++ )
{
if( PlayLeft() <= 2 ) break;
cBufferToFill[i*2+0] = float(iBuffer[iBufferPlay*2+0])/32768.;
Modified: Mercury2/src/MercuryUtil.cpp
===================================================================
--- Mercury2/src/MercuryUtil.cpp 2010-01-10 22:13:44 UTC (rev 647)
+++ Mercury2/src/MercuryUtil.cpp 2010-01-10 22:27:01 UTC (rev 648)
@@ -234,6 +234,7 @@
if( !f ) return false;
f->Write( data.c_str(), data.length() );
delete f;
+ return true;
}
Modified: Mercury2/src/StateChanger.cpp
===================================================================
--- Mercury2/src/StateChanger.cpp 2010-01-10 22:13:44 UTC (rev 647)
+++ Mercury2/src/StateChanger.cpp 2010-01-10 22:27:01 UTC (rev 648)
@@ -61,7 +61,7 @@
void Stringify( MString & sOut )
{
- sOut = ssprintf( "%f", bEnable );
+ sOut = (bEnable)?"1":"0";
}
void Activate()
@@ -99,7 +99,7 @@
void Stringify( MString & sOut )
{
- sOut = ssprintf( "%f", bEnable );
+ sOut = (bEnable)?"1":"0";
}
void Activate()
@@ -136,7 +136,7 @@
void Stringify( MString & sOut )
{
- sOut = ssprintf( "%f", bEnable );
+ sOut = (bEnable)?"1":"0";
}
void Activate()
@@ -188,6 +188,7 @@
STRTOGL(s, CONSTANT_ALPHA);
STRTOGL(s, ONE_MINUS_CONSTANT_ALPHA);
STRTOGL(s, SRC_ALPHA_SATURATE);
+ return -1;
}
#define GLTOSTR(x,s) case GL_##s: return #s;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cn...@us...> - 2010-01-11 08:43:24
|
Revision: 650
http://hgengine.svn.sourceforge.net/hgengine/?rev=650&view=rev
Author: cnlohr
Date: 2010-01-11 08:43:17 +0000 (Mon, 11 Jan 2010)
Log Message:
-----------
add testing code in Mercury2.cpp for this variable thing
Modified Paths:
--------------
Mercury2/src/Mercury2.cpp
Mercury2/src/MercuryInput.cpp
Mercury2/src/MercuryMessageManager.cpp
Mercury2/src/MercuryMessageManager.h
Mercury2/src/MercuryValue.cpp
Mercury2/src/MercuryValue.h
Modified: Mercury2/src/Mercury2.cpp
===================================================================
--- Mercury2/src/Mercury2.cpp 2010-01-11 08:01:21 UTC (rev 649)
+++ Mercury2/src/Mercury2.cpp 2010-01-11 08:43:17 UTC (rev 650)
@@ -199,8 +199,30 @@
// printf("Render wait %%%f\n", (RenderWaited/double(totalWaited))*100.0f);
return 0;
-}
+}
+
+
+
+
+
+///XXXXXXXX STUB CODE XXXXXXXXXXX THIS CODE SHOULD BE REMOVED AS SOON AS TESTING OF THE VARIABLE SYSTEM IS COMPLETE
+class TestMouse
+{
+public:
+ TestMouse()
+ {
+ MESSAGEMAN.GetValue( "Input.CursorDeltaX" )->AttachModifyDelegate( (ValueDelegate)&TestMouse::ChangeX, (MessageHandler*)this );
+ }
+
+ void ChangeX( MValue * v )
+ {
+ printf( "Changed: %f\n", v->GetFloat() );
+ }
+} TM;
+///XXXXXXX REMOVE THIS CODE BEFORE ANY RELEASE XXXXXXXXXXx
+
+
/* Copyright (c) 2008, Joshua Allen
* All rights reserved.
*
Modified: Mercury2/src/MercuryInput.cpp
===================================================================
--- Mercury2/src/MercuryInput.cpp 2010-01-11 08:01:21 UTC (rev 649)
+++ Mercury2/src/MercuryInput.cpp 2010-01-11 08:43:17 UTC (rev 650)
@@ -1,6 +1,9 @@
#include <MercuryInput.h>
#include <MercuryMessageManager.h>
+MVRefFloat GlobalMouseX_Set( "Input.CursorDeltaX" );
+MVRefFloat GlobalMouseY_Set( "Input.CursorDeltaY" );
+
MouseInput::MouseInput()
:MessageData(), dx(0), dy(0)
{
@@ -20,7 +23,10 @@
buttons.scrolldown = scrollDownButton;
mi->buttons = buttons;
currentButtonMasks = buttons;
-
+
+ GlobalMouseX_Set.Set( dx );
+ GlobalMouseY_Set.Set( dy );
+
POST_MESSAGE( INPUTEVENT_MOUSE, mi, 0 );
}
Modified: Mercury2/src/MercuryMessageManager.cpp
===================================================================
--- Mercury2/src/MercuryMessageManager.cpp 2010-01-11 08:01:21 UTC (rev 649)
+++ Mercury2/src/MercuryMessageManager.cpp 2010-01-11 08:43:17 UTC (rev 650)
@@ -147,6 +147,17 @@
return mh;
}
+MValue * MercuryMessageManager::GetValue( const MString & sVariableName )
+{
+ MValue * v = m_allValues.get( sVariableName );
+ if( !v )
+ {
+ v = &m_allValues[sVariableName];
+ v->SetReferences( 1 );
+ }
+ return v;
+}
+
MercuryMessageManager& MercuryMessageManager::GetInstance()
{
static MercuryMessageManager *instance = NULL;
Modified: Mercury2/src/MercuryMessageManager.h
===================================================================
--- Mercury2/src/MercuryMessageManager.h 2010-01-11 08:01:21 UTC (rev 649)
+++ Mercury2/src/MercuryMessageManager.h 2010-01-11 08:43:17 UTC (rev 650)
@@ -46,7 +46,9 @@
void RegisterForMessage(const MString& message, MessageHandler* ptr, MessageDelegate d = 0 );
void UnRegisterForMessage(const MString& message, MessageHandler* ptr);
-
+
+ MValue * GetValue( const MString & sVariableName );
+
static MercuryMessageManager& GetInstance();
private:
void FireOffMessage( const MessageHolder & message );
@@ -63,7 +65,8 @@
};
MHash< std::list< MessagePair > > m_messageRecipients;
-
+ MHash< MValue > m_allValues; //Careful - these cannot be deleted.
+
// MercuryMutex m_lock;
MSemaphore m_queueLock;
MSemaphore m_recipientLock;
Modified: Mercury2/src/MercuryValue.cpp
===================================================================
--- Mercury2/src/MercuryValue.cpp 2010-01-11 08:01:21 UTC (rev 649)
+++ Mercury2/src/MercuryValue.cpp 2010-01-11 08:43:17 UTC (rev 650)
@@ -43,6 +43,10 @@
+MValue::MValue( ) : m_References( 0 ), m_CurType( TYPE_UNDEF ), DLDelete( 0 ), DLModify( 0 )
+{
+ m_Data.v = 0;
+}
MValue::MValue( MVType t ) : m_References( 0 ), m_CurType( t ), DLDelete( 0 ), DLModify( 0 )
{
@@ -113,3 +117,43 @@
}
}
+MVRefBase::MVRefBase(const MString & sPath)
+{
+ mv = MESSAGEMAN.GetValue( sPath );
+ MSemaphoreLock( &mv->m_Sema );
+ mv->m_References++;
+}
+
+
+/****************************************************************************
+ * Copyright (C) 2010 by Charles Lohr *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
+
Modified: Mercury2/src/MercuryValue.h
===================================================================
--- Mercury2/src/MercuryValue.h 2010-01-11 08:01:21 UTC (rev 649)
+++ Mercury2/src/MercuryValue.h 2010-01-11 08:43:17 UTC (rev 650)
@@ -42,7 +42,7 @@
class MValue
{
public:
-
+ MValue();
MValue( MVType t );
~MValue();
@@ -80,6 +80,15 @@
}
MVType GetType() { return m_CurType; }
+
+ void AttachModifyDelegate( DeletionNotifier NotifyFunction, MessageHandler * NotifyObject )
+ {
+ DelegateNotifierList * d = new DelegateNotifierList( NotifyFunction, NotifyObject );
+ d->Next = DLModify;
+ DLModify = d;
+ }
+
+ void SetReferences( short RefCount ) { m_References = RefCount; }
private:
//Conv functions are not thread protected - this is because the caller of these functions should be.
int ConvInt();
@@ -144,6 +153,9 @@
class MVRefInt : public MVRefBase
{
public:
+ MVRefInt( MValue * m ) : MVRefBase( m ) { }
+ MVRefInt( const MString & p ) : MVRefBase( p ) { }
+
int Get() { return mv->GetInt(); }
void Set( int iv ) { mv->SetInt( iv ); }
};
@@ -152,6 +164,9 @@
class MVRefFloat : public MVRefBase
{
public:
+ MVRefFloat( MValue * m ) : MVRefBase( m ) { }
+ MVRefFloat( const MString & p ) : MVRefBase( p ) { }
+
float Get() { return mv->GetFloat(); }
void Set( float fv ) { mv->SetFloat( fv ); }
};
@@ -160,6 +175,9 @@
class MVRefString : public MVRefBase
{
public:
+ MVRefString( MValue * m ) : MVRefBase( m ) { }
+ MVRefString( const MString & p ) : MVRefBase( p ) { }
+
const MString & Get() { return mv->GetString(); }
void Set( const MString & sv ) { mv->SetString( sv ); }
};
@@ -168,6 +186,9 @@
class MVRefPtr : public MVRefBase
{
public:
+ MVRefPtr( MValue * m ) : MVRefBase( m ) { }
+ MVRefPtr( const MString & p ) : MVRefBase( p ) { }
+
T * Get() {
return (T*)mv->GetPtr();
}
@@ -208,3 +229,4 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
***************************************************************************/
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2010-01-11 22:31:14
|
Revision: 655
http://hgengine.svn.sourceforge.net/hgengine/?rev=655&view=rev
Author: axlecrusher
Date: 2010-01-11 22:31:04 +0000 (Mon, 11 Jan 2010)
Log Message:
-----------
ability for assets to reload if there is a newer version
Modified Paths:
--------------
Mercury2/src/FullscreenQuad.h
Mercury2/src/HGMDLModel.cpp
Mercury2/src/HGMDLModel.h
Mercury2/src/ImageLoader.cpp
Mercury2/src/MercuryAsset.cpp
Mercury2/src/MercuryAsset.h
Mercury2/src/MercuryVBO.h
Mercury2/src/Quad.h
Mercury2/src/RenderDeferredLights.h
Mercury2/src/Shader.cpp
Mercury2/src/Shader.h
Mercury2/src/StateChanger.h
Mercury2/src/Texture.cpp
Mercury2/src/Texture.h
Modified: Mercury2/src/FullscreenQuad.h
===================================================================
--- Mercury2/src/FullscreenQuad.h 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/FullscreenQuad.h 2010-01-11 22:31:04 UTC (rev 655)
@@ -13,6 +13,10 @@
virtual void Render(const MercuryNode* node);
GENRTTI( FullscreenQuad );
+ protected:
+ virtual bool CheckForNewer() { return false; }
+ virtual void Reload() {};
+
private:
MercuryMatrix m_matrix;
};
Modified: Mercury2/src/HGMDLModel.cpp
===================================================================
--- Mercury2/src/HGMDLModel.cpp 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/HGMDLModel.cpp 2010-01-11 22:31:04 UTC (rev 655)
@@ -7,7 +7,7 @@
const uint16_t EXPCTMNRV = 3;
HGMDLModel::HGMDLModel( const MString & key, bool bInstanced )
- :MercuryAsset( key, bInstanced )
+ :MercuryAsset( key, bInstanced ), m_timeStamp( 0 )
{
}
@@ -17,12 +17,35 @@
void HGMDLModel::LoadFromXML(const XMLNode& node)
{
- MString path = node.Attribute("file");
+ LoadFromFile( node.Attribute("file") );
+ MercuryAsset::LoadFromXML( node );
+}
+
+
+void HGMDLModel::LoadFromFile(const MString& path)
+{
+ m_path = path;
ChangeKey( path );
+}
+
+bool HGMDLModel::CheckForNewer()
+{
+ uint32_t t = 0;
+ MercuryFile *f = FILEMAN.Open(m_path);
- MercuryAsset::LoadFromXML( node );
+ if (f)
+ {
+ t = f->GetModTime();
+ delete f;
+ }
+ return t != m_timeStamp;
}
+void HGMDLModel::Reload()
+{
+ LoadFromFile(m_path);
+}
+
void HGMDLModel::LoadModel(MercuryFile* hgmdl, HGMDLModel* model)
{
char fingerPrint[5];
Modified: Mercury2/src/HGMDLModel.h
===================================================================
--- Mercury2/src/HGMDLModel.h 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/HGMDLModel.h 2010-01-11 22:31:04 UTC (rev 655)
@@ -12,6 +12,7 @@
~HGMDLModel();
virtual void LoadFromXML(const XMLNode& node);
+ void LoadFromFile(const MString& path);
static void LoadModel(MercuryFile* hgmdl, HGMDLModel* model);
@@ -21,11 +22,16 @@
virtual void Render(const MercuryNode* node);
GENRTTI( HGMDLModel );
protected:
+ virtual bool CheckForNewer();
+ virtual void Reload();
+
MVector< MAutoPtr< HGMDLMesh > > m_meshes;
private:
CLASS_HELPERS( MercuryAsset );
static void* LoaderThread(void* d);
+
+ uint32_t m_timeStamp;
};
Modified: Mercury2/src/ImageLoader.cpp
===================================================================
--- Mercury2/src/ImageLoader.cpp 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/ImageLoader.cpp 2010-01-11 22:31:04 UTC (rev 655)
@@ -56,11 +56,12 @@
if (i->first == t)
{
RawImageData* d = i->second(f);
- delete f;
+ SAFE_DELETE(f);
return d;
}
}
- delete f;
+
+ SAFE_DELETE(f);
return NULL;
}
Modified: Mercury2/src/MercuryAsset.cpp
===================================================================
--- Mercury2/src/MercuryAsset.cpp 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/MercuryAsset.cpp 2010-01-11 22:31:04 UTC (rev 655)
@@ -6,7 +6,7 @@
extern bool DOOCCLUSIONCULL;
MercuryAsset::MercuryAsset( const MString & key, bool bInstanced )
- :slType( 0 ), m_isInstanced(bInstanced), m_boundingVolume(NULL), m_path( key ), m_loadState(NONE), m_ignoreCull(false), m_iPasses( DEFAULT_PASSES )
+ :slType( 0 ), m_isInstanced(bInstanced), m_boundingVolume(NULL), m_path( key ), m_loadState(NONE), m_ignoreCull(false), m_iPasses( DEFAULT_PASSES ), m_lastNewerCheck(0)
{
}
@@ -53,6 +53,13 @@
void MercuryAsset::PreRender(const MercuryNode* node)
{
+ uint32_t t = time(0);
+ if ( CheckForNewer() && (m_lastNewerCheck < t) )
+ {
+ m_lastNewerCheck = t;
+ Reload();
+ }
+
/*
MercuryNode* n = const_cast<MercuryNode*>(node);
if ( m_boundingVolume )
Modified: Mercury2/src/MercuryAsset.h
===================================================================
--- Mercury2/src/MercuryAsset.h 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/MercuryAsset.h 2010-01-11 22:31:04 UTC (rev 655)
@@ -84,14 +84,21 @@
protected:
void SetLoadState(LoadState ls); //thread safe
+ virtual bool CheckForNewer() = 0;
+ virtual void Reload() = 0;
+
bool m_isInstanced;
BoundingVolume* m_boundingVolume;
MString m_path;
+
private:
LoadState m_loadState;
MSemaphore m_lock;
bool m_ignoreCull;
unsigned short m_iPasses;
+
+ uint32_t m_lastNewerCheck;
+// uint32_t m_timeStamp; //creation timestamp of asset eg. file timestamp
};
/** This holds the per-instance data for each asset instance.
Modified: Mercury2/src/MercuryVBO.h
===================================================================
--- Mercury2/src/MercuryVBO.h 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/MercuryVBO.h 2010-01-11 22:31:04 UTC (rev 655)
@@ -46,6 +46,10 @@
inline static void IncrementBatches() { ++m_vboBatches; }
GENRTTI( MercuryVBO );
+ protected:
+ virtual bool CheckForNewer() { return false; }
+ virtual void Reload() {};
+
private:
virtual void InitVBO();
static void* m_lastVBOrendered;
Modified: Mercury2/src/Quad.h
===================================================================
--- Mercury2/src/Quad.h 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/Quad.h 2010-01-11 22:31:04 UTC (rev 655)
@@ -14,6 +14,9 @@
virtual bool ChangeKey( const MString & sDescription );
GENRTTI( Quad );
+ protected:
+ virtual bool CheckForNewer() { return false; }
+ virtual void Reload() {};
private:
bool m_bFlipV;
Modified: Mercury2/src/RenderDeferredLights.h
===================================================================
--- Mercury2/src/RenderDeferredLights.h 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/RenderDeferredLights.h 2010-01-11 22:31:04 UTC (rev 655)
@@ -11,6 +11,9 @@
virtual void Render(const MercuryNode* node);
GENRTTI( RenderDeferredLights );
+ protected:
+ virtual bool CheckForNewer() { return false; }
+ virtual void Reload() {};
};
#endif
Modified: Mercury2/src/Shader.cpp
===================================================================
--- Mercury2/src/Shader.cpp 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/Shader.cpp 2010-01-11 22:31:04 UTC (rev 655)
@@ -384,16 +384,21 @@
return;
}
-void Shader::CheckForNewer( )
+void Shader::Reload()
{
+ DestroyShader( );
+ LoadShader( );
+}
+
+bool Shader::CheckForNewer()
+{
unsigned long iCurTimes[3];
GetTimeCodes( iCurTimes );
if( iCurTimes[0] != iTimeCode[0] || iCurTimes[1] != iTimeCode[1] || iCurTimes[2] != iTimeCode[2] )
- {
- DestroyShader( );
- LoadShader( );
- }
+ return true;
+
+ return false;
}
void Shader::GetTimeCodes( unsigned long * iOut )
Modified: Mercury2/src/Shader.h
===================================================================
--- Mercury2/src/Shader.h 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/Shader.h 2010-01-11 22:31:04 UTC (rev 655)
@@ -90,6 +90,11 @@
///Explicitly get the OpenGL ProgramID in the event you need it for advanced techniques
unsigned int GetProgramID() { return iProgramID; }
inline static Shader* GetCurrentShader() { return CurrentShader; }
+
+ protected:
+ virtual bool CheckForNewer();
+ virtual void Reload();
+
private:
int32_t GetUniformLocation(const MString& n);
@@ -127,7 +132,7 @@
bool LinkShaders();
///Check for newer version of 'this' shader
- void CheckForNewer( );
+// void CheckForNewer( );
///Get the last modified time for sShaderName
/* This function takes on iOut as being where to put the last time the shader was modified.
Modified: Mercury2/src/StateChanger.h
===================================================================
--- Mercury2/src/StateChanger.h 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/StateChanger.h 2010-01-11 22:31:04 UTC (rev 655)
@@ -64,6 +64,10 @@
virtual bool ChangeKey( const MString & sNewKey );
virtual bool LoadInternal( const MString & sFile );
GENRTTI( StateChanger );
+
+ protected:
+ virtual bool CheckForNewer() { return false; }
+ virtual void Reload() {};
private:
MVector< MAutoPtr< StateChange > > m_vStates;
Modified: Mercury2/src/Texture.cpp
===================================================================
--- Mercury2/src/Texture.cpp 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/Texture.cpp 2010-01-11 22:31:04 UTC (rev 655)
@@ -13,7 +13,7 @@
#define BUFFER_OFFSET(i) ((char*)NULL + (i))
Texture::Texture( const MString & key, bool bInstanced )
- :MercuryAsset( key, bInstanced ), m_raw(NULL),m_textureID(0),m_bDeleteRaw(true),m_dynamic(false), m_bClamp(true), m_tFilterMode(TF_LINEAR_MIPS)
+ :MercuryAsset( key, bInstanced ), m_raw(NULL),m_textureID(0),m_bDeleteRaw(true),m_dynamic(false), m_bClamp(true), m_tFilterMode(TF_LINEAR_MIPS), m_timeStamp(0)
{
if (!m_initTextureSuccess)
{
@@ -292,6 +292,27 @@
GLERRORCHECK;
}
+bool Texture::CheckForNewer()
+{
+ uint32_t timeStamp = m_timeStamp;
+
+ if (timeStamp == 0) return false;
+
+ MercuryFile *f = FILEMAN.Open(m_path);
+ if (f)
+ {
+ m_timeStamp = f->GetModTime();
+ delete f;
+ }
+
+ return timeStamp != m_timeStamp;
+}
+
+void Texture::Reload()
+{
+ LoadImagePath(m_path);
+}
+
MAutoPtr< Texture > Texture::LoadFromFile(const MString& path)
{
MAutoPtr< MercuryAsset > t( AssetFactory::GetInstance().Generate("Texture", path) );
Modified: Mercury2/src/Texture.h
===================================================================
--- Mercury2/src/Texture.h 2010-01-11 21:56:22 UTC (rev 654)
+++ Mercury2/src/Texture.h 2010-01-11 22:31:04 UTC (rev 655)
@@ -47,9 +47,13 @@
static void DisableUnusedTextures();
void SetFilter( TextureFilterMode t ) { m_tFilterMode = t; }
+ GENRTTI( Texture );
+ protected:
+ virtual bool CheckForNewer();
+ virtual void Reload();
- GENRTTI( Texture );
private:
+
void LoadImagePath(const MString& path);
void BindTexture();
@@ -59,7 +63,7 @@
void Deactivate(uint32_t textureResource);
void InitiateBindCache();
-
+
RawImageData* m_raw;
uint32_t m_textureID;
@@ -75,7 +79,7 @@
bool m_dynamic;
bool m_bClamp;
TextureFilterMode m_tFilterMode;
-
+ uint32_t m_timeStamp;
};
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2010-01-14 19:34:58
|
Revision: 657
http://hgengine.svn.sourceforge.net/hgengine/?rev=657&view=rev
Author: axlecrusher
Date: 2010-01-14 19:34:46 +0000 (Thu, 14 Jan 2010)
Log Message:
-----------
Fix windows compiling.
Fix shader compiling multiple times.
Fix shader destruction when opengl driver gives successful link message.
Modified Paths:
--------------
Mercury2/src/DataStructures/SpatialHash.h
Mercury2/src/MercuryAsset.cpp
Mercury2/src/Shader.cpp
Modified: Mercury2/src/DataStructures/SpatialHash.h
===================================================================
--- Mercury2/src/DataStructures/SpatialHash.h 2010-01-13 12:06:26 UTC (rev 656)
+++ Mercury2/src/DataStructures/SpatialHash.h 2010-01-14 19:34:46 UTC (rev 657)
@@ -1,7 +1,7 @@
#ifndef SPATIALHASH_H
#define SPATIALHASH_H
-#include <stdint.h>
+//#include <stdint.h>
#include <list>
#include <math.h>
Modified: Mercury2/src/MercuryAsset.cpp
===================================================================
--- Mercury2/src/MercuryAsset.cpp 2010-01-13 12:06:26 UTC (rev 656)
+++ Mercury2/src/MercuryAsset.cpp 2010-01-14 19:34:46 UTC (rev 657)
@@ -3,6 +3,8 @@
#include <MercuryNode.h>
#include <GLHeaders.h>
+#include <time.h>
+
extern bool DOOCCLUSIONCULL;
MercuryAsset::MercuryAsset( const MString & key, bool bInstanced )
@@ -192,7 +194,7 @@
void AssetFactory::RemoveAssetInstance(const MString& key)
{
m_assetInstances.remove( key );
- puts( "removed asset "+key );
+ LOG.Write("removed asset "+key);
}
/****************************************************************************
Modified: Mercury2/src/Shader.cpp
===================================================================
--- Mercury2/src/Shader.cpp 2010-01-13 12:06:26 UTC (rev 656)
+++ Mercury2/src/Shader.cpp 2010-01-14 19:34:46 UTC (rev 657)
@@ -94,6 +94,9 @@
fPriority = StrToFloat( node.Attribute("priority" ) );
ChangeKey( node.Attribute("file") );
+
+ if (iProgramID == NULL)
+ LoadShader();
}
bool Shader::ChangeKey( const MString& path )
@@ -102,7 +105,7 @@
return true;
sShaderName = path;
- LoadShader( );
+// LoadShader( );
return MercuryAsset::ChangeKey( path );
}
@@ -206,8 +209,7 @@
{
char * tmpstr = (char*)malloc( stringLength + 1 );
GLCALL( glGetInfoLogARB( fragmentShader, stringLength, NULL, tmpstr ) );
- puts( "Compiling Fragment Shader response follows:" );
- puts( tmpstr );
+ LOG.Write( ssprintf("Compiling Fragment Shader response follows:%s" ,tmpstr) );
free( tmpstr );
return bFragCompiled!=0;
}
@@ -234,8 +236,7 @@
{
char * tmpstr = (char*)malloc( stringLength + 1 );
GLCALL( glGetInfoLogARB( vertexShader, stringLength, NULL, tmpstr ) );
- puts( "Compiling Vertex Shader response follows:" );
- puts( tmpstr );
+ LOG.Write( ssprintf("Compiling Vertex Shader response follows:%s", tmpstr) );
free( tmpstr );
return bVertCompiled!=0;
}
@@ -263,8 +264,7 @@
{
char * tmpstr = (char*)malloc( stringLength + 1 );
GLCALL( glGetInfoLogARB( geometryShader, stringLength, NULL, tmpstr ) );
- puts( "Compiling Geometry Shader response follows:" );
- puts( tmpstr );
+ LOG.Write( ssprintf("Compiling Geometry Shader response follows:%s",tmpstr) );
free( tmpstr );
return bGeomCompiled!=0;
}
@@ -304,8 +304,8 @@
GLCALL( glGetIntegerv(GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT,&imaxvert) );
if( (ierror = glGetError()) != 0 )
{
- puts( "ERROR: You cannot load a geometry shader when there are still errors left in OpenGL." );
- puts( "Please track down the error remaining by using glGetError() to cordon off your code." );
+ LOG.Write( "ERROR: You cannot load a geometry shader when there are still errors left in OpenGL." );
+ LOG.Write( "Please track down the error remaining by using glGetError() to cordon off your code." );
LOG.Write( ssprintf( "The last error received was: %d", ierror ) );
}
for( i = 1; i < imaxvert; i++ )
@@ -326,11 +326,14 @@
{
char * tmpstr = (char*)malloc( stringLength + 1 );
GLCALL( glGetInfoLogARB( iProgramID, stringLength, NULL, tmpstr ) );
- puts( "Linking shaders. response follows:" );
- puts( tmpstr );
+ LOG.Write( ssprintf("Linking shaders. response follows:%s",tmpstr) );
free( tmpstr );
+ }
+
+ if (bLinked == 0)
+ {
DestroyShader();
- return bLinked!=0;
+ return false;
}
//Build the list of uniform tabs.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2010-01-15 18:11:50
|
Revision: 660
http://hgengine.svn.sourceforge.net/hgengine/?rev=660&view=rev
Author: axlecrusher
Date: 2010-01-15 18:11:44 +0000 (Fri, 15 Jan 2010)
Log Message:
-----------
Fix deadlock on windows.
Mutexes can not have a default name. In windows, mutexes with identical names are shared.
Modified Paths:
--------------
Mercury2/src/MScopedArray.h
Mercury2/src/MercuryThreads.cpp
Mercury2/src/MercuryThreads.h
Mercury2/src/ModuleManager.cpp
Modified: Mercury2/src/MScopedArray.h
===================================================================
--- Mercury2/src/MScopedArray.h 2010-01-14 21:30:42 UTC (rev 659)
+++ Mercury2/src/MScopedArray.h 2010-01-15 18:11:44 UTC (rev 660)
@@ -14,9 +14,9 @@
MScopedArray(T* ptr)
:m_ptr(ptr), m_count(NULL)
{
- m_criticalSection.Wait();
+ m_criticalSection.DangerousWait();
IncrementReference();
- m_criticalSection.UnLock();
+ m_criticalSection.DangerousWait();
}
MScopedArray()
@@ -35,26 +35,26 @@
inline ~MScopedArray()
{
- m_criticalSection.Wait();
+ m_criticalSection.DangerousWait();
DecrementReference();
- m_criticalSection.UnLock();
+ m_criticalSection.DangerousUnLock();
}
inline unsigned int Count()
{
unsigned int count = 0;
- m_criticalSection.Wait();
+ m_criticalSection.DangerousWait();
if( m_ptr && m_count ) count = *m_count;
- m_criticalSection.UnLock();
+ m_criticalSection.DangerousUnLock();
return count;
}
void Clear()
{
- m_criticalSection.Wait();
+ m_criticalSection.DangerousWait();
DecrementReference();
m_ptr = NULL;
- m_criticalSection.UnLock();
+ m_criticalSection.DangerousUnLock();
}
/*
void Forget()
@@ -85,11 +85,11 @@
//Assignment
MScopedArray& operator=(const MScopedArray<T>& rhs)
{
- m_criticalSection.Wait();
+ m_criticalSection.DangerousWait();
DecrementReference();
m_ptr = rhs.m_ptr;
IncrementReference();
- m_criticalSection.UnLock();
+ m_criticalSection.DangerousUnLock();
return *this;
}
Modified: Mercury2/src/MercuryThreads.cpp
===================================================================
--- Mercury2/src/MercuryThreads.cpp 2010-01-14 21:30:42 UTC (rev 659)
+++ Mercury2/src/MercuryThreads.cpp 2010-01-15 18:11:44 UTC (rev 660)
@@ -4,6 +4,9 @@
#include <windows.h>
#endif
+//XXX WARNING in windows mutex of the same name are shared!!!
+//we can not give mutexes a default name
+
#include <stdio.h>
MercuryThread::MercuryThread()
@@ -131,7 +134,7 @@
//Mutex functions
MercuryMutex::MercuryMutex( )
-:m_name("(null)")
+:m_heldBy(0)
{
iLockCount = 0;
Open( );
@@ -139,7 +142,7 @@
}
MercuryMutex::MercuryMutex( const MString &name )
-:m_name(name)
+:m_name(name),m_heldBy(0)
{
iLockCount = 0;
Open( );
@@ -151,11 +154,26 @@
Close( );
}
-int MercuryMutex::Wait( long lMilliseconds )
+void MercuryMutex::SetName(const MString& name)
{
+ m_name = name;
+}
+
+bool MercuryMutex::Wait( long lMilliseconds )
+{
int r = 0;
#if defined( WIN32 )
r = WaitForSingleObject( m_mutex, lMilliseconds );
+
+ switch( r )
+ {
+ case WAIT_TIMEOUT:
+ fprintf(stderr, "Mutex held by thread ID 0x%x timed out (%d locks)\n", m_heldBy, iLockCount );
+ return false;
+ case WAIT_FAILED:
+ fprintf(stderr, "Mutex held by thread ID 0x%x failed (%d locks)\n", m_heldBy, iLockCount );
+ return false;
+ }
#else
/* timespec abstime;
abstime.tv_sec = 0;
@@ -172,25 +190,30 @@
// }
#endif
// printf("Locked %s\n", m_name.c_str());
+ m_heldBy = MercuryThread::Current();
++iLockCount;
- return r;
+// return r;
+ return true;
}
-int MercuryMutex::UnLock( )
+bool MercuryMutex::UnLock( )
{
// printf("Unlocked %s\n", m_name.c_str());
--iLockCount;
+ if (iLockCount==0) m_heldBy = 0;
#if defined( WIN32 )
- return ReleaseMutex( m_mutex );
+ bool r = ReleaseMutex( m_mutex )!=0;
+ if (!r) fprintf(stderr, "Failed to release mutex %s, error %d!!\n", m_name.c_str(), GetLastError());
+ return r;
#else
pthread_mutex_unlock( &m_mutex );
- return 0;
+ return true;
#endif
}
int MercuryMutex::Open( )
{
- iLockCount++;
+ ++iLockCount;
#if defined( WIN32 )
SECURITY_ATTRIBUTES *p = ( SECURITY_ATTRIBUTES* ) malloc( sizeof( SECURITY_ATTRIBUTES ) );
p->nLength = sizeof( SECURITY_ATTRIBUTES );
Modified: Mercury2/src/MercuryThreads.h
===================================================================
--- Mercury2/src/MercuryThreads.h 2010-01-14 21:30:42 UTC (rev 659)
+++ Mercury2/src/MercuryThreads.h 2010-01-15 18:11:44 UTC (rev 660)
@@ -22,6 +22,8 @@
class StartThreadData;
#endif
+#include <stdio.h>
+
///Thread object
class MercuryThread
{
@@ -74,13 +76,22 @@
MercuryMutex( const MString &name );
~MercuryMutex();
+ /** These functions are dangerous because you need to be VERY careful to cover all
+ unlock scenarios including errors and exceptions.
+ Recommend using AutoMutexLock on the stack to avoid problems **/
+
///Wait for a mutex to unlock (0xFFFFFF is infinate on windows)
- int Wait( long lMilliseconds = 0xFFFFFF );
+ bool DangerousWait( long lMilliseconds = 0xFFFFFF ) { return Wait(lMilliseconds); } //return false on error
+ /// Unlock a mutex for the next thing waiting in line.
+ bool DangerousUnLock( ) { return UnLock( ); } //return false on error
- ///Unlock a mutex for the next thing waiting in line.
- int UnLock( );
+ inline unsigned long HeldBy() const { return m_heldBy; }
+ void SetName(const MString& name);
private:
+ friend class AutoMutexLock;
+ bool Wait( long lMilliseconds = 0xFFFFFF ); //return false on error
+ bool UnLock( ); //return false on error
///Start up a mutex. You need to do this as well as UnLock() afterwards when in a constructor.
int Open( );
@@ -91,6 +102,7 @@
MString m_name;
int iLockCount;
+ unsigned long m_heldBy;
#if defined( WIN32 )
void * m_mutex;
#else
@@ -109,8 +121,12 @@
AutoMutexLock( MercuryMutex& mutex)
:m_mutex(&mutex)
{
- m_mutex->Wait();
+ //loop until we get a lock but use a timeout so we are warned
+ //of a held mutex indicating a possible deadlock
+ bool l = m_mutex->Wait(1000);
+ while (!l) m_mutex->Wait(1000);
}
+
~AutoMutexLock()
{
m_mutex->UnLock();
Modified: Mercury2/src/ModuleManager.cpp
===================================================================
--- Mercury2/src/ModuleManager.cpp 2010-01-14 21:30:42 UTC (rev 659)
+++ Mercury2/src/ModuleManager.cpp 2010-01-15 18:11:44 UTC (rev 660)
@@ -37,7 +37,8 @@
void ModuleManager::InitializeAllModules()
{
- m_mHandleMutex.Wait();
+ AutoMutexLock lock(m_mHandleMutex);
+
XMLDocument* doc = XMLDocument::Load("modules.xml");
XMLNode r = doc->GetRootNode();
for (XMLNode child = r.Child(); child.IsValid(); child = child.NextNode())
@@ -60,7 +61,7 @@
m_hClassMFunction[child.Attribute( "class" )] = LoadFunct;
LoadModule( ModuleName, LoadFunct );
}
- m_mHandleMutex.UnLock();
+
delete doc;
}
@@ -72,26 +73,27 @@
void * ModuleManager::LoadModule( const MString & ModuleName, const MString & LoadFunction )
{
- m_mHandleMutex.Wait();
+ {
+ //scope mutex lock
+ AutoMutexLock lock(m_mHandleMutex);
- if( m_hAllHandles[ModuleName] ) UnloadModule( ModuleName );
+ if( m_hAllHandles[ModuleName] ) UnloadModule( ModuleName );
- void * v = dlopen( ModuleName.c_str(), RTLD_NOW | RTLD_GLOBAL );
- m_hAllHandles[ModuleName] = v;
+ void * v = dlopen( ModuleName.c_str(), RTLD_NOW | RTLD_GLOBAL );
+ m_hAllHandles[ModuleName] = v;
- if( !m_hAllHandles[ModuleName] )
- {
+ if( !m_hAllHandles[ModuleName] )
+ {
#ifdef WIN32
- fprintf( stderr, "Error opening: %s\n", ModuleName.c_str() );
+ fprintf( stderr, "Error opening: %s\n", ModuleName.c_str() );
#else
- fprintf( stderr, "Error opening: %s (%s)\n", ModuleName.c_str(), dlerror() );
+ fprintf( stderr, "Error opening: %s (%s)\n", ModuleName.c_str(), dlerror() );
#endif
- return false;
+ return false;
+ }
}
- m_mHandleMutex.UnLock();
-
//If no load funct, just exit early.
if( LoadFunction == "" )
return 0;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2010-01-15 21:52:24
|
Revision: 662
http://hgengine.svn.sourceforge.net/hgengine/?rev=662&view=rev
Author: axlecrusher
Date: 2010-01-15 21:52:17 +0000 (Fri, 15 Jan 2010)
Log Message:
-----------
add replace routine
Modified Paths:
--------------
Mercury2/src/MercuryString.cpp
Mercury2/src/MercuryString.h
Modified: Mercury2/src/MercuryString.cpp
===================================================================
--- Mercury2/src/MercuryString.cpp 2010-01-15 18:58:16 UTC (rev 661)
+++ Mercury2/src/MercuryString.cpp 2010-01-15 21:52:17 UTC (rev 662)
@@ -336,6 +336,17 @@
return strncmp( m_sCur + start, cmp, len );
}
+MString MString::replace(const MString& old, const MString& n)
+{
+ if (this->empty() || old.empty() || n.empty()) return *this;
+
+ int i = this->find(old);
+ if (i<0) return *this;
+
+ MString s = this->substr(0,i) + n + this->substr(i+old.length());
+ return s.replace(old, n);
+}
+
unsigned int MString::hash() const
{
unsigned int ret = 0;
Modified: Mercury2/src/MercuryString.h
===================================================================
--- Mercury2/src/MercuryString.h 2010-01-15 18:58:16 UTC (rev 661)
+++ Mercury2/src/MercuryString.h 2010-01-15 21:52:17 UTC (rev 662)
@@ -65,6 +65,8 @@
int compare( int start, int len, const MString & cmp ) const;
int compare( int start, int len, const char * cmp ) const;
+ MString replace(const MString& old, const MString& n);
+
unsigned int hash() const;
enum
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2010-01-15 21:56:03
|
Revision: 664
http://hgengine.svn.sourceforge.net/hgengine/?rev=664&view=rev
Author: axlecrusher
Date: 2010-01-15 21:55:57 +0000 (Fri, 15 Jan 2010)
Log Message:
-----------
fix warnings
Modified Paths:
--------------
Mercury2/src/BoundingBox.cpp
Mercury2/src/Camera.cpp
Mercury2/src/DataStructures/SpatialHash.h
Mercury2/src/DataTypes/MTriangle.cpp
Mercury2/src/DataTypes/MTriangle.h
Mercury2/src/MercuryVBO.h
Modified: Mercury2/src/BoundingBox.cpp
===================================================================
--- Mercury2/src/BoundingBox.cpp 2010-01-15 21:53:59 UTC (rev 663)
+++ Mercury2/src/BoundingBox.cpp 2010-01-15 21:55:57 UTC (rev 664)
@@ -22,7 +22,7 @@
uint32_t OcclusionResult::GetSamples() const
{
- if (m_occlusionQuery == 0) return ~0;
+ if (m_occlusionQuery == 0) return ~(uint32_t(0));
uint32_t samples;
GLCALL( glGetQueryObjectuivARB(m_occlusionQuery, GL_QUERY_RESULT_ARB, &samples) );
Modified: Mercury2/src/Camera.cpp
===================================================================
--- Mercury2/src/Camera.cpp 2010-01-15 21:53:59 UTC (rev 663)
+++ Mercury2/src/Camera.cpp 2010-01-15 21:55:57 UTC (rev 664)
@@ -155,7 +155,7 @@
{
TransformNode::LoadFromXML( node );
m_origionalPosition = GetPosition();
- POST_MESSAGE("QueryTerrainPoint", new VertexDataMessage(GetPosition()), 0.00001);
+ POST_MESSAGE("QueryTerrainPoint", new VertexDataMessage(GetPosition()), 0.00001f);
}
Modified: Mercury2/src/DataStructures/SpatialHash.h
===================================================================
--- Mercury2/src/DataStructures/SpatialHash.h 2010-01-15 21:53:59 UTC (rev 663)
+++ Mercury2/src/DataStructures/SpatialHash.h 2010-01-15 21:55:57 UTC (rev 664)
@@ -46,8 +46,13 @@
//check for and skip duplicate
std::list<T>& cell = m_hashTable[ Index( ix, iy, iz ) ];
+
typename std::list<T>::iterator i = cell.begin();
- for (;i != cell.end(); ++i) if (*i == d) return;
+ for (;i != cell.end(); ++i)
+ {
+ const T& a = *i;
+ if (a == d) return;
+ }
cell.push_back( d );
// printf("added at %d %d %d\n", ix, iy, iz);
@@ -107,7 +112,7 @@
}
std::list<T>* m_hashTable;
- uint32_t m_spacing;
+ float m_spacing;
uint32_t m_cellCount;
};
Modified: Mercury2/src/DataTypes/MTriangle.cpp
===================================================================
--- Mercury2/src/DataTypes/MTriangle.cpp 2010-01-15 21:53:59 UTC (rev 663)
+++ Mercury2/src/DataTypes/MTriangle.cpp 2010-01-15 21:55:57 UTC (rev 664)
@@ -73,7 +73,7 @@
return r.Length() * 0.5;
}
-bool MTriangle::operator == (const MTriangle& rhs)
+bool MTriangle::operator == (const MTriangle& rhs) const
{
if (m_verts[0] != rhs.m_verts[0]) return false;
if (m_verts[1] != rhs.m_verts[1]) return false;
Modified: Mercury2/src/DataTypes/MTriangle.h
===================================================================
--- Mercury2/src/DataTypes/MTriangle.h 2010-01-15 21:53:59 UTC (rev 663)
+++ Mercury2/src/DataTypes/MTriangle.h 2010-01-15 21:55:57 UTC (rev 664)
@@ -15,7 +15,7 @@
float Area();
MercuryVertex InterpolatePosition(const MercuryVertex& barycentric);
- bool operator == (const MTriangle& rhs);
+ bool operator == (const MTriangle& rhs) const;
// private:
MercuryVertex m_verts[3];
Modified: Mercury2/src/MercuryVBO.h
===================================================================
--- Mercury2/src/MercuryVBO.h 2010-01-15 21:53:59 UTC (rev 663)
+++ Mercury2/src/MercuryVBO.h 2010-01-15 21:55:57 UTC (rev 664)
@@ -34,7 +34,7 @@
const short unsigned int* GetIndexHandle() const { return m_indexData.Buffer(); }
short unsigned int* GetIndexHandle() { return m_indexData.Buffer(); }
- inline uint16_t IndiceCount() const { return m_indexData.Length(); }
+ inline uint16_t IndiceCount() const { return (uint16_t)m_indexData.Length(); }
inline void DirtyVertices() { m_bDirtyVertices = true; }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2010-01-15 23:15:30
|
Revision: 665
http://hgengine.svn.sourceforge.net/hgengine/?rev=665&view=rev
Author: axlecrusher
Date: 2010-01-15 23:15:24 +0000 (Fri, 15 Jan 2010)
Log Message:
-----------
updates for linux
Modified Paths:
--------------
Mercury2/src/MercuryThreads.cpp
Mercury2/src/ModuleManager.cpp
Modified: Mercury2/src/MercuryThreads.cpp
===================================================================
--- Mercury2/src/MercuryThreads.cpp 2010-01-15 21:55:57 UTC (rev 664)
+++ Mercury2/src/MercuryThreads.cpp 2010-01-15 23:15:24 UTC (rev 665)
@@ -2,6 +2,8 @@
#if defined( WIN32 )
#include <windows.h>
+#else
+#include <errno.h>
#endif
//XXX WARNING in windows mutex of the same name are shared!!!
@@ -185,7 +187,19 @@
// if (pthread_mutex_trylock( &m_mutex ) != 0)
// {
// printf("%s waiting\n", m_name.c_str());
- pthread_mutex_lock( &m_mutex );
+ r = pthread_mutex_lock( &m_mutex );
+ switch (r)
+ {
+ case EBUSY:
+ fprintf(stderr, "Mutex held by thread ID 0x%x failed (%d locks)\n", m_heldBy, iLockCount );
+ return false;
+ case EINVAL:
+ fprintf(stderr, "Invalid Mutex\n");
+ return true;
+ case EAGAIN:
+ fprintf(stderr, "Max Recursive Locks Reached\n");
+ return false;
+ }
// printf("%s locked\n", m_name.c_str());
// }
#endif
@@ -201,14 +215,16 @@
// printf("Unlocked %s\n", m_name.c_str());
--iLockCount;
if (iLockCount==0) m_heldBy = 0;
+
+ int r, error;
#if defined( WIN32 )
- bool r = ReleaseMutex( m_mutex )!=0;
- if (!r) fprintf(stderr, "Failed to release mutex %s, error %d!!\n", m_name.c_str(), GetLastError());
- return r;
+ r = ReleaseMutex( m_mutex );
+ if (r!=0) error = GetLastError();
#else
- pthread_mutex_unlock( &m_mutex );
- return true;
+ error = r = pthread_mutex_unlock( &m_mutex );
#endif
+ if (r!=0) fprintf(stderr, "Failed to release mutex %s, error %d!!\n", m_name.c_str(), error);
+ return r!=0;
}
int MercuryMutex::Open( )
Modified: Mercury2/src/ModuleManager.cpp
===================================================================
--- Mercury2/src/ModuleManager.cpp 2010-01-15 21:55:57 UTC (rev 664)
+++ Mercury2/src/ModuleManager.cpp 2010-01-15 23:15:24 UTC (rev 665)
@@ -120,7 +120,7 @@
void ModuleManager::ReloadModule( const MString & sClass )
{
- m_mHandleMutex.Wait();
+ AutoMutexLock lock(m_mHandleMutex);
std::set< void * > & s = m_hAllInstances[sClass];
std::set< void * >::iterator i = s.begin();
@@ -129,8 +129,6 @@
for( ; i != s.end(); i++ )
*((void**)(*i)) = newvtable;
-
- m_mHandleMutex.UnLock();
}
void ModuleManager::RegisterInstance( void * instance, const char * sClass )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2010-01-17 02:32:31
|
Revision: 668
http://hgengine.svn.sourceforge.net/hgengine/?rev=668&view=rev
Author: axlecrusher
Date: 2010-01-17 02:32:13 +0000 (Sun, 17 Jan 2010)
Log Message:
-----------
build vertex from 3 and 4 float arrays
Modified Paths:
--------------
Mercury2/src/MercuryValue.cpp
Mercury2/src/MercuryVertex.cpp
Modified: Mercury2/src/MercuryValue.cpp
===================================================================
--- Mercury2/src/MercuryValue.cpp 2010-01-17 02:26:59 UTC (rev 667)
+++ Mercury2/src/MercuryValue.cpp 2010-01-17 02:32:13 UTC (rev 668)
@@ -4,7 +4,7 @@
DelegateNotifierList::DelegateNotifierList( DeletionNotifier nf, MessageHandler * no ) :
- NotifyFunction( nf ), NotifyObject( no ), Next( 0 )
+ NotifyFunction( nf ), NotifyObject( no ), Next( NULL )
{
}
@@ -43,14 +43,14 @@
-MValue::MValue( ) : m_References( 0 ), m_CurType( TYPE_UNDEF ), DLDelete( 0 ), DLModify( 0 )
+MValue::MValue( ) : m_References( NULL ), m_CurType( TYPE_UNDEF ), DLDelete( NULL ), DLModify( NULL )
{
- m_Data.v = 0;
+ m_Data.v = NULL;
}
-MValue::MValue( MVType t ) : m_References( 0 ), m_CurType( t ), DLDelete( 0 ), DLModify( 0 )
+MValue::MValue( MVType t ) : m_References( NULL ), m_CurType( t ), DLDelete( NULL ), DLModify( NULL )
{
- m_Data.v = 0;
+ m_Data.v = NULL;
}
MValue::~MValue()
Modified: Mercury2/src/MercuryVertex.cpp
===================================================================
--- Mercury2/src/MercuryVertex.cpp 2010-01-17 02:26:59 UTC (rev 667)
+++ Mercury2/src/MercuryVertex.cpp 2010-01-17 02:32:13 UTC (rev 668)
@@ -19,10 +19,17 @@
(*this)[3] = iw;
}
-MercuryVertex::MercuryVertex( const float * in )
+MercuryVertex::MercuryVertex( const float* in3f, float f )
{
+ for (unsigned int i = 0; i < 3; ++i)
+ (*this)[i] = in3f[i];
+ (*this)[3] = f;
+}
+
+MercuryVertex::MercuryVertex( const float* in4f )
+{
for (unsigned int i = 0; i < 4; ++i)
- (*this)[i] = in[i];
+ (*this)[i] = in4f[i];
}
MercuryVertex::MercuryVertex( const MercuryVertex& v)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cn...@us...> - 2010-02-23 02:19:24
|
Revision: 673
http://hgengine.svn.sourceforge.net/hgengine/?rev=673&view=rev
Author: cnlohr
Date: 2010-02-23 02:19:18 +0000 (Tue, 23 Feb 2010)
Log Message:
-----------
tweak passes and add endurance mode to the assets, so that you can have things that just /stay/ on.
Modified Paths:
--------------
Mercury2/src/MercuryNode.cpp
Mercury2/src/StateChanger.cpp
Mercury2/src/StateChanger.h
Modified: Mercury2/src/MercuryNode.cpp
===================================================================
--- Mercury2/src/MercuryNode.cpp 2010-02-23 01:08:42 UTC (rev 672)
+++ Mercury2/src/MercuryNode.cpp 2010-02-23 02:19:18 UTC (rev 673)
@@ -223,7 +223,7 @@
{
#ifdef WRITE_OUT_RENDERGARPH
static int depth;
- if ( IsHidden() || IsCulled() || (! (m_iPasses & (1<<g_iPass))) )
+ if ( IsHidden() || IsCulled() || ((! (m_iPasses & (1<<g_iPass))) && m_iForcePasses ) )
{
printf( "x%*c %p:%s (%d %d %d)\n", depth, 0, this, GetName().c_str(), IsHidden(), IsCulled(), (! (m_iPasses & (1<<g_iPass))) );
return;
@@ -231,7 +231,7 @@
printf( "1%*c %p:%s\n", depth, 0, this, GetName().c_str() );
depth++;
#else
- if ( IsHidden() || IsCulled() || (! (m_iPasses & (1<<g_iPass))) )
+ if ( IsHidden() || IsCulled() || ((! (m_iPasses & (1<<g_iPass))) && m_iForcePasses ) )
return;
#endif
Modified: Mercury2/src/StateChanger.cpp
===================================================================
--- Mercury2/src/StateChanger.cpp 2010-02-23 01:08:42 UTC (rev 672)
+++ Mercury2/src/StateChanger.cpp 2010-02-23 02:19:18 UTC (rev 673)
@@ -285,27 +285,29 @@
{
MAutoPtr< StateChange > & k = m_vStates[i];
k->Activate();
- m_StateSet[k->sID].push_back( k );
+ if( !m_isEnduring )
+ m_StateSet[k->sID].push_back( k );
}
}
void StateChanger::PostRender(const MercuryNode* node)
{
- for( unsigned i = 0; i < m_vStates.size(); i++ )
- {
- MAutoPtr< StateChange > & k = m_vStates[i];
- MVector< MAutoPtr< StateChange > > & l = m_StateSet[k->sID];
+ if( !m_isEnduring )
+ for( unsigned i = 0; i < m_vStates.size(); i++ )
+ {
+ MAutoPtr< StateChange > & k = m_vStates[i];
+ MVector< MAutoPtr< StateChange > > & l = m_StateSet[k->sID];
- unsigned ilpos = l.size() - 1;
+ unsigned ilpos = l.size() - 1;
- if( ilpos <= 0 )
- continue;
+ if( ilpos <= 0 )
+ continue;
- l.resize( ilpos-- );
+ l.resize( ilpos-- );
- if( ilpos >= 0 )
- l[ilpos]->Activate();
- }
+ if( ilpos >= 0 )
+ l[ilpos]->Activate();
+ }
}
bool StateChanger::ChangeKey( const MString & sFile )
@@ -353,6 +355,8 @@
MString sFile = node.Attribute("file");
ChangeKey( sFile );
}
+
+ LOAD_FROM_XML( "enduring", m_isEnduring, StrToBool );
}
void StateChanger::SaveToXMLTag( MString & sXMLStream )
@@ -364,6 +368,9 @@
sXMLStream += "file=\"" + sStr + "\" ";
}
+ if( m_isEnduring )
+ sXMLStream += "enduring=\"1\" ";
+
MercuryAsset::SaveToXMLTag( sXMLStream );
}
Modified: Mercury2/src/StateChanger.h
===================================================================
--- Mercury2/src/StateChanger.h 2010-02-23 01:08:42 UTC (rev 672)
+++ Mercury2/src/StateChanger.h 2010-02-23 02:19:18 UTC (rev 673)
@@ -69,6 +69,7 @@
virtual bool CheckForNewer() { return false; }
virtual void Reload() {};
private:
+ bool m_isEnduring; //If set, then, it does not get "undone" when going back up stack. 90% of all assets should set this to 0
MVector< MAutoPtr< StateChange > > m_vStates;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cn...@us...> - 2010-02-23 22:04:19
|
Revision: 679
http://hgengine.svn.sourceforge.net/hgengine/?rev=679&view=rev
Author: cnlohr
Date: 2010-02-23 22:04:13 +0000 (Tue, 23 Feb 2010)
Log Message:
-----------
tweak - avoid some memory leak junks
Modified Paths:
--------------
Mercury2/src/MercurySound.cpp
Mercury2/src/MercurySound.h
Mercury2/src/MercurySoundDriverALSA.cpp
Modified: Mercury2/src/MercurySound.cpp
===================================================================
--- Mercury2/src/MercurySound.cpp 2010-02-23 20:46:06 UTC (rev 678)
+++ Mercury2/src/MercurySound.cpp 2010-02-23 22:04:13 UTC (rev 679)
@@ -24,6 +24,16 @@
return tm;
}
+MercurySoundManager::~MercurySoundManager()
+{
+ if( m_SoundDriver )
+ {
+ m_SoundDriver->Close();
+ SAFE_DELETE( m_SoundDriver );
+ }
+}
+
+
void MercurySoundManager::Init( const MString & sParameters )
{
MercurySoundDriverConstructionPair * dBest = 0;
@@ -54,7 +64,7 @@
//Otherwise something went wrong.
m_SoundDriver->Close();
- delete m_SoundDriver;
+ SAFE_DELETE( m_SoundDriver );
scBlacklist.insert( dBest );
} while( true );
Modified: Mercury2/src/MercurySound.h
===================================================================
--- Mercury2/src/MercurySound.h 2010-02-23 20:46:06 UTC (rev 678)
+++ Mercury2/src/MercurySound.h 2010-02-23 22:04:13 UTC (rev 679)
@@ -60,6 +60,7 @@
{
public:
MercurySoundManager() { }
+ ~MercurySoundManager();
static MercurySoundManager * Instance();
Modified: Mercury2/src/MercurySoundDriverALSA.cpp
===================================================================
--- Mercury2/src/MercurySoundDriverALSA.cpp 2010-02-23 20:46:06 UTC (rev 678)
+++ Mercury2/src/MercurySoundDriverALSA.cpp 2010-02-23 22:04:13 UTC (rev 679)
@@ -138,7 +138,9 @@
{
tPlayback.Halt( true );
if( playback_handle )
+ {
snd_pcm_close (playback_handle);
+ }
}
void * MercurySoundDriverALSA::playback_thread( void * )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cn...@us...> - 2010-03-03 08:51:28
|
Revision: 684
http://hgengine.svn.sourceforge.net/hgengine/?rev=684&view=rev
Author: cnlohr
Date: 2010-03-03 08:51:22 +0000 (Wed, 03 Mar 2010)
Log Message:
-----------
forgot camera .h and add more traditional lights to state changer, for those who which to manually control their lighting
Modified Paths:
--------------
Mercury2/src/Camera.h
Mercury2/src/StateChanger.cpp
Modified: Mercury2/src/Camera.h
===================================================================
--- Mercury2/src/Camera.h 2010-03-03 08:49:47 UTC (rev 683)
+++ Mercury2/src/Camera.h 2010-03-03 08:51:22 UTC (rev 684)
@@ -26,6 +26,7 @@
MercuryVertex m_origionalPosition;
MercuryVector m_lookAt;
float m_x, m_y;
+ bool m_bFreeFly;
MercuryMatrix m_viewMatrix;
};
Modified: Mercury2/src/StateChanger.cpp
===================================================================
--- Mercury2/src/StateChanger.cpp 2010-03-03 08:49:47 UTC (rev 683)
+++ Mercury2/src/StateChanger.cpp 2010-03-03 08:51:22 UTC (rev 684)
@@ -271,6 +271,7 @@
REGISTER_STATECHANGE( BlendFunc );
+///Change the alpha blending function (can be useful for non-shader farcry-like foliage)
class AlphaFunc : public StateChange
{
public:
@@ -334,6 +335,51 @@
REGISTER_STATECHANGE( AlphaFunc );
+///OpenGL-based fixed light
+class OGLLight : public StateChange
+{
+public:
+ OGLLight( const MVector< MString > & sParameters ) : StateChange( sParameters )
+ {
+ if( sParameters.size() < 5 )
+ {
+ LOG.Write( ssprintf( "Error: Light has invalid number of parameters(%d).", sParameters.size() ) );
+ return;
+ }
+
+ iLight = StrToInt( sParameters[0] );
+
+ for( unsigned i = 0; i < 16; i++ )
+ if( i+1 < sParameters.size() )
+ {
+ fParams[i] = StrToFloat( sParameters[i+1] );
+ }
+ }
+
+ void Stringify( MString & sOut )
+ {
+ sOut = ssprintf( "%d", iLight );
+ for( unsigned i = 0; i < 16; i++ )
+ sOut += ssprintf( ",%f", fParams[i] );
+ }
+
+ void Activate()
+ {
+ GLCALL( glEnable(GL_LIGHT0 + iLight) );
+ GLCALL( glLightfv(GL_LIGHT0, GL_POSITION, &fParams[0]) );
+ GLCALL( glLightfv(GL_LIGHT0, GL_DIFFUSE, &fParams[4]) );
+ GLCALL( glLightfv(GL_LIGHT0, GL_AMBIENT, &fParams[8]) );
+ GLCALL( glLightfv(GL_LIGHT0, GL_SPECULAR, &fParams[12]) );
+
+ }
+
+ STATECHANGE_RTTI( OGLLight );
+
+ int iLight;
+ float fParams[16]; //Position, Diffuse, Ambient, Specular; each [4]
+};
+
+REGISTER_STATECHANGE( OGLLight );
//////////////////////////////////////STATE CHANGE CHUNK//////////////////////////////////////
StateChangeRegister & StateChangeRegister::Instance()
@@ -442,7 +488,7 @@
MString sParameters = sFile.substr( f+1 );
MVector< MString > vsParameters;
- SplitStrings( sParameters, vsParameters, ",", " ", 1, 1 );
+ SplitStrings( sParameters, vsParameters, ",;", " ", 2, 1 );
MAutoPtr< StateChange > s = StateChangeRegister::Instance().Create( sType, vsParameters );
if( s.Ptr() )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cn...@us...> - 2010-03-03 09:07:43
|
Revision: 685
http://hgengine.svn.sourceforge.net/hgengine/?rev=685&view=rev
Author: cnlohr
Date: 2010-03-03 09:07:37 +0000 (Wed, 03 Mar 2010)
Log Message:
-----------
add utility functions for new tweening template thingie that will be coming soon.
Modified Paths:
--------------
Mercury2/src/MercuryUtil.cpp
Mercury2/src/MercuryUtil.h
Modified: Mercury2/src/MercuryUtil.cpp
===================================================================
--- Mercury2/src/MercuryUtil.cpp 2010-03-03 08:51:22 UTC (rev 684)
+++ Mercury2/src/MercuryUtil.cpp 2010-03-03 09:07:37 UTC (rev 685)
@@ -3,6 +3,7 @@
#include <Mint.h>
#include <MercuryVector.h>
#include <MercuryBacktrace.h>
+#include <math.h>
#ifdef WIN32
#include <Windows.h>
@@ -298,6 +299,34 @@
#endif
}
+float FLinear( float in, float slice )
+{
+ float fret = (in - 0.5) * slice;
+
+ if( fret > 0.5 ) fret = 0.5;
+ else if( fret < -0.5 ) fret = -0.5;
+ return fret + 0.5;
+}
+
+float FExponential( float in, float powx )
+{
+ return pow( in, powx );
+}
+
+float FStep( float in, float stepplace )
+{
+ return ( in < stepplace )?0:1;
+}
+
+float FSigmoid( float in, float fspeed )
+{
+ float fi = in - 0.5;
+ float fr = ( exp( fi * fspeed ) - 1 ) / ( exp( fi * fspeed ) + 1 );
+ float smax = ( exp( fspeed * 0.5 ) - 1 ) / ( exp( fspeed * 0.5 ) + 1 );
+ return (fr / smax) / 2. + 0.5;
+}
+
+
/* Copyright (c) 2009, Joshua Allen and Charles Lohr
* All rights reserved.
*
Modified: Mercury2/src/MercuryUtil.h
===================================================================
--- Mercury2/src/MercuryUtil.h 2010-03-03 08:51:22 UTC (rev 684)
+++ Mercury2/src/MercuryUtil.h 2010-03-03 09:07:37 UTC (rev 685)
@@ -135,7 +135,19 @@
MString ConvertToUnformatted( const MString & cf );
///millisecond sleep
-void msleep(uint32_t msec);
+void msleep(uint32_t msec);
+
+///Utility linear function, in = [0..1] out = [0..1]; respectively, if slice >= 1
+float FLinear( float in, float slice = 1. );
+
+///Utility exponential function, in = [0..1] out = [0..1]; respectively; regardless of pow. If pow == 1, would be identical to linear.
+float FExponential( float in, float powx = 1. );
+
+///Utility step function; out = 0 when in < stepplace; out = 1 when in >= stepplace
+float FStep( float in, float stepplace = 1. );
+
+///Utility sigmoid function; in = [0..1] out = [0..1]; speed is the slope of change in the middle.
+float FSigmoid( float in, float fspeed = 1. );
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cn...@us...> - 2010-03-14 23:04:41
|
Revision: 686
http://hgengine.svn.sourceforge.net/hgengine/?rev=686&view=rev
Author: cnlohr
Date: 2010-03-14 23:04:33 +0000 (Sun, 14 Mar 2010)
Log Message:
-----------
Working MQuat
Modified Paths:
--------------
Mercury2/src/MQuaternion.cpp
Mercury2/src/MQuaternion.h
Modified: Mercury2/src/MQuaternion.cpp
===================================================================
--- Mercury2/src/MQuaternion.cpp 2010-03-03 09:07:37 UTC (rev 685)
+++ Mercury2/src/MQuaternion.cpp 2010-03-14 23:04:33 UTC (rev 686)
@@ -7,7 +7,7 @@
m_wxyz[0] = 0;
m_wxyz[1] = 0;
m_wxyz[2] = 0;
- m_wxyz[3] = 0;
+ m_wxyz[3] = 1;
}
MQuaternion::MQuaternion(float W, float X, float Y, float Z)
Modified: Mercury2/src/MQuaternion.h
===================================================================
--- Mercury2/src/MQuaternion.h 2010-03-03 09:07:37 UTC (rev 685)
+++ Mercury2/src/MQuaternion.h 2010-03-14 23:04:33 UTC (rev 686)
@@ -86,6 +86,9 @@
///Produce a matrix out of a rotation x, then y then z (how Mercury does it)
void AngleMatrix (const MercuryVector & angles, MercuryMatrix & mat );
+///Spherically interpolate between two quaternions t = 0..1
+MQuaternion SLERP( const MQuaternion &a, const MQuaternion &b,float t);
+
#endif
/****************************************************************************
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cn...@us...> - 2010-04-08 03:48:50
|
Revision: 689
http://hgengine.svn.sourceforge.net/hgengine/?rev=689&view=rev
Author: cnlohr
Date: 2010-04-08 03:48:44 +0000 (Thu, 08 Apr 2010)
Log Message:
-----------
whoops forgot this stuff
Modified Paths:
--------------
Mercury2/src/MercuryVBO.cpp
Mercury2/src/MercuryVBO.h
Added Paths:
-----------
Mercury2/src/MercuryTransform.cpp
Mercury2/src/MercuryTransform.h
Mercury2/src/MercuryTween.cpp
Mercury2/src/MercuryTween.h
Mercury2/src/VariableRegister.h
Added: Mercury2/src/MercuryTransform.cpp
===================================================================
--- Mercury2/src/MercuryTransform.cpp (rev 0)
+++ Mercury2/src/MercuryTransform.cpp 2010-04-08 03:48:44 UTC (rev 689)
@@ -0,0 +1,57 @@
+#include <MercuryTransform.h>
+
+MercuryTransform::MercuryTransform() : m_bDirty( true )
+{
+ Scale[0] = Scale[1] = Scale[2] = 1;
+}
+
+void MercuryTransform::SetTween( const MercuryTransform & left, const MercuryTransform & right, float fPercent )
+{
+ Position = left.Position * (1-fPercent) + right.Position * fPercent;
+ Scale = left.Scale * (1-fPercent) + right.Scale * fPercent;
+ Rotation = SLERP( left.Rotation, right.Rotation, fPercent );
+ Dirty();
+}
+
+MercuryMatrix & MercuryTransform::GetMatrix()
+{
+ if( m_bDirty )
+ {
+ m_Matrix = MercuryMatrix::Identity();
+ m_Matrix.Translate( Position[0], Position[1], Position[2] );
+ m_Matrix.Rotate( Rotation );
+ m_Matrix.Scale( Scale[0], Scale[1], Scale[2] );
+ m_bDirty = 0;
+ }
+ return m_Matrix;
+}
+
+
+/*
+ * Copyright (c) 2010 Charles Lohr
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ * - Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Mercury Engine nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
Added: Mercury2/src/MercuryTransform.h
===================================================================
--- Mercury2/src/MercuryTransform.h (rev 0)
+++ Mercury2/src/MercuryTransform.h 2010-04-08 03:48:44 UTC (rev 689)
@@ -0,0 +1,60 @@
+#ifndef _MERCURYTRANSFORM_H
+#define _MERCURYTRANSFORM_H
+
+#include <MercuryMatrix.h>
+
+class MercuryTransform
+{
+public:
+ MercuryTransform();
+
+ void SetTween( const MercuryTransform & left, const MercuryTransform & right, float fPercent );
+
+ MercuryMatrix & GetMatrix();
+ inline void Dirty() { m_bDirty = true; }
+ inline bool IsDirty() { return m_bDirty; }
+ MQuaternion Rotation;
+ MercuryVertex Position;
+ MercuryVertex Scale;
+private:
+ MercuryMatrix m_Matrix;
+ bool m_bDirty;
+};
+
+inline void SetTween( MercuryTransform & ActOn, const MercuryTransform & left, const MercuryTransform & right, float fPercent )
+{
+ ActOn.SetTween( left, right, fPercent );
+}
+
+
+#endif
+
+
+/*
+ * Copyright (c) 2010 Charles Lohr
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ * - Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Mercury Engine nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
Added: Mercury2/src/MercuryTween.cpp
===================================================================
--- Mercury2/src/MercuryTween.cpp (rev 0)
+++ Mercury2/src/MercuryTween.cpp 2010-04-08 03:48:44 UTC (rev 689)
@@ -0,0 +1,33 @@
+#include <MercuryTween.h>
+
+//This file is just to make sure MercuryTween compiles OK.
+
+
+/*
+ * Copyright (c) 2010 Charles Lohr
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ * - Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Mercury Engine nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
Added: Mercury2/src/MercuryTween.h
===================================================================
--- Mercury2/src/MercuryTween.h (rev 0)
+++ Mercury2/src/MercuryTween.h 2010-04-08 03:48:44 UTC (rev 689)
@@ -0,0 +1,125 @@
+#ifndef _MERCURYTWEEN_H
+#define _MERCURYTWEEN_H
+
+#include <deque>
+#include "MercuryUtil.h"
+
+typedef float (*TweenFunction)( float, float );
+
+template< typename T >
+class MercuryTweenState
+{
+public:
+ T Target;
+
+ TweenFunction Function;
+ float FunctionP;
+
+ float Time;
+};
+
+template< typename T >
+class MercuryTween
+{
+public:
+ MercuryTween() : Current( 0 ), m_fInOnThisTween( 0 ){ }
+ T * Current;
+
+ void Attach( T * val )
+ {
+ Current = val;
+ m_Last = *Current;
+ }
+
+ void Update( float fDelta )
+ {
+ if( !Current || !m_FutureTweens.size() )
+ return;
+
+ //The following few lines are incredibly convoluted. I do not suggest trying to figure it out.
+ m_fInOnThisTween += fDelta;
+
+ while( m_FutureTweens.size() && m_fInOnThisTween > m_FutureTweens.front().Time )
+ {
+ m_Last = *Current;
+ *Current = m_FutureTweens.front().Target;
+ m_fInOnThisTween -= m_FutureTweens.front().Time;
+ m_FutureTweens.pop_front();
+ }
+
+ if( !m_FutureTweens.size() )
+ {
+ m_fInOnThisTween = 0;
+ m_Last = *Current;
+ return;
+ }
+
+ MercuryTweenState<T> & ts = m_FutureTweens.front();
+
+ SetTween( *Current, m_Last, ts.Target, ts.Function( m_fInOnThisTween/ts.Time, ts.FunctionP ) );
+ }
+
+ void Finish()
+ {
+ Current = m_FutureTweens.back().Target;
+ m_FutureTweens.clear();
+ m_fInOnThisTween = 0;
+ }
+
+ void Stop()
+ {
+ m_FutureTweens.clear();
+ m_fInOnThisTween = 0;
+ }
+
+ void AddTween( MercuryTweenState< T > s )
+ {
+ m_FutureTweens.push_back( s );
+ }
+
+ void AddTween( MString & sTweenSet )
+ {
+ MVector < MString > out;
+ SplitStrings( sTweenSet, out, ";\n", " \t", 2, 2 );
+// for( unsigned i = 0
+ }
+
+private:
+ float m_fInOnThisTween;
+ T m_Last;
+ std::deque< MercuryTweenState< T > > m_FutureTweens;
+};
+
+
+
+#endif
+
+
+/*
+ * Copyright (c) 2010 Charles Lohr
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ * - Redistributions of source code must retain the above
+ * copyright notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the distribution.
+ * - Neither the name of the Mercury Engine nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
Modified: Mercury2/src/MercuryVBO.cpp
===================================================================
--- Mercury2/src/MercuryVBO.cpp 2010-04-05 06:12:33 UTC (rev 688)
+++ Mercury2/src/MercuryVBO.cpp 2010-04-08 03:48:44 UTC (rev 689)
@@ -10,7 +10,7 @@
extern bool SHOWAXISES;
MercuryVBO::MercuryVBO( const MString & key, bool bInstanced, bool useVertexColor )
- :MercuryAsset( key, bInstanced ), m_initiated(false), m_useVertexColor(useVertexColor)
+ :MercuryAsset( key, bInstanced ), m_initiated(false), m_useVertexColor(useVertexColor), m_iIndexCountOverride( -1 )
{
m_bufferIDs[0] = m_bufferIDs[1] = m_bufferIDs[2] = 0;
m_bDirtyIndices = m_bDirtyVertices = m_bDirtyVertexColor = false;
@@ -59,7 +59,11 @@
GLCALL( glEnableClientState( GL_NORMAL_ARRAY ) );
GLCALL( glNormalPointer(GL_FLOAT, STRIDE*sizeof(float), BUFFER_OFFSET(sizeof(float)*2)) );
- GLCALL( glDrawRangeElements(GL_TRIANGLES, 0, m_indexData.Length()-1, m_indexData.Length(), GL_UNSIGNED_SHORT, NULL) );
+ unsigned long iElemsToDraw = (m_iIndexCountOverride!=-1)?m_iIndexCountOverride:(m_indexData.Length()-1);
+//printf( "%d (%d,%d)\n", iElemsToDraw,m_iIndexCountOverride,m_indexData.Length()-1 );
+ GLCALL( glDrawRangeElements( GL_TRIANGLES, 0, iElemsToDraw,
+ iElemsToDraw+1, GL_UNSIGNED_SHORT, NULL) );
+
IncrementBatches();
if (m_boundingVolume && SHOWBOUNDINGVOLUME) m_boundingVolume->Render();
Modified: Mercury2/src/MercuryVBO.h
===================================================================
--- Mercury2/src/MercuryVBO.h 2010-04-05 06:12:33 UTC (rev 688)
+++ Mercury2/src/MercuryVBO.h 2010-04-08 03:48:44 UTC (rev 689)
@@ -45,12 +45,15 @@
inline static const void* GetLastRendered() { return m_lastVBOrendered; }
inline static void IncrementBatches() { ++m_vboBatches; }
+ inline void SetIndexCountOverride( int iCount ) { m_iIndexCountOverride = iCount; }
GENRTTI( MercuryVBO );
protected:
virtual bool CheckForNewer() { return false; }
virtual void Reload() {};
private:
+
+ unsigned long m_iIndexCountOverride;
virtual void InitVBO();
static void* m_lastVBOrendered;
Added: Mercury2/src/VariableRegister.h
===================================================================
--- Mercury2/src/VariableRegister.h (rev 0)
+++ Mercury2/src/VariableRegister.h 2010-04-08 03:48:44 UTC (rev 689)
@@ -0,0 +1,74 @@
+#ifndef _VARIABLE_REGISTER_H
+#define _VARIABLE_REGISTER_H
+
+class VariableReceiver
+{
+public:
+ void VariableDelegate( const MString & sChangedVariable, const MString & sChangedValue );
+};
+
+typedef void (VariableReceiver::*VariableDelegate)( const MString & sChangedVariable, const MString & sChangedValue );
+
+///Variable Register
+/**This is a tool that can be used by programmers and the like to control global variables.
+ It is quite useful in situations where you want to be able to change variables without
+ use of code, and be able to catch changes. */
+class VariablesRegister
+{
+public:
+ void RegisterListener( const MString & sVariable, VariableDelegate d );
+ const MString & GetVariable( const MString & var ) { MString * s = m_mVariables->Get( var ); return s?*s:""; }
+ static MercuryMessageManager& GetInstance();
+private:
+ MHash< MString > m_mVariables;
+
+ struct Sender
+ {
+ VariableDelegate * d;
+
+ };
+ MHash< VariableDelegate > m_mDelegates;
+ MHash<
+};
+
+
+
+static InstanceCounter<VariablesRegister> MMcounter("VariablesRegister");
+
+#define VARIABLES VariablesRegister::GetInstance()
+
+
+#endif
+
+/****************************************************************************
+ * Copyright (C) 2008 by Charles Lohr *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2010-04-25 17:59:49
|
Revision: 695
http://hgengine.svn.sourceforge.net/hgengine/?rev=695&view=rev
Author: axlecrusher
Date: 2010-04-25 17:59:43 +0000 (Sun, 25 Apr 2010)
Log Message:
-----------
box intersection
Modified Paths:
--------------
Mercury2/src/BoundingBox.cpp
Mercury2/src/BoundingBox.h
Modified: Mercury2/src/BoundingBox.cpp
===================================================================
--- Mercury2/src/BoundingBox.cpp 2010-04-25 02:50:12 UTC (rev 694)
+++ Mercury2/src/BoundingBox.cpp 2010-04-25 17:59:43 UTC (rev 695)
@@ -109,12 +109,22 @@
*this = bb;
}
+float BoundingBox::ComputeRadius() const
+{
+/* MercuryVertex p(m_center+m_extend);
+ float r = (m_center-p).Length();
+ if (abs(m_extend.Length() - r) > .000001) printf("wrong %f %f\n",m_extend.Length(), r);
+ return (m_center-p).Length();
+ */
+ return m_extend.Length(); //this is actually correct, verified above
+}
+
bool BoundingBox::Clip( const MercuryPlane& p )
{
//do a quick spherical test using the signed distance
//from the center of the box
float d = p.GetNormal().DotProduct( m_center - p.GetCenter() );
- if (d < -m_extend.Length()) return true; //sphere is further than radius distance behind plane
+ if (d < -ComputeRadius()) return true; //sphere is further than radius distance behind plane
//all points must be behind a plane to be considered clipped
bool clip = true;
@@ -133,6 +143,15 @@
return clipped;
}
+bool BoundingBox::Intersect( const BoundingBox& b )
+{
+ MercuryVector d(m_center - b.m_center);
+ if ( d.Length() > (ComputeRadius()+b.ComputeRadius()) ) return false; //quick circle check
+
+ MercuryVector l(m_extend+b.GetExtend());
+ return l.GetX()<=abs(d.GetX()) && l.GetY()<=abs(d.GetY()) && l.GetZ()<=abs(d.GetZ());
+}
+
bool BoundingBox::DoFrustumTest( const MercuryMatrix& m )
{
BoundingBox bb(*this);
Modified: Mercury2/src/BoundingBox.h
===================================================================
--- Mercury2/src/BoundingBox.h 2010-04-25 02:50:12 UTC (rev 694)
+++ Mercury2/src/BoundingBox.h 2010-04-25 17:59:43 UTC (rev 695)
@@ -85,10 +85,13 @@
virtual bool Clip( const MercuryPlane& p );
virtual bool Clip( const Frustum& f );
+ virtual bool Intersect( const BoundingBox& b );
+
virtual bool DoFrustumTest( const MercuryMatrix& m );
virtual void DoOcclusionTest(OcclusionResult& result);
private:
+ float ComputeRadius() const;
void ComputeNormals();
static void PopulateVertices();
static void InitVBO();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2010-04-25 19:41:25
|
Revision: 697
http://hgengine.svn.sourceforge.net/hgengine/?rev=697&view=rev
Author: axlecrusher
Date: 2010-04-25 19:41:19 +0000 (Sun, 25 Apr 2010)
Log Message:
-----------
Make FloatRow a class to abstract the differences between __m128 and float[4].
Clean up how numbers are accessed in MercuryVertex.
Modified Paths:
--------------
Mercury2/src/MercuryMath.cpp
Mercury2/src/MercuryMath.h
Mercury2/src/MercuryMatrix.cpp
Mercury2/src/MercuryVertex.cpp
Mercury2/src/MercuryVertex.h
Modified: Mercury2/src/MercuryMath.cpp
===================================================================
--- Mercury2/src/MercuryMath.cpp 2010-04-25 18:21:24 UTC (rev 696)
+++ Mercury2/src/MercuryMath.cpp 2010-04-25 19:41:19 UTC (rev 697)
@@ -144,6 +144,13 @@
f[i] = r[i];
}
+void MMCrossProduct( const FloatRow& r1, const FloatRow& r2, FloatRow& result)
+{
+ result[0] = r1[1]*r2[2] - r1[2]*r2[1];
+ result[1] = r1[2]*r2[0] - r1[0]*r2[2];
+ result[2] = r1[0]*r2[1] - r1[1]*r2[0];
+}
+
#else
//inline __m128 Hadd4(__m128 x);
@@ -258,7 +265,7 @@
void ZeroFloatRow(FloatRow& r)
{
- r = (FloatRow)_mm_setzero_ps();
+ r = _mm_setzero_ps();
}
void Float2FloatRow(const float* f, FloatRow& r)
@@ -271,6 +278,20 @@
_mm_store_ps( f, r );
}
+void MMCrossProduct( const FloatRow& r1, const FloatRow& r2, FloatRow& result)
+{
+ __m128 a,b,c,d,r;//using more registers is faster
+
+ a = _mm_shuffle_ps(r1, r1, 0xc9);
+ b = _mm_shuffle_ps(r2, r2, 0xd2);
+ r = _mm_mul_ps( a, b );
+
+ c = _mm_shuffle_ps(r2, r2, 0xc9);
+ d = _mm_shuffle_ps(r1, r1, 0xd2);
+ r -= _mm_mul_ps( c, d );
+ result = r;
+}
+
#endif
/*
Modified: Mercury2/src/MercuryMath.h
===================================================================
--- Mercury2/src/MercuryMath.h 2010-04-25 18:21:24 UTC (rev 696)
+++ Mercury2/src/MercuryMath.h 2010-04-25 19:41:19 UTC (rev 697)
@@ -10,10 +10,26 @@
#ifdef USE_SSE
#include <xmmintrin.h>
-typedef __m128 FloatRow __attribute__((aligned(16)));
+#endif
+class FloatRow
+{
+ public:
+ inline float& operator[](unsigned int i) { return ((float*)&m_floats)[i]; }
+ inline const float& operator[](unsigned int i) const { return ((const float*)&m_floats)[i]; }
+
+ inline operator float*() { return (float*)&m_floats; }
+ inline operator const float*() const { return (const float*)&m_floats; }
+
+#ifndef USE_SSE
+ float m_floats[4];
#else
-typedef float FloatRow[4];
+ inline FloatRow& operator=(const __m128& f) { m_floats=f; return *this; }
+
+ inline operator __m128&() { return m_floats; }
+ inline operator const __m128&() const { return m_floats; }
+ __m128 m_floats __attribute__((aligned(16)));
#endif
+};
#ifdef WIN32
#include <limits>
@@ -79,37 +95,15 @@
void MatrixMultiply4f ( const FloatRow* in1, const FloatRow* in2, FloatRow* out );
void VectorMultiply4f(const FloatRow* matrix, const FloatRow& p, FloatRow& out );
void TransposeMatrix( FloatRow* m );
+void MMCrossProduct( const FloatRow& r1, const FloatRow& r2, FloatRow& result);
//void Float2FloatRow(const float* f, FloatRow& r);
//void FloatRow2Float(const FloatRow& fr, float* f);
-#ifdef USE_SSE
-inline void MMCrossProduct( const FloatRow& r1, const FloatRow& r2, FloatRow& result)
-{
- __m128 a,b,c,d,r;//using more registers is faster
+const FloatRow gfrZero = { { 0.f, 0.f, 0.f, 0.f } };
- a = _mm_shuffle_ps(r1, r1, 0xc9);
- b = _mm_shuffle_ps(r2, r2, 0xd2);
- r = _mm_mul_ps( a, b );
-
- c = _mm_shuffle_ps(r2, r2, 0xc9);
- d = _mm_shuffle_ps(r1, r1, 0xd2);
- r -= _mm_mul_ps( c, d );
- result = r;
-}
-#else
-inline void MMCrossProduct( const FloatRow& r1, const FloatRow& r2, FloatRow& result)
-{
- result[0] = r1[1]*r2[2] - r1[2]*r2[1];
- result[1] = r1[2]*r2[0] - r1[0]*r2[2];
- result[2] = r1[0]*r2[1] - r1[1]*r2[0];
-}
#endif
-const FloatRow gfrZero = { 0.f, 0.f, 0.f, 0.f };
-
-#endif
-
/*
* (c) 2006 Joshua Allen
* All rights reserved.
Modified: Mercury2/src/MercuryMatrix.cpp
===================================================================
--- Mercury2/src/MercuryMatrix.cpp 2010-04-25 18:21:24 UTC (rev 696)
+++ Mercury2/src/MercuryMatrix.cpp 2010-04-25 19:41:19 UTC (rev 697)
@@ -8,7 +8,7 @@
0.0f, 0.0f, 0.0f, 1.0f };
MercuryMatrix::MercuryMatrix()
-{
+{/*
#ifdef USE_SSE
m_matrix[0] = _mm_load1_ps( &base_matrix_identity[0] );
m_matrix[1] = _mm_load1_ps( &base_matrix_identity[4] );
@@ -17,6 +17,8 @@
#else
Copy16f(m_matrix[0], base_matrix_identity );
#endif
+*/
+ *this = Identity();
}
const MercuryMatrix& MercuryMatrix::operator=(const MercuryMatrix& m)
@@ -46,7 +48,7 @@
if (!bSetIdentity)
{
bSetIdentity = true;
-#ifdef USE_SSE
+#ifdef USE_SSEXXX //XXX broken _mm_load1_ps routines
MercuryMatrix::IdentityMatrix.m_matrix[0] = _mm_load1_ps( &base_matrix_identity[0] );
MercuryMatrix::IdentityMatrix.m_matrix[1] = _mm_load1_ps( &base_matrix_identity[4] );
MercuryMatrix::IdentityMatrix.m_matrix[2] = _mm_load1_ps( &base_matrix_identity[8] );
Modified: Mercury2/src/MercuryVertex.cpp
===================================================================
--- Mercury2/src/MercuryVertex.cpp 2010-04-25 18:21:24 UTC (rev 696)
+++ Mercury2/src/MercuryVertex.cpp 2010-04-25 19:41:19 UTC (rev 697)
@@ -7,22 +7,22 @@
MercuryVertex::MercuryVertex()
{
- (*this)[0] = (*this)[1] = (*this)[2] = (*this)[3] = 0;
+ m_xyzw[0] = m_xyzw[1] = m_xyzw[2] = m_xyzw[3] = 0;
}
MercuryVertex::MercuryVertex( float ix, float iy, float iz, float iw )
{
- (*this)[0] = ix;
- (*this)[1] = iy;
- (*this)[2] = iz;
- (*this)[3] = iw;
+ m_xyzw[0] = ix;
+ m_xyzw[1] = iy;
+ m_xyzw[2] = iz;
+ m_xyzw[3] = iw;
}
MercuryVertex::MercuryVertex( const float* in3f, float f )
{
for (unsigned int i = 0; i < 3; ++i)
(*this)[i] = in3f[i];
- (*this)[3] = f;
+ m_xyzw[3] = f;
}
MercuryVertex::MercuryVertex( const float* in4f )
@@ -41,7 +41,7 @@
{
for (unsigned int i = 0; i < 3; ++i)
(*this)[i] = v[i];
- (*this)[3] = w;
+ m_xyzw[3] = w;
}
void MercuryVertex::NormalizeSelf()
@@ -60,19 +60,19 @@
float MercuryVertex::Length() const
{
- float length = (*this)[0]*(*this)[0];
- length += (*this)[1]*(*this)[1];
- length += (*this)[2]*(*this)[2];
- length += (*this)[3]*(*this)[3];
+ float length = m_xyzw[0]*m_xyzw[0];
+ length += m_xyzw[1]*m_xyzw[1];
+ length += m_xyzw[2]*m_xyzw[2];
+ length += m_xyzw[3]*m_xyzw[3];
return SQRT(length);
}
float MercuryVertex::GetBiggestElement() const
{
- float tmp = (*this)[0];
- tmp = MAX<float>(tmp, (*this)[1]);
- tmp = MAX<float>(tmp, (*this)[2]);
- return MAX<float>(tmp, (*this)[3]);
+ float tmp = m_xyzw[0];
+ tmp = MAX<float>(tmp, m_xyzw[1]);
+ tmp = MAX<float>(tmp, m_xyzw[2]);
+ return MAX<float>(tmp, m_xyzw[3]);
}
const MercuryVertex& MercuryVertex::operator *= (const MercuryVertex& p)
@@ -114,7 +114,7 @@
float MercuryVertex::DotProduct(const MercuryVertex& rhs) const
{
//XXX should this use all 4 components?
- return ((*this)[0]*rhs[0]+(*this)[1]*rhs[1]+(*this)[2]*rhs[2]);
+ return (m_xyzw[0]*rhs[0]+m_xyzw[1]*rhs[1]+m_xyzw[2]*rhs[2]);
}
MercuryVertex MercuryVertex::DotProduct3(const MercuryVertex& rhs1, const MercuryVertex& rhs2, const MercuryVertex& rhs3) const
@@ -150,7 +150,7 @@
MString MercuryVertex::Stringify(const MString& s) const
{
- return ssprintf("%s: %f %f %f %f", s.c_str(), (*this)[0], (*this)[1], (*this)[2], (*this)[3]);
+ return ssprintf("%s: %f %f %f %f", s.c_str(), m_xyzw[0], m_xyzw[1], m_xyzw[2], m_xyzw[3]);
}
MercuryVertex MercuryVertex::Rotate(const MQuaternion& q) const
Modified: Mercury2/src/MercuryVertex.h
===================================================================
--- Mercury2/src/MercuryVertex.h 2010-04-25 18:21:24 UTC (rev 696)
+++ Mercury2/src/MercuryVertex.h 2010-04-25 19:41:19 UTC (rev 697)
@@ -24,23 +24,23 @@
MercuryVertex( const MercuryVertex& v, float w);
///Direct conversion to float*
- __inline__ operator float* () { return (float*)&m_xyzw; }
+ __inline__ operator float* () { return m_xyzw; }
///Direct conversion to const float*
- __inline__ operator const float* () const { return (float*)&m_xyzw; }
+ __inline__ operator const float* () const { return m_xyzw; }
inline FloatRow& ToFloatRow() { return m_xyzw; }
inline const FloatRow& ToFloatRow() const { return m_xyzw; }
- inline float GetX() const { return (*this)[0]; }
- inline float GetY() const { return (*this)[1]; }
- inline float GetZ() const { return (*this)[2]; }
- inline float GetW() const { return (*this)[3]; }
- inline void SetX(const float ix) { (*this)[0] = ix; }
- inline void SetY(const float iy) { (*this)[1] = iy; }
- inline void SetZ(const float iz) { (*this)[2] = iz; }
- inline void SetW(const float iw) { (*this)[3] = iw; }
+ inline float GetX() const { return m_xyzw[0]; }
+ inline float GetY() const { return m_xyzw[1]; }
+ inline float GetZ() const { return m_xyzw[2]; }
+ inline float GetW() const { return m_xyzw[3]; }
+ inline void SetX(const float ix) { m_xyzw[0] = ix; }
+ inline void SetY(const float iy) { m_xyzw[1] = iy; }
+ inline void SetZ(const float iz) { m_xyzw[2] = iz; }
+ inline void SetW(const float iw) { m_xyzw[3] = iw; }
- inline void Zero() { (*this)[0] = 0; (*this)[1] = 0; (*this)[2] = 0; }
+ inline void Zero() { m_xyzw[0] = 0; m_xyzw[1] = 0; m_xyzw[2] = 0; }
///Normalize (make |point| = 1)
void NormalizeSelf();
@@ -52,11 +52,11 @@
float GetBiggestElement() const;
///Write out to be = to this point
- inline void ConvertToVector3( float* out ) const { out[0] = (*this)[0]; out[1] = (*this)[1]; out[2] = (*this)[2]; }
+ inline void ConvertToVector3( float* out ) const { out[0] = m_xyzw[0]; out[1] = m_xyzw[1]; out[2] = m_xyzw[2]; }
///Write out to be = to this point, however the 4th element will be 0
- inline void ConvertToVector4( float* out, float w = 0 ) const { out[0] = (*this)[0]; out[1] = (*this)[1]; out[2] = (*this)[2]; out[3] = w; }
+ inline void ConvertToVector4( float* out, float w = 0 ) const { out[0] = m_xyzw[0]; out[1] = m_xyzw[1]; out[2] = m_xyzw[2]; out[3] = w; }
///Write out to be = - to this point, however the 4th element will be 0
- inline void ConvertToIVector4( float* out, float w = 0 ) const { out[0] = -(*this)[0]; out[1] = -(*this)[1]; out[2] = -(*this)[2]; out[3] = w; }
+ inline void ConvertToIVector4( float* out, float w = 0 ) const { out[0] = -m_xyzw[0]; out[1] = -m_xyzw[1]; out[2] = -m_xyzw[2]; out[3] = w; }
const MercuryVertex& operator *= (const MercuryVertex& p);
const MercuryVertex& operator /= (const MercuryVertex& p);
@@ -66,15 +66,15 @@
MercuryVertex operator*(const MercuryMatrix& m) const;
- inline MercuryVertex& operator += ( const MercuryVertex& other ) { (*this)[0]+=other[0]; (*this)[1]+=other[1]; (*this)[2]+=other[2]; return *this; }
- inline MercuryVertex& operator -= ( const MercuryVertex& other ) { (*this)[0]-=other[0]; (*this)[1]-=other[1]; (*this)[2]-=other[2]; return *this; }
- inline MercuryVertex& operator *= ( float f ) { (*this)[0]*=f; (*this)[1]*=f; (*this)[2]*=f; return *this; }
- inline MercuryVertex& operator /= ( float f ) { (*this)[0]/=f; (*this)[1]/=f; (*this)[2]/=f; return *this; }
+ inline MercuryVertex& operator += ( const MercuryVertex& other ) { m_xyzw[0]+=other[0]; m_xyzw[1]+=other[1]; m_xyzw[2]+=other[2]; return *this; }
+ inline MercuryVertex& operator -= ( const MercuryVertex& other ) { m_xyzw[0]-=other[0]; m_xyzw[1]-=other[1]; m_xyzw[2]-=other[2]; return *this; }
+ inline MercuryVertex& operator *= ( float f ) { m_xyzw[0]*=f; m_xyzw[1]*=f; m_xyzw[2]*=f; return *this; }
+ inline MercuryVertex& operator /= ( float f ) { m_xyzw[0]/=f; m_xyzw[1]/=f; m_xyzw[2]/=f; return *this; }
- inline MercuryVertex operator + ( const MercuryVertex& other ) const { return MercuryVertex( (*this)[0]+other[0], (*this)[1]+other[1], (*this)[2]+other[2] ); }
- inline MercuryVertex operator - ( const MercuryVertex& other ) const { return MercuryVertex( (*this)[0]-other[0], (*this)[1]-other[1], (*this)[2]-other[2] ); }
- inline MercuryVertex operator * ( float f ) const { return MercuryVertex( (*this)[0]*f, (*this)[1]*f, (*this)[2]*f ); }
- inline MercuryVertex operator / ( float f ) const { return MercuryVertex( (*this)[0]/f, (*this)[1]/f, (*this)[2]/f ); }
+ inline MercuryVertex operator + ( const MercuryVertex& other ) const { return MercuryVertex( m_xyzw[0]+other[0], m_xyzw[1]+other[1], m_xyzw[2]+other[2] ); }
+ inline MercuryVertex operator - ( const MercuryVertex& other ) const { return MercuryVertex( m_xyzw[0]-other[0], m_xyzw[1]-other[1], m_xyzw[2]-other[2] ); }
+ inline MercuryVertex operator * ( float f ) const { return MercuryVertex( m_xyzw[0]*f, m_xyzw[1]*f, m_xyzw[2]*f ); }
+ inline MercuryVertex operator / ( float f ) const { return MercuryVertex( m_xyzw[0]/f, m_xyzw[1]/f, m_xyzw[2]/f ); }
bool operator==(const MercuryVertex& p) const;
inline bool operator!=(const MercuryVertex& p) const { return !(*this == p); }
@@ -96,7 +96,7 @@
static MercuryVertex CreateFromString(const MString& s);
-// float (*this)[3];
+// float m_xyzw[3];
FloatRow m_xyzw;
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2010-04-26 02:41:16
|
Revision: 701
http://hgengine.svn.sourceforge.net/hgengine/?rev=701&view=rev
Author: axlecrusher
Date: 2010-04-26 02:41:10 +0000 (Mon, 26 Apr 2010)
Log Message:
-----------
fix ambiguous warnings
Modified Paths:
--------------
Mercury2/src/MercuryMath.cpp
Mercury2/src/MercuryMath.h
Modified: Mercury2/src/MercuryMath.cpp
===================================================================
--- Mercury2/src/MercuryMath.cpp 2010-04-25 22:33:57 UTC (rev 700)
+++ Mercury2/src/MercuryMath.cpp 2010-04-26 02:41:10 UTC (rev 701)
@@ -205,7 +205,11 @@
{
unsigned int y;
__m128 xmm[4];
-
+
+// PREFETCH(in1, _MM_HINT_T0);
+// PREFETCH(in2, _MM_HINT_T1);
+// PREFETCH(out, _MM_HINT_T1);
+
for (y = 0; y < 4; ++y)
{
//load rows as columns
Modified: Mercury2/src/MercuryMath.h
===================================================================
--- Mercury2/src/MercuryMath.h 2010-04-25 22:33:57 UTC (rev 700)
+++ Mercury2/src/MercuryMath.h 2010-04-26 02:41:10 UTC (rev 701)
@@ -10,13 +10,13 @@
#ifdef USE_SSE
#include <xmmintrin.h>
+#define PREFETCH(a,sel) _mm_prefetch(a,sel); //prefetch a cache line (64 bytes)
+#else
+#define PREFETCH(a,sel) ; //prefetch a cache line (64 bytes)
#endif
class FloatRow
{
public:
- inline float& operator[](unsigned int i) { return ((float*)&m_floats)[i]; }
- inline const float& operator[](unsigned int i) const { return ((const float*)&m_floats)[i]; }
-
inline operator float*() { return (float*)&m_floats; }
inline operator const float*() const { return (const float*)&m_floats; }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2010-04-27 00:16:12
|
Revision: 702
http://hgengine.svn.sourceforge.net/hgengine/?rev=702&view=rev
Author: axlecrusher
Date: 2010-04-27 00:16:04 +0000 (Tue, 27 Apr 2010)
Log Message:
-----------
Convert boolean variables into bitwise flags to cut down on memory use.
Modified Paths:
--------------
Mercury2/src/MercuryMath.h
Mercury2/src/MercuryNode.cpp
Mercury2/src/MercuryNode.h
Modified: Mercury2/src/MercuryMath.h
===================================================================
--- Mercury2/src/MercuryMath.h 2010-04-26 02:41:10 UTC (rev 701)
+++ Mercury2/src/MercuryMath.h 2010-04-27 00:16:04 UTC (rev 702)
@@ -97,6 +97,10 @@
void TransposeMatrix( FloatRow* m );
void MMCrossProduct( const FloatRow& r1, const FloatRow& r2, FloatRow& result);
+//http://graphics.stanford.edu/~seander/bithacks.html
+#define SetBit(x,mask,t) ((x & ~mask) | (-t & mask)) /*superscalar CPU version*/
+#define GetBit(x,mask) (x & mask)
+
//void Float2FloatRow(const float* f, FloatRow& r);
//void FloatRow2Float(const FloatRow& fr, float* f);
Modified: Mercury2/src/MercuryNode.cpp
===================================================================
--- Mercury2/src/MercuryNode.cpp 2010-04-26 02:41:10 UTC (rev 701)
+++ Mercury2/src/MercuryNode.cpp 2010-04-27 00:16:04 UTC (rev 702)
@@ -17,9 +17,7 @@
MercuryNode::MercuryNode()
:m_parent(NULL), m_prevSibling(NULL),
- m_nextSibling(NULL), m_hidden(false),
- m_useAlphaPath(false), m_culled(false),
- m_bEnableSave(true), m_bEnableSaveChildren(true),
+ m_nextSibling(NULL), m_flags(SAVECHILDREN & ENABLESAVE),
m_iPasses( DEFAULT_PASSES ), m_iForcePasses( 0 )
{
m_pGlobalMatrix = &MercuryMatrix::Identity();
@@ -213,7 +211,7 @@
for (MercuryNode* child = FirstChild(); child != NULL; child = NextChild(child))
{
child->RecursivePreRender();
- m_culled = m_culled && child->IsCulled();
+ SetCulled( IsCulled() && child->IsCulled() );
}
}
@@ -254,7 +252,7 @@
//call render on other render graph entries under me
for (MercuryNode* child = FirstChild(); child != NULL; child = NextChild(child))
{
- if ( child->m_useAlphaPath )
+ if ( child->GetUseAlphaPass() )
CURRENTRENDERGRAPH->AddAlphaNode(child);
else
child->RecursiveRender();
@@ -284,10 +282,12 @@
{
SetName( node.Attribute("name") );
- LOAD_FROM_XML( "hidden", m_hidden, StrToBool );
- LOAD_FROM_XML( "alphaPath", m_useAlphaPath, StrToBool );
- LOAD_FROM_XML( "enableSave", m_bEnableSave, StrToBool );
- LOAD_FROM_XML( "enableSaveChildren", m_bEnableSaveChildren, StrToBool );
+ bool t;
+ t = IsHidden(); LOAD_FROM_XML( "hidden", t, StrToBool ); SetHidden(t);
+ t = GetUseAlphaPass(); LOAD_FROM_XML( "alphaPath", t, StrToBool ); SetUseAlphaPass(t);
+ t = GetEnableSave(); LOAD_FROM_XML( "enableSave", t, StrToBool ); SetEnableSave(t);
+ t = GetSaveChildren(); LOAD_FROM_XML( "enableSaveChildren", t, StrToBool );
+ SetSaveChildren(t);
//Not much to do here except run through all the children nodes
@@ -324,7 +324,7 @@
void MercuryNode::SaveToXML( MString & sXMLStream, int depth )
{
- if( !m_bEnableSave ) return;
+ if( !GetEnableSave() ) return;
sXMLStream += ssprintf( "%*c<node ", depth * 3, 32 );
SaveBaseXMLTag( sXMLStream );
@@ -332,7 +332,7 @@
bool bNoChildren = true;
- if( m_bEnableSaveChildren )
+ if( GetSaveChildren() )
{
if( !m_assets.empty() )
{
@@ -350,7 +350,7 @@
//No children yet (but we have them, so terminate (>) )
for( std::list< MercuryNode * >::iterator i = m_children.begin(); i != m_children.end(); i++ )
{
- if( (*i)->m_bEnableSave )
+ if( (*i)->GetEnableSave() )
{
if( bNoChildren )
sXMLStream += ">\n";
@@ -377,7 +377,7 @@
sXMLStream+= ssprintf( "type=\"%s\" ", GetType() );
if( GetName().length() )
sXMLStream += ssprintf( "name=\"%s\" ", GetName().c_str() );
- if( m_useAlphaPath )
+ if( GetUseAlphaPass() )
sXMLStream += "alphaPath=\"true\" ";
}
Modified: Mercury2/src/MercuryNode.h
===================================================================
--- Mercury2/src/MercuryNode.h 2010-04-26 02:41:10 UTC (rev 701)
+++ Mercury2/src/MercuryNode.h 2010-04-27 00:16:04 UTC (rev 702)
@@ -28,6 +28,15 @@
///The Global Pass Number (which Pass is currently doing Render)
extern __ThreadLocalStore int g_iPass;
+enum MercuryNodeFlagMask
+{
+ HIDDEN = 1,
+ CULLED,
+ SAVECHILDREN,
+ ENABLESAVE,
+ ALPHAPATH
+};
+
class MercuryNode : public MessageHandler
{
public:
@@ -114,10 +123,21 @@
virtual void Render(const MercuryMatrix& matrix);
virtual void PostRender(const MercuryMatrix& matrix);
- inline bool IsHidden() { return m_hidden; }
+ virtual void SetHidden( bool bHide ) { m_flags = SetBit(m_flags,HIDDEN,bHide); } //is there anyway to make this not virtual??
+ inline bool IsHidden() { return GetBit(m_flags,HIDDEN); }
- inline void SetCulled(bool t) { m_culled = t; }
- inline bool IsCulled() const { return m_culled; }
+ inline void SetCulled(bool t) { m_flags = SetBit(m_flags,CULLED,t); }
+ inline bool IsCulled() const { return GetBit(m_flags,CULLED); }
+
+ inline void SetSaveChildren(bool t) { m_flags = SetBit(m_flags,SAVECHILDREN,t); }
+ inline bool GetSaveChildren() const { return GetBit(m_flags,SAVECHILDREN); }
+
+ inline void SetEnableSave(bool t) { m_flags = SetBit(m_flags,ENABLESAVE,t); }
+ inline bool GetEnableSave() const { return GetBit(m_flags,ENABLESAVE); }
+
+ inline void SetUseAlphaPass(bool t) { m_flags = SetBit(m_flags,ALPHAPATH,t); }
+ inline bool GetUseAlphaPass() const { return GetBit(m_flags,ALPHAPATH); }
+
virtual MercuryMatrix ManipulateMatrix(const MercuryMatrix& matrix);
const MercuryMatrix & GetGlobalMatrix() const { return m_pGlobalMatrix[g_iViewportID]; }
@@ -125,7 +145,6 @@
inline unsigned short GetPasses() const { return m_iPasses; }
- virtual void SetHidden( bool bHide ) { m_hidden = bHide; }
protected:
std::list< MercuryNode* > m_children; //These nodes are unique, not instanced
MercuryNode* m_parent;
@@ -135,11 +154,7 @@
static bool m_rebuildRenderGraph;
MString m_name;
- bool m_hidden;
- bool m_useAlphaPath;
- bool m_culled;
- bool m_bEnableSave;
- bool m_bEnableSaveChildren;
+ unsigned char m_flags;
bool IsInAssetList(MercuryAsset* asset) const;
unsigned short m_iPasses;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2010-04-27 18:20:49
|
Revision: 705
http://hgengine.svn.sourceforge.net/hgengine/?rev=705&view=rev
Author: axlecrusher
Date: 2010-04-27 18:20:41 +0000 (Tue, 27 Apr 2010)
Log Message:
-----------
visual studio and GCC Alignment
Modified Paths:
--------------
Mercury2/src/MQuaternion.h
Mercury2/src/MercuryMath.h
Mercury2/src/MercuryMatrix.cpp
Mercury2/src/MercuryMatrix.h
Mercury2/src/MercuryUtil.h
Modified: Mercury2/src/MQuaternion.h
===================================================================
--- Mercury2/src/MQuaternion.h 2010-04-27 18:16:51 UTC (rev 704)
+++ Mercury2/src/MQuaternion.h 2010-04-27 18:20:41 UTC (rev 705)
@@ -7,7 +7,7 @@
class MercuryMatrix;
///Mathematical Quaternion (Used for Rotation)
-class MQuaternion {
+VC_ALIGN(16) class MQuaternion {
public:
enum WXYZ { QW = 0, QX, QY, QZ };
@@ -81,7 +81,7 @@
//Also, for most operations, it appeared to go slower. All the moving in and out of these variables
//is disadvantagious.
float m_wxyz[4];
-} M_ALIGN(32);
+} CC_ALIGN(16);
///Produce a matrix out of a rotation x, then y then z (how Mercury does it)
void AngleMatrix (const MercuryVector & angles, MercuryMatrix & mat );
Modified: Mercury2/src/MercuryMath.h
===================================================================
--- Mercury2/src/MercuryMath.h 2010-04-27 18:16:51 UTC (rev 704)
+++ Mercury2/src/MercuryMath.h 2010-04-27 18:20:41 UTC (rev 705)
@@ -1,5 +1,5 @@
#ifndef _MERCURYMATH_H
-#define _MERCURYMATH_H
+#define _MERCURYMATH_H
#include <math.h>
#ifdef HGENGINE
@@ -8,13 +8,21 @@
#endif
#endif
+#if defined(__GNUC__)
+#define VC_ALIGN(n)
+#define CC_ALIGN(n) __attribute__((aligned(n)))
+#else
+#define VC_ALIGN(n) __declspec(align(n))
+#define CC_ALIGN(n)
+#endif
+
#ifdef USE_SSE
#include <xmmintrin.h>
#define PREFETCH(a,sel) _mm_prefetch(a,sel); //prefetch a cache line (64 bytes)
#else
#define PREFETCH(a,sel) ; //prefetch a cache line (64 bytes)
#endif
-class FloatRow
+VC_ALIGN(16) class FloatRow
{
public:
inline operator float*() { return (float*)&m_floats; }
@@ -27,9 +35,10 @@
inline operator __m128&() { return m_floats; }
inline operator const __m128&() const { return m_floats; }
- __m128 m_floats __attribute__((aligned(16)));
+// __m128 m_floats __attribute__((aligned(16)));
+ __m128 m_floats;
#endif
-};
+} CC_ALIGN(16);
#ifdef WIN32
#include <limits>
@@ -99,7 +108,7 @@
//http://graphics.stanford.edu/~seander/bithacks.html
#define SetBit(x,mask,t) ((x & ~mask) | (-t & mask)) /*superscalar CPU version*/
-#define GetBit(x,mask) (x & mask)
+#define GetBit(x,mask) ((x & mask)>0)
//void Float2FloatRow(const float* f, FloatRow& r);
//void FloatRow2Float(const FloatRow& fr, float* f);
Modified: Mercury2/src/MercuryMatrix.cpp
===================================================================
--- Mercury2/src/MercuryMatrix.cpp 2010-04-27 18:16:51 UTC (rev 704)
+++ Mercury2/src/MercuryMatrix.cpp 2010-04-27 18:20:41 UTC (rev 705)
@@ -1,7 +1,7 @@
#include "MercuryMatrix.h"
#include <MercuryLog.h>
-float base_matrix_identity[16] = {
+VC_ALIGN(16) float base_matrix_identity[16] CC_ALIGN(16) = {
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
@@ -18,7 +18,8 @@
Copy16f(m_matrix[0], base_matrix_identity );
#endif
*/
- *this = Identity();
+// *this = Identity();
+ LoadIdentity();
}
const MercuryMatrix& MercuryMatrix::operator=(const MercuryMatrix& m)
@@ -61,6 +62,11 @@
return IdentityMatrix;
}
+void MercuryMatrix::LoadIdentity()
+{
+ Copy16f(m_matrix, base_matrix_identity );
+}
+
void MercuryMatrix::Translate(float x, float y, float z)
{
MercuryMatrix m;
Modified: Mercury2/src/MercuryMatrix.h
===================================================================
--- Mercury2/src/MercuryMatrix.h 2010-04-27 18:16:51 UTC (rev 704)
+++ Mercury2/src/MercuryMatrix.h 2010-04-27 18:20:41 UTC (rev 705)
@@ -8,7 +8,7 @@
#include <MQuaternion.h>
///General Purpose 4x4 row-major matrix
-class MercuryMatrix
+ VC_ALIGN(16) class MercuryMatrix
{
private:
///[row][column] (The internal matrix)
@@ -52,14 +52,10 @@
void Zero();
static const MercuryMatrix& Identity();
+ void LoadIdentity();
void Print() const;
-}
-#if !defined( WIN32 ) || defined( _MSC_VER )
-M_ALIGN(64);
-#else
-M_ALIGN(16);
-#endif
+} CC_ALIGN(16);
//namespace MercuryMath
//{
Modified: Mercury2/src/MercuryUtil.h
===================================================================
--- Mercury2/src/MercuryUtil.h 2010-04-27 18:16:51 UTC (rev 704)
+++ Mercury2/src/MercuryUtil.h 2010-04-27 18:20:41 UTC (rev 705)
@@ -19,12 +19,6 @@
void* mmemalign(size_t align, size_t size, void*& mem);
bool isAligned(size_t align, const void* mem);
-#if defined(__GNUC__)
-#define M_ALIGN(n) __attribute__((aligned(n)))
-#else
-#define M_ALIGN(n)
-#endif
-
///Make a string all upper case
MString ToUpper(const MString & s);
@@ -96,10 +90,10 @@
///Open up filename: sFileName and dump it into a new buffer; you must delete the return value when done.
///The return value is -1 if there was an issue, otherwise it is valid.
long FileToString( const MString & sFileName, char * & data );
-
-///Take a string and write it to the hard drive as a file. True indicates everything is okay.
-bool StringToFile( const MString & sFileName, const MString & data );
+///Take a string and write it to the hard drive as a file. True indicates everything is okay.
+bool StringToFile( const MString & sFileName, const MString & data );
+
/* These two functions are very different */
/// nextPow2 will go to the NEXT power of 2 even if x is already a power of 2.
inline int nextPow2(int x) { int num = 1; while(num <= x) num <<= 1; return num; }
@@ -135,20 +129,20 @@
MString ConvertToUnformatted( const MString & cf );
///millisecond sleep
-void msleep(uint32_t msec);
-
-///Utility linear function, in = [0..1] out = [0..1]; respectively, if slice >= 1
-float FLinear( float in, float slice = 1. );
-
-///Utility exponential function, in = [0..1] out = [0..1]; respectively; regardless of pow. If pow == 1, would be identical to linear.
-float FExponential( float in, float powx = 1. );
-
-///Utility step function; out = 0 when in < stepplace; out = 1 when in >= stepplace
-float FStep( float in, float stepplace = 1. );
-
-///Utility sigmoid function; in = [0..1] out = [0..1]; speed is the slope of change in the middle.
-float FSigmoid( float in, float fspeed = 1. );
+void msleep(uint32_t msec);
+///Utility linear function, in = [0..1] out = [0..1]; respectively, if slice >= 1
+float FLinear( float in, float slice = 1. );
+
+///Utility exponential function, in = [0..1] out = [0..1]; respectively; regardless of pow. If pow == 1, would be identical to linear.
+float FExponential( float in, float powx = 1. );
+
+///Utility step function; out = 0 when in < stepplace; out = 1 when in >= stepplace
+float FStep( float in, float stepplace = 1. );
+
+///Utility sigmoid function; in = [0..1] out = [0..1]; speed is the slope of change in the middle.
+float FSigmoid( float in, float fspeed = 1. );
+
#endif
/* Copyright (c) 2009, Joshua Allen and Charles Lohr
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2010-05-03 02:26:00
|
Revision: 720
http://hgengine.svn.sourceforge.net/hgengine/?rev=720&view=rev
Author: axlecrusher
Date: 2010-05-03 02:25:54 +0000 (Mon, 03 May 2010)
Log Message:
-----------
It is not necessary to look up the uniform by name again when we just found it and can just pass the uniform location along.
Modified Paths:
--------------
Mercury2/src/Shader.cpp
Mercury2/src/Shader.h
Modified: Mercury2/src/Shader.cpp
===================================================================
--- Mercury2/src/Shader.cpp 2010-05-03 02:22:28 UTC (rev 719)
+++ Mercury2/src/Shader.cpp 2010-05-03 02:25:54 UTC (rev 720)
@@ -442,7 +442,7 @@
{
ShaderAttribute* a = m_globalAttributes.get( ui->name );
if( a )
- SetAttributeInternal(ui->name,*a);
+ SetAttributeInternal(ui->id,*a);
}
}
@@ -479,26 +479,30 @@
void Shader::SetAttributeInternal(const MString& name, const ShaderAttribute& x)
{
int location = GetUniformLocation( name );
+ SetAttributeInternal(location, x);
+}
- if ( location != -1 )
+void Shader::SetAttributeInternal(int uniformLoc, const ShaderAttribute& x)
+{
+ if ( uniformLoc != -1 )
{
switch( x.type )
{
case ShaderAttribute::TYPE_INT:
case ShaderAttribute::TYPE_SAMPLER:
- GLCALL( glUniform1iARB( location, x.value.iInt ) );
+ GLCALL( glUniform1iARB( uniformLoc, x.value.iInt ) );
break;
case ShaderAttribute::TYPE_FLOAT:
- GLCALL( glUniform1fARB( location, x.value.fFloat ) );
+ GLCALL( glUniform1fARB( uniformLoc, x.value.fFloat ) );
break;
case ShaderAttribute::TYPE_FLOATV4:
- GLCALL( glUniform4fvARB( location, 1, &x.value.fFloatV4[0] ) );
+ GLCALL( glUniform4fvARB( uniformLoc, 1, &x.value.fFloatV4[0] ) );
break;
case ShaderAttribute::TYPE_MATRIX:
- GLCALL( glUniformMatrix4fvARB(location, 1, 1, x.value.matrix) ); //transpose too
+ GLCALL( glUniformMatrix4fvARB(uniformLoc, 1, 1, x.value.matrix) ); //transpose too
break;
case ShaderAttribute::TYPE_INT4:
- GLCALL( glUniform4ivARB( location, 1, x.value.iInts ) );
+ GLCALL( glUniform4ivARB( uniformLoc, 1, x.value.iInts ) );
break;
};
GLERRORCHECK;
Modified: Mercury2/src/Shader.h
===================================================================
--- Mercury2/src/Shader.h 2010-05-03 02:22:28 UTC (rev 719)
+++ Mercury2/src/Shader.h 2010-05-03 02:25:54 UTC (rev 720)
@@ -100,6 +100,7 @@
int32_t GetUniformLocation(const MString& n);
void SetAttributeInternal(const MString& name, const ShaderAttribute& x);
+ void SetAttributeInternal(int uniformLoc, const ShaderAttribute& x);
///Suggested function for loading shaders.
/** This function looks for {sShaderName}.vert and {sShaderName}.frag. It will
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2010-05-03 03:10:31
|
Revision: 719
http://hgengine.svn.sourceforge.net/hgengine/?rev=719&view=rev
Author: axlecrusher
Date: 2010-05-03 02:22:28 +0000 (Mon, 03 May 2010)
Log Message:
-----------
Take advantage of the source and destination matrices being able to be the same address.
Modified Paths:
--------------
Mercury2/src/MercuryMatrix.cpp
Mercury2/src/MercuryMatrix.h
Modified: Mercury2/src/MercuryMatrix.cpp
===================================================================
--- Mercury2/src/MercuryMatrix.cpp 2010-05-03 02:11:54 UTC (rev 718)
+++ Mercury2/src/MercuryMatrix.cpp 2010-05-03 02:22:28 UTC (rev 719)
@@ -129,10 +129,12 @@
void MercuryMatrix::Translate(float x, float y, float z)
{
MercuryMatrix m;
+
m[0][3] = x;
m[1][3] = y;
m[2][3] = z;
- *this *= m;
+
+ MatrixMultiply4f(m_matrix,m.m_matrix,m_matrix);
}
void MercuryMatrix::RotateXYZ(float x, float y, float z)
@@ -172,7 +174,7 @@
matrix[2][3] = 0;
matrix[3][3] = 1;
- *this *= matrix;
+ MatrixMultiply4f(m_matrix,matrix.m_matrix,m_matrix);
}
void MercuryMatrix::RotateAngAxis( float fAngle, float ix, float iy, float iz )
@@ -249,7 +251,7 @@
matrix[2][3] = tZ;
matrix[3][3] = 1;
- *this *= matrix;
+ MatrixMultiply4f(m_matrix,matrix.m_matrix,m_matrix);
}
@@ -271,12 +273,6 @@
return r;
}
-MercuryMatrix& MercuryMatrix::operator*=(const MercuryMatrix& m)
-{
- MatrixMultiply4f ( m_matrix, m.m_matrix, m_matrix);
- return *this;
-}
-
void MercuryMatrix::Print() const
{
for (int i = 0; i < 4; ++i)
Modified: Mercury2/src/MercuryMatrix.h
===================================================================
--- Mercury2/src/MercuryMatrix.h 2010-05-03 02:11:54 UTC (rev 718)
+++ Mercury2/src/MercuryMatrix.h 2010-05-03 02:22:28 UTC (rev 719)
@@ -52,8 +52,10 @@
inline const float* Ptr() const { return (const float*)m_matrix; }
MercuryMatrix operator*(const MercuryMatrix& m) const;
- MercuryMatrix& operator*=(const MercuryMatrix& m);
+ inline MercuryMatrix& operator*=(const MercuryMatrix& m)
+ { MatrixMultiply4f ( m_matrix, m.m_matrix, m_matrix); return *this; }
+
MercuryVector operator*(const MercuryVertex& v) const;
void Translate(float x, float y, float z);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cn...@us...> - 2010-05-04 07:06:19
|
Revision: 722
http://hgengine.svn.sourceforge.net/hgengine/?rev=722&view=rev
Author: cnlohr
Date: 2010-05-04 07:06:13 +0000 (Tue, 04 May 2010)
Log Message:
-----------
"fix" threads on Linux i686, or rather, avoid potentially problematic area
Modified Paths:
--------------
Mercury2/src/MercuryThreads.cpp
Mercury2/src/MercuryThreads.h
Modified: Mercury2/src/MercuryThreads.cpp
===================================================================
--- Mercury2/src/MercuryThreads.cpp 2010-05-03 02:28:59 UTC (rev 721)
+++ Mercury2/src/MercuryThreads.cpp 2010-05-04 07:06:13 UTC (rev 722)
@@ -9,6 +9,26 @@
#include <stdint.h>
#endif
+//#define EXTRA_DEBUG_ON_THREAD_FAIL
+
+#ifdef EXTRA_DEBUG_ON_THREAD_FAIL
+#include <MercuryBacktrace.h>
+void ThreadPrintBacktrace()
+{
+ fprintf( stderr, "Printing backtrace...\n" );
+ char buffer[2048];
+ int i = cnget_backtrace( 1, buffer, 2048 );
+ fprintf( stderr, "%s\n", buffer );
+}
+
+#else
+void ThreadPrintBacktrace()
+{
+}
+#endif
+
+
+
//XXX WARNING in windows mutex of the same name are shared!!!
//we can not give mutexes a default name
@@ -169,13 +189,22 @@
switch( r )
{
case WAIT_TIMEOUT:
+ //
+ ThreadPrintBacktrace();
+ //
fprintf(stderr, "Mutex held by thread ID 0x%x timed out (%d locks)\n", m_heldBy, iLockCount );
return false;
case WAIT_FAILED:
+ //
+ ThreadPrintBacktrace();
+ //
fprintf(stderr, "Mutex held by thread ID 0x%x failed (%d locks)\n", m_heldBy, iLockCount );
return false;
}
#else
+ //This seems to have some curious behavior in i386 Linux (tested and found problematic in Ubuntu 9.04)
+ //which can cause a crash of the program in an infinite loop. I do not know what is casuing it, but
+ //My general suggestion is that it be avoided - Charles
if ( lMilliseconds < 0xFFFFFF )
{
timeval t;
@@ -205,6 +234,7 @@
fprintf(stderr, "Max Recursive Locks Reached\n");
return false;
case ETIMEDOUT:
+ ThreadPrintBacktrace();
fprintf(stderr, "Mutex held by thread ID 0x%lx timed out (%d locks)\n", m_heldBy, iLockCount );
return false;
}
Modified: Mercury2/src/MercuryThreads.h
===================================================================
--- Mercury2/src/MercuryThreads.h 2010-05-03 02:28:59 UTC (rev 721)
+++ Mercury2/src/MercuryThreads.h 2010-05-04 07:06:13 UTC (rev 722)
@@ -123,8 +123,8 @@
{
//loop until we get a lock but use a timeout so we are warned
//of a held mutex indicating a possible deadlock
- bool l = m_mutex->Wait(1000);
- while (!l) m_mutex->Wait(1000);
+ bool l = m_mutex->Wait(0xFFFFFF);
+ while (!l) m_mutex->Wait(0xFFFFFF);
}
~AutoMutexLock()
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2010-05-05 11:04:23
|
Revision: 724
http://hgengine.svn.sourceforge.net/hgengine/?rev=724&view=rev
Author: axlecrusher
Date: 2010-05-05 11:04:17 +0000 (Wed, 05 May 2010)
Log Message:
-----------
Explicit call to destructor if using MercuryCTA. Fixes MercuryMatrix leak when IsHidden.
Modified Paths:
--------------
Mercury2/src/MercuryMessageManager.cpp
Mercury2/src/RenderGraph.cpp
Modified: Mercury2/src/MercuryMessageManager.cpp
===================================================================
--- Mercury2/src/MercuryMessageManager.cpp 2010-05-04 10:41:53 UTC (rev 723)
+++ Mercury2/src/MercuryMessageManager.cpp 2010-05-05 11:04:17 UTC (rev 724)
@@ -42,6 +42,7 @@
{
FireOffMessage( *mh );
SAFE_DELETE( mh->data );
+ mh->~MessageHolder();//explicitly call destructor since free() is used
HolderAllocator.Free(mh);
}
}
Modified: Mercury2/src/RenderGraph.cpp
===================================================================
--- Mercury2/src/RenderGraph.cpp 2010-05-04 10:41:53 UTC (rev 723)
+++ Mercury2/src/RenderGraph.cpp 2010-05-05 11:04:17 UTC (rev 724)
@@ -125,6 +125,7 @@
for (i = srs->Assets.begin();i != srs->Assets.end(); ++i)
(*i)->PostRender(srs->Node);
+ srs->~StoreRenderState();//explicitly call destructor since free() is used
AlphaHolderAllocator.Free( srs );
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2010-05-17 23:58:33
|
Revision: 733
http://hgengine.svn.sourceforge.net/hgengine/?rev=733&view=rev
Author: axlecrusher
Date: 2010-05-17 23:58:27 +0000 (Mon, 17 May 2010)
Log Message:
-----------
Fix SSE on windows. We can't rely on the stack to align variables properly so we need to do it ourself.
Modified Paths:
--------------
Mercury2/src/AlignedBuffer.h
Mercury2/src/MercuryMath.cpp
Mercury2/src/MercuryMatrix.cpp
Mercury2/src/MercuryMatrix.h
Modified: Mercury2/src/AlignedBuffer.h
===================================================================
--- Mercury2/src/AlignedBuffer.h 2010-05-16 15:28:56 UTC (rev 732)
+++ Mercury2/src/AlignedBuffer.h 2010-05-17 23:58:27 UTC (rev 733)
@@ -18,7 +18,10 @@
void Allocate(unsigned long count, uint8_t alignment = 32)
{
- SAFE_FREE(m_mem);
+ if (m_mem!=0)
+ free(m_mem);
+ m_mem=0;
+
void * m_memret;
m_data = (T*)mmemalign(alignment, sizeof(T)*count, m_memret);
m_mem = (T*)m_memret;
@@ -27,7 +30,8 @@
void Free()
{
- SAFE_FREE(m_mem);
+ if (m_mem!=0)
+ free(m_mem);
m_data = NULL;
m_length = 0;
}
Modified: Mercury2/src/MercuryMath.cpp
===================================================================
--- Mercury2/src/MercuryMath.cpp 2010-05-16 15:28:56 UTC (rev 732)
+++ Mercury2/src/MercuryMath.cpp 2010-05-17 23:58:27 UTC (rev 733)
@@ -320,13 +320,15 @@
_mm_store_ps( f, r );
}
*/
+
void MMCrossProduct( const FloatRow& r1, const FloatRow& r2, FloatRow& result)
{
__m128 a,b,c,d,r;//using more registers is faster
__m128 t1,t2;
- t1 = _mm_load_ps(r1);
- t2 = _mm_load_ps(r2);
+ //unaligned load, vectors are not aligned
+ t1 = _mm_loadu_ps(r1);
+ t2 = _mm_loadu_ps(r2);
a = _mm_shuffle_ps(t1, t1, 0xc9);
b = _mm_shuffle_ps(t2, t2, 0xd2);
@@ -337,7 +339,7 @@
a = _mm_mul_ps( c, d );
r = _mm_sub_ps(r,a);
- _mm_store_ps(result, r);
+ _mm_storeu_ps(result, r);
}
#endif
Modified: Mercury2/src/MercuryMatrix.cpp
===================================================================
--- Mercury2/src/MercuryMatrix.cpp 2010-05-16 15:28:56 UTC (rev 732)
+++ Mercury2/src/MercuryMatrix.cpp 2010-05-17 23:58:27 UTC (rev 733)
@@ -1,6 +1,11 @@
#include "MercuryMatrix.h"
#include <MercuryLog.h>
+MercuryMatrixMemory::MercuryMatrixMemory()
+{
+ m_data.Allocate(rows,16);
+}
+
MercuryMatrixMemory& MercuryMatrixMemory::GetInstance()
{
static MercuryMatrixMemory* mmm = NULL;
@@ -19,7 +24,7 @@
MSemaphoreLock lock(&m_lock);
for (unsigned int i = 0; i < rows;i++)
- m_free.push_back( m_data+i );
+ m_free.push_back( m_data.Buffer()+i );
}
FloatRow* MercuryMatrixMemory::GetNewMatrix()
Modified: Mercury2/src/MercuryMatrix.h
===================================================================
--- Mercury2/src/MercuryMatrix.h 2010-05-16 15:28:56 UTC (rev 732)
+++ Mercury2/src/MercuryMatrix.h 2010-05-17 23:58:27 UTC (rev 733)
@@ -10,6 +10,8 @@
#include <list>
#include <MSemaphore.h>
+#include <AlignedBuffer.h>
+
///Memory holder for matrices
class MercuryMatrixMemory
{
@@ -17,15 +19,16 @@
to try to take advantage of data prefetching. Some matrix data should get a
free ride into the CPU cache. */
public:
+ MercuryMatrixMemory();
void Init();
static MercuryMatrixMemory& GetInstance();
FloatRow* GetNewMatrix();
void FreeMatrix(FloatRow* m);
private:
+ static const unsigned int rows = 1024; //1024 matrices * 64bytes each = 64kb
typedef FloatRow MatrixArray[4]; //64kb
- static const unsigned int rows = 1024; //1024 matrices * 64bytes each = 64kb
+ AlignedBuffer<MatrixArray> m_data;
std::list< MatrixArray* > m_free;
- MatrixArray m_data[rows];
MSemaphore m_lock;
};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|