2017-01-11 18:50:07 +00:00
|
|
|
//
|
|
|
|
// Copyright (C) 1993-1996 by id Software, Inc.
|
|
|
|
//
|
|
|
|
// This source is available for distribution and/or modification
|
|
|
|
// only under the terms of the DOOM Source Code License as
|
|
|
|
// published by id Software. All rights reserved.
|
|
|
|
//
|
|
|
|
// The source is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
|
|
|
|
#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
|
|
|
|
{
|
2017-01-16 02:46:05 +00:00
|
|
|
VisibleSpriteList *VisibleSpriteList::Instance()
|
2017-01-11 18:50:07 +00:00
|
|
|
{
|
2017-01-16 02:46:05 +00:00
|
|
|
static VisibleSpriteList instance;
|
|
|
|
return &instance;
|
2017-01-11 18:50:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-01-16 02:46:05 +00:00
|
|
|
void VisibleSpriteList::Push(vissprite_t *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-16 02:46:05 +00:00
|
|
|
void VisibleSpriteList::Sort(bool compare2d)
|
2017-01-11 18:50:07 +00:00
|
|
|
{
|
2017-01-16 02:46:05 +00:00
|
|
|
size_t first = StartIndices.Size() == 0 ? 0 : StartIndices.Last();
|
|
|
|
size_t 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 02:46:05 +00:00
|
|
|
for (size_t i = 0; i < count; i++)
|
|
|
|
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 02:46:05 +00:00
|
|
|
for (size_t i = 0; i < count; i++)
|
|
|
|
SortedSprites[i] = Sprites[first + count - i - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (compare2d)
|
|
|
|
{
|
|
|
|
// This is an alternate version, for when one or more voxel is in view.
|
|
|
|
// It does a 2D distance test based on whichever one is furthest from
|
|
|
|
// the viewpoint.
|
|
|
|
|
|
|
|
std::stable_sort(&SortedSprites[0], &SortedSprites[count], [](vissprite_t *a, vissprite_t *b) -> bool
|
2017-01-11 18:50:07 +00:00
|
|
|
{
|
2017-01-16 02:46:05 +00:00
|
|
|
return DVector2(a->deltax, a->deltay).LengthSquared() < DVector2(b->deltax, b->deltay).LengthSquared();
|
|
|
|
});
|
2017-01-11 18:50:07 +00:00
|
|
|
}
|
2017-01-16 02:46:05 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// This is the standard version, which does a simple test based on depth.
|
2017-01-11 18:50:07 +00:00
|
|
|
|
2017-01-16 02:46:05 +00:00
|
|
|
std::stable_sort(&SortedSprites[0], &SortedSprites[count], [](vissprite_t *a, vissprite_t *b) -> bool
|
|
|
|
{
|
|
|
|
return a->idepth > b->idepth;
|
|
|
|
});
|
|
|
|
}
|
2017-01-11 18:50:07 +00:00
|
|
|
}
|
|
|
|
}
|