2017-01-03 06:17:54 +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.
|
|
|
|
//
|
2016-12-28 06:04:13 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "templates.h"
|
|
|
|
#include "doomdef.h"
|
|
|
|
#include "m_bbox.h"
|
|
|
|
#include "i_system.h"
|
|
|
|
#include "p_lnspec.h"
|
|
|
|
#include "p_setup.h"
|
|
|
|
#include "a_sharedglobal.h"
|
|
|
|
#include "g_level.h"
|
|
|
|
#include "p_effect.h"
|
|
|
|
#include "doomstat.h"
|
|
|
|
#include "r_state.h"
|
|
|
|
#include "v_palette.h"
|
|
|
|
#include "r_sky.h"
|
|
|
|
#include "po_man.h"
|
|
|
|
#include "r_data/colormaps.h"
|
2017-01-03 06:13:40 +00:00
|
|
|
#include "d_net.h"
|
|
|
|
#include "swrenderer/r_memory.h"
|
|
|
|
#include "swrenderer/drawers/r_draw.h"
|
|
|
|
#include "swrenderer/scene/r_3dfloors.h"
|
2017-01-11 19:42:39 +00:00
|
|
|
#include "swrenderer/scene/r_opaque_pass.h"
|
2017-01-03 18:25:00 +00:00
|
|
|
#include "swrenderer/scene/r_portal.h"
|
2017-01-03 06:13:40 +00:00
|
|
|
#include "swrenderer/line/r_wallsetup.h"
|
|
|
|
#include "swrenderer/line/r_walldraw.h"
|
2017-01-03 18:16:37 +00:00
|
|
|
#include "swrenderer/line/r_fogboundary.h"
|
2016-12-31 11:45:07 +00:00
|
|
|
#include "swrenderer/segments/r_drawsegment.h"
|
2017-01-11 14:41:42 +00:00
|
|
|
#include "swrenderer/things/r_visiblesprite.h"
|
2017-01-12 15:21:46 +00:00
|
|
|
#include "swrenderer/scene/r_light.h"
|
2017-02-02 14:10:06 +00:00
|
|
|
#include "swrenderer/viewport/r_viewport.h"
|
2017-02-04 23:42:42 +00:00
|
|
|
#include "swrenderer/r_renderthread.h"
|
2017-01-11 14:41:42 +00:00
|
|
|
|
2016-12-28 06:04:13 +00:00
|
|
|
namespace swrenderer
|
|
|
|
{
|
2017-02-03 23:25:37 +00:00
|
|
|
DrawSegmentList::DrawSegmentList(RenderThread *thread)
|
2016-12-30 04:01:42 +00:00
|
|
|
{
|
2017-02-03 23:25:37 +00:00
|
|
|
Thread = thread;
|
2016-12-30 04:01:42 +00:00
|
|
|
}
|
|
|
|
|
2017-02-03 20:11:55 +00:00
|
|
|
void DrawSegmentList::Clear()
|
2016-12-30 04:01:42 +00:00
|
|
|
{
|
2017-02-03 20:11:55 +00:00
|
|
|
Segments.Clear();
|
|
|
|
StartIndices.Clear();
|
|
|
|
StartIndices.Push(0);
|
|
|
|
|
|
|
|
InterestingSegments.Clear();
|
|
|
|
StartInterestingIndices.Clear();
|
|
|
|
StartInterestingIndices.Push(0);
|
2016-12-30 04:01:42 +00:00
|
|
|
}
|
|
|
|
|
2017-02-03 20:11:55 +00:00
|
|
|
void DrawSegmentList::PushPortal()
|
2016-12-28 06:04:13 +00:00
|
|
|
{
|
2017-02-03 20:11:55 +00:00
|
|
|
StartIndices.Push(Segments.Size());
|
|
|
|
StartInterestingIndices.Push(InterestingSegments.Size());
|
2016-12-28 06:04:13 +00:00
|
|
|
}
|
|
|
|
|
2017-02-03 20:11:55 +00:00
|
|
|
void DrawSegmentList::PopPortal()
|
2016-12-30 04:01:42 +00:00
|
|
|
{
|
2017-02-03 20:11:55 +00:00
|
|
|
Segments.Resize(StartIndices.Last());
|
|
|
|
StartIndices.Pop();
|
|
|
|
|
2017-02-08 01:59:25 +00:00
|
|
|
InterestingSegments.Resize(StartInterestingIndices.Last());
|
2017-02-03 20:11:55 +00:00
|
|
|
StartInterestingIndices.Pop();
|
|
|
|
}
|
2016-12-30 04:01:42 +00:00
|
|
|
|
2017-02-03 20:11:55 +00:00
|
|
|
void DrawSegmentList::Push(DrawSegment *segment)
|
|
|
|
{
|
|
|
|
Segments.Push(segment);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawSegmentList::PushInteresting(DrawSegment *segment)
|
|
|
|
{
|
|
|
|
InterestingSegments.Push(segment);
|
2016-12-30 04:01:42 +00:00
|
|
|
}
|
2017-02-04 23:42:42 +00:00
|
|
|
|
|
|
|
void DrawSegmentList::BuildSegmentGroups()
|
|
|
|
{
|
|
|
|
SegmentGroups.Clear();
|
|
|
|
|
|
|
|
unsigned int groupSize = 100;
|
2017-02-09 21:58:28 +00:00
|
|
|
for (unsigned int index = 0; index < SegmentsCount(); index += groupSize)
|
2017-02-04 23:42:42 +00:00
|
|
|
{
|
|
|
|
auto ds = Segment(index);
|
|
|
|
|
|
|
|
DrawSegmentGroup group;
|
|
|
|
group.BeginIndex = index;
|
2017-02-09 21:58:28 +00:00
|
|
|
group.EndIndex = MIN(index + groupSize, SegmentsCount());
|
2017-02-04 23:42:42 +00:00
|
|
|
group.x1 = ds->x1;
|
|
|
|
group.x2 = ds->x2;
|
|
|
|
group.neardepth = MIN(ds->sz1, ds->sz2);
|
|
|
|
group.fardepth = MAX(ds->sz1, ds->sz2);
|
|
|
|
|
|
|
|
for (unsigned int groupIndex = group.BeginIndex + 1; groupIndex < group.EndIndex; groupIndex++)
|
|
|
|
{
|
|
|
|
ds = Segment(groupIndex);
|
|
|
|
group.x1 = MIN(group.x1, ds->x1);
|
|
|
|
group.x2 = MAX(group.x2, ds->x2);
|
|
|
|
group.neardepth = MIN(group.neardepth, ds->sz1);
|
|
|
|
group.neardepth = MIN(group.neardepth, ds->sz2);
|
|
|
|
group.fardepth = MAX(ds->sz1, group.fardepth);
|
|
|
|
group.fardepth = MAX(ds->sz2, group.fardepth);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int x = group.x1; x < group.x2; x++)
|
|
|
|
{
|
|
|
|
cliptop[x] = 0;
|
|
|
|
clipbottom[x] = viewheight;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned int groupIndex = group.BeginIndex; groupIndex < group.EndIndex; groupIndex++)
|
|
|
|
{
|
|
|
|
ds = Segment(groupIndex);
|
|
|
|
|
|
|
|
// kg3D - no clipping on fake segs
|
|
|
|
if (ds->fake) continue;
|
|
|
|
|
|
|
|
if (ds->silhouette & SIL_BOTTOM)
|
|
|
|
{
|
|
|
|
short *clip1 = clipbottom + ds->x1;
|
|
|
|
const short *clip2 = ds->sprbottomclip;
|
|
|
|
int i = ds->x2 - ds->x1;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (*clip1 > *clip2)
|
|
|
|
*clip1 = *clip2;
|
|
|
|
clip1++;
|
|
|
|
clip2++;
|
|
|
|
} while (--i);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ds->silhouette & SIL_TOP)
|
|
|
|
{
|
|
|
|
short *clip1 = cliptop + ds->x1;
|
|
|
|
const short *clip2 = ds->sprtopclip;
|
|
|
|
int i = ds->x2 - ds->x1;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (*clip1 < *clip2)
|
|
|
|
*clip1 = *clip2;
|
|
|
|
clip1++;
|
|
|
|
clip2++;
|
|
|
|
} while (--i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
group.sprtopclip = Thread->FrameMemory->AllocMemory<short>(group.x2 - group.x1);
|
|
|
|
group.sprbottomclip = Thread->FrameMemory->AllocMemory<short>(group.x2 - group.x1);
|
|
|
|
memcpy(group.sprtopclip, cliptop + group.x1, (group.x2 - group.x1) * sizeof(short));
|
|
|
|
memcpy(group.sprbottomclip, clipbottom + group.x1, (group.x2 - group.x1) * sizeof(short));
|
|
|
|
|
|
|
|
SegmentGroups.Push(group);
|
|
|
|
}
|
|
|
|
}
|
2016-12-28 06:04:13 +00:00
|
|
|
}
|