Cafu Engine
CompMapEntity.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 #ifndef CAFU_MAPEDITOR_COMPONENT_MAP_ENTITY_HPP_INCLUDED
8 #define CAFU_MAPEDITOR_COMPONENT_MAP_ENTITY_HPP_INCLUDED
9 
10 #include "EntProperty.hpp"
11 #include "GameSys/CompBase.hpp"
12 #include "GameSys/Entity.hpp" // For GetMapEnt() only.
13 #include "Math3D/Angles.hpp"
14 #include "Math3D/BoundingBox.hpp"
15 
16 
17 class MapDocumentT;
18 class MapElementT;
19 class MapEntRepresT;
20 class MapPrimitiveT;
21 class wxProgressDialog;
22 
23 
24 namespace MapEditor
25 {
26  /// This component houses the Map Editor specific parts of its entity.
27  /// It is intended for use by the Map Editor application only, that is, as the "App" component of `cf::GameSys::EntityT`s.
28  /// As such, it doesn't integrate with the TypeSys, and thus isn't available for scripting and whereever else we need
29  /// the related meta-data.
31  {
32  public:
33 
34  /// The constructor.
36 
37  /// The copy constructor. It creates a new component as a copy of another component.
38  ///
39  /// Note that the new map entity is created without any primitives, that is, the primitives are
40  /// intentionally *not* copied from `Comp`. This is because it is easy to call CopyPrimitives()
41  /// with the new instance if the user code wants to have the map primitives copied as well,
42  /// whereas the reverse would be very difficult to handle.
43  ///
44  /// (If primitives were copied per default, having them not copied when they are not wanted
45  /// would require another parameter to the copy constructor -- which had to be passed through by
46  /// the EntityT copy constructors and Clone() methods as well as by all Clone() methods in the
47  /// ComponentBaseT hierarchy. This would be difficult to understand and bother large amounts of
48  /// completely unrelated code.)
49  ///
50  /// @param Comp The component to copy-construct this component from.
51  CompMapEntityT(const CompMapEntityT& Comp);
52 
53  /// The destructor.
55 
56  // Base class overrides.
57  CompMapEntityT* Clone() const;
58  const char* GetName() const { return "MapEntity"; }
59  void Render() const;
60 
61 
62  void Load_cmap (TextParserT& TP, MapDocumentT& MapDoc, wxProgressDialog* ProgressDialog, unsigned long EntityNr, unsigned int& cmapVersion, bool IgnoreGroups);
63  void Load_HL1_map(TextParserT& TP, MapDocumentT& MapDoc, wxProgressDialog* ProgressDialog, unsigned long EntityNr);
64  void Load_HL2_vmf(TextParserT& TP, MapDocumentT& MapDoc, wxProgressDialog* ProgressDialog, unsigned long EntityNr);
65  void Load_D3_map (TextParserT& TP, MapDocumentT& MapDoc, wxProgressDialog* ProgressDialog, unsigned long EntityNr);
66  void Save_cmap(const MapDocumentT& MapDoc, std::ostream& OutFile, unsigned long EntityNr, const BoundingBox3fT* Intersecting) const;
67 
68 
69  MapDocumentT& GetDoc() const { return m_MapDoc; }
70 
71  bool IsWorld() const;
72 
73  const ArrayT<EntPropertyT>& GetProperties() const { return m_Properties; }
74  ArrayT<EntPropertyT>& GetProperties() { return m_Properties; }
75 
76  EntPropertyT* FindProperty (const wxString& Key, int* Index=NULL, bool Create=false); ///< Find the property.
77  const EntPropertyT* FindProperty (const wxString& Key, int* Index=NULL) const; ///< Find the property.
78  void RemoveProperty(const wxString& Key); ///< Remove this property.
79  std::string GetProperty(const wxString& Key, const char* Default="") const; ///< Returns the value of this property, using the default if not found.
80  std::string GetAndRemove(const wxString& Key, const char* Default=""); ///< Returns the value of this property, using the default if not found, and removes it.
81 
82  MapEntRepresT* GetRepres() const { return m_Repres; }
83 
84  const ArrayT<MapPrimitiveT*>& GetPrimitives() const { return m_Primitives; }
85 
86  /// Creates a copy of each primitive in MapEnt and adds it to this instance.
87  /// If `Recursive` is true, the primitives of all child entities are copied recursively
88  /// (as far as the two entity hierarchies match).
89  void CopyPrimitives(const CompMapEntityT& MapEnt, bool Recursive = false);
90 
91  void AddPrim(MapPrimitiveT* Prim);
92  void RemovePrim(MapPrimitiveT* Prim);
93 
94  /// Returns all map elements (the representation and the primitives) of this entity and of all of its children.
96 
97  /// Returns the "overall" bounding-box of this entity.
98  /// The returned bounding-box contains all elements (the representation and all primitives) of this entity.
99  BoundingBox3fT GetElemsBB() const;
100 
101 
102  private:
103 
104  MapDocumentT& m_MapDoc; ///< The document that contains, keeps and manages this entity.
105  ArrayT<EntPropertyT> m_Properties; ///< Properties associated with this entity. Obsolete, kept so that we can import old or foreign map file formats.
106  MapEntRepresT* m_Repres; ///< The graphical representation of this entity in the map.
107  ArrayT<MapPrimitiveT*> m_Primitives; ///< The primitive, atomic elements of this entity (brushes, patches, terrains, models, plants, ...).
108  };
109 
110 
112  {
113  return dynamic_pointer_cast<CompMapEntityT>(Entity->GetApp());
114  }
115 }
116 
117 #endif
This class represents a CaWE "map" document.
Definition: MapDocument.hpp:45
const char * GetName() const
Returns the name of this component.
Definition: CompMapEntity.hpp:58
CompMapEntityT(MapDocumentT &MapDoc)
The constructor.
Definition: CompMapEntity.cpp:16
EntPropertyT * FindProperty(const wxString &Key, int *Index=NULL, bool Create=false)
Find the property.
Definition: CompMapEntity.cpp:67
This class adds no functionality of its own, but only exists for proper type separation.
Definition: MapPrimitive.hpp:21
void RemoveProperty(const wxString &Key)
Remove this property.
Definition: CompMapEntity.cpp:112
BoundingBox3fT GetElemsBB() const
Returns the "overall" bounding-box of this entity.
Definition: CompMapEntity.cpp:218
ArrayT< MapElementT * > GetAllMapElements() const
Returns all map elements (the representation and the primitives) of this entity and of all of its chi...
Definition: CompMapEntity.cpp:197
IntrusivePtrT< ComponentBaseT > GetApp()
Returns the application component of this entity.
Definition: Entity.hpp:128
std::string GetAndRemove(const wxString &Key, const char *Default="")
Returns the value of this property, using the default if not found, and removes it.
Definition: CompMapEntity.cpp:133
std::string GetProperty(const wxString &Key, const char *Default="") const
Returns the value of this property, using the default if not found.
Definition: CompMapEntity.cpp:123
void CopyPrimitives(const CompMapEntityT &MapEnt, bool Recursive=false)
Creates a copy of each primitive in MapEnt and adds it to this instance.
Definition: CompMapEntity.cpp:147
~CompMapEntityT()
The destructor.
Definition: CompMapEntity.cpp:39
Definition: EntProperty.hpp:18
void Load_HL2_vmf(TextParserT &TP, MapDocumentT &MapDoc, wxProgressDialog *ProgressDialog, unsigned long EntityNr)
This method reads a "world" or "entity" chunk.
Definition: Load_HL2_vmf.cpp:175
CompMapEntityT * Clone() const
The virtual copy constructor.
Definition: CompMapEntity.cpp:50
This class provides a graphical representation of an entity in the Map Editor.
Definition: MapEntRepres.hpp:20
This component houses the Map Editor specific parts of its entity.
Definition: CompMapEntity.hpp:30
This is the base class for all elements ("objects") that can exist in a map.
Definition: MapElement.hpp:57
This is the base class for the components that an entity is composed/aggregated of.
Definition: CompBase.hpp:54
This is a class for parsing text.
Definition: TextParser.hpp:21