From a2f507d044f1356930cc526381493fb1abc3e837 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Tue, 11 Feb 2020 06:35:14 +0000 Subject: [PATCH] CON: Add getarraysequence and setarraysequence Patch from Fox. git-svn-id: https://svn.eduke32.com/eduke32@8623 1a8010ca-5511-0410-912e-c29ae57300e0 # Conflicts: # source/duke3d/src/game.h --- source/duke3d/src/game.h | 1 + source/duke3d/src/gamedef.cpp | 26 +++++++++++++++++++++++ source/duke3d/src/gamedef.h | 2 ++ source/duke3d/src/gameexec.cpp | 38 ++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+) diff --git a/source/duke3d/src/game.h b/source/duke3d/src/game.h index 593b55f19..2ac45b188 100644 --- a/source/duke3d/src/game.h +++ b/source/duke3d/src/game.h @@ -136,6 +136,7 @@ static inline int32_t G_GetLogoFlags(void) #define MAX_RETURN_VALUES 6 +#define MAX_ARRAYRANGE_VALUES 32 typedef struct { vec3_t camerapos; int32_t const_visibility,uw_framerate; diff --git a/source/duke3d/src/gamedef.cpp b/source/duke3d/src/gamedef.cpp index ca98372cb..5ec5bdc5f 100644 --- a/source/duke3d/src/gamedef.cpp +++ b/source/duke3d/src/gamedef.cpp @@ -267,6 +267,7 @@ static tokenmap_t const vm_keywords[] = { "getactorvar", CON_GETACTORVAR }, { "getangle", CON_GETANGLE }, { "getangletotarget", CON_GETANGLETOTARGET }, + { "getarraysequence", CON_GETARRAYSEQUENCE }, { "getarraysize", CON_GETARRAYSIZE }, { "getceilzofslope", CON_GETCEILZOFSLOPE }, { "getclosestcol", CON_GETCLOSESTCOL }, @@ -480,6 +481,7 @@ static tokenmap_t const vm_keywords[] = { "setactorsoundpitch", CON_SETACTORSOUNDPITCH }, { "setactorvar", CON_SETACTORVAR }, { "setarray", CON_SETARRAY }, + { "setarraysequence", CON_SETARRAYSEQUENCE }, { "setaspect", CON_SETASPECT }, { "setcfgname", CON_SETCFGNAME }, { "setdefname", CON_SETDEFNAME }, @@ -621,6 +623,7 @@ static tokenmap_t const vm_keywords[] = { "getw", CON_GETWALL }, { "getu", CON_GETUSERDEF }, { "geti", CON_GETINPUT }, + { "getarrayseq", CON_GETARRAYSEQUENCE }, { "setp", CON_SETPLAYER }, { "setpv", CON_SETPLAYERVAR }, @@ -630,6 +633,7 @@ static tokenmap_t const vm_keywords[] = { "setw", CON_SETWALL }, { "setu", CON_SETUSERDEF }, { "seti", CON_SETINPUT }, + { "setarrayseq", CON_SETARRAYSEQUENCE }, { "string", CON_DEFINEQUOTE }, { "print", CON_QUOTE }, @@ -3771,6 +3775,28 @@ setvarvar: C_GetNextVarType(GAMEVAR_READONLY); continue; + case CON_GETARRAYSEQUENCE: + case CON_SETARRAYSEQUENCE: + { + i = C_GetNextGameArrayName(); + if (EDUKE32_PREDICT_FALSE(i < 0)) + return 1; + C_SkipComments(); + + auto pSize = g_scriptPtr++; + + for (j = 0; j < MAX_ARRAYRANGE_VALUES; ++j) + { + if (C_GetKeyword() != -1) + break; + + C_GetNextVarType(tw == CON_GETARRAYSEQUENCE ? GAMEVAR_READONLY : 0); + } + + scriptWriteAtOffset(j, pSize); + continue; + } + case CON_RESIZEARRAY: i = C_GetNextGameArrayName(); if (EDUKE32_PREDICT_FALSE(i < 0)) diff --git a/source/duke3d/src/gamedef.h b/source/duke3d/src/gamedef.h index e4d77bdff..5e5819b04 100644 --- a/source/duke3d/src/gamedef.h +++ b/source/duke3d/src/gamedef.h @@ -1012,6 +1012,7 @@ enum IterationTypes_t TRANSFORM(CON_SETACTORSTRUCT) DELIMITER \ TRANSFORM(CON_SETACTORVAR) DELIMITER \ TRANSFORM(CON_SETARRAY) DELIMITER \ + TRANSFORM(CON_SETARRAYSEQUENCE) DELIMITER \ TRANSFORM(CON_SETPLAYER) DELIMITER \ TRANSFORM(CON_SETPLAYERVAR) DELIMITER \ TRANSFORM(CON_SETPROJECTILE) DELIMITER \ @@ -1109,6 +1110,7 @@ enum IterationTypes_t TRANSFORM(CON_GAMETEXTZ) DELIMITER \ TRANSFORM(CON_GETACTORANGLE) DELIMITER \ TRANSFORM(CON_GETANGLETOTARGET) DELIMITER \ + TRANSFORM(CON_GETARRAYSEQUENCE) DELIMITER \ TRANSFORM(CON_GETARRAYSIZE) DELIMITER \ TRANSFORM(CON_GETCEILZOFSLOPE) DELIMITER \ TRANSFORM(CON_GETCLOSESTCOL) DELIMITER \ diff --git a/source/duke3d/src/gameexec.cpp b/source/duke3d/src/gameexec.cpp index b36cbeea4..740f83412 100644 --- a/source/duke3d/src/gameexec.cpp +++ b/source/duke3d/src/gameexec.cpp @@ -5586,6 +5586,44 @@ badindex: dispatch(); } + vInstruction(CON_GETARRAYSEQUENCE): + { + insptr++; + int32_t const arrayNum = *insptr++; + int32_t const arraySize = (aGameArrays[arrayNum].flags & GAMEARRAY_VARSIZE) ? Gv_GetVar(aGameArrays[arrayNum].size) : aGameArrays[arrayNum].size; + int32_t const sequenceSize = *insptr++; + int32_t const copySize = min(sequenceSize, arraySize); // warning? + auto const insptrbak = insptr; + + for (int arrayIndex = 0; arrayIndex < copySize; ++arrayIndex) + { + int32_t const gameVar = *insptr++; + int32_t const newValue = Gv_GetArrayValue(arrayNum, arrayIndex); + Gv_SetVar(gameVar, newValue); + } + + insptr = insptrbak + sequenceSize; + dispatch(); + } + + vInstruction(CON_SETARRAYSEQUENCE): + { + insptr++; + int32_t const arrayNum = *insptr++; + int32_t const sequenceSize = *insptr++; + + ResizeArray(arrayNum, sequenceSize); + + for (int arrayIndex = 0; arrayIndex < sequenceSize; ++arrayIndex) + { + int32_t const gameVar = *insptr++; + int32_t const newValue = Gv_GetVar(gameVar); + SetArray(arrayNum, arrayIndex, newValue); + } + + dispatch(); + } + vInstruction(CON_READARRAYFROMFILE): insptr++; {