ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

grim/actor.h

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef GRIM_ACTOR_H
00024 #define GRIM_ACTOR_H
00025 
00026 #include "engines/grim/pool.h"
00027 #include "engines/grim/object.h"
00028 #include "engines/grim/color.h"
00029 #include "math/vector3d.h"
00030 #include "math/angle.h"
00031 #include "math/quat.h"
00032 
00033 namespace Grim {
00034 
00035 class TextObject;
00036 class Sector;
00037 class Costume;
00038 class LipSync;
00039 class Font;
00040 class Set;
00041 class Material;
00042 struct SetShadow;
00043 struct Joint;
00044 class EMIModel;
00045 
00046 struct Plane {
00047     Common::String setName;
00048     Sector *sector;
00049 };
00050 
00051 typedef Common::List<Plane> SectorListType;
00052 
00053 #define MAX_SHADOWS 8
00054 
00055 struct Shadow {
00056     Shadow();
00057 
00058     Common::String name;
00059     Math::Vector3d pos;
00060     SectorListType planeList;
00061     byte *shadowMask;
00062     int shadowMaskSize;
00063     bool active;
00064     bool dontNegate;
00065     Color color;
00066     void *userData;
00067 };
00068 
00074 class Actor : public PoolObject<Actor> {
00075 public:
00076     enum CollisionMode {
00077         CollisionOff = 0,
00078         CollisionBox = 1,
00079         CollisionSphere = 2
00080     };
00081 
00082     enum AlphaMode {
00083         AlphaOff = -1,
00084         AlphaReplace = 2,
00085         AlphaModulate = 3 // Seems to be unused
00086     };
00087 
00088     enum LightMode {
00089         LightStatic = 0,
00090         LightFastDyn = 1,
00091         LightNormDyn = 2,
00092         LightNone = 3
00093     };
00094 
00098     Actor();
00103     ~Actor();
00104 
00105     static int32 getStaticTag() { return MKTAG('A', 'C', 'T', 'R'); }
00106 
00112     void saveState(SaveGame *savedState) const;
00118     bool restoreState(SaveGame *savedState);
00119 
00123     const Common::String &getName() const { return _name; }
00124 
00130     void setName(const Common::String &name) { _name = name; }
00131 
00138     void setTalkColor(const Color &color) { _talkColor = color; }
00144     Color getTalkColor() const { return _talkColor; }
00145 
00152     void setPos(const Math::Vector3d &position);
00158     Math::Vector3d getPos() const { return _pos; }
00159     inline Math::Vector3d getDestPos() const { return _destPos; }
00160 
00170     void walkTo(const Math::Vector3d &position);
00177     void stopWalking() { _walking = false; }
00184     bool isWalking() const;
00185 
00202     void turnTo(const Math::Angle &pitch, const Math::Angle &yaw, const Math::Angle &roll, bool snap = false);
00213     void turnTo(const Math::Vector3d &pos, bool snap = false);
00224     bool singleTurnTo(const Math::Vector3d &pos);
00230     bool isTurning() const;
00234     void stopTurning();
00249     void setRot(const Math::Angle &pitch, const Math::Angle &yaw, const Math::Angle &roll);
00258     void setRot(const Math::Vector3d &pos);
00271     void turn(int dir);
00282     Math::Angle getPitch() const { return _pitch; }
00293     Math::Angle getYaw() const { return _yaw; }
00304     Math::Angle getRoll() const { return _roll; }
00305 
00312     Math::Angle  getYawTo(const Actor *actor) const;
00319     Math::Angle  getYawTo(const Math::Vector3d &p) const;
00320 
00327     void setVisibility(bool val) { _visible = val; }
00333     bool isVisible() const { return _visible; }
00334 
00341     void setScale(float scale) { _scale = scale; }
00342     float getScale() const { return _scale; }
00343 
00352     void setTimeScale(float scale) { _timeScale = scale; }
00358     float getTimeScale() const { return _timeScale; }
00359 
00365     void putInSet(const Common::String &setName);
00372     bool isDrawableInSet(const Common::String &setName) const;
00379     bool isInSet(const Common::String &setName) const;
00380 
00387     void setTurnRate(float rate) { _turnRate = rate; }
00393     float getTurnRate() const { return _turnRate; }
00400     void setWalkRate(float rate) { _walkRate = rate; }
00406     float getWalkRate() const { return _walkRate; }
00407 
00408     void setLooking(bool lookingMode) { _lookingMode = lookingMode; }
00409 
00417     void walkForward();
00418     void moveTo(const Math::Vector3d &pos);
00424     void setRunning(bool running) { _running = running; }
00425     void setReflection(float angle) { _reflectionAngle = angle; }
00430     Math::Vector3d getPuckVector() const;
00431 
00432     void setPuckOrient(bool orient);
00433 
00444     void sayLine(const char *msgId, bool background, float x, float y);
00445     // When we clean all text objects we don't want the actors to clean their
00446     // objects again since they're already freed
00447     void lineCleanup();
00454     void shutUp();
00461     bool isTalking();
00462 
00463     void setRestChore(int choreNumber, Costume *cost);
00464     int getRestChore() const;
00465     void setWalkChore(int choreNumber, Costume *cost);
00466     void setTurnChores(int left_chore, int right_chore, Costume *cost);
00467     void setTalkChore(int index, int choreNumber, Costume *cost);
00468     int getTalkChore(int index) const;
00469     Costume *getTalkCostume(int index) const;
00470     void setMumbleChore(int choreNumber, Costume *cost);
00471     void stopAllChores(bool ignoreLoopingChores = false);
00472     void setColormap(const char *map);
00473     void pushCostume(const char *name);
00474     void setCostume(const char *name);
00475     void popCostume();
00476     void clearCostumes();
00477     Costume *getCurrentCostume() const;
00478     void setLocalAlphaMode(unsigned int vertex, AlphaMode alphamode);
00479     void setLocalAlpha(unsigned int vertex, float alpha);
00480     bool hasLocalAlpha() const;
00481     float getLocalAlpha(unsigned int vertex) const;
00482     Costume *findCostume(const Common::String &name);
00483     int getCostumeStackDepth() const {
00484         return _costumeStack.size();
00485     }
00486     const Common::List<Costume *> &getCostumes() const { return _costumeStack; }
00487 
00488     void setActiveShadow(int shadowId);
00489     void setShadowPoint(const Math::Vector3d &pos);
00490     void setShadowColor(const Color &color);
00491     void setShadowPlane(const char *name);
00492     void addShadowPlane(const char *name);
00493     void clearShadowPlanes();
00494     void clearShadowPlane(int i);
00495     void setShadowValid(int);
00496     void setActivateShadow(int, bool);
00497 
00498     void setFollowBoxes(bool follow);
00499     bool hasFollowedBoxes() const { return _hasFollowedBoxes; }
00500     void update(uint frameTime);
00504     bool updateTalk(uint frameTime);
00505     void draw();
00506 
00507     bool isLookAtVectorZero() {
00508         return _lookAtVector.isZero();
00509     }
00510     void setLookAtVectorZero() {
00511         _lookAtVector.set(0.f, 0.f, 0.f);
00512         _lookAtActor = 0;
00513     }
00514     void setLookAtVector(const Math::Vector3d &vector) {
00515         _lookAtVector = vector;
00516         _lookAtActor = 0;
00517     }
00518     Math::Vector3d getLookAtVector() {
00519         return _lookAtVector;
00520     }
00521     void setLookAtActor(Actor *other) { _lookAtActor = other->getId(); }
00522     void setLookAtRate(float rate);
00523     float getLookAtRate() const;
00524     void setHead(int joint1, int joint2, int joint3, float maxRoll, float maxPitch, float maxYaw);
00525     void setHead(const char *joint, const Math::Vector3d &offset);
00526     void setHeadLimits(float yawRange, float maxPitch, float minPitch);
00527 
00528     void setCollisionMode(CollisionMode mode);
00529     void setCollisionScale(float scale);
00530 
00531     bool handleCollisionWith(Actor *actor, CollisionMode mode, Math::Vector3d *vec) const;
00532 
00533     static void saveStaticState(SaveGame *state);
00534     static void restoreStaticState(SaveGame *state);
00535 
00536     bool isAttached() const { return _attachedActor != 0; }
00537     Math::Vector3d getWorldPos() const;
00538     void attachToActor(Actor *other, const char *joint);
00539     void detach();
00540     Math::Quaternion getRotationQuat() const;
00541     const Math::Matrix4 getFinalMatrix() const;
00542     Math::Vector3d getHeadPos() const;
00543 
00544     void setInOverworld(bool inOverworld) { _inOverworld = inOverworld; }
00545     bool isInOverworld() const { return _inOverworld; }
00546 
00547     float getGlobalAlpha() const { return _globalAlpha; }
00548     AlphaMode getAlphaMode() const { return _alphaMode; }
00549     float getEffectiveAlpha() const { return _alphaMode != AlphaOff ? _globalAlpha : 1.f; }
00550     void setGlobalAlpha(float alpha, const Common::String &mesh);
00551     void setAlphaMode(AlphaMode mode, const Common::String &mesh);
00552 
00553     int getSortOrder() const;
00554     void setSortOrder(const int order);
00555     int getEffectiveSortOrder() const;
00556 
00557     void activateShadow(bool active, const char *shadowName);
00558     void activateShadow(bool active, SetShadow *shadow);
00559 
00560     void drawToCleanBuffer();
00561 
00562     bool isTalkingForeground() const;
00563 
00564     LightMode getLightMode() const { return _lightMode; }
00565     void setLightMode(LightMode lightMode) { _lightMode = lightMode; }
00566 
00567     ObjectPtr<Material> loadMaterial(const Common::String &name, bool clamp);
00568     ObjectPtr<Material> findMaterial(const Common::String &name);
00569 
00570     void getBBoxInfo(Math::Vector3d &bboxPos, Math::Vector3d &bboxSize) const;
00571 
00572 private:
00573     void costumeMarkerCallback(int marker);
00574     void collisionHandlerCallback(Actor *other) const;
00575     void updateWalk();
00576     void addShadowPlane(const char *n, Set *scene, int shadowId);
00577     bool shouldDrawShadow(int shadowId);
00578     void stopTalking();
00579     bool stopMumbleChore();
00580     void drawCostume(Costume *costume);
00585     Math::Vector3d handleCollisionTo(const Math::Vector3d &from, const Math::Vector3d &pos) const;
00591     Math::Vector3d getTangentPos(const Math::Vector3d &pos, const Math::Vector3d &dest) const;
00592 
00593     Math::Vector3d getSimplePuckVector() const;
00594     void calculateOrientation(const Math::Vector3d &pos, Math::Angle *pitch, Math::Angle *yaw, Math::Angle *roll);
00595 
00596     bool getSphereInfo(bool adjustZ, float &size, Math::Vector3d &pos) const;
00597     EMIModel *findModelWithMesh(const Common::String &mesh);
00598 
00599     Common::String _name;
00600     Common::String _setName;    // The actual current set
00601 
00602     Color _talkColor;
00603     Math::Vector3d _pos;
00604     Math::Angle _pitch, _yaw, _roll;
00605     float _walkRate, _turnRate;
00606 
00607     bool _followBoxes;  // Constrain to walkboxes
00608     bool _hasFollowedBoxes;
00609     float _reflectionAngle; // Maximum angle to turn by at walls
00610     bool _visible;
00611     float _scale;
00612     float _timeScale;
00613     bool _lookingMode;
00614     Common::String _talkSoundName;
00615     bool _talking;
00616     bool _backgroundTalk;
00617     ObjectPtr<LipSync> _lipSync;
00618     Common::List<Costume *> _costumeStack;
00619 
00620     // Variables for gradual turning
00621     bool _turning;
00622     bool _singleTurning;
00623     // NOTE: The movement direction is separate from the direction
00624     // the actor's model is facing. The model's direction is gradually
00625     // updated to match the movement direction. This produces a smooth
00626     // turning animation while still allowing the actor to move in a
00627     // new direction immediately after reflecting off a wall.
00628     Math::Angle _moveYaw;
00629     Math::Angle _movePitch;
00630     Math::Angle _moveRoll;
00631     // This is used to increase momentarily the turn rate when needed
00632     float _turnRateMultiplier;
00633 
00634     // Variables for walking to a point
00635     bool _walking;
00636     Math::Vector3d _destPos;
00637 
00638     //chores
00639     class ActionChore {
00640     public:
00641         ActionChore();
00642         ActionChore(Costume *cost, int chore);
00643 
00644         void play(bool fade = false, unsigned int time = fadeTime);
00645         void playLooping(bool fade = false, unsigned int time = fadeTime);
00646         void stop(bool fade = false, unsigned int time = fadeTime);
00647         void setLastFrame();
00648 
00649         inline bool isValid() const { return _chore > -1 && _costume != nullptr; }
00650         bool isPlaying() const;
00651         inline bool equals(const Costume *cost, int chore) const {
00652             return (_costume == cost && _chore == chore);
00653         }
00654 
00655         void saveState(SaveGame *state) const;
00656         void restoreState(SaveGame *state, Actor *actor);
00657 
00658         Costume *_costume;
00659         int _chore;
00660 
00661         static const unsigned int fadeTime;
00662         static const unsigned int talkFadeTime;
00663     };
00664     ActionChore _restChore;
00665 
00666     ActionChore _walkChore;
00667     bool _walkedLast, _walkedCur;
00668     bool _running;
00669 
00670     ActionChore _leftTurnChore, _rightTurnChore;
00671     int _lastTurnDir, _currTurnDir;
00672 
00673     ActionChore _talkChore[10];
00674     int _talkAnim;
00675 
00676     ActionChore _mumbleChore;
00677 
00678     Shadow *_shadowArray;
00679     int _activeShadowSlot;
00680 
00681     static ObjectPtr<Font> _sayLineFont;
00682     int _sayLineText;
00683     bool _mustPlaceText;
00684 
00685     ActionChore *getTurnChore(int dir) {
00686         return (dir > 0 ? &_leftTurnChore : &_rightTurnChore);
00687     }
00688 
00689     void freeCostume(Costume *costume);
00690     void freeCostumeChore(const Costume *toFree, ActionChore *chore);
00691 
00692     // lookAt
00693     Math::Vector3d _lookAtVector;
00694 
00695     // struct used for path finding
00696     struct PathNode {
00697         Sector *sect;
00698         PathNode *parent;
00699         Math::Vector3d pos;
00700         float dist;
00701         float cost;
00702     };
00703     Common::List<Math::Vector3d> _path;
00704 
00705     CollisionMode _collisionMode;
00706     float _collisionScale;
00707 
00708     bool _puckOrient;
00709 
00710     static bool _isTalkingBackground;
00711     int _talkDelay;
00712     int _attachedActor;
00713     int _lookAtActor;
00714     Common::String _attachedJoint;
00715     AlphaMode _alphaMode;
00716     float _globalAlpha;
00717 
00718     bool _inOverworld;
00719 
00720     int _sortOrder;
00721     int _sectorSortOrder;
00722     bool _useParentSortOrder;
00723 
00724     bool _fakeUnbound;
00725     bool _drawnToClean;
00726 
00727     LightMode _lightMode;
00728 
00729     Common::List<ObjectPtr<Material> > _materials;
00730 
00731     // Highest vertex used in EMI
00732     const static unsigned int MAX_LOCAL_ALPHA_VERTICES = 48;
00733     Common::Array<float> _localAlpha;
00734     Common::Array<int> _localAlphaMode;
00735 };
00736 
00737 } // end of namespace Grim
00738 
00739 #endif


Generated on Sat May 18 2019 05:00:54 for ResidualVM by doxygen 1.7.1
curved edge   curved edge