Pyrogenesis  trunk
ICmpVisual.h
Go to the documentation of this file.
1 /* Copyright (C) 2017 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() const = 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  */
48  virtual CBoundingBoxOriented GetSelectionBox() const = 0;
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() const = 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() const = 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() const = 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() const = 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  * Set the variant selection of the actor for a certain key.
84  * This overrides a previous selection on that key, so every component
85  * should use unique keys.
86  */
87  virtual void SetVariant(const CStr& key, const CStr& selection) = 0;
88 
89  /**
90  * Returns the name of the currently played animation.
91  */
92  virtual std::string GetAnimationName() const = 0;
93 
94  /**
95  * Start playing the given animation. If there are multiple possible animations then it will
96  * pick one at random (not network-synchronised).
97  * If @p soundgroup is specified, then the sound will be played at each 'event' point in the
98  * animation cycle.
99  * @param name animation name (e.g. "idle", "walk", "melee"; the names are determined by actor XML files)
100  * @param once if true then the animation will play once and freeze at the final frame, else it will loop
101  * @param speed animation speed multiplier (typically 1.0 for the default speed)
102  * @param soundgroup VFS path of sound group .xml, relative to audio/, or empty string for none
103  */
104  virtual void SelectAnimation(const std::string& name, bool once, fixed speed, const std::wstring& soundgroup) = 0;
105 
106  /**
107  * Replaces a specified animation with another. Only affects the special speed-based
108  * animation determination behaviour.
109  * @param name Animation to match.
110  * @param replace Animation that should replace the matched animation.
111  */
112  virtual void ReplaceMoveAnimation(const std::string& name, const std::string& replace) = 0;
113 
114  /**
115  * Ensures that the given animation will be used when it normally would be,
116  * removing reference to any animation that might replace it.
117  * @param name Animation name to remove from the replacement map.
118  */
119  virtual void ResetMoveAnimation(const std::string& name) = 0;
120 
121  /**
122  * Start playing the walk/run animations, scaled to the unit's movement speed.
123  * @param runThreshold movement speed at which to switch to the run animation
124  */
125  virtual void SelectMovementAnimation(fixed runThreshold) = 0;
126 
127  /**
128  * Adjust the speed of the current animation, so it can match simulation events.
129  * @param repeattime time for complete loop of animation, in msec
130  */
131  virtual void SetAnimationSyncRepeat(fixed repeattime) = 0;
132 
133  /**
134  * Adjust the offset of the current animation, so it can match simulation events.
135  * @param actiontime time between now and when the 'action' event should occur, in msec
136  */
137  virtual void SetAnimationSyncOffset(fixed actiontime) = 0;
138 
139  /**
140  * Set the shading color that will be modulated with the model's textures.
141  * Default shading is (1, 1, 1, 1).
142  * Alpha should probably be 1 else it's unlikely to work properly.
143  * @param r red component, expected range [0, 1]
144  * @param g green component, expected range [0, 1]
145  * @param b blue component, expected range [0, 1]
146  * @param a alpha component, expected range [0, 1]
147  */
148  virtual void SetShadingColor(fixed r, fixed g, fixed b, fixed a) = 0;
149 
150  /**
151  * Set an arbitrarily-named variable that the model may use to alter its appearance
152  * (e.g. in particle emitter parameter computations).
153  */
154  virtual void SetVariable(const std::string& name, float value) = 0;
155 
156  /**
157  * Get actor seed used for random variations
158  */
159  virtual u32 GetActorSeed() const = 0;
160 
161  /**
162  * Set actor seed for random variations and reload model
163  */
164  virtual void SetActorSeed(u32 seed) = 0;
165 
166  /**
167  * Returns true if this entity should have a construction preview
168  */
169  virtual bool HasConstructionPreview() const = 0;
170 
171  /**
172  * Called when an actor file has been modified and reloaded dynamically.
173  * If this component uses the named actor file, it should regenerate its actor
174  * to pick up the new definitions.
175  */
176  virtual void Hotload(const VfsPath& name) = 0;
177 
178  DECLARE_INTERFACE_TYPE(Visual)
179 };
180 
181 // TODO: rename this to VisualActor, because the interface is actor-specific, maybe?
182 
183 #endif // INCLUDED_ICMPVISUAL
Definition: IComponent.h:33
A simple fixed-point number class.
Definition: Fixed.h:115
virtual bool HasConstructionPreview() const =0
Returns true if this entity should have a construction preview.
virtual std::wstring GetActorShortName() const =0
Return the short name of the actor that&#39;s being displayed, or the empty string on error...
virtual void SetVariant(const CStr &key, const CStr &selection)=0
Set the variant selection of the actor for a certain key.
virtual CUnit * GetUnit()=0
Returns the underlying unit of this visual actor.
Definition: Vector3D.h:28
virtual std::wstring GetProjectileActor() const =0
Return the filename of the actor to be used for projectiles from this unit, or the empty string if no...
Definition: Unit.h:36
virtual void SelectAnimation(const std::string &name, bool once, fixed speed, const std::wstring &soundgroup)=0
Start playing the given animation.
virtual u32 GetActorSeed() const =0
Get actor seed used for random variations.
virtual void Hotload(const VfsPath &name)=0
Called when an actor file has been modified and reloaded dynamically.
uint32_t u32
Definition: types.h:39
virtual void SetShadingColor(fixed r, fixed g, fixed b, fixed a)=0
Set the shading color that will be modulated with the model&#39;s textures.
Definition: path.h:77
virtual void ResetMoveAnimation(const std::string &name)=0
Ensures that the given animation will be used when it normally would be, removing reference to any an...
pthread_key_t key
Definition: wpthread.cpp:140
virtual CBoundingBoxAligned GetBounds() const =0
Get the world-space bounding box of the object&#39;s visual representation.
#define DECLARE_INTERFACE_TYPE(iname)
Definition: Interface.h:23
virtual void SetVariable(const std::string &name, float value)=0
Set an arbitrarily-named variable that the model may use to alter its appearance (e.g.
virtual CVector3D GetProjectileLaunchPoint() const =0
Return the exact position where a projectile should be launched from (based on the actor&#39;s ammo prop ...
virtual std::string GetAnimationName() const =0
Returns the name of the currently played animation.
virtual void SetAnimationSyncRepeat(fixed repeattime)=0
Adjust the speed of the current animation, so it can match simulation events.
virtual void ReplaceMoveAnimation(const std::string &name, const std::string &replace)=0
Replaces a specified animation with another.
Definition: BoundingBoxAligned.h:35
virtual void SetAnimationSyncOffset(fixed actiontime)=0
Adjust the offset of the current animation, so it can match simulation events.
Definition: BoundingBoxOriented.h:30
virtual void SelectMovementAnimation(fixed runThreshold)=0
Start playing the walk/run animations, scaled to the unit&#39;s movement speed.
virtual CBoundingBoxOriented GetSelectionBox() const =0
Get the oriented world-space bounding box of the object&#39;s visual representation, clipped at the Y=0 p...
virtual CVector3D GetPosition() const =0
Get the world-space position of the base point of the object&#39;s visual representation.
virtual void SetActorSeed(u32 seed)=0
Set actor seed for random variations and reload model.
The visual representation of an entity (typically an actor).
Definition: ICmpVisual.h:34