- Backend update from Raze.

* TArray extensions
* MSVC setup so that [[deprecated]] emits warnings.
This commit is contained in:
Christoph Oelckers 2021-11-12 09:36:19 +01:00
parent 3cce406bd5
commit c598d9bab7
20 changed files with 348 additions and 29 deletions

View File

@ -245,7 +245,7 @@ if( MSVC )
set( DEB_C_FLAGS "/D _CRTDBG_MAP_ALLOC /MTd" )
# Disable warnings for unsecure CRT functions from VC8+
set( ALL_C_FLAGS "${ALL_C_FLAGS} /wd4996 /DUNICODE /D_UNICODE /D_WIN32_WINNT=0x0600" )
set( ALL_C_FLAGS "${ALL_C_FLAGS} /DUNICODE /D_UNICODE /D_WIN32_WINNT=0x0600 /D_CRT_SECURE_NO_DEPRECATE /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_WARNINGS" )
# The CMake configurations set /GR and /MD by default, which conflict with our settings.
string(REPLACE "/MD " " " CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} )

View File

@ -132,7 +132,7 @@ public:
RenderCommand()
{
memset(this, 0, sizeof(*this));
memset((void*)this, 0, sizeof(*this));
}
// If these fields match, two draw commands can be batched.

View File

@ -686,6 +686,17 @@ void ReadBindings(int lump, bool override)
FKeyBindings* dest = &Bindings;
int key;
if (sc.Compare("unbind"))
{
sc.MustGetString();
if (override)
{
// This is only for games to clear unsuitable base defaults, not for mods.
dest->UnbindKey(sc.String);
}
continue;
}
// bind destination is optional and is the same as the console command
if (sc.Compare("bind"))
{
@ -722,7 +733,18 @@ void ReadBindings(int lump, bool override)
void C_SetDefaultKeys(const char* baseconfig)
{
auto lump = fileSystem.CheckNumForFullName("engine/commonbinds.txt");
if (lump >= 0) ReadBindings(lump, true);
if (lump >= 0)
{
// Bail out if a mod tries to override this. Main game resources are allowed to do this, though.
auto fileno2 = fileSystem.GetFileContainer(lump);
if (fileno2 > fileSystem.GetMaxIwadNum())
{
I_FatalError("File %s is overriding core lump %s.",
fileSystem.GetResourceFileFullName(fileno2), "engine/commonbinds.txt");
}
ReadBindings(lump, true);
}
int lastlump = 0;
while ((lump = fileSystem.FindLumpFullName(baseconfig, &lastlump)) != -1)

View File

@ -42,7 +42,7 @@
//
//==========================================================================
struct GrpInfo
struct GrpHeader
{
uint32_t Magic[3];
uint32_t NumLumps;
@ -95,7 +95,7 @@ FGrpFile::FGrpFile(const char *filename, FileReader &file)
bool FGrpFile::Open(bool quiet, LumpFilterInfo*)
{
GrpInfo header;
GrpHeader header;
Reader.Read(&header, sizeof(header));
NumLumps = LittleLong(header.NumLumps);
@ -105,7 +105,7 @@ bool FGrpFile::Open(bool quiet, LumpFilterInfo*)
Lumps.Resize(NumLumps);
int Position = sizeof(GrpInfo) + NumLumps * sizeof(GrpLump);
int Position = sizeof(GrpHeader) + NumLumps * sizeof(GrpLump);
for(uint32_t i = 0; i < NumLumps; i++)
{

View File

@ -111,9 +111,9 @@ void I_InitGraphics ()
// todo: implement ATI version of this. this only works for nvidia notebooks, for now.
currentgpuswitch = vid_gpuswitch;
if (currentgpuswitch == 1)
putenv("SHIM_MCCOMPAT=0x800000001"); // discrete
_putenv("SHIM_MCCOMPAT=0x800000001"); // discrete
else if (currentgpuswitch == 2)
putenv("SHIM_MCCOMPAT=0x800000000"); // integrated
_putenv("SHIM_MCCOMPAT=0x800000000"); // integrated
// If the focus window is destroyed, it doesn't go back to the active window.
// (e.g. because the net pane was up, and a button on it had focus)

View File

@ -34,6 +34,7 @@
// HEADER FILES ------------------------------------------------------------
#pragma warning(disable:4996)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <richedit.h>

View File

@ -45,6 +45,7 @@
// HEADER FILES ------------------------------------------------------------
#pragma warning(disable:4996)
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

View File

@ -25,6 +25,17 @@
</Expand>
</Type>
<Type Name="TSparseArrayView&lt;*&gt;">
<DisplayString>Size = {Count}</DisplayString>
<Expand>
<Item Name="Size">Count</Item>
<ArrayItems>
<Size>Count</Size>
<ValuePointer>(value_type*)Array</ValuePointer>
</ArrayItems>
</Expand>
</Type>
<Type Name="TStaticPointedArray&lt;*&gt;">
<DisplayString>Size = {Count}</DisplayString>
<Expand>

View File

@ -12,10 +12,7 @@ struct HWSkyPortal;
struct HWDrawInfo;
// 57 world units roughly represent one sky texel for the glTranslate call.
enum
{
skyoffsetfactor = 57
};
const int skyoffsetfactor = 57;
struct FSkyVertex
{

View File

@ -21,7 +21,6 @@
*/
#include <stddef.h>
#include "poly_thread.h"
#include "screen_scanline_setup.h"
#include <cmath>

View File

@ -22,7 +22,6 @@
#include <stddef.h>
#include "filesystem.h"
#include "v_video.h"
#include "poly_triangle.h"

View File

@ -36,7 +36,7 @@
#include "flatvertices.h"
#include "r_videoscale.h"
#include "filesystem.h"
#include "templates.h"
EXTERN_CVAR(Int, gl_dither_bpc)

View File

@ -27,7 +27,7 @@
#include "vulkan/system/vk_builders.h"
#include "vulkan/system/vk_framebuffer.h"
#include "hw_cvars.h"
#include "templates.h"
VkRenderBuffers::VkRenderBuffers()
{

View File

@ -26,7 +26,7 @@
#include "vulkan/renderer/vk_renderpass.h"
#include "vulkan/renderer/vk_renderbuffers.h"
#include "vulkan/textures/vk_hwtexture.h"
#include "templates.h"
#include "hw_skydome.h"
#include "hw_viewpointuniforms.h"
#include "hw_lightbuffer.h"

View File

@ -26,7 +26,7 @@
#include "v_video.h"
#include "m_png.h"
#include "templates.h"
#include "r_videoscale.h"
#include "i_time.h"
#include "v_text.h"

View File

@ -20,7 +20,7 @@
**
*/
#include "templates.h"
#include "c_cvars.h"
#include "hw_material.h"
#include "hw_cvars.h"

View File

@ -572,7 +572,7 @@ void FMultipatchTextureBuilder::ParsePatch(FScanner &sc, BuildInfo &info, TexPar
else if (sc.Compare("alpha"))
{
sc.MustGetFloat();
part.Alpha = clamp<blend_t>(int(sc.Float * BLENDUNIT), 0, BLENDUNIT);
part.Alpha = clamp<blend_t>(int(sc.Float * +BLENDUNIT), 0, BLENDUNIT);
// bComplex is not set because it is only needed when the style is not OP_COPY.
}
else if (sc.Compare("style"))

View File

@ -29,6 +29,7 @@ RAPIDJSON_DIAG_PUSH
#ifdef _MSC_VER
RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
RAPIDJSON_DIAG_OFF(4244) // conversion from kXxxFlags to 'uint16_t', possible loss of data
RAPIDJSON_DIAG_OFF(4996) // deprecation of std::iterator
#endif
#ifdef __clang__

View File

@ -248,7 +248,7 @@ bool GetFileInfo(const char* pathname, size_t *size, time_t *time)
bool res = _wstat64(wstr.c_str(), &info) == 0;
#endif
if (!res || (info.st_mode & S_IFDIR)) return false;
if (size) *size = (size_t)info.st_size;
if (size) *size = info.st_size;
if (time) *time = info.st_mtime;
return res;
}

View File

@ -63,14 +63,14 @@
#include "m_alloc.h"
template<typename T> class TIterator : public std::iterator<std::random_access_iterator_tag, T>
template<typename T> class TIterator
{
public:
typedef typename TIterator::value_type value_type;
typedef typename TIterator::difference_type difference_type;
typedef typename TIterator::pointer pointer;
typedef typename TIterator::reference reference;
typedef typename TIterator::iterator_category iterator_category;
using iterator_category = std::random_access_iterator_tag;
using value_type = T;
using difference_type = ptrdiff_t;
using pointer = value_type*;
using reference = value_type&;
TIterator(T* ptr = nullptr) { m_ptr = ptr; }
@ -125,6 +125,8 @@ public:
typedef TIterator<T> iterator;
typedef TIterator<const T> const_iterator;
using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
typedef T value_type;
iterator begin()
@ -153,7 +155,32 @@ public:
return &Array[Count];
}
reverse_iterator rbegin()
{
return reverse_iterator(end());
}
const_reverse_iterator rbegin() const
{
return const_reverse_iterator(end());
}
const_reverse_iterator crbegin() const
{
return const_reverse_iterator(cend());
}
reverse_iterator rend()
{
return reverse_iterator(begin());
}
const_reverse_iterator rend() const
{
return const_reverse_iterator(begin());
}
const_reverse_iterator crend() const
{
return const_reverse_iterator(cbegin());
}
////////
// This is a dummy constructor that does nothing. The purpose of this
@ -636,6 +663,8 @@ public:
typedef TIterator<T> iterator;
typedef TIterator<const T> const_iterator;
using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
typedef T value_type;
iterator begin()
@ -664,6 +693,32 @@ public:
return &Array[Count];
}
reverse_iterator rbegin()
{
return reverse_iterator(end());
}
const_reverse_iterator rbegin() const
{
return const_reverse_iterator(end());
}
const_reverse_iterator crbegin() const
{
return const_reverse_iterator(cend());
}
reverse_iterator rend()
{
return reverse_iterator(begin());
}
const_reverse_iterator rend() const
{
return const_reverse_iterator(begin());
}
const_reverse_iterator crend() const
{
return const_reverse_iterator(cbegin());
}
void Init(T *ptr, unsigned cnt)
{
Array = ptr;
@ -1579,7 +1634,7 @@ public:
}
BitArray(unsigned elem)
: bytes((elem + 7) / 8, true)
: bytes((elem + 7) / 8, true), size(elem)
{
}
@ -1637,6 +1692,11 @@ public:
{
memset(&bytes[0], 0, bytes.Size());
}
TArray<uint8_t> &Storage()
{
return bytes;
}
};
@ -1704,6 +1764,8 @@ public:
typedef TIterator<T> iterator;
typedef TIterator<const T> const_iterator;
using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
typedef T value_type;
iterator begin()
@ -1732,6 +1794,32 @@ public:
return &Array[Count];
}
reverse_iterator rbegin()
{
return reverse_iterator(end());
}
const_reverse_iterator rbegin() const
{
return const_reverse_iterator(end());
}
const_reverse_iterator crbegin() const
{
return const_reverse_iterator(cend());
}
reverse_iterator rend()
{
return reverse_iterator(begin());
}
const_reverse_iterator rend() const
{
return const_reverse_iterator(begin());
}
const_reverse_iterator crend() const
{
return const_reverse_iterator(cbegin());
}
////////
TArrayView() = default; // intended to keep this type trivial.
@ -1807,3 +1895,203 @@ private:
T *Array;
unsigned int Count;
};
template<typename T> class TSparseIterator
{
public:
using iterator_category = std::random_access_iterator_tag;
using value_type = T;
using difference_type = ptrdiff_t;
using pointer = value_type*;
using reference = value_type&;
TSparseIterator(unsigned char* ptr = nullptr, unsigned stride = 0) { m_Ptr = ptr; Stride = stride; }
// Comparison operators
bool operator==(const TSparseIterator &other) const { return m_Ptr == other.m_Ptr; }
bool operator!=(const TSparseIterator &other) const { return m_Ptr != other.m_Ptr; }
bool operator< (const TSparseIterator &other) const { return m_Ptr < other.m_Ptr; }
bool operator<=(const TSparseIterator &other) const { return m_Ptr <= other.m_Ptr; }
bool operator> (const TSparseIterator &other) const { return m_Ptr > other.m_Ptr; }
bool operator>=(const TSparseIterator &other) const { return m_Ptr >= other.m_Ptr; }
// Arithmetic operators
TSparseIterator &operator++() { m_Ptr += Stride; return *this; }
TSparseIterator operator++(int) { auto tmp = *this; ++*this; return tmp; }
TSparseIterator &operator--() { m_Ptr -= Stride; return *this; }
TSparseIterator operator--(int) { auto tmp = *this; --*this; return tmp; }
TSparseIterator &operator+=(difference_type offset) { m_Ptr += offset * Stride; return *this; }
TSparseIterator operator+(difference_type offset) const { return TSparseIterator(m_Ptr + offset * Stride, Stride); }
friend TSparseIterator operator+(difference_type offset, const TSparseIterator &other) { return TSparseIterator(offset*other.Stride + other.m_Ptr, other.Stride); }
TSparseIterator &operator-=(difference_type offset) { m_Ptr -= offset * Stride; return *this; }
TSparseIterator operator-(difference_type offset) const { return TSparseIterator(m_Ptr - offset * Stride, Stride); }
difference_type operator-(const TSparseIterator &other) const { return (m_Ptr - other.m_Ptr) / Stride; }
// Random access operators
T& operator[](difference_type i) { return *(T*)(m_Ptr + i * Stride); }
const T& operator[](difference_type i) const { return *(T*)(m_Ptr + i * Stride); }
T &operator*() const { return (T*)m_Ptr; }
T* operator->() { return (T*)m_Ptr; }
protected:
unsigned char* m_Ptr;
unsigned Stride;
};
// A wrapper to externally stored data.
// Like the above but with a customizable stride
template <class T>
class TSparseArrayView
{
public:
typedef TSparseIterator<T> iterator;
typedef TSparseIterator<const T> const_iterator;
using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
typedef T value_type;
iterator begin()
{
return iterator(Array, Stride);
}
const_iterator begin() const
{
return const_iterator(Array, Stride);
}
const_iterator cbegin() const
{
return const_iterator(Array, Stride);
}
iterator end()
{
return iterator(Array + Count * Stride, Stride);
}
const_iterator end() const
{
return const_iterator(Array + Count * Stride, Stride);
}
const_iterator cend() const
{
return const_iterator(Array + Count * Stride, Stride);
}
reverse_iterator rbegin()
{
return reverse_iterator(end());
}
const_reverse_iterator rbegin() const
{
return const_reverse_iterator(end());
}
const_reverse_iterator crbegin() const
{
return const_reverse_iterator(cend());
}
reverse_iterator rend()
{
return reverse_iterator(begin());
}
const_reverse_iterator rend() const
{
return const_reverse_iterator(begin());
}
const_reverse_iterator crend() const
{
return const_reverse_iterator(cbegin());
}
////////
TSparseArrayView() = default; // intended to keep this type trivial.
TSparseArrayView(T *data, unsigned stride, unsigned count = 0)
{
Count = count;
Array = data;
Stride = stride;
}
TSparseArrayView(const TSparseArrayView<T> &other) = default;
TSparseArrayView<T> &operator= (const TSparseArrayView<T> &other) = default;
// Check equality of two arrays
bool operator==(const TArrayView<T> &other) const
{
if (Count != other.Count)
{
return false;
}
for (unsigned int i = 0; i < Count; ++i)
{
if (Element(i) != other.Element(i))
{
return false;
}
}
return true;
}
T &Element(size_t index)
{
return (T*)Array[index*Stride];
}
// Return a reference to an element
T &operator[] (size_t index) const
{
return Element(index);
}
// Returns a reference to the last element
T &Last() const
{
return Element(Count - 1);
}
// returns address of first element
T *Data() const
{
return &Element(0);
}
unsigned Size() const
{
return Count;
}
unsigned int Find(const T& item) const
{
unsigned int i;
for (i = 0; i < Count; ++i)
{
if (Element(i) == item)
break;
}
return i;
}
void Set(T *data, unsigned stride, unsigned count)
{
Array = reinterpret_cast<unsigned char*>(data);
Count = count;
Stride = stride;
}
void Set(void *data, unsigned stride, unsigned count)
{
Array = reinterpret_cast<unsigned char*>(data);
Count = count;
Stride = stride;
}
void Clear()
{
Count = 0;
Stride = 0;
Array = nullptr;
}
private:
unsigned char* Array;
unsigned int Count;
unsigned int Stride;
};