4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
10 /** @file viewport_sprite_sorter.h Types related to sprite sorting. */
13 #include "core/smallvec_type.hpp"
16 #ifndef VIEWPORT_SPRITE_SORTER_H
17 #define VIEWPORT_SPRITE_SORTER_H
19 /** Parent sprite that should be drawn */
20 struct ParentSpriteToDraw
{
21 /* Block of 16B loadable in xmm register */
22 int32 xmin
; ///< minimal world X coordinate of bounding box
23 int32 ymin
; ///< minimal world Y coordinate of bounding box
24 int32 zmin
; ///< minimal world Z coordinate of bounding box
25 int32 x
; ///< screen X coordinate of sprite
27 /* Second block of 16B loadable in xmm register */
28 int32 xmax
; ///< maximal world X coordinate of bounding box
29 int32 ymax
; ///< maximal world Y coordinate of bounding box
30 int32 zmax
; ///< maximal world Z coordinate of bounding box
31 int32 y
; ///< screen Y coordinate of sprite
33 SpriteID image
; ///< sprite to draw
34 PaletteID pal
; ///< palette to use
35 const SubSprite
*sub
; ///< only draw a rectangular part of the sprite
37 int32 left
; ///< minimal screen X coordinate of sprite (= x + sprite->x_offs), reference point for child sprites
38 int32 top
; ///< minimal screen Y coordinate of sprite (= y + sprite->y_offs), reference point for child sprites
40 int first_child
; ///< the first child to draw.
41 bool comparison_done
; ///< Used during sprite sorting: true if sprite has been compared with all other sprites
45 static inline void SortParentSprites (const T
&comparator
,
46 ParentSpriteToDraw
**psd
, const ParentSpriteToDraw
*const *psdvend
)
48 while (psd
!= psdvend
) {
49 ParentSpriteToDraw
*const ps
= *psd
;
51 if (ps
->comparison_done
) {
56 ps
->comparison_done
= true;
58 for (ParentSpriteToDraw
**psd2
= psd
+ 1; psd2
!= psdvend
; psd2
++) {
59 ParentSpriteToDraw
*const ps2
= *psd2
;
61 if (ps2
->comparison_done
) continue;
63 if (comparator (ps
, ps2
)) continue;
65 /* Move ps2 in front of ps */
66 for (ParentSpriteToDraw
**psd3
= psd2
; psd3
> psd
; psd3
--) {
75 void ViewportSortParentSpritesSSE41 (ParentSpriteToDraw
**psd
, const ParentSpriteToDraw
*const *psdvend
);
78 #endif /* VIEWPORT_SPRITE_SORTER_H */