2017-04-17 10:27:19 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2017-01-11 18:50:07 +00:00
|
|
|
//
|
2017-04-17 10:27:19 +00:00
|
|
|
// Copyright 1993-1996 id Software
|
|
|
|
// Copyright 1999-2016 Randy Heit
|
|
|
|
// Copyright 2016 Magnus Norddahl
|
2017-01-11 18:50:07 +00:00
|
|
|
//
|
2017-04-17 10:27:19 +00:00
|
|
|
// This program 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, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
2017-01-11 18:50:07 +00:00
|
|
|
//
|
2017-04-17 10:27:19 +00:00
|
|
|
// This program is distributed in the hope that it will be useful,
|
2017-01-11 18:50:07 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2017-04-17 10:27:19 +00:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
2017-01-11 18:50:07 +00:00
|
|
|
//
|
2017-04-17 10:27:19 +00:00
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program. If not, see http://www.gnu.org/licenses/
|
|
|
|
//
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-01-11 18:50:07 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <algorithm>
|
|
|
|
#include "p_lnspec.h"
|
|
|
|
#include "templates.h"
|
|
|
|
#include "doomdef.h"
|
|
|
|
#include "m_swap.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "w_wad.h"
|
|
|
|
#include "g_levellocals.h"
|
|
|
|
#include "p_maputl.h"
|
|
|
|
#include "swrenderer/things/r_visiblesprite.h"
|
|
|
|
#include "swrenderer/things/r_visiblespritelist.h"
|
|
|
|
#include "swrenderer/r_memory.h"
|
|
|
|
|
|
|
|
namespace swrenderer
|
|
|
|
{
|
|
|
|
void VisibleSpriteList::Clear()
|
|
|
|
{
|
2017-01-16 02:46:05 +00:00
|
|
|
Sprites.Clear();
|
|
|
|
StartIndices.Clear();
|
|
|
|
SortedSprites.Clear();
|
2017-01-11 18:50:07 +00:00
|
|
|
}
|
|
|
|
|
2017-01-16 02:46:05 +00:00
|
|
|
void VisibleSpriteList::PushPortal()
|
2017-01-11 18:50:07 +00:00
|
|
|
{
|
2017-01-16 02:46:05 +00:00
|
|
|
StartIndices.Push(Sprites.Size());
|
2017-01-11 18:50:07 +00:00
|
|
|
}
|
|
|
|
|
2017-01-16 02:46:05 +00:00
|
|
|
void VisibleSpriteList::PopPortal()
|
2017-01-11 18:50:07 +00:00
|
|
|
{
|
2017-01-16 02:46:05 +00:00
|
|
|
Sprites.Resize(StartIndices.Last());
|
|
|
|
StartIndices.Pop();
|
2017-01-11 18:50:07 +00:00
|
|
|
}
|
|
|
|
|
2017-07-02 18:09:46 +00:00
|
|
|
void VisibleSpriteList::Push(VisibleSprite *sprite)
|
2017-01-11 18:50:07 +00:00
|
|
|
{
|
2017-01-16 02:46:05 +00:00
|
|
|
Sprites.Push(sprite);
|
2017-01-11 18:50:07 +00:00
|
|
|
}
|
|
|
|
|
2017-01-26 07:39:44 +00:00
|
|
|
void VisibleSpriteList::Sort()
|
2017-01-11 18:50:07 +00:00
|
|
|
{
|
2017-01-16 04:26:22 +00:00
|
|
|
unsigned int first = StartIndices.Size() == 0 ? 0 : StartIndices.Last();
|
|
|
|
unsigned int count = Sprites.Size() - first;
|
2017-01-11 18:50:07 +00:00
|
|
|
|
2017-01-16 02:46:05 +00:00
|
|
|
SortedSprites.Resize(count);
|
2017-01-11 18:50:07 +00:00
|
|
|
|
2017-01-16 02:46:05 +00:00
|
|
|
if (count == 0)
|
2017-01-11 18:50:07 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!(i_compatflags & COMPATF_SPRITESORT))
|
|
|
|
{
|
2017-01-16 04:26:22 +00:00
|
|
|
for (unsigned int i = 0; i < count; i++)
|
2017-01-16 02:46:05 +00:00
|
|
|
SortedSprites[i] = Sprites[first + i];
|
2017-01-11 18:50:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// If the compatibility option is on sprites of equal distance need to
|
|
|
|
// be sorted in inverse order. This is most easily achieved by
|
|
|
|
// filling the sort array backwards before the sort.
|
2017-01-16 04:26:22 +00:00
|
|
|
for (unsigned int i = 0; i < count; i++)
|
2017-01-16 02:46:05 +00:00
|
|
|
SortedSprites[i] = Sprites[first + count - i - 1];
|
|
|
|
}
|
|
|
|
|
2017-07-02 18:09:46 +00:00
|
|
|
std::stable_sort(&SortedSprites[0], &SortedSprites[count], [](VisibleSprite *a, VisibleSprite *b) -> bool
|
2017-01-16 02:46:05 +00:00
|
|
|
{
|
2017-07-02 18:09:46 +00:00
|
|
|
return a->SortDist() > b->SortDist();
|
|
|
|
});
|
2017-01-11 18:50:07 +00:00
|
|
|
}
|
|
|
|
}
|