Skip to content

Commit 127ddac

Browse files
committed
🔥Remove Color3B (#2607)
1 parent c5cb447 commit 127ddac

File tree

303 files changed

+9692
-10372
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

303 files changed

+9692
-10372
lines changed

‎core/2d/ActionInterval.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2208,10 +2208,10 @@ void FadeTo::update(float time)
22082208
//
22092209
// TintTo
22102210
//
2211-
TintTo* TintTo::create(float duration, uint8_t red, uint8_t green, uint8_t blue)
2211+
TintTo* TintTo::create(float duration, const Color32& color)
22122212
{
22132213
TintTo* tintTo = new TintTo();
2214-
if (tintTo->initWithDuration(duration, red, green, blue))
2214+
if (tintTo->initWithDuration(duration, color))
22152215
{
22162216
tintTo->autorelease();
22172217
return tintTo;
@@ -2221,16 +2221,11 @@ TintTo* TintTo::create(float duration, uint8_t red, uint8_t green, uint8_t blue)
22212221
return nullptr;
22222222
}
22232223

2224-
TintTo* TintTo::create(float duration, const Color3B& color)
2225-
{
2226-
return create(duration, color.r, color.g, color.b);
2227-
}
2228-
2229-
bool TintTo::initWithDuration(float duration, uint8_t red, uint8_t green, uint8_t blue)
2224+
bool TintTo::initWithDuration(float duration, const Color32& color)
22302225
{
22312226
if (ActionInterval::initWithDuration(duration))
22322227
{
2233-
_to = Color3B(red, green, blue);
2228+
_to = color;
22342229
return true;
22352230
}
22362231

@@ -2240,7 +2235,7 @@ bool TintTo::initWithDuration(float duration, uint8_t red, uint8_t green, uint8_
22402235
TintTo* TintTo::clone() const
22412236
{
22422237
// no copy constructor
2243-
return TintTo::create(_duration, _to.r, _to.g, _to.b);
2238+
return TintTo::create(_duration, _to);
22442239
}
22452240

22462241
TintTo* TintTo::reverse() const
@@ -2262,9 +2257,11 @@ void TintTo::update(float time)
22622257
{
22632258
if (_target)
22642259
{
2265-
_target->setColor(Color3B(uint8_t(_from.r + (_to.r - _from.r) * time),
2260+
// FIXME: should we need introduce opacity tint support in axmol-v3?
2261+
auto opacity = _target->getColor().a;
2262+
_target->setColor(Color32{uint8_t(_from.r + (_to.r - _from.r) * time),
22662263
(uint8_t)(_from.g + (_to.g - _from.g) * time),
2267-
(uint8_t)(_from.b + (_to.b - _from.b) * time)));
2264+
(uint8_t)(_from.b + (_to.b - _from.b) * time), opacity});
22682265
}
22692266
}
22702267

@@ -2311,7 +2308,7 @@ void TintBy::startWithTarget(Node* target)
23112308

23122309
if (target)
23132310
{
2314-
Color3B color = target->getColor();
2311+
auto color = target->getColor();
23152312
_fromR = color.r;
23162313
_fromG = color.g;
23172314
_fromB = color.b;
@@ -2322,8 +2319,10 @@ void TintBy::update(float time)
23222319
{
23232320
if (_target)
23242321
{
2325-
_target->setColor(Color3B((uint8_t)(_fromR + _deltaR * time), (uint8_t)(_fromG + _deltaG * time),
2326-
(uint8_t)(_fromB + _deltaB * time)));
2322+
// FIXME: do we should introduce opacity tint support in axmol-v3?
2323+
auto opacity = _target->getColor().a;
2324+
_target->setColor(Color32((uint8_t)(_fromR + _deltaR * time), (uint8_t)(_fromG + _deltaG * time),
2325+
(uint8_t)(_fromB + _deltaB * time), opacity));
23272326
}
23282327
}
23292328

‎core/2d/ActionInterval.h

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,19 +1282,14 @@ class AX_DLL TintTo : public ActionInterval
12821282
/**
12831283
* Creates an action with duration and color.
12841284
* @param duration Duration time, in seconds.
1285-
* @param red Red Color, from 0 to 255.
1286-
* @param green Green Color, from 0 to 255.
1287-
* @param blue Blue Color, from 0 to 255.
1285+
* @param color It's a Color32 type.
12881286
* @return An autoreleased TintTo object.
12891287
*/
1290-
static TintTo* create(float duration, uint8_t red, uint8_t green, uint8_t blue);
1291-
/**
1292-
* Creates an action with duration and color.
1293-
* @param duration Duration time, in seconds.
1294-
* @param color It's a Color3B type.
1295-
* @return An autoreleased TintTo object.
1296-
*/
1297-
static TintTo* create(float duration, const Color3B& color);
1288+
static TintTo* create(float duration, uint8_t r, uint8_t g, uint8_t b)
1289+
{
1290+
return TintTo::create(duration, Color32{r, g, b});
1291+
}
1292+
static TintTo* create(float duration, const Color32& color);
12981293

12991294
//
13001295
// Overrides
@@ -1311,11 +1306,11 @@ class AX_DLL TintTo : public ActionInterval
13111306
virtual ~TintTo() {}
13121307

13131308
/** initializes the action with duration and color */
1314-
bool initWithDuration(float duration, uint8_t red, uint8_t green, uint8_t blue);
1309+
bool initWithDuration(float duration, const Color32& color);
13151310

13161311
protected:
1317-
Color3B _to;
1318-
Color3B _from;
1312+
Color32 _to;
1313+
Color32 _from;
13191314

13201315
private:
13211316
AX_DISALLOW_COPY_AND_ASSIGN(TintTo);

‎core/2d/AtlasNode.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Copyright (c) 2010-2012 cocos2d-x.org
44
Copyright (c) 2011 Zynga Inc.
55
Copyright (c) 2013-2016 Chukong Technologies Inc.
66
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
7+
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
78
89
https://axmol.dev/
910
@@ -72,7 +73,7 @@ bool AtlasNode::initWithTexture(Texture2D* texture, int tileWidth, int tileHeigh
7273
_itemWidth = tileWidth;
7374
_itemHeight = tileHeight;
7475

75-
_colorUnmodified = Color3B::WHITE;
76+
_colorUnmodified = Color32::WHITE;
7677
_isOpacityModifyRGB = true;
7778

7879
_blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
@@ -145,7 +146,7 @@ void AtlasNode::draw(Renderer* renderer, const Mat4& transform, uint32_t flags)
145146

146147
// AtlasNode - RGBA protocol
147148

148-
const Color3B& AtlasNode::getColor() const
149+
const Color32& AtlasNode::getColor() const
149150
{
150151
if (_isOpacityModifyRGB)
151152
{
@@ -154,16 +155,15 @@ const Color3B& AtlasNode::getColor() const
154155
return Node::getColor();
155156
}
156157

157-
void AtlasNode::setColor(const Color3B& color3)
158+
void AtlasNode::setColor(const Color32& color)
158159
{
159-
Color3B tmp = color3;
160-
_colorUnmodified = color3;
161-
160+
Color32 tmp = color;
161+
_colorUnmodified = color;
162162
if (_isOpacityModifyRGB)
163163
{
164-
tmp.r = tmp.r * _displayedOpacity / 255;
165-
tmp.g = tmp.g * _displayedOpacity / 255;
166-
tmp.b = tmp.b * _displayedOpacity / 255;
164+
tmp.r = tmp.r * _displayedColor.a / 255;
165+
tmp.g = tmp.g * _displayedColor.a / 255;
166+
tmp.b = tmp.b * _displayedColor.a / 255;
167167
}
168168
Node::setColor(tmp);
169169
}
@@ -179,7 +179,7 @@ void AtlasNode::setOpacity(uint8_t opacity)
179179

180180
void AtlasNode::setOpacityModifyRGB(bool value)
181181
{
182-
Color3B oldColor = this->getColor();
182+
Color32 oldColor = this->getColor();
183183
_isOpacityModifyRGB = value;
184184
this->setColor(oldColor);
185185
}

‎core/2d/AtlasNode.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Copyright (c) 2010-2012 cocos2d-x.org
44
Copyright (c) 2011 Zynga Inc.
55
Copyright (c) 2013-2016 Chukong Technologies Inc.
66
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
7+
Copyright (c) 2019-present Axmol Engine contributors (see AUTHORS.md).
78
89
https://axmol.dev/
910
@@ -66,14 +67,14 @@ class AX_DLL AtlasNode : public Node, public TextureProtocol
6667
virtual void updateAtlasValues();
6768

6869
// Overrides
69-
virtual void draw(Renderer* renderer, const Mat4& transform, uint32_t flags) override;
70-
virtual Texture2D* getTexture() const override;
71-
virtual void setTexture(Texture2D* texture) override;
72-
virtual bool isOpacityModifyRGB() const override;
73-
virtual void setOpacityModifyRGB(bool isOpacityModifyRGB) override;
74-
virtual const Color3B& getColor() const override;
75-
virtual void setColor(const Color3B& color) override;
76-
virtual void setOpacity(uint8_t opacity) override;
70+
void draw(Renderer* renderer, const Mat4& transform, uint32_t flags) override;
71+
Texture2D* getTexture() const override;
72+
void setTexture(Texture2D* texture) override;
73+
bool isOpacityModifyRGB() const override;
74+
void setOpacityModifyRGB(bool isOpacityModifyRGB) override;
75+
const Color32& getColor() const override;
76+
void setColor(const Color32& color) override;
77+
void setOpacity(uint8_t opacity) override;
7778

7879
/**
7980
* @code
@@ -131,7 +132,7 @@ class AX_DLL AtlasNode : public Node, public TextureProtocol
131132
/** Height of each char. */
132133
int _itemHeight = 0;
133134

134-
Color3B _colorUnmodified;
135+
Color32 _colorUnmodified;
135136

136137
TextureAtlas* _textureAtlas = nullptr;
137138
/** Protocol variables. */

‎core/2d/DrawNode.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ void DrawNode::updateUniforms(const Mat4& transform, CustomCommand& cmd)
200200
auto mvpLocation = pipelineDescriptor.programState->getUniformLocation("u_MVPMatrix");
201201
pipelineDescriptor.programState->setUniform(mvpLocation, matrixMVP.m, sizeof(matrixMVP.m));
202202

203-
float alpha = _displayedOpacity / 255.0f;
203+
// FIXME: consider whether 'u_alpha' is a redundant uniform in shaders?
204+
float alpha = _displayedColor.a / 255.0f;
204205
auto alphaUniformLocation = pipelineDescriptor.programState->getUniformLocation("u_alpha");
205206
pipelineDescriptor.programState->setUniform(alphaUniformLocation, &alpha, sizeof(alpha));
206207
}

0 commit comments

Comments
 (0)