From c259f7da26df54b94b913c0763a43288f961458f Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 12:16:43 +0330 Subject: [PATCH 01/53] Add new display type `DISPLAY_GIF` --- Client/mods/deathmatch/logic/CClientDisplay.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Client/mods/deathmatch/logic/CClientDisplay.h b/Client/mods/deathmatch/logic/CClientDisplay.h index 291180c3c5..ede6d8783c 100644 --- a/Client/mods/deathmatch/logic/CClientDisplay.h +++ b/Client/mods/deathmatch/logic/CClientDisplay.h @@ -18,6 +18,7 @@ enum eDisplayType { DISPLAY_TEXT, DISPLAY_VECTORGRAPHIC, + DISPLAY_GIF }; class CClientDisplay From e762bf2201447f83f42b0d3a00ab3633b61efcc6 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 12:19:01 +0330 Subject: [PATCH 02/53] Add `Gif` entity class --- Client/mods/deathmatch/logic/CClientEntity.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Client/mods/deathmatch/logic/CClientEntity.h b/Client/mods/deathmatch/logic/CClientEntity.h index ac9094674e..5891355844 100644 --- a/Client/mods/deathmatch/logic/CClientEntity.h +++ b/Client/mods/deathmatch/logic/CClientEntity.h @@ -76,6 +76,7 @@ enum eClientEntityType CCLIENTBROWSER, CCLIENTSEARCHLIGHT, CCLIENTIFP, + CCLIENTGIF, CCLIENTVECTORGRAPHIC, CCLIENTUNKNOWN, }; @@ -137,6 +138,7 @@ enum eCClientEntityClassTypes CLASS_CClientScreenSource, CLASS_CClientWebBrowser, CLASS_CClientVectorGraphic, + CLASS_CClientGif, CLASS_CClientWeapon, CLASS_CClientEffect, CLASS_CClientPointLights, From 562b87f90bd5e69b61f9564e6d4907aa6214c9b3 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 12:21:19 +0330 Subject: [PATCH 03/53] Load Gif functions on startup --- Client/mods/deathmatch/logic/lua/CLuaManager.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Client/mods/deathmatch/logic/lua/CLuaManager.cpp b/Client/mods/deathmatch/logic/lua/CLuaManager.cpp index 0076c4d578..55fab88685 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaManager.cpp +++ b/Client/mods/deathmatch/logic/lua/CLuaManager.cpp @@ -13,6 +13,7 @@ #include "../luadefs/CLuaFireDefs.h" #include "../luadefs/CLuaClientDefs.h" #include "../luadefs/CLuaVectorGraphicDefs.h" +#include "../luadefs/CLuaGifDefs.h" using std::list; @@ -273,6 +274,7 @@ void CLuaManager::LoadCFunctions() CLuaTeamDefs::LoadFunctions(); CLuaTimerDefs::LoadFunctions(); CLuaVectorGraphicDefs::LoadFunctions(); + CLuaGifDefs::LoadFunctions(); CLuaVehicleDefs::LoadFunctions(); CLuaWaterDefs::LoadFunctions(); CLuaWeaponDefs::LoadFunctions(); From 45c77e01c74aa75d6627b044fd89e7962bfbb5a4 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 12:23:29 +0330 Subject: [PATCH 04/53] Load Gif class on startup --- Client/mods/deathmatch/logic/lua/CLuaMain.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Client/mods/deathmatch/logic/lua/CLuaMain.cpp b/Client/mods/deathmatch/logic/lua/CLuaMain.cpp index 4dbe913aa0..70e24230b0 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaMain.cpp +++ b/Client/mods/deathmatch/logic/lua/CLuaMain.cpp @@ -27,6 +27,8 @@ SString CLuaMain::ms_strExpectedUndumpHash; #include "luascripts/exports.lua.h" #include "luascripts/inspect.lua.h" +#include "../luadefs/CLuaGifDefs.h" + CLuaMain::CLuaMain(CLuaManager* pLuaManager, CResource* pResourceOwner, bool bEnableOOP) { // Initialise everything to be setup in the Start function @@ -127,6 +129,7 @@ void CLuaMain::InitClasses(lua_State* luaVM) CLuaVehicleDefs::AddClass(luaVM); CLuaWaterDefs::AddClass(luaVM); CLuaWeaponDefs::AddClass(luaVM); + CLuaGifDefs::AddClass(luaVM); CLuaShared::AddClasses(luaVM); } From a363cae0e1d1208ad54d14db9d65fe854ec509de Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 12:25:20 +0330 Subject: [PATCH 05/53] Add `Gif` class type name --- Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h b/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h index 201a70a427..66159932b1 100644 --- a/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h +++ b/Client/mods/deathmatch/logic/lua/CLuaFunctionParseHelpers.h @@ -489,6 +489,11 @@ inline SString GetClassTypeName(CClientVectorGraphic*) return "svg"; } +inline SString GetClassTypeName(CClientGif*) +{ + return "gif"; +} + // // CResource from userdata // From 66c7f7b199c08a76fd3e7ef224834f451ac2b217 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 12:27:10 +0330 Subject: [PATCH 06/53] Create CLuaGifDefs.h --- .../deathmatch/logic/luadefs/CLuaGifDefs.h | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h new file mode 100644 index 0000000000..ee0a6ab045 --- /dev/null +++ b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h @@ -0,0 +1,32 @@ +/***************************************************************************** + * + * PROJECT: Multi Theft Auto + * LICENSE: See LICENSE in the top level directory + * + * Multi Theft Auto is available from https://www.multitheftauto.com/ + * + *****************************************************************************/ + +#pragma once + +#include "CLuaDefs.h" +#include "CClientGif.h" + +class CLuaGifDefs : public CLuaDefs +{ +public: + static void LoadFunctions(); + static void AddClass(lua_State*); + static int GifCreate(lua_State*); + static int GifPlay(lua_State*); + static int GifStop(lua_State*); + static int GifNavigateToThumbnail(lua_State*); + static int GifSetFrameDelay(lua_State*); + static int GifGetFrameCount(lua_State*); + static int GifGetFrameDelay(lua_State*); + static int GifGetShowingFrame(lua_State*); + static int GifGetFrameDefaultDelay(lua_State*); + static int GifGetFormat(lua_State*); + static int GifGetTick(lua_State*); + static int IsGifPlaying(lua_State*); +}; From 5af7c4c160fe1697085016a48a311f286ba132c9 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 12:29:28 +0330 Subject: [PATCH 07/53] Create CLuaGifDefs.cpp --- .../deathmatch/logic/luadefs/CLuaGifDefs.cpp | 359 ++++++++++++++++++ 1 file changed, 359 insertions(+) create mode 100644 Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp new file mode 100644 index 0000000000..aedd8874ed --- /dev/null +++ b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp @@ -0,0 +1,359 @@ +/***************************************************************************** + * + * PROJECT: Multi Theft Auto + * LICENSE: See LICENSE in the top level directory + * + * Multi Theft Auto is available from https://www.multitheftauto.com/ + * + *****************************************************************************/ + +#include "StdInc.h" +#include "lua/CLuaFunctionParser.h" +#include "CLuaGifDefs.h" +#include "CScriptFile.h" + +#ifndef DEFAULT_MAX_FILESIZE + #define DEFAULT_MAX_FILESIZE 52428800 +#endif + +void CLuaGifDefs::LoadFunctions(){ + constexpr static const std::pair functions[]{ + {"gifCreate", GifCreate}, + {"gifPlay", GifPlay}, + {"gifStop", GifStop}, + {"gifNavigateToThumbnail", GifNavigateToThumbnail}, + {"gifSetFrameDelay", GifSetFrameDelay}, + {"gifGetFrameCount", GifGetFrameCount}, + {"gifGetFrameDelay", GifGetFrameDelay}, + {"gifGetShowingFrame", GifGetShowingFrame}, + {"gifGetFrameDefaultDelay", GifGetFrameDefaultDelay}, + {"gifGetFormat", GifGetFormat}, + {"gifGetTick", GifGetTick}, + {"isGifPlaying", IsGifPlaying}, + }; + for (const auto& [name, func] : functions) + CLuaCFunctions::AddFunction(name, func); +} + +void CLuaGifDefs::AddClass(lua_State* luaVM){ + lua_newclass(luaVM); + lua_classfunction(luaVM, "play", "gifPlay"); + lua_classfunction(luaVM, "stop", "gifStop"); + lua_classfunction(luaVM, "navigateToThumbnail", "gifNavigateToThumbnail"); + lua_classfunction(luaVM, "setFrameDelay", "gifSetFrameDelay"); + lua_classfunction(luaVM, "getFrameCount", "gifGetFrameCount"); + lua_classfunction(luaVM, "getFrameDelay", "gifGetFrameDelay"); + lua_classfunction(luaVM, "getShowingFrame", "gifGetShowingFrame"); + lua_classfunction(luaVM, "getFrameDefaultDelay", "gifGetFrameDefaultDelay"); + lua_classfunction(luaVM, "getFormat", "gifGetFormat"); + lua_classfunction(luaVM, "getTick", "gifGetTick"); + lua_classfunction(luaVM, "isPlaying", "isGifPlaying"); + lua_registerclass(luaVM, "Gif"); +} + +int CLuaGifDefs::GifCreate(lua_State* luaVM) { + SString buffer; + CScriptArgReader argStream(luaVM); + argStream.ReadString(buffer); + if (!argStream.HasErrors()) { + CLuaMain& luaMain = lua_getownercluamain(luaVM); + CResource* resource = luaMain.GetResource(); + SString path; + SString metaPath; + SString fileBuffer; + SString lastPath = buffer; + SString format = buffer.substr(0,6); + CClientGifLoader loader; + if (format == "GIF87a" || format == "GIF89a") { + loader = CClientGifLoader(buffer); + }else if (CResourceManager::ParseResourcePathInput(buffer,resource,&path,&metaPath)){ + if (FileExists(path)) { + eAccessType access = buffer[0] == '@' ? eAccessType::ACCESS_PRIVATE : eAccessType::ACCESS_PUBLIC; + CScriptFile* file = new CScriptFile(resource->GetScriptID(), metaPath, DEFAULT_MAX_FILESIZE,access); + if (file->Load(resource, CScriptFile::MODE_READ)) { + file->SetLuaDebugInfo(g_pClientGame->GetScriptDebugging()->GetLuaDebugInfo(luaVM)); + long size = file->GetSize(); + long bytesRead = file->Read(size,fileBuffer); + if (bytesRead >= 0){ + loader = CClientGifLoader(fileBuffer); + }else if (bytesRead == -2){ + m_pScriptDebugging->LogWarning(luaVM, "out of memory"); + }else{ + m_pScriptDebugging->LogError(luaVM, SString("error while reading file [%s]", lastPath.c_str()).c_str()); + } + file->Unload(); + m_pElementDeleter->Delete(file); + }else{ + delete file; + m_pScriptDebugging->LogError(luaVM, SString("couldn't load file [%s]",lastPath.c_str()).c_str()); + lua_pushboolean(luaVM, false); + return 1; + } + }else{ + m_pScriptDebugging->LogError(luaVM, SString("file [%s] doesn't exists!",lastPath.c_str()).c_str()); + lua_pushboolean(luaVM, false); + return 1; + } + }else{ + loader = CClientGifLoader(buffer); + } + std::vector frames; + std::vector delays; + loader.Load(frames, delays, 0L); + if (!loader) { + m_pScriptDebugging->LogError(luaVM, "wrong file format"); + lua_pushboolean(luaVM, false); + return 1; + } + if (frames.size() < 1) { + m_pScriptDebugging->LogError(luaVM, "gif has no frames"); + lua_pushboolean(luaVM,false); + return 1; + } + uint width = (uint)loader.GetWidth(); + uint height = (uint)loader.GetHeight(); + if (width < 1 || height < 1) { + m_pScriptDebugging->LogError(luaVM, "gif must be 1x1 at least"); + lua_pushboolean(luaVM,false); + return 1; + } + CClientGif* gif = g_pClientGame->GetManager()->GetRenderElementManager()->CreateGif(width,height); + if (!gif) { + m_pScriptDebugging->LogError(luaVM, "error while creating gif"); + lua_pushboolean(luaVM, false); + return 1; + } + gif->SetParent(resource->GetResourceDynamicEntity()); + gif->SetResource(resource); + gif->Register(frames,delays); + gif->SetFrameCount(frames.size()); + gif->SetFormat(loader.GetFormat()); + lua_pushelement(luaVM, gif); + return 1; + }else{ + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + } + lua_pushboolean(luaVM,false); + return 1; +} + +int CLuaGifDefs::GifPlay(lua_State* luaVM) { + CClientGif* gif = nullptr; + CScriptArgReader argStream(luaVM); + argStream.ReadUserData(gif); + if (!gif) { + m_pScriptDebugging->LogCustom(luaVM,argStream.GetFullErrorMessage()); + lua_pushboolean(luaVM, false); + return 1; + } + if (!argStream.HasErrors()) { + gif->Play(); + lua_pushboolean(luaVM,true); + return 1; + }else{ + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + } + lua_pushboolean(luaVM,false); + return 1; +} + +int CLuaGifDefs::GifStop(lua_State* luaVM) { + CClientGif* gif = nullptr; + CScriptArgReader argStream(luaVM); + argStream.ReadUserData(gif); + if (!gif) { + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + lua_pushboolean(luaVM,false); + return 1; + } + if (!argStream.HasErrors()) { + gif->Stop(); + lua_pushboolean(luaVM, true); + return 1; + }else{ + m_pScriptDebugging->LogCustom(luaVM,argStream.GetFullErrorMessage()); + } + lua_pushboolean(luaVM,false); + return 1; +} + +int CLuaGifDefs::GifNavigateToThumbnail(lua_State* luaVM) { + CClientGif* gif = nullptr; + CScriptArgReader argStream(luaVM); + argStream.ReadUserData(gif); + if (!gif) { + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + lua_pushboolean(luaVM,false); + return 1; + } + if (!argStream.HasErrors()) { + gif->NavigateToThumbnail(); + lua_pushboolean(luaVM, true); + return 1; + }else{ + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + } + lua_pushboolean(luaVM,false); + return 1; +} + +int CLuaGifDefs::GifSetFrameDelay(lua_State* luaVM) { + CClientGif* gif = nullptr; + uint index = 0; + uint delay = 0; + CScriptArgReader argStream(luaVM); + argStream.ReadUserData(gif); + if (!gif) { + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + lua_pushboolean(luaVM,false); + return 1; + } + argStream.ReadNumber(index,-1); + argStream.ReadNumber(delay); + if (!argStream.HasErrors()) { + gif->SetFrameDelay(index, delay); + lua_pushboolean(luaVM,true); + return 1; + }else{ + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + } + lua_pushboolean(luaVM,false); + return 1; +} + +int CLuaGifDefs::GifGetFrameCount(lua_State* luaVM) { + CClientGif* gif = nullptr; + CScriptArgReader argStream(luaVM); + argStream.ReadUserData(gif); + if (!gif) { + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + lua_pushboolean(luaVM,false); + return 1; + } + if (!argStream.HasErrors()) { + lua_pushnumber(luaVM, gif->GetFrameCount()); + return 1; + }else{ + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + } + lua_pushboolean(luaVM,false); + return 1; +} + +int CLuaGifDefs::GifGetFrameDelay(lua_State* luaVM) { + CClientGif* gif = nullptr; + uint index = 0; + CScriptArgReader argStream(luaVM); + argStream.ReadUserData(gif); + if (!gif) { + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + lua_pushboolean(luaVM,false); + return 1; + } + argStream.ReadNumber(index,-1); + if (!argStream.HasErrors()) { + lua_pushnumber(luaVM, gif->GetFrameDelay(index)); + return 1; + }else{ + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + } + lua_pushboolean(luaVM,false); + return 1; +} + +int CLuaGifDefs::GifGetShowingFrame(lua_State* luaVM){ + CClientGif* gif = nullptr; + CScriptArgReader argStream(luaVM); + argStream.ReadUserData(gif); + if (!gif) { + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + lua_pushboolean(luaVM,false); + return 1; + } + if (!argStream.HasErrors()) { + lua_pushnumber(luaVM, gif->GetShowingFrame()); + return 1; + }else{ + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + } + lua_pushboolean(luaVM,false); + return 1; +} + +int CLuaGifDefs::GifGetFrameDefaultDelay(lua_State* luaVM) { + CClientGif* gif = nullptr; + uint index = 0; + CScriptArgReader argStream(luaVM); + argStream.ReadUserData(gif); + if (!gif) { + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + lua_pushboolean(luaVM,false); + return 1; + } + argStream.ReadNumber(index,-1); + if (!argStream.HasErrors()) { + lua_pushnumber(luaVM, gif->GetFrameDefaultDelay(index)); + return 1; + }else{ + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + } + lua_pushboolean(luaVM,false); + return 1; +} + +int CLuaGifDefs::GifGetFormat(lua_State* luaVM) { + CClientGif* gif = nullptr; + CScriptArgReader argStream(luaVM); + argStream.ReadUserData(gif); + if (!gif) { + m_pScriptDebugging->LogCustom(luaVM,argStream.GetFullErrorMessage()); + lua_pushboolean(luaVM,false); + return 1; + } + if (!argStream.HasErrors()) { + lua_pushstring(luaVM, gif->GetFormat().c_str()); + return 1; + }else{ + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + } + lua_pushboolean(luaVM,false); + return 1; +} + +int CLuaGifDefs::GifGetTick(lua_State* luaVM) { + CClientGif* gif = nullptr; + CScriptArgReader argStream(luaVM); + argStream.ReadUserData(gif); + if (!gif){ + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + lua_pushboolean(luaVM, false); + return 1; + } + if (!argStream.HasErrors()) { + lua_pushnumber(luaVM, gif->GetTick()); + return 1; + }else{ + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + } + lua_pushboolean(luaVM,false); + return 1; +} + +int CLuaGifDefs::IsGifPlaying(lua_State* luaVM) { + CClientGif* gif = nullptr; + CScriptArgReader argStream(luaVM); + argStream.ReadUserData(gif); + if (!gif) { + m_pScriptDebugging->LogCustom(luaVM,argStream.GetFullErrorMessage()); + lua_pushboolean(luaVM,false); + return 1; + } + if (!argStream.HasErrors()) { + lua_pushboolean(luaVM, gif->IsPlaying()); + return 1; + }else{ + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + } + lua_pushboolean(luaVM,false); + return 1; +} From 3f33535eab483ef13ace81d55f625ef7f5a3654b Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 12:31:58 +0330 Subject: [PATCH 08/53] Create CClientGif.h --- Client/mods/deathmatch/logic/CClientGif.h | 129 ++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 Client/mods/deathmatch/logic/CClientGif.h diff --git a/Client/mods/deathmatch/logic/CClientGif.h b/Client/mods/deathmatch/logic/CClientGif.h new file mode 100644 index 0000000000..523a81255b --- /dev/null +++ b/Client/mods/deathmatch/logic/CClientGif.h @@ -0,0 +1,129 @@ +/***************************************************************************** + * + * PROJECT: Multi Theft Auto + * LICENSE: See LICENSE in the top level directory + * + * Multi Theft Auto is available from https://www.multitheftauto.com/ + * + *****************************************************************************/ + +#pragma once + +#include "CClientGifDisplay.h" + +enum { + CGif_None = 0, + CGif_Current = 1, + CGif_Background = 2, + CGif_Previous = 3 +}; + +class CClientGifRect { +public: + uint left = 0; + uint top = 0; + uint width = 0; + uint height = 0; + bool valid = false; + CClientGifRect() = default; + CClientGifRect(const uint& l, const uint& t, const uint& w, const uint& h) : left(l), top(t), width(w), height(h) { valid = true; } +}; + +class CClientGifLoader { +public: + CClientGifLoader() = default; + CClientGifLoader(SString&); + CClientGifLoader(uint8_t*,unsigned long); + CClientGifLoader(char*); + void CreateFrame(std::vector&,std::vector&); + void Load(std::vector&,std::vector&,long); + uint8_t* GetBuffer() { return buffer; } + long& GetWidth() { return width; } + long& GetHeight() { return height; } + long& GetDelay() { return delay; } + long& GetFrameNumber() { return frameNumber; } + long& GetFrameCount() { return frameCount; } + SString GetFormat() { return format; } + bool operator!(); + + static long SkipChunk(uint8_t**, long); + static long LoadHeader(unsigned, uint8_t**, void**, unsigned, long*, long); + static long LoadFrame(uint8_t**, long*, uint8_t*, uint8_t*); + +private: + struct { + uint8_t r; + uint8_t g; + uint8_t b; + }* pallete; + SString format = "Undefined"; + uint8_t* buffer = nullptr; + uint8_t* address = nullptr; + void* palleteDecoder = nullptr; + void* palleteDecoderPrevious = nullptr; + long size = 0; + long width = 0; + long height = 0; + long palleteSize = 0; + long background = 0; + long transparent = 0; + long interlaced = 0; + long delay = 0; + long frameNumber = 0; + long frameCount = 0; + long mode = CGif_None; + unsigned long last = 0; + CClientGifRect rect = {0,0,0,0}; + bool error = false; +}; + +class CClientGif final : public CClientTexture { + DECLARE_CLASS(CClientGif, CClientTexture); + +public: + CClientGif(CClientManager*, ElementID, CGifItem*); + ~CClientGif(); + virtual void Unlink() override; + void Register(std::vector,std::vector); + CResource* GetResource() { return m_pResource; } + void SetResource(CResource* resource) { m_pResource = resource; } + eClientEntityType GetType() const { return CCLIENTGIF; } + CGifItem* GetRenderItem() const { return static_cast(m_pRenderItem); } + CClientGifDisplay* GetDisplay() const { return m_pGifDisplay.get(); } + std::vector& GetFrames() { return frames; } + uint GetStride() { return stride; } + uint GetShowingFrame() { return showing; } + uint GetFrameDelay(const uint& id) { return delays[(id < 1 ? showing : (id > GetImageCount() ? showing : id)) - 1]; } + uint GetFrameDefaultDelay(const uint& id) { return defaultDelays[(id < 1 ? showing : (id > GetImageCount() ? showing : id)) - 1]; } + int GetImageCount() { return frames.size(); } + double& GetTick() { return tick; } + unsigned char* GetFrame() { return showing <= GetImageCount() ? frames[showing - 1] : nullptr; } + SString& GetFormat() { return format; } + uint GetFrameCount() { return frameCount; } + void SetFrameDelay(const uint& id, const uint32_t& delay) { delays[(id < 1 ? showing : (id > GetImageCount() ? (showing) : id)) - 1] = delay; } + void SetFormat(const SString& fmt) { if (!fmt.empty()) format = fmt; } + void SetFrameCount(const uint& count) { frameCount = count; } + void UpdateTick() { tick = (double)GetTickCount64_(); } + void Play() { playing = true; } + void Stop() { playing = false; } + void Next(); + void NavigateToThumbnail() { showing = 1; } + bool IsPlaying() { return playing; } + bool IsDestoryed() const { return m_bIsDestoryed; } + +private: + CResource* m_pResource = nullptr; + CClientManager* m_pManager; + std::unique_ptr m_pGifDisplay; + SString format = "Undefined"; + std::vector frames; + std::vector defaultDelays; + std::vector delays; + uint frameCount = 0; + uint stride; + uint showing = 1; + double tick = (double)GetTickCount64_(); + bool playing = false; + bool m_bIsDestoryed = false; + std::string error = ""; +}; From ce4fcd2ba92fbfbb47cd6ecd0375dc03ef1eea00 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 12:33:47 +0330 Subject: [PATCH 09/53] Create CClientGif.cpp --- Client/mods/deathmatch/logic/CClientGif.cpp | 356 ++++++++++++++++++++ 1 file changed, 356 insertions(+) create mode 100644 Client/mods/deathmatch/logic/CClientGif.cpp diff --git a/Client/mods/deathmatch/logic/CClientGif.cpp b/Client/mods/deathmatch/logic/CClientGif.cpp new file mode 100644 index 0000000000..e04ee2f42e --- /dev/null +++ b/Client/mods/deathmatch/logic/CClientGif.cpp @@ -0,0 +1,356 @@ +/***************************************************************************** + * + * PROJECT: Multi Theft Auto + * LICENSE: See LICENSE in the top level directory + * + * Multi Theft Auto is available from https://www.multitheftauto.com/ + * + *****************************************************************************/ + +#include "StdInc.h" +#include "CClientGif.h" + +#define GIF_ALLOCATE(pointer,size,release) pointer = (uint8_t*)realloc((release) ? 0 : pointer,(release) ? size : 0UL) +#define BIGE 0 +#define _SWAP(h) ((BIGE) ? ((uint16_t)(h << 8) | (h << 8)) : h) + +CClientGif::CClientGif(CClientManager* pManager, ElementID ID, CGifItem* p_GifItem) + : ClassInit(this), CClientTexture(pManager, ID, p_GifItem) +{ + SetTypeName("gif"); + m_pManager = pManager; + stride = GetRenderItem()->m_uiSizeX * 4; + m_pGifDisplay = std::make_unique(m_pManager->GetDisplayManager(), this); +} + +CClientGif::~CClientGif(){ + Unlink(); +} + +void CClientGif::Register(std::vector frms, std::vector dls) { + frames = frms; + delays = dls; + defaultDelays = dls; + m_pGifDisplay->UpdateTexture(); +} + +void CClientGif::Next(){ + if (showing >= GetImageCount()) { + showing = 1; + }else{ + showing++; + } +} + +void CClientGif::Unlink(){ + for (unsigned char* frame : frames) { + if (frame) { + delete[] frame; + } + } + frames.clear(); + delays.clear(); + defaultDelays.clear(); + m_bIsDestoryed = true; + CClientRenderElement::Unlink(); +} + +CClientGifLoader::CClientGifLoader(SString& data) { + buffer = reinterpret_cast(data.data()); + size = (long)((unsigned long)data.size()); +} + +CClientGifLoader::CClientGifLoader(uint8_t* data,unsigned long dataSize) { + buffer = data; + size = (long)dataSize; +} + +CClientGifLoader::CClientGifLoader(char* data) { + buffer = reinterpret_cast(data); + size = (long)((unsigned long)strlen(data)); +} + +void CClientGifLoader::CreateFrame(std::vector& frames, std::vector& delays) { + long frameStride = width*4; + long frameSize = frameStride*height; + unsigned char* frame = new unsigned char[frameSize]; + memset(frame, 0, frameSize); + uint32_t x; + uint32_t y; + uint32_t yoffset; + uint32_t iterator; + uint32_t inter; + uint32_t source; + uint32_t dstSource; + uint32_t* pDecoder; + uint32_t* pPrevious; + #define ARGB(i) ( \ + (address[i] == transparent) ? \ + 0 : \ + ( \ + (uint32_t)pallete[address[i]].r << 16 | \ + (uint32_t)pallete[address[i]].g << 8 | \ + (uint32_t)pallete[address[i]].b << 0 | \ + 0xff000000 \ + ) \ + ) + if (!frameNumber) { + frameCount = ((frameCount < 0) ? -frameCount : frameCount)*height; + frameCount = (frameCount < 0xffff) ? frameCount : 0xffff; + dstSource = (uint32_t)(width*height); + palleteDecoder = calloc(sizeof(uint32_t),dstSource); + palleteDecoderPrevious = calloc(sizeof(uint32_t),dstSource); + } + pDecoder = (uint32_t*)palleteDecoder; + dstSource = (uint32_t)(width*rect.top + rect.left); + inter = (!(iterator = interlaced ? 0 : 4)) ? 4 : 5; + for (source = -1; iterator < inter; iterator++) { + for (yoffset = 16U >> ((iterator > 1) ? iterator : 0), y = (8 >> iterator) & 7; y < (uint32_t)rect.height; y += yoffset) { + for (x = 0; x < (uint32_t)rect.width; x++) { + if (transparent != (long)address[++source]) { + pDecoder[(uint32_t)width*y + x + dstSource] = ARGB(source); + } + } + } + } + memcpy((uint32_t*)frame, pDecoder, sizeof(uint32_t)*(uint32_t)width*(uint32_t)height); // copy pixels to frame + if ((mode == CGif_Previous) && !last) { + rect.width = width; + rect.height = height; + mode = CGif_Background; + dstSource = 0; + }else{ + last = (mode == CGif_Previous) ? last : (unsigned long)(frameNumber + 1); + pDecoder = (uint32_t*)((mode == CGif_Previous) ? palleteDecoder : palleteDecoderPrevious); + pPrevious = (uint32_t*)((mode == CGif_Previous) ? palleteDecoderPrevious : palleteDecoder); + for (x = (uint32_t)(width*height);--x;pDecoder[x - 1] = pPrevious[x - 1]); + } + if (mode == CGif_Background) { + for (address[0] = (uint8_t)((transparent >= 0) ? transparent : background), y = 0, pDecoder = (uint32_t*)palleteDecoder; y < (uint32_t)rect.height; y++) { + for (x = 0; x < (uint32_t)rect.width; x++) { + pDecoder[(uint32_t)width*y + x + dstSource] = ARGB(0); + } + } + } + #undef ARGB + frames.push_back(frame); + delays.push_back((int)delay); +} + +void CClientGifLoader::Load(std::vector& frames,std::vector& delays,long skip) { + const long Blen = (1 << 12)*sizeof(uint32_t); + const uint8_t extensionHeaderMark = 0x21; + const uint8_t frameHeaderMark = 0x2c; + const uint8_t endOfBufferMark = 0x3b; + const uint8_t graphicControlMark = 0xf9; + const uint8_t appMetadataMark = 0xff; + if (!buffer) { + error = true; + return; + } + #pragma pack(push,1) + struct GlobalHeader { + uint8_t head[6]; + uint16_t width; + uint16_t height; + uint8_t flags; + uint8_t background; + uint8_t aspectRatio; + }* header = (struct GlobalHeader*)buffer; + struct FrameHeader { + uint16_t x; + uint16_t y; + uint16_t width; + uint16_t height; + uint8_t flags; + }* frameHeader; + struct GraphicControlHeader { + uint8_t flags; + uint16_t delay; + uint8_t transparent; + }* graphicControl = 0; + #pragma pack(pop) + long desc; + long blen; + uint8_t* decoder; + if ( // check if header is : `GIF89a` or `GIF87a` + !header || + (size <= (long)sizeof(*header)) || + (*(decoder = header->head) != 71) || + decoder[1] != 73 || + decoder[2] != 70 || + decoder[3] != 56 || + skip < 0 || + (decoder[4] != 55 && decoder[4] != 57) || + decoder[5] != 97 + ){ + error = true; + return; + } + format = decoder[4] ? "GIF87a" : "GIF89a"; + decoder = (uint8_t*)(header + 1) + LoadHeader(header->flags, 0, 0, 0, 0, 0L) * 3L; + if ((size -= decoder - (uint8_t*)header) <= 0) { + error = true; + return; + } + width = _SWAP(header->width); + height = _SWAP(header->height); + for ( + address = decoder, + background = header->background, + blen = --size; + blen >= 0 && + ((desc = *address++) != endOfBufferMark); + blen = SkipChunk(&address,blen) - 1 + ){ + if (desc == frameHeaderMark) { + frameHeader = (struct FrameHeader*)address; + if (LoadHeader(header->flags, &address, (void**)&pallete,frameHeader->flags,&blen,sizeof(*frameHeader)) <= 0) { + break; + } + rect.width = _SWAP(frameHeader->width); + rect.height = _SWAP(frameHeader->height); + rect.left = (rect.width > rect.left) ? rect.width : rect.left; + rect.top = (rect.height > rect.top) ? rect.height : rect.top; + frameNumber++; + } + } + blen = rect.left*rect.top*(long)sizeof(*address); + GIF_ALLOCATE(address, (unsigned long)(blen + Blen + 2),1); + frameCount = (desc != endOfBufferMark) ? -frameNumber : frameNumber; + for ( + address += Blen, + frameNumber = -1; + blen && + (skip < ((frameCount < 0) ? -frameCount : frameCount)) && size >= 0; + size = (desc != endOfBufferMark) ? ((desc != frameHeaderMark) || (skip > frameNumber)) ? SkipChunk(&decoder,size) - 1 : size - 1 : -1 + ){ + if ((desc = *decoder++) == frameHeaderMark) { // found a frame + interlaced = !!((frameHeader = (struct FrameHeader*)decoder)->flags & 0x40); + *(void**)&pallete = (void*)(header + 1); + palleteSize = LoadHeader(header->flags, &decoder, (void**)&pallete, frameHeader->flags, &size, sizeof(*frameHeader)); + if ( + (skip <= ++frameNumber) && + ( + (palleteSize <= 0) || + LoadFrame(&decoder,&size,address,address + blen) < 0 + ) + ){ + size = -(frameNumber--) - 1; // failed to load frame + }else if (skip <= frameNumber) { + rect.left = _SWAP(frameHeader->x); + rect.top = _SWAP(frameHeader->y); + rect.width = _SWAP(frameHeader->width); + rect.height = _SWAP(frameHeader->height); + delay = (graphicControl) ? _SWAP(graphicControl->delay) : 0; + transparent = (graphicControl && (graphicControl->flags & 0x01)) ? graphicControl->transparent : -1; + delay = ((graphicControl && (graphicControl->flags & 0x02)) ? -delay - 1 : delay)*10; + mode = (graphicControl && !(graphicControl->flags & 0x10)) ? (graphicControl->flags & 0x0c) >> 2 : CGif_None; + graphicControl = 0; + CreateFrame(frames,delays); // creating frame plain + } + }else if (desc == extensionHeaderMark){ // found an extension + if (*decoder == graphicControlMark) { + graphicControl = (struct GraphicControlHeader*)(decoder + 1 + 1); + } + } + } + address -= Blen; + GIF_ALLOCATE(address, (unsigned long)(blen + Blen + 2), 0); +} + +bool CClientGifLoader::operator!() { + return buffer ? error : false; +} + +long CClientGifLoader::SkipChunk(uint8_t** buffer, long size){ + long skip; + for (skip = 2, ++size, ++(*buffer); ((size -= skip) > 0) && (skip > 1);*buffer += (skip = 1 + **buffer)); + return size; +} + +long CClientGifLoader::LoadHeader(unsigned globalFlags, uint8_t** buffer, void** pallete, unsigned state, long* size, long length) { + if (length && (!(*buffer += length) || ((*size -= length) <= 0))){ + return -2; + } + if (length && (state & 0x80)) { + *pallete = *buffer; + *buffer += (length = 2 << (state & 7))*3L; + return ((*size -= length * 3L) > 0) ? length : -1; + } + return (globalFlags & 0x80) ? (2 << (globalFlags & 7)) : 0; +} + +long CClientGifLoader::LoadFrame(uint8_t** buffer, long* size, uint8_t* address, uint8_t* blen){ + const long headerLength = sizeof(uint16_t); + const long tableLength = 1 << 12; + uint16_t accumulator; + uint16_t mask; + long lastCodeTable; + long iterator; + long previous; + long current; + long minLZWSize; + long currentLZWSize; + long blockSequense; + long bitSize; + uint32_t* code = (uint32_t*)address - tableLength; + if ((--(*size) <= headerLength) || !*++(*buffer)){ + return -4; + } + mask = (uint16_t)((1 << (currentLZWSize = (minLZWSize = *(*buffer - 1)) + 1)) - 1); + if (minLZWSize < 2 || minLZWSize > 8) { + return -3; + } + if ((lastCodeTable = (1L << minLZWSize)) != (mask & _SWAP(*(uint16_t*)(*buffer + 1)))) { + return -2; + } + for (current = ++lastCodeTable; current; code[--current] = 0); + for (--(*size), bitSize = -currentLZWSize, previous = current = 0; ((*size -= (blockSequense = *(*buffer)++) + 1) >= 0) && blockSequense; *buffer += blockSequense) { + for (; blockSequense > 0; blockSequense -= headerLength, *buffer += headerLength) { + for ( + accumulator = (uint16_t)(_SWAP(*(uint16_t*)*buffer) & ((blockSequense < headerLength) ? ((1U << (8 * blockSequense)) - 1U) : ~0U)), + current |= accumulator << (currentLZWSize + bitSize), + accumulator = (uint16_t)(accumulator >> -bitSize), + bitSize += 8 * ((blockSequense < headerLength) ? blockSequense : headerLength); + bitSize >= 0; + bitSize -= currentLZWSize, + previous = current, + current = accumulator, + accumulator = (uint16_t)(accumulator >> currentLZWSize) + ){ + if (((current &= mask) & ~1L) == (1L << minLZWSize)) { + if (~(lastCodeTable = current + 1) & 1){ // end of frame data + return (*((*buffer += blockSequense + 1) - 1)) ? -1 : 1; + } + mask = (uint16_t)((1 << (currentLZWSize = minLZWSize + 1)) - 1); + }else{ + if (lastCodeTable < tableLength){ + if ((lastCodeTable == mask) && (lastCodeTable < tableLength - 1)) { + mask = (uint16_t)(mask + mask + 1); + currentLZWSize++; + } + code[lastCodeTable] = (uint32_t)previous + (code[previous] & 0xfff000); + } + previous = (long)code[iterator = (lastCodeTable > current) ? current : previous]; + if ((address += (previous = (previous >> 12) & 0xfff)) > blen) { + continue; + } + for (previous++; (iterator &= 0xfff) >> minLZWSize; *address-- = (uint8_t)((iterator = (long)code[iterator]) >> 24)); + (address += previous)[-previous] = (uint8_t)iterator; + if (lastCodeTable < tableLength) { + if (lastCodeTable == current) { + *address++ = (uint8_t)iterator; + }else if (lastCodeTable < current){ + return -5; // wrong code + } + code[lastCodeTable++] += ((uint32_t)iterator << 24) + 0x1000; + } + } + } + } + } + return (++(*size) >= 0) ? 0 : -4; // recoverable error +} + +#undef _SWAP From 56399ae8d621eba1b03de631e1d09bce3c21e615 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 12:34:19 +0330 Subject: [PATCH 10/53] Create CClientGifDisplay.h --- .../mods/deathmatch/logic/CClientGifDisplay.h | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Client/mods/deathmatch/logic/CClientGifDisplay.h diff --git a/Client/mods/deathmatch/logic/CClientGifDisplay.h b/Client/mods/deathmatch/logic/CClientGifDisplay.h new file mode 100644 index 0000000000..ea2c3e6975 --- /dev/null +++ b/Client/mods/deathmatch/logic/CClientGifDisplay.h @@ -0,0 +1,33 @@ +/***************************************************************************** + * + * PROJECT: Multi Theft Auto + * LICENSE: See LICENSE in the top level directory + * + * Multi Theft Auto is available from https://www.multitheftauto.com/ + * + *****************************************************************************/ + +class CClientGifDisplay; + +#pragma once + +#include "CClientDisplay.h" +#include "CClientDisplayManager.h" + +class CClientGifDisplay final : public CClientDisplay +{ + friend class CClientDisplayManager; + +public: + CClientGifDisplay(CClientDisplayManager*, CClientGif*, int ID = DISPLAY_GIF); + ~CClientGifDisplay() = default; + eDisplayType GetType() { return DISPLAY_GIF; } + void Render(); + void UpdateTexture(); + void ClearTexture(); + bool IsCleared() { return m_bIsCleared; } + +private: + CClientGif* m_pGif; + bool m_bIsCleared; +}; From 304b7cd73e0b23aa4597afc1b01236830bf7b768 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 12:35:20 +0330 Subject: [PATCH 11/53] Create CClientGifDisplay.cpp --- .../deathmatch/logic/CClientGifDisplay.cpp | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 Client/mods/deathmatch/logic/CClientGifDisplay.cpp diff --git a/Client/mods/deathmatch/logic/CClientGifDisplay.cpp b/Client/mods/deathmatch/logic/CClientGifDisplay.cpp new file mode 100644 index 0000000000..67139fafa3 --- /dev/null +++ b/Client/mods/deathmatch/logic/CClientGifDisplay.cpp @@ -0,0 +1,95 @@ +/***************************************************************************** + * + * PROJECT: Multi Theft Auto + * LICENSE: See LICENSE in the top level directory + * + * Multi Theft Auto is available from https://www.multitheftauto.com/ + * + *****************************************************************************/ + +#include "StdInc.h" +#include "CClientGifDisplay.h" +#include "CClientGif.h" + +CClientGifDisplay::CClientGifDisplay(CClientDisplayManager* pDisplayManager, CClientGif* pGif, int ID) + : CClientDisplay(pDisplayManager, ID) +{ + m_pGif = pGif; + m_bVisible = true; + m_bIsCleared = false; +} + +void CClientGifDisplay::Render(){ + if (!m_pGif || m_pGif->IsDestoryed()){ + return; + } + if (!m_bVisible){ + if (!IsCleared()){ + ClearTexture(); + } + return; + }else if (IsCleared()){ + m_bIsCleared = false; + } + if (m_pGif->IsPlaying()) { + if ((double)GetTickCount64_() >= m_pGif->GetTick() + m_pGif->GetFrameDelay(-1)) { + m_pGif->Next(); + m_pGif->UpdateTick(); + UpdateTexture(); + } + } +} + +void CClientGifDisplay::UpdateTexture(){ + if (!m_pGif || m_pGif->IsDestoryed()){ + return; + } + CGifItem* pGifItem = m_pGif->GetRenderItem(); + if (!pGifItem){ + return; + } + IDirect3DSurface9* surface = pGifItem->m_pD3DRenderTargetSurface; + if (!surface){ + return; + } + IDirect3DDevice9* device = pGifItem->m_pDevice; + // Lock Surface + D3DLOCKED_RECT LockedRect; + ZeroMemory(&LockedRect, sizeof(D3DLOCKED_RECT)); + surface->LockRect(&LockedRect, nullptr, 0); + // Unlock Surface + unsigned char* frame = m_pGif->GetFrame(); + if (frame){ + uint stride = m_pGif->GetStride(); + auto surfaceData = static_cast(LockedRect.pBits); + auto data = static_cast(frame); + for (int i = 0; i < pGifItem->m_uiSizeY; i++) { + memcpy(surfaceData,data,stride); + data += stride; + surfaceData += LockedRect.Pitch; + } + } + surface->UnlockRect(); +} + +void CClientGifDisplay::ClearTexture(){ + if (!m_pGif || m_pGif->IsDestoryed()){ + return; + } + CGifItem* pGif = m_pGif->GetRenderItem(); + if (!pGif){ + return; + } + IDirect3DSurface9* surface = pGif->m_pD3DRenderTargetSurface; + if (!surface){ + return; + } + IDirect3DDevice9* device = pGif->m_pDevice; + // Lock Surface + D3DLOCKED_RECT LockedRect; + surface->LockRect(&LockedRect, nullptr, 0); + device->ColorFill(surface, nullptr, D3DCOLOR_RGBA(0, 0, 0, 0)); + // Unlock Surface + surface->UnlockRect(); + m_bIsCleared = true; +} From ea85709a41f53606f0a95eac0eb264bc1f61fbb5 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 12:37:29 +0330 Subject: [PATCH 12/53] Add `CreateGif` function --- Client/mods/deathmatch/logic/CClientRenderElementManager.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Client/mods/deathmatch/logic/CClientRenderElementManager.h b/Client/mods/deathmatch/logic/CClientRenderElementManager.h index 64d76b835e..708b45e377 100644 --- a/Client/mods/deathmatch/logic/CClientRenderElementManager.h +++ b/Client/mods/deathmatch/logic/CClientRenderElementManager.h @@ -18,6 +18,7 @@ class CClientRenderTarget; class CClientScreenSource; class CClientWebBrowser; class CClientVectorGraphic; +class CClientGif; class CClientRenderElementManager { @@ -36,6 +37,7 @@ class CClientRenderElementManager CClientScreenSource* CreateScreenSource(uint uiSizeX, uint uiSizeY); CClientWebBrowser* CreateWebBrowser(uint uiSizeX, uint uiSizeY, bool bIsLocal, bool bTransparent); CClientVectorGraphic* CreateVectorGraphic(uint width, uint height); + CClientGif* CreateGif(uint width,uint height); CClientTexture* FindAutoTexture(const SString& strFullFilePath, const SString& strUniqueName); void Remove(CClientRenderElement* pElement); @@ -47,6 +49,7 @@ class CClientRenderElementManager uint GetScreenSourceCount() { return m_uiStatsScreenSourceCount; } uint GetWebBrowserCount() { return m_uiStatsWebBrowserCount; } uint GetVectorGraphicCount() { return m_uiStatsVectorGraphicCount; } + uint GetGifCount() { return m_uiStatsGifCount; } protected: CClientManager* m_pClientManager; @@ -61,4 +64,5 @@ class CClientRenderElementManager uint m_uiStatsScreenSourceCount; uint m_uiStatsWebBrowserCount; uint m_uiStatsVectorGraphicCount; + uint m_uiStatsGifCount; }; From 4f21b9a3e8bcb9d0d4eff49b5f1712ff21d44e4a Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 12:40:38 +0330 Subject: [PATCH 13/53] Add `CreateGif` function --- .../logic/CClientRenderElementManager.cpp | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Client/mods/deathmatch/logic/CClientRenderElementManager.cpp b/Client/mods/deathmatch/logic/CClientRenderElementManager.cpp index 10e4459ebd..7f89cf5b1e 100644 --- a/Client/mods/deathmatch/logic/CClientRenderElementManager.cpp +++ b/Client/mods/deathmatch/logic/CClientRenderElementManager.cpp @@ -10,6 +10,7 @@ #include "StdInc.h" #include "CClientVectorGraphic.h" +#include "CClientGif.h" //////////////////////////////////////////////////////////////// // @@ -29,6 +30,7 @@ CClientRenderElementManager::CClientRenderElementManager(CClientManager* pClient m_uiStatsScreenSourceCount = 0; m_uiStatsWebBrowserCount = 0; m_uiStatsVectorGraphicCount = 0; + m_uiStatsGifCount = 0; } //////////////////////////////////////////////////////////////// @@ -272,6 +274,35 @@ CClientVectorGraphic* CClientRenderElementManager::CreateVectorGraphic(uint widt return pVectorGraphicElement; } +//////////////////////////////////////////////////////////////// +// +// CClientRenderElementManager::CreateGif +// +// +// +//////////////////////////////////////////////////////////////// +CClientGif* CClientRenderElementManager::CreateGif(uint width, uint height) +{ + // Create the item + CGifItem* pGifItem = m_pRenderItemManager->CreateGif(width, height); + + // Check create worked + if (!pGifItem) + { + return nullptr; + } + + // Create the element + CClientGif* pGifElement = new CClientGif(m_pClientManager, INVALID_ELEMENT_ID, pGifItem); + + // Add to this manager's list + MapSet(m_ItemElementMap, pGifElement->GetRenderItem(), pGifElement); + + m_uiStatsGifCount++; + + return pGifElement; +} + //////////////////////////////////////////////////////////////// // // CClientRenderElementManager::FindAutoTexture @@ -342,6 +373,8 @@ void CClientRenderElementManager::Remove(CClientRenderElement* pElement) m_uiStatsWebBrowserCount--; else if (pElement->IsA(CClientVectorGraphic::GetClassId())) m_uiStatsVectorGraphicCount--; + else if (pElement->IsA(CClientGif::GetClassId())) + m_uiStatsGifCount--; else if (pElement->IsA(CClientTexture::GetClassId())) m_uiStatsTextureCount--; From 494e4bad277fa15eff2ef031e008524d6487f17b Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 12:44:16 +0330 Subject: [PATCH 14/53] Add `Gif` render item --- Client/sdk/core/CRenderItemManagerInterface.h | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Client/sdk/core/CRenderItemManagerInterface.h b/Client/sdk/core/CRenderItemManagerInterface.h index 4a08e62261..6635a37fa3 100644 --- a/Client/sdk/core/CRenderItemManagerInterface.h +++ b/Client/sdk/core/CRenderItemManagerInterface.h @@ -40,6 +40,7 @@ enum eAspectRatio; class CWebViewInterface; class CEffectTemplate; class CVectorGraphicItem; +class CGifItem; #define RDEFAULT ((uint)-1) @@ -161,6 +162,7 @@ class CRenderItemManagerInterface virtual CScreenSourceItem* CreateScreenSource(uint uiSizeX, uint uiSizeY) = 0; virtual CWebBrowserItem* CreateWebBrowser(uint uiSizeX, uint uiSizeY) = 0; virtual CVectorGraphicItem* CreateVectorGraphic(uint uiSizeX, uint uiSizeY) = 0; + virtual CGifItem* CreateGif(uint uiSizeX,uint uiSizeY) = 0; virtual bool SetRenderTarget(CRenderTargetItem* pItem, bool bClear) = 0; virtual void EnableSetRenderTargetOldVer(bool bEnable) = 0; virtual bool IsSetRenderTargetEnabledOldVer() = 0; @@ -237,6 +239,7 @@ enum eRenderItemClassTypes CLASS_CShaderInstance, CLASS_CTextureItem, CLASS_CVectorGraphicItem, + CLASS_CGifItem, CLASS_CFileTextureItem, CLASS_CRenderTargetItem, CLASS_CScreenSourceItem, @@ -491,6 +494,28 @@ class CVectorGraphicItem : public CTextureItem IDirect3DSurface9* m_pD3DRenderTargetSurface; }; +//////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////// +// +// CGifItem - CClientGif to texture +// +class CGifItem : public CTextureItem +{ + DECLARE_CLASS(CGifItem, CTextureItem) + CGifItem() : ClassInit(this) {} + virtual void PostConstruct(CRenderItemManager* pRenderItemManager, uint width, uint height); + virtual void PreDestruct(); + virtual bool IsValid(); + virtual void OnLostDevice(); + virtual void OnResetDevice(); + void CreateUnderlyingData(); + void ReleaseUnderlyingData(); + void UpdateTexture(); + virtual void Resize(const CVector2D& size); + + IDirect3DSurface9* m_pD3DRenderTargetSurface; +}; + //////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////// // From 595f40e8b0981f62d2592b111d8ded778b005f88 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 12:46:11 +0330 Subject: [PATCH 15/53] Create CRenderItem.Gif.cpp --- Client/core/Graphics/CRenderItem.Gif.cpp | 140 +++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 Client/core/Graphics/CRenderItem.Gif.cpp diff --git a/Client/core/Graphics/CRenderItem.Gif.cpp b/Client/core/Graphics/CRenderItem.Gif.cpp new file mode 100644 index 0000000000..c9db491f34 --- /dev/null +++ b/Client/core/Graphics/CRenderItem.Gif.cpp @@ -0,0 +1,140 @@ +/***************************************************************************** + * + * PROJECT: Multi Theft Auto + * LICENSE: See LICENSE in the top level directory + * + * Multi Theft Auto is available from https://www.multitheftauto.com/ + * + *****************************************************************************/ + +#include "StdInc.h" + +//////////////////////////////////////////////////////////////// +// +// CGifItem::PostConstruct +// +// +// +//////////////////////////////////////////////////////////////// +void CGifItem::PostConstruct(CRenderItemManager* pManager, uint width, uint height) +{ + Super::PostConstruct(pManager); + + m_uiSizeX = width; + m_uiSizeY = height; + m_uiSurfaceSizeX = width; + m_uiSurfaceSizeY = height; + + CreateUnderlyingData(); +} + +//////////////////////////////////////////////////////////////// +// +// CGifItem::PreDestruct +// +// +// +//////////////////////////////////////////////////////////////// +void CGifItem::PreDestruct() +{ + ReleaseUnderlyingData(); + Super::PreDestruct(); +} + +//////////////////////////////////////////////////////////////// +// +// CGifItem::IsValid +// +// Check underlying data is present +// +//////////////////////////////////////////////////////////////// +bool CGifItem::IsValid() +{ + return m_pD3DTexture != nullptr; +} + +//////////////////////////////////////////////////////////////// +// +// CGifItem::OnLostDevice +// +// Release device stuff +// +//////////////////////////////////////////////////////////////// +void CGifItem::OnLostDevice() +{ + // Nothing required for CGifItem +} + +//////////////////////////////////////////////////////////////// +// +// CGifItem::OnResetDevice +// +// Recreate device stuff +// +//////////////////////////////////////////////////////////////// +void CGifItem::OnResetDevice() +{ + // Nothing required for CGifItem +} + +//////////////////////////////////////////////////////////////// +// +// CGifItem::CreateUnderlyingData +// +// From file +// +//////////////////////////////////////////////////////////////// +void CGifItem::CreateUnderlyingData() +{ + assert(!m_pD3DRenderTargetSurface); + assert(!m_pD3DTexture); + + D3DXCreateTexture(m_pDevice, m_uiSizeX, m_uiSizeY, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, (IDirect3DTexture9**)&m_pD3DTexture); + + // Check texture created + if (!m_pD3DTexture) + return; + + // D3DXCreateTexture sets width and height to 1 if the argument value was 0 + // See: https://docs.microsoft.com/en-us/windows/desktop/direct3d9/d3dxcreatetexture + if (m_uiSizeX == 0) + m_uiSizeX = 1; + + if (m_uiSizeY == 0) + m_uiSizeY = 1; + + // Get the render target surface here for convenience + ((IDirect3DTexture9*)m_pD3DTexture)->GetSurfaceLevel(0, &m_pD3DRenderTargetSurface); + + // Update surface size, although it probably will be unchanged | Todo: Remove this + D3DSURFACE_DESC desc; + m_pD3DRenderTargetSurface->GetDesc(&desc); + m_uiSurfaceSizeX = desc.Width; + m_uiSurfaceSizeY = desc.Height; + + m_iMemoryKBUsed = CRenderItemManager::CalcD3DResourceMemoryKBUsage(m_pD3DRenderTargetSurface); +} + +//////////////////////////////////////////////////////////////// +// +// CGifItem::ReleaseUnderlyingData +// +// +// +//////////////////////////////////////////////////////////////// +void CGifItem::ReleaseUnderlyingData() +{ + SAFE_RELEASE(m_pD3DRenderTargetSurface); + SAFE_RELEASE(m_pD3DTexture); +} + +void CGifItem::Resize(const CVector2D& size) +{ + // Update size + m_uiSizeX = static_cast(size.fX); + m_uiSizeY = static_cast(size.fY); + + // Recreate texture + ReleaseUnderlyingData(); + CreateUnderlyingData(); +} From 6cedb9fb520b199c7a8c71902c44394e0dd892a0 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 12:47:51 +0330 Subject: [PATCH 16/53] Add `Gif` render item creator --- Client/core/Graphics/CRenderItemManager.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Client/core/Graphics/CRenderItemManager.h b/Client/core/Graphics/CRenderItemManager.h index 532e815a01..1ed56f1ef7 100644 --- a/Client/core/Graphics/CRenderItemManager.h +++ b/Client/core/Graphics/CRenderItemManager.h @@ -33,6 +33,7 @@ class CRenderItemManager : public CRenderItemManagerInterface virtual CRenderTargetItem* CreateRenderTarget(uint uiSizeX, uint uiSizeY, bool bWithAlphaChannel, bool bForce = false); virtual CScreenSourceItem* CreateScreenSource(uint uiSizeX, uint uiSizeY); virtual CVectorGraphicItem* CreateVectorGraphic(uint width, uint height); + virtual CGifItem* CreateGif(uint width,uint height); virtual CWebBrowserItem* CreateWebBrowser(uint uiSizeX, uint uiSizeY); virtual bool SetRenderTarget(CRenderTargetItem* pItem, bool bClear); virtual void EnableSetRenderTargetOldVer(bool bEnable); From 9915258e7da7470c43020713de379cffb956a425 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 12:49:29 +0330 Subject: [PATCH 17/53] Add `Gif` render item creator --- Client/core/Graphics/CRenderItemManager.cpp | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Client/core/Graphics/CRenderItemManager.cpp b/Client/core/Graphics/CRenderItemManager.cpp index 6911e6ef1c..bc91d9fbb8 100644 --- a/Client/core/Graphics/CRenderItemManager.cpp +++ b/Client/core/Graphics/CRenderItemManager.cpp @@ -171,6 +171,32 @@ CVectorGraphicItem* CRenderItemManager::CreateVectorGraphic(uint width, uint hei return pVectorItem; } +//////////////////////////////////////////////////////////////// +// +// CRenderItemManager::CreateGif +// +// +// +//////////////////////////////////////////////////////////////// +CGifItem* CRenderItemManager::CreateGif(uint width, uint height) +{ + if (!CanCreateRenderItem(CGifItem::GetClassId())) + return nullptr; + + CGifItem* pVectorItem = new CGifItem; + pVectorItem->PostConstruct(this, width, height); + + if (!pVectorItem->IsValid()) + { + SAFE_RELEASE(pVectorItem); + return nullptr; + } + + UpdateMemoryUsage(); + + return pVectorItem; +} + //////////////////////////////////////////////////////////////// // // CRenderItemManager::CreateRenderTarget From 564029b941ea1ccd82353132c9a0a53aa31ddfd9 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 14:28:29 +0330 Subject: [PATCH 18/53] check if rect locked to surface --- .../deathmatch/logic/CClientGifDisplay.cpp | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientGifDisplay.cpp b/Client/mods/deathmatch/logic/CClientGifDisplay.cpp index 67139fafa3..78f9fd36a4 100644 --- a/Client/mods/deathmatch/logic/CClientGifDisplay.cpp +++ b/Client/mods/deathmatch/logic/CClientGifDisplay.cpp @@ -55,21 +55,21 @@ void CClientGifDisplay::UpdateTexture(){ IDirect3DDevice9* device = pGifItem->m_pDevice; // Lock Surface D3DLOCKED_RECT LockedRect; - ZeroMemory(&LockedRect, sizeof(D3DLOCKED_RECT)); - surface->LockRect(&LockedRect, nullptr, 0); - // Unlock Surface - unsigned char* frame = m_pGif->GetFrame(); - if (frame){ - uint stride = m_pGif->GetStride(); - auto surfaceData = static_cast(LockedRect.pBits); - auto data = static_cast(frame); - for (int i = 0; i < pGifItem->m_uiSizeY; i++) { - memcpy(surfaceData,data,stride); - data += stride; - surfaceData += LockedRect.Pitch; + if (SUCCEEDED(surface->LockRect(&LockedRect, nullptr, D3DLOCK_DISCARD))) { + // Unlock Surface + unsigned char* frame = m_pGif->GetFrame(); + if (frame){ + uint stride = m_pGif->GetStride(); + auto surfaceData = static_cast(LockedRect.pBits); + auto data = static_cast(frame); + for (int i = 0; i < pGifItem->m_uiSizeY; i++) { + memcpy(surfaceData,data,stride); + data += stride; + surfaceData += LockedRect.Pitch; + } } + surface->UnlockRect(); } - surface->UnlockRect(); } void CClientGifDisplay::ClearTexture(){ From 6ed185383146738be7f98489079739b8ed674d7f Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 14:38:16 +0330 Subject: [PATCH 19/53] Erase GetTickCount64 and add it inside constructor --- Client/mods/deathmatch/logic/CClientGif.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/CClientGif.h b/Client/mods/deathmatch/logic/CClientGif.h index 523a81255b..f1d84b469c 100644 --- a/Client/mods/deathmatch/logic/CClientGif.h +++ b/Client/mods/deathmatch/logic/CClientGif.h @@ -122,7 +122,7 @@ class CClientGif final : public CClientTexture { uint frameCount = 0; uint stride; uint showing = 1; - double tick = (double)GetTickCount64_(); + double tick = 0; bool playing = false; bool m_bIsDestoryed = false; std::string error = ""; From 0c6a575f868bd8e2df53423fc2b31e01fdf0c1cf Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 14:40:16 +0330 Subject: [PATCH 20/53] Update tick inside constructor --- Client/mods/deathmatch/logic/CClientGif.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Client/mods/deathmatch/logic/CClientGif.cpp b/Client/mods/deathmatch/logic/CClientGif.cpp index e04ee2f42e..609abf4914 100644 --- a/Client/mods/deathmatch/logic/CClientGif.cpp +++ b/Client/mods/deathmatch/logic/CClientGif.cpp @@ -20,6 +20,7 @@ CClientGif::CClientGif(CClientManager* pManager, ElementID ID, CGifItem* p_GifIt SetTypeName("gif"); m_pManager = pManager; stride = GetRenderItem()->m_uiSizeX * 4; + UpdateTick(); m_pGifDisplay = std::make_unique(m_pManager->GetDisplayManager(), this); } From c11b6233e15a28c1e46ef4e45062550acfdc77ce Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 15:47:11 +0330 Subject: [PATCH 21/53] Change CClientGif::Register definition --- Client/mods/deathmatch/logic/CClientGif.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/CClientGif.cpp b/Client/mods/deathmatch/logic/CClientGif.cpp index 609abf4914..4f16848f02 100644 --- a/Client/mods/deathmatch/logic/CClientGif.cpp +++ b/Client/mods/deathmatch/logic/CClientGif.cpp @@ -28,7 +28,7 @@ CClientGif::~CClientGif(){ Unlink(); } -void CClientGif::Register(std::vector frms, std::vector dls) { +void CClientGif::Register(std::vector&& frms, std::vector&& dls) { frames = frms; delays = dls; defaultDelays = dls; From 39ca727509630634a50ef5581b05450e10b2686c Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 15:48:27 +0330 Subject: [PATCH 22/53] Change CClientGif::Register definition --- Client/mods/deathmatch/logic/CClientGif.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/CClientGif.h b/Client/mods/deathmatch/logic/CClientGif.h index f1d84b469c..159fcd41dc 100644 --- a/Client/mods/deathmatch/logic/CClientGif.h +++ b/Client/mods/deathmatch/logic/CClientGif.h @@ -84,7 +84,7 @@ class CClientGif final : public CClientTexture { CClientGif(CClientManager*, ElementID, CGifItem*); ~CClientGif(); virtual void Unlink() override; - void Register(std::vector,std::vector); + void Register(std::vector&&,std::vector&&); CResource* GetResource() { return m_pResource; } void SetResource(CResource* resource) { m_pResource = resource; } eClientEntityType GetType() const { return CCLIENTGIF; } From 1998dab767c897b856ff938b6caf61323300aa4f Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 15:49:46 +0330 Subject: [PATCH 23/53] Move frames and delays instead of copying them --- Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp index aedd8874ed..d2a0fec277 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp @@ -125,7 +125,7 @@ int CLuaGifDefs::GifCreate(lua_State* luaVM) { } gif->SetParent(resource->GetResourceDynamicEntity()); gif->SetResource(resource); - gif->Register(frames,delays); + gif->Register(std::move(frames),std::move(delays)); gif->SetFrameCount(frames.size()); gif->SetFormat(loader.GetFormat()); lua_pushelement(luaVM, gif); From c66131537d940c9ea08e436392585122279428b5 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 16:08:59 +0330 Subject: [PATCH 24/53] Use move inside Gif_Register for frames and delays --- Client/mods/deathmatch/logic/CClientGif.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientGif.cpp b/Client/mods/deathmatch/logic/CClientGif.cpp index 4f16848f02..369b8636e3 100644 --- a/Client/mods/deathmatch/logic/CClientGif.cpp +++ b/Client/mods/deathmatch/logic/CClientGif.cpp @@ -29,8 +29,8 @@ CClientGif::~CClientGif(){ } void CClientGif::Register(std::vector&& frms, std::vector&& dls) { - frames = frms; - delays = dls; + frames = std::move(frms); + delays = std::move(dls); defaultDelays = dls; m_pGifDisplay->UpdateTexture(); } From 9769a5582cadd592c44f0679b9fe29106a69ff6b Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 16:16:23 +0330 Subject: [PATCH 25/53] fix a tiny problem --- Client/mods/deathmatch/logic/CClientGif.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/CClientGif.cpp b/Client/mods/deathmatch/logic/CClientGif.cpp index 369b8636e3..34372ac11d 100644 --- a/Client/mods/deathmatch/logic/CClientGif.cpp +++ b/Client/mods/deathmatch/logic/CClientGif.cpp @@ -31,7 +31,7 @@ CClientGif::~CClientGif(){ void CClientGif::Register(std::vector&& frms, std::vector&& dls) { frames = std::move(frms); delays = std::move(dls); - defaultDelays = dls; + defaultDelays = delays; m_pGifDisplay->UpdateTexture(); } From 85a5765c5dad347b76986d443693110ef4ba8181 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 16:42:28 +0330 Subject: [PATCH 26/53] Missing space fixed! --- Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp index d2a0fec277..fce548b89a 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp @@ -117,7 +117,7 @@ int CLuaGifDefs::GifCreate(lua_State* luaVM) { lua_pushboolean(luaVM,false); return 1; } - CClientGif* gif = g_pClientGame->GetManager()->GetRenderElementManager()->CreateGif(width,height); + CClientGif* gif = g_pClientGame->GetManager()->GetRenderElementManager()->CreateGif(width, height); if (!gif) { m_pScriptDebugging->LogError(luaVM, "error while creating gif"); lua_pushboolean(luaVM, false); From d6ed7fb80e82b80d916332b36938074e038824a2 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 16:43:33 +0330 Subject: [PATCH 27/53] Missing space fixed! --- Client/sdk/core/CRenderItemManagerInterface.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/sdk/core/CRenderItemManagerInterface.h b/Client/sdk/core/CRenderItemManagerInterface.h index 6635a37fa3..aded3427e4 100644 --- a/Client/sdk/core/CRenderItemManagerInterface.h +++ b/Client/sdk/core/CRenderItemManagerInterface.h @@ -162,7 +162,7 @@ class CRenderItemManagerInterface virtual CScreenSourceItem* CreateScreenSource(uint uiSizeX, uint uiSizeY) = 0; virtual CWebBrowserItem* CreateWebBrowser(uint uiSizeX, uint uiSizeY) = 0; virtual CVectorGraphicItem* CreateVectorGraphic(uint uiSizeX, uint uiSizeY) = 0; - virtual CGifItem* CreateGif(uint uiSizeX,uint uiSizeY) = 0; + virtual CGifItem* CreateGif(uint uiSizeX, uint uiSizeY) = 0; virtual bool SetRenderTarget(CRenderTargetItem* pItem, bool bClear) = 0; virtual void EnableSetRenderTargetOldVer(bool bEnable) = 0; virtual bool IsSetRenderTargetEnabledOldVer() = 0; From a7ae18cc3c69822e53b07a1eb8dbf200899ff6d6 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 17:27:43 +0330 Subject: [PATCH 28/53] Add const for all getters --- Client/mods/deathmatch/logic/CClientGif.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientGif.h b/Client/mods/deathmatch/logic/CClientGif.h index 159fcd41dc..7e112e6071 100644 --- a/Client/mods/deathmatch/logic/CClientGif.h +++ b/Client/mods/deathmatch/logic/CClientGif.h @@ -90,16 +90,16 @@ class CClientGif final : public CClientTexture { eClientEntityType GetType() const { return CCLIENTGIF; } CGifItem* GetRenderItem() const { return static_cast(m_pRenderItem); } CClientGifDisplay* GetDisplay() const { return m_pGifDisplay.get(); } - std::vector& GetFrames() { return frames; } - uint GetStride() { return stride; } - uint GetShowingFrame() { return showing; } - uint GetFrameDelay(const uint& id) { return delays[(id < 1 ? showing : (id > GetImageCount() ? showing : id)) - 1]; } - uint GetFrameDefaultDelay(const uint& id) { return defaultDelays[(id < 1 ? showing : (id > GetImageCount() ? showing : id)) - 1]; } - int GetImageCount() { return frames.size(); } - double& GetTick() { return tick; } - unsigned char* GetFrame() { return showing <= GetImageCount() ? frames[showing - 1] : nullptr; } - SString& GetFormat() { return format; } - uint GetFrameCount() { return frameCount; } + std::vector GetFrames() const { return frames; } + uint GetStride() const { return stride; } + uint GetShowingFrame() const { return showing; } + uint GetFrameDelay(const uint& id) const { return delays[(id < 1 ? showing : (id > GetImageCount() ? showing : id)) - 1]; } + uint GetFrameDefaultDelay(const uint& id) const { return defaultDelays[(id < 1 ? showing : (id > GetImageCount() ? showing : id)) - 1]; } + int GetImageCount() const { return frames.size(); } + double GetTick() const { return tick; } + unsigned char* GetFrame() const { return showing <= GetImageCount() ? frames[showing - 1] : nullptr; } + SString GetFormat() const { return format; } + uint GetFrameCount() const { return frameCount; } void SetFrameDelay(const uint& id, const uint32_t& delay) { delays[(id < 1 ? showing : (id > GetImageCount() ? (showing) : id)) - 1] = delay; } void SetFormat(const SString& fmt) { if (!fmt.empty()) format = fmt; } void SetFrameCount(const uint& count) { frameCount = count; } @@ -108,7 +108,7 @@ class CClientGif final : public CClientTexture { void Stop() { playing = false; } void Next(); void NavigateToThumbnail() { showing = 1; } - bool IsPlaying() { return playing; } + bool IsPlaying() const { return playing; } bool IsDestoryed() const { return m_bIsDestoryed; } private: From ec49804530e66aa13e8955c66c5e06315accbb7a Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 17:36:38 +0330 Subject: [PATCH 29/53] Fix setting Gif frame count --- Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp index fce548b89a..9470237732 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp @@ -125,8 +125,8 @@ int CLuaGifDefs::GifCreate(lua_State* luaVM) { } gif->SetParent(resource->GetResourceDynamicEntity()); gif->SetResource(resource); - gif->Register(std::move(frames),std::move(delays)); gif->SetFrameCount(frames.size()); + gif->Register(std::move(frames),std::move(delays)); gif->SetFormat(loader.GetFormat()); lua_pushelement(luaVM, gif); return 1; From 6b5ea31372191b7004ef11b620f9754879e70e6d Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 19:59:41 +0330 Subject: [PATCH 30/53] Change code style --- Client/mods/deathmatch/logic/CClientGif.cpp | 196 ++++++++++---------- 1 file changed, 98 insertions(+), 98 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientGif.cpp b/Client/mods/deathmatch/logic/CClientGif.cpp index 34372ac11d..aa61974973 100644 --- a/Client/mods/deathmatch/logic/CClientGif.cpp +++ b/Client/mods/deathmatch/logic/CClientGif.cpp @@ -19,7 +19,7 @@ CClientGif::CClientGif(CClientManager* pManager, ElementID ID, CGifItem* p_GifIt { SetTypeName("gif"); m_pManager = pManager; - stride = GetRenderItem()->m_uiSizeX * 4; + m_bStride = GetRenderItem()->m_uiSizeX * 4; UpdateTick(); m_pGifDisplay = std::make_unique(m_pManager->GetDisplayManager(), this); } @@ -29,51 +29,51 @@ CClientGif::~CClientGif(){ } void CClientGif::Register(std::vector&& frms, std::vector&& dls) { - frames = std::move(frms); - delays = std::move(dls); - defaultDelays = delays; + m_bFrames = std::move(frms); + m_bDelays = std::move(dls); + m_bDefaultDelays = m_bDelays; m_pGifDisplay->UpdateTexture(); } void CClientGif::Next(){ - if (showing >= GetImageCount()) { - showing = 1; + if (m_bShowing >= GetImageCount()) { + m_bShowing = 1; }else{ - showing++; + m_bShowing++; } } void CClientGif::Unlink(){ - for (unsigned char* frame : frames) { + for (unsigned char* frame : m_bFrames) { if (frame) { delete[] frame; } } - frames.clear(); - delays.clear(); - defaultDelays.clear(); + m_bFrames.clear(); + m_bDelays.clear(); + m_bDefaultDelays.clear(); m_bIsDestoryed = true; CClientRenderElement::Unlink(); } CClientGifLoader::CClientGifLoader(SString& data) { - buffer = reinterpret_cast(data.data()); - size = (long)((unsigned long)data.size()); + m_pBuffer = reinterpret_cast(data.data()); + m_bSize = (long)((unsigned long)data.size()); } CClientGifLoader::CClientGifLoader(uint8_t* data,unsigned long dataSize) { - buffer = data; - size = (long)dataSize; + m_pBuffer = data; + m_bSize = (long)dataSize; } CClientGifLoader::CClientGifLoader(char* data) { - buffer = reinterpret_cast(data); - size = (long)((unsigned long)strlen(data)); + m_pBuffer = reinterpret_cast(data); + m_bSize = (long)((unsigned long)strlen(data)); } void CClientGifLoader::CreateFrame(std::vector& frames, std::vector& delays) { - long frameStride = width*4; - long frameSize = frameStride*height; + long frameStride = m_bWidth*4; + long frameSize = frameStride*m_bHeight; unsigned char* frame = new unsigned char[frameSize]; memset(frame, 0, frameSize); uint32_t x; @@ -86,56 +86,56 @@ void CClientGifLoader::CreateFrame(std::vector& frames, std::vec uint32_t* pDecoder; uint32_t* pPrevious; #define ARGB(i) ( \ - (address[i] == transparent) ? \ + (m_pAddress[i] == m_bTransparent) ? \ 0 : \ ( \ - (uint32_t)pallete[address[i]].r << 16 | \ - (uint32_t)pallete[address[i]].g << 8 | \ - (uint32_t)pallete[address[i]].b << 0 | \ + (uint32_t)m_pPallete[m_pAddress[i]].r << 16 | \ + (uint32_t)m_pPallete[m_pAddress[i]].g << 8 | \ + (uint32_t)m_pPallete[m_pAddress[i]].b << 0 | \ 0xff000000 \ ) \ ) - if (!frameNumber) { - frameCount = ((frameCount < 0) ? -frameCount : frameCount)*height; - frameCount = (frameCount < 0xffff) ? frameCount : 0xffff; - dstSource = (uint32_t)(width*height); - palleteDecoder = calloc(sizeof(uint32_t),dstSource); - palleteDecoderPrevious = calloc(sizeof(uint32_t),dstSource); + if (!m_bFrameNumber) { + m_bFrameCount = ((m_bFrameCount < 0) ? -m_bFrameCount : m_bFrameCount)*m_bHeight; + m_bFrameCount = (m_bFrameCount < 0xffff) ? m_bFrameCount : 0xffff; + dstSource = (uint32_t)(m_bWidth*m_bHeight); + m_pPalleteDecoder = calloc(sizeof(uint32_t),dstSource); + m_pPalleteDecoderPrevious = calloc(sizeof(uint32_t),dstSource); } - pDecoder = (uint32_t*)palleteDecoder; - dstSource = (uint32_t)(width*rect.top + rect.left); - inter = (!(iterator = interlaced ? 0 : 4)) ? 4 : 5; + pDecoder = (uint32_t*)m_pPalleteDecoder; + dstSource = (uint32_t)(m_bWidth*m_bRect.top + m_bRect.left); + inter = (!(iterator = m_bInterlaced ? 0 : 4)) ? 4 : 5; for (source = -1; iterator < inter; iterator++) { - for (yoffset = 16U >> ((iterator > 1) ? iterator : 0), y = (8 >> iterator) & 7; y < (uint32_t)rect.height; y += yoffset) { - for (x = 0; x < (uint32_t)rect.width; x++) { - if (transparent != (long)address[++source]) { - pDecoder[(uint32_t)width*y + x + dstSource] = ARGB(source); + for (yoffset = 16U >> ((iterator > 1) ? iterator : 0), y = (8 >> iterator) & 7; y < (uint32_t)m_bRect.height; y += yoffset) { + for (x = 0; x < (uint32_t)m_bRect.width; x++) { + if (m_bTransparent != (long)m_pAddress[++source]) { + pDecoder[(uint32_t)m_bWidth*y + x + dstSource] = ARGB(source); } } } } - memcpy((uint32_t*)frame, pDecoder, sizeof(uint32_t)*(uint32_t)width*(uint32_t)height); // copy pixels to frame - if ((mode == CGif_Previous) && !last) { - rect.width = width; - rect.height = height; - mode = CGif_Background; + memcpy((uint32_t*)frame, pDecoder, sizeof(uint32_t)*(uint32_t)m_bWidth*(uint32_t)m_bHeight); // copy pixels to frame + if ((m_bMode == CGif_Previous) && !m_bLast) { + m_bRect.width = m_bWidth; + m_bRect.height = m_bHeight; + m_bMode = CGif_Background; dstSource = 0; }else{ - last = (mode == CGif_Previous) ? last : (unsigned long)(frameNumber + 1); - pDecoder = (uint32_t*)((mode == CGif_Previous) ? palleteDecoder : palleteDecoderPrevious); - pPrevious = (uint32_t*)((mode == CGif_Previous) ? palleteDecoderPrevious : palleteDecoder); - for (x = (uint32_t)(width*height);--x;pDecoder[x - 1] = pPrevious[x - 1]); + m_bLast = (m_bMode == CGif_Previous) ? m_bLast : (unsigned long)(m_bFrameNumber + 1); + pDecoder = (uint32_t*)((m_bMode == CGif_Previous) ? m_pPalleteDecoder : m_pPalleteDecoderPrevious); + pPrevious = (uint32_t*)((m_bMode == CGif_Previous) ? m_pPalleteDecoderPrevious : m_pPalleteDecoder); + for (x = (uint32_t)(m_bWidth*m_bHeight);--x;pDecoder[x - 1] = pPrevious[x - 1]); } - if (mode == CGif_Background) { - for (address[0] = (uint8_t)((transparent >= 0) ? transparent : background), y = 0, pDecoder = (uint32_t*)palleteDecoder; y < (uint32_t)rect.height; y++) { - for (x = 0; x < (uint32_t)rect.width; x++) { - pDecoder[(uint32_t)width*y + x + dstSource] = ARGB(0); + if (m_bMode == CGif_Background) { + for (m_pAddress[0] = (uint8_t)((m_bTransparent >= 0) ? m_bTransparent : m_bBackground), y = 0, pDecoder = (uint32_t*)m_pPalleteDecoder; y < (uint32_t)m_bRect.height; y++) { + for (x = 0; x < (uint32_t)m_bRect.width; x++) { + pDecoder[(uint32_t)m_bWidth*y + x + dstSource] = ARGB(0); } } } #undef ARGB frames.push_back(frame); - delays.push_back((int)delay); + delays.push_back((int)m_bDelay); } void CClientGifLoader::Load(std::vector& frames,std::vector& delays,long skip) { @@ -145,8 +145,8 @@ void CClientGifLoader::Load(std::vector& frames,std::vector const uint8_t endOfBufferMark = 0x3b; const uint8_t graphicControlMark = 0xf9; const uint8_t appMetadataMark = 0xff; - if (!buffer) { - error = true; + if (!m_pBuffer) { + m_bError = true; return; } #pragma pack(push,1) @@ -157,7 +157,7 @@ void CClientGifLoader::Load(std::vector& frames,std::vector uint8_t flags; uint8_t background; uint8_t aspectRatio; - }* header = (struct GlobalHeader*)buffer; + }* header = (struct GlobalHeader*)m_pBuffer; struct FrameHeader { uint16_t x; uint16_t y; @@ -176,7 +176,7 @@ void CClientGifLoader::Load(std::vector& frames,std::vector uint8_t* decoder; if ( // check if header is : `GIF89a` or `GIF87a` !header || - (size <= (long)sizeof(*header)) || + (m_bSize <= (long)sizeof(*header)) || (*(decoder = header->head) != 71) || decoder[1] != 73 || decoder[2] != 70 || @@ -185,68 +185,68 @@ void CClientGifLoader::Load(std::vector& frames,std::vector (decoder[4] != 55 && decoder[4] != 57) || decoder[5] != 97 ){ - error = true; + m_bError = true; return; } - format = decoder[4] ? "GIF87a" : "GIF89a"; + m_bFormat = decoder[4] ? "GIF87a" : "GIF89a"; decoder = (uint8_t*)(header + 1) + LoadHeader(header->flags, 0, 0, 0, 0, 0L) * 3L; - if ((size -= decoder - (uint8_t*)header) <= 0) { - error = true; + if ((m_bSize -= decoder - (uint8_t*)header) <= 0) { + m_bError = true; return; } - width = _SWAP(header->width); - height = _SWAP(header->height); + m_bWidth = _SWAP(header->width); + m_bHeight = _SWAP(header->height); for ( - address = decoder, - background = header->background, - blen = --size; + m_pAddress = decoder, + m_bBackground = header->background, + blen = --m_bSize; blen >= 0 && - ((desc = *address++) != endOfBufferMark); - blen = SkipChunk(&address,blen) - 1 + ((desc = *m_pAddress++) != endOfBufferMark); + blen = SkipChunk(&m_pAddress,blen) - 1 ){ if (desc == frameHeaderMark) { - frameHeader = (struct FrameHeader*)address; - if (LoadHeader(header->flags, &address, (void**)&pallete,frameHeader->flags,&blen,sizeof(*frameHeader)) <= 0) { + frameHeader = (struct FrameHeader*)m_pAddress; + if (LoadHeader(header->flags, &m_pAddress, (void**)&m_pPallete,frameHeader->flags,&blen,sizeof(*frameHeader)) <= 0) { break; } - rect.width = _SWAP(frameHeader->width); - rect.height = _SWAP(frameHeader->height); - rect.left = (rect.width > rect.left) ? rect.width : rect.left; - rect.top = (rect.height > rect.top) ? rect.height : rect.top; - frameNumber++; + m_bRect.width = _SWAP(frameHeader->width); + m_bRect.height = _SWAP(frameHeader->height); + m_bRect.left = (m_bRect.width > m_bRect.left) ? m_bRect.width : m_bRect.left; + m_bRect.top = (m_bRect.height > m_bRect.top) ? m_bRect.height : m_bRect.top; + m_bFrameNumber++; } } - blen = rect.left*rect.top*(long)sizeof(*address); - GIF_ALLOCATE(address, (unsigned long)(blen + Blen + 2),1); - frameCount = (desc != endOfBufferMark) ? -frameNumber : frameNumber; + blen = m_bRect.left*m_bRect.top*(long)sizeof(*m_pAddress); + GIF_ALLOCATE(m_pAddress, (unsigned long)(blen + Blen + 2),1); + m_bFrameCount = (desc != endOfBufferMark) ? -m_bFrameNumber : m_bFrameNumber; for ( - address += Blen, - frameNumber = -1; + m_pAddress += Blen, + m_bFrameNumber = -1; blen && - (skip < ((frameCount < 0) ? -frameCount : frameCount)) && size >= 0; - size = (desc != endOfBufferMark) ? ((desc != frameHeaderMark) || (skip > frameNumber)) ? SkipChunk(&decoder,size) - 1 : size - 1 : -1 + (skip < ((m_bFrameCount < 0) ? -m_bFrameCount : m_bFrameCount)) && m_bSize >= 0; + m_bSize = (desc != endOfBufferMark) ? ((desc != frameHeaderMark) || (skip > m_bFrameNumber)) ? SkipChunk(&decoder,m_bSize) - 1 : m_bSize - 1 : -1 ){ if ((desc = *decoder++) == frameHeaderMark) { // found a frame - interlaced = !!((frameHeader = (struct FrameHeader*)decoder)->flags & 0x40); - *(void**)&pallete = (void*)(header + 1); - palleteSize = LoadHeader(header->flags, &decoder, (void**)&pallete, frameHeader->flags, &size, sizeof(*frameHeader)); + m_bInterlaced = !!((frameHeader = (struct FrameHeader*)decoder)->flags & 0x40); + *(void**)&m_pPallete = (void*)(header + 1); + m_bPalleteSize = LoadHeader(header->flags, &decoder, (void**)&m_pPallete, frameHeader->flags, &m_bSize, sizeof(*frameHeader)); if ( - (skip <= ++frameNumber) && + (skip <= ++m_bFrameNumber) && ( - (palleteSize <= 0) || - LoadFrame(&decoder,&size,address,address + blen) < 0 + (m_bPalleteSize <= 0) || + LoadFrame(&decoder,&m_bSize,m_pAddress,m_pAddress + blen) < 0 ) ){ - size = -(frameNumber--) - 1; // failed to load frame - }else if (skip <= frameNumber) { - rect.left = _SWAP(frameHeader->x); - rect.top = _SWAP(frameHeader->y); - rect.width = _SWAP(frameHeader->width); - rect.height = _SWAP(frameHeader->height); - delay = (graphicControl) ? _SWAP(graphicControl->delay) : 0; - transparent = (graphicControl && (graphicControl->flags & 0x01)) ? graphicControl->transparent : -1; - delay = ((graphicControl && (graphicControl->flags & 0x02)) ? -delay - 1 : delay)*10; - mode = (graphicControl && !(graphicControl->flags & 0x10)) ? (graphicControl->flags & 0x0c) >> 2 : CGif_None; + m_bSize = -(m_bFrameNumber--) - 1; // failed to load frame + }else if (skip <= m_bFrameNumber) { + m_bRect.left = _SWAP(frameHeader->x); + m_bRect.top = _SWAP(frameHeader->y); + m_bRect.width = _SWAP(frameHeader->width); + m_bRect.height = _SWAP(frameHeader->height); + m_bDelay = (graphicControl) ? _SWAP(graphicControl->delay) : 0; + m_bTransparent = (graphicControl && (graphicControl->flags & 0x01)) ? graphicControl->transparent : -1; + m_bDelay = ((graphicControl && (graphicControl->flags & 0x02)) ? -m_bDelay - 1 : m_bDelay)*10; + m_bMode = (graphicControl && !(graphicControl->flags & 0x10)) ? (graphicControl->flags & 0x0c) >> 2 : CGif_None; graphicControl = 0; CreateFrame(frames,delays); // creating frame plain } @@ -256,12 +256,12 @@ void CClientGifLoader::Load(std::vector& frames,std::vector } } } - address -= Blen; - GIF_ALLOCATE(address, (unsigned long)(blen + Blen + 2), 0); + m_pAddress -= Blen; + GIF_ALLOCATE(m_pAddress, (unsigned long)(blen + Blen + 2), 0); } bool CClientGifLoader::operator!() { - return buffer ? error : false; + return m_pBuffer ? m_bError : false; } long CClientGifLoader::SkipChunk(uint8_t** buffer, long size){ From e33d2c3ee19d6b99259c4c96bde07eccac50a5f0 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 20:00:17 +0330 Subject: [PATCH 31/53] Change code style --- Client/mods/deathmatch/logic/CClientGif.h | 109 +++++++++++----------- 1 file changed, 54 insertions(+), 55 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientGif.h b/Client/mods/deathmatch/logic/CClientGif.h index 7e112e6071..86d5e5dc7f 100644 --- a/Client/mods/deathmatch/logic/CClientGif.h +++ b/Client/mods/deathmatch/logic/CClientGif.h @@ -37,13 +37,13 @@ class CClientGifLoader { CClientGifLoader(char*); void CreateFrame(std::vector&,std::vector&); void Load(std::vector&,std::vector&,long); - uint8_t* GetBuffer() { return buffer; } - long& GetWidth() { return width; } - long& GetHeight() { return height; } - long& GetDelay() { return delay; } - long& GetFrameNumber() { return frameNumber; } - long& GetFrameCount() { return frameCount; } - SString GetFormat() { return format; } + uint8_t* GetBuffer() { return m_pBuffer; } + long& GetWidth() { return m_bWidth; } + long& GetHeight() { return m_bHeight; } + long& GetDelay() { return m_bDelay; } + long& GetFrameNumber() { return m_bFrameNumber; } + long& GetFrameCount() { return m_bFrameCount; } + SString GetFormat() { return m_bFormat; } bool operator!(); static long SkipChunk(uint8_t**, long); @@ -55,26 +55,26 @@ class CClientGifLoader { uint8_t r; uint8_t g; uint8_t b; - }* pallete; - SString format = "Undefined"; - uint8_t* buffer = nullptr; - uint8_t* address = nullptr; - void* palleteDecoder = nullptr; - void* palleteDecoderPrevious = nullptr; - long size = 0; - long width = 0; - long height = 0; - long palleteSize = 0; - long background = 0; - long transparent = 0; - long interlaced = 0; - long delay = 0; - long frameNumber = 0; - long frameCount = 0; - long mode = CGif_None; - unsigned long last = 0; - CClientGifRect rect = {0,0,0,0}; - bool error = false; + }* m_pPallete; + SString m_bFormat = "Undefined"; + uint8_t* m_pBuffer = nullptr; + uint8_t* m_pAddress = nullptr; + void* m_pPalleteDecoder = nullptr; + void* m_pPalleteDecoderPrevious = nullptr; + long m_bSize = 0; + long m_bWidth = 0; + long m_bHeight = 0; + long m_bPalleteSize = 0; + long m_bBackground = 0; + long m_bTransparent = 0; + long m_bInterlaced = 0; + long m_bDelay = 0; + long m_bFrameNumber = 0; + long m_bFrameCount = 0; + long m_bMode = CGif_None; + unsigned long m_bLast = 0; + CClientGifRect m_bRect = {0,0,0,0}; + bool m_bError = false; }; class CClientGif final : public CClientTexture { @@ -90,40 +90,39 @@ class CClientGif final : public CClientTexture { eClientEntityType GetType() const { return CCLIENTGIF; } CGifItem* GetRenderItem() const { return static_cast(m_pRenderItem); } CClientGifDisplay* GetDisplay() const { return m_pGifDisplay.get(); } - std::vector GetFrames() const { return frames; } - uint GetStride() const { return stride; } - uint GetShowingFrame() const { return showing; } - uint GetFrameDelay(const uint& id) const { return delays[(id < 1 ? showing : (id > GetImageCount() ? showing : id)) - 1]; } - uint GetFrameDefaultDelay(const uint& id) const { return defaultDelays[(id < 1 ? showing : (id > GetImageCount() ? showing : id)) - 1]; } - int GetImageCount() const { return frames.size(); } - double GetTick() const { return tick; } - unsigned char* GetFrame() const { return showing <= GetImageCount() ? frames[showing - 1] : nullptr; } - SString GetFormat() const { return format; } - uint GetFrameCount() const { return frameCount; } - void SetFrameDelay(const uint& id, const uint32_t& delay) { delays[(id < 1 ? showing : (id > GetImageCount() ? (showing) : id)) - 1] = delay; } - void SetFormat(const SString& fmt) { if (!fmt.empty()) format = fmt; } - void SetFrameCount(const uint& count) { frameCount = count; } - void UpdateTick() { tick = (double)GetTickCount64_(); } - void Play() { playing = true; } - void Stop() { playing = false; } + std::vector GetFrames() const { return m_bFrames; } + uint GetStride() const { return m_bStride; } + uint GetShowingFrame() const { return m_bShowing; } + uint GetFrameDelay(const uint& id) const { return m_bDelays[(id < 1 ? m_bShowing : (id > GetImageCount() ? m_bShowing : id)) - 1]; } + uint GetFrameDefaultDelay(const uint& id) const { return m_bDefaultDelays[(id < 1 ? m_bShowing : (id > GetImageCount() ? m_bShowing : id)) - 1]; } + int GetImageCount() const { return m_bFrames.size(); } + double GetTick() const { return m_bTick; } + unsigned char* GetFrame() const { return m_bShowing <= GetImageCount() ? m_bFrames[m_bShowing - 1] : nullptr; } + SString GetFormat() const { return m_bFormat; } + uint GetFrameCount() const { return m_bFrameCount; } + void SetFrameDelay(const uint& id, const uint32_t& delay) { m_bDelays[(id < 1 ? m_bShowing : (id > GetImageCount() ? (m_bShowing) : id)) - 1] = delay; } + void SetFormat(const SString& fmt) { if (!fmt.empty()) m_bFormat = fmt; } + void SetFrameCount(const uint& count) { m_bFrameCount = count; } + void UpdateTick() { m_bTick = (double)GetTickCount64_(); } + void Play() { m_bPlaying = true; } + void Stop() { m_bPlaying = false; } void Next(); - void NavigateToThumbnail() { showing = 1; } - bool IsPlaying() const { return playing; } + void NavigateToThumbnail() { m_bShowing = 1; } + bool IsPlaying() const { return m_bPlaying; } bool IsDestoryed() const { return m_bIsDestoryed; } private: CResource* m_pResource = nullptr; CClientManager* m_pManager; std::unique_ptr m_pGifDisplay; - SString format = "Undefined"; - std::vector frames; - std::vector defaultDelays; - std::vector delays; - uint frameCount = 0; - uint stride; - uint showing = 1; - double tick = 0; - bool playing = false; + SString m_bFormat = "Undefined"; + std::vector m_bFrames; + std::vector m_bDefaultDelays; + std::vector m_bDelays; + uint m_bFrameCount = 0; + uint m_bStride; + uint m_bShowing = 1; + double m_bTick = 0; + bool m_bPlaying = false; bool m_bIsDestoryed = false; - std::string error = ""; }; From d9907afabbd73ca8e9035fc75822dc2cf2baf6c7 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 20:52:35 +0330 Subject: [PATCH 32/53] Using vector arrays instead of raw pointer --- Client/mods/deathmatch/logic/CClientGif.h | 60 +++++++++++------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientGif.h b/Client/mods/deathmatch/logic/CClientGif.h index 86d5e5dc7f..d22d7b5695 100644 --- a/Client/mods/deathmatch/logic/CClientGif.h +++ b/Client/mods/deathmatch/logic/CClientGif.h @@ -35,8 +35,8 @@ class CClientGifLoader { CClientGifLoader(SString&); CClientGifLoader(uint8_t*,unsigned long); CClientGifLoader(char*); - void CreateFrame(std::vector&,std::vector&); - void Load(std::vector&,std::vector&,long); + void CreateFrame(std::vector>&, std::vector&); + void Load(std::vector>&, std::vector&, long); uint8_t* GetBuffer() { return m_pBuffer; } long& GetWidth() { return m_bWidth; } long& GetHeight() { return m_bHeight; } @@ -83,40 +83,40 @@ class CClientGif final : public CClientTexture { public: CClientGif(CClientManager*, ElementID, CGifItem*); ~CClientGif(); - virtual void Unlink() override; - void Register(std::vector&&,std::vector&&); - CResource* GetResource() { return m_pResource; } - void SetResource(CResource* resource) { m_pResource = resource; } - eClientEntityType GetType() const { return CCLIENTGIF; } - CGifItem* GetRenderItem() const { return static_cast(m_pRenderItem); } - CClientGifDisplay* GetDisplay() const { return m_pGifDisplay.get(); } - std::vector GetFrames() const { return m_bFrames; } - uint GetStride() const { return m_bStride; } - uint GetShowingFrame() const { return m_bShowing; } - uint GetFrameDelay(const uint& id) const { return m_bDelays[(id < 1 ? m_bShowing : (id > GetImageCount() ? m_bShowing : id)) - 1]; } - uint GetFrameDefaultDelay(const uint& id) const { return m_bDefaultDelays[(id < 1 ? m_bShowing : (id > GetImageCount() ? m_bShowing : id)) - 1]; } - int GetImageCount() const { return m_bFrames.size(); } - double GetTick() const { return m_bTick; } - unsigned char* GetFrame() const { return m_bShowing <= GetImageCount() ? m_bFrames[m_bShowing - 1] : nullptr; } - SString GetFormat() const { return m_bFormat; } - uint GetFrameCount() const { return m_bFrameCount; } - void SetFrameDelay(const uint& id, const uint32_t& delay) { m_bDelays[(id < 1 ? m_bShowing : (id > GetImageCount() ? (m_bShowing) : id)) - 1] = delay; } - void SetFormat(const SString& fmt) { if (!fmt.empty()) m_bFormat = fmt; } - void SetFrameCount(const uint& count) { m_bFrameCount = count; } - void UpdateTick() { m_bTick = (double)GetTickCount64_(); } - void Play() { m_bPlaying = true; } - void Stop() { m_bPlaying = false; } - void Next(); - void NavigateToThumbnail() { m_bShowing = 1; } - bool IsPlaying() const { return m_bPlaying; } - bool IsDestoryed() const { return m_bIsDestoryed; } + virtual void Unlink() override; + void Register(std::vector>&&, std::vector&); + CResource* GetResource() { return m_pResource; } + void SetResource(CResource* resource) { m_pResource = resource; } + eClientEntityType GetType() const { return CCLIENTGIF; } + CGifItem* GetRenderItem() const { return static_cast(m_pRenderItem); } + CClientGifDisplay* GetDisplay() const { return m_pGifDisplay.get(); } + std::vector> GetFrames() const { return m_bFrames; } + uint GetStride() const { return m_bStride; } + uint GetShowingFrame() const { return m_bShowing; } + uint GetFrameDelay(const uint& id) const { return m_bDelays[(id < 1 ? m_bShowing : (id > GetImageCount() ? m_bShowing : id)) - 1]; } + uint GetFrameDefaultDelay(const uint& id) const { return m_bDefaultDelays[(id < 1 ? m_bShowing : (id > GetImageCount() ? m_bShowing : id)) - 1]; } + int GetImageCount() const { return m_bFrames.size(); } + double GetTick() const { return m_bTick; } + unsigned char* GetFrame() { return m_bShowing <= GetImageCount() ? m_bFrames[m_bShowing - 1].data() : nullptr; } + SString GetFormat() const { return m_bFormat; } + uint GetFrameCount() const { return m_bFrameCount; } + void SetFrameDelay(const uint& id, const uint32_t& delay) { m_bDelays[(id < 1 ? m_bShowing : (id > GetImageCount() ? (m_bShowing) : id)) - 1] = delay; } + void SetFormat(const SString& fmt) { if (!fmt.empty()) m_bFormat = fmt; } + void SetFrameCount(const uint& count) { m_bFrameCount = count; } + void UpdateTick() { m_bTick = (double)GetTickCount64_(); } + void Play() { m_bPlaying = true; } + void Stop() { m_bPlaying = false; } + void Next(); + void NavigateToThumbnail() { m_bShowing = 1; } + bool IsPlaying() const { return m_bPlaying; } + bool IsDestoryed() const { return m_bIsDestoryed; } private: CResource* m_pResource = nullptr; CClientManager* m_pManager; std::unique_ptr m_pGifDisplay; SString m_bFormat = "Undefined"; - std::vector m_bFrames; + std::vector> m_bFrames; std::vector m_bDefaultDelays; std::vector m_bDelays; uint m_bFrameCount = 0; From 1870a31b88fec6ea45ea1d987b200f5b23441cb4 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 21:01:28 +0330 Subject: [PATCH 33/53] Using vector arrays instread of raw pointers --- Client/mods/deathmatch/logic/CClientGif.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientGif.cpp b/Client/mods/deathmatch/logic/CClientGif.cpp index aa61974973..82d13149a4 100644 --- a/Client/mods/deathmatch/logic/CClientGif.cpp +++ b/Client/mods/deathmatch/logic/CClientGif.cpp @@ -28,7 +28,7 @@ CClientGif::~CClientGif(){ Unlink(); } -void CClientGif::Register(std::vector&& frms, std::vector&& dls) { +void CClientGif::Register(std::vector>&& frms,std::vector& dls) { m_bFrames = std::move(frms); m_bDelays = std::move(dls); m_bDefaultDelays = m_bDelays; @@ -44,10 +44,8 @@ void CClientGif::Next(){ } void CClientGif::Unlink(){ - for (unsigned char* frame : m_bFrames) { - if (frame) { - delete[] frame; - } + for (std::vector& frame : m_bFrames) { + frame.clear(); } m_bFrames.clear(); m_bDelays.clear(); @@ -71,11 +69,11 @@ CClientGifLoader::CClientGifLoader(char* data) { m_bSize = (long)((unsigned long)strlen(data)); } -void CClientGifLoader::CreateFrame(std::vector& frames, std::vector& delays) { +void CClientGifLoader::CreateFrame(std::vector>& frames,std::vector& delays) { long frameStride = m_bWidth*4; long frameSize = frameStride*m_bHeight; - unsigned char* frame = new unsigned char[frameSize]; - memset(frame, 0, frameSize); + std::vector frame; + for (long i = 0; i < frameSize; i++, frame.push_back(0)); uint32_t x; uint32_t y; uint32_t yoffset; @@ -114,7 +112,7 @@ void CClientGifLoader::CreateFrame(std::vector& frames, std::vec } } } - memcpy((uint32_t*)frame, pDecoder, sizeof(uint32_t)*(uint32_t)m_bWidth*(uint32_t)m_bHeight); // copy pixels to frame + memcpy((uint32_t*)frame.data(), pDecoder, sizeof(uint32_t)*(uint32_t)m_bWidth*(uint32_t)m_bHeight); if ((m_bMode == CGif_Previous) && !m_bLast) { m_bRect.width = m_bWidth; m_bRect.height = m_bHeight; @@ -134,11 +132,11 @@ void CClientGifLoader::CreateFrame(std::vector& frames, std::vec } } #undef ARGB - frames.push_back(frame); + frames.push_back(std::move(frame)); delays.push_back((int)m_bDelay); } -void CClientGifLoader::Load(std::vector& frames,std::vector& delays,long skip) { +void CClientGifLoader::Load(std::vector>& frames,std::vector& delays,long skip) { const long Blen = (1 << 12)*sizeof(uint32_t); const uint8_t extensionHeaderMark = 0x21; const uint8_t frameHeaderMark = 0x2c; From b4d4aed361a21aaad9e176234bd110f7cebb7b16 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 16 Dec 2022 21:03:20 +0330 Subject: [PATCH 34/53] Using vector arrays instead of raw pointer --- Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp index 9470237732..7556935d80 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp @@ -97,7 +97,7 @@ int CLuaGifDefs::GifCreate(lua_State* luaVM) { }else{ loader = CClientGifLoader(buffer); } - std::vector frames; + std::vector> frames; std::vector delays; loader.Load(frames, delays, 0L); if (!loader) { From e3e06dc03b23e7596d93109a6755f08f03847fc2 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 13 Jan 2023 20:40:35 +0330 Subject: [PATCH 35/53] Remove useless functions --- Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h index ee0a6ab045..5f28363639 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h @@ -23,10 +23,6 @@ class CLuaGifDefs : public CLuaDefs static int GifNavigateToThumbnail(lua_State*); static int GifSetFrameDelay(lua_State*); static int GifGetFrameCount(lua_State*); - static int GifGetFrameDelay(lua_State*); - static int GifGetShowingFrame(lua_State*); static int GifGetFrameDefaultDelay(lua_State*); - static int GifGetFormat(lua_State*); - static int GifGetTick(lua_State*); static int IsGifPlaying(lua_State*); }; From 1e5cea0f3bb31b4484521b22a8006543092273ee Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 13 Jan 2023 20:47:43 +0330 Subject: [PATCH 36/53] Remove useless functions (2) --- Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h index 5f28363639..2a27785a64 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h @@ -21,8 +21,5 @@ class CLuaGifDefs : public CLuaDefs static int GifPlay(lua_State*); static int GifStop(lua_State*); static int GifNavigateToThumbnail(lua_State*); - static int GifSetFrameDelay(lua_State*); - static int GifGetFrameCount(lua_State*); - static int GifGetFrameDefaultDelay(lua_State*); static int IsGifPlaying(lua_State*); }; From 074c82b0b9c554a12f622fa6d8569bd569edbf8a Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Fri, 13 Jan 2023 20:49:04 +0330 Subject: [PATCH 37/53] Remove useless functions --- .../deathmatch/logic/luadefs/CLuaGifDefs.cpp | 156 ------------------ 1 file changed, 156 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp index 7556935d80..fea5056096 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp @@ -22,13 +22,6 @@ void CLuaGifDefs::LoadFunctions(){ {"gifPlay", GifPlay}, {"gifStop", GifStop}, {"gifNavigateToThumbnail", GifNavigateToThumbnail}, - {"gifSetFrameDelay", GifSetFrameDelay}, - {"gifGetFrameCount", GifGetFrameCount}, - {"gifGetFrameDelay", GifGetFrameDelay}, - {"gifGetShowingFrame", GifGetShowingFrame}, - {"gifGetFrameDefaultDelay", GifGetFrameDefaultDelay}, - {"gifGetFormat", GifGetFormat}, - {"gifGetTick", GifGetTick}, {"isGifPlaying", IsGifPlaying}, }; for (const auto& [name, func] : functions) @@ -40,13 +33,6 @@ void CLuaGifDefs::AddClass(lua_State* luaVM){ lua_classfunction(luaVM, "play", "gifPlay"); lua_classfunction(luaVM, "stop", "gifStop"); lua_classfunction(luaVM, "navigateToThumbnail", "gifNavigateToThumbnail"); - lua_classfunction(luaVM, "setFrameDelay", "gifSetFrameDelay"); - lua_classfunction(luaVM, "getFrameCount", "gifGetFrameCount"); - lua_classfunction(luaVM, "getFrameDelay", "gifGetFrameDelay"); - lua_classfunction(luaVM, "getShowingFrame", "gifGetShowingFrame"); - lua_classfunction(luaVM, "getFrameDefaultDelay", "gifGetFrameDefaultDelay"); - lua_classfunction(luaVM, "getFormat", "gifGetFormat"); - lua_classfunction(luaVM, "getTick", "gifGetTick"); lua_classfunction(luaVM, "isPlaying", "isGifPlaying"); lua_registerclass(luaVM, "Gif"); } @@ -197,148 +183,6 @@ int CLuaGifDefs::GifNavigateToThumbnail(lua_State* luaVM) { return 1; } -int CLuaGifDefs::GifSetFrameDelay(lua_State* luaVM) { - CClientGif* gif = nullptr; - uint index = 0; - uint delay = 0; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(gif); - if (!gif) { - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM,false); - return 1; - } - argStream.ReadNumber(index,-1); - argStream.ReadNumber(delay); - if (!argStream.HasErrors()) { - gif->SetFrameDelay(index, delay); - lua_pushboolean(luaVM,true); - return 1; - }else{ - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - } - lua_pushboolean(luaVM,false); - return 1; -} - -int CLuaGifDefs::GifGetFrameCount(lua_State* luaVM) { - CClientGif* gif = nullptr; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(gif); - if (!gif) { - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM,false); - return 1; - } - if (!argStream.HasErrors()) { - lua_pushnumber(luaVM, gif->GetFrameCount()); - return 1; - }else{ - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - } - lua_pushboolean(luaVM,false); - return 1; -} - -int CLuaGifDefs::GifGetFrameDelay(lua_State* luaVM) { - CClientGif* gif = nullptr; - uint index = 0; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(gif); - if (!gif) { - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM,false); - return 1; - } - argStream.ReadNumber(index,-1); - if (!argStream.HasErrors()) { - lua_pushnumber(luaVM, gif->GetFrameDelay(index)); - return 1; - }else{ - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - } - lua_pushboolean(luaVM,false); - return 1; -} - -int CLuaGifDefs::GifGetShowingFrame(lua_State* luaVM){ - CClientGif* gif = nullptr; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(gif); - if (!gif) { - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM,false); - return 1; - } - if (!argStream.HasErrors()) { - lua_pushnumber(luaVM, gif->GetShowingFrame()); - return 1; - }else{ - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - } - lua_pushboolean(luaVM,false); - return 1; -} - -int CLuaGifDefs::GifGetFrameDefaultDelay(lua_State* luaVM) { - CClientGif* gif = nullptr; - uint index = 0; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(gif); - if (!gif) { - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM,false); - return 1; - } - argStream.ReadNumber(index,-1); - if (!argStream.HasErrors()) { - lua_pushnumber(luaVM, gif->GetFrameDefaultDelay(index)); - return 1; - }else{ - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - } - lua_pushboolean(luaVM,false); - return 1; -} - -int CLuaGifDefs::GifGetFormat(lua_State* luaVM) { - CClientGif* gif = nullptr; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(gif); - if (!gif) { - m_pScriptDebugging->LogCustom(luaVM,argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM,false); - return 1; - } - if (!argStream.HasErrors()) { - lua_pushstring(luaVM, gif->GetFormat().c_str()); - return 1; - }else{ - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - } - lua_pushboolean(luaVM,false); - return 1; -} - -int CLuaGifDefs::GifGetTick(lua_State* luaVM) { - CClientGif* gif = nullptr; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(gif); - if (!gif){ - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM, false); - return 1; - } - if (!argStream.HasErrors()) { - lua_pushnumber(luaVM, gif->GetTick()); - return 1; - }else{ - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - } - lua_pushboolean(luaVM,false); - return 1; -} - int CLuaGifDefs::IsGifPlaying(lua_State* luaVM) { CClientGif* gif = nullptr; CScriptArgReader argStream(luaVM); From bbbfcbe809fefc60b3d65ca98dac429f25bed226 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Sat, 14 Jan 2023 09:19:55 +0330 Subject: [PATCH 38/53] Change `IsGifPlaying` to `GifIsplaying` --- Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h index 2a27785a64..a2a641c164 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h @@ -21,5 +21,5 @@ class CLuaGifDefs : public CLuaDefs static int GifPlay(lua_State*); static int GifStop(lua_State*); static int GifNavigateToThumbnail(lua_State*); - static int IsGifPlaying(lua_State*); + static int GifIsPlaying(lua_State*); }; From 2f8eff3a325a7dbcf9db9be4ae4efc1dc2d6bc9a Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Sat, 14 Jan 2023 09:21:49 +0330 Subject: [PATCH 39/53] Change `IsGifPlaying` to `GifIsPlaying` --- Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp index fea5056096..97038ac996 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp @@ -22,7 +22,7 @@ void CLuaGifDefs::LoadFunctions(){ {"gifPlay", GifPlay}, {"gifStop", GifStop}, {"gifNavigateToThumbnail", GifNavigateToThumbnail}, - {"isGifPlaying", IsGifPlaying}, + {"gifIsPlaying", GifIsPlaying}, }; for (const auto& [name, func] : functions) CLuaCFunctions::AddFunction(name, func); @@ -183,7 +183,7 @@ int CLuaGifDefs::GifNavigateToThumbnail(lua_State* luaVM) { return 1; } -int CLuaGifDefs::IsGifPlaying(lua_State* luaVM) { +int CLuaGifDefs::GifIsPlaying(lua_State* luaVM) { CClientGif* gif = nullptr; CScriptArgReader argStream(luaVM); argStream.ReadUserData(gif); From dc4ec8275737672db59607f0401a2a0cbac04a60 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Sat, 14 Jan 2023 11:23:52 +0330 Subject: [PATCH 40/53] Add `SetFrame` function --- Client/mods/deathmatch/logic/CClientGif.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Client/mods/deathmatch/logic/CClientGif.h b/Client/mods/deathmatch/logic/CClientGif.h index d22d7b5695..56fe801ad1 100644 --- a/Client/mods/deathmatch/logic/CClientGif.h +++ b/Client/mods/deathmatch/logic/CClientGif.h @@ -103,6 +103,7 @@ class CClientGif final : public CClientTexture { void SetFrameDelay(const uint& id, const uint32_t& delay) { m_bDelays[(id < 1 ? m_bShowing : (id > GetImageCount() ? (m_bShowing) : id)) - 1] = delay; } void SetFormat(const SString& fmt) { if (!fmt.empty()) m_bFormat = fmt; } void SetFrameCount(const uint& count) { m_bFrameCount = count; } + void SetFrame(const int& frame) { if (frame <= GetImageCount()) m_bShowing = 1; } void UpdateTick() { m_bTick = (double)GetTickCount64_(); } void Play() { m_bPlaying = true; } void Stop() { m_bPlaying = false; } From 60a3c9929821a86b1e4b19ee887dd1080a34ed47 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Sat, 14 Jan 2023 11:31:13 +0330 Subject: [PATCH 41/53] Add `GifSetProperty` & `GifGetProperty` --- Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h index a2a641c164..27c8baf4ea 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h @@ -20,6 +20,7 @@ class CLuaGifDefs : public CLuaDefs static int GifCreate(lua_State*); static int GifPlay(lua_State*); static int GifStop(lua_State*); - static int GifNavigateToThumbnail(lua_State*); + static int GifSetProperty(lua_State*); + static int GifGetProperty(lua_State*); static int GifIsPlaying(lua_State*); }; From 798c5bcd41ccf5c97257d83a4bd4267144bde7a6 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Sat, 14 Jan 2023 11:32:05 +0330 Subject: [PATCH 42/53] Add `GifSetProperty` & `GifGetProperty` --- .../deathmatch/logic/luadefs/CLuaGifDefs.cpp | 151 +++++++++++++++++- 1 file changed, 143 insertions(+), 8 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp index 97038ac996..c39ff97896 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp @@ -21,7 +21,8 @@ void CLuaGifDefs::LoadFunctions(){ {"gifCreate", GifCreate}, {"gifPlay", GifPlay}, {"gifStop", GifStop}, - {"gifNavigateToThumbnail", GifNavigateToThumbnail}, + {"gifSetProperty", GifSetProperty}, + {"gifGetProperty", GifGetProperty}, {"gifIsPlaying", GifIsPlaying}, }; for (const auto& [name, func] : functions) @@ -32,8 +33,9 @@ void CLuaGifDefs::AddClass(lua_State* luaVM){ lua_newclass(luaVM); lua_classfunction(luaVM, "play", "gifPlay"); lua_classfunction(luaVM, "stop", "gifStop"); - lua_classfunction(luaVM, "navigateToThumbnail", "gifNavigateToThumbnail"); - lua_classfunction(luaVM, "isPlaying", "isGifPlaying"); + lua_classfunction(luaVM, "setProperty", "gifSetProperty"); + lua_classfunction(luaVM, "getProperty", "gifGetProperty"); + lua_classfunction(luaVM, "isPlaying", "GifIsPlaying"); lua_registerclass(luaVM, "Gif"); } @@ -163,23 +165,156 @@ int CLuaGifDefs::GifStop(lua_State* luaVM) { return 1; } -int CLuaGifDefs::GifNavigateToThumbnail(lua_State* luaVM) { +int CLuaGifDefs::GifSetProperty(lua_State* luaVM) { CClientGif* gif = nullptr; + int frame = 0; + bool readFrame = false; + SString property; + SString strValue; + int numberValue = -1; + bool readNumberValue = false; CScriptArgReader argStream(luaVM); argStream.ReadUserData(gif); if (!gif) { m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM,false); + lua_pushboolean(luaVM, false); return 1; } + if (argStream.NextIsNumber()) { + argStream.ReadNumber(frame, 0); + readFrame = true; + } + argStream.ReadString(property); + if (argStream.NextIsNumber()) { + argStream.ReadNumber(numberValue); + readNumberValue = true; + }else{ + argStream.ReadString(strValue); + } if (!argStream.HasErrors()) { - gif->NavigateToThumbnail(); - lua_pushboolean(luaVM, true); + bool success = false; + if (property.empty()) { + m_pScriptDebugging->LogError(luaVM, "property can't be empty"); + lua_pushboolean(luaVM, false); + return 1; + } + if (readNumberValue) { + if (numberValue < 0) { + m_pScriptDebugging->LogError(luaVM, "property value can't be a negative number"); + lua_pushboolean(luaVM, false); + return 1; + } + }else{ + if (strValue.empty()) { + m_pScriptDebugging->LogError(luaVM, "property value can't be empty"); + lua_pushboolean(luaVM, false); + return 1; + } + } + if (frame > 0) { + int frameCount = gif->GetFrameCount(); + if (frame > frameCount){ + m_pScriptDebugging->LogError(luaVM, "couldn't find frame"); + lua_pushboolean(luaVM, false); + return 1; + } + if (property == "delay") { + if (numberValue > -1){ + gif->SetFrameDelay(frame, numberValue); + success = true; + } + }else{ + m_pScriptDebugging->LogError(luaVM, "property doesn't exist for frame"); + } + }else{ + if (readFrame) { + m_pScriptDebugging->LogError(luaVM, "couldn't find frame"); + }else{ + if (property == "showing_frame"){ + if (numberValue > -1){ + gif->SetFrame(numberValue); + success = true; + } + }else{ + m_pScriptDebugging->LogError(luaVM, "property doesn't exist for gif"); + } + } + } + if (success) { + lua_pushboolean(luaVM, true); + return 1; + } + }else{ + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + } + lua_pushboolean(luaVM, false); + return 1; +} + +int CLuaGifDefs::GifGetProperty(lua_State* luaVM) { + CClientGif* gif = nullptr; + int frame = 0; + bool readFrame = false; + SString property; + CScriptArgReader argStream(luaVM); + argStream.ReadUserData(gif); + if (!gif){ + m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + lua_pushboolean(luaVM, false); return 1; + } + if (argStream.NextIsNumber()){ + argStream.ReadNumber(frame, 0); + readFrame = true; + } + argStream.ReadString(property); + if (!argStream.HasErrors()){ + if (property.empty()){ + m_pScriptDebugging->LogError(luaVM, "property can't be empty"); + lua_pushboolean(luaVM, false); + return 1; + } + if (frame > 0){ + int frameCount = gif->GetFrameCount(); + if (frame > frameCount){ + m_pScriptDebugging->LogError(luaVM, "couldn't find frame"); + lua_pushboolean(luaVM, false); + return 1; + } + if (property == "delay"){ + lua_pushnumber(luaVM, gif->GetFrameDelay(frame)); + return 1; + }else if (property == "default_delay") { + lua_pushnumber(luaVM, gif->GetFrameDefaultDelay(frame)); + return 1; + }else{ + m_pScriptDebugging->LogError(luaVM, "property doesn't exist for frame"); + } + }else{ + if (readFrame){ + m_pScriptDebugging->LogError(luaVM, "couldn't find frame"); + }else{ + if (property == "showing_frame"){ + lua_pushnumber(luaVM, gif->GetShowingFrame()); + return 1; + }else if (property == "frame_count"){ + lua_pushnumber(luaVM, gif->GetFrameCount()); + return 1; + }else if (property == "format"){ + lua_pushstring(luaVM, gif->GetFormat().c_str()); + return 1; + }else if (property == "tick"){ + lua_pushnumber(luaVM, gif->GetTick()); + return 1; + }else{ + m_pScriptDebugging->LogError(luaVM, "property doesn't exist for gif"); + } + } + } }else{ m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); } - lua_pushboolean(luaVM,false); + lua_pushboolean(luaVM, false); return 1; } From 515ccfe894fbda729e50f74c8eb3db5db76df12a Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Sat, 14 Jan 2023 14:07:16 +0330 Subject: [PATCH 43/53] Using new lua parser --- .../mods/deathmatch/logic/luadefs/CLuaGifDefs.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h index 27c8baf4ea..3ef707f7c7 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h @@ -15,12 +15,12 @@ class CLuaGifDefs : public CLuaDefs { public: - static void LoadFunctions(); - static void AddClass(lua_State*); - static int GifCreate(lua_State*); - static int GifPlay(lua_State*); - static int GifStop(lua_State*); - static int GifSetProperty(lua_State*); - static int GifGetProperty(lua_State*); - static int GifIsPlaying(lua_State*); + static void LoadFunctions(); + static void AddClass(lua_State*); + static CClientGif* GifCreate(lua_State*, std::string); + static bool GifPlay(CClientGif*); + static bool GifStop(CClientGif*); + static bool GifSetProperty(lua_State*, CClientGif*, std::string, std::variant, std::optional); + static std::variant GifGetProperty(lua_State*, CClientGif*, std::string, std::optional); + static bool GifIsPlaying(CClientGif*); }; From d1189a4c8fd02e4e2fabaca889fac9b75d9f30d2 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Sat, 14 Jan 2023 14:08:36 +0330 Subject: [PATCH 44/53] Using new lua parser --- .../deathmatch/logic/luadefs/CLuaGifDefs.cpp | 401 ++++++------------ 1 file changed, 134 insertions(+), 267 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp index c39ff97896..8f7a9bb912 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp @@ -18,12 +18,12 @@ void CLuaGifDefs::LoadFunctions(){ constexpr static const std::pair functions[]{ - {"gifCreate", GifCreate}, - {"gifPlay", GifPlay}, - {"gifStop", GifStop}, - {"gifSetProperty", GifSetProperty}, - {"gifGetProperty", GifGetProperty}, - {"gifIsPlaying", GifIsPlaying}, + {"gifCreate", ArgumentParser}, + {"gifPlay", ArgumentParser}, + {"gifStop", ArgumentParser}, + {"gifSetProperty", ArgumentParser}, + {"gifGetProperty", ArgumentParser}, + {"gifIsPlaying", ArgumentParser}, }; for (const auto& [name, func] : functions) CLuaCFunctions::AddFunction(name, func); @@ -39,300 +39,167 @@ void CLuaGifDefs::AddClass(lua_State* luaVM){ lua_registerclass(luaVM, "Gif"); } -int CLuaGifDefs::GifCreate(lua_State* luaVM) { - SString buffer; - CScriptArgReader argStream(luaVM); - argStream.ReadString(buffer); - if (!argStream.HasErrors()) { - CLuaMain& luaMain = lua_getownercluamain(luaVM); - CResource* resource = luaMain.GetResource(); - SString path; - SString metaPath; - SString fileBuffer; - SString lastPath = buffer; - SString format = buffer.substr(0,6); - CClientGifLoader loader; - if (format == "GIF87a" || format == "GIF89a") { +CClientGif* CLuaGifDefs::GifCreate(lua_State* luaVM, std::string pathOrRawdata) { + SString buffer = pathOrRawdata; + CLuaMain& luaMain = lua_getownercluamain(luaVM); + CResource* resource = luaMain.GetResource(); + SString path; + SString metaPath; + SString fileBuffer; + SString lastPath = buffer; + SString format = buffer.substr(0, 6); + CClientGifLoader loader; + if (format == "GIF87a" || format == "GIF89a"){ loader = CClientGifLoader(buffer); - }else if (CResourceManager::ParseResourcePathInput(buffer,resource,&path,&metaPath)){ - if (FileExists(path)) { - eAccessType access = buffer[0] == '@' ? eAccessType::ACCESS_PRIVATE : eAccessType::ACCESS_PUBLIC; - CScriptFile* file = new CScriptFile(resource->GetScriptID(), metaPath, DEFAULT_MAX_FILESIZE,access); - if (file->Load(resource, CScriptFile::MODE_READ)) { - file->SetLuaDebugInfo(g_pClientGame->GetScriptDebugging()->GetLuaDebugInfo(luaVM)); - long size = file->GetSize(); - long bytesRead = file->Read(size,fileBuffer); - if (bytesRead >= 0){ - loader = CClientGifLoader(fileBuffer); - }else if (bytesRead == -2){ - m_pScriptDebugging->LogWarning(luaVM, "out of memory"); - }else{ - m_pScriptDebugging->LogError(luaVM, SString("error while reading file [%s]", lastPath.c_str()).c_str()); - } - file->Unload(); - m_pElementDeleter->Delete(file); + }else if (CResourceManager::ParseResourcePathInput(buffer, resource, &path, &metaPath)){ + if (FileExists(path)){ + eAccessType access = buffer[0] == '@' ? eAccessType::ACCESS_PRIVATE : eAccessType::ACCESS_PUBLIC; + CScriptFile* file = new CScriptFile(resource->GetScriptID(), metaPath, DEFAULT_MAX_FILESIZE, access); + if (file->Load(resource, CScriptFile::MODE_READ)){ + file->SetLuaDebugInfo(g_pClientGame->GetScriptDebugging()->GetLuaDebugInfo(luaVM)); + long size = file->GetSize(); + long bytesRead = file->Read(size, fileBuffer); + if (bytesRead >= 0){ + loader = CClientGifLoader(fileBuffer); + }else if (bytesRead == -2){ + m_pScriptDebugging->LogWarning(luaVM, "out of memory"); }else{ - delete file; - m_pScriptDebugging->LogError(luaVM, SString("couldn't load file [%s]",lastPath.c_str()).c_str()); - lua_pushboolean(luaVM, false); - return 1; + m_pScriptDebugging->LogError(luaVM, SString("error while reading file [%s]", lastPath.c_str()).c_str()); } + file->Unload(); + m_pElementDeleter->Delete(file); }else{ - m_pScriptDebugging->LogError(luaVM, SString("file [%s] doesn't exists!",lastPath.c_str()).c_str()); - lua_pushboolean(luaVM, false); - return 1; + delete file; + m_pScriptDebugging->LogError(luaVM, SString("couldn't load file [%s]", lastPath.c_str()).c_str()); + return nullptr; } }else{ - loader = CClientGifLoader(buffer); - } - std::vector> frames; - std::vector delays; - loader.Load(frames, delays, 0L); - if (!loader) { - m_pScriptDebugging->LogError(luaVM, "wrong file format"); - lua_pushboolean(luaVM, false); - return 1; - } - if (frames.size() < 1) { - m_pScriptDebugging->LogError(luaVM, "gif has no frames"); - lua_pushboolean(luaVM,false); - return 1; + m_pScriptDebugging->LogError(luaVM, SString("file [%s] doesn't exists!", lastPath.c_str()).c_str()); + return nullptr; } - uint width = (uint)loader.GetWidth(); - uint height = (uint)loader.GetHeight(); - if (width < 1 || height < 1) { - m_pScriptDebugging->LogError(luaVM, "gif must be 1x1 at least"); - lua_pushboolean(luaVM,false); - return 1; - } - CClientGif* gif = g_pClientGame->GetManager()->GetRenderElementManager()->CreateGif(width, height); - if (!gif) { - m_pScriptDebugging->LogError(luaVM, "error while creating gif"); - lua_pushboolean(luaVM, false); - return 1; - } - gif->SetParent(resource->GetResourceDynamicEntity()); - gif->SetResource(resource); - gif->SetFrameCount(frames.size()); - gif->Register(std::move(frames),std::move(delays)); - gif->SetFormat(loader.GetFormat()); - lua_pushelement(luaVM, gif); - return 1; }else{ - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + loader = CClientGifLoader(buffer); } - lua_pushboolean(luaVM,false); - return 1; -} - -int CLuaGifDefs::GifPlay(lua_State* luaVM) { - CClientGif* gif = nullptr; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(gif); - if (!gif) { - m_pScriptDebugging->LogCustom(luaVM,argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM, false); - return 1; + std::vector> frames; + std::vector delays; + loader.Load(frames, delays, 0L); + if (!loader){ + m_pScriptDebugging->LogError(luaVM, "wrong file format"); + return nullptr; } - if (!argStream.HasErrors()) { - gif->Play(); - lua_pushboolean(luaVM,true); - return 1; - }else{ - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + if (frames.size() < 1){ + m_pScriptDebugging->LogError(luaVM, "gif has no frames"); + return nullptr; } - lua_pushboolean(luaVM,false); - return 1; -} - -int CLuaGifDefs::GifStop(lua_State* luaVM) { - CClientGif* gif = nullptr; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(gif); - if (!gif) { - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM,false); - return 1; + uint width = (uint)loader.GetWidth(); + uint height = (uint)loader.GetHeight(); + if (width < 1 || height < 1){ + m_pScriptDebugging->LogError(luaVM, "gif must be 1x1 at least"); + return nullptr; } - if (!argStream.HasErrors()) { - gif->Stop(); - lua_pushboolean(luaVM, true); - return 1; - }else{ - m_pScriptDebugging->LogCustom(luaVM,argStream.GetFullErrorMessage()); + CClientGif* gif = g_pClientGame->GetManager()->GetRenderElementManager()->CreateGif(width, height); + if (!gif){ + m_pScriptDebugging->LogError(luaVM, "error while creating gif"); + return nullptr; } - lua_pushboolean(luaVM,false); - return 1; + gif->SetParent(resource->GetResourceDynamicEntity()); + gif->SetResource(resource); + gif->SetFrameCount(frames.size()); + gif->Register(std::move(frames), std::move(delays)); + gif->SetFormat(loader.GetFormat()); + return gif; } -int CLuaGifDefs::GifSetProperty(lua_State* luaVM) { - CClientGif* gif = nullptr; - int frame = 0; - bool readFrame = false; - SString property; - SString strValue; - int numberValue = -1; - bool readNumberValue = false; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(gif); - if (!gif) { - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM, false); - return 1; - } - if (argStream.NextIsNumber()) { - argStream.ReadNumber(frame, 0); - readFrame = true; +bool CLuaGifDefs::GifPlay(CClientGif* gif) { + gif->Play(); + return true; +} + +bool CLuaGifDefs::GifStop(CClientGif* gif) { + gif->Stop(); + return true; +} + +bool CLuaGifDefs::GifSetProperty(lua_State* luaVM,CClientGif* gif, std::string property, std::variant value, std::optional frame) { + bool valIsNumber = false; + int numberValue = -1; + if (std::holds_alternative(value)) { + valIsNumber = true; + numberValue = std::get(value); + if (numberValue < 0) { + m_pScriptDebugging->LogError(luaVM, "property value can't be a negative number"); + return false; + } } - argStream.ReadString(property); - if (argStream.NextIsNumber()) { - argStream.ReadNumber(numberValue); - readNumberValue = true; - }else{ - argStream.ReadString(strValue); + if (property.empty()) { + m_pScriptDebugging->LogError(luaVM ,"property can't be empty"); + return false; } - if (!argStream.HasErrors()) { - bool success = false; - if (property.empty()) { - m_pScriptDebugging->LogError(luaVM, "property can't be empty"); - lua_pushboolean(luaVM, false); - return 1; + if (frame.has_value()) { + int frameCount = gif->GetFrameCount(); + if (frame > frameCount) { + m_pScriptDebugging->LogError(luaVM, "frame doesn't exist"); + return false; } - if (readNumberValue) { - if (numberValue < 0) { - m_pScriptDebugging->LogError(luaVM, "property value can't be a negative number"); - lua_pushboolean(luaVM, false); - return 1; + if (property == "delay") { + if (!valIsNumber) { + m_pScriptDebugging->LogError(luaVM, "property `delay` must be a number value"); + return false; } + gif->SetFrameDelay(frame.value(), numberValue); + return true; }else{ - if (strValue.empty()) { - m_pScriptDebugging->LogError(luaVM, "property value can't be empty"); - lua_pushboolean(luaVM, false); - return 1; - } + m_pScriptDebugging->LogError(luaVM, "property doesn't exist for frame"); } - if (frame > 0) { - int frameCount = gif->GetFrameCount(); - if (frame > frameCount){ - m_pScriptDebugging->LogError(luaVM, "couldn't find frame"); - lua_pushboolean(luaVM, false); - return 1; - } - if (property == "delay") { - if (numberValue > -1){ - gif->SetFrameDelay(frame, numberValue); - success = true; - } - }else{ - m_pScriptDebugging->LogError(luaVM, "property doesn't exist for frame"); + }else{ + if (property == "showing_frame") { + if (!valIsNumber) { + m_pScriptDebugging->LogError(luaVM, "property `showing_frame` must be a number value"); + return false; } + gif->SetFrame(numberValue); + return true; }else{ - if (readFrame) { - m_pScriptDebugging->LogError(luaVM, "couldn't find frame"); - }else{ - if (property == "showing_frame"){ - if (numberValue > -1){ - gif->SetFrame(numberValue); - success = true; - } - }else{ - m_pScriptDebugging->LogError(luaVM, "property doesn't exist for gif"); - } - } + m_pScriptDebugging->LogError(luaVM, "property doens't exist for gif"); } - if (success) { - lua_pushboolean(luaVM, true); - return 1; - } - }else{ - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); } - lua_pushboolean(luaVM, false); - return 1; + return false; } -int CLuaGifDefs::GifGetProperty(lua_State* luaVM) { - CClientGif* gif = nullptr; - int frame = 0; - bool readFrame = false; - SString property; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(gif); - if (!gif){ - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM, false); - return 1; +std::variant CLuaGifDefs::GifGetProperty(lua_State* luaVM, CClientGif* gif, std::string property, std::optional frame) { + if (property.empty()) { + m_pScriptDebugging->LogError(luaVM, "property can't be empty"); + return false; } - if (argStream.NextIsNumber()){ - argStream.ReadNumber(frame, 0); - readFrame = true; - } - argStream.ReadString(property); - if (!argStream.HasErrors()){ - if (property.empty()){ - m_pScriptDebugging->LogError(luaVM, "property can't be empty"); - lua_pushboolean(luaVM, false); - return 1; + if (frame.has_value()) { + int frameCount = gif->GetFrameCount(); + if (frame > frameCount) { + m_pScriptDebugging->LogError(luaVM, "frame doesn't exist"); + return false; } - if (frame > 0){ - int frameCount = gif->GetFrameCount(); - if (frame > frameCount){ - m_pScriptDebugging->LogError(luaVM, "couldn't find frame"); - lua_pushboolean(luaVM, false); - return 1; - } - if (property == "delay"){ - lua_pushnumber(luaVM, gif->GetFrameDelay(frame)); - return 1; - }else if (property == "default_delay") { - lua_pushnumber(luaVM, gif->GetFrameDefaultDelay(frame)); - return 1; - }else{ - m_pScriptDebugging->LogError(luaVM, "property doesn't exist for frame"); - } + if (property == "delay") { + return (int)gif->GetFrameDelay(frame.value()); + }else if (property == "default_delay") { + return (int)gif->GetFrameDefaultDelay(frame.value()); }else{ - if (readFrame){ - m_pScriptDebugging->LogError(luaVM, "couldn't find frame"); - }else{ - if (property == "showing_frame"){ - lua_pushnumber(luaVM, gif->GetShowingFrame()); - return 1; - }else if (property == "frame_count"){ - lua_pushnumber(luaVM, gif->GetFrameCount()); - return 1; - }else if (property == "format"){ - lua_pushstring(luaVM, gif->GetFormat().c_str()); - return 1; - }else if (property == "tick"){ - lua_pushnumber(luaVM, gif->GetTick()); - return 1; - }else{ - m_pScriptDebugging->LogError(luaVM, "property doesn't exist for gif"); - } - } + m_pScriptDebugging->LogError(luaVM, "property doesn't exist for frame"); } }else{ - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + if (property == "showing_frame") { + return (int)gif->GetShowingFrame(); + }else if (property == "frame_count") { + return (int)gif->GetFrameCount(); + }else if (property == "format") { + return (std::string)gif->GetFormat(); + }else if (property == "tick") { + return (int)gif->GetTick(); + }else{ + m_pScriptDebugging->LogError(luaVM, "property doesn't exist for gif"); + } } - lua_pushboolean(luaVM, false); - return 1; + return false; } -int CLuaGifDefs::GifIsPlaying(lua_State* luaVM) { - CClientGif* gif = nullptr; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(gif); - if (!gif) { - m_pScriptDebugging->LogCustom(luaVM,argStream.GetFullErrorMessage()); - lua_pushboolean(luaVM,false); - return 1; - } - if (!argStream.HasErrors()) { - lua_pushboolean(luaVM, gif->IsPlaying()); - return 1; - }else{ - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - } - lua_pushboolean(luaVM,false); - return 1; +bool CLuaGifDefs::GifIsPlaying(CClientGif* gif) { + return gif->IsPlaying(); } From c46dcea2e28b4ab3c7a69bb4b74b6b41fb89c690 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Wed, 1 Mar 2023 13:08:32 +0330 Subject: [PATCH 45/53] change `pVectorItem` to `pGifItem` --- Client/core/Graphics/CRenderItemManager.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Client/core/Graphics/CRenderItemManager.cpp b/Client/core/Graphics/CRenderItemManager.cpp index bc91d9fbb8..cd38a58812 100644 --- a/Client/core/Graphics/CRenderItemManager.cpp +++ b/Client/core/Graphics/CRenderItemManager.cpp @@ -183,18 +183,18 @@ CGifItem* CRenderItemManager::CreateGif(uint width, uint height) if (!CanCreateRenderItem(CGifItem::GetClassId())) return nullptr; - CGifItem* pVectorItem = new CGifItem; - pVectorItem->PostConstruct(this, width, height); + CGifItem* pGifItem = new CGifItem; + pGifItem->PostConstruct(this, width, height); - if (!pVectorItem->IsValid()) + if (!pGifItem->IsValid()) { - SAFE_RELEASE(pVectorItem); + SAFE_RELEASE(pGifItem); return nullptr; } UpdateMemoryUsage(); - return pVectorItem; + return pGifItem; } //////////////////////////////////////////////////////////////// From 97e65e24586588a306452da7682481c9f8933e85 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Wed, 1 Mar 2023 13:11:08 +0330 Subject: [PATCH 46/53] change `p_GifItem` to `pGifItem` --- Client/mods/deathmatch/logic/CClientGif.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientGif.cpp b/Client/mods/deathmatch/logic/CClientGif.cpp index 82d13149a4..3203160fd0 100644 --- a/Client/mods/deathmatch/logic/CClientGif.cpp +++ b/Client/mods/deathmatch/logic/CClientGif.cpp @@ -14,8 +14,8 @@ #define BIGE 0 #define _SWAP(h) ((BIGE) ? ((uint16_t)(h << 8) | (h << 8)) : h) -CClientGif::CClientGif(CClientManager* pManager, ElementID ID, CGifItem* p_GifItem) - : ClassInit(this), CClientTexture(pManager, ID, p_GifItem) +CClientGif::CClientGif(CClientManager* pManager, ElementID ID, CGifItem* pGifItem) + : ClassInit(this), CClientTexture(pManager, ID, pGifItem) { SetTypeName("gif"); m_pManager = pManager; From dd6296b84c1b309146abbe833330d80aa4f06857 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Wed, 1 Mar 2023 14:10:11 +0330 Subject: [PATCH 47/53] change format --- Client/mods/deathmatch/logic/CClientGif.h | 159 ++++++++++++---------- 1 file changed, 85 insertions(+), 74 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientGif.h b/Client/mods/deathmatch/logic/CClientGif.h index 56fe801ad1..685d318ad7 100644 --- a/Client/mods/deathmatch/logic/CClientGif.h +++ b/Client/mods/deathmatch/logic/CClientGif.h @@ -11,14 +11,16 @@ #include "CClientGifDisplay.h" -enum { +enum +{ CGif_None = 0, CGif_Current = 1, CGif_Background = 2, CGif_Previous = 3 }; -class CClientGifRect { +class CClientGifRect +{ public: uint left = 0; uint top = 0; @@ -29,101 +31,110 @@ class CClientGifRect { CClientGifRect(const uint& l, const uint& t, const uint& w, const uint& h) : left(l), top(t), width(w), height(h) { valid = true; } }; -class CClientGifLoader { +class CClientGifLoader +{ public: CClientGifLoader() = default; - CClientGifLoader(SString&); - CClientGifLoader(uint8_t*,unsigned long); - CClientGifLoader(char*); - void CreateFrame(std::vector>&, std::vector&); - void Load(std::vector>&, std::vector&, long); - uint8_t* GetBuffer() { return m_pBuffer; } - long& GetWidth() { return m_bWidth; } - long& GetHeight() { return m_bHeight; } - long& GetDelay() { return m_bDelay; } - long& GetFrameNumber() { return m_bFrameNumber; } - long& GetFrameCount() { return m_bFrameCount; } - SString GetFormat() { return m_bFormat; } - bool operator!(); - - static long SkipChunk(uint8_t**, long); - static long LoadHeader(unsigned, uint8_t**, void**, unsigned, long*, long); - static long LoadFrame(uint8_t**, long*, uint8_t*, uint8_t*); + CClientGifLoader(SString& data); + CClientGifLoader(uint8_t* data, unsigned long dataSize); + CClientGifLoader(char* data); + + void CreateFrame(std::vector>& frames, std::vector& delays); + void Load(std::vector>& frames, std::vector& delays, long skip); + uint8_t* GetBuffer() { return m_pBuffer; } + long& GetWidth() { return m_lgWidth; } + long& GetHeight() { return m_lgHeight; } + long& GetDelay() { return m_lgDelay; } + long& GetFrameNumber() { return m_lgFrameNumber; } + long& GetFrameCount() { return m_uiFrameCount; } + SString GetFormat() { return m_strFormat; } + bool operator!(); + + static long SkipChunk(uint8_t** buffer, long size); + static long LoadHeader(unsigned globalFlags, uint8_t** buffer, void** pallete, unsigned state, long* size, long length); + static long LoadFrame(uint8_t** buffer, long* size, uint8_t* address, uint8_t* blen); private: - struct { + struct + { uint8_t r; uint8_t g; uint8_t b; - }* m_pPallete; - SString m_bFormat = "Undefined"; + }* m_pPallete; + SString m_strFormat = "Undefined"; uint8_t* m_pBuffer = nullptr; uint8_t* m_pAddress = nullptr; void* m_pPalleteDecoder = nullptr; void* m_pPalleteDecoderPrevious = nullptr; - long m_bSize = 0; - long m_bWidth = 0; - long m_bHeight = 0; - long m_bPalleteSize = 0; - long m_bBackground = 0; - long m_bTransparent = 0; - long m_bInterlaced = 0; - long m_bDelay = 0; - long m_bFrameNumber = 0; - long m_bFrameCount = 0; - long m_bMode = CGif_None; - unsigned long m_bLast = 0; - CClientGifRect m_bRect = {0,0,0,0}; + long m_lgSize = 0; + long m_lgWidth = 0; + long m_lgHeight = 0; + long m_lgPalleteSize = 0; + long m_lgBackground = 0; + long m_lgTransparent = 0; + long m_lgInterlaced = 0; + long m_lgDelay = 0; + long m_lgFrameNumber = 0; + long m_uiFrameCount = 0; + long m_lgMode = CGif_None; + unsigned long m_ulgLast = 0; + CClientGifRect m_rcRect = {0, 0, 0, 0}; bool m_bError = false; }; -class CClientGif final : public CClientTexture { +class CClientGif final : public CClientTexture +{ DECLARE_CLASS(CClientGif, CClientTexture); public: - CClientGif(CClientManager*, ElementID, CGifItem*); + CClientGif(CClientManager* pManager, ElementID id, CGifItem* pGifItem); ~CClientGif(); - virtual void Unlink() override; - void Register(std::vector>&&, std::vector&); + + virtual void Unlink() override; + void Register(std::vector>&& frms, std::vector& dls); + CResource* GetResource() { return m_pResource; } void SetResource(CResource* resource) { m_pResource = resource; } eClientEntityType GetType() const { return CCLIENTGIF; } CGifItem* GetRenderItem() const { return static_cast(m_pRenderItem); } CClientGifDisplay* GetDisplay() const { return m_pGifDisplay.get(); } - std::vector> GetFrames() const { return m_bFrames; } - uint GetStride() const { return m_bStride; } - uint GetShowingFrame() const { return m_bShowing; } - uint GetFrameDelay(const uint& id) const { return m_bDelays[(id < 1 ? m_bShowing : (id > GetImageCount() ? m_bShowing : id)) - 1]; } - uint GetFrameDefaultDelay(const uint& id) const { return m_bDefaultDelays[(id < 1 ? m_bShowing : (id > GetImageCount() ? m_bShowing : id)) - 1]; } - int GetImageCount() const { return m_bFrames.size(); } - double GetTick() const { return m_bTick; } - unsigned char* GetFrame() { return m_bShowing <= GetImageCount() ? m_bFrames[m_bShowing - 1].data() : nullptr; } - SString GetFormat() const { return m_bFormat; } - uint GetFrameCount() const { return m_bFrameCount; } - void SetFrameDelay(const uint& id, const uint32_t& delay) { m_bDelays[(id < 1 ? m_bShowing : (id > GetImageCount() ? (m_bShowing) : id)) - 1] = delay; } - void SetFormat(const SString& fmt) { if (!fmt.empty()) m_bFormat = fmt; } - void SetFrameCount(const uint& count) { m_bFrameCount = count; } - void SetFrame(const int& frame) { if (frame <= GetImageCount()) m_bShowing = 1; } - void UpdateTick() { m_bTick = (double)GetTickCount64_(); } - void Play() { m_bPlaying = true; } - void Stop() { m_bPlaying = false; } - void Next(); - void NavigateToThumbnail() { m_bShowing = 1; } - bool IsPlaying() const { return m_bPlaying; } - bool IsDestoryed() const { return m_bIsDestoryed; } + std::vector> GetFrames() const { return m_vecFrames; } + uint GetStride() const { return m_uiStride; } + uint GetShowingFrame() const { return m_uiShowing; } + uint GetFrameDelay(const uint& id) const { return m_vecDelays[(id < 1 ? m_uiShowing : (id > GetImageCount() ? m_uiShowing : id)) - 1]; } + uint GetFrameDefaultDelay(const uint& id) const { return m_vecDefaultDelays[(id < 1 ? m_uiShowing : (id > GetImageCount() ? m_uiShowing : id)) - 1]; } + int GetImageCount() const { return m_vecFrames.size(); } + double GetTick() const { return m_dbTick; } + unsigned char* GetFrame() { return m_uiShowing <= GetImageCount() ? m_vecFrames[m_uiShowing - 1].data() : nullptr; } + SString GetFormat() const { return m_strFormat; } + uint GetFrameCount() const { return m_uiFrameCount; } + + void SetFrameDelay(const uint& id, const uint32_t& delay) { m_vecDelays[(id < 1 ? m_uiShowing : (id > GetImageCount() ? (m_uiShowing) : id)) - 1] = delay; } + void SetFormat(const SString& fmt) { if (!fmt.empty()) m_strFormat = fmt; } + void SetFrameCount(const uint& count) { m_uiFrameCount = count; } + void SetFrame(const int& frame) { if (frame <= GetImageCount()) m_uiShowing = 1; } + + void UpdateTick() { m_dbTick = (double)GetTickCount64_(); } + void Play() { m_bPlaying = true; } + void Stop() { m_bPlaying = false; } + void Next(); + void NavigateToThumbnail() { m_uiShowing = 1; } + + bool IsPlaying() const { return m_bPlaying; } + bool IsDestoryed() const { return m_bIsDestoryed; } private: - CResource* m_pResource = nullptr; - CClientManager* m_pManager; - std::unique_ptr m_pGifDisplay; - SString m_bFormat = "Undefined"; - std::vector> m_bFrames; - std::vector m_bDefaultDelays; - std::vector m_bDelays; - uint m_bFrameCount = 0; - uint m_bStride; - uint m_bShowing = 1; - double m_bTick = 0; - bool m_bPlaying = false; - bool m_bIsDestoryed = false; + CResource* m_pResource = nullptr; + CClientManager* m_pManager; + std::unique_ptr m_pGifDisplay; + SString m_strFormat = "Undefined"; + std::vector> m_vecFrames; + std::vector m_vecDefaultDelays; + std::vector m_vecDelays; + uint m_uiFrameCount = 0; + uint m_uiStride; + uint m_uiShowing = 1; + double m_dbTick = 0; + bool m_bPlaying = false; + bool m_bIsDestoryed = false; }; From ea35b68dea140f7f54c8e8afed11cdeafe517cfe Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Wed, 1 Mar 2023 14:11:17 +0330 Subject: [PATCH 48/53] change format --- Client/mods/deathmatch/logic/CClientGif.cpp | 426 +++++++++++--------- 1 file changed, 229 insertions(+), 197 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientGif.cpp b/Client/mods/deathmatch/logic/CClientGif.cpp index 3203160fd0..5cea3f9f4d 100644 --- a/Client/mods/deathmatch/logic/CClientGif.cpp +++ b/Client/mods/deathmatch/logic/CClientGif.cpp @@ -10,145 +10,167 @@ #include "StdInc.h" #include "CClientGif.h" -#define GIF_ALLOCATE(pointer,size,release) pointer = (uint8_t*)realloc((release) ? 0 : pointer,(release) ? size : 0UL) -#define BIGE 0 -#define _SWAP(h) ((BIGE) ? ((uint16_t)(h << 8) | (h << 8)) : h) +#define GIF_ALLOCATE(pointer, size, release) pointer = (uint8_t*)realloc((release) ? 0 : pointer, (release) ? size : 0UL) +#define BIGE 0 +#define _SWAP(h) ((BIGE) ? ((uint16_t)(h << 8) | (h << 8)) : h) -CClientGif::CClientGif(CClientManager* pManager, ElementID ID, CGifItem* pGifItem) - : ClassInit(this), CClientTexture(pManager, ID, pGifItem) +CClientGif::CClientGif(CClientManager* pManager, ElementID ID, CGifItem* pGifItem) : ClassInit(this), CClientTexture(pManager, ID, pGifItem) { SetTypeName("gif"); m_pManager = pManager; - m_bStride = GetRenderItem()->m_uiSizeX * 4; + m_uiStride = GetRenderItem()->m_uiSizeX * 4; UpdateTick(); m_pGifDisplay = std::make_unique(m_pManager->GetDisplayManager(), this); } -CClientGif::~CClientGif(){ +CClientGif::~CClientGif() +{ Unlink(); } -void CClientGif::Register(std::vector>&& frms,std::vector& dls) { - m_bFrames = std::move(frms); - m_bDelays = std::move(dls); - m_bDefaultDelays = m_bDelays; +void CClientGif::Register(std::vector>&& frms, std::vector& dls) +{ + m_vecFrames = std::move(frms); + m_vecDelays = std::move(dls); + m_vecDefaultDelays = m_vecDelays; m_pGifDisplay->UpdateTexture(); } -void CClientGif::Next(){ - if (m_bShowing >= GetImageCount()) { - m_bShowing = 1; - }else{ - m_bShowing++; +void CClientGif::Next() +{ + if (m_uiShowing >= GetImageCount()) + { + m_uiShowing = 1; + } + else + { + m_uiShowing++; } } -void CClientGif::Unlink(){ - for (std::vector& frame : m_bFrames) { +void CClientGif::Unlink() +{ + for (std::vector& frame : m_vecFrames) + { frame.clear(); } - m_bFrames.clear(); - m_bDelays.clear(); - m_bDefaultDelays.clear(); + m_vecFrames.clear(); + m_vecDelays.clear(); + m_vecDefaultDelays.clear(); m_bIsDestoryed = true; CClientRenderElement::Unlink(); } -CClientGifLoader::CClientGifLoader(SString& data) { +CClientGifLoader::CClientGifLoader(SString& data) +{ m_pBuffer = reinterpret_cast(data.data()); - m_bSize = (long)((unsigned long)data.size()); + m_lgSize = (long)((unsigned long)data.size()); } -CClientGifLoader::CClientGifLoader(uint8_t* data,unsigned long dataSize) { +CClientGifLoader::CClientGifLoader(uint8_t* data, unsigned long dataSize) +{ m_pBuffer = data; - m_bSize = (long)dataSize; + m_lgSize = (long)dataSize; } -CClientGifLoader::CClientGifLoader(char* data) { +CClientGifLoader::CClientGifLoader(char* data) +{ m_pBuffer = reinterpret_cast(data); - m_bSize = (long)((unsigned long)strlen(data)); + m_lgSize = (long)((unsigned long)strlen(data)); } -void CClientGifLoader::CreateFrame(std::vector>& frames,std::vector& delays) { - long frameStride = m_bWidth*4; - long frameSize = frameStride*m_bHeight; +void CClientGifLoader::CreateFrame(std::vector>& frames, std::vector& delays) +{ + long frameStride = m_lgWidth * 4; + long frameSize = frameStride * m_lgHeight; std::vector frame; - for (long i = 0; i < frameSize; i++, frame.push_back(0)); - uint32_t x; - uint32_t y; - uint32_t yoffset; - uint32_t iterator; - uint32_t inter; - uint32_t source; - uint32_t dstSource; + for (long i = 0; i < frameSize; i++, frame.push_back(0)) + ; + uint32_t x; + uint32_t y; + uint32_t yoffset; + uint32_t iterator; + uint32_t inter; + uint32_t source; + uint32_t dstSource; uint32_t* pDecoder; uint32_t* pPrevious; - #define ARGB(i) ( \ - (m_pAddress[i] == m_bTransparent) ? \ - 0 : \ - ( \ - (uint32_t)m_pPallete[m_pAddress[i]].r << 16 | \ - (uint32_t)m_pPallete[m_pAddress[i]].g << 8 | \ - (uint32_t)m_pPallete[m_pAddress[i]].b << 0 | \ - 0xff000000 \ - ) \ - ) - if (!m_bFrameNumber) { - m_bFrameCount = ((m_bFrameCount < 0) ? -m_bFrameCount : m_bFrameCount)*m_bHeight; - m_bFrameCount = (m_bFrameCount < 0xffff) ? m_bFrameCount : 0xffff; - dstSource = (uint32_t)(m_bWidth*m_bHeight); - m_pPalleteDecoder = calloc(sizeof(uint32_t),dstSource); - m_pPalleteDecoderPrevious = calloc(sizeof(uint32_t),dstSource); +#define ARGB(i) \ + ((m_pAddress[i] == m_lgTransparent) ? 0 \ + : ((uint32_t)m_pPallete[m_pAddress[i]].r << 16 | (uint32_t)m_pPallete[m_pAddress[i]].g << 8 | \ + (uint32_t)m_pPallete[m_pAddress[i]].b << 0 | 0xff000000)) + if (!m_lgFrameNumber) + { + m_uiFrameCount = ((m_uiFrameCount < 0) ? -m_uiFrameCount : m_uiFrameCount) * m_lgHeight; + m_uiFrameCount = (m_uiFrameCount < 0xffff) ? m_uiFrameCount : 0xffff; + dstSource = (uint32_t)(m_lgWidth * m_lgHeight); + m_pPalleteDecoder = calloc(sizeof(uint32_t), dstSource); + m_pPalleteDecoderPrevious = calloc(sizeof(uint32_t), dstSource); } pDecoder = (uint32_t*)m_pPalleteDecoder; - dstSource = (uint32_t)(m_bWidth*m_bRect.top + m_bRect.left); - inter = (!(iterator = m_bInterlaced ? 0 : 4)) ? 4 : 5; - for (source = -1; iterator < inter; iterator++) { - for (yoffset = 16U >> ((iterator > 1) ? iterator : 0), y = (8 >> iterator) & 7; y < (uint32_t)m_bRect.height; y += yoffset) { - for (x = 0; x < (uint32_t)m_bRect.width; x++) { - if (m_bTransparent != (long)m_pAddress[++source]) { - pDecoder[(uint32_t)m_bWidth*y + x + dstSource] = ARGB(source); + dstSource = (uint32_t)(m_lgWidth * m_rcRect.top + m_rcRect.left); + inter = (!(iterator = m_lgInterlaced ? 0 : 4)) ? 4 : 5; + for (source = -1; iterator < inter; iterator++) + { + for (yoffset = 16U >> ((iterator > 1) ? iterator : 0), y = (8 >> iterator) & 7; y < (uint32_t)m_rcRect.height; y += yoffset) + { + for (x = 0; x < (uint32_t)m_rcRect.width; x++) + { + if (m_lgTransparent != (long)m_pAddress[++source]) + { + pDecoder[(uint32_t)m_lgWidth * y + x + dstSource] = ARGB(source); } } } } - memcpy((uint32_t*)frame.data(), pDecoder, sizeof(uint32_t)*(uint32_t)m_bWidth*(uint32_t)m_bHeight); - if ((m_bMode == CGif_Previous) && !m_bLast) { - m_bRect.width = m_bWidth; - m_bRect.height = m_bHeight; - m_bMode = CGif_Background; + memcpy((uint32_t*)frame.data(), pDecoder, sizeof(uint32_t) * (uint32_t)m_lgWidth * (uint32_t)m_lgHeight); + if ((m_lgMode == CGif_Previous) && !m_ulgLast) + { + m_rcRect.width = m_lgWidth; + m_rcRect.height = m_lgHeight; + m_lgMode = CGif_Background; dstSource = 0; - }else{ - m_bLast = (m_bMode == CGif_Previous) ? m_bLast : (unsigned long)(m_bFrameNumber + 1); - pDecoder = (uint32_t*)((m_bMode == CGif_Previous) ? m_pPalleteDecoder : m_pPalleteDecoderPrevious); - pPrevious = (uint32_t*)((m_bMode == CGif_Previous) ? m_pPalleteDecoderPrevious : m_pPalleteDecoder); - for (x = (uint32_t)(m_bWidth*m_bHeight);--x;pDecoder[x - 1] = pPrevious[x - 1]); } - if (m_bMode == CGif_Background) { - for (m_pAddress[0] = (uint8_t)((m_bTransparent >= 0) ? m_bTransparent : m_bBackground), y = 0, pDecoder = (uint32_t*)m_pPalleteDecoder; y < (uint32_t)m_bRect.height; y++) { - for (x = 0; x < (uint32_t)m_bRect.width; x++) { - pDecoder[(uint32_t)m_bWidth*y + x + dstSource] = ARGB(0); + else + { + m_ulgLast = (m_lgMode == CGif_Previous) ? m_ulgLast : (unsigned long)(m_lgFrameNumber + 1); + pDecoder = (uint32_t*)((m_lgMode == CGif_Previous) ? m_pPalleteDecoder : m_pPalleteDecoderPrevious); + pPrevious = (uint32_t*)((m_lgMode == CGif_Previous) ? m_pPalleteDecoderPrevious : m_pPalleteDecoder); + for (x = (uint32_t)(m_lgWidth * m_lgHeight); --x; pDecoder[x - 1] = pPrevious[x - 1]) + ; + } + if (m_lgMode == CGif_Background) + { + for (m_pAddress[0] = (uint8_t)((m_lgTransparent >= 0) ? m_lgTransparent : m_lgBackground), y = 0, pDecoder = (uint32_t*)m_pPalleteDecoder; + y < (uint32_t)m_rcRect.height; y++) + { + for (x = 0; x < (uint32_t)m_rcRect.width; x++) + { + pDecoder[(uint32_t)m_lgWidth * y + x + dstSource] = ARGB(0); } } } - #undef ARGB +#undef ARGB frames.push_back(std::move(frame)); - delays.push_back((int)m_bDelay); + delays.push_back((int)m_lgDelay); } -void CClientGifLoader::Load(std::vector>& frames,std::vector& delays,long skip) { - const long Blen = (1 << 12)*sizeof(uint32_t); +void CClientGifLoader::Load(std::vector>& frames, std::vector& delays, long skip) +{ + const long Blen = (1 << 12) * sizeof(uint32_t); const uint8_t extensionHeaderMark = 0x21; const uint8_t frameHeaderMark = 0x2c; const uint8_t endOfBufferMark = 0x3b; const uint8_t graphicControlMark = 0xf9; const uint8_t appMetadataMark = 0xff; - if (!m_pBuffer) { + if (!m_pBuffer) + { m_bError = true; return; } - #pragma pack(push,1) - struct GlobalHeader { +#pragma pack(push, 1) + struct GlobalHeader + { uint8_t head[6]; uint16_t width; uint16_t height; @@ -156,100 +178,90 @@ void CClientGifLoader::Load(std::vector>& frames,std: uint8_t background; uint8_t aspectRatio; }* header = (struct GlobalHeader*)m_pBuffer; - struct FrameHeader { + struct FrameHeader + { uint16_t x; uint16_t y; uint16_t width; uint16_t height; uint8_t flags; }* frameHeader; - struct GraphicControlHeader { + struct GraphicControlHeader + { uint8_t flags; uint16_t delay; uint8_t transparent; }* graphicControl = 0; - #pragma pack(pop) - long desc; - long blen; +#pragma pack(pop) + long desc; + long blen; uint8_t* decoder; - if ( // check if header is : `GIF89a` or `GIF87a` - !header || - (m_bSize <= (long)sizeof(*header)) || - (*(decoder = header->head) != 71) || - decoder[1] != 73 || - decoder[2] != 70 || - decoder[3] != 56 || - skip < 0 || - (decoder[4] != 55 && decoder[4] != 57) || - decoder[5] != 97 - ){ + if ( // check if header is : `GIF89a` or `GIF87a` + !header || (m_lgSize <= (long)sizeof(*header)) || (*(decoder = header->head) != 71) || decoder[1] != 73 || decoder[2] != 70 || decoder[3] != 56 || + skip < 0 || (decoder[4] != 55 && decoder[4] != 57) || decoder[5] != 97) + { m_bError = true; return; } - m_bFormat = decoder[4] ? "GIF87a" : "GIF89a"; + m_strFormat = decoder[4] ? "GIF87a" : "GIF89a"; decoder = (uint8_t*)(header + 1) + LoadHeader(header->flags, 0, 0, 0, 0, 0L) * 3L; - if ((m_bSize -= decoder - (uint8_t*)header) <= 0) { + if ((m_lgSize -= decoder - (uint8_t*)header) <= 0) + { m_bError = true; return; } - m_bWidth = _SWAP(header->width); - m_bHeight = _SWAP(header->height); - for ( - m_pAddress = decoder, - m_bBackground = header->background, - blen = --m_bSize; - blen >= 0 && - ((desc = *m_pAddress++) != endOfBufferMark); - blen = SkipChunk(&m_pAddress,blen) - 1 - ){ - if (desc == frameHeaderMark) { + m_lgWidth = _SWAP(header->width); + m_lgHeight = _SWAP(header->height); + for (m_pAddress = decoder, m_lgBackground = header->background, blen = --m_lgSize; blen >= 0 && ((desc = *m_pAddress++) != endOfBufferMark); + blen = SkipChunk(&m_pAddress, blen) - 1) + { + if (desc == frameHeaderMark) + { frameHeader = (struct FrameHeader*)m_pAddress; - if (LoadHeader(header->flags, &m_pAddress, (void**)&m_pPallete,frameHeader->flags,&blen,sizeof(*frameHeader)) <= 0) { + if (LoadHeader(header->flags, &m_pAddress, (void**)&m_pPallete, frameHeader->flags, &blen, sizeof(*frameHeader)) <= 0) + { break; } - m_bRect.width = _SWAP(frameHeader->width); - m_bRect.height = _SWAP(frameHeader->height); - m_bRect.left = (m_bRect.width > m_bRect.left) ? m_bRect.width : m_bRect.left; - m_bRect.top = (m_bRect.height > m_bRect.top) ? m_bRect.height : m_bRect.top; - m_bFrameNumber++; + m_rcRect.width = _SWAP(frameHeader->width); + m_rcRect.height = _SWAP(frameHeader->height); + m_rcRect.left = (m_rcRect.width > m_rcRect.left) ? m_rcRect.width : m_rcRect.left; + m_rcRect.top = (m_rcRect.height > m_rcRect.top) ? m_rcRect.height : m_rcRect.top; + m_lgFrameNumber++; } } - blen = m_bRect.left*m_bRect.top*(long)sizeof(*m_pAddress); - GIF_ALLOCATE(m_pAddress, (unsigned long)(blen + Blen + 2),1); - m_bFrameCount = (desc != endOfBufferMark) ? -m_bFrameNumber : m_bFrameNumber; - for ( - m_pAddress += Blen, - m_bFrameNumber = -1; - blen && - (skip < ((m_bFrameCount < 0) ? -m_bFrameCount : m_bFrameCount)) && m_bSize >= 0; - m_bSize = (desc != endOfBufferMark) ? ((desc != frameHeaderMark) || (skip > m_bFrameNumber)) ? SkipChunk(&decoder,m_bSize) - 1 : m_bSize - 1 : -1 - ){ - if ((desc = *decoder++) == frameHeaderMark) { // found a frame - m_bInterlaced = !!((frameHeader = (struct FrameHeader*)decoder)->flags & 0x40); + blen = m_rcRect.left * m_rcRect.top * (long)sizeof(*m_pAddress); + GIF_ALLOCATE(m_pAddress, (unsigned long)(blen + Blen + 2), 1); + m_uiFrameCount = (desc != endOfBufferMark) ? -m_lgFrameNumber : m_lgFrameNumber; + for (m_pAddress += Blen, m_lgFrameNumber = -1; blen && (skip < ((m_uiFrameCount < 0) ? -m_uiFrameCount : m_uiFrameCount)) && m_lgSize >= 0; + m_lgSize = (desc != endOfBufferMark) ? ((desc != frameHeaderMark) || (skip > m_lgFrameNumber)) ? SkipChunk(&decoder, m_lgSize) - 1 : m_lgSize - 1 : -1) + { + if ((desc = *decoder++) == frameHeaderMark) + { // found a frame + m_lgInterlaced = !!((frameHeader = (struct FrameHeader*)decoder)->flags & 0x40); *(void**)&m_pPallete = (void*)(header + 1); - m_bPalleteSize = LoadHeader(header->flags, &decoder, (void**)&m_pPallete, frameHeader->flags, &m_bSize, sizeof(*frameHeader)); - if ( - (skip <= ++m_bFrameNumber) && - ( - (m_bPalleteSize <= 0) || - LoadFrame(&decoder,&m_bSize,m_pAddress,m_pAddress + blen) < 0 - ) - ){ - m_bSize = -(m_bFrameNumber--) - 1; // failed to load frame - }else if (skip <= m_bFrameNumber) { - m_bRect.left = _SWAP(frameHeader->x); - m_bRect.top = _SWAP(frameHeader->y); - m_bRect.width = _SWAP(frameHeader->width); - m_bRect.height = _SWAP(frameHeader->height); - m_bDelay = (graphicControl) ? _SWAP(graphicControl->delay) : 0; - m_bTransparent = (graphicControl && (graphicControl->flags & 0x01)) ? graphicControl->transparent : -1; - m_bDelay = ((graphicControl && (graphicControl->flags & 0x02)) ? -m_bDelay - 1 : m_bDelay)*10; - m_bMode = (graphicControl && !(graphicControl->flags & 0x10)) ? (graphicControl->flags & 0x0c) >> 2 : CGif_None; + m_lgPalleteSize = LoadHeader(header->flags, &decoder, (void**)&m_pPallete, frameHeader->flags, &m_lgSize, sizeof(*frameHeader)); + if ((skip <= ++m_lgFrameNumber) && ((m_lgPalleteSize <= 0) || LoadFrame(&decoder, &m_lgSize, m_pAddress, m_pAddress + blen) < 0)) + { + m_lgSize = -(m_lgFrameNumber--) - 1; // failed to load frame + } + else if (skip <= m_lgFrameNumber) + { + m_rcRect.left = _SWAP(frameHeader->x); + m_rcRect.top = _SWAP(frameHeader->y); + m_rcRect.width = _SWAP(frameHeader->width); + m_rcRect.height = _SWAP(frameHeader->height); + m_lgDelay = (graphicControl) ? _SWAP(graphicControl->delay) : 0; + m_lgTransparent = (graphicControl && (graphicControl->flags & 0x01)) ? graphicControl->transparent : -1; + m_lgDelay = ((graphicControl && (graphicControl->flags & 0x02)) ? -m_lgDelay - 1 : m_lgDelay) * 10; + m_lgMode = (graphicControl && !(graphicControl->flags & 0x10)) ? (graphicControl->flags & 0x0c) >> 2 : CGif_None; graphicControl = 0; - CreateFrame(frames,delays); // creating frame plain + CreateFrame(frames, delays); // creating frame plain } - }else if (desc == extensionHeaderMark){ // found an extension - if (*decoder == graphicControlMark) { + } + else if (desc == extensionHeaderMark) + { // found an extension + if (*decoder == graphicControlMark) + { graphicControl = (struct GraphicControlHeader*)(decoder + 1 + 1); } } @@ -258,90 +270,110 @@ void CClientGifLoader::Load(std::vector>& frames,std: GIF_ALLOCATE(m_pAddress, (unsigned long)(blen + Blen + 2), 0); } -bool CClientGifLoader::operator!() { +bool CClientGifLoader::operator!() +{ return m_pBuffer ? m_bError : false; } -long CClientGifLoader::SkipChunk(uint8_t** buffer, long size){ +long CClientGifLoader::SkipChunk(uint8_t** buffer, long size) +{ long skip; - for (skip = 2, ++size, ++(*buffer); ((size -= skip) > 0) && (skip > 1);*buffer += (skip = 1 + **buffer)); + for (skip = 2, ++size, ++(*buffer); ((size -= skip) > 0) && (skip > 1); *buffer += (skip = 1 + **buffer)) + ; return size; } -long CClientGifLoader::LoadHeader(unsigned globalFlags, uint8_t** buffer, void** pallete, unsigned state, long* size, long length) { - if (length && (!(*buffer += length) || ((*size -= length) <= 0))){ +long CClientGifLoader::LoadHeader(unsigned globalFlags, uint8_t** buffer, void** pallete, unsigned state, long* size, long length) +{ + if (length && (!(*buffer += length) || ((*size -= length) <= 0))) + { return -2; } - if (length && (state & 0x80)) { + if (length && (state & 0x80)) + { *pallete = *buffer; - *buffer += (length = 2 << (state & 7))*3L; + *buffer += (length = 2 << (state & 7)) * 3L; return ((*size -= length * 3L) > 0) ? length : -1; } return (globalFlags & 0x80) ? (2 << (globalFlags & 7)) : 0; } -long CClientGifLoader::LoadFrame(uint8_t** buffer, long* size, uint8_t* address, uint8_t* blen){ +long CClientGifLoader::LoadFrame(uint8_t** buffer, long* size, uint8_t* address, uint8_t* blen) +{ const long headerLength = sizeof(uint16_t); const long tableLength = 1 << 12; - uint16_t accumulator; - uint16_t mask; - long lastCodeTable; - long iterator; - long previous; - long current; - long minLZWSize; - long currentLZWSize; - long blockSequense; - long bitSize; - uint32_t* code = (uint32_t*)address - tableLength; - if ((--(*size) <= headerLength) || !*++(*buffer)){ + uint16_t accumulator; + uint16_t mask; + long lastCodeTable; + long iterator; + long previous; + long current; + long minLZWSize; + long currentLZWSize; + long blockSequense; + long bitSize; + uint32_t* code = (uint32_t*)address - tableLength; + if ((--(*size) <= headerLength) || !*++(*buffer)) + { return -4; } mask = (uint16_t)((1 << (currentLZWSize = (minLZWSize = *(*buffer - 1)) + 1)) - 1); - if (minLZWSize < 2 || minLZWSize > 8) { + if (minLZWSize < 2 || minLZWSize > 8) + { return -3; } - if ((lastCodeTable = (1L << minLZWSize)) != (mask & _SWAP(*(uint16_t*)(*buffer + 1)))) { + if ((lastCodeTable = (1L << minLZWSize)) != (mask & _SWAP(*(uint16_t*)(*buffer + 1)))) + { return -2; } - for (current = ++lastCodeTable; current; code[--current] = 0); - for (--(*size), bitSize = -currentLZWSize, previous = current = 0; ((*size -= (blockSequense = *(*buffer)++) + 1) >= 0) && blockSequense; *buffer += blockSequense) { - for (; blockSequense > 0; blockSequense -= headerLength, *buffer += headerLength) { - for ( - accumulator = (uint16_t)(_SWAP(*(uint16_t*)*buffer) & ((blockSequense < headerLength) ? ((1U << (8 * blockSequense)) - 1U) : ~0U)), - current |= accumulator << (currentLZWSize + bitSize), - accumulator = (uint16_t)(accumulator >> -bitSize), + for (current = ++lastCodeTable; current; code[--current] = 0) + ; + for (--(*size), bitSize = -currentLZWSize, previous = current = 0; ((*size -= (blockSequense = *(*buffer)++) + 1) >= 0) && blockSequense; + *buffer += blockSequense) + { + for (; blockSequense > 0; blockSequense -= headerLength, *buffer += headerLength) + { + for (accumulator = (uint16_t)(_SWAP(*(uint16_t*)*buffer) & ((blockSequense < headerLength) ? ((1U << (8 * blockSequense)) - 1U) : ~0U)), + current |= accumulator << (currentLZWSize + bitSize), accumulator = (uint16_t)(accumulator >> -bitSize), bitSize += 8 * ((blockSequense < headerLength) ? blockSequense : headerLength); - bitSize >= 0; - bitSize -= currentLZWSize, - previous = current, - current = accumulator, - accumulator = (uint16_t)(accumulator >> currentLZWSize) - ){ - if (((current &= mask) & ~1L) == (1L << minLZWSize)) { - if (~(lastCodeTable = current + 1) & 1){ // end of frame data + bitSize >= 0; bitSize -= currentLZWSize, previous = current, current = accumulator, accumulator = (uint16_t)(accumulator >> currentLZWSize)) + { + if (((current &= mask) & ~1L) == (1L << minLZWSize)) + { + if (~(lastCodeTable = current + 1) & 1) + { // end of frame data return (*((*buffer += blockSequense + 1) - 1)) ? -1 : 1; } mask = (uint16_t)((1 << (currentLZWSize = minLZWSize + 1)) - 1); - }else{ - if (lastCodeTable < tableLength){ - if ((lastCodeTable == mask) && (lastCodeTable < tableLength - 1)) { + } + else + { + if (lastCodeTable < tableLength) + { + if ((lastCodeTable == mask) && (lastCodeTable < tableLength - 1)) + { mask = (uint16_t)(mask + mask + 1); currentLZWSize++; } code[lastCodeTable] = (uint32_t)previous + (code[previous] & 0xfff000); } previous = (long)code[iterator = (lastCodeTable > current) ? current : previous]; - if ((address += (previous = (previous >> 12) & 0xfff)) > blen) { + if ((address += (previous = (previous >> 12) & 0xfff)) > blen) + { continue; } - for (previous++; (iterator &= 0xfff) >> minLZWSize; *address-- = (uint8_t)((iterator = (long)code[iterator]) >> 24)); + for (previous++; (iterator &= 0xfff) >> minLZWSize; *address-- = (uint8_t)((iterator = (long)code[iterator]) >> 24)) + ; (address += previous)[-previous] = (uint8_t)iterator; - if (lastCodeTable < tableLength) { - if (lastCodeTable == current) { + if (lastCodeTable < tableLength) + { + if (lastCodeTable == current) + { *address++ = (uint8_t)iterator; - }else if (lastCodeTable < current){ - return -5; // wrong code + } + else if (lastCodeTable < current) + { + return -5; // wrong code } code[lastCodeTable++] += ((uint32_t)iterator << 24) + 0x1000; } @@ -349,7 +381,7 @@ long CClientGifLoader::LoadFrame(uint8_t** buffer, long* size, uint8_t* address, } } } - return (++(*size) >= 0) ? 0 : -4; // recoverable error + return (++(*size) >= 0) ? 0 : -4; // recoverable error } #undef _SWAP From 07331b969b72f6539d9338cd08fab262869c46c2 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Wed, 1 Mar 2023 14:14:54 +0330 Subject: [PATCH 49/53] change format --- Client/mods/deathmatch/logic/CClientGifDisplay.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientGifDisplay.h b/Client/mods/deathmatch/logic/CClientGifDisplay.h index ea2c3e6975..2f7b6f22a2 100644 --- a/Client/mods/deathmatch/logic/CClientGifDisplay.h +++ b/Client/mods/deathmatch/logic/CClientGifDisplay.h @@ -19,7 +19,7 @@ class CClientGifDisplay final : public CClientDisplay friend class CClientDisplayManager; public: - CClientGifDisplay(CClientDisplayManager*, CClientGif*, int ID = DISPLAY_GIF); + CClientGifDisplay(CClientDisplayManager* pDisplayManager, CClientGif* pGif, int ID = DISPLAY_GIF); ~CClientGifDisplay() = default; eDisplayType GetType() { return DISPLAY_GIF; } void Render(); @@ -28,6 +28,6 @@ class CClientGifDisplay final : public CClientDisplay bool IsCleared() { return m_bIsCleared; } private: - CClientGif* m_pGif; - bool m_bIsCleared; + CClientGif* m_pGif; + bool m_bIsCleared; }; From a372ff5dab7347cb3778c9f025ad917acbfc58ad Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Wed, 1 Mar 2023 14:15:20 +0330 Subject: [PATCH 50/53] change format --- .../deathmatch/logic/CClientGifDisplay.cpp | 60 ++++++++++++------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientGifDisplay.cpp b/Client/mods/deathmatch/logic/CClientGifDisplay.cpp index 78f9fd36a4..de92a91c36 100644 --- a/Client/mods/deathmatch/logic/CClientGifDisplay.cpp +++ b/Client/mods/deathmatch/logic/CClientGifDisplay.cpp @@ -11,28 +11,35 @@ #include "CClientGifDisplay.h" #include "CClientGif.h" -CClientGifDisplay::CClientGifDisplay(CClientDisplayManager* pDisplayManager, CClientGif* pGif, int ID) - : CClientDisplay(pDisplayManager, ID) +CClientGifDisplay::CClientGifDisplay(CClientDisplayManager* pDisplayManager, CClientGif* pGif, int ID) : CClientDisplay(pDisplayManager, ID) { m_pGif = pGif; m_bVisible = true; m_bIsCleared = false; } -void CClientGifDisplay::Render(){ - if (!m_pGif || m_pGif->IsDestoryed()){ +void CClientGifDisplay::Render() +{ + if (!m_pGif || m_pGif->IsDestoryed()) + { return; } - if (!m_bVisible){ - if (!IsCleared()){ + if (!m_bVisible) + { + if (!IsCleared()) + { ClearTexture(); } return; - }else if (IsCleared()){ + } + else if (IsCleared()) + { m_bIsCleared = false; } - if (m_pGif->IsPlaying()) { - if ((double)GetTickCount64_() >= m_pGif->GetTick() + m_pGif->GetFrameDelay(-1)) { + if (m_pGif->IsPlaying()) + { + if ((double)GetTickCount64_() >= m_pGif->GetTick() + m_pGif->GetFrameDelay(-1)) + { m_pGif->Next(); m_pGif->UpdateTick(); UpdateTexture(); @@ -40,30 +47,37 @@ void CClientGifDisplay::Render(){ } } -void CClientGifDisplay::UpdateTexture(){ - if (!m_pGif || m_pGif->IsDestoryed()){ +void CClientGifDisplay::UpdateTexture() +{ + if (!m_pGif || m_pGif->IsDestoryed()) + { return; } CGifItem* pGifItem = m_pGif->GetRenderItem(); - if (!pGifItem){ + if (!pGifItem) + { return; } IDirect3DSurface9* surface = pGifItem->m_pD3DRenderTargetSurface; - if (!surface){ + if (!surface) + { return; } IDirect3DDevice9* device = pGifItem->m_pDevice; // Lock Surface D3DLOCKED_RECT LockedRect; - if (SUCCEEDED(surface->LockRect(&LockedRect, nullptr, D3DLOCK_DISCARD))) { + if (SUCCEEDED(surface->LockRect(&LockedRect, nullptr, D3DLOCK_DISCARD))) + { // Unlock Surface unsigned char* frame = m_pGif->GetFrame(); - if (frame){ + if (frame) + { uint stride = m_pGif->GetStride(); auto surfaceData = static_cast(LockedRect.pBits); auto data = static_cast(frame); - for (int i = 0; i < pGifItem->m_uiSizeY; i++) { - memcpy(surfaceData,data,stride); + for (int i = 0; i < pGifItem->m_uiSizeY; i++) + { + memcpy(surfaceData, data, stride); data += stride; surfaceData += LockedRect.Pitch; } @@ -72,16 +86,20 @@ void CClientGifDisplay::UpdateTexture(){ } } -void CClientGifDisplay::ClearTexture(){ - if (!m_pGif || m_pGif->IsDestoryed()){ +void CClientGifDisplay::ClearTexture() +{ + if (!m_pGif || m_pGif->IsDestoryed()) + { return; } CGifItem* pGif = m_pGif->GetRenderItem(); - if (!pGif){ + if (!pGif) + { return; } IDirect3DSurface9* surface = pGif->m_pD3DRenderTargetSurface; - if (!surface){ + if (!surface) + { return; } IDirect3DDevice9* device = pGif->m_pDevice; From ced64740f35608134c2efcefe516dde42638a021 Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Wed, 1 Mar 2023 14:18:00 +0330 Subject: [PATCH 51/53] change format --- Client/mods/deathmatch/logic/CClientRenderElementManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/mods/deathmatch/logic/CClientRenderElementManager.h b/Client/mods/deathmatch/logic/CClientRenderElementManager.h index 708b45e377..6208fdf9ef 100644 --- a/Client/mods/deathmatch/logic/CClientRenderElementManager.h +++ b/Client/mods/deathmatch/logic/CClientRenderElementManager.h @@ -37,7 +37,7 @@ class CClientRenderElementManager CClientScreenSource* CreateScreenSource(uint uiSizeX, uint uiSizeY); CClientWebBrowser* CreateWebBrowser(uint uiSizeX, uint uiSizeY, bool bIsLocal, bool bTransparent); CClientVectorGraphic* CreateVectorGraphic(uint width, uint height); - CClientGif* CreateGif(uint width,uint height); + CClientGif* CreateGif(uint width, uint height); CClientTexture* FindAutoTexture(const SString& strFullFilePath, const SString& strUniqueName); void Remove(CClientRenderElement* pElement); From f5752a38cadce144c5d3ea07fe3183377858a99d Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Wed, 1 Mar 2023 14:31:38 +0330 Subject: [PATCH 52/53] change format --- .../deathmatch/logic/luadefs/CLuaGifDefs.h | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h index 3ef707f7c7..e520796fca 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.h @@ -15,12 +15,15 @@ class CLuaGifDefs : public CLuaDefs { public: - static void LoadFunctions(); - static void AddClass(lua_State*); - static CClientGif* GifCreate(lua_State*, std::string); - static bool GifPlay(CClientGif*); - static bool GifStop(CClientGif*); - static bool GifSetProperty(lua_State*, CClientGif*, std::string, std::variant, std::optional); - static std::variant GifGetProperty(lua_State*, CClientGif*, std::string, std::optional); - static bool GifIsPlaying(CClientGif*); + static void LoadFunctions(); + static void AddClass(lua_State* luaVM); + + static CClientGif* GifCreate(lua_State* luaVM, std::string pathOrRawdata); + static bool GifPlay(CClientGif* gif); + static bool GifStop(CClientGif* gif); + + static bool GifSetProperty(lua_State* luaVM, CClientGif* gif, std::string property, std::variant value, std::optional frame); + static std::variant GifGetProperty(lua_State* luaVM, CClientGif* gif, std::string property, std::optional frame); + + static bool GifIsPlaying(CClientGif* gif); }; From f8ca3b7798a5202fd11a103f9b3594bdec173d1b Mon Sep 17 00:00:00 2001 From: Mobin <99535731+MobinYengejehi@users.noreply.github.com> Date: Wed, 1 Mar 2023 14:32:18 +0330 Subject: [PATCH 53/53] change format --- .../deathmatch/logic/luadefs/CLuaGifDefs.cpp | 160 ++++++++++++------ 1 file changed, 111 insertions(+), 49 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp index 8f7a9bb912..158bf974cd 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaGifDefs.cpp @@ -16,7 +16,8 @@ #define DEFAULT_MAX_FILESIZE 52428800 #endif -void CLuaGifDefs::LoadFunctions(){ +void CLuaGifDefs::LoadFunctions() +{ constexpr static const std::pair functions[]{ {"gifCreate", ArgumentParser}, {"gifPlay", ArgumentParser}, @@ -29,7 +30,8 @@ void CLuaGifDefs::LoadFunctions(){ CLuaCFunctions::AddFunction(name, func); } -void CLuaGifDefs::AddClass(lua_State* luaVM){ +void CLuaGifDefs::AddClass(lua_State* luaVM) +{ lua_newclass(luaVM); lua_classfunction(luaVM, "play", "gifPlay"); lua_classfunction(luaVM, "stop", "gifStop"); @@ -39,7 +41,8 @@ void CLuaGifDefs::AddClass(lua_State* luaVM){ lua_registerclass(luaVM, "Gif"); } -CClientGif* CLuaGifDefs::GifCreate(lua_State* luaVM, std::string pathOrRawdata) { +CClientGif* CLuaGifDefs::GifCreate(lua_State* luaVM, std::string pathOrRawdata) +{ SString buffer = pathOrRawdata; CLuaMain& luaMain = lua_getownercluamain(luaVM); CResource* resource = luaMain.GetResource(); @@ -49,56 +52,76 @@ CClientGif* CLuaGifDefs::GifCreate(lua_State* luaVM, std::string pathOrRawdata) SString lastPath = buffer; SString format = buffer.substr(0, 6); CClientGifLoader loader; - if (format == "GIF87a" || format == "GIF89a"){ - loader = CClientGifLoader(buffer); - }else if (CResourceManager::ParseResourcePathInput(buffer, resource, &path, &metaPath)){ - if (FileExists(path)){ + if (format == "GIF87a" || format == "GIF89a") + { + loader = CClientGifLoader(buffer); + } + else if (CResourceManager::ParseResourcePathInput(buffer, resource, &path, &metaPath)) + { + if (FileExists(path)) + { eAccessType access = buffer[0] == '@' ? eAccessType::ACCESS_PRIVATE : eAccessType::ACCESS_PUBLIC; CScriptFile* file = new CScriptFile(resource->GetScriptID(), metaPath, DEFAULT_MAX_FILESIZE, access); - if (file->Load(resource, CScriptFile::MODE_READ)){ + if (file->Load(resource, CScriptFile::MODE_READ)) + { file->SetLuaDebugInfo(g_pClientGame->GetScriptDebugging()->GetLuaDebugInfo(luaVM)); long size = file->GetSize(); long bytesRead = file->Read(size, fileBuffer); - if (bytesRead >= 0){ + if (bytesRead >= 0) + { loader = CClientGifLoader(fileBuffer); - }else if (bytesRead == -2){ + } + else if (bytesRead == -2) + { m_pScriptDebugging->LogWarning(luaVM, "out of memory"); - }else{ + } + else + { m_pScriptDebugging->LogError(luaVM, SString("error while reading file [%s]", lastPath.c_str()).c_str()); } file->Unload(); m_pElementDeleter->Delete(file); - }else{ + } + else + { delete file; m_pScriptDebugging->LogError(luaVM, SString("couldn't load file [%s]", lastPath.c_str()).c_str()); return nullptr; } - }else{ + } + else + { m_pScriptDebugging->LogError(luaVM, SString("file [%s] doesn't exists!", lastPath.c_str()).c_str()); return nullptr; } - }else{ + } + else + { loader = CClientGifLoader(buffer); } std::vector> frames; std::vector delays; loader.Load(frames, delays, 0L); - if (!loader){ + if (!loader) + { m_pScriptDebugging->LogError(luaVM, "wrong file format"); return nullptr; } - if (frames.size() < 1){ + if (frames.size() < 1) + { m_pScriptDebugging->LogError(luaVM, "gif has no frames"); return nullptr; } uint width = (uint)loader.GetWidth(); uint height = (uint)loader.GetHeight(); - if (width < 1 || height < 1){ + if (width < 1 || height < 1) + { m_pScriptDebugging->LogError(luaVM, "gif must be 1x1 at least"); return nullptr; } CClientGif* gif = g_pClientGame->GetManager()->GetRenderElementManager()->CreateGif(width, height); - if (!gif){ + if (!gif) + { m_pScriptDebugging->LogError(luaVM, "error while creating gif"); return nullptr; } @@ -110,96 +133,135 @@ CClientGif* CLuaGifDefs::GifCreate(lua_State* luaVM, std::string pathOrRawdata) return gif; } -bool CLuaGifDefs::GifPlay(CClientGif* gif) { +bool CLuaGifDefs::GifPlay(CClientGif* gif) +{ gif->Play(); return true; } -bool CLuaGifDefs::GifStop(CClientGif* gif) { +bool CLuaGifDefs::GifStop(CClientGif* gif) +{ gif->Stop(); return true; } -bool CLuaGifDefs::GifSetProperty(lua_State* luaVM,CClientGif* gif, std::string property, std::variant value, std::optional frame) { +bool CLuaGifDefs::GifSetProperty(lua_State* luaVM, CClientGif* gif, std::string property, std::variant value, std::optional frame) +{ bool valIsNumber = false; - int numberValue = -1; - if (std::holds_alternative(value)) { + int numberValue = -1; + if (std::holds_alternative(value)) + { valIsNumber = true; numberValue = std::get(value); - if (numberValue < 0) { + if (numberValue < 0) + { m_pScriptDebugging->LogError(luaVM, "property value can't be a negative number"); return false; } } - if (property.empty()) { - m_pScriptDebugging->LogError(luaVM ,"property can't be empty"); + if (property.empty()) + { + m_pScriptDebugging->LogError(luaVM, "property can't be empty"); return false; } - if (frame.has_value()) { + if (frame.has_value()) + { int frameCount = gif->GetFrameCount(); - if (frame > frameCount) { + if (frame > frameCount) + { m_pScriptDebugging->LogError(luaVM, "frame doesn't exist"); return false; } - if (property == "delay") { - if (!valIsNumber) { + if (property == "delay") + { + if (!valIsNumber) + { m_pScriptDebugging->LogError(luaVM, "property `delay` must be a number value"); return false; } gif->SetFrameDelay(frame.value(), numberValue); return true; - }else{ + } + else + { m_pScriptDebugging->LogError(luaVM, "property doesn't exist for frame"); } - }else{ - if (property == "showing_frame") { - if (!valIsNumber) { + } + else + { + if (property == "showing_frame") + { + if (!valIsNumber) + { m_pScriptDebugging->LogError(luaVM, "property `showing_frame` must be a number value"); return false; } gif->SetFrame(numberValue); return true; - }else{ + } + else + { m_pScriptDebugging->LogError(luaVM, "property doens't exist for gif"); } } return false; } -std::variant CLuaGifDefs::GifGetProperty(lua_State* luaVM, CClientGif* gif, std::string property, std::optional frame) { - if (property.empty()) { +std::variant CLuaGifDefs::GifGetProperty(lua_State* luaVM, CClientGif* gif, std::string property, std::optional frame) +{ + if (property.empty()) + { m_pScriptDebugging->LogError(luaVM, "property can't be empty"); return false; } - if (frame.has_value()) { + if (frame.has_value()) + { int frameCount = gif->GetFrameCount(); - if (frame > frameCount) { + if (frame > frameCount) + { m_pScriptDebugging->LogError(luaVM, "frame doesn't exist"); return false; } - if (property == "delay") { + if (property == "delay") + { return (int)gif->GetFrameDelay(frame.value()); - }else if (property == "default_delay") { + } + else if (property == "default_delay") + { return (int)gif->GetFrameDefaultDelay(frame.value()); - }else{ + } + else + { m_pScriptDebugging->LogError(luaVM, "property doesn't exist for frame"); } - }else{ - if (property == "showing_frame") { + } + else + { + if (property == "showing_frame") + { return (int)gif->GetShowingFrame(); - }else if (property == "frame_count") { + } + else if (property == "frame_count") + { return (int)gif->GetFrameCount(); - }else if (property == "format") { + } + else if (property == "format") + { return (std::string)gif->GetFormat(); - }else if (property == "tick") { + } + else if (property == "tick") + { return (int)gif->GetTick(); - }else{ + } + else + { m_pScriptDebugging->LogError(luaVM, "property doesn't exist for gif"); } } return false; } -bool CLuaGifDefs::GifIsPlaying(CClientGif* gif) { +bool CLuaGifDefs::GifIsPlaying(CClientGif* gif) +{ return gif->IsPlaying(); }