ManaPlus
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes | Private Attributes
Actor Class Referenceabstract

#include <actor.h>

Inheritance diagram for Actor:
ActorSprite CastingEffect Particle Being FloorItem ImageParticle TextParticle LocalPlayer AnimationParticle RotationalParticle

Public Member Functions

virtual ~Actor ()
 
virtual void draw (Graphics *const graphics, const int offsetX, const int offsetY) const =0
 
virtual int getWidth () const
 
virtual int getHeight () const
 
const VectorgetPixelPositionF () const
 
virtual void setPixelPositionF (const Vector &pos)
 
int getPixelX () const
 
virtual int getPixelY () const
 
virtual int getSortPixelY () const
 
virtual int getTileX () const
 
virtual int getTileY () const
 
virtual int getNumberOfLayers () const
 
virtual float getAlpha () const =0
 
virtual void setAlpha (float alpha)=0
 
virtual void setMap (Map *const map)
 
const MapgetMap () const
 

Data Fields

int mPixelX
 
int mPixelY
 

Protected Member Functions

 Actor ()
 

Protected Attributes

MapmMap
 
Vector mPos
 
int mYDiff
 

Private Attributes

Actors::iterator mMapActor
 

Detailed Description

Definition at line 40 of file actor.h.

Constructor & Destructor Documentation

◆ ~Actor()

Actor::~Actor ( )
virtual

Definition at line 38 of file actor.cpp.

References mMap, mMapActor, and Map::removeActor().

39 {
40  if (mMap != nullptr)
41  {
43  mMap = nullptr;
44  }
45 }
void removeActor(const Actors::iterator &iterator)
Definition: map.cpp:817
Actors::iterator mMapActor
Definition: actor.h:143
Map * mMap
Definition: actor.h:138

◆ Actor()

Actor::Actor ( )
protected

Definition at line 28 of file actor.cpp.

28  :
29  mPixelX(0),
30  mPixelY(0),
31  mMap(nullptr),
32  mPos(),
33  mYDiff(0),
34  mMapActor()
35 {
36 }
Vector mPos
Definition: actor.h:139
Actors::iterator mMapActor
Definition: actor.h:143
int mPixelX
Definition: actor.h:132
int mPixelY
Definition: actor.h:133
int mYDiff
Definition: actor.h:140
Map * mMap
Definition: actor.h:138

Member Function Documentation

◆ draw()

virtual void Actor::draw ( Graphics *const  graphics,
const int  offsetX,
const int  offsetY 
) const
pure virtual

Draws the Actor to the given graphics context.

Note: this function could be simplified if the graphics context would support setting a translation offset. It already does this partly with the clipping rectangle support.

Implemented in Being, FloorItem, Particle, ImageParticle, CastingEffect, and TextParticle.

◆ getAlpha()

virtual float Actor::getAlpha ( ) const
pure virtual

Returns the current alpha value used to draw the actor.

Implemented in Particle, ActorSprite, and CastingEffect.

Referenced by getNumberOfLayers().

◆ getHeight()

virtual int Actor::getHeight ( ) const
inlinevirtual

Returns the vertical size of the actors graphical representation in pixels or 0 when it is undefined.

Reimplemented in Being, and ActorSprite.

Definition at line 69 of file actor.h.

70  { return 0; }

◆ getMap()

const Map* Actor::getMap ( ) const
inline

Definition at line 129 of file actor.h.

References mMap.

Referenced by Actions::changeRelation(), and CrazyMoves::crazyMove8().

130  { return mMap; }
Map * mMap
Definition: actor.h:138

◆ getNumberOfLayers()

virtual int Actor::getNumberOfLayers ( ) const
inlinevirtual

Returns the number of Image layers used to draw the actor.

Reimplemented in Being, and Particle.

Definition at line 114 of file actor.h.

References getAlpha(), setAlpha(), and setMap().

115  { return 0; }

◆ getPixelPositionF()

const Vector& Actor::getPixelPositionF ( ) const
inline

Returns the pixel position of this actor.

Definition at line 75 of file actor.h.

References mPos, restrict, restrict2, and setPixelPositionF().

Referenced by FindBeingFunctor::operator()().

76  { return mPos; }
Vector mPos
Definition: actor.h:139

◆ getPixelX()

int Actor::getPixelX ( ) const
inline

Returns the pixels X coordinate of the actor.

Definition at line 86 of file actor.h.

References CAST_S32, mPos, and Vector::x.

Referenced by Actions::doSit(), DebugWindow::draw(), MapLayer::drawFringe(), ActorManager::findBeingByPixel(), ActorManager::findBeingsByPixel(), ActorSprite::getActorX(), getTileX(), DebugWindow::safeDraw(), and Actions::setTarget().

87  { return CAST_S32(mPos.x); }
Vector mPos
Definition: actor.h:139
#define CAST_S32
Definition: cast.h:29
float x
Definition: vector.h:208

◆ getPixelY()

virtual int Actor::getPixelY ( ) const
inlinevirtual

Returns the pixel Y coordinate of the actor.

Reimplemented in Particle, and TextParticle.

Definition at line 92 of file actor.h.

References CAST_S32, mPos, and Vector::y.

Referenced by Actions::doSit(), DebugWindow::draw(), MapLayer::drawFringe(), ActorManager::findBeingByPixel(), ActorManager::findBeingsByPixel(), ActorSprite::getActorY(), getTileY(), DebugWindow::safeDraw(), and Actions::setTarget().

93  { return CAST_S32(mPos.y); }
Vector mPos
Definition: actor.h:139
#define CAST_S32
Definition: cast.h:29
float y
Definition: vector.h:208

◆ getSortPixelY()

virtual int Actor::getSortPixelY ( ) const
inlinevirtual

Returns the pixel Y coordinate of the actor for sorting only.

Reimplemented in Being, Particle, TextParticle, and CastingEffect.

Definition at line 98 of file actor.h.

References A_WARN_UNUSED, CAST_S32, getTileX(), getTileY(), mPos, mYDiff, and Vector::y.

99  { return CAST_S32(mPos.y) - mYDiff; }
Vector mPos
Definition: actor.h:139
#define CAST_S32
Definition: cast.h:29
int mYDiff
Definition: actor.h:140
float y
Definition: vector.h:208

◆ getTileX()

int Actor::getTileX ( ) const
virtual

Returns the x coordinate in tiles of the actor.

Reimplemented in Being, and FloorItem.

Definition at line 60 of file actor.cpp.

References getPixelX(), Map::getTileWidth(), and mMap.

Referenced by getSortPixelY().

61 {
62  if (mMap == nullptr ||
63  mMap->getTileWidth() == 0)
64  {
65  return 0;
66  }
67 
68  return getPixelX() / mMap->getTileWidth();
69 }
int getPixelX() const
Definition: actor.h:86
int getTileWidth() const
Definition: map.h:174
Map * mMap
Definition: actor.h:138

◆ getTileY()

int Actor::getTileY ( ) const
virtual

Returns the y coordinate in tiles of the actor.

Reimplemented in Being, and FloorItem.

Definition at line 71 of file actor.cpp.

References getPixelY(), Map::getTileHeight(), and mMap.

Referenced by getSortPixelY().

72 {
73  if (mMap == nullptr ||
74  mMap->getTileHeight() == 0)
75  {
76  return 0;
77  }
78 
79  return getPixelY() / mMap->getTileHeight();
80 }
int getTileHeight() const
Definition: map.h:180
virtual int getPixelY() const
Definition: actor.h:92
Map * mMap
Definition: actor.h:138

◆ getWidth()

virtual int Actor::getWidth ( ) const
inlinevirtual

Returns the horizontal size of the actors graphical representation in pixels or 0 when it is undefined.

Reimplemented in Being, and ActorSprite.

Definition at line 62 of file actor.h.

63  { return 0; }

◆ setAlpha()

virtual void Actor::setAlpha ( float  alpha)
pure virtual

Sets the alpha value used to draw the actor.

Implemented in Particle, ActorSprite, CastingEffect, and ImageParticle.

Referenced by getNumberOfLayers().

◆ setMap()

void Actor::setMap ( Map *const  map)
virtual

Reimplemented in Being, LocalPlayer, and ActorSprite.

Definition at line 47 of file actor.cpp.

References Map::addActor(), mMap, mMapActor, and Map::removeActor().

Referenced by Being::addCast(), Particle::addEffect(), ParticleEngine::addEffect(), ParticleEngine::addTextRiseFadeOutEffect(), ParticleEngine::addTextSplashEffect(), ParticleEngine::createChild(), ParticleEmitter::createParticles(), getNumberOfLayers(), and ActorSprite::setMap().

48 {
49  // Remove Actor from potential previous map
50  if (mMap != nullptr)
52 
53  mMap = map;
54 
55  // Add Actor to potential new map
56  if (mMap != nullptr)
57  mMapActor = mMap->addActor(this);
58 }
void removeActor(const Actors::iterator &iterator)
Definition: map.cpp:817
Actors::iterator addActor(Actor *const actor)
Definition: map.cpp:810
Actors::iterator mMapActor
Definition: actor.h:143
Map * mMap
Definition: actor.h:138

◆ setPixelPositionF()

void Actor::setPixelPositionF ( const Vector pos)
virtual

Sets the pixel position of this actor.

Reimplemented in Being.

Definition at line 82 of file actor.cpp.

References CAST_S32, mPixelX, mPixelY, mPos, Vector::x, and Vector::y.

Referenced by getPixelPositionF(), and Being::setPixelPositionF().

83 {
84  mPos = pos;
87 }
Vector mPos
Definition: actor.h:139
int mPixelX
Definition: actor.h:132
#define CAST_S32
Definition: cast.h:29
int mPixelY
Definition: actor.h:133
float x
Definition: vector.h:208
float y
Definition: vector.h:208

Field Documentation

◆ mMap

Map* Actor::mMap
protected

◆ mMapActor

Actors::iterator Actor::mMapActor
private

Definition at line 143 of file actor.h.

Referenced by setMap(), and ~Actor().

◆ mPixelX

int Actor::mPixelX

◆ mPixelY

int Actor::mPixelY

◆ mPos

Vector Actor::mPos
protected

◆ mYDiff

int Actor::mYDiff
protected

The documentation for this class was generated from the following files: