|
From: <axl...@us...> - 2009-05-16 03:55:11
|
Revision: 256
http://hgengine.svn.sourceforge.net/hgengine/?rev=256&view=rev
Author: axlecrusher
Date: 2009-05-16 03:54:59 +0000 (Sat, 16 May 2009)
Log Message:
-----------
remove unneeded
Modified Paths:
--------------
Mercury2/src/Frustum.cpp
Mercury2/src/Frustum.h
Mercury2/src/Viewport.cpp
Modified: Mercury2/src/Frustum.cpp
===================================================================
--- Mercury2/src/Frustum.cpp 2009-05-16 03:46:27 UTC (rev 255)
+++ Mercury2/src/Frustum.cpp 2009-05-16 03:54:59 UTC (rev 256)
@@ -55,9 +55,6 @@
//Right now this only builds the frustum planes
MercuryVector X,Y,Z;
- m_lookAt = look;
- m_eye = eye;
-
Z = (eye - look).Normalize(); //direction behind camera
X = (up.CrossProduct(Z)).Normalize(); //X axis
Y = Z.CrossProduct( X ); //real up
Modified: Mercury2/src/Frustum.h
===================================================================
--- Mercury2/src/Frustum.h 2009-05-16 03:46:27 UTC (rev 255)
+++ Mercury2/src/Frustum.h 2009-05-16 03:54:59 UTC (rev 256)
@@ -24,8 +24,6 @@
void LookAt(const MercuryVertex& eye, const MercuryVector& look, const MercuryVector& up);
inline const MercuryPlane& GetPlane(int i) const { return m_planes[i]; }
- inline const MercuryVertex& GetLookAt() const { return m_lookAt; }
- inline const MercuryVertex& GetEye() const { return m_eye; }
private:
MercuryPlane m_planes[6];
@@ -35,8 +33,6 @@
float m_nh, m_nw, m_fh, m_fw;
MercuryVector m_nc, m_fc;
- MercuryVertex m_lookAt;
- MercuryVertex m_eye;
};
#endif
Modified: Mercury2/src/Viewport.cpp
===================================================================
--- Mercury2/src/Viewport.cpp 2009-05-16 03:46:27 UTC (rev 255)
+++ Mercury2/src/Viewport.cpp 2009-05-16 03:54:59 UTC (rev 256)
@@ -35,7 +35,7 @@
EYE[2] = matrix[2][3]; // same as float* [11]
EYE *= -1;
- MercuryVector l(0,0,1,1);
+ MercuryVector l(0,0,1);
LOOKAT = (matrix * l).Normalize();
// LOOKAT.Print();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-05-31 04:13:25
|
Revision: 286
http://hgengine.svn.sourceforge.net/hgengine/?rev=286&view=rev
Author: axlecrusher
Date: 2009-05-31 04:13:24 +0000 (Sun, 31 May 2009)
Log Message:
-----------
Move vector rotate out of quaternion into vertex
Modified Paths:
--------------
Mercury2/src/MQuaternion.cpp
Mercury2/src/MQuaternion.h
Mercury2/src/MercuryVertex.cpp
Mercury2/src/MercuryVertex.h
Modified: Mercury2/src/MQuaternion.cpp
===================================================================
--- Mercury2/src/MQuaternion.cpp 2009-05-31 04:04:35 UTC (rev 285)
+++ Mercury2/src/MQuaternion.cpp 2009-05-31 04:13:24 UTC (rev 286)
@@ -245,12 +245,6 @@
printf("%s: %f %f %f %f\n", s.c_str(), m_wxyz[0], m_wxyz[1], m_wxyz[2], m_wxyz[3]);
}
-MercuryVector MQuaternion::operator * (const MercuryVector &rhs) const
-{
- return (*this * MQuaternion(0, rhs) * reciprocal()).ToVector();
-}
-
-
//Returns the Euclidian Inner Product of two MQuaternions (Similar to Vector Dot-Product)
float innerProduct(const MQuaternion & a, const MQuaternion &b)
{
Modified: Mercury2/src/MQuaternion.h
===================================================================
--- Mercury2/src/MQuaternion.h 2009-05-31 04:04:35 UTC (rev 285)
+++ Mercury2/src/MQuaternion.h 2009-05-31 04:13:24 UTC (rev 286)
@@ -61,8 +61,6 @@
MQuaternion& operator *= (const float &rhs);
MQuaternion& operator /= (const float &rhs);
- MercuryVector operator * (const MercuryVector &rhs) const;
-
bool operator==(const MQuaternion &rhs) const;
inline bool operator!=(const MQuaternion &rhs) const { return !(*this == rhs); }
Modified: Mercury2/src/MercuryVertex.cpp
===================================================================
--- Mercury2/src/MercuryVertex.cpp 2009-05-31 04:04:35 UTC (rev 285)
+++ Mercury2/src/MercuryVertex.cpp 2009-05-31 04:13:24 UTC (rev 286)
@@ -1,6 +1,7 @@
#include <MercuryVertex.h>
#include <MercuryUtil.h>
#include <MercuryMath.h>
+#include <MQuaternion.h>
MercuryVertex::MercuryVertex()
{
@@ -115,8 +116,11 @@
printf("%s: %f %f %f %f\n", s.c_str(), (*this)[0], (*this)[1], (*this)[2], (*this)[3]);
}
+MercuryVertex MercuryVertex::Rotate(const MQuaternion& q) const
+{
+ return (q * MQuaternion(0, *this) * q.reciprocal()).ToVector();
+}
-
/****************************************************************************
* Copyright (C) 2009 by Joshua Allen *
* *
Modified: Mercury2/src/MercuryVertex.h
===================================================================
--- Mercury2/src/MercuryVertex.h 2009-05-31 04:04:35 UTC (rev 285)
+++ Mercury2/src/MercuryVertex.h 2009-05-31 04:13:24 UTC (rev 286)
@@ -10,6 +10,8 @@
#define __inline__ inline
#endif
+class MQuaternion;
+
class MercuryVertex
{
public:
@@ -79,6 +81,8 @@
MercuryVertex DotProduct3(const MercuryVertex& rhs1, const MercuryVertex& rhs2, const MercuryVertex& rhs3) const;
void Print(const MString& s = "Vertex") const;
+
+ MercuryVertex Rotate(const MQuaternion& q) const;
// float (*this)[3];
FloatRow m_xyzw;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-05-31 04:28:57
|
Revision: 291
http://hgengine.svn.sourceforge.net/hgengine/?rev=291&view=rev
Author: axlecrusher
Date: 2009-05-31 04:28:19 +0000 (Sun, 31 May 2009)
Log Message:
-----------
still working on the camera
Modified Paths:
--------------
Mercury2/src/Camera.cpp
Mercury2/src/Camera.h
Modified: Mercury2/src/Camera.cpp
===================================================================
--- Mercury2/src/Camera.cpp 2009-05-31 04:27:34 UTC (rev 290)
+++ Mercury2/src/Camera.cpp 2009-05-31 04:28:19 UTC (rev 291)
@@ -18,10 +18,10 @@
MercuryMatrix local;
- m_lookAt = GetRotation() * MQuaternion(1, MercuryVector(0,0,1) ) * GetRotation().reciprocal();
- m_lookAt.Print();
+// m_lookAt = GetRotation() * MercuryVector(0,0,1);
+// m_lookAt.Print();
- AngleMatrix( GetRotation().ToVertex()*-1, local);
+ AngleMatrix( GetRotation().ToVector()*-1, local);
local.Translate( GetPosition()*-1 );
m_globalMatrix = GetParentMatrix() * local;
@@ -36,9 +36,19 @@
// MercuryVertex r;
// MQuaternion rot, d(0,0,1,0);
- MQuaternion r = GetRotation();
- r[MQuaternion::X] += m->dy/30.0f;
- r[MQuaternion::Y] += m->dx/30.0f;
+ MQuaternion qx = MQuaternion::CreateFromAxisAngle(MercuryVector(1,0,0), m->dy/10.0f);
+ MQuaternion qy = MQuaternion::CreateFromAxisAngle(MercuryVector(0,1,0), m->dx/10.0f);
+
+ MQuaternion rot = GetRotation();
+ rot *= (qx * qy).normalize();
+// rot[MQuaternion::W]=0;
+// rot.CreateFromAxisAngle(r,1);
+// rot = GetRotation() * rot;
+// rot = rot.normalize();
+ rot.Print();
+// MQuaternion r = GetRotation();
+// r[MQuaternion::X] += m->dy/30.0f;
+// r[MQuaternion::Y] += m->dx/30.0f;
// r = r.normalize();
// r = r * m_lookAt * r.reciprocal();
@@ -49,7 +59,7 @@
// r += m_rotation;
// r[3] = 1;
// rot.SetEuler( r );
- SetRotation(r);
+ SetRotation(rot);
}
if (message == INPUTEVENT_KEYBOARD)
{
Modified: Mercury2/src/Camera.h
===================================================================
--- Mercury2/src/Camera.h 2009-05-31 04:27:34 UTC (rev 290)
+++ Mercury2/src/Camera.h 2009-05-31 04:28:19 UTC (rev 291)
@@ -14,7 +14,7 @@
GENRTTI(CameraNode);
private:
- MQuaternion m_lookAt;
+ MercuryVector m_lookAt;
};
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cn...@us...> - 2009-06-28 21:58:39
|
Revision: 386
http://hgengine.svn.sourceforge.net/hgengine/?rev=386&view=rev
Author: cnlohr
Date: 2009-06-28 21:58:37 +0000 (Sun, 28 Jun 2009)
Log Message:
-----------
cleanup - Actually use Mercury Vector, instead of the crazy #define happenstance.
Modified Paths:
--------------
Mercury2/src/MercuryFile.cpp
Mercury2/src/MercuryFile.h
Mercury2/src/MercuryFileDriverDirect.cpp
Mercury2/src/MercuryFileDriverPacked.cpp
Mercury2/src/MercuryFileDriverZipped.cpp
Modified: Mercury2/src/MercuryFile.cpp
===================================================================
--- Mercury2/src/MercuryFile.cpp 2009-06-28 21:57:18 UTC (rev 385)
+++ Mercury2/src/MercuryFile.cpp 2009-06-28 21:58:37 UTC (rev 386)
@@ -1,5 +1,5 @@
#include "MercuryFile.h"
-
+#include <MercuryVector.h>
#include <MercuryFileDriverDirect.h>
#include <MercuryFileDriverNet.h>
#include <MercuryFileDriverMem.h>
Modified: Mercury2/src/MercuryFile.h
===================================================================
--- Mercury2/src/MercuryFile.h 2009-06-28 21:57:18 UTC (rev 385)
+++ Mercury2/src/MercuryFile.h 2009-06-28 21:58:37 UTC (rev 386)
@@ -4,11 +4,10 @@
#include <MAutoPtr.h>
#include <MercuryUtil.h>
-#include <vector>
+//Forward decleration, as there's no real need to have this included unless we _need_ it.
+template< typename t >
+class MVector;
-//XXX When we write a Mercury Vector, replace this line !!! XXX !!! NOTE
-#define MVector std::vector
-
///File permissions (self-explainatory)
enum FilePermission
{
Modified: Mercury2/src/MercuryFileDriverDirect.cpp
===================================================================
--- Mercury2/src/MercuryFileDriverDirect.cpp 2009-06-28 21:57:18 UTC (rev 385)
+++ Mercury2/src/MercuryFileDriverDirect.cpp 2009-06-28 21:58:37 UTC (rev 386)
@@ -1,4 +1,5 @@
-#include "MercuryFileDriverDirect.h"
+#include <MercuryFileDriverDirect.h>
+#include <MercuryVector.h>
#ifndef WIN32
#include <dirent.h>
Modified: Mercury2/src/MercuryFileDriverPacked.cpp
===================================================================
--- Mercury2/src/MercuryFileDriverPacked.cpp 2009-06-28 21:57:18 UTC (rev 385)
+++ Mercury2/src/MercuryFileDriverPacked.cpp 2009-06-28 21:58:37 UTC (rev 386)
@@ -1,4 +1,5 @@
#include <MercuryFileDriverPacked.h>
+#include <MercuryVector.h>
#include <string.h>
const MString PackagePrefix = "Packages/";
Modified: Mercury2/src/MercuryFileDriverZipped.cpp
===================================================================
--- Mercury2/src/MercuryFileDriverZipped.cpp 2009-06-28 21:57:18 UTC (rev 385)
+++ Mercury2/src/MercuryFileDriverZipped.cpp 2009-06-28 21:58:37 UTC (rev 386)
@@ -1,14 +1,15 @@
#include <MercuryFileDriverZipped.h>
#include <MercuryFileDriverPacked.h>
+#include <MercuryVector.h>
//For the store compression on zips
#include <zlib.h>
#include <string.h>
-#if defined(WIN32)
-# if defined(_MSC_VER)
-# pragma comment(lib, "zdll.lib")
-# endif
+#if defined(WIN32)
+# if defined(_MSC_VER)
+# pragma comment(lib, "zdll.lib")
+# endif
#endif
const MString PackagePrefix = "Packages/";
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-07-05 21:15:50
|
Revision: 409
http://hgengine.svn.sourceforge.net/hgengine/?rev=409&view=rev
Author: axlecrusher
Date: 2009-07-05 21:15:50 +0000 (Sun, 05 Jul 2009)
Log Message:
-----------
commit what I have done before I mess it up
Modified Paths:
--------------
Mercury2/src/BoundingBox.cpp
Mercury2/src/BoundingBox.h
Mercury2/src/HGMDLModel.cpp
Mercury2/src/MercuryAsset.cpp
Mercury2/src/MercuryNode.cpp
Mercury2/src/MercuryNode.h
Modified: Mercury2/src/BoundingBox.cpp
===================================================================
--- Mercury2/src/BoundingBox.cpp 2009-07-05 15:48:11 UTC (rev 408)
+++ Mercury2/src/BoundingBox.cpp 2009-07-05 21:15:50 UTC (rev 409)
@@ -109,13 +109,13 @@
return !inView;
}
-bool BoundingBox::FrustumCull() const
-{
+//bool BoundingBox::FrustumCull() const
+//{
/*feedback in openGL is probably depreciated
and is known to fallback to software
the OcclusionTest provides the same performence
it is probably best to avoid using this function */
-
+/*
static float b[3];
uint32_t samples;
const float* center = GetCenter();
@@ -161,9 +161,18 @@
// return false;
return samples==0;
}
+*/
+bool BoundingBox::DoFrustumTest( const MercuryMatrix& m )
+{
+ BoundingBox bb(*this);
+ bb.Transform( m );
+ return false;
+}
+
void BoundingBox::DoOcclusionTest( OcclusionResult& result )
{
+ return;
const float* center = GetCenter();
const float* extend = GetExtend();
Modified: Mercury2/src/BoundingBox.h
===================================================================
--- Mercury2/src/BoundingBox.h 2009-07-05 15:48:11 UTC (rev 408)
+++ Mercury2/src/BoundingBox.h 2009-07-05 21:15:50 UTC (rev 409)
@@ -42,8 +42,7 @@
virtual bool Clip( const MercuryPlane& p ) = 0;
virtual bool Clip( const Frustum& f ) = 0;
- virtual bool FrustumCull() const = 0; //Do not use
-// virtual bool OcclusionCull() const = 0;
+ virtual bool DoFrustumTest( const MercuryMatrix& m ) = 0;
/** This uses openGL to do an occlusion test in hardware.
The answer is not immediately known, but this can be run on the GPU
@@ -85,8 +84,7 @@
virtual bool Clip( const MercuryPlane& p );
virtual bool Clip( const Frustum& f );
- virtual bool FrustumCull() const; //Do not use
-// virtual bool OcclusionCull() const;
+ virtual bool DoFrustumTest( const MercuryMatrix& m );
virtual void DoOcclusionTest(OcclusionResult& result);
private:
Modified: Mercury2/src/HGMDLModel.cpp
===================================================================
--- Mercury2/src/HGMDLModel.cpp 2009-07-05 15:48:11 UTC (rev 408)
+++ Mercury2/src/HGMDLModel.cpp 2009-07-05 21:15:50 UTC (rev 409)
@@ -71,7 +71,7 @@
{
for(uint16_t i = 0; i < m_meshes.size(); ++i)
{
- if ( !node->GetOcclusionResult().IsOccluded() )
+ if ( !(node->GetOcclusionResult().IsOccluded() || node->IsCulled()) )
m_meshes[i]->Render(node);
}
}
Modified: Mercury2/src/MercuryAsset.cpp
===================================================================
--- Mercury2/src/MercuryAsset.cpp 2009-07-05 15:48:11 UTC (rev 408)
+++ Mercury2/src/MercuryAsset.cpp 2009-07-05 21:15:50 UTC (rev 409)
@@ -41,7 +41,11 @@
{
MercuryNode* n = const_cast<MercuryNode*>(node);
if ( m_boundingVolume )
- m_boundingVolume->DoOcclusionTest( n->GetOcclusionResult() );
+ {
+// n->SetCulled( m_boundingVolume->DoFrustumTest(matrix) );
+ if ( !n->IsCulled() )
+ m_boundingVolume->DoOcclusionTest( n->GetOcclusionResult() );
+ }
}
void MercuryAsset::DrawAxes()
Modified: Mercury2/src/MercuryNode.cpp
===================================================================
--- Mercury2/src/MercuryNode.cpp 2009-07-05 15:48:11 UTC (rev 408)
+++ Mercury2/src/MercuryNode.cpp 2009-07-05 21:15:50 UTC (rev 409)
@@ -14,7 +14,7 @@
REGISTER_NODE_TYPE(MercuryNode);
MercuryNode::MercuryNode()
- :m_parent(NULL), m_prevSibling(NULL), m_nextSibling(NULL), m_hidden(false), m_useAlphaPath(false)
+ :m_parent(NULL), m_prevSibling(NULL), m_nextSibling(NULL), m_hidden(false), m_useAlphaPath(false), m_culled(false)
{
}
@@ -146,7 +146,7 @@
void MercuryNode::RecursiveRender()
{
- if ( IsHidden() || m_occlusionResult.IsOccluded() ) return;
+ if ( IsHidden() || m_occlusionResult.IsOccluded() || IsCulled() ) return;
MercuryMatrix matrix = FindGlobalMatrix();
MercuryMatrix modelView = ManipulateMatrix( matrix );
Modified: Mercury2/src/MercuryNode.h
===================================================================
--- Mercury2/src/MercuryNode.h 2009-07-05 15:48:11 UTC (rev 408)
+++ Mercury2/src/MercuryNode.h 2009-07-05 21:15:50 UTC (rev 409)
@@ -91,8 +91,10 @@
const MercuryMatrix& FindGlobalMatrix() const;
virtual bool IsCulled(const MercuryMatrix& matrix);
- bool IsHidden() { return m_hidden; }
+ inline bool IsHidden() { return m_hidden; }
+ inline void SetCulled(bool t) { m_culled = t; }
+ inline bool IsCulled() const { return m_culled; }
virtual MercuryMatrix ManipulateMatrix(const MercuryMatrix& matrix);
inline OcclusionResult& GetOcclusionResult() { return m_occlusionResult; }
@@ -105,8 +107,10 @@
static bool m_rebuildRenderGraph;
MString m_name;
+
bool m_hidden;
bool m_useAlphaPath;
+ bool m_culled;
private:
bool IsInAssetList(MercuryAsset* asset) const;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cn...@us...> - 2009-07-15 04:23:35
|
Revision: 426
http://hgengine.svn.sourceforge.net/hgengine/?rev=426&view=rev
Author: cnlohr
Date: 2009-07-15 04:23:32 +0000 (Wed, 15 Jul 2009)
Log Message:
-----------
Make the VBO able to dirty Vertices so that they can be updated on the
fly.
Modified Paths:
--------------
Mercury2/src/MercuryVBO.cpp
Mercury2/src/MercuryVBO.h
Modified: Mercury2/src/MercuryVBO.cpp
===================================================================
--- Mercury2/src/MercuryVBO.cpp 2009-07-15 04:23:04 UTC (rev 425)
+++ Mercury2/src/MercuryVBO.cpp 2009-07-15 04:23:32 UTC (rev 426)
@@ -14,6 +14,7 @@
:MercuryAsset(), m_initiated(false)
{
m_bufferIDs[0] = m_bufferIDs[1] = 0;
+ m_bDirtyIndices = m_bDirtyVertices = 0;
}
MercuryVBO::~MercuryVBO()
@@ -27,11 +28,18 @@
uint8_t numTextures = Texture::NumberActiveTextures();
uint16_t stride = sizeof(float)*8;
- if ( !m_initiated ) InitVBO();
-
+ if ( !m_initiated )
+ InitVBO();
+
if ( this != m_lastVBOrendered )
- {
+ {
m_lastVBOrendered = this;
+
+ if ( m_bDirtyVertices )
+ UpdateVertices();
+ if( m_bDirtyIndices )
+ UpdateIndices();
+
glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferIDs[0]);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_bufferIDs[1]);
glVertexPointer(3, GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*5));
@@ -58,21 +66,32 @@
void MercuryVBO::InitVBO()
{
- glGenBuffersARB(2, m_bufferIDs);
-
- //vertex VBO
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferIDs[0]);
- glBufferDataARB(GL_ARRAY_BUFFER_ARB, m_vertexData.LengthInBytes(), m_vertexData.Buffer(), GL_STATIC_DRAW_ARB);
+ if (!m_bufferIDs[0])
+ {
+ glGenBuffersARB(2, m_bufferIDs);
+ }
- //indices VBO
- glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_bufferIDs[1]);
- glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_indexData.LengthInBytes(), m_indexData.Buffer(), GL_STATIC_DRAW_ARB);
-
+ UpdateIndices();
+ UpdateVertices();
glEnableClientState(GL_VERTEX_ARRAY);
m_initiated = true;
}
+void MercuryVBO::UpdateIndices()
+{
+ glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_bufferIDs[1]);
+ glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_indexData.LengthInBytes(), m_indexData.Buffer(), GL_STATIC_DRAW_ARB);
+ m_bDirtyIndices = 0;
+}
+
+void MercuryVBO::UpdateVertices()
+{
+ glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferIDs[0]);
+ glBufferDataARB(GL_ARRAY_BUFFER_ARB, m_vertexData.LengthInBytes(), m_vertexData.Buffer(), GL_STATIC_DRAW_ARB);
+ m_bDirtyVertices = 0;
+}
+
void MercuryVBO::AllocateVertexSpace(unsigned int count)
{
m_vertexData.Allocate(count*8);
Modified: Mercury2/src/MercuryVBO.h
===================================================================
--- Mercury2/src/MercuryVBO.h 2009-07-15 04:23:04 UTC (rev 425)
+++ Mercury2/src/MercuryVBO.h 2009-07-15 04:23:32 UTC (rev 426)
@@ -26,13 +26,20 @@
short unsigned int * GetIndexHandle() { return &m_indexData[0]; }
static void* m_lastVBOrendered;
-
+
+ void DirtyVertices() { m_bDirtyVertices = 1; }
+ void DirtyIndices() { m_bDirtyIndices = 1; }
private:
virtual void InitVBO();
unsigned int m_bufferIDs[2];
- bool m_initiated;
+ bool m_initiated;
+
+ bool m_bDirtyIndices;
+ bool m_bDirtyVertices;
+ void UpdateVertices();
+ void UpdateIndices();
protected:
AlignedBuffer<float> m_vertexData;
AlignedBuffer<uint16_t> m_indexData;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-08-01 14:14:38
|
Revision: 448
http://hgengine.svn.sourceforge.net/hgengine/?rev=448&view=rev
Author: axlecrusher
Date: 2009-08-01 14:14:27 +0000 (Sat, 01 Aug 2009)
Log Message:
-----------
add depth range uniform for shaders
Modified Paths:
--------------
Mercury2/src/Frustum.h
Mercury2/src/Viewport.cpp
Modified: Mercury2/src/Frustum.h
===================================================================
--- Mercury2/src/Frustum.h 2009-08-01 02:46:05 UTC (rev 447)
+++ Mercury2/src/Frustum.h 2009-08-01 14:14:27 UTC (rev 448)
@@ -25,6 +25,9 @@
void Ortho(float left, float right, float bottom, float top, float near, float far);
inline const MercuryPlane& GetPlane(int i) const { return m_planes[i]; }
+ inline float ZNear() const { return m_zNear; }
+ inline float ZFar() const { return m_zFar; }
+ inline float DepthRange() const { return m_zFar - m_zNear; }
private:
MercuryPlane m_planes[6];
Modified: Mercury2/src/Viewport.cpp
===================================================================
--- Mercury2/src/Viewport.cpp 2009-08-01 02:46:05 UTC (rev 447)
+++ Mercury2/src/Viewport.cpp 2009-08-01 14:14:27 UTC (rev 448)
@@ -53,6 +53,13 @@
sa.type = ShaderAttribute::TYPE_INT4;
glGetIntegerv(GL_VIEWPORT, sa.value.iInts);
Shader::SetAttribute("HG_ViewPort", sa);
+
+ sa.type = ShaderAttribute::TYPE_FLOATV4;
+ sa.value.fFloatV4[0] = m_frustum.ZNear();
+ sa.value.fFloatV4[1] = m_frustum.ZFar();
+ sa.value.fFloatV4[2] = m_frustum.DepthRange();
+ sa.value.fFloatV4[3] = 1.0f/m_frustum.DepthRange();
+ Shader::SetAttribute("HG_DepthRange", sa);
}
void Viewport::PostRender(const MercuryMatrix& matrix)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cn...@us...> - 2009-08-11 03:09:02
|
Revision: 473
http://hgengine.svn.sourceforge.net/hgengine/?rev=473&view=rev
Author: cnlohr
Date: 2009-08-11 03:08:53 +0000 (Tue, 11 Aug 2009)
Log Message:
-----------
free up some some protection (temporarily with note) and fix traversal code
Modified Paths:
--------------
Mercury2/src/MercuryNode.cpp
Mercury2/src/MercuryNode.h
Modified: Mercury2/src/MercuryNode.cpp
===================================================================
--- Mercury2/src/MercuryNode.cpp 2009-08-11 03:06:51 UTC (rev 472)
+++ Mercury2/src/MercuryNode.cpp 2009-08-11 03:08:53 UTC (rev 473)
@@ -128,18 +128,25 @@
return ret;
}
-MercuryNode * MercuryNode::TraversalNextNode( MercuryNode * stopnode )
+MercuryNode * MercuryNode::TraversalNextNode( MercuryNode * stopnode, int & iDepthDelta )
{
if( !m_children.empty() )
+ {
+ iDepthDelta++;
return *(m_children.begin());
+ }
else if( m_nextSibling )
return m_nextSibling;
else if( m_parent )
{
MercuryNode * ret = m_parent;
+ iDepthDelta--;
while( ret && ret != stopnode && !ret->m_nextSibling )
+ {
+ iDepthDelta--;
ret = ret->m_parent;
+ }
if( !ret || ret == stopnode )
return 0;
Modified: Mercury2/src/MercuryNode.h
===================================================================
--- Mercury2/src/MercuryNode.h 2009-08-11 03:06:51 UTC (rev 472)
+++ Mercury2/src/MercuryNode.h 2009-08-11 03:08:53 UTC (rev 473)
@@ -55,7 +55,7 @@
///Get the next node in an in-order traversal
/** In the traversal, stopnode indicates the node that when passing
by on returning up the tree haults traversal. */
- MercuryNode * TraversalNextNode( MercuryNode * stopnode );
+ MercuryNode * TraversalNextNode( MercuryNode * stopnode, int & iDepthDelta );
virtual void Update(float dTime) {};
virtual void RecursiveUpdate(float dTime);
@@ -121,7 +121,7 @@
bool m_hidden;
bool m_useAlphaPath;
bool m_culled;
- private:
+ public: //XXX: This will become private sooner or later... It is temporarily public for other work.
bool IsInAssetList(MercuryAsset* asset) const;
OcclusionResult m_occlusionResult;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <cn...@us...> - 2009-10-03 02:34:29
|
Revision: 550
http://hgengine.svn.sourceforge.net/hgengine/?rev=550&view=rev
Author: cnlohr
Date: 2009-10-03 02:34:18 +0000 (Sat, 03 Oct 2009)
Log Message:
-----------
fix copyright notices
Modified Paths:
--------------
Mercury2/src/MercuryNode.cpp
Mercury2/src/MercuryNode.h
Mercury2/src/X11Window.cpp
Mercury2/src/X11Window.h
Modified: Mercury2/src/MercuryNode.cpp
===================================================================
--- Mercury2/src/MercuryNode.cpp 2009-10-02 06:49:36 UTC (rev 549)
+++ Mercury2/src/MercuryNode.cpp 2009-10-03 02:34:18 UTC (rev 550)
@@ -396,27 +396,37 @@
__ThreadLocalStore int g_iViewportID;
__ThreadLocalStore int g_iPass;
+/****************************************************************************
+ * 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. *
+ ***************************************************************************/
-/***************************************************************************
- * Copyright (C) 2008 by Joshua Allen *
- * *
- * *
- * 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 <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. *
- * *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR *
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
- ***************************************************************************/
+
Modified: Mercury2/src/MercuryNode.h
===================================================================
--- Mercury2/src/MercuryNode.h 2009-10-02 06:49:36 UTC (rev 549)
+++ Mercury2/src/MercuryNode.h 2009-10-03 02:34:18 UTC (rev 550)
@@ -175,26 +175,37 @@
#endif
-/***************************************************************************
- * Copyright (C) 2008 by Joshua Allen *
- * *
- * *
- * 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 <ORGANIZATION> 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. *
+/****************************************************************************
+ * 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. *
***************************************************************************/
+
+
Modified: Mercury2/src/X11Window.cpp
===================================================================
--- Mercury2/src/X11Window.cpp 2009-10-02 06:49:36 UTC (rev 549)
+++ Mercury2/src/X11Window.cpp 2009-10-03 02:34:18 UTC (rev 550)
@@ -370,26 +370,36 @@
return NULL;
}
-/***************************************************************************
- * Copyright (C) 2008 by Joshua Allen *
- * *
- * *
- * 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 developers 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. *
+
+/****************************************************************************
+ * Copyright (C) 2008 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
***************************************************************************/
+
Modified: Mercury2/src/X11Window.h
===================================================================
--- Mercury2/src/X11Window.h 2009-10-02 06:49:36 UTC (rev 549)
+++ Mercury2/src/X11Window.h 2009-10-03 02:34:18 UTC (rev 550)
@@ -32,26 +32,36 @@
#endif
-/***************************************************************************
- * Copyright (C) 2008 by Joshua Allen *
- * *
- * *
- * 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 developers 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. *
+/****************************************************************************
+ * Copyright (C) 2008 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
***************************************************************************/
+
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-10-10 22:21:55
|
Revision: 555
http://hgengine.svn.sourceforge.net/hgengine/?rev=555&view=rev
Author: axlecrusher
Date: 2009-10-10 22:21:49 +0000 (Sat, 10 Oct 2009)
Log Message:
-----------
add spatial hash and triangle class
Added Paths:
-----------
Mercury2/src/DataStructures/
Mercury2/src/DataStructures/SpatialHash.h
Mercury2/src/DataTypes/
Mercury2/src/DataTypes/MTriangle.cpp
Mercury2/src/DataTypes/MTriangle.h
Added: Mercury2/src/DataStructures/SpatialHash.h
===================================================================
--- Mercury2/src/DataStructures/SpatialHash.h (rev 0)
+++ Mercury2/src/DataStructures/SpatialHash.h 2009-10-10 22:21:49 UTC (rev 555)
@@ -0,0 +1,127 @@
+#ifndef SPATIALHASH_H
+#define SPATIALHASH_H
+
+#include <stdint.h>
+#include <list>
+#include <math.h>
+
+template<typename T>
+class SpatialHash
+{
+ public:
+ SpatialHash()
+ :m_hashTable(NULL), m_spacing(1.0f)
+ {
+ m_xSize = m_ySize = m_zSize = 0;
+ }
+
+ ~SpatialHash()
+ {
+ DeleteHash();
+ }
+
+ void Allocate(uint32_t xmax, uint32_t ymax, uint32_t zmax, uint32_t spacing)
+ {
+ DeleteHash();
+
+ m_spacing = spacing;
+
+ m_xSize = (abs(xmax)/m_spacing) + 1;
+ m_ySize = (abs(ymax)/m_spacing) + 1;
+ m_zSize = (abs(zmax)/m_spacing) + 1;
+
+ uint32_t size = m_xSize*m_ySize*m_zSize;
+ m_hashTable = new std::list<T>[size];
+ }
+
+ void Insert(float x, float y, float z, const T& d)
+ {
+ unsigned int ix = abs(x) / m_spacing;
+ unsigned int iy = abs(y) / m_spacing;
+ unsigned int iz = abs(z) / m_spacing;
+
+ if (ix >= m_xSize || iy >= m_ySize || iz >= m_zSize)
+ {
+ printf("%d >= %d || %d >= %d || %d >= %d\n", ix, m_xSize, iy, m_ySize, iz, m_zSize);
+ return;
+ }
+
+ //check for and skip duplicate
+ std::list<T>& cell = m_hashTable[ Index( ix, iy, iz ) ];
+ typename std::list<T>::iterator i = cell.begin();
+ for (;i != cell.end(); ++i) if (*i == d) return;
+
+ cell.push_back( d );
+// printf("added at %d %d %d\n", ix, iy, iz);
+ }
+
+ std::list<T> FindByXY(float x, float y)
+ {
+ int ix = x / m_spacing;
+ int iy = y / m_spacing;
+
+ std::list<T> r;
+
+ for (uint32_t iz = 0; iz < m_zSize; ++iz)
+ CopyIntoList(m_hashTable[Index(ix, iy, iz)], r);
+
+ return r;
+ }
+ private:
+ inline uint32_t Index(uint32_t x, uint32_t y, uint32_t z)
+ {
+ return x + (m_xSize * y) + (m_xSize * m_ySize * z);
+ }
+
+ void DeleteHash()
+ {
+ if (m_hashTable) delete[] m_hashTable;
+ m_spacing = 1;
+ m_xSize = m_ySize = m_zSize = 0;
+ }
+
+ void CopyIntoList(std::list<T>& in, std::list<T>& r)
+ {
+ typename std::list<T>::iterator i = in.begin();
+ for (;i != in.end(); ++i) r.push_back(*i);
+ }
+
+ std::list<T>* m_hashTable;
+ uint32_t m_spacing;
+ uint32_t m_xSize, m_ySize, m_zSize;
+};
+
+#endif
+
+
+/****************************************************************************
+ * Copyright (C) 2009 by Joshua Allen *
+ * *
+ * *
+ * 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/DataTypes/MTriangle.cpp
===================================================================
--- Mercury2/src/DataTypes/MTriangle.cpp (rev 0)
+++ Mercury2/src/DataTypes/MTriangle.cpp 2009-10-10 22:21:49 UTC (rev 555)
@@ -0,0 +1,96 @@
+#include <MTriangle.h>
+
+#include <stdio.h>
+
+MTriangle::MTriangle()
+{
+}
+
+MTriangle::MTriangle(const MercuryVertex a, const MercuryVertex& b, const MercuryVertex& c)
+{
+ m_verts[0] = a;
+ m_verts[1] = b;
+ m_verts[2] = c;
+}
+
+MercuryVertex MTriangle::Barycentric(const MercuryVertex& p)
+{
+ MercuryVector v[3];
+ v[0] = m_verts[1] - m_verts[0];
+ v[1] = m_verts[2] - m_verts[0];
+ v[2] = p - m_verts[0];
+
+ float dp[5];
+ dp[0] = v[0].DotProduct(v[0]);
+ dp[1] = v[0].DotProduct(v[1]);
+ dp[2] = v[0].DotProduct(v[2]);
+ dp[3] = v[1].DotProduct(v[1]);
+ dp[4] = v[1].DotProduct(v[2]);
+
+ // Compute barycentric coordinates
+ float invDenom = 1 / (dp[0] * dp[3] - dp[1] * dp[1]);
+ float ru = (dp[3] * dp[2] - dp[1] * dp[4]) * invDenom;
+ float rv = (dp[0] * dp[4] - dp[1] * dp[2]) * invDenom;
+
+ return MercuryVertex(ru, rv, 1-(ru+rv));
+}
+
+bool MTriangle::IsInTriangle(const MercuryVertex& p)
+{
+ MercuryVertex v = Barycentric(p);
+
+ //no edges
+// return (v.GetX() > 0) && (v.GetY() > 0) && (v.GetX() + v.GetY() < 1);
+
+ //includes edges
+ return (v.GetX() >= 0) && (v.GetY() >= 0) && (v.GetX() + v.GetY() <= 1);
+}
+
+float MTriangle::Area()
+{
+ MercuryVector v[2];
+ v[0] = m_verts[1] - m_verts[0];
+ v[1] = m_verts[2] - m_verts[0];
+ MercuryVector r( v[0].CrossProduct( v[1] ) );
+ return r.Length() * 0.5;
+}
+
+bool MTriangle::operator == (const MTriangle& rhs)
+{
+ if (m_verts[0] != rhs.m_verts[0]) return false;
+ if (m_verts[1] != rhs.m_verts[1]) return false;
+ if (m_verts[2] != rhs.m_verts[2]) return false;
+ return true;
+}
+
+/****************************************************************************
+ * Copyright (C) 2009 by Joshua Allen *
+ * *
+ * *
+ * 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/DataTypes/MTriangle.h
===================================================================
--- Mercury2/src/DataTypes/MTriangle.h (rev 0)
+++ Mercury2/src/DataTypes/MTriangle.h 2009-10-10 22:21:49 UTC (rev 555)
@@ -0,0 +1,55 @@
+#ifndef MTRIANGLE_H
+#define MTRIANGLE_H
+
+#include <MercuryVertex.h>
+
+class MTriangle
+{
+ public:
+ MTriangle();
+ MTriangle(const MercuryVertex a, const MercuryVertex& b, const MercuryVertex& c);
+
+ MercuryVertex Barycentric(const MercuryVertex& p);
+ bool IsInTriangle( const MercuryVertex& p );
+
+ float Area();
+
+ bool operator == (const MTriangle& rhs);
+ private:
+
+ MercuryVertex m_verts[3];
+};
+
+#endif
+
+/****************************************************************************
+ * Copyright (C) 2009 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2010-04-28 02:05:32
|
Revision: 707
http://hgengine.svn.sourceforge.net/hgengine/?rev=707&view=rev
Author: axlecrusher
Date: 2010-04-28 02:05:26 +0000 (Wed, 28 Apr 2010)
Log Message:
-----------
preallocate matrix space in one giant chunk.
Modified Paths:
--------------
Mercury2/src/MercuryMatrix.cpp
Mercury2/src/MercuryMatrix.h
Modified: Mercury2/src/MercuryMatrix.cpp
===================================================================
--- Mercury2/src/MercuryMatrix.cpp 2010-04-27 21:39:01 UTC (rev 706)
+++ Mercury2/src/MercuryMatrix.cpp 2010-04-28 02:05:26 UTC (rev 707)
@@ -1,13 +1,52 @@
#include "MercuryMatrix.h"
#include <MercuryLog.h>
+MercuryMatrixMemory& MercuryMatrixMemory::Instance()
+{
+ static MercuryMatrixMemory* mmm = NULL;
+
+ if (mmm==NULL)
+ {
+ mmm = new MercuryMatrixMemory();
+ mmm->Init();
+ }
+
+ return *mmm;
+}
+
+void MercuryMatrixMemory::Init()
+{
+ MSemaphoreLock lock(&m_lock);
+ for (unsigned int i = 0; i < rows;i++)
+ m_free.push_back( m_data+i );
+}
+
+FloatRow* MercuryMatrixMemory::GetNewMatrix()
+{
+ MatrixArray* m = (MatrixArray*)0xdeadbeef;
+ MSemaphoreLock lock(&m_lock);
+ if ( m_free.begin() != m_free.end() )
+ {
+ m = m_free.front();
+ m_free.pop_front();
+ }
+ return (FloatRow*)m;
+}
+
+void MercuryMatrixMemory::FreeMatrix(FloatRow* m)
+{
+ MSemaphoreLock lock(&m_lock);
+ m_free.push_back((MatrixArray*)m);
+}
+/*
VC_ALIGN(16) float base_matrix_identity[16] CC_ALIGN(16) = {
1.0f, 0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f };
-
+*/
MercuryMatrix::MercuryMatrix()
+ :m_matrix(0)
{/*
#ifdef USE_SSE
m_matrix[0] = _mm_load1_ps( &base_matrix_identity[0] );
@@ -19,9 +58,24 @@
#endif
*/
// *this = Identity();
+ m_matrix = MercuryMatrixMemory::Instance().GetNewMatrix();
LoadIdentity();
}
+MercuryMatrix::MercuryMatrix(const MercuryMatrix& m)
+ :m_matrix(0)
+{
+ m_matrix = MercuryMatrixMemory::Instance().GetNewMatrix();
+ Copy16f(m_matrix, m.m_matrix);
+}
+
+MercuryMatrix::~MercuryMatrix()
+{
+ if (m_matrix)
+ MercuryMatrixMemory::Instance().FreeMatrix( m_matrix );
+ m_matrix = NULL;
+}
+
const MercuryMatrix& MercuryMatrix::operator=(const MercuryMatrix& m)
{
Copy16f(m_matrix, m.m_matrix);
@@ -44,7 +98,8 @@
const MercuryMatrix& MercuryMatrix::Identity()
{
- static bool bSetIdentity = false;
+ return IdentityMatrix;
+/* static bool bSetIdentity = false;
if (!bSetIdentity)
{
@@ -60,11 +115,14 @@
}
return IdentityMatrix;
+ */
}
void MercuryMatrix::LoadIdentity()
{
- Copy16f(m_matrix, base_matrix_identity );
+ for (uint8_t x=0;x<4;++x)
+ for (uint8_t y=0;y<4;++y)
+ m_matrix[x][y] = (x==y)?1.0f:0.0f;
}
void MercuryMatrix::Translate(float x, float y, float z)
Modified: Mercury2/src/MercuryMatrix.h
===================================================================
--- Mercury2/src/MercuryMatrix.h 2010-04-27 21:39:01 UTC (rev 706)
+++ Mercury2/src/MercuryMatrix.h 2010-04-28 02:05:26 UTC (rev 707)
@@ -7,25 +7,49 @@
#include <MercuryVertex.h>
#include <MQuaternion.h>
+#include <list>
+#include <MSemaphore.h>
+
+///Memory holder for matrices
+class MercuryMatrixMemory
+{
+ /* Allocates all matrix space as one contigous block
+ to try to take advantage of data prefetching. Some matrix data should get a
+ free ride into the CPU cache. */
+ public:
+ void Init();
+ static MercuryMatrixMemory& Instance();
+ FloatRow* GetNewMatrix();
+ void FreeMatrix(FloatRow* m);
+ private:
+ typedef FloatRow MatrixArray[4]; //64kb
+ static const unsigned int rows = 1024; //1024 matrices * 64bytes each = 64kb
+ std::list< MatrixArray* > m_free;
+ MatrixArray m_data[rows];
+ MSemaphore m_lock;
+};
+
///General Purpose 4x4 row-major matrix
- VC_ALIGN(16) class MercuryMatrix
+class MercuryMatrix
{
private:
///[row][column] (The internal matrix)
// float m_matrix[4][4];
- FloatRow m_matrix[4];
+// FloatRow m_matrix[4];
+ FloatRow* m_matrix;
static MercuryMatrix IdentityMatrix;
public:
MercuryMatrix();
- inline MercuryMatrix(const MercuryMatrix& m) { *this = m; }
- inline float* operator[](unsigned int i) { return (float*)&m_matrix[i]; }
+ MercuryMatrix(const MercuryMatrix& m);
+ ~MercuryMatrix();
+ inline float* operator[](unsigned int i) { return m_matrix[i]; }
///Allow typecasting to float * for use in APIs
- inline const float* operator[](unsigned int i) const { return (float*)&m_matrix[i]; }
+ inline const float* operator[](unsigned int i) const { return m_matrix[i]; }
const MercuryMatrix& operator=(const MercuryMatrix& m);
const MercuryMatrix& operator=(const float* m);
- inline float* Ptr() { return (float*)&m_matrix; }
- inline const float* Ptr() const { return (float*)&m_matrix; }
+ inline float* Ptr() { return (float*)m_matrix; }
+ inline const float* Ptr() const { return (const float*)m_matrix; }
MercuryMatrix operator*(const MercuryMatrix& m) const;
MercuryMatrix& operator*=(const MercuryMatrix& m);
@@ -55,13 +79,8 @@
void LoadIdentity();
void Print() const;
-} CC_ALIGN(16);
+};
-//namespace MercuryMath
-//{
-//}
-
-
#endif
/*
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2010-04-29 10:51:00
|
Revision: 714
http://hgengine.svn.sourceforge.net/hgengine/?rev=714&view=rev
Author: axlecrusher
Date: 2010-04-29 10:50:54 +0000 (Thu, 29 Apr 2010)
Log Message:
-----------
instance counter for MercuryMatrixMemory singleton
Modified Paths:
--------------
Mercury2/src/MercuryMatrix.cpp
Mercury2/src/MercuryMatrix.h
Modified: Mercury2/src/MercuryMatrix.cpp
===================================================================
--- Mercury2/src/MercuryMatrix.cpp 2010-04-29 10:32:21 UTC (rev 713)
+++ Mercury2/src/MercuryMatrix.cpp 2010-04-29 10:50:54 UTC (rev 714)
@@ -1,7 +1,7 @@
#include "MercuryMatrix.h"
#include <MercuryLog.h>
-MercuryMatrixMemory& MercuryMatrixMemory::Instance()
+MercuryMatrixMemory& MercuryMatrixMemory::GetInstance()
{
static MercuryMatrixMemory* mmm = NULL;
@@ -58,21 +58,21 @@
#endif
*/
// *this = Identity();
- m_matrix = MercuryMatrixMemory::Instance().GetNewMatrix();
+ m_matrix = MercuryMatrixMemory::GetInstance().GetNewMatrix();
LoadIdentity();
}
MercuryMatrix::MercuryMatrix(const MercuryMatrix& m)
:m_matrix(0)
{
- m_matrix = MercuryMatrixMemory::Instance().GetNewMatrix();
+ m_matrix = MercuryMatrixMemory::GetInstance().GetNewMatrix();
Copy16f(m_matrix, m.m_matrix);
}
MercuryMatrix::~MercuryMatrix()
{
if (m_matrix)
- MercuryMatrixMemory::Instance().FreeMatrix( m_matrix );
+ MercuryMatrixMemory::GetInstance().FreeMatrix( m_matrix );
m_matrix = NULL;
}
@@ -90,10 +90,10 @@
void MercuryMatrix::Zero()
{
- ZeroFloatRow( m_matrix[0] );
- ZeroFloatRow( m_matrix[1] );
- ZeroFloatRow( m_matrix[2] );
- ZeroFloatRow( m_matrix[3] );
+ m_matrix[0] = {0,0,0,0};
+ m_matrix[1] = {0,0,0,0};
+ m_matrix[2] = {0,0,0,0};
+ m_matrix[3] = {0,0,0,0};
}
const MercuryMatrix& MercuryMatrix::Identity()
Modified: Mercury2/src/MercuryMatrix.h
===================================================================
--- Mercury2/src/MercuryMatrix.h 2010-04-29 10:32:21 UTC (rev 713)
+++ Mercury2/src/MercuryMatrix.h 2010-04-29 10:50:54 UTC (rev 714)
@@ -18,7 +18,7 @@
free ride into the CPU cache. */
public:
void Init();
- static MercuryMatrixMemory& Instance();
+ static MercuryMatrixMemory& GetInstance();
FloatRow* GetNewMatrix();
void FreeMatrix(FloatRow* m);
private:
@@ -81,6 +81,8 @@
void Print() const;
};
+static InstanceCounter<MercuryMatrixMemory> MMMcounter("MercuryMatrixMemory");
+
#endif
/*
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2010-11-23 03:04:23
|
Revision: 770
http://hgengine.svn.sourceforge.net/hgengine/?rev=770&view=rev
Author: axlecrusher
Date: 2010-11-23 03:04:17 +0000 (Tue, 23 Nov 2010)
Log Message:
-----------
add CAS_PTR and license on MercuryThreads
Modified Paths:
--------------
Mercury2/src/MSemaphore.h
Mercury2/src/MercuryThreads.cpp
Mercury2/src/MercuryThreads.h
Modified: Mercury2/src/MSemaphore.h
===================================================================
--- Mercury2/src/MSemaphore.h 2010-11-21 19:38:18 UTC (rev 769)
+++ Mercury2/src/MSemaphore.h 2010-11-23 03:04:17 UTC (rev 770)
@@ -13,15 +13,21 @@
#define COMPARE_AND_SWAP(d,o,n) __sync_val_compare_and_swap(d,o,n)
#define SYNC_AND_AND_FETCH(d,v) __sync_and_and_fetch(d,v)
+inline void* CAS_PTR(volatile void** d, void* e, void* c)
+{
+ //these variables must be 32 bit aligned on x86 and 64 bit aligned on x64
+ return __sync_val_compare_and_swap((void**)d,c,e);
+}
+
#else
#define SYNC_OR_AND_FETCH(d,v) ((uint32_t)OrAndFetch(d,v))
#define COMPARE_AND_SWAP(d,o,n) ((uint32_t)InterlockedCompareExchange(d, n, o))
#define SYNC_AND_AND_FETCH(d,v) ((uint32_t)__sync_and_and_fetch(d,v))
-inline void* CAS_PTR(volatile void** d, void* e, void* c)
-{
- //these variables must be 32 bit aligned on x86 and 64 bit aligned on x64
+inline void* CAS_PTR(volatile void** d, void* e, void* c)
+{
+ //these variables must be 32 bit aligned on x86 and 64 bit aligned on x64
return InterlockedCompareExchangePointer((volatile PVOID*)d,e,c);
}
Modified: Mercury2/src/MercuryThreads.cpp
===================================================================
--- Mercury2/src/MercuryThreads.cpp 2010-11-21 19:38:18 UTC (rev 769)
+++ Mercury2/src/MercuryThreads.cpp 2010-11-23 03:04:17 UTC (rev 770)
@@ -306,3 +306,35 @@
return 0;
#endif
}
+
+/****************************************************************************
+ * Copyright (C) 2006 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
Modified: Mercury2/src/MercuryThreads.h
===================================================================
--- Mercury2/src/MercuryThreads.h 2010-11-21 19:38:18 UTC (rev 769)
+++ Mercury2/src/MercuryThreads.h 2010-11-23 03:04:17 UTC (rev 770)
@@ -190,3 +190,34 @@
#endif
+/****************************************************************************
+ * Copyright (C) 2006 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-07 15:52:17
|
Revision: 61
http://hgengine.svn.sourceforge.net/hgengine/?rev=61&view=rev
Author: axlecrusher
Date: 2008-12-07 15:52:14 +0000 (Sun, 07 Dec 2008)
Log Message:
-----------
update how nodes handle onAdd actions
Modified Paths:
--------------
Mercury2/src/MercuryNode.cpp
Mercury2/src/MercuryNode.h
Modified: Mercury2/src/MercuryNode.cpp
===================================================================
--- Mercury2/src/MercuryNode.cpp 2008-12-07 15:49:32 UTC (rev 60)
+++ Mercury2/src/MercuryNode.cpp 2008-12-07 15:52:14 UTC (rev 61)
@@ -26,9 +26,8 @@
m_children.push_back(n);
n->m_parent = this;
- list< Callback2< MercuryNode*, MercuryNode* > >::iterator i;
- for (i = OnAddChild.begin(); i != OnAddChild.end(); ++i )
- (*i)(this, n);
+ OnAddChild();
+ n->OnAdded();
}
void MercuryNode::RemoveChild(MercuryNode* n)
@@ -38,10 +37,9 @@
{
if (*i == n)
{
- list< Callback2< MercuryNode*, MercuryNode* > >::iterator ic;
- for (ic = OnRemoveChild.begin(); ic != OnRemoveChild.end(); ++ic )
- (*ic)(this, n);
-
+ n->OnRemoved();
+ OnRemoveChild();
+ n->m_parent = NULL;
m_children.erase(i);
return;
}
Modified: Mercury2/src/MercuryNode.h
===================================================================
--- Mercury2/src/MercuryNode.h 2008-12-07 15:49:32 UTC (rev 60)
+++ Mercury2/src/MercuryNode.h 2008-12-07 15:52:14 UTC (rev 61)
@@ -40,15 +40,21 @@
virtual void Update(float dTime) {};
void RecursiveUpdate(float dTime);
- ///Provides callback ability when a child node is added (parent, child) arguement order
- std::list< Callback2< MercuryNode*, MercuryNode* > > OnAddChild;
+ ///Run on parent when a child is added
+ virtual void OnAddChild() {};
- ///Provides callback ability when a child node is removed (parent, child) arguement order
- std::list< Callback2< MercuryNode*, MercuryNode* > > OnRemoveChild;
+ ///Run on parent when a child is added
+ virtual void OnRemoveChild() {};
///Loads a node from an XMLNode representing itself
virtual void LoadFromXML(const XMLNode& node);
+
+ ///Run on a child when added to a parent
+ virtual void OnAdded() {};
+ ///Run on a child when removed from a parent
+ virtual void OnRemoved() {};
+
GENRTTI(MercuryNode);
protected:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-07 15:53:48
|
Revision: 62
http://hgengine.svn.sourceforge.net/hgengine/?rev=62&view=rev
Author: axlecrusher
Date: 2008-12-07 15:53:43 +0000 (Sun, 07 Dec 2008)
Log Message:
-----------
Make transform nodes find a paren't taint on add
Modified Paths:
--------------
Mercury2/src/TransformNode.cpp
Mercury2/src/TransformNode.h
Modified: Mercury2/src/TransformNode.cpp
===================================================================
--- Mercury2/src/TransformNode.cpp 2008-12-07 15:52:14 UTC (rev 61)
+++ Mercury2/src/TransformNode.cpp 2008-12-07 15:53:43 UTC (rev 62)
@@ -5,6 +5,7 @@
TransformNode::TransformNode()
:m_scale( MercuryPoint(1,1,1) )
{
+ SetTaint( true ); //taint because of the scale set above
}
void TransformNode::Update(float dTime)
@@ -14,20 +15,29 @@
void TransformNode::SetScale( const MercuryPoint& scale )
{
- m_scale = scale;
- SetTaint( true );
+ if (scale != m_scale)
+ {
+ m_scale = scale;
+ SetTaint( true );
+ }
}
void TransformNode::SetPosition( const MercuryPoint& position )
{
- m_position = position;
- SetTaint( true );
+ if (position != m_position)
+ {
+ m_position = position;
+ SetTaint( true );
+ }
}
void TransformNode::SetRotation( const MercuryPoint& rotation )
{
- m_rotation = rotation;
- SetTaint( true );
+ if (rotation != m_rotation)
+ {
+ m_rotation = rotation;
+ SetTaint( true );
+ }
}
void TransformNode::SetTaint(bool taint)
@@ -40,13 +50,14 @@
{
m_tainted = false;
- m_localMatrix.Identity();
+ MercuryMatrix local;
+ local.Identity();
- m_localMatrix.Transotale( m_position.x, m_position.y, m_position.z,
+ local.Transotale( m_position.x, m_position.y, m_position.z,
m_rotation.x, m_rotation.y, m_rotation.z,
m_scale.x, m_scale.y, m_scale.z );
- m_globalMatrix = GetParentMatrix() * m_localMatrix;
+ m_globalMatrix = GetParentMatrix() * local;
}
const MercuryMatrix& TransformNode::GetParentMatrix() const
@@ -116,26 +127,50 @@
MercuryNode::LoadFromXML( node );
}
-/***************************************************************************
- * Copyright (C) 2008 by Joshua Allen *
- * *
- * *
- * 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 <ORGANIZATION> 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. *
+void TransformNode::OnAdded()
+{
+ //Try to get the taint flag from the parent transform
+ MercuryNode* n = m_parent;
+ TransformNode* tn;
+ while (n)
+ {
+ if ( (tn = TransformNode::Cast( n )) )
+ {
+ tn->RippleTaintDown();
+ return;
+ }
+ n = n->Parent();
+ }
+}
+
+/****************************************************************************
+ * Copyright (C) 2008 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
***************************************************************************/
Modified: Mercury2/src/TransformNode.h
===================================================================
--- Mercury2/src/TransformNode.h 2008-12-07 15:52:14 UTC (rev 61)
+++ Mercury2/src/TransformNode.h 2008-12-07 15:53:43 UTC (rev 62)
@@ -27,6 +27,8 @@
void ComputeMatrix();
virtual void LoadFromXML(const XMLNode& node);
+
+ virtual void OnAdded();
GENRTTI(TransformNode);
@@ -37,32 +39,40 @@
MercuryPoint m_position;
MercuryPoint m_rotation;
- MercuryMatrix m_localMatrix;
+// MercuryMatrix m_localMatrix;
MercuryMatrix m_globalMatrix;
bool m_tainted;
};
-/***************************************************************************
- * Copyright (C) 2008 by Joshua Allen *
- * *
- * *
- * 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 <ORGANIZATION> 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. *
+/****************************************************************************
+ * Copyright (C) 2008 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
***************************************************************************/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-07 17:41:45
|
Revision: 67
http://hgengine.svn.sourceforge.net/hgengine/?rev=67&view=rev
Author: axlecrusher
Date: 2008-12-07 17:41:41 +0000 (Sun, 07 Dec 2008)
Log Message:
-----------
fix warnings
Modified Paths:
--------------
Mercury2/src/Mercury2.cpp
Mercury2/src/MercuryUtil.cpp
Mercury2/src/PNGLoader.cpp
Mercury2/src/X11Window.cpp
Modified: Mercury2/src/Mercury2.cpp
===================================================================
--- Mercury2/src/Mercury2.cpp 2008-12-07 17:35:58 UTC (rev 66)
+++ Mercury2/src/Mercury2.cpp 2008-12-07 17:41:41 UTC (rev 67)
@@ -9,7 +9,7 @@
int main()
{
unsigned long m_count = 0;
- unsigned long m_time;
+ long m_time;
MercuryWindow* w = MercuryWindow::MakeWindow();
MercuryNode* root = new MercuryNode();
@@ -32,7 +32,7 @@
if (time(NULL) > m_time)
{
m_time = time(NULL);
- printf("FPS: %d\n", m_count);
+ printf("FPS: %lu\n", m_count);
m_count = 0;
}
}
Modified: Mercury2/src/MercuryUtil.cpp
===================================================================
--- Mercury2/src/MercuryUtil.cpp 2008-12-07 17:35:58 UTC (rev 66)
+++ Mercury2/src/MercuryUtil.cpp 2008-12-07 17:41:41 UTC (rev 67)
@@ -3,7 +3,7 @@
std::string ToUpper(const std::string& s)
{
std::string t = s;
- for (int i = 0; i < s.length(); ++i)
+ for (unsigned long i = 0; i < s.length(); ++i)
{
t[i] = toupper(t[i]);
}
Modified: Mercury2/src/PNGLoader.cpp
===================================================================
--- Mercury2/src/PNGLoader.cpp 2008-12-07 17:35:58 UTC (rev 66)
+++ Mercury2/src/PNGLoader.cpp 2008-12-07 17:41:41 UTC (rev 67)
@@ -106,7 +106,7 @@
case RGBA:
for ( y=0; y < (unsigned)image->m_height; ++y) {
png_byte* row = row_pointers[y];
- for (int x = 0; x < image->m_width; ++x) {
+ for (unsigned long x = 0; x < image->m_width; ++x) {
png_byte* ptr = &(row[x*4]);
image->m_data[(x + y * image->m_width) * 4] = ptr[0];
image->m_data[(x + y * image->m_width) * 4 + 1] = ptr[1];
@@ -118,7 +118,7 @@
case RGB:
for ( y=0; y < (unsigned)image->m_height; y++) {
png_byte* row = row_pointers[y];
- for (int x=0; x<image->m_width; x++) {
+ for (unsigned long x=0; x<image->m_width; x++) {
png_byte* ptr = &(row[x * 3]);
image->m_data[(x + y * image->m_width) * 3] = ptr[0];
image->m_data[(x + y * image->m_width) * 3 + 1] = ptr[1];
@@ -171,4 +171,4 @@
* 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.
- */
\ No newline at end of file
+ */
Modified: Mercury2/src/X11Window.cpp
===================================================================
--- Mercury2/src/X11Window.cpp 2008-12-07 17:35:58 UTC (rev 66)
+++ Mercury2/src/X11Window.cpp 2008-12-07 17:41:41 UTC (rev 67)
@@ -100,7 +100,7 @@
{
case ClientMessage:
{
- if ( event.xclient.data.l[0] == m_wmDeleteMessage )
+ if ( unsigned(event.xclient.data.l[0]) == m_wmDeleteMessage )
XDestroyWindow(m_display,m_window);
break;
}
@@ -145,7 +145,7 @@
void* X11Window::GetProcAddress(const string& x)
{
-
+return NULL;
}
/***************************************************************************
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-13 00:11:14
|
Revision: 70
http://hgengine.svn.sourceforge.net/hgengine/?rev=70&view=rev
Author: axlecrusher
Date: 2008-12-13 00:11:10 +0000 (Sat, 13 Dec 2008)
Log Message:
-----------
experimental threaded updater
Added Paths:
-----------
Mercury2/src/UpdateThreader.cpp
Mercury2/src/UpdateThreader.h
Added: Mercury2/src/UpdateThreader.cpp
===================================================================
--- Mercury2/src/UpdateThreader.cpp (rev 0)
+++ Mercury2/src/UpdateThreader.cpp 2008-12-13 00:11:10 UTC (rev 70)
@@ -0,0 +1,87 @@
+#include <UpdateThreader.h>
+
+void* UpdateThreader::ThreadClbk(void*)
+{
+ UpdateThreader& ut = UpdateThreader::GetInstance();
+ while ( ut.HasWork() )
+ {
+ MercuryNode* n = ut.GetWorkNode();
+ n->ThreadedUpdate(0.01f);
+ }
+ return NULL;
+}
+
+UpdateThreader& UpdateThreader::GetInstance()
+{
+ static UpdateThreader* instance = NULL;
+ if (!instance)
+ instance = new UpdateThreader;
+ return *instance;
+
+}
+
+bool UpdateThreader::AddNode(MercuryNode* node)
+{
+ AutoMutexLock lock( m_mutex );
+ m_nodes.push( node );
+ return true;
+}
+
+void UpdateThreader::DoWork()
+{
+ MercuryThread thread1,thread2;
+ thread1.HaltOnDestroy(false);
+ thread2.HaltOnDestroy(false);
+ thread1.Create( ThreadClbk, NULL, false );
+ thread2.Create( ThreadClbk, NULL, false );
+ thread1.Wait();
+ thread2.Wait();
+}
+
+bool UpdateThreader::HasWork()
+{
+ AutoMutexLock lock(m_mutex);
+ return !m_nodes.empty();
+}
+
+MercuryNode* UpdateThreader::GetWorkNode()
+{
+ MercuryNode* n = NULL;
+ AutoMutexLock lock(m_mutex);
+ n = m_nodes.front();
+ m_nodes.pop();
+ return n;
+}
+
+
+/****************************************************************************
+ * Copyright (C) 2008 by Joshua Allen *
+ * *
+ * *
+ * 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/UpdateThreader.h
===================================================================
--- Mercury2/src/UpdateThreader.h (rev 0)
+++ Mercury2/src/UpdateThreader.h 2008-12-13 00:11:10 UTC (rev 70)
@@ -0,0 +1,64 @@
+#ifndef UPDATETHREADER_H
+#define UPDATETHREADER_H
+
+#include <queue>
+#include <MQueue.h>
+#include <MercuryNode.h>
+#include <MercuryThreads.h>
+
+//XXX EXPERIMENTAL
+class UpdateThreader
+{
+ public:
+ static UpdateThreader& GetInstance();
+
+ bool AddNode(MercuryNode* node);
+ void DoWork();
+
+ MercuryMutex m_mutex;
+
+ private:
+ static void* ThreadClbk(void*);
+
+ bool HasWork();
+ MercuryNode* GetWorkNode();
+
+ std::queue< MercuryNode* > m_nodes;
+// MQueue< MercuryNode* > m_nodes;
+};
+
+static InstanceCounter<UpdateThreader> UTcounter("UpdateThreader");
+
+
+#endif
+/****************************************************************************
+ * Copyright (C) 2008 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-13 00:13:51
|
Revision: 71
http://hgengine.svn.sourceforge.net/hgengine/?rev=71&view=rev
Author: axlecrusher
Date: 2008-12-13 00:13:48 +0000 (Sat, 13 Dec 2008)
Log Message:
-----------
experimental threaded update
Modified Paths:
--------------
Mercury2/src/MercuryNode.cpp
Mercury2/src/MercuryNode.h
Modified: Mercury2/src/MercuryNode.cpp
===================================================================
--- Mercury2/src/MercuryNode.cpp 2008-12-13 00:11:10 UTC (rev 70)
+++ Mercury2/src/MercuryNode.cpp 2008-12-13 00:13:48 UTC (rev 71)
@@ -1,5 +1,6 @@
#include <MercuryNode.h>
#include <MercuryUtil.h>
+#include <UpdateThreader.h>
using namespace std;
@@ -88,6 +89,16 @@
(*i)->RecursiveUpdate(dTime);
}
+void MercuryNode::ThreadedUpdate(float dTime)
+{
+ //XXX EXPERIMENTAL
+ Update(dTime);
+
+ list< MercuryNode* >::iterator i;
+ for (i = m_children.begin(); i != m_children.end(); ++i )
+ UpdateThreader::GetInstance().AddNode( *i );
+}
+
void MercuryNode::LoadFromXML(const XMLNode& node)
{
//Not much to do here except run through all the children nodes
Modified: Mercury2/src/MercuryNode.h
===================================================================
--- Mercury2/src/MercuryNode.h 2008-12-13 00:11:10 UTC (rev 70)
+++ Mercury2/src/MercuryNode.h 2008-12-13 00:13:48 UTC (rev 71)
@@ -39,6 +39,7 @@
virtual void Update(float dTime) {};
void RecursiveUpdate(float dTime);
+ void ThreadedUpdate(float dTime);
///Run on parent when a child is added
virtual void OnAddChild() {};
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-13 00:18:17
|
Revision: 73
http://hgengine.svn.sourceforge.net/hgengine/?rev=73&view=rev
Author: axlecrusher
Date: 2008-12-13 00:18:15 +0000 (Sat, 13 Dec 2008)
Log Message:
-----------
update
Modified Paths:
--------------
Mercury2/src/MercuryThreads.cpp
Mercury2/src/MercuryThreads.h
Modified: Mercury2/src/MercuryThreads.cpp
===================================================================
--- Mercury2/src/MercuryThreads.cpp 2008-12-13 00:15:43 UTC (rev 72)
+++ Mercury2/src/MercuryThreads.cpp 2008-12-13 00:18:15 UTC (rev 73)
@@ -44,7 +44,7 @@
}
#endif
-int MercuryThread::Create( void * (*fn)(void *), void *data )
+int MercuryThread::Create( void * (*fn)(void *), void *data, bool detach )
{
#if defined( WIN32 )
mkThreadData = new StartThreadData;
@@ -59,7 +59,8 @@
return false;
else
{
- pthread_detach( m_thread ); //reclaim memory on thread destruction
+ if (detach)
+ pthread_detach( m_thread ); //reclaim memory on thread destruction
return true;
}
#endif
Modified: Mercury2/src/MercuryThreads.h
===================================================================
--- Mercury2/src/MercuryThreads.h 2008-12-13 00:15:43 UTC (rev 72)
+++ Mercury2/src/MercuryThreads.h 2008-12-13 00:18:15 UTC (rev 73)
@@ -24,7 +24,7 @@
~MercuryThread();
///Create a thread of function fn and pass it data *data.
- int Create( void * (*fn)(void *), void *data );
+ int Create( void * (*fn)(void *), void *data, bool detach = true );
///Wait for the thread to complete.
int Wait( long lMilliseconds = 10000000 );
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-13 17:23:09
|
Revision: 74
http://hgengine.svn.sourceforge.net/hgengine/?rev=74&view=rev
Author: axlecrusher
Date: 2008-12-13 17:23:05 +0000 (Sat, 13 Dec 2008)
Log Message:
-----------
add mercury semaphore
Added Paths:
-----------
Mercury2/src/MSemaphore.cpp
Mercury2/src/MSemaphore.h
Added: Mercury2/src/MSemaphore.cpp
===================================================================
--- Mercury2/src/MSemaphore.cpp (rev 0)
+++ Mercury2/src/MSemaphore.cpp 2008-12-13 17:23:05 UTC (rev 74)
@@ -0,0 +1,73 @@
+#include <MSemaphore.h>
+
+MSemaphore::MSemaphore()
+ :m_counter(0)
+{
+}
+
+unsigned long MSemaphore::ReadValue()
+{
+ return __sync_or_and_fetch(&m_counter, 0);
+}
+
+unsigned long MSemaphore::Decrement()
+{
+ return __sync_sub_and_fetch(&m_counter, 1);
+}
+
+unsigned long MSemaphore::Increment()
+{
+ return __sync_add_and_fetch(&m_counter, 1);
+}
+
+MSemaphoreIncOnDestroy::MSemaphoreIncOnDestroy(MSemaphore* s)
+ :m_s(s)
+{
+}
+
+MSemaphoreIncOnDestroy::~MSemaphoreIncOnDestroy()
+{
+ m_s->Increment();
+}
+
+MSemaphoreDecOnDestroy::MSemaphoreDecOnDestroy(MSemaphore* s)
+ :m_s(s)
+{
+}
+
+MSemaphoreDecOnDestroy::~MSemaphoreDecOnDestroy()
+{
+ m_s->Decrement();
+}
+
+/****************************************************************************
+ * Copyright (C) 2008 by Joshua Allen *
+ * *
+ * *
+ * 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/MSemaphore.h
===================================================================
--- Mercury2/src/MSemaphore.h (rev 0)
+++ Mercury2/src/MSemaphore.h 2008-12-13 17:23:05 UTC (rev 74)
@@ -0,0 +1,66 @@
+#ifndef MSEMAPHORE_H
+#define MSEMAPHORE_H
+
+class MSemaphore
+{
+ public:
+ MSemaphore();
+
+ unsigned long ReadValue();
+ unsigned long Decrement();
+ unsigned long Increment();
+
+ private:
+ unsigned long m_counter;
+};
+
+class MSemaphoreIncOnDestroy
+{
+ public:
+ MSemaphoreIncOnDestroy(MSemaphore* s);
+ ~MSemaphoreIncOnDestroy();
+ private:
+ MSemaphore* m_s;
+};
+
+class MSemaphoreDecOnDestroy
+{
+ public:
+ MSemaphoreDecOnDestroy(MSemaphore* s);
+ ~MSemaphoreDecOnDestroy();
+ private:
+ MSemaphore* m_s;
+};
+
+#endif
+/****************************************************************************
+ * Copyright (C) 2008 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-13 17:26:51
|
Revision: 75
http://hgengine.svn.sourceforge.net/hgengine/?rev=75&view=rev
Author: axlecrusher
Date: 2008-12-13 17:26:41 +0000 (Sat, 13 Dec 2008)
Log Message:
-----------
Add semaphore to renderables
Modified Paths:
--------------
Mercury2/src/RenderableNode.cpp
Mercury2/src/RenderableNode.h
Modified: Mercury2/src/RenderableNode.cpp
===================================================================
--- Mercury2/src/RenderableNode.cpp 2008-12-13 17:23:05 UTC (rev 74)
+++ Mercury2/src/RenderableNode.cpp 2008-12-13 17:26:41 UTC (rev 75)
@@ -19,6 +19,12 @@
m_postrender.clear();
}
+void RenderableNode::Update(float dTime)
+{
+ MSemaphoreIncOnDestroy s( &m_semaphore );
+ while (m_semaphore.ReadValue() != 0);
+}
+
void RenderableNode::Render()
{
list< MercuryAsset* >::iterator i;
@@ -87,9 +93,15 @@
return false;
}
-void RenderableNode::RecursiveRender( const MercuryNode* n )
+void RenderableNode::RecursiveRender( MercuryNode* n )
{
- if ( Cast(n) ) ((RenderableNode*)n)->Render();
+ RenderableNode* rn;
+ if ( rn = Cast(n) )
+ {
+ MSemaphoreDecOnDestroy s( &(rn->m_semaphore) );
+ while (rn->m_semaphore.ReadValue() != 1);
+ rn->Render();
+ }
const list< MercuryNode* >& children = n->Children();
list< MercuryNode* >::const_iterator i;
Modified: Mercury2/src/RenderableNode.h
===================================================================
--- Mercury2/src/RenderableNode.h 2008-12-13 17:23:05 UTC (rev 74)
+++ Mercury2/src/RenderableNode.h 2008-12-13 17:26:41 UTC (rev 75)
@@ -5,6 +5,7 @@
#include <MAutoPtr.h>
#include <MercuryAsset.h>
#include <MercuryMatrix.h>
+#include <MSemaphore.h>
#define MCHECKASSETS
@@ -15,7 +16,7 @@
~RenderableNode();
virtual void Render();
- virtual void Update(float dTime) {};
+ virtual void Update(float dTime);
///Returnes true if N is of type RenderableNode
// static bool IsMyType( MercuryNode* n );
@@ -26,7 +27,7 @@
void AddRender(MercuryAsset* asset);
void AddPostRender(MercuryAsset* asset);
- static void RecursiveRender( const MercuryNode* n );
+ static void RecursiveRender( MercuryNode* n );
virtual void LoadFromXML(const XMLNode& node);
const MercuryMatrix& FindGlobalMatrix() const;
@@ -47,6 +48,8 @@
std::list< MercuryAsset* > m_prerender;
std::list< MercuryAsset* > m_render;
std::list< MercuryAsset* > m_postrender;
+
+ MSemaphore m_semaphore;
};
#endif
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-15 01:23:32
|
Revision: 77
http://hgengine.svn.sourceforge.net/hgengine/?rev=77&view=rev
Author: axlecrusher
Date: 2008-12-15 01:23:28 +0000 (Mon, 15 Dec 2008)
Log Message:
-----------
update
Modified Paths:
--------------
Mercury2/src/RenderableNode.cpp
Mercury2/src/RenderableNode.h
Modified: Mercury2/src/RenderableNode.cpp
===================================================================
--- Mercury2/src/RenderableNode.cpp 2008-12-13 17:28:34 UTC (rev 76)
+++ Mercury2/src/RenderableNode.cpp 2008-12-15 01:23:28 UTC (rev 77)
@@ -22,7 +22,7 @@
void RenderableNode::Update(float dTime)
{
MSemaphoreIncOnDestroy s( &m_semaphore );
- while (m_semaphore.ReadValue() != 0);
+ Spinlock(0);
}
void RenderableNode::Render()
@@ -99,7 +99,7 @@
if ( rn = Cast(n) )
{
MSemaphoreDecOnDestroy s( &(rn->m_semaphore) );
- while (rn->m_semaphore.ReadValue() != 1);
+ rn->Spinlock(1);
rn->Render();
}
Modified: Mercury2/src/RenderableNode.h
===================================================================
--- Mercury2/src/RenderableNode.h 2008-12-13 17:28:34 UTC (rev 76)
+++ Mercury2/src/RenderableNode.h 2008-12-15 01:23:28 UTC (rev 77)
@@ -39,6 +39,7 @@
bool m_hidden;
private:
bool IsInAssetList(MercuryAsset* asset) const;
+ inline void Spinlock( unsigned long value ) { while (m_semaphore.ReadValue() != value); }
std::list< MAutoPtr< MercuryAsset > > m_assets; ///serves as a holder for memory
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-22 01:03:35
|
Revision: 78
http://hgengine.svn.sourceforge.net/hgengine/?rev=78&view=rev
Author: axlecrusher
Date: 2008-12-22 01:03:32 +0000 (Mon, 22 Dec 2008)
Log Message:
-----------
update
Modified Paths:
--------------
Mercury2/src/Mercury2.cpp
Mercury2/src/RenderableNode.cpp
Mercury2/src/RenderableNode.h
Modified: Mercury2/src/Mercury2.cpp
===================================================================
--- Mercury2/src/Mercury2.cpp 2008-12-15 01:23:28 UTC (rev 77)
+++ Mercury2/src/Mercury2.cpp 2008-12-22 01:03:32 UTC (rev 78)
@@ -6,9 +6,12 @@
#include <XMLParser.h>
+#include <RenderableNode.h>
+
+MSemaphore UpdateLoopGo;
void* UpdateThread(void* node)
{
- while(true)
+ while( UpdateLoopGo.ReadValue() < 1 )
{
MercuryNode* n = (MercuryNode*)node;
n->RecursiveUpdate(0.01f);
@@ -30,13 +33,13 @@
SAFE_DELETE(doc);
- MercuryThread updateThread;
+// MercuryThread updateThread;
m_time = time(NULL);
- updateThread.Create( UpdateThread, root, false);
+// updateThread.Create( UpdateThread, root, false);
do
{
-// root->RecursiveUpdate(0.01f);
+ root->RecursiveUpdate(0.01f);
// updateThread.Create( UpdateThread, root, false);
RenderableNode::RecursiveRender(root);
w->SwapBuffers();
@@ -48,16 +51,19 @@
printf("FPS: %lu\n", m_count);
m_count = 0;
}
-// updateThread.Wait();
}
while ( w->PumpMessages() );
- updateThread.HaltOnDestroy(true);
- updateThread.Halt();
+// UpdateLoopGo.Increment();
+// updateThread.Wait();
SAFE_DELETE(root);
SAFE_DELETE(w);
+ uint64_t totalWaited = UpdateWaited + RenderWaited;
+ printf("Update wait %%%f\n", (UpdateWaited/double(totalWaited))*100.0f);
+ printf("Render wait %%%f\n", (RenderWaited/double(totalWaited))*100.0f);
+
return 0;
}
Modified: Mercury2/src/RenderableNode.cpp
===================================================================
--- Mercury2/src/RenderableNode.cpp 2008-12-15 01:23:28 UTC (rev 77)
+++ Mercury2/src/RenderableNode.cpp 2008-12-22 01:03:32 UTC (rev 78)
@@ -7,6 +7,9 @@
REGISTER_NODE_TYPE(RenderableNode);
+uint64_t RenderWaited = 0;
+uint64_t UpdateWaited = 0;
+
RenderableNode::RenderableNode()
:m_hidden(false)
{
@@ -21,8 +24,19 @@
void RenderableNode::Update(float dTime)
{
+ static unsigned long waitTime = 0;
MSemaphoreIncOnDestroy s( &m_semaphore );
- Spinlock(0);
+// if ( Spinlock(0) ) ++UpdateWaited;
+// if ( SpinlockWait(0, 100000) ) ++UpdateWaited;
+// UpdateWaited += Spinlock(0);
+
+ int unsigned long waited = SpinlockWait(0, waitTime);
+ if (waited > 0)
+ waitTime = (waitTime<1000000)?waitTime+1000:waitTime;
+ else
+ waitTime = (waitTime!=0)?waitTime-1000:0;
+
+ UpdateWaited += waited;
}
void RenderableNode::Render()
@@ -95,11 +109,21 @@
void RenderableNode::RecursiveRender( MercuryNode* n )
{
+ static unsigned long waitTime = 0;
RenderableNode* rn;
if ( rn = Cast(n) )
{
MSemaphoreDecOnDestroy s( &(rn->m_semaphore) );
- rn->Spinlock(1);
+
+ int unsigned long waited = rn->SpinlockWait(1, waitTime);
+ if (waited > 0)
+ waitTime = (waitTime<1000000)?waitTime+1000:waitTime;
+ else
+ waitTime = (waitTime!=0)?waitTime-1000:0;
+
+ RenderWaited += waited;
+
+// ++RenderWaited += rn->Spinlock(1);
rn->Render();
}
@@ -132,6 +156,27 @@
MercuryNode::LoadFromXML( node );
}
+unsigned long RenderableNode::Spinlock( unsigned long value )
+{
+ unsigned long waited = 0;
+ while (m_semaphore.ReadValue() != value) ++waited;
+ return waited;
+}
+
+unsigned long RenderableNode::SpinlockWait( unsigned long value, unsigned long usec )
+{
+ unsigned long waited = 0;
+ while (m_semaphore.ReadValue() != value)
+ {
+// waited=true;
+ ++waited;
+ if (usec>0) usleep(usec);
+ }
+ return waited;
+}
+
+
+
/***************************************************************************
* Copyright (C) 2008 by Joshua Allen *
* *
Modified: Mercury2/src/RenderableNode.h
===================================================================
--- Mercury2/src/RenderableNode.h 2008-12-15 01:23:28 UTC (rev 77)
+++ Mercury2/src/RenderableNode.h 2008-12-22 01:03:32 UTC (rev 78)
@@ -9,6 +9,9 @@
#define MCHECKASSETS
+extern uint64_t RenderWaited;
+extern uint64_t UpdateWaited;
+
class RenderableNode : public MercuryNode
{
public:
@@ -39,7 +42,8 @@
bool m_hidden;
private:
bool IsInAssetList(MercuryAsset* asset) const;
- inline void Spinlock( unsigned long value ) { while (m_semaphore.ReadValue() != value); }
+ unsigned long Spinlock( unsigned long value );
+ unsigned long SpinlockWait( unsigned long value, unsigned long usec );
std::list< MAutoPtr< MercuryAsset > > m_assets; ///serves as a holder for memory
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-23 19:23:26
|
Revision: 79
http://hgengine.svn.sourceforge.net/hgengine/?rev=79&view=rev
Author: axlecrusher
Date: 2008-12-23 19:23:21 +0000 (Tue, 23 Dec 2008)
Log Message:
-----------
add support for vbo
Added Paths:
-----------
Mercury2/src/MercuryVBO.cpp
Mercury2/src/MercuryVBO.h
Added: Mercury2/src/MercuryVBO.cpp
===================================================================
--- Mercury2/src/MercuryVBO.cpp (rev 0)
+++ Mercury2/src/MercuryVBO.cpp 2008-12-23 19:23:21 UTC (rev 79)
@@ -0,0 +1,123 @@
+#include <MercuryVBO.h>
+
+#define GL_GLEXT_PROTOTYPES
+
+#include <GL/gl.h>
+#include <GL/glext.h>
+
+#include <Texture.h>
+
+#define BUFFER_OFFSET(i) ((char*)NULL + (i))
+
+MercuryVBO::MercuryVBO()
+ :MercuryAsset(), m_vertexData(NULL), m_vMem(NULL), m_vertexIndexList(NULL), m_iMem(NULL), m_initiated(false)
+{
+ m_bufferIDs[0] = m_bufferIDs[1] = 0;
+}
+
+MercuryVBO::~MercuryVBO()
+{
+ SAFE_FREE(m_vMem);
+ SAFE_FREE(m_iMem);
+
+ if (m_bufferIDs[0]) glDeleteBuffersARB(2, m_bufferIDs);
+ m_bufferIDs[0] = m_bufferIDs[1] = 0;
+}
+
+void MercuryVBO::Render(MercuryNode* node)
+{
+// unsigned short numTextures = Texture::NumberActiveTextures();
+ unsigned short stride = sizeof(float)*5;
+
+ if ( m_initiated )
+ {
+ if ( this != m_lastVBOrendered)
+ {
+ glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferIDs[0]);
+ glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_bufferIDs[1]);
+ }
+ }
+ else
+ InitVBO();
+
+ if ( this != m_lastVBOrendered)
+ glVertexPointer(3, GL_FLOAT, stride, 0);
+
+ //XXX This seems to apply texture coordinates to all active texture units
+ glTexCoordPointer(2, GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*3));
+
+ glDrawRangeElements(GL_QUADS, 0, m_bufferLength[1], m_bufferLength[1], GL_UNSIGNED_SHORT, NULL);
+
+ m_lastVBOrendered = this;
+}
+
+void MercuryVBO::InitVBO()
+{
+ glGenBuffersARB(2, m_bufferIDs);
+
+ //vertex VBO
+ glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferIDs[0]);
+ glBufferDataARB(GL_ARRAY_BUFFER_ARB, m_bufferLength[0], m_vertexData, GL_STATIC_DRAW_ARB);
+
+ //indices VBO
+ glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_bufferIDs[1]);
+ glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, sizeof(uint16_t)*m_bufferLength[1], m_vertexIndexList, GL_STATIC_DRAW_ARB);
+
+ SAFE_FREE(m_vMem);
+ SAFE_FREE(m_iMem);
+
+ glEnableClientState(GL_VERTEX_ARRAY);
+
+ m_initiated = true;
+}
+
+void MercuryVBO::AllocateVertexSpace(unsigned int count, unsigned int elementSize)
+{
+ SAFE_FREE(m_vMem);
+ void* mem = NULL;
+ m_vertexData = (char*)mmemalign(32, elementSize*count, mem);
+ m_vMem = (char*)mem;
+ m_bufferLength[0] = elementSize*count;
+}
+
+void MercuryVBO::AllocateIndexSpace(unsigned int count)
+{
+ SAFE_FREE(m_iMem);
+ void* mem = NULL;
+ m_vertexIndexList = (uint16_t*)mmemalign(32, sizeof(uint16_t)*count, mem);
+ m_iMem = (uint16_t*)mem;
+ m_bufferLength[1] = count;
+}
+
+void* MercuryVBO::m_lastVBOrendered = NULL;
+/****************************************************************************
+ * Copyright (C) 2008 by Joshua Allen *
+ * *
+ * *
+ * 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/MercuryVBO.h
===================================================================
--- Mercury2/src/MercuryVBO.h (rev 0)
+++ Mercury2/src/MercuryVBO.h 2008-12-23 19:23:21 UTC (rev 79)
@@ -0,0 +1,60 @@
+#include <MercuryAsset.h>
+
+class MercuryVBO : public MercuryAsset
+{
+ public:
+ MercuryVBO();
+ virtual ~MercuryVBO();
+
+ virtual void Render(MercuryNode* node);
+
+ void AllocateVertexSpace(unsigned int count, unsigned int elementSize);
+ void AllocateIndexSpace(unsigned int count);
+
+ inline char* Buffer() { return m_vertexData; }
+ inline uint16_t* IndexBuffer() { return m_vertexIndexList; }
+ private:
+ virtual void InitVBO();
+
+ unsigned int m_bufferIDs[2];
+ unsigned int m_bufferLength[2];
+
+ char *m_vertexData, *m_vMem;
+ uint16_t *m_vertexIndexList, *m_iMem;
+
+ bool m_initiated;
+
+ static void* m_lastVBOrendered;
+};
+
+/****************************************************************************
+ * Copyright (C) 2008 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-23 19:29:26
|
Revision: 81
http://hgengine.svn.sourceforge.net/hgengine/?rev=81&view=rev
Author: axlecrusher
Date: 2008-12-23 19:29:21 +0000 (Tue, 23 Dec 2008)
Log Message:
-----------
make quad use VBO and instacne quads
Modified Paths:
--------------
Mercury2/src/Quad.cpp
Mercury2/src/Quad.h
Modified: Mercury2/src/Quad.cpp
===================================================================
--- Mercury2/src/Quad.cpp 2008-12-23 19:24:48 UTC (rev 80)
+++ Mercury2/src/Quad.cpp 2008-12-23 19:29:21 UTC (rev 81)
@@ -5,37 +5,49 @@
#include <GL/gl.h>
#include <GL/glext.h>
-#include <Texture.h>
-
REGISTER_ASSET_TYPE(Quad);
-void Quad::Render(MercuryNode* node)
+Quad::Quad()
{
- unsigned short numTextures = Texture::NumberActiveTextures();
- unsigned int i;
+ AllocateIndexSpace(4);
+ AllocateVertexSpace(4, sizeof(float)*5);
- glBegin(GL_QUADS);
+ float* buffer = (float*)Buffer();
+ int i = 0;
- for (i=0; i < numTextures; ++i)
- glMultiTexCoord2f(GL_TEXTURE0+i, 0, 1);
- glVertex3f(-0.5f, -0.5f, 0.0f);
+ buffer[i++] = -0.5; buffer[i++] = -0.5; buffer[i++] = 0.0;
+ buffer[i++] = 0; buffer[i++] = 1;
- for (i=0; i < numTextures; ++i)
- glMultiTexCoord2f(GL_TEXTURE0+i, 1, 1);
- glVertex3f( 0.5f, -0.5f, 0.0f);
+ buffer[i++] = 0.5; buffer[i++] = -0.5; buffer[i++] = 0.0;
+ buffer[i++] = 1; buffer[i++] = 1;
- for (i=0; i < numTextures; ++i)
- glMultiTexCoord2f(GL_TEXTURE0+i, 1, 0);
- glVertex3f( 0.5f, 0.5f, 0.0f);
+ buffer[i++] = 0.5; buffer[i++] = 0.5; buffer[i++] = 0.0;
+ buffer[i++] = 1; buffer[i++] = 0;
-// glTexCoord2f(0,1);
- for (i=0; i < numTextures; ++i)
- glMultiTexCoord2f(GL_TEXTURE0+i, 0, 0);
- glVertex3f(-0.5f, 0.5f, 0.0f);
+ buffer[i++] = -0.5; buffer[i++] = 0.5; buffer[i++] = 0.0;
+ buffer[i++] = 0; buffer[i++] = 0;
+
+ uint16_t* indice = IndexBuffer();
+ indice[0] = 0;
+ indice[1] = 1;
+ indice[2] = 2;
+ indice[3] = 3;
+}
- glEnd();
+Quad::~Quad()
+{
+ m_myInstance = NULL;
}
+Quad* Quad::Generate()
+{
+ if ( !m_myInstance )
+ m_myInstance = new Quad();
+ return m_myInstance;
+}
+
+Quad* Quad::m_myInstance = NULL;
+
/***************************************************************************
* Copyright (C) 2008 by Joshua Allen *
* *
Modified: Mercury2/src/Quad.h
===================================================================
--- Mercury2/src/Quad.h 2008-12-23 19:24:48 UTC (rev 80)
+++ Mercury2/src/Quad.h 2008-12-23 19:29:21 UTC (rev 81)
@@ -1,9 +1,17 @@
#include <MercuryAsset.h>
-class Quad : public MercuryAsset
+#include <MercuryVBO.h>
+
+class Quad : public MercuryVBO
{
public:
- void Render(MercuryNode* node);
+ Quad();
+ ~Quad();
+
+ static Quad* Generate();
+
+ private:
+ static Quad* m_myInstance;
};
/***************************************************************************
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|