| 1 | /* |
|---|
| 2 | ================================================================================= |
|---|
| 3 | This file is part of Cafu, the open-source game engine and graphics engine |
|---|
| 4 | for multiplayer, cross-platform, real-time 3D action. |
|---|
| 5 | Copyright (C) 2002-2012 Carsten Fuchs Software. |
|---|
| 6 | |
|---|
| 7 | Cafu is free software: you can redistribute it and/or modify it under the terms |
|---|
| 8 | of the GNU General Public License as published by the Free Software Foundation, |
|---|
| 9 | either version 3 of the License, or (at your option) any later version. |
|---|
| 10 | |
|---|
| 11 | Cafu is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
|---|
| 12 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|---|
| 13 | PURPOSE. See the GNU General Public License for more details. |
|---|
| 14 | |
|---|
| 15 | You should have received a copy of the GNU General Public License |
|---|
| 16 | along with Cafu. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 17 | |
|---|
| 18 | For support and more information about Cafu, visit us at <http://www.cafu.de>. |
|---|
| 19 | ================================================================================= |
|---|
| 20 | */ |
|---|
| 21 | |
|---|
| 22 | /****************************/ |
|---|
| 23 | /*** CaPVS World (Header) ***/ |
|---|
| 24 | /****************************/ |
|---|
| 25 | |
|---|
| 26 | #ifndef CAFU_CAPVSWORLD_HPP_INCLUDED |
|---|
| 27 | #define CAFU_CAPVSWORLD_HPP_INCLUDED |
|---|
| 28 | |
|---|
| 29 | #include "../Common/World.hpp" |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | struct SuperLeafT |
|---|
| 33 | { |
|---|
| 34 | struct NeighbourT |
|---|
| 35 | { |
|---|
| 36 | unsigned long SuperLeafNr; ///< Der Nachbar ist ein SuperLeaf, und hat die Indexnummer 'SuperLeafNr'. |
|---|
| 37 | Polygon3T<double> SubPortal; ///< Das zum Nachbar führende (Sub-)Portal. |
|---|
| 38 | }; |
|---|
| 39 | |
|---|
| 40 | ArrayT<unsigned long> LeafSet; ///< Die Menge der Map-Leaves, aus denen dieses SuperLeaf ursprünglich besteht. |
|---|
| 41 | ArrayT< Polygon3T<double> > Portals; ///< Die Portals dieses SuperLeafs, d.h. ALLE Portals ALLER Leaves des LeafSet. |
|---|
| 42 | BoundingBox3T<double> BB; ///< Die BoundingBox der BoundingBoxes der Leaves im LeafSet. |
|---|
| 43 | ArrayT<NeighbourT> Neighbours; ///< Die Nachbarn dieses SuperLeafs. |
|---|
| 44 | }; |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | class CaPVSWorldT |
|---|
| 48 | { |
|---|
| 49 | private: |
|---|
| 50 | |
|---|
| 51 | WorldT World; |
|---|
| 52 | |
|---|
| 53 | unsigned long SLC_MaxRecursionDepth; |
|---|
| 54 | double SLC_MinSubTreeFacesArea; |
|---|
| 55 | |
|---|
| 56 | double SubTreeFacesArea (unsigned long NodeNr) const; |
|---|
| 57 | bool SuperLeafConditionIsMet (unsigned long NodeNr, unsigned long RecursionDepth) const; |
|---|
| 58 | void CreateSuperLeafFromSubTreeRecursive(unsigned long NodeNr, SuperLeafT& SuperLeaf) const; |
|---|
| 59 | SuperLeafT CreateSuperLeafFromSubTree (unsigned long NodeNr) const; |
|---|
| 60 | void CreateSuperLeavesRecursive (unsigned long NodeNr, ArrayT<SuperLeafT>& SuperLeaves, unsigned long RecursionDepth) const; |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | public: |
|---|
| 64 | |
|---|
| 65 | // Constructor. |
|---|
| 66 | CaPVSWorldT(const char* FileName, ModelManagerT& ModelMan, unsigned long SLC_MaxRecursionDepth_, double SLC_MinSubTreeFacesArea_); |
|---|
| 67 | |
|---|
| 68 | // This functions creates the 'SuperLeaves' from the world leaves. Notes: |
|---|
| 69 | // a) There is no need at all to differentiate between inner and outer leaves. |
|---|
| 70 | // They are both treated the same, outer leaves just don't have any portals. |
|---|
| 71 | // b) It is well possible that the resulting 'SuperLeaves' will not differ from the original 'Leaves', |
|---|
| 72 | // because in cases where the BSP tree depth is not limited, the end result is equivalent to the old, best-quality mode. |
|---|
| 73 | void CreateSuperLeaves(ArrayT<SuperLeafT>& SuperLeaves) const; |
|---|
| 74 | |
|---|
| 75 | // This functions forwards the 'WorldT::MapT::WhatLeaf()' function. |
|---|
| 76 | // It is useful, for example, if CaPVS wants to perform some trivial tests on visibility. |
|---|
| 77 | unsigned long WhatLeaf(const VectorT& Position) const; |
|---|
| 78 | |
|---|
| 79 | // This functions forwards the 'WorldT::MapT::ClipLine()' function, NOT taking terrains into account. |
|---|
| 80 | // It is useful, for example, if CaPVS wants to perform some trivial tests on visibility. |
|---|
| 81 | double ClipLine(const VectorT& P, const VectorT& U) const; |
|---|
| 82 | |
|---|
| 83 | // Takes the 'SuperLeaves' and the 'SuperLeavesPVS', and constructs the leaf-wise world PVS from it. |
|---|
| 84 | void StorePVS(const ArrayT<SuperLeafT>& SuperLeaves, const ArrayT<unsigned long>& SuperLeavesPVS); |
|---|
| 85 | |
|---|
| 86 | // Prints some statistics and returns a check-sum. |
|---|
| 87 | unsigned long GetChecksumAndPrintStats() const; |
|---|
| 88 | |
|---|
| 89 | // Saves this world to disk. |
|---|
| 90 | void SaveToDisk(const char* FileName) const; |
|---|
| 91 | }; |
|---|
| 92 | |
|---|
| 93 | #endif |
|---|