mirror of
https://github.com/minetest/irrlicht.git
synced 2025-07-01 15:50:27 +02:00
Reformat the code, using:
find -type f | # list all regular files grep -E '\.(h|cpp|mm)$' | # filter for source files grep -v '/mt_' | # filter out generated files grep -v '/vendor/' | # and vendored GL grep -v '/test/image_loader_test.cpp' | # and this file (has giant literals arrays) xargs -n 1 -P $(nproc) clang-format -i # reformat everything Co-authored-by: numzero <numzer0@yandex.ru>
This commit is contained in:
@ -13,22 +13,20 @@ namespace irr
|
||||
namespace gui
|
||||
{
|
||||
|
||||
CGUISpriteBank::CGUISpriteBank(IGUIEnvironment* env) :
|
||||
Environment(env), Driver(0)
|
||||
CGUISpriteBank::CGUISpriteBank(IGUIEnvironment *env) :
|
||||
Environment(env), Driver(0)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
#ifdef _DEBUG
|
||||
setDebugName("CGUISpriteBank");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (Environment)
|
||||
{
|
||||
if (Environment) {
|
||||
Driver = Environment->getVideoDriver();
|
||||
if (Driver)
|
||||
Driver->grab();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CGUISpriteBank::~CGUISpriteBank()
|
||||
{
|
||||
clear();
|
||||
@ -38,26 +36,22 @@ CGUISpriteBank::~CGUISpriteBank()
|
||||
Driver->drop();
|
||||
}
|
||||
|
||||
|
||||
core::array< core::rect<s32> >& CGUISpriteBank::getPositions()
|
||||
core::array<core::rect<s32>> &CGUISpriteBank::getPositions()
|
||||
{
|
||||
return Rectangles;
|
||||
}
|
||||
|
||||
|
||||
core::array< SGUISprite >& CGUISpriteBank::getSprites()
|
||||
core::array<SGUISprite> &CGUISpriteBank::getSprites()
|
||||
{
|
||||
return Sprites;
|
||||
}
|
||||
|
||||
|
||||
u32 CGUISpriteBank::getTextureCount() const
|
||||
{
|
||||
return Textures.size();
|
||||
}
|
||||
|
||||
|
||||
video::ITexture* CGUISpriteBank::getTexture(u32 index) const
|
||||
video::ITexture *CGUISpriteBank::getTexture(u32 index) const
|
||||
{
|
||||
if (index < Textures.size())
|
||||
return Textures[index];
|
||||
@ -65,8 +59,7 @@ video::ITexture* CGUISpriteBank::getTexture(u32 index) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void CGUISpriteBank::addTexture(video::ITexture* texture)
|
||||
void CGUISpriteBank::addTexture(video::ITexture *texture)
|
||||
{
|
||||
if (texture)
|
||||
texture->grab();
|
||||
@ -74,8 +67,7 @@ void CGUISpriteBank::addTexture(video::ITexture* texture)
|
||||
Textures.push_back(texture);
|
||||
}
|
||||
|
||||
|
||||
void CGUISpriteBank::setTexture(u32 index, video::ITexture* texture)
|
||||
void CGUISpriteBank::setTexture(u32 index, video::ITexture *texture)
|
||||
{
|
||||
while (index >= Textures.size())
|
||||
Textures.push_back(0);
|
||||
@ -89,13 +81,11 @@ void CGUISpriteBank::setTexture(u32 index, video::ITexture* texture)
|
||||
Textures[index] = texture;
|
||||
}
|
||||
|
||||
|
||||
//! clear everything
|
||||
void CGUISpriteBank::clear()
|
||||
{
|
||||
// drop textures
|
||||
for (u32 i=0; i<Textures.size(); ++i)
|
||||
{
|
||||
for (u32 i = 0; i < Textures.size(); ++i) {
|
||||
if (Textures[i])
|
||||
Textures[i]->drop();
|
||||
}
|
||||
@ -105,16 +95,16 @@ void CGUISpriteBank::clear()
|
||||
}
|
||||
|
||||
//! Add the texture and use it for a single non-animated sprite.
|
||||
s32 CGUISpriteBank::addTextureAsSprite(video::ITexture* texture)
|
||||
s32 CGUISpriteBank::addTextureAsSprite(video::ITexture *texture)
|
||||
{
|
||||
if ( !texture )
|
||||
if (!texture)
|
||||
return -1;
|
||||
|
||||
addTexture(texture);
|
||||
u32 textureIndex = getTextureCount() - 1;
|
||||
|
||||
u32 rectangleIndex = Rectangles.size();
|
||||
Rectangles.push_back( core::rect<s32>(0,0, texture->getOriginalSize().Width, texture->getOriginalSize().Height) );
|
||||
Rectangles.push_back(core::rect<s32>(0, 0, texture->getOriginalSize().Width, texture->getOriginalSize().Height));
|
||||
|
||||
SGUISprite sprite;
|
||||
sprite.frameTime = 0;
|
||||
@ -122,27 +112,26 @@ s32 CGUISpriteBank::addTextureAsSprite(video::ITexture* texture)
|
||||
SGUISpriteFrame frame;
|
||||
frame.textureNumber = textureIndex;
|
||||
frame.rectNumber = rectangleIndex;
|
||||
sprite.Frames.push_back( frame );
|
||||
sprite.Frames.push_back(frame);
|
||||
|
||||
Sprites.push_back( sprite );
|
||||
Sprites.push_back(sprite);
|
||||
|
||||
return Sprites.size() - 1;
|
||||
}
|
||||
|
||||
// get FrameNr for time. return true on exisiting frame
|
||||
inline bool CGUISpriteBank::getFrameNr(u32& frame,u32 index, u32 time, bool loop) const
|
||||
inline bool CGUISpriteBank::getFrameNr(u32 &frame, u32 index, u32 time, bool loop) const
|
||||
{
|
||||
frame = 0;
|
||||
if (index >= Sprites.size())
|
||||
return false;
|
||||
|
||||
const SGUISprite& sprite = Sprites[index];
|
||||
const SGUISprite &sprite = Sprites[index];
|
||||
const u32 frameSize = sprite.Frames.size();
|
||||
if (frameSize < 1)
|
||||
return false;
|
||||
|
||||
if (sprite.frameTime)
|
||||
{
|
||||
if (sprite.frameTime) {
|
||||
u32 f = (time / sprite.frameTime);
|
||||
if (loop)
|
||||
frame = f % frameSize;
|
||||
@ -153,15 +142,15 @@ inline bool CGUISpriteBank::getFrameNr(u32& frame,u32 index, u32 time, bool loop
|
||||
}
|
||||
|
||||
//! draws a sprite in 2d with scale and color
|
||||
void CGUISpriteBank::draw2DSprite(u32 index, const core::position2di& pos,
|
||||
const core::rect<s32>* clip, const video::SColor& color,
|
||||
void CGUISpriteBank::draw2DSprite(u32 index, const core::position2di &pos,
|
||||
const core::rect<s32> *clip, const video::SColor &color,
|
||||
u32 starttime, u32 currenttime, bool loop, bool center)
|
||||
{
|
||||
u32 frame = 0;
|
||||
if (!getFrameNr(frame, index, currenttime - starttime, loop))
|
||||
return;
|
||||
|
||||
const video::ITexture* tex = getTexture(Sprites[index].Frames[frame].textureNumber);
|
||||
const video::ITexture *tex = getTexture(Sprites[index].Frames[frame].textureNumber);
|
||||
if (!tex)
|
||||
return;
|
||||
|
||||
@ -169,24 +158,23 @@ void CGUISpriteBank::draw2DSprite(u32 index, const core::position2di& pos,
|
||||
if (rn >= Rectangles.size())
|
||||
return;
|
||||
|
||||
const core::rect<s32>& r = Rectangles[rn];
|
||||
const core::rect<s32> &r = Rectangles[rn];
|
||||
core::position2di p(pos);
|
||||
if (center)
|
||||
{
|
||||
if (center) {
|
||||
p -= r.getSize() / 2;
|
||||
}
|
||||
Driver->draw2DImage(tex, p, r, clip, color, true);
|
||||
}
|
||||
|
||||
void CGUISpriteBank::draw2DSprite(u32 index, const core::rect<s32>& destRect,
|
||||
const core::rect<s32>* clip, const video::SColor * const colors,
|
||||
void CGUISpriteBank::draw2DSprite(u32 index, const core::rect<s32> &destRect,
|
||||
const core::rect<s32> *clip, const video::SColor *const colors,
|
||||
u32 timeTicks, bool loop)
|
||||
{
|
||||
u32 frame = 0;
|
||||
if (!getFrameNr(frame,index, timeTicks, loop))
|
||||
if (!getFrameNr(frame, index, timeTicks, loop))
|
||||
return;
|
||||
|
||||
const video::ITexture* tex = getTexture(Sprites[index].Frames[frame].textureNumber);
|
||||
const video::ITexture *tex = getTexture(Sprites[index].Frames[frame].textureNumber);
|
||||
if (!tex)
|
||||
return;
|
||||
|
||||
@ -197,27 +185,25 @@ void CGUISpriteBank::draw2DSprite(u32 index, const core::rect<s32>& destRect,
|
||||
Driver->draw2DImage(tex, destRect, Rectangles[rn], clip, colors, true);
|
||||
}
|
||||
|
||||
void CGUISpriteBank::draw2DSpriteBatch( const core::array<u32>& indices,
|
||||
const core::array<core::position2di>& pos,
|
||||
const core::rect<s32>* clip,
|
||||
const video::SColor& color,
|
||||
u32 starttime, u32 currenttime,
|
||||
bool loop, bool center)
|
||||
void CGUISpriteBank::draw2DSpriteBatch(const core::array<u32> &indices,
|
||||
const core::array<core::position2di> &pos,
|
||||
const core::rect<s32> *clip,
|
||||
const video::SColor &color,
|
||||
u32 starttime, u32 currenttime,
|
||||
bool loop, bool center)
|
||||
{
|
||||
const irr::u32 drawCount = core::min_<u32>(indices.size(), pos.size());
|
||||
|
||||
if (!getTextureCount())
|
||||
return;
|
||||
core::array<SDrawBatch> drawBatches(getTextureCount());
|
||||
for (u32 i=0; i < Textures.size(); ++i)
|
||||
{
|
||||
for (u32 i = 0; i < Textures.size(); ++i) {
|
||||
drawBatches.push_back(SDrawBatch());
|
||||
drawBatches[i].positions.reallocate(drawCount);
|
||||
drawBatches[i].sourceRects.reallocate(drawCount);
|
||||
}
|
||||
|
||||
for (u32 i = 0; i < drawCount; ++i)
|
||||
{
|
||||
for (u32 i = 0; i < drawCount; ++i) {
|
||||
const u32 index = indices[i];
|
||||
|
||||
// work out frame number
|
||||
@ -226,38 +212,33 @@ void CGUISpriteBank::draw2DSpriteBatch( const core::array<u32>& indices,
|
||||
return;
|
||||
|
||||
const u32 texNum = Sprites[index].Frames[frame].textureNumber;
|
||||
if (texNum >= drawBatches.size())
|
||||
{
|
||||
if (texNum >= drawBatches.size()) {
|
||||
continue;
|
||||
}
|
||||
SDrawBatch& currentBatch = drawBatches[texNum];
|
||||
SDrawBatch ¤tBatch = drawBatches[texNum];
|
||||
|
||||
const u32 rn = Sprites[index].Frames[frame].rectNumber;
|
||||
if (rn >= Rectangles.size())
|
||||
return;
|
||||
|
||||
const core::rect<s32>& r = Rectangles[rn];
|
||||
const core::rect<s32> &r = Rectangles[rn];
|
||||
|
||||
if (center)
|
||||
{
|
||||
if (center) {
|
||||
core::position2di p = pos[i];
|
||||
p -= r.getSize() / 2;
|
||||
|
||||
currentBatch.positions.push_back(p);
|
||||
currentBatch.sourceRects.push_back(r);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
currentBatch.positions.push_back(pos[i]);
|
||||
currentBatch.sourceRects.push_back(r);
|
||||
}
|
||||
}
|
||||
|
||||
for(u32 i = 0;i < drawBatches.size();i++)
|
||||
{
|
||||
if(!drawBatches[i].positions.empty() && !drawBatches[i].sourceRects.empty())
|
||||
for (u32 i = 0; i < drawBatches.size(); i++) {
|
||||
if (!drawBatches[i].positions.empty() && !drawBatches[i].sourceRects.empty())
|
||||
Driver->draw2DImageBatch(getTexture(i), drawBatches[i].positions,
|
||||
drawBatches[i].sourceRects, clip, color, true);
|
||||
drawBatches[i].sourceRects, clip, color, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user