From: <axl...@us...> - 2009-04-12 23:37:14
|
Revision: 211 http://hgengine.svn.sourceforge.net/hgengine/?rev=211&view=rev Author: axlecrusher Date: 2009-04-12 23:37:04 +0000 (Sun, 12 Apr 2009) Log Message: ----------- use glu mipmaps Modified Paths: -------------- Mercury2/src/Mercury2.cpp Mercury2/src/MercuryVBO.cpp Mercury2/src/MercuryVBO.h Mercury2/src/Texture.cpp Modified: Mercury2/src/Mercury2.cpp =================================================================== --- Mercury2/src/Mercury2.cpp 2009-04-12 22:24:37 UTC (rev 210) +++ Mercury2/src/Mercury2.cpp 2009-04-12 23:37:04 UTC (rev 211) @@ -83,8 +83,9 @@ if (fpsTimer.Age() > 1) { float batches = MercuryVBO::ResetBatchCount()/(float)m_count; - float binds = Texture::ReadAndResetBindCount()/(float)m_count; - printf("FPS: %f, VBO batches %f, TBinds %f\n", m_count/fpsTimer.Age(), batches, binds); + float VBinds = MercuryVBO::ResetBindCount()/(float)m_count; + float Tbinds = Texture::ReadAndResetBindCount()/(float)m_count; + printf("FPS: %f, VBO batches %f, TBinds %f, VBinds %f\n", m_count/fpsTimer.Age(), batches, Tbinds, VBinds); m_count = 0; fpsTimer = timer; } Modified: Mercury2/src/MercuryVBO.cpp =================================================================== --- Mercury2/src/MercuryVBO.cpp 2009-04-12 22:24:37 UTC (rev 210) +++ Mercury2/src/MercuryVBO.cpp 2009-04-12 23:37:04 UTC (rev 211) @@ -40,7 +40,10 @@ InitVBO(); if ( this != m_lastVBOrendered) + { glVertexPointer(3, GL_FLOAT, stride, BUFFER_OFFSET(sizeof(float)*5)); + ++m_vboBinds; + } //apply all the active textures for (uint8_t i = 0; i < numTextures; ++i) @@ -87,6 +90,7 @@ void* MercuryVBO::m_lastVBOrendered = NULL; uint32_t MercuryVBO::m_vboBatches; +uint32_t MercuryVBO::m_vboBinds; /**************************************************************************** * Copyright (C) 2008 by Joshua Allen * Modified: Mercury2/src/MercuryVBO.h =================================================================== --- Mercury2/src/MercuryVBO.h 2009-04-12 22:24:37 UTC (rev 210) +++ Mercury2/src/MercuryVBO.h 2009-04-12 23:37:04 UTC (rev 211) @@ -20,6 +20,7 @@ static uint32_t BatchCount() { return m_vboBatches; } static uint32_t ResetBatchCount() { uint32_t t = m_vboBatches; m_vboBatches = 0; return t; } + static uint32_t ResetBindCount() { uint32_t t = m_vboBinds; m_vboBinds = 0; return t; } private: virtual void InitVBO(); @@ -33,6 +34,7 @@ AlignedBuffer<uint16_t> m_indexData; static uint32_t m_vboBatches; + static uint32_t m_vboBinds; }; #endif Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2009-04-12 22:24:37 UTC (rev 210) +++ Mercury2/src/Texture.cpp 2009-04-12 23:37:04 UTC (rev 211) @@ -6,6 +6,7 @@ #include <GL/gl.h> #include <GL/glext.h> +#include <GL/glu.h> using namespace std; @@ -62,6 +63,7 @@ } glBindTexture(GL_TEXTURE_2D, m_textureID); +/* glTexImage2D(GL_TEXTURE_2D, 0, ByteType, @@ -71,8 +73,10 @@ ByteType, GL_UNSIGNED_BYTE, m_raw->m_data); +*/ + gluBuild2DMipmaps( GL_TEXTURE_2D, 3, m_raw->m_width, m_raw->m_height, ByteType, GL_UNSIGNED_BYTE, m_raw->m_data ); - glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); @@ -80,6 +84,8 @@ glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); +// gluBuild2DMipmaps( GL_TEXTURE_2D, 3, m_raw->m_width, m_raw->m_height, ByteType, GL_UNSIGNED_BYTE, m_raw->m_data ); + }; void Texture::Render(const MercuryNode* node) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-04-14 01:05:01
|
Revision: 213 http://hgengine.svn.sourceforge.net/hgengine/?rev=213&view=rev Author: axlecrusher Date: 2009-04-14 01:04:54 +0000 (Tue, 14 Apr 2009) Log Message: ----------- updates to viewport calculations Modified Paths: -------------- Mercury2/src/MercuryUtil.cpp Mercury2/src/MercuryUtil.h Mercury2/src/MercuryWindow.h Mercury2/src/Viewport.cpp Mercury2/src/Viewport.h Mercury2/src/X11Window.cpp Modified: Mercury2/src/MercuryUtil.cpp =================================================================== --- Mercury2/src/MercuryUtil.cpp 2009-04-13 10:51:03 UTC (rev 212) +++ Mercury2/src/MercuryUtil.cpp 2009-04-14 01:04:54 UTC (rev 213) @@ -14,10 +14,10 @@ return t; } -float StrToFloat(const MString & s) +float StrToFloat(const MString & s, float d) { - float x; - sscanf(s.c_str(), "%f", &x); + float x = d; + if ( s.length() > 0) sscanf(s.c_str(), "%f", &x); return x; } Modified: Mercury2/src/MercuryUtil.h =================================================================== --- Mercury2/src/MercuryUtil.h 2009-04-13 10:51:03 UTC (rev 212) +++ Mercury2/src/MercuryUtil.h 2009-04-14 01:04:54 UTC (rev 213) @@ -29,7 +29,7 @@ MString ToUpper(const MString & s); -float StrToFloat(const MString & s); +float StrToFloat(const MString & s, float d = 0); template<typename T> const T& max(const T& t1, const T& t2) Modified: Mercury2/src/MercuryWindow.h =================================================================== --- Mercury2/src/MercuryWindow.h 2009-04-13 10:51:03 UTC (rev 212) +++ Mercury2/src/MercuryWindow.h 2009-04-14 01:04:54 UTC (rev 213) @@ -25,6 +25,9 @@ } virtual void* GetProcAddress(const MString& x) = 0; + + inline int Width() const { return m_width; } + inline int Height() const { return m_height; } protected: static Callback0R< MercuryWindow* > genWindowClbk; Modified: Mercury2/src/Viewport.cpp =================================================================== --- Mercury2/src/Viewport.cpp 2009-04-13 10:51:03 UTC (rev 212) +++ Mercury2/src/Viewport.cpp 2009-04-14 01:04:54 UTC (rev 213) @@ -1,13 +1,22 @@ #include <Viewport.h> #include <GL/gl.h> +#include <MercuryWindow.h> REGISTER_NODE_TYPE(Viewport); const Frustum* FRUSTUM; +Viewport::Viewport() + :m_xFactor(1), m_yFactor(0.5), m_minx(0), m_miny(0) +{ +} + void Viewport::Render(const MercuryMatrix& matrix) { FRUSTUM = &m_frustum; + MercuryWindow* w = MercuryWindow::GetCurrentWindow(); + glViewport(m_minx, m_miny, w->Width()*m_xFactor, w->Height()*m_yFactor); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); @@ -24,11 +33,19 @@ void Viewport::LoadFromXML(const XMLNode& node) { + m_xFactor = StrToFloat(node.Attribute("xfactor"), 1.0f); + m_yFactor = StrToFloat(node.Attribute("yfactor"), 1.0f); + m_minx = StrToFloat(node.Attribute("minx"), 0); + m_miny = StrToFloat(node.Attribute("miny"), 0); + + MercuryWindow* w = MercuryWindow::GetCurrentWindow(); + m_frustum.SetPerspective( StrToFloat(node.Attribute("fov")), - StrToFloat(node.Attribute("aspect")), + (w->Width()*m_xFactor)/(w->Height()*m_yFactor), +// StrToFloat(node.Attribute("aspect")), StrToFloat(node.Attribute("near")), StrToFloat(node.Attribute("far"))); - + m_frustum.LookAt(MercuryVertex(), MercuryVertex(0,0,1), MercuryVertex(0,1,0)); RenderableNode::LoadFromXML(node); Modified: Mercury2/src/Viewport.h =================================================================== --- Mercury2/src/Viewport.h 2009-04-13 10:51:03 UTC (rev 212) +++ Mercury2/src/Viewport.h 2009-04-14 01:04:54 UTC (rev 213) @@ -12,6 +12,7 @@ class Viewport : public RenderableNode { public: + Viewport(); virtual void Render(const MercuryMatrix& matrix); virtual void LoadFromXML(const XMLNode& node); @@ -19,6 +20,8 @@ GENRTTI(Viewport); private: Frustum m_frustum; + float m_xFactor, m_yFactor; + int m_minx, m_miny; }; #endif Modified: Mercury2/src/X11Window.cpp =================================================================== --- Mercury2/src/X11Window.cpp 2009-04-13 10:51:03 UTC (rev 212) +++ Mercury2/src/X11Window.cpp 2009-04-14 01:04:54 UTC (rev 213) @@ -145,7 +145,8 @@ case ConfigureNotify: { XConfigureEvent* e = (XConfigureEvent*)&event; - glViewport(0,0, e->width, e->height); + m_width = e->width; + m_height = e->height; break; } default: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-04-25 14:20:17
|
Revision: 216 http://hgengine.svn.sourceforge.net/hgengine/?rev=216&view=rev Author: axlecrusher Date: 2009-04-25 14:20:15 +0000 (Sat, 25 Apr 2009) Log Message: ----------- update method for clearing frame buffer Modified Paths: -------------- Mercury2/src/Mercury2.cpp Mercury2/src/MercuryWindow.h Mercury2/src/Viewport.cpp Mercury2/src/X11Window.cpp Mercury2/src/X11Window.h Modified: Mercury2/src/Mercury2.cpp =================================================================== --- Mercury2/src/Mercury2.cpp 2009-04-24 02:03:21 UTC (rev 215) +++ Mercury2/src/Mercury2.cpp 2009-04-25 14:20:15 UTC (rev 216) @@ -73,7 +73,7 @@ renderGraph.Build(root); } - + w->Clear(); renderGraph.Render(); // RenderableNode::RecursiveRender(root); w->SwapBuffers(); Modified: Mercury2/src/MercuryWindow.h =================================================================== --- Mercury2/src/MercuryWindow.h 2009-04-24 02:03:21 UTC (rev 215) +++ Mercury2/src/MercuryWindow.h 2009-04-25 14:20:15 UTC (rev 216) @@ -26,6 +26,8 @@ virtual void* GetProcAddress(const MString& x) = 0; + virtual void Clear() = 0; + inline int Width() const { return m_width; } inline int Height() const { return m_height; } Modified: Mercury2/src/Viewport.cpp =================================================================== --- Mercury2/src/Viewport.cpp 2009-04-24 02:03:21 UTC (rev 215) +++ Mercury2/src/Viewport.cpp 2009-04-25 14:20:15 UTC (rev 216) @@ -17,7 +17,6 @@ MercuryWindow* w = MercuryWindow::GetCurrentWindow(); glViewport(m_minx, m_miny, w->Width()*m_xFactor, w->Height()*m_yFactor); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); MercuryMatrix f = m_frustum.GetMatrix(); Modified: Mercury2/src/X11Window.cpp =================================================================== --- Mercury2/src/X11Window.cpp 2009-04-24 02:03:21 UTC (rev 215) +++ Mercury2/src/X11Window.cpp 2009-04-25 14:20:15 UTC (rev 216) @@ -156,6 +156,11 @@ return true; } +void X11Window::Clear() +{ + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +} + void* X11Window::GetProcAddress(const MString& x) { return NULL; Modified: Mercury2/src/X11Window.h =================================================================== --- Mercury2/src/X11Window.h 2009-04-24 02:03:21 UTC (rev 215) +++ Mercury2/src/X11Window.h 2009-04-25 14:20:15 UTC (rev 216) @@ -18,6 +18,8 @@ virtual bool PumpMessages(); virtual void* GetProcAddress(const MString& x); + + virtual void Clear(); private: Display* m_display; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-04-25 21:01:58
|
Revision: 217 http://hgengine.svn.sourceforge.net/hgengine/?rev=217&view=rev Author: axlecrusher Date: 2009-04-25 21:01:43 +0000 (Sat, 25 Apr 2009) Log Message: ----------- Many updates focused on threaded loading. Modified Paths: -------------- Mercury2/src/ImageLoader.cpp Mercury2/src/ImageLoader.h Mercury2/src/MSemaphore.cpp Mercury2/src/MSemaphore.h Mercury2/src/MercuryAsset.cpp Mercury2/src/MercuryAsset.h Mercury2/src/MercuryNode.cpp Mercury2/src/MercuryNode.h Mercury2/src/MercuryString.h Mercury2/src/Texture.cpp Mercury2/src/Texture.h Modified: Mercury2/src/ImageLoader.cpp =================================================================== --- Mercury2/src/ImageLoader.cpp 2009-04-25 14:20:15 UTC (rev 216) +++ Mercury2/src/ImageLoader.cpp 2009-04-25 21:01:43 UTC (rev 217) @@ -1,8 +1,20 @@ #include <ImageLoader.h> #include <MercuryUtil.h> +#include <Texture.h> using namespace std; +void* ImageLoader::ImageLoaderThread(void* d) +{ + ThreadData *pd = (ThreadData*)d; + ThreadData data = *pd; + delete pd; + RawImageData* imageData = data.imageloader->LoadImage( data.filename ); + ((Texture*)data.asset)->SetRawData(imageData); + data.asset->LoadedCallback(); + return 0; +} + ImageLoader& ImageLoader::GetInstance() { static ImageLoader* instance = NULL; @@ -24,7 +36,7 @@ MercuryFile* f = FILEMAN.Open( filename ); char fingerprint[4]; fingerprint[3] = 0; - + if( !f ) { printf( "Error opening image: %s\n", filename.c_str() ); @@ -49,6 +61,14 @@ return NULL; } +void ImageLoader::LoadImageThreaded(MercuryAsset* t, const MString& filename) +{ + ThreadData* data = new ThreadData(this, t, filename); + MercuryThread loaderThread; + loaderThread.HaltOnDestroy(false); + loaderThread.Create( ImageLoader::ImageLoaderThread, data, true ); +} + /**************************************************************************** * Copyright (C) 2008 by Joshua Allen * * * Modified: Mercury2/src/ImageLoader.h =================================================================== --- Mercury2/src/ImageLoader.h 2009-04-25 14:20:15 UTC (rev 216) +++ Mercury2/src/ImageLoader.h 2009-04-25 21:01:43 UTC (rev 217) @@ -7,17 +7,35 @@ #include <list> #include <MercuryUtil.h> +#include <MercuryAsset.h> + class ImageLoader { public: static ImageLoader& GetInstance(); bool RegisterFactoryCallback(const MString& type, Callback1R< MercuryFile *, RawImageData* >); RawImageData* LoadImage(const MString& filename); - + void LoadImageThreaded(MercuryAsset* t, const MString& filename); + private: + static void* ImageLoaderThread(void* d); std::list< std::pair< MString, Callback1R< MercuryFile*, RawImageData* > > > m_factoryCallbacks; }; +class ThreadData +{ + public: + ThreadData(ImageLoader* il, MercuryAsset* a, const MString& f) + { + asset = a; + filename = f; + imageloader = il; + } + MercuryAsset* asset; + MString filename; + ImageLoader* imageloader; +}; + static InstanceCounter<ImageLoader> ILcounter("ImageLoader"); #define REGISTER_IMAGE_TYPE(fingerprint,functor)\ Modified: Mercury2/src/MSemaphore.cpp =================================================================== --- Mercury2/src/MSemaphore.cpp 2009-04-25 14:20:15 UTC (rev 216) +++ Mercury2/src/MSemaphore.cpp 2009-04-25 21:01:43 UTC (rev 217) @@ -25,6 +25,22 @@ return __sync_add_and_fetch(&m_counter, 1); } +void MSemaphore::WaitAndSet(unsigned long value, unsigned long newVal) +{ + while ( !__sync_bool_compare_and_swap(&m_counter, value, newVal) ); +} + +MSemaphoreLock::MSemaphoreLock(MSemaphore* s) + :m_s(s) +{ + m_s->WaitAndSet(0,1); +} + +MSemaphoreLock::~MSemaphoreLock() +{ + m_s->WaitAndSet(1,0); +} + MSemaphoreIncOnDestroy::MSemaphoreIncOnDestroy(MSemaphore* s) :m_s(s) { Modified: Mercury2/src/MSemaphore.h =================================================================== --- Mercury2/src/MSemaphore.h 2009-04-25 14:20:15 UTC (rev 216) +++ Mercury2/src/MSemaphore.h 2009-04-25 21:01:43 UTC (rev 217) @@ -10,11 +10,21 @@ unsigned long ReadAndClear(); unsigned long Decrement(); unsigned long Increment(); + void WaitAndSet(unsigned long value, unsigned long newVal); private: unsigned long m_counter; }; +class MSemaphoreLock +{ + public: + MSemaphoreLock(MSemaphore* s); + ~MSemaphoreLock(); + private: + MSemaphore* m_s; +}; + class MSemaphoreIncOnDestroy { public: Modified: Mercury2/src/MercuryAsset.cpp =================================================================== --- Mercury2/src/MercuryAsset.cpp 2009-04-25 14:20:15 UTC (rev 216) +++ Mercury2/src/MercuryAsset.cpp 2009-04-25 21:01:43 UTC (rev 217) @@ -18,6 +18,19 @@ rn->AddRender(this); } +void MercuryAsset::SetLoadState(LoadState ls) +{ + MSemaphoreLock lock( &m_lock ); + m_loadState = ls; +} + +LoadState MercuryAsset::GetLoadState() +{ + MSemaphoreLock lock( &m_lock ); + return m_loadState; +} + + AssetFactory& AssetFactory::GetInstance() { static AssetFactory* instance = NULL; Modified: Mercury2/src/MercuryAsset.h =================================================================== --- Mercury2/src/MercuryAsset.h 2009-04-25 14:20:15 UTC (rev 216) +++ Mercury2/src/MercuryAsset.h 2009-04-25 21:01:43 UTC (rev 217) @@ -7,7 +7,15 @@ #include <map> #include <MercuryMatrix.h> #include <BoundingBox.h> +#include <MSemaphore.h> +enum LoadState +{ + LOADING, + LOADED, + NONE +}; + class MercuryAsset : public RefBase, MessageHandler { public: @@ -23,12 +31,20 @@ ///Loads an asset from an XMLAsset representing itself virtual void LoadFromXML(const XMLNode& node) {}; + virtual void LoadedCallback() {}; + inline void IsInstanced(bool b) { m_isInstanced = b; } inline const BoundingVolume* GetBoundingVolume() const { return m_boundingVolume; } protected: + void SetLoadState(LoadState ls); + LoadState GetLoadState(); + bool m_isInstanced; BoundingVolume* m_boundingVolume; + private: + LoadState m_loadState; + MSemaphore m_lock; }; class AssetFactory Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-04-25 14:20:15 UTC (rev 216) +++ Mercury2/src/MercuryNode.cpp 2009-04-25 21:01:43 UTC (rev 217) @@ -110,6 +110,7 @@ void MercuryNode::LoadFromXML(const XMLNode& node) { + SetName( node.Attribute("name") ); //Not much to do here except run through all the children nodes for (XMLNode child = node.Child(); child.IsValid(); child = child.NextNode()) { Modified: Mercury2/src/MercuryNode.h =================================================================== --- Mercury2/src/MercuryNode.h 2009-04-25 14:20:15 UTC (rev 216) +++ Mercury2/src/MercuryNode.h 2009-04-25 21:01:43 UTC (rev 217) @@ -41,7 +41,7 @@ const std::list< MercuryNode* >& Children() const { return m_children; } virtual void Update(float dTime) {}; - void RecursiveUpdate(float dTime); + virtual void RecursiveUpdate(float dTime); void ThreadedUpdate(float dTime); ///Run on parent when a child is added @@ -62,7 +62,9 @@ GENRTTI(MercuryNode); inline static bool NeedsRebuild() { bool t=m_rebuildRenderGraph; m_rebuildRenderGraph = false; return t; } - + inline void SetName(const MString& name) { m_name = name; } + inline MString GetName() const { return m_name; } + protected: std::list< MercuryNode* > m_children; //These nodes are unique, not instanced MercuryNode* m_parent; @@ -70,6 +72,7 @@ MercuryNode* m_nextSibling; static bool m_rebuildRenderGraph; + MString m_name; }; Modified: Mercury2/src/MercuryString.h =================================================================== --- Mercury2/src/MercuryString.h 2009-04-25 14:20:15 UTC (rev 216) +++ Mercury2/src/MercuryString.h 2009-04-25 21:01:43 UTC (rev 217) @@ -32,7 +32,7 @@ inline const char * c_str() const { return m_sCur; } inline unsigned long length() const { return m_iLen; } inline unsigned long size() const { return m_iLen; } - inline bool empty() const { return m_iLen == 0; } + inline bool empty() const { return m_iLen <= 0; } void append( const MString & app ); void append( const char app ); Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2009-04-25 14:20:15 UTC (rev 216) +++ Mercury2/src/Texture.cpp 2009-04-25 21:01:43 UTC (rev 217) @@ -41,11 +41,12 @@ rn->AddPostRender( this ); } -void Texture::LoadFromRaw(const RawImageData* raw) +void Texture::LoadFromRaw() { + if ( !m_raw ) return; if ( !m_textureID ) glGenTextures(1, &m_textureID); - m_raw = raw; +// m_raw = raw; int ByteType; switch (m_raw->m_ColorByteType) @@ -90,6 +91,11 @@ void Texture::Render(const MercuryNode* node) { + if (GetLoadState() == LOADED) + { + LoadFromRaw(); + SetLoadState(NONE); + } BindTexture(); } @@ -100,7 +106,7 @@ void Texture::LoadFromXML(const XMLNode& node) { - LoadImage( node.Attribute("file") ); + LoadImage( node.Attribute("file") ); } void Texture::BindTexture() @@ -132,11 +138,30 @@ { ADD_ASSET_INSTANCE(Texture, path, this); m_filename = path; - RawImageData* d = ImageLoader::GetInstance().LoadImage( m_filename ); - if (d) LoadFromRaw( d ); + SetLoadState(LOADING); + + MercuryThread loaderThread; +// ImageLoader::LoadImageThreaded(this, m_filename ); + ImageLoader::GetInstance().LoadImageThreaded(this, m_filename ); +// LoadFromRaw(); +// RawImageData* d = ImageLoader::GetInstance().LoadImage( m_filename ); +// if (d) LoadFromRaw( d ); +// m_raw = d; } } +void Texture::LoadedCallback() +{ + printf("loaded!!!!!\n"); + SetLoadState(LOADED); +} + +void Texture::SetRawData(RawImageData* raw) +{ + SAFE_DELETE(m_raw); + m_raw = raw; +} + Texture* Texture::Generate() { return new Texture(); Modified: Mercury2/src/Texture.h =================================================================== --- Mercury2/src/Texture.h 2009-04-25 14:20:15 UTC (rev 216) +++ Mercury2/src/Texture.h 2009-04-25 21:01:43 UTC (rev 217) @@ -17,13 +17,16 @@ virtual void LoadFromXML(const XMLNode& node); - void LoadFromRaw(const RawImageData* raw); + void LoadFromRaw(); + virtual void LoadedCallback(); inline static unsigned short NumberActiveTextures() { return m_activeTextures; } inline static uint32_t ReadAndResetBindCount() { uint32_t t = m_textureBinds; m_textureBinds = 0; return t; } static Texture* Generate(); static MAutoPtr< Texture > LoadFromFile(const MString& path); + + void SetRawData(RawImageData* raw); private: void LoadImage(const MString& path); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-04-26 15:37:58
|
Revision: 218 http://hgengine.svn.sourceforge.net/hgengine/?rev=218&view=rev Author: axlecrusher Date: 2009-04-26 15:37:56 +0000 (Sun, 26 Apr 2009) Log Message: ----------- use auto pointer to protect against deleting objects while loading Modified Paths: -------------- Mercury2/src/ImageLoader.cpp Mercury2/src/ImageLoader.h Mercury2/src/MAutoPtr.h Modified: Mercury2/src/ImageLoader.cpp =================================================================== --- Mercury2/src/ImageLoader.cpp 2009-04-25 21:01:43 UTC (rev 217) +++ Mercury2/src/ImageLoader.cpp 2009-04-26 15:37:56 UTC (rev 218) @@ -8,9 +8,10 @@ { ThreadData *pd = (ThreadData*)d; ThreadData data = *pd; + Texture *texture = (Texture*)data.asset.Ptr(); delete pd; RawImageData* imageData = data.imageloader->LoadImage( data.filename ); - ((Texture*)data.asset)->SetRawData(imageData); + texture->SetRawData(imageData); data.asset->LoadedCallback(); return 0; } Modified: Mercury2/src/ImageLoader.h =================================================================== --- Mercury2/src/ImageLoader.h 2009-04-25 21:01:43 UTC (rev 217) +++ Mercury2/src/ImageLoader.h 2009-04-26 15:37:56 UTC (rev 218) @@ -31,7 +31,9 @@ filename = f; imageloader = il; } - MercuryAsset* asset; + + //use and autoptr here to prevent crashes if asset is removed during load + MAutoPtr< MercuryAsset > asset; MString filename; ImageLoader* imageloader; }; Modified: Mercury2/src/MAutoPtr.h =================================================================== --- Mercury2/src/MAutoPtr.h 2009-04-25 21:01:43 UTC (rev 217) +++ Mercury2/src/MAutoPtr.h 2009-04-26 15:37:56 UTC (rev 218) @@ -114,6 +114,8 @@ inline operator const T*() const { return m_ptr; } inline bool IsValid() { return m_ptr != NULL; } //true if valid + + inline T* Ptr() { return m_ptr; } private: void IncrementReference() //not thread safe, must guard { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-04-26 16:46:21
|
Revision: 219 http://hgengine.svn.sourceforge.net/hgengine/?rev=219&view=rev Author: axlecrusher Date: 2009-04-26 16:46:17 +0000 (Sun, 26 Apr 2009) Log Message: ----------- more improvements to threaded loading HGMDL now thread loading Modified Paths: -------------- Mercury2/src/HGMDLModel.cpp Mercury2/src/HGMDLModel.h Mercury2/src/ImageLoader.cpp Mercury2/src/ImageLoader.h Mercury2/src/MercuryAsset.cpp Mercury2/src/MercuryAsset.h Mercury2/src/RenderableNode.h Mercury2/src/Texture.cpp Mercury2/src/Texture.h Modified: Mercury2/src/HGMDLModel.cpp =================================================================== --- Mercury2/src/HGMDLModel.cpp 2009-04-26 15:37:56 UTC (rev 218) +++ Mercury2/src/HGMDLModel.cpp 2009-04-26 16:46:17 UTC (rev 219) @@ -21,7 +21,7 @@ LoadHGMDL( path ); } -void HGMDLModel::LoadModel(MercuryFile* hgmdl) +void HGMDLModel::LoadModel(MercuryFile* hgmdl, HGMDLModel* model) { char fingerPrint[5]; fingerPrint[4] = 0; @@ -54,14 +54,15 @@ { MAutoPtr< HGMDLMesh > mesh( new HGMDLMesh() ); mesh->LoadFromFile( hgmdl ); - m_meshes.push_back(mesh); + model->m_meshes.push_back(mesh); } } void HGMDLModel::Render(const MercuryNode* node) { - for(uint16_t i = 0; i < m_meshes.size(); ++i) - m_meshes[i]->Render(node); + if ( GetLoadState() != LOADING ) + for(uint16_t i = 0; i < m_meshes.size(); ++i) + m_meshes[i]->Render(node); } void HGMDLModel::LoadHGMDL( const MString& path ) @@ -69,16 +70,14 @@ if ( m_isInstanced ) return; if ( !path.empty() ) { + SetLoadState(LOADING); ADD_ASSET_INSTANCE(HGMDLModel, path, this); m_path = path; - MercuryFile * f = FILEMAN.Open( path ); - if( !f ) - { - printf( "Could not open file: \"%s\" for model\n", path.c_str() ); - return; - } - LoadModel( f ); - delete f; + + LoaderThreadData* ltd = new LoaderThreadData( this ); + MercuryThread loaderThread; + loaderThread.HaltOnDestroy(false); + loaderThread.Create( LoaderThread, ltd ); } } @@ -88,6 +87,29 @@ return new HGMDLModel(); } +void* HGMDLModel::LoaderThread(void* d) +{ + LoaderThreadData *pd = (LoaderThreadData*)d; + LoaderThreadData data = *pd; + delete pd; + + HGMDLModel *model = (HGMDLModel*)data.asset.Ptr(); + + MercuryFile * f = FILEMAN.Open( model->m_path ); + if( !f ) + { + printf( "Could not open file: \"%s\" for model\n", model->m_path.c_str() ); + return 0; + } + + LoadModel(f, model); + + delete f; + + model->LoadedCallback(); + return 0; +} + /**************************************************************************** * Copyright (C) 2008 by Joshua Allen * * * Modified: Mercury2/src/HGMDLModel.h =================================================================== --- Mercury2/src/HGMDLModel.h 2009-04-26 15:37:56 UTC (rev 218) +++ Mercury2/src/HGMDLModel.h 2009-04-26 16:46:17 UTC (rev 219) @@ -15,18 +15,20 @@ virtual void LoadFromXML(const XMLNode& node); - void LoadModel(MercuryFile* hgmdl); + static void LoadModel(MercuryFile* hgmdl, HGMDLModel* model); static HGMDLModel* Generate(); virtual void Render(const MercuryNode* node); private: void LoadHGMDL( const MString& path ); + static void* LoaderThread(void* d); - MString m_path; std::vector< MAutoPtr< HGMDLMesh > > m_meshes; }; + + #endif /**************************************************************************** Modified: Mercury2/src/ImageLoader.cpp =================================================================== --- Mercury2/src/ImageLoader.cpp 2009-04-26 15:37:56 UTC (rev 218) +++ Mercury2/src/ImageLoader.cpp 2009-04-26 16:46:17 UTC (rev 219) @@ -6,11 +6,12 @@ void* ImageLoader::ImageLoaderThread(void* d) { - ThreadData *pd = (ThreadData*)d; - ThreadData data = *pd; + LoaderThreadData *pd = (LoaderThreadData*)d; + LoaderThreadData data = *pd; + delete pd; + Texture *texture = (Texture*)data.asset.Ptr(); - delete pd; - RawImageData* imageData = data.imageloader->LoadImage( data.filename ); + RawImageData* imageData = GetInstance().LoadImage( data.asset->Path() ); texture->SetRawData(imageData); data.asset->LoadedCallback(); return 0; @@ -62,9 +63,9 @@ return NULL; } -void ImageLoader::LoadImageThreaded(MercuryAsset* t, const MString& filename) +void ImageLoader::LoadImageThreaded(MercuryAsset* t) { - ThreadData* data = new ThreadData(this, t, filename); + LoaderThreadData* data = new LoaderThreadData(t); MercuryThread loaderThread; loaderThread.HaltOnDestroy(false); loaderThread.Create( ImageLoader::ImageLoaderThread, data, true ); Modified: Mercury2/src/ImageLoader.h =================================================================== --- Mercury2/src/ImageLoader.h 2009-04-26 15:37:56 UTC (rev 218) +++ Mercury2/src/ImageLoader.h 2009-04-26 16:46:17 UTC (rev 219) @@ -15,29 +15,13 @@ static ImageLoader& GetInstance(); bool RegisterFactoryCallback(const MString& type, Callback1R< MercuryFile *, RawImageData* >); RawImageData* LoadImage(const MString& filename); - void LoadImageThreaded(MercuryAsset* t, const MString& filename); + void LoadImageThreaded(MercuryAsset* t); private: static void* ImageLoaderThread(void* d); - std::list< std::pair< MString, Callback1R< MercuryFile*, RawImageData* > > > m_factoryCallbacks; + std::list< std::pair< MString, Callback1R< MercuryFile*, RawImageData* > > > m_factoryCallbacks; }; -class ThreadData -{ - public: - ThreadData(ImageLoader* il, MercuryAsset* a, const MString& f) - { - asset = a; - filename = f; - imageloader = il; - } - - //use and autoptr here to prevent crashes if asset is removed during load - MAutoPtr< MercuryAsset > asset; - MString filename; - ImageLoader* imageloader; -}; - static InstanceCounter<ImageLoader> ILcounter("ImageLoader"); #define REGISTER_IMAGE_TYPE(fingerprint,functor)\ Modified: Mercury2/src/MercuryAsset.cpp =================================================================== --- Mercury2/src/MercuryAsset.cpp 2009-04-26 15:37:56 UTC (rev 218) +++ Mercury2/src/MercuryAsset.cpp 2009-04-26 16:46:17 UTC (rev 219) @@ -2,7 +2,7 @@ #include <RenderableNode.h> MercuryAsset::MercuryAsset() - :m_isInstanced(false), m_boundingVolume(NULL) + :m_isInstanced(false), m_boundingVolume(NULL), m_loadState(NONE) { } @@ -30,6 +30,10 @@ return m_loadState; } +void MercuryAsset::LoadedCallback() +{ + SetLoadState( LOADED ); +} AssetFactory& AssetFactory::GetInstance() { Modified: Mercury2/src/MercuryAsset.h =================================================================== --- Mercury2/src/MercuryAsset.h 2009-04-26 15:37:56 UTC (rev 218) +++ Mercury2/src/MercuryAsset.h 2009-04-26 16:46:17 UTC (rev 219) @@ -16,6 +16,9 @@ NONE }; +/* Assets are stored in renderable nodes with MAuto pointers. +The renderable nodes handle the memory management +*/ class MercuryAsset : public RefBase, MessageHandler { public: @@ -31,22 +34,36 @@ ///Loads an asset from an XMLAsset representing itself virtual void LoadFromXML(const XMLNode& node) {}; - virtual void LoadedCallback() {}; + virtual void LoadedCallback(); //thread safe inline void IsInstanced(bool b) { m_isInstanced = b; } inline const BoundingVolume* GetBoundingVolume() const { return m_boundingVolume; } + inline const MString& Path() const { return m_path; } protected: - void SetLoadState(LoadState ls); - LoadState GetLoadState(); + void SetLoadState(LoadState ls); //thread safe + LoadState GetLoadState(); //thread safe bool m_isInstanced; BoundingVolume* m_boundingVolume; + MString m_path; private: LoadState m_loadState; MSemaphore m_lock; }; +class LoaderThreadData +{ + public: + LoaderThreadData(MercuryAsset* a) + { + asset = a; + } + + //use and autoptr here to prevent crashes if asset is removed during load + MAutoPtr< MercuryAsset > asset; +}; + class AssetFactory { public: @@ -62,6 +79,7 @@ std::list< std::pair< MString, Callback0R< MAutoPtr<MercuryAsset> > > > m_factoryCallbacks; + //the actual storage point is in renderable nodes static std::map<MString, MercuryAsset*> m_assetInstances; }; Modified: Mercury2/src/RenderableNode.h =================================================================== --- Mercury2/src/RenderableNode.h 2009-04-26 15:37:56 UTC (rev 218) +++ Mercury2/src/RenderableNode.h 2009-04-26 16:46:17 UTC (rev 219) @@ -40,9 +40,10 @@ bool m_hidden; private: bool IsInAssetList(MercuryAsset* asset) const; - - std::list< MAutoPtr< MercuryAsset > > m_assets; ///serves as a holder for memory + //The asset is actually stored here + std::list< MAutoPtr< MercuryAsset > > m_assets; + //we will just use normal pointers here because we don't want to waste too much time //dereferencing the autopointer. As a precaution when assets are added to these lists, //they must exist in m_assets. Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2009-04-26 15:37:56 UTC (rev 218) +++ Mercury2/src/Texture.cpp 2009-04-26 16:46:17 UTC (rev 219) @@ -24,7 +24,7 @@ Texture::~Texture() { - REMOVE_ASSET_INSTANCE(TEXTURE, m_filename); + REMOVE_ASSET_INSTANCE(TEXTURE, m_path); if (m_textureID) glDeleteTextures(1, &m_textureID); m_textureID = 0; @@ -136,13 +136,13 @@ if (m_isInstanced) return; if ( !path.empty() ) { - ADD_ASSET_INSTANCE(Texture, path, this); - m_filename = path; SetLoadState(LOADING); + ADD_ASSET_INSTANCE(Texture, path, this); + m_path = path; - MercuryThread loaderThread; +// MercuryThread loaderThread; // ImageLoader::LoadImageThreaded(this, m_filename ); - ImageLoader::GetInstance().LoadImageThreaded(this, m_filename ); + ImageLoader::GetInstance().LoadImageThreaded(this); // LoadFromRaw(); // RawImageData* d = ImageLoader::GetInstance().LoadImage( m_filename ); // if (d) LoadFromRaw( d ); @@ -150,12 +150,6 @@ } } -void Texture::LoadedCallback() -{ - printf("loaded!!!!!\n"); - SetLoadState(LOADED); -} - void Texture::SetRawData(RawImageData* raw) { SAFE_DELETE(m_raw); @@ -170,7 +164,7 @@ MAutoPtr< Texture > Texture::LoadFromFile(const MString& path) { MAutoPtr< MercuryAsset > t( AssetFactory::GetInstance().Generate("Texture", path) ); - Texture *a = (Texture*)&(*t); + Texture *a = (Texture*)t.Ptr(); a->LoadImage( path ); return a; } Modified: Mercury2/src/Texture.h =================================================================== --- Mercury2/src/Texture.h 2009-04-26 15:37:56 UTC (rev 218) +++ Mercury2/src/Texture.h 2009-04-26 16:46:17 UTC (rev 219) @@ -18,7 +18,6 @@ virtual void LoadFromXML(const XMLNode& node); void LoadFromRaw(); - virtual void LoadedCallback(); inline static unsigned short NumberActiveTextures() { return m_activeTextures; } inline static uint32_t ReadAndResetBindCount() { uint32_t t = m_textureBinds; m_textureBinds = 0; return t; } @@ -41,7 +40,7 @@ static unsigned short m_activeTextures; static uint32_t m_textureBinds; - MString m_filename; +// MString m_filename; }; #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-05-12 05:01:57
|
Revision: 231 http://hgengine.svn.sourceforge.net/hgengine/?rev=231&view=rev Author: cnlohr Date: 2009-05-12 05:01:48 +0000 (Tue, 12 May 2009) Log Message: ----------- prototypes won't help us here. Modified Paths: -------------- Mercury2/src/MercuryVBO.cpp Mercury2/src/Quad.cpp Mercury2/src/Shader.cpp Mercury2/src/Texture.cpp Modified: Mercury2/src/MercuryVBO.cpp =================================================================== --- Mercury2/src/MercuryVBO.cpp 2009-05-12 04:59:31 UTC (rev 230) +++ Mercury2/src/MercuryVBO.cpp 2009-05-12 05:01:48 UTC (rev 231) @@ -1,7 +1,5 @@ #include <MercuryVBO.h> -#define GL_GLEXT_PROTOTYPES - #include <GLHeaders.h> Modified: Mercury2/src/Quad.cpp =================================================================== --- Mercury2/src/Quad.cpp 2009-05-12 04:59:31 UTC (rev 230) +++ Mercury2/src/Quad.cpp 2009-05-12 05:01:48 UTC (rev 231) @@ -1,7 +1,5 @@ #include <Quad.h> -#define GL_GLEXT_PROTOTYPES - #include <GLHeaders.h> Modified: Mercury2/src/Shader.cpp =================================================================== --- Mercury2/src/Shader.cpp 2009-05-12 04:59:31 UTC (rev 230) +++ Mercury2/src/Shader.cpp 2009-05-12 05:01:48 UTC (rev 231) @@ -2,8 +2,6 @@ #include <RenderableNode.h> #include <MercuryFile.h> -#define GL_GLEXT_PROTOTYPES - #include <GLHeaders.h> Modified: Mercury2/src/Texture.cpp =================================================================== --- Mercury2/src/Texture.cpp 2009-05-12 04:59:31 UTC (rev 230) +++ Mercury2/src/Texture.cpp 2009-05-12 05:01:48 UTC (rev 231) @@ -2,8 +2,6 @@ #include <RenderableNode.h> #include <ImageLoader.h> -#define GL_GLEXT_PROTOTYPES - #include <GLHeaders.h> using namespace std; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-05-12 05:02:53
|
Revision: 234 http://hgengine.svn.sourceforge.net/hgengine/?rev=234&view=rev Author: cnlohr Date: 2009-05-12 05:02:45 +0000 (Tue, 12 May 2009) Log Message: ----------- add OGL Extensions manager for windows. Added Paths: ----------- Mercury2/src/OGLExtensions.cpp Mercury2/src/OGLExtensions.h Added: Mercury2/src/OGLExtensions.cpp =================================================================== --- Mercury2/src/OGLExtensions.cpp (rev 0) +++ Mercury2/src/OGLExtensions.cpp 2009-05-12 05:02:45 UTC (rev 234) @@ -0,0 +1,74 @@ +#include <GLHeaders.h> +#include <OGLExtensions.h> + +//To be removed and switched to LOG? +#include <stdio.h> + +PFNGLBINDBUFFERARBPROC glBindBufferARB; +PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB; + +PFNGLACTIVETEXTUREPROC glActiveTexture; +PFNGLCLIENTACTIVETEXTUREARBPROC glClientActiveTextureARB; + +PFNGLGENBUFFERSARBPROC glGenBuffersARB; +PFNGLBUFFERDATAARBPROC glBufferDataARB; +PFNGLDRAWRANGEELEMENTSPROC glDrawRangeElements; + + + +PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB; +PFNGLDELETEOBJECTARBPROC glDeleteObjectARB; +PFNGLDETACHOBJECTARBPROC glDetachObjectARB; +PFNGLGETATTACHEDOBJECTSARBPROC glGetAttachedObjectsARB; +PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB; +PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB ; +PFNGLSHADERSOURCEARBPROC glShaderSourceARB; +PFNGLCOMPILESHADERARBPROC glCompileShaderARB; +PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB; +PFNGLATTACHOBJECTARBPROC glAttachObjectARB; +PFNGLGETINFOLOGARBPROC glGetInfoLogARB; +PFNGLLINKPROGRAMARBPROC glLinkProgramARB; +PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB; +PFNGLPROGRAMPARAMETERIEXTPROC glProgramParameteriEXT; +PFNGLGETACTIVEUNIFORMARBPROC glGetActiveUniformARB; +PFNGLUNIFORM1IARBPROC glUniform1iARB; +PFNGLUNIFORM4FVARBPROC glUniform4fvARB; + + + +#define EXTENSION( proc, name ) \ + name = (proc)wglGetProcAddress( #name ); \ + if( !name ) \ + { \ + fprintf( stderr, "Error. Could not load extensions: %s\n", #name ); \ + } + +void SetupOGLExtensions() +{ +EXTENSION( PFNGLBINDBUFFERARBPROC, glBindBufferARB ); +EXTENSION( PFNGLDELETEBUFFERSARBPROC,glDeleteBuffersARB ); +EXTENSION( PFNGLACTIVETEXTUREPROC,glActiveTexture ); +EXTENSION( PFNGLCLIENTACTIVETEXTUREARBPROC,glClientActiveTextureARB ); +EXTENSION( PFNGLGENBUFFERSARBPROC,glGenBuffersARB ); +EXTENSION( PFNGLBUFFERDATAARBPROC,glBufferDataARB ); +EXTENSION( PFNGLDRAWRANGEELEMENTSPROC,glDrawRangeElements ); + + +EXTENSION( PFNGLCREATEPROGRAMOBJECTARBPROC,glCreateProgramObjectARB ); +EXTENSION( PFNGLDELETEOBJECTARBPROC,glDeleteObjectARB ); +EXTENSION( PFNGLDETACHOBJECTARBPROC,glDetachObjectARB ); +EXTENSION( PFNGLGETATTACHEDOBJECTSARBPROC,glGetAttachedObjectsARB ); +EXTENSION( PFNGLUSEPROGRAMOBJECTARBPROC,glUseProgramObjectARB ); +EXTENSION( PFNGLCREATESHADEROBJECTARBPROC,glCreateShaderObjectARB ); +EXTENSION( PFNGLSHADERSOURCEARBPROC,glShaderSourceARB ); +EXTENSION( PFNGLCOMPILESHADERARBPROC,glCompileShaderARB ); +EXTENSION( PFNGLGETOBJECTPARAMETERIVARBPROC,glGetObjectParameterivARB ); +EXTENSION( PFNGLATTACHOBJECTARBPROC,glAttachObjectARB ); +EXTENSION( PFNGLGETINFOLOGARBPROC,glGetInfoLogARB ); +EXTENSION( PFNGLLINKPROGRAMARBPROC,glLinkProgramARB ); +EXTENSION( PFNGLGETUNIFORMLOCATIONARBPROC,glGetUniformLocationARB ); +EXTENSION( PFNGLPROGRAMPARAMETERIEXTPROC,glProgramParameteriEXT ); +EXTENSION( PFNGLGETACTIVEUNIFORMARBPROC,glGetActiveUniformARB ); +EXTENSION( PFNGLUNIFORM1IARBPROC,glUniform1iARB ); +EXTENSION( PFNGLUNIFORM4FVARBPROC,glUniform4fvARB ); +} Added: Mercury2/src/OGLExtensions.h =================================================================== --- Mercury2/src/OGLExtensions.h (rev 0) +++ Mercury2/src/OGLExtensions.h 2009-05-12 05:02:45 UTC (rev 234) @@ -0,0 +1,34 @@ +#ifndef _OGL_EXTENSIONS_H + +#include <glext.h> + +extern PFNGLBINDBUFFERARBPROC glBindBufferARB; +extern PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB; +extern PFNGLACTIVETEXTUREPROC glActiveTexture; +extern PFNGLCLIENTACTIVETEXTUREARBPROC glClientActiveTextureARB; +extern PFNGLGENBUFFERSARBPROC glGenBuffersARB; +extern PFNGLBUFFERDATAARBPROC glBufferDataARB; +extern PFNGLDRAWRANGEELEMENTSPROC glDrawRangeElements; + +//glsl +extern PFNGLCREATEPROGRAMOBJECTARBPROC glCreateProgramObjectARB; +extern PFNGLDELETEOBJECTARBPROC glDeleteObjectARB; +extern PFNGLDETACHOBJECTARBPROC glDetachObjectARB; +extern PFNGLGETATTACHEDOBJECTSARBPROC glGetAttachedObjectsARB; +extern PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB; +extern PFNGLCREATESHADEROBJECTARBPROC glCreateShaderObjectARB ; +extern PFNGLSHADERSOURCEARBPROC glShaderSourceARB; +extern PFNGLCOMPILESHADERARBPROC glCompileShaderARB; +extern PFNGLGETOBJECTPARAMETERIVARBPROC glGetObjectParameterivARB; +extern PFNGLATTACHOBJECTARBPROC glAttachObjectARB; +extern PFNGLGETINFOLOGARBPROC glGetInfoLogARB; +extern PFNGLLINKPROGRAMARBPROC glLinkProgramARB; +extern PFNGLGETUNIFORMLOCATIONARBPROC glGetUniformLocationARB; +extern PFNGLPROGRAMPARAMETERIEXTPROC glProgramParameteriEXT; +extern PFNGLGETACTIVEUNIFORMARBPROC glGetActiveUniformARB; +extern PFNGLUNIFORM1IARBPROC glUniform1iARB; +extern PFNGLUNIFORM4FVARBPROC glUniform4fvARB; + +void SetupOGLExtensions(); + +#endif \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cn...@us...> - 2009-05-12 06:02:26
|
Revision: 236 http://hgengine.svn.sourceforge.net/hgengine/?rev=236&view=rev Author: cnlohr Date: 2009-05-12 06:02:19 +0000 (Tue, 12 May 2009) Log Message: ----------- fix up compile on Linux Modified Paths: -------------- Mercury2/src/GLHeaders.h Mercury2/src/global.h Modified: Mercury2/src/GLHeaders.h =================================================================== --- Mercury2/src/GLHeaders.h 2009-05-12 06:02:07 UTC (rev 235) +++ Mercury2/src/GLHeaders.h 2009-05-12 06:02:19 UTC (rev 236) @@ -3,6 +3,8 @@ #ifdef WIN32 #include <windows.h> +#else +#define GL_GLEXT_PROTOTYPES #endif #include <GL/gl.h> @@ -12,9 +14,8 @@ #include <freeglut/glut.h> #include <OGLExtensions.h> #else -#define GL_GLEXT_PROTOTYPES #include <GL/glext.h> -#include <glut.h> +#include <GL/freeglut.h> #endif #endif \ No newline at end of file Modified: Mercury2/src/global.h =================================================================== --- Mercury2/src/global.h 2009-05-12 06:02:07 UTC (rev 235) +++ Mercury2/src/global.h 2009-05-12 06:02:19 UTC (rev 236) @@ -1,7 +1,10 @@ #ifndef GLOBAL_H #define GLOBAL_H +#ifdef WIN32 #pragma warning( disable : 4100 ) +#endif + #include <Mint.h> #endif \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-05-13 02:26:04
|
Revision: 238 http://hgengine.svn.sourceforge.net/hgengine/?rev=238&view=rev Author: axlecrusher Date: 2009-05-13 02:25:55 +0000 (Wed, 13 May 2009) Log Message: ----------- Fix Thread related bugs. Works on windows now. Modified Paths: -------------- Mercury2/src/MScopedArray.h Mercury2/src/MSemaphore.cpp Mercury2/src/MercuryThreads.cpp Mercury2/src/MercuryThreads.h Modified: Mercury2/src/MScopedArray.h =================================================================== --- Mercury2/src/MScopedArray.h 2009-05-13 00:46:57 UTC (rev 237) +++ Mercury2/src/MScopedArray.h 2009-05-13 02:25:55 UTC (rev 238) @@ -16,7 +16,7 @@ { m_criticalSection.Wait(); IncrementReference(); - m_criticalSection.Open(); + m_criticalSection.UnLock(); } MScopedArray() @@ -30,14 +30,14 @@ m_ptr = autoPtr.m_ptr; m_count = autoPtr.m_count; IncrementReference(); - m_criticalSection.Open(); + m_criticalSection.UnLock(); } inline ~MScopedArray() { m_criticalSection.Wait(); DecrementReference(); - m_criticalSection.Open(); + m_criticalSection.UnLock(); } inline unsigned int Count() @@ -45,7 +45,7 @@ unsigned int count = 0; m_criticalSection.Wait(); if( m_ptr && m_count ) count = *m_count; - m_criticalSection.Open(); + m_criticalSection.UnLock(); return count; } @@ -54,7 +54,7 @@ m_criticalSection.Wait(); DecrementReference(); m_ptr = NULL; - m_criticalSection.Open(); + m_criticalSection.UnLock(); } /* void Forget() @@ -64,7 +64,7 @@ if (m_ptr->m_count) if ((m_ptr->m_count) > 0) { --m_ptr->m_count; } m_ptr = NULL; - m_criticalSection.Open(); + m_criticalSection.UnLock(); } */ //Comparative @@ -89,7 +89,7 @@ DecrementReference(); m_ptr = rhs.m_ptr; IncrementReference(); - m_criticalSection.Open(); + m_criticalSection.UnLock(); return *this; } Modified: Mercury2/src/MSemaphore.cpp =================================================================== --- Mercury2/src/MSemaphore.cpp 2009-05-13 00:46:57 UTC (rev 237) +++ Mercury2/src/MSemaphore.cpp 2009-05-13 02:25:55 UTC (rev 238) @@ -33,10 +33,9 @@ #else -//These functions seem to be missing from x86 WinBase FORCEINLINE LONG -MyInterlockedOr ( +OrAndFetch ( __inout LONG volatile *Destination, __in LONG Value ) @@ -49,9 +48,10 @@ Old | Value, Old) != Old); - return Old; + return Old | Value; } +//Function seem to be missing from x86 WinBase FORCEINLINE LONG MyInterlockedAnd ( @@ -72,7 +72,8 @@ unsigned long MSemaphore::Read() { - return MyInterlockedOr(&m_counter, 0); + return OrAndFetch(&m_counter, 0); +// return MyInterlockedOr(&m_counter, 0); } unsigned long MSemaphore::ReadAndClear() Modified: Mercury2/src/MercuryThreads.cpp =================================================================== --- Mercury2/src/MercuryThreads.cpp 2009-05-13 00:46:57 UTC (rev 237) +++ Mercury2/src/MercuryThreads.cpp 2009-05-13 02:25:55 UTC (rev 238) @@ -7,7 +7,7 @@ #include <stdio.h> MercuryThread::MercuryThread() - :m_name("(null)"), m_haltOnDestroy(true), m_thread(0) + :m_haltOnDestroy(true), m_thread(0) { #if defined( WIN32 ) mkThreadData = NULL; @@ -186,7 +186,10 @@ p->nLength = sizeof( SECURITY_ATTRIBUTES ); p->bInheritHandle = true; p->lpSecurityDescriptor = NULL; - m_mutex = CreateMutex( p, true, (LPCWSTR)m_name.c_str() ); + if ( m_name.empty() ) + m_mutex = CreateMutex( p, true, NULL ); + else + m_mutex = CreateMutex( p, true, (LPCWSTR)m_name.c_str() ); free( p ); return (int)m_mutex; #else Modified: Mercury2/src/MercuryThreads.h =================================================================== --- Mercury2/src/MercuryThreads.h 2009-05-13 00:46:57 UTC (rev 237) +++ Mercury2/src/MercuryThreads.h 2009-05-13 02:25:55 UTC (rev 238) @@ -75,12 +75,14 @@ ///Unlock a mutex for the next thing waiting in line. int UnLock( ); +private: + ///Start up a mutex. You need to do this as well as UnLock() afterwards when in a constructor. int Open( ); - + ///Clean up a mutex. This is done automatically on destruction of mutex. int Close( ); -private: + MString m_name; int iLockCount; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-05-14 02:03:30
|
Revision: 240 http://hgengine.svn.sourceforge.net/hgengine/?rev=240&view=rev Author: axlecrusher Date: 2009-05-14 01:47:52 +0000 (Thu, 14 May 2009) Log Message: ----------- recursive lock semaphore??? Modified Paths: -------------- Mercury2/src/MSemaphore.cpp Mercury2/src/MSemaphore.h Mercury2/src/MercuryThreads.cpp Modified: Mercury2/src/MSemaphore.cpp =================================================================== --- Mercury2/src/MSemaphore.cpp 2009-05-13 02:26:18 UTC (rev 239) +++ Mercury2/src/MSemaphore.cpp 2009-05-14 01:47:52 UTC (rev 240) @@ -1,4 +1,5 @@ #include <MSemaphore.h> +#include <MercuryThreads.h> MSemaphore::MSemaphore() :m_counter(0) @@ -6,10 +7,9 @@ } #ifndef WIN32 -unsigned long MSemaphore::Read() -{ - return __sync_or_and_fetch(&m_counter, 0); -} +#define SYNC_OR_AND_FETCH(d,v) __sync_or_and_fetch(d,v) +#define COMPARE_AND_SWAP(d,o,n) __sync_val_compare_and_swap(d,o,n) +#define SYNC_AND_AND_FETCH(d,v) __sync_and_and_fetch(d,v) unsigned long MSemaphore::ReadAndClear() { @@ -28,7 +28,7 @@ void MSemaphore::WaitAndSet(unsigned long value, unsigned long newVal) { - while ( !__sync_bool_compare_and_swap(&m_counter, value, newVal) ); + while( (unsigned long)__sync_val_compare_and_swap(&m_counter, value, newVal) != value ); } #else @@ -70,11 +70,8 @@ return Old; } -unsigned long MSemaphore::Read() -{ - return OrAndFetch(&m_counter, 0); -// return MyInterlockedOr(&m_counter, 0); -} +#define SYNC_OR_AND_FETCH(d,v) OrAndFetch(d,v) +#define COMPARE_AND_SWAP(d,o,n) InterlockedCompareExchange(d, n, o) unsigned long MSemaphore::ReadAndClear() { @@ -93,21 +90,48 @@ void MSemaphore::WaitAndSet(unsigned long value, unsigned long newVal) { - InterlockedCompareExchange(&m_counter, newVal, value); -// while ( !__sync_bool_compare_and_swap(&m_counter, value, newVal) ); + while ( InterlockedCompareExchange(Destination, newVal, value) != value ); } #endif +unsigned long MSemaphore::Read() +{ + return SYNC_OR_AND_FETCH(&m_counter, 0); +} + +void MSemaphore::Wait() +{ + uint32_t thread = MercuryThread::Current(); + if ( COMPARE_AND_SWAP(&m_thread, 0, thread) == thread) //recursive lock + { + ++m_lockCount; + return; + } + WaitAndSet(0,1); + ++m_lockCount; +} + +void MSemaphore::UnLock() +{ + uint32_t thread = MercuryThread::Current(); + if ( SYNC_OR_AND_FETCH(&m_thread, 0) == thread) //unlock given from correct thread + { + --m_lockCount; + if (m_lockCount == 0) WaitAndSet(1,0); + SYNC_AND_AND_FETCH(&m_thread, 0 ); + } +} + MSemaphoreLock::MSemaphoreLock(MSemaphore* s) :m_s(s) { - m_s->WaitAndSet(0,1); + m_s->Wait(); } MSemaphoreLock::~MSemaphoreLock() { - m_s->WaitAndSet(1,0); + m_s->UnLock(); } MSemaphoreIncOnDestroy::MSemaphoreIncOnDestroy(MSemaphore* s) Modified: Mercury2/src/MSemaphore.h =================================================================== --- Mercury2/src/MSemaphore.h 2009-05-13 02:26:18 UTC (rev 239) +++ Mercury2/src/MSemaphore.h 2009-05-14 01:47:52 UTC (rev 240) @@ -17,13 +17,19 @@ unsigned long Decrement(); unsigned long Increment(); void WaitAndSet(unsigned long value, unsigned long newVal); - + + void Wait(); + void UnLock(); private: + //what exactly needs to be volatile + uint32_t m_lockCount; #ifndef WIN32 - int32_t m_counter; + uint32_t m_counter; + uint32_t m_thread; #else - volatile LONG m_counter; + volatile LONG m_counter; //align to 32bit boundary + volatile LONG m_thread; #endif }; Modified: Mercury2/src/MercuryThreads.cpp =================================================================== --- Mercury2/src/MercuryThreads.cpp 2009-05-13 02:26:18 UTC (rev 239) +++ Mercury2/src/MercuryThreads.cpp 2009-05-14 01:47:52 UTC (rev 240) @@ -119,6 +119,12 @@ } } +unsigned long MercuryThread::Current() +{ + return pthread_self(); +} + + //Mutex functions MercuryMutex::MercuryMutex( ) :m_name("(null)") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-05-14 10:54:01
|
Revision: 241 http://hgengine.svn.sourceforge.net/hgengine/?rev=241&view=rev Author: axlecrusher Date: 2009-05-14 10:53:50 +0000 (Thu, 14 May 2009) Log Message: ----------- just use the semaphore to hold the thread id Modified Paths: -------------- Mercury2/src/MSemaphore.cpp Mercury2/src/MSemaphore.h Modified: Mercury2/src/MSemaphore.cpp =================================================================== --- Mercury2/src/MSemaphore.cpp 2009-05-14 01:47:52 UTC (rev 240) +++ Mercury2/src/MSemaphore.cpp 2009-05-14 10:53:50 UTC (rev 241) @@ -1,9 +1,12 @@ #include <MSemaphore.h> #include <MercuryThreads.h> +#include <stdio.h> + MSemaphore::MSemaphore() - :m_counter(0) + :m_lockCount(0), m_semaphore(0) { + printf("cs %d\n", m_semaphore); } #ifndef WIN32 @@ -13,24 +16,19 @@ unsigned long MSemaphore::ReadAndClear() { - return __sync_fetch_and_and(&m_counter, 0); + return __sync_fetch_and_and(&m_semaphore, 0); } unsigned long MSemaphore::Decrement() { - return __sync_sub_and_fetch(&m_counter, 1); + return __sync_sub_and_fetch(&m_semaphore, 1); } unsigned long MSemaphore::Increment() { - return __sync_add_and_fetch(&m_counter, 1); + return __sync_add_and_fetch(&m_semaphore, 1); } -void MSemaphore::WaitAndSet(unsigned long value, unsigned long newVal) -{ - while( (unsigned long)__sync_val_compare_and_swap(&m_counter, value, newVal) != value ); -} - #else FORCEINLINE @@ -75,51 +73,51 @@ unsigned long MSemaphore::ReadAndClear() { - return MyInterlockedAnd(&m_counter, 0); + return MyInterlockedAnd(&m_semaphore, 0); } unsigned long MSemaphore::Decrement() { - return InterlockedDecrement(&m_counter); + return InterlockedDecrement(&m_semaphore); } unsigned long MSemaphore::Increment() { - return InterlockedIncrement(&m_counter); + return InterlockedIncrement(&m_semaphore); } -void MSemaphore::WaitAndSet(unsigned long value, unsigned long newVal) -{ - while ( InterlockedCompareExchange(Destination, newVal, value) != value ); -} - #endif unsigned long MSemaphore::Read() { - return SYNC_OR_AND_FETCH(&m_counter, 0); + return SYNC_OR_AND_FETCH(&m_semaphore, 0); } +void MSemaphore::WaitAndSet(unsigned long value, unsigned long newVal) +{ + while( COMPARE_AND_SWAP(&m_semaphore, value, newVal) != value ); +} + void MSemaphore::Wait() { uint32_t thread = MercuryThread::Current(); - if ( COMPARE_AND_SWAP(&m_thread, 0, thread) == thread) //recursive lock + if ( SYNC_OR_AND_FETCH(&m_semaphore, 0) == thread) //recursive lock { ++m_lockCount; return; } - WaitAndSet(0,1); + + WaitAndSet(0,thread); //new lock ++m_lockCount; } void MSemaphore::UnLock() { uint32_t thread = MercuryThread::Current(); - if ( SYNC_OR_AND_FETCH(&m_thread, 0) == thread) //unlock given from correct thread + if ( SYNC_OR_AND_FETCH(&m_semaphore, 0) == thread) //unlock given from correct thread { --m_lockCount; - if (m_lockCount == 0) WaitAndSet(1,0); - SYNC_AND_AND_FETCH(&m_thread, 0 ); + if (m_lockCount == 0) SYNC_AND_AND_FETCH(&m_semaphore, 0 ); } } Modified: Mercury2/src/MSemaphore.h =================================================================== --- Mercury2/src/MSemaphore.h 2009-05-14 01:47:52 UTC (rev 240) +++ Mercury2/src/MSemaphore.h 2009-05-14 10:53:50 UTC (rev 241) @@ -22,14 +22,12 @@ void UnLock(); private: - //what exactly needs to be volatile + //what exactly needs to be volatile? uint32_t m_lockCount; #ifndef WIN32 - uint32_t m_counter; - uint32_t m_thread; + uint32_t m_semaphore; #else volatile LONG m_counter; //align to 32bit boundary - volatile LONG m_thread; #endif }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-05-14 22:15:03
|
Revision: 245 http://hgengine.svn.sourceforge.net/hgengine/?rev=245&view=rev Author: axlecrusher Date: 2009-05-14 22:15:01 +0000 (Thu, 14 May 2009) Log Message: ----------- Fix windows compile Modified Paths: -------------- Mercury2/src/MSemaphore.cpp Mercury2/src/MSemaphore.h Mercury2/src/MercuryThreads.cpp Mercury2/src/PNGLoader.cpp Modified: Mercury2/src/MSemaphore.cpp =================================================================== --- Mercury2/src/MSemaphore.cpp 2009-05-14 21:59:18 UTC (rev 244) +++ Mercury2/src/MSemaphore.cpp 2009-05-14 22:15:01 UTC (rev 245) @@ -65,8 +65,27 @@ return Old; } +FORCEINLINE +LONG +__sync_and_and_fetch ( + __inout LONG volatile *Destination, + __in LONG Value + ) +{ + LONG Old; + + do { + Old = *Destination; + } while (InterlockedCompareExchange(Destination, + Old & Value, + Old) != Old); + + return Old & Value; +} + #define SYNC_OR_AND_FETCH(d,v) OrAndFetch(d,v) #define COMPARE_AND_SWAP(d,o,n) InterlockedCompareExchange(d, n, o) +#define SYNC_AND_AND_FETCH(d,v) __sync_and_and_fetch(d,v) unsigned long MSemaphore::ReadAndClear() { @@ -90,15 +109,15 @@ return SYNC_OR_AND_FETCH(&m_semaphore, 0); } -void MSemaphore::WaitAndSet(unsigned long value, unsigned long newVal) +void MSemaphore::WaitAndSet(uint32_t value, uint32_t newVal) { - while( COMPARE_AND_SWAP(&m_semaphore, value, newVal) != value ); + while( COMPARE_AND_SWAP(&m_semaphore, value, newVal) != ((int32_t)value) ); } void MSemaphore::Wait() { uint32_t thread = MercuryThread::Current(); - if ( SYNC_OR_AND_FETCH(&m_semaphore, 0) == thread) //recursive lock + if ( SYNC_OR_AND_FETCH(&m_semaphore, 0) == ((int32_t)thread) ) //recursive lock { ++m_lockCount; return; @@ -111,7 +130,7 @@ void MSemaphore::UnLock() { uint32_t thread = MercuryThread::Current(); - if ( SYNC_OR_AND_FETCH(&m_semaphore, 0) == thread) //unlock given from correct thread + if ( SYNC_OR_AND_FETCH(&m_semaphore, 0) == ((int32_t)thread) ) //unlock given from correct thread { --m_lockCount; if (m_lockCount == 0) SYNC_AND_AND_FETCH(&m_semaphore, 0 ); Modified: Mercury2/src/MSemaphore.h =================================================================== --- Mercury2/src/MSemaphore.h 2009-05-14 21:59:18 UTC (rev 244) +++ Mercury2/src/MSemaphore.h 2009-05-14 22:15:01 UTC (rev 245) @@ -16,7 +16,7 @@ unsigned long ReadAndClear(); unsigned long Decrement(); unsigned long Increment(); - void WaitAndSet(unsigned long value, unsigned long newVal); + void WaitAndSet(uint32_t value, uint32_t newVal); void Wait(); void UnLock(); @@ -27,7 +27,7 @@ #ifndef WIN32 uint32_t m_semaphore; #else - volatile LONG m_counter; //align to 32bit boundary + volatile LONG m_semaphore; //align to 32bit boundary #endif }; Modified: Mercury2/src/MercuryThreads.cpp =================================================================== --- Mercury2/src/MercuryThreads.cpp 2009-05-14 21:59:18 UTC (rev 244) +++ Mercury2/src/MercuryThreads.cpp 2009-05-14 22:15:01 UTC (rev 245) @@ -121,7 +121,11 @@ unsigned long MercuryThread::Current() { +#ifdef WIN32 + return GetCurrentThreadId(); +#else return pthread_self(); +#endif } Modified: Mercury2/src/PNGLoader.cpp =================================================================== --- Mercury2/src/PNGLoader.cpp 2009-05-14 21:59:18 UTC (rev 244) +++ Mercury2/src/PNGLoader.cpp 2009-05-14 22:15:01 UTC (rev 245) @@ -1,8 +1,8 @@ -#include <ImageLoader.h> -#include <MercuryUtil.h> - -#include <assert.h> - +#include <ImageLoader.h> +#include <MercuryUtil.h> + +#include <assert.h> + #if defined(WIN32) # include <png.h> # if defined(_MSC_VER) @@ -12,173 +12,173 @@ #else # include <png.h> #endif - - -void PNGRead( png_struct *png, png_byte *p, png_size_t size ) -{ - MercuryFile * f = (MercuryFile*)png->io_ptr; - - int got = f->Read( p, (unsigned long)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( MercuryFile * 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 (unsigned long x = 0; x < image->m_width; ++x) { - png_byte* ptr = &(row[x*4]); - image->m_data[(x + y * image->m_width) * 4] = ptr[0]; - image->m_data[(x + y * image->m_width) * 4 + 1] = ptr[1]; - 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 (unsigned long x=0; x<image->m_width; x++) { - png_byte* ptr = &(row[x * 3]); - image->m_data[(x + y * image->m_width) * 3] = ptr[0]; - image->m_data[(x + y * image->m_width) * 3 + 1] = ptr[1]; - 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. + + +void PNGRead( png_struct *png, png_byte *p, png_size_t size ) +{ + MercuryFile * f = (MercuryFile*)png->io_ptr; + + int got = f->Read( p, (unsigned long)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( MercuryFile * 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 (unsigned long x = 0; x < image->m_width; ++x) { + png_byte* ptr = &(row[x*4]); + image->m_data[(x + y * image->m_width) * 4] = ptr[0]; + image->m_data[(x + y * image->m_width) * 4 + 1] = ptr[1]; + 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 (unsigned long x=0; x<image->m_width; x++) { + png_byte* ptr = &(row[x * 3]); + image->m_data[(x + y * image->m_width) * 3] = ptr[0]; + image->m_data[(x + y * image->m_width) * 3 + 1] = ptr[1]; + 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 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-05-15 00:52:40
|
Revision: 247 http://hgengine.svn.sourceforge.net/hgengine/?rev=247&view=rev Author: axlecrusher Date: 2009-05-15 00:52:32 +0000 (Fri, 15 May 2009) Log Message: ----------- instance shaders Modified Paths: -------------- Mercury2/src/Shader.cpp Mercury2/src/Shader.h Modified: Mercury2/src/Shader.cpp =================================================================== --- Mercury2/src/Shader.cpp 2009-05-14 22:34:39 UTC (rev 246) +++ Mercury2/src/Shader.cpp 2009-05-15 00:52:32 UTC (rev 247) @@ -81,11 +81,19 @@ void Shader::LoadFromXML(const XMLNode& node) { - sShaderName = node.Attribute("file"); - fPriority = StrToFloat( node.Attribute("priority").c_str() ); - LoadShader( ); + LoadShader( node.Attribute("file"), StrToFloat( node.Attribute("priority") ) ); } +void Shader::LoadShader( const MString& path, float priority ) +{ + if (m_isInstanced) return; + + sShaderName = path; + fPriority = priority; + ADD_ASSET_INSTANCE(Shader, sShaderName, this); + LoadShader( ); +} + bool Shader::LoadShader( ) { GetTimeCodes( iTimeCode ); Modified: Mercury2/src/Shader.h =================================================================== --- Mercury2/src/Shader.h 2009-05-14 22:34:39 UTC (rev 246) +++ Mercury2/src/Shader.h 2009-05-15 00:52:32 UTC (rev 247) @@ -72,6 +72,8 @@ ///Explicitly get the OpenGL ProgramID in the event you need it for advanced techniques unsigned int GetProgramID() { return iProgramID; } private: + void LoadShader( const MString& path, float priority ); + ///Suggested function for loading shaders. /** This function looks for {sShaderName}.vert and {sShaderName}.frag. It will attempt to load, compile and link the files. If any errors are found, they will This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-05-16 00:37:16
|
Revision: 250 http://hgengine.svn.sourceforge.net/hgengine/?rev=250&view=rev Author: axlecrusher Date: 2009-05-16 00:37:07 +0000 (Sat, 16 May 2009) Log Message: ----------- add billboard (needs debugging) Added Paths: ----------- Mercury2/src/BillboardNode.cpp Mercury2/src/BillboardNode.h Added: Mercury2/src/BillboardNode.cpp =================================================================== --- Mercury2/src/BillboardNode.cpp (rev 0) +++ Mercury2/src/BillboardNode.cpp 2009-05-16 00:37:07 UTC (rev 250) @@ -0,0 +1,66 @@ +#include <BillboardNode.h> +#include <MercuryVertex.h> +#include <Viewport.h> + +REGISTER_NODE_TYPE(Billboard); + +MercuryMatrix Billboard::ManipulateMatrix(const MercuryMatrix& matrix) +{ + MercuryMatrix m = matrix; +// m.Transpose(); + + //manually transposed + MercuryVertex center(m[3][0], m[3][1], m[3][2]); + + const MercuryVertex& eye = FRUSTUM->GetEye(); + const MercuryVector& lookAt = FRUSTUM->GetLookAt(); + + MercuryVector v = (eye - center).Normalize(); + MercuryVector up = lookAt.CrossProduct( v ); + float angleCos = lookAt.DotProduct(v); + + if ((angleCos < 0.99990) && (angleCos > -0.9999)) + { + float f = ACOS(angleCos)*RADDEG; +// printf("billboard!!! %f %f %f\n",up[0]*f, up[1]*f, up[2]*f ); + +// MercuryMatrix m; +// m.RotateXYZ(ACOS(angleCosine)*RADDEG,upAux[0], upAux[1], upAux[2]) +// glRotatef(ACOS(angleCosine)*RADDEG,upAux[0], upAux[1], upAux[2]); + m.RotateXYZ(up[0]*f, up[1]*f, up[2]*f); + } +// m.Transpose(); + return m; +} + +/**************************************************************************** + * 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/BillboardNode.h =================================================================== --- Mercury2/src/BillboardNode.h (rev 0) +++ Mercury2/src/BillboardNode.h 2009-05-16 00:37:07 UTC (rev 250) @@ -0,0 +1,47 @@ +#ifndef BILLBOARDNODE_H +#define BILLBOARDNODE_H + +#include <RenderableNode.h> + +class Billboard : public RenderableNode +{ + public: + virtual MercuryMatrix ManipulateMatrix(const MercuryMatrix& matrix); + + private: +}; + +#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-05-16 00:41:21
|
Revision: 251 http://hgengine.svn.sourceforge.net/hgengine/?rev=251&view=rev Author: axlecrusher Date: 2009-05-16 00:41:20 +0000 (Sat, 16 May 2009) Log Message: ----------- updates aimed at being able to billboard Modified Paths: -------------- Mercury2/src/Frustum.cpp Mercury2/src/Frustum.h Mercury2/src/MercuryNode.cpp Mercury2/src/MercuryVertex.h Mercury2/src/RenderGraph.cpp Mercury2/src/RenderableNode.cpp Mercury2/src/RenderableNode.h Mercury2/src/TransformNode.h Modified: Mercury2/src/Frustum.cpp =================================================================== --- Mercury2/src/Frustum.cpp 2009-05-16 00:37:07 UTC (rev 250) +++ Mercury2/src/Frustum.cpp 2009-05-16 00:41:20 UTC (rev 251) @@ -53,6 +53,9 @@ //Right now this only builds the frustum planes MercuryVector X,Y,Z; + m_lookAt = look; + m_eye = eye; + Z = (eye - look).Normalize(); //direction behind camera X = (up.CrossProduct(Z)).Normalize(); //X axis Y = Z.CrossProduct( X ); //real up Modified: Mercury2/src/Frustum.h =================================================================== --- Mercury2/src/Frustum.h 2009-05-16 00:37:07 UTC (rev 250) +++ Mercury2/src/Frustum.h 2009-05-16 00:41:20 UTC (rev 251) @@ -24,6 +24,8 @@ void LookAt(const MercuryVertex& eye, const MercuryVector& look, const MercuryVector& up); inline const MercuryPlane& GetPlane(int i) const { return m_planes[i]; } + inline const MercuryVertex& GetLookAt() const { return m_lookAt; } + inline const MercuryVertex& GetEye() const { return m_eye; } private: MercuryPlane m_planes[6]; @@ -33,6 +35,8 @@ float m_nh, m_nw, m_fh, m_fw; MercuryVector m_nc, m_fc; + MercuryVertex m_lookAt; + MercuryVertex m_eye; }; #endif Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-05-16 00:37:07 UTC (rev 250) +++ Mercury2/src/MercuryNode.cpp 2009-05-16 00:41:20 UTC (rev 251) @@ -147,6 +147,7 @@ std::list< std::pair< MString, Callback0R<MercuryNode*> > >::iterator i; for (i = m_factoryCallbacks.begin(); i != m_factoryCallbacks.end(); ++i) if (i->first == t) return i->second(); + printf("WARNING: Node type %s not found.\n", type.c_str()); return NULL; } Modified: Mercury2/src/MercuryVertex.h =================================================================== --- Mercury2/src/MercuryVertex.h 2009-05-16 00:37:07 UTC (rev 250) +++ Mercury2/src/MercuryVertex.h 2009-05-16 00:41:20 UTC (rev 251) @@ -25,9 +25,9 @@ inline FloatRow& ToFloatRow() { return m_xyzw; } inline const FloatRow& ToFloatRow() const { return m_xyzw; } - inline const float GetX() const { return (*this)[0]; } - inline const float GetY() const { return (*this)[1]; } - inline const float GetZ() const { return (*this)[2]; } + inline float GetX() const { return (*this)[0]; } + inline float GetY() const { return (*this)[1]; } + inline float GetZ() const { return (*this)[2]; } inline void SetX(const float ix) { (*this)[0] = ix; } inline void SetY(const float iy) { (*this)[1] = iy; } inline void SetZ(const float iz) { (*this)[2] = iz; } Modified: Mercury2/src/RenderGraph.cpp =================================================================== --- Mercury2/src/RenderGraph.cpp 2009-05-16 00:37:07 UTC (rev 250) +++ Mercury2/src/RenderGraph.cpp 2009-05-16 00:41:20 UTC (rev 251) @@ -9,8 +9,8 @@ if (m_node) { - if ( m_node->IsHidden() || m_node->IsCulled(*m_matrix) ) return; - m = *m_matrix; + m = m_node->ManipulateMatrix( *m_matrix ); + if ( m_node->IsHidden() || m_node->IsCulled(m) ) return; m.Transpose(); glLoadMatrixf( m.Ptr() ); m_node->PreRender( m ); Modified: Mercury2/src/RenderableNode.cpp =================================================================== --- Mercury2/src/RenderableNode.cpp 2009-05-16 00:37:07 UTC (rev 250) +++ Mercury2/src/RenderableNode.cpp 2009-05-16 00:41:20 UTC (rev 251) @@ -158,6 +158,11 @@ return clip; } +MercuryMatrix RenderableNode::ManipulateMatrix(const MercuryMatrix& matrix) +{ + return matrix; +} + /*************************************************************************** * Copyright (C) 2008 by Joshua Allen * * * Modified: Mercury2/src/RenderableNode.h =================================================================== --- Mercury2/src/RenderableNode.h 2009-05-16 00:37:07 UTC (rev 250) +++ Mercury2/src/RenderableNode.h 2009-05-16 00:41:20 UTC (rev 251) @@ -34,6 +34,8 @@ virtual bool IsCulled(const MercuryMatrix& matrix); bool IsHidden() { return m_hidden; } + + virtual MercuryMatrix ManipulateMatrix(const MercuryMatrix& matrix); GENRTTI(RenderableNode); protected: Modified: Mercury2/src/TransformNode.h =================================================================== --- Mercury2/src/TransformNode.h 2009-05-16 00:37:07 UTC (rev 250) +++ Mercury2/src/TransformNode.h 2009-05-16 00:41:20 UTC (rev 251) @@ -27,7 +27,7 @@ void SetTaint(bool taint); - void ComputeMatrix(); + virtual void ComputeMatrix(); virtual void LoadFromXML(const XMLNode& node); @@ -43,6 +43,7 @@ MercuryPoint m_rotation; // MercuryMatrix m_localMatrix; + protected: MercuryMatrix m_globalMatrix; bool m_tainted; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-05-16 02:41:32
|
Revision: 252 http://hgengine.svn.sourceforge.net/hgengine/?rev=252&view=rev Author: axlecrusher Date: 2009-05-16 02:41:31 +0000 (Sat, 16 May 2009) Log Message: ----------- updates for billboards (broken) Modified Paths: -------------- Mercury2/src/BillboardNode.cpp Mercury2/src/Frustum.cpp Mercury2/src/RenderGraph.cpp Mercury2/src/RenderableNode.cpp Mercury2/src/RenderableNode.h Mercury2/src/Viewport.cpp Mercury2/src/Viewport.h Modified: Mercury2/src/BillboardNode.cpp =================================================================== --- Mercury2/src/BillboardNode.cpp 2009-05-16 00:41:20 UTC (rev 251) +++ Mercury2/src/BillboardNode.cpp 2009-05-16 02:41:31 UTC (rev 252) @@ -6,30 +6,28 @@ MercuryMatrix Billboard::ManipulateMatrix(const MercuryMatrix& matrix) { - MercuryMatrix m = matrix; -// m.Transpose(); + MercuryMatrix m = RenderableNode::ManipulateMatrix( matrix ); - //manually transposed - MercuryVertex center(m[3][0], m[3][1], m[3][2]); + MercuryVertex center(m.Ptr()[3], m.Ptr()[7], m.Ptr()[11]); - const MercuryVertex& eye = FRUSTUM->GetEye(); - const MercuryVector& lookAt = FRUSTUM->GetLookAt(); - - MercuryVector v = (eye - center).Normalize(); - MercuryVector up = lookAt.CrossProduct( v ); - float angleCos = lookAt.DotProduct(v); + MercuryVector v = (EYE - center).Normalize(); + MercuryVector up = LOOKAT.CrossProduct( v ); + float angleCos = LOOKAT.DotProduct(v); + +// VIEWMATRIX.Ptr()[3]; +// EYE.Print(); +// center.Print(); +// printf("angleCos %f\n",angleCos); + if ((angleCos < 0.99990) && (angleCos > -0.9999)) { float f = ACOS(angleCos)*RADDEG; // printf("billboard!!! %f %f %f\n",up[0]*f, up[1]*f, up[2]*f ); -// MercuryMatrix m; -// m.RotateXYZ(ACOS(angleCosine)*RADDEG,upAux[0], upAux[1], upAux[2]) -// glRotatef(ACOS(angleCosine)*RADDEG,upAux[0], upAux[1], upAux[2]); m.RotateXYZ(up[0]*f, up[1]*f, up[2]*f); } -// m.Transpose(); + return m; } Modified: Mercury2/src/Frustum.cpp =================================================================== --- Mercury2/src/Frustum.cpp 2009-05-16 00:41:20 UTC (rev 251) +++ Mercury2/src/Frustum.cpp 2009-05-16 02:41:31 UTC (rev 252) @@ -2,6 +2,7 @@ void Frustum::SetPerspective( float fov, float aspect, float znear, float zfar ) { + //Should go in projection matrix float xmin, xmax, ymin, ymax; m_fov = fov; @@ -24,6 +25,7 @@ void Frustum::ComputeFrustum(float left, float right, float bottom, float top, float zNear, float zFar) { + //Should go in projection matrix float near2 = 2*zNear; float rml = right-left; float tmb = top - bottom; Modified: Mercury2/src/RenderGraph.cpp =================================================================== --- Mercury2/src/RenderGraph.cpp 2009-05-16 00:41:20 UTC (rev 251) +++ Mercury2/src/RenderGraph.cpp 2009-05-16 02:41:31 UTC (rev 252) @@ -9,11 +9,11 @@ if (m_node) { + m_node->PreRender( *m_matrix ); m = m_node->ManipulateMatrix( *m_matrix ); if ( m_node->IsHidden() || m_node->IsCulled(m) ) return; m.Transpose(); glLoadMatrixf( m.Ptr() ); - m_node->PreRender( m ); m_node->Render( m ); } Modified: Mercury2/src/RenderableNode.cpp =================================================================== --- Mercury2/src/RenderableNode.cpp 2009-05-16 00:41:20 UTC (rev 251) +++ Mercury2/src/RenderableNode.cpp 2009-05-16 02:41:31 UTC (rev 252) @@ -160,7 +160,7 @@ MercuryMatrix RenderableNode::ManipulateMatrix(const MercuryMatrix& matrix) { - return matrix; + return VIEWMATRIX * matrix; } /*************************************************************************** Modified: Mercury2/src/RenderableNode.h =================================================================== --- Mercury2/src/RenderableNode.h 2009-05-16 00:41:20 UTC (rev 251) +++ Mercury2/src/RenderableNode.h 2009-05-16 02:41:31 UTC (rev 252) @@ -24,8 +24,11 @@ void AddRender(MercuryAsset* asset); void AddPostRender(MercuryAsset* asset); + ///This will get the world space matrix virtual void PreRender(const MercuryMatrix& matrix); + virtual void Render(const MercuryMatrix& matrix); + virtual void PostRender(const MercuryMatrix& matrix); virtual void LoadFromXML(const XMLNode& node); Modified: Mercury2/src/Viewport.cpp =================================================================== --- Mercury2/src/Viewport.cpp 2009-05-16 00:41:20 UTC (rev 251) +++ Mercury2/src/Viewport.cpp 2009-05-16 02:41:31 UTC (rev 252) @@ -4,30 +4,41 @@ REGISTER_NODE_TYPE(Viewport); const Frustum* FRUSTUM; +MercuryMatrix VIEWMATRIX; +MercuryVertex EYE; +MercuryVector LOOKAT; Viewport::Viewport() :m_xFactor(1), m_yFactor(0.5), m_minx(0), m_miny(0) { } -void Viewport::Render(const MercuryMatrix& matrix) +void Viewport::PreRender(const MercuryMatrix& matrix) { FRUSTUM = &m_frustum; MercuryWindow* w = MercuryWindow::GetCurrentWindow(); glViewport(m_minx, m_miny, (GLsizei)(w->Width()*m_xFactor), (GLsizei)(w->Height()*m_yFactor)); + //Load the frustum into the projection + //"eye" position does not go into projection glMatrixMode(GL_PROJECTION); - MercuryMatrix f = m_frustum.GetMatrix(); f.Transpose(); - - glLoadMatrixf( (matrix * f).Ptr() ); - //The following 2 are equivelent to above -// glLoadMatrixf( m_frustum.Ptr() ); -// glMultMatrixf( m.Ptr() ); + glLoadMatrixf( f.Ptr() ); glMatrixMode(GL_MODELVIEW); + + VIEWMATRIX = matrix; + EYE[0] = matrix[0][3]; + EYE[1] = matrix[1][3]; + EYE[2] = matrix[2][3]; + EYE *= -1; + + MercuryVector l(0,0,1); +// l += EYE; + LOOKAT = (matrix * l).Normalize(); +// LOOKAT.Print(); } void Viewport::LoadFromXML(const XMLNode& node) Modified: Mercury2/src/Viewport.h =================================================================== --- Mercury2/src/Viewport.h 2009-05-16 00:41:20 UTC (rev 251) +++ Mercury2/src/Viewport.h 2009-05-16 02:41:31 UTC (rev 252) @@ -8,12 +8,15 @@ #include <Frustum.h> extern const Frustum* FRUSTUM; +extern MercuryMatrix VIEWMATRIX; +extern MercuryVertex EYE; +extern MercuryVector LOOKAT; class Viewport : public RenderableNode { public: Viewport(); - virtual void Render(const MercuryMatrix& matrix); + virtual void PreRender(const MercuryMatrix& matrix); 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...> - 2009-05-16 03:46:33
|
Revision: 255 http://hgengine.svn.sourceforge.net/hgengine/?rev=255&view=rev Author: axlecrusher Date: 2009-05-16 03:46:27 +0000 (Sat, 16 May 2009) Log Message: ----------- vector multiplication Modified Paths: -------------- Mercury2/src/MercuryVertex.cpp Mercury2/src/MercuryVertex.h Mercury2/src/Viewport.cpp Modified: Mercury2/src/MercuryVertex.cpp =================================================================== --- Mercury2/src/MercuryVertex.cpp 2009-05-16 03:13:09 UTC (rev 254) +++ Mercury2/src/MercuryVertex.cpp 2009-05-16 03:46:27 UTC (rev 255) @@ -4,25 +4,26 @@ MercuryVertex::MercuryVertex() { - (*this)[0] = (*this)[1] = (*this)[2] = 0; + (*this)[0] = (*this)[1] = (*this)[2] = (*this)[3] = 0; } -MercuryVertex::MercuryVertex( float ix, float iy, float iz ) +MercuryVertex::MercuryVertex( float ix, float iy, float iz, float iw ) { (*this)[0] = ix; (*this)[1] = iy; (*this)[2] = iz; + (*this)[3] = iw; } - +/* MercuryVertex::MercuryVertex( const float * in ) { - for (unsigned int i = 0; i < 3; ++i) + for (unsigned int i = 0; i < 4; ++i) (*this)[i] = in[i]; } - +*/ MercuryVertex::MercuryVertex( const MercuryVertex& v) { - for (unsigned int i = 0; i < 3; ++i) + for (unsigned int i = 0; i < 4; ++i) (*this)[i] = v[i]; } @@ -106,7 +107,7 @@ void MercuryVertex::Print() const { - printf("%f %f %f\n", (*this)[0], (*this)[1], (*this)[2]); + printf("Vertex: %f %f %f %f\n", (*this)[0], (*this)[1], (*this)[2], (*this)[3]); } Modified: Mercury2/src/MercuryVertex.h =================================================================== --- Mercury2/src/MercuryVertex.h 2009-05-16 03:13:09 UTC (rev 254) +++ Mercury2/src/MercuryVertex.h 2009-05-16 03:46:27 UTC (rev 255) @@ -13,8 +13,8 @@ { public: MercuryVertex(); - MercuryVertex( float ix, float iy, float iz ); - MercuryVertex( const float * in ); + MercuryVertex( float ix, float iy, float iz, float iw = 0 ); +// MercuryVertex( const float * in ); MercuryVertex( const MercuryVertex& v); ///Direct conversion to float* Modified: Mercury2/src/Viewport.cpp =================================================================== --- Mercury2/src/Viewport.cpp 2009-05-16 03:13:09 UTC (rev 254) +++ Mercury2/src/Viewport.cpp 2009-05-16 03:46:27 UTC (rev 255) @@ -30,13 +30,12 @@ glMatrixMode(GL_MODELVIEW); VIEWMATRIX = matrix; - EYE[0] = matrix[0][3]; - EYE[1] = matrix[1][3]; - EYE[2] = matrix[2][3]; + EYE[0] = matrix[0][3]; // same as float* [3] + EYE[1] = matrix[1][3]; // same as float* [7] + EYE[2] = matrix[2][3]; // same as float* [11] EYE *= -1; - MercuryVector l(0,0,1); -// l += EYE; + MercuryVector l(0,0,1,1); LOOKAT = (matrix * l).Normalize(); // LOOKAT.Print(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-05-17 12:44:04
|
Revision: 260 http://hgengine.svn.sourceforge.net/hgengine/?rev=260&view=rev Author: axlecrusher Date: 2009-05-17 12:43:56 +0000 (Sun, 17 May 2009) Log Message: ----------- Add camera node Added Paths: ----------- Mercury2/src/Camera.cpp Mercury2/src/Camera.h Added: Mercury2/src/Camera.cpp =================================================================== --- Mercury2/src/Camera.cpp (rev 0) +++ Mercury2/src/Camera.cpp 2009-05-17 12:43:56 UTC (rev 260) @@ -0,0 +1,47 @@ +#include <Camera.h> + +REGISTER_NODE_TYPE(CameraNode); + +void CameraNode::ComputeMatrix() +{ + m_tainted = false; + + MercuryMatrix local; + + local.RotateXYZ( m_rotation*-1 ); + local.Translate( m_position*-1 ); + + m_globalMatrix = GetParentMatrix() * local; +} + +/**************************************************************************** + * 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/Camera.h =================================================================== --- Mercury2/src/Camera.h (rev 0) +++ Mercury2/src/Camera.h 2009-05-17 12:43:56 UTC (rev 260) @@ -0,0 +1,47 @@ +#ifndef CAMERA_H +#define CAMERA_H + +#include <TransformNode.h> + +class CameraNode : public TransformNode +{ + public: + virtual void ComputeMatrix(); + GENRTTI(CameraNode); + + +}; + +#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-05-17 12:44:45
|
Revision: 261 http://hgengine.svn.sourceforge.net/hgengine/?rev=261&view=rev Author: axlecrusher Date: 2009-05-17 12:44:42 +0000 (Sun, 17 May 2009) Log Message: ----------- revert back to what it was Modified Paths: -------------- Mercury2/src/MercuryVertex.cpp Mercury2/src/MercuryVertex.h Modified: Mercury2/src/MercuryVertex.cpp =================================================================== --- Mercury2/src/MercuryVertex.cpp 2009-05-17 12:43:56 UTC (rev 260) +++ Mercury2/src/MercuryVertex.cpp 2009-05-17 12:44:42 UTC (rev 261) @@ -14,13 +14,13 @@ (*this)[2] = iz; (*this)[3] = iw; } -/* + MercuryVertex::MercuryVertex( const float * in ) { - for (unsigned int i = 0; i < 4; ++i) + for (unsigned int i = 0; i < 3; ++i) (*this)[i] = in[i]; } -*/ + MercuryVertex::MercuryVertex( const MercuryVertex& v) { for (unsigned int i = 0; i < 4; ++i) Modified: Mercury2/src/MercuryVertex.h =================================================================== --- Mercury2/src/MercuryVertex.h 2009-05-17 12:43:56 UTC (rev 260) +++ Mercury2/src/MercuryVertex.h 2009-05-17 12:44:42 UTC (rev 261) @@ -14,7 +14,7 @@ public: MercuryVertex(); MercuryVertex( float ix, float iy, float iz, float iw = 0 ); -// MercuryVertex( const float * in ); + MercuryVertex( const float * in ); MercuryVertex( const MercuryVertex& v); ///Direct conversion to float* This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-05-17 12:46:50
|
Revision: 262 http://hgengine.svn.sourceforge.net/hgengine/?rev=262&view=rev Author: axlecrusher Date: 2009-05-17 12:46:42 +0000 (Sun, 17 May 2009) Log Message: ----------- Use MercuryVertex not MercuryPoint Modified Paths: -------------- Mercury2/src/TransformNode.cpp Mercury2/src/TransformNode.h Modified: Mercury2/src/TransformNode.cpp =================================================================== --- Mercury2/src/TransformNode.cpp 2009-05-17 12:44:42 UTC (rev 261) +++ Mercury2/src/TransformNode.cpp 2009-05-17 12:46:42 UTC (rev 262) @@ -4,7 +4,7 @@ REGISTER_NODE_TYPE(RotatorNode); TransformNode::TransformNode() - :m_scale( MercuryPoint(1,1,1) ) + :m_scale( MercuryVertex(1,1,1) ) { SetTaint( true ); //taint because of the scale set above } @@ -14,7 +14,7 @@ if (m_tainted) ComputeMatrix(); } -void TransformNode::SetScale( const MercuryPoint& scale ) +void TransformNode::SetScale( const MercuryVertex& scale ) { if (scale != m_scale) { @@ -23,7 +23,7 @@ } } -void TransformNode::SetPosition( const MercuryPoint& position ) +void TransformNode::SetPosition( const MercuryVertex& position ) { if (position != m_position) { @@ -32,7 +32,7 @@ } } -void TransformNode::SetRotation( const MercuryPoint& rotation ) +void TransformNode::SetRotation( const MercuryVertex& rotation ) { if (rotation != m_rotation) { @@ -54,9 +54,9 @@ MercuryMatrix local; // local.Identity(); - local.Transotale( m_position.x, m_position.y, m_position.z, - m_rotation.x, m_rotation.y, m_rotation.z, - m_scale.x, m_scale.y, m_scale.z ); + local.Transotale( m_position[0], m_position[1], m_position[2], + m_rotation[0], m_rotation[1], m_rotation[2], + m_scale[0], m_scale[1], m_scale[2] ); m_globalMatrix = GetParentMatrix() * local; } @@ -94,7 +94,7 @@ void TransformNode::LoadFromXML(const XMLNode& node) { - MercuryPoint rot(m_rotation), pos(m_position), scale(m_scale); + MercuryVertex rot(m_rotation), pos(m_position), scale(m_scale); //only change the values that exist in the XML if ( !node.Attribute("rotx").empty() ) @@ -150,9 +150,9 @@ void RotatorNode::Update(float dTime) { - MercuryPoint r = GetRotation(); - r.x += (dTime)*25; - r.y += (dTime)*75; + float* r = m_rotation; + r[0] += (dTime)*25; + r[1] += (dTime)*75; SetRotation( r ); Modified: Mercury2/src/TransformNode.h =================================================================== --- Mercury2/src/TransformNode.h 2009-05-17 12:44:42 UTC (rev 261) +++ Mercury2/src/TransformNode.h 2009-05-17 12:46:42 UTC (rev 262) @@ -2,7 +2,7 @@ #define TRANSFORMNODE_H #include <MercuryNode.h> -#include <MercuryPoint.h> +#include <MercuryVertex.h> #include <MercuryMatrix.h> //I am not sure if I like the idea of rippling a taint flag down the tree @@ -14,13 +14,13 @@ virtual void Update(float dTime); - void SetScale( const MercuryPoint& scale ); - void SetPosition( const MercuryPoint& position ); - void SetRotation( const MercuryPoint& rotation ); + void SetScale( const MercuryVertex& scale ); + void SetPosition( const MercuryVertex& position ); + void SetRotation( const MercuryVertex& rotation ); - inline const MercuryPoint& GetScale() const { return m_scale; } - inline const MercuryPoint& GetPosition() const { return m_position; } - inline const MercuryPoint& GetRotation() const { return m_rotation; } + inline const MercuryVertex& GetScale() const { return m_scale; } + inline const MercuryVertex& GetPosition() const { return m_position; } + inline const MercuryVertex& GetRotation() const { return m_rotation; } inline const MercuryMatrix& GetGlobalMatrix() const { return m_globalMatrix; } const MercuryMatrix& GetParentMatrix() const; @@ -38,12 +38,12 @@ private: void RippleTaintDown(); - MercuryPoint m_scale; - MercuryPoint m_position; - MercuryPoint m_rotation; - // MercuryMatrix m_localMatrix; protected: + MercuryVertex m_scale; + MercuryVertex m_position; + MercuryVertex m_rotation; + MercuryMatrix m_globalMatrix; bool m_tainted; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-05-17 12:59:56
|
Revision: 266 http://hgengine.svn.sourceforge.net/hgengine/?rev=266&view=rev Author: axlecrusher Date: 2009-05-17 12:59:54 +0000 (Sun, 17 May 2009) Log Message: ----------- debugging Modified Paths: -------------- Mercury2/src/MercuryVertex.cpp Mercury2/src/MercuryVertex.h Mercury2/src/Viewport.cpp Modified: Mercury2/src/MercuryVertex.cpp =================================================================== --- Mercury2/src/MercuryVertex.cpp 2009-05-17 12:48:57 UTC (rev 265) +++ Mercury2/src/MercuryVertex.cpp 2009-05-17 12:59:54 UTC (rev 266) @@ -105,9 +105,9 @@ return dp; } -void MercuryVertex::Print() const +void MercuryVertex::Print(const MString& s) const { - printf("Vertex: %f %f %f %f\n", (*this)[0], (*this)[1], (*this)[2], (*this)[3]); + printf("%s: %f %f %f %f\n", s.c_str(), (*this)[0], (*this)[1], (*this)[2], (*this)[3]); } Modified: Mercury2/src/MercuryVertex.h =================================================================== --- Mercury2/src/MercuryVertex.h 2009-05-17 12:48:57 UTC (rev 265) +++ Mercury2/src/MercuryVertex.h 2009-05-17 12:59:54 UTC (rev 266) @@ -2,6 +2,7 @@ #define MERCURYVECTOR_H #include <MercuryMath.h> +#include <MercuryString.h> #ifndef WIN32 #define __inline__ __inline__ __attribute__((always_inline)) @@ -77,7 +78,7 @@ float DotProduct(const MercuryVertex& rhs) const; MercuryVertex DotProduct3(const MercuryVertex& rhs1, const MercuryVertex& rhs2, const MercuryVertex& rhs3) const; - void Print() const; + void Print(const MString& s = "Vertex") const; // float (*this)[3]; FloatRow m_xyzw; Modified: Mercury2/src/Viewport.cpp =================================================================== --- Mercury2/src/Viewport.cpp 2009-05-17 12:48:57 UTC (rev 265) +++ Mercury2/src/Viewport.cpp 2009-05-17 12:59:54 UTC (rev 266) @@ -32,18 +32,20 @@ //compute the position of the eye EYE = MercuryVertex(0,0,0,1); EYE = matrix * EYE; - EYE *= -1; - -// VIEWMATRIX = MercuryMatrix::Identity(); -// VIEWMATRIX.Scale(1,1,1); -// VIEWMATRIX.Translate( EYE[0], EYE[1], EYE[2] ); -// VIEWMATRIX.RotateXYZ( matrix[0][0], matrix[1][1], matrix[2][2] ); + VIEWMATRIX = matrix; + + MercuryVector z(0,0,1); + LOOKAT = (matrix * z).Normalize(); + // matrix.Print(); + EYE.Print("Eye"); + LOOKAT.Print("Lookat"); + printf("******\n"); +// LOOKAT = (matrix * l).Normalize(); +// LOOKAT. +// LOOKAT.Print(); - MercuryVector l(0,0,1); - LOOKAT = (matrix * l).Normalize(); - //Sets up the clipping frustum m_frustum.LookAt(EYE, LOOKAT, MercuryVertex(0,1,0)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-05-17 19:16:45
|
Revision: 267 http://hgengine.svn.sourceforge.net/hgengine/?rev=267&view=rev Author: axlecrusher Date: 2009-05-17 19:16:37 +0000 (Sun, 17 May 2009) Log Message: ----------- Input system via messages. Camera movable by mouse Modified Paths: -------------- Mercury2/src/Camera.cpp Mercury2/src/Camera.h Mercury2/src/MercuryMessageManager.cpp Mercury2/src/MercuryMessageManager.h Mercury2/src/MessageHandler.h Mercury2/src/Viewport.cpp Mercury2/src/X11Window.cpp Added Paths: ----------- Mercury2/src/MercuryInput.cpp Mercury2/src/MercuryInput.h Modified: Mercury2/src/Camera.cpp =================================================================== --- Mercury2/src/Camera.cpp 2009-05-17 12:59:54 UTC (rev 266) +++ Mercury2/src/Camera.cpp 2009-05-17 19:16:37 UTC (rev 267) @@ -1,7 +1,15 @@ #include <Camera.h> +#include <MercuryMessageManager.h> +#include <MercuryInput.h> REGISTER_NODE_TYPE(CameraNode); +CameraNode::CameraNode() + :TransformNode() +{ + REGISTER_FOR_MESSAGE( INPUTEVENT_MOUSE ); +} + void CameraNode::ComputeMatrix() { m_tainted = false; @@ -14,6 +22,20 @@ m_globalMatrix = GetParentMatrix() * local; } +void CameraNode::HandleMessage(const MString& message, const MessageData* data) +{ + if (message == INPUTEVENT_MOUSE) + { + MouseInput* m = (MouseInput*)data; + + MercuryVector r = m_rotation; + r[0] += m->dy/30.0f; + r[1] += m->dx/30.0f; + + SetRotation(r); + } +} + /**************************************************************************** * Copyright (C) 2009 by Joshua Allen * * * Modified: Mercury2/src/Camera.h =================================================================== --- Mercury2/src/Camera.h 2009-05-17 12:59:54 UTC (rev 266) +++ Mercury2/src/Camera.h 2009-05-17 19:16:37 UTC (rev 267) @@ -6,10 +6,12 @@ class CameraNode : public TransformNode { public: + CameraNode(); virtual void ComputeMatrix(); + virtual void HandleMessage(const MString& message, const MessageData* data); + GENRTTI(CameraNode); - - + private: }; #endif Added: Mercury2/src/MercuryInput.cpp =================================================================== --- Mercury2/src/MercuryInput.cpp (rev 0) +++ Mercury2/src/MercuryInput.cpp 2009-05-17 19:16:37 UTC (rev 267) @@ -0,0 +1,48 @@ +#include <MercuryInput.h> +#include <MercuryMessageManager.h> + +MouseInput::MouseInput() + :MessageData(), dx(0), dy(0), buttonMasks(0) +{ +} + +void MouseInput::ProcessMouseInput(int dx, int dy) +{ + MouseInput* mi = new MouseInput(); + mi->dx = dx; + mi->dy = dy; + + POST_MESSAGE( INPUTEVENT_MOUSE, mi, 0 ); +} + +/**************************************************************************** + * 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/MercuryInput.h =================================================================== --- Mercury2/src/MercuryInput.h (rev 0) +++ Mercury2/src/MercuryInput.h 2009-05-17 19:16:37 UTC (rev 267) @@ -0,0 +1,54 @@ +#ifndef MERCURYINPUT_H +#define MERCURYINPUT_H + +#include <MessageHandler.h> + +const MString INPUTEVENT_MOUSE = "MouseInputEvent"; + +class MouseInput : public MessageData +{ + public: + static const uint8_t LEFTBUTTON = 1; + static const uint8_t RIGHTBUTTON = 2; + static const uint8_t CENTERBUTTON = 4; + + static void ProcessMouseInput(int x, int y); + + MouseInput(); + int32_t dx, dy; + uint8_t buttonMasks; +}; + +#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. * + ***************************************************************************/ Modified: Mercury2/src/MercuryMessageManager.cpp =================================================================== --- Mercury2/src/MercuryMessageManager.cpp 2009-05-17 12:59:54 UTC (rev 266) +++ Mercury2/src/MercuryMessageManager.cpp 2009-05-17 19:16:37 UTC (rev 267) @@ -1,9 +1,17 @@ #include <MercuryMessageManager.h> -void MercuryMessageManager::PostMessage(const MString& message, float delay) +MessageHolder::MessageHolder() + :data(NULL) { +} + +void MercuryMessageManager::PostMessage(const MString& message, MessageData* data, float delay) +{ + MessageHolder m; + m.message = message; + m.data = data; uint64_t fireTime = m_currTime + uint64_t(delay*1000000); - m_messageQueue.Insert(fireTime, message); + m_messageQueue.Insert(fireTime, m); } void MercuryMessageManager::PumpMessages(const uint64_t& currTime) @@ -13,8 +21,9 @@ { if ( m_messageQueue.PeekNextPriority() > m_currTime ) return; - MString& message = m_messageQueue.GetNext(); + MessageHolder& message = m_messageQueue.GetNext(); FireOffMessage( message ); + SAFE_DELETE( message.data ); m_messageQueue.PopNext(); } } @@ -24,15 +33,17 @@ m_messageRecipients[message].push_back(ptr); } -void MercuryMessageManager::FireOffMessage(const MString& message) +void MercuryMessageManager::FireOffMessage(const MessageHolder& message) { - std::map< MString, std::list< MessageHandler* > >::iterator i = m_messageRecipients.find(message); + std::map< MString, std::list< MessageHandler* > >::iterator i = m_messageRecipients.find(message.message); + if ( i != m_messageRecipients.end() ) + { + std::list< MessageHandler* >::iterator recipients = i->second.begin(); - std::list< MessageHandler* >::iterator recipients = i->second.begin(); - - for (; recipients != i->second.end(); ++recipients) - (*recipients)->HandleMessage(message); + for (; recipients != i->second.end(); ++recipients) + (*recipients)->HandleMessage(message.message, message.data); + } } MercuryMessageManager& MercuryMessageManager::GetInstance() Modified: Mercury2/src/MercuryMessageManager.h =================================================================== --- Mercury2/src/MercuryMessageManager.h 2009-05-17 12:59:54 UTC (rev 266) +++ Mercury2/src/MercuryMessageManager.h 2009-05-17 19:16:37 UTC (rev 267) @@ -9,6 +9,14 @@ #include <MercuryUtil.h> #include <Mint.h> +class MessageHolder +{ + public: + MessageHolder(); + MString message; + MessageData* data; +}; + /* This message system uses absolute integer time values to fire off events. This ensures accuarate firing times while eliminating floating point error. Because we use absolute times in the queue we do not need to "count down" the @@ -17,15 +25,15 @@ class MercuryMessageManager { public: - void PostMessage(const MString& message, float delay); + void PostMessage(const MString& message, MessageData* data, float delay); void PumpMessages(const uint64_t& currTime); void RegisterForMessage(const MString& message, MessageHandler* ptr); static MercuryMessageManager& GetInstance(); private: - void FireOffMessage(const MString& message); + void FireOffMessage(const MessageHolder& message); - PriorityQueue<uint64_t, MString> m_messageQueue; + PriorityQueue<uint64_t, MessageHolder> m_messageQueue; uint64_t m_currTime; //microseconds std::map< MString, std::list< MessageHandler* > > m_messageRecipients; @@ -34,8 +42,8 @@ static InstanceCounter<MercuryMessageManager> MMcounter("MessageManager"); #define MESSAGEMAN MercuryMessageManager -#define REGISTER_FOR_MESSAGE(x) MESSAGEMAN::GetInstance().RegisterForMessage(#x, this) -#define POST_MESSAGE(x,delay) MESSAGEMAN::GetInstance().PostMessage(#x, delay) +#define REGISTER_FOR_MESSAGE(x) MESSAGEMAN::GetInstance().RegisterForMessage(x, this) +#define POST_MESSAGE(x,data,delay) MESSAGEMAN::GetInstance().PostMessage(x, data, delay) #endif Modified: Mercury2/src/MessageHandler.h =================================================================== --- Mercury2/src/MessageHandler.h 2009-05-17 12:59:54 UTC (rev 266) +++ Mercury2/src/MessageHandler.h 2009-05-17 19:16:37 UTC (rev 267) @@ -4,11 +4,17 @@ #include <MercuryString.h> #include <global.h> +class MessageData +{ + public: + virtual ~MessageData() {}; +}; + class MessageHandler { public: virtual ~MessageHandler() {}; - virtual void HandleMessage(const MString& message) {}; + virtual void HandleMessage(const MString& message, const MessageData* data) {}; }; #endif Modified: Mercury2/src/Viewport.cpp =================================================================== --- Mercury2/src/Viewport.cpp 2009-05-17 12:59:54 UTC (rev 266) +++ Mercury2/src/Viewport.cpp 2009-05-17 19:16:37 UTC (rev 267) @@ -39,9 +39,9 @@ LOOKAT = (matrix * z).Normalize(); // matrix.Print(); - EYE.Print("Eye"); - LOOKAT.Print("Lookat"); - printf("******\n"); +// EYE.Print("Eye"); +// LOOKAT.Print("Lookat"); +// printf("******\n"); // LOOKAT = (matrix * l).Normalize(); // LOOKAT. // LOOKAT.Print(); Modified: Mercury2/src/X11Window.cpp =================================================================== --- Mercury2/src/X11Window.cpp 2009-05-17 12:59:54 UTC (rev 266) +++ Mercury2/src/X11Window.cpp 2009-05-17 19:16:37 UTC (rev 267) @@ -1,4 +1,6 @@ #include <X11Window.h> +#include <MercuryMessageManager.h> +#include <MercuryInput.h> Callback0R< MercuryWindow* > MercuryWindow::genWindowClbk(X11Window::GenX11Window); //Register window generation callback @@ -34,7 +36,7 @@ attr.background_pixel = 0; attr.border_pixel = 0; attr.colormap = XCreateColormap( m_display, root_window, visinfo->visual, AllocNone); - attr.event_mask = StructureNotifyMask | SubstructureNotifyMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | ButtonPressMask | PointerMotionMask | ButtonMotionMask | EnterWindowMask | LeaveWindowMask |KeyPressMask |KeyReleaseMask | SubstructureNotifyMask; + attr.event_mask = StructureNotifyMask | SubstructureNotifyMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | ButtonPressMask | PointerMotionMask | ButtonMotionMask | EnterWindowMask | LeaveWindowMask |KeyPressMask |KeyReleaseMask | SubstructureNotifyMask | FocusChangeMask; unsigned long mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask; @@ -97,10 +99,12 @@ bool X11Window::PumpMessages() { + static bool inFocus = false; XEvent event; while ( XPending(m_display) > 0) { XNextEvent(m_display, &event); + switch (event.type) { case ClientMessage: @@ -115,6 +119,27 @@ if (e->window == m_window) return false; break; } + case ConfigureNotify: + { + XConfigureEvent* e = (XConfigureEvent*)&event; + m_width = e->width; + m_height = e->height; + break; + } + case FocusIn: + case FocusOut: + { + XFocusChangeEvent*e = (XFocusChangeEvent*)&event; + inFocus = (event.type == FocusIn); + if (inFocus) XWarpPointer(m_display, None, m_window, 0,0,0,0,m_width/2,m_height/2); + break; + } + } + + //The events below only get processed if window is in focus + if ( !inFocus ) continue; + switch (event.type) + { case ButtonPress: { XButtonEvent* e = (XButtonEvent*)&event; @@ -128,7 +153,8 @@ case KeyPress: { XKeyEvent* e = (XKeyEvent*)&event; - e->keycode; +// unsigned int* keycode = new unsigned int( e->keycode ); +// POST_MESSAGE( "KeyPress", (void*)keycode, 0 ); break; } case KeyRelease: @@ -140,15 +166,16 @@ case MotionNotify: { XMotionEvent* e = (XMotionEvent*)&event; + int x, y; + x = m_width/2 - e->x; + y = m_height/2 - e->y; + if (x!=0 || y!=0) //prevent recursive XWarp + { + MouseInput::ProcessMouseInput(x, y); + XWarpPointer(m_display, None, m_window, 0,0,0,0,m_width/2,m_height/2); + } break; } - case ConfigureNotify: - { - XConfigureEvent* e = (XConfigureEvent*)&event; - m_width = e->width; - m_height = e->height; - break; - } default: break; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-05-17 21:14:20
|
Revision: 268 http://hgengine.svn.sourceforge.net/hgengine/?rev=268&view=rev Author: axlecrusher Date: 2009-05-17 21:14:12 +0000 (Sun, 17 May 2009) Log Message: ----------- Add keyboard input. Move camera around with keyboard input Modified Paths: -------------- Mercury2/src/Camera.cpp Mercury2/src/Camera.h Mercury2/src/MercuryInput.cpp Mercury2/src/MercuryInput.h Mercury2/src/X11Window.cpp Mercury2/src/X11Window.h Modified: Mercury2/src/Camera.cpp =================================================================== --- Mercury2/src/Camera.cpp 2009-05-17 19:16:37 UTC (rev 267) +++ Mercury2/src/Camera.cpp 2009-05-17 21:14:12 UTC (rev 268) @@ -36,6 +36,20 @@ } } +void CameraNode::Update(float dTime) +{ + MercuryVector p = GetPosition(); + + if ( KeyboardInput::IsKeyDown(25) ) p[2] -= dTime*2; + if ( KeyboardInput::IsKeyDown(38) ) p[0] -= dTime*2; + if ( KeyboardInput::IsKeyDown(39) ) p[2] += dTime*2; + if ( KeyboardInput::IsKeyDown(40) ) p[0] += dTime*2; + + SetPosition( p ); + + TransformNode::Update( dTime ); +} + /**************************************************************************** * Copyright (C) 2009 by Joshua Allen * * * Modified: Mercury2/src/Camera.h =================================================================== --- Mercury2/src/Camera.h 2009-05-17 19:16:37 UTC (rev 267) +++ Mercury2/src/Camera.h 2009-05-17 21:14:12 UTC (rev 268) @@ -9,6 +9,7 @@ CameraNode(); virtual void ComputeMatrix(); virtual void HandleMessage(const MString& message, const MessageData* data); + virtual void Update(float dTime); GENRTTI(CameraNode); private: Modified: Mercury2/src/MercuryInput.cpp =================================================================== --- Mercury2/src/MercuryInput.cpp 2009-05-17 19:16:37 UTC (rev 267) +++ Mercury2/src/MercuryInput.cpp 2009-05-17 21:14:12 UTC (rev 268) @@ -15,6 +15,46 @@ POST_MESSAGE( INPUTEVENT_MOUSE, mi, 0 ); } +KeyboardInput::KeyboardInput() + :key(0), isDown(false) +{ + //init initial keymap + if (m_keyStates[0] < 1) + { + m_keyStates[0] = 1; + for (uint16_t i = 1; i < 512; ++i) + m_keyStates[i] = 0; + } +} + +void KeyboardInput::ProcessKeyInput(uint16_t key, bool isDown) +{ + KeyboardInput* ki = new KeyboardInput(); + ki->isDown = isDown; + ki->key = key; + + if (isDown) + { + m_keyStates[key] |= (1 << 1); + printf("press %d\n", key); + } + else + { + m_keyStates[key] &= ~(1 << 1); + printf("release %d\n", key); + } + + POST_MESSAGE( INPUTEVENT_KEYBOARD, ki, 0 ); +} + +bool KeyboardInput::IsKeyDown(uint16_t key) +{ + return (m_keyStates[key] & (1 << 1)) > 0; +} + +uint8_t KeyboardInput::m_keyStates[512]; + + /**************************************************************************** * Copyright (C) 2009 by Joshua Allen * * * Modified: Mercury2/src/MercuryInput.h =================================================================== --- Mercury2/src/MercuryInput.h 2009-05-17 19:16:37 UTC (rev 267) +++ Mercury2/src/MercuryInput.h 2009-05-17 21:14:12 UTC (rev 268) @@ -4,6 +4,7 @@ #include <MessageHandler.h> const MString INPUTEVENT_MOUSE = "MouseInputEvent"; +const MString INPUTEVENT_KEYBOARD = "KeyboardInputEvent"; class MouseInput : public MessageData { @@ -19,6 +20,20 @@ uint8_t buttonMasks; }; +class KeyboardInput : public MessageData +{ + public: + static void ProcessKeyInput(uint16_t key, bool isDown); + static bool IsKeyDown(uint16_t key); + + KeyboardInput(); + + int16_t key; + bool isDown; + private: + static uint8_t m_keyStates[512]; +}; + #endif /**************************************************************************** Modified: Mercury2/src/X11Window.cpp =================================================================== --- Mercury2/src/X11Window.cpp 2009-05-17 19:16:37 UTC (rev 267) +++ Mercury2/src/X11Window.cpp 2009-05-17 21:14:12 UTC (rev 268) @@ -110,7 +110,9 @@ case ClientMessage: { if ( unsigned(event.xclient.data.l[0]) == m_wmDeleteMessage ) + { XDestroyWindow(m_display,m_window); + } break; } case DestroyNotify: @@ -152,15 +154,18 @@ } case KeyPress: { - XKeyEvent* e = (XKeyEvent*)&event; -// unsigned int* keycode = new unsigned int( e->keycode ); -// POST_MESSAGE( "KeyPress", (void*)keycode, 0 ); + //ignore autorepeat +// if ( IsKeyRepeat(&event.xkey) ) break; + + KeyboardInput::ProcessKeyInput(event.xkey.keycode, true); break; } case KeyRelease: { - XKeyEvent* e = (XKeyEvent*)&event; - e->keycode; + //ignore autorepeat +// if ( IsKeyRepeat(&event.xkey) ) break; + + KeyboardInput::ProcessKeyInput(event.xkey.keycode, false); break; } case MotionNotify: @@ -183,6 +188,25 @@ return true; } +bool X11Window::IsKeyRepeat(XKeyEvent* e) +{ + XEvent nEvent; + + if ( XPending(m_display) > 0 ) + { + XPeekEvent(m_display, &nEvent); + if ( (nEvent.type == KeyRelease || nEvent.type == KeyPress) && + nEvent.xkey.keycode == e->keycode && + nEvent.xkey.time == e->time) + { + XNextEvent(m_display, &nEvent); //forget next event + return true; + } + } + + return false; +} + void X11Window::Clear() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); Modified: Mercury2/src/X11Window.h =================================================================== --- Mercury2/src/X11Window.h 2009-05-17 19:16:37 UTC (rev 267) +++ Mercury2/src/X11Window.h 2009-05-17 21:14:12 UTC (rev 268) @@ -22,6 +22,8 @@ virtual void Clear(); private: + bool IsKeyRepeat(XKeyEvent* e); + Display* m_display; GLXContext m_renderCtx; Window m_window; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <axl...@us...> - 2009-05-17 21:38:06
|
Revision: 269 http://hgengine.svn.sourceforge.net/hgengine/?rev=269&view=rev Author: axlecrusher Date: 2009-05-17 21:37:58 +0000 (Sun, 17 May 2009) Log Message: ----------- add in key repeat Modified Paths: -------------- Mercury2/src/MercuryInput.cpp Mercury2/src/MercuryInput.h Mercury2/src/X11Window.cpp Modified: Mercury2/src/MercuryInput.cpp =================================================================== --- Mercury2/src/MercuryInput.cpp 2009-05-17 21:14:12 UTC (rev 268) +++ Mercury2/src/MercuryInput.cpp 2009-05-17 21:37:58 UTC (rev 269) @@ -27,23 +27,21 @@ } } -void KeyboardInput::ProcessKeyInput(uint16_t key, bool isDown) +void KeyboardInput::ProcessKeyInput(uint16_t key, bool isDown, bool repeat) { KeyboardInput* ki = new KeyboardInput(); ki->isDown = isDown; ki->key = key; + ki->isRepeat = repeat; + + //if statements are for old people, bruit force it - if (isDown) - { - m_keyStates[key] |= (1 << 1); - printf("press %d\n", key); - } - else - { - m_keyStates[key] &= ~(1 << 1); - printf("release %d\n", key); - } + m_keyStates[key] &= ~(1 << 1); //disable + m_keyStates[key] |= (isDown << 1); //enable if true + m_keyStates[key] &= ~(1 << 2); //disable + m_keyStates[key] |= (repeat << 2); //enable if true + POST_MESSAGE( INPUTEVENT_KEYBOARD, ki, 0 ); } @@ -52,6 +50,12 @@ return (m_keyStates[key] & (1 << 1)) > 0; } +bool KeyboardInput::IsKeyRepeat(uint16_t key) +{ + return (m_keyStates[key] & (1 << 2)) > 0; +} + + uint8_t KeyboardInput::m_keyStates[512]; Modified: Mercury2/src/MercuryInput.h =================================================================== --- Mercury2/src/MercuryInput.h 2009-05-17 21:14:12 UTC (rev 268) +++ Mercury2/src/MercuryInput.h 2009-05-17 21:37:58 UTC (rev 269) @@ -23,13 +23,15 @@ class KeyboardInput : public MessageData { public: - static void ProcessKeyInput(uint16_t key, bool isDown); + static void ProcessKeyInput(uint16_t key, bool isDown, bool repeat); static bool IsKeyDown(uint16_t key); + static bool IsKeyRepeat(uint16_t key); KeyboardInput(); int16_t key; bool isDown; + bool isRepeat; private: static uint8_t m_keyStates[512]; }; Modified: Mercury2/src/X11Window.cpp =================================================================== --- Mercury2/src/X11Window.cpp 2009-05-17 21:14:12 UTC (rev 268) +++ Mercury2/src/X11Window.cpp 2009-05-17 21:37:58 UTC (rev 269) @@ -155,17 +155,17 @@ case KeyPress: { //ignore autorepeat -// if ( IsKeyRepeat(&event.xkey) ) break; + if ( IsKeyRepeat(&event.xkey) ) break; - KeyboardInput::ProcessKeyInput(event.xkey.keycode, true); + KeyboardInput::ProcessKeyInput(event.xkey.keycode, true, false); break; } case KeyRelease: { //ignore autorepeat -// if ( IsKeyRepeat(&event.xkey) ) break; + if ( IsKeyRepeat(&event.xkey) ) break; - KeyboardInput::ProcessKeyInput(event.xkey.keycode, false); + KeyboardInput::ProcessKeyInput(event.xkey.keycode, false, false); break; } case MotionNotify: @@ -200,6 +200,7 @@ nEvent.xkey.time == e->time) { XNextEvent(m_display, &nEvent); //forget next event + KeyboardInput::ProcessKeyInput(e->keycode, true, true); //set repeat flag return true; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |