Browse Source

Re-enabled AngelScript type caching.
Eliminated constant reallocation of lighting related helper hashsets/hashmaps in View.

Lasse Öörni 14 years ago
parent
commit
e2e29ff790
3 changed files with 34 additions and 28 deletions
  1. 18 22
      Engine/Graphics/View.cpp
  2. 7 1
      Engine/Graphics/View.h
  3. 9 5
      ThirdParty/AngelScript/source/as_scriptengine.cpp

+ 18 - 22
Engine/Graphics/View.cpp

@@ -388,9 +388,9 @@ void View::GetDrawables()
 
 void View::GetBatches()
 {
-    HashSet<LitTransparencyCheck> litTransparencies;
-    HashSet<Drawable*> maxLightsDrawables;
-    Map<Light*, unsigned> lightQueueIndex;
+    litTransparencies_.Clear();
+    maxLightsDrawables_.Clear();
+    lightQueueIndex_.Clear();
     
     // Go through lights
     {
@@ -463,11 +463,11 @@ void View::GetBatches()
                         
                         // If drawable limits maximum lights, only record the light, and check maximum count / build batches later
                         if (!drawable->GetMaxLights())
-                            GetLitBatches(drawable, light, splitLight, &lightQueue, litTransparencies);
+                            GetLitBatches(drawable, light, splitLight, lightQueue);
                         else
                         {
                             drawable->AddLight(splitLight);
-                            maxLightsDrawables.Insert(drawable);
+                            maxLightsDrawables_.Insert(drawable);
                         }
                     }
                     
@@ -496,7 +496,7 @@ void View::GetBatches()
                     
                     if (storeLightQueue)
                     {
-                        lightQueueIndex[splitLight] = lightQueueCount;
+                        lightQueueIndex_[splitLight] = lightQueueCount;
                         firstSplitStored = true;
                         ++lightQueueCount;
                     }
@@ -509,11 +509,11 @@ void View::GetBatches()
     }
     
     // Process drawables with limited light count
-    if (maxLightsDrawables.Size())
+    if (maxLightsDrawables_.Size())
     {
         PROFILE(GetMaxLightsBatches);
         
-        for (HashSet<Drawable*>::Iterator i = maxLightsDrawables.Begin(); i != maxLightsDrawables.End(); ++i)
+        for (HashSet<Drawable*>::Iterator i = maxLightsDrawables_.Begin(); i != maxLightsDrawables_.End(); ++i)
         {
             Drawable* drawable = *i;
             drawable->LimitLights();
@@ -528,11 +528,9 @@ void View::GetBatches()
                 
                 // Find the correct light queue again
                 LightBatchQueue* queue = 0;
-                Map<Light*, unsigned>::Iterator j = lightQueueIndex.Find(splitLight);
-                if (j != lightQueueIndex.End())
-                    queue = &lightQueues_[j->second_];
-                
-                GetLitBatches(drawable, light, splitLight, queue, litTransparencies);
+                Map<Light*, unsigned>::Iterator j = lightQueueIndex_.Find(splitLight);
+                if (j != lightQueueIndex_.End())
+                    GetLitBatches(drawable, light, splitLight, lightQueues_[j->second_]);
             }
         }
     }
@@ -626,8 +624,7 @@ void View::GetBatches()
     SortBatches();
 }
 
-void View::GetLitBatches(Drawable* drawable, Light* light, Light* splitLight, LightBatchQueue* lightQueue,
-    HashSet<LitTransparencyCheck>& litTransparencies)
+void View::GetLitBatches(Drawable* drawable, Light* light, Light* splitLight, LightBatchQueue& lightQueue)
 {
     bool splitPointLight = splitLight->GetLightType() == LIGHT_SPLITPOINT;
     // Whether to allow shadows for transparencies, or for forward lit objects in deferred mode
@@ -683,11 +680,8 @@ void View::GetLitBatches(Drawable* drawable, Light* light, Light* splitLight, Li
         {
             if (mode_ == RENDER_FORWARD)
             {
-                if (lightQueue)
-                {
-                    renderer_->SetBatchShaders(litBatch, tech, pass);
-                    lightQueue->litBatches_.AddBatch(litBatch);
-                }
+                renderer_->SetBatchShaders(litBatch, tech, pass);
+                lightQueue.litBatches_.AddBatch(litBatch);
             }
             else
             {
@@ -701,12 +695,14 @@ void View::GetLitBatches(Drawable* drawable, Light* light, Light* splitLight, Li
             {
                 // Check if already lit
                 LitTransparencyCheck check(light, drawable, i);
-                if (!litTransparencies.Contains(check))
+                if (!litTransparencies_.Contains(check))
                 {
                     // Use the original light instead of the split one, to choose correct scissor
                     litBatch.light_ = light;
-                    litTransparencies.Insert(check);
+                    litTransparencies_.Insert(check);
                 }
+                else
+                    continue;
             }
             
             renderer_->SetBatchShaders(litBatch, tech, pass, allowShadows);

+ 7 - 1
Engine/Graphics/View.h

@@ -138,7 +138,7 @@ private:
     /// Construct batches from the drawable objects.
     void GetBatches();
     /// Get lit batches for a certain light and drawable.
-    void GetLitBatches(Drawable* drawable, Light* light, Light* SplitLight, LightBatchQueue* lightQueue, HashSet<LitTransparencyCheck>& litTransparencies);
+    void GetLitBatches(Drawable* drawable, Light* light, Light* SplitLight, LightBatchQueue& lightQueue);
     /// Render batches, forward mode.
     void RenderBatchesForward();
     /// Render batches, deferred mode.
@@ -248,6 +248,12 @@ private:
     HashSet<RenderSurface*> gBufferErrorDisplayed_;
     /// Helper set for combining lit geometries of a split light.
     HashSet<Drawable*> allLitGeometries_;
+    /// Transparent drawables that are already lit, to avoid multiple lighting.
+    HashSet<LitTransparencyCheck> litTransparencies_;
+    /// Drawables that limit their maximum light count.
+    HashSet<Drawable*> maxLightsDrawables_;
+    /// Light queue indices of processed lights.
+    Map<Light*, unsigned> lightQueueIndex_;
     /// View-global shader parameters.
     HashMap<StringHash, Vector4> shaderParameters_;
     /// Cache for light scissor queries.

+ 9 - 5
ThirdParty/AngelScript/source/as_scriptengine.cpp

@@ -3220,15 +3220,19 @@ void asCScriptEngine::GCEnumCallback(void *reference)
 
 
 // TODO: multithread: The mapTypeIdToDataType must be protected with critical sections in all functions that access it
-int asCScriptEngine::GetTypeIdFromDataType(const asCDataType &dtIn) const
+// Urho3D: modified for id caching
+int asCScriptEngine::GetTypeIdFromDataType(const asCDataType &dt) const
 {
-	if( dtIn.IsNullHandle() ) return 0;
+	if( dt.IsNullHandle() ) return 0;
 
 	// ASHANDLE is mimicking a handle, but it really is a value 
 	// type so only the non-handle form should be registered.
-	asCDataType dt(dtIn);
-	if( dt.GetObjectType() && dt.GetObjectType()->flags & asOBJ_ASHANDLE )
-		dt.MakeHandle(false);
+	if( dt.GetObjectType() && dt.GetObjectType()->flags & asOBJ_ASHANDLE && dt.IsObjectHandle() )
+	{
+		asCDataType dtNoHandle(dt);
+		dtNoHandle.MakeHandle(false);
+		return GetTypeIdFromDataType(dtNoHandle);
+	}
 
 	// Urho3D: check first for cached id in the type itself
 	int typeId = dt.GetCachedTypeId();