From: <axl...@us...> - 2009-10-11 03:33:13
|
Revision: 560 http://hgengine.svn.sourceforge.net/hgengine/?rev=560&view=rev Author: axlecrusher Date: 2009-10-11 03:33:05 +0000 (Sun, 11 Oct 2009) Log Message: ----------- add vector * matrix multiply Modified Paths: -------------- Mercury2/src/MercuryVertex.cpp Mercury2/src/MercuryVertex.h Modified: Mercury2/src/MercuryVertex.cpp =================================================================== --- Mercury2/src/MercuryVertex.cpp 2009-10-11 03:32:30 UTC (rev 559) +++ Mercury2/src/MercuryVertex.cpp 2009-10-11 03:33:05 UTC (rev 560) @@ -4,6 +4,8 @@ #include <MQuaternion.h> #include <MercuryLog.h> +#include <MercuryMatrix.h> + MercuryVertex::MercuryVertex() { (*this)[0] = (*this)[1] = (*this)[2] = (*this)[3] = 0; @@ -119,6 +121,27 @@ return dp; } +MercuryVertex MercuryVertex::operator*(const MercuryMatrix& m) const +{ + MercuryVertex r; + MercuryVertex v1(m[0][0], m[1][0], m[2][0], m[3][0]); + MercuryVertex v2(m[0][1], m[1][1], m[2][1], m[3][1]); + MercuryVertex v3(m[0][2], m[1][2], m[2][2], m[3][2]); + MercuryVertex v4(m[0][3], m[1][4], m[1][4], m[1][4]); + + r[0] = ((*this)*v1).AddComponents(); + r[1] = ((*this)*v2).AddComponents(); + r[2] = ((*this)*v3).AddComponents(); + r[3] = ((*this)*v4).AddComponents(); + + return r; +} + +float MercuryVertex::AddComponents() const +{ + return GetX() + GetY() + GetZ() + GetW(); +} + void MercuryVertex::Print(const MString& s) const { LOG.Write(ssprintf("%s: %f %f %f %f", s.c_str(), (*this)[0], (*this)[1], (*this)[2], (*this)[3])); Modified: Mercury2/src/MercuryVertex.h =================================================================== --- Mercury2/src/MercuryVertex.h 2009-10-11 03:32:30 UTC (rev 559) +++ Mercury2/src/MercuryVertex.h 2009-10-11 03:33:05 UTC (rev 560) @@ -11,6 +11,7 @@ #endif class MQuaternion; +class MercuryMatrix; class MercuryVertex { @@ -32,9 +33,11 @@ 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 void Zero() { (*this)[0] = 0; (*this)[1] = 0; (*this)[2] = 0; } @@ -59,6 +62,9 @@ inline MercuryVertex operator * (const MercuryVertex& p) const { MercuryVertex r(*this); r*=p; return r; } inline MercuryVertex operator / (const MercuryVertex& p) const { MercuryVertex r(*this); r/=p; return r; } + 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; } @@ -85,6 +91,8 @@ MercuryVertex Rotate(const MQuaternion& q) const; + float AddComponents() const; + static MercuryVertex CreateFromString(const MString& s); // float (*this)[3]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-10-12 23:55:09
|
Revision: 566 http://hgengine.svn.sourceforge.net/hgengine/?rev=566&view=rev Author: axlecrusher Date: 2009-10-12 23:54:57 +0000 (Mon, 12 Oct 2009) Log Message: ----------- updates to allow for walking on terrain Modified Paths: -------------- Mercury2/src/Camera.cpp Mercury2/src/Camera.h Mercury2/src/MercuryAsset.h Mercury2/src/MessageHandler.h Modified: Mercury2/src/Camera.cpp =================================================================== --- Mercury2/src/Camera.cpp 2009-10-12 23:47:55 UTC (rev 565) +++ Mercury2/src/Camera.cpp 2009-10-12 23:54:57 UTC (rev 566) @@ -12,6 +12,7 @@ { m_lookAt = MercuryVector(0,0,-1); REGISTER_FOR_MESSAGE( INPUTEVENT_MOUSE ); + REGISTER_FOR_MESSAGE( "SetCameraPosition" ); } void CameraNode::PreRender(const MercuryMatrix& matrix) @@ -99,12 +100,24 @@ SetRotation(qUpDown*qLeftRight); // GetRotation().Print(); +// POST_MESSAGE("QueryTerrainPoint", new MessageData(), 0); + } + else if (message == "SetCameraPosition") + { +// LOG.Write("SetCamPosition"); + VertexDataMessage* m = (VertexDataMessage*)data; + SetPosition(m->Vertex); +// Update(0); +// ComputeMatrix(); +// m->Vertex.Print(); + } } void CameraNode::Update(float dTime) { - MercuryVector p = GetPosition(); +// MercuryVector p = GetPosition(); + MercuryVector p = m_origionalPosition; float a = 0; float b = 0; @@ -120,9 +133,15 @@ p += m_lookAt * a; p += Xaxis * b; // p.SetY(0); //lock to ground - SetPosition( p ); +// SetPosition( p ); + m_origionalPosition = p; + TransformNode::Update( dTime ); + + if (a != 0 || b != 0) + { + POST_MESSAGE("QueryTerrainPoint", new VertexDataMessage(p), 0); + } - TransformNode::Update( dTime ); } /**************************************************************************** Modified: Mercury2/src/Camera.h =================================================================== --- Mercury2/src/Camera.h 2009-10-12 23:47:55 UTC (rev 565) +++ Mercury2/src/Camera.h 2009-10-12 23:54:57 UTC (rev 566) @@ -16,6 +16,7 @@ GENRTTI(CameraNode); private: + MercuryVertex m_origionalPosition; MercuryVector m_lookAt; float m_x, m_y; MercuryMatrix m_viewMatrix; Modified: Mercury2/src/MercuryAsset.h =================================================================== --- Mercury2/src/MercuryAsset.h 2009-10-12 23:47:55 UTC (rev 565) +++ Mercury2/src/MercuryAsset.h 2009-10-12 23:54:57 UTC (rev 566) @@ -99,8 +99,9 @@ inline void SetPasses( unsigned short p ) { m_iPasses = p; } protected: MercuryNode* m_parentNode; + MAutoPtr< MercuryAsset > m_asset; //actual asset storage + private: - MAutoPtr< MercuryAsset > m_asset; //actual asset storage OcclusionResult m_occlusionResult; bool m_isCulled; Modified: Mercury2/src/MessageHandler.h =================================================================== --- Mercury2/src/MessageHandler.h 2009-10-12 23:47:55 UTC (rev 565) +++ Mercury2/src/MessageHandler.h 2009-10-12 23:54:57 UTC (rev 566) @@ -4,12 +4,23 @@ #include <MercuryString.h> #include <global.h> +#include <MercuryVertex.h> + class MessageData { public: virtual ~MessageData() {}; }; +class VertexDataMessage : public MessageData +{ + public: + VertexDataMessage(const MercuryVertex& v) + :Vertex(v) + {} + MercuryVertex Vertex; +}; + class MessageHandler { public: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-10-17 02:53:55
|
Revision: 574 http://hgengine.svn.sourceforge.net/hgengine/?rev=574&view=rev Author: axlecrusher Date: 2009-10-17 02:53:41 +0000 (Sat, 17 Oct 2009) Log Message: ----------- Make message manager thread safe. Used semaphores to avoid OS scheduling. Modified Paths: -------------- Mercury2/src/MercuryMessageManager.cpp Mercury2/src/MercuryMessageManager.h Modified: Mercury2/src/MercuryMessageManager.cpp =================================================================== --- Mercury2/src/MercuryMessageManager.cpp 2009-10-17 01:34:21 UTC (rev 573) +++ Mercury2/src/MercuryMessageManager.cpp 2009-10-17 02:53:41 UTC (rev 574) @@ -3,6 +3,9 @@ MercuryCTA HolderAllocator( sizeof(MessageHolder), 8 ); +/* MessageManager needs to be thread safe. Semaphores are used as locks (spin locks) to avoid OS rescheduling. +Locks need to be held for as little time as possible. Scoping is used to put locking classes on the stack +so that are ALWAYS released when out of scope.*/ MessageHolder::MessageHolder() :data(NULL),when(0) @@ -19,31 +22,40 @@ MessageHolder * m = new(HolderAllocator.Malloc()) MessageHolder(); m->message = message; m->data = data; - m->when = m_currTime + uint64_t(delay*1000000); - m_messageQueue.Push( m ); + + { + //scope the lock to a very small portion of code + MSemaphoreLock lock(&m_queueLock); + m->when = m_currTime + uint64_t(delay*1000000); + m_messageQueue.Push( m ); + } } void MercuryMessageManager::PumpMessages(const uint64_t& currTime) { - m_currTime = currTime; - while ( !m_messageQueue.Empty() ) { - if ( ((MessageHolder *)m_messageQueue.Peek())->when > m_currTime ) return; - - MessageHolder * message = (MessageHolder *)m_messageQueue.Pop(); - FireOffMessage( *message ); - SAFE_DELETE( message->data ); - HolderAllocator.Free(message); + MSemaphoreLock lock(&m_queueLock); + m_currTime = currTime; } + + for (MessageHolder* mh = GetNextMessageFromQueue(); mh; mh = GetNextMessageFromQueue()) + { + FireOffMessage( *mh ); + SAFE_DELETE( mh->data ); + HolderAllocator.Free(mh); + } } void MercuryMessageManager::RegisterForMessage(const MString& message, MessageHandler* ptr) { + MSemaphoreLock lock(&m_recipientLock); m_messageRecipients[message].push_back(ptr); } void MercuryMessageManager::UnRegisterForMessage(const MString& message, MessageHandler* ptr) { + MSemaphoreLock lock(&m_recipientLock); + std::list< MessageHandler* >& subscriptions = m_messageRecipients[message]; std::list< MessageHandler* >::iterator i = subscriptions.begin(); @@ -61,15 +73,38 @@ void MercuryMessageManager::FireOffMessage( const MessageHolder & message ) { -// std::map< MString, std::list< MessageHandler* > >::iterator i = m_messageRecipients.find(message.message); - std::list< MessageHandler* > * ref = m_messageRecipients.get( message.message ); - if ( ref ) + std::list< MessageHandler* > recipients; { - std::list< MessageHandler* >::iterator recipients = ref->begin(); + //copy list first (quick lock) + MSemaphoreLock lock(&m_recipientLock); + std::list< MessageHandler* > * r = m_messageRecipients.get( message.message ); + if ( r ) recipients = *r; + } + + if ( !recipients.empty() ) + { + std::list< MessageHandler* >::iterator recipient = recipients.begin(); + for (; recipient != recipients.end(); ++recipient) + { + (*recipient)->HandleMessage(message.message, *(message.data) ); + } + } +} + +MessageHolder* MercuryMessageManager::GetNextMessageFromQueue() +{ + /* We need to ensure that viewing the queue and retrieving the message + happens without the queue changing. */ + MSemaphoreLock lock(&m_queueLock); - for (; recipients != ref->end(); ++recipients) - (*recipients)->HandleMessage(message.message, *(message.data) ); + MessageHolder* mh = NULL; + if ( !m_messageQueue.Empty() ) + { + if ( ((MessageHolder *)m_messageQueue.Peek())->when > m_currTime ) return NULL; + mh = (MessageHolder *)m_messageQueue.Pop(); } + + return mh; } MercuryMessageManager& MercuryMessageManager::GetInstance() Modified: Mercury2/src/MercuryMessageManager.h =================================================================== --- Mercury2/src/MercuryMessageManager.h 2009-10-17 01:34:21 UTC (rev 573) +++ Mercury2/src/MercuryMessageManager.h 2009-10-17 02:53:41 UTC (rev 574) @@ -12,6 +12,8 @@ #include <Mint.h> #include <MAutoPtr.h> +#include <MSemaphore.h> + class MessageHolder : public RefBase { public: @@ -40,11 +42,16 @@ static MercuryMessageManager& GetInstance(); private: void FireOffMessage( const MessageHolder & message ); + MessageHolder* GetNextMessageFromQueue(); PriorityQueue m_messageQueue; uint64_t m_currTime; //microseconds MHash< std::list< MessageHandler* > > m_messageRecipients; + +// MercuryMutex m_lock; + MSemaphore m_queueLock; + MSemaphore m_recipientLock; }; static InstanceCounter<MercuryMessageManager> MMcounter("MessageManager"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-10-25 20:29:00
|
Revision: 580 http://hgengine.svn.sourceforge.net/hgengine/?rev=580&view=rev Author: cnlohr Date: 2009-10-25 20:28:46 +0000 (Sun, 25 Oct 2009) Log Message: ----------- remove wonky RTTI Type String, and make the Instace Watching feature handle it correct.y Modified Paths: -------------- Mercury2/src/MercuryNode.cpp Mercury2/src/MercuryNode.h Mercury2/src/ModuleManager.cpp Mercury2/src/ModuleManager.h Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-10-22 19:52:50 UTC (rev 579) +++ Mercury2/src/MercuryNode.cpp 2009-10-25 20:28:46 UTC (rev 580) @@ -16,7 +16,7 @@ REGISTER_NODE_TYPE(MercuryNode); MercuryNode::MercuryNode() - :Type( 0 ), m_parent(NULL), m_prevSibling(NULL), + :m_parent(NULL), m_prevSibling(NULL), m_nextSibling(NULL), m_hidden(false), m_useAlphaPath(false), m_culled(false), m_iPasses( DEFAULT_PASSES ), m_iForcePasses( 0 ) @@ -27,8 +27,7 @@ { #ifdef INSTANCE_WATCH - if( Type ) - DEL_INSTANCE(this, Type); + DEL_INSTANCE(this); #endif m_parent = NULL; Modified: Mercury2/src/MercuryNode.h =================================================================== --- Mercury2/src/MercuryNode.h 2009-10-22 19:52:50 UTC (rev 579) +++ Mercury2/src/MercuryNode.h 2009-10-25 20:28:46 UTC (rev 580) @@ -21,7 +21,7 @@ { if (n==NULL) return NULL; return dynamic_cast<const x*>(n); } \ static x* Cast(MercuryNode* n) \ { if (n==NULL) return NULL; return dynamic_cast<x*>(n); } \ -virtual const char * GetType() { if( !Type ) Type = #x; return #x; } +virtual const char * GetType() { return #x; } /* #define GENRTTI(x) static bool IsMyType(const MercuryNode* n) \ @@ -117,8 +117,6 @@ const MercuryMatrix & GetModelViewMatrix() const { return m_pModelViewMatrix[g_iViewportID]; } inline unsigned short GetPasses() const { return m_iPasses; } - - const char * Type; protected: std::list< MercuryNode* > m_children; //These nodes are unique, not instanced MercuryNode* m_parent; @@ -167,6 +165,8 @@ std::list< std::pair< MString, Callback0R<MercuryNode*> > > m_factoryCallbacks; }; +#define NODEFACTORY NodeFactory::GetInstance() + static InstanceCounter<NodeFactory> NFcounter("NodeFactory"); #define REGISTER_NODE_TYPE(class)\ Modified: Mercury2/src/ModuleManager.cpp =================================================================== --- Mercury2/src/ModuleManager.cpp 2009-10-22 19:52:50 UTC (rev 579) +++ Mercury2/src/ModuleManager.cpp 2009-10-25 20:28:46 UTC (rev 580) @@ -134,10 +134,12 @@ void ModuleManager::RegisterInstance( void * instance, const char * sClass ) { m_hAllInstances[sClass].insert( instance ); + m_pAllInstanceTypes[instance] = sClass; } -void ModuleManager::UnregisterInstance( void * instance, const char * sClass ) +void ModuleManager::UnregisterInstance( void * instance ) { + const char * sClass = m_pAllInstanceTypes[instance]; std::set< void * > & s = m_hAllInstances[sClass]; std::set< void * >::iterator i = s.find( instance ); Modified: Mercury2/src/ModuleManager.h =================================================================== --- Mercury2/src/ModuleManager.h 2009-10-22 19:52:50 UTC (rev 579) +++ Mercury2/src/ModuleManager.h 2009-10-25 20:28:46 UTC (rev 580) @@ -4,7 +4,11 @@ #include <MercuryUtil.h> #include <MercuryHash.h> #include <MercuryThreads.h> + +#ifdef INSTANCE_WATCH #include <set> +#include <map> +#endif /* This is the module loader mechanism. This allows for run-time loading of new modules. Eventually, it will allow for run-time re-loading of modules. @@ -24,7 +28,7 @@ void ReloadModule( const MString & sClass ); void RegisterInstance( void * instance, const char * sClass ); - void UnregisterInstance( void * instance, const char * sClass ); + void UnregisterInstance( void * instance ); #endif private: @@ -33,6 +37,7 @@ #ifdef INSTANCE_WATCH MHash< std::set< void * > > m_hAllInstances; + std::map< void *, const char * > m_pAllInstanceTypes; #endif MHash< void * > m_hAllHandles; @@ -46,7 +51,7 @@ #ifdef INSTANCE_WATCH #define NEW_INSTANCE( node, t ) ModuleManager::GetInstance().RegisterInstance( node, t ); -#define DEL_INSTANCE( node, t ) ModuleManager::GetInstance().UnregisterInstance( node, t ); +#define DEL_INSTANCE( node ) ModuleManager::GetInstance().UnregisterInstance( node ); #else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-10-26 22:17:05
|
Revision: 585 http://hgengine.svn.sourceforge.net/hgengine/?rev=585&view=rev Author: cnlohr Date: 2009-10-26 22:16:58 +0000 (Mon, 26 Oct 2009) Log Message: ----------- Add Delegates to the Mesage Manager. They help clean up the syntax for receiving messages, as it makes it possible for you to just call the function you want called based on message, so you don't have to have if clauses for messages. Modified Paths: -------------- Mercury2/src/Camera.cpp Mercury2/src/Camera.h Mercury2/src/MercuryMessageManager.cpp Mercury2/src/MercuryMessageManager.h Mercury2/src/ModuleManager.h Modified: Mercury2/src/Camera.cpp =================================================================== --- Mercury2/src/Camera.cpp 2009-10-26 02:00:33 UTC (rev 584) +++ Mercury2/src/Camera.cpp 2009-10-26 22:16:58 UTC (rev 585) @@ -11,8 +11,8 @@ :TransformNode(), m_x(0), m_y(0) { m_lookAt = MercuryVector(0,0,-1); - REGISTER_FOR_MESSAGE( INPUTEVENT_MOUSE ); - REGISTER_FOR_MESSAGE( "SetCameraPosition" ); + REGISTER_MESSAGE_WITH_DELEGATE( INPUTEVENT_MOUSE, &CameraNode::HandleMouseInput ); + REGISTER_MESSAGE_WITH_DELEGATE( "SetCameraPosition", &CameraNode::SetCameraPosition ); POST_MESSAGE("QueryTerrainPoint", new VertexDataMessage(m_origionalPosition), 0.00001); } @@ -80,39 +80,28 @@ // EYE.Print(); } -void CameraNode::HandleMessage(const MString& message, const MessageData& data) +void CameraNode::HandleMouseInput(const MessageData& data) { - if (message == INPUTEVENT_MOUSE) - { - const MouseInput& m( dynamic_cast<const MouseInput&>( data ) ); - - m_y += m.dy/1200.0f; - m_x += m.dx/1200.0f; - - m_y = Clamp((-Q_PI/2.0f)+0.00001f, (Q_PI/2.0f)-0.00001f, m_y); + const MouseInput& m( dynamic_cast<const MouseInput&>( data ) ); + + m_y += m.dy/1200.0f; + m_x += m.dx/1200.0f; + + m_y = Clamp((-Q_PI/2.0f)+0.00001f, (Q_PI/2.0f)-0.00001f, m_y); - MQuaternion qLeftRight = MQuaternion::CreateFromAxisAngle(MercuryVector(0,1,0), m_x); - MercuryVector LocalX = MercuryVector( 1, 0, 0 ); - LocalX = LocalX.Rotate( qLeftRight ); - - MQuaternion qUpDown = MQuaternion::CreateFromAxisAngle(LocalX, m_y); - -// qLeftRight.Print(); - - SetRotation(qUpDown*qLeftRight); -// GetRotation().Print(); -// POST_MESSAGE("QueryTerrainPoint", new MessageData(), 0); + MQuaternion qLeftRight = MQuaternion::CreateFromAxisAngle(MercuryVector(0,1,0), m_x); + MercuryVector LocalX = MercuryVector( 1, 0, 0 ); + LocalX = LocalX.Rotate( qLeftRight ); + + MQuaternion qUpDown = MQuaternion::CreateFromAxisAngle(LocalX, m_y); + + SetRotation(qUpDown*qLeftRight); +} - } - else if (message == "SetCameraPosition") - { -// LOG.Write("SetCamPosition"); - const VertexDataMessage& m( dynamic_cast<const VertexDataMessage&>( data ) ); - SetPosition(m.Vertex); -// Update(0); -// ComputeMatrix(); -// m->Vertex.Print(); - } +void CameraNode::SetCameraPosition(const MessageData& data) +{ + const VertexDataMessage& m( dynamic_cast<const VertexDataMessage&>( data ) ); + SetPosition(m.Vertex); } void CameraNode::Update(float dTime) Modified: Mercury2/src/Camera.h =================================================================== --- Mercury2/src/Camera.h 2009-10-26 02:00:33 UTC (rev 584) +++ Mercury2/src/Camera.h 2009-10-26 22:16:58 UTC (rev 585) @@ -9,10 +9,11 @@ public: CameraNode(); virtual void ComputeMatrix(); - virtual void HandleMessage(const MString& message, const MessageData& data); + virtual void HandleMouseInput(const MessageData& data); virtual void Update(float dTime); virtual void PreRender(const MercuryMatrix& matrix); virtual void Render(const MercuryMatrix& matrix); + virtual void SetCameraPosition(const MessageData& data); GENRTTI(CameraNode); private: Modified: Mercury2/src/MercuryMessageManager.cpp =================================================================== --- Mercury2/src/MercuryMessageManager.cpp 2009-10-26 02:00:33 UTC (rev 584) +++ Mercury2/src/MercuryMessageManager.cpp 2009-10-26 22:16:58 UTC (rev 585) @@ -46,24 +46,17 @@ } } -void MercuryMessageManager::RegisterForMessage(const MString& message, MessageHandler* ptr) -{ - MSemaphoreLock lock(&m_recipientLock); - m_messageRecipients[message].push_back(ptr); -} - void MercuryMessageManager::UnRegisterForMessage(const MString& message, MessageHandler* ptr) { MSemaphoreLock lock(&m_recipientLock); - std::list< MessageHandler* >& subscriptions = m_messageRecipients[message]; - std::list< MessageHandler* >::iterator i = subscriptions.begin(); + std::list< MessagePair >& subscriptions = m_messageRecipients[message]; + std::list< MessagePair >::iterator i = subscriptions.begin(); for (;i != subscriptions.end(); ++i) { - if (*i == ptr) + if ((*i).h == ptr) { - printf("Deleted subscription\n"); subscriptions.erase( i ); return; } @@ -71,22 +64,39 @@ } +void MercuryMessageManager::RegisterForMessage(const MString& message, MessageHandler* ptr, Delegate d ) +{ + MSemaphoreLock lock(&m_recipientLock); + m_messageRecipients[message].push_back(MessagePair(ptr, d)); + +} + + void MercuryMessageManager::FireOffMessage( const MessageHolder & message ) { - std::list< MessageHandler* > recipients; + std::list< MessagePair > recipients; { //copy list first (quick lock) MSemaphoreLock lock(&m_recipientLock); - std::list< MessageHandler* > * r = m_messageRecipients.get( message.message ); + std::list< MessagePair > * r = m_messageRecipients.get( message.message ); if ( r ) recipients = *r; } if ( !recipients.empty() ) { - std::list< MessageHandler* >::iterator recipient = recipients.begin(); + std::list< MessagePair >::iterator recipient = recipients.begin(); for (; recipient != recipients.end(); ++recipient) { - (*recipient)->HandleMessage(message.message, *(message.data) ); + MessagePair & mp = *recipient; + //Okay, the following lines look horrible. Reason is we're using + //a horrible horrible c++ construct from the anals of pointerdom. + //The idea is we're using a delegate. If we have a delegate, use it. + //If you are receiving a delegate, you do not need the message name. + //Otherwise, send a standard message through the old interface. + if( mp.d ) + (mp.h->*(mp.d))( *(message.data) ); + else + mp.h->HandleMessage(message.message, *(message.data) ); } } } Modified: Mercury2/src/MercuryMessageManager.h =================================================================== --- Mercury2/src/MercuryMessageManager.h 2009-10-26 02:00:33 UTC (rev 584) +++ Mercury2/src/MercuryMessageManager.h 2009-10-26 22:16:58 UTC (rev 585) @@ -24,6 +24,8 @@ static bool Compare( void * left, void * right ); }; +typedef void (MessageHandler::*Delegate)(const MessageData&); + /* This message system uses absolute integer time values to fire off events. This ensures accuarate firing times while eliminating floating point error. Because we use absolute times in the queue we do not need to "count down" the @@ -36,7 +38,7 @@ void PostMessage(const MString& message, MessageData* data, float delay); void PumpMessages(const uint64_t& currTime); - void RegisterForMessage(const MString& message, MessageHandler* ptr); + void RegisterForMessage(const MString& message, MessageHandler* ptr, Delegate d = 0 ); void UnRegisterForMessage(const MString& message, MessageHandler* ptr); static MercuryMessageManager& GetInstance(); @@ -46,9 +48,16 @@ PriorityQueue m_messageQueue; uint64_t m_currTime; //microseconds + + struct MessagePair + { + MessagePair( MessageHandler * th, Delegate td ) : h(th), d(td) { } + MessageHandler * h; + Delegate d; + }; + + MHash< std::list< MessagePair > > m_messageRecipients; - MHash< std::list< MessageHandler* > > m_messageRecipients; - // MercuryMutex m_lock; MSemaphore m_queueLock; MSemaphore m_recipientLock; @@ -57,6 +66,7 @@ static InstanceCounter<MercuryMessageManager> MMcounter("MessageManager"); #define MESSAGEMAN MercuryMessageManager +#define REGISTER_MESSAGE_WITH_DELEGATE(x, d) MESSAGEMAN::GetInstance().RegisterForMessage(x, this, (Delegate)d) #define REGISTER_FOR_MESSAGE(x) MESSAGEMAN::GetInstance().RegisterForMessage(x, this) #define UNREGISTER_FOR_MESSAGE(x) MESSAGEMAN::GetInstance().UnRegisterForMessage(x, this) #define POST_MESSAGE(x,data,delay) MESSAGEMAN::GetInstance().PostMessage(x, data, delay) Modified: Mercury2/src/ModuleManager.h =================================================================== --- Mercury2/src/ModuleManager.h 2009-10-26 02:00:33 UTC (rev 584) +++ Mercury2/src/ModuleManager.h 2009-10-26 22:16:58 UTC (rev 585) @@ -29,6 +29,7 @@ void RegisterInstance( void * instance, const char * sClass ); void UnregisterInstance( void * instance ); + const char * GetInstanceType( void * inst ) { return m_pAllInstanceTypes[inst]; } #endif private: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-10-27 03:09:40
|
Revision: 586 http://hgengine.svn.sourceforge.net/hgengine/?rev=586&view=rev Author: cnlohr Date: 2009-10-27 03:09:34 +0000 (Tue, 27 Oct 2009) Log Message: ----------- Write should not be changing the contents of what you are writing. Modified Paths: -------------- Mercury2/src/MercuryFile.h Mercury2/src/MercuryFileDriverDirect.cpp Mercury2/src/MercuryFileDriverDirect.h Mercury2/src/MercuryFileDriverPacked.cpp Mercury2/src/MercuryFileDriverPacked.h Mercury2/src/MercuryFileDriverZipped.cpp Mercury2/src/MercuryFileDriverZipped.h Modified: Mercury2/src/MercuryFile.h =================================================================== --- Mercury2/src/MercuryFile.h 2009-10-26 22:16:58 UTC (rev 585) +++ Mercury2/src/MercuryFile.h 2009-10-27 03:09:34 UTC (rev 586) @@ -34,7 +34,7 @@ ///Return the length of the file (in bytes) virtual unsigned long Length() = 0; ///Writes length bytes, returns true if it wrote successfully - virtual bool Write( void * data, unsigned long length ) = 0; + virtual bool Write( const void * data, unsigned long length ) = 0; ///Returns the number of bytes read virtual unsigned long Read( void * data, unsigned long length ) = 0; ///Reads one line from the file. Modified: Mercury2/src/MercuryFileDriverDirect.cpp =================================================================== --- Mercury2/src/MercuryFileDriverDirect.cpp 2009-10-26 22:16:58 UTC (rev 585) +++ Mercury2/src/MercuryFileDriverDirect.cpp 2009-10-27 03:09:34 UTC (rev 586) @@ -139,7 +139,7 @@ return ret; } -bool MercuryFileObjectDirect::Write( void * data, unsigned long length ) +bool MercuryFileObjectDirect::Write( const void * data, unsigned long length ) { if ( m_fF == NULL ) return false; Modified: Mercury2/src/MercuryFileDriverDirect.h =================================================================== --- Mercury2/src/MercuryFileDriverDirect.h 2009-10-26 22:16:58 UTC (rev 585) +++ Mercury2/src/MercuryFileDriverDirect.h 2009-10-27 03:09:34 UTC (rev 586) @@ -15,7 +15,7 @@ virtual void Close(); virtual unsigned long Tell(); virtual unsigned long Length(); - virtual bool Write( void * data, unsigned long length ); + virtual bool Write( const void * data, unsigned long length ); virtual unsigned long Read( void * data, unsigned long length ); virtual bool Check(); virtual bool Eof(); Modified: Mercury2/src/MercuryFileDriverPacked.cpp =================================================================== --- Mercury2/src/MercuryFileDriverPacked.cpp 2009-10-26 22:16:58 UTC (rev 585) +++ Mercury2/src/MercuryFileDriverPacked.cpp 2009-10-27 03:09:34 UTC (rev 586) @@ -48,7 +48,7 @@ return m_size; } -bool MercuryFileObjectPacked::Write( void * data, unsigned long length ) +bool MercuryFileObjectPacked::Write( const void * data, unsigned long length ) { //First make sure we won't over-write good data. if ( length >= ( m_size - m_location ) ) Modified: Mercury2/src/MercuryFileDriverPacked.h =================================================================== --- Mercury2/src/MercuryFileDriverPacked.h 2009-10-26 22:16:58 UTC (rev 585) +++ Mercury2/src/MercuryFileDriverPacked.h 2009-10-27 03:09:34 UTC (rev 586) @@ -14,7 +14,7 @@ virtual void Close(); virtual unsigned long Tell(); virtual unsigned long Length(); - virtual bool Write( void * data, unsigned long length ); + virtual bool Write( const void * data, unsigned long length ); virtual unsigned long Read( void * data, unsigned long length ); virtual bool Check(); virtual bool Eof(); Modified: Mercury2/src/MercuryFileDriverZipped.cpp =================================================================== --- Mercury2/src/MercuryFileDriverZipped.cpp 2009-10-26 22:16:58 UTC (rev 585) +++ Mercury2/src/MercuryFileDriverZipped.cpp 2009-10-27 03:09:34 UTC (rev 586) @@ -121,7 +121,7 @@ return m_size; } -bool MercuryFileObjectZipped::Write( void * data, unsigned long length ) +bool MercuryFileObjectZipped::Write( const void * data, unsigned long length ) { //You cannot write to a zipped file in the store form. return false; Modified: Mercury2/src/MercuryFileDriverZipped.h =================================================================== --- Mercury2/src/MercuryFileDriverZipped.h 2009-10-26 22:16:58 UTC (rev 585) +++ Mercury2/src/MercuryFileDriverZipped.h 2009-10-27 03:09:34 UTC (rev 586) @@ -15,7 +15,7 @@ virtual void Close(); virtual unsigned long Tell(); virtual unsigned long Length(); - virtual bool Write( void * data, unsigned long length ); + virtual bool Write( const void * data, unsigned long length ); virtual unsigned long Read( void * data, unsigned long length ); virtual bool Check(); virtual bool Eof(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-10-27 03:10:06
|
Revision: 587 http://hgengine.svn.sourceforge.net/hgengine/?rev=587&view=rev Author: cnlohr Date: 2009-10-27 03:09:56 +0000 (Tue, 27 Oct 2009) Log Message: ----------- add utility function for file writing Modified Paths: -------------- Mercury2/src/MercuryUtil.cpp Mercury2/src/MercuryUtil.h Modified: Mercury2/src/MercuryUtil.cpp =================================================================== --- Mercury2/src/MercuryUtil.cpp 2009-10-27 03:09:34 UTC (rev 586) +++ Mercury2/src/MercuryUtil.cpp 2009-10-27 03:09:56 UTC (rev 587) @@ -228,6 +228,15 @@ return length; } +bool StringToFile( const MString & sFileName, const MString & data ) +{ + MercuryFile * f = FILEMAN.Open( sFileName, MFP_WRITE_ONLY ); + if( !f ) return false; + f->Write( data.c_str(), data.length() ); + delete f; +} + + int GeneralUsePrimes[] = { 3, 13, 37, 73, 131, 229, 337, 821, 2477, 4594, 8941, 14797, 24953, 39041, 60811, 104729 }; int GetAPrime( int ith ) Modified: Mercury2/src/MercuryUtil.h =================================================================== --- Mercury2/src/MercuryUtil.h 2009-10-27 03:09:34 UTC (rev 586) +++ Mercury2/src/MercuryUtil.h 2009-10-27 03:09:56 UTC (rev 587) @@ -96,6 +96,9 @@ ///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 ); /* These two functions are very different */ /// nextPow2 will go to the NEXT power of 2 even if x is already a power of 2. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-10-27 03:18:34
|
Revision: 589 http://hgengine.svn.sourceforge.net/hgengine/?rev=589&view=rev Author: cnlohr Date: 2009-10-27 03:18:28 +0000 (Tue, 27 Oct 2009) Log Message: ----------- first incarnation of XML Saving Modified Paths: -------------- Mercury2/src/Mercury2.cpp Mercury2/src/MercuryAsset.cpp Mercury2/src/MercuryAsset.h Mercury2/src/MercuryNode.cpp Mercury2/src/MercuryNode.h Mercury2/src/MessageHandler.h Modified: Mercury2/src/Mercury2.cpp =================================================================== --- Mercury2/src/Mercury2.cpp 2009-10-27 03:18:01 UTC (rev 588) +++ Mercury2/src/Mercury2.cpp 2009-10-27 03:18:28 UTC (rev 589) @@ -42,7 +42,9 @@ { char buffer[2048]; LOG.Write(ssprintf( "Fatal error encountered in Mercury 2: %s", cn_get_crash_description( signal ) )); - cnget_backtrace( 1, buffer, 2047 ); + cnget_backtrace( 1, buffer, 2047 ); + + //XXX: Sometimes we produce a crash, we get the crash report, and the next line doesn't work... This should be examined. LOG.Write( buffer ); return 0; //Continue regular crash. @@ -173,7 +175,11 @@ #endif m_count = 0; fpsTimer = timer; - } + } + + MString st; + root->SaveToXML( st ); + StringToFile( "test.xml", st ); } while ( w->PumpMessages() ); Modified: Mercury2/src/MercuryAsset.cpp =================================================================== --- Mercury2/src/MercuryAsset.cpp 2009-10-27 03:18:01 UTC (rev 588) +++ Mercury2/src/MercuryAsset.cpp 2009-10-27 03:18:28 UTC (rev 589) @@ -77,6 +77,22 @@ } } +void MercuryAsset::SaveToXML( MString & sXMLStream, int depth ) +{ + sXMLStream += ssprintf( "%*c<node type=\"%s\" ", depth*3, 32, GetType() ); + if( m_path.length() ) + sXMLStream += ssprintf( "file=\"%s\" ", m_path.c_str() ); + + SaveToXMLTag( sXMLStream ); + sXMLStream += "/>\n"; +} + +void MercuryAsset::SaveToXMLTag( MString & sXMLStream ) +{ + //Assets, generally do not actually have anything else to save... +} + + void MercuryAsset::DrawAxes() { GLCALL( glBegin(GL_LINES) ); Modified: Mercury2/src/MercuryAsset.h =================================================================== --- Mercury2/src/MercuryAsset.h 2009-10-27 03:18:01 UTC (rev 588) +++ Mercury2/src/MercuryAsset.h 2009-10-27 03:18:28 UTC (rev 589) @@ -45,7 +45,15 @@ ///Loads an asset from an XMLAsset representing itself virtual void LoadFromXML(const XMLNode& node); - + + ///Saves the main body of an XML node. + /** This behaves very similarly to MercuryNode::SaveToXML + The most notable difference is it doesn't handle children.*/ + virtual void SaveToXML( MString & sXMLStream, int depth = 0 ); + + ///Saves individual portions into the tag. + virtual void SaveToXMLTag( MString & sXMLStream ); + virtual void LoadedCallback(); //thread safe inline void IsInstanced(bool b) { m_isInstanced = b; } @@ -66,6 +74,8 @@ virtual MercuryAssetInstance* GenerateInstanceData(MercuryNode* parentNode); LoadState GetLoadState(); //thread safe + + GENRTTI( MercuryAsset ); protected: void SetLoadState(LoadState ls); //thread safe Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-10-27 03:18:01 UTC (rev 588) +++ Mercury2/src/MercuryNode.cpp 2009-10-27 03:18:28 UTC (rev 589) @@ -306,9 +306,48 @@ for( unsigned i = 0; i < out.size(); i++ ) m_iForcePasses = m_iForcePasses | (1<<StrToInt( out[i] ) ); } +} +void MercuryNode::SaveToXML( MString & sXMLStream, int depth ) +{ + sXMLStream += ssprintf( "%*c<node type=\"%s\" ", depth*3, 32, GetType() ); + if( GetName().length() ) + sXMLStream += ssprintf( "name=\"%s\" ", GetName().c_str() ); + + SaveToXMLTag( sXMLStream ); + + bool bNoChildren = true; + if( !m_assets.empty() ) + { + //No children yet (but we have them, so terminate (>) ) + if( bNoChildren ) + sXMLStream += ">\n"; + bNoChildren = false; + + for( std::list< MercuryAssetInstance * >::iterator i = m_assets.begin(); i != m_assets.end(); i++ ) + (*i)->Asset().SaveToXML( sXMLStream, depth + 1 ); + } + + if( ! m_children.empty() ) + { + //No children yet (but we have them, so terminate (>) ) + if( bNoChildren ) + sXMLStream += ">\n"; + bNoChildren = false; + for( std::list< MercuryNode * >::iterator i = m_children.begin(); i != m_children.end(); i++ ) + (*i)->SaveToXML( sXMLStream, depth + 1 ); + } + + if( bNoChildren ) + sXMLStream += "/>\n"; + else + sXMLStream += ssprintf( "%*c</node>\n", depth * 3, 32 ); } +void MercuryNode::SaveToXMLTag( MString & sXMLStream ) +{ + //MercuryNodes do not have anything else to save. +} void MercuryNode::PreRender(const MercuryMatrix& matrix) { Modified: Mercury2/src/MercuryNode.h =================================================================== --- Mercury2/src/MercuryNode.h 2009-10-27 03:18:01 UTC (rev 588) +++ Mercury2/src/MercuryNode.h 2009-10-27 03:18:28 UTC (rev 589) @@ -17,12 +17,6 @@ Each node exists as a single entity in the scene graph. **/ -#define GENRTTI(x) static const x* Cast(const MercuryNode* n) \ -{ if (n==NULL) return NULL; return dynamic_cast<const x*>(n); } \ -static x* Cast(MercuryNode* n) \ -{ if (n==NULL) return NULL; return dynamic_cast<x*>(n); } \ -virtual const char * GetType() { return #x; } - /* #define GENRTTI(x) static bool IsMyType(const MercuryNode* n) \ { const MercuryNode* tn = n; \ @@ -87,7 +81,22 @@ ///Loads a node from an XMLNode representing itself virtual void LoadFromXML(const XMLNode& node); - + + ///Saves the main body of an XML node. + /** This, in the base class sets up the stream (i.e. <node and invokes the + SaveToXML tag then outputs the termination (i.e. /> or > ) it then outputs + all of the various Assets and Nodes that are attached as children. It handles + closing the argument as well. Unless you intend to modify the behavior, do not + override this. In addition, it is generally best to completely re-write it if + you intend to modify the behavior. */ + virtual void SaveToXML( MString & sXMLStream, int depth = 0 ); + + ///Saves just the tag portion of an XML node. + /** The update process here is tricky. This is invoked by the base + MercuryNode class. It does not handle setting it up, i.e. type=... name=... + The various abstracted classes must append on arguments they require. */ + virtual void SaveToXMLTag( MString & sXMLStream ); + ///Run on a child when added to a parent virtual void OnAdded() {}; Modified: Mercury2/src/MessageHandler.h =================================================================== --- Mercury2/src/MessageHandler.h 2009-10-27 03:18:01 UTC (rev 588) +++ Mercury2/src/MessageHandler.h 2009-10-27 03:18:28 UTC (rev 589) @@ -3,9 +3,14 @@ #include <MercuryString.h> #include <global.h> - #include <MercuryVertex.h> +#define GENRTTI(x) static const x* Cast(const MessageHandler* n) \ +{ if (!n) return 0; return dynamic_cast<const x*>(n); } \ +static x* Cast(MessageHandler* n) \ +{ if (!n) return 0; return dynamic_cast<x*>(n); } \ +virtual const char * GetType() { return #x; } + class MessageData { public: @@ -23,9 +28,10 @@ class MessageHandler { - public: - virtual ~MessageHandler() {}; - virtual void HandleMessage(const MString& message, const MessageData& data) {}; +public: + virtual ~MessageHandler() {}; + virtual void HandleMessage(const MString& message, const MessageData& data) {}; + GENRTTI( MessageHandler ); }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-10-27 04:49:07
|
Revision: 590 http://hgengine.svn.sourceforge.net/hgengine/?rev=590&view=rev Author: cnlohr Date: 2009-10-27 04:48:57 +0000 (Tue, 27 Oct 2009) Log Message: ----------- add to euler (useful for saving) it hasn't actually been tested yet... Modified Paths: -------------- Mercury2/src/MQuaternion.cpp Mercury2/src/MQuaternion.h Modified: Mercury2/src/MQuaternion.cpp =================================================================== --- Mercury2/src/MQuaternion.cpp 2009-10-27 03:18:28 UTC (rev 589) +++ Mercury2/src/MQuaternion.cpp 2009-10-27 04:48:57 UTC (rev 590) @@ -52,6 +52,14 @@ *this = this->normalize(); } +void MQuaternion::ToEuler(MercuryVertex&angles) const +{ + //According to http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles (Oct 26, 2009) + angles[0] = atan2( 2 * (m_wxyz[0]*m_wxyz[1] + m_wxyz[2]*m_wxyz[3]), 1 - 2 * (m_wxyz[1]*m_wxyz[1] + m_wxyz[2]*m_wxyz[2] ) ); + angles[1] = asin( 2 * (m_wxyz[0] *m_wxyz[2] - m_wxyz[3]*m_wxyz[1] ) ); + angles[2] = atan2( 2 * (m_wxyz[0]*m_wxyz[3] + m_wxyz[1]*m_wxyz[2]), 1 - 2 * (m_wxyz[2]*m_wxyz[2] + m_wxyz[3]*m_wxyz[3] ) ); +} + MQuaternion MQuaternion::CreateFromAxisAngle(const MercuryVertex& p, const float radians) { MQuaternion q; Modified: Mercury2/src/MQuaternion.h =================================================================== --- Mercury2/src/MQuaternion.h 2009-10-27 03:18:28 UTC (rev 589) +++ Mercury2/src/MQuaternion.h 2009-10-27 04:48:57 UTC (rev 590) @@ -23,6 +23,9 @@ static MQuaternion CreateFromAxisAngle(const MercuryVertex& p, const float radians); void FromAxisAngle(const MercuryVertex& p, const float radians); void ToAxisAngle(float& angle, float& x, float& y, float& z) const; + + //Convert the quaternion back into euler angles (mathematically doesn't always work) + void ToEuler(MercuryVertex&angles) const; ///Access a component of the quaternion with the [] operator inline float & operator[] ( const WXYZ i ) { return m_wxyz[i]; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-11-03 08:20:53
|
Revision: 594 http://hgengine.svn.sourceforge.net/hgengine/?rev=594&view=rev Author: cnlohr Date: 2009-11-03 08:20:45 +0000 (Tue, 03 Nov 2009) Log Message: ----------- wooh state changers Added Paths: ----------- Mercury2/src/StateChanger.cpp Mercury2/src/StateChanger.h Added: Mercury2/src/StateChanger.cpp =================================================================== --- Mercury2/src/StateChanger.cpp (rev 0) +++ Mercury2/src/StateChanger.cpp 2009-11-03 08:20:45 UTC (rev 594) @@ -0,0 +1,220 @@ +#include <StateChanger.h> +#include <MercuryNode.h> +#include <GLHeaders.h> + +using namespace std; + +//////////////////////////////////////STATE CHANGERS////////////////////////////////////////// + +///State changer for color changing. +class ColorChange : public StateChange +{ +public: + ColorChange( const MVector< MString > & sParameters ) : StateChange( sParameters ) + { + if( sParameters.size() < 3 ) + { + LOG.Write( ssprintf( "Error: ColorChange state has invalid number of parameters(%d).", sParameters.size() ) ); + return; + } + + r = StrToFloat( sParameters[0] ); + g = StrToFloat( sParameters[1] ); + b = StrToFloat( sParameters[2] ); + + if( sParameters.size() > 3 ) + a = StrToFloat( sParameters[3] ); + else + a = 1.; + } + + void Stringify( MString & sOut ) + { + sOut = ssprintf( "%f,%f,%f,%f", r,g,b,a ); + } + + void Activate() + { + glColor4f( r,g,b,a ); + } + + STATECHANGE_RTTI( ColorChange ); + float r,g,b,a; +}; + +REGISTER_STATECHANGE( ColorChange ); + + +//////////////////////////////////////STATE CHANGE CHUNK////////////////////////////////////// +StateChangeRegister * StateChangeRegister::m_Instance; + +StateChangeRegister & StateChangeRegister::Instance() +{ + if( !m_Instance ) + m_Instance = new StateChangeRegister(); + return *m_Instance; +} + +int StateChangeRegister::RegisterGenerator( const MString & name, StateChange*(*gn)( const MVector< MString > &sParameters ) ) +{ + m_Generators[name] = gn; + m_hStateIDs[name] = m_iStateCount++; + return m_iStateCount-1; +} + +MAutoPtr< StateChange > StateChangeRegister::Create( const MString & name, const MVector< MString > & sParameters ) +{ + StateChange*(**tgn)( const MVector< MString > &sParameters ); + if( !( tgn = m_Generators.get( name ) ) ) + return 0; + + return (**tgn)(sParameters ); +} + +int StateChangeRegister::GetStateID( const MString & spar ) +{ + int * r = m_hStateIDs.get( spar ); + if( r ) + return *r; + else + return 0; +} + + +//////////////////////////////////////STATE CHANGER ASSET///////////////////////////////////// + +REGISTER_ASSET_TYPE(StateChanger); + +StateChanger::StateChanger() + :MercuryAsset() +{ + //Make sure our state stack is correctly sized + if( m_StateSet.size() < (unsigned)StateChangeRegister::Instance().GetStateCount() ) + m_StateSet.resize( StateChangeRegister::Instance().GetStateCount() ); +} + +StateChanger::~StateChanger() +{ + REMOVE_ASSET_INSTANCE(TEXTURE, m_path); +} + +void StateChanger::Render(const MercuryNode* node) +{ + for( unsigned i = 0; i < m_vStates.size(); i++ ) + { + MAutoPtr< StateChange > & k = m_vStates[i]; + k->Activate(); + 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]; + + unsigned ilpos = l.size() - 1; + + if( ilpos <= 0 ) + continue; + + l.resize( ilpos-- ); + + if( ilpos >= 0 ) + l[ilpos]->Activate(); + } +} + +bool StateChanger::LoadFromString( const MString & sFile ) +{ + int f = sFile.find( ":", 0 ); + if( f <= 0 ) + { + LOG.Write( ssprintf( "Error loading new StateChanger node. File: \"%s\" improperly formatted, required \"[type]:[parameters]\".", sFile.c_str() ) ); + return false; + } + + MString sType = sFile.substr( 0, f ); + MString sParameters = sFile.substr( f+1 ); + MVector< MString > vsParameters; + + SplitStrings( sParameters, vsParameters, ",", " ", 1, 1 ); + + MAutoPtr< StateChange > s = StateChangeRegister::Instance().Create( sType, vsParameters ); + if( s.Ptr() ) + m_vStates.push_back( s ); + else + { + LOG.Write( ssprintf( "Error: Could not make new StateChanger from: \"%s\"", sFile.c_str() ) ); + return false; + } + + + return true; +} + +void StateChanger::LoadFromXML(const XMLNode& node) +{ + MercuryAsset::LoadFromXML(node); + if ( !node.Attribute("file").empty() ) + { + MString sFile = node.Attribute("file"); + LoadFromString( sFile ); + } +} + +void StateChanger::SaveToXMLTag( MString & sXMLStream ) +{ + if( m_vStates.size() ) + { + MString sStr; + m_vStates[0]->Stringify( sStr ); + sXMLStream += "file=\"" + sStr + "\" "; + } + + MercuryAsset::SaveToXMLTag( sXMLStream ); +} + +StateChanger* StateChanger::Generate() +{ + return new StateChanger(); +} + +MVector< MVector< MAutoPtr< StateChange > > > StateChanger::m_StateSet; + + +/**************************************************************************** + * Copyright (C) 2008 - 2009 by Joshua Allen * + * 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/StateChanger.h =================================================================== --- Mercury2/src/StateChanger.h (rev 0) +++ Mercury2/src/StateChanger.h 2009-11-03 08:20:45 UTC (rev 594) @@ -0,0 +1,107 @@ +#ifndef STATE_CHANGER_H +#define STATE_CHANGER_H + +#include <MercuryAsset.h> +#include <RawImageData.h> + + +#define STATECHANGE_RTTI(x) const char * GetType() { return #x; } + +class StateChange : public RefBase +{ +public: + StateChange( const MVector< MString > & sParameters ) { } + void Stringify( MString & sOut ) { } + + virtual void Activate() = 0; + + STATECHANGE_RTTI( StateChange ); + int sID; +}; + +#define REGISTER_STATECHANGE( x ) \ + extern int sID##x;\ + StateChange*CreateNew##x( const MVector< MString > & sParameters ) { x * ret = new x( sParameters ); ret->sID = sID##x; return ret; } \ + int sID##x = StateChangeRegister::Instance().RegisterGenerator( #x, CreateNew##x ); + +class StateChangeRegister +{ +public: + static StateChangeRegister & Instance(); + int RegisterGenerator( const MString & name, StateChange*(*gn)( const MVector< MString > &sParameters ) ); + MAutoPtr< StateChange > Create( const MString & name, const MVector< MString > & sParameters ); + + int GetStateID( const MString & spar ); + int GetStateCount() { return m_iStateCount; } +private: + MHash< StateChange*(*)(const MVector< MString > &sParameters) > m_Generators; + static StateChangeRegister * m_Instance; + MHash< int > m_hStateIDs; + int m_iStateCount; +}; + +///State Changer Node +/** + This node is for things like changing the color of everything, or turning on/off + blending modes, etc. in the overall system. + Note: While this node can handle multiple states at once - it is currently + only set up to be able to load one from the incoming XML. */ +class StateChanger : public MercuryAsset +{ +public: + StateChanger(); + virtual ~StateChanger(); + + virtual void Render(const MercuryNode* node); + virtual void PostRender(const MercuryNode* node); + + virtual void LoadFromXML(const XMLNode& node); + virtual void SaveToXMLTag( MString & sXMLStream ); + static StateChanger* Generate(); + + bool LoadFromString( const MString & sDescription ); + + GENRTTI( StateChanger ); +private: + + MVector< MAutoPtr< StateChange > > m_vStates; + + //Actually... It's faster if we use MercuryVectors here. + static MVector< MVector< MAutoPtr< StateChange > > > m_StateSet; +}; + +#endif + +/**************************************************************************** + * Copyright (C) 2008 - 2009 by Joshua Allen * + * 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: <cn...@us...> - 2009-11-07 08:37:24
|
Revision: 605 http://hgengine.svn.sourceforge.net/hgengine/?rev=605&view=rev Author: cnlohr Date: 2009-11-07 08:37:17 +0000 (Sat, 07 Nov 2009) Log Message: ----------- add extra utility to the screen to point stuff... Allow textures to be fed from code or to feed code... and add a new state changer (lighting disable/enabling) Modified Paths: -------------- Mercury2/src/GLHelpers.cpp Mercury2/src/GLHelpers.h Mercury2/src/StateChanger.cpp Mercury2/src/Texture.cpp Mercury2/src/Texture.h Modified: Mercury2/src/GLHelpers.cpp =================================================================== --- Mercury2/src/GLHelpers.cpp 2009-11-07 05:51:41 UTC (rev 604) +++ Mercury2/src/GLHelpers.cpp 2009-11-07 08:37:17 UTC (rev 605) @@ -57,7 +57,7 @@ return mm; } -MercuryVertex pointFromScreenLoc(int screen_x, int screen_y) +MercuryVertex pointFromScreenLoc(int screen_x, int screen_y, float fForceDepth) { GLfloat winX, winY, winZ; GLdouble mouseX = 0, mouseY = 0, mouseZ = 0; @@ -71,15 +71,26 @@ winX = (float)screen_x; winY = (float)viewport[3] - (float)screen_y; - GLCALL( glReadPixels( screen_x, (int)winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ ) ); gluUnProject( - winX, winY, winZ, + winX, winY, fForceDepth, modelview, projection, viewport, &mouseX, &mouseY, &mouseZ); return MercuryVertex( (float)mouseX, (float)mouseY, (float)mouseZ ); } +MercuryVertex pointFromScreenLoc(int screen_x, int screen_y ) +{ + GLint viewport[4]; + GLCALL( glGetIntegerv(GL_VIEWPORT, viewport) ); + + float winY = (float)viewport[3] - (float)screen_y; + + float winZ; + GLCALL( glReadPixels( screen_x, (int)winY, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &winZ ) ); + return pointFromScreenLoc( screen_x, screen_y, winZ ); +} + unsigned int ToGLColorType(ColorByteType cbt) { switch (cbt) Modified: Mercury2/src/GLHelpers.h =================================================================== --- Mercury2/src/GLHelpers.h 2009-11-07 05:51:41 UTC (rev 604) +++ Mercury2/src/GLHelpers.h 2009-11-07 08:37:17 UTC (rev 605) @@ -18,6 +18,7 @@ void glLoadMatrix(const MercuryMatrix& m); MercuryMatrix glGetMatrix(unsigned int m); MercuryVertex pointFromScreenLoc(int screen_x, int screen_y); +MercuryVertex pointFromScreenLoc(int screen_x, int screen_y, float fForceDepth); unsigned int ToGLColorType(ColorByteType cbt); #ifdef GL_PROFILE Modified: Mercury2/src/StateChanger.cpp =================================================================== --- Mercury2/src/StateChanger.cpp 2009-11-07 05:51:41 UTC (rev 604) +++ Mercury2/src/StateChanger.cpp 2009-11-07 08:37:17 UTC (rev 605) @@ -44,7 +44,41 @@ REGISTER_STATECHANGE( ColorChange ); +///State changer for enabling/disabling lighting +class LightingSwitch : public StateChange +{ +public: + LightingSwitch( const MVector< MString > & sParameters ) : StateChange( sParameters ) + { + if( sParameters.size() < 1 ) + { + LOG.Write( ssprintf( "Error: ColorChange state has invalid number of parameters(%d).", sParameters.size() ) ); + return; + } + bEnable = StrToBool( sParameters[0] ); + } + + void Stringify( MString & sOut ) + { + sOut = ssprintf( "%f", bEnable ); + } + + void Activate() + { + if( bEnable ) + glEnable( GL_LIGHTING ); + else + glDisable( GL_LIGHTING ); + } + + STATECHANGE_RTTI( LightingSwitch ); + bool bEnable; +}; + +REGISTER_STATECHANGE( LightingSwitch ); + + //////////////////////////////////////STATE CHANGE CHUNK////////////////////////////////////// StateChangeRegister * StateChangeRegister::m_Instance; Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2009-11-07 05:51:41 UTC (rev 604) +++ Mercury2/src/Texture.cpp 2009-11-07 08:37:17 UTC (rev 605) @@ -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_dynamic(false) + :MercuryAsset( key, bInstanced ), m_raw(NULL),m_textureID(0),m_bDeleteRaw(true),m_dynamic(false) { if (!m_initTextureSuccess) { @@ -76,7 +76,8 @@ GLCALL( glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP) ); // GLCALL( gluBuild2DMipmaps( GL_TEXTURE_2D, 3, m_raw->m_width, m_raw->m_height, ByteType, GL_UNSIGNED_BYTE, m_raw->m_data ) ); - SAFE_DELETE(m_raw); + if( m_bDeleteRaw ) + SAFE_DELETE(m_raw); GLCALL( glPopAttrib() ); Modified: Mercury2/src/Texture.h =================================================================== --- Mercury2/src/Texture.h 2009-11-07 05:51:41 UTC (rev 604) +++ Mercury2/src/Texture.h 2009-11-07 08:37:17 UTC (rev 605) @@ -20,7 +20,10 @@ virtual bool ChangeKey( const MString & sNewKey ); void LoadFromRaw(); - + + void SetDeleteRawData( bool bDelete = true ) { m_bDeleteRaw = bDelete; } + RawImageData * GetRawImageDataHandle() { return m_raw; } + inline static uint8_t NumberActiveTextures() { return m_numActiveTextures; } inline static uint32_t ReadAndResetBindCount() { uint32_t t = m_textureBinds; m_textureBinds = 0; return t; } inline uint32_t TextureID() const { return m_textureID; } @@ -35,6 +38,7 @@ static void ApplyActiveTextures(uint16_t stride); static void DisableUnusedTextures(); + GENRTTI( Texture ); private: void LoadImagePath(const MString& path); @@ -47,7 +51,7 @@ void InitiateBindCache(); - const RawImageData* m_raw; + RawImageData* m_raw; uint32_t m_textureID; static bool m_initTextureSuccess; @@ -58,6 +62,7 @@ static uint8_t m_maxActiveTextures; static Texture** m_lastBound; + bool m_bDeleteRaw; bool m_dynamic; // MString m_filename; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-11-07 22:40:53
|
Revision: 606 http://hgengine.svn.sourceforge.net/hgengine/?rev=606&view=rev Author: cnlohr Date: 2009-11-07 22:40:43 +0000 (Sat, 07 Nov 2009) Log Message: ----------- add new utility for getting a point + ray equation for the camera / point and click ... plus enable diabling of clamping of textures. Modified Paths: -------------- Mercury2/src/GLHelpers.cpp Mercury2/src/GLHelpers.h Mercury2/src/Texture.cpp Mercury2/src/Texture.h Modified: Mercury2/src/GLHelpers.cpp =================================================================== --- Mercury2/src/GLHelpers.cpp 2009-11-07 08:37:17 UTC (rev 605) +++ Mercury2/src/GLHelpers.cpp 2009-11-07 22:40:43 UTC (rev 606) @@ -91,6 +91,41 @@ return pointFromScreenLoc( screen_x, screen_y, winZ ); } +void CameraPointAndRay(int screen_x, int screen_y, MercuryVertex & p, MercuryVertex & r) +{ + GLfloat winX, winY, winZ; + GLdouble dox = 0, doy = 0, doz = 0; + GLint viewport[4]; + GLdouble modelview[16]; + GLdouble projection[16]; + + GLCALL( glGetIntegerv(GL_VIEWPORT, viewport) ); + GLCALL( glGetDoublev(GL_MODELVIEW_MATRIX, modelview) ); + GLCALL( glGetDoublev(GL_PROJECTION_MATRIX, projection) ); + + winX = (float)screen_x; + winY = (float)viewport[3] - (float)screen_y; + + gluUnProject( + winX, winY, -1000, + modelview, projection, viewport, + &dox, &doy, &doz); + + p = MercuryVertex( dox, doy, doz ); + + gluUnProject( + winX, winY, 1, + modelview, projection, viewport, + &dox, &doy, &doz ); + r = MercuryVertex( dox, doy, doz ) - p; + + r.NormalizeSelf(); + + return; + +} + + unsigned int ToGLColorType(ColorByteType cbt) { switch (cbt) Modified: Mercury2/src/GLHelpers.h =================================================================== --- Mercury2/src/GLHelpers.h 2009-11-07 08:37:17 UTC (rev 605) +++ Mercury2/src/GLHelpers.h 2009-11-07 22:40:43 UTC (rev 606) @@ -19,6 +19,7 @@ MercuryMatrix glGetMatrix(unsigned int m); MercuryVertex pointFromScreenLoc(int screen_x, int screen_y); MercuryVertex pointFromScreenLoc(int screen_x, int screen_y, float fForceDepth); +void CameraPointAndRay(int screen_x, int screen_y, MercuryVertex & p, MercuryVertex & r); unsigned int ToGLColorType(ColorByteType cbt); #ifdef GL_PROFILE Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2009-11-07 08:37:17 UTC (rev 605) +++ Mercury2/src/Texture.cpp 2009-11-07 22:40:43 UTC (rev 606) @@ -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) + :MercuryAsset( key, bInstanced ), m_raw(NULL),m_textureID(0),m_bDeleteRaw(true),m_dynamic(false), m_bClamp(true) { if (!m_initTextureSuccess) { @@ -72,8 +72,11 @@ // GLCALL( glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ); - GLCALL( glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP) ); - GLCALL( glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP) ); + if( m_bClamp ) + { + GLCALL( glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP) ); + GLCALL( glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP) ); + } // GLCALL( gluBuild2DMipmaps( GL_TEXTURE_2D, 3, m_raw->m_width, m_raw->m_height, ByteType, GL_UNSIGNED_BYTE, m_raw->m_data ) ); if( m_bDeleteRaw ) @@ -102,8 +105,10 @@ void Texture::LoadFromXML(const XMLNode& node) { if ( !node.Attribute("dynamic").empty() ) - m_dynamic = node.Attribute("dynamic")=="true"?true:false; - + m_dynamic = StrToBool( node.Attribute("dynamic") ); + if( !node.Attribute( "clamp" ).empty() ) + m_bClamp = StrToBool( node.Attribute("clamp" ) ); + MString file = node.Attribute("file"); ChangeKey( file ); Modified: Mercury2/src/Texture.h =================================================================== --- Mercury2/src/Texture.h 2009-11-07 08:37:17 UTC (rev 605) +++ Mercury2/src/Texture.h 2009-11-07 22:40:43 UTC (rev 606) @@ -64,6 +64,7 @@ bool m_bDeleteRaw; bool m_dynamic; + bool m_bClamp; // MString m_filename; }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-11-08 15:48:45
|
Revision: 607 http://hgengine.svn.sourceforge.net/hgengine/?rev=607&view=rev Author: axlecrusher Date: 2009-11-08 15:48:23 +0000 (Sun, 08 Nov 2009) Log Message: ----------- untested vertex color arrays Modified Paths: -------------- Mercury2/src/MercuryVBO.cpp Mercury2/src/MercuryVBO.h Modified: Mercury2/src/MercuryVBO.cpp =================================================================== --- Mercury2/src/MercuryVBO.cpp 2009-11-07 22:40:43 UTC (rev 606) +++ Mercury2/src/MercuryVBO.cpp 2009-11-08 15:48:23 UTC (rev 607) @@ -9,17 +9,18 @@ extern bool SHOWBOUNDINGVOLUME; extern bool SHOWAXISES; -MercuryVBO::MercuryVBO( const MString & key, bool bInstanced ) - :MercuryAsset( key, bInstanced ), m_initiated(false) +MercuryVBO::MercuryVBO( const MString & key, bool bInstanced, bool useVertexColor ) + :MercuryAsset( key, bInstanced ), m_initiated(false), m_useVertexColor(useVertexColor) { - m_bufferIDs[0] = m_bufferIDs[1] = 0; - m_bDirtyIndices = m_bDirtyVertices = 0; + m_bufferIDs[0] = m_bufferIDs[1] = m_bufferIDs[2] = 0; + m_bDirtyIndices = m_bDirtyVertices = m_bDirtyVertexColor = false; } MercuryVBO::~MercuryVBO() { - if (m_bufferIDs[0]) { GLCALL( glDeleteBuffersARB(2, m_bufferIDs) ); } - m_bufferIDs[0] = m_bufferIDs[1] = 0; + if (m_bufferIDs[0] > 0) { GLCALL( glDeleteBuffersARB(2, m_bufferIDs) ); } + if (m_bufferIDs[2] > 0) { GLCALL( glDeleteBuffersARB(1, &m_bufferIDs[2]) ); } + m_bufferIDs[0] = m_bufferIDs[1] = m_bufferIDs[2] = 0; } void MercuryVBO::Render(const MercuryNode* node) @@ -31,38 +32,51 @@ { m_lastVBOrendered = this; - if ( m_bDirtyVertices ) - UpdateVertices(); - if( m_bDirtyIndices ) - UpdateIndices(); + if ( m_bDirtyVertices ) UpdateVertices(); + if( m_bDirtyIndices ) UpdateIndices(); + if( m_bDirtyVertexColor ) UpdateVertexColor(); GLCALL( glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferIDs[0]) ); GLCALL( glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_bufferIDs[1]) ); GLCALL( glVertexPointer(3, GL_FLOAT, STRIDE*sizeof(float), BUFFER_OFFSET( VERTEX_OFFSET*sizeof(float) ) ) ); + + if (m_useVertexColor) + { + GLCALL( glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferIDs[2]) ); + GLCALL( glColorPointer(4, GL_FLOAT, 0, 0 ) ); + } + ++m_vboBinds; } + GLCALL( glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT) ); + + if (m_useVertexColor) { GLCALL( glEnableClientState( GL_COLOR_ARRAY ) ); } + Texture::ApplyActiveTextures(STRIDE*sizeof(float)); 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) ); - m_vboBatches++; + ++m_vboBatches; if (m_boundingVolume && SHOWBOUNDINGVOLUME) m_boundingVolume->Render(); + + GLCALL( glPopClientAttrib() ); + if ( SHOWAXISES ) DrawAxes(); } void MercuryVBO::InitVBO() { - if (!m_bufferIDs[0]) - { - GLCALL( glGenBuffersARB(2, m_bufferIDs) ); - } + if (!m_bufferIDs[0]) { GLCALL( glGenBuffersARB(2, m_bufferIDs) ); } + if (m_useVertexColor) { GLCALL( glGenBuffersARB(1, &m_bufferIDs[2]) ); } UpdateIndices(); UpdateVertices(); + UpdateVertexColor(); + GLCALL( glEnableClientState(GL_VERTEX_ARRAY) ); m_initiated = true; @@ -72,19 +86,30 @@ { GLCALL( glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_bufferIDs[1]) ); GLCALL( glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_indexData.LengthInBytes(), m_indexData.Buffer(), GL_STATIC_DRAW_ARB) ); - m_bDirtyIndices = 0; + m_bDirtyIndices = false; } void MercuryVBO::UpdateVertices() { GLCALL( glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferIDs[0]) ); GLCALL( glBufferDataARB(GL_ARRAY_BUFFER_ARB, m_vertexData.LengthInBytes(), m_vertexData.Buffer(), GL_STATIC_DRAW_ARB) ); - m_bDirtyVertices = 0; + m_bDirtyVertices = false; } +void MercuryVBO::UpdateVertexColor() +{ + if (m_useVertexColor) + { + GLCALL( glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferIDs[2]) ); + GLCALL( glBufferDataARB(GL_ARRAY_BUFFER_ARB, m_vertexColorData.LengthInBytes(), m_vertexColorData.Buffer(), GL_STATIC_DRAW_ARB) ); + } + m_bDirtyVertexColor = false; +} + void MercuryVBO::AllocateVertexSpace(unsigned int count) { m_vertexData.Allocate(count*8); + if (m_useVertexColor) m_vertexColorData.Allocate(count*4); } void MercuryVBO::AllocateIndexSpace(unsigned int count) Modified: Mercury2/src/MercuryVBO.h =================================================================== --- Mercury2/src/MercuryVBO.h 2009-11-07 22:40:43 UTC (rev 606) +++ Mercury2/src/MercuryVBO.h 2009-11-08 15:48:23 UTC (rev 607) @@ -13,7 +13,7 @@ static const uint16_t STRIDE = 8; static const uint16_t VERTEX_OFFSET = 5; - MercuryVBO( const MString & key, bool bInstanced ); + MercuryVBO( const MString & key, bool bInstanced, bool useVertexColor = false ); virtual ~MercuryVBO(); virtual void Render(const MercuryNode* node); @@ -27,7 +27,10 @@ const float* GetVertexHandle() const { return m_vertexData.Buffer(); } float* GetVertexHandle() { return m_vertexData.Buffer(); } - + + const float* GetVertexColorHandle() const { return m_vertexColorData.Buffer(); } + float* GetVertexColorHandle() { return m_vertexColorData.Buffer(); } + const short unsigned int* GetIndexHandle() const { return m_indexData.Buffer(); } short unsigned int* GetIndexHandle() { return m_indexData.Buffer(); } @@ -35,22 +38,29 @@ static void* m_lastVBOrendered; - void DirtyVertices() { m_bDirtyVertices = 1; } - void DirtyIndices() { m_bDirtyIndices = 1; } + inline void DirtyVertices() { m_bDirtyVertices = true; } + inline void DirtyVerexColor() { m_bDirtyVertexColor = true; } + inline void DirtyIndices() { m_bDirtyIndices = true; } + GENRTTI( MercuryVBO ); private: virtual void InitVBO(); - unsigned int m_bufferIDs[2]; + unsigned int m_bufferIDs[3]; bool m_initiated; bool m_bDirtyIndices; bool m_bDirtyVertices; + bool m_bDirtyVertexColor; + + bool m_useVertexColor; void UpdateVertices(); + void UpdateVertexColor(); void UpdateIndices(); protected: AlignedBuffer<float> m_vertexData; + AlignedBuffer<float> m_vertexColorData; AlignedBuffer<uint16_t> m_indexData; static uint32_t m_vboBatches; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-11-08 23:15:54
|
Revision: 608 http://hgengine.svn.sourceforge.net/hgengine/?rev=608&view=rev Author: cnlohr Date: 2009-11-08 23:15:45 +0000 (Sun, 08 Nov 2009) Log Message: ----------- add framework for attributes + make quads able to have straight V's for normal texture mapping Modified Paths: -------------- Mercury2/src/Quad.cpp Mercury2/src/Quad.h Modified: Mercury2/src/Quad.cpp =================================================================== --- Mercury2/src/Quad.cpp 2009-11-08 15:48:23 UTC (rev 607) +++ Mercury2/src/Quad.cpp 2009-11-08 23:15:45 UTC (rev 608) @@ -6,7 +6,7 @@ REGISTER_ASSET_TYPE(Quad); Quad::Quad( const MString & key, bool bInstanced ) - :MercuryVBO( key, bInstanced ) + :MercuryVBO( key, bInstanced ), m_bFlipV( true ) { ChangeKey( key ); } @@ -35,6 +35,7 @@ float hX = 0.5; float hY = 0.5; float zp = 0; + m_bFlipV = true; AllocateIndexSpace(6); AllocateVertexSpace(4); @@ -42,6 +43,20 @@ MVector< MString > vsDescription; SplitStrings( sDescription, vsDescription, ",", " ", 1, 1 ); + //First, check for known attributes... + do + { + if( !vsDescription.size() ) + break; + + if( vsDescription[0] == "straightv" ) + { + m_bFlipV = false; + vsDescription.remove( 0 ); + } + + } while(1); + if( vsDescription.size() == 0 ) { //Do nothing @@ -73,19 +88,19 @@ //UV oriented so 0,0 is lower left and 1,0 upper right. //this makes it so FBO images render correctly right out of the buffer, no flip needed - m_vertexData[i++] = 0; m_vertexData[i++] = 0; + m_vertexData[i++] = 0; m_vertexData[i++] = (m_bFlipV)?0:1; m_vertexData[i++] = 0; m_vertexData[i++] = 0; m_vertexData[i++] = -1.0; m_vertexData[i++] = lX; m_vertexData[i++] = lY; m_vertexData[i++] = zp; - m_vertexData[i++] = 1; m_vertexData[i++] = 0; + m_vertexData[i++] = 1; m_vertexData[i++] = (m_bFlipV)?0:1; m_vertexData[i++] = 0; m_vertexData[i++] = 0; m_vertexData[i++] = -1.0; m_vertexData[i++] = hX; m_vertexData[i++] = lY; m_vertexData[i++] = zp; - m_vertexData[i++] = 1; m_vertexData[i++] = 1; + m_vertexData[i++] = 1; m_vertexData[i++] = (m_bFlipV)?1:0; m_vertexData[i++] = 0; m_vertexData[i++] = 0; m_vertexData[i++] = -1.0; m_vertexData[i++] = hX; m_vertexData[i++] = hY; m_vertexData[i++] = zp; - m_vertexData[i++] = 0; m_vertexData[i++] = 1; + m_vertexData[i++] = 0; m_vertexData[i++] = (m_bFlipV)?1:0; m_vertexData[i++] = 0; m_vertexData[i++] = 0; m_vertexData[i++] = -1.0; m_vertexData[i++] = lX; m_vertexData[i++] = hY; m_vertexData[i++] = zp; Modified: Mercury2/src/Quad.h =================================================================== --- Mercury2/src/Quad.h 2009-11-08 15:48:23 UTC (rev 607) +++ Mercury2/src/Quad.h 2009-11-08 23:15:45 UTC (rev 608) @@ -14,7 +14,9 @@ virtual bool ChangeKey( const MString & sDescription ); GENRTTI( Quad ); + private: + bool m_bFlipV; }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-11-13 07:35:45
|
Revision: 612 http://hgengine.svn.sourceforge.net/hgengine/?rev=612&view=rev Author: cnlohr Date: 2009-11-13 07:35:37 +0000 (Fri, 13 Nov 2009) Log Message: ----------- Oops - forgot to commit these - the RAM Vorbis players Added Paths: ----------- Mercury2/src/MercurySoundSourceVorbisRAM.cpp Mercury2/src/MercurySoundSourceVorbisRAM.h Added: Mercury2/src/MercurySoundSourceVorbisRAM.cpp =================================================================== --- Mercury2/src/MercurySoundSourceVorbisRAM.cpp (rev 0) +++ Mercury2/src/MercurySoundSourceVorbisRAM.cpp 2009-11-13 07:35:37 UTC (rev 612) @@ -0,0 +1,150 @@ +#include <MercurySoundSourceVorbisRAM.h> +#include <vorbis/vorbisfile.h> +#include <MercuryFile.h> +#include <MercuryLog.h> +#include <ogg/ogg.h> + + +REGISTER_SOUND_SOURCE( MercurySoundSourceVorbisRAM, "VorbisRAM" ); + +size_t vorbis_read_func(void *ptr, size_t size, size_t nmemb, void *datasource) +{ + MercuryFile * f = (MercuryFile*)datasource; + return f->Read( ptr, size * nmemb ); +} + +int vorbis_seek_func(void *datasource, ogg_int64_t offset, int whence) +{ + MercuryFile * f = (MercuryFile*)datasource; + switch( whence ) + { + case SEEK_SET: + return !f->Seek( offset ); + case SEEK_END: + return !f->Seek( f->Length() - offset - 1 ); + case SEEK_CUR: + return !f->Seek( f->Tell() + offset ); + default: + LOG.Write( ssprintf( "Warning: OGG Decided to seek with invalid whence!" ) ); + } + return -1; +} + +int vorbis_close_func(void *datasource) +{ + return 0; +} + +long vorbis_tell_func(void *datasource) +{ + MercuryFile * f = (MercuryFile*)datasource; + return f->Tell(); +} + + +MercurySoundSourceVorbisRAM::MercurySoundSourceVorbisRAM( MercurySoundSource * chain ) : + MercurySoundSourceRAM( chain ) +{ +} + +bool MercurySoundSourceVorbisRAM::Load( const MString & sDescriptor ) +{ + unsigned Vorbistotal_bytes_read = 0; + int VorbisAbstream; + + MAutoPtr< HGRawSound > r; + MAutoPtr< HGRawSound > * g; + if( ( g = g_SoundLibrary.get( sDescriptor ) ) ) + { + m_Sound = *g; + return true; + } + + MercuryFile * f = FILEMAN.Open( sDescriptor ); + + OggVorbis_File * vorbisFile = new OggVorbis_File; + + ov_callbacks vorbisCallbacks; + vorbisCallbacks.read_func = vorbis_read_func; + vorbisCallbacks.seek_func = vorbis_seek_func; + vorbisCallbacks.close_func = vorbis_close_func; + vorbisCallbacks.tell_func = vorbis_tell_func; + + int ret = ov_open_callbacks( f, vorbisFile, NULL, 0, vorbisCallbacks ); + + 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; + + if( VorbisSamples <= 0 ) + { + delete f; + delete vorbisFile; + } + + short * VorbisData = new short[VorbisSamples*VorbisChannels]; + + while( (Vorbisbytes_read = ov_read(vorbisFile, ((char*)VorbisData) + + Vorbistotal_bytes_read, VorbisSamples*VorbisChannels*2 - + Vorbistotal_bytes_read, 0, 2, 1, &VorbisAbstream)) > 0 ) + { + if( VorbisAbstream == 0 ) + Vorbistotal_bytes_read+= Vorbisbytes_read; + } + + r = new HGRawSound(new float[VorbisSamples*VorbisChannels],VorbisSamples); + + for( unsigned i = 0; i < VorbisSamples*VorbisChannels; i++ ) + { + r->fSound[i] = ((float)VorbisData[i])/32768.0; + } + + delete vorbisFile; + delete f; + + m_Sound = r; + g_SoundLibrary[sDescriptor] = r; + return true; +} + +MHash< MAutoPtr< HGRawSound > > MercurySoundSourceVorbisRAM::g_SoundLibrary; + + + +/**************************************************************************** + * Copyright (C) 2009 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. * + ***************************************************************************/ + + Added: Mercury2/src/MercurySoundSourceVorbisRAM.h =================================================================== --- Mercury2/src/MercurySoundSourceVorbisRAM.h (rev 0) +++ Mercury2/src/MercurySoundSourceVorbisRAM.h 2009-11-13 07:35:37 UTC (rev 612) @@ -0,0 +1,52 @@ +#ifndef _MERCURY_SOUND_SOURCE_VORBISRAM +#define _MERCURY_SOUND_SOURCE_VORBISRAM + +#include <MercurySoundSourceRAM.h> + + +class MercurySoundSourceVorbisRAM : public MercurySoundSourceRAM +{ +public: + MercurySoundSourceVorbisRAM( MercurySoundSource * chain = 0 ); + + virtual bool Load( const MString & sDescriptor ); +protected: + static MHash< MAutoPtr< HGRawSound > > g_SoundLibrary; +}; + + +#endif + +/**************************************************************************** + * Copyright (C) 2009 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: <cn...@us...> - 2009-11-13 07:38:29
|
Revision: 613 http://hgengine.svn.sourceforge.net/hgengine/?rev=613&view=rev Author: cnlohr Date: 2009-11-13 07:38:19 +0000 (Fri, 13 Nov 2009) Log Message: ----------- permit other texture modes Modified Paths: -------------- Mercury2/src/Texture.cpp Mercury2/src/Texture.h Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2009-11-13 07:35:37 UTC (rev 612) +++ Mercury2/src/Texture.cpp 2009-11-13 07:38:19 UTC (rev 613) @@ -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) + :MercuryAsset( key, bInstanced ), m_raw(NULL),m_textureID(0),m_bDeleteRaw(true),m_dynamic(false), m_bClamp(true), m_tFilterMode(TF_LINEAR_MIPS) { if (!m_initTextureSuccess) { @@ -65,10 +65,24 @@ GL_UNSIGNED_BYTE, m_raw->m_data); */ - GLCALL( gluBuild2DMipmaps( GL_TEXTURE_2D, byteType, m_raw->m_width, m_raw->m_height, byteType, GL_UNSIGNED_BYTE, m_raw->m_data ) ); - - GLCALL( glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST) ); - GLCALL( glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR) ); + if( m_tFilterMode == TF_NONE ) + { + GLCALL( glTexImage2D(GL_TEXTURE_2D, 0, byteType, m_raw->m_width, m_raw->m_height, 0, byteType, GL_UNSIGNED_BYTE, m_raw->m_data) ); + GLCALL( glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST) ); + GLCALL( glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST) ); + } + else if( m_tFilterMode == TF_LINEAR ) + { + GLCALL( glTexImage2D(GL_TEXTURE_2D, 0, byteType, m_raw->m_width, m_raw->m_height, 0, byteType, GL_UNSIGNED_BYTE, m_raw->m_data) ); + GLCALL( glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR) ); + GLCALL( glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR) ); + } + else + { + GLCALL( gluBuild2DMipmaps( GL_TEXTURE_2D, byteType, m_raw->m_width, m_raw->m_height, byteType, GL_UNSIGNED_BYTE, m_raw->m_data ) ); + GLCALL( glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR) ); + GLCALL( glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR) ); + } // GLCALL( glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ) ); @@ -104,11 +118,23 @@ void Texture::LoadFromXML(const XMLNode& node) { - if ( !node.Attribute("dynamic").empty() ) - m_dynamic = StrToBool( node.Attribute("dynamic") ); - if( !node.Attribute( "clamp" ).empty() ) - m_bClamp = StrToBool( node.Attribute("clamp" ) ); + LOAD_FROM_XML( "dynamic", m_dynamic, StrToBool ); + LOAD_FROM_XML( "clamp", m_bClamp, StrToBool ); + + MString filter = node.Attribute( "filter" ); + if( !filter.empty() ) + { + if( filter == "none" ) + { + m_tFilterMode = TF_NONE; + } + else if( filter == "linear" ) + { + m_tFilterMode = TF_LINEAR; + } + } + MString file = node.Attribute("file"); ChangeKey( file ); Modified: Mercury2/src/Texture.h =================================================================== --- Mercury2/src/Texture.h 2009-11-13 07:35:37 UTC (rev 612) +++ Mercury2/src/Texture.h 2009-11-13 07:38:19 UTC (rev 613) @@ -4,6 +4,13 @@ #include <MercuryAsset.h> #include <RawImageData.h> +enum TextureFilterMode +{ + TF_NONE, + TF_LINEAR, + TF_LINEAR_MIPS, +}; + class Texture : public MercuryAsset { public: @@ -39,6 +46,8 @@ static void ApplyActiveTextures(uint16_t stride); static void DisableUnusedTextures(); + void SetFilter( TextureFilterMode t ) { m_tFilterMode = t; } + GENRTTI( Texture ); private: void LoadImagePath(const MString& path); @@ -65,7 +74,8 @@ bool m_bDeleteRaw; bool m_dynamic; bool m_bClamp; -// MString m_filename; + TextureFilterMode m_tFilterMode; + }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-11-13 07:40:22
|
Revision: 614 http://hgengine.svn.sourceforge.net/hgengine/?rev=614&view=rev Author: cnlohr Date: 2009-11-13 07:40:16 +0000 (Fri, 13 Nov 2009) Log Message: ----------- virtualize addition/removal of children, and add macro for helping out load from XML. Modified Paths: -------------- Mercury2/src/MercuryNode.cpp Mercury2/src/MercuryNode.h Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-11-13 07:38:19 UTC (rev 613) +++ Mercury2/src/MercuryNode.cpp 2009-11-13 07:40:16 UTC (rev 614) @@ -275,11 +275,11 @@ { SetName( node.Attribute("name") ); - if ( !node.Attribute("hidden").empty() ) - m_hidden = StrToBool( node.Attribute("hidden") ); + 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 ); - if ( !node.Attribute("alphaPath").empty() ) - m_useAlphaPath = StrToBool( node.Attribute("alphaPath") ); //Not much to do here except run through all the children nodes for (XMLNode child = node.Child(); child.IsValid(); child = child.NextNode()) Modified: Mercury2/src/MercuryNode.h =================================================================== --- Mercury2/src/MercuryNode.h 2009-11-13 07:38:19 UTC (rev 613) +++ Mercury2/src/MercuryNode.h 2009-11-13 07:40:16 UTC (rev 614) @@ -17,14 +17,7 @@ Each node exists as a single entity in the scene graph. **/ -/* -#define GENRTTI(x) static bool IsMyType(const MercuryNode* n) \ -{ const MercuryNode* tn = n; \ -while(tn) { if (typeid(x) == typeid(*tn)) return true; tn = *n; } \ -return false;} -*/ - #define STANDARD_PASS 7 ///Which passes, by default, should be run on all nodes. #define DEFAULT_PASSES ( (1<<STANDARD_PASS) ) @@ -41,8 +34,8 @@ MercuryNode(); virtual ~MercuryNode(); - void AddChild(MercuryNode* n); - void RemoveChild(MercuryNode* n); + virtual void AddChild(MercuryNode* n); + virtual void RemoveChild(MercuryNode* n); inline MercuryNode* Parent() const { return m_parent; } inline MercuryNode* NextSibling() const { return m_nextSibling; } @@ -128,6 +121,8 @@ const MercuryMatrix & GetModelViewMatrix() const { return m_pModelViewMatrix[g_iViewportID]; } 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; @@ -182,6 +177,8 @@ static InstanceCounter<NodeFactory> NFcounter("NodeFactory"); + +///Register a new instance of the node with the main Mercury Node Registration System. #define REGISTER_NODE_TYPE(class)\ MercuryNode* FactoryFunct##class() { return new class(); } \ Callback0R<MercuryNode*> factoryclbk##class( FactoryFunct##class ); \ @@ -195,6 +192,17 @@ } } +///Load a variable from XML (safely) - this loads a variable of type name into variable using the transform function. +#define LOAD_FROM_XML( name, variable, function ) \ + if ( !node.Attribute( name ).empty() ) \ + variable = function ( node.Attribute(name) ); + +///Call callee if attribute name exists in XML - attribute can be transformed using function +#define LOAD_FROM_XML_CALL( name, callee, function ) \ + if ( !node.Attribute( name ).empty() ) \ + callee( function ( node.Attribute(name) ) ); + + #endif /**************************************************************************** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-11-13 07:43:20
|
Revision: 615 http://hgengine.svn.sourceforge.net/hgengine/?rev=615&view=rev Author: cnlohr Date: 2009-11-13 07:43:08 +0000 (Fri, 13 Nov 2009) Log Message: ----------- Add BroadcastMessage for immediate sending AND Modify the MESSAGEMAN macro to include Instance(). Modified Paths: -------------- Mercury2/src/Mercury2.cpp Mercury2/src/MercuryMessageManager.cpp Mercury2/src/MercuryMessageManager.h Modified: Mercury2/src/Mercury2.cpp =================================================================== --- Mercury2/src/Mercury2.cpp 2009-11-13 07:40:16 UTC (rev 614) +++ Mercury2/src/Mercury2.cpp 2009-11-13 07:43:08 UTC (rev 615) @@ -130,7 +130,7 @@ do { timer.Touch(); - MESSAGEMAN::GetInstance().PumpMessages( timer.MicrosecondsSinceInit() ); + MESSAGEMAN.PumpMessages( timer.MicrosecondsSinceInit() ); root->RecursiveUpdate( timer.Age() ); //comment to use threads Modified: Mercury2/src/MercuryMessageManager.cpp =================================================================== --- Mercury2/src/MercuryMessageManager.cpp 2009-11-13 07:40:16 UTC (rev 614) +++ Mercury2/src/MercuryMessageManager.cpp 2009-11-13 07:43:08 UTC (rev 615) @@ -46,6 +46,36 @@ } } +void MercuryMessageManager::BroadcastMessage( const MString & message, MessageData * data ) +{ + std::list< MessagePair > recipients; + { + //copy list first (quick lock) + MSemaphoreLock lock(&m_recipientLock); + std::list< MessagePair > * r = m_messageRecipients.get( message ); + if ( r ) recipients = *r; + } + + if ( !recipients.empty() ) + { + std::list< MessagePair >::iterator recipient = recipients.begin(); + for (; recipient != recipients.end(); ++recipient) + { + MessagePair & mp = *recipient; + //Okay, the following lines look horrible. Reason is we're using + //a horrible horrible c++ construct from the anals of pointerdom. + //The idea is we're using a delegate. If we have a delegate, use it. + //If you are receiving a delegate, you do not need the message name. + //Otherwise, send a standard message through the old interface. + if( mp.d ) + (mp.h->*(mp.d))( *(data) ); + else + mp.h->HandleMessage(message, *(data) ); + } + } + +} + void MercuryMessageManager::UnRegisterForMessage(const MString& message, MessageHandler* ptr) { MSemaphoreLock lock(&m_recipientLock); Modified: Mercury2/src/MercuryMessageManager.h =================================================================== --- Mercury2/src/MercuryMessageManager.h 2009-11-13 07:40:16 UTC (rev 614) +++ Mercury2/src/MercuryMessageManager.h 2009-11-13 07:43:08 UTC (rev 615) @@ -35,7 +35,13 @@ { public: MercuryMessageManager() : m_messageQueue( MessageHolder::Compare ) { } + + ///Dispatch message whenever the message manager gets control again; delay after now. void PostMessage(const MString& message, MessageData* data, float delay); + + ///Immediately dispatch message + void BroadcastMessage( const MString & message, MessageData * data ); + void PumpMessages(const uint64_t& currTime); void RegisterForMessage(const MString& message, MessageHandler* ptr, Delegate d = 0 ); @@ -65,11 +71,11 @@ static InstanceCounter<MercuryMessageManager> MMcounter("MessageManager"); -#define MESSAGEMAN MercuryMessageManager -#define REGISTER_MESSAGE_WITH_DELEGATE(x, d) MESSAGEMAN::GetInstance().RegisterForMessage(x, this, (Delegate)d) -#define REGISTER_FOR_MESSAGE(x) MESSAGEMAN::GetInstance().RegisterForMessage(x, this) -#define UNREGISTER_FOR_MESSAGE(x) MESSAGEMAN::GetInstance().UnRegisterForMessage(x, this) -#define POST_MESSAGE(x,data,delay) MESSAGEMAN::GetInstance().PostMessage(x, data, delay) +#define MESSAGEMAN MercuryMessageManager::GetInstance() +#define REGISTER_MESSAGE_WITH_DELEGATE(x, d) MESSAGEMAN.RegisterForMessage(x, this, (Delegate)d) +#define REGISTER_FOR_MESSAGE(x) MESSAGEMAN.RegisterForMessage(x, this) +#define UNREGISTER_FOR_MESSAGE(x) MESSAGEMAN.UnRegisterForMessage(x, this) +#define POST_MESSAGE(x,data,delay) MESSAGEMAN.PostMessage(x, data, delay) #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-11-13 07:45:04
|
Revision: 618 http://hgengine.svn.sourceforge.net/hgengine/?rev=618&view=rev Author: cnlohr Date: 2009-11-13 07:44:56 +0000 (Fri, 13 Nov 2009) Log Message: ----------- Broadcast button press location along with button presses. Modified Paths: -------------- Mercury2/src/X11Window.cpp Mercury2/src/X11Window.h Modified: Mercury2/src/X11Window.cpp =================================================================== --- Mercury2/src/X11Window.cpp 2009-11-13 07:44:34 UTC (rev 617) +++ Mercury2/src/X11Window.cpp 2009-11-13 07:44:56 UTC (rev 618) @@ -286,7 +286,7 @@ su = ((e->state & X11_MASK(MOUSE_BTN_SCROLL_UP))!=0) ^ (e->button == MOUSE_BTN_SCROLL_UP); sd = ((e->state & X11_MASK(MOUSE_BTN_SCROLL_DOWN))!=0) ^ (e->button == MOUSE_BTN_SCROLL_DOWN); - MouseInput::ProcessMouseInput(0, 0, + MouseInput::ProcessMouseInput(m_iLastMouseX, m_iLastMouseY , left, right, center, su, sd); break; } @@ -323,12 +323,16 @@ y = m_height/2 - e->y; if (x!=0 || y!=0) //prevent recursive XWarp { + m_iLastMouseX = x; + m_iLastMouseY = y; MouseInput::ProcessMouseInput(x, y, left, right, center, su, sd); XWarpPointer(m_display, None, m_window, 0,0,0,0,m_width/2,m_height/2); } } else { + m_iLastMouseX = e->x; + m_iLastMouseY = e->y; MouseInput::ProcessMouseInput(e->x, e->y, left, right, center, su, sd); } break; Modified: Mercury2/src/X11Window.h =================================================================== --- Mercury2/src/X11Window.h 2009-11-13 07:44:34 UTC (rev 617) +++ Mercury2/src/X11Window.h 2009-11-13 07:44:56 UTC (rev 618) @@ -28,6 +28,9 @@ GLXContext m_renderCtx; Window m_window; Atom m_wmDeleteMessage; + + int m_iLastMouseX; + int m_iLastMouseY; }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-11-18 22:09:31
|
Revision: 622 http://hgengine.svn.sourceforge.net/hgengine/?rev=622&view=rev Author: cnlohr Date: 2009-11-18 22:09:24 +0000 (Wed, 18 Nov 2009) Log Message: ----------- add lastchild Modified Paths: -------------- Mercury2/src/MercuryNode.cpp Mercury2/src/MercuryNode.h Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-11-18 22:09:16 UTC (rev 621) +++ Mercury2/src/MercuryNode.cpp 2009-11-18 22:09:24 UTC (rev 622) @@ -114,6 +114,15 @@ return NULL; } +MercuryNode* MercuryNode::LastChild() const +{ + if( !m_children.empty() ) + return m_children.back(); + else + return NULL; +} + + MercuryNode* MercuryNode::NextChild(const MercuryNode* child) const { if (child==NULL) return NULL; Modified: Mercury2/src/MercuryNode.h =================================================================== --- Mercury2/src/MercuryNode.h 2009-11-18 22:09:16 UTC (rev 621) +++ Mercury2/src/MercuryNode.h 2009-11-18 22:09:24 UTC (rev 622) @@ -41,6 +41,7 @@ inline MercuryNode* NextSibling() const { return m_nextSibling; } inline MercuryNode* PrevSibling() const { return m_prevSibling; } MercuryNode* FirstChild() const; + MercuryNode* LastChild() const; MercuryNode* NextChild(const MercuryNode* n) const; ///Finds the next child in regards to n MercuryNode* PrevChild(const MercuryNode* n) const; ///Finds the previous child in regards to n const std::list< MercuryNode* >& Children() const { return m_children; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-12-14 20:16:47
|
Revision: 626 http://hgengine.svn.sourceforge.net/hgengine/?rev=626&view=rev Author: axlecrusher Date: 2009-12-14 20:16:40 +0000 (Mon, 14 Dec 2009) Log Message: ----------- updates Modified Paths: -------------- Mercury2/src/GLHeaders.h Mercury2/src/MercuryNode.h Mercury2/src/Shader.cpp Mercury2/src/StateChanger.cpp Modified: Mercury2/src/GLHeaders.h =================================================================== --- Mercury2/src/GLHeaders.h 2009-11-18 23:03:51 UTC (rev 625) +++ Mercury2/src/GLHeaders.h 2009-12-14 20:16:40 UTC (rev 626) @@ -1,8 +1,8 @@ #ifndef GLHEADERS_H #define GLHEADERS_H - -#include <configuration.h> +#include <configuration.h> + #ifdef WIN32 #include <windows.h> #else @@ -29,6 +29,7 @@ uint32_t e = GLCALL( glGetError() ); \ if ( e != GL_NO_ERROR ) { \ LOG.Write(ssprintf("GL Error:%s", GlError2String(e).c_str())); \ +printf("GL Error:%s", GlError2String(e).c_str()); \ assert(0); } } #define CHECKFBO { \ Modified: Mercury2/src/MercuryNode.h =================================================================== --- Mercury2/src/MercuryNode.h 2009-11-18 23:03:51 UTC (rev 625) +++ Mercury2/src/MercuryNode.h 2009-12-14 20:16:40 UTC (rev 626) @@ -34,6 +34,8 @@ MercuryNode(); virtual ~MercuryNode(); + virtual void Init() {}; + virtual void AddChild(MercuryNode* n); virtual void RemoveChild(MercuryNode* n); Modified: Mercury2/src/Shader.cpp =================================================================== --- Mercury2/src/Shader.cpp 2009-11-18 23:03:51 UTC (rev 625) +++ Mercury2/src/Shader.cpp 2009-12-14 20:16:40 UTC (rev 626) @@ -160,7 +160,7 @@ f2->Read( Buffer, i ); f2->Close(); Buffer[i] = '\0'; - LOG.Write("Compiling: %s"+s2); + LOG.Write("Compiling: "+s2); if( !LoadShaderVert( Buffer ) ) { if( f3 ) @@ -178,7 +178,7 @@ f3->Read( Buffer, i ); f3->Close(); Buffer[i] = '\0'; - LOG.Write("Compiling: %s"+s3); + LOG.Write("Compiling: "+s3); if( !LoadShaderGeom( Buffer ) ) { free( Buffer ); @@ -485,11 +485,13 @@ GLCALL( glUniform1iARB( location, x.value.iInt ) ); break; case ShaderAttribute::TYPE_FLOAT: + GLCALL( glUniform1fARB( location, x.value.fFloat ) ); + break; case ShaderAttribute::TYPE_FLOATV4: GLCALL( glUniform4fvARB( location, 1, &x.value.fFloatV4[0] ) ); break; case ShaderAttribute::TYPE_MATRIX: - GLCALL( glUniformMatrix4fvARB(location, 1, 1, x.value.matrix) ); //transpase too + GLCALL( glUniformMatrix4fvARB(location, 1, 1, x.value.matrix) ); //transpose too break; case ShaderAttribute::TYPE_INT4: GLCALL( glUniform4ivARB( location, 1, x.value.iInts ) ); Modified: Mercury2/src/StateChanger.cpp =================================================================== --- Mercury2/src/StateChanger.cpp 2009-11-18 23:03:51 UTC (rev 625) +++ Mercury2/src/StateChanger.cpp 2009-12-14 20:16:40 UTC (rev 626) @@ -112,7 +112,36 @@ REGISTER_STATECHANGE( DepthTest ); +class DepthWrite : public StateChange +{ +public: + DepthWrite( const MVector< MString > & sParameters ) : StateChange( sParameters ) + { + if( sParameters.size() < 1 ) + { + LOG.Write( ssprintf( "Error: DepthWrite state has invalid number of parameters(%d).", sParameters.size() ) ); + return; + } + bEnable = StrToBool( sParameters[0] ); + } + + void Stringify( MString & sOut ) + { + sOut = ssprintf( "%f", bEnable ); + } + + void Activate() + { + glDepthMask( bEnable ); + } + + STATECHANGE_RTTI( DepthWrite ); + bool bEnable; +}; + +REGISTER_STATECHANGE( DepthWrite ); + //////////////////////////////////////STATE CHANGE CHUNK////////////////////////////////////// StateChangeRegister * StateChangeRegister::m_Instance; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-12-21 20:08:34
|
Revision: 631 http://hgengine.svn.sourceforge.net/hgengine/?rev=631&view=rev Author: axlecrusher Date: 2009-12-21 20:08:27 +0000 (Mon, 21 Dec 2009) Log Message: ----------- windows keyboard input Modified Paths: -------------- Mercury2/src/Win32Window.cpp Mercury2/src/Win32Window.h Modified: Mercury2/src/Win32Window.cpp =================================================================== --- Mercury2/src/Win32Window.cpp 2009-12-21 19:10:26 UTC (rev 630) +++ Mercury2/src/Win32Window.cpp 2009-12-21 20:08:27 UTC (rev 631) @@ -1,5 +1,6 @@ #include <Win32Window.h> #include <GLHeaders.h> +#include <MercuryInput.h> LRESULT CALLBACK WindowCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); //Window callback Callback0R< MercuryWindow* > MercuryWindow::genWindowClbk(Win32Window::GenWin32Window); //Register window generation callback @@ -197,9 +198,18 @@ case WM_QUIT: return false; case WM_KEYDOWN: - printf( "%d\n", message.lParam>>16 ); + { + if ( IsKeyRepeat(message.lParam) ) break; +// printf( "%d\n", message.lParam>>16 ); + KeyboardInput::ProcessKeyInput( ConvertScancode( message.lParam ), true, false); + } break; case WM_KEYUP: + { + if ( IsKeyRepeat(message.lParam) ) break; +// printf( "%d\n", message.lParam>>16 ); + KeyboardInput::ProcessKeyInput( ConvertScancode( message.lParam ), false, false); + } break; case WM_MOUSEMOVE: break; @@ -236,7 +246,119 @@ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); } +bool Win32Window::IsKeyRepeat(uint32_t c) +{ +// printf("count %d\n", (c&65535)); + return (c&65535) > 1; +} +short Win32Window::ConvertScancode( uint32_t scanin ) +{ +// Specifies the scan code. The value depends on the OEM. + scanin = (scanin>>16)&511; + switch( scanin ) + { + case 1: return 27; //esc + case 0: return '0'; + case 41: return 97; //` + case 14: return 8; //backspace + case 87: return 292; //F11 + case 88: return 293; //F12 + case 12: return 45; //- + case 13: return 61; //= + case 43: return 92; //backslash + case 15: return 9; //tab + case 58: return 15; //Caps lock + case 42: return 160; //[lshift] + case 54: return 161; //[rshift] + + case 30: return 'a'; + case 48: return 'b'; + case 46: return 'c'; + case 32: return 'd'; + case 18: return 'e'; + case 33: return 'f'; + case 34: return 'g'; + case 35: return 'h'; + case 23: return 'i'; + case 36: return 'j'; + case 37: return 'k'; + case 38: return 'l'; + case 50: return 'm'; + case 49: return 'n'; + case 24: return 'o'; + case 25: return 'p'; + case 16: return 'q'; + case 19: return 'r'; + case 31: return 's'; + case 20: return 't'; + case 22: return 'u'; + case 47: return 'v'; + case 17: return 'w'; + case 45: return 'x'; + case 21: return 'y'; + case 44: return 'z'; + + case 39: return 59; //; + case 40: return 39; //' + case 51: return 44; //, + case 52: return 46; //. + case 53: return 47; // / + + case 328: return 273; //arrow keys: up + case 331: return 276; //arrow keys: left + case 333: return 275; //arrow keys: right + case 336: return 274; //arrow keys: down +//STOPPED HERE + case 29: return 162; //left ctrl + case 347: return 91; //left super (aka win) + case 64: return 164; //left alt + case 57: return 32; //space bar + case 108: return 165; //right alt + case 134: return 91; //right super (aka win) + case 349: return 93; //menu + case 285: return 268; //right control + + case 107: return 316; //Print Screen + //case 78: scroll lock + case 127: return 19; //Pause + case 118: return 277; //Insert + case 110: return 278; //Home + case 112: return 280; //Page Up + case 119: return 127; //Delete + case 115: return 279; //End + case 117: return 181; //Page Down + + //case 77: Num Lock (not mapped) + case 106: return 267; //Keypad / + case 63: return 268; //Keypad * + case 82: return 269; //Keypad - + case 79: return 263; //Keypad 7 + case 80: return 264; //Keypad 8 + case 81: return 265; //Keypad 9 + case 86: return 270; //Keypad + + case 83: return 260; //Keypad 4 + case 84: return 261; //Keypad 5 + case 85: return 262; //Keypad 6 +// case 87: return 257; //Keypad 1 +// case 88: return 258; //Keypad 2 + case 89: return 259; //Keypad 3 +// case 36: //Enter + case 104: return 13; //Keypad enter + case 90: return 260; //Keypad 0 + case 91: return 266; //Keypad . + + default: + // numbers + if( scanin >= 10 && scanin <= 18 ) + return scanin + ( (short)'1' - 10 ); + // f1 -- f10 + if( scanin >= 67 && scanin <= 76 ) + return scanin + ( 282 - 67 ); + return scanin; + } +} + LRESULT CALLBACK WindowCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) Modified: Mercury2/src/Win32Window.h =================================================================== --- Mercury2/src/Win32Window.h 2009-12-21 19:10:26 UTC (rev 630) +++ Mercury2/src/Win32Window.h 2009-12-21 20:08:27 UTC (rev 631) @@ -17,8 +17,11 @@ static MercuryWindow* GenWin32Window(); virtual void* GetProcAddress(const MString& x); virtual void Clear(); + static short ConvertScancode( uint32_t scanin ); private: + bool IsKeyRepeat(uint32_t c); + void GenWindow(); void GenWinClass(); void SetPixelType(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-12-22 16:08:59
|
Revision: 632 http://hgengine.svn.sourceforge.net/hgengine/?rev=632&view=rev Author: axlecrusher Date: 2009-12-22 16:08:48 +0000 (Tue, 22 Dec 2009) Log Message: ----------- add windows mouse handling Modified Paths: -------------- Mercury2/src/MercuryWindow.cpp Mercury2/src/MercuryWindow.h Mercury2/src/Win32Window.cpp Mercury2/src/Win32Window.h Mercury2/src/X11Window.cpp Mercury2/src/X11Window.h Modified: Mercury2/src/MercuryWindow.cpp =================================================================== --- Mercury2/src/MercuryWindow.cpp 2009-12-21 20:08:27 UTC (rev 631) +++ Mercury2/src/MercuryWindow.cpp 2009-12-22 16:08:48 UTC (rev 632) @@ -2,7 +2,7 @@ MercuryWindow::MercuryWindow(const MString& title, int width, int height, int bits, int depthBits, bool fullscreen) :m_title(title), m_width(width), m_height(height), m_bits(bits), m_depthBits(depthBits), m_fullscreen(fullscreen), - m_bGrabbed(true) + m_bGrabbed(true),m_iLastMouseX(0),m_iLastMouseY(0),m_inFocus(false) { } Modified: Mercury2/src/MercuryWindow.h =================================================================== --- Mercury2/src/MercuryWindow.h 2009-12-21 20:08:27 UTC (rev 631) +++ Mercury2/src/MercuryWindow.h 2009-12-22 16:08:48 UTC (rev 632) @@ -34,6 +34,9 @@ void SetGrabbedMouseMode( bool bGrabbed ) { m_bGrabbed = bGrabbed; } bool GetGrabbedMouseMode( ) { return m_bGrabbed; } + + inline bool InFocus() const { return m_inFocus; } + protected: static Callback0R< MercuryWindow* > genWindowClbk; static MercuryWindow* m_windowInstance; @@ -43,6 +46,11 @@ uint8_t m_bits, m_depthBits; bool m_fullscreen; bool m_bGrabbed; + + int m_iLastMouseX; + int m_iLastMouseY; + + bool m_inFocus; }; #endif Modified: Mercury2/src/Win32Window.cpp =================================================================== --- Mercury2/src/Win32Window.cpp 2009-12-21 20:08:27 UTC (rev 631) +++ Mercury2/src/Win32Window.cpp 2009-12-22 16:08:48 UTC (rev 632) @@ -1,9 +1,11 @@ #include <Win32Window.h> +//#include <Windowsx.h> #include <GLHeaders.h> -#include <MercuryInput.h> +#include <MercuryInput.h> LRESULT CALLBACK WindowCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam); //Window callback Callback0R< MercuryWindow* > MercuryWindow::genWindowClbk(Win32Window::GenWin32Window); //Register window generation callback +bool ACTIVE = false; MercuryWindow* Win32Window::GenWin32Window() { @@ -20,8 +22,8 @@ } Win32Window::Win32Window(const MString& title, int width, int height, int bits, int depthBits, bool fullscreen) - :m_hwnd(NULL), m_hdc(NULL), m_hglrc(NULL), m_hInstance(NULL), m_className(NULL), m_windowAtom(NULL), m_winTitle(NULL), - MercuryWindow(title, width, height, bits, depthBits, fullscreen) + :m_hwnd(NULL), m_hdc(NULL), m_hglrc(NULL), m_hInstance(NULL), m_className(NULL), m_windowAtom(NULL), m_winTitle(NULL),m_cX(0), + m_cY(0),MercuryWindow(title, width, height, bits, depthBits, fullscreen) { m_className = (WCHAR*)StringToLPCTSTR("Mercury Render Window"); m_winTitle = (WCHAR*)StringToLPCTSTR(title); @@ -191,44 +193,62 @@ { MSG message; + if ( InFocus() != ACTIVE ) + { + m_inFocus = ACTIVE; + ShowCursor(!m_inFocus); + PointerToCenter(); + } + while (PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) { - switch( message.message ) + if ( InFocus() ) { - case WM_QUIT: - return false; - case WM_KEYDOWN: + switch( message.message ) { - if ( IsKeyRepeat(message.lParam) ) break; -// printf( "%d\n", message.lParam>>16 ); - KeyboardInput::ProcessKeyInput( ConvertScancode( message.lParam ), true, false); - } - break; - case WM_KEYUP: - { - if ( IsKeyRepeat(message.lParam) ) break; -// printf( "%d\n", message.lParam>>16 ); - KeyboardInput::ProcessKeyInput( ConvertScancode( message.lParam ), false, false); - } - break; - case WM_MOUSEMOVE: - break; - case WM_LBUTTONDOWN: - break; - case WM_LBUTTONUP: - break; - case WM_RBUTTONDOWN: - break; - case WM_RBUTTONUP: - break; - case WM_MBUTTONDOWN: - break; - case WM_MBUTTONUP: - break; - case 0x020A: //Do nothing (at least now) It's a mouse wheel! - break; + case WM_KEYDOWN: + { + if ( IsKeyRepeat(message.lParam) ) break; + KeyboardInput::ProcessKeyInput( ConvertScancode( message.lParam ), true, false); + } + break; + case WM_KEYUP: + { + if ( IsKeyRepeat(message.lParam) ) break; + KeyboardInput::ProcessKeyInput( ConvertScancode( message.lParam ), false, false); + } + break; + case WM_MOUSEMOVE: + { + POINT pos; + GetCursorPos(&pos); + if (pos.x!=m_cX || pos.y!=m_cY) //ignore the resets to center + { + int dx = m_cX - pos.x; + int dy = m_cY - pos.y; + m_iLastMouseX += dx; + m_iLastMouseY += dy; + MouseInput::ProcessMouseInput(dx, dy, message.wParam&MK_LBUTTON, message.wParam&MK_RBUTTON, message.wParam&MK_MBUTTON, 0, 0); + PointerToCenter(); + } + } + break; + case WM_LBUTTONDOWN: + break; + case WM_LBUTTONUP: + break; + case WM_RBUTTONDOWN: + break; + case WM_RBUTTONUP: + break; + case WM_MBUTTONDOWN: + break; + case WM_MBUTTONUP: + break; + case 0x020A: //Do nothing (at least now) It's a mouse wheel! + break; + } } - TranslateMessage(&message); // Translate The Message DispatchMessage(&message); // Dispatch The Message } @@ -246,127 +266,139 @@ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); } -bool Win32Window::IsKeyRepeat(uint32_t c) -{ -// printf("count %d\n", (c&65535)); - return (c&65535) > 1; -} +bool Win32Window::IsKeyRepeat(uint32_t c) +{ +// printf("count %d\n", (c&65535)); + return (c&65535) > 1; +} -short Win32Window::ConvertScancode( uint32_t scanin ) -{ -// Specifies the scan code. The value depends on the OEM. - scanin = (scanin>>16)&511; - switch( scanin ) - { - case 1: return 27; //esc - case 0: return '0'; - case 41: return 97; //` - case 14: return 8; //backspace - case 87: return 292; //F11 - case 88: return 293; //F12 - case 12: return 45; //- - case 13: return 61; //= - case 43: return 92; //backslash - case 15: return 9; //tab - case 58: return 15; //Caps lock - case 42: return 160; //[lshift] - case 54: return 161; //[rshift] - - case 30: return 'a'; - case 48: return 'b'; - case 46: return 'c'; - case 32: return 'd'; - case 18: return 'e'; - case 33: return 'f'; - case 34: return 'g'; - case 35: return 'h'; - case 23: return 'i'; - case 36: return 'j'; - case 37: return 'k'; - case 38: return 'l'; - case 50: return 'm'; - case 49: return 'n'; - case 24: return 'o'; - case 25: return 'p'; - case 16: return 'q'; - case 19: return 'r'; - case 31: return 's'; - case 20: return 't'; - case 22: return 'u'; - case 47: return 'v'; - case 17: return 'w'; - case 45: return 'x'; - case 21: return 'y'; - case 44: return 'z'; - - case 39: return 59; //; - case 40: return 39; //' - case 51: return 44; //, - case 52: return 46; //. - case 53: return 47; // / - - case 328: return 273; //arrow keys: up - case 331: return 276; //arrow keys: left - case 333: return 275; //arrow keys: right - case 336: return 274; //arrow keys: down -//STOPPED HERE - case 29: return 162; //left ctrl - case 347: return 91; //left super (aka win) - case 64: return 164; //left alt - case 57: return 32; //space bar - case 108: return 165; //right alt - case 134: return 91; //right super (aka win) - case 349: return 93; //menu - case 285: return 268; //right control - - case 107: return 316; //Print Screen - //case 78: scroll lock - case 127: return 19; //Pause - case 118: return 277; //Insert - case 110: return 278; //Home - case 112: return 280; //Page Up - case 119: return 127; //Delete - case 115: return 279; //End - case 117: return 181; //Page Down - - //case 77: Num Lock (not mapped) - case 106: return 267; //Keypad / - case 63: return 268; //Keypad * - case 82: return 269; //Keypad - - case 79: return 263; //Keypad 7 - case 80: return 264; //Keypad 8 - case 81: return 265; //Keypad 9 - case 86: return 270; //Keypad + - case 83: return 260; //Keypad 4 - case 84: return 261; //Keypad 5 - case 85: return 262; //Keypad 6 -// case 87: return 257; //Keypad 1 -// case 88: return 258; //Keypad 2 - case 89: return 259; //Keypad 3 -// case 36: //Enter - case 104: return 13; //Keypad enter - case 90: return 260; //Keypad 0 - case 91: return 266; //Keypad . - - default: - // numbers - if( scanin >= 10 && scanin <= 18 ) - return scanin + ( (short)'1' - 10 ); - // f1 -- f10 - if( scanin >= 67 && scanin <= 76 ) - return scanin + ( 282 - 67 ); - return scanin; - } +void Win32Window::PointerToCenter() +{ + RECT rect; + GetWindowRect(m_hwnd, &rect); + m_cX = rect.left+m_width/2; + m_cY = rect.top+m_height/2; + SetCursorPos(m_cX, m_cY); } +short Win32Window::ConvertScancode( uint32_t scanin ) +{ +// Specifies the scan code. The value depends on the OEM. + scanin = (scanin>>16)&511; + switch( scanin ) + { + case 1: return 27; //esc + case 0: return '0'; + case 41: return 97; //` + case 14: return 8; //backspace + case 87: return 292; //F11 + case 88: return 293; //F12 + case 12: return 45; //- + case 13: return 61; //= + case 43: return 92; //backslash + case 15: return 9; //tab + case 58: return 15; //Caps lock + case 42: return 160; //[lshift] + case 54: return 161; //[rshift] + + case 30: return 'a'; + case 48: return 'b'; + case 46: return 'c'; + case 32: return 'd'; + case 18: return 'e'; + case 33: return 'f'; + case 34: return 'g'; + case 35: return 'h'; + case 23: return 'i'; + case 36: return 'j'; + case 37: return 'k'; + case 38: return 'l'; + case 50: return 'm'; + case 49: return 'n'; + case 24: return 'o'; + case 25: return 'p'; + case 16: return 'q'; + case 19: return 'r'; + case 31: return 's'; + case 20: return 't'; + case 22: return 'u'; + case 47: return 'v'; + case 17: return 'w'; + case 45: return 'x'; + case 21: return 'y'; + case 44: return 'z'; + + case 39: return 59; //; + case 40: return 39; //' + case 51: return 44; //, + case 52: return 46; //. + case 53: return 47; // / + + case 328: return 273; //arrow keys: up + case 331: return 276; //arrow keys: left + case 333: return 275; //arrow keys: right + case 336: return 274; //arrow keys: down +//STOPPED HERE + case 29: return 162; //left ctrl + case 347: return 91; //left super (aka win) + case 64: return 164; //left alt + case 57: return 32; //space bar + case 108: return 165; //right alt + case 134: return 91; //right super (aka win) + case 349: return 93; //menu + case 285: return 268; //right control + + case 107: return 316; //Print Screen + //case 78: scroll lock + case 127: return 19; //Pause + case 118: return 277; //Insert + case 110: return 278; //Home + case 112: return 280; //Page Up + case 119: return 127; //Delete + case 115: return 279; //End + case 117: return 181; //Page Down + + //case 77: Num Lock (not mapped) + case 106: return 267; //Keypad / + case 63: return 268; //Keypad * + case 82: return 269; //Keypad - + case 79: return 263; //Keypad 7 + case 80: return 264; //Keypad 8 + case 81: return 265; //Keypad 9 + case 86: return 270; //Keypad + + case 83: return 260; //Keypad 4 + case 84: return 261; //Keypad 5 + case 85: return 262; //Keypad 6 +// case 87: return 257; //Keypad 1 +// case 88: return 258; //Keypad 2 + case 89: return 259; //Keypad 3 +// case 36: //Enter + case 104: return 13; //Keypad enter + case 90: return 260; //Keypad 0 + case 91: return 266; //Keypad . + + default: + // numbers + if( scanin >= 10 && scanin <= 18 ) + return scanin + ( (short)'1' - 10 ); + // f1 -- f10 + if( scanin >= 67 && scanin <= 76 ) + return scanin + ( 282 - 67 ); + return scanin; + } +} + LRESULT CALLBACK WindowCallback(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_CLOSE: - { - exit(1); - } + exit(1); + break; + case WM_ACTIVATE: + ACTIVE = LOWORD(wParam)!=WA_INACTIVE; +// return 0; + break; } return DefWindowProc(hWnd,uMsg,wParam,lParam); } Modified: Mercury2/src/Win32Window.h =================================================================== --- Mercury2/src/Win32Window.h 2009-12-21 20:08:27 UTC (rev 631) +++ Mercury2/src/Win32Window.h 2009-12-22 16:08:48 UTC (rev 632) @@ -17,17 +17,19 @@ static MercuryWindow* GenWin32Window(); virtual void* GetProcAddress(const MString& x); virtual void Clear(); - static short ConvertScancode( uint32_t scanin ); + static short ConvertScancode( uint32_t scanin ); private: - bool IsKeyRepeat(uint32_t c); - + bool IsKeyRepeat(uint32_t c); + void GenWindow(); void GenWinClass(); void SetPixelType(); void CreateRenderingContext(); void GenPixelType(); + void PointerToCenter(); + HWND m_hwnd; //window handle HDC m_hdc; //device handle PIXELFORMATDESCRIPTOR m_pfd; //pixel format descriptor @@ -40,6 +42,8 @@ MScopedArray< WCHAR > m_className; MScopedArray< WCHAR > m_winTitle; + + uint16_t m_cX, m_cY; }; #endif Modified: Mercury2/src/X11Window.cpp =================================================================== --- Mercury2/src/X11Window.cpp 2009-12-21 20:08:27 UTC (rev 631) +++ Mercury2/src/X11Window.cpp 2009-12-22 16:08:48 UTC (rev 632) @@ -231,7 +231,7 @@ bool X11Window::PumpMessages() { - static bool inFocus = false; +// static bool inFocus = false; XEvent event; while ( XPending(m_display) > 0) { @@ -265,14 +265,14 @@ case FocusOut: { //XFocusChangeEvent*e = (XFocusChangeEvent*)&event; - inFocus = (event.type == FocusIn); - if (inFocus && m_bGrabbed ) XWarpPointer(m_display, None, m_window, 0,0,0,0,m_width/2,m_height/2); + m_inFocus = (event.type == FocusIn); + if (m_inFocus && m_bGrabbed ) XWarpPointer(m_display, None, m_window, 0,0,0,0,m_width/2,m_height/2); break; } } //The events below only get processed if window is in focus - if ( !inFocus ) continue; + if ( !m_inFocus ) continue; switch (event.type) { case ButtonPress: Modified: Mercury2/src/X11Window.h =================================================================== --- Mercury2/src/X11Window.h 2009-12-21 20:08:27 UTC (rev 631) +++ Mercury2/src/X11Window.h 2009-12-22 16:08:48 UTC (rev 632) @@ -28,9 +28,6 @@ GLXContext m_renderCtx; Window m_window; Atom m_wmDeleteMessage; - - int m_iLastMouseX; - int m_iLastMouseY; }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-12-24 17:58:18
|
Revision: 635 http://hgengine.svn.sourceforge.net/hgengine/?rev=635&view=rev Author: axlecrusher Date: 2009-12-24 17:58:11 +0000 (Thu, 24 Dec 2009) Log Message: ----------- ability to specify different UV offset Modified Paths: -------------- Mercury2/src/MercuryVBO.cpp Mercury2/src/Texture.cpp Mercury2/src/Texture.h Modified: Mercury2/src/MercuryVBO.cpp =================================================================== --- Mercury2/src/MercuryVBO.cpp 2009-12-23 21:24:26 UTC (rev 634) +++ Mercury2/src/MercuryVBO.cpp 2009-12-24 17:58:11 UTC (rev 635) @@ -49,11 +49,12 @@ ++m_vboBinds; } + GLCALL( glPushAttrib(GL_CURRENT_BIT) ); GLCALL( glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT) ); if (m_useVertexColor) { GLCALL( glEnableClientState( GL_COLOR_ARRAY ) ); } - Texture::ApplyActiveTextures(STRIDE*sizeof(float)); + Texture::ApplyActiveTextures(STRIDE*sizeof(float), 0); GLCALL( glEnableClientState( GL_NORMAL_ARRAY ) ); GLCALL( glNormalPointer(GL_FLOAT, STRIDE*sizeof(float), BUFFER_OFFSET(sizeof(float)*2)) ); @@ -64,6 +65,7 @@ if (m_boundingVolume && SHOWBOUNDINGVOLUME) m_boundingVolume->Render(); GLCALL( glPopClientAttrib() ); + GLCALL( glPopAttrib() ); if ( SHOWAXISES ) DrawAxes(); } @@ -118,8 +120,8 @@ } void* MercuryVBO::m_lastVBOrendered = NULL; -uint32_t MercuryVBO::m_vboBatches; -uint32_t MercuryVBO::m_vboBinds; +uint32_t MercuryVBO::m_vboBatches = 0; +uint32_t MercuryVBO::m_vboBinds = 0; /**************************************************************************** * Copyright (C) 2008 by Joshua Allen * Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2009-12-23 21:24:26 UTC (rev 634) +++ Mercury2/src/Texture.cpp 2009-12-24 17:58:11 UTC (rev 635) @@ -217,13 +217,13 @@ GLERRORCHECK; } -void Texture::ApplyActiveTextures(uint16_t stride) +void Texture::ApplyActiveTextures(uint16_t stride, uint8_t uvByteOffset) { for (uint8_t i = 0; i < m_numActiveTextures; ++i) { GLCALL( glActiveTexture( GL_TEXTURE0+i ) ); GLCALL( glClientActiveTextureARB(GL_TEXTURE0+i) ); - GLCALL( glTexCoordPointer(2, GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*0)) ); + GLCALL( glTexCoordPointer(2, GL_FLOAT, stride, BUFFER_OFFSET(uvByteOffset)) ); } Texture::DisableUnusedTextures(); Modified: Mercury2/src/Texture.h =================================================================== --- Mercury2/src/Texture.h 2009-12-23 21:24:26 UTC (rev 634) +++ Mercury2/src/Texture.h 2009-12-24 17:58:11 UTC (rev 635) @@ -43,7 +43,7 @@ void SetRawData(RawImageData* raw); - static void ApplyActiveTextures(uint16_t stride); + static void ApplyActiveTextures(uint16_t stride, uint8_t uvByteOffset); static void DisableUnusedTextures(); void SetFilter( TextureFilterMode t ) { m_tFilterMode = t; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-12-24 19:31:58
|
Revision: 640 http://hgengine.svn.sourceforge.net/hgengine/?rev=640&view=rev Author: axlecrusher Date: 2009-12-24 19:31:48 +0000 (Thu, 24 Dec 2009) Log Message: ----------- more accurate vbo stats Modified Paths: -------------- Mercury2/src/BoundingBox.cpp Mercury2/src/MercuryVBO.cpp Mercury2/src/MercuryVBO.h Modified: Mercury2/src/BoundingBox.cpp =================================================================== --- Mercury2/src/BoundingBox.cpp 2009-12-24 18:11:56 UTC (rev 639) +++ Mercury2/src/BoundingBox.cpp 2009-12-24 19:31:48 UTC (rev 640) @@ -155,9 +155,9 @@ if (m_vboID == 0) InitVBO(); - if ( MercuryVBO::m_lastVBOrendered != &m_vboID ) + if ( MercuryVBO::GetLastRendered() != &m_vboID ) { - MercuryVBO::m_lastVBOrendered = &m_vboID; + MercuryVBO::SetLastRendered( &m_vboID ); GLCALL( glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_vboID) ); // once GLCALL( glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0) ); // once GLCALL( glVertexPointer(3, GL_FLOAT, 0, 0) ); // once @@ -170,7 +170,7 @@ GLCALL( glDepthMask(GL_FALSE) ); GLCALL( glDrawArrays(GL_QUADS, 0, 24) ); - + MercuryVBO::IncrementBatches(); GLCALL( glEndQueryARB(GL_SAMPLES_PASSED_ARB) ); // GLCALL( glGetQueryObjectuivARB(q, GL_QUERY_RESULT_ARB, &samples) ); @@ -189,15 +189,16 @@ if (m_vboID == 0) InitVBO(); -// if ( MercuryVBO::m_lastVBOrendered != &m_vboID ) +// if ( MercuryVBO::GetLastRendered() != &m_vboID ) { - MercuryVBO::m_lastVBOrendered = &m_vboID; + MercuryVBO::SetLastRendered( &m_vboID ); GLCALL( glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_vboID) ); // once GLCALL( glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0) ); // once GLCALL( glVertexPointer(3, GL_FLOAT, 0, 0) ); // once } GLCALL( glDrawArrays(GL_QUADS, 0, 24) ); + MercuryVBO::IncrementBatches(); GLCALL( glPopMatrix() ); } Modified: Mercury2/src/MercuryVBO.cpp =================================================================== --- Mercury2/src/MercuryVBO.cpp 2009-12-24 18:11:56 UTC (rev 639) +++ Mercury2/src/MercuryVBO.cpp 2009-12-24 19:31:48 UTC (rev 640) @@ -28,9 +28,9 @@ if ( !m_initiated ) InitVBO(); - if ( this != m_lastVBOrendered ) + if ( this != GetLastRendered() ) { - m_lastVBOrendered = this; + SetLastRendered(this); if ( m_bDirtyVertices ) UpdateVertices(); if( m_bDirtyIndices ) UpdateIndices(); @@ -60,7 +60,7 @@ 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) ); - ++m_vboBatches; + IncrementBatches(); if (m_boundingVolume && SHOWBOUNDINGVOLUME) m_boundingVolume->Render(); @@ -119,6 +119,12 @@ m_indexData.Allocate(count); } +void MercuryVBO::SetLastRendered(void* p) +{ + m_lastVBOrendered = p; + ++m_vboBinds; +} + void* MercuryVBO::m_lastVBOrendered = NULL; uint32_t MercuryVBO::m_vboBatches = 0; uint32_t MercuryVBO::m_vboBinds = 0; Modified: Mercury2/src/MercuryVBO.h =================================================================== --- Mercury2/src/MercuryVBO.h 2009-12-24 18:11:56 UTC (rev 639) +++ Mercury2/src/MercuryVBO.h 2009-12-24 19:31:48 UTC (rev 640) @@ -36,15 +36,19 @@ inline uint16_t IndiceCount() const { return m_indexData.Length(); } - static void* m_lastVBOrendered; inline void DirtyVertices() { m_bDirtyVertices = true; } inline void DirtyVerexColor() { m_bDirtyVertexColor = true; } inline void DirtyIndices() { m_bDirtyIndices = true; } + + static void SetLastRendered(void* p); + inline static const void* GetLastRendered() { return m_lastVBOrendered; } + inline static void IncrementBatches() { ++m_vboBatches; } GENRTTI( MercuryVBO ); private: virtual void InitVBO(); + static void* m_lastVBOrendered; unsigned int m_bufferIDs[3]; bool m_initiated; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |