1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef R2_VISUAL_DISPLAYER_GROUP_H
18 #define R2_VISUAL_DISPLAYER_GROUP_H
20 #include "displayer_visual.h"
21 #include "prim_render.h"
22 #include "island_collision.h"
24 #include "nel/3d/u_instance.h"
26 #include "nel/misc/polygon.h"
38 * Display an instance in a R2 scenario as a primitive. (through the CPrimRender class)
39 * Display is made in both the 3D scene and the world map.
41 * This displayer is intended to be used for compound objects display
42 * The displayer will look into a sub-instance array in the displayed instance to find the vertices of the primitive
45 * The displayer is initialized from a lua table, (instance displayers are defined in their lua class definition, see base_class.lua for details)
48 * \TODO: rename this into CDisplayerVisualPrimitive (would be more informative)
50 class CDisplayerVisualGroup
: public CDisplayerVisual
53 typedef NLMISC::CRefPtr
<CDisplayerVisualGroup
> TRefPtr
;
54 enum TShape
{ Star
, PolyLine
, ClosedPolyLine
, ShapeCount
};
55 NLMISC_DECLARE_CLASS(R2::CDisplayerVisualGroup
);
57 CDisplayerVisualGroup ();
58 /** Init from a lua table : T
59 * The 'Shape' field is a string that give the shape (same values than the TShape enum).
60 * The 'Array' field is a string that give the name of the sub-instance array containing the primitive vertices
62 virtual bool init(const CLuaObject
¶meters
);
64 ~CDisplayerVisualGroup();
66 virtual void onPreRender();
67 virtual void onPostRender();
68 virtual void onFocus(bool focused
);
69 virtual void onSelect(bool selected
);
70 virtual void onAttrModified(const std::string
&attrName
, sint32 attrIndex
);
72 virtual void onParentDisplayModeChanged();
73 //virtual void onTableModified(const std::string &tableName, const std::string &keyInTable, sint32 indexInTable);
74 // eval of link point returns first vetrex
75 virtual NLMISC::CVector
evalLinkPoint(bool leader
);
76 virtual bool evalEnterPoint(const NLMISC::CVector
&startPoint
, NLMISC::CVector
&result
);
77 virtual NLMISC::CVector
evalExitPoint();
78 // from ISelectableObject
79 virtual TSelectionType
getSelectionType() const { return GroundProjected
; }
80 virtual bool isInProjection(const NLMISC::CVector2f
&pos
) const;
81 virtual bool isInProjectionBorder(const NLMISC::CVector2f
&pos
) const;
82 // see if a position if over an edge, return the edge index in this case, or -1 if not found
83 virtual sint
isOnEdge(const NLMISC::CVector2f
&pos
) const;
84 const NLMISC::CMatrix
&getInvertedMatrix() const;
85 uint
getFadeTimeInMS() const;
86 virtual void getSons(std::vector
<CDisplayerVisual
*> &sons
) const;
87 // from CDisplayerVisual
88 virtual bool isInvalidPacsPosAcceptable() const { return false; }
89 virtual void getSonsWorldPos2f(std::vector
<NLMISC::CVector2f
> &result
);
90 virtual uint
getNumSons() const;
91 virtual CDisplayerVisual
*getSon(uint index
) const;
92 virtual bool isAccessible();
93 virtual bool isGroup() const { return true; }
94 virtual bool isValidShape() const { return _CurrPrimValid
; }
95 virtual bool isCompound() const { return true; }
96 virtual void setDisplayMode(sint32 mode
);
98 /** Active contextual visibility. This is road / region specific
99 * In this mode, the road or the region is only displayed if some entity is attached to it
102 void setContextualVisibilityActive(bool active
);
103 bool getContextualVisibilityActive() const { return _ContextualVisibilityActive
; }
104 /** If contextual is enabled, tells whether this object is visible with current context
105 * Actually when one entity uses that road / region
107 bool isContextuallyVisible();
110 // from CVisualDisplayer
111 virtual TDisplayMode
getActualDisplayMode() const;
113 REFLECT_EXPORT_START(R2::CDisplayerVisualGroup
, R2::CDisplayerBase
)
114 REFLECT_BOOL("ContextualVisibilityActive", getContextualVisibilityActive
, setContextualVisibilityActive
);
118 mutable std::vector
<CDisplayerVisual
*> _Instances
;
119 /** Special CRenderPrim : when 'in world map' intersection test is done, the CCtrlPolygon will
120 * allow to know which CInstance is actually displayed by this polygon.
121 * This is because the CPrimRender class does not now anything about R2::CInstance or anything related to the scenario...
123 class CSelectablePrimRender
: public CPrimRender
126 CSelectablePrimRender() : DisplayedInstance(NULL
) {}
128 virtual CCtrlPolygon
*newCtrlPolygon() const;
130 virtual CCtrlQuad
*newCtrlQuad(uint edgeIndex
) const;
131 CInstance
*DisplayedInstance
;
133 CSelectablePrimRender _Prim
; // rendering of edges in the worldmap
134 CPrimRender _InaccessiblePrim
; // inaccessible parts of primitive
136 CPrimLook _PrimLookInvalid
;
137 bool _CurrPrimValid
; // is the current polygon valid (e.g can be split into convex polys ?)
138 bool _CurrPrimInaccessible
;
139 mutable bool _PrimTouched
;
140 mutable bool _InstanceListTouched
;
141 mutable bool _AccessibilityTouched
;
142 bool _DrawnThisFrame
;
144 bool _ContextualVisibilityActive
; // when true, visibility depends on current selection : group must be part of selectedentity sequence
146 sint64 _ContextualVisibilityDate
;
147 bool _VisibleLastFrame
;
148 mutable NLMISC::CPolygon2D _Poly2D
;
149 mutable NLMISC::CAABBox _BBox
;
150 std::string _ArrayName
; // name of the array containing the sons
152 CRefCountedPackedWorld::TSmartPtr _LastIsland
;
154 NLMISC::CVector
evalLinkPoint(CEntityCL
&entity
);
156 void updateInstanceList() const;
157 void updatePrimVertices();
158 void updateAccessibility();
159 void updateBoundingBox();
160 void updatePrimLook();
163 // from CDisplayerVisual
164 virtual void setActive(bool active
);
165 virtual bool getActive() const;
166 virtual void updateWorldPos();
167 // from CDisplayerBase
168 virtual void setDisplayedInstance(CInstance
*instance
);
170 virtual void setActiveRecurse(bool active
);
171 void setContextualVisibilityDate(sint64 date
) { _ContextualVisibilityDate
= date
; }