diff options
author | UbitUmarov | 2014-08-07 05:20:45 +0100 |
---|---|---|
committer | UbitUmarov | 2014-08-07 05:20:45 +0100 |
commit | c3f9c99fb32d15e57b24502b71c79fe028ed3007 (patch) | |
tree | 0b7cef6c028edfff0e09ca6d5442141221bc85a2 /OpenSim/Region/CoreModules/Avatar | |
parent | bakemodule didnt like last changes (diff) | |
download | opensim-SC-c3f9c99fb32d15e57b24502b71c79fe028ed3007.zip opensim-SC-c3f9c99fb32d15e57b24502b71c79fe028ed3007.tar.gz opensim-SC-c3f9c99fb32d15e57b24502b71c79fe028ed3007.tar.bz2 opensim-SC-c3f9c99fb32d15e57b24502b71c79fe028ed3007.tar.xz |
DANGER... changed bakedtextures caching. Assuming grid baking is cache
only, reduced number of accesses to it. TESTING
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar')
-rw-r--r-- | OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs | 279 |
1 files changed, 198 insertions, 81 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs index 09cc998..b4aefce 100644 --- a/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/AvatarFactory/AvatarFactoryModule.cs | |||
@@ -188,27 +188,7 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory | |||
188 | // Process the visual params, this may change height as well | 188 | // Process the visual params, this may change height as well |
189 | if (visualParams != null) | 189 | if (visualParams != null) |
190 | { | 190 | { |
191 | // string[] visualParamsStrings = new string[visualParams.Length]; | ||
192 | // for (int i = 0; i < visualParams.Length; i++) | ||
193 | // visualParamsStrings[i] = visualParams[i].ToString(); | ||
194 | // m_log.DebugFormat( | ||
195 | // "[AVFACTORY]: Setting visual params for {0} to {1}", | ||
196 | // client.Name, string.Join(", ", visualParamsStrings)); | ||
197 | /* | ||
198 | float oldHeight = sp.Appearance.AvatarHeight; | ||
199 | changed = sp.Appearance.SetVisualParams(visualParams); | ||
200 | |||
201 | if (sp.Appearance.AvatarHeight != oldHeight && sp.Appearance.AvatarHeight > 0) | ||
202 | ((ScenePresence)sp).SetHeight(sp.Appearance.AvatarHeight); | ||
203 | */ | ||
204 | // float oldoff = sp.Appearance.AvatarFeetOffset; | ||
205 | // Vector3 oldbox = sp.Appearance.AvatarBoxSize; | ||
206 | changed = sp.Appearance.SetVisualParams(visualParams); | 191 | changed = sp.Appearance.SetVisualParams(visualParams); |
207 | // float off = sp.Appearance.AvatarFeetOffset; | ||
208 | // Vector3 box = sp.Appearance.AvatarBoxSize; | ||
209 | // if(oldoff != off || oldbox != box) | ||
210 | // ((ScenePresence)sp).SetSize(box,off); | ||
211 | |||
212 | } | 192 | } |
213 | 193 | ||
214 | // Process the baked texture array | 194 | // Process the baked texture array |
@@ -222,9 +202,15 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory | |||
222 | 202 | ||
223 | // WriteBakedTexturesReport(sp, m_log.DebugFormat); | 203 | // WriteBakedTexturesReport(sp, m_log.DebugFormat); |
224 | 204 | ||
205 | |||
225 | // If bake textures are missing and this is not an NPC, request a rebake from client | 206 | // If bake textures are missing and this is not an NPC, request a rebake from client |
226 | if (!ValidateBakedTextureCache(sp) && (((ScenePresence)sp).PresenceType != PresenceType.Npc)) | 207 | // rebake may messup caching, and should not be needed |
227 | RequestRebake(sp, true); | 208 | |
209 | |||
210 | // if (!UpdateBakedTextureCache(sp,cacheItems) && (((ScenePresence)sp).PresenceType != PresenceType.Npc)) | ||
211 | // RequestRebake(sp, true); | ||
212 | |||
213 | UpdateBakedTextureCache(sp, cacheItems); | ||
228 | 214 | ||
229 | // This appears to be set only in the final stage of the appearance | 215 | // This appears to be set only in the final stage of the appearance |
230 | // update transaction. In theory, we should be able to do an immediate | 216 | // update transaction. In theory, we should be able to do an immediate |
@@ -377,13 +363,138 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory | |||
377 | } | 363 | } |
378 | } | 364 | } |
379 | 365 | ||
366 | // called on textures update | ||
367 | public bool UpdateBakedTextureCache(IScenePresence sp, WearableCacheItem[] cacheItems) | ||
368 | { | ||
369 | bool defonly = true; // are we only using default textures | ||
370 | |||
371 | // uploaded baked textures will be in assets local cache | ||
372 | IAssetService cache = m_scene.AssetService; | ||
373 | |||
374 | int validDirtyBakes = 0; | ||
375 | int hits = 0; | ||
376 | |||
377 | // our main cacheIDs mapper is p.Appearance.WearableCacheItems | ||
378 | WearableCacheItem[] wearableCache = sp.Appearance.WearableCacheItems; | ||
379 | |||
380 | if (wearableCache == null) | ||
381 | { | ||
382 | wearableCache = WearableCacheItem.GetDefaultCacheItem(); | ||
383 | } | ||
384 | |||
385 | // Process received baked textures | ||
386 | for (int i = 0; i < cacheItems.Length; i++) | ||
387 | { | ||
388 | int idx = (int)cacheItems[i].TextureIndex; | ||
389 | Primitive.TextureEntryFace face = sp.Appearance.Texture.FaceTextures[idx]; | ||
390 | |||
391 | // No face | ||
392 | if (face == null) | ||
393 | { | ||
394 | // for some reason viewer is cleaning this | ||
395 | sp.Appearance.Texture.FaceTextures[idx] = sp.Appearance.Texture.CreateFace((uint) idx); | ||
396 | sp.Appearance.Texture.FaceTextures[idx].TextureID = AppearanceManager.DEFAULT_AVATAR_TEXTURE; | ||
397 | wearableCache[idx].CacheId = UUID.Zero; | ||
398 | wearableCache[idx].TextureID = UUID.Zero; | ||
399 | wearableCache[idx].TextureAsset = null; | ||
400 | continue; | ||
401 | } | ||
402 | else | ||
403 | { | ||
404 | if (face.TextureID == UUID.Zero || face.TextureID == AppearanceManager.DEFAULT_AVATAR_TEXTURE) | ||
405 | { | ||
406 | wearableCache[idx].CacheId = UUID.Zero; | ||
407 | wearableCache[idx].TextureID = UUID.Zero; | ||
408 | wearableCache[idx].TextureAsset = null; | ||
409 | continue; | ||
410 | } | ||
411 | |||
412 | defonly = false; // found a non-default texture reference | ||
413 | |||
414 | if(sp.Appearance.Texture.FaceTextures[idx].TextureID == wearableCache[idx].TextureID) | ||
415 | { | ||
416 | if(wearableCache[idx].CacheId != cacheItems[i].CacheId) | ||
417 | { | ||
418 | wearableCache[idx].CacheId = cacheItems[i].CacheId; | ||
419 | validDirtyBakes++; | ||
420 | hits++; | ||
421 | //assuming this can only happen if asset is in cache | ||
422 | } | ||
423 | continue; | ||
424 | } | ||
425 | |||
426 | |||
427 | wearableCache[idx].TextureAsset = null; | ||
428 | if (cache != null) | ||
429 | wearableCache[idx].TextureAsset = cache.GetCached(face.TextureID.ToString()); | ||
430 | |||
431 | if (wearableCache[idx].TextureAsset != null) | ||
432 | { | ||
433 | wearableCache[idx].CacheId = cacheItems[i].CacheId; | ||
434 | wearableCache[idx].TextureID = sp.Appearance.Texture.FaceTextures[idx].TextureID; | ||
435 | validDirtyBakes++; | ||
436 | hits++; | ||
437 | } | ||
438 | else | ||
439 | { | ||
440 | wearableCache[idx].CacheId = UUID.Zero; | ||
441 | wearableCache[idx].TextureID = UUID.Zero; | ||
442 | wearableCache[idx].TextureAsset = null; | ||
443 | continue; | ||
444 | } | ||
445 | } | ||
446 | } | ||
447 | |||
448 | sp.Appearance.WearableCacheItems = wearableCache; | ||
449 | |||
450 | // if we got a full set of baked textures save all in BakedTextureModule | ||
451 | |||
452 | if (validDirtyBakes == cacheItems.Length) | ||
453 | { | ||
454 | IBakedTextureModule m_BakedTextureModule = m_scene.RequestModuleInterface<IBakedTextureModule>(); | ||
455 | if (m_BakedTextureModule != null) | ||
456 | { | ||
457 | m_log.Debug("[UpdateBakedCache] uploading to bakedModule cache"); | ||
458 | |||
459 | m_BakedTextureModule.Store(sp.UUID, wearableCache); | ||
460 | } | ||
461 | } | ||
462 | |||
463 | // debug | ||
464 | for (int iter = 0; iter < AvatarAppearance.BAKE_INDICES.Length; iter++) | ||
465 | { | ||
466 | int j = AvatarAppearance.BAKE_INDICES[iter]; | ||
467 | m_log.Debug("[UpdateBCache] {" + iter + "/" + | ||
468 | sp.Appearance.WearableCacheItems[j].TextureIndex + "}: c-" + | ||
469 | sp.Appearance.WearableCacheItems[j].CacheId + ", t-" + | ||
470 | sp.Appearance.WearableCacheItems[j].TextureID); | ||
471 | } | ||
472 | |||
473 | // If we only found default textures, then the appearance is not cached | ||
474 | return (defonly ? false : true); | ||
475 | } | ||
476 | |||
477 | // called when we get a new root avatar | ||
380 | public bool ValidateBakedTextureCache(IScenePresence sp) | 478 | public bool ValidateBakedTextureCache(IScenePresence sp) |
381 | { | 479 | { |
382 | bool defonly = true; // are we only using default textures | 480 | bool defonly = true; // are we only using default textures |
383 | IImprovedAssetCache cache = m_scene.RequestModuleInterface<IImprovedAssetCache>(); | 481 | IAssetService cache = m_scene.AssetService; |
384 | IBakedTextureModule bakedModule = m_scene.RequestModuleInterface<IBakedTextureModule>(); | 482 | IBakedTextureModule bakedModule = m_scene.RequestModuleInterface<IBakedTextureModule>(); |
385 | WearableCacheItem[] wearableCache = null; | 483 | WearableCacheItem[] wearableCache = null; |
386 | 484 | ||
485 | // debug | ||
486 | for (int iter = 0; iter < AvatarAppearance.BAKE_INDICES.Length; iter++) | ||
487 | { | ||
488 | int j = AvatarAppearance.BAKE_INDICES[iter]; | ||
489 | Primitive.TextureEntryFace face = sp.Appearance.Texture.FaceTextures[iter]; | ||
490 | if(face != null) | ||
491 | m_log.Debug("[ValidateBakedCache] {" + iter + "/" + j + " t - " + face.TextureID); | ||
492 | else | ||
493 | m_log.Debug("[ValidateBakedCache] {" + iter + "/" + j + " t - No texture"); | ||
494 | } | ||
495 | |||
496 | |||
497 | int hits = 0; | ||
387 | // Cache wearable data for teleport. | 498 | // Cache wearable data for teleport. |
388 | // Only makes sense if there's a bake module and a cache module | 499 | // Only makes sense if there's a bake module and a cache module |
389 | if (bakedModule != null && cache != null) | 500 | if (bakedModule != null && cache != null) |
@@ -394,41 +505,35 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory | |||
394 | } | 505 | } |
395 | catch (Exception) | 506 | catch (Exception) |
396 | { | 507 | { |
397 | 508 | wearableCache = null; | |
398 | } | 509 | } |
510 | |||
399 | if (wearableCache != null) | 511 | if (wearableCache != null) |
400 | { | 512 | { |
401 | for (int i = 0; i < wearableCache.Length; i++) | 513 | for (int i = 0; i < wearableCache.Length; i++) |
402 | { | 514 | { |
403 | cache.Cache(wearableCache[i].TextureAsset); | 515 | |
404 | } | 516 | m_log.Debug("[ValidateBakedCache] got bakedModule cache"); |
405 | } | 517 | |
406 | } | 518 | if (wearableCache[i].TextureAsset != null) |
407 | /* | ||
408 | IBakedTextureModule bakedModule = m_scene.RequestModuleInterface<IBakedTextureModule>(); | ||
409 | if (invService.GetRootFolder(userID) != null) | ||
410 | { | ||
411 | WearableCacheItem[] wearableCache = null; | ||
412 | if (bakedModule != null) | ||
413 | { | ||
414 | try | ||
415 | { | ||
416 | wearableCache = bakedModule.Get(userID); | ||
417 | appearance.WearableCacheItems = wearableCache; | ||
418 | appearance.WearableCacheItemsDirty = false; | ||
419 | foreach (WearableCacheItem item in wearableCache) | ||
420 | { | 519 | { |
421 | appearance.Texture.FaceTextures[item.TextureIndex].TextureID = item.TextureID; | 520 | wearableCache[i].TextureAsset.Temporary = true; |
521 | wearableCache[i].TextureAsset.Local = true; | ||
522 | cache.Store(wearableCache[i].TextureAsset); | ||
523 | } | ||
524 | else | ||
525 | { | ||
526 | wearableCache[i].TextureID = UUID.Zero; | ||
527 | wearableCache[i].CacheId = UUID.Zero; | ||
422 | } | 528 | } |
423 | } | ||
424 | catch (Exception) | ||
425 | { | ||
426 | |||
427 | } | 529 | } |
428 | } | 530 | } |
429 | */ | 531 | } |
532 | |||
533 | if(wearableCache == null) | ||
534 | wearableCache = WearableCacheItem.GetDefaultCacheItem(); | ||
430 | 535 | ||
431 | // Process the texture entry | 536 | // Process the baked textures |
432 | for (int i = 0; i < AvatarAppearance.BAKE_INDICES.Length; i++) | 537 | for (int i = 0; i < AvatarAppearance.BAKE_INDICES.Length; i++) |
433 | { | 538 | { |
434 | int idx = AvatarAppearance.BAKE_INDICES[i]; | 539 | int idx = AvatarAppearance.BAKE_INDICES[i]; |
@@ -437,61 +542,73 @@ namespace OpenSim.Region.CoreModules.Avatar.AvatarFactory | |||
437 | // No face, so lets check our baked service cache, teleport or login. | 542 | // No face, so lets check our baked service cache, teleport or login. |
438 | if (face == null) | 543 | if (face == null) |
439 | { | 544 | { |
440 | if (wearableCache != null) | 545 | sp.Appearance.Texture.FaceTextures[idx] = sp.Appearance.Texture.CreateFace((uint)idx); |
546 | if (wearableCache[idx].TextureID != UUID.Zero) | ||
441 | { | 547 | { |
442 | // If we find the an appearance item, set it as the textureentry and the face | 548 | sp.Appearance.Texture.FaceTextures[idx].TextureID = wearableCache[idx].TextureID; |
443 | WearableCacheItem searchitem = WearableCacheItem.SearchTextureIndex((uint) idx, wearableCache); | 549 | face = sp.Appearance.Texture.FaceTextures[idx]; |
444 | if (searchitem != null) | 550 | // let run to end of loop to check cache |
445 | { | ||
446 | sp.Appearance.Texture.FaceTextures[idx] = sp.Appearance.Texture.CreateFace((uint) idx); | ||
447 | sp.Appearance.Texture.FaceTextures[idx].TextureID = searchitem.TextureID; | ||
448 | face = sp.Appearance.Texture.FaceTextures[idx]; | ||
449 | } | ||
450 | else | ||
451 | { | ||
452 | // if there is no texture entry and no baked cache, skip it | ||
453 | continue; | ||
454 | } | ||
455 | } | 551 | } |
456 | else | 552 | else |
457 | { | 553 | { |
458 | //No texture entry face and no cache. Skip this face. | 554 | sp.Appearance.Texture.FaceTextures[idx].TextureID = AppearanceManager.DEFAULT_AVATAR_TEXTURE; |
555 | face = sp.Appearance.Texture.FaceTextures[idx]; | ||
556 | wearableCache[idx].CacheId = UUID.Zero; | ||
557 | wearableCache[idx].TextureID = UUID.Zero; | ||
558 | wearableCache[idx].TextureAsset = null; | ||
459 | continue; | 559 | continue; |
460 | } | 560 | } |
461 | } | 561 | } |
462 | 562 | ||
463 | |||
464 | // m_log.DebugFormat( | ||
465 | // "[AVFACTORY]: Looking for texture {0}, id {1} for {2} {3}", | ||
466 | // face.TextureID, idx, client.Name, client.AgentId); | ||
467 | 563 | ||
468 | // if the texture is one of the "defaults" then skip it | ||
469 | // this should probably be more intelligent (skirt texture doesnt matter | ||
470 | // if the avatar isnt wearing a skirt) but if any of the main baked | ||
471 | // textures is default then the rest should be as well | ||
472 | if (face.TextureID == UUID.Zero || face.TextureID == AppearanceManager.DEFAULT_AVATAR_TEXTURE) | 564 | if (face.TextureID == UUID.Zero || face.TextureID == AppearanceManager.DEFAULT_AVATAR_TEXTURE) |
565 | { | ||
566 | wearableCache[idx].CacheId = UUID.Zero; | ||
567 | wearableCache[idx].TextureID = UUID.Zero; | ||
568 | wearableCache[idx].TextureAsset = null; | ||
473 | continue; | 569 | continue; |
474 | 570 | } | |
571 | |||
475 | defonly = false; // found a non-default texture reference | 572 | defonly = false; // found a non-default texture reference |
476 | 573 | ||
477 | if (cache != null) | 574 | if(wearableCache[idx].TextureID != sp.Appearance.Texture.FaceTextures[idx].TextureID) |
478 | { | 575 | { |
479 | if (!cache.Check(face.TextureID.ToString())) | 576 | wearableCache[idx].CacheId = UUID.Zero; |
480 | return false; | 577 | wearableCache[idx].TextureID = UUID.Zero; |
578 | wearableCache[idx].TextureAsset = null; | ||
579 | continue; | ||
481 | } | 580 | } |
482 | else | 581 | |
582 | wearableCache[idx].TextureAsset = null; | ||
583 | if (cache != null) | ||
483 | { | 584 | { |
484 | if (m_scene.AssetService.Get(face.TextureID.ToString()) == null) | 585 | wearableCache[idx].TextureAsset = m_scene.AssetService.Get(face.TextureID.ToString()); |
485 | return false; | 586 | if (wearableCache[idx].TextureAsset == null) |
587 | { | ||
588 | wearableCache[idx].CacheId = UUID.Zero; | ||
589 | wearableCache[idx].TextureID = UUID.Zero; | ||
590 | } | ||
591 | else | ||
592 | hits++; | ||
486 | } | 593 | } |
487 | } | 594 | } |
488 | 595 | ||
489 | // m_log.DebugFormat("[AVFACTORY]: Completed texture check for {0} {1}", sp.Name, sp.UUID); | 596 | sp.Appearance.WearableCacheItems = wearableCache; |
597 | |||
598 | m_log.DebugFormat("[AVFACTORY]: Completed texture check for {0} {1} {2} {3}", sp.Name, sp.UUID, hits, defonly.ToString()); | ||
599 | // debug | ||
600 | for (int iter = 0; iter < AvatarAppearance.BAKE_INDICES.Length; iter++) | ||
601 | { | ||
602 | int j = AvatarAppearance.BAKE_INDICES[iter]; | ||
603 | m_log.Debug("[ValidateBakedCache] {" + iter + "/" + | ||
604 | sp.Appearance.WearableCacheItems[j].TextureIndex + "}: c-" + | ||
605 | sp.Appearance.WearableCacheItems[j].CacheId + ", t-" + | ||
606 | sp.Appearance.WearableCacheItems[j].TextureID); | ||
607 | } | ||
490 | 608 | ||
491 | // If we only found default textures, then the appearance is not cached | 609 | // If we only found default textures, then the appearance is not cached |
492 | return (defonly ? false : true); | 610 | return (defonly ? false : true); |
493 | } | 611 | } |
494 | |||
495 | public int RequestRebake(IScenePresence sp, bool missingTexturesOnly) | 612 | public int RequestRebake(IScenePresence sp, bool missingTexturesOnly) |
496 | { | 613 | { |
497 | int texturesRebaked = 0; | 614 | int texturesRebaked = 0; |