sceneLighting.h
Engine/source/lighting/common/sceneLighting.h
Classes:
class
class
Create a proxy for each object to store data.
Public Variables
Detailed Description
Public Variables
SceneLighting * gLighting
1 2//----------------------------------------------------------------------------- 3// Copyright (c) 2012 GarageGames, LLC 4// 5// Permission is hereby granted, free of charge, to any person obtaining a copy 6// of this software and associated documentation files (the "Software"), to 7// deal in the Software without restriction, including without limitation the 8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 9// sell copies of the Software, and to permit persons to whom the Software is 10// furnished to do so, subject to the following conditions: 11// 12// The above copyright notice and this permission notice shall be included in 13// all copies or substantial portions of the Software. 14// 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21// IN THE SOFTWARE. 22//----------------------------------------------------------------------------- 23 24#ifndef _SCENELIGHTING_H_ 25#define _SCENELIGHTING_H_ 26 27#ifndef _SCENEOBJECT_H_ 28#include "scene/sceneObject.h" 29#endif 30#ifndef _SGSCENEPERSIST_H_ 31#include "lighting/common/scenePersist.h" 32#endif 33#ifndef _LIGHTINFO_H_ 34#include "lighting/lightInfo.h" 35#endif 36 37class ShadowVolumeBSP; 38class LightInfo; 39class AvailableSLInterfaces; 40 41class SceneLighting : public SimObject 42{ 43 typedef SimObject Parent; 44protected: 45 AvailableSLInterfaces* mLightingInterfaces; 46 virtual void getMLName(const char* misName, const U32 missionCRC, const U32 buffSize, char* filenameBuffer); 47public: 48 S32 sgTimeTemp; 49 S32 sgTimeTemp2; 50 51 virtual void sgNewEvent(U32 light, S32 object, U32 event); 52 53 virtual void sgLightingStartEvent(); 54 virtual void sgLightingCompleteEvent(); 55 56 virtual void sgTGEPassSetupEvent(); 57 virtual void sgTGELightStartEvent(U32 light); 58 virtual void sgTGELightProcessEvent(U32 light, S32 object); 59 virtual void sgTGELightCompleteEvent(U32 light); 60 virtual void sgTGESetProgress(U32 light, S32 object); 61 62 virtual void sgSGPassSetupEvent(); 63 virtual void sgSGObjectStartEvent(S32 object); 64 virtual void sgSGObjectProcessEvent(U32 light, S32 object); 65 virtual void sgSGObjectCompleteEvent(S32 object); 66 virtual void sgSGSetProgress(U32 light, S32 object); 67 68 // 'sg' prefix omitted to conform with existing 'addInterior' method... 69 void addStatic(ShadowVolumeBSP *shadowVolume, SceneObject *sceneobject, LightInfo *light, S32 level); 70 71 // persist objects moved to 'sgScenePersist.h' for clarity... 72 // everything below this line should be original code... 73 74 U32 calcMissionCRC(); 75 76 bool verifyMissionInfo(PersistInfo::PersistChunk *); 77 bool getMissionInfo(PersistInfo::PersistChunk *); 78 79 bool loadPersistInfo(const char *); 80 bool savePersistInfo(const char *); 81 82 class ObjectProxy; 83 84 enum { 85 SHADOW_DETAIL = -1 86 }; 87 88 //------------------------------------------------------------------------------ 89 /// Create a proxy for each object to store data. 90 class ObjectProxy 91 { 92 public: 93 SimObjectPtr<SceneObject> mObj; 94 U32 mChunkCRC; 95 96 ObjectProxy(SceneObject * obj) : mObj(obj){mChunkCRC = 0;} 97 virtual ~ObjectProxy(){} 98 SceneObject * operator->() {return(mObj);} 99 SceneObject * getObject() {return(mObj);} 100 101 /// @name Lighting Interface 102 /// @{ 103 virtual bool loadResources() {return(true);} 104 virtual void init() {} 105 virtual bool tgePreLight(LightInfo* light) { return preLight(light); } 106 virtual bool preLight(LightInfo *) {return(false);} 107 virtual void light(LightInfo *) {} 108 virtual void postLight(bool lastLight) {} 109 /// @} 110 111 /// @name Lighting events 112 /// @{ 113 // Called when the lighting process begins 114 virtual void processLightingStart() {} 115 // Called when a TGELight event is started, return true if status has been reported to console 116 virtual void processTGELightProcessEvent(U32 curr, U32 max, LightInfo*) { Con::printf(" Lighting object %d of %d...", (curr+1), max); } 117 // Called for lighting kit lights 118 virtual bool processStartObjectLightingEvent(U32 current, U32 max) { Con::printf(" Lighting object %d of %d... %s: %s", (current+1), max, mObj->getClassName(), mObj->getName()); return true; } 119 // Called once per object and SG light - used for calling light on an object 120 virtual void processSGObjectProcessEvent(LightInfo* currLight) { light(currLight); }; 121 /// @} 122 123 /// @name Persistence 124 /// 125 /// We cache lighting information to cut down on load times. 126 /// 127 /// There are flags such as ForceAlways and LoadOnly which allow you 128 /// to control this behaviour. 129 /// @{ 130 bool calcValidation(); 131 bool isValidChunk(PersistInfo::PersistChunk *); 132 133 virtual U32 getResourceCRC() = 0; 134 virtual bool setPersistInfo(PersistInfo::PersistChunk *); 135 virtual bool getPersistInfo(PersistInfo::PersistChunk *); 136 /// @} 137 138 // Called to figure out if this object should be added to the shadow volume 139 virtual bool supportsShadowVolume() { return false; } 140 // Called to retrieve the clip planes of the object. Currently used for terrain lighting, but could be used to speed up other 141 // lighting calculations. 142 virtual void getClipPlanes(Vector<PlaneF>& planes) { } 143 // Called to add the object to the shadow volume 144 virtual void addToShadowVolume(ShadowVolumeBSP * shadowVolume, LightInfo * light, S32 level) { } ; 145 }; 146 147 typedef Vector<ObjectProxy*> ObjectProxyList; 148 149 ObjectProxyList mSceneObjects; 150 ObjectProxyList mLitObjects; 151 152 LightInfoList mLights; 153 154 SceneLighting(AvailableSLInterfaces* lightingInterfaces); 155 ~SceneLighting(); 156 157 enum Flags { 158 ForceAlways = BIT(0), ///< Regenerate the scene lighting no matter what. 159 ForceWritable = BIT(1), ///< Regenerate the scene lighting only if we can write to the lighting cache files. 160 LoadOnly = BIT(2), ///< Just load cached lighting data. 161 }; 162 bool lightScene(const char *, BitSet32 flags = 0); 163 bool isLighting(); 164 165 S32 mStartTime; 166 char mFileName[1024]; 167 SceneManager * mSceneManager; 168 169 bool light(BitSet32); 170 void completed(bool success); 171 void processEvent(U32 light, S32 object); 172 void processCache(); 173}; 174 175class sgSceneLightingProcessEvent : public SimEvent 176{ 177private: 178 U32 sgLightIndex; 179 S32 sgObjectIndex; 180 U32 sgEvent; 181 182public: 183 enum sgEventTypes 184 { 185 sgLightingStartEventType, 186 sgLightingCompleteEventType, 187 188 sgSGPassSetupEventType, 189 sgSGObjectStartEventType, 190 sgSGObjectCompleteEventType, 191 sgSGObjectProcessEventType, 192 193 sgTGEPassSetupEventType, 194 sgTGELightStartEventType, 195 sgTGELightCompleteEventType, 196 sgTGELightProcessEventType 197 }; 198 199 sgSceneLightingProcessEvent(U32 lightIndex, S32 objectIndex, U32 event) 200 { 201 sgLightIndex = lightIndex; 202 sgObjectIndex = objectIndex; 203 sgEvent = event; 204 } 205 void process(SimObject * object) 206 { 207 AssertFatal(object, "SceneLightingProcessEvent:: null event object!"); 208 if(!object) 209 return; 210 211 SceneLighting *sl = static_cast<SceneLighting*>(object); 212 switch(sgEvent) 213 { 214 case sgLightingStartEventType: 215 sl->sgLightingStartEvent(); 216 break; 217 case sgLightingCompleteEventType: 218 sl->sgLightingCompleteEvent(); 219 break; 220 221 case sgTGEPassSetupEventType: 222 sl->sgTGEPassSetupEvent(); 223 break; 224 case sgTGELightStartEventType: 225 sl->sgTGELightStartEvent(sgLightIndex); 226 break; 227 case sgTGELightProcessEventType: 228 sl->sgTGELightProcessEvent(sgLightIndex, sgObjectIndex); 229 break; 230 case sgTGELightCompleteEventType: 231 sl->sgTGELightCompleteEvent(sgLightIndex); 232 break; 233 234 case sgSGPassSetupEventType: 235 sl->sgSGPassSetupEvent(); 236 break; 237 case sgSGObjectStartEventType: 238 sl->sgSGObjectStartEvent(sgObjectIndex); 239 break; 240 case sgSGObjectProcessEventType: 241 sl->sgSGObjectProcessEvent(sgLightIndex, sgObjectIndex); 242 break; 243 case sgSGObjectCompleteEventType: 244 sl->sgSGObjectCompleteEvent(sgObjectIndex); 245 break; 246 247 default: 248 return; 249 }; 250 }; 251}; 252 253extern SceneLighting *gLighting; 254 255#endif//_SGSCENELIGHTING_H_ 256