Line data Source code
1 : /* Copyright (C) 2026 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 : 21 : #include "simulation2/system/Interface.h" 22 : 23 : #include "lib/file/vfs/vfs_path.h" 24 : #include "maths/BoundingBoxAligned.h" 25 : #include "maths/BoundingBoxOriented.h" 26 : #include "maths/Fixed.h" 27 : #include "maths/FixedVector3D.h" 28 : #include "maths/Vector3D.h" 29 : #include "ps/CStr.h" 30 : #include "simulation2/system/Component.h" 31 : 32 : #include <js/Value.h> 33 : #include <string> 34 : 35 : class CUnit; 36 : 37 : /** 38 : * The visual representation of an entity (typically an actor). 39 : */ 40 195 : class ICmpVisual : public IComponent 41 : { 42 : public: 43 : /** 44 : * Get the world-space bounding box of the object's visual representation. 45 : * (Not safe for use in simulation code.) 46 : */ 47 : virtual CBoundingBoxAligned GetBounds() const = 0; 48 : 49 : /** 50 : * Get the oriented world-space bounding box of the object's visual representation, clipped at the Y=0 plane in object space 51 : * to prevent it from extending into the terrain. The primary difference with GetBounds is that this bounding box is not aligned 52 : * to the world axes, but arbitrarily rotated according to the model transform. 53 : */ 54 : virtual CBoundingBoxOriented GetSelectionBox() const = 0; 55 : 56 : /** 57 : * Get the world-space position of the base point of the object's visual representation. 58 : * (Not safe for use in simulation code.) 59 : */ 60 : virtual CVector3D GetPosition() 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 : * Return type is CFixedVector3D because it is exposed to the JS interface. 72 : * Returns (0,0,0) if no point can be found. 73 : */ 74 : virtual CFixedVector3D GetProjectileLaunchPoint() const = 0; 75 : 76 : /** 77 : * Returns the underlying unit of this visual actor. May return NULL to indicate that no unit exists (e.g. may happen if the 78 : * game is started without graphics rendering). 79 : * Originally intended for introspection purposes in Atlas; for other purposes, consider using a specialized getter first. 80 : */ 81 : virtual CUnit* GetUnit() = 0; 82 : 83 : /** 84 : * Set the variant selection of the actor for a certain key. 85 : * This overrides a previous selection on that key, so every component 86 : * should use unique keys. 87 : */ 88 : virtual void SetVariant(const CStr& key, const CStr& selection) = 0; 89 : 90 : /** 91 : * Returns the name of the currently played animation. 92 : */ 93 : virtual std::string GetAnimationName() const = 0; 94 : 95 : /** 96 : * Start playing the given animation. If there are multiple possible animations then it will 97 : * pick one at random (not network-synchronised). 98 : * @param name animation name (e.g. "idle", "walk", "melee"; the names are determined by actor XML files) 99 : * @param once if true then the animation will play once and freeze at the final frame, else it will loop 100 : * @param speed animation speed multiplier (typically 1.0 for the default speed) 101 : */ 102 : virtual void SelectAnimation(const std::string& name, bool once, fixed speed) = 0; 103 : 104 : /** 105 : * Start playing the given movement animation unless we are currently playing a non-movement animation. 106 : * This is necessary so UnitMotion can set the movement animations without overwriting specific animations 107 : * that might have been set by other components. 108 : * TODO: Non-movement animations should probably be made into variants, defining "idle" (really "default"), "walk" and "run" as appropriate, 109 : * and this would no longer be necessary. 110 : * @param name animation name (i.e. one of "idle", "walk", "run"). 111 : * @param speed animation speed multiplier (typically 1.0 for the default speed) 112 : */ 113 : virtual void SelectMovementAnimation(const std::string& name, fixed speed) = 0; 114 : 115 : /** 116 : * Adjust the speed of the current animation, so it can match simulation events. 117 : * @param repeattime time for complete loop of animation, in msec 118 : */ 119 : virtual void SetAnimationSyncRepeat(fixed repeattime) = 0; 120 : 121 : /** 122 : * Adjust the offset of the current animation, so it can match simulation events. 123 : * @param actiontime time between now and when the 'action' event should occur, in msec 124 : */ 125 : virtual void SetAnimationSyncOffset(fixed actiontime) = 0; 126 : 127 : /** 128 : * Set the shading color that will be modulated with the model's textures. 129 : * Default shading is (1, 1, 1, 1). 130 : * Alpha should probably be 1 else it's unlikely to work properly. 131 : * @param r red component, expected range [0, 1] 132 : * @param g green component, expected range [0, 1] 133 : * @param b blue component, expected range [0, 1] 134 : * @param a alpha component, expected range [0, 1] 135 : */ 136 : virtual void SetShadingColor(fixed r, fixed g, fixed b, fixed a) = 0; 137 : 138 : /** 139 : * Set an arbitrarily-named variable that the model may use to alter its appearance 140 : * (e.g. in particle emitter parameter computations). 141 : */ 142 : virtual void SetVariable(const std::string& name, float value) = 0; 143 : 144 : /** 145 : * Get actor seed used for random variations 146 : */ 147 : virtual std::uint32_t GetActorSeed() const = 0; 148 : 149 : /** 150 : * Set actor seed for random variations and reload model 151 : */ 152 : virtual void SetActorSeed(std::uint32_t seed) = 0; 153 : 154 : /** 155 : * Recalculate the actor name, applying modifiers. 156 : */ 157 : virtual void RecomputeActorName() = 0; 158 : 159 : /** 160 : * Returns true if this entity should have a construction preview 161 : */ 162 : virtual bool HasConstructionPreview() const = 0; 163 : 164 : /** 165 : * Called when an actor file has been modified and reloaded dynamically. 166 : * If this component uses the named actor file, it should regenerate its actor 167 : * to pick up the new definitions. 168 : * If name is empty, this reloads all the time. This is used when global quality settings change. 169 : */ 170 : virtual void Hotload(const VfsPath& name = L"") = 0; 171 : 172 7278 : DECLARE_INTERFACE_TYPE(Visual) 173 : }; 174 : 175 : // TODO: rename this to VisualActor, because the interface is actor-specific, maybe? 176 : 177 : #endif // INCLUDED_ICMPVISUAL