/* ========================================================================== * ÀÛ ¼º ÀÚ : À̼ø±Ô * ÀÛ ¼º ÀÏ : 2006.12.15 * ³» ¿ë : Àå¸é °ü¸®ÀÚ * ÁÖÀÇ»çÇ× : *===========================================================================*/ #pragma once #include "SceneTree.h" #include "VisibleArray.h" #include "VisibleArraySorter.h" class cRay; class cCamera; class cTerrain; class cAreaGroup; class cAreaSceneNode; class cAreaSceneNodeParam; class cLightSceneNode; class cLightSceneNodeParam; #ifdef MAP_EDITOR class cSoundSceneNode; #endif class cSoundSceneNodeParam; class cStaticSceneNode; class cStaticSceneNodeParam; class cDynamicSceneNode; class cNpcSceneNode; class cNpcSceneNodeParam; class cMonsterSceneNode; class cMonsterSceneNodeParam; class cPortalSceneNode; class cPortalSceneNodeParam; class cGatheringSceneNode; class cGatheringSceneNodeParam; class cPatternSceneNode; class cPatternSceneNodeParam; class cDoorSceneNode; class cDoorSceneNodeParam; class cShadowGeometry; /// Àå¸é ÆÄÀÏ Çì´õ #pragma pack( push, 1 ) class cSceneFileHeader { public: /// ½Äº° ÄÚµå char mCode[10]; /// ¹öÀü unsigned int mVersion; /// Àå¸é Æ®¸® Á¤º¸ NiPoint3 mCenter; float mMinRadius; float mMaxRadius; /// Àå¸é ³ëµå ¼ö unsigned int mNumSceneNodes; }; class cSoundSceneFileHeader { public: /// ½Äº° ÄÚµå char mCode[10]; /// ¹öÀü unsigned int mVersion; /// Àå¸é ³ëµå ¼ö unsigned int mNumSceneNodes; }; #pragma pack( pop ) /// Àå¸é Ä÷¯ class cSceneCuller : public NiMeshCullingProcess { public: cSceneCuller( const cCamera* cam, const NiPoint3& heroPos, bool testing ); #ifdef MAP_EDITOR /// °¡½Ã ·¹º§ unsigned int GetVisibleLevel( const NiPoint3& pos ); #endif public: const cCamera* mCamera; NiPoint3 mHeroPos; bool mPlaying; #ifdef MAP_EDITOR float mSqaredLevelDistance0; float mSqaredLevelDistance1; float mSqaredLevelDistance2; #endif }; class cModifierProcess : public NiMeshCullingProcess { public: cModifierProcess(); virtual ~cModifierProcess(); void Cull( const NiCamera* pcamera, cSceneNode* pnode ); protected: virtual void AppendVirtual( NiRenderObject& /*geom*/ ){} virtual void Process( NiAVObject* pobj ); virtual void Process(const NiCamera* pkCamera, NiAVObject* pkScene, NiVisibleArray* pkVisibleSet); }; /// Àå¸é °ü¸®ÀÚ /// Àå¸é ³ëµå¸¦ »ý¼º, Á¦°ÅÇÏ´Â °ü¸®ÀÚÀÌ´Ù. /// Àå¸éÀ» ·»´õ¸µÇϰí, /// Ãæµ¹ °Ë»ç, °¡½Ã¼º °Ë»ç, Á¤·Ä µîÀÇ ÀÛ¾÷À» ¼öÇàÇÑ´Ù. class cSceneManager { static cSceneManager* mSingleton; friend class cObjectEditor; friend class cLightEditor; public: cSceneManager(); ~cSceneManager(); /// Áö¿ò void Clear(); /// ÃʱâÈ­ bool Init( const cTerrain& terrain, float minRadius = 1000 ); bool Init( const NiPoint3& center, float minRadius, float maxRadius ); bool InitTree( const cTerrain& terrain, float minRadius = 1000 ); bool InitTree( const NiPoint3& center, float minRadius, float maxRadius ); bool IsInited() const; /// ·Îµù #ifdef MAP_EDITOR bool Load( const cString& pathName, tHashSet& objectSet, tHashSet& lightSet, tHashSet& soundSet, tHashSet& areaSet, bool add = false ); bool LoadSound( const cString& pathName, tHashSet& soundSet ); #else bool Load( const cString& pathName, bool add = false ); bool LoadSound( const cString& pathName ); #endif bool LoadEnvVer6( cFileLoader& loader, bool add ); bool LoadEnvVer7( cFileLoader& loader, bool add ); bool LoadEnvVer8( cFileLoader& loader, bool add ); bool LoadEnvVer9( cFileLoader& loader , bool add); bool LoadEnvVer10( cFileLoader& loader, bool add ); bool LoadGlobalAreaVer6( cFileLoader& loader, bool add ); bool LoadGlobalAreaVer7( cFileLoader& loader, bool add ); bool LoadGlobalAreaVer8( cFileLoader& loader, bool add ); bool LoadGlobalAreaVer9( cFileLoader& loader, bool add ); bool LoadGlobalAreaVer10( cFileLoader& loader, bool add ); #ifdef MAP_EDITOR bool LoadVer6( cFileLoader& loader, cSceneFileHeader& header, tHashSet& objectSet, tHashSet& lightSet, tHashSet& soundSet, tHashSet& areaSet ); bool LoadVer7( cFileLoader& loader, cSceneFileHeader& header, tHashSet& objectSet, tHashSet& lightSet, tHashSet& soundSet, tHashSet& areaSet ); bool LoadVer8( cFileLoader& loader, cSceneFileHeader& header, tHashSet& objectSet, tHashSet& lightSet, tHashSet& soundSet, tHashSet& areaSet ); bool LoadVer9( cFileLoader& loader, cSceneFileHeader& header, tHashSet& objectSet, tHashSet& lightSet, tHashSet& soundSet, tHashSet& areaSet ); bool LoadVer10( cFileLoader& loader, cSceneFileHeader& header, tHashSet& objectSet, tHashSet& lightSet, tHashSet& soundSet, tHashSet& areaSet ); bool LoadVer11( cFileLoader& loader, cSceneFileHeader& header, tHashSet& objectSet, tHashSet& lightSet, tHashSet& areaSet ); bool LoadVer12( cFileLoader& loader, cSceneFileHeader& header, tHashSet& objectSet, tHashSet& lightSet, tHashSet& areaSet ); bool LoadAreaGroup( const cString& pathName ); bool LoadObjectTransformScript( const cString& pathName, tHashSet& objectSet ); bool LoadSoundVer11( cFileLoader& loader, cSoundSceneFileHeader& header, tHashSet& soundSet ); #else bool LoadVer6( cFileLoader& loader, cSceneFileHeader& header ); bool LoadVer7( cFileLoader& loader, cSceneFileHeader& header ); bool LoadVer8( cFileLoader& loader, cSceneFileHeader& header ); bool LoadVer9( cFileLoader& loader, cSceneFileHeader& header ); bool LoadVer10( cFileLoader& loader, cSceneFileHeader& header ); bool LoadVer11( cFileLoader& loader, cSceneFileHeader& header ); bool LoadVer12( cFileLoader& loader, cSceneFileHeader& header ); bool LoadSoundVer11( cFileLoader& loader, cSoundSceneFileHeader& header ); #endif /// ó¸® void Process( unsigned long deltaTime, unsigned long accumTime, bool testing ); /// ·»´õ¸µ void Render(); void RenderShadow(); /// ¿ÀºêÁ§Æ® À§Ä¡, Å©±â Á¶Àý void AdjustAllPos( float scale ); void AdjustAllSize( float scale ); /// È­¸é »óÀÇ ÁÂÇ¥¿¡ ´ëÀÀÇÏ´Â Àå¸é ³ëµåµéÀ» ¸®ÅÏ /// »ï°¢Çü ´ÜÀ§·Î °Ë»çÇÑ´Ù. bool Pick( tArray* pickedArray, int mouseX, int mouseY, bool sortByDistance, eSceneNodeType type ); /// Ãæµ¹ÇÏ´Â Àå¸é ³ëµåµéÀ» ¼öÁý bool Pick( tArray* pickedArray, const cRay& ray, float maxDistance, bool sortByDistance, eSceneNodeType type ); bool Pick( tArray* pickedArray, const cSphere& sphere, eSceneNodeType type ); /// ³ëµå¸¦ Á¦°Å void DestroyAll(); bool DestroyNode( cSceneNode* node ); bool DestroyNode( eSceneNodeType type, unsigned int index ); /// ³ëµå¸¦ »ý¼º cAreaSceneNode* CreateArea( const cAreaSceneNodeParam& param ); cLightSceneNode* CreateLight( const cLightSceneNodeParam& param ); cStaticSceneNode* CreateStatic( cStaticSceneNodeParam& param ); cNpcSceneNode* CreateNPC( const cNpcSceneNodeParam& param ); cMonsterSceneNode* CreateMonster( const cMonsterSceneNodeParam& param ); cGatheringSceneNode* CreateGathering( cGatheringSceneNodeParam& param ); cPortalSceneNode* CreatePortal( cPortalSceneNodeParam& param ); cPatternSceneNode* CreatePattern( cPatternSceneNodeParam& param ); cDoorSceneNode* CreateDoor( cDoorSceneNodeParam& param ); #ifdef MAP_EDITOR cSoundSceneNode* CreateSound( const cSoundSceneNodeParam& param ); void SetStaticeObjectWireframe( bool view ) { mStaticObjectWireframe = view; } #endif /// ÁÖº¯±¤ void SetAmbientLightAmbient( unsigned int i, const NiColor& color ); void SetAmbientLightDiffuse( unsigned int i, const NiColor& color ); void SetAmbientLightDimmer( unsigned int i, float dimmer ); NiAmbientLight* GetAmbientLight( unsigned int i ) const; /// ¹æÇⱤ void SetDirLightAmbient( unsigned int i, const NiColor& color ); void SetDirLightDiffuse( unsigned int i, const NiColor& color ); void SetDirLightDimmer( unsigned int i, float dimmer ); void SetDirLightRotate( unsigned int i, float xangle, float yangle, float zangle ); NiDirectionalLight* GetDirLight( unsigned int i ) const; /// ¾È°³ void SetFog( bool enabled, const NiColor& color, float depth ); void SetFogColor( const NiColor& color ); void SetFogDepth( float depth ); NiFogProperty* GetFogProperty() const; /// °¡½Ã ·¹º§ °Å¸® void SetLevelDistance( float dist0, float dist1, float dist2 ); float GetLevelDistance0() const; float GetLevelDistance1() const; float GetLevelDistance2() const; unsigned int CalcVisibleLevel( cStaticSceneNode* n ); /// Àå¸é Æ®¸®ÀÇ Á¤º¸ const NiPoint3& GetCenter() const; float GetMinRadius() const; float GetMaxRadius() const; /// º¸ÀÌ´Â Àå¸é ³ëµå ¼ö unsigned int GetNumVisibleAlphaNodes() const; unsigned int GetNumVisibleSolidNodes() const; /// Àüü ¿µ¿ª ³ëµå cAreaSceneNode* GetGlobalArea(); /// ±×¸²ÀÚ void AddVisibleShadowGeom( cShadowGeometry* geom ); void OnVisibleModifierPocess( cSceneNode* node ); protected: /// ³ëµå¸¦ Ãß°¡ void AddNode( cSceneNode* node ); public: /// ´ÜÀÏü¸¦ ¸®ÅÏ static cSceneManager* GetSingleton(); protected: /// ÃʱâÈ­ ¿©ºÎ bool mInited; /// ÅØ½ºÃ³ ¸Ê typedef tHashMap cTextureMap; cTextureMap mTextureMap; /// Æ®¸® /// °ø°£À» ºÐÇÒÇÏ¿© ³ëµåµéÀ» °èÃþÀûÀ¸·Î °ü¸®ÇÑ´Ù. /// Ãæµ¹ °Ë»ç ¹× ÄøµÀ» È¿À²ÀûÀ¸·Î ¼öÇàÇϱâÀ§ÇØ »ç¿ëÇÑ´Ù. NiPoint3 mCenter; float mMinRadius; float mMaxRadius; cSceneTree mNodeTree; cModifierProcess mModifierProcess; /// ¿µ¿ª ¹è¿­ typedef tArray cAreaArray; cAreaArray mAreaArray; /// Á¶¸í ¹è¿­ typedef tArray cLightArray; cLightArray mLightArray; /// Á¤Àû ³ëµå ¹è¿­ typedef tArray cStaticArray; cStaticArray mStaticArray; #ifdef MAP_EDITOR bool mStaticObjectWireframe; #endif /// µ¿Àû ³ëµå ¹è¿­ typedef tArray cDynamicArray; cDynamicArray mDynamicArray; #ifdef MAP_EDITOR /// »ç¿îµå ¹è¿­ typedef tArray cSoundArray; cSoundArray mSoundArray; #endif /// °¡½Ã ·¹º§ °Å¸® float mLevelDistance0; float mLevelDistance1; float mLevelDistance2; float mSqaredLevelDistance0; float mSqaredLevelDistance1; float mSqaredLevelDistance2; /// ¹ÝÅõ¸í ³ëµå °¡½Ã ¹è¿­ cVisibleArray mAlphaArray; cVisibleArray mAlphaTestArray; /// ºÒÅõ¸í ³ëµå °¡½Ã ¹è¿­ cVisibleArray mSolidArray; /// ¹ÝÅõ¸í ³ëµå °¡½Ã ¹è¿­ Á¤·ÄÀÚ cAlphaArraySorter mAlphaArraySorter; /// ºÒÅõ¸í ³ëµå °¡½Ã ¹è¿­ Á¤·ÄÀÚ cSolidArraySorter mSolidArraySorter; /// ¾È°³ ¼Ó¼º NiFogPropertyPtr mFogProp; /// Á¶¸í NiAmbientLightPtr mAmbientLight[2]; NiDirectionalLightPtr mDirLight[2]; /// ÇÈÅ·µÈ Àå¸é ³ëµå ¹è¿­ typedef tArray cPickedArray; cPickedArray mPickedArray; /// Àüü ¿µ¿ª ³ëµå cAreaSceneNode* mGlobalArea; #ifdef MAP_EDITOR /// ¿µ¿ª ±×·ì typedef tHashMap cAreaGroupMap; cAreaGroupMap mAreaGroupMap; #endif /// ±×¸²ÀÚ °¡½Ã ¹è¿­ typedef tArray cShadowGeomArray; cShadowGeomArray mShadowGeomArray; NiPoint3 mHeroPos; }; inline bool cSceneManager::IsInited() const { return mInited; } inline NiFogProperty* cSceneManager::GetFogProperty() const { return mFogProp; } inline NiAmbientLight* cSceneManager::GetAmbientLight( unsigned int i ) const { return mAmbientLight[i]; } inline NiDirectionalLight* cSceneManager::GetDirLight( unsigned int i ) const { return mDirLight[i]; } inline const NiPoint3& cSceneManager::GetCenter() const { return mCenter; } inline float cSceneManager::GetMinRadius() const { return mMinRadius; } inline float cSceneManager::GetMaxRadius() const { return mMaxRadius; } inline unsigned int cSceneManager::GetNumVisibleAlphaNodes() const { return mAlphaArray.GetCount(); } inline unsigned int cSceneManager::GetNumVisibleSolidNodes() const { return mSolidArray.GetCount(); } inline cAreaSceneNode* cSceneManager::GetGlobalArea() { return mGlobalArea; } inline void cSceneManager::SetLevelDistance( float dist0, float dist1, float dist2 ) { mLevelDistance0 = dist0; mLevelDistance1 = dist1; mLevelDistance2 = dist2; mSqaredLevelDistance0 = mLevelDistance0 * mLevelDistance0;//dist0 * dist0; mSqaredLevelDistance1 = mLevelDistance1 * mLevelDistance1;//dist1 * dist1; mSqaredLevelDistance2 = mLevelDistance2 * mLevelDistance2;//dist2 * dist2; } inline float cSceneManager::GetLevelDistance0() const { return mLevelDistance0; } inline float cSceneManager::GetLevelDistance1() const { return mLevelDistance1; } inline float cSceneManager::GetLevelDistance2() const { return mLevelDistance2; } inline void cSceneManager::AddVisibleShadowGeom( cShadowGeometry* geom ) { assert( geom ); mShadowGeomArray.PushBack( geom ); } inline cSceneManager* cSceneManager::GetSingleton() { return mSingleton; } #define SCENEMAN cSceneManager::GetSingleton()