ManaPlus
src
particle
imageparticle.cpp
Go to the documentation of this file.
1
/*
2
* The ManaPlus Client
3
* Copyright (C) 2006-2009 The Mana World Development Team
4
* Copyright (C) 2009-2010 The Mana Developers
5
* Copyright (C) 2011-2019 The ManaPlus Developers
6
* Copyright (C) 2019-2021 Andrei Karas
7
*
8
* This file is part of The ManaPlus Client.
9
*
10
* This program is free software; you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation; either version 2 of the License, or
13
* any later version.
14
*
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
19
*
20
* You should have received a copy of the GNU General Public License
21
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
*/
23
24
#include "
particle/imageparticle.h
"
25
26
#include "render/graphics.h"
27
28
#include "
resources/image/image.h
"
29
30
#include "
debug.h
"
31
32
StringIntMap
ImageParticle::imageParticleCountByName
;
33
34
ImageParticle::ImageParticle
(
Image
*
restrict
const
image) :
35
Particle
()
36
{
37
mType
=
ParticleType::Image
;
38
mImage
= image;
39
if
(
mImage
!=
nullptr
)
40
{
41
mImage
->incRef();
42
43
const
std::string &
restrict
name =
mImage
->mIdPath;
44
StringIntMapIter
it
45
=
ImageParticle::imageParticleCountByName
.find(name);
46
if
(it ==
ImageParticle::imageParticleCountByName
.end())
47
ImageParticle::imageParticleCountByName
[name] = 1;
48
else
49
(*it).second ++;
50
}
51
}
52
53
void
ImageParticle::draw
(
Graphics
*
restrict
const
graphics,
54
const
int
offsetX,
55
const
int
offsetY)
const
restrict2
56
{
57
FUNC_BLOCK
(
"ImageParticle::draw"
, 1)
58
if
(mAlive !=
AliveStatus::ALIVE
|| (mImage ==
nullptr
))
59
return
;
60
61
const
int
w = mImage->mBounds.w;
62
const
int
h = mImage->mBounds.h;
63
const
int
screenX =
CAST_S32
(
mPos
.x)
64
+ offsetX - w / 2;
65
const
int
screenY =
CAST_S32
(
mPos
.y) -
CAST_S32
(
mPos
.z)
66
+ offsetY - h / 2;
67
68
// Check if on screen
69
if
(screenX + w < 0 ||
70
screenX > graphics->mWidth ||
71
screenY + h < 0 ||
72
screenY > graphics->mHeight)
73
{
74
return
;
75
}
76
77
float
alphafactor = mAlpha;
78
79
if
((mFadeOut != 0) && mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut)
80
{
81
alphafactor *=
static_cast<
float
>
(mLifetimeLeft)
82
/
static_cast<
float
>
(mFadeOut);
83
}
84
85
if
((mFadeIn != 0) && mLifetimePast < mFadeIn)
86
{
87
alphafactor *=
static_cast<
float
>
(mLifetimePast)
88
/
static_cast<
float
>
(mFadeIn);
89
}
90
91
mImage->setAlpha(alphafactor);
92
graphics->drawImage(mImage, screenX, screenY);
93
}
CAST_S32
#define CAST_S32
Definition:
cast.h:30
Graphics
Definition:
graphics.h:109
ImageParticle::ImageParticle
ImageParticle(Image *const image)
Definition:
imageparticle.cpp:34
ImageParticle::draw
void draw(Graphics *const graphics, const int offsetX, const int offsetY) const
Definition:
imageparticle.cpp:53
ImageParticle::imageParticleCountByName
static StringIntMap imageParticleCountByName
Definition:
imageparticle.h:59
Image
Particle
Definition:
particle.h:46
Particle::mImage
Image * mImage
Definition:
particle.h:277
Particle::mType
ParticleTypeT mType
Definition:
particle.h:271
debug.h
image.h
imageparticle.h
restrict
#define restrict
Definition:
localconsts.h:165
restrict2
#define restrict2
Definition:
localconsts.h:166
AliveStatus::ALIVE
@ ALIVE
Definition:
alivestatus.h:31
ParticleType::Image
@ Image
Definition:
particletype.h:31
anonymous_namespace{mrand.cpp}::mPos
int mPos
Definition:
mrand.cpp:31
FUNC_BLOCK
#define FUNC_BLOCK(name, id)
Definition:
perfomance.h:81
StringIntMap
std::map< std::string, int > StringIntMap
Definition:
stringmap.h:28
StringIntMapIter
StringIntMap::iterator StringIntMapIter
Definition:
stringmap.h:29
Generated on Wed Mar 17 2021 19:19:09 for ManaPlus by
1.9.1