00001 #include "MercuryDisplay.h" 00002 #include "MercuryParticle.h" 00003 #include "MercuryTextureManager.h" 00004 #include "MercurySprite.h" 00005 #include "MercuryObjectFactory.h" 00006 00007 #define MC_TEXTURELOADED 0 00008 00009 void MercuryParticleField::Init() 00010 { 00011 MercuryObject::Init(); 00012 m_glState.Disable(MGLS_ALL); 00013 m_glState.Enable(MGLS_BLEND | MGLS_DEPTHTEST | MGLS_COLORWRITE | MGLS_OPAQUE); 00014 m_destroyOnEmpty = true; 00015 } 00016 00017 void MercuryParticleField::Message( int Message, PStack & data, const MString & name ) 00018 { 00019 switch ( Message ) 00020 { 00021 case MC_TEXTURELOADED: 00022 { 00023 const MercuryTexture* t = (const MercuryTexture*)data.PeekItem(0).GetValueV(); 00024 const ImageAttrs* imageAttrs = (const ImageAttrs*)data.PeekItem(1).GetValueV(); 00025 const MercuryTexture *tt = m_material.GetTexture(0); 00026 if(tt == t) 00027 { 00028 // SetImageAttrs(*imageAttrs); 00029 m_state = LOADED; 00030 MercuryMessageHandler::UnregisterMessage( MC_TEXTURELOADED, "GetTextureID" ); 00031 MDequeIterator<ParentHoldPair> child = m_objects.begin(); 00032 while (child != m_objects.end()) 00033 ((MercurySprite*)(child++)->pObject)->LoadMaterial(this->m_material); 00034 } 00035 } 00036 break; 00037 } 00038 } 00039 00040 MercuryObject* MercuryParticleField::SpawnParticle() 00041 { 00042 MercurySprite* s = (MercurySprite*)Spawn("MercurySprite", "ParticleSprite"); 00043 if ( m_state == LOADED ) 00044 s->LoadMaterial( m_material ); 00045 return s; 00046 } 00047 00048 void MercuryParticleField::CustomRender() 00049 { 00050 DISPLAY->SendMatrixData(GetFinalMatrix()); 00051 DISPLAY->SetStates( GetInheritedGLState() ); 00052 DISPLAY->EnableShaders(&m_material); 00053 DISPLAY->EnableTextures( &m_material ); 00054 DISPLAY->DrawParticleField(this); 00055 } 00056 00057 void MercuryParticleField::LoadImage(MString path) 00058 { 00059 m_state = UNLOADED; 00060 m_imagePath = path; 00061 //eves drop on texture loading 00062 m_material.ClearTextures(); 00063 m_material.AddTexture(MercuryTextureManager::CreateTexture(path)); 00064 //eves drop on texture loading 00065 MercuryMessageHandler::RegisterMessage( MC_TEXTURELOADED, "GetTextureID" ); 00066 } 00067 00068 void MercuryParticleField::Update( const float dTime ) 00069 { 00070 if (m_objects.empty() && m_destroyOnEmpty) 00071 m_bMarkedForDestroy = true; 00072 00073 MercuryObject::Update( dTime ); 00074 } 00075 00076 00077 REGISTER_OBJECT_TYPE( MercuryParticleField ); 00078 00079 /* 00080 * Copyright (c) 2006 Joshua Allen 00081 * All rights reserved. 00082 * 00083 * Redistribution and use in source and binary forms, with or 00084 * without modification, are permitted provided that the following 00085 * conditions are met: 00086 * - Redistributions of source code must retain the above 00087 * copyright notice, this list of conditions and the following disclaimer. 00088 * - Redistributions in binary form must reproduce the above copyright 00089 * notice, this list of conditions and the following disclaimer in 00090 * the documentation and/or other materials provided with the distribution. 00091 * - Neither the name of the Mercury Engine nor the names of its 00092 * contributors may be used to endorse or promote products derived from 00093 * this software without specific prior written permission. 00094 * 00095 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00096 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00097 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00098 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 00099 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00100 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00101 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00102 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00103 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00104 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00105 */ 00106