1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) <dfighter1985@gmail.com>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef R2_DISPLAYER_VISUAL_ENTITY_H
21 #define R2_DISPLAYER_VISUAL_ENTITY_H
23 #include "displayer_visual.h"
26 #include "nel/gui/lua_object.h"
27 #include "instance_map_deco.h"
38 class CMapDecoEntity
; // display of entity on the map
39 class CDisplayerVisualShape
;
41 /** Display of entities
43 class CDisplayerVisualEntity
: public CDisplayerVisual
46 typedef NLMISC::CRefPtr
<CDisplayerVisualEntity
> TRefPtr
;
48 enum TSelectionDisplayMode
{ AutoSelection
= 0, BoxSelection
= 1, CircleSelection
= 2, SelectionDisplayModeCount
};
50 NLMISC_DECLARE_CLASS(R2::CDisplayerVisualEntity
);
52 CDisplayerVisualEntity();
54 ~CDisplayerVisualEntity();
59 virtual void onPreRender();
60 virtual void onPostRender();
61 virtual void onAttrModified(const std::string
&name
, sint32 index
);
62 virtual void onSelect(bool selected
);
63 virtual void onPostHrcMove();
64 virtual void onFocus(bool focused
);
65 virtual void onCreate();
66 virtual void onPostCreate();
68 virtual void onParentDisplayModeChanged();
73 std::string
getSheet() const;
74 float getAngle() const { return _Angle
; }
75 std::string
getVisualProperties() const;
76 void setVisualProperties(const std::string
&) {}
78 // from ISelectableObject
79 const NLMISC::CMatrix
&getInvertedMatrix() const;
80 virtual bool getLastClip() const;
81 virtual NLMISC::CAABBox
getSelectBox() const;
82 virtual float preciseIntersectionTest(const NLMISC::CVector
&worldRayStart
, const NLMISC::CVector
&worldRayDir
) const;
87 float getSelectionDecalRadius() const;
88 //virtual NLMISC::CVector evalLinkPoint(bool leader) const;
89 virtual void snapToGround();
90 // Get pointer to client entity that is used to display that object
91 CEntityCL
*getEntity() const { return _Entity
; }
95 void setSlotEntity(sint32
/* val */){}
96 sint32
getSlotEntity() const;
98 // value of type TSelectDisplayMode (uint32 type for script export)
99 void setSelectionDisplayMode(sint32 value
) { _SelectionDisplayMode
= (TSelectionDisplayMode
) ((uint32
) value
% SelectionDisplayModeCount
); }
100 sint32
getSelectionDisplayMode() const { return (sint32
) _SelectionDisplayMode
; }
102 /// Return the entity permanent content texture name.
103 const std::string
&getPermanentStatutIcon() const {return _PermanentStatutIcon
;}
104 /// Change the entity permanent content texture name.
105 void setPermanentStatutIcon(const std::string
&name
) { _PermanentStatutIcon
=name
; }
107 int luaUpdateName(CLuaState
&ls
);
108 int luaUpdatePermanentStatutIcon(CLuaState
&ls
);
109 REFLECT_EXPORT_START(R2::CDisplayerVisualEntity
, R2::CDisplayerVisual
)
111 REFLECT_SINT32("slotEntity", getSlotEntity
, setSlotEntity
);
112 REFLECT_STRING("visualProperties", getVisualProperties
, setVisualProperties
);
113 REFLECT_LUA_METHOD("updateName", luaUpdateName
);
114 REFLECT_LUA_METHOD("updatePermanentStatutIcon", luaUpdatePermanentStatutIcon
);
115 REFLECT_SINT32("SelectionDisplayMode", getSelectionDisplayMode
, setSelectionDisplayMode
);
118 // from ISelectableObject
119 virtual bool isInProjection(const NLMISC::CVector2f
&pos
) const;
120 // from ISelectableObject
121 virtual TSelectionType
getSelectionType() const;
123 // return radius of the cylinder for the collision primitive, or -1 if a box is used
124 float getCylinderRadius() const;
126 // from CDisplayerVisual
127 virtual void setDisplayMode(sint32 mode
);
129 // manage clipping of entity to display then earest entities (and thus bypass the 255 entities limit)
130 void setClipBlend(float amount
);
133 // test if the entity was created by the user right now (not by another user or undo/reload/reload operation)
134 bool isCreatedThisFrame() const;
136 bool isUserCreated() const;
138 // from CDisplayerBase
139 virtual bool maxVisibleEntityExceeded() const;
141 // from CDisplayerVisual
142 virtual void setActive(bool active
);
143 virtual bool getActive() const;
147 uint64 _CreationTimeSwpBufCount
;
148 TSelectionDisplayMode _SelectionDisplayMode
;
150 mutable NLMISC::CMatrix _InvertedMatrix
;
151 mutable bool _InvertedMatrixTouched
;
152 CInstanceMapDeco _MapDeco
;
155 bool _RegisteredInEditor
; // entitiy displayer register themselves in editor (it sorts entities by distance
156 // and display the nearest one by updating their clipping by calling 'setClipAmount')
159 // Current permanent content symbol for the entity
160 std::string _PermanentStatutIcon
;
162 CDisplayerVisualShape
*_PlaceHolder
; // place holder used when there are too many visible entities
165 void deletePlaceHolder();
168 void updateRaceAndSex();
169 void updateEntityWorldPos();
170 void updateEntityRot();
172 void updatePermanentStatutIcon(const std::string
& textureName
);
173 void updateMapDeco();
174 void updateWorldMapPresence();
175 void retrieveAngle();
177 void drawBBox(NLMISC::CRGBA colOverZ
, NLMISC::CRGBA colUnderZ
);
178 void drawBBox(const NLMISC::CMatrix
&modelMatrix
, const NLMISC::CAABBox
&bbox
, NLMISC::CRGBA colOverZ
, NLMISC::CRGBA colUnderZ
);
180 void showHighlighted();
181 void setVisualSelectionBlink(bool on
, NLMISC::CRGBA color
);
182 TSelectionDisplayMode
getActualSelectionDisplayMode() const;
185 // update world position from position property
186 virtual void updateWorldPos();
187 //void updateValidPosFlag();
189 void updateVisibility();