Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Assets/Resources/defaults.ini.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ DungeonShadowDistance=20.0
InteriorShadowDistance=30.0
ExteriorShadowDistance=90.0
EnableTextureArrays=True
EnableObjectCulling=True
RandomDungeonTextures=0

[Effects]
Expand Down
75 changes: 75 additions & 0 deletions Assets/Scenes/DaggerfallUnityGame.unity
Original file line number Diff line number Diff line change
Expand Up @@ -2894,3 +2894,78 @@ PrefabInstance:
objectReference: {fileID: 1769263313}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: bbe5e15c9f6b3dc47bb9485a437750a0, type: 3}
--- !u!114 &69466200359737372
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1834928754549345153}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 43fe9d3db5f70f24bb00284402a4d97e, type: 3}
m_Name:
m_EditorClassIdentifier:
culledObjectsParent: {fileID: 1269490794079082448}
--- !u!4 &357226078190250312
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1834928754549345153}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 14.787919, y: 27.745857, z: 29.176554}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 2109761705362116671}
m_Father: {fileID: 0}
m_RootOrder: 23
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1269490794079082448
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2109761705362116671}
m_Layer: 0
m_Name: CulledObjects
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!1 &1834928754549345153
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 357226078190250312}
- component: {fileID: 69466200359737372}
m_Layer: 0
m_Name: CulledGameObjectManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2109761705362116671
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1269490794079082448}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 357226078190250312}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
171 changes: 149 additions & 22 deletions Assets/Scripts/ActiveGameObjectDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ public GameObjectCache(string name)
// Returns all the active GameObjects in the cache
// If a system calls SetActive(false) on an object without destroying it, it will not be returned here
public IEnumerable<GameObject> GetActiveObjects()
{
return GetActiveObjects(false);
}

public IEnumerable<GameObject> GetActiveObjects(bool includeInactive)
{
cacheLock.EnterReadLock();
try
Expand All @@ -42,7 +47,7 @@ public IEnumerable<GameObject> GetActiveObjects()
// A null check on a GameObject does more than C#'s reference check,
// it also checks if the object has been destroyed
// Like Object.FindObjectsOfType, we should only include active objects
if (activeObject != null && activeObject.activeInHierarchy)
if (activeObject != null && (includeInactive || activeObject.activeInHierarchy))
gameObjects.Add(activeObject);
}
}
Expand All @@ -59,10 +64,15 @@ public IEnumerable<GameObject> GetActiveObjects()
// If a system calls SetActive(false) on an object without destroying it, it will not be returned here
public IEnumerable<T> GetActiveComponents<T>() where T : MonoBehaviour
{
foreach (GameObject gameObject in GetActiveObjects())
return GetActiveComponents<T>(false);
}

public IEnumerable<T> GetActiveComponents<T>(bool includeInactive) where T : MonoBehaviour
{
foreach (GameObject gameObject in GetActiveObjects(includeInactive))
{
var t = gameObject.GetComponent<T>();
if (t != null && t.isActiveAndEnabled)
if (t != null && (includeInactive || t.isActiveAndEnabled))
yield return t;
}
}
Expand Down Expand Up @@ -201,35 +211,86 @@ public static class ActiveGameObjectDatabase
static GameObjectCache staticNpcCache = new GameObjectCache("Static NPC");
static GameObjectCache actionDoorCache = new GameObjectCache("Action Door");
static GameObjectCache rdbCache = new GameObjectCache("RDB");
static GameObjectCache billboardCache = new GameObjectCache("Billboard");

public static IEnumerable<GameObject> GetActiveBillboardObjects()
{
return GetActiveBillboardObjects(false);
}

public static IEnumerable<GameObject> GetActiveBillboardObjects(bool includeInactive)
{
return billboardCache.GetActiveObjects(includeInactive);
}

public static IEnumerable<DaggerfallBillboard> GetActiveBillboards()
{
return GetActiveBillboards(false);
}

public static IEnumerable<DaggerfallBillboard> GetActiveBillboards(bool includeInactive)
{
return billboardCache.GetActiveComponents<DaggerfallBillboard>(includeInactive);
}

public static void RegisterBillboard(GameObject billboard)
{
billboardCache.AddObject(billboard);
}

// Gets all the active enemy GameObjects. Must be registered as Enemy (see below)
public static IEnumerable<GameObject> GetActiveEnemyObjects()
{
return enemyCache.GetActiveObjects();
return GetActiveEnemyObjects(false);
}

public static IEnumerable<GameObject> GetActiveEnemyObjects(bool includeInactive)
{
return enemyCache.GetActiveObjects(includeInactive);
}

// Gets all the enabled DaggerfallEntityBehaviour components from active registered enemies
public static IEnumerable<DaggerfallEntityBehaviour> GetActiveEnemyBehaviours()
{
return enemyCache.GetActiveComponents<DaggerfallEntityBehaviour>();
return GetActiveEnemyBehaviours(false);
}

public static IEnumerable<DaggerfallEntityBehaviour> GetActiveEnemyBehaviours(bool includeInactive)
{
return enemyCache.GetActiveComponents<DaggerfallEntityBehaviour>(includeInactive);
}

// Gets all the enabled DaggerfallEnemy components from active registered enemies
public static IEnumerable<DaggerfallEnemy> GetActiveEnemyEntities()
{
return enemyCache.GetActiveComponents<DaggerfallEnemy>();
return GetActiveEnemyEntities(false);
}

public static IEnumerable<DaggerfallEnemy> GetActiveEnemyEntities(bool includeInactive)
{
return enemyCache.GetActiveComponents<DaggerfallEnemy>(includeInactive);
}

// Gets all the enabled QuestResourceBehaviour components from active registered enemies
public static IEnumerable<QuestResourceBehaviour> GetActiveEnemyQuestResourceBehaviours()
{
return enemyCache.GetActiveComponents<QuestResourceBehaviour>();
return GetActiveEnemyQuestResourceBehaviours(false);
}

public static IEnumerable<QuestResourceBehaviour> GetActiveEnemyQuestResourceBehaviours(bool includeInactive)
{
return enemyCache.GetActiveComponents<QuestResourceBehaviour>(includeInactive);
}

// Gets all the enabled EnemyMotor components from active registered enemies
public static IEnumerable<EnemyMotor> GetActiveEnemyMotors()
{
return enemyCache.GetActiveComponents<EnemyMotor>();
return GetActiveEnemyMotors(false);
}

public static IEnumerable<EnemyMotor> GetActiveEnemyMotors(bool includeInactive)
{
return enemyCache.GetActiveComponents<EnemyMotor>(includeInactive);
}

// Registers an enemy (monster or class) to the enemy cache. Does not have to be active
Expand All @@ -241,13 +302,23 @@ public static void RegisterEnemy(GameObject enemy)
// Gets all the active Civilian Mobile GameObjects. Must be registered as Civilian Mobile (see below)
public static IEnumerable<GameObject> GetActiveCivilianMobileObjects()
{
return civilianCache.GetActiveObjects();
return GetActiveCivilianMobileObjects(false);
}

public static IEnumerable<GameObject> GetActiveCivilianMobileObjects(bool includeInactive)
{
return civilianCache.GetActiveObjects(includeInactive);
}

// Gets all the enabled DaggerfallEntityBehaviour components from active registered Civilian Mobiles
public static IEnumerable<DaggerfallEntityBehaviour> GetActiveCivilianMobileBehaviours()
{
return civilianCache.GetActiveComponents<DaggerfallEntityBehaviour>();
return GetActiveCivilianMobileBehaviours(false);
}

public static IEnumerable<DaggerfallEntityBehaviour> GetActiveCivilianMobileBehaviours(bool includeInactive)
{
return civilianCache.GetActiveComponents<DaggerfallEntityBehaviour>(includeInactive);
}

// Registers a mobile civilian NPC to the civilian cache. Does not have to be active
Expand All @@ -259,13 +330,23 @@ public static void RegisterCivilianMobile(GameObject civilian)
// Gets all the active loot GameObjects. Must be registered as Loot (see below)
public static IEnumerable<GameObject> GetActiveLootObjects()
{
return lootCache.GetActiveObjects();
return GetActiveLootObjects(false);
}

public static IEnumerable<GameObject> GetActiveLootObjects(bool includeInactive)
{
return lootCache.GetActiveObjects(includeInactive);
}

// Gets all the enabled DaggerfallLoot components from active registered loot
public static IEnumerable<DaggerfallLoot> GetActiveLoot()
{
return lootCache.GetActiveComponents<DaggerfallLoot>();
return GetActiveLoot(false);
}

public static IEnumerable<DaggerfallLoot> GetActiveLoot(bool includeInactive)
{
return lootCache.GetActiveComponents<DaggerfallLoot>(includeInactive);
}

// Registers a loot object to the loot cache. Does not have to be active
Expand All @@ -277,13 +358,23 @@ public static void RegisterLoot(GameObject loot)
// Gets all the active Foe Spawner GameObjects. Must be registered as Foe Spawner (see below)
public static IEnumerable<GameObject> GetActiveFoeSpawnerObjects()
{
return foeSpawnerCache.GetActiveObjects();
return GetActiveFoeSpawnerObjects(false);
}

public static IEnumerable<GameObject> GetActiveFoeSpawnerObjects(bool includeInactive)
{
return foeSpawnerCache.GetActiveObjects(includeInactive);
}

// Gets all the enabled FoeSpawner components from active registered foe spawners
public static IEnumerable<FoeSpawner> GetActiveFoeSpawners()
{
return foeSpawnerCache.GetActiveComponents<FoeSpawner>();
return GetActiveFoeSpawners(false);
}

public static IEnumerable<FoeSpawner> GetActiveFoeSpawners(bool includeInactive)
{
return foeSpawnerCache.GetActiveComponents<FoeSpawner>(includeInactive);
}

// Registers a foe spawner object to the foe spawner cache. Does not have to be active
Expand All @@ -295,19 +386,34 @@ public static void RegisterFoeSpawner(GameObject foeSpawner)
// Gets all the active Static NPC GameObjects. Must be registered as a Static NPC (see below)
public static IEnumerable<GameObject> GetActiveStaticNPCObjects()
{
return staticNpcCache.GetActiveObjects();
return GetActiveStaticNPCObjects(false);
}

public static IEnumerable<GameObject> GetActiveStaticNPCObjects(bool includeInactive)
{
return staticNpcCache.GetActiveObjects(includeInactive);
}

// Gets all the enabled StaticNPC components from active registered static NPCs
public static IEnumerable<StaticNPC> GetActiveStaticNPCs()
{
return staticNpcCache.GetActiveComponents<StaticNPC>();
return GetActiveStaticNPCs(false);
}

public static IEnumerable<StaticNPC> GetActiveStaticNPCs(bool includeInactive)
{
return staticNpcCache.GetActiveComponents<StaticNPC>(includeInactive);
}

// Gets all the enabled QuestResourceBehaviour components from active registered static NPCs
public static IEnumerable<QuestResourceBehaviour> GetActiveStaticNPCQuestResourceBehaviours()
{
return staticNpcCache.GetActiveComponents<QuestResourceBehaviour>();
return GetActiveStaticNPCQuestResourceBehaviours(false);
}

public static IEnumerable<QuestResourceBehaviour> GetActiveStaticNPCQuestResourceBehaviours(bool includeInactive)
{
return staticNpcCache.GetActiveComponents<QuestResourceBehaviour>(includeInactive);
}

// Registers a static NPC object to the Static NPC cache. Does not have to be active
Expand All @@ -319,13 +425,23 @@ public static void RegisterStaticNPC(GameObject staticNPC)
// Gets all the active Action Door GameObjects. Must be registered as Action Door (see below)
public static IEnumerable<GameObject> GetActiveActionDoorObjects()
{
return actionDoorCache.GetActiveObjects();
return GetActiveActionDoorObjects(false);
}

public static IEnumerable<GameObject> GetActiveActionDoorObjects(bool includeInactive)
{
return actionDoorCache.GetActiveObjects(includeInactive);
}

// Gets all the enabled DaggerfallActionDoor components from active registered doors
public static IEnumerable<DaggerfallActionDoor> GetActiveActionDoors()
{
return actionDoorCache.GetActiveComponents<DaggerfallActionDoor>();
return GetActiveActionDoors(false);
}

public static IEnumerable<DaggerfallActionDoor> GetActiveActionDoors(bool includeInactive)
{
return actionDoorCache.GetActiveComponents<DaggerfallActionDoor>(includeInactive);
}

// Registers an Action Door object to the Action Door cache. Does not have to be active
Expand All @@ -338,13 +454,23 @@ public static void RegisterActionDoor(GameObject door)
// Gets all the active RDB GameObjects. Must be registered as RDB (see below)
public static IEnumerable<GameObject> GetActiveRDBObjects()
{
return rdbCache.GetActiveObjects();
return GetActiveRDBObjects(false);
}

public static IEnumerable<GameObject> GetActiveRDBObjects(bool includeInactive)
{
return rdbCache.GetActiveObjects(includeInactive);
}

// Gets all the enabled DaggerfallStaticDoors components from active registered RDBs
public static IEnumerable<DaggerfallStaticDoors> GetActiveRDBStaticDoors()
{
return rdbCache.GetActiveComponents<DaggerfallStaticDoors>();
return GetActiveRDBStaticDoors(false);
}

public static IEnumerable<DaggerfallStaticDoors> GetActiveRDBStaticDoors(bool includeInactive)
{
return rdbCache.GetActiveComponents<DaggerfallStaticDoors>(includeInactive);
}

// Registers a Daggerfall dungeon block "RDB" game object to the RDB cache. Does not have to be active
Expand All @@ -363,6 +489,7 @@ public static IEnumerable<string> GetCacheDebugLines()
yield return staticNpcCache.GetDebugString();
yield return actionDoorCache.GetDebugString();
yield return rdbCache.GetDebugString();
yield return billboardCache.GetDebugString();
}
}
}
}
Loading