- backend update from GZDoom

* replacement of 'long' in string code.
* palette removal in V_GetColor.
* fixes to DShape2D buffer management.
This commit is contained in:
Christoph Oelckers 2021-08-14 10:04:45 +02:00
parent c4c9f4acbe
commit bad2c2e55f
32 changed files with 242 additions and 180 deletions

View file

@ -124,7 +124,7 @@ static void Shape2D_Clear(DShape2D* self, int which)
if (which & C_Verts) self->mVertices.Clear();
if (which & C_Coords) self->mCoords.Clear();
if (which & C_Indices) self->mIndices.Clear();
self->needsVertexUpload = true;
self->bufferInfo->needsVertexUpload = true;
}
DEFINE_ACTION_FUNCTION_NATIVE(DShape2D, Clear, Shape2D_Clear)
@ -138,7 +138,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(DShape2D, Clear, Shape2D_Clear)
static void Shape2D_PushVertex(DShape2D* self, double x, double y)
{
self->mVertices.Push(DVector2(x, y));
self->needsVertexUpload = true;
self->bufferInfo->needsVertexUpload = true;
}
DEFINE_ACTION_FUNCTION_NATIVE(DShape2D, PushVertex, Shape2D_PushVertex)
@ -153,7 +153,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(DShape2D, PushVertex, Shape2D_PushVertex)
static void Shape2D_PushCoord(DShape2D* self, double u, double v)
{
self->mCoords.Push(DVector2(u, v));
self->needsVertexUpload = true;
self->bufferInfo->needsVertexUpload = true;
}
DEFINE_ACTION_FUNCTION_NATIVE(DShape2D, PushCoord, Shape2D_PushCoord)
@ -170,7 +170,7 @@ static void Shape2D_PushTriangle(DShape2D* self, int a, int b, int c)
self->mIndices.Push(a);
self->mIndices.Push(b);
self->mIndices.Push(c);
self->needsVertexUpload = true;
self->bufferInfo->needsVertexUpload = true;
}
DEFINE_ACTION_FUNCTION_NATIVE(DShape2D, PushTriangle, Shape2D_PushTriangle)
@ -528,13 +528,15 @@ void F2DDrawer::AddTexture(FGameTexture* img, DrawParms& parms)
offset = osave;
}
static TArray<RefCountedPtr<DShape2DBufferInfo>> buffersToDestroy;
void DShape2D::OnDestroy() {
if (lastParms) delete lastParms;
lastParms = nullptr;
mIndices.Reset();
mVertices.Reset();
mCoords.Reset();
buffers.Reset();
buffersToDestroy.Push(std::move(bufferInfo));
}
//==========================================================================
@ -567,11 +569,11 @@ void F2DDrawer::AddShape(FGameTexture* img, DShape2D* shape, DrawParms& parms)
shape->lastParms = new DrawParms(parms);
}
else if (shape->lastParms->vertexColorChange(parms)) {
shape->needsVertexUpload = true;
if (!shape->uploadedOnce) {
shape->bufIndex = -1;
shape->buffers.Clear();
shape->lastCommand = -1;
shape->bufferInfo->needsVertexUpload = true;
if (!shape->bufferInfo->uploadedOnce) {
shape->bufferInfo->bufIndex = -1;
shape->bufferInfo->buffers.Clear();
shape->bufferInfo->lastCommand = -1;
}
delete shape->lastParms;
shape->lastParms = new DrawParms(parms);
@ -583,7 +585,7 @@ void F2DDrawer::AddShape(FGameTexture* img, DShape2D* shape, DrawParms& parms)
auto osave = offset;
if (parms.nooffset) offset = { 0,0 };
if (shape->needsVertexUpload)
if (shape->bufferInfo->needsVertexUpload)
{
shape->minx = 16383;
shape->miny = 16383;
@ -622,15 +624,15 @@ void F2DDrawer::AddShape(FGameTexture* img, DShape2D* shape, DrawParms& parms)
dg.transform = shape->transform;
dg.transform.Cells[0][2] += offset.X;
dg.transform.Cells[1][2] += offset.Y;
dg.shape2D = shape;
dg.shape2DBufInfo = shape->bufferInfo;
dg.shape2DIndexCount = shape->mIndices.Size();
if (shape->needsVertexUpload)
if (shape->bufferInfo->needsVertexUpload)
{
shape->bufIndex += 1;
shape->bufferInfo->bufIndex += 1;
shape->buffers.Reserve(1);
shape->bufferInfo->buffers.Reserve(1);
auto buf = &shape->buffers[shape->bufIndex];
auto buf = &shape->bufferInfo->buffers[shape->bufferInfo->bufIndex];
auto verts = TArray<TwoDVertex>(dg.mVertCount, true);
for ( int i=0; i<dg.mVertCount; i++ )
@ -649,12 +651,12 @@ void F2DDrawer::AddShape(FGameTexture* img, DShape2D* shape, DrawParms& parms)
}
buf->UploadData(&verts[0], dg.mVertCount, &shape->mIndices[0], shape->mIndices.Size());
shape->needsVertexUpload = false;
shape->uploadedOnce = true;
shape->bufferInfo->needsVertexUpload = false;
shape->bufferInfo->uploadedOnce = true;
}
dg.shape2DBufIndex = shape->bufIndex;
shape->lastCommand += 1;
dg.shape2DCommandCounter = shape->lastCommand;
dg.shape2DBufIndex = shape->bufferInfo->bufIndex;
shape->bufferInfo->lastCommand += 1;
dg.shape2DCommandCounter = shape->bufferInfo->lastCommand;
AddCommand(&dg);
offset = osave;
}
@ -1082,6 +1084,17 @@ void F2DDrawer::Clear()
screenFade = 1.f;
}
//==========================================================================
//
//
//
//==========================================================================
void F2DDrawer::OnFrameDone()
{
buffersToDestroy.Clear();
}
F2DVertexBuffer::F2DVertexBuffer()
{
mVertexBuffer = screen->CreateVertexBuffer();

View file

@ -7,6 +7,7 @@
#include "textures.h"
#include "renderstyle.h"
#include "dobject.h"
#include "refcounted.h"
struct DrawParms;
struct FColormap;
@ -49,6 +50,7 @@ struct F2DPolygons
};
class DShape2D;
struct DShape2DBufferInfo;
class F2DDrawer
{
@ -123,7 +125,7 @@ public:
bool useTransform;
DMatrix3x3 transform;
DShape2D* shape2D;
RefCountedPtr<DShape2DBufferInfo> shape2DBufInfo;
int shape2DBufIndex;
int shape2DIndexCount;
int shape2DCommandCounter;
@ -136,7 +138,7 @@ public:
// If these fields match, two draw commands can be batched.
bool isCompatible(const RenderCommand &other) const
{
if (shape2D != nullptr || other.shape2D != nullptr) return false;
if (shape2DBufInfo != nullptr || other.shape2DBufInfo != nullptr) return false;
return mTexture == other.mTexture &&
mType == other.mType &&
mTranslationId == other.mTranslationId &&
@ -214,6 +216,7 @@ public:
void Begin(int w, int h) { isIn2D = true; Width = w; Height = h; }
void End() { isIn2D = false; }
bool HasBegun2D() { return isIn2D; }
void OnFrameDone();
void ClearClipRect() { clipleft = cliptop = 0; clipwidth = clipheight = -1; }
void SetClipRect(int x, int y, int w, int h);
@ -240,12 +243,22 @@ public:
bool mIsFirstPass = true;
};
struct DShape2DBufferInfo : NoVirtualRefCountedBase
{
TArray<F2DVertexBuffer> buffers;
bool needsVertexUpload = true;
int bufIndex = -1;
int lastCommand = -1;
bool uploadedOnce = false;
};
class DShape2D : public DObject
{
DECLARE_CLASS(DShape2D,DObject)
public:
DShape2D()
: bufferInfo(new DShape2DBufferInfo)
{
transform.Identity();
}
@ -261,12 +274,8 @@ public:
DMatrix3x3 transform;
TArray<F2DVertexBuffer> buffers;
bool needsVertexUpload = true;
int bufIndex = -1;
int lastCommand = -1;
RefCountedPtr<DShape2DBufferInfo> bufferInfo;
bool uploadedOnce = false;
DrawParms* lastParms;
void OnDestroy() override;

View file

@ -291,7 +291,7 @@ void FCommandBuffer::AddString(FString clip)
if (clip.IsNotEmpty())
{
// Only paste the first line.
long brk = clip.IndexOfAny("\r\n\b");
auto brk = clip.IndexOfAny("\r\n\b");
std::u32string build;
if (brk >= 0)
{

View file

@ -839,11 +839,11 @@ int FColorCVar::ToInt2 (UCVarValue value, ECVarType type)
if (string.IsNotEmpty())
{
ret = V_GetColorFromString (NULL, string);
ret = V_GetColorFromString (string);
}
else
{
ret = V_GetColorFromString (NULL, value.String);
ret = V_GetColorFromString (value.String);
}
}
else

View file

@ -533,7 +533,7 @@ FString BuildString (int argc, FString *argv)
else if (strchr(argv[arg], '"'))
{ // If it contains one or more quotes, we need to escape them.
buf << '"';
long substr_start = 0, quotepos;
ptrdiff_t substr_start = 0, quotepos;
while ((quotepos = argv[arg].IndexOf('"', substr_start)) >= 0)
{
if (substr_start < quotepos)

View file

@ -435,7 +435,7 @@ void FStringTable::InsertString(int lumpnum, int langid, FName label, const FStr
{
const char *strlangid = (const char *)&langid;
TableElement te = { fileSystem.GetFileContainer(lumpnum), { string, string, string, string } };
long index;
ptrdiff_t index;
while ((index = te.strings[0].IndexOf("@[")) >= 0)
{
auto endindex = te.strings[0].IndexOf(']', index);

View file

@ -1546,7 +1546,7 @@ bool FileSystem::CreatePathlessCopy(const char *name, int id, int /*flags*/)
if (lump < 0) return false; // Does not exist.
auto oldlump = FileInfo[lump];
int slash = oldlump.longName.LastIndexOf('/');
ptrdiff_t slash = oldlump.longName.LastIndexOf('/');
if (slash == -1)
{

View file

@ -348,8 +348,8 @@ void FResourceFile::PostProcessArchive(void *lumps, size_t lumpsize, LumpFilterI
uint32_t max = NumLumps;
max -= FilterLumpsByGameType(filter, lumps, lumpsize, max);
long len;
int lastpos = -1;
ptrdiff_t len;
ptrdiff_t lastpos = -1;
FString file;
FString LumpFilter = filter->dotFilter;
while ((len = LumpFilter.IndexOf('.', lastpos+1)) > 0)

View file

@ -415,19 +415,19 @@ void V_InitFontColors ()
else if (sc.Compare ("Flat:"))
{
sc.MustGetString();
logcolor = V_GetColor (nullptr, sc);
logcolor = V_GetColor (sc);
}
else
{
// Get first color
c = V_GetColor (nullptr, sc);
c = V_GetColor (sc);
tparm.Start[0] = RPART(c);
tparm.Start[1] = GPART(c);
tparm.Start[2] = BPART(c);
// Get second color
sc.MustGetString();
c = V_GetColor (nullptr, sc);
c = V_GetColor (sc);
tparm.End[0] = RPART(c);
tparm.End[1] = GPART(c);
tparm.End[2] = BPART(c);

View file

@ -88,7 +88,7 @@ TArray<FBrokenLines> V_BreakLines (FFont *font, int maxwidth, const uint8_t *str
{
if (*string == '[')
{
const uint8_t *start = string;
const uint8_t* start = string;
while (*string != ']' && *string != '\0')
{
string++;
@ -97,11 +97,6 @@ TArray<FBrokenLines> V_BreakLines (FFont *font, int maxwidth, const uint8_t *str
{
string++;
}
lastcolor = FString((const char *)start, string - start);
}
else
{
lastcolor = *string++;
}
}
continue;
@ -130,6 +125,33 @@ TArray<FBrokenLines> V_BreakLines (FFont *font, int maxwidth, const uint8_t *str
}
auto index = Lines.Reserve(1);
for (const uint8_t* pos = start; pos < space; pos++)
{
if (*pos == TEXTCOLOR_ESCAPE)
{
pos++;
if (*pos)
{
if (*pos == '[')
{
const uint8_t* cstart = pos;
while (*pos != ']' && *pos != '\0')
{
pos++;
}
if (*pos != '\0')
{
pos++;
}
lastcolor = FString((const char*)cstart, pos - start);
}
else
{
lastcolor = *pos++;
}
}
}
}
breakit (&Lines[index], font, start, space, linecolor);
if (c == '\n' && !preservecolor)
{

View file

@ -459,7 +459,7 @@ static void DoParseListMenuBody(FScanner &sc, DListMenuDescriptor *desc, bool &s
}
else if (args[i] == TypeColor)
{
params.Push(V_GetColor(nullptr, sc));
params.Push(V_GetColor(sc));
}
else if (args[i] == TypeFont)
{
@ -1028,7 +1028,7 @@ static void ParseOptionMenuBody(FScanner &sc, DOptionMenuDescriptor *desc, int i
}
else if (args[i] == TypeColor)
{
params.Push(V_GetColor(nullptr, sc));
params.Push(V_GetColor(sc));
}
else if (args[i]->isIntCompatible())
{
@ -1274,7 +1274,7 @@ static void ParseImageScrollerBody(FScanner& sc, DImageScrollerDescriptor* desc)
}
else if (args[i] == TypeColor)
{
params.Push(V_GetColor(nullptr, sc));
params.Push(V_GetColor(sc));
}
else if (args[i]->isIntCompatible())
{

View file

@ -90,8 +90,8 @@ static int FindGFXFile(FString & fn)
if (lump != -1) return lump;
int best = -1;
int dot = fn.LastIndexOf('.');
int slash = fn.LastIndexOf('/');
auto dot = fn.LastIndexOf('.');
auto slash = fn.LastIndexOf('/');
if (dot > slash) fn.Truncate(dot);
static const char * extensions[] = { ".png", ".jpg", ".tga", ".pcx", nullptr };

View file

@ -44,8 +44,8 @@ bool FOBJModel::Load(const char* fn, int lumpnum, const char* buffer, int length
{
// Ensure usemtl statements remain intact
TArray<FString> mtlUsages;
TArray<long> mtlUsageIdxs;
long bpos = 0, nlpos = 0, slashpos = 0;
TArray<ptrdiff_t> mtlUsageIdxs;
ptrdiff_t bpos = 0, nlpos = 0, slashpos = 0;
while (1)
{
bpos = objBuf.IndexOf("\nusemtl", bpos);
@ -58,7 +58,7 @@ bool FOBJModel::Load(const char* fn, int lumpnum, const char* buffer, int length
}
if (nlpos == -1)
{
nlpos = (long)objBuf.Len();
nlpos = objBuf.Len();
}
FString lineStr(objBuf.GetChars() + bpos, nlpos - bpos);
mtlUsages.Push(lineStr);
@ -76,7 +76,7 @@ bool FOBJModel::Load(const char* fn, int lumpnum, const char* buffer, int length
nlpos = objBuf.IndexOf('\n', bpos);
if (nlpos == -1)
{
nlpos = (long)objBuf.Len();
nlpos = objBuf.Len();
}
memcpy(wObjBuf + bpos, mtlUsages[i].GetChars(), nlpos - bpos);
}

View file

@ -52,15 +52,15 @@ static bool IsGlslWhitespace(char c)
}
}
static FString NextGlslToken(const char *chars, long len, long &pos)
static FString NextGlslToken(const char *chars, ptrdiff_t len, ptrdiff_t &pos)
{
// Eat whitespace
long tokenStart = pos;
ptrdiff_t tokenStart = pos;
while (tokenStart != len && IsGlslWhitespace(chars[tokenStart]))
tokenStart++;
// Find token end
long tokenEnd = tokenStart;
ptrdiff_t tokenEnd = tokenStart;
while (tokenEnd != len && !IsGlslWhitespace(chars[tokenEnd]) && chars[tokenEnd] != ';')
tokenEnd++;
@ -82,13 +82,13 @@ FString RemoveLegacyUserUniforms(FString code)
// The following code searches for legacy uniform declarations in the shader itself and replaces them with whitespace.
long len = (long)code.Len();
ptrdiff_t len = code.Len();
char *chars = code.LockBuffer();
long startIndex = 0;
ptrdiff_t startIndex = 0;
while (true)
{
long matchIndex = code.IndexOf("uniform", startIndex);
ptrdiff_t matchIndex = code.IndexOf("uniform", startIndex);
if (matchIndex == -1)
break;
@ -98,7 +98,7 @@ FString RemoveLegacyUserUniforms(FString code)
bool isKeywordEnd = matchIndex + 7 == len || IsGlslWhitespace(chars[matchIndex + 7]);
if (isKeywordStart && isKeywordEnd)
{
long pos = matchIndex + 7;
ptrdiff_t pos = matchIndex + 7;
FString type = NextGlslToken(chars, len, pos);
FString identifier = NextGlslToken(chars, len, pos);
@ -107,10 +107,10 @@ FString RemoveLegacyUserUniforms(FString code)
if (isLegacyUniformName)
{
long statementEndIndex = code.IndexOf(';', matchIndex + 7);
ptrdiff_t statementEndIndex = code.IndexOf(';', matchIndex + 7);
if (statementEndIndex == -1)
statementEndIndex = len;
for (long i = matchIndex; i <= statementEndIndex; i++)
for (ptrdiff_t i = matchIndex; i <= statementEndIndex; i++)
{
if (!IsGlslWhitespace(chars[i]))
chars[i] = ' ';
@ -127,7 +127,7 @@ FString RemoveLegacyUserUniforms(FString code)
// Modern GLSL only allows use of 'texture'.
while (true)
{
long matchIndex = code.IndexOf("texture2d", startIndex);
ptrdiff_t matchIndex = code.IndexOf("texture2d", startIndex);
if (matchIndex == -1)
break;
@ -148,14 +148,14 @@ FString RemoveLegacyUserUniforms(FString code)
FString RemoveSamplerBindings(FString code, TArray<std::pair<FString, int>> &samplerstobind)
{
long len = (long)code.Len();
ptrdiff_t len = code.Len();
char *chars = code.LockBuffer();
long startIndex = 0;
long startpos, endpos;
ptrdiff_t startIndex = 0;
ptrdiff_t startpos, endpos;
while (true)
{
long matchIndex = code.IndexOf("layout(binding", startIndex);
ptrdiff_t matchIndex = code.IndexOf("layout(binding", startIndex);
if (matchIndex == -1)
break;
@ -165,7 +165,7 @@ FString RemoveSamplerBindings(FString code, TArray<std::pair<FString, int>> &sam
bool isKeywordEnd = matchIndex + 14 == len || IsGlslWhitespace(chars[matchIndex + 14]) || chars[matchIndex + 14] == '=';
if (isKeywordStart && isKeywordEnd)
{
long pos = matchIndex + 14;
ptrdiff_t pos = matchIndex + 14;
startpos = matchIndex;
while (IsGlslWhitespace(chars[pos])) pos++;
if (chars[pos] == '=')
@ -175,7 +175,7 @@ FString RemoveSamplerBindings(FString code, TArray<std::pair<FString, int>> &sam
auto val = strtol(&chars[pos], &p, 0);
if (p != &chars[pos])
{
pos = long(p - chars);
pos = (p - chars);
while (IsGlslWhitespace(chars[pos])) pos++;
if (chars[pos] == ')')
{
@ -216,17 +216,17 @@ FString RemoveSamplerBindings(FString code, TArray<std::pair<FString, int>> &sam
FString RemoveLayoutLocationDecl(FString code, const char *inoutkeyword)
{
long len = (long)code.Len();
ptrdiff_t len = code.Len();
char *chars = code.LockBuffer();
long startIndex = 0;
ptrdiff_t startIndex = 0;
while (true)
{
long matchIndex = code.IndexOf("layout(location", startIndex);
ptrdiff_t matchIndex = code.IndexOf("layout(location", startIndex);
if (matchIndex == -1)
break;
long endIndex = matchIndex;
ptrdiff_t endIndex = matchIndex;
// Find end of layout declaration
while (chars[endIndex] != ')' && chars[endIndex] != 0)
@ -255,7 +255,7 @@ FString RemoveLayoutLocationDecl(FString code, const char *inoutkeyword)
if (keywordFound && IsGlslWhitespace(chars[endIndex + i]))
{
// yes - replace declaration with spaces
for (long i = matchIndex; i < endIndex; i++)
for (auto i = matchIndex; i < endIndex; i++)
chars[i] = ' ';
}

View file

@ -98,7 +98,8 @@ bool IShadowMap::PerformUpdate()
LightsProcessed = 0;
LightsShadowmapped = 0;
if (gl_lights && gl_light_shadowmap && (screen->hwcaps & RFL_SHADER_STORAGE_BUFFER) && CollectLights != nullptr)
// CollectLights will be null if the calling code decides that shadowmaps are not needed.
if (CollectLights != nullptr)
{
UpdateCycles.Clock();
UploadAABBTree();

View file

@ -178,22 +178,22 @@ void Draw2D(F2DDrawer *drawer, FRenderState &state)
state.EnableTexture(false);
}
if (cmd.shape2D != nullptr)
if (cmd.shape2DBufInfo != nullptr)
{
state.SetVertexBuffer(&cmd.shape2D->buffers[cmd.shape2DBufIndex]);
state.SetVertexBuffer(&cmd.shape2DBufInfo->buffers[cmd.shape2DBufIndex]);
state.DrawIndexed(DT_Triangles, 0, cmd.shape2DIndexCount);
state.SetVertexBuffer(&vb);
if (cmd.shape2DCommandCounter == cmd.shape2D->lastCommand)
if (cmd.shape2DCommandCounter == cmd.shape2DBufInfo->lastCommand)
{
cmd.shape2D->lastCommand = -1;
if (cmd.shape2D->bufIndex > 0)
cmd.shape2DBufInfo->lastCommand = -1;
if (cmd.shape2DBufInfo->bufIndex > 0)
{
cmd.shape2D->needsVertexUpload = true;
cmd.shape2D->buffers.Clear();
cmd.shape2D->bufIndex = -1;
cmd.shape2DBufInfo->needsVertexUpload = true;
cmd.shape2DBufInfo->buffers.Clear();
cmd.shape2DBufInfo->bufIndex = -1;
}
}
cmd.shape2D->uploadedOnce = false;
cmd.shape2DBufInfo->uploadedOnce = false;
}
else
{

View file

@ -154,7 +154,6 @@ int DisplayWidth, DisplayHeight;
// There's also only one, not four.
DFrameBuffer *screen;
CVAR(Bool, gl_lights, true, CVAR_ARCHIVE)
CVAR (Int, vid_defwidth, 640, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Int, vid_defheight, 480, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Bool, ticker, false, 0)

View file

@ -279,7 +279,6 @@ extern DFrameBuffer *screen;
#define SCREENPITCH (screen->GetPitch ())
EXTERN_CVAR (Float, vid_gamma)
EXTERN_CVAR(Bool, gl_lights)
// Allocates buffer screens, call before R_Init.

View file

@ -1328,7 +1328,7 @@ FxExpression *FxColorCast::Resolve(FCompileContext &ctx)
}
else
{
FxExpression *x = new FxConstant(V_GetColor(nullptr, constval.GetString(), &ScriptPosition), ScriptPosition);
FxExpression *x = new FxConstant(V_GetColor(constval.GetString(), &ScriptPosition), ScriptPosition);
delete this;
return x;
}

View file

@ -419,7 +419,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, Filter, StringFilter)
static int StringIndexOf(FString *self, const FString &substr, int startIndex)
{
return self->IndexOf(substr, startIndex);
return (int)self->IndexOf(substr, startIndex);
}
DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, IndexOf, StringIndexOf)
@ -427,12 +427,12 @@ DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, IndexOf, StringIndexOf)
PARAM_SELF_STRUCT_PROLOGUE(FString);
PARAM_STRING(substr);
PARAM_INT(startIndex);
ACTION_RETURN_INT(self->IndexOf(substr, startIndex));
ACTION_RETURN_INT(StringIndexOf(self, substr, startIndex));
}
static int StringLastIndexOf(FString *self, const FString &substr, int endIndex)
{
return self->LastIndexOfBroken(substr, endIndex);
return (int)self->LastIndexOfBroken(substr, endIndex);
}
DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, LastIndexOf, StringLastIndexOf)
@ -440,12 +440,12 @@ DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, LastIndexOf, StringLastIndexOf)
PARAM_SELF_STRUCT_PROLOGUE(FString);
PARAM_STRING(substr);
PARAM_INT(endIndex);
ACTION_RETURN_INT(self->LastIndexOfBroken(substr, endIndex));
ACTION_RETURN_INT(StringLastIndexOf(self, substr, endIndex));
}
static int StringRightIndexOf(FString *self, const FString &substr, int endIndex)
{
return self->LastIndexOf(substr, endIndex);
return (int)self->LastIndexOf(substr, endIndex);
}
DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, RightIndexOf, StringRightIndexOf)
@ -453,7 +453,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, RightIndexOf, StringRightIndexOf)
PARAM_SELF_STRUCT_PROLOGUE(FString);
PARAM_STRING(substr);
PARAM_INT(endIndex);
ACTION_RETURN_INT(self->LastIndexOf(substr, endIndex));
ACTION_RETURN_INT(StringRightIndexOf(self, substr, endIndex));
}
static void StringToUpper(FString *self)

View file

@ -49,7 +49,7 @@ static int CastS2I(FString *b) { return (int)b->ToLong(); }
static double CastS2F(FString *b) { return b->ToDouble(); }
static int CastS2N(FString *b) { return b->Len() == 0 ? NAME_None : FName(*b).GetIndex(); }
static void CastN2S(FString *a, int b) { FName name = FName(ENamedName(b)); *a = name.IsValidName() ? name.GetChars() : ""; }
static int CastS2Co(FString *b) { return V_GetColor(nullptr, *b); }
static int CastS2Co(FString *b) { return V_GetColor(*b); }
static void CastCo2S(FString *a, int b) { PalEntry c(b); a->Format("%02x %02x %02x", c.r, c.g, c.b); }
static int CastS2So(FString *b) { return FSoundID(*b); }
static void CastSo2S(FString* a, int b) { *a = soundEngine->GetSoundName(b); }

View file

@ -1826,7 +1826,7 @@ static void DoCast(const VMRegisters &reg, const VMFrame *f, int a, int b, int c
case CAST_S2Co:
ASSERTD(a); ASSERTS(b);
reg.d[a] = V_GetColor(NULL, reg.s[b]);
reg.d[a] = V_GetColor(reg.s[b]);
break;
case CAST_Co2S:

View file

@ -542,7 +542,7 @@ void FMultipatchTextureBuilder::ParsePatch(FScanner &sc, BuildInfo &info, TexPar
if (!sc.CheckNumber())
{
sc.MustGetString();
part.Blend = V_GetColor(NULL, sc);
part.Blend = V_GetColor(sc);
}
else
{

View file

@ -523,7 +523,7 @@ PalEntry averageColor(const uint32_t* data, int size, int maxout)
//
//==========================================================================
int V_GetColorFromString(const uint32_t* palette, const char* cstr, FScriptPosition* sc)
int V_GetColorFromString(const char* cstr, FScriptPosition* sc)
{
int c[3], i, p;
char val[3];
@ -609,10 +609,7 @@ int V_GetColorFromString(const uint32_t* palette, const char* cstr, FScriptPosit
}
}
}
if (palette)
return BestColor(palette, c[0], c[1], c[2]);
else
return MAKERGB(c[0], c[1], c[2]);
return MAKERGB(c[0], c[1], c[2]);
}
//==========================================================================
@ -715,26 +712,26 @@ FString V_GetColorStringByName(const char* name, FScriptPosition* sc)
//
//==========================================================================
int V_GetColor(const uint32_t* palette, const char* str, FScriptPosition* sc)
int V_GetColor(const char* str, FScriptPosition* sc)
{
FString string = V_GetColorStringByName(str, sc);
int res;
if (!string.IsEmpty())
{
res = V_GetColorFromString(palette, string, sc);
res = V_GetColorFromString(string, sc);
}
else
{
res = V_GetColorFromString(palette, str, sc);
res = V_GetColorFromString(str, sc);
}
return res;
}
int V_GetColor(const uint32_t* palette, FScanner& sc)
int V_GetColor(FScanner& sc)
{
FScriptPosition scc = sc;
return V_GetColor(palette, sc.String, &scc);
return V_GetColor(sc.String, &scc);
}
//==========================================================================

View file

@ -22,14 +22,14 @@ void HSVtoRGB (float *r, float *g, float *b, float h, float s, float v);
// Returns the closest color to the one desired. String
// should be of the form "rr gg bb".
int V_GetColorFromString(const uint32_t* palette, const char* colorstring, FScriptPosition* sc = nullptr);
int V_GetColorFromString(const char* colorstring, FScriptPosition* sc = nullptr);
// Scans through the X11R6RGB lump for a matching color
// and returns a color string suitable for V_GetColorFromString.
FString V_GetColorStringByName(const char* name, FScriptPosition* sc = nullptr);
// Tries to get color by name, then by string
int V_GetColor(const uint32_t* palette, const char* str, FScriptPosition* sc = nullptr);
int V_GetColor(const uint32_t* palette, FScanner& sc);
int V_GetColor(const char* str, FScriptPosition* sc = nullptr);
int V_GetColor(FScanner& sc);
PalEntry averageColor(const uint32_t* data, int size, int maxout);
enum

View file

@ -1,20 +1,29 @@
#pragma once
// Simple lightweight reference counting pointer alternative for std::shared_ptr which stores the reference counter in the handled object itself.
// Base class for handled objects
// Base classes for handled objects
class NoVirtualRefCountedBase
{
public:
void IncRef() { refCount++; }
void DecRef() { if (--refCount <= 0) delete this; }
private:
int refCount = 0;
};
class RefCountedBase
{
public:
void IncRef() { refCount++; }
void DecRef() { if (--refCount <= 0) delete this; }
void IncRef() { refCount++; }
void DecRef() { if (--refCount <= 0) delete this; }
private:
int refCount = 0;
int refCount = 0;
protected:
virtual ~RefCountedBase() = default;
virtual ~RefCountedBase() = default;
};
// The actual pointer object
// The actual pointer object
template<class T>
class RefCountedPtr
{
@ -31,10 +40,20 @@ public:
{
if (ptr) ptr->IncRef();
}
RefCountedPtr(const RefCountedPtr& r) : ptr(r.ptr)
{
if (ptr) ptr->IncRef();
}
RefCountedPtr(RefCountedPtr&& r) : ptr(r.ptr)
{
r.ptr = nullptr;
}
RefCountedPtr & operator=(const RefCountedPtr& r)
{
if (ptr != r.ptr)
if (this != &r)
{
if (ptr) ptr->DecRef();
ptr = r.ptr;
@ -54,11 +73,14 @@ public:
return *this;
}
RefCountedPtr & operator=(const RefCountedPtr&& r)
RefCountedPtr & operator=(RefCountedPtr&& r)
{
if (ptr) ptr->DecRef();
ptr = r.ptr;
r.ptr = nullptr;
if (this != &r)
{
if (ptr) ptr->DecRef();
ptr = r.ptr;
r.ptr = nullptr;
}
return *this;
}

View file

@ -95,7 +95,7 @@ bool FPlayList::ChangeList (const char *path)
}
// Check for relative paths.
long slashpos = song.IndexOf('/');
auto slashpos = song.IndexOf('/');
if (slashpos == 0)
{

View file

@ -422,7 +422,7 @@ void FString::Remove(size_t index, size_t remlen)
{
if (index + remlen >= Len())
{
Truncate((long)index);
Truncate(index);
}
else
{
@ -500,12 +500,12 @@ void FString::DeleteLastCharacter()
}
long FString::IndexOf (const FString &substr, long startIndex) const
ptrdiff_t FString::IndexOf (const FString &substr, ptrdiff_t startIndex) const
{
return IndexOf (substr.Chars, startIndex);
}
long FString::IndexOf (const char *substr, long startIndex) const
ptrdiff_t FString::IndexOf (const char *substr, ptrdiff_t startIndex) const
{
if (startIndex > 0 && Len() <= (size_t)startIndex)
{
@ -516,10 +516,10 @@ long FString::IndexOf (const char *substr, long startIndex) const
{
return -1;
}
return long(str - Chars);
return str - Chars;
}
long FString::IndexOf (char subchar, long startIndex) const
ptrdiff_t FString::IndexOf (char subchar, ptrdiff_t startIndex) const
{
if (startIndex > 0 && Len() <= (size_t)startIndex)
{
@ -530,15 +530,15 @@ long FString::IndexOf (char subchar, long startIndex) const
{
return -1;
}
return long(str - Chars);
return str - Chars;
}
long FString::IndexOfAny (const FString &charset, long startIndex) const
ptrdiff_t FString::IndexOfAny (const FString &charset, ptrdiff_t startIndex) const
{
return IndexOfAny (charset.Chars, startIndex);
}
long FString::IndexOfAny (const char *charset, long startIndex) const
ptrdiff_t FString::IndexOfAny (const char *charset, ptrdiff_t startIndex) const
{
if (startIndex > 0 && Len() <= (size_t)startIndex)
{
@ -549,19 +549,19 @@ long FString::IndexOfAny (const char *charset, long startIndex) const
{
return -1;
}
return long(brk - Chars);
return brk - Chars;
}
long FString::LastIndexOf (char subchar) const
ptrdiff_t FString::LastIndexOf (char subchar) const
{
return LastIndexOf (subchar, long(Len()));
return LastIndexOf (subchar, Len());
}
long FString::LastIndexOf (char subchar, long endIndex) const
ptrdiff_t FString::LastIndexOf (char subchar, ptrdiff_t endIndex) const
{
if ((size_t)endIndex > Len())
{
endIndex = long(Len());
endIndex = Len();
}
while (--endIndex >= 0)
{
@ -573,16 +573,16 @@ long FString::LastIndexOf (char subchar, long endIndex) const
return -1;
}
long FString::LastIndexOfBroken (const FString &_substr, long endIndex) const
ptrdiff_t FString::LastIndexOfBroken (const FString &_substr, ptrdiff_t endIndex) const
{
const char *substr = _substr.GetChars();
size_t substrlen = _substr.Len();
if ((size_t)endIndex > Len())
{
endIndex = long(Len());
endIndex = Len();
}
substrlen--;
while (--endIndex >= long(substrlen))
while (--endIndex >= ptrdiff_t(substrlen))
{
if (strncmp (substr, Chars + endIndex - substrlen, substrlen + 1) == 0)
{
@ -592,26 +592,26 @@ long FString::LastIndexOfBroken (const FString &_substr, long endIndex) const
return -1;
}
long FString::LastIndexOfAny (const FString &charset) const
ptrdiff_t FString::LastIndexOfAny (const FString &charset) const
{
return LastIndexOfAny (charset.Chars, long(Len()));
return LastIndexOfAny (charset.Chars, Len());
}
long FString::LastIndexOfAny (const char *charset) const
ptrdiff_t FString::LastIndexOfAny (const char *charset) const
{
return LastIndexOfAny (charset, long(Len()));
}
long FString::LastIndexOfAny (const FString &charset, long endIndex) const
ptrdiff_t FString::LastIndexOfAny (const FString &charset, ptrdiff_t endIndex) const
{
return LastIndexOfAny (charset.Chars, endIndex);
}
long FString::LastIndexOfAny (const char *charset, long endIndex) const
ptrdiff_t FString::LastIndexOfAny (const char *charset, ptrdiff_t endIndex) const
{
if ((size_t)endIndex > Len())
{
endIndex = long(Len());
endIndex = Len();
}
while (--endIndex >= 0)
{
@ -623,31 +623,31 @@ long FString::LastIndexOfAny (const char *charset, long endIndex) const
return -1;
}
long FString::LastIndexOf (const FString &substr) const
ptrdiff_t FString::LastIndexOf (const FString &substr) const
{
return LastIndexOf(substr.Chars, long(Len() - substr.Len()), substr.Len());
return LastIndexOf(substr.Chars, Len() - substr.Len(), substr.Len());
}
long FString::LastIndexOf (const FString &substr, long endIndex) const
ptrdiff_t FString::LastIndexOf (const FString &substr, ptrdiff_t endIndex) const
{
return LastIndexOf(substr.Chars, endIndex, substr.Len());
}
long FString::LastIndexOf (const char *substr) const
ptrdiff_t FString::LastIndexOf (const char *substr) const
{
return LastIndexOf(substr, long(Len() - strlen(substr)), strlen(substr));
return LastIndexOf(substr, Len() - strlen(substr), strlen(substr));
}
long FString::LastIndexOf (const char *substr, long endIndex) const
ptrdiff_t FString::LastIndexOf (const char *substr, ptrdiff_t endIndex) const
{
return LastIndexOf(substr, endIndex, strlen(substr));
}
long FString::LastIndexOf (const char *substr, long endIndex, size_t substrlen) const
ptrdiff_t FString::LastIndexOf (const char *substr, ptrdiff_t endIndex, size_t substrlen) const
{
if ((size_t)endIndex + substrlen > Len())
{
endIndex = long(Len() - substrlen);
endIndex = Len() - substrlen;
}
while (endIndex >= 0)
{
@ -1256,15 +1256,15 @@ void FString::Split(TArray<FString>& tokens, const char *delimiter, EmptyTokenTy
{
assert(nullptr != delimiter);
const long selfLen = static_cast<long>(Len());
const long delimLen = static_cast<long>(strlen(delimiter));
long lastPos = 0;
const auto selfLen = static_cast<ptrdiff_t>(Len());
const auto delimLen = static_cast<ptrdiff_t>(strlen(delimiter));
ptrdiff_t lastPos = 0;
if (selfLen == 0) return; // Empty strings do not contain tokens, even with TOK_KEEPEMPTY.
while (lastPos <= selfLen)
{
long pos = IndexOf(delimiter, lastPos);
auto pos = IndexOf(delimiter, lastPos);
if (-1 == pos)
{

View file

@ -215,28 +215,28 @@ public:
void AppendCharacter(int codepoint);
void DeleteLastCharacter();
long IndexOf (const FString &substr, long startIndex=0) const;
long IndexOf (const char *substr, long startIndex=0) const;
long IndexOf (char subchar, long startIndex=0) const;
ptrdiff_t IndexOf (const FString &substr, ptrdiff_t startIndex=0) const;
ptrdiff_t IndexOf (const char *substr, ptrdiff_t startIndex=0) const;
ptrdiff_t IndexOf (char subchar, ptrdiff_t startIndex=0) const;
long IndexOfAny (const FString &charset, long startIndex=0) const;
long IndexOfAny (const char *charset, long startIndex=0) const;
ptrdiff_t IndexOfAny (const FString &charset, ptrdiff_t startIndex=0) const;
ptrdiff_t IndexOfAny (const char *charset, ptrdiff_t startIndex=0) const;
// This is only kept for backwards compatibility with old ZScript versions that used this function and depend on its bug.
long LastIndexOf (char subchar) const;
long LastIndexOfBroken (const FString &substr, long endIndex) const;
long LastIndexOf (char subchar, long endIndex) const;
ptrdiff_t LastIndexOf (char subchar) const;
ptrdiff_t LastIndexOfBroken (const FString &substr, ptrdiff_t endIndex) const;
ptrdiff_t LastIndexOf (char subchar, ptrdiff_t endIndex) const;
long LastIndexOfAny (const FString &charset) const;
long LastIndexOfAny (const char *charset) const;
long LastIndexOfAny (const FString &charset, long endIndex) const;
long LastIndexOfAny (const char *charset, long endIndex) const;
ptrdiff_t LastIndexOfAny (const FString &charset) const;
ptrdiff_t LastIndexOfAny (const char *charset) const;
ptrdiff_t LastIndexOfAny (const FString &charset, ptrdiff_t endIndex) const;
ptrdiff_t LastIndexOfAny (const char *charset, ptrdiff_t endIndex) const;
long LastIndexOf (const FString &substr) const;
long LastIndexOf (const FString &substr, long endIndex) const;
long LastIndexOf (const char *substr) const;
long LastIndexOf (const char *substr, long endIndex) const;
long LastIndexOf (const char *substr, long endIndex, size_t substrlen) const;
ptrdiff_t LastIndexOf (const FString &substr) const;
ptrdiff_t LastIndexOf (const FString &substr, ptrdiff_t endIndex) const;
ptrdiff_t LastIndexOf (const char *substr) const;
ptrdiff_t LastIndexOf (const char *substr, ptrdiff_t endIndex) const;
ptrdiff_t LastIndexOf (const char *substr, ptrdiff_t endIndex, size_t substrlen) const;
void ToUpper ();
void ToLower ();

View file

@ -408,7 +408,7 @@ DEFINE_MAP_OPTION(fade, true)
{
parse.ParseAssign();
parse.sc.MustGetString();
info->fadeto = V_GetColor(nullptr, parse.sc);
info->fadeto = V_GetColor(parse.sc);
}
DEFINE_MAP_OPTION(partime, true)

View file

@ -698,7 +698,7 @@ static TArray<GrpEntry> SetupGame()
{
auto grplower = grp.FileName.MakeLower();
FixPathSeperator(grplower);
int pos = grplower.LastIndexOf(gamegrplower);
auto pos = grplower.LastIndexOf(gamegrplower);
if (pos >= 0 && pos == grplower.Len() - gamegrplower.Len())
{
groupno = g;

View file

@ -117,10 +117,10 @@ static TArray<FString> ParseGameInfo(TArray<FString>& pwads, const char* fn, con
else if (!nextKey.CompareNoCase("STARTUPCOLORS"))
{
sc.MustGetString();
GameStartupInfo.FgColor = V_GetColor(NULL, sc);
GameStartupInfo.FgColor = V_GetColor(sc);
sc.MustGetStringName(",");
sc.MustGetString();
GameStartupInfo.BkColor = V_GetColor(NULL, sc);
GameStartupInfo.BkColor = V_GetColor(sc);
}
else if (!nextKey.CompareNoCase("CON"))
{