|
From: <axl...@us...> - 2008-12-02 01:46:59
|
Revision: 24
http://hgengine.svn.sourceforge.net/hgengine/?rev=24&view=rev
Author: axlecrusher
Date: 2008-12-02 01:46:57 +0000 (Tue, 02 Dec 2008)
Log Message:
-----------
Quiet node destruction
Modified Paths:
--------------
Mercury2/src/Mercury2.cpp
Mercury2/src/MercuryNode.cpp
Mercury2/src/X11Window.cpp
Modified: Mercury2/src/Mercury2.cpp
===================================================================
--- Mercury2/src/Mercury2.cpp 2008-12-02 00:10:55 UTC (rev 23)
+++ Mercury2/src/Mercury2.cpp 2008-12-02 01:46:57 UTC (rev 24)
@@ -42,7 +42,6 @@
}
while ( w->PumpMessages() );
- printf("end\n");
SAFE_DELETE(root);
delete w;
Modified: Mercury2/src/MercuryNode.cpp
===================================================================
--- Mercury2/src/MercuryNode.cpp 2008-12-02 00:10:55 UTC (rev 23)
+++ Mercury2/src/MercuryNode.cpp 2008-12-02 01:46:57 UTC (rev 24)
@@ -10,7 +10,6 @@
MercuryNode::~MercuryNode()
{
- printf("destroying node\n");
m_parent = NULL;
list< MercuryNode* >::iterator i;
@@ -18,7 +17,6 @@
SAFE_DELETE(*i);
m_children.clear();
- printf("destroyed node\n");
}
void MercuryNode::AddChild(MercuryNode* n)
Modified: Mercury2/src/X11Window.cpp
===================================================================
--- Mercury2/src/X11Window.cpp 2008-12-02 00:10:55 UTC (rev 23)
+++ Mercury2/src/X11Window.cpp 2008-12-02 01:46:57 UTC (rev 24)
@@ -106,7 +106,6 @@
}
case DestroyNotify:
{
- printf("destroy notify\n");
XDestroyWindowEvent* e = (XDestroyWindowEvent*)&event;
if (e->window == m_window) return false;
break;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-03 11:51:00
|
Revision: 29
http://hgengine.svn.sourceforge.net/hgengine/?rev=29&view=rev
Author: axlecrusher
Date: 2008-12-03 11:46:22 +0000 (Wed, 03 Dec 2008)
Log Message:
-----------
Add a node factory and a function to load from XML
Modified Paths:
--------------
Mercury2/src/MercuryNode.cpp
Mercury2/src/MercuryNode.h
Modified: Mercury2/src/MercuryNode.cpp
===================================================================
--- Mercury2/src/MercuryNode.cpp 2008-12-03 11:43:29 UTC (rev 28)
+++ Mercury2/src/MercuryNode.cpp 2008-12-03 11:46:22 UTC (rev 29)
@@ -3,6 +3,8 @@
using namespace std;
+REGISTER_NODE_TYPE(MercuryNode);
+
MercuryNode::MercuryNode()
:m_parent(NULL)
{
@@ -88,6 +90,47 @@
(*i)->RecursiveUpdate(dTime);
}
+void MercuryNode::LoadFromXML(const XMLNode& node)
+{
+ //Not much to do here except run through all the children nodes
+ for (XMLNode child = node.Child(); child.IsValid(); child = child.NextNode())
+ {
+ if ( child.Name() == "node" )
+ {
+ MercuryNode* node = NodeFactory::GetInstance().Generate( child.Attribute("type") );
+ if (!node) node = new MercuryNode();
+ node->LoadFromXML( child );
+ this->AddChild( node );
+ }
+ }
+}
+
+NodeFactory& NodeFactory::GetInstance()
+{
+ static NodeFactory* instance = NULL;
+ if (!instance)
+ instance = new NodeFactory;
+ return *instance;
+
+}
+
+bool NodeFactory::RegisterFactoryCallback(const std::string& type, Callback0R<MercuryNode*> functor)
+{
+ string t = ToUpper( type );
+ std::pair<std::string, Callback0R<MercuryNode*> > pp(t, functor);
+ m_factoryCallbacks.push_back( pp );
+ return true;
+}
+
+MercuryNode* NodeFactory::Generate(const std::string& type)
+{
+ string t = ToUpper( type );
+ std::list< std::pair< std::string, Callback0R<MercuryNode*> > >::iterator i;
+ for (i = m_factoryCallbacks.begin(); i != m_factoryCallbacks.end(); ++i)
+ if (i->first == t) return i->second();
+ return NULL;
+}
+
/***************************************************************************
* Copyright (C) 2008 by Joshua Allen *
* *
Modified: Mercury2/src/MercuryNode.h
===================================================================
--- Mercury2/src/MercuryNode.h 2008-12-03 11:43:29 UTC (rev 28)
+++ Mercury2/src/MercuryNode.h 2008-12-03 11:46:22 UTC (rev 29)
@@ -4,6 +4,7 @@
#include <list>
#include <Callback.h>
#include <typeinfo>
+#include <XMLParser.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.
@@ -44,14 +45,35 @@
///Provides callback ability when a child node is removed (parent, child) arguement order
std::list< Callback2< MercuryNode*, MercuryNode* > > OnRemoveChild;
+
+ ///Loads a node from an XMLNode representing itself
+ virtual void LoadFromXML(const XMLNode& node);
GENRTTI(MercuryNode);
-
+
protected:
std::list< MercuryNode* > m_children; //These nodes are unique, not instanced
MercuryNode* m_parent;
};
+class NodeFactory
+{
+ public:
+ static NodeFactory& GetInstance();
+ bool RegisterFactoryCallback(const std::string& type, Callback0R<MercuryNode*>);
+ MercuryNode* Generate(const std::string& type);
+
+ private:
+ std::list< std::pair< std::string, Callback0R<MercuryNode*> > > m_factoryCallbacks;
+};
+
+static InstanceCounter<NodeFactory> NFcounter("NodeFactory");
+
+#define REGISTER_NODE_TYPE(class)\
+ MercuryNode* FactoryFunct##class() { return new class(); } \
+ Callback0R<MercuryNode*> factoryclbk( FactoryFunct##class ); \
+ bool GlobalRegisterSuccess##class = NodeFactory::GetInstance().RegisterFactoryCallback("#class", factoryclbk);
+
#endif
/***************************************************************************
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-03 12:22:21
|
Revision: 28
http://hgengine.svn.sourceforge.net/hgengine/?rev=28&view=rev
Author: axlecrusher
Date: 2008-12-03 11:43:29 +0000 (Wed, 03 Dec 2008)
Log Message:
-----------
Add instance counter and functions to convert strings to upper
Modified Paths:
--------------
Mercury2/src/MercuryUtil.h
Added Paths:
-----------
Mercury2/src/MercuryUtil.cpp
Added: Mercury2/src/MercuryUtil.cpp
===================================================================
--- Mercury2/src/MercuryUtil.cpp (rev 0)
+++ Mercury2/src/MercuryUtil.cpp 2008-12-03 11:43:29 UTC (rev 28)
@@ -0,0 +1,35 @@
+#include <MercuryUtil.h>
+
+std::string ToUpper(const std::string& s)
+{
+ std::string t = s;
+ for (int i = 0; i < s.length(); ++i)
+ {
+ t[i] = toupper(t[i]);
+ }
+ return t;
+}
+
+/***************************************************************************
+ * Copyright (C) 2008 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: *
+ * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. *
+ * * Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR *
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
Modified: Mercury2/src/MercuryUtil.h
===================================================================
--- Mercury2/src/MercuryUtil.h 2008-12-03 11:40:01 UTC (rev 27)
+++ Mercury2/src/MercuryUtil.h 2008-12-03 11:43:29 UTC (rev 28)
@@ -2,6 +2,7 @@
#define MERCURYUTIL_H
#include <stdlib.h>
+#include <string>
/*#ifndef NULL
#define NULL 0
#endif*/
@@ -9,13 +10,50 @@
#define SAFE_DELETE( x ) { if (x) { delete x; } x = NULL; }
#define SAFE_DELETE_ARRAY( x ) { if (x) { delete[] x; } x = NULL; }
-#if defined(__GNUC__)
-#define M_ALIGN(n) __attribute__((aligned(n)))
-#else
-#define M_ALIGN(n)
-#endif
+#if defined(__GNUC__)
+#define M_ALIGN(n) __attribute__((aligned(n)))
+#else
+#define M_ALIGN(n)
+#endif
+std::string ToUpper(const std::string& s);
+//This counter is used with singletons to
+//ensure proper destruction order of the
+//singleton
+#include <stdio.h>
+template<typename T>
+class InstanceCounter
+{
+ public:
+ InstanceCounter(const std::string& name)
+ :m_name(name)
+ {
+ if (m_count == 0)
+ {
+ printf("Creating instance %s\n", m_name.c_str());
+ m_instance = &T::GetInstance();
+ }
+ ++m_count;
+ }
+ ~InstanceCounter()
+ {
+ --m_count;
+ if (m_count == 0)
+ {
+ printf("Destroying instance %s\n", m_name.c_str());
+ SAFE_DELETE(m_instance);
+ }
+ }
+ private:
+ static unsigned long m_count;
+ std::string m_name;
+ T* m_instance;
+};
+
+template<typename T>
+ unsigned long InstanceCounter<T>::m_count = 0;
+
#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: <axl...@us...> - 2008-12-03 12:22:27
|
Revision: 25
http://hgengine.svn.sourceforge.net/hgengine/?rev=25&view=rev
Author: axlecrusher
Date: 2008-12-03 11:34:31 +0000 (Wed, 03 Dec 2008)
Log Message:
-----------
Add a few basic XML parsing classes.
Added Paths:
-----------
Mercury2/src/XMLParser.cpp
Mercury2/src/XMLParser.h
Added: Mercury2/src/XMLParser.cpp
===================================================================
--- Mercury2/src/XMLParser.cpp (rev 0)
+++ Mercury2/src/XMLParser.cpp 2008-12-03 11:34:31 UTC (rev 25)
@@ -0,0 +1,137 @@
+#include <XMLParser.h>
+//#include <SMOException.h>
+
+XMLNode::XMLNode(xmlNode* node, xmlDoc* doc)
+ :m_node(node), m_doc(doc)
+{
+}
+
+XMLNode::XMLNode(const XMLNode& n)
+ :m_node(n.m_node)
+{
+}
+
+XMLNode::~XMLNode()
+{
+ m_node = NULL;
+}
+
+XMLNode XMLNode::NextNode() const
+{
+ for (xmlNode* node = m_node->next; node; node=node->next)
+ if (node->type == XML_ELEMENT_NODE)
+ return XMLNode(node,m_doc);
+ return XMLNode();
+}
+
+XMLNode XMLNode::PreviousNode() const
+{
+ for (xmlNode* node = m_node->prev; node; node=node->prev)
+ if (node->type == XML_ELEMENT_NODE)
+ return XMLNode(node,m_doc);
+ return XMLNode();
+}
+
+XMLNode XMLNode::Child() const
+{
+ for (xmlNode* node = m_node->children; node; node=node->next)
+ if (node->type == XML_ELEMENT_NODE)
+ return XMLNode(node,m_doc);
+ return XMLNode();
+}
+
+std::string XMLNode::Name()
+{
+ return std::string((const char*)m_node->name); //XXX fix utf8
+}
+
+std::string XMLNode::Content()
+{
+ string data;
+// xmlChar* d = xmlNodeListGetString(m_doc, m_node->xmlChildrenNode, 1);
+ xmlChar* d = xmlNodeGetContent(m_node);
+
+ if (d)
+ {
+ data = string((const char*)d);
+ xmlFree(d);
+ }
+
+ return data;
+}
+
+std::string XMLNode::Attribute(const std::string& tag)
+{
+ string data;
+ xmlChar* d = xmlGetProp(m_node, (const xmlChar*)tag.c_str());
+
+ if (d)
+ {
+ data = string((const char*)d);
+ xmlFree(d);
+ }
+ return data;
+}
+
+XMLDocument::XMLDocument()
+ :m_doc(NULL)
+{
+}
+
+XMLDocument::~XMLDocument()
+{
+ FreeDocument();
+ xmlCleanupParser(); //XXX WTF am I supposed to do with this
+}
+
+void XMLDocument::FreeDocument()
+{
+ if (m_doc) xmlFreeDoc(m_doc);
+}
+
+XMLDocument* XMLDocument::Load(const std::string& file)
+{
+ XMLDocument* xmldoc = new XMLDocument();
+
+ xmlInitParser(); //XXX WTF am I supposed to do with this
+ xmldoc->m_doc = xmlReadFile(file.c_str(), NULL, 0);
+
+ return xmldoc;
+}
+
+void XMLDocument::LoadFromString(const std::string& xml)
+{
+ xmlInitParser(); //XXX WTF am I supposed to do with this
+ m_doc = xmlReadMemory(xml.c_str(), xml.length(), "noname.xml", NULL, 0);
+}
+
+XMLNode XMLDocument::GetRootNode()
+{
+// if (!m_doc) throw SMOException("XML Document NULL");
+ return XMLNode(xmlDocGetRootElement(m_doc), m_doc);
+}
+
+
+/***************************************************************************
+ * Copyright (C) 2008 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: *
+ * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. *
+ * * Neither the name of the Mercury developers nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR *
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
Added: Mercury2/src/XMLParser.h
===================================================================
--- Mercury2/src/XMLParser.h (rev 0)
+++ Mercury2/src/XMLParser.h 2008-12-03 11:34:31 UTC (rev 25)
@@ -0,0 +1,78 @@
+#ifndef XMLPARSER_H
+#define XMLPARSER_H
+
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+#include <string>
+#include <MAutoPtr.h>
+
+class XMLElement
+{
+ public:
+ private:
+};
+
+class XMLNode
+{
+ public:
+ XMLNode(xmlNode* node = NULL, xmlDoc* doc = NULL);
+ XMLNode(const XMLNode& n);
+ ~XMLNode();
+
+ XMLNode NextNode() const;
+ XMLNode PreviousNode() const;
+ XMLNode Child() const;
+
+ std::string Name();
+ std::string Content();
+ std::string Attribute(const std::string& tag);
+
+ inline bool IsValid() const { return m_node!=NULL; }
+
+ private:
+ xmlNode* m_node;
+ xmlDoc* m_doc; //parent doc, don't free
+};
+
+class XMLDocument : public RefBase
+{
+ public:
+ XMLDocument();
+ virtual ~XMLDocument();
+
+ static XMLDocument* Load(const std::string& file);
+ void LoadFromString(const std::string& xml);
+
+
+ XMLNode GetRootNode();
+
+ private:
+ void FreeDocument();
+ xmlDoc *m_doc;
+};
+
+#endif
+
+/***************************************************************************
+ * Copyright (C) 2008 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: *
+ * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. *
+ * * Neither the name of the Mercury developers nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR *
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-03 23:58:22
|
Revision: 32
http://hgengine.svn.sourceforge.net/hgengine/?rev=32&view=rev
Author: axlecrusher
Date: 2008-12-03 23:58:19 +0000 (Wed, 03 Dec 2008)
Log Message:
-----------
register node types
Modified Paths:
--------------
Mercury2/src/RenderableNode.cpp
Mercury2/src/TransformNode.cpp
Modified: Mercury2/src/RenderableNode.cpp
===================================================================
--- Mercury2/src/RenderableNode.cpp 2008-12-03 23:56:32 UTC (rev 31)
+++ Mercury2/src/RenderableNode.cpp 2008-12-03 23:58:19 UTC (rev 32)
@@ -5,6 +5,8 @@
using namespace std;
+REGISTER_NODE_TYPE(RenderableNode);
+
RenderableNode::~RenderableNode()
{
m_prerender.clear();
Modified: Mercury2/src/TransformNode.cpp
===================================================================
--- Mercury2/src/TransformNode.cpp 2008-12-03 23:56:32 UTC (rev 31)
+++ Mercury2/src/TransformNode.cpp 2008-12-03 23:58:19 UTC (rev 32)
@@ -1,5 +1,7 @@
#include <TransformNode.h>
+REGISTER_NODE_TYPE(TransformNode);
+
TransformNode::TransformNode()
:m_scale( MercuryPoint(1,1,1) )
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-04 01:50:03
|
Revision: 34
http://hgengine.svn.sourceforge.net/hgengine/?rev=34&view=rev
Author: axlecrusher
Date: 2008-12-04 01:48:14 +0000 (Thu, 04 Dec 2008)
Log Message:
-----------
add string to float function
Modified Paths:
--------------
Mercury2/src/MercuryUtil.cpp
Mercury2/src/MercuryUtil.h
Modified: Mercury2/src/MercuryUtil.cpp
===================================================================
--- Mercury2/src/MercuryUtil.cpp 2008-12-04 01:46:14 UTC (rev 33)
+++ Mercury2/src/MercuryUtil.cpp 2008-12-04 01:48:14 UTC (rev 34)
@@ -10,6 +10,13 @@
return t;
}
+float StrToFloat(const std::string& s)
+{
+ float x;
+ sscanf(s.c_str(), "%f", &x);
+ return x;
+}
+
/***************************************************************************
* Copyright (C) 2008 by Joshua Allen *
* *
Modified: Mercury2/src/MercuryUtil.h
===================================================================
--- Mercury2/src/MercuryUtil.h 2008-12-04 01:46:14 UTC (rev 33)
+++ Mercury2/src/MercuryUtil.h 2008-12-04 01:48:14 UTC (rev 34)
@@ -18,6 +18,8 @@
std::string ToUpper(const std::string& s);
+float StrToFloat(const std::string& s);
+
//This counter is used with singletons to
//ensure proper destruction order of the
//singleton
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-04 01:50:07
|
Revision: 33
http://hgengine.svn.sourceforge.net/hgengine/?rev=33&view=rev
Author: axlecrusher
Date: 2008-12-04 01:46:14 +0000 (Thu, 04 Dec 2008)
Log Message:
-----------
Add asset factory
Modified Paths:
--------------
Mercury2/src/MercuryAsset.cpp
Mercury2/src/MercuryAsset.h
Mercury2/src/Quad.cpp
Modified: Mercury2/src/MercuryAsset.cpp
===================================================================
--- Mercury2/src/MercuryAsset.cpp 2008-12-03 23:58:19 UTC (rev 32)
+++ Mercury2/src/MercuryAsset.cpp 2008-12-04 01:46:14 UTC (rev 33)
@@ -1,7 +1,31 @@
#include <MercuryAsset.h>
+AssetFactory& AssetFactory::GetInstance()
+{
+ static AssetFactory* instance = NULL;
+ if (!instance)
+ instance = new AssetFactory;
+ return *instance;
+}
+bool AssetFactory::RegisterFactoryCallback(const std::string& type, Callback0R< MAutoPtr<MercuryAsset> > functor)
+{
+ string t = ToUpper( type );
+ std::pair<std::string, Callback0R< MAutoPtr<MercuryAsset> > > pp(t, functor);
+ m_factoryCallbacks.push_back( pp );
+ return true;
+}
+
+MAutoPtr<MercuryAsset> AssetFactory::Generate(const std::string& type)
+{
+ string t = ToUpper( type );
+ std::list< std::pair< std::string, Callback0R< MAutoPtr<MercuryAsset> > > >::iterator i;
+ for (i = m_factoryCallbacks.begin(); i != m_factoryCallbacks.end(); ++i)
+ if (i->first == t) return i->second();
+ return NULL;
+}
+
/***************************************************************************
* Copyright (C) 2008 by Joshua Allen *
* *
Modified: Mercury2/src/MercuryAsset.h
===================================================================
--- Mercury2/src/MercuryAsset.h 2008-12-03 23:58:19 UTC (rev 32)
+++ Mercury2/src/MercuryAsset.h 2008-12-04 01:46:14 UTC (rev 33)
@@ -12,8 +12,30 @@
virtual void PreRender(MercuryNode* node) {};
virtual void Render(MercuryNode* node) = 0;
virtual void PostRender(MercuryNode* node) {};
+
+ ///Loads a node from an XMLNode representing itself
+ virtual void LoadFromXML(const XMLNode& node) {};
};
+class AssetFactory
+{
+ public:
+ static AssetFactory& GetInstance();
+ bool RegisterFactoryCallback(const std::string& type, Callback0R< MAutoPtr<MercuryAsset> >);
+ MAutoPtr<MercuryAsset> Generate(const std::string& type);
+
+ private:
+ std::list< std::pair< std::string, Callback0R< MAutoPtr<MercuryAsset> > > > m_factoryCallbacks;
+};
+
+static InstanceCounter<AssetFactory> AFcounter("AssetFactory");
+
+#define REGISTER_ASSET_TYPE(class)\
+ MAutoPtr<MercuryAsset> FactoryFunct##class() { return MAutoPtr<MercuryAsset>(new class()); } \
+ Callback0R< MAutoPtr<MercuryAsset> > factoryclbk##class( FactoryFunct##class ); \
+ bool GlobalRegisterSuccess##class = AssetFactory::GetInstance().RegisterFactoryCallback(#class, factoryclbk##class);
+
+
#endif
/***************************************************************************
Modified: Mercury2/src/Quad.cpp
===================================================================
--- Mercury2/src/Quad.cpp 2008-12-03 23:58:19 UTC (rev 32)
+++ Mercury2/src/Quad.cpp 2008-12-04 01:46:14 UTC (rev 33)
@@ -1,6 +1,8 @@
#include <Quad.h>
#include <GL/gl.h>
+REGISTER_ASSET_TYPE(Quad);
+
void Quad::Render(MercuryNode* node)
{
glBegin(GL_QUADS);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-04 01:50:35
|
Revision: 35
http://hgengine.svn.sourceforge.net/hgengine/?rev=35&view=rev
Author: axlecrusher
Date: 2008-12-04 01:50:32 +0000 (Thu, 04 Dec 2008)
Log Message:
-----------
These functions should be const
Modified Paths:
--------------
Mercury2/src/XMLParser.cpp
Mercury2/src/XMLParser.h
Modified: Mercury2/src/XMLParser.cpp
===================================================================
--- Mercury2/src/XMLParser.cpp 2008-12-04 01:48:14 UTC (rev 34)
+++ Mercury2/src/XMLParser.cpp 2008-12-04 01:50:32 UTC (rev 35)
@@ -35,17 +35,16 @@
XMLNode XMLNode::Child() const
{
for (xmlNode* node = m_node->children; node; node=node->next)
- if (node->type == XML_ELEMENT_NODE)
- return XMLNode(node,m_doc);
+ if (node->type == XML_ELEMENT_NODE) return XMLNode(node,m_doc);
return XMLNode();
}
-std::string XMLNode::Name()
+std::string XMLNode::Name() const
{
return std::string((const char*)m_node->name); //XXX fix utf8
}
-std::string XMLNode::Content()
+std::string XMLNode::Content() const
{
string data;
// xmlChar* d = xmlNodeListGetString(m_doc, m_node->xmlChildrenNode, 1);
@@ -60,7 +59,7 @@
return data;
}
-std::string XMLNode::Attribute(const std::string& tag)
+std::string XMLNode::Attribute(const std::string& tag) const
{
string data;
xmlChar* d = xmlGetProp(m_node, (const xmlChar*)tag.c_str());
Modified: Mercury2/src/XMLParser.h
===================================================================
--- Mercury2/src/XMLParser.h 2008-12-04 01:48:14 UTC (rev 34)
+++ Mercury2/src/XMLParser.h 2008-12-04 01:50:32 UTC (rev 35)
@@ -23,9 +23,9 @@
XMLNode PreviousNode() const;
XMLNode Child() const;
- std::string Name();
- std::string Content();
- std::string Attribute(const std::string& tag);
+ std::string Name() const;
+ std::string Content() const;
+ std::string Attribute(const std::string& tag) const;
inline bool IsValid() const { return m_node!=NULL; }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-04 01:53:02
|
Revision: 36
http://hgengine.svn.sourceforge.net/hgengine/?rev=36&view=rev
Author: axlecrusher
Date: 2008-12-04 01:52:54 +0000 (Thu, 04 Dec 2008)
Log Message:
-----------
load from xml
Modified Paths:
--------------
Mercury2/src/TransformNode.cpp
Mercury2/src/TransformNode.h
Modified: Mercury2/src/TransformNode.cpp
===================================================================
--- Mercury2/src/TransformNode.cpp 2008-12-04 01:50:32 UTC (rev 35)
+++ Mercury2/src/TransformNode.cpp 2008-12-04 01:52:54 UTC (rev 36)
@@ -77,6 +77,45 @@
}
}
+void TransformNode::LoadFromXML(const XMLNode& node)
+{
+ MercuryPoint rot(m_rotation), pos(m_position), scale(m_scale);
+
+ //only change the values that exist in the XML
+ if ( !node.Attribute("rotx").empty() )
+ rot.SetX( StrToFloat( node.Attribute("rotx") ) );
+
+ if ( !node.Attribute("roty").empty() )
+ rot.SetY( StrToFloat( node.Attribute("roty") ) );
+
+ if ( !node.Attribute("rotz").empty() )
+ rot.SetZ( StrToFloat( node.Attribute("rotz") ) );
+
+ if ( !node.Attribute("scalex").empty() )
+ scale.SetX( StrToFloat( node.Attribute("scalex") ) );
+
+ if ( !node.Attribute("scaley").empty() )
+ scale.SetY( StrToFloat( node.Attribute("scaley") ) );
+
+ if ( !node.Attribute("scalez").empty() )
+ scale.SetZ( StrToFloat( node.Attribute("scalez") ) );
+
+ if ( !node.Attribute("movx").empty() )
+ pos.SetX( StrToFloat( node.Attribute("movx") ) );
+
+ if ( !node.Attribute("movy").empty() )
+ pos.SetY( StrToFloat( node.Attribute("movy") ) );
+
+ if ( !node.Attribute("movz").empty() )
+ pos.SetZ( StrToFloat( node.Attribute("movz") ) );
+
+ SetRotation(rot);
+ SetPosition(pos);
+ SetScale(scale);
+
+ MercuryNode::LoadFromXML( node );
+}
+
/***************************************************************************
* Copyright (C) 2008 by Joshua Allen *
* *
Modified: Mercury2/src/TransformNode.h
===================================================================
--- Mercury2/src/TransformNode.h 2008-12-04 01:50:32 UTC (rev 35)
+++ Mercury2/src/TransformNode.h 2008-12-04 01:52:54 UTC (rev 36)
@@ -26,6 +26,8 @@
void ComputeMatrix();
+ virtual void LoadFromXML(const XMLNode& node);
+
GENRTTI(TransformNode);
private:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-04 01:59:29
|
Revision: 38
http://hgengine.svn.sourceforge.net/hgengine/?rev=38&view=rev
Author: axlecrusher
Date: 2008-12-04 01:59:28 +0000 (Thu, 04 Dec 2008)
Log Message:
-----------
load from XML
Modified Paths:
--------------
Mercury2/src/Viewport.cpp
Mercury2/src/Viewport.h
Modified: Mercury2/src/Viewport.cpp
===================================================================
--- Mercury2/src/Viewport.cpp 2008-12-04 01:55:03 UTC (rev 37)
+++ Mercury2/src/Viewport.cpp 2008-12-04 01:59:28 UTC (rev 38)
@@ -2,6 +2,8 @@
#include <GL/gl.h>
//#include <GL/glut.h>
+REGISTER_NODE_TYPE(Viewport);
+
void Viewport::Render()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
@@ -13,7 +15,7 @@
void Viewport::Perspective( float fov, float aspect, float znear, float zfar )
{
float xmin, xmax, ymin, ymax;
-
+
ymax = znear * TAN(fov * Q_PI / 360.0);
ymin = -ymax;
xmin = ymin * aspect;
@@ -48,6 +50,16 @@
m_frustum.Transpose(); //XXX fix it to remove this
}
+void Viewport::LoadFromXML(const XMLNode& node)
+{
+ Perspective( StrToFloat(node.Attribute("fov")),
+ StrToFloat(node.Attribute("aspect")),
+ StrToFloat(node.Attribute("near")),
+ StrToFloat(node.Attribute("far")));
+
+ RenderableNode::LoadFromXML(node);
+}
+
/***************************************************************************
* Copyright (C) 2008 by Joshua Allen *
* *
Modified: Mercury2/src/Viewport.h
===================================================================
--- Mercury2/src/Viewport.h 2008-12-04 01:55:03 UTC (rev 37)
+++ Mercury2/src/Viewport.h 2008-12-04 01:59:28 UTC (rev 38)
@@ -6,6 +6,7 @@
virtual void Render();
void Perspective( float fov, float aspect, float znear, float zfar );
+ virtual void LoadFromXML(const XMLNode& node);
GENRTTI(Viewport);
private:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-04 02:01:20
|
Revision: 39
http://hgengine.svn.sourceforge.net/hgengine/?rev=39&view=rev
Author: axlecrusher
Date: 2008-12-04 02:01:18 +0000 (Thu, 04 Dec 2008)
Log Message:
-----------
load from xml
Modified Paths:
--------------
Mercury2/src/RenderableNode.cpp
Mercury2/src/RenderableNode.h
Modified: Mercury2/src/RenderableNode.cpp
===================================================================
--- Mercury2/src/RenderableNode.cpp 2008-12-04 01:59:28 UTC (rev 38)
+++ Mercury2/src/RenderableNode.cpp 2008-12-04 02:01:18 UTC (rev 39)
@@ -3,6 +3,8 @@
#include <GL/gl.h>
#include <TransformNode.h>
+#include <Quad.h>
+
using namespace std;
REGISTER_NODE_TYPE(RenderableNode);
@@ -17,7 +19,7 @@
void RenderableNode::Render()
{
list< MercuryAsset* >::iterator i;
-
+
MercuryNode* n = Parent();
TransformNode* tn;
for (; n; n = n->Parent())
@@ -94,6 +96,25 @@
RenderableNode::RecursiveRender( *i );
}
+void RenderableNode::LoadFromXML(const XMLNode& node)
+{
+ for (XMLNode child = node.Child(); child.IsValid(); child = child.NextNode())
+ {
+ if ( child.Name() == "asset" )
+ {
+ MAutoPtr< MercuryAsset > asset( AssetFactory::GetInstance().Generate(child.Attribute("type") ) );
+ if ( asset.IsValid() )
+ {
+ asset->LoadFromXML( child );
+ this->AddAsset( asset );
+ this->AddRender( asset );
+ }
+ }
+ }
+
+ MercuryNode::LoadFromXML( node );
+}
+
/***************************************************************************
* Copyright (C) 2008 by Joshua Allen *
* *
Modified: Mercury2/src/RenderableNode.h
===================================================================
--- Mercury2/src/RenderableNode.h 2008-12-04 01:59:28 UTC (rev 38)
+++ Mercury2/src/RenderableNode.h 2008-12-04 02:01:18 UTC (rev 39)
@@ -25,7 +25,8 @@
void AddPostRender(MercuryAsset* asset);
static void RecursiveRender( const MercuryNode* n );
-
+ virtual void LoadFromXML(const XMLNode& node);
+
GENRTTI(RenderableNode);
private:
bool IsInAssetList(MercuryAsset* asset) const;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-04 02:53:11
|
Revision: 44
http://hgengine.svn.sourceforge.net/hgengine/?rev=44&view=rev
Author: axlecrusher
Date: 2008-12-04 02:53:08 +0000 (Thu, 04 Dec 2008)
Log Message:
-----------
make a function that finds the global matrix
Modified Paths:
--------------
Mercury2/src/RenderableNode.cpp
Mercury2/src/RenderableNode.h
Modified: Mercury2/src/RenderableNode.cpp
===================================================================
--- Mercury2/src/RenderableNode.cpp 2008-12-04 02:12:05 UTC (rev 43)
+++ Mercury2/src/RenderableNode.cpp 2008-12-04 02:53:08 UTC (rev 44)
@@ -18,18 +18,9 @@
{
list< MercuryAsset* >::iterator i;
- MercuryNode* n = Parent();
- TransformNode* tn;
- for (; n; n = n->Parent())
- {
- if ( (tn = TransformNode::Cast(n)) )
- {
- MercuryMatrix m = tn->GetGlobalMatrix();
- m.Transpose();
- glLoadMatrixf( m.Ptr() );
- break;
- }
- }
+ MercuryMatrix m = FindGlobalMatrix();
+ m.Transpose();
+ glLoadMatrixf( m.Ptr() );
for (i = m_prerender.begin(); i != m_prerender.end(); ++i )
(*i)->PreRender(this);
@@ -41,6 +32,17 @@
(*i)->PostRender(this);
}
+const MercuryMatrix& RenderableNode::FindGlobalMatrix() const
+{
+ MercuryNode* n = NULL;
+ TransformNode* tn;
+ for (n = Parent(); n; n = n->Parent())
+ if ( (tn = TransformNode::Cast(n)) )
+ return tn->GetGlobalMatrix();
+
+ return MercuryMath::IdentityMatrix;
+}
+
void RenderableNode::AddPreRender(MercuryAsset* asset)
{
#ifdef MCHECKASSETS
Modified: Mercury2/src/RenderableNode.h
===================================================================
--- Mercury2/src/RenderableNode.h 2008-12-04 02:12:05 UTC (rev 43)
+++ Mercury2/src/RenderableNode.h 2008-12-04 02:53:08 UTC (rev 44)
@@ -4,6 +4,7 @@
#include <MercuryNode.h>
#include <MAutoPtr.h>
#include <MercuryAsset.h>
+#include <MercuryMatrix.h>
#define MCHECKASSETS
@@ -26,6 +27,8 @@
static void RecursiveRender( const MercuryNode* n );
virtual void LoadFromXML(const XMLNode& node);
+
+ const MercuryMatrix& FindGlobalMatrix() const;
GENRTTI(RenderableNode);
private:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-05 12:22:16
|
Revision: 48
http://hgengine.svn.sourceforge.net/hgengine/?rev=48&view=rev
Author: axlecrusher
Date: 2008-12-05 11:51:29 +0000 (Fri, 05 Dec 2008)
Log Message:
-----------
Quick and dirty texture
Modified Paths:
--------------
Mercury2/src/MercuryAsset.h
Mercury2/src/MercuryUtil.h
Mercury2/src/Quad.cpp
Mercury2/src/Viewport.cpp
Added Paths:
-----------
Mercury2/src/Texture.cpp
Mercury2/src/Texture.h
Modified: Mercury2/src/MercuryAsset.h
===================================================================
--- Mercury2/src/MercuryAsset.h 2008-12-05 11:49:09 UTC (rev 47)
+++ Mercury2/src/MercuryAsset.h 2008-12-05 11:51:29 UTC (rev 48)
@@ -13,7 +13,7 @@
virtual void Render(MercuryNode* node) = 0;
virtual void PostRender(MercuryNode* node) {};
- ///Loads a node from an XMLNode representing itself
+ ///Loads an asset from an XMLAsset representing itself
virtual void LoadFromXML(const XMLNode& node) {};
};
Modified: Mercury2/src/MercuryUtil.h
===================================================================
--- Mercury2/src/MercuryUtil.h 2008-12-05 11:49:09 UTC (rev 47)
+++ Mercury2/src/MercuryUtil.h 2008-12-05 11:51:29 UTC (rev 48)
@@ -10,6 +10,8 @@
#define SAFE_DELETE( x ) { if (x) { delete x; } x = NULL; }
#define SAFE_DELETE_ARRAY( x ) { if (x) { delete[] x; } x = NULL; }
+#define TO_ENDIAN( x )
+
#if defined(__GNUC__)
#define M_ALIGN(n) __attribute__((aligned(n)))
#else
Modified: Mercury2/src/Quad.cpp
===================================================================
--- Mercury2/src/Quad.cpp 2008-12-05 11:49:09 UTC (rev 47)
+++ Mercury2/src/Quad.cpp 2008-12-05 11:51:29 UTC (rev 48)
@@ -6,10 +6,18 @@
void Quad::Render(MercuryNode* node)
{
glBegin(GL_QUADS);
+ glTexCoord2f(0,0);
glVertex3f(-0.5f, -0.5f, 0.0f);
+
+ glTexCoord2f(1,0);
glVertex3f( 0.5f, -0.5f, 0.0f);
+
+ glTexCoord2f(1,1);
glVertex3f( 0.5f, 0.5f, 0.0f);
+
+ glTexCoord2f(0,1);
glVertex3f(-0.5f, 0.5f, 0.0f);
+
glEnd();
}
Added: Mercury2/src/Texture.cpp
===================================================================
--- Mercury2/src/Texture.cpp (rev 0)
+++ Mercury2/src/Texture.cpp 2008-12-05 11:51:29 UTC (rev 48)
@@ -0,0 +1,244 @@
+#include <Texture.h>
+#include <GL/gl.h>
+
+using namespace std;
+
+REGISTER_ASSET_TYPE(Texture);
+
+RawImageData* LoadBMP( const string& filename )
+{
+ int offset;
+ char* tmp = new char[sizeof(int)];
+ int compression = 0;
+ int length;
+ int rawlength = 0;
+ int bitsapix = 0;
+ unsigned char b[3];
+ unsigned int res_x, res_y;
+
+ FILE* file = fopen(filename.c_str(), "rb");
+ printf( "BMP Load Start\n" );
+ if (file==NULL)
+ {
+ printf("Could not open BMP (null file pointer)\n");
+ SAFE_DELETE_ARRAY(tmp);
+ return NULL;
+ }
+
+ //Get the type of file and test
+ memset(tmp, 0, 4);
+// file->Read(tmp, sizeof(char) * 2);
+ fread(tmp, sizeof(char) * 2, 1, file);
+ string type(tmp);
+
+ if (type != "BM")
+ {
+ printf("not a valid BMP\n");
+ SAFE_DELETE_ARRAY(tmp);
+ return NULL;
+ }
+ //Offset of bitmap data.
+ fseek(file, 10, SEEK_SET);
+// file->Seek(10);
+ fread(tmp, 4, 1, file);
+// file->Read(tmp, 4);
+ memcpy(&offset, tmp, 4);
+ TO_ENDIAN( offset );
+
+ RawImageData* image = new RawImageData;
+
+ //width & width
+ fseek(file, 18, SEEK_SET);
+// file->Seek(18);
+ fread(tmp, sizeof(int), 1, file);
+// file->Read(tmp, sizeof(int));
+ memcpy(&image->m_width, tmp, sizeof(int));
+ TO_ENDIAN( image->m_width );
+ fread(tmp, sizeof(int), 1, file);
+// file->Read(tmp, sizeof(int));
+ memcpy(&image->m_height, tmp, sizeof(int));
+ TO_ENDIAN( image->m_height );
+
+ //bits per pixel
+ memset(tmp, 0, sizeof(int));
+ fseek(file, 28, SEEK_SET);
+// file->Seek(28);
+// file->Read(tmp, sizeof(int));
+ fread(tmp, sizeof(int), 1, file);
+ memcpy(&bitsapix, tmp, sizeof(int));
+ TO_ENDIAN( bitsapix );
+
+ if (bitsapix != 24)
+ {
+ printf("is not 24b/pix\n");
+ SAFE_DELETE_ARRAY(tmp);
+ SAFE_DELETE_ARRAY(image);
+ return NULL;
+ }
+
+ //compression
+// file->Seek(30);
+ fseek(file, 30, SEEK_SET);
+// file->Read(tmp, sizeof(int));
+ fread(tmp, sizeof(int), 1, file);
+ memcpy(&compression, tmp, sizeof(int));
+ TO_ENDIAN(compression);
+
+ if (compression != 0)
+ {
+ printf("uses compression (not supported)\n");
+ SAFE_DELETE_ARRAY(tmp);
+ SAFE_DELETE_ARRAY(image);
+ return NULL;
+ }
+
+ //pix/m X
+ memset(tmp, 0, sizeof(int));
+// file->Seek(38);
+ fseek(file, 38, SEEK_SET);
+// file->Read(tmp, sizeof(int));
+ fread(tmp, sizeof(int), 1, file);
+ memcpy(&res_x, tmp, sizeof(int));
+ TO_ENDIAN(res_x);
+
+ //pix/m Y
+ memset(tmp, 0, sizeof(int));
+ fseek(file, 42, SEEK_SET);
+// file->Seek(42);
+// file->Read(tmp, sizeof(int));
+ fread(tmp, sizeof(int), 1, file);
+ memcpy(&res_y, tmp, sizeof(int));
+ TO_ENDIAN(res_y);
+
+ if (res_x > 0)
+ {
+// image->attrs.m_dpi_x = M2DPI(res_x);
+ }
+
+ if (res_y > 0)
+ {
+// image->attrs.m_dpi_y = M2DPI(res_y);
+ }
+
+ //Get the file length
+// length = file->Length();
+ fseek(file,0,SEEK_END);
+ length = ftell(file);
+ rawlength = (length) - (offset-1); //Remember to subtract 1 from the offset.
+
+ //Allocate space
+ SAFE_DELETE_ARRAY(image->m_data);
+ image->m_data = new unsigned char[rawlength];
+
+ memset(image->m_data, 0, rawlength);
+
+ //Get raw data and convert BGR->RGB
+// file->Seek(offset);
+ fseek(file, offset, SEEK_SET);
+// for (unsigned int x = 0; !file->Eof(); x += 3)
+ for (unsigned int x = 0; !feof(file); x += 3)
+ {
+ memset(b, 0, sizeof(unsigned char) * 3);
+// file->Read((char*)&b, sizeof(unsigned char) * 3);
+ fread(&b, sizeof(unsigned char) * 3, 1, file);
+
+ image->m_data[x] = b[2];
+ image->m_data[x+1] = b[1];
+ image->m_data[x+2] = b[0];
+ }
+// image->attrs.m_ColorByteType = RGB;
+ SAFE_DELETE_ARRAY(tmp);
+ printf( "BMP Load End\n" );
+// RID = image;
+ return image;
+}
+
+
+RawImageData::RawImageData()
+ :m_data(NULL)
+{
+}
+
+RawImageData::~RawImageData()
+{
+ SAFE_DELETE_ARRAY(m_data);
+}
+
+Texture::Texture()
+ :m_raw(NULL),m_textureID(0)
+{
+ glEnable( GL_TEXTURE_2D );
+}
+
+Texture::~Texture()
+{
+ if (m_textureID) glDeleteTextures(1, &m_textureID);
+ m_textureID = 0;
+
+ SAFE_DELETE(m_raw);
+}
+
+void Texture::LoadFromRaw(const RawImageData* raw)
+{
+ if ( !m_textureID ) glGenTextures(1, &m_textureID);
+
+ m_raw = raw;
+
+ glBindTexture(GL_TEXTURE_2D, m_textureID);
+ glTexImage2D(GL_TEXTURE_2D,
+ 0,
+ 3,
+ m_raw->m_width,
+ m_raw->m_height,
+ 0,
+ GL_RGB,
+ GL_UNSIGNED_BYTE,
+ m_raw->m_data);
+
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
+
+ glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
+
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+};
+
+void Texture::Render(MercuryNode* node)
+{
+ glEnable( GL_TEXTURE_2D );
+ glBindTexture(GL_TEXTURE_2D, m_textureID);
+}
+
+void Texture::LoadFromXML(const XMLNode& node)
+{
+ if ( !node.Attribute("imagefile").empty() )
+ {
+ RawImageData* d = LoadBMP( node.Attribute("imagefile") );
+ if (d) LoadFromRaw( d );
+ }
+}
+
+/***************************************************************************
+ * Copyright (C) 2008 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: *
+ * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. *
+ * * Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR *
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
Added: Mercury2/src/Texture.h
===================================================================
--- Mercury2/src/Texture.h (rev 0)
+++ Mercury2/src/Texture.h 2008-12-05 11:51:29 UTC (rev 48)
@@ -0,0 +1,55 @@
+#include <MercuryAsset.h>
+
+class RawImageData
+{
+ public:
+ RawImageData();
+ ~RawImageData();
+
+ unsigned int m_width;
+ unsigned int m_height;
+ unsigned short m_bits;
+ unsigned char* m_data;
+};
+
+class Texture : public MercuryAsset
+{
+ public:
+ Texture();
+ virtual ~Texture();
+
+ virtual void PreRender(MercuryNode* node) {};
+ virtual void Render(MercuryNode* node);
+ virtual void PostRender(MercuryNode* node) {};
+
+ virtual void LoadFromXML(const XMLNode& node);
+
+ void LoadFromRaw(const RawImageData* raw);
+ private:
+ const RawImageData* m_raw;
+ unsigned int m_textureID;
+};
+
+/***************************************************************************
+ * Copyright (C) 2008 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: *
+ * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. *
+ * * Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR *
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
Modified: Mercury2/src/Viewport.cpp
===================================================================
--- Mercury2/src/Viewport.cpp 2008-12-05 11:49:09 UTC (rev 47)
+++ Mercury2/src/Viewport.cpp 2008-12-05 11:51:29 UTC (rev 48)
@@ -1,6 +1,5 @@
#include <Viewport.h>
#include <GL/gl.h>
-//#include <GL/glut.h>
REGISTER_NODE_TYPE(Viewport);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-05 12:22:32
|
Revision: 47
http://hgengine.svn.sourceforge.net/hgengine/?rev=47&view=rev
Author: axlecrusher
Date: 2008-12-05 11:49:09 +0000 (Fri, 05 Dec 2008)
Log Message:
-----------
Hide and cull
Modified Paths:
--------------
Mercury2/src/RenderableNode.cpp
Mercury2/src/RenderableNode.h
Modified: Mercury2/src/RenderableNode.cpp
===================================================================
--- Mercury2/src/RenderableNode.cpp 2008-12-04 02:57:41 UTC (rev 46)
+++ Mercury2/src/RenderableNode.cpp 2008-12-05 11:49:09 UTC (rev 47)
@@ -7,6 +7,11 @@
REGISTER_NODE_TYPE(RenderableNode);
+RenderableNode::RenderableNode()
+ :m_hidden(false)
+{
+}
+
RenderableNode::~RenderableNode()
{
m_prerender.clear();
@@ -18,6 +23,8 @@
{
list< MercuryAsset* >::iterator i;
+ if (m_hidden || IsCulled()) return;
+
MercuryMatrix m = FindGlobalMatrix();
m.Transpose();
glLoadMatrixf( m.Ptr() );
@@ -71,12 +78,7 @@
m_postrender.push_back(asset);
}
-/*
-bool RenderableNode::IsMyType( MercuryNode* n )
-{
- return ( typeid(RenderableNode) == typeid(*n) );
-}
-*/
+
bool RenderableNode::IsInAssetList( MercuryAsset* asset ) const
{
std::list< MAutoPtr< MercuryAsset > >::const_iterator i;
@@ -97,7 +99,10 @@
}
void RenderableNode::LoadFromXML(const XMLNode& node)
-{
+{
+ if ( !node.Attribute("hidden").empty() )
+ m_hidden = node.Attribute("hidden")=="true"?true:false;
+
for (XMLNode child = node.Child(); child.IsValid(); child = child.NextNode())
{
if ( child.Name() == "asset" )
Modified: Mercury2/src/RenderableNode.h
===================================================================
--- Mercury2/src/RenderableNode.h 2008-12-04 02:57:41 UTC (rev 46)
+++ Mercury2/src/RenderableNode.h 2008-12-05 11:49:09 UTC (rev 47)
@@ -11,6 +11,7 @@
class RenderableNode : public MercuryNode
{
public:
+ RenderableNode();
~RenderableNode();
virtual void Render();
@@ -29,8 +30,12 @@
virtual void LoadFromXML(const XMLNode& node);
const MercuryMatrix& FindGlobalMatrix() const;
+
+ virtual bool IsCulled() { return false; }
GENRTTI(RenderableNode);
+ protected:
+ bool m_hidden;
private:
bool IsInAssetList(MercuryAsset* asset) const;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-05 23:54:58
|
Revision: 50
http://hgengine.svn.sourceforge.net/hgengine/?rev=50&view=rev
Author: axlecrusher
Date: 2008-12-05 23:54:50 +0000 (Fri, 05 Dec 2008)
Log Message:
-----------
texture should make use of the postrender to disable or unbind the textures that it set up in render
Modified Paths:
--------------
Mercury2/src/MercuryAsset.cpp
Mercury2/src/MercuryAsset.h
Mercury2/src/RenderableNode.cpp
Mercury2/src/Texture.cpp
Mercury2/src/Texture.h
Modified: Mercury2/src/MercuryAsset.cpp
===================================================================
--- Mercury2/src/MercuryAsset.cpp 2008-12-05 11:53:20 UTC (rev 49)
+++ Mercury2/src/MercuryAsset.cpp 2008-12-05 23:54:50 UTC (rev 50)
@@ -1,12 +1,19 @@
#include <MercuryAsset.h>
+#include <RenderableNode.h>
+void MercuryAsset::Init(MercuryNode* node)
+{
+ RenderableNode* rn;
+ if ( (rn=RenderableNode::Cast( node )) )
+ rn->AddRender(this);
+}
+
AssetFactory& AssetFactory::GetInstance()
{
static AssetFactory* instance = NULL;
if (!instance)
instance = new AssetFactory;
return *instance;
-
}
bool AssetFactory::RegisterFactoryCallback(const std::string& type, Callback0R< MAutoPtr<MercuryAsset> > functor)
Modified: Mercury2/src/MercuryAsset.h
===================================================================
--- Mercury2/src/MercuryAsset.h 2008-12-05 11:53:20 UTC (rev 49)
+++ Mercury2/src/MercuryAsset.h 2008-12-05 23:54:50 UTC (rev 50)
@@ -9,6 +9,8 @@
public:
virtual ~MercuryAsset() {};
+ virtual void Init(MercuryNode* node);
+
virtual void PreRender(MercuryNode* node) {};
virtual void Render(MercuryNode* node) = 0;
virtual void PostRender(MercuryNode* node) {};
Modified: Mercury2/src/RenderableNode.cpp
===================================================================
--- Mercury2/src/RenderableNode.cpp 2008-12-05 11:53:20 UTC (rev 49)
+++ Mercury2/src/RenderableNode.cpp 2008-12-05 23:54:50 UTC (rev 50)
@@ -112,7 +112,7 @@
{
asset->LoadFromXML( child );
this->AddAsset( asset );
- this->AddRender( asset );
+ asset->Init( this );
}
}
}
Modified: Mercury2/src/Texture.cpp
===================================================================
--- Mercury2/src/Texture.cpp 2008-12-05 11:53:20 UTC (rev 49)
+++ Mercury2/src/Texture.cpp 2008-12-05 23:54:50 UTC (rev 50)
@@ -1,5 +1,6 @@
#include <Texture.h>
#include <GL/gl.h>
+#include <RenderableNode.h>
using namespace std;
@@ -178,6 +179,15 @@
SAFE_DELETE(m_raw);
}
+void Texture::Init(MercuryNode* node)
+{
+ MercuryAsset::Init( node );
+
+ RenderableNode* rn;
+ if ( (rn=RenderableNode::Cast( node )) )
+ rn->AddPostRender( this );
+}
+
void Texture::LoadFromRaw(const RawImageData* raw)
{
if ( !m_textureID ) glGenTextures(1, &m_textureID);
@@ -202,6 +212,7 @@
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+
};
void Texture::Render(MercuryNode* node)
@@ -210,6 +221,11 @@
glBindTexture(GL_TEXTURE_2D, m_textureID);
}
+void Texture::PostRender(MercuryNode* node)
+{
+ glDisable( GL_TEXTURE_2D );
+}
+
void Texture::LoadFromXML(const XMLNode& node)
{
if ( !node.Attribute("imagefile").empty() )
Modified: Mercury2/src/Texture.h
===================================================================
--- Mercury2/src/Texture.h 2008-12-05 11:53:20 UTC (rev 49)
+++ Mercury2/src/Texture.h 2008-12-05 23:54:50 UTC (rev 50)
@@ -17,10 +17,11 @@
public:
Texture();
virtual ~Texture();
+
+ virtual void Init(MercuryNode* node);
- virtual void PreRender(MercuryNode* node) {};
virtual void Render(MercuryNode* node);
- virtual void PostRender(MercuryNode* node) {};
+ virtual void PostRender(MercuryNode* node);
virtual void LoadFromXML(const XMLNode& node);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-06 19:53:50
|
Revision: 51
http://hgengine.svn.sourceforge.net/hgengine/?rev=51&view=rev
Author: axlecrusher
Date: 2008-12-06 19:53:45 +0000 (Sat, 06 Dec 2008)
Log Message:
-----------
support multi texture
Modified Paths:
--------------
Mercury2/src/Texture.cpp
Mercury2/src/Texture.h
Modified: Mercury2/src/Texture.cpp
===================================================================
--- Mercury2/src/Texture.cpp 2008-12-05 23:54:50 UTC (rev 50)
+++ Mercury2/src/Texture.cpp 2008-12-06 19:53:45 UTC (rev 51)
@@ -1,7 +1,11 @@
#include <Texture.h>
-#include <GL/gl.h>
#include <RenderableNode.h>
+#define GL_GLEXT_PROTOTYPES
+
+#include <GL/gl.h>
+#include <GL/glext.h>
+
using namespace std;
REGISTER_ASSET_TYPE(Texture);
@@ -168,7 +172,11 @@
Texture::Texture()
:m_raw(NULL),m_textureID(0)
{
- glEnable( GL_TEXTURE_2D );
+ if (!m_initTextureSuccess)
+ {
+ m_initTextureSuccess = true;
+ m_activeTextures = 0;
+ }
}
Texture::~Texture()
@@ -208,7 +216,7 @@
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
- glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
+// glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
@@ -217,13 +225,12 @@
void Texture::Render(MercuryNode* node)
{
- glEnable( GL_TEXTURE_2D );
- glBindTexture(GL_TEXTURE_2D, m_textureID);
+ BindTexture();
}
void Texture::PostRender(MercuryNode* node)
{
- glDisable( GL_TEXTURE_2D );
+ UnbindTexture();
}
void Texture::LoadFromXML(const XMLNode& node)
@@ -235,6 +242,26 @@
}
}
+void Texture::BindTexture()
+{
+ m_textureResource = GL_TEXTURE0+m_activeTextures;
+ glActiveTexture( m_textureResource );
+ glEnable( GL_TEXTURE_2D );
+ glBindTexture(GL_TEXTURE_2D, m_textureID);
+ glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
+ ++m_activeTextures;
+}
+
+void Texture::UnbindTexture()
+{
+ glActiveTexture( m_textureResource );
+ glDisable( GL_TEXTURE_2D );
+ --m_activeTextures;
+}
+
+bool Texture::m_initTextureSuccess;
+unsigned short Texture::m_activeTextures;
+
/***************************************************************************
* Copyright (C) 2008 by Joshua Allen *
* *
Modified: Mercury2/src/Texture.h
===================================================================
--- Mercury2/src/Texture.h 2008-12-05 23:54:50 UTC (rev 50)
+++ Mercury2/src/Texture.h 2008-12-06 19:53:45 UTC (rev 51)
@@ -26,9 +26,19 @@
virtual void LoadFromXML(const XMLNode& node);
void LoadFromRaw(const RawImageData* raw);
+
+ inline static unsigned short NumberActiveTextures() { return m_activeTextures; }
+
private:
+ void BindTexture();
+ void UnbindTexture();
+
const RawImageData* m_raw;
unsigned int m_textureID;
+ unsigned int m_textureResource;
+
+ static bool m_initTextureSuccess;
+ static unsigned short m_activeTextures;
};
/***************************************************************************
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-06 20:16:48
|
Revision: 52
http://hgengine.svn.sourceforge.net/hgengine/?rev=52&view=rev
Author: axlecrusher
Date: 2008-12-06 20:16:44 +0000 (Sat, 06 Dec 2008)
Log Message:
-----------
update
Modified Paths:
--------------
Mercury2/src/MercuryWindow.h
Mercury2/src/X11Window.h
Modified: Mercury2/src/MercuryWindow.h
===================================================================
--- Mercury2/src/MercuryWindow.h 2008-12-06 19:53:45 UTC (rev 51)
+++ Mercury2/src/MercuryWindow.h 2008-12-06 20:16:44 UTC (rev 52)
@@ -14,14 +14,25 @@
MercuryWindow(const string& title, int width, int height, int bits, int depthBits, bool fullscreen);
virtual ~MercuryWindow();
- inline static MercuryWindow* MakeWindow() { return genWindowClbk(); }
+ inline static MercuryWindow* MakeWindow() {
+ MercuryWindow::m_windowInstance = genWindowClbk();
+ return GetCurrentWindow();
+ }
virtual bool SwapBuffers() = 0;
virtual bool PumpMessages() = 0;
+
+ inline static MercuryWindow* GetCurrentWindow()
+ {
+ return MercuryWindow::m_windowInstance;
+ }
+
+ virtual void* GetProcAddress(const string& x) = 0;
protected:
static Callback0R< MercuryWindow* > genWindowClbk;
-
+ static MercuryWindow* m_windowInstance;
+
string m_title;
int m_width, m_height, m_bits, m_depthBits;
bool m_fullscreen;
Modified: Mercury2/src/X11Window.h
===================================================================
--- Mercury2/src/X11Window.h 2008-12-06 19:53:45 UTC (rev 51)
+++ Mercury2/src/X11Window.h 2008-12-06 20:16:44 UTC (rev 52)
@@ -14,6 +14,8 @@
virtual bool SwapBuffers();
virtual bool PumpMessages();
+ virtual void* GetProcAddress(const string& x);
+
private:
Display* m_display;
GLXContext m_renderCtx;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-06 20:18:05
|
Revision: 53
http://hgengine.svn.sourceforge.net/hgengine/?rev=53&view=rev
Author: axlecrusher
Date: 2008-12-06 20:18:00 +0000 (Sat, 06 Dec 2008)
Log Message:
-----------
Update
Modified Paths:
--------------
Mercury2/src/MercuryWindow.cpp
Mercury2/src/X11Window.cpp
Modified: Mercury2/src/MercuryWindow.cpp
===================================================================
--- Mercury2/src/MercuryWindow.cpp 2008-12-06 20:16:44 UTC (rev 52)
+++ Mercury2/src/MercuryWindow.cpp 2008-12-06 20:18:00 UTC (rev 53)
@@ -10,6 +10,8 @@
{
}
+MercuryWindow* MercuryWindow::m_windowInstance;
+
/*
* Copyright (c) 2008, Joshua Allen
* All rights reserved.
Modified: Mercury2/src/X11Window.cpp
===================================================================
--- Mercury2/src/X11Window.cpp 2008-12-06 20:16:44 UTC (rev 52)
+++ Mercury2/src/X11Window.cpp 2008-12-06 20:18:00 UTC (rev 53)
@@ -143,6 +143,11 @@
return true;
}
+void* X11Window::GetProcAddress(const string& x)
+{
+
+}
+
/***************************************************************************
* 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-07 02:57:00
|
Revision: 57
http://hgengine.svn.sourceforge.net/hgengine/?rev=57&view=rev
Author: axlecrusher
Date: 2008-12-07 02:56:50 +0000 (Sun, 07 Dec 2008)
Log Message:
-----------
Seperate textures and image types, and use an image loader to load registered image types
Modified Paths:
--------------
Mercury2/src/Callback.h
Mercury2/src/Texture.cpp
Mercury2/src/Texture.h
Added Paths:
-----------
Mercury2/src/BMPLoader.cpp
Mercury2/src/ImageLoader.cpp
Mercury2/src/ImageLoader.h
Mercury2/src/RawImageData.cpp
Mercury2/src/RawImageData.h
Added: Mercury2/src/BMPLoader.cpp
===================================================================
--- Mercury2/src/BMPLoader.cpp (rev 0)
+++ Mercury2/src/BMPLoader.cpp 2008-12-07 02:56:50 UTC (rev 57)
@@ -0,0 +1,187 @@
+#include <RawImageData.h>
+#include <MercuryUtil.h>
+#include <ImageLoader.h>
+
+using namespace std;
+
+RawImageData* LoadBMP( FILE* file )
+{
+ int offset;
+ char* tmp = new char[sizeof(int)];
+ int compression = 0;
+ int length;
+ int rawlength = 0;
+ int bitsapix = 0;
+ unsigned char b[3];
+ unsigned int res_x, res_y;
+
+// FILE* file = fopen(filename.c_str(), "rb");
+ printf( "BMP Load Start\n" );
+ if (file==NULL)
+ {
+ printf("Could not open BMP (null file pointer)\n");
+ SAFE_DELETE_ARRAY(tmp);
+ return NULL;
+ }
+
+ //Get the type of file and test
+ memset(tmp, 0, 4);
+// file->Read(tmp, sizeof(char) * 2);
+ fread(tmp, sizeof(char) * 2, 1, file);
+ string type(tmp);
+
+ if (type != "BM")
+ {
+ printf("not a valid BMP\n");
+ SAFE_DELETE_ARRAY(tmp);
+ return NULL;
+ }
+ //Offset of bitmap data.
+ fseek(file, 10, SEEK_SET);
+// file->Seek(10);
+ fread(tmp, 4, 1, file);
+// file->Read(tmp, 4);
+ memcpy(&offset, tmp, 4);
+ TO_ENDIAN( offset );
+
+ RawImageData* image = new RawImageData;
+
+ //width & width
+ fseek(file, 18, SEEK_SET);
+// file->Seek(18);
+ fread(tmp, sizeof(int), 1, file);
+// file->Read(tmp, sizeof(int));
+ memcpy(&image->m_width, tmp, sizeof(int));
+ TO_ENDIAN( image->m_width );
+ fread(tmp, sizeof(int), 1, file);
+// file->Read(tmp, sizeof(int));
+ memcpy(&image->m_height, tmp, sizeof(int));
+ TO_ENDIAN( image->m_height );
+
+ //bits per pixel
+ memset(tmp, 0, sizeof(int));
+ fseek(file, 28, SEEK_SET);
+// file->Seek(28);
+// file->Read(tmp, sizeof(int));
+ fread(tmp, sizeof(int), 1, file);
+ memcpy(&bitsapix, tmp, sizeof(int));
+ TO_ENDIAN( bitsapix );
+
+ if (bitsapix != 24)
+ {
+ printf("is not 24b/pix\n");
+ SAFE_DELETE_ARRAY(tmp);
+ SAFE_DELETE_ARRAY(image);
+ return NULL;
+ }
+
+ //compression
+// file->Seek(30);
+ fseek(file, 30, SEEK_SET);
+// file->Read(tmp, sizeof(int));
+ fread(tmp, sizeof(int), 1, file);
+ memcpy(&compression, tmp, sizeof(int));
+ TO_ENDIAN(compression);
+
+ if (compression != 0)
+ {
+ printf("uses compression (not supported)\n");
+ SAFE_DELETE_ARRAY(tmp);
+ SAFE_DELETE_ARRAY(image);
+ return NULL;
+ }
+
+ //pix/m X
+ memset(tmp, 0, sizeof(int));
+// file->Seek(38);
+ fseek(file, 38, SEEK_SET);
+// file->Read(tmp, sizeof(int));
+ fread(tmp, sizeof(int), 1, file);
+ memcpy(&res_x, tmp, sizeof(int));
+ TO_ENDIAN(res_x);
+
+ //pix/m Y
+ memset(tmp, 0, sizeof(int));
+ fseek(file, 42, SEEK_SET);
+// file->Seek(42);
+// file->Read(tmp, sizeof(int));
+ fread(tmp, sizeof(int), 1, file);
+ memcpy(&res_y, tmp, sizeof(int));
+ TO_ENDIAN(res_y);
+
+ if (res_x > 0)
+ {
+// image->attrs.m_dpi_x = M2DPI(res_x);
+ }
+
+ if (res_y > 0)
+ {
+// image->attrs.m_dpi_y = M2DPI(res_y);
+ }
+
+ //Get the file length
+// length = file->Length();
+ fseek(file,0,SEEK_END);
+ length = ftell(file);
+ rawlength = (length) - (offset-1); //Remember to subtract 1 from the offset.
+
+ //Allocate space
+ SAFE_DELETE_ARRAY(image->m_data);
+ image->m_data = new unsigned char[rawlength];
+
+ memset(image->m_data, 0, rawlength);
+
+ //Get raw data and convert BGR->RGB
+// file->Seek(offset);
+ fseek(file, offset, SEEK_SET);
+// for (unsigned int x = 0; !file->Eof(); x += 3)
+ for (unsigned int x = 0; !feof(file); x += 3)
+ {
+ memset(b, 0, sizeof(unsigned char) * 3);
+// file->Read((char*)&b, sizeof(unsigned char) * 3);
+ fread(&b, sizeof(unsigned char) * 3, 1, file);
+
+ image->m_data[x] = b[2];
+ image->m_data[x+1] = b[1];
+ image->m_data[x+2] = b[0];
+ }
+// image->attrs.m_ColorByteType = RGB;
+ SAFE_DELETE_ARRAY(tmp);
+ printf( "BMP Load End\n" );
+// RID = image;
+ return image;
+}
+
+REGISTER_IMAGE_TYPE(BM6, LoadBMP);
+
+/****************************************************************************
+ * Copyright (C) 2008 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
Modified: Mercury2/src/Callback.h
===================================================================
--- Mercury2/src/Callback.h 2008-12-06 21:58:06 UTC (rev 56)
+++ Mercury2/src/Callback.h 2008-12-07 02:56:50 UTC (rev 57)
@@ -35,7 +35,24 @@
R (*functor)(void);
};
+template <typename P1, typename R1>
+ class Callback1R
+{
+ public:
+ Callback1R(R1(*f)(P1))
+ :functor(f)
+ {}
+ R1 operator()(P1 p1) const
+ {
+ functor(p1);
+ }
+
+ private:
+ R1 (*functor)(P1);
+};
+
+
template <typename P1>
class Callback1
{
Added: Mercury2/src/ImageLoader.cpp
===================================================================
--- Mercury2/src/ImageLoader.cpp (rev 0)
+++ Mercury2/src/ImageLoader.cpp 2008-12-07 02:56:50 UTC (rev 57)
@@ -0,0 +1,77 @@
+#include <ImageLoader.h>
+#include <string>
+#include <MercuryUtil.h>
+
+using namespace std;
+
+ImageLoader& ImageLoader::GetInstance()
+{
+ static ImageLoader* instance = NULL;
+ if (!instance)
+ instance = new ImageLoader;
+ return *instance;
+}
+
+bool ImageLoader::RegisterFactoryCallback(const std::string& type, Callback1R< FILE*, RawImageData* > functor)
+{
+ string t = ToUpper( type );
+ std::pair<std::string, Callback1R< FILE*, RawImageData* > > pp(t, functor);
+ m_factoryCallbacks.push_back( pp );
+ return true;
+}
+
+RawImageData* ImageLoader::LoadImage(const std::string& filename)
+{
+ FILE* f = fopen(filename.c_str(), "rb");
+ char fingerprint[4];
+ fingerprint[3] = 0;
+
+ 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;
+ for (i = m_factoryCallbacks.begin(); i != m_factoryCallbacks.end(); ++i)
+ {
+ if (i->first == t)
+ {
+ RawImageData* d = i->second(f);
+ fclose(f);
+ return d;
+ }
+ }
+ fclose(f);
+ return NULL;
+}
+
+/****************************************************************************
+ * Copyright (C) 2008 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury 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/ImageLoader.h
===================================================================
--- Mercury2/src/ImageLoader.h (rev 0)
+++ Mercury2/src/ImageLoader.h 2008-12-07 02:56:50 UTC (rev 57)
@@ -0,0 +1,60 @@
+#ifndef IMAGELOADER_H
+#define IMAGELOADER_H
+
+#include <string>
+#include <RawImageData.h>
+#include <Callback.h>
+#include <list>
+#include <MercuryUtil.h>
+
+class ImageLoader
+{
+ public:
+ static ImageLoader& GetInstance();
+ bool RegisterFactoryCallback(const std::string& type, Callback1R< FILE*, RawImageData* >);
+ RawImageData* LoadImage(const std::string& filename);
+
+ private:
+ std::list< std::pair< std::string, Callback1R< FILE*, RawImageData* > > > m_factoryCallbacks;
+};
+
+static InstanceCounter<ImageLoader> ILcounter("ImageLoader");
+
+#define REGISTER_IMAGE_TYPE(fingerprint,functor)\
+ Callback1R< FILE*, RawImageData* > factoryclbk##functor( functor ); \
+ bool GlobalImageRegisterSuccess##functor = ImageLoader::GetInstance().RegisterFactoryCallback(#fingerprint, factoryclbk##functor);
+
+
+#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/RawImageData.cpp
===================================================================
--- Mercury2/src/RawImageData.cpp (rev 0)
+++ Mercury2/src/RawImageData.cpp 2008-12-07 02:56:50 UTC (rev 57)
@@ -0,0 +1,44 @@
+#include <RawImageData.h>
+#include <MercuryUtil.h>
+
+RawImageData::RawImageData()
+ :m_data(NULL)
+{
+}
+
+RawImageData::~RawImageData()
+{
+ SAFE_DELETE_ARRAY(m_data);
+}
+
+/****************************************************************************
+ * 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/RawImageData.h
===================================================================
--- Mercury2/src/RawImageData.h (rev 0)
+++ Mercury2/src/RawImageData.h 2008-12-07 02:56:50 UTC (rev 57)
@@ -0,0 +1,48 @@
+#ifndef RAWIMAGEDATA_H
+#define RAWIMAGEDATA_H
+
+class RawImageData
+{
+ public:
+ RawImageData();
+ ~RawImageData();
+
+ unsigned int m_width;
+ unsigned int m_height;
+ unsigned short m_bits;
+ unsigned char* m_data;
+};
+
+#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. *
+ ***************************************************************************/
Modified: Mercury2/src/Texture.cpp
===================================================================
--- Mercury2/src/Texture.cpp 2008-12-06 21:58:06 UTC (rev 56)
+++ Mercury2/src/Texture.cpp 2008-12-07 02:56:50 UTC (rev 57)
@@ -1,5 +1,6 @@
#include <Texture.h>
#include <RenderableNode.h>
+#include <ImageLoader.h>
#define GL_GLEXT_PROTOTYPES
@@ -10,165 +11,6 @@
REGISTER_ASSET_TYPE(Texture);
-RawImageData* LoadBMP( const string& filename )
-{
- int offset;
- char* tmp = new char[sizeof(int)];
- int compression = 0;
- int length;
- int rawlength = 0;
- int bitsapix = 0;
- unsigned char b[3];
- unsigned int res_x, res_y;
-
- FILE* file = fopen(filename.c_str(), "rb");
- printf( "BMP Load Start\n" );
- if (file==NULL)
- {
- printf("Could not open BMP (null file pointer)\n");
- SAFE_DELETE_ARRAY(tmp);
- return NULL;
- }
-
- //Get the type of file and test
- memset(tmp, 0, 4);
-// file->Read(tmp, sizeof(char) * 2);
- fread(tmp, sizeof(char) * 2, 1, file);
- string type(tmp);
-
- if (type != "BM")
- {
- printf("not a valid BMP\n");
- SAFE_DELETE_ARRAY(tmp);
- return NULL;
- }
- //Offset of bitmap data.
- fseek(file, 10, SEEK_SET);
-// file->Seek(10);
- fread(tmp, 4, 1, file);
-// file->Read(tmp, 4);
- memcpy(&offset, tmp, 4);
- TO_ENDIAN( offset );
-
- RawImageData* image = new RawImageData;
-
- //width & width
- fseek(file, 18, SEEK_SET);
-// file->Seek(18);
- fread(tmp, sizeof(int), 1, file);
-// file->Read(tmp, sizeof(int));
- memcpy(&image->m_width, tmp, sizeof(int));
- TO_ENDIAN( image->m_width );
- fread(tmp, sizeof(int), 1, file);
-// file->Read(tmp, sizeof(int));
- memcpy(&image->m_height, tmp, sizeof(int));
- TO_ENDIAN( image->m_height );
-
- //bits per pixel
- memset(tmp, 0, sizeof(int));
- fseek(file, 28, SEEK_SET);
-// file->Seek(28);
-// file->Read(tmp, sizeof(int));
- fread(tmp, sizeof(int), 1, file);
- memcpy(&bitsapix, tmp, sizeof(int));
- TO_ENDIAN( bitsapix );
-
- if (bitsapix != 24)
- {
- printf("is not 24b/pix\n");
- SAFE_DELETE_ARRAY(tmp);
- SAFE_DELETE_ARRAY(image);
- return NULL;
- }
-
- //compression
-// file->Seek(30);
- fseek(file, 30, SEEK_SET);
-// file->Read(tmp, sizeof(int));
- fread(tmp, sizeof(int), 1, file);
- memcpy(&compression, tmp, sizeof(int));
- TO_ENDIAN(compression);
-
- if (compression != 0)
- {
- printf("uses compression (not supported)\n");
- SAFE_DELETE_ARRAY(tmp);
- SAFE_DELETE_ARRAY(image);
- return NULL;
- }
-
- //pix/m X
- memset(tmp, 0, sizeof(int));
-// file->Seek(38);
- fseek(file, 38, SEEK_SET);
-// file->Read(tmp, sizeof(int));
- fread(tmp, sizeof(int), 1, file);
- memcpy(&res_x, tmp, sizeof(int));
- TO_ENDIAN(res_x);
-
- //pix/m Y
- memset(tmp, 0, sizeof(int));
- fseek(file, 42, SEEK_SET);
-// file->Seek(42);
-// file->Read(tmp, sizeof(int));
- fread(tmp, sizeof(int), 1, file);
- memcpy(&res_y, tmp, sizeof(int));
- TO_ENDIAN(res_y);
-
- if (res_x > 0)
- {
-// image->attrs.m_dpi_x = M2DPI(res_x);
- }
-
- if (res_y > 0)
- {
-// image->attrs.m_dpi_y = M2DPI(res_y);
- }
-
- //Get the file length
-// length = file->Length();
- fseek(file,0,SEEK_END);
- length = ftell(file);
- rawlength = (length) - (offset-1); //Remember to subtract 1 from the offset.
-
- //Allocate space
- SAFE_DELETE_ARRAY(image->m_data);
- image->m_data = new unsigned char[rawlength];
-
- memset(image->m_data, 0, rawlength);
-
- //Get raw data and convert BGR->RGB
-// file->Seek(offset);
- fseek(file, offset, SEEK_SET);
-// for (unsigned int x = 0; !file->Eof(); x += 3)
- for (unsigned int x = 0; !feof(file); x += 3)
- {
- memset(b, 0, sizeof(unsigned char) * 3);
-// file->Read((char*)&b, sizeof(unsigned char) * 3);
- fread(&b, sizeof(unsigned char) * 3, 1, file);
-
- image->m_data[x] = b[2];
- image->m_data[x+1] = b[1];
- image->m_data[x+2] = b[0];
- }
-// image->attrs.m_ColorByteType = RGB;
- SAFE_DELETE_ARRAY(tmp);
- printf( "BMP Load End\n" );
-// RID = image;
- return image;
-}
-
-
-RawImageData::RawImageData()
- :m_data(NULL)
-{
-}
-
-RawImageData::~RawImageData()
-{
- SAFE_DELETE_ARRAY(m_data);
-}
-
Texture::Texture()
:m_raw(NULL),m_textureID(0)
{
@@ -218,8 +60,8 @@
// glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
+ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
};
@@ -237,7 +79,8 @@
{
if ( !node.Attribute("imagefile").empty() )
{
- RawImageData* d = LoadBMP( node.Attribute("imagefile") );
+// RawImageData* d = LoadBMP( node.Attribute("imagefile") );
+ RawImageData* d = ImageLoader::GetInstance().LoadImage( node.Attribute("imagefile") );
if (d) LoadFromRaw( d );
}
}
Modified: Mercury2/src/Texture.h
===================================================================
--- Mercury2/src/Texture.h 2008-12-06 21:58:06 UTC (rev 56)
+++ Mercury2/src/Texture.h 2008-12-07 02:56:50 UTC (rev 57)
@@ -1,17 +1,6 @@
#include <MercuryAsset.h>
+#include <RawImageData.h>
-class RawImageData
-{
- public:
- RawImageData();
- ~RawImageData();
-
- unsigned int m_width;
- unsigned int m_height;
- unsigned short m_bits;
- unsigned char* m_data;
-};
-
class Texture : public MercuryAsset
{
public:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-07 03:46:19
|
Revision: 59
http://hgengine.svn.sourceforge.net/hgengine/?rev=59&view=rev
Author: axlecrusher
Date: 2008-12-07 03:46:14 +0000 (Sun, 07 Dec 2008)
Log Message:
-----------
add png loading
Modified Paths:
--------------
Mercury2/src/BMPLoader.cpp
Mercury2/src/MercuryUtil.h
Mercury2/src/RawImageData.h
Mercury2/src/Texture.cpp
Added Paths:
-----------
Mercury2/src/PNGLoader.cpp
Modified: Mercury2/src/BMPLoader.cpp
===================================================================
--- Mercury2/src/BMPLoader.cpp 2008-12-07 03:43:41 UTC (rev 58)
+++ Mercury2/src/BMPLoader.cpp 2008-12-07 03:46:14 UTC (rev 59)
@@ -137,6 +137,7 @@
// for (unsigned int x = 0; !file->Eof(); x += 3)
for (unsigned int x = 0; !feof(file); x += 3)
{
+ //XXX FIX THIS, BMP ARE STORED UPSIDE DOWN
memset(b, 0, sizeof(unsigned char) * 3);
// file->Read((char*)&b, sizeof(unsigned char) * 3);
fread(&b, sizeof(unsigned char) * 3, 1, file);
@@ -145,14 +146,16 @@
image->m_data[x+1] = b[1];
image->m_data[x+2] = b[0];
}
-// image->attrs.m_ColorByteType = RGB;
+ image->m_ColorByteType = RGB;
SAFE_DELETE_ARRAY(tmp);
printf( "BMP Load End\n" );
// RID = image;
return image;
}
+//I think the fingerprint is actually just BM
REGISTER_IMAGE_TYPE(BM6, LoadBMP);
+//REGISTER_IMAGE_TYPE(BM8, LoadBMP);
/****************************************************************************
* Copyright (C) 2008 by Joshua Allen *
Modified: Mercury2/src/MercuryUtil.h
===================================================================
--- Mercury2/src/MercuryUtil.h 2008-12-07 03:43:41 UTC (rev 58)
+++ Mercury2/src/MercuryUtil.h 2008-12-07 03:46:14 UTC (rev 59)
@@ -9,6 +9,7 @@
#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 TO_ENDIAN( x )
Added: Mercury2/src/PNGLoader.cpp
===================================================================
--- Mercury2/src/PNGLoader.cpp (rev 0)
+++ Mercury2/src/PNGLoader.cpp 2008-12-07 03:46:14 UTC (rev 59)
@@ -0,0 +1,174 @@
+#include <ImageLoader.h>
+#include <png.h>
+#include <MercuryUtil.h>
+
+#include <assert.h>
+
+void PNGRead( png_struct *png, png_byte *p, png_size_t size )
+{
+ FILE* f = (FILE*)png->io_ptr;
+
+// int got = f->Read( p, size );
+ int got = fread(p, size, 1, f );
+
+ if( got == -1 )
+ png_error( png, "Error reading from file");
+// else if( got != size )
+// png_error( png, "Unexpected EOF" );
+}
+
+RawImageData* LoadPNG( FILE * fp )
+{
+ png_structp png_ptr;
+ png_infop info_ptr;
+ int number_of_passes;
+ png_bytep* row_pointers;
+ png_byte color_type;
+ png_byte bit_depth;
+ RawImageData* image = 0;
+ unsigned char header[8]; // 8 is the maximum size that can be checked
+
+ //open file and test for it being a png
+ if (!fp)
+ assert("[read_png_file] File %s could not be opened for reading");
+// fp->Read(header, 8 );
+ fread(header, 8, 1, fp);
+ if (png_sig_cmp(header, 0, 8))
+ assert("[read_png_file] File %s is not recognized as a PNG file");
+
+
+ //initialize stuff
+ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
+
+ if (!png_ptr)
+ assert("[read_png_file] png_create_read_struct failed");
+
+ info_ptr = png_create_info_struct(png_ptr);
+ if (!info_ptr)
+ assert("[read_png_file] png_create_info_struct failed");
+
+ if (setjmp(png_jmpbuf(png_ptr)))
+ assert("[read_png_file] Error during init_io");
+
+ png_set_sig_bytes(png_ptr, 8);
+ png_set_read_fn( png_ptr, fp, PNGRead );
+
+ png_read_info(png_ptr, info_ptr);
+
+ image = new RawImageData;
+
+ image->m_width = info_ptr->width;
+ image->m_height = info_ptr->height;
+ color_type = info_ptr->color_type;
+ bit_depth = info_ptr->bit_depth;
+
+// if ( color_type & PNG_COLOR_MASK_PALETTE )
+// {
+// SAFE_DELETE(image);
+// assert("Cannot open paletted PNG files.");
+// }
+ if (color_type == PNG_COLOR_TYPE_PALETTE)
+ png_set_palette_to_rgb(png_ptr);
+
+ number_of_passes = png_set_interlace_handling(png_ptr);
+ png_read_update_info(png_ptr, info_ptr);
+
+ // read file
+ if (setjmp(png_jmpbuf(png_ptr)))
+ {
+ SAFE_DELETE_ARRAY(image);
+ assert("[read_png_file] Error during read_image");
+ }
+
+ row_pointers = (png_bytep*) malloc(sizeof(png_bytep) * image->m_height);
+ unsigned int y;
+ for ( y=0; y < (unsigned)image->m_height; y++)
+ row_pointers[y] = (png_byte*) malloc(info_ptr->rowbytes);
+
+ png_read_image(png_ptr, row_pointers);
+
+ png_read_end( png_ptr, info_ptr );
+ png_destroy_read_struct( &png_ptr, &info_ptr, NULL );
+
+ png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
+
+ if (color_type & PNG_COLOR_MASK_ALPHA)
+ image->m_ColorByteType = RGBA;
+ else
+ image->m_ColorByteType = RGB;
+
+// SAFE_DELETE(texture->m_data);
+
+ image->m_data = new unsigned char[sizeof(unsigned char) * image->m_height * image->m_width * 4];
+
+ switch (image->m_ColorByteType)
+ {
+ case RGBA:
+ for ( y=0; y < (unsigned)image->m_height; ++y) {
+ png_byte* row = row_pointers[y];
+ for (int x = 0; x < image->m_width; ++x) {
+ png_byte* ptr = &(row[x*4]);
+ image->m_data[(x + y * image->m_width) * 4] = ptr[0];
+ image->m_data[(x + y * image->m_width) * 4 + 1] = ptr[1];
+ image->m_data[(x + y * image->m_width) * 4 + 2] = ptr[2];
+ image->m_data[(x + y * image->m_width) * 4 + 3] = ptr[3];
+ }
+ }
+ break;
+ case RGB:
+ for ( y=0; y < (unsigned)image->m_height; y++) {
+ png_byte* row = row_pointers[y];
+ for (int x=0; x<image->m_width; x++) {
+ png_byte* ptr = &(row[x * 3]);
+ image->m_data[(x + y * image->m_width) * 3] = ptr[0];
+ image->m_data[(x + y * image->m_width) * 3 + 1] = ptr[1];
+ image->m_data[(x + y * image->m_width) * 3 + 2] = ptr[2];
+ }
+ }
+ break;
+ default:
+ printf("Invalid color byte type for PNG.\n");
+ SAFE_DELETE_ARRAY( image );
+ return false;
+ }
+
+ for ( y=0; y < (unsigned)image->m_height; y++)
+ SAFE_FREE(row_pointers[y]);
+ SAFE_FREE(row_pointers);
+
+// texture->CorrectSize();
+// texture->CreateCache();
+
+ return image;
+}
+
+REGISTER_IMAGE_TYPE(\x89PN, LoadPNG);
+
+/*
+ * Copyright (c) 2004 Glenn Maynard
+ * (c) 2008 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.
+ */
\ No newline at end of file
Modified: Mercury2/src/RawImageData.h
===================================================================
--- Mercury2/src/RawImageData.h 2008-12-07 03:43:41 UTC (rev 58)
+++ Mercury2/src/RawImageData.h 2008-12-07 03:46:14 UTC (rev 59)
@@ -1,6 +1,12 @@
#ifndef RAWIMAGEDATA_H
#define RAWIMAGEDATA_H
+enum ColorByteType
+{
+ RGB,
+ RGBA
+};
+
class RawImageData
{
public:
@@ -11,6 +17,7 @@
unsigned int m_height;
unsigned short m_bits;
unsigned char* m_data;
+ ColorByteType m_ColorByteType;
};
#endif
Modified: Mercury2/src/Texture.cpp
===================================================================
--- Mercury2/src/Texture.cpp 2008-12-07 03:43:41 UTC (rev 58)
+++ Mercury2/src/Texture.cpp 2008-12-07 03:46:14 UTC (rev 59)
@@ -43,15 +43,25 @@
if ( !m_textureID ) glGenTextures(1, &m_textureID);
m_raw = raw;
+ int ByteType;
+
+ switch (m_raw->m_ColorByteType)
+ {
+ case RGB:
+ ByteType = GL_RGB;
+ break;
+ case RGBA:
+ ByteType = GL_RGBA;
+ }
glBindTexture(GL_TEXTURE_2D, m_textureID);
glTexImage2D(GL_TEXTURE_2D,
0,
- 3,
+ ByteType,
m_raw->m_width,
m_raw->m_height,
0,
- GL_RGB,
+ ByteType,
GL_UNSIGNED_BYTE,
m_raw->m_data);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2008-12-07 15:49:42
|
Revision: 60
http://hgengine.svn.sourceforge.net/hgengine/?rev=60&view=rev
Author: axlecrusher
Date: 2008-12-07 15:49:32 +0000 (Sun, 07 Dec 2008)
Log Message:
-----------
update copyright
Modified Paths:
--------------
Mercury2/src/BMPLoader.cpp
Mercury2/src/ImageLoader.cpp
Mercury2/src/ImageLoader.h
Modified: Mercury2/src/BMPLoader.cpp
===================================================================
--- Mercury2/src/BMPLoader.cpp 2008-12-07 03:46:14 UTC (rev 59)
+++ Mercury2/src/BMPLoader.cpp 2008-12-07 15:49:32 UTC (rev 60)
@@ -158,33 +158,33 @@
//REGISTER_IMAGE_TYPE(BM8, LoadBMP);
/****************************************************************************
- * 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. *
+ * Copyright (C) 2008 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
***************************************************************************/
Modified: Mercury2/src/ImageLoader.cpp
===================================================================
--- Mercury2/src/ImageLoader.cpp 2008-12-07 03:46:14 UTC (rev 59)
+++ Mercury2/src/ImageLoader.cpp 2008-12-07 15:49:32 UTC (rev 60)
@@ -45,33 +45,33 @@
}
/****************************************************************************
- * 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. *
+ * Copyright (C) 2008 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
***************************************************************************/
Modified: Mercury2/src/ImageLoader.h
===================================================================
--- Mercury2/src/ImageLoader.h 2008-12-07 03:46:14 UTC (rev 59)
+++ Mercury2/src/ImageLoader.h 2008-12-07 15:49:32 UTC (rev 60)
@@ -28,33 +28,33 @@
#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. *
+ * 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 17:04:06
|
Revision: 135
http://hgengine.svn.sourceforge.net/hgengine/?rev=135&view=rev
Author: axlecrusher
Date: 2009-01-01 17:04:02 +0000 (Thu, 01 Jan 2009)
Log Message:
-----------
use MercuryTimer
Modified Paths:
--------------
Mercury2/src/Mercury2.cpp
Mercury2/src/MercuryUtil.cpp
Mercury2/src/MercuryUtil.h
Modified: Mercury2/src/Mercury2.cpp
===================================================================
--- Mercury2/src/Mercury2.cpp 2009-01-01 17:01:48 UTC (rev 134)
+++ Mercury2/src/Mercury2.cpp 2009-01-01 17:04:02 UTC (rev 135)
@@ -13,6 +13,9 @@
#include <MercuryCrash.h>
#include <MercuryBacktrace.h>
#include <MercuryMessageManager.h>
+
+#include <MercuryTimer.h>
+
MSemaphore UpdateLoopGo;
void* UpdateThread(void* node)
{
@@ -37,8 +40,6 @@
int main()
{
unsigned long m_count = 0;
- uint64_t startTime = GetTimeInMicroSeconds();
- uint64_t timeSinceStart = 0;
cnset_execute_on_crash( SignalHandler );
@@ -51,31 +52,29 @@
root->LoadFromXML( r );
SAFE_DELETE(doc);
+
+ MercuryTimer timer;
+ MercuryTimer fpsTimer;
- uint64_t oTime = timeSinceStart;
- uint64_t m_time = oTime;
-
//uncomment the next 2 lines to use threads
// MercuryThread updateThread;
// updateThread.Create( UpdateThread, root, false);
do
{
- timeSinceStart = GetTimeInMicroSeconds() - startTime;
- MESSAGEMAN::GetInstance().PumpMessages( timeSinceStart );
- root->RecursiveUpdate((timeSinceStart-oTime)/1000000.0f); //comment to use threads
+ timer.Touch();
+// MESSAGEMAN::GetInstance().PumpMessages( timer.MicrosecondsSinceInit() );
+ root->RecursiveUpdate( timer.Age() ); //comment to use threads
RenderableNode::RecursiveRender(root);
w->SwapBuffers();
++m_count;
- float seconds = (timeSinceStart-m_time)/1000000.0f;
- if (seconds > 1)
+ fpsTimer.Touch(timer);
+ if (fpsTimer.Age() > 1)
{
- m_time = timeSinceStart;
- printf("FPS: %f\n", m_count/seconds);
+ printf("FPS: %f\n", m_count/fpsTimer.Age());
m_count = 0;
+ fpsTimer = timer;
}
-
- oTime = timeSinceStart;
}
while ( w->PumpMessages() );
Modified: Mercury2/src/MercuryUtil.cpp
===================================================================
--- Mercury2/src/MercuryUtil.cpp 2009-01-01 17:01:48 UTC (rev 134)
+++ Mercury2/src/MercuryUtil.cpp 2009-01-01 17:04:02 UTC (rev 135)
@@ -2,12 +2,6 @@
#include <MercuryFile.h>
#include <stdint.h>
-#ifndef WIN32
-#include <sys/time.h>
-#else
-#include <windows.h>
-#endif
-
MString ToUpper(const MString& s)
{
MString t = s;
@@ -35,15 +29,6 @@
return ptr;
}
-int64_t GetTimeInMicroSeconds()
-{
- struct timeval tv;
- gettimeofday( &tv, 0 );
-
- return (int64_t(tv.tv_sec) * 1000000) + tv.tv_usec;
-
-}
-
long FileToString( const MString & sFileName, char * & data )
{
data = 0;
Modified: Mercury2/src/MercuryUtil.h
===================================================================
--- Mercury2/src/MercuryUtil.h 2009-01-01 17:01:48 UTC (rev 134)
+++ Mercury2/src/MercuryUtil.h 2009-01-01 17:04:02 UTC (rev 135)
@@ -17,8 +17,6 @@
//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)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-03-04 00:46:52
|
Revision: 176
http://hgengine.svn.sourceforge.net/hgengine/?rev=176&view=rev
Author: axlecrusher
Date: 2009-03-04 00:46:51 +0000 (Wed, 04 Mar 2009)
Log Message:
-----------
test clipping
Modified Paths:
--------------
Mercury2/src/BoundingBox.cpp
Mercury2/src/Viewport.cpp
Modified: Mercury2/src/BoundingBox.cpp
===================================================================
--- Mercury2/src/BoundingBox.cpp 2009-03-03 22:30:27 UTC (rev 175)
+++ Mercury2/src/BoundingBox.cpp 2009-03-04 00:46:51 UTC (rev 176)
@@ -53,10 +53,8 @@
const BoundingBox& bb = *m_bb;
BoundingBox gbb = m_bb->Transform( GetGlobalMatrix() );
+ if ( FRUSTUM->Clip( gbb ) ) return;
- FRUSTUM->m_planes[PFAR].IsBehindPlane( gbb.GetCenter() );
-// printf("clip %d\n", FRUSTUM->m_planes[PFAR].IsBehindPlane( gbb.GetCenter() ));
-
const float* center = m_bb->GetCenter();
const float* extend = m_bb->GetExtend();
Modified: Mercury2/src/Viewport.cpp
===================================================================
--- Mercury2/src/Viewport.cpp 2009-03-03 22:30:27 UTC (rev 175)
+++ Mercury2/src/Viewport.cpp 2009-03-04 00:46:51 UTC (rev 176)
@@ -127,10 +127,10 @@
bool Frustum::Clip(const BoundingBox& bb) const
{
- bool inView = false;
- for (uint8_t i = 0; (i < 6) && !inView; ++i)
+ bool inView = true;
+ for (uint8_t i = 0; (i < 6) && inView; ++i)
{
- inView = m_planes[i].IsBehindPlane( bb )?inView:true;
+ inView = m_planes[i].IsBehindPlane( bb )?false:inView;
}
return !inView;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-04-04 19:50:55
|
Revision: 195
http://hgengine.svn.sourceforge.net/hgengine/?rev=195&view=rev
Author: axlecrusher
Date: 2009-04-04 19:50:52 +0000 (Sat, 04 Apr 2009)
Log Message:
-----------
add render graph
Added Paths:
-----------
Mercury2/src/RenderGraph.cpp
Mercury2/src/RenderGraph.h
Added: Mercury2/src/RenderGraph.cpp
===================================================================
--- Mercury2/src/RenderGraph.cpp (rev 0)
+++ Mercury2/src/RenderGraph.cpp 2009-04-04 19:50:52 UTC (rev 195)
@@ -0,0 +1,67 @@
+#include <RenderGraph.h>
+
+void RenderGraphEntry::Render()
+{
+ if (m_node) m_node->Render();
+ std::list< RenderGraphEntry >::iterator i;
+ for (i = m_children.begin(); i != m_children.end(); ++i )
+ i->Render();
+}
+
+void RenderGraph::Build( MercuryNode* node )
+{
+ m_root = RenderGraphEntry();
+ Build(node, m_root);
+}
+
+void RenderGraph::Build( MercuryNode* node, RenderGraphEntry& entry)
+{
+ RenderGraphEntry* lastEntry = &entry;
+ RenderableNode* rn = RenderableNode::Cast(node);
+
+ if ( rn )
+ {
+ //found a new renderable
+ printf("Found renderable %p\n", rn);
+ entry.m_children.push_back( RenderGraphEntry(rn) );
+ lastEntry = &(entry.m_children.back());
+ }
+
+ for (MercuryNode* child = node->FirstChild(); child != NULL; child = node->NextChild(child))
+ Build(child, *lastEntry);
+
+ //coming back up the tree
+// entry = lastEntry;
+}
+
+/****************************************************************************
+ * Copyright (C) 2009 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
Added: Mercury2/src/RenderGraph.h
===================================================================
--- Mercury2/src/RenderGraph.h (rev 0)
+++ Mercury2/src/RenderGraph.h 2009-04-04 19:50:52 UTC (rev 195)
@@ -0,0 +1,64 @@
+#ifndef RENDERGRAPH_H
+#define RENDERGRAPH_H
+
+#include <MercuryNode.h>
+#include <RenderableNode.h>
+
+class RenderGraphEntry
+{
+ friend class RenderGraph;
+ public:
+ RenderGraphEntry(RenderableNode* node = NULL)
+ :m_node(node)
+ {}
+
+ void AddChild(RenderGraphEntry entry);
+ void Render();
+ private:
+ RenderableNode* m_node; //we don't own this, no new or free
+ std::list< RenderGraphEntry > m_children;
+};
+
+class RenderGraph
+{
+ public:
+ void Build( MercuryNode* node );
+ inline void Render() { m_root.Render(); }
+ private:
+ void Build( MercuryNode* node, RenderGraphEntry& entry );
+ RenderGraphEntry m_root;
+};
+
+#endif
+
+/****************************************************************************
+ * Copyright (C) 2009 by Joshua Allen *
+ * *
+ * *
+ * All rights reserved. *
+ * *
+ * Redistribution and use in source and binary forms, with or without *
+ * modification, are permitted provided that the following conditions *
+ * are met: *
+ * * Redistributions of source code must retain the above copyright *
+ * notice, this list of conditions and the following disclaimer. *
+ * * Redistributions in binary form must reproduce the above *
+ * copyright notice, this list of conditions and the following *
+ * disclaimer in the documentation and/or other materials provided *
+ * with the distribution. *
+ * * Neither the name of the Mercury Engine nor the names of its *
+ * contributors may be used to endorse or promote products derived *
+ * from this software without specific prior written permission. *
+ * *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
+ ***************************************************************************/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <axl...@us...> - 2009-04-18 13:47:12
|
Revision: 214
http://hgengine.svn.sourceforge.net/hgengine/?rev=214&view=rev
Author: axlecrusher
Date: 2009-04-18 13:44:00 +0000 (Sat, 18 Apr 2009)
Log Message:
-----------
search up parent tree first, then down
Modified Paths:
--------------
Mercury2/src/XMLParser.cpp
Mercury2/src/XMLParser.h
Modified: Mercury2/src/XMLParser.cpp
===================================================================
--- Mercury2/src/XMLParser.cpp 2009-04-14 01:04:54 UTC (rev 213)
+++ Mercury2/src/XMLParser.cpp 2009-04-18 13:44:00 UTC (rev 214)
@@ -117,12 +117,24 @@
if (d)
{
- //start searching at the root
- XMLNode root( xmlDocGetRootElement(m_doc), m_doc );
+ MString path((const char*)d);
+
+ int pos = path.find(".");
+ MString name = pos<=0?path:path.substr(0, pos);
+ MString rpath = pos<=0?"":path.substr(pos+1); //skip the period
+
+ XMLNode parent = FindParentWithName( name );
+ if ( !parent.IsValid() )
+ {
+ //nothing found, do search down from root
+ parent = XMLNode( xmlDocGetRootElement(m_doc), m_doc );
+ rpath = path;
+ }
+
//prevent infinite recursion on self
- if ( root.m_node != m_node )
+ if ( parent.m_node != m_node )
{
- n = root.RecursiveFindFallbackNode( MString((const char*)d) );
+ n = parent.RecursiveFindFallbackNode( rpath );
}
xmlFree(d);
}
@@ -130,6 +142,19 @@
return n;
}
+XMLNode XMLNode::FindParentWithName(const MString& name) const
+{
+ if ( (!name.empty()) && (m_node->parent) )
+ {
+ XMLNode parent(m_node->parent, m_doc);
+ if (parent.Attribute("name") == name)
+ return parent;
+ return parent.FindParentWithName( name );
+ }
+ return XMLNode();
+}
+
+
XMLNode XMLNode::RecursiveFindFallbackNode(const MString& path) const
{
if ( !IsValid() ) return XMLNode();
Modified: Mercury2/src/XMLParser.h
===================================================================
--- Mercury2/src/XMLParser.h 2009-04-14 01:04:54 UTC (rev 213)
+++ Mercury2/src/XMLParser.h 2009-04-18 13:44:00 UTC (rev 214)
@@ -37,6 +37,7 @@
const XMLNode& operator=(const XMLNode& n);
private:
XMLNode RecursiveFindFallbackNode(const MString& path) const;
+ XMLNode FindParentWithName(const MString& name) const;
xmlNode* m_node;
xmlDoc* m_doc; //parent doc, don't free
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|