Cafu Engine
CaPVSWorld.hpp
1 /*
2 Cafu Engine, http://www.cafu.de/
3 Copyright (c) Carsten Fuchs and other contributors.
4 This project is licensed under the terms of the MIT license.
5 */
6 
7 /****************************/
8 /*** CaPVS World (Header) ***/
9 /****************************/
10 
11 #ifndef CAFU_CAPVSWORLD_HPP_INCLUDED
12 #define CAFU_CAPVSWORLD_HPP_INCLUDED
13 
14 #include "../Common/World.hpp"
15 
16 
17 struct SuperLeafT
18 {
19  struct NeighbourT
20  {
21  unsigned long SuperLeafNr; ///< Der Nachbar ist ein SuperLeaf, und hat die Indexnummer 'SuperLeafNr'.
22  Polygon3T<double> SubPortal; ///< Das zum Nachbar führende (Sub-)Portal.
23  };
24 
25  ArrayT<unsigned long> LeafSet; ///< Die Menge der Map-Leaves, aus denen dieses SuperLeaf ursprünglich besteht.
26  ArrayT< Polygon3T<double> > Portals; ///< Die Portals dieses SuperLeafs, d.h. ALLE Portals ALLER Leaves des LeafSet.
27  BoundingBox3T<double> BB; ///< Die BoundingBox der BoundingBoxes der Leaves im LeafSet.
28  ArrayT<NeighbourT> Neighbours; ///< Die Nachbarn dieses SuperLeafs.
29 };
30 
31 
33 {
34  private:
35 
36  WorldT m_World;
38 
39  unsigned long SLC_MaxRecursionDepth;
40  double SLC_MinSubTreeFacesArea;
41 
42  double SubTreeFacesArea (unsigned long NodeNr) const;
43  bool SuperLeafConditionIsMet (unsigned long NodeNr, unsigned long RecursionDepth) const;
44  void CreateSuperLeafFromSubTreeRecursive(unsigned long NodeNr, SuperLeafT& SuperLeaf) const;
45  SuperLeafT CreateSuperLeafFromSubTree (unsigned long NodeNr) const;
46  void CreateSuperLeavesRecursive (unsigned long NodeNr, ArrayT<SuperLeafT>& SuperLeaves, unsigned long RecursionDepth) const;
47 
48 
49  public:
50 
51  // Constructor.
52  CaPVSWorldT(const char* FileName, ModelManagerT& ModelMan, cf::GuiSys::GuiResourcesT& GuiRes, unsigned long SLC_MaxRecursionDepth_, double SLC_MinSubTreeFacesArea_);
53 
54  // This functions creates the 'SuperLeaves' from the world leaves. Notes:
55  // a) There is no need at all to differentiate between inner and outer leaves.
56  // They are both treated the same, outer leaves just don't have any portals.
57  // b) It is well possible that the resulting 'SuperLeaves' will not differ from the original 'Leaves',
58  // because in cases where the BSP tree depth is not limited, the end result is equivalent to the old, best-quality mode.
59  void CreateSuperLeaves(ArrayT<SuperLeafT>& SuperLeaves) const;
60 
61  // This functions forwards the 'WorldT::MapT::WhatLeaf()' function.
62  // It is useful, for example, if CaPVS wants to perform some trivial tests on visibility.
63  unsigned long WhatLeaf(const VectorT& Position) const;
64 
65  // This functions forwards the 'WorldT::MapT::ClipLine()' function, NOT taking terrains into account.
66  // It is useful, for example, if CaPVS wants to perform some trivial tests on visibility.
67  double ClipLine(const VectorT& P, const VectorT& U) const;
68 
69  // Takes the 'SuperLeaves' and the 'SuperLeavesPVS', and constructs the leaf-wise world PVS from it.
70  void StorePVS(const ArrayT<SuperLeafT>& SuperLeaves, const ArrayT<unsigned long>& SuperLeavesPVS);
71 
72  // Prints some statistics and returns a check-sum.
73  unsigned long GetChecksumAndPrintStats() const;
74 
75  // Saves this world to disk.
76  void SaveToDisk(const char* FileName) const;
77 };
78 
79 #endif
unsigned long SuperLeafNr
Der Nachbar ist ein SuperLeaf, und hat die Indexnummer 'SuperLeafNr'.
Definition: CaPVSWorld.hpp:21
Definition: World.hpp:85
Definition: CaPVSWorld.hpp:32
BoundingBox3T< double > BB
Die BoundingBox der BoundingBoxes der Leaves im LeafSet.
Definition: CaPVSWorld.hpp:27
ArrayT< NeighbourT > Neighbours
Die Nachbarn dieses SuperLeafs.
Definition: CaPVSWorld.hpp:28
The class represents a BSP Tree node, implementing the Composite design pattern.
Definition: BspTreeNode.hpp:30
Definition: CaPVSWorld.hpp:17
This class is used for managing model instances.
Definition: ModelManager.hpp:31
ArrayT< Polygon3T< double > > Portals
Die Portals dieses SuperLeafs, d.h. ALLE Portals ALLER Leaves des LeafSet.
Definition: CaPVSWorld.hpp:26
Definition: CaPVSWorld.hpp:19
Polygon3T< double > SubPortal
Das zum Nachbar führende (Sub-)Portal.
Definition: CaPVSWorld.hpp:22
This class manages and provides resources (fonts and models) for GuiImplT instances.
Definition: GuiResources.hpp:26
ArrayT< unsigned long > LeafSet
Die Menge der Map-Leaves, aus denen dieses SuperLeaf ursprünglich besteht.
Definition: CaPVSWorld.hpp:25