mirror of
https://github.com/DrBeef/Raze.git
synced 2025-02-20 18:52:43 +00:00
- vertex height map creator for precise render mode like in GZDoom.
This commit is contained in:
parent
3fee8f3c4e
commit
27ae8d627b
5 changed files with 160 additions and 0 deletions
|
@ -1059,6 +1059,7 @@ set (PCH_SOURCES
|
|||
core/rendering/hw_voxels.cpp
|
||||
core/rendering/hw_palmanager.cpp
|
||||
core/rendering/hw_sections.cpp
|
||||
core/rendering/hw_vertexmap.cpp
|
||||
core/rendering/scene/hw_clipper.cpp
|
||||
core/rendering/scene/hw_walls.cpp
|
||||
core/rendering/scene/hw_flats.cpp
|
||||
|
|
|
@ -31,6 +31,8 @@ Prepared for public release: 03/21/2003 - Charlie Wiederhold, 3D Realms
|
|||
#include "tarray.h"
|
||||
#include "tflags.h"
|
||||
#include "intvec.h"
|
||||
#include "binaryangle.h"
|
||||
#include "dobject.h"
|
||||
|
||||
//=============================================================================
|
||||
//
|
||||
|
|
|
@ -43,6 +43,8 @@
|
|||
#include "memarena.h"
|
||||
#include "c_cvars.h"
|
||||
|
||||
void CreateVertexMap();
|
||||
|
||||
FMemArena sectionArena(102400);
|
||||
|
||||
TMap<int, bool> bugged;
|
||||
|
@ -701,6 +703,7 @@ void hw_CreateSections()
|
|||
SplitLoops(builders);
|
||||
|
||||
ConstructSections(builders);
|
||||
CreateVertexMap();
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
|
|
132
source/core/rendering/hw_vertexmap.cpp
Normal file
132
source/core/rendering/hw_vertexmap.cpp
Normal file
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
** gl_vertexmap.cpp
|
||||
** Vertex management for precise wall rendering.
|
||||
**
|
||||
**---------------------------------------------------------------------------
|
||||
** Copyright 2021-2022 Christoph Oelckers
|
||||
** All rights reserved.
|
||||
**
|
||||
** Redistribution and use in source and binary forms, with or without
|
||||
** modification, are permitted provided that the following conditions
|
||||
** are met:
|
||||
**
|
||||
** 1. Redistributions of source code must retain the above copyright
|
||||
** notice, this list of conditions and the following disclaimer.
|
||||
** 2. Redistributions in binary form must reproduce the above copyright
|
||||
** notice, this list of conditions and the following disclaimer in the
|
||||
** documentation and/or other materials provided with the distribution.
|
||||
** 3. The name of the author may not be used to endorse or promote products
|
||||
** derived from this software without specific prior written permission.
|
||||
**
|
||||
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
**---------------------------------------------------------------------------
|
||||
**
|
||||
**
|
||||
*/
|
||||
|
||||
#include "basics.h"
|
||||
#include "maptypes.h"
|
||||
#include "memarena.h"
|
||||
#include "gamefuncs.h"
|
||||
#include "hw_vertexmap.h"
|
||||
|
||||
extern FMemArena sectionArena; // allocate from the same arena as the section as the data here has the same lifetime.
|
||||
|
||||
TArray<int> vertexMap; // maps walls to the vertex data.
|
||||
TArray<vertex_t> vertices;
|
||||
|
||||
|
||||
void CreateVertexMap()
|
||||
{
|
||||
BitArray processed(wall.Size());
|
||||
processed.Zero();
|
||||
TArray<int> walls;
|
||||
TArray<int> sectors;
|
||||
|
||||
vertices.Clear();
|
||||
vertexMap.Resize(wall.Size());
|
||||
|
||||
for (unsigned i = 0; i < wall.Size(); i++)
|
||||
{
|
||||
if (processed[i]) continue;
|
||||
walls.Clear();
|
||||
sectors.Clear();
|
||||
|
||||
vertexscan(&wall[i], [&](walltype* wal)
|
||||
{
|
||||
int w = wallnum(wal);
|
||||
walls.Push(w);
|
||||
processed.Set(w);
|
||||
if (!sectors.Contains(wal->sector))
|
||||
sectors.Push(wal->sector);
|
||||
});
|
||||
|
||||
vertices.Reserve(1);
|
||||
auto newvert = &vertices.Last();
|
||||
|
||||
newvert->masterwall = walls[0];
|
||||
newvert->viewangle = 0;
|
||||
newvert->angletime = 0;
|
||||
newvert->dirty = true;
|
||||
newvert->numheights = 0;
|
||||
|
||||
// allocate all data within this struct from the arena to simplify memory management.
|
||||
auto sect = (int*)sectionArena.Alloc(sectors.Size() * sizeof(int));
|
||||
newvert->sectors.Set(sect, sectors.Size());
|
||||
memcpy(sect, sectors.Data(), sectors.Size() * sizeof(int));
|
||||
|
||||
auto wals = (int*)sectionArena.Alloc(walls.Size() * sizeof(int));
|
||||
newvert->walls.Set(wals, walls.Size());
|
||||
memcpy(wals, walls.Data(), walls.Size() * sizeof(int));
|
||||
|
||||
// 2x number of sectors is currently the upper bound for the number of associated heights.
|
||||
newvert->heightlist = (float*)sectionArena.Alloc(sectors.Size() * sizeof(float));
|
||||
}
|
||||
}
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
// Recalculate all heights affecting this vertex.
|
||||
//
|
||||
//==========================================================================
|
||||
|
||||
void vertex_t::RecalcVertexHeights()
|
||||
{
|
||||
numheights = 0;
|
||||
for (auto& sect : sectors)
|
||||
{
|
||||
float heights[2];
|
||||
|
||||
auto point = wall[masterwall].pos;
|
||||
PlanesAtPoint(§or[sect], point.X, point.Y, &heights[0], &heights[1]);
|
||||
for(auto height : heights)
|
||||
{
|
||||
int k;
|
||||
for ( k = 0; k < numheights; k++)
|
||||
{
|
||||
if (height == heightlist[k]) break;
|
||||
if (height < heightlist[k])
|
||||
{
|
||||
memmove(&heightlist[k + 1], &heightlist[k], sizeof(float) * (numheights - k));
|
||||
heightlist[k] = height;
|
||||
numheights++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (k == numheights) heightlist[numheights++] = height;
|
||||
}
|
||||
}
|
||||
if (numheights <= 2) numheights = 0; // is not in need of any special attention
|
||||
dirty = false;
|
||||
}
|
||||
|
||||
|
22
source/core/rendering/hw_vertexmap.h
Normal file
22
source/core/rendering/hw_vertexmap.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
#include "basics.h"
|
||||
#include "tarray.h"
|
||||
|
||||
|
||||
struct vertex_t
|
||||
{
|
||||
int masterwall;
|
||||
angle_t viewangle; // precalculated angle for clipping
|
||||
int angletime; // recalculation time for view angle
|
||||
bool dirty; // something has changed and needs to be recalculated
|
||||
int numheights;
|
||||
TArrayView<int> sectors;
|
||||
TArrayView<int> walls;
|
||||
float * heightlist;
|
||||
|
||||
void RecalcVertexHeights();
|
||||
};
|
||||
|
||||
extern TArray<int> vertexMap; // maps walls to the vertex data.
|
||||
extern TArray<vertex_t> vertices;
|
Loading…
Reference in a new issue