Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ICmpVisual.h
Go to the documentation of this file.
1 /* Copyright (C) 2013 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. 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 General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDED_ICMPVISUAL
19 #define INCLUDED_ICMPVISUAL
20 
22 
23 #include "ps/CStr.h"
26 #include "maths/Fixed.h"
27 #include "lib/file/vfs/vfs_path.h"
28 
29 class CUnit;
30 
31 /**
32  * The visual representation of an entity (typically an actor).
33  */
34 class ICmpVisual : public IComponent
35 {
36 public:
37  /**
38  * Get the world-space bounding box of the object's visual representation.
39  * (Not safe for use in simulation code.)
40  */
41  virtual CBoundingBoxAligned GetBounds() = 0;
42 
43  /**
44  * Get the oriented world-space bounding box of the object's visual representation, clipped at the Y=0 plane in object space
45  * to prevent it from extending into the terrain. The primary difference with GetBounds is that this bounding box is not aligned
46  * to the world axes, but arbitrarily rotated according to the model transform.
47  */
49 
50  /**
51  * Get the world-space position of the base point of the object's visual representation.
52  * (Not safe for use in simulation code.)
53  */
54  virtual CVector3D GetPosition() = 0;
55 
56  /**
57  * Return the short name of the actor that's being displayed, or the empty string on error.
58  * (Not safe for use in simulation code.)
59  */
60  virtual std::wstring GetActorShortName() = 0;
61 
62  /**
63  * Return the filename of the actor to be used for projectiles from this unit, or the empty string if none.
64  * (Not safe for use in simulation code.)
65  */
66  virtual std::wstring GetProjectileActor() = 0;
67 
68  /**
69  * Return the exact position where a projectile should be launched from (based on the actor's
70  * ammo prop points).
71  * Returns (0,0,0) if no point can be found.
72  */
73  virtual CVector3D GetProjectileLaunchPoint() = 0;
74 
75  /**
76  * Returns the underlying unit of this visual actor. May return NULL to indicate that no unit exists (e.g. may happen if the
77  * game is started without graphics rendering).
78  * Originally intended for introspection purposes in Atlas; for other purposes, consider using a specialized getter first.
79  */
80  virtual CUnit* GetUnit() = 0;
81 
82  /**
83  * Start playing the given animation. If there are multiple possible animations then it will
84  * pick one at random (not network-synchronised).
85  * If @p soundgroup is specified, then the sound will be played at each 'event' point in the
86  * animation cycle.
87  * @param name animation name (e.g. "idle", "walk", "melee"; the names are determined by actor XML files)
88  * @param once if true then the animation will play once and freeze at the final frame, else it will loop
89  * @param speed animation speed multiplier (typically 1.0 for the default speed)
90  * @param soundgroup VFS path of sound group .xml, relative to audio/, or empty string for none
91  */
92  virtual void SelectAnimation(std::string name, bool once, fixed speed, std::wstring soundgroup) = 0;
93 
94  /**
95  * Replaces a specified animation with another. Only affects the special speed-based
96  * animation determination behaviour.
97  * @param name Animation to match.
98  * @param replace Animation that should replace the matched animation.
99  */
100  virtual void ReplaceMoveAnimation(std::string name, std::string replace) = 0;
101 
102  /**
103  * Ensures that the given animation will be used when it normally would be,
104  * removing reference to any animation that might replace it.
105  * @param name Animation name to remove from the replacement map.
106  */
107  virtual void ResetMoveAnimation(std::string name) = 0;
108 
109  /**
110  * Sets the specified entity selection on the underlying unit.
111  */
112  virtual void SetUnitEntitySelection(const CStr& selection) = 0;
113 
114  /**
115  * Start playing the walk/run animations, scaled to the unit's movement speed.
116  * @param runThreshold movement speed at which to switch to the run animation
117  */
118  virtual void SelectMovementAnimation(fixed runThreshold) = 0;
119 
120  /**
121  * Adjust the speed of the current animation, so it can match simulation events.
122  * @param repeattime time for complete loop of animation, in msec
123  */
124  virtual void SetAnimationSyncRepeat(fixed repeattime) = 0;
125 
126  /**
127  * Adjust the offset of the current animation, so it can match simulation events.
128  * @param actiontime time between now and when the 'action' event should occur, in msec
129  */
130  virtual void SetAnimationSyncOffset(fixed actiontime) = 0;
131 
132  /**
133  * Set the shading colour that will be modulated with the model's textures.
134  * Default shading is (1, 1, 1, 1).
135  * Alpha should probably be 1 else it's unlikely to work properly.
136  * @param r red component, expected range [0, 1]
137  * @param g green component, expected range [0, 1]
138  * @param b blue component, expected range [0, 1]
139  * @param a alpha component, expected range [0, 1]
140  */
141  virtual void SetShadingColour(fixed r, fixed g, fixed b, fixed a) = 0;
142 
143  /**
144  * Set an arbitrarily-named variable that the model may use to alter its appearance
145  * (e.g. in particle emitter parameter computations).
146  */
147  virtual void SetVariable(std::string name, float value) = 0;
148 
149  /**
150  * Get actor seed used for random variations
151  */
152  virtual u32 GetActorSeed() = 0;
153 
154  /**
155  * Set actor seed for random variations and reload model
156  */
157  virtual void SetActorSeed(u32 seed) = 0;
158 
159  /**
160  * Returns true if this entity should have a construction preview
161  */
162  virtual bool HasConstructionPreview() = 0;
163 
164  /**
165  * Set construction progress of the model, this affects the rendered position of the model.
166  * 0.0 will be fully underground, 1.0 will be fully visible, 0.5 will be half underground.
167  */
168  virtual void SetConstructionProgress(fixed progress) = 0;
169 
170  /**
171  * Called when an actor file has been modified and reloaded dynamically.
172  * If this component uses the named actor file, it should regenerate its actor
173  * to pick up the new definitions.
174  */
175  virtual void Hotload(const VfsPath& name) = 0;
176 
177  DECLARE_INTERFACE_TYPE(Visual)
178 };
179 
180 // TODO: rename this to VisualActor, because the interface is actor-specific, maybe?
181 
182 #endif // INCLUDED_ICMPVISUAL
A simple fixed-point number class.
Definition: Fixed.h:115
virtual CVector3D GetProjectileLaunchPoint()=0
Return the exact position where a projectile should be launched from (based on the actor&#39;s ammo prop ...
virtual CUnit * GetUnit()=0
Returns the underlying unit of this visual actor.
virtual void SetVariable(std::string name, float value)=0
Set an arbitrarily-named variable that the model may use to alter its appearance (e.g.
virtual CVector3D GetPosition()=0
Get the world-space position of the base point of the object&#39;s visual representation.
virtual void SelectAnimation(std::string name, bool once, fixed speed, std::wstring soundgroup)=0
Start playing the given animation.
Definition: Unit.h:35
virtual void SetShadingColour(fixed r, fixed g, fixed b, fixed a)=0
Set the shading colour that will be modulated with the model&#39;s textures.
virtual std::wstring GetProjectileActor()=0
Return the filename of the actor to be used for projectiles from this unit, or the empty string if no...
virtual CBoundingBoxOriented GetSelectionBox()=0
Get the oriented world-space bounding box of the object&#39;s visual representation, clipped at the Y=0 p...
virtual void ReplaceMoveAnimation(std::string name, std::string replace)=0
Replaces a specified animation with another.
virtual void Hotload(const VfsPath &name)=0
Called when an actor file has been modified and reloaded dynamically.
Definition: path.h:75
virtual u32 GetActorSeed()=0
Get actor seed used for random variations.
#define DECLARE_INTERFACE_TYPE(iname)
Definition: Interface.h:23
virtual void SetAnimationSyncRepeat(fixed repeattime)=0
Adjust the speed of the current animation, so it can match simulation events.
virtual bool HasConstructionPreview()=0
Returns true if this entity should have a construction preview.
#define u32
Definition: types.h:41
virtual void SetUnitEntitySelection(const CStr &selection)=0
Sets the specified entity selection on the underlying unit.
virtual CBoundingBoxAligned GetBounds()=0
Get the world-space bounding box of the object&#39;s visual representation.
virtual void ResetMoveAnimation(std::string name)=0
Ensures that the given animation will be used when it normally would be, removing reference to any an...
virtual void SetAnimationSyncOffset(fixed actiontime)=0
Adjust the offset of the current animation, so it can match simulation events.
virtual void SelectMovementAnimation(fixed runThreshold)=0
Start playing the walk/run animations, scaled to the unit&#39;s movement speed.
virtual void SetConstructionProgress(fixed progress)=0
Set construction progress of the model, this affects the rendered position of the model...
virtual void SetActorSeed(u32 seed)=0
Set actor seed for random variations and reload model.
virtual std::wstring GetActorShortName()=0
Return the short name of the actor that&#39;s being displayed, or the empty string on error...
The visual representation of an entity (typically an actor).
Definition: ICmpVisual.h:34