qzdoom/src/swrenderer/scene/r_3dfloors.cpp

185 lines
3.7 KiB
C++
Raw Normal View History

/*
** r_3dfloors.cpp
** software 3D floors addon
**
** by kgsws
*/
#include "templates.h"
#include "doomdef.h"
#include "p_local.h"
#include "c_dispatch.h"
#include "r_opaque_pass.h"
#include "c_cvars.h"
#include "r_3dfloors.h"
#include "r_utility.h"
#include "swrenderer/r_renderthread.h"
#include "swrenderer/r_memory.h"
CVAR(Int, r_3dfloors, true, 0);
2016-12-22 04:20:53 +00:00
namespace swrenderer
{
Clip3DFloors::Clip3DFloors(RenderThread *thread)
2017-01-04 17:54:14 +00:00
{
Thread = thread;
2017-01-04 17:54:14 +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()
{
FakeFloors.clear();
2017-01-04 17:54:14 +00:00
fakeActive = false;
fake3D = 0;
while (CurrentSkybox)
{
DeleteHeights();
LeaveSkybox();
}
ResetClip();
DeleteHeights();
}
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);
}
2017-01-04 17:54:14 +00:00
height_max = -1;
height_top = height_cur = nullptr;
}
2017-01-04 17:54:14 +00:00
void Clip3DFloors::AddHeight(secplane_t *add, sector_t *sec)
{
HeightLevel *near;
HeightLevel *curr;
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++;
}
2017-01-04 17:54:14 +00:00
void Clip3DFloors::NewClip()
{
2017-01-04 17:54:14 +00:00
ClipStack *curr;
curr = (ClipStack*)M_Malloc(sizeof(ClipStack));
curr->next = 0;
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;
}
}
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;
}
2017-01-04 17:54:14 +00:00
void Clip3DFloors::EnterSkybox()
{
HeightStack current;
2017-01-04 17:54:14 +00:00
current.height_top = height_top;
current.height_cur = height_cur;
current.height_max = height_max;
2017-01-04 17:54:14 +00:00
toplist.Push(current);
2017-01-04 17:54:14 +00:00
height_top = nullptr;
height_cur = nullptr;
height_max = -1;
2017-01-04 17:54:14 +00:00
CurrentSkybox++;
}
2017-01-04 17:54:14 +00:00
void Clip3DFloors::LeaveSkybox()
{
HeightStack current;
2017-01-04 17:54:14 +00:00
current.height_top = nullptr;
current.height_cur = nullptr;
current.height_max = -1;
2017-01-04 17:54:14 +00:00
toplist.Pop(current);
2017-01-04 17:54:14 +00:00
height_top = current.height_top;
height_cur = current.height_cur;
height_max = current.height_max;
2017-01-04 17:54:14 +00:00
CurrentSkybox--;
}
}