From 905a9bfeae17954e1611fc36a9c570a6f1dab3d3 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 7 Jan 2023 19:30:49 +0100 Subject: [PATCH] - backend update from GZDoom. --- source/common/engine/serializer.cpp | 2 +- source/common/filesystem/filesystem.cpp | 2 +- source/common/fonts/font.cpp | 36 ++++++++-- source/common/fonts/hexfont.cpp | 12 ++-- source/common/fonts/v_font.cpp | 3 + source/common/fonts/v_font.h | 1 - source/common/menu/menu.cpp | 2 +- source/common/models/model_ue1.h | 5 +- source/common/models/models_ue1.cpp | 37 +++++----- source/common/models/models_voxel.cpp | 6 +- source/common/platform/win32/i_main.cpp | 2 +- source/common/scripting/backend/codegen.cpp | 69 +++++++++++++++++++ source/common/scripting/backend/codegen.h | 12 ++++ source/common/scripting/frontend/ast.cpp | 10 +++ .../common/scripting/frontend/zcc-parse.lemon | 12 ++++ .../common/scripting/frontend/zcc_compile.cpp | 22 ++++++ .../common/scripting/frontend/zcc_parser.cpp | 12 ++++ source/common/scripting/frontend/zcc_parser.h | 8 +++ .../scripting/interface/stringformat.cpp | 28 ++++++++ source/common/scripting/vm/vmexec.h | 4 ++ source/common/scripting/vm/vmframe.cpp | 2 +- source/common/textures/formats/anmtexture.cpp | 6 +- .../textures/formats/automaptexture.cpp | 6 +- .../common/textures/formats/buildtexture.cpp | 4 +- source/common/textures/formats/ddstexture.cpp | 6 +- .../common/textures/formats/emptytexture.cpp | 8 +-- .../common/textures/formats/flattexture.cpp | 6 +- source/common/textures/formats/fontchars.cpp | 4 +- source/common/textures/formats/fontchars.h | 2 +- .../common/textures/formats/imgztexture.cpp | 6 +- .../common/textures/formats/jpegtexture.cpp | 6 +- .../textures/formats/multipatchtexture.cpp | 4 +- .../textures/formats/multipatchtexture.h | 2 +- .../common/textures/formats/patchtexture.cpp | 8 +-- source/common/textures/formats/pcxtexture.cpp | 8 +-- source/common/textures/formats/pngtexture.cpp | 8 +-- .../textures/formats/rawpagetexture.cpp | 14 ++-- .../common/textures/formats/shadertexture.cpp | 4 +- .../textures/formats/startuptexture.cpp | 26 +++---- source/common/textures/formats/stbtexture.cpp | 6 +- source/common/textures/formats/tgatexture.cpp | 6 +- source/common/textures/image.cpp | 15 ++-- source/common/textures/image.h | 28 ++++++-- source/core/textures/tiletexture.cpp | 20 ++++-- 44 files changed, 360 insertions(+), 130 deletions(-) diff --git a/source/common/engine/serializer.cpp b/source/common/engine/serializer.cpp index 808b0fedc..8c68b5a3b 100644 --- a/source/common/engine/serializer.cpp +++ b/source/common/engine/serializer.cpp @@ -683,7 +683,7 @@ void FSerializer::ReadObjects(bool hubtravel) { r->mObjects.Clamp(size); // close all inner objects. // In case something in here throws an error, let's continue and deal with it later. - Printf(PRINT_NONOTIFY, TEXTCOLOR_RED "'%s'\n while restoring %s\n", err.GetMessage(), obj ? obj->GetClass()->TypeName.GetChars() : "invalid object"); + Printf(PRINT_NONOTIFY | PRINT_BOLD, TEXTCOLOR_RED "'%s'\n while restoring %s\n", err.GetMessage(), obj ? obj->GetClass()->TypeName.GetChars() : "invalid object"); mErrors++; } } diff --git a/source/common/filesystem/filesystem.cpp b/source/common/filesystem/filesystem.cpp index d4ef4e904..f18ad5138 100644 --- a/source/common/filesystem/filesystem.cpp +++ b/source/common/filesystem/filesystem.cpp @@ -1696,6 +1696,6 @@ CCMD(fs_dir) auto fnid = fileSystem.GetResourceId(i); auto length = fileSystem.FileLength(i); bool hidden = fileSystem.FindFile(fn1) != i; - Printf(PRINT_NONOTIFY, "%s%-64s %-15s (%5d) %10d %s %s\n", hidden ? TEXTCOLOR_RED : TEXTCOLOR_UNTRANSLATED, fn1, fns, fnid, length, container, hidden ? "(h)" : ""); + Printf(PRINT_HIGH | PRINT_NONOTIFY, "%s%-64s %-15s (%5d) %10d %s %s\n", hidden ? TEXTCOLOR_RED : TEXTCOLOR_UNTRANSLATED, fn1, fns, fnid, length, container, hidden ? "(h)" : ""); } } diff --git a/source/common/fonts/font.cpp b/source/common/fonts/font.cpp index e554f6366..011a9cadb 100644 --- a/source/common/fonts/font.cpp +++ b/source/common/fonts/font.cpp @@ -59,6 +59,7 @@ #include "fontinternals.h" +TArray sheetBitmaps; //========================================================================== @@ -367,10 +368,32 @@ FFont::FFont (const char *name, const char *nametemplate, const char *filetempla } } +class FSheetTexture : public FImageSource +{ + unsigned baseSheet; + int X, Y; + +public: + + FSheetTexture(unsigned source, int x, int y, int width, int height) + { + baseSheet = source; + Width = width; + Height = height; + X = x; + Y = y; + } + + int CopyPixels(FBitmap* dest, int conversion) + { + auto& pic = sheetBitmaps[baseSheet]; + dest->CopyPixelDataRGB(0, 0, pic.GetPixels() + 4 * (X + pic.GetWidth() * Y), Width, Height, 4, pic.GetWidth() * 4, 0, CF_BGRA); + return 0; + } + +}; void FFont::ReadSheetFont(TArray &folderdata, int width, int height, const DVector2 &Scale) { - // all valid lumps must be named with a hex number that represents the Unicode character index for its first character, - TArray part(1, true); TMap charMap; int minchar = INT_MAX; int maxchar = INT_MIN; @@ -391,14 +414,15 @@ void FFont::ReadSheetFont(TArray &folderdata, int width, int height if (minchar > position) minchar = int(position); if (maxchar < maxinsheet) maxchar = maxinsheet; + FBitmap* sheetimg = &sheetBitmaps[sheetBitmaps.Reserve(1)]; + sheetimg->Create(tex->GetTexelWidth(), tex->GetTexelHeight()); + tex->GetTexture()->GetImage()->CopyPixels(sheetimg, FImageSource::normal); + for (int y = 0; y < numtex_y; y++) { for (int x = 0; x < numtex_x; x++) { - part[0].OriginX = -width * x; - part[0].OriginY = -height * y; - part[0].TexImage = static_cast(tex->GetTexture()); - FMultiPatchTexture *image = new FMultiPatchTexture(width, height, part, false, false); + auto image = new FSheetTexture(sheetBitmaps.Size() - 1, x * width, y * width, width, height); FImageTexture *imgtex = new FImageTexture(image); auto gtex = MakeGameTexture(imgtex, nullptr, ETextureType::FontChar); gtex->SetWorldPanning(true); diff --git a/source/common/fonts/hexfont.cpp b/source/common/fonts/hexfont.cpp index d86f70f41..643b44d4d 100644 --- a/source/common/fonts/hexfont.cpp +++ b/source/common/fonts/hexfont.cpp @@ -109,7 +109,7 @@ class FHexFontChar : public FImageSource public: FHexFontChar(uint8_t *sourcedata, int swidth, int width, int height); - TArray CreatePalettedPixels(int conversion) override; + PalettedPixels CreatePalettedPixels(int conversion) override; int CopyPixels(FBitmap* bmp, int conversion); protected: @@ -144,10 +144,10 @@ FHexFontChar::FHexFontChar (uint8_t *sourcedata, int swidth, int width, int heig // //========================================================================== -TArray FHexFontChar::CreatePalettedPixels(int) +PalettedPixels FHexFontChar::CreatePalettedPixels(int) { int destSize = Width * Height; - TArray Pixels(destSize, true); + PalettedPixels Pixels(destSize); uint8_t *dest_p = Pixels.Data(); const uint8_t *src_p = SourceData; @@ -190,7 +190,7 @@ class FHexFontChar2 : public FHexFontChar public: FHexFontChar2(uint8_t *sourcedata, int swidth, int width, int height); - TArray CreatePalettedPixels(int conversion) override; + PalettedPixels CreatePalettedPixels(int conversion) override; int CopyPixels(FBitmap* bmp, int conversion); }; @@ -216,10 +216,10 @@ FHexFontChar2::FHexFontChar2(uint8_t *sourcedata, int swidth, int width, int hei // //========================================================================== -TArray FHexFontChar2::CreatePalettedPixels(int) +PalettedPixels FHexFontChar2::CreatePalettedPixels(int) { int destSize = Width * Height; - TArray Pixels(destSize, true); + PalettedPixels Pixels(destSize); uint8_t *dest_p = Pixels.Data(); assert(SourceData); diff --git a/source/common/fonts/v_font.cpp b/source/common/fonts/v_font.cpp index dd3e47648..f51813aeb 100644 --- a/source/common/fonts/v_font.cpp +++ b/source/common/fonts/v_font.cpp @@ -73,6 +73,7 @@ static int TranslationMapCompare (const void *a, const void *b); // EXTERNAL DATA DECLARATIONS ---------------------------------------------- extern int PrintColors[]; +extern TArray sheetBitmaps; // PUBLIC DATA DEFINITIONS ------------------------------------------------- FFont* SmallFont, * SmallFont2, * BigFont, * BigUpper, * ConFont, * IntermissionFont, * NewConsoleFont, * NewSmallFont, @@ -863,6 +864,7 @@ EColorRange V_ParseFontColor (const uint8_t *&color_value, int normalcolor, int void V_InitFonts() { + sheetBitmaps.Clear(); CreateLuminosityTranslationRanges(); V_InitCustomFonts(); @@ -929,6 +931,7 @@ void V_ClearFonts() } FFont::FirstFont = nullptr; AlternativeSmallFont = OriginalSmallFont = CurrentConsoleFont = NewSmallFont = NewConsoleFont = SmallFont = SmallFont2 = BigFont = ConFont = IntermissionFont = nullptr; + sheetBitmaps.Clear(); } //========================================================================== diff --git a/source/common/fonts/v_font.h b/source/common/fonts/v_font.h index 72fd49e29..343cbaf5d 100644 --- a/source/common/fonts/v_font.h +++ b/source/common/fonts/v_font.h @@ -208,7 +208,6 @@ protected: friend void V_InitFonts(); }; - extern FFont *SmallFont, *SmallFont2, *BigFont, *BigUpper, *ConFont, *IntermissionFont, *NewConsoleFont, *NewSmallFont, *CurrentConsoleFont, *OriginalSmallFont, *AlternativeSmallFont, *OriginalBigFont, *AlternativeBigFont; void V_InitFonts(); diff --git a/source/common/menu/menu.cpp b/source/common/menu/menu.cpp index deee74597..c5890080c 100644 --- a/source/common/menu/menu.cpp +++ b/source/common/menu/menu.cpp @@ -925,7 +925,7 @@ void M_Init (void) catch (CVMAbortException &err) { err.MaybePrintMessage(); - Printf(PRINT_NONOTIFY, "%s", err.stacktrace.GetChars()); + Printf(PRINT_NONOTIFY | PRINT_BOLD, "%s", err.stacktrace.GetChars()); I_FatalError("Failed to initialize menus"); } M_CreateMenus(); diff --git a/source/common/models/model_ue1.h b/source/common/models/model_ue1.h index 5123a22e9..9b529b44c 100644 --- a/source/common/models/model_ue1.h +++ b/source/common/models/model_ue1.h @@ -35,7 +35,6 @@ public: { mDataLump = -1; mAnivLump = -1; - mDataLoaded = false; dhead = NULL; dpolys = NULL; ahead = NULL; @@ -49,7 +48,6 @@ public: private: int mDataLump, mAnivLump; - bool mDataLoaded; // raw data structures struct d3dhead @@ -105,9 +103,10 @@ private: int numFrames; int numPolys; int numGroups; - TArray specialPolys; // for future model attachment support, unused for now + bool hasWeaponTriangle; TArray verts; TArray polys; TArray groups; + //TArray weapondata; // pseudo-bone generated from weapon triangle (not yet implemented) }; diff --git a/source/common/models/models_ue1.cpp b/source/common/models/models_ue1.cpp index 70245bc45..5db36a672 100644 --- a/source/common/models/models_ue1.cpp +++ b/source/common/models/models_ue1.cpp @@ -165,13 +165,17 @@ void FUE1Model::LoadGeometry() // populate poly groups (subdivided by texture number and type) // this method minimizes searches in the group list as much as possible // while still doing a single pass through the poly list + groups.Reset(); int curgroup = -1; UE1Group Group; + hasWeaponTriangle = false; + int weapontri = -1; for ( int i=0; iGetType())) return; - if ( !mDataLoaded ) - LoadGeometry(); + LoadGeometry(); int vsize = 0; for ( int i=0; iUnlockVertexBuffer(); + UnloadGeometry(); // don't forget this, save precious RAM } void FUE1Model::AddSkins( uint8_t *hitlist, const FTextureID* surfaceskinids) @@ -320,5 +323,5 @@ void FUE1Model::AddSkins( uint8_t *hitlist, const FTextureID* surfaceskinids) FUE1Model::~FUE1Model() { - UnloadGeometry(); + groups.Reset(); } diff --git a/source/common/models/models_voxel.cpp b/source/common/models/models_voxel.cpp index 6af34cf23..f723d1fe4 100644 --- a/source/common/models/models_voxel.cpp +++ b/source/common/models/models_voxel.cpp @@ -58,7 +58,7 @@ public: FVoxelTexture(FVoxel *voxel); int CopyPixels(FBitmap *bmp, int conversion) override; - TArray CreatePalettedPixels(int conversion) override; + PalettedPixels CreatePalettedPixels(int conversion) override; protected: FVoxel *SourceVox; @@ -84,10 +84,10 @@ FVoxelTexture::FVoxelTexture(FVoxel *vox) // //=========================================================================== -TArray FVoxelTexture::CreatePalettedPixels(int conversion) +PalettedPixels FVoxelTexture::CreatePalettedPixels(int conversion) { // GetPixels gets called when a translated palette is used so we still need to implement it here. - TArray Pixels(256, true); + PalettedPixels Pixels(256); uint8_t *pp = SourceVox->Palette.Data(); if(pp != NULL) diff --git a/source/common/platform/win32/i_main.cpp b/source/common/platform/win32/i_main.cpp index 8ef92e880..f153a1dac 100644 --- a/source/common/platform/win32/i_main.cpp +++ b/source/common/platform/win32/i_main.cpp @@ -548,7 +548,7 @@ int WINAPI wWinMain (HINSTANCE hInstance, HINSTANCE nothing, LPWSTR cmdline, int _CrtSetDbgFlag (_CrtSetDbgFlag(0) | _CRTDBG_LEAK_CHECK_DF); // Use this to break at a specific allocation number. - _crtBreakAlloc = 380659; + //_crtBreakAlloc = 227524; #endif int ret = DoMain (hInstance); diff --git a/source/common/scripting/backend/codegen.cpp b/source/common/scripting/backend/codegen.cpp index 6cf593fa2..a816ab437 100644 --- a/source/common/scripting/backend/codegen.cpp +++ b/source/common/scripting/backend/codegen.cpp @@ -2718,6 +2718,75 @@ ExpEmit FxMultiAssign::Emit(VMFunctionBuilder *build) return LocalVarContainer->Emit(build); } + +//========================================================================== +// +// +// +//========================================================================== + +FxMultiAssignDecl::FxMultiAssignDecl(FArgumentList &base, FxExpression *right, const FScriptPosition &pos) + :FxExpression(EFX_MultiAssignDecl, pos) +{ + Base = std::move(base); + Right = right; +} + +//========================================================================== +// +// +// +//========================================================================== + +FxMultiAssignDecl::~FxMultiAssignDecl() +{ + SAFE_DELETE(Right); +} + +//========================================================================== +// +// +// +//========================================================================== + +FxExpression *FxMultiAssignDecl::Resolve(FCompileContext &ctx) +{ + CHECKRESOLVED(); + SAFE_RESOLVE(Right, ctx); + if (Right->ExprType != EFX_VMFunctionCall) + { + Right->ScriptPosition.Message(MSG_ERROR, "Function call expected on right side of multi-assigment"); + delete this; + return nullptr; + } + auto VMRight = static_cast(Right); + auto rets = VMRight->GetReturnTypes(); + if (Base.Size() == 1) + { + Right->ScriptPosition.Message(MSG_ERROR, "Multi-assignment with only one element in function %s", VMRight->Function->SymbolName.GetChars()); + delete this; + return nullptr; + } + if (rets.Size() < Base.Size()) + { + Right->ScriptPosition.Message(MSG_ERROR, "Insufficient returns in function %s", VMRight->Function->SymbolName.GetChars()); + delete this; + return nullptr; + } + FxSequence * DeclAndAssign = new FxSequence(ScriptPosition); + const unsigned int n = Base.Size(); + for (unsigned int i = 0; i < n; i++) + { + assert(Base[i]->ExprType == EFX_Identifier); + DeclAndAssign->Add(new FxLocalVariableDeclaration(rets[i], ((FxIdentifier*)Base[i])->Identifier, nullptr, 0, Base[i]->ScriptPosition)); + } + DeclAndAssign->Add(new FxMultiAssign(Base, Right, ScriptPosition)); + Right = nullptr; + delete this; + return DeclAndAssign->Resolve(ctx); +} + + //========================================================================== // // diff --git a/source/common/scripting/backend/codegen.h b/source/common/scripting/backend/codegen.h index 8a156a529..1ce5529b3 100644 --- a/source/common/scripting/backend/codegen.h +++ b/source/common/scripting/backend/codegen.h @@ -294,6 +294,7 @@ enum EFxType EFX_Super, EFX_StackVariable, EFX_MultiAssign, + EFX_MultiAssignDecl, EFX_StaticArray, EFX_StaticArrayVariable, EFX_CVar, @@ -904,6 +905,17 @@ public: ExpEmit Emit(VMFunctionBuilder *build); }; +class FxMultiAssignDecl : public FxExpression +{ + FArgumentList Base; + FxExpression *Right; +public: + FxMultiAssignDecl(FArgumentList &base, FxExpression *right, const FScriptPosition &pos); + ~FxMultiAssignDecl(); + FxExpression *Resolve(FCompileContext&); + //ExpEmit Emit(VMFunctionBuilder *build); This node is transformed into Declarations + FxMultiAssign , so it won't ever be emitted itself +}; + //========================================================================== // // FxAssignSelf diff --git a/source/common/scripting/frontend/ast.cpp b/source/common/scripting/frontend/ast.cpp index 44cc0f516..50e1c2e9f 100644 --- a/source/common/scripting/frontend/ast.cpp +++ b/source/common/scripting/frontend/ast.cpp @@ -816,6 +816,15 @@ static void PrintAssignStmt(FLispString &out, const ZCC_TreeNode *node) out.Close(); } +static void PrintAssignDeclStmt(FLispString &out, const ZCC_TreeNode *node) +{ + ZCC_AssignDeclStmt *snode = (ZCC_AssignDeclStmt *)node; + out.Open("assign-stmt-decl"); + PrintNodes(out, snode->Dests); + PrintNodes(out, snode->Sources); + out.Close(); +} + static void PrintLocalVarStmt(FLispString &out, const ZCC_TreeNode *node) { ZCC_LocalVarStmt *snode = (ZCC_LocalVarStmt *)node; @@ -989,6 +998,7 @@ static const NodePrinterFunc TreeNodePrinter[] = PrintSwitchStmt, PrintCaseStmt, PrintAssignStmt, + PrintAssignDeclStmt, PrintLocalVarStmt, PrintFuncParamDecl, PrintConstantDef, diff --git a/source/common/scripting/frontend/zcc-parse.lemon b/source/common/scripting/frontend/zcc-parse.lemon index 560f15ad8..1a9146f37 100644 --- a/source/common/scripting/frontend/zcc-parse.lemon +++ b/source/common/scripting/frontend/zcc-parse.lemon @@ -1840,6 +1840,7 @@ statement(X) ::= iteration_statement(X). statement(X) ::= array_iteration_statement(X). statement(X) ::= jump_statement(X). statement(X) ::= assign_statement(A) SEMICOLON. { X = A; /*X-overwrites-A*/ } +statement(X) ::= assign_decl_statement(A) SEMICOLON.{ X = A; /*X-overwrites-A*/ } statement(X) ::= local_var(A) SEMICOLON. { X = A; /*X-overwrites-A*/ } statement(X) ::= error SEMICOLON. { X = NULL; } statement(X) ::= staticarray_statement(A). { X = A; /*X-overwrites-A*/ } @@ -2098,6 +2099,17 @@ assign_statement(X) ::= LBRACKET expr_list(A) RBRACKET EQ expr(B). [EQ] X = stmt; } +%type assign_decl_statement{ZCC_AssignDeclStmt *} + +assign_decl_statement(X) ::= LET LBRACKET identifier_list(A) RBRACKET EQ expr(B). [EQ] +{ + NEW_AST_NODE(AssignDeclStmt,stmt,A); + stmt->AssignOp = ZCC_EQ; + stmt->Dests = A; + stmt->Sources = B; + X = stmt; +} + /*----- Local Variable Definition "Statements" -----*/ %type local_var{ZCC_LocalVarStmt *} diff --git a/source/common/scripting/frontend/zcc_compile.cpp b/source/common/scripting/frontend/zcc_compile.cpp index 7777b7327..4c8b54792 100644 --- a/source/common/scripting/frontend/zcc_compile.cpp +++ b/source/common/scripting/frontend/zcc_compile.cpp @@ -3350,6 +3350,28 @@ FxExpression *ZCCCompiler::ConvertNode(ZCC_TreeNode *ast, bool substitute) return new FxMultiAssign(args, ConvertNode(ass->Sources), *ast); } + case AST_AssignDeclStmt: + { + auto ass = static_cast(ast); + FArgumentList args; + { + ZCC_TreeNode *n = ass->Dests; + if(n) do + { + args.Push(new FxIdentifier(static_cast(n)->Id,*n)); + n = n->SiblingNext; + } while(n != ass->Dests); + } + assert(ass->Sources->SiblingNext == ass->Sources); // right side should be a single function call - nothing else + if (ass->Sources->NodeType != AST_ExprFuncCall) + { + // don't let this through to the code generator. This node is only used to assign multiple returns of a function to more than one variable. + Error(ass, "Right side of multi-assignment must be a function call"); + return new FxNop(*ast); // allow compiler to continue looking for errors. + } + return new FxMultiAssignDecl(args, ConvertNode(ass->Sources), *ast); + } + default: break; } diff --git a/source/common/scripting/frontend/zcc_parser.cpp b/source/common/scripting/frontend/zcc_parser.cpp index 2343e4909..f1a3e8d1f 100644 --- a/source/common/scripting/frontend/zcc_parser.cpp +++ b/source/common/scripting/frontend/zcc_parser.cpp @@ -1195,6 +1195,18 @@ ZCC_TreeNode *TreeNodeDeepCopy_Internal(ZCC_AST *ast, ZCC_TreeNode *orig, bool c break; } + case AST_AssignDeclStmt: + { + TreeNodeDeepCopy_Start(AssignDeclStmt); + + // ZCC_AssignDeclStmt + copy->Dests = static_cast(TreeNodeDeepCopy_Internal(ast, origCasted->Dests, true, copiedNodesList)); + copy->Sources = static_cast(TreeNodeDeepCopy_Internal(ast, origCasted->Sources, true, copiedNodesList)); + copy->AssignOp = origCasted->AssignOp; + + break; + } + case AST_LocalVarStmt: { TreeNodeDeepCopy_Start(LocalVarStmt); diff --git a/source/common/scripting/frontend/zcc_parser.h b/source/common/scripting/frontend/zcc_parser.h index 7d2cce2e8..69276b768 100644 --- a/source/common/scripting/frontend/zcc_parser.h +++ b/source/common/scripting/frontend/zcc_parser.h @@ -122,6 +122,7 @@ enum EZCCTreeNodeType AST_SwitchStmt, AST_CaseStmt, AST_AssignStmt, + AST_AssignDeclStmt, AST_LocalVarStmt, AST_FuncParamDecl, AST_ConstantDef, @@ -533,6 +534,13 @@ struct ZCC_AssignStmt : ZCC_Statement int AssignOp; }; +struct ZCC_AssignDeclStmt : ZCC_Statement +{ + ZCC_Identifier *Dests; + ZCC_Expression *Sources; + int AssignOp; +}; + struct ZCC_LocalVarStmt : ZCC_Statement { ZCC_Type *Type; diff --git a/source/common/scripting/interface/stringformat.cpp b/source/common/scripting/interface/stringformat.cpp index 4bfe34ff6..77ce54ed6 100644 --- a/source/common/scripting/interface/stringformat.cpp +++ b/source/common/scripting/interface/stringformat.cpp @@ -578,6 +578,34 @@ DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, StripRight, StringStripRight) return 0; } +static void StringStripLeft(FString* self, const FString& junk) +{ + if (junk.IsNotEmpty()) self->StripLeft(junk); + else self->StripLeft(); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, StripLeft, StringStripLeft) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + PARAM_STRING(junk); + StringStripLeft(self, junk); + return 0; +} + +static void StringStripLeftRight(FString* self, const FString& junk) +{ + if (junk.IsNotEmpty()) self->StripLeftRight(junk); + else self->StripLeftRight(); +} + +DEFINE_ACTION_FUNCTION_NATIVE(FStringStruct, StripLeftRight, StringStripLeftRight) +{ + PARAM_SELF_STRUCT_PROLOGUE(FString); + PARAM_STRING(junk); + StringStripLeftRight(self, junk); + return 0; +} + static void StringSplit(FString* self, TArray* tokens, const FString& delimiter, int keepEmpty) { self->Split(*tokens, delimiter, static_cast(keepEmpty)); diff --git a/source/common/scripting/vm/vmexec.h b/source/common/scripting/vm/vmexec.h index 671bfc081..6716509da 100644 --- a/source/common/scripting/vm/vmexec.h +++ b/source/common/scripting/vm/vmexec.h @@ -824,6 +824,10 @@ static int ExecScriptFunc(VMFrameStack *stack, VMReturn *ret, int numret) assert(b < f->NumRegF); ::new(param) VMValue(®.f[b]); break; + case REGT_FLOAT | REGT_MULTIREG2 | REGT_ADDROF: + case REGT_FLOAT | REGT_MULTIREG3 | REGT_ADDROF: + case REGT_FLOAT | REGT_MULTIREG4 | REGT_ADDROF: + I_Error("REGT_ADDROF not implemented for vectors\n"); case REGT_FLOAT | REGT_KONST: assert(b < sfunc->NumKonstF); ::new(param) VMValue(konstf[b]); diff --git a/source/common/scripting/vm/vmframe.cpp b/source/common/scripting/vm/vmframe.cpp index 69b47dfd5..a2c972820 100644 --- a/source/common/scripting/vm/vmframe.cpp +++ b/source/common/scripting/vm/vmframe.cpp @@ -682,7 +682,7 @@ void CVMAbortException::MaybePrintMessage() auto m = GetMessage(); if (m != nullptr) { - Printf(PRINT_NONOTIFY, TEXTCOLOR_RED "%s\n", m); + Printf(PRINT_NONOTIFY | PRINT_BOLD, TEXTCOLOR_RED "%s\n", m); SetMessage(""); } } diff --git a/source/common/textures/formats/anmtexture.cpp b/source/common/textures/formats/anmtexture.cpp index 8e9555b9f..eeea41a89 100644 --- a/source/common/textures/formats/anmtexture.cpp +++ b/source/common/textures/formats/anmtexture.cpp @@ -51,7 +51,7 @@ class FAnmTexture : public FImageSource public: FAnmTexture (int lumpnum, int w, int h); void ReadFrame(uint8_t *buffer, uint8_t *palette); - TArray CreatePalettedPixels(int conversion) override; + PalettedPixels CreatePalettedPixels(int conversion) override; int CopyPixels(FBitmap *bmp, int conversion) override; }; @@ -127,9 +127,9 @@ void FAnmTexture::ReadFrame(uint8_t *pixels, uint8_t *palette) // //========================================================================== -TArray FAnmTexture::CreatePalettedPixels(int conversion) +PalettedPixels FAnmTexture::CreatePalettedPixels(int conversion) { - TArray pixels(Width*Height, true); + PalettedPixels pixels(Width*Height); uint8_t buffer[64000]; uint8_t palette[768]; uint8_t remap[256]; diff --git a/source/common/textures/formats/automaptexture.cpp b/source/common/textures/formats/automaptexture.cpp index 4135f4908..c253650fd 100644 --- a/source/common/textures/formats/automaptexture.cpp +++ b/source/common/textures/formats/automaptexture.cpp @@ -50,7 +50,7 @@ class FAutomapTexture : public FImageSource { public: FAutomapTexture(int lumpnum); - TArray CreatePalettedPixels(int conversion) override; + PalettedPixels CreatePalettedPixels(int conversion) override; }; @@ -89,13 +89,13 @@ FAutomapTexture::FAutomapTexture (int lumpnum) // //========================================================================== -TArray FAutomapTexture::CreatePalettedPixels(int conversion) +PalettedPixels FAutomapTexture::CreatePalettedPixels(int conversion) { int x, y; FileData data = fileSystem.ReadFile (SourceLump); const uint8_t *indata = (const uint8_t *)data.GetMem(); - TArray Pixels(Width * Height, true); + PalettedPixels Pixels(Width * Height); const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance); for (x = 0; x < Width; ++x) diff --git a/source/common/textures/formats/buildtexture.cpp b/source/common/textures/formats/buildtexture.cpp index 44648a51c..f8d8a7b6a 100644 --- a/source/common/textures/formats/buildtexture.cpp +++ b/source/common/textures/formats/buildtexture.cpp @@ -55,9 +55,9 @@ FBuildTexture::FBuildTexture(const FString &pathprefix, int tilenum, const uint8 TopOffset = top; } -TArray FBuildTexture::CreatePalettedPixels(int conversion) +PalettedPixels FBuildTexture::CreatePalettedPixels(int conversion) { - TArray Pixels(Width * Height, true); + PalettedPixels Pixels(Width * Height); FRemapTable *Remap = Translation; for (int i = 0; i < Width*Height; i++) { diff --git a/source/common/textures/formats/ddstexture.cpp b/source/common/textures/formats/ddstexture.cpp index 3a88fcdd1..8a3d0ba74 100644 --- a/source/common/textures/formats/ddstexture.cpp +++ b/source/common/textures/formats/ddstexture.cpp @@ -163,7 +163,7 @@ class FDDSTexture : public FImageSource public: FDDSTexture (FileReader &lump, int lumpnum, void *surfdesc); - TArray CreatePalettedPixels(int conversion) override; + PalettedPixels CreatePalettedPixels(int conversion) override; protected: uint32_t Format; @@ -371,11 +371,11 @@ void FDDSTexture::CalcBitShift (uint32_t mask, uint8_t *lshiftp, uint8_t *rshift // //========================================================================== -TArray FDDSTexture::CreatePalettedPixels(int conversion) +PalettedPixels FDDSTexture::CreatePalettedPixels(int conversion) { auto lump = fileSystem.OpenFileReader (SourceLump); - TArray Pixels(Width*Height, true); + PalettedPixels Pixels(Width*Height); lump.Seek (sizeof(DDSURFACEDESC2) + 4, FileReader::SeekSet); diff --git a/source/common/textures/formats/emptytexture.cpp b/source/common/textures/formats/emptytexture.cpp index bcbd682e0..74e8fe1cb 100644 --- a/source/common/textures/formats/emptytexture.cpp +++ b/source/common/textures/formats/emptytexture.cpp @@ -49,7 +49,7 @@ class FEmptyTexture : public FImageSource { public: FEmptyTexture (int lumpnum); - TArray CreatePalettedPixels(int conversion) override; + PalettedPixels CreatePalettedPixels(int conversion) override; }; //========================================================================== @@ -94,10 +94,10 @@ FEmptyTexture::FEmptyTexture (int lumpnum) // //========================================================================== -TArray FEmptyTexture::CreatePalettedPixels(int conversion) +PalettedPixels FEmptyTexture::CreatePalettedPixels(int conversion) { - TArray Pixel(1, true); - Pixel[0] = 0; + static uint8_t p; + PalettedPixels Pixel(&p, 1); return Pixel; } diff --git a/source/common/textures/formats/flattexture.cpp b/source/common/textures/formats/flattexture.cpp index 20c5d052a..a01016a36 100644 --- a/source/common/textures/formats/flattexture.cpp +++ b/source/common/textures/formats/flattexture.cpp @@ -48,7 +48,7 @@ class FFlatTexture : public FImageSource { public: FFlatTexture (int lumpnum); - TArray CreatePalettedPixels(int conversion) override; + PalettedPixels CreatePalettedPixels(int conversion) override; }; @@ -102,10 +102,10 @@ FFlatTexture::FFlatTexture (int lumpnum) // //========================================================================== -TArray FFlatTexture::CreatePalettedPixels(int conversion) +PalettedPixels FFlatTexture::CreatePalettedPixels(int conversion) { auto lump = fileSystem.OpenFileReader (SourceLump); - TArray Pixels(Width*Height, true); + PalettedPixels Pixels(Width*Height); auto numread = lump.Read (Pixels.Data(), Width*Height); if (numread < Width*Height) { diff --git a/source/common/textures/formats/fontchars.cpp b/source/common/textures/formats/fontchars.cpp index a48600437..add4f1f74 100644 --- a/source/common/textures/formats/fontchars.cpp +++ b/source/common/textures/formats/fontchars.cpp @@ -66,7 +66,7 @@ FFontChar2::FFontChar2(int sourcelump, int sourcepos, int width, int height, int // //========================================================================== -TArray FFontChar2::CreatePalettedPixels(int) +PalettedPixels FFontChar2::CreatePalettedPixels(int) { auto lump = fileSystem.OpenFileReader(SourceLump); int destSize = Width * Height; @@ -96,7 +96,7 @@ TArray FFontChar2::CreatePalettedPixels(int) } } - TArray Pixels(destSize, true); + PalettedPixels Pixels(destSize); int runlen = 0, setlen = 0; uint8_t setval = 0; // Shut up, GCC! diff --git a/source/common/textures/formats/fontchars.h b/source/common/textures/formats/fontchars.h index 79baf4a2b..45c678566 100644 --- a/source/common/textures/formats/fontchars.h +++ b/source/common/textures/formats/fontchars.h @@ -6,7 +6,7 @@ class FFontChar2 : public FImageSource public: FFontChar2 (int sourcelump, int sourcepos, int width, int height, int leftofs=0, int topofs=0); - TArray CreatePalettedPixels(int conversion) override; + PalettedPixels CreatePalettedPixels(int conversion) override; int CopyPixels(FBitmap* bmp, int conversion); void SetSourceRemap(const PalEntry* sourceremap) diff --git a/source/common/textures/formats/imgztexture.cpp b/source/common/textures/formats/imgztexture.cpp index 5c2e041ac..733d20f84 100644 --- a/source/common/textures/formats/imgztexture.cpp +++ b/source/common/textures/formats/imgztexture.cpp @@ -66,7 +66,7 @@ class FIMGZTexture : public FImageSource public: FIMGZTexture (int lumpnum, uint16_t w, uint16_t h, int16_t l, int16_t t, bool isalpha); - TArray CreatePalettedPixels(int conversion) override; + PalettedPixels CreatePalettedPixels(int conversion) override; int CopyPixels(FBitmap *bmp, int conversion) override; }; @@ -118,7 +118,7 @@ FIMGZTexture::FIMGZTexture (int lumpnum, uint16_t w, uint16_t h, int16_t l, int1 // //========================================================================== -TArray FIMGZTexture::CreatePalettedPixels(int conversion) +PalettedPixels FIMGZTexture::CreatePalettedPixels(int conversion) { FileData lump = fileSystem.ReadFile (SourceLump); const ImageHeader *imgz = (const ImageHeader *)lump.GetMem(); @@ -128,7 +128,7 @@ TArray FIMGZTexture::CreatePalettedPixels(int conversion) int dest_adv = Height; int dest_rew = Width * Height - 1; - TArray Pixels(Width*Height, true); + PalettedPixels Pixels(Width*Height); dest_p = Pixels.Data(); const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance, isalpha); diff --git a/source/common/textures/formats/jpegtexture.cpp b/source/common/textures/formats/jpegtexture.cpp index 75f4185b1..b1e5163b3 100644 --- a/source/common/textures/formats/jpegtexture.cpp +++ b/source/common/textures/formats/jpegtexture.cpp @@ -185,7 +185,7 @@ public: FJPEGTexture (int lumpnum, int width, int height); int CopyPixels(FBitmap *bmp, int conversion) override; - TArray CreatePalettedPixels(int conversion) override; + PalettedPixels CreatePalettedPixels(int conversion) override; }; //========================================================================== @@ -259,7 +259,7 @@ FJPEGTexture::FJPEGTexture (int lumpnum, int width, int height) // //========================================================================== -TArray FJPEGTexture::CreatePalettedPixels(int conversion) +PalettedPixels FJPEGTexture::CreatePalettedPixels(int conversion) { auto lump = fileSystem.OpenFileReader (SourceLump); JSAMPLE *buff = NULL; @@ -267,7 +267,7 @@ TArray FJPEGTexture::CreatePalettedPixels(int conversion) jpeg_decompress_struct cinfo; jpeg_error_mgr jerr; - TArray Pixels(Width * Height, true); + PalettedPixels Pixels(Width * Height); memset (Pixels.Data(), 0xBA, Width * Height); cinfo.err = jpeg_std_error(&jerr); diff --git a/source/common/textures/formats/multipatchtexture.cpp b/source/common/textures/formats/multipatchtexture.cpp index e131b9024..17c0a7b28 100644 --- a/source/common/textures/formats/multipatchtexture.cpp +++ b/source/common/textures/formats/multipatchtexture.cpp @@ -201,13 +201,13 @@ void FMultiPatchTexture::CopyToBlock(uint8_t *dest, int dwidth, int dheight, FIm // //========================================================================== -TArray FMultiPatchTexture::CreatePalettedPixels(int conversion) +PalettedPixels FMultiPatchTexture::CreatePalettedPixels(int conversion) { int numpix = Width * Height; uint8_t blendwork[256]; bool buildrgb = bComplex; - TArray Pixels(numpix, true); + PalettedPixels Pixels(numpix); memset (Pixels.Data(), 0, numpix); if (conversion == luminance) diff --git a/source/common/textures/formats/multipatchtexture.h b/source/common/textures/formats/multipatchtexture.h index c8cb16f24..4b92aad4f 100644 --- a/source/common/textures/formats/multipatchtexture.h +++ b/source/common/textures/formats/multipatchtexture.h @@ -75,7 +75,7 @@ protected: // The getters must optionally redirect if it's a simple one-patch texture. int CopyPixels(FBitmap *bmp, int conversion) override; - TArray CreatePalettedPixels(int conversion) override; + PalettedPixels CreatePalettedPixels(int conversion) override; void CopyToBlock(uint8_t *dest, int dwidth, int dheight, FImageSource *source, int xpos, int ypos, int rotate, const uint8_t *translation, int style); void CollectForPrecache(PrecacheInfo &info, bool requiretruecolor) override; diff --git a/source/common/textures/formats/patchtexture.cpp b/source/common/textures/formats/patchtexture.cpp index e680bf38a..2fe36efe7 100644 --- a/source/common/textures/formats/patchtexture.cpp +++ b/source/common/textures/formats/patchtexture.cpp @@ -61,7 +61,7 @@ class FPatchTexture : public FImageSource bool isalpha = false; public: FPatchTexture (int lumpnum, int w, int h, int lo, int to, bool isalphatex); - TArray CreatePalettedPixels(int conversion) override; + PalettedPixels CreatePalettedPixels(int conversion) override; int CopyPixels(FBitmap *bmp, int conversion) override; bool SupportRemap0() override { return !badflag; } void DetectBadPatches(); @@ -166,7 +166,7 @@ FPatchTexture::FPatchTexture (int lumpnum, int w, int h, int lo, int to, bool is // //========================================================================== -TArray FPatchTexture::CreatePalettedPixels(int conversion) +PalettedPixels FPatchTexture::CreatePalettedPixels(int conversion) { uint8_t *remap, remaptable[256]; int numspans; @@ -189,7 +189,7 @@ TArray FPatchTexture::CreatePalettedPixels(int conversion) if (badflag) { - TArray Pixels(Width * Height, true); + PalettedPixels Pixels(Width * Height); uint8_t *out; // Draw the image to the buffer @@ -210,7 +210,7 @@ TArray FPatchTexture::CreatePalettedPixels(int conversion) numspans = Width; - TArray Pixels(numpix, true); + PalettedPixels Pixels(numpix); memset (Pixels.Data(), 0, numpix); // Draw the image to the buffer diff --git a/source/common/textures/formats/pcxtexture.cpp b/source/common/textures/formats/pcxtexture.cpp index 32183155a..60e2f4aba 100644 --- a/source/common/textures/formats/pcxtexture.cpp +++ b/source/common/textures/formats/pcxtexture.cpp @@ -91,7 +91,7 @@ protected: void ReadPCX8bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr); void ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr, int planes); - TArray CreatePalettedPixels(int conversion) override; + PalettedPixels CreatePalettedPixels(int conversion) override; }; @@ -344,7 +344,7 @@ void FPCXTexture::ReadPCX24bits (uint8_t *dst, FileReader & lump, PCXHeader *hdr // //========================================================================== -TArray FPCXTexture::CreatePalettedPixels(int conversion) +PalettedPixels FPCXTexture::CreatePalettedPixels(int conversion) { uint8_t PaletteMap[256]; PCXHeader header; @@ -355,7 +355,7 @@ TArray FPCXTexture::CreatePalettedPixels(int conversion) lump.Read(&header, sizeof(header)); bitcount = header.bitsPerPixel * header.numColorPlanes; - TArray Pixels(Width*Height, true); + PalettedPixels Pixels(Width*Height); bool alphatex = conversion == luminance; if (bitcount < 24) @@ -402,7 +402,7 @@ TArray FPCXTexture::CreatePalettedPixels(int conversion) } else { - TArray newpix(Width*Height, true); + PalettedPixels newpix(Width*Height); ImageHelpers::FlipNonSquareBlockRemap (newpix.Data(), Pixels.Data(), Width, Height, Width, PaletteMap); return newpix; } diff --git a/source/common/textures/formats/pngtexture.cpp b/source/common/textures/formats/pngtexture.cpp index c91723b95..f9e39fc8c 100644 --- a/source/common/textures/formats/pngtexture.cpp +++ b/source/common/textures/formats/pngtexture.cpp @@ -56,7 +56,7 @@ public: FPNGTexture (FileReader &lump, int lumpnum, int width, int height, uint8_t bitdepth, uint8_t colortype, uint8_t interlace); int CopyPixels(FBitmap *bmp, int conversion) override; - TArray CreatePalettedPixels(int conversion) override; + PalettedPixels CreatePalettedPixels(int conversion) override; protected: void ReadAlphaRemap(FileReader *lump, uint8_t *alpharemap); @@ -411,7 +411,7 @@ void FPNGTexture::ReadAlphaRemap(FileReader *lump, uint8_t *alpharemap) // //========================================================================== -TArray FPNGTexture::CreatePalettedPixels(int conversion) +PalettedPixels FPNGTexture::CreatePalettedPixels(int conversion) { FileReader *lump; FileReader lfr; @@ -419,7 +419,7 @@ TArray FPNGTexture::CreatePalettedPixels(int conversion) lfr = fileSystem.OpenFileReader(SourceLump); lump = 𝔩 - TArray Pixels(Width*Height, true); + PalettedPixels Pixels(Width*Height); if (StartOfIDAT == 0) { memset (Pixels.Data(), 0x99, Width*Height); @@ -456,7 +456,7 @@ TArray FPNGTexture::CreatePalettedPixels(int conversion) } else { - TArray newpix(Width*Height, true); + PalettedPixels newpix(Width*Height); if (conversion != luminance) { if (!PaletteMap) SetupPalette(lfr); diff --git a/source/common/textures/formats/rawpagetexture.cpp b/source/common/textures/formats/rawpagetexture.cpp index 1ee29e13d..19d3f4587 100644 --- a/source/common/textures/formats/rawpagetexture.cpp +++ b/source/common/textures/formats/rawpagetexture.cpp @@ -51,7 +51,7 @@ class FRawPageTexture : public FImageSource int mPaletteLump = -1; public: FRawPageTexture (int lumpnum); - TArray CreatePalettedPixels(int conversion) override; + PalettedPixels CreatePalettedPixels(int conversion) override; int CopyPixels(FBitmap *bmp, int conversion) override; }; @@ -62,7 +62,7 @@ public: // //========================================================================== -bool CheckIfRaw(FileReader & data, int desiredsize) +bool CheckIfRaw(FileReader & data, unsigned desiredsize) { if (data.GetLength() != desiredsize) return false; @@ -94,7 +94,7 @@ bool CheckIfRaw(FileReader & data, int desiredsize) { gapAtStart = false; } - else if (ofs >= 64000-1) // Need one byte for an empty column + else if (ofs >= desiredsize-1) // Need one byte for an empty column { return true; } @@ -102,7 +102,7 @@ bool CheckIfRaw(FileReader & data, int desiredsize) { // Ensure this column does not extend beyond the end of the patch const uint8_t *foo2 = (const uint8_t *)foo; - while (ofs < 64000) + while (ofs < desiredsize) { if (foo2[ofs] == 255) { @@ -110,7 +110,7 @@ bool CheckIfRaw(FileReader & data, int desiredsize) } ofs += foo2[ofs+1] + 4; } - if (ofs >= 64000) + if (ofs >= desiredsize) { return true; } @@ -170,14 +170,14 @@ FRawPageTexture::FRawPageTexture (int lumpnum) // //========================================================================== -TArray FRawPageTexture::CreatePalettedPixels(int conversion) +PalettedPixels FRawPageTexture::CreatePalettedPixels(int conversion) { FileData lump = fileSystem.ReadFile (SourceLump); const uint8_t *source = (const uint8_t *)lump.GetMem(); const uint8_t *source_p = source; uint8_t *dest_p; - TArray Pixels(Width*Height, true); + PalettedPixels Pixels(Width*Height); dest_p = Pixels.Data(); const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance); diff --git a/source/common/textures/formats/shadertexture.cpp b/source/common/textures/formats/shadertexture.cpp index 6bde2b677..ce5952fc2 100644 --- a/source/common/textures/formats/shadertexture.cpp +++ b/source/common/textures/formats/shadertexture.cpp @@ -98,9 +98,9 @@ public: } } - TArray CreatePalettedPixels(int conversion) override + PalettedPixels CreatePalettedPixels(int conversion) override { - TArray Pix(512, true); + PalettedPixels Pix(512); if (conversion == luminance) { memcpy(Pix.Data(), Pixels, 512); diff --git a/source/common/textures/formats/startuptexture.cpp b/source/common/textures/formats/startuptexture.cpp index 5cda008e2..8a2a1e602 100644 --- a/source/common/textures/formats/startuptexture.cpp +++ b/source/common/textures/formats/startuptexture.cpp @@ -77,7 +77,7 @@ class FStartupTexture : public FImageSource { public: FStartupTexture (int lumpnum); - TArray CreatePalettedPixels(int conversion) override; + PalettedPixels CreatePalettedPixels(int conversion) override; int CopyPixels(FBitmap *bmp, int conversion) override; }; @@ -85,7 +85,7 @@ class FNotchTexture : public FImageSource { public: FNotchTexture (int lumpnum, int width, int height); - TArray CreatePalettedPixels(int conversion) override; + PalettedPixels CreatePalettedPixels(int conversion) override; int CopyPixels(FBitmap *bmp, int conversion) override; }; @@ -93,14 +93,14 @@ class FStrifeStartupTexture : public FImageSource { public: FStrifeStartupTexture (int lumpnum, int w, int h); - TArray CreatePalettedPixels(int conversion) override; + PalettedPixels CreatePalettedPixels(int conversion) override; }; class FStrifeStartupBackground : public FImageSource { public: FStrifeStartupBackground (int lumpnum); - TArray CreatePalettedPixels(int conversion) override; + PalettedPixels CreatePalettedPixels(int conversion) override; }; //========================================================================== @@ -109,7 +109,7 @@ public: // //========================================================================== -bool CheckIfRaw(FileReader & data, int desiredsize); +bool CheckIfRaw(FileReader & data, unsigned desiredsize); //========================================================================== // @@ -231,7 +231,7 @@ void PlanarToChunky(T* dest, const uint8_t* src, const T* remap, int width, int // //========================================================================== -TArray FStartupTexture::CreatePalettedPixels(int conversion) +PalettedPixels FStartupTexture::CreatePalettedPixels(int conversion) { FileData lump = fileSystem.ReadFile (SourceLump); const uint8_t *source = (const uint8_t *)lump.GetMem(); @@ -239,7 +239,7 @@ TArray FStartupTexture::CreatePalettedPixels(int conversion) TArray Work(Width*Height, true); - TArray Pixels(Width*Height, true); + PalettedPixels Pixels(Width*Height); PlanarToChunky(Work.Data(), source + 48, startuppalette8, Width, Height); ImageHelpers::FlipNonSquareBlockRemap(Pixels.Data(), Work.Data(), Width, Height, Width, remap); return Pixels; @@ -279,14 +279,14 @@ FNotchTexture::FNotchTexture (int lumpnum, int width, int height) // //========================================================================== -TArray FNotchTexture::CreatePalettedPixels(int conversion) +PalettedPixels FNotchTexture::CreatePalettedPixels(int conversion) { FileData lump = fileSystem.ReadFile (SourceLump); const uint8_t *source = (const uint8_t *)lump.GetMem(); const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance); TArray Work(Width*Height, true); - TArray Pixels(Width*Height, true); + PalettedPixels Pixels(Width*Height); for(int i=0; i * Width * Height / 2; i++) { Work[i * 2] = startuppalette8[source[i] >> 4]; @@ -336,11 +336,11 @@ FStrifeStartupTexture::FStrifeStartupTexture (int lumpnum, int w, int h) // //========================================================================== -TArray FStrifeStartupTexture::CreatePalettedPixels(int conversion) +PalettedPixels FStrifeStartupTexture::CreatePalettedPixels(int conversion) { FileData lump = fileSystem.ReadFile (SourceLump); const uint8_t *source = (const uint8_t *)lump.GetMem(); - TArray Pixels(Width*Height, true); + PalettedPixels Pixels(Width*Height); const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance); ImageHelpers::FlipNonSquareBlockRemap(Pixels.Data(), source, Width, Height, Width, remap); return Pixels; @@ -366,7 +366,7 @@ FStrifeStartupBackground::FStrifeStartupBackground (int lumpnum) // //========================================================================== -TArray FStrifeStartupBackground::CreatePalettedPixels(int conversion) +PalettedPixels FStrifeStartupBackground::CreatePalettedPixels(int conversion) { TArray source(64000, true); memset(source.Data(), 0xF0, 64000); @@ -374,7 +374,7 @@ TArray FStrifeStartupBackground::CreatePalettedPixels(int conversion) lumpr.Seek(57 * 320, FileReader::SeekSet); lumpr.Read(source.Data() + 41 * 320, 95 * 320); - TArray Pixels(Width*Height, true); + PalettedPixels Pixels(Width*Height); const uint8_t *remap = ImageHelpers::GetRemap(conversion == luminance); ImageHelpers::FlipNonSquareBlockRemap(Pixels.Data(), source.Data(), Width, Height, Width, remap); return Pixels; diff --git a/source/common/textures/formats/stbtexture.cpp b/source/common/textures/formats/stbtexture.cpp index 7ffb6f01d..e8d9fe2a0 100644 --- a/source/common/textures/formats/stbtexture.cpp +++ b/source/common/textures/formats/stbtexture.cpp @@ -67,7 +67,7 @@ class FStbTexture : public FImageSource public: FStbTexture (int lumpnum, int w, int h); - TArray CreatePalettedPixels(int conversion) override; + PalettedPixels CreatePalettedPixels(int conversion) override; int CopyPixels(FBitmap *bmp, int conversion) override; }; @@ -117,7 +117,7 @@ FStbTexture::FStbTexture (int lumpnum, int w, int h) // //========================================================================== -TArray FStbTexture::CreatePalettedPixels(int conversion) +PalettedPixels FStbTexture::CreatePalettedPixels(int conversion) { FBitmap bitmap; bitmap.Create(Width, Height); @@ -128,7 +128,7 @@ TArray FStbTexture::CreatePalettedPixels(int conversion) int dest_adv = Height; int dest_rew = Width * Height - 1; - TArray Pixels(Width*Height, true); + PalettedPixels Pixels(Width*Height); dest_p = Pixels.Data(); bool doalpha = conversion == luminance; diff --git a/source/common/textures/formats/tgatexture.cpp b/source/common/textures/formats/tgatexture.cpp index 690c2bc29..932eeeaf1 100644 --- a/source/common/textures/formats/tgatexture.cpp +++ b/source/common/textures/formats/tgatexture.cpp @@ -83,7 +83,7 @@ public: protected: void ReadCompressed(FileReader &lump, uint8_t * buffer, int bytesperpixel); - TArray CreatePalettedPixels(int conversion) override; + PalettedPixels CreatePalettedPixels(int conversion) override; }; //========================================================================== @@ -177,7 +177,7 @@ void FTGATexture::ReadCompressed(FileReader &lump, uint8_t * buffer, int bytespe // //========================================================================== -TArray FTGATexture::CreatePalettedPixels(int conversion) +PalettedPixels FTGATexture::CreatePalettedPixels(int conversion) { uint8_t PaletteMap[256]; auto lump = fileSystem.OpenFileReader (SourceLump); @@ -185,7 +185,7 @@ TArray FTGATexture::CreatePalettedPixels(int conversion) uint16_t w; uint8_t r,g,b,a; - TArray Pixels(Width*Height, true); + PalettedPixels Pixels(Width*Height); lump.Read(&hdr, sizeof(hdr)); lump.Seek(hdr.id_len, FileReader::SeekCur); diff --git a/source/common/textures/image.cpp b/source/common/textures/image.cpp index c7b42ab60..b32634948 100644 --- a/source/common/textures/image.cpp +++ b/source/common/textures/image.cpp @@ -48,7 +48,7 @@ static PrecacheInfo precacheInfo; struct PrecacheDataPaletted { - TArray Pixels; + PalettedPixels Pixels; int RefCount; int ImageID; }; @@ -71,9 +71,9 @@ TArray precacheDataRgba; // //=========================================================================== -TArray FImageSource::CreatePalettedPixels(int conversion) +PalettedPixels FImageSource::CreatePalettedPixels(int conversion) { - TArray Pixels(Width * Height, true); + PalettedPixels Pixels(Width * Height); memset(Pixels.Data(), 0, Width * Height); return Pixels; } @@ -99,8 +99,7 @@ PalettedPixels FImageSource::GetCachedPalettedPixels(int conversion) else if (cache->Pixels.Size() > 0) { //Printf("returning contents of %s, refcount = %d\n", name.GetChars(), cache->RefCount); - ret.PixelStore = std::move(cache->Pixels); - ret.Pixels.Set(ret.PixelStore.Data(), ret.PixelStore.Size()); + ret = std::move(cache->Pixels); precacheDataPaletted.Delete(index); } else @@ -116,8 +115,7 @@ PalettedPixels FImageSource::GetCachedPalettedPixels(int conversion) { // This is either the only copy needed or some access outside the caching block. In these cases create a new one and directly return it. //Printf("returning fresh copy of %s\n", name.GetChars()); - ret.PixelStore = CreatePalettedPixels(conversion); - ret.Pixels.Set(ret.PixelStore.Data(), ret.PixelStore.Size()); + return CreatePalettedPixels(conversion); } else { @@ -171,6 +169,7 @@ int FImageSource::CopyPixels(FBitmap *bmp, int conversion) { if (conversion == luminance) conversion = normal; // luminance images have no use as an RGB source. PalEntry *palette = GPalette.BaseColors; + auto ppix = CreatePalettedPixels(conversion); bmp->CopyPixelData(0, 0, ppix.Data(), Width, Height, Height, 1, 0, palette, nullptr); return 0; @@ -178,7 +177,7 @@ int FImageSource::CopyPixels(FBitmap *bmp, int conversion) int FImageSource::CopyTranslatedPixels(FBitmap *bmp, const PalEntry *remap) { - auto ppix = CreatePalettedPixels(false); + auto ppix = CreatePalettedPixels(normal); bmp->CopyPixelData(0, 0, ppix.Data(), Width, Height, Height, 1, 0, remap, nullptr); return 0; } diff --git a/source/common/textures/image.h b/source/common/textures/image.h index 1c641c04d..5be852549 100644 --- a/source/common/textures/image.h +++ b/source/common/textures/image.h @@ -26,10 +26,30 @@ struct PalettedPixels private: TArray PixelStore; +public: + PalettedPixels() = default; + PalettedPixels(unsigned size) + { + PixelStore.Resize(size); + Pixels.Set(PixelStore.Data(), PixelStore.Size()); + } + PalettedPixels(uint8_t* data, unsigned size) + { + Pixels.Set(data, size); + } bool ownsPixels() const { return Pixels.Data() == PixelStore.Data(); } + uint8_t* Data() const { return Pixels.Data(); } + unsigned Size() const { return Pixels.Size(); } + + uint8_t& operator[] (size_t index) const + { + assert(index < Size()); + return Pixels[index]; + } + }; // This represents a naked image. It has no high level logic attached to it. @@ -51,8 +71,7 @@ protected: // Internal image creation functions. All external access should go through the cache interface, // so that all code can benefit from future improvements to that. - virtual TArray CreatePalettedPixels(int conversion); - virtual int CopyPixels(FBitmap *bmp, int conversion); // This will always ignore 'luminance'. + virtual PalettedPixels CreatePalettedPixels(int conversion); int CopyTranslatedPixels(FBitmap *bmp, const PalEntry *remap); @@ -87,7 +106,8 @@ public: // tries to get a buffer from the cache. If not available, create a new one. If further references are pending, create a copy. TArray GetPalettedPixels(int conversion); - // Unlile for paletted images there is no variant here that returns a persistent bitmap, because all users have to process the returned image into another format. + virtual int CopyPixels(FBitmap* bmp, int conversion); + FBitmap GetCachedBitmap(const PalEntry *remap, int conversion, int *trans = nullptr); static void ClearImages() { ImageArena.FreeAll(); ImageForLump.Clear(); NextID = 0; } @@ -160,7 +180,7 @@ class FBuildTexture : public FImageSource { public: FBuildTexture(const FString& pathprefix, int tilenum, const uint8_t* pixels, FRemapTable* translation, int width, int height, int left, int top); - TArray CreatePalettedPixels(int conversion) override; + PalettedPixels CreatePalettedPixels(int conversion) override; int CopyPixels(FBitmap* bmp, int conversion) override; protected: diff --git a/source/core/textures/tiletexture.cpp b/source/core/textures/tiletexture.cpp index 3d0be68ca..07040a7a5 100644 --- a/source/core/textures/tiletexture.cpp +++ b/source/core/textures/tiletexture.cpp @@ -51,7 +51,7 @@ public: bTranslucent = false; } virtual uint8_t* GetRawData() = 0; - virtual TArray CreatePalettedPixels(int conversion); + virtual PalettedPixels CreatePalettedPixels(int conversion); virtual int CopyPixels(FBitmap* bmp, int conversion); // This will always ignore 'luminance'. }; @@ -186,13 +186,19 @@ int FTileTexture::CopyPixels(FBitmap* bmp, int conversion) return 0; } -TArray FTileTexture::CreatePalettedPixels(int conversion) +// 'conversion' is meaningless here becazse we do not have to bother with a software renderer. +PalettedPixels FTileTexture::CreatePalettedPixels(int conversion) { - TArray buffer(Width * Height, true); - auto p = GetRawData(); - if (p) memcpy(buffer.Data(), p, buffer.Size()); - else memset(buffer.Data(), 0, buffer.Size()); - return buffer; + if (GetRawData()) + { + return PalettedPixels(GetRawData(), Width * Height); + } + else + { + PalettedPixels buffer(Width * Height); + memset(buffer.Data(), 0, buffer.Size()); + return buffer; + } } //==========================================================================