性能优化

This commit is contained in:
Nomango 2018-07-28 20:06:27 +08:00
parent 4a80f2df88
commit 840b554190
50 changed files with 452 additions and 449 deletions

View File

@ -11,12 +11,12 @@ e2d::Animation::Animation(const std::vector<Image*>& frames)
this->add(frames);
}
e2d::Animation::Animation(double interval)
e2d::Animation::Animation(float interval)
: _interval(interval)
{
}
e2d::Animation::Animation(double interval, const std::vector<Image*>& frames)
e2d::Animation::Animation(float interval, const std::vector<Image*>& frames)
: _interval(interval)
{
this->add(frames);
@ -30,9 +30,9 @@ e2d::Animation::~Animation()
}
}
void e2d::Animation::setInterval(double interval)
void e2d::Animation::setInterval(float interval)
{
_interval = std::max(interval, 0.0);
_interval = std::max(interval, 0.f);
}
void e2d::Animation::add(Image * frame)
@ -52,7 +52,7 @@ void e2d::Animation::add(const std::vector<Image*>& frames)
}
}
double e2d::Animation::getInterval() const
float e2d::Animation::getInterval() const
{
return _interval;
}

View File

@ -1,8 +1,8 @@
#include "..\e2daction.h"
e2d::Delay::Delay(double duration)
e2d::Delay::Delay(float duration)
: _delta(0)
, _delay(std::max(duration, 0.0))
, _delay(std::max(duration, 0.f))
{
}

View File

@ -1,8 +1,8 @@
#include "..\e2daction.h"
e2d::FiniteTimeAction::FiniteTimeAction(double duration)
e2d::FiniteTimeAction::FiniteTimeAction(float duration)
: _delta(0)
, _duration(std::max(duration, 0.0))
, _duration(std::max(duration, 0.f))
{
}
@ -28,7 +28,7 @@ void e2d::FiniteTimeAction::_update()
}
else
{
_delta = std::min((Game::getInstance()->getTotalDuration().seconds() - _last) / _duration, 1.0);
_delta = std::min((Game::getInstance()->getTotalDuration().seconds() - _last) / _duration, 1.f);
if (_delta >= 1)
{

View File

@ -1,7 +1,7 @@
#include "..\e2daction.h"
#include "..\e2dnode.h"
e2d::JumpBy::JumpBy(double duration, const Vector2 & vec, double height, int jumps)
e2d::JumpBy::JumpBy(float duration, const Vector2 & vec, float height, int jumps)
: FiniteTimeAction(duration)
, _deltaPos(vec)
, _height(height)
@ -35,9 +35,9 @@ void e2d::JumpBy::_update()
if (_target)
{
double frac = fmod(_delta * _jumps, 1.0);
double x = _deltaPos.x * _delta;
double y = _height * 4 * frac * (1 - frac);
float frac = fmod(_delta * _jumps, 1.f);
float x = _deltaPos.x * _delta;
float y = _height * 4 * frac * (1 - frac);
y += _deltaPos.y * _delta;
Point currentPos = _target->getPos();

View File

@ -1,7 +1,7 @@
#include "..\e2daction.h"
#include "..\e2dnode.h"
e2d::JumpTo::JumpTo(double duration, const Point & pos, double height, int jumps)
e2d::JumpTo::JumpTo(float duration, const Point & pos, float height, int jumps)
: JumpBy(duration, Point(), height, jumps)
, _endPos(pos)
{

View File

@ -2,7 +2,7 @@
#include "..\e2dnode.h"
e2d::MoveBy::MoveBy(double duration, Vector2 vector)
e2d::MoveBy::MoveBy(float duration, Vector2 vector)
: FiniteTimeAction(duration)
{
_deltaPos = vector;

View File

@ -1,7 +1,7 @@
#include "..\e2daction.h"
#include "..\e2dnode.h"
e2d::MoveTo::MoveTo(double duration, Point pos)
e2d::MoveTo::MoveTo(float duration, Point pos)
: MoveBy(duration, Vector2())
{
_endPos = pos;

View File

@ -2,7 +2,7 @@
#include "..\e2dnode.h"
e2d::OpacityBy::OpacityBy(double duration, double opacity)
e2d::OpacityBy::OpacityBy(float duration, float opacity)
: FiniteTimeAction(duration)
{
_deltaVal = opacity;

View File

@ -2,7 +2,7 @@
#include "..\e2dnode.h"
e2d::OpacityTo::OpacityTo(double duration, double opacity)
e2d::OpacityTo::OpacityTo(float duration, float opacity)
: OpacityBy(duration, 0)
{
_endVal = opacity;

View File

@ -2,7 +2,7 @@
#include "..\e2dnode.h"
e2d::RotateBy::RotateBy(double duration, double rotation)
e2d::RotateBy::RotateBy(float duration, float rotation)
: FiniteTimeAction(duration)
{
_deltaVal = rotation;

View File

@ -2,7 +2,7 @@
#include "..\e2dnode.h"
e2d::RotateTo::RotateTo(double duration, double rotation)
e2d::RotateTo::RotateTo(float duration, float rotation)
: RotateBy(duration, 0)
{
_endVal = rotation;

View File

@ -2,14 +2,14 @@
#include "..\e2dnode.h"
e2d::ScaleBy::ScaleBy(double duration, double scale)
e2d::ScaleBy::ScaleBy(float duration, float scale)
: FiniteTimeAction(duration)
{
_deltaX = scale;
_deltaY = scale;
}
e2d::ScaleBy::ScaleBy(double duration, double scaleX, double scaleY)
e2d::ScaleBy::ScaleBy(float duration, float scaleX, float scaleY)
: FiniteTimeAction(duration)
{
_deltaX = scaleX;

View File

@ -1,14 +1,14 @@
#include "..\e2daction.h"
#include "..\e2dnode.h"
e2d::ScaleTo::ScaleTo(double duration, double scale)
e2d::ScaleTo::ScaleTo(float duration, float scale)
: ScaleBy(duration, 0, 0)
{
_endScaleX = scale;
_endScaleY = scale;
}
e2d::ScaleTo::ScaleTo(double duration, double scaleX, double scaleY)
e2d::ScaleTo::ScaleTo(float duration, float scaleX, float scaleY)
: ScaleBy(duration, 0, 0)
{
_endScaleX = scaleX;

View File

@ -107,11 +107,7 @@ void e2d::GC::safeRelease(Ref* ref)
if (ref)
{
auto iter = _pool.find(ref);
if (iter != _pool.end())
{
(*iter)->release();
_notifyed = true;
}
ref->release();
_notifyed = true;
}
}

View File

@ -184,12 +184,12 @@ bool e2d::Input::isRelease(MouseCode code)
return false;
}
double e2d::Input::getMouseX()
float e2d::Input::getMouseX()
{
return getMousePos().x;
}
double e2d::Input::getMouseY()
float e2d::Input::getMouseY()
{
return getMousePos().y;
}
@ -203,20 +203,20 @@ e2d::Point e2d::Input::getMousePos()
ScreenToClient(hWnd, &mousePos);
UINT ret = ::GetDpiForWindow(hWnd);
return Point(mousePos.x * 96.0 / ret, mousePos.y * 96.0 / ret);
return Point(mousePos.x * 96.f / ret, mousePos.y * 96.f / ret);
}
double e2d::Input::getMouseDeltaX()
float e2d::Input::getMouseDeltaX()
{
return (double)_mouseState.lX;
return (float)_mouseState.lX;
}
double e2d::Input::getMouseDeltaY()
float e2d::Input::getMouseDeltaY()
{
return (double)_mouseState.lY;
return (float)_mouseState.lY;
}
double e2d::Input::getMouseDeltaZ()
float e2d::Input::getMouseDeltaZ()
{
return (double)_mouseState.lZ;
return (float)_mouseState.lZ;
}

View File

@ -181,12 +181,12 @@ void e2d::Window::poll()
}
}
double e2d::Window::getWidth()
float e2d::Window::getWidth()
{
return _size.width;
}
double e2d::Window::getHeight()
float e2d::Window::getHeight()
{
return _size.height;
}
@ -216,7 +216,7 @@ HWND e2d::Window::getHWnd()
void e2d::Window::setSize(int width, int height)
{
this->_size = Size(width, height);
this->_size = Size(static_cast<float>(width), static_cast<float>(height));
if (_hWnd)
{
float dpiScaleX = 0.f, dpiScaleY = 0.f;
@ -225,7 +225,7 @@ void e2d::Window::setSize(int width, int height)
width = static_cast<int>(ceil(width * dpiScaleX / 96.f));
height = static_cast<int>(ceil(height * dpiScaleY / 96.f));
// 计算窗口大小
DWORD dwStyle = WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX &~WS_THICKFRAME;
DWORD dwStyle = WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX & ~WS_THICKFRAME;
RECT wr = { 0, 0, static_cast<LONG>(width), static_cast<LONG>(height) };
::AdjustWindowRectEx(&wr, dwStyle, FALSE, NULL);
// 获取新的宽高
@ -435,7 +435,7 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPar
if (wParam == SIZE_RESTORED)
{
UINT dpi = ::GetDpiForWindow(hWnd);
_instance->_size = Size(width * 96.0 / dpi, height * 96.0 / dpi);
_instance->_size = Size(width * 96.f / dpi, height * 96.f / dpi);
}
// 如果程序接收到一个 WM_SIZE 消息,这个方法将调整渲染

View File

@ -4,7 +4,7 @@
e2d::Collider::Collider(Node * parent)
: _visible(true)
, _color(Color::Blue, 0.6)
, _color(Color::Blue, 0.6f)
, _parentNode(parent)
, _geometry(nullptr)
, _enabled(true)
@ -16,7 +16,6 @@ e2d::Collider::Collider(Node * parent)
e2d::Collider::~Collider()
{
SafeRelease(_geometry);
}
e2d::Color e2d::Collider::getColor() const
@ -139,11 +138,7 @@ void e2d::Collider::recreate()
{
ID2D1RectangleGeometry* rectangle = nullptr;
Renderer::getFactory()->CreateRectangleGeometry(
D2D1::RectF(
0,
0,
float(_parentNode->getRealWidth()),
float(_parentNode->getRealHeight())),
D2D1::RectF(0, 0, _parentNode->getRealWidth(), _parentNode->getRealHeight()),
&rectangle
);
_geometry = rectangle;
@ -152,17 +147,17 @@ void e2d::Collider::recreate()
case Shape::Circle:
{
double minSide = std::min(_parentNode->getRealWidth(), _parentNode->getRealHeight());
float minSide = std::min(_parentNode->getRealWidth(), _parentNode->getRealHeight());
ID2D1EllipseGeometry* circle = nullptr;
Renderer::getFactory()->CreateEllipseGeometry(
D2D1::Ellipse(
D2D1::Point2F(
float(_parentNode->getRealWidth() / 2),
float(_parentNode->getRealHeight() / 2)
_parentNode->getRealWidth() / 2,
_parentNode->getRealHeight() / 2
),
float(minSide / 2),
float(minSide / 2)
minSide / 2,
minSide / 2
),
&circle
);
@ -172,8 +167,8 @@ void e2d::Collider::recreate()
case Shape::Ellipse:
{
float halfWidth = float(_parentNode->getWidth() / 2),
halfHeight = float(_parentNode->getHeight() / 2);
float halfWidth = _parentNode->getWidth() / 2,
halfHeight = _parentNode->getHeight() / 2;
ID2D1EllipseGeometry* ellipse = nullptr;
Renderer::getFactory()->CreateEllipseGeometry(

View File

@ -12,23 +12,23 @@ e2d::Color::Color()
: r(0)
, g(0)
, b(0)
, a(1)
, a(1.f)
{
}
e2d::Color::Color(double r, double g, double b)
: r(float(r))
, g(float(g))
, b(float(b))
, a(float(1))
e2d::Color::Color(float r, float g, float b)
: r(r)
, g(g)
, b(b)
, a(1.f)
{
}
e2d::Color::Color(double r, double g, double b, double alpha)
: r(float(r))
, g(float(g))
, b(float(b))
, a(float(alpha))
e2d::Color::Color(float r, float g, float b, float alpha)
: r(r)
, g(g)
, b(b)
, a(alpha)
{
}
@ -37,17 +37,17 @@ e2d::Color::Color(UINT rgb)
_init(rgb, 1);
}
e2d::Color::Color(UINT rgb, double alpha)
e2d::Color::Color(UINT rgb, float alpha)
{
_init(rgb, alpha);
}
void e2d::Color::_init(UINT rgb, double alpha)
void e2d::Color::_init(UINT rgb, float alpha)
{
r = float((rgb & sc_redMask) >> sc_redShift) / 255.f;
g = float((rgb & sc_greenMask) >> sc_greenShift) / 255.f;
b = float((rgb & sc_blueMask) >> sc_blueShift) / 255.f;
a = float(alpha);
r = ((rgb & sc_redMask) >> sc_redShift) / 255.f;
g = ((rgb & sc_greenMask) >> sc_greenShift) / 255.f;
b = ((rgb & sc_blueMask) >> sc_blueShift) / 255.f;
a = alpha;
}
D2D1_COLOR_F e2d::Color::toD2DColorF() const

View File

@ -57,8 +57,8 @@ void e2d::Config::setCollisionEnabled(bool enabled)
void e2d::Config::setNodeDefaultPivot(Point pivot)
{
_defaultNodePivot = Point(
std::min(std::max(pivot.x, 0.0), 1.0),
std::min(std::max(pivot.y, 0.0), 1.0)
std::min(std::max(pivot.x, 0.f), 1.f),
std::min(std::max(pivot.y, 0.f), 1.f)
);
}

View File

@ -22,9 +22,9 @@ int e2d::Duration::milliseconds() const
return static_cast<int>(_ms.count());
}
double e2d::Duration::seconds() const
float e2d::Duration::seconds() const
{
return _ms.count() / 1000.0;
return _ms.count() / 1000.f;
}
bool e2d::Duration::operator==(const Duration & other) const

View File

@ -8,7 +8,7 @@ e2d::Font::Font()
{
}
e2d::Font::Font(const String & family, double size, UINT weight, bool italic)
e2d::Font::Font(const String & family, float size, UINT weight, bool italic)
: family(family)
, size(size)
, weight(weight)

View File

@ -73,19 +73,19 @@ void e2d::Image::crop(const Rect& cropRect)
{
if (_bitmap)
{
_cropRect.origin.x = std::min(std::max(cropRect.origin.x, 0.0), this->getSourceWidth());
_cropRect.origin.y = std::min(std::max(cropRect.origin.y, 0.0), this->getSourceHeight());
_cropRect.size.width = std::min(std::max(cropRect.size.width, 0.0), this->getSourceWidth() - cropRect.origin.x);
_cropRect.size.height = std::min(std::max(cropRect.size.height, 0.0), this->getSourceHeight() - cropRect.origin.y);
_cropRect.origin.x = std::min(std::max(cropRect.origin.x, 0.f), this->getSourceWidth());
_cropRect.origin.y = std::min(std::max(cropRect.origin.y, 0.f), this->getSourceHeight());
_cropRect.size.width = std::min(std::max(cropRect.size.width, 0.f), this->getSourceWidth() - cropRect.origin.x);
_cropRect.size.height = std::min(std::max(cropRect.size.height, 0.f), this->getSourceHeight() - cropRect.origin.y);
}
}
double e2d::Image::getWidth() const
float e2d::Image::getWidth() const
{
return _cropRect.size.width;
}
double e2d::Image::getHeight() const
float e2d::Image::getHeight() const
{
return _cropRect.size.height;
}
@ -95,7 +95,7 @@ e2d::Size e2d::Image::getSize() const
return _cropRect.size;
}
double e2d::Image::getSourceWidth() const
float e2d::Image::getSourceWidth() const
{
if (_bitmap)
{
@ -107,7 +107,7 @@ double e2d::Image::getSourceWidth() const
}
}
double e2d::Image::getSourceHeight() const
float e2d::Image::getSourceHeight() const
{
if (_bitmap)
{
@ -131,12 +131,12 @@ e2d::Size e2d::Image::getSourceSize() const
}
}
double e2d::Image::getCropX() const
float e2d::Image::getCropX() const
{
return _cropRect.origin.x;
}
double e2d::Image::getCropY() const
float e2d::Image::getCropY() const
{
return _cropRect.origin.y;
}

View File

@ -8,7 +8,7 @@ e2d::Point::Point()
y = 0;
}
e2d::Point::Point(double x, double y)
e2d::Point::Point(float x, float y)
{
this->x = x;
this->y = y;
@ -30,12 +30,12 @@ e2d::Point e2d::Point::operator-(Point const & p) const
return Point(x - p.x, y - p.y);
}
e2d::Point e2d::Point::operator*(double const & value) const
e2d::Point e2d::Point::operator*(float const & value) const
{
return Point(x * value, y * value);
}
e2d::Point e2d::Point::operator/(double const & value) const
e2d::Point e2d::Point::operator/(float const & value) const
{
return Point(x / value, y / value);
}
@ -45,7 +45,7 @@ e2d::Point::operator e2d::Size() const
return Size(x, y);
}
double e2d::Point::distance(const Point &p1, const Point &p2)
float e2d::Point::distance(const Point &p1, const Point &p2)
{
return sqrt(
(p1.x - p2.x) * (p1.x - p2.x) +

View File

@ -2,10 +2,10 @@
e2d::Rect::Rect(void)
{
setRect(0.0, 0.0, 0.0, 0.0);
setRect(0.f, 0.f, 0.f, 0.f);
}
e2d::Rect::Rect(double x, double y, double width, double height)
e2d::Rect::Rect(float x, float y, float width, float height)
{
setRect(x, y, width, height);
}
@ -31,7 +31,7 @@ bool e2d::Rect::operator==(const Rect & rect) const
return (origin == rect.origin) && (size == rect.size);
}
void e2d::Rect::setRect(double x, double y, double width, double height)
void e2d::Rect::setRect(float x, float y, float width, float height)
{
origin.x = x;
origin.y = y;

View File

@ -6,7 +6,7 @@ e2d::Size::Size()
height = 0;
}
e2d::Size::Size(double width, double height)
e2d::Size::Size(float width, float height)
{
this->width = width;
this->height = height;
@ -28,12 +28,12 @@ e2d::Size e2d::Size::operator-(Size const & size) const
return Size(width - size.width, height - size.height);
}
e2d::Size e2d::Size::operator*(double const & value) const
e2d::Size e2d::Size::operator*(float const & value) const
{
return Size(width * value, height * value);
}
e2d::Size e2d::Size::operator/(double const & value) const
e2d::Size e2d::Size::operator/(float const & value) const
{
return Size(width / value, height / value);
}

View File

@ -406,6 +406,15 @@ int e2d::String::toInt() const
return std::stoi(_str, 0, 10);
}
float e2d::String::toFloat() const
{
if (_str.empty())
{
return 0.f;
}
return std::stof(_str, 0);
}
double e2d::String::toDouble() const
{
if (_str.empty())

View File

@ -10,12 +10,12 @@ e2d::MouseEvent::MouseEvent(UINT message, WPARAM wParam, LPARAM lParam)
{
}
double e2d::MouseEvent::getX() const
float e2d::MouseEvent::getX() const
{
return _pos.x;
}
double e2d::MouseEvent::getY() const
float e2d::MouseEvent::getY() const
{
return _pos.y;
}
@ -35,7 +35,7 @@ bool e2d::MouseEvent::isCtrlDown() const
return _ctrlDown;
}
double e2d::MouseEvent::getWheelDelta() const
float e2d::MouseEvent::getWheelDelta() const
{
return _wheelDelta;
}

View File

@ -70,8 +70,8 @@ e2d::Node::Node()
, _extrapolate(Property::Origin)
{
Point defPivot = Game::getInstance()->getConfig().getNodeDefaultPivot();
_pivotX = float(defPivot.x);
_pivotY = float(defPivot.y);
_pivotX = defPivot.x;
_pivotY = defPivot.y;
_collider.setShape(Game::getInstance()->getConfig().getDefaultColliderShape());
}
@ -425,12 +425,12 @@ size_t e2d::Node::getHashName() const
return _hashName;
}
double e2d::Node::getPosX() const
float e2d::Node::getPosX() const
{
return _posX;
}
double e2d::Node::getPosY() const
float e2d::Node::getPosY() const
{
return _posY;
}
@ -440,22 +440,22 @@ e2d::Point e2d::Node::getPos() const
return Point(_posX, _posY);
}
double e2d::Node::getWidth() const
float e2d::Node::getWidth() const
{
return _width * _scaleX;
}
double e2d::Node::getHeight() const
float e2d::Node::getHeight() const
{
return _height * _scaleY;
}
double e2d::Node::getRealWidth() const
float e2d::Node::getRealWidth() const
{
return _width;
}
double e2d::Node::getRealHeight() const
float e2d::Node::getRealHeight() const
{
return _height;
}
@ -465,12 +465,12 @@ e2d::Size e2d::Node::getRealSize() const
return Size(_width, _height);
}
double e2d::Node::getPivotX() const
float e2d::Node::getPivotX() const
{
return _pivotX;
}
double e2d::Node::getPivotY() const
float e2d::Node::getPivotY() const
{
return _pivotY;
}
@ -480,32 +480,32 @@ e2d::Size e2d::Node::getSize() const
return Size(getWidth(), getHeight());
}
double e2d::Node::getScaleX() const
float e2d::Node::getScaleX() const
{
return _scaleX;
}
double e2d::Node::getScaleY() const
float e2d::Node::getScaleY() const
{
return _scaleY;
}
double e2d::Node::getSkewX() const
float e2d::Node::getSkewX() const
{
return _skewAngleX;
}
double e2d::Node::getSkewY() const
float e2d::Node::getSkewY() const
{
return _skewAngleY;
}
double e2d::Node::getRotation() const
float e2d::Node::getRotation() const
{
return _rotation;
}
double e2d::Node::getOpacity() const
float e2d::Node::getOpacity() const
{
return _realOpacity;
}
@ -554,12 +554,12 @@ void e2d::Node::setOrder(int order)
}
}
void e2d::Node::setPosX(double x)
void e2d::Node::setPosX(float x)
{
this->setPos(x, _posY);
}
void e2d::Node::setPosY(double y)
void e2d::Node::setPosY(float y)
{
this->setPos(_posX, y);
}
@ -569,13 +569,13 @@ void e2d::Node::setPos(const Point & p)
this->setPos(p.x, p.y);
}
void e2d::Node::setPos(double x, double y)
void e2d::Node::setPos(float x, float y)
{
if (_posX == x && _posY == y)
return;
_posX = float(x);
_posY = float(y);
_posX = x;
_posY = y;
_needTransform = true;
}
@ -588,17 +588,17 @@ void e2d::Node::setPosFixed(bool fixed)
_needTransform = true;
}
void e2d::Node::movePosX(double x)
void e2d::Node::movePosX(float x)
{
this->movePos(x, 0);
}
void e2d::Node::movePosY(double y)
void e2d::Node::movePosY(float y)
{
this->movePos(0, y);
}
void e2d::Node::movePos(double x, double y)
void e2d::Node::movePos(float x, float y)
{
this->setPos(_posX + x, _posY + y);
}
@ -608,107 +608,107 @@ void e2d::Node::movePos(const Vector2 & v)
this->movePos(v.x, v.y);
}
void e2d::Node::setScaleX(double scaleX)
void e2d::Node::setScaleX(float scaleX)
{
this->setScale(scaleX, _scaleY);
}
void e2d::Node::setScaleY(double scaleY)
void e2d::Node::setScaleY(float scaleY)
{
this->setScale(_scaleX, scaleY);
}
void e2d::Node::setScale(double scale)
void e2d::Node::setScale(float scale)
{
this->setScale(scale, scale);
}
void e2d::Node::setScale(double scaleX, double scaleY)
void e2d::Node::setScale(float scaleX, float scaleY)
{
if (_scaleX == scaleX && _scaleY == scaleY)
return;
_scaleX = float(scaleX);
_scaleY = float(scaleY);
_scaleX = scaleX;
_scaleY = scaleY;
_needTransform = true;
}
void e2d::Node::setSkewX(double angleX)
void e2d::Node::setSkewX(float angleX)
{
this->setSkew(angleX, _skewAngleY);
}
void e2d::Node::setSkewY(double angleY)
void e2d::Node::setSkewY(float angleY)
{
this->setSkew(_skewAngleX, angleY);
}
void e2d::Node::setSkew(double angleX, double angleY)
void e2d::Node::setSkew(float angleX, float angleY)
{
if (_skewAngleX == angleX && _skewAngleY == angleY)
return;
_skewAngleX = float(angleX);
_skewAngleY = float(angleY);
_skewAngleX = angleX;
_skewAngleY = angleY;
_needTransform = true;
}
void e2d::Node::setRotation(double angle)
void e2d::Node::setRotation(float angle)
{
if (_rotation == angle)
return;
_rotation = float(angle);
_rotation = angle;
_needTransform = true;
}
void e2d::Node::setOpacity(double opacity)
void e2d::Node::setOpacity(float opacity)
{
if (_realOpacity == opacity)
return;
_displayOpacity = _realOpacity = std::min(std::max(float(opacity), 0.f), 1.f);
_displayOpacity = _realOpacity = std::min(std::max(opacity, 0.f), 1.f);
// ¸üнڵã͸Ã÷¶È
_updateOpacity();
}
void e2d::Node::setPivotX(double pivotX)
void e2d::Node::setPivotX(float pivotX)
{
this->setPivot(pivotX, _pivotY);
}
void e2d::Node::setPivotY(double pivotY)
void e2d::Node::setPivotY(float pivotY)
{
this->setPivot(_pivotX, pivotY);
}
void e2d::Node::setPivot(double pivotX, double pivotY)
void e2d::Node::setPivot(float pivotX, float pivotY)
{
if (_pivotX == pivotX && _pivotY == pivotY)
return;
_pivotX = std::min(std::max(float(pivotX), 0.f), 1.f);
_pivotY = std::min(std::max(float(pivotY), 0.f), 1.f);
_pivotX = std::min(std::max(pivotX, 0.f), 1.f);
_pivotY = std::min(std::max(pivotY, 0.f), 1.f);
_needTransform = true;
}
void e2d::Node::setWidth(double width)
void e2d::Node::setWidth(float width)
{
this->setSize(width, _height);
}
void e2d::Node::setHeight(double height)
void e2d::Node::setHeight(float height)
{
this->setSize(_width, height);
}
void e2d::Node::setSize(double width, double height)
void e2d::Node::setSize(float width, float height)
{
if (_width == width && _height == height)
return;
_width = float(width);
_height = float(height);
_width = width;
_height = height;
_needTransform = true;
}
@ -953,7 +953,7 @@ bool e2d::Node::containsPoint(const Point& point)
{
BOOL ret = 0;
_outline->FillContainsPoint(
D2D1::Point2F(float(point.x), float(point.y)),
D2D1::Point2F(point.x, point.y),
D2D1::Matrix3x2F::Identity(),
&ret
);

View File

@ -6,13 +6,13 @@ e2d::CircleShape::CircleShape()
this->setPivot(0.5, 0.5);
}
e2d::CircleShape::CircleShape(double radius)
e2d::CircleShape::CircleShape(float radius)
{
this->setRadius(radius);
this->setPivot(0.5, 0.5);
}
e2d::CircleShape::CircleShape(Point center, double radius)
e2d::CircleShape::CircleShape(Point center, float radius)
{
this->setRadius(radius);
this->setPos(center);
@ -23,14 +23,14 @@ e2d::CircleShape::~CircleShape()
{
}
double e2d::CircleShape::getRadius() const
float e2d::CircleShape::getRadius() const
{
return _radius;
}
void e2d::CircleShape::setRadius(double radius)
void e2d::CircleShape::setRadius(float radius)
{
_radius = float(radius);
_radius = radius;
Node::setSize(radius * 2, radius * 2);
}

View File

@ -7,14 +7,14 @@ e2d::EllipseShape::EllipseShape()
this->setPivot(0.5, 0.5);
}
e2d::EllipseShape::EllipseShape(double radiusX, double radiusY)
e2d::EllipseShape::EllipseShape(float radiusX, float radiusY)
{
this->setRadiusX(radiusX);
this->setRadiusY(radiusY);
this->setPivot(0.5, 0.5);
}
e2d::EllipseShape::EllipseShape(Point center, double radiusX, double radiusY)
e2d::EllipseShape::EllipseShape(Point center, float radiusX, float radiusY)
{
this->setRadiusX(radiusX);
this->setRadiusY(radiusY);
@ -26,25 +26,25 @@ e2d::EllipseShape::~EllipseShape()
{
}
double e2d::EllipseShape::getRadiusX() const
float e2d::EllipseShape::getRadiusX() const
{
return _radiusX;
}
double e2d::EllipseShape::getRadiusY() const
float e2d::EllipseShape::getRadiusY() const
{
return _radiusY;
}
void e2d::EllipseShape::setRadiusX(double radiusX)
void e2d::EllipseShape::setRadiusX(float radiusX)
{
_radiusX = float(radiusX);
_radiusX = radiusX;
Node::setWidth(radiusX * 2);
}
void e2d::EllipseShape::setRadiusY(double radiusY)
void e2d::EllipseShape::setRadiusY(float radiusY)
{
_radiusY = float(radiusY);
_radiusY = radiusY;
Node::setHeight(radiusY * 2);
}

View File

@ -6,16 +6,16 @@ e2d::RoundRectShape::RoundRectShape()
{
}
e2d::RoundRectShape::RoundRectShape(Size size, double radiusX, double radiusY)
: _radiusX(float(radiusX))
, _radiusY(float(radiusY))
e2d::RoundRectShape::RoundRectShape(Size size, float radiusX, float radiusY)
: _radiusX(radiusX)
, _radiusY(radiusY)
{
this->setSize(size);
}
e2d::RoundRectShape::RoundRectShape(Point topLeft, Size size, double radiusX, double radiusY)
: _radiusX(float(radiusX))
, _radiusY(float(radiusY))
e2d::RoundRectShape::RoundRectShape(Point topLeft, Size size, float radiusX, float radiusY)
: _radiusX(radiusX)
, _radiusY(radiusY)
{
this->setPivot(0, 0);
this->setPos(topLeft);
@ -26,24 +26,24 @@ e2d::RoundRectShape::~RoundRectShape()
{
}
double e2d::RoundRectShape::getRadiusX() const
float e2d::RoundRectShape::getRadiusX() const
{
return _radiusX;
}
double e2d::RoundRectShape::getRadiusY() const
float e2d::RoundRectShape::getRadiusY() const
{
return _radiusY;
}
void e2d::RoundRectShape::setRadiusX(double radiusX)
void e2d::RoundRectShape::setRadiusX(float radiusX)
{
_radiusX = float(radiusX);
_radiusX = radiusX;
}
void e2d::RoundRectShape::setRadiusY(double radiusY)
void e2d::RoundRectShape::setRadiusY(float radiusY)
{
_radiusY = float(radiusY);
_radiusY = radiusY;
}
void e2d::RoundRectShape::_renderLine() const

View File

@ -59,7 +59,7 @@ e2d::Color e2d::Shape::getLineColor() const
return _lineColor;
}
double e2d::Shape::getStrokeWidth() const
float e2d::Shape::getStrokeWidth() const
{
return _strokeWidth;
}
@ -79,9 +79,9 @@ void e2d::Shape::setLineColor(Color lineColor)
_lineColor = lineColor;
}
void e2d::Shape::setStrokeWidth(double strokeWidth)
void e2d::Shape::setStrokeWidth(float strokeWidth)
{
_strokeWidth = float(strokeWidth) * 2;
_strokeWidth = strokeWidth * 2;
}
void e2d::Shape::setStyle(Style style)

View File

@ -82,8 +82,8 @@ void e2d::Sprite::crop(const Rect& cropRect)
{
_image->crop(cropRect);
Node::setSize(
std::min(std::max(cropRect.size.width, 0.0), _image->getSourceWidth() - _image->getCropX()),
std::min(std::max(cropRect.size.height, 0.0), _image->getSourceHeight() - _image->getCropY())
std::min(std::max(cropRect.size.width, 0.f), _image->getSourceWidth() - _image->getCropX()),
std::min(std::max(cropRect.size.height, 0.f), _image->getSourceHeight() - _image->getCropY())
);
}
@ -97,8 +97,8 @@ void e2d::Sprite::onRender() const
if (_image && _image->getBitmap())
{
// »ñȡͼƬ²Ã¼ôλÖÃ
float fCropX = float(_image->getCropX());
float fCropY = float(_image->getCropY());
float fCropX = _image->getCropX();
float fCropY = _image->getCropY();
// äÖȾͼƬ
Renderer::getInstance()->getRenderTarget()->DrawBitmap(
_image->getBitmap(),

View File

@ -8,13 +8,13 @@ e2d::Text::Style::Style()
: color(Color::White)
, alignment(Align::Left)
, wrapping(false)
, wrappingWidth(0.0)
, lineSpacing(0.0)
, wrappingWidth(0.f)
, lineSpacing(0.f)
, hasUnderline(false)
, hasStrikethrough(false)
, hasOutline(true)
, outlineColor(Color(Color::Black, 0.5))
, outlineWidth(1.0)
, outlineWidth(1.f)
, outlineJoin(LineJoin::Round)
{}
@ -22,13 +22,13 @@ e2d::Text::Style::Style(
Color color,
Align alignment,
bool wrapping,
double wrappingWidth,
double lineSpacing,
float wrappingWidth,
float lineSpacing,
bool hasUnderline,
bool hasStrikethrough,
bool hasOutline,
Color outlineColor,
double outlineWidth,
float outlineWidth,
LineJoin outlineJoin
)
: color(color)
@ -94,7 +94,7 @@ e2d::String e2d::Text::getFontFamily() const
return _font.family;
}
double e2d::Text::getFontSize() const
float e2d::Text::getFontSize() const
{
return _font.size;
}
@ -114,7 +114,7 @@ e2d::Color e2d::Text::getOutlineColor() const
return _style.outlineColor;
}
double e2d::Text::getOutlineWidth() const
float e2d::Text::getOutlineWidth() const
{
return _style.outlineWidth;
}
@ -182,7 +182,7 @@ void e2d::Text::setFontFamily(const String& family)
_reset();
}
void e2d::Text::setFontSize(double size)
void e2d::Text::setFontSize(float size)
{
_font.size = size;
_reset();
@ -214,11 +214,11 @@ void e2d::Text::setWrapping(bool wrapping)
}
}
void e2d::Text::setWrappingWidth(double wrappingWidth)
void e2d::Text::setWrappingWidth(float wrappingWidth)
{
if (_style.wrappingWidth != wrappingWidth)
{
_style.wrappingWidth = std::max(wrappingWidth, 0.0);
_style.wrappingWidth = std::max(wrappingWidth, 0.f);
if (_style.wrapping)
{
@ -227,7 +227,7 @@ void e2d::Text::setWrappingWidth(double wrappingWidth)
}
}
void e2d::Text::setLineSpacing(double lineSpacing)
void e2d::Text::setLineSpacing(float lineSpacing)
{
if (_style.lineSpacing != lineSpacing)
{
@ -277,7 +277,7 @@ void e2d::Text::setOutlineColor(Color outlineColor)
_style.outlineColor = outlineColor;
}
void e2d::Text::setOutlineWidth(double outlineWidth)
void e2d::Text::setOutlineWidth(float outlineWidth)
{
_style.outlineWidth = outlineWidth;
}
@ -302,7 +302,7 @@ void e2d::Text::onRender() const
_style.color.toD2DColorF(),
_style.hasOutline,
_style.outlineColor.toD2DColorF(),
float(_style.outlineWidth),
_style.outlineWidth,
D2D1_LINE_JOIN(_style.outlineJoin)
);
_textLayout->Draw(nullptr, pTextRenderer, 0, 0);
@ -327,7 +327,7 @@ void e2d::Text::_createFormat()
DWRITE_FONT_WEIGHT(_font.weight),
_font.italic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL,
float(_font.size),
_font.size,
L"",
&_textFormat
);
@ -343,7 +343,7 @@ void e2d::Text::_createFormat()
// 设置文字对齐方式
_textFormat->SetTextAlignment(DWRITE_TEXT_ALIGNMENT(_style.alignment));
// 设置行间距
if (_style.lineSpacing == 0.0)
if (_style.lineSpacing == 0.f)
{
_textFormat->SetLineSpacing(DWRITE_LINE_SPACING_METHOD_DEFAULT, 0, 0);
}
@ -351,8 +351,8 @@ void e2d::Text::_createFormat()
{
_textFormat->SetLineSpacing(
DWRITE_LINE_SPACING_METHOD_UNIFORM,
float(_style.lineSpacing),
float(_style.lineSpacing) * 0.8f
_style.lineSpacing,
_style.lineSpacing * 0.8f
);
}
// 打开文本自动换行时,设置换行属性
@ -395,7 +395,7 @@ void e2d::Text::_createLayout()
(const WCHAR *)_text,
length,
_textFormat,
float(_style.wrappingWidth),
_style.wrappingWidth,
0,
&_textLayout
);

View File

@ -18,7 +18,7 @@ void e2d::Data::saveInt(int value)
);
}
void e2d::Data::saveDouble(double value)
void e2d::Data::saveDouble(float value)
{
::WritePrivateProfileString(
(LPCWSTR)_field,
@ -58,7 +58,7 @@ int e2d::Data::getInt(int defaultValue)
);
}
double e2d::Data::getDouble(double defaultValue)
float e2d::Data::getDouble(float defaultValue)
{
wchar_t temp[32] = { 0 };
::GetPrivateProfileString((LPCWSTR)_field, (LPCWSTR)_key, (LPCWSTR)String::parse(defaultValue), temp, 31, (LPCWSTR)_dataPath);

View File

@ -309,11 +309,11 @@ IXAudio2SourceVoice * e2d::Music::getIXAudio2SourceVoice() const
return _voice;
}
bool e2d::Music::setVolume(double volume)
bool e2d::Music::setVolume(float volume)
{
if (_voice)
{
return SUCCEEDED(_voice->SetVolume(float(volume)));
return SUCCEEDED(_voice->SetVolume(volume));
}
return false;
}

View File

@ -160,14 +160,14 @@ bool e2d::Player::isPlaying(const Resource& res)
return false;
}
double e2d::Player::getVolume()
float e2d::Player::getVolume()
{
return _volume;
}
void e2d::Player::setVolume(double volume)
void e2d::Player::setVolume(float volume)
{
_volume = std::min(std::max(float(volume), -224.f), 224.f);
_volume = std::min(std::max(volume, -224.f), 224.f);
for (auto pair : _musicList)
{
pair.second->setVolume(_volume);

View File

@ -6,20 +6,20 @@ e2d::Task::Task(const Function & func, const String & name)
, _stopped(false)
, _runTimes(0)
, _totalTimes(-1)
, _delay(0.0)
, _lastTime(0.0)
, _delay(0.f)
, _lastTime(0.f)
, _callback(func)
, _name(name)
{
}
e2d::Task::Task(const Function & func, double delay, int times, const String & name)
e2d::Task::Task(const Function & func, float delay, int times, const String & name)
: _running(true)
, _stopped(false)
, _runTimes(0)
, _totalTimes(times)
, _delay(std::max(delay, 0.0))
, _lastTime(0.0)
, _delay(std::max(delay, 0.f))
, _lastTime(0.f)
, _callback(func)
, _name(name)
{

View File

@ -1,7 +1,7 @@
#include "..\e2dtransition.h"
#include "..\e2dnode.h"
e2d::BoxTransition::BoxTransition(double duration)
e2d::BoxTransition::BoxTransition(float duration)
: Transition(duration)
{
}
@ -17,10 +17,10 @@ void e2d::BoxTransition::_updateCustom()
if (_delta <= 0.5)
{
_outLayerParam.contentBounds = D2D1::RectF(
float(_windowSize.width * _delta),
float(_windowSize.height * _delta),
float(_windowSize.width * (1 - _delta)),
float(_windowSize.height * (1 - _delta))
_windowSize.width * _delta,
_windowSize.height * _delta,
_windowSize.width * (1 - _delta),
_windowSize.height * (1 - _delta)
);
}
else
@ -28,10 +28,10 @@ void e2d::BoxTransition::_updateCustom()
_outLayerParam.opacity = 0;
_inLayerParam.opacity = 1;
_inLayerParam.contentBounds = D2D1::RectF(
float(_windowSize.width * (1 - _delta)),
float(_windowSize.height * (1 - _delta)),
float(_windowSize.width * _delta),
float(_windowSize.height * _delta)
_windowSize.width * (1 - _delta),
_windowSize.height * (1 - _delta),
_windowSize.width * _delta,
_windowSize.height * _delta
);
if (_delta >= 1)
{

View File

@ -1,7 +1,7 @@
#include "..\e2dtransition.h"
#include "..\e2dnode.h"
e2d::EmergeTransition::EmergeTransition(double duration)
e2d::EmergeTransition::EmergeTransition(float duration)
: Transition(duration)
{
}
@ -15,8 +15,8 @@ void e2d::EmergeTransition::_init(Scene * prev, Scene * next)
void e2d::EmergeTransition::_updateCustom()
{
_outLayerParam.opacity = float(1 - _delta);
_inLayerParam.opacity = float(_delta);
_outLayerParam.opacity = 1 - _delta;
_inLayerParam.opacity = _delta;
if (_delta >= 1)
{

View File

@ -1,7 +1,7 @@
#include "..\e2dtransition.h"
#include "..\e2dnode.h"
e2d::FadeTransition::FadeTransition(double duration)
e2d::FadeTransition::FadeTransition(float duration)
: Transition(duration)
{
}
@ -17,13 +17,13 @@ void e2d::FadeTransition::_updateCustom()
{
if (_delta < 0.5)
{
_outLayerParam.opacity = 1 - float(_delta) * 2;
_outLayerParam.opacity = 1 - _delta * 2;
_inLayerParam.opacity = 0;
}
else
{
_outLayerParam.opacity = 0;
_inLayerParam.opacity = float(_delta - 0.5) * 2;
_inLayerParam.opacity = (_delta - 0.5f) * 2;
if (_delta >= 1)
{
this->_stop();

View File

@ -1,7 +1,7 @@
#include "..\e2dtransition.h"
#include "..\e2dnode.h"
e2d::MoveTransition::MoveTransition(double duration, Direction direction)
e2d::MoveTransition::MoveTransition(float duration, Direction direction)
: Transition(duration)
, _direction(direction)
{
@ -11,8 +11,8 @@ void e2d::MoveTransition::_init(Scene * prev, Scene * next)
{
Transition::_init(prev, next);
double width = _windowSize.width;
double height = _windowSize.height;
float width = _windowSize.width;
float height = _windowSize.height;
if (_direction == Direction::Up)
{
_posDelta = Vector2(0, -height);

View File

@ -2,7 +2,7 @@
#include "..\e2dtransition.h"
#include "..\e2dnode.h"
e2d::Transition::Transition(double duration)
e2d::Transition::Transition(float duration)
: _end(false)
, _last()
, _delta(0)
@ -13,7 +13,7 @@ e2d::Transition::Transition(double duration)
, _outLayerParam()
, _inLayerParam()
{
_duration = std::max(duration, 0.0);
_duration = std::max(duration, 0.f);
}
e2d::Transition::~Transition()
@ -57,7 +57,7 @@ void e2d::Transition::_init(Scene * prev, Scene * next)
nullptr,
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE,
D2D1::Matrix3x2F::Identity(),
1.0,
1.f,
renderer->getSolidColorBrush(),
D2D1_LAYER_OPTIONS_NONE
);
@ -73,7 +73,7 @@ void e2d::Transition::_update()
else
{
_delta = (Game::getInstance()->getTotalDuration() - _last).seconds() / _duration;
_delta = std::min(_delta, 1.0);
_delta = std::min(_delta, 1.f);
}
this->_updateCustom();
@ -97,10 +97,10 @@ void e2d::Transition::_render()
{
Point rootPos = _outScene->getRoot()->getPos();
auto clipRect = D2D1::RectF(
float(std::max(rootPos.x, 0.0)),
float(std::max(rootPos.y, 0.0)),
float(std::min(rootPos.x + _windowSize.width, _windowSize.width)),
float(std::min(rootPos.y + _windowSize.height, _windowSize.height))
std::max(rootPos.x, 0.f),
std::max(rootPos.y, 0.f),
std::min(rootPos.x + _windowSize.width, _windowSize.width),
std::min(rootPos.y + _windowSize.height, _windowSize.height)
);
pRT->SetTransform(D2D1::Matrix3x2F::Identity());
pRT->PushAxisAlignedClip(clipRect, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
@ -116,10 +116,10 @@ void e2d::Transition::_render()
{
Point rootPos = _inScene->getRoot()->getPos();
auto clipRect = D2D1::RectF(
float(std::max(rootPos.x, 0.0)),
float(std::max(rootPos.y, 0.0)),
float(std::min(rootPos.x + _windowSize.width, _windowSize.width)),
float(std::min(rootPos.y + _windowSize.height, _windowSize.height))
std::max(rootPos.x, 0.f),
std::max(rootPos.y, 0.f),
std::min(rootPos.x + _windowSize.width, _windowSize.width),
std::min(rootPos.y + _windowSize.height, _windowSize.height)
);
pRT->SetTransform(D2D1::Matrix3x2F::Identity());
pRT->PushAxisAlignedClip(clipRect, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);

View File

@ -85,7 +85,7 @@ protected:
bool _done;
bool _initialized;
Node * _target;
double _last;
float _last;
};
@ -96,7 +96,7 @@ class FiniteTimeAction :
public:
// 创建特定时长的持续动作
explicit FiniteTimeAction(
double duration
float duration
);
// 重置动作
@ -115,8 +115,8 @@ protected:
virtual void _resetTime() override;
protected:
double _duration;
double _delta;
float _duration;
float _delta;
};
@ -126,7 +126,7 @@ class MoveBy :
{
public:
explicit MoveBy(
double duration, /* 持续时长 */
float duration, /* 持续时长 */
Vector2 vector /* 移动距离 */
);
@ -158,7 +158,7 @@ class MoveTo :
{
public:
explicit MoveTo(
double duration, /* 持续时长 */
float duration, /* 持续时长 */
Point pos /* 目的坐标 */
);
@ -189,9 +189,9 @@ class JumpBy :
{
public:
explicit JumpBy(
double duration, /* 持续时长 */
float duration, /* 持续时长 */
const Vector2& vec, /* 跳跃距离 */
double height, /* 跳跃高度 */
float height, /* 跳跃高度 */
int jumps = 1 /* 跳跃次数 */
);
@ -213,7 +213,7 @@ protected:
protected:
Point _startPos;
Vector2 _deltaPos;
double _height;
float _height;
int _jumps;
Point _prevPos;
};
@ -225,9 +225,9 @@ class JumpTo :
{
public:
explicit JumpTo(
double duration, /* 持续时长 */
float duration, /* 持续时长 */
const Point& pos, /* 目的坐标 */
double height, /* 跳跃高度 */
float height, /* 跳跃高度 */
int jumps = 1 /* 跳跃次数 */
);
@ -258,14 +258,14 @@ class ScaleBy :
{
public:
explicit ScaleBy(
double duration, /* 持续时长 */
double scale /* 相对变化值 */
float duration, /* 持续时长 */
float scale /* 相对变化值 */
);
explicit ScaleBy(
double duration, /* 持续时长 */
double scaleX, /* 横向缩放相对变化值 */
double scaleY /* 纵向缩放相对变化值 */
float duration, /* 持续时长 */
float scaleX, /* 横向缩放相对变化值 */
float scaleY /* 纵向缩放相对变化值 */
);
// 获取该动作的拷贝对象
@ -284,10 +284,10 @@ protected:
virtual void _update() override;
protected:
double _startScaleX;
double _startScaleY;
double _deltaX;
double _deltaY;
float _startScaleX;
float _startScaleY;
float _deltaX;
float _deltaY;
};
@ -297,14 +297,14 @@ class ScaleTo :
{
public:
explicit ScaleTo(
double duration, /* 持续时长 */
double scale /* 目标值 */
float duration, /* 持续时长 */
float scale /* 目标值 */
);
explicit ScaleTo(
double duration, /* 持续时长 */
double scaleX, /* 横向缩放目标值 */
double scaleY /* 纵向缩放目标值 */
float duration, /* 持续时长 */
float scaleX, /* 横向缩放目标值 */
float scaleY /* 纵向缩放目标值 */
);
// 获取该动作的拷贝对象
@ -324,8 +324,8 @@ protected:
virtual void _init() override;
protected:
double _endScaleX;
double _endScaleY;
float _endScaleX;
float _endScaleY;
};
@ -335,8 +335,8 @@ class OpacityBy :
{
public:
explicit OpacityBy(
double duration, /* 持续时长 */
double opacity /* 相对变化值 */
float duration, /* 持续时长 */
float opacity /* 相对变化值 */
);
// 获取该动作的拷贝对象
@ -355,8 +355,8 @@ protected:
virtual void _update() override;
protected:
double _startVal;
double _deltaVal;
float _startVal;
float _deltaVal;
};
@ -366,8 +366,8 @@ class OpacityTo :
{
public:
explicit OpacityTo(
double duration, /* 持续时长 */
double opacity /* 目标值 */
float duration, /* 持续时长 */
float opacity /* 目标值 */
);
// 获取该动作的拷贝对象
@ -387,7 +387,7 @@ protected:
virtual void _init() override;
protected:
double _endVal;
float _endVal;
};
@ -398,7 +398,7 @@ class FadeIn :
public:
// 创建淡入动作
explicit FadeIn(
double duration /* 持续时长 */
float duration /* 持续时长 */
)
: OpacityTo(duration, 1)
{
@ -416,7 +416,7 @@ class FadeOut :
public:
// 创建淡出动作
explicit FadeOut(
double duration /* 持续时长 */
float duration /* 持续时长 */
)
: OpacityTo(duration, 0)
{
@ -433,8 +433,8 @@ class RotateBy :
{
public:
explicit RotateBy(
double duration, /* 持续时长 */
double rotation /* 相对变化值 */
float duration, /* 持续时长 */
float rotation /* 相对变化值 */
);
// 获取该动作的拷贝对象
@ -453,8 +453,8 @@ protected:
virtual void _update() override;
protected:
double _startVal;
double _deltaVal;
float _startVal;
float _deltaVal;
};
@ -464,8 +464,8 @@ class RotateTo :
{
public:
explicit RotateTo(
double duration, /* 持续时长 */
double rotation /* 目标值 */
float duration, /* 持续时长 */
float rotation /* 目标值 */
);
// 获取该动作的拷贝对象
@ -485,7 +485,7 @@ protected:
virtual void _init() override;
protected:
double _endVal;
float _endVal;
};
@ -495,7 +495,7 @@ class Delay :
{
public:
explicit Delay(
double duration /* 延迟时长(秒) */
float duration /* 延迟时长(秒) */
);
// 获取该动作的拷贝对象
@ -520,8 +520,8 @@ protected:
virtual void _resetTime() override;
protected:
double _delay;
double _delta;
float _delay;
float _delta;
};
@ -705,11 +705,11 @@ public:
);
explicit Animation(
double interval /* 帧间隔(秒) */
float interval /* 帧间隔(秒) */
);
explicit Animation(
double interval, /* 帧间隔(秒) */
float interval, /* 帧间隔(秒) */
const std::vector<Image*>& frames /* 关键帧数组 */
);
@ -726,14 +726,14 @@ public:
);
// 获取帧间隔
double getInterval() const;
float getInterval() const;
// 获取关键帧
const std::vector<Image*>& getFrames() const;
// 设置每一帧的时间间隔
void setInterval(
double interval /* 帧间隔(秒) */
float interval /* 帧间隔(秒) */
);
// 获取帧动画的拷贝对象
@ -746,7 +746,7 @@ protected:
E2D_DISABLE_COPY(Animation);
protected:
double _interval;
float _interval;
std::vector<Image*> _frames;
};

View File

@ -130,10 +130,10 @@ public:
String getTitle();
// 資函完悶錐業
double getWidth();
float getWidth();
// 資函完悶互業
double getHeight();
float getHeight();
// 資函完悶寄弌
Size getSize();
@ -233,22 +233,22 @@ public:
);
// 資誼報炎X已恫炎峙
double getMouseX();
float getMouseX();
// 資誼報炎Y已恫炎峙
double getMouseY();
float getMouseY();
// 資誼報炎恫炎峙
Point getMousePos();
// 資誼報炎X已恫炎奐楚
double getMouseDeltaX();
float getMouseDeltaX();
// 資誼報炎Y已恫炎奐楚
double getMouseDeltaY();
float getMouseDeltaY();
// 資誼報炎Z已<5A>報炎獄態<E78D84>恫炎奐楚
double getMouseDeltaZ();
float getMouseDeltaZ();
// 泡仟補秘譜姥彜蓑
void update();

View File

@ -30,27 +30,27 @@ class Size;
class Point
{
public:
double x; // X ×ø±ê
double y; // Y ×ø±ê
float x; // X 坐标
float y; // Y 坐标
public:
Point();
Point(double x, double y);
Point(float x, float y);
Point(const Point& other);
Point operator + (Point const & point) const;
Point operator - (Point const & point) const;
Point operator * (double const & point) const;
Point operator / (double const & point) const;
Point operator * (float const & point) const;
Point operator / (float const & point) const;
Point operator - () const;
bool operator== (const Point& point) const;
operator e2d::Size() const;
// 判断两点间距离
static double distance(const Point&, const Point&);
static float distance(const Point&, const Point&);
};
@ -62,20 +62,20 @@ typedef Point Vector2;
class Size
{
public:
double width; // ¿í¶È
double height; // ¸ß¶È
float width; // 宽度
float height; // 高度
public:
Size();
Size(double width, double height);
Size(float width, float height);
Size(const Size& other);
Size operator + (Size const & size) const;
Size operator - (Size const & size) const;
Size operator * (double const & size) const;
Size operator / (double const & size) const;
Size operator * (float const & size) const;
Size operator / (float const & size) const;
Size operator - () const;
bool operator== (const Size& size) const;
@ -93,7 +93,7 @@ public:
public:
Rect();
Rect(double x, double y, double width, double height);
Rect(float x, float y, float width, float height);
Rect(const Point& pos, const Size& size);
@ -105,10 +105,10 @@ public:
// 设置矩形
void setRect(
double x,
double y,
double width,
double height
float x,
float y,
float width,
float height
);
// 判断点是否在矩形内
@ -202,6 +202,9 @@ public:
// 将字符串转化为 int 型
int toInt() const;
// 将字符串转化为 float 型
float toFloat() const;
// 将字符串转化为 double 型
double toDouble() const;
@ -288,16 +291,16 @@ public:
Color();
Color(
double r,
double g,
double b
float r,
float g,
float b
);
Color(
double r,
double g,
double b,
double alpha
float r,
float g,
float b,
float alpha
);
Color(
@ -306,7 +309,7 @@ public:
Color(
UINT rgb,
double alpha
float alpha
);
D2D1_COLOR_F toD2DColorF() const;
@ -358,7 +361,7 @@ public:
private:
void _init(
UINT rgb,
double alpha
float alpha
);
private:
@ -422,7 +425,7 @@ public:
int milliseconds() const;
// 获取秒数
double seconds() const;
float seconds() const;
bool operator== (const Duration &) const;
bool operator!= (const Duration &) const;
@ -470,7 +473,7 @@ class Font
{
public:
String family; // 字体族
double size; // ×ÖºÅ
float size; // 字号
UINT weight; // 粗细值
bool italic; // 斜体
@ -494,7 +497,7 @@ public:
explicit Font(
const String& family,
double size = 22,
float size = 22,
UINT weight = Font::Weight::Normal,
bool italic = false
);
@ -636,16 +639,16 @@ public:
LPARAM lParam
);
double getX() const;
float getX() const;
double getY() const;
float getY() const;
Point getPos() const;
// 获取事件类型
MouseEvent::Type getType() const;
double getWheelDelta() const;
float getWheelDelta() const;
// Shift 键是否按下
bool isShiftDown() const;
@ -656,7 +659,7 @@ public:
protected:
bool _shiftDown;
bool _ctrlDown;
double _wheelDelta;
float _wheelDelta;
Point _pos;
MouseEvent::Type _type;
};
@ -896,28 +899,28 @@ public:
);
// 获取宽度
virtual double getWidth() const;
virtual float getWidth() const;
// 获取高度
virtual double getHeight() const;
virtual float getHeight() const;
// 获取大小
virtual Size getSize() const;
// 获取源图片宽度
virtual double getSourceWidth() const;
virtual float getSourceWidth() const;
// 获取源图片高度
virtual double getSourceHeight() const;
virtual float getSourceHeight() const;
// 获取源图片大小
virtual Size getSourceSize() const;
// 获取裁剪位置 X 坐标
virtual double getCropX() const;
virtual float getCropX() const;
// 获取裁剪位置 Y 坐标
virtual double getCropY() const;
virtual float getCropY() const;
// 获取裁剪位置
virtual Point getCropPos() const;

View File

@ -23,17 +23,17 @@ public:
// 节点属性
struct Property
{
double posX; // X 坐标
double posY; // Y 坐标
double width; // 宽度
double height; // 高度
double pivotX; // 中心点 X 坐标
double pivotY; // 中心点 Y 坐标
double scaleX; // 横向缩放
double scaleY; // 纵向缩放
double rotation; // 旋转角度
double skewAngleX; // 横向倾斜角度
double skewAngleY; // 纵向倾斜角度
float posX; // X 坐标
float posY; // Y 坐标
float width; // 宽度
float height; // 高度
float pivotX; // 中心点 X 坐标
float pivotY; // 中心点 Y 坐标
float scaleX; // 横向缩放
float scaleY; // 纵向缩放
float rotation; // 旋转角度
float skewAngleX; // 横向倾斜角度
float skewAngleY; // 纵向倾斜角度
Property operator+ (Property const & prop) const;
Property operator- (Property const & prop) const;
@ -86,55 +86,55 @@ public:
int getOrder() const;
// 获取节点横坐标
double getPosX() const;
float getPosX() const;
// 获取节点纵坐标
double getPosY() const;
float getPosY() const;
// 获取节点坐标
Point getPos() const;
// 获取节点宽度
double getWidth() const;
float getWidth() const;
// 获取节点高度
double getHeight() const;
float getHeight() const;
// 获取节点宽度(不考虑缩放)
double getRealWidth() const;
float getRealWidth() const;
// 获取节点高度(不考虑缩放)
double getRealHeight() const;
float getRealHeight() const;
// 获取节点大小(不考虑缩放)
Size getRealSize() const;
// 获取节点的中心点
double getPivotX() const;
float getPivotX() const;
// 获取节点的中心点
double getPivotY() const;
float getPivotY() const;
// 获取节点大小
Size getSize() const;
// 获取节点横向缩放比例
double getScaleX() const;
float getScaleX() const;
// 获取节点纵向缩放比例
double getScaleY() const;
float getScaleY() const;
// 获取节点横向倾斜角度
double getSkewX() const;
float getSkewX() const;
// 获取节点纵向倾斜角度
double getSkewY() const;
float getSkewY() const;
// 获取节点旋转角度
double getRotation() const;
float getRotation() const;
// 获取节点透明度
double getOpacity() const;
float getOpacity() const;
// 获取节点属性
Property getProperty() const;
@ -200,12 +200,12 @@ public:
// 设置节点横坐标
virtual void setPosX(
double x
float x
);
// 设置节点纵坐标
virtual void setPosY(
double y
float y
);
// 设置节点坐标
@ -215,8 +215,8 @@ public:
// 设置节点坐标
virtual void setPos(
double x,
double y
float x,
float y
);
// 节点坐标固定
@ -226,18 +226,18 @@ public:
// 移动节点
virtual void movePosX(
double x
float x
);
// 移动节点
virtual void movePosY(
double y
float y
);
// 移动节点
virtual void movePos(
double x,
double y
float x,
float y
);
// 移动节点
@ -254,92 +254,92 @@ public:
// 设置横向缩放比例
// 默认为 1.0
virtual void setScaleX(
double scaleX
float scaleX
);
// 设置纵向缩放比例
// 默认为 1.0
virtual void setScaleY(
double scaleY
float scaleY
);
// 设置缩放比例
// 默认为 (1.0, 1.0)
virtual void setScale(
double scaleX,
double scaleY
float scaleX,
float scaleY
);
// 设置缩放比例
// 默认为 1.0
virtual void setScale(
double scale
float scale
);
// 设置横向倾斜角度
// 默认为 0
virtual void setSkewX(
double angleX
float angleX
);
// 设置纵向倾斜角度
// 默认为 0
virtual void setSkewY(
double angleY
float angleY
);
// 设置倾斜角度
// 默认为 (0, 0)
virtual void setSkew(
double angleX,
double angleY
float angleX,
float angleY
);
// 设置旋转角度
// 默认为 0
virtual void setRotation(
double rotation
float rotation
);
// 设置透明度
// 默认为 1.0, 范围 [0, 1]
virtual void setOpacity(
double opacity
float opacity
);
// 设置中心点的横向位置
// 默认为 0, 范围 [0, 1]
virtual void setPivotX(
double pivotX
float pivotX
);
// 设置中心点的纵向位置
// 默认为 0, 范围 [0, 1]
virtual void setPivotY(
double pivotY
float pivotY
);
// 设置中心点位置
// 默认为 (0, 0), 范围 [0, 1]
virtual void setPivot(
double pivotX,
double pivotY
float pivotX,
float pivotY
);
// 修改节点宽度
virtual void setWidth(
double width
float width
);
// 修改节点高度
virtual void setHeight(
double height
float height
);
// 修改节点大小
virtual void setSize(
double width,
double height
float width,
float height
);
// 修改节点大小
@ -558,13 +558,13 @@ public:
Color color; // 颜色
Align alignment; // 对齐方式
bool wrapping; // 打开自动换行
double wrappingWidth; // 自动换行宽度
double lineSpacing; // 行间距
float wrappingWidth; // 自动换行宽度
float lineSpacing; // 行间距
bool hasUnderline; // 下划线
bool hasStrikethrough; // 删除线
bool hasOutline; // 显示描边
Color outlineColor; // 描边颜色
double outlineWidth; // 描边线宽
float outlineWidth; // 描边线宽
LineJoin outlineJoin; // 描边线相交样式
public:
@ -574,13 +574,13 @@ public:
Color color,
Align alignment = Align::Left,
bool wrapping = false,
double wrappingWidth = 0.0,
double lineSpacing = 0.0,
float wrappingWidth = 0.f,
float lineSpacing = 0.f,
bool hasUnderline = false,
bool hasStrikethrough = false,
bool hasOutline = true,
Color outlineColor = Color(Color::Black, 0.5),
double outlineWidth = 1.0,
float outlineWidth = 1.f,
LineJoin outlineJoin = LineJoin::Round
);
};
@ -609,7 +609,7 @@ public:
String getFontFamily() const;
// 获取当前字号
double getFontSize() const;
float getFontSize() const;
// 获取当前字体粗细值
UINT getFontWeight() const;
@ -621,7 +621,7 @@ public:
Color getOutlineColor() const;
// 获取描边线宽
double getOutlineWidth() const;
float getOutlineWidth() const;
// 获取描边线相交样式
LineJoin getOutlineJoin() const;
@ -663,7 +663,7 @@ public:
// 设置字号(默认值为 22
void setFontSize(
double size
float size
);
// 设置字体粗细值(默认值为 Text::Font::Weight::Normal
@ -688,12 +688,12 @@ public:
// 设置文本自动换行的宽度(默认为 0
void setWrappingWidth(
double wrappingWidth
float wrappingWidth
);
// 设置行间距(默认为 0
void setLineSpacing(
double lineSpacing
float lineSpacing
);
// 设置对齐方式(默认为 Align::Left
@ -723,7 +723,7 @@ public:
// 设置描边线宽
void setOutlineWidth(
double outlineWidth
float outlineWidth
);
// 设置描边线相交样式

View File

@ -33,7 +33,7 @@ public:
Color getLineColor() const;
// 获取线条宽度
double getStrokeWidth() const;
float getStrokeWidth() const;
// 设置填充颜色
void setFillColor(
@ -47,7 +47,7 @@ public:
// 设置线条宽度
void setStrokeWidth(
double strokeWidth
float strokeWidth
);
// 设置样式
@ -117,33 +117,33 @@ public:
explicit RoundRectShape(
Size size, /* 宽度和高度 */
double radiusX, /* Ô˛˝Ç°ëžś */
double radiusY /* Ô˛˝Ç°ëžś */
float radiusX, /* Ô²½Ç°ë¾¶ */
float radiusY /* Ô²½Ç°ë¾¶ */
);
explicit RoundRectShape(
Point topLeft, /* 左上角坐标 */
Size size, /* 宽度和高度 */
double radiusX, /* Ô˛˝Ç°ëžś */
double radiusY /* Ô˛˝Ç°ëžś */
float radiusX, /* Ô²½Ç°ë¾¶ */
float radiusY /* Ô²½Ç°ë¾¶ */
);
virtual ~RoundRectShape();
// 获取圆角半径
double getRadiusX() const;
float getRadiusX() const;
// 获取圆角半径
double getRadiusY() const;
float getRadiusY() const;
// 设置圆角半径
virtual void setRadiusX(
double radiusX
float radiusX
);
// 设置圆角半径
virtual void setRadiusY(
double radiusY
float radiusY
);
protected:
@ -169,22 +169,22 @@ public:
CircleShape();
explicit CircleShape(
double radius /* °ëžś */
float radius /* °ë¾¶ */
);
explicit CircleShape(
Point center, /* 圆心坐标 */
double radius /* °ëžś */
float radius /* °ë¾¶ */
);
virtual ~CircleShape();
// 获取半径
double getRadius() const;
float getRadius() const;
// 设置半径
virtual void setRadius(
double radius
float radius
);
protected:
@ -209,32 +209,32 @@ public:
EllipseShape();
explicit EllipseShape(
double radiusX, /* şáÖá°ëžś */
double radiusY /* ×ÝÖá°ëžś */
float radiusX, /* ºáÖá°ë¾¶ */
float radiusY /* ×ÝÖá°ë¾¶ */
);
explicit EllipseShape(
Point center, /* 圆心坐标 */
double radiusX, /* şáÖá°ëžś */
double radiusY /* ×ÝÖá°ëžś */
float radiusX, /* ºáÖá°ë¾¶ */
float radiusY /* ×ÝÖá°ë¾¶ */
);
virtual ~EllipseShape();
// 获取横轴半径
double getRadiusX() const;
float getRadiusX() const;
// 获取纵轴半径
double getRadiusY() const;
float getRadiusY() const;
// 设置横轴半径
virtual void setRadiusX(
double radiusX
float radiusX
);
// 设置纵轴半径
virtual void setRadiusY(
double radiusY
float radiusY
);
protected:

View File

@ -17,13 +17,13 @@ public:
}
// 取得范围内的一个浮点数随机数
static inline double range(float min, float max)
static inline float range(float min, float max)
{
return e2d::Random::__randomReal(min, max);
}
// 取得范围内的一个浮点数随机数
static inline double range(double min, double max)
static inline double range(double min, double max)
{
return e2d::Random::__randomReal(min, max);
}
@ -99,7 +99,7 @@ public:
// 设置音量
bool setVolume(
double volume
float volume
);
// 设置播放结束时的执行函数
@ -222,11 +222,11 @@ public:
);
// 获取音量
double getVolume();
float getVolume();
// 设置音量
void setVolume(
double volume /* 音量范围为 -224 ~ 2240 是静音1 是正常音量 */
float volume /* 音量范围为 -224 ~ 2240 是静音1 是正常音量 */
);
// 暂停所有音乐
@ -277,7 +277,7 @@ public:
explicit Task(
const Function& func, /* 执行函数 */
double delay, /* 时间间隔(秒) */
float delay, /* 时间间隔(秒) */
int times = -1, /* 执行次数(设 -1 为永久执行) */
const String& name = L"" /* 任务名称 */
);
@ -308,8 +308,8 @@ private:
bool _stopped;
int _runTimes;
int _totalTimes;
double _delay;
double _lastTime;
float _delay;
float _lastTime;
String _name;
Function _callback;
};
@ -391,9 +391,9 @@ public:
int value /* 数据 */
);
// 保存 double 类型的值
// 保存 float 类型的值
void saveDouble(
double value /* 数据 */
float value /* 数据 */
);
// 保存 bool 类型的值
@ -412,10 +412,10 @@ public:
int defaultValue /* 默认值 */
);
// 获取 double 类型的值
// 获取 float 类型的值
// (若不存在则返回 defaultValue 参数的值)
double getDouble(
double defaultValue /* 默认值 */
float getDouble(
float defaultValue /* 默认值 */
);
// 获取 bool 类型的值

View File

@ -15,7 +15,7 @@ class Transition :
friend class SceneManager;
public:
explicit Transition(double duration);
explicit Transition(float duration);
virtual ~Transition();
@ -46,8 +46,8 @@ protected:
protected:
bool _end;
double _duration;
double _delta;
float _duration;
float _delta;
Duration _last;
Size _windowSize;
Scene * _outScene;
@ -65,7 +65,7 @@ class FadeTransition :
{
public:
explicit FadeTransition(
double duration /* 动画持续时长 */
float duration /* 动画持续时长 */
);
protected:
@ -87,7 +87,7 @@ class EmergeTransition :
{
public:
explicit EmergeTransition(
double duration /* 浮现动画持续时长 */
float duration /* 浮现动画持续时长 */
);
protected:
@ -109,7 +109,7 @@ class BoxTransition :
{
public:
explicit BoxTransition(
double duration /* 动画持续时长 */
float duration /* 动画持续时长 */
);
protected:
@ -131,7 +131,7 @@ class MoveTransition :
{
public:
explicit MoveTransition(
double moveDuration, /* 场景移动动画持续时长 */
float moveDuration, /* 场景移动动画持续时长 */
Direction direction = Direction::Left /* 场景移动方向 */
);