From 5c777eeb381edc4df9b397b1cd2a7c6d457ff64c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 16 Sep 2020 00:21:17 +0200 Subject: [PATCH] - moved implementation of 'animtilerange' into buildtiles.cpp. --- source/build/src/defs.cpp | 48 ++++------------------------- source/core/textures/buildtiles.cpp | 27 +++++++++++++++- source/core/textures/buildtiles.h | 23 ++++++++++++-- 3 files changed, 53 insertions(+), 45 deletions(-) diff --git a/source/build/src/defs.cpp b/source/build/src/defs.cpp index 7f3387c9f..b9c187b15 100644 --- a/source/build/src/defs.cpp +++ b/source/build/src/defs.cpp @@ -607,44 +607,12 @@ static int32_t defsparser(scriptfile *script) break; case T_ANIMTILERANGE: { - int32_t tile1, tile2, spd, type; - - if (scriptfile_getsymbol(script,&tile1)) break; - if (scriptfile_getsymbol(script,&tile2)) break; - if (scriptfile_getsymbol(script,&spd)) break; - if (scriptfile_getsymbol(script,&type)) break; - - if (check_tile("animtilerange", tile1, script, pos)) - break; - if (check_tile("animtilerange", tile2, script, pos)) - break; - - spd = clamp(spd, 0, 15); - if (type&~3) - { - pos.Message(MSG_ERROR, "animtilerange: animation type must be 0, 1, 2 or 3"); - break; - } - - int32_t num = tile2-tile1; - if (type == 3 && tile1 > tile2) // PICANM_ANIMTYPE_BACK - num = -num; - - if ((unsigned)num > 255) - { - pos.Message(MSG_ERROR, "animtilerange: tile difference can be at most 255"); - break; - } - - // set anim speed - picanm[tile1].sf &= ~PICANM_ANIMSPEED_MASK; - picanm[tile1].sf |= spd; - // set anim type - picanm[tile1].sf &= ~PICANM_ANIMTYPE_MASK; - picanm[tile1].sf |= type< 3) + { + pos.Message(MSG_ERROR, "%s: animation type must be 0-3, got %d", cmd, imp.type); + return; + } + + int count = imp.tile2 - imp.tile1; + if (imp.type == (PICANM_ANIMTYPE_BACK >> PICANM_ANIMTYPE_SHIFT) && imp.tile1 > imp.tile2) + count = -count; + + TileFiles.setAnim(imp.tile1, imp.type, imp.speed, count); +} + TileSiz tilesiz; PicAnm picanm; diff --git a/source/core/textures/buildtiles.h b/source/core/textures/buildtiles.h index 8215c1226..c3e01aac9 100644 --- a/source/core/textures/buildtiles.h +++ b/source/core/textures/buildtiles.h @@ -51,7 +51,7 @@ enum class ReplacementType : int // accordingly. struct picanm_t { - uint8_t num; // animate number + uint16_t num; // animate number uint8_t sf; // anim. speed and flags uint8_t extra; @@ -344,6 +344,15 @@ struct BuildTiles } } + + void setAnim(int tile, int type, int speed, int frames) + { + auto& anm = tiledata[tile].picanm; + anm.sf &= ~(PICANM_ANIMTYPE_MASK | PICANM_ANIMSPEED_MASK); + anm.sf |= clamp(speed, 0, 15) | (type << PICANM_ANIMTYPE_SHIFT); + anm.num = frames; + } + FGameTexture* ValidateCustomTile(int tilenum, ReplacementType type); int32_t artLoadFiles(const char* filename); uint8_t* tileMakeWritable(int num); @@ -374,7 +383,6 @@ void tileRemoveReplacement(int tile); bool tileLoad(int tileNum); void artClearMapArt(void); void artSetupMapArt(const char* filename); -void tileSetAnim(int tile, const picanm_t& anm); int tileSetHightileReplacement(int picnum, int palnum, const char *filen, float alphacut, float xscale, float yscale, float specpower, float specfactor, uint8_t flags); int tileSetSkybox(int picnum, int palnum, const char **facenames, int flags ); int tileDeleteReplacement(int picnum, int palnum); @@ -503,6 +511,10 @@ inline FGameTexture* tileGetTexture(int tile, bool animate = false) bool PickTexture(int picnum, FGameTexture* tex, int paletteid, TexturePick& pick); +bool ValidateTileRange(const char* cmd, int& begin, int& end, FScriptPosition pos, bool allowswap = true); +bool ValidateTilenum(const char* cmd, int tile, FScriptPosition pos); + + struct TileImport { FString fn; @@ -519,3 +531,10 @@ struct TileImport }; void processTileImport(const char* cmd, FScriptPosition& pos, TileImport& imp); + +struct SetAnim +{ + int tile1, tile2, speed, type; +}; + +void processSetAnim(const char* cmd, FScriptPosition& pos, SetAnim& imp);