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.

39 {
40  if (mMap != nullptr)
41  {
43  mMap = nullptr;
44  }
45 }

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

◆ 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 }

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.

◆ 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.

130  { return mMap; }

References mMap.

Referenced by CrazyMoves::crazyMove8().

◆ 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.

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.

76  { return mPos; }

References mPos.

Referenced by FindBeingFunctor::operator()().

◆ getPixelX()

int Actor::getPixelX ( ) const
inline

Returns the pixels X coordinate of the actor.

Definition at line 86 of file actor.h.

87  { return CAST_S32(mPos.x); }

References CAST_S32, mPos, and Vector::x.

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

◆ 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.

93  { return CAST_S32(mPos.y); }

References CAST_S32, mPos, and Vector::y.

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

◆ 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.

99  { return CAST_S32(mPos.y) - mYDiff; }

References CAST_S32, mPos, mYDiff, and Vector::y.

◆ 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.

61 {
62  if (mMap == nullptr ||
63  mMap->getTileWidth() == 0)
64  {
65  return 0;
66  }
67 
68  return getPixelX() / mMap->getTileWidth();
69 }

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

◆ 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.

72 {
73  if (mMap == nullptr ||
74  mMap->getTileHeight() == 0)
75  {
76  return 0;
77  }
78 
79  return getPixelY() / mMap->getTileHeight();
80 }

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

◆ 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.

◆ setMap()

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

Reimplemented in Being, LocalPlayer, and ActorSprite.

Definition at line 47 of file actor.cpp.

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 }

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

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

◆ 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.

83 {
84  mPos = pos;
87 }

References CAST_S32, and anonymous_namespace{mrand.cpp}::mPos.

Referenced by Being::setPixelPositionF().

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:
Map::removeActor
void removeActor(const Actors::iterator &iterator)
Definition: map.cpp:828
Vector::x
float x
Definition: vector.h:208
Actor::mMap
Map * mMap
Definition: actor.h:138
Actor::mPos
Vector mPos
Definition: actor.h:139
Actor::mMapActor
Actors::iterator mMapActor
Definition: actor.h:143
Actor::mPixelY
int mPixelY
Definition: actor.h:133
Actor::getPixelY
virtual int getPixelY() const
Definition: actor.h:92
Map::getTileWidth
int getTileWidth() const
Definition: map.h:177
Actor::mPixelX
int mPixelX
Definition: actor.h:132
Actor::mYDiff
int mYDiff
Definition: actor.h:140
Actor::getPixelX
int getPixelX() const
Definition: actor.h:86
Vector::y
float y
Definition: vector.h:208
Map::getTileHeight
int getTileHeight() const
Definition: map.h:183
CAST_S32
#define CAST_S32
Definition: cast.h:29
Map::addActor
Actors::iterator addActor(Actor *const actor)
Definition: map.cpp:821