2011-01-29 11:09:38 +00:00
|
|
|
/*
|
|
|
|
** r_3dfloors.cpp
|
|
|
|
** software 3D floors addon
|
|
|
|
**
|
|
|
|
** by kgsws
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "templates.h"
|
|
|
|
#include "doomdef.h"
|
|
|
|
#include "p_local.h"
|
|
|
|
#include "c_dispatch.h"
|
2017-01-11 19:42:39 +00:00
|
|
|
#include "r_opaque_pass.h"
|
2011-04-13 02:34:48 +00:00
|
|
|
#include "c_cvars.h"
|
2011-01-29 11:09:38 +00:00
|
|
|
#include "r_3dfloors.h"
|
2017-01-12 15:21:46 +00:00
|
|
|
#include "r_utility.h"
|
2017-02-03 23:25:37 +00:00
|
|
|
#include "swrenderer/r_renderthread.h"
|
2017-02-04 18:13:56 +00:00
|
|
|
#include "swrenderer/r_memory.h"
|
2011-01-29 11:09:38 +00:00
|
|
|
|
2016-12-01 01:38:32 +00:00
|
|
|
CVAR(Int, r_3dfloors, true, 0);
|
|
|
|
|
2016-12-22 04:20:53 +00:00
|
|
|
namespace swrenderer
|
2016-12-01 01:38:32 +00:00
|
|
|
{
|
2017-02-03 23:25:37 +00:00
|
|
|
Clip3DFloors::Clip3DFloors(RenderThread *thread)
|
2017-01-04 17:54:14 +00:00
|
|
|
{
|
2017-02-03 23:25:37 +00:00
|
|
|
Thread = thread;
|
2017-01-04 17:54:14 +00:00
|
|
|
}
|
2016-12-01 01:38:32 +00:00
|
|
|
|
2017-02-04 18:13:56 +00:00
|
|
|
void Clip3DFloors::SetFakeFloor(F3DFloor *newFakeFloor)
|
|
|
|
{
|
|
|
|
auto &clip = FakeFloors[newFakeFloor];
|
|
|
|
if (clip == nullptr)
|
|
|
|
{
|
|
|
|
clip = Thread->FrameMemory->NewObject<FakeFloorClip>(newFakeFloor);
|
|
|
|
}
|
|
|
|
fakeFloor = clip;
|
|
|
|
}
|
|
|
|
|
2017-01-04 17:54:14 +00:00
|
|
|
void Clip3DFloors::Cleanup()
|
|
|
|
{
|
2017-02-04 18:13:56 +00:00
|
|
|
FakeFloors.clear();
|
|
|
|
|
2017-01-04 17:54:14 +00:00
|
|
|
fakeActive = false;
|
|
|
|
fake3D = 0;
|
|
|
|
while (CurrentSkybox)
|
|
|
|
{
|
|
|
|
DeleteHeights();
|
|
|
|
LeaveSkybox();
|
|
|
|
}
|
|
|
|
ResetClip();
|
|
|
|
DeleteHeights();
|
2011-01-29 11:09:38 +00:00
|
|
|
}
|
|
|
|
|
2017-01-04 17:54:14 +00:00
|
|
|
void Clip3DFloors::DeleteHeights()
|
|
|
|
{
|
|
|
|
height_cur = height_top;
|
|
|
|
while (height_cur)
|
|
|
|
{
|
|
|
|
height_top = height_cur;
|
|
|
|
height_cur = height_cur->next;
|
|
|
|
M_Free(height_top);
|
2011-01-29 11:09:38 +00:00
|
|
|
}
|
2017-01-04 17:54:14 +00:00
|
|
|
height_max = -1;
|
|
|
|
height_top = height_cur = nullptr;
|
2011-01-29 11:09:38 +00:00
|
|
|
}
|
|
|
|
|
2017-01-04 17:54:14 +00:00
|
|
|
void Clip3DFloors::AddHeight(secplane_t *add, sector_t *sec)
|
|
|
|
{
|
|
|
|
HeightLevel *near;
|
|
|
|
HeightLevel *curr;
|
|
|
|
|
2017-03-11 22:28:07 +00:00
|
|
|
double height = add->ZatPoint(r_viewpoint.Pos);
|
2017-01-04 17:54:14 +00:00
|
|
|
if (height >= sec->CenterCeiling()) return;
|
|
|
|
if (height <= sec->CenterFloor()) return;
|
|
|
|
|
|
|
|
fakeActive = true;
|
|
|
|
|
|
|
|
if (height_max >= 0)
|
|
|
|
{
|
|
|
|
near = height_top;
|
|
|
|
while (near && near->height < height) near = near->next;
|
|
|
|
if (near)
|
|
|
|
{
|
|
|
|
if (near->height == height) return;
|
|
|
|
curr = (HeightLevel*)M_Malloc(sizeof(HeightLevel));
|
|
|
|
curr->height = height;
|
|
|
|
curr->prev = near->prev;
|
|
|
|
curr->next = near;
|
|
|
|
if (near->prev) near->prev->next = curr;
|
|
|
|
else height_top = curr;
|
|
|
|
near->prev = curr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
curr = (HeightLevel*)M_Malloc(sizeof(HeightLevel));
|
|
|
|
curr->height = height;
|
|
|
|
curr->prev = height_cur;
|
|
|
|
curr->next = nullptr;
|
|
|
|
height_cur->next = curr;
|
|
|
|
height_cur = curr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
height_top = height_cur = (HeightLevel*)M_Malloc(sizeof(HeightLevel));
|
|
|
|
height_top->height = height;
|
|
|
|
height_top->prev = nullptr;
|
|
|
|
height_top->next = nullptr;
|
|
|
|
}
|
|
|
|
height_max++;
|
2011-01-29 11:09:38 +00:00
|
|
|
}
|
|
|
|
|
2017-01-04 17:54:14 +00:00
|
|
|
void Clip3DFloors::NewClip()
|
2011-01-29 11:09:38 +00:00
|
|
|
{
|
2017-01-04 17:54:14 +00:00
|
|
|
ClipStack *curr;
|
|
|
|
|
|
|
|
curr = (ClipStack*)M_Malloc(sizeof(ClipStack));
|
|
|
|
curr->next = 0;
|
2017-02-03 23:25:37 +00:00
|
|
|
memcpy(curr->floorclip, Thread->OpaquePass->floorclip, sizeof(short) * MAXWIDTH);
|
|
|
|
memcpy(curr->ceilingclip, Thread->OpaquePass->ceilingclip, sizeof(short) * MAXWIDTH);
|
2017-01-04 17:54:14 +00:00
|
|
|
curr->ffloor = fakeFloor;
|
|
|
|
assert(fakeFloor->floorclip == nullptr);
|
|
|
|
assert(fakeFloor->ceilingclip == nullptr);
|
|
|
|
fakeFloor->floorclip = curr->floorclip;
|
|
|
|
fakeFloor->ceilingclip = curr->ceilingclip;
|
|
|
|
if (clip_top)
|
|
|
|
{
|
|
|
|
clip_cur->next = curr;
|
|
|
|
clip_cur = curr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clip_top = clip_cur = curr;
|
|
|
|
}
|
2011-01-29 11:09:38 +00:00
|
|
|
}
|
|
|
|
|
2017-01-04 17:54:14 +00:00
|
|
|
void Clip3DFloors::ResetClip()
|
|
|
|
{
|
|
|
|
clip_cur = clip_top;
|
|
|
|
while (clip_cur)
|
|
|
|
{
|
|
|
|
assert(clip_cur->ffloor->floorclip != nullptr);
|
|
|
|
assert(clip_cur->ffloor->ceilingclip != nullptr);
|
|
|
|
clip_cur->ffloor->ceilingclip = clip_cur->ffloor->floorclip = nullptr;
|
|
|
|
clip_top = clip_cur;
|
|
|
|
clip_cur = clip_cur->next;
|
|
|
|
M_Free(clip_top);
|
|
|
|
}
|
|
|
|
clip_cur = clip_top = nullptr;
|
|
|
|
}
|
2011-01-29 11:09:38 +00:00
|
|
|
|
2017-01-04 17:54:14 +00:00
|
|
|
void Clip3DFloors::EnterSkybox()
|
|
|
|
{
|
|
|
|
HeightStack current;
|
2011-01-29 11:09:38 +00:00
|
|
|
|
2017-01-04 17:54:14 +00:00
|
|
|
current.height_top = height_top;
|
|
|
|
current.height_cur = height_cur;
|
|
|
|
current.height_max = height_max;
|
2011-01-29 11:09:38 +00:00
|
|
|
|
2017-01-04 17:54:14 +00:00
|
|
|
toplist.Push(current);
|
2011-01-29 11:09:38 +00:00
|
|
|
|
2017-01-04 17:54:14 +00:00
|
|
|
height_top = nullptr;
|
|
|
|
height_cur = nullptr;
|
|
|
|
height_max = -1;
|
2011-01-29 11:09:38 +00:00
|
|
|
|
2017-01-04 17:54:14 +00:00
|
|
|
CurrentSkybox++;
|
|
|
|
}
|
2011-01-29 11:09:38 +00:00
|
|
|
|
2017-01-04 17:54:14 +00:00
|
|
|
void Clip3DFloors::LeaveSkybox()
|
|
|
|
{
|
|
|
|
HeightStack current;
|
2011-01-29 11:09:38 +00:00
|
|
|
|
2017-01-04 17:54:14 +00:00
|
|
|
current.height_top = nullptr;
|
|
|
|
current.height_cur = nullptr;
|
|
|
|
current.height_max = -1;
|
2011-01-29 11:09:38 +00:00
|
|
|
|
2017-01-04 17:54:14 +00:00
|
|
|
toplist.Pop(current);
|
2011-01-29 11:09:38 +00:00
|
|
|
|
2017-01-04 17:54:14 +00:00
|
|
|
height_top = current.height_top;
|
|
|
|
height_cur = current.height_cur;
|
|
|
|
height_max = current.height_max;
|
2011-01-29 11:09:38 +00:00
|
|
|
|
2017-01-04 17:54:14 +00:00
|
|
|
CurrentSkybox--;
|
|
|
|
}
|
2016-12-01 01:38:32 +00:00
|
|
|
}
|