From: <axl...@us...> - 2008-12-23 19:30:19
|
Revision: 82 http://hgengine.svn.sourceforge.net/hgengine/?rev=82&view=rev Author: axlecrusher Date: 2008-12-23 19:30:16 +0000 (Tue, 23 Dec 2008) Log Message: ----------- memory aligned allocation Modified Paths: -------------- Mercury2/src/MercuryUtil.cpp Mercury2/src/MercuryUtil.h Modified: Mercury2/src/MercuryUtil.cpp =================================================================== --- Mercury2/src/MercuryUtil.cpp 2008-12-23 19:29:21 UTC (rev 81) +++ Mercury2/src/MercuryUtil.cpp 2008-12-23 19:30:16 UTC (rev 82) @@ -17,6 +17,14 @@ return x; } +void* mmemalign(size_t align, size_t size, void*& mem) +{ + uintptr_t mask = ~(uintptr_t)(align - 1); + mem = malloc(size+align-1); + void *ptr = (void *)(((uintptr_t)mem+align-1) & mask); + return ptr; +} + /*************************************************************************** * Copyright (C) 2008 by Joshua Allen * * * Modified: Mercury2/src/MercuryUtil.h =================================================================== --- Mercury2/src/MercuryUtil.h 2008-12-23 19:29:21 UTC (rev 81) +++ Mercury2/src/MercuryUtil.h 2008-12-23 19:30:16 UTC (rev 82) @@ -9,12 +9,17 @@ #define SAFE_DELETE( x ) { if (x) { delete x; } x = NULL; } #define SAFE_DELETE_ARRAY( x ) { if (x) { delete[] x; } x = NULL; } -#define SAFE_FREE(p) { if(p) { free(p); (p)=0; } } +#define SAFE_FREE(p) { if(p) { free(p); p=0; } } #define TO_ENDIAN( x ) +//returns an aligned pointer, mem is the actual (unaligned) pointer for freeing +void* mmemalign(size_t align, size_t size, void*& mem); + #if defined(__GNUC__) #define M_ALIGN(n) __attribute__((aligned(n))) +//#define MMALLOC(n) memalign(32, n) +//#define MMALLOC(n) malloc(n) #else #define M_ALIGN(n) #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2008-12-23 23:06:38
|
Revision: 85 http://hgengine.svn.sourceforge.net/hgengine/?rev=85&view=rev Author: axlecrusher Date: 2008-12-23 22:53:08 +0000 (Tue, 23 Dec 2008) Log Message: ----------- draw triangles Modified Paths: -------------- Mercury2/src/MercuryVBO.cpp Mercury2/src/Quad.cpp Mercury2/src/X11Window.cpp Modified: Mercury2/src/MercuryVBO.cpp =================================================================== --- Mercury2/src/MercuryVBO.cpp 2008-12-23 19:35:29 UTC (rev 84) +++ Mercury2/src/MercuryVBO.cpp 2008-12-23 22:53:08 UTC (rev 85) @@ -46,7 +46,7 @@ //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); + glDrawRangeElements(GL_TRIANGLES, 0, m_bufferLength[1], m_bufferLength[1], GL_UNSIGNED_SHORT, NULL); m_lastVBOrendered = this; } Modified: Mercury2/src/Quad.cpp =================================================================== --- Mercury2/src/Quad.cpp 2008-12-23 19:35:29 UTC (rev 84) +++ Mercury2/src/Quad.cpp 2008-12-23 22:53:08 UTC (rev 85) @@ -9,7 +9,7 @@ Quad::Quad() { - AllocateIndexSpace(4); + AllocateIndexSpace(6); AllocateVertexSpace(4, sizeof(float)*5); float* buffer = (float*)Buffer(); @@ -31,7 +31,10 @@ indice[0] = 0; indice[1] = 1; indice[2] = 2; - indice[3] = 3; + + indice[3] = 2; + indice[4] = 3; + indice[5] = 0; } Quad::~Quad() Modified: Mercury2/src/X11Window.cpp =================================================================== --- Mercury2/src/X11Window.cpp 2008-12-23 19:35:29 UTC (rev 84) +++ Mercury2/src/X11Window.cpp 2008-12-23 22:53:08 UTC (rev 85) @@ -70,7 +70,9 @@ XFree(visinfo); m_window = win; - m_renderCtx = ctx; + m_renderCtx = ctx; + + glEnable(GL_CULL_FACE); } X11Window::~X11Window() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2008-12-25 01:20:31
|
Revision: 87 http://hgengine.svn.sourceforge.net/hgengine/?rev=87&view=rev Author: axlecrusher Date: 2008-12-25 01:20:29 +0000 (Thu, 25 Dec 2008) Log Message: ----------- Clean up how VBO and quads work using the AlignedBuffer Modified Paths: -------------- Mercury2/src/AlignedBuffer.h Mercury2/src/Mercury2.cpp Mercury2/src/MercuryVBO.cpp Mercury2/src/MercuryVBO.h Mercury2/src/Quad.cpp Modified: Mercury2/src/AlignedBuffer.h =================================================================== --- Mercury2/src/AlignedBuffer.h 2008-12-25 01:15:26 UTC (rev 86) +++ Mercury2/src/AlignedBuffer.h 2008-12-25 01:20:29 UTC (rev 87) @@ -31,10 +31,7 @@ inline T* Buffer() { return m_data; } - T& operator[](unsigned long x) - { - return m_data[x]; - } + inline T& operator[](unsigned long x) { return m_data[x]; } private: unsigned long m_length; Modified: Mercury2/src/Mercury2.cpp =================================================================== --- Mercury2/src/Mercury2.cpp 2008-12-25 01:15:26 UTC (rev 86) +++ Mercury2/src/Mercury2.cpp 2008-12-25 01:20:29 UTC (rev 87) @@ -16,6 +16,7 @@ MercuryNode* n = (MercuryNode*)node; n->RecursiveUpdate(0.01f); } + return NULL; } int main() Modified: Mercury2/src/MercuryVBO.cpp =================================================================== --- Mercury2/src/MercuryVBO.cpp 2008-12-25 01:15:26 UTC (rev 86) +++ Mercury2/src/MercuryVBO.cpp 2008-12-25 01:20:29 UTC (rev 87) @@ -10,16 +10,13 @@ #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) + :MercuryAsset(), 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; } @@ -46,7 +43,7 @@ //XXX This seems to apply texture coordinates to all active texture units glTexCoordPointer(2, GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*3)); - glDrawRangeElements(GL_TRIANGLES, 0, m_bufferLength[1], m_bufferLength[1], GL_UNSIGNED_SHORT, NULL); + glDrawRangeElements(GL_TRIANGLES, 0, m_indexData.Length()-1, m_indexData.Length(), GL_UNSIGNED_SHORT, NULL); m_lastVBOrendered = this; } @@ -57,36 +54,25 @@ //vertex VBO glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_bufferIDs[0]); - glBufferDataARB(GL_ARRAY_BUFFER_ARB, m_bufferLength[0], m_vertexData, GL_STATIC_DRAW_ARB); + glBufferDataARB(GL_ARRAY_BUFFER_ARB, m_vertexData.LengthInBytes(), m_vertexData.Buffer(), 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); - + glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, m_indexData.LengthInBytes(), m_indexData.Buffer(), GL_STATIC_DRAW_ARB); + glEnableClientState(GL_VERTEX_ARRAY); m_initiated = true; } -void MercuryVBO::AllocateVertexSpace(unsigned int count, unsigned int elementSize) +void MercuryVBO::AllocateVertexSpace(unsigned int count) { - SAFE_FREE(m_vMem); - void* mem = NULL; - m_vertexData = (char*)mmemalign(32, elementSize*count, mem); - m_vMem = (char*)mem; - m_bufferLength[0] = elementSize*count; + m_vertexData.Allocate(count*5); } 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; + m_indexData.Allocate(count); } void* MercuryVBO::m_lastVBOrendered = NULL; Modified: Mercury2/src/MercuryVBO.h =================================================================== --- Mercury2/src/MercuryVBO.h 2008-12-25 01:15:26 UTC (rev 86) +++ Mercury2/src/MercuryVBO.h 2008-12-25 01:20:29 UTC (rev 87) @@ -1,4 +1,5 @@ #include <MercuryAsset.h> +#include <AlignedBuffer.h> class MercuryVBO : public MercuryAsset { @@ -8,23 +9,19 @@ virtual void Render(MercuryNode* node); - void AllocateVertexSpace(unsigned int count, unsigned int elementSize); + void AllocateVertexSpace(unsigned int count); 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; - + bool m_initiated; static void* m_lastVBOrendered; + + protected: + AlignedBuffer<float> m_vertexData; + AlignedBuffer<uint16_t> m_indexData; }; /**************************************************************************** Modified: Mercury2/src/Quad.cpp =================================================================== --- Mercury2/src/Quad.cpp 2008-12-25 01:15:26 UTC (rev 86) +++ Mercury2/src/Quad.cpp 2008-12-25 01:20:29 UTC (rev 87) @@ -10,36 +10,33 @@ Quad::Quad() { AllocateIndexSpace(6); - AllocateVertexSpace(4, sizeof(float)*5); + AllocateVertexSpace(4); - float* buffer = (float*)Buffer(); +// float* buffer = m_vertexData.m_vertexData(); int i = 0; - buffer[i++] = -0.5; buffer[i++] = -0.5; buffer[i++] = 0.0; - buffer[i++] = 0; buffer[i++] = 1; + m_vertexData[i++] = -0.5; m_vertexData[i++] = -0.5; m_vertexData[i++] = 0.0; + m_vertexData[i++] = 0; m_vertexData[i++] = 1; - buffer[i++] = 0.5; buffer[i++] = -0.5; buffer[i++] = 0.0; - buffer[i++] = 1; buffer[i++] = 1; + m_vertexData[i++] = 0.5; m_vertexData[i++] = -0.5; m_vertexData[i++] = 0.0; + m_vertexData[i++] = 1; m_vertexData[i++] = 1; - buffer[i++] = 0.5; buffer[i++] = 0.5; buffer[i++] = 0.0; - buffer[i++] = 1; buffer[i++] = 0; + m_vertexData[i++] = 0.5; m_vertexData[i++] = 0.5; m_vertexData[i++] = 0.0; + m_vertexData[i++] = 1; m_vertexData[i++] = 0; - buffer[i++] = -0.5; buffer[i++] = 0.5; buffer[i++] = 0.0; - buffer[i++] = 0; buffer[i++] = 0; + m_vertexData[i++] = -0.5; m_vertexData[i++] = 0.5; m_vertexData[i++] = 0.0; + m_vertexData[i++] = 0; m_vertexData[i++] = 0; - uint16_t* indice = IndexBuffer(); - indice[0] = 0; - indice[1] = 1; - indice[2] = 2; - - indice[3] = 2; - indice[4] = 3; - indice[5] = 0; + m_indexData[5] = m_indexData[0] = 0; + m_indexData[1] = 1; + m_indexData[3] = m_indexData[2] = 2; + m_indexData[4] = 3; } Quad::~Quad() { - m_myInstance = NULL; + if (m_myInstance == this) + m_myInstance = NULL; } Quad* Quad::Generate() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2008-12-29 03:15:57
|
Revision: 88 http://hgengine.svn.sourceforge.net/hgengine/?rev=88&view=rev Author: axlecrusher Date: 2008-12-29 03:15:55 +0000 (Mon, 29 Dec 2008) Log Message: ----------- add normals Modified Paths: -------------- Mercury2/src/MercuryVBO.cpp Mercury2/src/Quad.cpp Modified: Mercury2/src/MercuryVBO.cpp =================================================================== --- Mercury2/src/MercuryVBO.cpp 2008-12-25 01:20:29 UTC (rev 87) +++ Mercury2/src/MercuryVBO.cpp 2008-12-29 03:15:55 UTC (rev 88) @@ -24,7 +24,7 @@ void MercuryVBO::Render(MercuryNode* node) { // unsigned short numTextures = Texture::NumberActiveTextures(); - unsigned short stride = sizeof(float)*5; + unsigned short stride = sizeof(float)*8; if ( m_initiated ) { @@ -38,10 +38,10 @@ InitVBO(); if ( this != m_lastVBOrendered) - glVertexPointer(3, GL_FLOAT, stride, 0); + glVertexPointer(3, GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*5)); //XXX This seems to apply texture coordinates to all active texture units - glTexCoordPointer(2, GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*3)); + glTexCoordPointer(2, GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*0)); glDrawRangeElements(GL_TRIANGLES, 0, m_indexData.Length()-1, m_indexData.Length(), GL_UNSIGNED_SHORT, NULL); @@ -67,7 +67,7 @@ void MercuryVBO::AllocateVertexSpace(unsigned int count) { - m_vertexData.Allocate(count*5); + m_vertexData.Allocate(count*8); } void MercuryVBO::AllocateIndexSpace(unsigned int count) Modified: Mercury2/src/Quad.cpp =================================================================== --- Mercury2/src/Quad.cpp 2008-12-25 01:20:29 UTC (rev 87) +++ Mercury2/src/Quad.cpp 2008-12-29 03:15:55 UTC (rev 88) @@ -15,17 +15,21 @@ // float* buffer = m_vertexData.m_vertexData(); int i = 0; + m_vertexData[i++] = 0; m_vertexData[i++] = 1; + m_vertexData[i++] = 0; m_vertexData[i++] = 0; m_vertexData[i++] = -1.0; m_vertexData[i++] = -0.5; m_vertexData[i++] = -0.5; m_vertexData[i++] = 0.0; - m_vertexData[i++] = 0; m_vertexData[i++] = 1; + m_vertexData[i++] = 1; m_vertexData[i++] = 1; + m_vertexData[i++] = 0; m_vertexData[i++] = 0; m_vertexData[i++] = -1.0; m_vertexData[i++] = 0.5; m_vertexData[i++] = -0.5; m_vertexData[i++] = 0.0; - m_vertexData[i++] = 1; m_vertexData[i++] = 1; + m_vertexData[i++] = 1; m_vertexData[i++] = 0; + m_vertexData[i++] = 0; m_vertexData[i++] = 0; m_vertexData[i++] = -1.0; m_vertexData[i++] = 0.5; m_vertexData[i++] = 0.5; m_vertexData[i++] = 0.0; - m_vertexData[i++] = 1; m_vertexData[i++] = 0; + m_vertexData[i++] = 0; m_vertexData[i++] = 0; + m_vertexData[i++] = 0; m_vertexData[i++] = 0; m_vertexData[i++] = -1.0; m_vertexData[i++] = -0.5; m_vertexData[i++] = 0.5; m_vertexData[i++] = 0.0; - m_vertexData[i++] = 0; m_vertexData[i++] = 0; m_indexData[5] = m_indexData[0] = 0; m_indexData[1] = 1; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2008-12-30 05:11:45
|
Revision: 92 http://hgengine.svn.sourceforge.net/hgengine/?rev=92&view=rev Author: cnlohr Date: 2008-12-30 05:11:42 +0000 (Tue, 30 Dec 2008) Log Message: ----------- fix warnings Modified Paths: -------------- Mercury2/src/BMPLoader.cpp Mercury2/src/RenderableNode.cpp Mercury2/src/Texture.cpp Modified: Mercury2/src/BMPLoader.cpp =================================================================== --- Mercury2/src/BMPLoader.cpp 2008-12-30 04:59:37 UTC (rev 91) +++ Mercury2/src/BMPLoader.cpp 2008-12-30 05:11:42 UTC (rev 92) @@ -140,7 +140,7 @@ unsigned long row, pixel; unsigned char* rowPtr; - for (unsigned int x = 0; !feof(file) && (x+3 < rawlength); x += 3) + for (unsigned int x = 0; !feof(file) && (x+3 < (unsigned)rawlength); x += 3) { memset(b, 0, sizeof(unsigned char) * 3); // file->Read((char*)&b, sizeof(unsigned char) * 3); Modified: Mercury2/src/RenderableNode.cpp =================================================================== --- Mercury2/src/RenderableNode.cpp 2008-12-30 04:59:37 UTC (rev 91) +++ Mercury2/src/RenderableNode.cpp 2008-12-30 05:11:42 UTC (rev 92) @@ -111,7 +111,7 @@ { static unsigned long waitTime = 0; RenderableNode* rn; - if ( rn = Cast(n) ) + if ( ( rn = Cast(n) ) ) { MSemaphoreDecOnDestroy s( &(rn->m_semaphore) ); Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2008-12-30 04:59:37 UTC (rev 91) +++ Mercury2/src/Texture.cpp 2008-12-30 05:11:42 UTC (rev 92) @@ -52,6 +52,11 @@ break; case RGBA: ByteType = GL_RGBA; + break; + default: + printf( "Unsupported byte type (%d) in Texture::LoadFromRaw\n", m_raw->m_ColorByteType ); + ByteType = GL_RGB; + break; } glBindTexture(GL_TEXTURE_2D, m_textureID); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2008-12-30 14:52:19
|
Revision: 93 http://hgengine.svn.sourceforge.net/hgengine/?rev=93&view=rev Author: axlecrusher Date: 2008-12-30 14:52:16 +0000 (Tue, 30 Dec 2008) Log Message: ----------- Add models Added Paths: ----------- Mercury2/src/HGMDLMesh.cpp Mercury2/src/HGMDLMesh.h Mercury2/src/HGMDLModel.cpp Mercury2/src/HGMDLModel.h Added: Mercury2/src/HGMDLMesh.cpp =================================================================== --- Mercury2/src/HGMDLMesh.cpp (rev 0) +++ Mercury2/src/HGMDLMesh.cpp 2008-12-30 14:52:16 UTC (rev 93) @@ -0,0 +1,65 @@ +#include <HGMDLMesh.h> + +void HGMDLMesh::LoadFromFile(FILE* hgmdl) +{ + uint32_t nameLength; + fread(&nameLength, sizeof(uint32_t), 1, hgmdl); + + if (nameLength > 0) + { + char* name = new char[nameLength+1]; + name[nameLength] = 0; + fread(name, nameLength, 1, hgmdl); + m_name = name; + } + + fread(&m_cachable, sizeof(bool), 1, hgmdl); + + uint32_t dataLength; + fread(&dataLength, sizeof(uint32_t), 1, hgmdl); + if (dataLength > 0) + { + m_vertexData.Allocate( dataLength/sizeof(float) ); //they are all floats + fread(m_vertexData.Buffer(), dataLength, 1, hgmdl); + } + + uint16_t numIndices; + fread(&numIndices, sizeof(uint16_t), 1, hgmdl); + if (numIndices > 0) + { + m_indexData.Allocate( numIndices ); + fread(m_indexData.Buffer(), numIndices*sizeof(uint16_t), 1, hgmdl); + } +} + +/**************************************************************************** + * 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/HGMDLMesh.h =================================================================== --- Mercury2/src/HGMDLMesh.h (rev 0) +++ Mercury2/src/HGMDLMesh.h 2008-12-30 14:52:16 UTC (rev 93) @@ -0,0 +1,44 @@ +#include <MercuryVBO.h> + +class HGMDLMesh : public MercuryVBO +{ + public: + void LoadFromFile(FILE* hgmdl); + private: + string m_name; + bool m_cachable; +}; + +/**************************************************************************** + * 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/HGMDLModel.cpp =================================================================== --- Mercury2/src/HGMDLModel.cpp (rev 0) +++ Mercury2/src/HGMDLModel.cpp 2008-12-30 14:52:16 UTC (rev 93) @@ -0,0 +1,91 @@ +#include <HGMDLModel.h> + +REGISTER_ASSET_TYPE(HGMDLModel); + +void HGMDLModel::LoadFromXML(const XMLNode& node) +{ + if ( !node.Attribute("file").empty() ) + { + FILE* f = fopen( node.Attribute("file").c_str(), "rb" ); + LoadModel( f ); + fclose( f ); + } +} + +void HGMDLModel::LoadModel(FILE* hgmdl) +{ + char fingerPrint[5]; + fingerPrint[5] = 0; + fread(fingerPrint, 4, 1, hgmdl); + + string p(fingerPrint); + if (p != "MBMF") + { + printf("Not a HGMDL file.\n"); + return; + } + + uint32_t version; + fread(&version, 4, 1, hgmdl); + + if (version != 200) + { + printf("Invalid HGMDL version %d\n", version); + return; + } + + uint16_t numMeshes; + fread(&numMeshes, sizeof(uint16_t), 1, hgmdl); + for (uint16_t i = 0; i < numMeshes; ++i) + { + HGMDLMesh *mesh = new HGMDLMesh(); + mesh->LoadFromFile( hgmdl ); + m_meshes.push_back(mesh); + } +} + +void HGMDLModel::Render(MercuryNode* node) +{ + list< HGMDLMesh* >::iterator i = m_meshes.begin(); + for(;i != m_meshes.end(); ++i) + { + (*i)->Render(node); + } +} + +HGMDLModel* HGMDLModel::Generate() +{ + return new HGMDLModel(); +} + +/**************************************************************************** + * 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/HGMDLModel.h =================================================================== --- Mercury2/src/HGMDLModel.h (rev 0) +++ Mercury2/src/HGMDLModel.h 2008-12-30 14:52:16 UTC (rev 93) @@ -0,0 +1,49 @@ +#include <MercuryAsset.h> +#include <HGMDLMesh.h> + +class HGMDLModel : public MercuryAsset +{ + public: + + virtual void LoadFromXML(const XMLNode& node); + + void LoadModel(FILE* hgmdl); + + static HGMDLModel* Generate(); + virtual void Render(MercuryNode* node); + + private: + std::list< HGMDLMesh* > m_meshes; +}; + +/**************************************************************************** + * 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-30 15:09:03
|
Revision: 95 http://hgengine.svn.sourceforge.net/hgengine/?rev=95&view=rev Author: axlecrusher Date: 2008-12-30 15:08:53 +0000 (Tue, 30 Dec 2008) Log Message: ----------- fix header defines Modified Paths: -------------- Mercury2/src/AlignedBuffer.h Mercury2/src/HGMDLMesh.h Mercury2/src/HGMDLModel.h Mercury2/src/MercuryPoint.h Mercury2/src/MercuryVBO.cpp Mercury2/src/MercuryVBO.h Mercury2/src/Quad.h Mercury2/src/Texture.h Mercury2/src/TransformNode.h Mercury2/src/Viewport.h Mercury2/src/X11Window.h Modified: Mercury2/src/AlignedBuffer.h =================================================================== --- Mercury2/src/AlignedBuffer.h 2008-12-30 14:53:52 UTC (rev 94) +++ Mercury2/src/AlignedBuffer.h 2008-12-30 15:08:53 UTC (rev 95) @@ -1,3 +1,5 @@ +#ifndef ALIGNEDBUFFER_H +#define ALIGNEDBUFFER_H template <typename T> class AlignedBuffer @@ -38,6 +40,8 @@ T* m_data, *m_mem; }; +#endif + /**************************************************************************** * Copyright (C) 2008 by Joshua Allen * * * Modified: Mercury2/src/HGMDLMesh.h =================================================================== --- Mercury2/src/HGMDLMesh.h 2008-12-30 14:53:52 UTC (rev 94) +++ Mercury2/src/HGMDLMesh.h 2008-12-30 15:08:53 UTC (rev 95) @@ -1,3 +1,6 @@ +#ifndef HGMDLMESH_H +#define HGMDLMESH_H + #include <MercuryVBO.h> class HGMDLMesh : public MercuryVBO @@ -9,6 +12,8 @@ bool m_cachable; }; +#endif + /**************************************************************************** * Copyright (C) 2008 by Joshua Allen * * * Modified: Mercury2/src/HGMDLModel.h =================================================================== --- Mercury2/src/HGMDLModel.h 2008-12-30 14:53:52 UTC (rev 94) +++ Mercury2/src/HGMDLModel.h 2008-12-30 15:08:53 UTC (rev 95) @@ -1,3 +1,6 @@ +#ifndef HGMDLMODEL_H +#define HGMDLMODEL_H + #include <MercuryAsset.h> #include <HGMDLMesh.h> @@ -16,6 +19,8 @@ std::list< HGMDLMesh* > m_meshes; }; +#endif + /**************************************************************************** * Copyright (C) 2008 by Joshua Allen * * * Modified: Mercury2/src/MercuryPoint.h =================================================================== --- Mercury2/src/MercuryPoint.h 2008-12-30 14:53:52 UTC (rev 94) +++ Mercury2/src/MercuryPoint.h 2008-12-30 15:08:53 UTC (rev 95) @@ -1,3 +1,6 @@ +#ifndef MERCURYPOINT_H +#define MERCURYPOINT_H + ///A point in space/vector class MercuryPoint { @@ -77,6 +80,8 @@ float z; }; +#endif + /*************************************************************************** * Copyright (C) 2008 by Joshua Allen, Charles Lohr * * * Modified: Mercury2/src/MercuryVBO.cpp =================================================================== --- Mercury2/src/MercuryVBO.cpp 2008-12-30 14:53:52 UTC (rev 94) +++ Mercury2/src/MercuryVBO.cpp 2008-12-30 15:08:53 UTC (rev 95) @@ -23,8 +23,8 @@ void MercuryVBO::Render(MercuryNode* node) { - unsigned short numTextures = Texture::NumberActiveTextures(); - unsigned short stride = sizeof(float)*8; + uint8_t numTextures = Texture::NumberActiveTextures(); + uint16_t stride = sizeof(float)*8; if ( m_initiated ) { Modified: Mercury2/src/MercuryVBO.h =================================================================== --- Mercury2/src/MercuryVBO.h 2008-12-30 14:53:52 UTC (rev 94) +++ Mercury2/src/MercuryVBO.h 2008-12-30 15:08:53 UTC (rev 95) @@ -1,3 +1,6 @@ +#ifndef MERCURYVBO_H +#define MERCURYVBO_H + #include <MercuryAsset.h> #include <AlignedBuffer.h> @@ -24,6 +27,8 @@ AlignedBuffer<uint16_t> m_indexData; }; +#endif + /**************************************************************************** * Copyright (C) 2008 by Joshua Allen * * * Modified: Mercury2/src/Quad.h =================================================================== --- Mercury2/src/Quad.h 2008-12-30 14:53:52 UTC (rev 94) +++ Mercury2/src/Quad.h 2008-12-30 15:08:53 UTC (rev 95) @@ -1,5 +1,7 @@ +#ifndef MERCURYQUAD_H +#define MERCURYQUAD_H + #include <MercuryAsset.h> - #include <MercuryVBO.h> class Quad : public MercuryVBO @@ -14,6 +16,8 @@ static Quad* m_myInstance; }; +#endif + /*************************************************************************** * Copyright (C) 2008 by Joshua Allen * * * Modified: Mercury2/src/Texture.h =================================================================== --- Mercury2/src/Texture.h 2008-12-30 14:53:52 UTC (rev 94) +++ Mercury2/src/Texture.h 2008-12-30 15:08:53 UTC (rev 95) @@ -1,3 +1,6 @@ +#ifndef TEXTURE_H +#define TEXTURE_H + #include <MercuryAsset.h> #include <RawImageData.h> @@ -31,6 +34,8 @@ static unsigned short m_activeTextures; }; +#endif + /*************************************************************************** * Copyright (C) 2008 by Joshua Allen * * * Modified: Mercury2/src/TransformNode.h =================================================================== --- Mercury2/src/TransformNode.h 2008-12-30 14:53:52 UTC (rev 94) +++ Mercury2/src/TransformNode.h 2008-12-30 15:08:53 UTC (rev 95) @@ -1,3 +1,6 @@ +#ifndef TRANSFORMNODE_H +#define TRANSFORMNODE_H + #include <MercuryNode.h> #include <MercuryPoint.h> #include <MercuryMatrix.h> @@ -45,6 +48,8 @@ bool m_tainted; }; +#endif + /**************************************************************************** * Copyright (C) 2008 by Joshua Allen * * * Modified: Mercury2/src/Viewport.h =================================================================== --- Mercury2/src/Viewport.h 2008-12-30 14:53:52 UTC (rev 94) +++ Mercury2/src/Viewport.h 2008-12-30 15:08:53 UTC (rev 95) @@ -1,3 +1,6 @@ +#ifndef VIEWPORT_H +#define VIEWPORT_H + #include <RenderableNode.h> #include <MercuryMatrix.h> class Viewport : public RenderableNode @@ -14,6 +17,8 @@ MercuryMatrix m_frustum; }; +#endif + /*************************************************************************** * Copyright (C) 2008 by Joshua Allen * * * Modified: Mercury2/src/X11Window.h =================================================================== --- Mercury2/src/X11Window.h 2008-12-30 14:53:52 UTC (rev 94) +++ Mercury2/src/X11Window.h 2008-12-30 15:08:53 UTC (rev 95) @@ -1,3 +1,6 @@ +#ifndef X11WINDOW_H +#define X11WINDOW_H + #include <MercuryWindow.h> #include <X11/Xlib.h> #include <GL/glx.h> @@ -23,6 +26,8 @@ Atom m_wmDeleteMessage; }; +#endif + /*************************************************************************** * Copyright (C) 2008 by Joshua Allen * * * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2008-12-30 15:15:12
|
Revision: 96 http://hgengine.svn.sourceforge.net/hgengine/?rev=96&view=rev Author: axlecrusher Date: 2008-12-30 15:15:02 +0000 (Tue, 30 Dec 2008) Log Message: ----------- use MAutoPtr Modified Paths: -------------- Mercury2/src/HGMDLModel.cpp Mercury2/src/HGMDLModel.h Modified: Mercury2/src/HGMDLModel.cpp =================================================================== --- Mercury2/src/HGMDLModel.cpp 2008-12-30 15:08:53 UTC (rev 95) +++ Mercury2/src/HGMDLModel.cpp 2008-12-30 15:15:02 UTC (rev 96) @@ -38,7 +38,7 @@ fread(&numMeshes, sizeof(uint16_t), 1, hgmdl); for (uint16_t i = 0; i < numMeshes; ++i) { - HGMDLMesh *mesh = new HGMDLMesh(); + MAutoPtr< HGMDLMesh > mesh( new HGMDLMesh() ); mesh->LoadFromFile( hgmdl ); m_meshes.push_back(mesh); } @@ -46,11 +46,9 @@ void HGMDLModel::Render(MercuryNode* node) { - list< HGMDLMesh* >::iterator i = m_meshes.begin(); + list< MAutoPtr< HGMDLMesh > >::iterator i = m_meshes.begin(); for(;i != m_meshes.end(); ++i) - { (*i)->Render(node); - } } HGMDLModel* HGMDLModel::Generate() Modified: Mercury2/src/HGMDLModel.h =================================================================== --- Mercury2/src/HGMDLModel.h 2008-12-30 15:08:53 UTC (rev 95) +++ Mercury2/src/HGMDLModel.h 2008-12-30 15:15:02 UTC (rev 96) @@ -16,7 +16,7 @@ virtual void Render(MercuryNode* node); private: - std::list< HGMDLMesh* > m_meshes; + std::list< MAutoPtr< HGMDLMesh > > m_meshes; }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2008-12-30 21:25:12
|
Revision: 107 http://hgengine.svn.sourceforge.net/hgengine/?rev=107&view=rev Author: cnlohr Date: 2008-12-30 21:25:06 +0000 (Tue, 30 Dec 2008) Log Message: ----------- add MercuryString Added Paths: ----------- Mercury2/src/MercuryString.cpp Mercury2/src/MercuryString.h Added: Mercury2/src/MercuryString.cpp =================================================================== --- Mercury2/src/MercuryString.cpp (rev 0) +++ Mercury2/src/MercuryString.cpp 2008-12-30 21:25:06 UTC (rev 107) @@ -0,0 +1,453 @@ +#include "MercuryString.h" +#include <stdlib.h> +#include <string.h> + +//For ssprintf. +#include <stdarg.h> +#include <stdio.h> + +#define BASE_ALLOC 16 + +#define NEXT_ALLOC( x, y ) ( x + y + BASE_ALLOC ) + +#define MANAGE_ALLOC( y ) \ + if ( m_iLen + y + 1 > m_iAlloc ) \ + { \ + m_iAlloc = NEXT_ALLOC( m_iLen, y ); \ + m_sCur = (char*)realloc( m_sCur, m_iAlloc ); \ + } + +MString::MString() +{ + m_sCur = (char*)malloc( BASE_ALLOC ); + m_sCur[0] = '\0'; + m_iLen = 0; + m_iAlloc = BASE_ALLOC; +} + +MString::MString( int iPreAlloc ) +{ + m_sCur = (char*)malloc( iPreAlloc ); + m_sCur[0] = '\0'; + m_iLen = 0; + m_iAlloc = iPreAlloc; +} + +MString::MString( const char sIn ) +{ + m_iLen = 1; + m_iAlloc = 2; + m_sCur = (char*)malloc( m_iAlloc ); + m_sCur[0] = sIn; + m_sCur[1] = '\0'; +} + +MString::MString( const char * sIn ) +{ + m_iLen = strlen( sIn ); + m_iAlloc = m_iLen + 1; + m_sCur = (char*)malloc( m_iAlloc ); + memcpy( m_sCur, sIn, m_iAlloc ); +} + +MString::MString( const char * sIn, int iSize ) +{ + m_iLen = iSize; + m_iAlloc = m_iLen + 1; + m_sCur = (char*)malloc( m_iAlloc ); + memcpy( m_sCur, sIn, m_iLen ); + m_sCur[m_iLen] = '\0'; +} + +MString::MString( const MString & rhs ) +{ + m_iLen = rhs.m_iLen; + m_iAlloc = rhs.m_iAlloc; + m_sCur = (char*)malloc( m_iAlloc ); + memcpy( m_sCur, rhs.m_sCur, m_iLen ); + m_sCur[m_iLen] = '\0'; +} + +MString::~MString() +{ + free(m_sCur); +} + +const MString & MString::operator = ( const MString & rhs ) +{ + if (&rhs != this) + { + free (m_sCur); + m_iLen = rhs.m_iLen; + m_iAlloc = rhs.m_iAlloc; + m_sCur = (char*)malloc( m_iAlloc ); + memcpy( m_sCur, rhs.m_sCur, m_iLen ); + m_sCur[m_iLen] = '\0'; + } + return (*this); +} + +const MString & MString::operator = ( const char * rhs ) +{ + if (rhs != m_sCur) + { + free (m_sCur); + m_iLen = strlen( rhs ); + m_iAlloc = m_iLen + 1; + m_sCur = (char*)malloc( m_iAlloc ); + memcpy( m_sCur, rhs, m_iAlloc ); + } + return (*this); +} + +const MString MString::operator + ( const MString & rhs ) const +{ + int iNextMalloc = NEXT_ALLOC( m_iLen, rhs.m_iLen ); + MString ret( iNextMalloc ); + ret.m_iLen = m_iLen + rhs.m_iLen; + memcpy( ret.m_sCur, m_sCur, m_iLen ); + memcpy( ret.m_sCur + m_iLen, rhs.m_sCur, rhs.m_iLen ); + ret.m_sCur[ret.m_iLen] = '\0'; + return ret; +} + +const MString MString::operator + ( const char * rhs ) const +{ + if ( !rhs ) + return (*this); + int iRhsLen = strlen( rhs ); + int iNextMalloc = NEXT_ALLOC( m_iLen, iRhsLen ); + MString ret( iNextMalloc ); + ret.m_iLen = m_iLen + iRhsLen; + memcpy( ret.m_sCur, m_sCur, m_iLen ); + memcpy( ret.m_sCur + m_iLen, rhs, iRhsLen ); + ret.m_sCur[ret.m_iLen] = '\0'; + return ret; +} + +const MString MString::operator + ( const char rhs ) const +{ + int iNextMalloc = NEXT_ALLOC( m_iLen, 1 ); + MString ret( iNextMalloc ); + ret.m_iLen = m_iLen + 1; + memcpy( ret.m_sCur, m_sCur, m_iLen ); + ret.m_sCur[ret.m_iLen - 1] = rhs; + ret.m_sCur[ret.m_iLen] = '\0'; + return ret; +} + +const MString & MString::operator += ( const char * rhs ) +{ + int iRhsLen = strlen( rhs ); + MANAGE_ALLOC( iRhsLen ) + memcpy( m_sCur + m_iLen, rhs, iRhsLen ); + m_iLen += iRhsLen; + m_sCur[m_iLen] = '\0'; + return (*this); +} + +const MString & MString::operator += ( const MString & rhs ) +{ + MANAGE_ALLOC( rhs.m_iLen ) + memcpy( m_sCur + m_iLen, rhs.m_sCur, rhs.m_iLen ); + m_iLen += rhs.m_iLen; + m_sCur[m_iLen] = '\0'; + return (*this); +} + +const MString & MString::operator += ( const char rhs ) +{ + MANAGE_ALLOC( 1 ) + m_sCur[m_iLen] = rhs; + m_iLen++; + m_sCur[m_iLen] = '\0'; + return (*this); +} + +bool MString::operator == ( const MString & rhs ) +{ + return strcmp( m_sCur, rhs.m_sCur ) == 0; +} + +bool MString::operator == ( const char * rhs ) +{ + return strcmp( m_sCur, rhs ) == 0; +} + +bool MString::operator < ( const MString & rhs ) +{ + return strcmp( m_sCur, rhs.m_sCur ) < 0; +} + +bool MString::operator > ( const MString & rhs ) +{ + return strcmp( m_sCur, rhs.m_sCur ) > 0; +} + +void MString::append( const MString & app ) +{ + MANAGE_ALLOC( app.m_iLen ) + memcpy( m_sCur + m_iLen, app.m_sCur, app.m_iLen ); + m_iLen += app.m_iLen; + m_sCur[m_iLen] = '\0'; +} + +void MString::append( const char app ) +{ + MANAGE_ALLOC( 1 ) + m_sCur[m_iLen] = app; + m_iLen++; + m_sCur[m_iLen] = '\0'; +} + +void MString::append( const char * app ) +{ + int iRhsLen = strlen( app ); + MANAGE_ALLOC( iRhsLen ) + memcpy( m_sCur + m_iLen, app, iRhsLen ); + m_iLen += iRhsLen; + m_sCur[m_iLen] = '\0'; +} + +void MString::append( const char * app, int len ) +{ + MANAGE_ALLOC( len ) + memcpy( m_sCur + m_iLen, app, len ); + m_iLen += len; + m_sCur[m_iLen] = '\0'; +} + +void MString::append( const char app, int len ) +{ + MANAGE_ALLOC( len ) + memset( m_sCur + m_iLen, app, len ); + m_iLen += len; + m_sCur[m_iLen] = '\0'; +} + +void MString::assign( const MString & app ) +{ + free( m_sCur ); + m_iLen = app.m_iLen; + m_iAlloc = app.m_iAlloc; + m_sCur = (char*)malloc( m_iAlloc ); + memcpy( m_sCur, app.m_sCur, m_iLen ); + m_sCur[m_iLen] = '\0'; +} + +void MString::assign( const char * app ) +{ + free( m_sCur ); + m_iLen = strlen( app ); + m_iAlloc = m_iLen + 1; + m_sCur = (char*)malloc( m_iAlloc ); + memcpy( m_sCur, app, m_iAlloc ); +} + +void MString::assign( const char * app, int len ) +{ + free( m_sCur ); + m_iLen = len; + m_iAlloc = m_iLen + 1; + m_sCur = (char*)malloc( m_iAlloc ); + memcpy( m_sCur, app, m_iLen ); + m_sCur[m_iLen] = '\0'; +} + +int MString::find( const MString & tofind, int start ) const +{ + const char * ret = strstr( m_sCur + start, tofind.m_sCur ); + return (ret)?(ret-m_sCur):npos; +} + +int MString::rfind( const MString & tofind ) const +{ + int iLen = tofind.length(); + int iTarg = m_iLen - iLen; + + while ( iTarg >= 0 ) + { + if ( strncmp( tofind.m_sCur+iTarg, tofind, iLen ) == 0 ) + return iTarg; + iTarg--; + } + return npos; +} + +int MString::find( const char * tofind, int start ) const +{ + const char * ret = strstr( m_sCur + start, tofind ); + return (ret)?(ret-m_sCur):npos; +} + +int MString::rfind( const char * tofind ) const +{ + int iLen = strlen( tofind ); + int iTarg = m_iLen - iLen; + + while ( iTarg >= 0 ) + { + if ( strncmp( m_sCur+iTarg, tofind, iLen ) == 0 ) + return iTarg; + iTarg--; + } + return npos; +} + +int MString::find( const char tofind, int start ) const +{ + const char * ret = strchr( m_sCur + start, tofind ); + return (ret)?(ret-m_sCur):npos; +} + +int MString::rfind( const char tofind ) const +{ + const char * ret = strrchr( m_sCur, tofind ); + return (ret)?(ret-m_sCur):npos; +} + +const MString MString::substr( int iStart ) const +{ + return MString( m_sCur + iStart, m_iLen - iStart ); +} + +const MString MString::substr( int iStart, int iLength ) const +{ + return MString( m_sCur + iStart, iLength ); +} + +int MString::compare( const MString & cmp ) const +{ + return strcmp( m_sCur, cmp.m_sCur ); +} + +int MString::compare( const char * cmp ) const +{ + return strcmp( m_sCur, cmp ); +} + +int MString::compare( int start, int len, const MString & cmp ) const +{ + return strncmp( m_sCur + start, cmp.m_sCur, len ); +} + +int MString::compare( int start, int len, const char * cmp ) const +{ + return strncmp( m_sCur + start, cmp, len ); +} + +unsigned int MString::hash() const +{ + unsigned int ret = 0; + unsigned int i; + unsigned int j = size()>>2; + for( i = 0; i < j; i++ ) + ret += ((unsigned int *)m_sCur)[i]; + + for( i = j<<2; i < size(); i++ ) + ret += (unsigned int)(unsigned char)m_sCur[i]; + + return ret; +} + +void MString::resize( unsigned int size ) +{ + if( size <= m_iLen ) + { + m_iLen = size; + m_sCur[size] = '\0'; + } else + { + MANAGE_ALLOC( size ) + } +} + +bool operator < ( const MString & lhs, const MString & rhs ) +{ + return strcmp( lhs.m_sCur, rhs.m_sCur ) < 0; +} + +bool operator > ( const MString & lhs, const MString & rhs ) +{ + return strcmp( lhs.m_sCur, rhs.m_sCur ) > 0; +} + +//YUCK! This cannot be a friend function becuse of VC6 internal compiler error! +MString operator + ( const char * lhs, const MString & rhs ) +{ + return MString( lhs ) + rhs; +} + +MString operator + ( const char lhs, const MString & rhs ) +{ + return MString( lhs ) + rhs; +} + +#define FMT_BLOCK_SIZE 127 + +MString ssprintf( const char *fmt, ...) +{ + if ( strlen(fmt)==0 ) + return MString(""); + + + int CurMal = FMT_BLOCK_SIZE; + MString ret; + + while ( true ) + { + va_list va; + va_start(va, fmt); + char * base = (char*)malloc( CurMal + 1 ); + #if defined(WIN32) + int len = _vsnprintf( base, CurMal, fmt, va ); + #else + int len = vsnprintf( base, CurMal, fmt, va ); + #endif + + va_end( va ); + + if (len > CurMal) + while (CurMal < len) + CurMal*=2; + else + if ( len > 0 ) + { + ret.assign( base, len ); + free( base ); + break; + } else + CurMal*=2; + + free(base); + } + return ret; +} + +/* + * Copyright (c) 2006,2008, Charles Lohr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the distribution. + * - Neither the name of the Mercury Engine nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ Added: Mercury2/src/MercuryString.h =================================================================== --- Mercury2/src/MercuryString.h (rev 0) +++ Mercury2/src/MercuryString.h 2008-12-30 21:25:06 UTC (rev 107) @@ -0,0 +1,133 @@ +#ifndef _MERCURY_STRING_H +#define _MERCURY_STRING_H + +///Very fast String class +class MString +{ +public: + MString(); + MString( int iPreAlloc ); + MString( const char sIn ); + MString( const char * sIn ); + MString( const char * sIn, int iSize ); + MString( const MString & rhs ); + ~MString(); + + const MString & operator = ( const MString & rhs ); + const MString & operator = ( const char * rhs ); + const MString operator + ( const MString & rhs ) const; + const MString operator + ( const char * rhs ) const; + const MString operator + ( const char rhs ) const; + const MString & operator += ( const char * rhs ); + const MString & operator += ( const MString & rhs ); + const MString & operator += ( const char rhs ); + + bool operator == ( const MString & rhs ); + bool operator == ( const char * rhs ); + bool operator < ( const MString & rhs ); + bool operator > ( const MString & rhs ); + + operator const char * () const { return m_sCur; } + + inline const char * c_str() const { return m_sCur; } + inline unsigned long length() const { return m_iLen; } + inline unsigned long size() const { return m_iLen; } + inline bool empty() const { return m_iLen == 0; } + + void append( const MString & app ); + void append( const char app ); + void append( const char * app ); + void append( const char * app, int len ); + + ///Special: Append app len times + void append( const char app, int len ); + + void assign( const MString & app ); + void assign( const char * app ); + void assign( const char * app, int len ); + + int find( const MString & tofind, int start = 0 ) const; + int rfind( const MString & tofind ) const; + inline int find_last_of( const MString & tofind ) const { return rfind( tofind ); } + + int find( const char * tofind,int start = 0 ) const; + int find( const char tofind, int start = 0 ) const; + int rfind( const char * tofind ) const; + int rfind( const char tofind ) const; + inline int find_last_of( const char * tofind ) const { return rfind( tofind ); } + + const MString substr( int iStart ) const; + const MString substr( int iStart, int iLength ) const; + + int compare( const MString & cmp ) const; + int compare( const char * cmp ) const; + + int compare( int start, int len, const MString & cmp ) const; + int compare( int start, int len, const char * cmp ) const; + + unsigned int hash() const; + + enum + { + npos = -1 + }; + + void resize( unsigned int size ); +private: + char * m_sCur; + unsigned int m_iLen; + unsigned int m_iAlloc; + friend bool operator < ( const MString & lhs, const MString & rhs ); + friend bool operator > ( const MString & lhs, const MString & rhs ); +}; + +/* //Keep around incase we need to debug a little and use our old string +#include "StdString.h" +typedef StdString::CStdString MString; +*/ + +bool operator < ( const MString & lhs, const MString & rhs ); +bool operator > ( const MString & lhs, const MString & rhs ); +inline bool operator == ( const MString & lhs, const char * rhs ) { return lhs.compare( rhs ) == 0; } +inline bool operator != ( const MString & lhs, const char * rhs ) { return lhs.compare( rhs ) != 0; } + +MString operator + ( const char lhs, const MString & rhs ); +MString operator + ( const char * lhs, const MString & rhs ); + +#if defined(__GNUC__) +#define PRINTF(a,b) __attribute__((format(__printf__,a,b))) +#else +#define PRINTF(a,b) +#endif + +MString ssprintf( const char *fmt, ...) PRINTF(1,2); + +#endif + +/* + * Copyright (c) 2006,2008, Charles Lohr + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the distribution. + * - Neither the name of the Mercury Engine nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2008-12-30 21:25:25
|
Revision: 108 http://hgengine.svn.sourceforge.net/hgengine/?rev=108&view=rev Author: cnlohr Date: 2008-12-30 21:25:22 +0000 (Tue, 30 Dec 2008) Log Message: ----------- clean up the XML parser and switch to MString Modified Paths: -------------- Mercury2/src/XMLParser.cpp Mercury2/src/XMLParser.h Modified: Mercury2/src/XMLParser.cpp =================================================================== --- Mercury2/src/XMLParser.cpp 2008-12-30 21:25:06 UTC (rev 107) +++ Mercury2/src/XMLParser.cpp 2008-12-30 21:25:22 UTC (rev 108) @@ -1,4 +1,7 @@ #include <XMLParser.h> +#include <libxml/parser.h> +#include <libxml/tree.h> + //#include <SMOException.h> XMLNode::XMLNode(xmlNode* node, xmlDoc* doc) @@ -39,34 +42,34 @@ return XMLNode(); } -std::string XMLNode::Name() const +MString XMLNode::Name() const { - return std::string((const char*)m_node->name); //XXX fix utf8 + return MString((const char*)m_node->name); //XXX fix utf8 } -std::string XMLNode::Content() const +MString XMLNode::Content() const { - string data; + MString data; // xmlChar* d = xmlNodeListGetString(m_doc, m_node->xmlChildrenNode, 1); xmlChar* d = xmlNodeGetContent(m_node); if (d) { - data = string((const char*)d); + data = MString((const char*)d); xmlFree(d); } return data; } -std::string XMLNode::Attribute(const std::string& tag) const +MString XMLNode::Attribute(const MString& tag) const { - string data; + MString data; xmlChar* d = xmlGetProp(m_node, (const xmlChar*)tag.c_str()); if (d) { - data = string((const char*)d); + data = MString((const char*)d); xmlFree(d); } return data; @@ -88,7 +91,7 @@ if (m_doc) xmlFreeDoc(m_doc); } -XMLDocument* XMLDocument::Load(const std::string& file) +XMLDocument* XMLDocument::Load(const MString& file) { XMLDocument* xmldoc = new XMLDocument(); @@ -98,7 +101,7 @@ return xmldoc; } -void XMLDocument::LoadFromString(const std::string& xml) +void XMLDocument::LoadFromString(const MString& xml) { xmlInitParser(); //XXX WTF am I supposed to do with this m_doc = xmlReadMemory(xml.c_str(), xml.length(), "noname.xml", NULL, 0); Modified: Mercury2/src/XMLParser.h =================================================================== --- Mercury2/src/XMLParser.h 2008-12-30 21:25:06 UTC (rev 107) +++ Mercury2/src/XMLParser.h 2008-12-30 21:25:22 UTC (rev 108) @@ -1,11 +1,13 @@ #ifndef XMLPARSER_H #define XMLPARSER_H -#include <libxml/parser.h> -#include <libxml/tree.h> -#include <string> #include <MAutoPtr.h> +struct _xmlNode; +typedef struct _xmlNode xmlNode; +struct _xmlDoc; +typedef struct _xmlDoc xmlDoc; + class XMLElement { public: @@ -23,9 +25,9 @@ XMLNode PreviousNode() const; XMLNode Child() const; - std::string Name() const; - std::string Content() const; - std::string Attribute(const std::string& tag) const; + MString Name() const; + MString Content() const; + MString Attribute(const MString & tag) const; inline bool IsValid() const { return m_node!=NULL; } @@ -40,8 +42,8 @@ XMLDocument(); virtual ~XMLDocument(); - static XMLDocument* Load(const std::string& file); - void LoadFromString(const std::string& xml); + static XMLDocument* Load(const MString& file); + void LoadFromString(const MString& xml); XMLNode GetRootNode(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2008-12-30 21:25:59
|
Revision: 109 http://hgengine.svn.sourceforge.net/hgengine/?rev=109&view=rev Author: cnlohr Date: 2008-12-30 21:25:50 +0000 (Tue, 30 Dec 2008) Log Message: ----------- switch to MString Modified Paths: -------------- Mercury2/src/BMPLoader.cpp Mercury2/src/HGMDLMesh.h Mercury2/src/HGMDLModel.cpp Mercury2/src/ImageLoader.cpp Mercury2/src/ImageLoader.h Mercury2/src/MAutoPtr.h Mercury2/src/MercuryAsset.cpp Mercury2/src/MercuryAsset.h Mercury2/src/MercuryNode.cpp Mercury2/src/MercuryNode.h Mercury2/src/MercuryThreads.cpp Mercury2/src/MercuryThreads.h Mercury2/src/MercuryUtil.cpp Mercury2/src/MercuryUtil.h Mercury2/src/MercuryWindow.cpp Mercury2/src/MercuryWindow.h Mercury2/src/Win32Window.cpp Mercury2/src/Win32Window.h Mercury2/src/X11Window.cpp Mercury2/src/X11Window.h Modified: Mercury2/src/BMPLoader.cpp =================================================================== --- Mercury2/src/BMPLoader.cpp 2008-12-30 21:25:22 UTC (rev 108) +++ Mercury2/src/BMPLoader.cpp 2008-12-30 21:25:50 UTC (rev 109) @@ -28,7 +28,7 @@ memset(tmp, 0, 4); // file->Read(tmp, sizeof(char) * 2); fread(tmp, sizeof(char) * 2, 1, file); - string type(tmp); + MString type(tmp); if (type != "BM") { Modified: Mercury2/src/HGMDLMesh.h =================================================================== --- Mercury2/src/HGMDLMesh.h 2008-12-30 21:25:22 UTC (rev 108) +++ Mercury2/src/HGMDLMesh.h 2008-12-30 21:25:50 UTC (rev 109) @@ -8,7 +8,7 @@ public: void LoadFromFile(FILE* hgmdl); private: - string m_name; + MString m_name; bool m_cachable; }; Modified: Mercury2/src/HGMDLModel.cpp =================================================================== --- Mercury2/src/HGMDLModel.cpp 2008-12-30 21:25:22 UTC (rev 108) +++ Mercury2/src/HGMDLModel.cpp 2008-12-30 21:25:50 UTC (rev 109) @@ -18,7 +18,8 @@ fingerPrint[4] = 0; fread(fingerPrint, 4, 1, hgmdl); - if (string(fingerPrint) != "MBMF") + MString p(fingerPrint); + if (p != "MBMF") { printf("Not a HGMDL file.\n"); return; Modified: Mercury2/src/ImageLoader.cpp =================================================================== --- Mercury2/src/ImageLoader.cpp 2008-12-30 21:25:22 UTC (rev 108) +++ Mercury2/src/ImageLoader.cpp 2008-12-30 21:25:50 UTC (rev 109) @@ -1,5 +1,4 @@ #include <ImageLoader.h> -#include <string> #include <MercuryUtil.h> using namespace std; @@ -12,15 +11,15 @@ return *instance; } -bool ImageLoader::RegisterFactoryCallback(const std::string& type, Callback1R< FILE*, RawImageData* > functor) +bool ImageLoader::RegisterFactoryCallback(const MString& type, Callback1R< FILE*, RawImageData* > functor) { - string t = ToUpper( type ); - std::pair<std::string, Callback1R< FILE*, RawImageData* > > pp(t, functor); + MString t = ToUpper( type ); + std::pair<MString, Callback1R< FILE*, RawImageData* > > pp(t, functor); m_factoryCallbacks.push_back( pp ); return true; } -RawImageData* ImageLoader::LoadImage(const std::string& filename) +RawImageData* ImageLoader::LoadImage(const MString& filename) { FILE* f = fopen(filename.c_str(), "rb"); char fingerprint[4]; @@ -29,8 +28,8 @@ fread(fingerprint, sizeof(char)*3, 1, f); fseek(f, 0, SEEK_SET); - string t(fingerprint);// = ToUpper( type ); - std::list< std::pair< std::string, Callback1R< FILE*, RawImageData* > > >::iterator i; + MString t(fingerprint);// = ToUpper( type ); + std::list< std::pair< MString, Callback1R< FILE*, RawImageData* > > >::iterator i; for (i = m_factoryCallbacks.begin(); i != m_factoryCallbacks.end(); ++i) { if (i->first == t) Modified: Mercury2/src/ImageLoader.h =================================================================== --- Mercury2/src/ImageLoader.h 2008-12-30 21:25:22 UTC (rev 108) +++ Mercury2/src/ImageLoader.h 2008-12-30 21:25:50 UTC (rev 109) @@ -1,7 +1,6 @@ #ifndef IMAGELOADER_H #define IMAGELOADER_H -#include <string> #include <RawImageData.h> #include <Callback.h> #include <list> @@ -11,11 +10,11 @@ { public: static ImageLoader& GetInstance(); - bool RegisterFactoryCallback(const std::string& type, Callback1R< FILE*, RawImageData* >); - RawImageData* LoadImage(const std::string& filename); + bool RegisterFactoryCallback(const MString& type, Callback1R< FILE*, RawImageData* >); + RawImageData* LoadImage(const MString& filename); private: - std::list< std::pair< std::string, Callback1R< FILE*, RawImageData* > > > m_factoryCallbacks; + std::list< std::pair< MString, Callback1R< FILE*, RawImageData* > > > m_factoryCallbacks; }; static InstanceCounter<ImageLoader> ILcounter("ImageLoader"); Modified: Mercury2/src/MAutoPtr.h =================================================================== --- Mercury2/src/MAutoPtr.h 2008-12-30 21:25:22 UTC (rev 108) +++ Mercury2/src/MAutoPtr.h 2008-12-30 21:25:50 UTC (rev 109) @@ -1,9 +1,6 @@ #ifndef MAUTOPTR_H #define MAUTOPTR_H -//#include <util.h> -//#include <stdlib.h> -//#include <stdio.h> #include <MercuryThreads.h> class RefBase Modified: Mercury2/src/MercuryAsset.cpp =================================================================== --- Mercury2/src/MercuryAsset.cpp 2008-12-30 21:25:22 UTC (rev 108) +++ Mercury2/src/MercuryAsset.cpp 2008-12-30 21:25:50 UTC (rev 109) @@ -16,18 +16,18 @@ return *instance; } -bool AssetFactory::RegisterFactoryCallback(const std::string& type, Callback0R< MAutoPtr<MercuryAsset> > functor) +bool AssetFactory::RegisterFactoryCallback(const MString & type, Callback0R< MAutoPtr<MercuryAsset> > functor) { - string t = ToUpper( type ); - std::pair<std::string, Callback0R< MAutoPtr<MercuryAsset> > > pp(t, functor); + MString t = ToUpper( type ); + std::pair<MString , Callback0R< MAutoPtr<MercuryAsset> > > pp(t, functor); m_factoryCallbacks.push_back( pp ); return true; } -MAutoPtr<MercuryAsset> AssetFactory::Generate(const std::string& type) +MAutoPtr<MercuryAsset> AssetFactory::Generate(const MString& type) { - string t = ToUpper( type ); - std::list< std::pair< std::string, Callback0R< MAutoPtr<MercuryAsset> > > >::iterator i; + MString t = ToUpper( type ); + std::list< std::pair< MString, Callback0R< MAutoPtr<MercuryAsset> > > >::iterator i; for (i = m_factoryCallbacks.begin(); i != m_factoryCallbacks.end(); ++i) if (i->first == t) return i->second(); printf("WARNING: Asset type %s not found.\n", type.c_str()); Modified: Mercury2/src/MercuryAsset.h =================================================================== --- Mercury2/src/MercuryAsset.h 2008-12-30 21:25:22 UTC (rev 108) +++ Mercury2/src/MercuryAsset.h 2008-12-30 21:25:50 UTC (rev 109) @@ -23,11 +23,11 @@ { public: static AssetFactory& GetInstance(); - bool RegisterFactoryCallback(const std::string& type, Callback0R< MAutoPtr<MercuryAsset> >); - MAutoPtr<MercuryAsset> Generate(const std::string& type); + bool RegisterFactoryCallback(const MString& type, Callback0R< MAutoPtr<MercuryAsset> >); + MAutoPtr<MercuryAsset> Generate(const MString& type); private: - std::list< std::pair< std::string, Callback0R< MAutoPtr<MercuryAsset> > > > m_factoryCallbacks; + std::list< std::pair< MString, Callback0R< MAutoPtr<MercuryAsset> > > > m_factoryCallbacks; }; static InstanceCounter<AssetFactory> AFcounter("AssetFactory"); Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2008-12-30 21:25:22 UTC (rev 108) +++ Mercury2/src/MercuryNode.cpp 2008-12-30 21:25:50 UTC (rev 109) @@ -123,18 +123,18 @@ } -bool NodeFactory::RegisterFactoryCallback(const std::string& type, Callback0R<MercuryNode*> functor) +bool NodeFactory::RegisterFactoryCallback(const MString& type, Callback0R<MercuryNode*> functor) { - string t = ToUpper( type ); - std::pair<std::string, Callback0R<MercuryNode*> > pp(t, functor); + MString t = ToUpper( type ); + std::pair<MString, Callback0R<MercuryNode*> > pp(t, functor); m_factoryCallbacks.push_back( pp ); return true; } -MercuryNode* NodeFactory::Generate(const std::string& type) +MercuryNode* NodeFactory::Generate(const MString& type) { - string t = ToUpper( type ); - std::list< std::pair< std::string, Callback0R<MercuryNode*> > >::iterator i; + MString t = ToUpper( type ); + std::list< std::pair< MString, Callback0R<MercuryNode*> > >::iterator i; for (i = m_factoryCallbacks.begin(); i != m_factoryCallbacks.end(); ++i) if (i->first == t) return i->second(); return NULL; Modified: Mercury2/src/MercuryNode.h =================================================================== --- Mercury2/src/MercuryNode.h 2008-12-30 21:25:22 UTC (rev 108) +++ Mercury2/src/MercuryNode.h 2008-12-30 21:25:50 UTC (rev 109) @@ -5,6 +5,7 @@ #include <Callback.h> #include <typeinfo> #include <XMLParser.h> +#include <MercuryUtil.h> /** This is the basic node of the scene graph. It is not intended to be instanced. Each node exists as a single entity in the scene graph. @@ -67,11 +68,11 @@ { public: static NodeFactory& GetInstance(); - bool RegisterFactoryCallback(const std::string& type, Callback0R<MercuryNode*>); - MercuryNode* Generate(const std::string& type); + bool RegisterFactoryCallback(const MString& type, Callback0R<MercuryNode*>); + MercuryNode* Generate(const MString& type); private: - std::list< std::pair< std::string, Callback0R<MercuryNode*> > > m_factoryCallbacks; + std::list< std::pair< MString, Callback0R<MercuryNode*> > > m_factoryCallbacks; }; static InstanceCounter<NodeFactory> NFcounter("NodeFactory"); Modified: Mercury2/src/MercuryThreads.cpp =================================================================== --- Mercury2/src/MercuryThreads.cpp 2008-12-30 21:25:22 UTC (rev 108) +++ Mercury2/src/MercuryThreads.cpp 2008-12-30 21:25:50 UTC (rev 109) @@ -14,7 +14,7 @@ #endif } -MercuryThread::MercuryThread( const string &name ) +MercuryThread::MercuryThread( const MString &name ) :m_name(name), m_haltOnDestroy(true), m_thread(0) { #if defined( WIN32 ) @@ -128,7 +128,7 @@ UnLock(); } -MercuryMutex::MercuryMutex( const string &name ) +MercuryMutex::MercuryMutex( const MString &name ) :m_name(name) { iLockCount = 0; Modified: Mercury2/src/MercuryThreads.h =================================================================== --- Mercury2/src/MercuryThreads.h 2008-12-30 21:25:22 UTC (rev 108) +++ Mercury2/src/MercuryThreads.h 2008-12-30 21:25:50 UTC (rev 109) @@ -1,9 +1,13 @@ #ifndef _MERCURY_THREADS_H #define _MERCURY_THREADS_H +#ifdef HGENGINE +#include <MercuryString.h> +#else #include <string> +typedef std::string MString; +#endif -using namespace std; #if !defined(WIN32) #if !defined(_EE) @@ -20,7 +24,7 @@ { public: MercuryThread(); - MercuryThread( const string &name ); + MercuryThread( const MString &name ); ~MercuryThread(); ///Create a thread of function fn and pass it data *data. @@ -41,7 +45,7 @@ // inline void Exit() { pthread_exit(NULL); } inline void HaltOnDestroy(bool t) { m_haltOnDestroy = t; } private: - string m_name; + MString m_name; bool m_haltOnDestroy; #if defined(WIN32) @@ -62,7 +66,7 @@ { public: MercuryMutex( ); - MercuryMutex( const string &name ); + MercuryMutex( const MString &name ); ~MercuryMutex(); ///Wait for a mutex to unlock (0xFFFFFF is infinate on windows) @@ -77,7 +81,7 @@ ///Clean up a mutex. This is done automatically on destruction of mutex. int Close( ); private: - string m_name; + MString m_name; int iLockCount; #if defined( WIN32 ) Modified: Mercury2/src/MercuryUtil.cpp =================================================================== --- Mercury2/src/MercuryUtil.cpp 2008-12-30 21:25:22 UTC (rev 108) +++ Mercury2/src/MercuryUtil.cpp 2008-12-30 21:25:50 UTC (rev 109) @@ -1,16 +1,19 @@ #include <MercuryUtil.h> +#include <stdint.h> -std::string ToUpper(const std::string& s) +MString ToUpper(const MString& s) { - std::string t = s; + MString t = s; + char * ti = (char*)t.c_str(); for (unsigned long i = 0; i < s.length(); ++i) { - t[i] = toupper(t[i]); + if( ti[i] >= 'a' && ti[i] <= 'z' ) + ti[i] -= ( 'a' - 'A' ); } return t; } -float StrToFloat(const std::string& s) +float StrToFloat(const MString & s) { float x; sscanf(s.c_str(), "%f", &x); Modified: Mercury2/src/MercuryUtil.h =================================================================== --- Mercury2/src/MercuryUtil.h 2008-12-30 21:25:22 UTC (rev 108) +++ Mercury2/src/MercuryUtil.h 2008-12-30 21:25:50 UTC (rev 109) @@ -2,7 +2,8 @@ #define MERCURYUTIL_H #include <stdlib.h> -#include <string> +#include <MercuryString.h> + /*#ifndef NULL #define NULL 0 #endif*/ @@ -24,9 +25,9 @@ #define M_ALIGN(n) #endif -std::string ToUpper(const std::string& s); +MString ToUpper(const MString & s); -float StrToFloat(const std::string& s); +float StrToFloat(const MString & s); //This counter is used with singletons to //ensure proper destruction order of the @@ -36,7 +37,7 @@ class InstanceCounter { public: - InstanceCounter(const std::string& name) + InstanceCounter(const MString & name) :m_name(name) { if (m_count == 0) @@ -57,7 +58,7 @@ } private: static unsigned long m_count; - std::string m_name; + MString m_name; T* m_instance; }; Modified: Mercury2/src/MercuryWindow.cpp =================================================================== --- Mercury2/src/MercuryWindow.cpp 2008-12-30 21:25:22 UTC (rev 108) +++ Mercury2/src/MercuryWindow.cpp 2008-12-30 21:25:50 UTC (rev 109) @@ -1,7 +1,6 @@ -#include <string.h> #include "MercuryWindow.h" -MercuryWindow::MercuryWindow(const string& title, int width, int height, int bits, int depthBits, bool fullscreen) +MercuryWindow::MercuryWindow(const MString& title, int width, int height, int bits, int depthBits, bool fullscreen) :m_title(title), m_width(width), m_height(height), m_bits(bits), m_depthBits(depthBits), m_fullscreen(fullscreen) { } Modified: Mercury2/src/MercuryWindow.h =================================================================== --- Mercury2/src/MercuryWindow.h 2008-12-30 21:25:22 UTC (rev 108) +++ Mercury2/src/MercuryWindow.h 2008-12-30 21:25:50 UTC (rev 109) @@ -1,17 +1,14 @@ #ifndef MERCURYWINDOW_H #define MERCURYWINDOW_H -#include <string> #include <MercuryUtil.h> #include <list> #include <Callback.h> -using namespace std; - class MercuryWindow { public: - MercuryWindow(const string& title, int width, int height, int bits, int depthBits, bool fullscreen); + MercuryWindow(const MString& title, int width, int height, int bits, int depthBits, bool fullscreen); virtual ~MercuryWindow(); inline static MercuryWindow* MakeWindow() { @@ -27,13 +24,13 @@ return MercuryWindow::m_windowInstance; } - virtual void* GetProcAddress(const string& x) = 0; + virtual void* GetProcAddress(const MString& x) = 0; protected: static Callback0R< MercuryWindow* > genWindowClbk; static MercuryWindow* m_windowInstance; - string m_title; + MString m_title; int m_width, m_height, m_bits, m_depthBits; bool m_fullscreen; }; Modified: Mercury2/src/Win32Window.cpp =================================================================== --- Mercury2/src/Win32Window.cpp 2008-12-30 21:25:22 UTC (rev 108) +++ Mercury2/src/Win32Window.cpp 2008-12-30 21:25:50 UTC (rev 109) @@ -8,7 +8,7 @@ return new Win32Window("Mercury2 Tests", 640, 480, 24, 16, false); } -LPCTSTR StringToLPCTSTR(const string& s) +LPCTSTR StringToLPCTSTR(const MString & s) { size_t length = s.length(); LPCTSTR str = new WCHAR[length+1]; @@ -17,7 +17,7 @@ return str; } -Win32Window::Win32Window(const string& title, int width, int height, int bits, int depthBits, bool fullscreen) +Win32Window::Win32Window(const MString& title, int width, int height, int bits, int depthBits, bool fullscreen) :m_hwnd(NULL), m_hdc(NULL), m_hglrc(NULL), m_hInstance(NULL), m_className(NULL), m_windowAtom(NULL), m_winTitle(NULL), MercuryWindow(title, width, height, bits, depthBits, fullscreen) { Modified: Mercury2/src/Win32Window.h =================================================================== --- Mercury2/src/Win32Window.h 2008-12-30 21:25:22 UTC (rev 108) +++ Mercury2/src/Win32Window.h 2008-12-30 21:25:50 UTC (rev 109) @@ -2,7 +2,6 @@ #define WIN32WINDOW_H #include <windows.h> -#include <string> #include <MercuryWindow.h> #include <MScopedArray.h> @@ -10,7 +9,7 @@ class Win32Window : public MercuryWindow { public: - Win32Window(const string& title, int width, int height, int bits, int depthBits, bool fullscreen); + Win32Window(const MString& title, int width, int height, int bits, int depthBits, bool fullscreen); virtual ~Win32Window(); virtual bool SwapBuffers(); virtual bool PumpMessages(); Modified: Mercury2/src/X11Window.cpp =================================================================== --- Mercury2/src/X11Window.cpp 2008-12-30 21:25:22 UTC (rev 108) +++ Mercury2/src/X11Window.cpp 2008-12-30 21:25:50 UTC (rev 109) @@ -2,7 +2,7 @@ Callback0R< MercuryWindow* > MercuryWindow::genWindowClbk(X11Window::GenX11Window); //Register window generation callback -X11Window::X11Window(const string& title, int width, int height, int bits, int depthBits, bool fullscreen) +X11Window::X11Window(const MString& title, int width, int height, int bits, int depthBits, bool fullscreen) :MercuryWindow(title, width, height, bits, depthBits, fullscreen), m_display(NULL) { m_display = XOpenDisplay(NULL); @@ -148,7 +148,7 @@ return true; } -void* X11Window::GetProcAddress(const string& x) +void* X11Window::GetProcAddress(const MString& x) { return NULL; } Modified: Mercury2/src/X11Window.h =================================================================== --- Mercury2/src/X11Window.h 2008-12-30 21:25:22 UTC (rev 108) +++ Mercury2/src/X11Window.h 2008-12-30 21:25:50 UTC (rev 109) @@ -9,7 +9,7 @@ class X11Window : public MercuryWindow { public: - X11Window(const string& title, int width, int height, int bits, int depthBits, bool fullscreen); + X11Window(const MString& title, int width, int height, int bits, int depthBits, bool fullscreen); virtual ~X11Window(); static MercuryWindow* GenX11Window(); @@ -17,7 +17,7 @@ virtual bool SwapBuffers(); virtual bool PumpMessages(); - virtual void* GetProcAddress(const string& x); + virtual void* GetProcAddress(const MString& x); private: Display* m_display; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2008-12-30 22:35:32
|
Revision: 114 http://hgengine.svn.sourceforge.net/hgengine/?rev=114&view=rev Author: axlecrusher Date: 2008-12-30 22:35:28 +0000 (Tue, 30 Dec 2008) Log Message: ----------- use microseconds Modified Paths: -------------- Mercury2/src/Mercury2.cpp Mercury2/src/MercuryUtil.cpp Mercury2/src/MercuryUtil.h Mercury2/src/TransformNode.cpp Modified: Mercury2/src/Mercury2.cpp =================================================================== --- Mercury2/src/Mercury2.cpp 2008-12-30 22:10:30 UTC (rev 113) +++ Mercury2/src/Mercury2.cpp 2008-12-30 22:35:28 UTC (rev 114) @@ -8,6 +8,8 @@ #include <RenderableNode.h> +#include <sys/time.h> + #include <MercuryCrash.h> #include <MercuryBacktrace.h> @@ -35,7 +37,7 @@ int main() { unsigned long m_count = 0; - long m_time; +// long m_time; cnset_execute_on_crash( SignalHandler ); @@ -51,22 +53,29 @@ // MercuryThread updateThread; - m_time = time(NULL); +// m_time = time(NULL); + uint64_t oTime = GetTimeInMicroSeconds(); + uint64_t m_time = oTime; + // updateThread.Create( UpdateThread, root, false); do { - root->RecursiveUpdate(0.01f); + uint64_t curTime = GetTimeInMicroSeconds(); + root->RecursiveUpdate((curTime-oTime)/1000000.0f); // updateThread.Create( UpdateThread, root, false); RenderableNode::RecursiveRender(root); w->SwapBuffers(); ++m_count; - if (time(NULL) > m_time) + float seconds = (curTime-m_time)/1000000.0f; + if (seconds > 1) { - m_time = time(NULL); - printf("FPS: %lu\n", m_count); + m_time = curTime; + printf("FPS: %f\n", m_count/seconds); m_count = 0; } + + oTime = curTime; } while ( w->PumpMessages() ); @@ -109,3 +118,4 @@ * 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/MercuryUtil.cpp =================================================================== --- Mercury2/src/MercuryUtil.cpp 2008-12-30 22:10:30 UTC (rev 113) +++ Mercury2/src/MercuryUtil.cpp 2008-12-30 22:35:28 UTC (rev 114) @@ -1,6 +1,12 @@ #include <MercuryUtil.h> #include <stdint.h> +#ifndef WIN32 +#include <sys/time.h> +#else +#include <windows.h> +#endif + MString ToUpper(const MString& s) { MString t = s; @@ -28,6 +34,15 @@ return ptr; } +int64_t GetTimeInMicroSeconds() +{ + struct timeval tv; + gettimeofday( &tv, 0 ); + + return (int64_t(tv.tv_sec) * 1000000) + tv.tv_usec; + +} + /*************************************************************************** * Copyright (C) 2008 by Joshua Allen * * * Modified: Mercury2/src/MercuryUtil.h =================================================================== --- Mercury2/src/MercuryUtil.h 2008-12-30 22:10:30 UTC (rev 113) +++ Mercury2/src/MercuryUtil.h 2008-12-30 22:35:28 UTC (rev 114) @@ -17,6 +17,8 @@ //returns an aligned pointer, mem is the actual (unaligned) pointer for freeing void* mmemalign(size_t align, size_t size, void*& mem); +int64_t GetTimeInMicroSeconds(); + #if defined(__GNUC__) #define M_ALIGN(n) __attribute__((aligned(n))) //#define MMALLOC(n) memalign(32, n) Modified: Mercury2/src/TransformNode.cpp =================================================================== --- Mercury2/src/TransformNode.cpp 2008-12-30 22:10:30 UTC (rev 113) +++ Mercury2/src/TransformNode.cpp 2008-12-30 22:35:28 UTC (rev 114) @@ -147,8 +147,8 @@ void RotatorNode::Update(float dTime) { MercuryPoint r = GetRotation(); - r.x += (dTime)*2.5; - r.y += (dTime)*5; + r.x += (dTime)*25; + r.y += (dTime)*75; SetRotation( r ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2008-12-30 23:50:20
|
Revision: 118 http://hgengine.svn.sourceforge.net/hgengine/?rev=118&view=rev Author: cnlohr Date: 2008-12-30 23:50:17 +0000 (Tue, 30 Dec 2008) Log Message: ----------- add utility function to dump a file to a buffer Modified Paths: -------------- Mercury2/src/MercuryUtil.cpp Mercury2/src/MercuryUtil.h Modified: Mercury2/src/MercuryUtil.cpp =================================================================== --- Mercury2/src/MercuryUtil.cpp 2008-12-30 23:46:54 UTC (rev 117) +++ Mercury2/src/MercuryUtil.cpp 2008-12-30 23:50:17 UTC (rev 118) @@ -1,4 +1,5 @@ #include <MercuryUtil.h> +#include <MercuryFile.h> #include <stdint.h> #ifndef WIN32 @@ -43,6 +44,36 @@ } +long FileToString( const MString & sFileName, char * & data ) +{ + data = 0; + + MercuryFile * f = FILEMAN.Open( sFileName ); + if( !f ) return -1; + + int length = f->Length(); + + data = (char*)malloc( length + 1 ); + + if( !data ) + { + data = 0; + return -1; + } + + int r = f->Read( data, length ); + + if( r != length ) + { + free( data ); + data = 0; + return -1; + } + + return length; +} + + /*************************************************************************** * Copyright (C) 2008 by Joshua Allen * * * Modified: Mercury2/src/MercuryUtil.h =================================================================== --- Mercury2/src/MercuryUtil.h 2008-12-30 23:46:54 UTC (rev 117) +++ Mercury2/src/MercuryUtil.h 2008-12-30 23:50:17 UTC (rev 118) @@ -67,6 +67,10 @@ template<typename T> unsigned long InstanceCounter<T>::m_count = 0; +///Open up filename: sFileName and dump it into a new buffer; you must delete the return value when done. +///The return value is -1 if there was an issue, otherwise it is valid. +long FileToString( const MString & sFileName, char * & data ); + #endif /* Copyright (c) 2008, Joshua Allen This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2008-12-31 00:30:53
|
Revision: 121 http://hgengine.svn.sourceforge.net/hgengine/?rev=121&view=rev Author: cnlohr Date: 2008-12-31 00:30:44 +0000 (Wed, 31 Dec 2008) Log Message: ----------- make Meshes use MercuryFile *'s Modified Paths: -------------- Mercury2/src/HGMDLMesh.cpp Mercury2/src/HGMDLMesh.h Mercury2/src/HGMDLModel.cpp Mercury2/src/HGMDLModel.h Modified: Mercury2/src/HGMDLMesh.cpp =================================================================== --- Mercury2/src/HGMDLMesh.cpp 2008-12-31 00:12:56 UTC (rev 120) +++ Mercury2/src/HGMDLMesh.cpp 2008-12-31 00:30:44 UTC (rev 121) @@ -1,34 +1,41 @@ #include <HGMDLMesh.h> -void HGMDLMesh::LoadFromFile(FILE* hgmdl) +void HGMDLMesh::LoadFromFile(MercuryFile* hgmdl) { uint32_t nameLength; - fread(&nameLength, sizeof(uint32_t), 1, hgmdl); + //fread(&nameLength, sizeof(uint32_t), 1, hgmdl); + hgmdl->Read( &nameLength, sizeof( uint32_t ) ); if (nameLength > 0) { char* name = new char[nameLength+1]; name[nameLength] = 0; - fread(name, nameLength, 1, hgmdl); + hgmdl->Read( name, nameLength ); + //fread(name, nameLength, 1, hgmdl); m_name = name; } - fread(&m_cachable, sizeof(bool), 1, hgmdl); + hgmdl->Read( &m_cachable, sizeof( char ) ); + //fread(&m_cachable, sizeof(bool), 1, hgmdl); uint32_t dataLength; - fread(&dataLength, sizeof(uint32_t), 1, hgmdl); + //fread(&dataLength, sizeof(uint32_t), 1, hgmdl); + hgmdl->Read( &dataLength, sizeof( uint32_t ) ); if (dataLength > 0) { m_vertexData.Allocate( dataLength/sizeof(float) ); //they are all floats - fread(m_vertexData.Buffer(), dataLength, 1, hgmdl); + //fread(m_vertexData.Buffer(), dataLength, 1, hgmdl); + hgmdl->Read( m_vertexData.Buffer(), dataLength ); } uint16_t numIndices; - fread(&numIndices, sizeof(uint16_t), 1, hgmdl); + //fread(&numIndices, sizeof(uint16_t), 1, hgmdl); + hgmdl->Read( &numIndices, sizeof( uint16_t ) ); if (numIndices > 0) { m_indexData.Allocate( numIndices ); - fread(m_indexData.Buffer(), numIndices*sizeof(uint16_t), 1, hgmdl); + //fread(m_indexData.Buffer(), numIndices*sizeof(uint16_t), 1, hgmdl); + hgmdl->Read( m_indexData.Buffer(), numIndices*sizeof(uint16_t) ); } } Modified: Mercury2/src/HGMDLMesh.h =================================================================== --- Mercury2/src/HGMDLMesh.h 2008-12-31 00:12:56 UTC (rev 120) +++ Mercury2/src/HGMDLMesh.h 2008-12-31 00:30:44 UTC (rev 121) @@ -2,11 +2,12 @@ #define HGMDLMESH_H #include <MercuryVBO.h> +#include <MercuryFile.h> class HGMDLMesh : public MercuryVBO { public: - void LoadFromFile(FILE* hgmdl); + void LoadFromFile(MercuryFile* hgmdl); private: MString m_name; bool m_cachable; Modified: Mercury2/src/HGMDLModel.cpp =================================================================== --- Mercury2/src/HGMDLModel.cpp 2008-12-31 00:12:56 UTC (rev 120) +++ Mercury2/src/HGMDLModel.cpp 2008-12-31 00:30:44 UTC (rev 121) @@ -6,18 +6,25 @@ { if ( !node.Attribute("file").empty() ) { - FILE* f = fopen( node.Attribute("file").c_str(), "rb" ); + //FILE* f = fopen( node.Attribute("file").c_str(), "rb" ); + MercuryFile * f = FILEMAN.Open( node.Attribute("file") ); + if( !f ) + { + printf( "Could not open file: \"%s\" for model\n", node.Attribute("file").c_str() ); + return; + } LoadModel( f ); - fclose( f ); + delete f; } } -void HGMDLModel::LoadModel(FILE* hgmdl) +void HGMDLModel::LoadModel(MercuryFile* hgmdl) { char fingerPrint[5]; fingerPrint[4] = 0; - fread(fingerPrint, 4, 1, hgmdl); + hgmdl->Read( fingerPrint, 4 ); + MString p(fingerPrint); if (p != "MBMF") { @@ -26,7 +33,8 @@ } uint32_t version; - fread(&version, 4, 1, hgmdl); + //fread(&version, 4, 1, hgmdl); + hgmdl->Read( &version, 4 ); if (version != 200) { @@ -35,7 +43,8 @@ } uint16_t numMeshes; - fread(&numMeshes, sizeof(uint16_t), 1, hgmdl); + + hgmdl->Read( &numMeshes, sizeof( uint16_t ) ); for (uint16_t i = 0; i < numMeshes; ++i) { MAutoPtr< HGMDLMesh > mesh( new HGMDLMesh() ); Modified: Mercury2/src/HGMDLModel.h =================================================================== --- Mercury2/src/HGMDLModel.h 2008-12-31 00:12:56 UTC (rev 120) +++ Mercury2/src/HGMDLModel.h 2008-12-31 00:30:44 UTC (rev 121) @@ -3,6 +3,7 @@ #include <MercuryAsset.h> #include <HGMDLMesh.h> +#include <MercuryFile.h> #include <vector> @@ -12,7 +13,7 @@ virtual void LoadFromXML(const XMLNode& node); - void LoadModel(FILE* hgmdl); + void LoadModel(MercuryFile* hgmdl); static HGMDLModel* Generate(); virtual void Render(MercuryNode* node); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2008-12-31 04:37:05
|
Revision: 123 http://hgengine.svn.sourceforge.net/hgengine/?rev=123&view=rev Author: axlecrusher Date: 2008-12-31 04:37:02 +0000 (Wed, 31 Dec 2008) Log Message: ----------- Use the unified asset instances in the asset factory Modified Paths: -------------- Mercury2/src/MercuryAsset.cpp Mercury2/src/MercuryAsset.h Mercury2/src/Quad.cpp Mercury2/src/Quad.h Mercury2/src/RenderableNode.cpp Mercury2/src/Texture.cpp Mercury2/src/Texture.h Modified: Mercury2/src/MercuryAsset.cpp =================================================================== --- Mercury2/src/MercuryAsset.cpp 2008-12-31 00:35:14 UTC (rev 122) +++ Mercury2/src/MercuryAsset.cpp 2008-12-31 04:37:02 UTC (rev 123) @@ -24,9 +24,13 @@ return true; } -MAutoPtr<MercuryAsset> AssetFactory::Generate(const MString& type) +MAutoPtr<MercuryAsset> AssetFactory::Generate(const MString& type, const MString& key) { MString t = ToUpper( type ); + + MercuryAsset *asset = LocateAsset(t+key); + if ( asset ) return asset; + std::list< std::pair< MString, Callback0R< MAutoPtr<MercuryAsset> > > >::iterator i; for (i = m_factoryCallbacks.begin(); i != m_factoryCallbacks.end(); ++i) if (i->first == t) return i->second(); @@ -34,6 +38,27 @@ return NULL; } +MercuryAsset* AssetFactory::LocateAsset( const MString& key ) +{ + std::map<MString, MercuryAsset*>::iterator asset = m_assetInstances.find(key); + if ( asset != m_assetInstances.end() ) return asset->second; + return NULL; +} + +void AssetFactory::AddAssetInstance(const MString& key, MercuryAsset* asset) +{ + m_assetInstances[key] = asset; +} + +void AssetFactory::RemoveAssetInstance(const MString& key) +{ + std::map<MString, MercuryAsset*>::iterator asset = m_assetInstances.find(key); + if ( asset != m_assetInstances.end() ) + m_assetInstances.erase( asset ); +} + +std::map<MString, MercuryAsset*> AssetFactory::m_assetInstances; + /*************************************************************************** * Copyright (C) 2008 by Joshua Allen * * * Modified: Mercury2/src/MercuryAsset.h =================================================================== --- Mercury2/src/MercuryAsset.h 2008-12-31 00:35:14 UTC (rev 122) +++ Mercury2/src/MercuryAsset.h 2008-12-31 04:37:02 UTC (rev 123) @@ -4,6 +4,8 @@ #include <MAutoPtr.h> #include <MercuryNode.h> +#include <map> + class MercuryAsset : public RefBase { public: @@ -24,10 +26,18 @@ public: static AssetFactory& GetInstance(); bool RegisterFactoryCallback(const MString& type, Callback0R< MAutoPtr<MercuryAsset> >); - MAutoPtr<MercuryAsset> Generate(const MString& type); + MAutoPtr<MercuryAsset> Generate(const MString& type, const MString& key); + + void AddAssetInstance(const MString& key, MercuryAsset* asset); + void RemoveAssetInstance(const MString& key); - private: + MercuryAsset* LocateAsset( const MString& key ); + + private: std::list< std::pair< MString, Callback0R< MAutoPtr<MercuryAsset> > > > m_factoryCallbacks; + + static std::map<MString, MercuryAsset*> m_assetInstances; + }; static InstanceCounter<AssetFactory> AFcounter("AssetFactory"); Modified: Mercury2/src/Quad.cpp =================================================================== --- Mercury2/src/Quad.cpp 2008-12-31 00:35:14 UTC (rev 122) +++ Mercury2/src/Quad.cpp 2008-12-31 04:37:02 UTC (rev 123) @@ -39,19 +39,17 @@ Quad::~Quad() { - if (m_myInstance == this) - m_myInstance = NULL; + AssetFactory::GetInstance().RemoveAssetInstance( "QUAD" ); } Quad* Quad::Generate() { - if ( !m_myInstance ) - m_myInstance = new Quad(); - return m_myInstance; + Quad *asset = new Quad(); + AssetFactory::GetInstance().AddAssetInstance( "QUAD", asset ); + printf("new quad\n"); + return asset; } -Quad* Quad::m_myInstance = NULL; - /*************************************************************************** * Copyright (C) 2008 by Joshua Allen * * * Modified: Mercury2/src/Quad.h =================================================================== --- Mercury2/src/Quad.h 2008-12-31 00:35:14 UTC (rev 122) +++ Mercury2/src/Quad.h 2008-12-31 04:37:02 UTC (rev 123) @@ -13,7 +13,6 @@ static Quad* Generate(); private: - static Quad* m_myInstance; }; #endif Modified: Mercury2/src/RenderableNode.cpp =================================================================== --- Mercury2/src/RenderableNode.cpp 2008-12-31 00:35:14 UTC (rev 122) +++ Mercury2/src/RenderableNode.cpp 2008-12-31 04:37:02 UTC (rev 123) @@ -143,7 +143,8 @@ { if ( child.Name() == "asset" ) { - MAutoPtr< MercuryAsset > asset( AssetFactory::GetInstance().Generate(child.Attribute("type") ) ); + MString key = child.Attribute("file"); + MAutoPtr< MercuryAsset > asset( AssetFactory::GetInstance().Generate( child.Attribute("type"), key ) ); if ( asset.IsValid() ) { asset->LoadFromXML( child ); Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2008-12-31 00:35:14 UTC (rev 122) +++ Mercury2/src/Texture.cpp 2008-12-31 04:37:02 UTC (rev 123) @@ -12,7 +12,7 @@ REGISTER_ASSET_TYPE(Texture); Texture::Texture() - :m_raw(NULL),m_textureID(0) + :m_raw(NULL),m_textureID(0),m_isLoaded(false) { if (!m_initTextureSuccess) { @@ -23,6 +23,8 @@ Texture::~Texture() { + AssetFactory::GetInstance().RemoveAssetInstance( "TEXTURE"+m_filename ); + if (m_textureID) glDeleteTextures(1, &m_textureID); m_textureID = 0; @@ -92,12 +94,8 @@ void Texture::LoadFromXML(const XMLNode& node) { - if ( !node.Attribute("imagefile").empty() ) - { -// RawImageData* d = LoadBMP( node.Attribute("imagefile") ); - RawImageData* d = ImageLoader::GetInstance().LoadImage( node.Attribute("imagefile") ); - if (d) LoadFromRaw( d ); - } + if (m_isLoaded) return; + LoadImage( node.Attribute("file") ); } void Texture::BindTexture() @@ -121,9 +119,34 @@ --m_activeTextures; } +void Texture::LoadImage(const MString& path) +{ + if ( !path.empty() ) + { + m_isLoaded = true; + m_filename = path; + AssetFactory::GetInstance().AddAssetInstance("TEXTURE" + m_filename, this); + RawImageData* d = ImageLoader::GetInstance().LoadImage( m_filename ); + if (d) LoadFromRaw( d ); + } +} + +Texture* Texture::Generate() +{ + return new Texture(); +} + +Texture* Texture::LoadFromFile(const MString& path) +{ + Texture *t = (Texture*)AssetFactory::GetInstance().LocateAsset("TEXTURE" + path); + if (!t) t = Generate(); + t->LoadImage( path ); +} + bool Texture::m_initTextureSuccess = false; unsigned short Texture::m_activeTextures = 0; + /*************************************************************************** * Copyright (C) 2008 by Joshua Allen * * * Modified: Mercury2/src/Texture.h =================================================================== --- Mercury2/src/Texture.h 2008-12-31 00:35:14 UTC (rev 122) +++ Mercury2/src/Texture.h 2008-12-31 04:37:02 UTC (rev 123) @@ -21,8 +21,11 @@ inline static unsigned short NumberActiveTextures() { return m_activeTextures; } - static Texture* Generate() { return new Texture(); } + static Texture* Generate(); + static Texture* LoadFromFile(const MString& path); private: + void LoadImage(const MString& path); + void BindTexture(); void UnbindTexture(); @@ -32,6 +35,9 @@ static bool m_initTextureSuccess; static unsigned short m_activeTextures; + + MString m_filename; + bool m_isLoaded; }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2008-12-31 04:49:32
|
Revision: 124 http://hgengine.svn.sourceforge.net/hgengine/?rev=124&view=rev Author: axlecrusher Date: 2008-12-31 04:49:29 +0000 (Wed, 31 Dec 2008) Log Message: ----------- make macros to add and remove instances Modified Paths: -------------- Mercury2/src/MercuryAsset.h Mercury2/src/Quad.cpp Mercury2/src/Texture.cpp Modified: Mercury2/src/MercuryAsset.h =================================================================== --- Mercury2/src/MercuryAsset.h 2008-12-31 04:37:02 UTC (rev 123) +++ Mercury2/src/MercuryAsset.h 2008-12-31 04:49:29 UTC (rev 124) @@ -47,7 +47,12 @@ Callback0R< MAutoPtr<MercuryAsset> > factoryclbk##class( FactoryFunct##class ); \ bool GlobalRegisterSuccess##class = AssetFactory::GetInstance().RegisterFactoryCallback(#class, factoryclbk##class); +#define ADD_ASSET_INSTANCE(class, key, ptr)\ + AssetFactory::GetInstance().AddAssetInstance( ToUpper(#class)+key, ptr ); +#define REMOVE_ASSET_INSTANCE(class, key)\ + AssetFactory::GetInstance().RemoveAssetInstance( ToUpper(#class)+key ); + #endif /*************************************************************************** Modified: Mercury2/src/Quad.cpp =================================================================== --- Mercury2/src/Quad.cpp 2008-12-31 04:37:02 UTC (rev 123) +++ Mercury2/src/Quad.cpp 2008-12-31 04:49:29 UTC (rev 124) @@ -39,13 +39,13 @@ Quad::~Quad() { - AssetFactory::GetInstance().RemoveAssetInstance( "QUAD" ); + REMOVE_ASSET_INSTANCE(Quad,""); } Quad* Quad::Generate() { Quad *asset = new Quad(); - AssetFactory::GetInstance().AddAssetInstance( "QUAD", asset ); + ADD_ASSET_INSTANCE(Quad,"",asset); printf("new quad\n"); return asset; } Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2008-12-31 04:37:02 UTC (rev 123) +++ Mercury2/src/Texture.cpp 2008-12-31 04:49:29 UTC (rev 124) @@ -23,7 +23,7 @@ Texture::~Texture() { - AssetFactory::GetInstance().RemoveAssetInstance( "TEXTURE"+m_filename ); + REMOVE_ASSET_INSTANCE(TEXTURE, m_filename); if (m_textureID) glDeleteTextures(1, &m_textureID); m_textureID = 0; @@ -125,7 +125,7 @@ { m_isLoaded = true; m_filename = path; - AssetFactory::GetInstance().AddAssetInstance("TEXTURE" + m_filename, this); + ADD_ASSET_INSTANCE(Texture, m_filename, this); RawImageData* d = ImageLoader::GetInstance().LoadImage( m_filename ); if (d) LoadFromRaw( d ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2008-12-31 05:04:10
|
Revision: 126 http://hgengine.svn.sourceforge.net/hgengine/?rev=126&view=rev Author: axlecrusher Date: 2008-12-31 05:04:06 +0000 (Wed, 31 Dec 2008) Log Message: ----------- don't give access to the factory's locate function, go through the factory's generate Modified Paths: -------------- Mercury2/src/MercuryAsset.h Mercury2/src/Texture.cpp Mercury2/src/Texture.h Modified: Mercury2/src/MercuryAsset.h =================================================================== --- Mercury2/src/MercuryAsset.h 2008-12-31 04:52:33 UTC (rev 125) +++ Mercury2/src/MercuryAsset.h 2008-12-31 05:04:06 UTC (rev 126) @@ -30,10 +30,10 @@ void AddAssetInstance(const MString& key, MercuryAsset* asset); void RemoveAssetInstance(const MString& key); - + + private: MercuryAsset* LocateAsset( const MString& key ); - private: std::list< std::pair< MString, Callback0R< MAutoPtr<MercuryAsset> > > > m_factoryCallbacks; static std::map<MString, MercuryAsset*> m_assetInstances; Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2008-12-31 04:52:33 UTC (rev 125) +++ Mercury2/src/Texture.cpp 2008-12-31 05:04:06 UTC (rev 126) @@ -136,11 +136,12 @@ return new Texture(); } -Texture* Texture::LoadFromFile(const MString& path) +MAutoPtr< Texture > Texture::LoadFromFile(const MString& path) { - Texture *t = (Texture*)AssetFactory::GetInstance().LocateAsset("TEXTURE" + path); - if (!t) t = Generate(); - t->LoadImage( path ); + MAutoPtr< MercuryAsset > t( AssetFactory::GetInstance().Generate("Texture", path) ); + Texture *a = (Texture*)&(*t); + a->LoadImage( path ); + return a; } bool Texture::m_initTextureSuccess = false; Modified: Mercury2/src/Texture.h =================================================================== --- Mercury2/src/Texture.h 2008-12-31 04:52:33 UTC (rev 125) +++ Mercury2/src/Texture.h 2008-12-31 05:04:06 UTC (rev 126) @@ -22,7 +22,7 @@ inline static unsigned short NumberActiveTextures() { return m_activeTextures; } static Texture* Generate(); - static Texture* LoadFromFile(const MString& path); + static MAutoPtr< Texture > LoadFromFile(const MString& path); private: void LoadImage(const MString& path); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-01-01 03:38:45
|
Revision: 130 http://hgengine.svn.sourceforge.net/hgengine/?rev=130&view=rev Author: axlecrusher Date: 2009-01-01 03:38:38 +0000 (Thu, 01 Jan 2009) Log Message: ----------- add message manager Added Paths: ----------- Mercury2/src/MercuryMessageManager.cpp Mercury2/src/MercuryMessageManager.h Mercury2/src/MessageHandler.h Mercury2/src/PriorityQueue.h Added: Mercury2/src/MercuryMessageManager.cpp =================================================================== --- Mercury2/src/MercuryMessageManager.cpp (rev 0) +++ Mercury2/src/MercuryMessageManager.cpp 2009-01-01 03:38:38 UTC (rev 130) @@ -0,0 +1,76 @@ +#include <MercuryMessageManager.h> + +void MercuryMessageManager::PostMessage(const MString& message, float delay) +{ + uint64_t fireTime = m_currTime + uint64_t(delay*1000000); + m_messageQueue.Insert(fireTime, message); +} + +void MercuryMessageManager::PumpMessages(const uint64_t& currTime) +{ + m_currTime = currTime; + while ( !m_messageQueue.empty() ) + { + if ( m_messageQueue.PeekNextPriority() > m_currTime ) return; + + MString& message = m_messageQueue.GetNext(); + FireOffMessage( message ); + m_messageQueue.PopNext(); + } +} + +void MercuryMessageManager::RegisterForMessage(const MString& message, MessageHandler* ptr) +{ + m_messageRecipients[message].push_back(ptr); +} + +void MercuryMessageManager::FireOffMessage(const MString& message) +{ + std::map< MString, std::list< MessageHandler* > >::iterator i = m_messageRecipients.find(message); + + + std::list< MessageHandler* >::iterator recipients = i->second.begin(); + + for (; recipients != i->second.end(); ++recipients) + (*recipients)->HandleMessage(message); +} + +MercuryMessageManager& MercuryMessageManager::GetInstance() +{ + static MercuryMessageManager *instance = NULL; + if (!instance) + instance = new MercuryMessageManager(); + return *instance; +} + +/**************************************************************************** + * 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/MercuryMessageManager.h =================================================================== --- Mercury2/src/MercuryMessageManager.h (rev 0) +++ Mercury2/src/MercuryMessageManager.h 2009-01-01 03:38:38 UTC (rev 130) @@ -0,0 +1,71 @@ +#ifndef MERCURYMESSAGEMANAGER_H +#define MERCURYMESSAGEMANAGER_H + +#include <Callback.h> +#include <MessageHandler.h> +#include <map> +#include <PriorityQueue.h> +#include <MercuryString.h> +#include <MercuryUtil.h> + +/* This message system uses absolute integer time values to fire off events. +This ensures accuarate firing times while eliminating floating point error. +Because we use absolute times in the queue we do not need to "count down" the +firing times of all the messages. We only need to pop off the nearest events +from the beginning of the queue." */ +class MercuryMessageManager +{ + public: + void PostMessage(const MString& message, float delay); + void PumpMessages(const uint64_t& currTime); + void RegisterForMessage(const MString& message, MessageHandler* ptr); + + static MercuryMessageManager& GetInstance(); + private: + void FireOffMessage(const MString& message); + + PriorityQueue<uint64_t, MString> m_messageQueue; + uint64_t m_currTime; //microseconds + + std::map< MString, std::list< MessageHandler* > > m_messageRecipients; +}; + +static InstanceCounter<MercuryMessageManager> MMcounter("MessageManager"); + +#define MESSAGEMAN MercuryMessageManager +#define REGISTER_FOR_MESSAGE(x) MESSAGEMAN::GetInstance().RegisterForMessage(#x, this) +#define POST_MESSAGE(x,delay) MESSAGEMAN::GetInstance().PostMessage(#x, delay) + +#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. * + ***************************************************************************/ Added: Mercury2/src/MessageHandler.h =================================================================== --- Mercury2/src/MessageHandler.h (rev 0) +++ Mercury2/src/MessageHandler.h 2009-01-01 03:38:38 UTC (rev 130) @@ -0,0 +1,44 @@ +#ifndef MESSAGEHANDLER_H +#define MESSAGEHANDLER_H + +#include <MercuryString.h> + +class MessageHandler +{ + public: + virtual ~MessageHandler() {}; + virtual void HandleMessage(const MString& message) {}; +}; + +#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. * + ***************************************************************************/ Added: Mercury2/src/PriorityQueue.h =================================================================== --- Mercury2/src/PriorityQueue.h (rev 0) +++ Mercury2/src/PriorityQueue.h 2009-01-01 03:38:38 UTC (rev 130) @@ -0,0 +1,64 @@ +#ifndef PRIORITYQUEUE_H +#define PRIORITYQUEUE_H + +#include <list> +#include <map> + +template<typename T1, typename T2> +class PriorityQueue +{ + public: + void Insert(const T1& priority, const T2& x) + { + m_queue[priority].push_back(x); + } + + bool empty() { return m_queue.empty(); } + + const T1& PeekNextPriority() { return m_queue.begin()->first; } + T2& GetNext() { return m_queue.begin()->second.front(); } + void PopNext() + { + m_queue.begin()->second.pop_front(); + + if ( m_queue.begin()->second.empty() ) + m_queue.erase( m_queue.begin() ); + } + + private: + std::map< T1, std::list<T2> > m_queue; +}; + +#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...> - 2009-01-01 03:40:51
|
Revision: 131 http://hgengine.svn.sourceforge.net/hgengine/?rev=131&view=rev Author: axlecrusher Date: 2009-01-01 03:40:46 +0000 (Thu, 01 Jan 2009) Log Message: ----------- use MessageHandler as base Modified Paths: -------------- Mercury2/src/MercuryAsset.h Mercury2/src/MercuryNode.h Modified: Mercury2/src/MercuryAsset.h =================================================================== --- Mercury2/src/MercuryAsset.h 2009-01-01 03:38:38 UTC (rev 130) +++ Mercury2/src/MercuryAsset.h 2009-01-01 03:40:46 UTC (rev 131) @@ -3,10 +3,10 @@ #include <MAutoPtr.h> #include <MercuryNode.h> - +#include <MessageHandler.h> #include <map> -class MercuryAsset : public RefBase +class MercuryAsset : public RefBase, MessageHandler { public: MercuryAsset(); Modified: Mercury2/src/MercuryNode.h =================================================================== --- Mercury2/src/MercuryNode.h 2009-01-01 03:38:38 UTC (rev 130) +++ Mercury2/src/MercuryNode.h 2009-01-01 03:40:46 UTC (rev 131) @@ -6,6 +6,7 @@ #include <typeinfo> #include <XMLParser.h> #include <MercuryUtil.h> +#include <MessageHandler.h> /** This is the basic node of the scene graph. It is not intended to be instanced. Each node exists as a single entity in the scene graph. @@ -22,7 +23,7 @@ while(tn) { if (typeid(x) == typeid(*tn)) return true; tn = *n; } \ return false;} */ -class MercuryNode +class MercuryNode : public MessageHandler { public: MercuryNode(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-01-01 17:01:53
|
Revision: 134 http://hgengine.svn.sourceforge.net/hgengine/?rev=134&view=rev Author: axlecrusher Date: 2009-01-01 17:01:48 +0000 (Thu, 01 Jan 2009) Log Message: ----------- Add timer Added Paths: ----------- Mercury2/src/MercuryTimer.cpp Mercury2/src/MercuryTimer.h Added: Mercury2/src/MercuryTimer.cpp =================================================================== --- Mercury2/src/MercuryTimer.cpp (rev 0) +++ Mercury2/src/MercuryTimer.cpp 2009-01-01 17:01:48 UTC (rev 134) @@ -0,0 +1,89 @@ +#include <MercuryTimer.h> + +#ifndef WIN32 +#include <sys/time.h> +#else +#include <windows.h> +#endif + +int64_t GetTimeInMicroSeconds() +{ + struct timeval tv; + gettimeofday( &tv, 0 ); + + return (int64_t(tv.tv_sec) * 1000000) + tv.tv_usec; +} + +MercuryTimer::MercuryTimer() + :m_lastTouch(0), m_thisTouch(0) +{ + if (m_initTime == 0) + m_initTime = GetTimeInMicroSeconds(); + + Touch(); + m_lastTouch = m_thisTouch; +} + +uint64_t MercuryTimer::MicrosecondsSinceInit() +{ + return m_thisTouch; +} + +float MercuryTimer::Touch() +{ + m_lastTouch = m_thisTouch; + m_thisTouch = GetTimeInMicroSeconds() - m_initTime; + return Age(); +} + +float MercuryTimer::Touch(const MercuryTimer& t) +{ + m_thisTouch = t.m_thisTouch; + return Age(); +} + +float MercuryTimer::Age() +{ + return (m_thisTouch - m_lastTouch)/1000000.0f; +} + +const MercuryTimer& MercuryTimer::operator=(const MercuryTimer& t) +{ + m_lastTouch = t.m_lastTouch; + m_thisTouch = t.m_thisTouch; + return *this; +} + +uint64_t MercuryTimer::m_initTime = 0; + +/**************************************************************************** + * 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/MercuryTimer.h =================================================================== --- Mercury2/src/MercuryTimer.h (rev 0) +++ Mercury2/src/MercuryTimer.h 2009-01-01 17:01:48 UTC (rev 134) @@ -0,0 +1,62 @@ +#ifndef MERCURYTIMER_H +#define MERCURYTIMER_H + +#include <stdint.h> + +class MercuryTimer +{ + public: + MercuryTimer(); + + uint64_t MicrosecondsSinceInit(); + + ///returns the age + float Touch(); + + ///sets this touch equal to t.m_thisTouch, leaves last touch unchanged + float Touch(const MercuryTimer& t); + + ///time between last last touch and this touch + float Age(); + + const MercuryTimer& operator=(const MercuryTimer& t); + private: + static uint64_t m_initTime; + + uint64_t m_lastTouch; + uint64_t m_thisTouch; +}; + +#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...> - 2009-01-02 01:15:57
|
Revision: 136 http://hgengine.svn.sourceforge.net/hgengine/?rev=136&view=rev Author: axlecrusher Date: 2009-01-02 01:15:53 +0000 (Fri, 02 Jan 2009) Log Message: ----------- inline age Modified Paths: -------------- Mercury2/src/MercuryTimer.cpp Mercury2/src/MercuryTimer.h Modified: Mercury2/src/MercuryTimer.cpp =================================================================== --- Mercury2/src/MercuryTimer.cpp 2009-01-01 17:04:02 UTC (rev 135) +++ Mercury2/src/MercuryTimer.cpp 2009-01-02 01:15:53 UTC (rev 136) @@ -42,11 +42,6 @@ return Age(); } -float MercuryTimer::Age() -{ - return (m_thisTouch - m_lastTouch)/1000000.0f; -} - const MercuryTimer& MercuryTimer::operator=(const MercuryTimer& t) { m_lastTouch = t.m_lastTouch; Modified: Mercury2/src/MercuryTimer.h =================================================================== --- Mercury2/src/MercuryTimer.h 2009-01-01 17:04:02 UTC (rev 135) +++ Mercury2/src/MercuryTimer.h 2009-01-02 01:15:53 UTC (rev 136) @@ -3,6 +3,8 @@ #include <stdint.h> +int64_t GetTimeInMicroSeconds(); + class MercuryTimer { public: @@ -17,7 +19,7 @@ float Touch(const MercuryTimer& t); ///time between last last touch and this touch - float Age(); + inline float Age() { return (m_thisTouch - m_lastTouch)/1000000.0f; } const MercuryTimer& operator=(const MercuryTimer& t); private: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-01-02 01:19:09
|
Revision: 138 http://hgengine.svn.sourceforge.net/hgengine/?rev=138&view=rev Author: axlecrusher Date: 2009-01-02 01:19:05 +0000 (Fri, 02 Jan 2009) Log Message: ----------- fix memory leaks Modified Paths: -------------- Mercury2/src/HGMDLMesh.cpp Mercury2/src/X11Window.cpp Modified: Mercury2/src/HGMDLMesh.cpp =================================================================== --- Mercury2/src/HGMDLMesh.cpp 2009-01-02 01:17:34 UTC (rev 137) +++ Mercury2/src/HGMDLMesh.cpp 2009-01-02 01:19:05 UTC (rev 138) @@ -13,6 +13,7 @@ hgmdl->Read( name, nameLength ); //fread(name, nameLength, 1, hgmdl); m_name = name; + SAFE_DELETE_ARRAY(name); } hgmdl->Read( &m_cachable, sizeof( char ) ); Modified: Mercury2/src/X11Window.cpp =================================================================== --- Mercury2/src/X11Window.cpp 2009-01-02 01:17:34 UTC (rev 137) +++ Mercury2/src/X11Window.cpp 2009-01-02 01:19:05 UTC (rev 138) @@ -78,7 +78,9 @@ X11Window::~X11Window() { + if (m_renderCtx) glXDestroyContext(m_display, m_renderCtx); if (m_display) XCloseDisplay(m_display); + m_renderCtx = NULL; m_display = NULL; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-01-02 02:22:31
|
Revision: 140 http://hgengine.svn.sourceforge.net/hgengine/?rev=140&view=rev Author: axlecrusher Date: 2009-01-02 01:45:52 +0000 (Fri, 02 Jan 2009) Log Message: ----------- add ability to pause Modified Paths: -------------- Mercury2/src/MercuryTimer.cpp Mercury2/src/MercuryTimer.h Modified: Mercury2/src/MercuryTimer.cpp =================================================================== --- Mercury2/src/MercuryTimer.cpp 2009-01-02 01:20:29 UTC (rev 139) +++ Mercury2/src/MercuryTimer.cpp 2009-01-02 01:45:52 UTC (rev 140) @@ -15,7 +15,7 @@ } MercuryTimer::MercuryTimer() - :m_lastTouch(0), m_thisTouch(0) + :m_lastTouch(0), m_thisTouch(0), m_paused(false) { if (m_initTime == 0) m_initTime = GetTimeInMicroSeconds(); @@ -33,6 +33,8 @@ { m_lastTouch = m_thisTouch; m_thisTouch = GetTimeInMicroSeconds() - m_initTime; + + if (m_paused) m_lastTouch = m_thisTouch; return Age(); } @@ -42,6 +44,11 @@ return Age(); } +void MercuryTimer::Pause() +{ + m_paused = !m_paused; +} + const MercuryTimer& MercuryTimer::operator=(const MercuryTimer& t) { m_lastTouch = t.m_lastTouch; Modified: Mercury2/src/MercuryTimer.h =================================================================== --- Mercury2/src/MercuryTimer.h 2009-01-02 01:20:29 UTC (rev 139) +++ Mercury2/src/MercuryTimer.h 2009-01-02 01:45:52 UTC (rev 140) @@ -21,12 +21,15 @@ ///time between last last touch and this touch inline float Age() { return (m_thisTouch - m_lastTouch)/1000000.0f; } + void Pause(); + const MercuryTimer& operator=(const MercuryTimer& t); private: static uint64_t m_initTime; uint64_t m_lastTouch; uint64_t m_thisTouch; + bool m_paused; }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-01-03 17:48:49
|
Revision: 141 http://hgengine.svn.sourceforge.net/hgengine/?rev=141&view=rev Author: axlecrusher Date: 2009-01-03 17:48:45 +0000 (Sat, 03 Jan 2009) Log Message: ----------- function to check alignedness Modified Paths: -------------- Mercury2/src/MercuryUtil.cpp Mercury2/src/MercuryUtil.h Modified: Mercury2/src/MercuryUtil.cpp =================================================================== --- Mercury2/src/MercuryUtil.cpp 2009-01-02 01:45:52 UTC (rev 140) +++ Mercury2/src/MercuryUtil.cpp 2009-01-03 17:48:45 UTC (rev 141) @@ -29,6 +29,11 @@ return ptr; } +bool isAligned(size_t align, const void* mem) +{ + return (uintptr_t(mem) % align) == 0; +} + long FileToString( const MString & sFileName, char * & data ) { data = 0; Modified: Mercury2/src/MercuryUtil.h =================================================================== --- Mercury2/src/MercuryUtil.h 2009-01-02 01:45:52 UTC (rev 140) +++ Mercury2/src/MercuryUtil.h 2009-01-03 17:48:45 UTC (rev 141) @@ -3,6 +3,7 @@ #include <stdlib.h> #include <MercuryString.h> +#include <assert.h> /*#ifndef NULL #define NULL 0 @@ -16,11 +17,12 @@ //returns an aligned pointer, mem is the actual (unaligned) pointer for freeing void* mmemalign(size_t align, size_t size, void*& mem); +bool isAligned(size_t align, const void* mem); +#define ASSERT(x) assert(!x) + #if defined(__GNUC__) #define M_ALIGN(n) __attribute__((aligned(n))) -//#define MMALLOC(n) memalign(32, n) -//#define MMALLOC(n) malloc(n) #else #define M_ALIGN(n) #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-01-03 17:50:49
|
Revision: 142 http://hgengine.svn.sourceforge.net/hgengine/?rev=142&view=rev Author: axlecrusher Date: 2009-01-03 17:50:45 +0000 (Sat, 03 Jan 2009) Log Message: ----------- updates Modified Paths: -------------- Mercury2/src/AlignedBuffer.h Mercury2/src/MercuryTimer.h Modified: Mercury2/src/AlignedBuffer.h =================================================================== --- Mercury2/src/AlignedBuffer.h 2009-01-03 17:48:45 UTC (rev 141) +++ Mercury2/src/AlignedBuffer.h 2009-01-03 17:50:45 UTC (rev 142) @@ -14,11 +14,11 @@ Free(); } - void Allocate(unsigned long count) + void Allocate(unsigned long count, uint8_t alignment = 32) { SAFE_FREE(m_mem); void * m_memret; - m_data = (T*)mmemalign(32, sizeof(T)*count, m_memret); + m_data = (T*)mmemalign(alignment, sizeof(T)*count, m_memret); m_mem = (T*)m_memret; m_length = count; } Modified: Mercury2/src/MercuryTimer.h =================================================================== --- Mercury2/src/MercuryTimer.h 2009-01-03 17:48:45 UTC (rev 141) +++ Mercury2/src/MercuryTimer.h 2009-01-03 17:50:45 UTC (rev 142) @@ -19,7 +19,8 @@ float Touch(const MercuryTimer& t); ///time between last last touch and this touch - inline float Age() { return (m_thisTouch - m_lastTouch)/1000000.0f; } + inline float Age() { return MicrosecondAge()/1000000.0f; } + inline uint64_t MicrosecondAge() { return m_thisTouch - m_lastTouch; } void Pause(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |