diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f0031d4e7..ea6eb8d27 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -49,6 +49,9 @@ else() # Always generate debug information add_compile_options(-g) add_link_options(-g) + + # Add _DEBUG flag + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG") endif() # this is crucial to include libs first diff --git a/src/apps/engine/rsrc/icon1.ico b/src/apps/engine/rsrc/icon1.ico index 359173d65..16db83812 100644 Binary files a/src/apps/engine/rsrc/icon1.ico and b/src/apps/engine/rsrc/icon1.ico differ diff --git a/src/apps/engine/src/main.cpp b/src/apps/engine/src/main.cpp index aff05a5d6..e085d2362 100644 --- a/src/apps/engine/src/main.cpp +++ b/src/apps/engine/src/main.cpp @@ -210,7 +210,7 @@ int main(int argc, char *argv[]) std::shared_ptr window = storm::OSWindow::Create(width, height, preferred_display, fullscreen, show_borders); - window->SetTitle("Sea Dogs"); + window->SetTitle("Caribbean Legend"); window->Subscribe(HandleWindowEvent); window->Show(); core_private->SetWindow(window); diff --git a/src/libs/battle_interface/include/utils.h b/src/libs/battle_interface/include/bi_utils.h similarity index 93% rename from src/libs/battle_interface/include/utils.h rename to src/libs/battle_interface/include/bi_utils.h index 5ece935e2..602c07800 100644 --- a/src/libs/battle_interface/include/utils.h +++ b/src/libs/battle_interface/include/bi_utils.h @@ -24,6 +24,7 @@ class BITextInfo final float fScale; int32_t nFont; uint32_t dwColor; + int32_t nAlign; bool bShadow; ATTRIBUTES *pARefresh; @@ -91,8 +92,8 @@ class BIUtils static bool ReadStringFromAttr(ATTRIBUTES *pA, const char *name, char *buf, int32_t bufSize, const char *defVal); static const char *GetStringFromAttr(ATTRIBUTES *pA, const char *name, const char *defVal); static int32_t GetTextureFromAttr(VDX9RENDER *rs, ATTRIBUTES *pA, const char *sAttrName); - static bool ReadRectFromAttr(ATTRIBUTES *pA, const std::string_view &name, FRECT &rOut, FRECT &rDefault); - static bool ReadRectFromAttr(ATTRIBUTES *pA, const std::string_view &name, RECT &rOut, RECT &rDefault); + static bool ReadRectFromAttr(ATTRIBUTES *pA, const char *name, FRECT &rOut, FRECT &rDefault); + static bool ReadRectFromAttr(ATTRIBUTES *pA, const char *name, RECT &rOut, RECT &rDefault); static bool ReadPosFromAttr(ATTRIBUTES *pA, const char *name, float &fX, float &fY, float fXDef, float fYDef); static bool ReadPosFromAttr(ATTRIBUTES *pA, const char *name, int32_t &nX, int32_t &nY, int32_t nXDef, int32_t nYDef); static int32_t GetAlignmentFromAttr(ATTRIBUTES *pA, const char *name, int32_t nDefAlign); @@ -107,7 +108,7 @@ class BIUtils static bool GetIntervalRect(float fk, const FRECT &r1, const FRECT &r2, FRECT &rOut); static int32_t GetMaxFromFourLong(int32_t n1, int32_t n2, int32_t n3, int32_t n4); - + static float GetFromStr_Float(const char *&pcStr, float fDefault); static void FillTextInfoArray(VDX9RENDER *pRS, ATTRIBUTES *pA, std::vector &tia); diff --git a/src/libs/battle_interface/include/log_and_action.h b/src/libs/battle_interface/include/log_and_action.h deleted file mode 100644 index aa6aa5c7f..000000000 --- a/src/libs/battle_interface/include/log_and_action.h +++ /dev/null @@ -1,91 +0,0 @@ -#pragma once - -#include "utils.h" - -class ILogAndActions : public Entity -{ - VDX9RENDER *rs; - - struct STRING_DESCR - { - char *str; - float offset; - float alpha; - STRING_DESCR *next; - }; - - public: - ILogAndActions(ILogAndActions &&) = delete; - ILogAndActions(const ILogAndActions &) = delete; - ILogAndActions(); - ~ILogAndActions() override; - bool Init() override; - void Execute(uint32_t delta_time); - void Realize(uint32_t delta_time); - uint64_t ProcessMessage(MESSAGE &message) override; - - void ProcessStage(Stage stage, uint32_t delta) override - { - switch (stage) - { - case Stage::execute: - Execute(delta); - break; - case Stage::realize: - Realize(delta); - break; - /*case Stage::lost_render: - LostRender(delta); break; - case Stage::restore_render: - RestoreRender(delta); break;*/ - } - } - - protected: - void Create(bool bFastComShow, bool bLogStringShow); - void ActionChange(bool bFastComShow, bool bLogStringShow); - void Release(); - - void SetString(const char *str, bool immortal); - void SetAction(const char *actionName); - - protected: - // log stings parameters - // ----------------------- - int32_t m_nWindowWidth; // X window size - int32_t m_nWindowHeight; // Y window size - int32_t m_nWindowLeft; - int32_t m_nWindowRight; - int32_t m_nWindowUp; - int32_t m_fontID; - float m_fFontScale; - uint32_t m_dwColor; - int32_t m_nStringBegin; - int32_t m_nStringOffset; - float m_fShiftSpeed; - float m_fBlendSpeed; - STRING_DESCR *m_sRoot; - - // Action parameters - //------------------- - bool m_bThatRealAction; - int32_t m_nIconWidth; // X icon size - int32_t m_nIconHeight; // Y icon size - int32_t m_nIconLeft; - int32_t m_nIconUp; - int32_t m_idIconTexture; - int32_t m_horzDiv; - int32_t m_vertDiv; - BI_ONETEXTURE_VERTEX m_IconVertex[4]; - char m_sActionName[64]; - char m_sOldActionName[64]; - - bool m_bShowActiveCommand; - bool m_bShowLogStrings; - bool m_bDontShowAll; - - int32_t m_nTimeCounter; - - BITextInfo m_ActionHint1; - BITextInfo m_ActionHint2; -}; diff --git a/src/libs/battle_interface/include/active_perk_shower.h b/src/libs/battle_interface/src/active_perk_shower.h similarity index 100% rename from src/libs/battle_interface/include/active_perk_shower.h rename to src/libs/battle_interface/src/active_perk_shower.h diff --git a/src/libs/battle_interface/src/battle_command.cpp b/src/libs/battle_interface/src/battle_command.cpp index fec9be056..b7998550f 100644 --- a/src/libs/battle_interface/src/battle_command.cpp +++ b/src/libs/battle_interface/src/battle_command.cpp @@ -1,5 +1,5 @@ #include "battle_command.h" -#include "utils.h" +#include "bi_utils.h" #include "core.h" #include "image/img_render.h" #include "sea/ships_list.h" @@ -22,7 +22,7 @@ BICommandList::BICommandList(entid_t eid, ATTRIBUTES *pA, VDX9RENDER *rs) m_NotePos.x = m_NotePos.y = 0; m_NoteOffset.x = m_NoteOffset.y = 0; - m_bUpArrow = m_bDownArrow = false; + m_bUpArrow = m_bDownArrow = m_bLeftArrow = m_bRightArrow = false; m_bActive = false; @@ -63,6 +63,13 @@ void BICommandList::Draw() void BICommandList::Update(int32_t nTopLine, int32_t nCharacterIndex, int32_t nCommandMode) { + + if (m_nCurrentCommandMode != nCommandMode) + { + m_nStartUsedCommandIndex = 0; + m_nSelectedCommandIndex = 0; + } + int32_t nOldSelIndex = 0; if (nTopLine == m_LeftTopPoint.y && nCharacterIndex == m_nCurrentCommandCharacterIndex && m_nCurrentCommandMode == nCommandMode) @@ -74,8 +81,6 @@ void BICommandList::Update(int32_t nTopLine, int32_t nCharacterIndex, int32_t nC m_nCurrentCommandCharacterIndex = nCharacterIndex; m_nCurrentCommandMode = nCommandMode; - m_nStartUsedCommandIndex = 0; - m_nSelectedCommandIndex = 0; m_aUsedCommand.clear(); m_aCooldownUpdate.clear(); @@ -224,9 +229,21 @@ void BICommandList::Init() FULLRECT(m_frDownArrowUV); m_pntUpArrowOffset.x = 32; m_pntUpArrowOffset.y = -34; + + m_pntDownArrowOffset0.x = 32; + m_pntDownArrowOffset0.y = 66; m_pntDownArrowOffset.x = 32; m_pntDownArrowOffset.y = 66; + m_sLeftRightArrowTexture = ""; + m_pntLeftRightArrowSize.x = m_pntLeftRightArrowSize.y = 0; + FULLRECT(m_frLeftArrowUV); + FULLRECT(m_frRightArrowUV); + m_pntLeftArrowOffset.x = 0; + m_pntLeftArrowOffset.y = 0; + m_pntRightArrowOffset.x = 0; + m_pntRightArrowOffset.y = 0; + // default data for active icon m_sActiveIconTexture = ""; m_pntActiveIconOffset.x = -33; @@ -266,8 +283,21 @@ void BICommandList::Init() m_pntUpDownArrowSize.x, m_pntUpDownArrowSize.y); BIUtils::ReadPosFromAttr(pAList, "UDArrow_Offset_Up", m_pntUpArrowOffset.x, m_pntUpArrowOffset.y, m_pntUpArrowOffset.x, m_pntUpArrowOffset.y); - BIUtils::ReadPosFromAttr(pAList, "UDArrow_Offset_Down", m_pntDownArrowOffset.x, m_pntDownArrowOffset.y, + BIUtils::ReadPosFromAttr(pAList, "UDArrow_Offset_Down", m_pntDownArrowOffset.x, m_pntDownArrowOffset.y, m_pntDownArrowOffset.x, m_pntDownArrowOffset.y); + BIUtils::ReadPosFromAttr(pAList, "UDArrow_Offset_Down0", m_pntDownArrowOffset0.x, m_pntDownArrowOffset0.y, + m_pntDownArrowOffset0.x, m_pntDownArrowOffset0.y); + + if (attr = pAList->GetAttribute("LRArrow_Texture")) + m_sLeftRightArrowTexture = attr; + BIUtils::ReadRectFromAttr(pAList, "LRArrow_UV_Left", m_frLeftArrowUV, m_frLeftArrowUV); + BIUtils::ReadRectFromAttr(pAList, "LRArrow_UV_Right", m_frRightArrowUV, m_frRightArrowUV); + BIUtils::ReadPosFromAttr(pAList, "LRArrow_Size", m_pntLeftRightArrowSize.x, m_pntLeftRightArrowSize.y, + m_pntLeftRightArrowSize.x, m_pntLeftRightArrowSize.y); + BIUtils::ReadPosFromAttr(pAList, "LRArrow_Offset_Left", m_pntLeftArrowOffset.x, m_pntLeftArrowOffset.y, + m_pntLeftArrowOffset.x, m_pntLeftArrowOffset.y); + BIUtils::ReadPosFromAttr(pAList, "LRArrow_Offset_Right", m_pntRightArrowOffset.x, m_pntRightArrowOffset.y, + m_pntRightArrowOffset.x, m_pntRightArrowOffset.y); // set values for the menu activity icon if (attr = pAList->GetAttribute("ActiveIcon_Texture")) @@ -314,9 +344,9 @@ void BICommandList::Init() m_nIconShowMaxQuantity = 5; } -int32_t BICommandList::AddToIconList(int32_t nTextureNum, int32_t nNormPictureNum, int32_t nSelPictureNum, int32_t nCooldownPictureNum, - int32_t nCharacterIndex, const char *pcCommandName, int32_t nTargetIndex, - const char *pcLocName, const char *pcNoteName) +int32_t BICommandList::AddToIconList(int32_t nTextureNum, int32_t nNormPictureNum, int32_t nSelPictureNum, + int32_t nCooldownPictureNum, int32_t nCharacterIndex, const char *pcCommandName, + int32_t nTargetIndex, const char *pcLocName, const char *pcNoteName) { int32_t n; // filtering out already used objects @@ -361,7 +391,8 @@ int32_t BICommandList::AddToIconList(int32_t nTextureNum, int32_t nNormPictureNu return 1; } -void BICommandList::AddAdditiveToIconList(int32_t nTextureNum, int32_t nPictureNum, float fDist, float fWidth, float fHeight) +void BICommandList::AddAdditiveToIconList(int32_t nTextureNum, int32_t nPictureNum, float fDist, float fWidth, + float fHeight) { if (m_aUsedCommand.empty()) return; @@ -395,7 +426,7 @@ int32_t BICommandList::IconAdd(int32_t nPictureNum, int32_t nTextureNum, RECT &r } int32_t BICommandList::ClockIconAdd(int32_t nForePictureNum, int32_t nBackPictureNum, int32_t nTextureNum, RECT &rpos, - float fFactor) + float fFactor) { if (nTextureNum < 0 || nTextureNum >= m_aTexture.size() || nForePictureNum < 0 || nForePictureNum >= m_aTexture[nTextureNum].nCols * m_aTexture[nTextureNum].nRows) @@ -483,7 +514,7 @@ void BICommandList::UpdateShowIcon() m_pImgRender->CreateImage(BIType_square, m_sActiveIconTexture.c_str(), 0xFF808080, m_frActiveIconUV2, rPos); m_bLeftArrow = m_nStartUsedCommandIndex > 0; - m_bRightArrow = false; + m_bRightArrow = m_aUsedCommand.size() - m_nStartUsedCommandIndex > m_nIconShowMaxQuantity; int32_t i = 0; for (auto n = m_nStartUsedCommandIndex; n < m_aUsedCommand.size() && i < m_nIconShowMaxQuantity; n++) @@ -527,12 +558,28 @@ void BICommandList::UpdateShowIcon() } if (m_bDownArrow) { - rPos.left = m_LeftTopPoint.x + m_pntDownArrowOffset.x; - rPos.top = m_LeftTopPoint.y + m_pntDownArrowOffset.y; + rPos.left = m_bUpArrow ? m_LeftTopPoint.x + m_pntDownArrowOffset.x : m_LeftTopPoint.x + m_pntDownArrowOffset0.x; + rPos.top = m_bUpArrow ? m_LeftTopPoint.y + m_pntDownArrowOffset.y : m_LeftTopPoint.y + m_pntDownArrowOffset0.y; rPos.right = rPos.left + m_pntUpDownArrowSize.x; rPos.bottom = rPos.top + m_pntUpDownArrowSize.y; m_pImgRender->CreateImage(BIType_square, m_sUpDownArrowTexture.c_str(), 0xFF808080, m_frDownArrowUV, rPos); } + if (m_bLeftArrow) + { + rPos.left = m_LeftTopPoint.x + m_pntLeftArrowOffset.x; + rPos.top = m_LeftTopPoint.y + m_pntLeftArrowOffset.y; + rPos.right = rPos.left + m_pntLeftRightArrowSize.x; + rPos.bottom = rPos.top + m_pntLeftRightArrowSize.y; + m_pImgRender->CreateImage(BIType_square, m_sLeftRightArrowTexture.c_str(), 0xFF808080, m_frLeftArrowUV, rPos); + } + if (m_bRightArrow) + { + rPos.left = m_LeftTopPoint.x + m_pntRightArrowOffset.x; + rPos.top = m_LeftTopPoint.y + m_pntRightArrowOffset.y; + rPos.right = rPos.left + m_pntLeftRightArrowSize.x; + rPos.bottom = rPos.top + m_pntLeftRightArrowSize.y; + m_pImgRender->CreateImage(BIType_square, m_sLeftRightArrowTexture.c_str(), 0xFF808080, m_frRightArrowUV, rPos); + } } void BICommandList::SetNote(const char *pcNote, int32_t nX, int32_t nY) diff --git a/src/libs/battle_interface/include/battle_command.h b/src/libs/battle_interface/src/battle_command.h similarity index 87% rename from src/libs/battle_interface/include/battle_command.h rename to src/libs/battle_interface/src/battle_command.h index c7baf0800..86b8bdc79 100644 --- a/src/libs/battle_interface/include/battle_command.h +++ b/src/libs/battle_interface/src/battle_command.h @@ -47,9 +47,9 @@ class BICommandList virtual void Init(); - int32_t AddToIconList(int32_t nTextureNum, int32_t nNormPictureNum, int32_t nSelPictureNum, int32_t nCooldownPictureNum, - int32_t nCharacterIndex, const char *pcCommandName, int32_t nTargetIndex, const char *pcLocName, - const char *pcNoteName); + int32_t AddToIconList(int32_t nTextureNum, int32_t nNormPictureNum, int32_t nSelPictureNum, + int32_t nCooldownPictureNum, int32_t nCharacterIndex, const char *pcCommandName, + int32_t nTargetIndex, const char *pcLocName, const char *pcNoteName); void AddAdditiveToIconList(int32_t nTextureNum, int32_t nPictureNum, float fDist, float fWidth, float fHeight); protected: @@ -100,8 +100,6 @@ class BICommandList int32_t m_nStartUsedCommandIndex; int32_t m_nSelectedCommandIndex; int32_t m_nIconShowMaxQuantity; - bool m_bLeftArrow; - bool m_bRightArrow; IPOINT m_pntActiveIconOffset; IPOINT m_pntActiveIconSize; @@ -118,6 +116,16 @@ class BICommandList IPOINT m_pntUpDownArrowSize; IPOINT m_pntUpArrowOffset; IPOINT m_pntDownArrowOffset; + IPOINT m_pntDownArrowOffset0; + + bool m_bLeftArrow; + bool m_bRightArrow; + std::string m_sLeftRightArrowTexture; + FRECT m_frLeftArrowUV; + FRECT m_frRightArrowUV; + IPOINT m_pntLeftRightArrowSize; + IPOINT m_pntLeftArrowOffset; + IPOINT m_pntRightArrowOffset; std::string m_sCurrentCommandName; int32_t m_nCurrentCommandCharacterIndex; @@ -146,7 +154,8 @@ class BICommandList void Release(); int32_t IconAdd(int32_t nPictureNum, int32_t nTextureNum, RECT &rpos); - int32_t ClockIconAdd(int32_t nForePictureNum, int32_t nBackPictureNum, int32_t nTextureNum, RECT &rpos, float fFactor); + int32_t ClockIconAdd(int32_t nForePictureNum, int32_t nBackPictureNum, int32_t nTextureNum, RECT &rpos, + float fFactor); void AdditiveIconAdd(float fX, float fY, std::vector &aList); FRECT &GetPictureUV(int32_t nTextureNum, int32_t nPictureNum, FRECT &uv); RECT &GetCurrentPos(int32_t num, RECT &rpos) const; diff --git a/src/libs/battle_interface/src/battle_sign.cpp b/src/libs/battle_interface/src/battle_sign.cpp index f013dceeb..4ff155c71 100644 --- a/src/libs/battle_interface/src/battle_sign.cpp +++ b/src/libs/battle_interface/src/battle_sign.cpp @@ -1,5 +1,5 @@ #include "battle_sign.h" -#include "utils.h" +#include "bi_utils.h" #include "controls.h" #include "core.h" #include "vma.hpp" diff --git a/src/libs/battle_interface/include/battle_sign.h b/src/libs/battle_interface/src/battle_sign.h similarity index 100% rename from src/libs/battle_interface/include/battle_sign.h rename to src/libs/battle_interface/src/battle_sign.h diff --git a/src/libs/battle_interface/src/utils.cpp b/src/libs/battle_interface/src/bi_utils.cpp similarity index 91% rename from src/libs/battle_interface/src/utils.cpp rename to src/libs/battle_interface/src/bi_utils.cpp index 9b1b2ffce..be770e377 100644 --- a/src/libs/battle_interface/src/utils.cpp +++ b/src/libs/battle_interface/src/bi_utils.cpp @@ -1,4 +1,4 @@ -#include "utils.h" +#include "bi_utils.h" #include "core.h" #include "string_compare.hpp" @@ -73,26 +73,32 @@ int32_t BIUtils::GetTextureFromAttr(VDX9RENDER *rs, ATTRIBUTES *pA, const char * return rs->TextureCreate(sname); } -bool BIUtils::ReadRectFromAttr(ATTRIBUTES *pA, const std::string_view &name, FRECT &rOut, FRECT &rDefault) +bool BIUtils::ReadRectFromAttr(ATTRIBUTES *pA, const char *name, FRECT &rOut, FRECT &rDefault) { rOut = rDefault; - if (pA) + if (pA && name) { - const std::string str_value = pA->GetAttribute(name); - sscanf(str_value.c_str(), "%f,%f,%f,%f", &rOut.left, &rOut.top, &rOut.right, &rOut.bottom); - return true; + const char *pcStr = pA->GetAttribute(name); + if (pcStr) + { + sscanf(pcStr, "%f,%f,%f,%f", &rOut.left, &rOut.top, &rOut.right, &rOut.bottom); + return true; + } } return false; } -bool BIUtils::ReadRectFromAttr(ATTRIBUTES *pA, const std::string_view &name, RECT &rOut, RECT &rDefault) +bool BIUtils::ReadRectFromAttr(ATTRIBUTES *pA, const char *name, RECT &rOut, RECT &rDefault) { rOut = rDefault; - if (pA) + if (pA && name) { - const std::string str_value = pA->GetAttribute(name); - sscanf(str_value.c_str(), "%d,%d,%d,%d", &rOut.left, &rOut.top, &rOut.right, &rOut.bottom); - return true; + const char *pcStr = pA->GetAttribute(name); + if (pcStr) + { + sscanf(pcStr, "%d,%d,%d,%d", &rOut.left, &rOut.top, &rOut.right, &rOut.bottom); + return true; + } } return false; } @@ -334,7 +340,8 @@ void BITextInfo::Init(VDX9RENDER *rs, ATTRIBUTES *pA) fScale = pA->GetAttributeAsFloat("scale", 1.f); dwColor = pA->GetAttributeAsDword("color", 0xFFFFFFFF); bShadow = pA->GetAttributeAsDword("shadow", 1) != 0; - + nAlign = BIUtils::GetAlignmentFromAttr(pA, "align", PR_ALIGN_CENTER); + ATTRIBUTES *pAttr = pA->GetAttributeClass("pos"); if (pAttr) { @@ -362,9 +369,21 @@ void BITextInfo::Print() { const char *textAttr = pARefresh->GetAttribute("text"); sText = textAttr ? textAttr : ""; + dwColor = pARefresh->GetAttributeAsDword("color", 0xFFFFFFFF); + nAlign = BIUtils::GetAlignmentFromAttr(pARefresh, "align", PR_ALIGN_CENTER); + ATTRIBUTES *pAttr = pARefresh->GetAttributeClass("pos"); + if (pAttr) + { + pos.x = pAttr->GetAttributeAsDword("x", 0); + pos.y = pAttr->GetAttributeAsDword("y", 0); + } + else + { + pos.x = pos.y = 0; + } } if (!sText.empty()) - pRS->ExtPrint(nFont, dwColor, 0, PR_ALIGN_CENTER, bShadow, fScale, 0, 0, pos.x, pos.y, "%s", sText.c_str()); + pRS->ExtPrint(nFont, dwColor, 0, nAlign, bShadow, fScale, 0, 0, pos.x, pos.y, "%s", sText.c_str()); } } @@ -372,7 +391,7 @@ void BITextInfo::Print(std::string outputText) { if (nFont != -1 && !outputText.empty()) { - pRS->ExtPrint(nFont, dwColor, 0, PR_ALIGN_CENTER, bShadow, fScale, 0, 0, pos.x, pos.y, "%s", + pRS->ExtPrint(nFont, dwColor, 0, nAlign, bShadow, fScale, 0, 0, pos.x, pos.y, "%s", outputText.c_str()); } } diff --git a/src/libs/battle_interface/src/image/img_render.cpp b/src/libs/battle_interface/src/image/img_render.cpp index a1d39c582..baf60717c 100644 --- a/src/libs/battle_interface/src/image/img_render.cpp +++ b/src/libs/battle_interface/src/image/img_render.cpp @@ -2,6 +2,8 @@ #include "storm_assert.h" #include "string.h" +#include + BIImageRender::BIImageRender(VDX9RENDER *pRS) : m_nBeginOutputPrioritet(0), m_nEndOutputPrioritet(0) { diff --git a/src/libs/battle_interface/src/interface_manager/interface_group/sea_group.cpp b/src/libs/battle_interface/src/interface_manager/interface_group/sea_group.cpp index 4385e96ef..fd285b988 100644 --- a/src/libs/battle_interface/src/interface_manager/interface_group/sea_group.cpp +++ b/src/libs/battle_interface/src/interface_manager/interface_group/sea_group.cpp @@ -1,5 +1,5 @@ #include "sea_group.h" -#include "utils.h" +#include "bi_utils.h" #include "platform/platform.hpp" BI_SeaGroup::BI_SeaGroup(BI_ManagerBase *pManager) : BI_BaseGroup(pManager) diff --git a/src/libs/battle_interface/src/interface_manager/mouse_pointer.cpp b/src/libs/battle_interface/src/interface_manager/mouse_pointer.cpp index 51703dfbb..7cd0afcc5 100644 --- a/src/libs/battle_interface/src/interface_manager/mouse_pointer.cpp +++ b/src/libs/battle_interface/src/interface_manager/mouse_pointer.cpp @@ -1,5 +1,5 @@ #include "mouse_pointer.h" -#include "utils.h" +#include "bi_utils.h" #include "../image/img_render.h" #include "core.h" #include "vma.hpp" diff --git a/src/libs/battle_interface/src/item_entity/item_entity.cpp b/src/libs/battle_interface/src/item_entity/item_entity.cpp index 421f79830..abf272f15 100644 --- a/src/libs/battle_interface/src/item_entity/item_entity.cpp +++ b/src/libs/battle_interface/src/item_entity/item_entity.cpp @@ -1,5 +1,5 @@ #include "item_entity.h" -#include "utils.h" +#include "bi_utils.h" #include "entity.h" #include "core.h" #include "message.h" diff --git a/src/libs/battle_interface/src/land/battle_land.h b/src/libs/battle_interface/src/land/battle_land.h index 2e0a1efd2..6833d63d3 100644 --- a/src/libs/battle_interface/src/land/battle_land.h +++ b/src/libs/battle_interface/src/land/battle_land.h @@ -1,6 +1,6 @@ #pragma once -#include "utils.h" +#include "bi_utils.h" #include "bi_defines.h" class BIManSign; diff --git a/src/libs/battle_interface/src/land/battle_man_command.h b/src/libs/battle_interface/src/land/battle_man_command.h index 09d15c802..8e531664f 100644 --- a/src/libs/battle_interface/src/land/battle_man_command.h +++ b/src/libs/battle_interface/src/land/battle_man_command.h @@ -1,6 +1,6 @@ #pragma once -#include "battle_command.h" +#include "../battle_command.h" class BIManCommandList : public BICommandList { diff --git a/src/libs/battle_interface/src/land/battle_man_sign.cpp b/src/libs/battle_interface/src/land/battle_man_sign.cpp index 2e8f32505..9d8ba0ccb 100644 --- a/src/libs/battle_interface/src/land/battle_man_sign.cpp +++ b/src/libs/battle_interface/src/land/battle_man_sign.cpp @@ -1,5 +1,5 @@ #include "battle_man_sign.h" -#include "utils.h" +#include "bi_utils.h" #include "battle_man_command.h" #include "core.h" #include "shared/battle_interface/msg_control.h" diff --git a/src/libs/battle_interface/src/log_and_action.cpp b/src/libs/battle_interface/src/log_and_action.cpp index 7ad9b4f53..e8c3dcafe 100644 --- a/src/libs/battle_interface/src/log_and_action.cpp +++ b/src/libs/battle_interface/src/log_and_action.cpp @@ -32,6 +32,19 @@ ILogAndActions::ILogAndActions() m_bDontShowAll = false; m_sOldActionName[0] = 0; m_nTimeCounter = 0; + + //picinfo + m_pRoot = nullptr; + m_PicInfofontID = -1; + m_fPicInfoFontScale = 1.f; + m_nPicInfoStringBegin = 0; + + // TimeSpeed + bShowTimeSpeed = false; + + // level up + m_idLUBackTexture = -1; + AlphaLU = 0.f; } ILogAndActions::~ILogAndActions() @@ -96,6 +109,39 @@ void ILogAndActions::Execute(uint32_t delta_time) } top += m_nStringOffset; } + + // pic info string + + // fade out lines + const auto colDelta1 = delta_time * m_fPicInfoBlendSpeed; + STRING_DESCR *prev_pd = nullptr; + STRING_DESCR *pd; + for (pd = m_pRoot; pd != nullptr;) + { + if (pd->alpha <= 255.f) + if ((pd->alpha -= colDelta1) <= 0) + { + if (prev_pd == nullptr) + m_pRoot = pd->next; + else + prev_pd->next = pd->next; + STORM_DELETE(pd->str); + STORM_DELETE(pd); + pd = m_pRoot; + continue; + } + prev_pd = pd; + pd = pd->next; + } + + + if ((AlphaBI -= colDelta1) <= 0) AlphaBI = 0.f; + if ((AlphaBI2 -= colDelta1) <= 0) AlphaBI2 = 0.f; + if ((AlphaBI3 -= colDelta1) <= 0) AlphaBI3 = 0.f; + if (m_pRoot == nullptr) PIstage = 0; + const auto colDelta2 = delta_time * m_fLUStringSpeed; + if ((AlphaLU -= colDelta2) <= 0) AlphaLU = 0.f; + } uint64_t ILogAndActions::ProcessMessage(MESSAGE &message) @@ -147,6 +193,32 @@ uint64_t ILogAndActions::ProcessMessage(MESSAGE &message) SetString(param.c_str(), false); } break; + + case LOG_ADD_PIC: + { + if(PIstage == 3) break; + const std::string ¶m = message.String(); + m_nPicInfoIconIndex = message.Long(); + SetPicInfo(param.c_str()); + } + break; + + case LOG_TIME_SPEED: + { + TimeSpeedText = message.String(); + bShowTimeSpeed = message.Long() != 0 ; + if(!bShowTimeSpeed) break; + } + break; + + case LOG_LEVEL_UP: + { + LUStringText = message.String(); + LURankText = message.String(); + SetLevelUp(); + } + break; + case LOG_SET_ACTIVE_ACTION: { const std::string ¶m = message.String(); SetAction(param.c_str()); @@ -232,6 +304,14 @@ void ILogAndActions::Realize(uint32_t delta_time) { CMatrix matw; rs->SetTransform(D3DTS_WORLD, matw); + //backimage + if (m_idActionBackTexture != -1L && m_bThatRealAction && rs->StringWidth(m_ActionHint2.sText.c_str(), m_ActionHint2.nFont, m_ActionHint2.fScale, 0) > 1) + { + rs->TextureSet(0, m_idActionBackTexture); + rs->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, BI_COLOR_VERTEX_FORMAT, 2, m_ActionBackVertex, + sizeof(BI_COLOR_VERTEX), "battle_rectangle"); + } + // show icon if ((m_idIconTexture != -1L) && m_bThatRealAction) { @@ -243,12 +323,45 @@ void ILogAndActions::Realize(uint32_t delta_time) m_ActionHint2.Print(); } } - + + // time speed + if(m_bShowLogStrings && bShowTimeSpeed) + { + + rs->TextureSet(0, m_idTimeSpeedIconTexture); + rs->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, BI_COLOR_VERTEX_FORMAT, 2, m_TimeSpeedIconVertex, + sizeof(BI_COLOR_VERTEX), "battle_tex_col_Rectangle"); + + rs->ExtPrint(m_TimeSpeedfontID, m_dwTimeSpeedColor, 0, PR_ALIGN_LEFT, true, m_fTimeSpeedFontScale, + 0, 0, m_nTimeSpeedLeft, m_nTimeSpeedUp, "%s", TimeSpeedText.c_str()); + + + } + + //level up + if (m_bShowLogStrings && AlphaLU > 0.f) + { + m_LUBackVertex[0].col = m_dwLUBackColor + (static_cast(AlphaLU) << 24); + m_LUBackVertex[1].col = m_dwLUBackColor + (static_cast(AlphaLU) << 24); + m_LUBackVertex[2].col = m_dwLUBackColor + (static_cast(AlphaLU) << 24); + m_LUBackVertex[3].col = m_dwLUBackColor + (static_cast(AlphaLU) << 24); + + rs->TextureSet(0, m_idLUBackTexture); + rs->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, BI_COLOR_VERTEX_FORMAT, 2, m_LUBackVertex, + sizeof(BI_COLOR_VERTEX), "battle_tex_col_Rectangle"); + + rs->ExtPrint(m_LUStringfontID, m_dwLUStringColor + (static_cast(AlphaLU) << 24), 0, PR_ALIGN_CENTER, true, m_fLUStringFontScale, + 0, 0, m_nLUStringLeft, m_nLUStringUp, "%s", LUStringText.c_str()); + + rs->ExtPrint(m_LURankfontID, m_dwLURankColor + (static_cast(AlphaLU) << 24), 0, PR_ALIGN_CENTER, true, m_fLURankFontScale, + 0, 0, m_nLURankLeft, m_nLURankUp, "%s", LURankText.c_str()); + } + // Show log strings if (m_bShowLogStrings) { - if (m_sRoot == nullptr) - return; + if (m_sRoot == nullptr && m_pRoot == nullptr) + return; auto *ptr = m_sRoot; int32_t nAlign = PR_ALIGN_LEFT; auto strX = m_nWindowLeft; @@ -273,6 +386,93 @@ void ILogAndActions::Realize(uint32_t delta_time) ptr = ptr->next; } } + + // Show Pic Info strings + if (m_bShowLogStrings) + { + if (m_pRoot == nullptr) + return; + auto *ptr = m_pRoot; + int32_t nPIAlign = PR_ALIGN_LEFT; + auto strPIX = m_nPicInfoWindowLeft; + if (m_nPicInfoWindowRight >= 0) + { + strPIX = m_nPicInfoWindowRight; + nPIAlign = PR_ALIGN_RIGHT; + } + + if(m_PicInfoBackVertex[0].col != m_dwPicInfoMinColor) + { + m_PicInfoBackVertex[0].col = m_dwPicInfoMinColor + (static_cast(AlphaBI) << 24); + m_PicInfoBackVertex[1].col = m_dwPicInfoMinColor + (static_cast(AlphaBI) << 24); + m_PicInfoBackVertex[2].col = m_dwPicInfoMinColor + (static_cast(AlphaBI) << 24); + m_PicInfoBackVertex[3].col = m_dwPicInfoMinColor + (static_cast(AlphaBI) << 24); + + m_PicInfoIconVertex[0].col = m_dwPicInfoMinColor + (static_cast(AlphaBI) << 24); + m_PicInfoIconVertex[1].col = m_dwPicInfoMinColor + (static_cast(AlphaBI) << 24); + m_PicInfoIconVertex[2].col = m_dwPicInfoMinColor + (static_cast(AlphaBI) << 24); + m_PicInfoIconVertex[3].col = m_dwPicInfoMinColor + (static_cast(AlphaBI) << 24); + + rs->TextureSet(0, m_idPicInfoBackTexture); + rs->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, BI_COLOR_VERTEX_FORMAT, 2, m_PicInfoBackVertex, + sizeof(BI_COLOR_VERTEX), "battle_tex_col_Rectangle"); + + rs->TextureSet(0, m_idPicInfoIconTexture); + rs->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, BI_COLOR_VERTEX_FORMAT, 2, m_PicInfoIconVertex, + sizeof(BI_COLOR_VERTEX), "battle_tex_col_Rectangle"); + } + + if(m_PicInfoBackVertex1[0].col != m_dwPicInfoMinColor) + { + m_PicInfoBackVertex1[0].col = m_dwPicInfoMinColor + (static_cast(AlphaBI2) << 24); + m_PicInfoBackVertex1[1].col = m_dwPicInfoMinColor + (static_cast(AlphaBI2) << 24); + m_PicInfoBackVertex1[2].col = m_dwPicInfoMinColor + (static_cast(AlphaBI2) << 24); + m_PicInfoBackVertex1[3].col = m_dwPicInfoMinColor + (static_cast(AlphaBI2) << 24); + + m_PicInfoIconVertex1[0].col = m_dwPicInfoMinColor + (static_cast(AlphaBI2) << 24); + m_PicInfoIconVertex1[1].col = m_dwPicInfoMinColor + (static_cast(AlphaBI2) << 24); + m_PicInfoIconVertex1[2].col = m_dwPicInfoMinColor + (static_cast(AlphaBI2) << 24); + m_PicInfoIconVertex1[3].col = m_dwPicInfoMinColor + (static_cast(AlphaBI2) << 24); + + rs->TextureSet(0, m_idPicInfoBackTexture); + rs->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, BI_COLOR_VERTEX_FORMAT, 2, m_PicInfoBackVertex1, + sizeof(BI_COLOR_VERTEX), "battle_tex_col_Rectangle"); + + rs->TextureSet(0, m_idPicInfoIconTexture); + rs->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, BI_COLOR_VERTEX_FORMAT, 2, m_PicInfoIconVertex1, + sizeof(BI_COLOR_VERTEX), "battle_tex_col_Rectangle"); + } + + if(m_PicInfoBackVertex2[0].col != m_dwPicInfoMinColor) + { + m_PicInfoBackVertex2[0].col = m_dwPicInfoMinColor + (static_cast(AlphaBI3) << 24); + m_PicInfoBackVertex2[1].col = m_dwPicInfoMinColor + (static_cast(AlphaBI3) << 24); + m_PicInfoBackVertex2[2].col = m_dwPicInfoMinColor + (static_cast(AlphaBI3) << 24); + m_PicInfoBackVertex2[3].col = m_dwPicInfoMinColor + (static_cast(AlphaBI3) << 24); + + m_PicInfoIconVertex2[0].col = m_dwPicInfoMinColor + (static_cast(AlphaBI3) << 24); + m_PicInfoIconVertex2[1].col = m_dwPicInfoMinColor + (static_cast(AlphaBI3) << 24); + m_PicInfoIconVertex2[2].col = m_dwPicInfoMinColor + (static_cast(AlphaBI3) << 24); + m_PicInfoIconVertex2[3].col = m_dwPicInfoMinColor + (static_cast(AlphaBI3) << 24); + + rs->TextureSet(0, m_idPicInfoBackTexture); + rs->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, BI_COLOR_VERTEX_FORMAT, 2, m_PicInfoBackVertex2, + sizeof(BI_COLOR_VERTEX), "battle_tex_col_Rectangle"); + + rs->TextureSet(0, m_idPicInfoIconTexture); + rs->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, BI_COLOR_VERTEX_FORMAT, 2, m_PicInfoIconVertex2, + sizeof(BI_COLOR_VERTEX), "battle_tex_col_Rectangle"); + } + auto strPIY = m_nPicInfoStringBegin; + while (ptr != nullptr) + { + rs->ExtPrint(m_PicInfofontID, m_dwPicInfoColor + (static_cast(ptr->alpha) << 24), 0, nPIAlign, true, m_fPicInfoFontScale, + 0, 0, strPIX, m_nPicInfoWindowUp + static_cast(ptr->offset), "%s", ptr->str); + + strPIY += m_nPicInfoStringOffset; + ptr = ptr->next; + } + } } void ILogAndActions::Create(bool bFastComShow, bool bLogStringShow) @@ -347,6 +547,434 @@ void ILogAndActions::Create(bool bFastComShow, bool bLogStringShow) m_fShiftSpeed = 1.f / 50.f; m_fBlendSpeed = 1.f / 50.f; } + + //backimage + pA = AttributesPointer->GetAttributeClass("ActiveActionsBack"); + if (pA != nullptr) + { + m_idActionBackTexture = rs->TextureCreate(pA->GetAttribute("TextureName")); + m_nActionBackWidth = pA->GetAttributeAsDword("width", 64); + m_nActionBackHeight = pA->GetAttributeAsDword("height", 64); + m_nActionBackCentr = pA->GetAttributeAsDword("centr", 0); + m_nActionBackUp = pA->GetAttributeAsDword("top", 0); + m_dwActionBackColor = pA->GetAttributeAsDword("color", 0x00FFFFFF); + } + else + { + m_idActionBackTexture = -1L; + m_nActionBackWidth = 64; + m_nActionBackHeight = 64; + m_nActionBackCentr = 0; + m_nActionBackUp = 0; + m_dwActionBackColor = 0x00FFFFFF; + } + m_ActionBackVertex[0].w = m_ActionBackVertex[1].w = m_ActionBackVertex[2].w = m_ActionBackVertex[3].w = .5f; + m_ActionBackVertex[0].pos.z = m_ActionBackVertex[1].pos.z = m_ActionBackVertex[2].pos.z = m_ActionBackVertex[3].pos.z = 1.f; + m_ActionBackVertex[0].col = m_ActionBackVertex[1].col = m_ActionBackVertex[2].col = m_ActionBackVertex[3].col = m_dwActionBackColor; + m_ActionBackVertex[0].pos.x = static_cast(m_nActionBackCentr); + m_ActionBackVertex[0].pos.y = static_cast(m_nActionBackUp); + m_ActionBackVertex[0].tu = 0.f; + m_ActionBackVertex[0].tv = 0.f; + + m_ActionBackVertex[1].pos.x = static_cast(m_nActionBackCentr); + m_ActionBackVertex[1].pos.y = static_cast(m_nActionBackUp + m_nActionBackHeight); + m_ActionBackVertex[1].tu = 0.f; + m_ActionBackVertex[1].tv = 1.f ; + + m_ActionBackVertex[2].pos.x = static_cast(m_nActionBackCentr + m_nActionBackWidth); + m_ActionBackVertex[2].pos.y = static_cast(m_nActionBackUp); + m_ActionBackVertex[2].tu = 1.f; + m_ActionBackVertex[2].tv = 0.f; + + m_ActionBackVertex[3].pos.x = static_cast(m_nActionBackCentr + m_nActionBackWidth); + m_ActionBackVertex[3].pos.y = static_cast(m_nActionBackUp + m_nActionBackHeight); + m_ActionBackVertex[3].tu = 1.f ; + m_ActionBackVertex[3].tv = 1.f ; + + + // set param for pic info + PIstage = 0; + pA = AttributesPointer->GetAttributeClass("PicInfo"); + if (pA != nullptr) + { + m_nPicInfoWindowWidth = pA->GetAttributeAsDword("width", 200); + m_nPicInfoWindowHeight = pA->GetAttributeAsDword("height", 128); + m_nPicInfoWindowLeft = pA->GetAttributeAsDword("left", -1); + m_nPicInfoWindowRight = pA->GetAttributeAsDword("right", -1); + m_nPicInfoWindowUp = pA->GetAttributeAsDword("up", 0); + m_PicInfofontID = rs->LoadFont(pA->GetAttribute("font")); + m_fPicInfoFontScale = pA->GetAttributeAsFloat("fontscale", 1.f); + m_dwPicInfoColor = pA->GetAttributeAsDword("color", 0x00FFFFFF); + m_nPicInfoStringOffset = pA->GetAttributeAsDword("offsetString", 24); + m_fPicInfoShiftSpeed = pA->GetAttributeAsFloat("speed", 1.f / 50.f); + m_fPicInfoBlendSpeed = pA->GetAttributeAsFloat("color_speed", 1.f / 50.f); + m_dwPicInfoMaxColor = pA->GetAttributeAsDword("maxcolor", 0x00FFFFFF); + m_dwPicInfoMinColor = pA->GetAttributeAsDword("mincolor", 0x00FFFFFF); + } + else + { + m_nPicInfoWindowWidth = 200; + m_nPicInfoWindowHeight = 128; + m_nPicInfoWindowLeft = 64; + m_nPicInfoWindowUp = 0; + m_PicInfofontID = -1L; + m_fPicInfoFontScale = 1.f; + m_dwPicInfoColor = 0x00FFFFFF; + m_nPicInfoStringBegin = 0; + m_nPicInfoStringOffset = 24; + m_fPicInfoShiftSpeed = 1.f / 50.f; + m_fPicInfoBlendSpeed = 1.f / 50.f; + m_dwPicInfoMaxColor = 0x00FFFFFF; + m_dwPicInfoMinColor = 0x00FFFFFF; + } + AlphaBI = 0.f; + AlphaBI2 = 0.f; + AlphaBI3 = 0.f; + // backimage + pA = AttributesPointer->GetAttributeClass("PicInfoBack"); + if (pA != nullptr) + { + m_idPicInfoBackTexture = rs->TextureCreate(pA->GetAttribute("TextureName")); + m_nPicInfoBackWidth = pA->GetAttributeAsDword("width", 64); + m_nPicInfoBackHeight = pA->GetAttributeAsDword("height", 64); + m_nPicInfoBackLeft = pA->GetAttributeAsDword("left", 0); + m_nPicInfoBackUp = pA->GetAttributeAsDword("top", 0); + } + else + { + m_idPicInfoBackTexture = -1L; + m_nPicInfoBackWidth = 64; + m_nPicInfoBackHeight = 64; + m_nPicInfoBackLeft = 0; + m_nPicInfoBackUp = 0; + } + m_PicInfoBackVertex[0].w = m_PicInfoBackVertex[1].w = m_PicInfoBackVertex[2].w = m_PicInfoBackVertex[3].w = .5f; + m_PicInfoBackVertex[0].pos.z = m_PicInfoBackVertex[1].pos.z = m_PicInfoBackVertex[2].pos.z = m_PicInfoBackVertex[3].pos.z = 1.f; + m_PicInfoBackVertex[0].col = m_PicInfoBackVertex[1].col = m_PicInfoBackVertex[2].col = m_PicInfoBackVertex[3].col = m_dwPicInfoMinColor; + m_PicInfoBackVertex[0].pos.x = static_cast(m_nPicInfoBackLeft); + m_PicInfoBackVertex[0].pos.y = static_cast(m_nPicInfoBackUp); + m_PicInfoBackVertex[0].tu = 0.f; + m_PicInfoBackVertex[0].tv = 0.f; + + m_PicInfoBackVertex[1].pos.x = static_cast(m_nPicInfoBackLeft); + m_PicInfoBackVertex[1].pos.y = static_cast(m_nPicInfoBackUp + m_nPicInfoBackHeight); + m_PicInfoBackVertex[1].tu = 0.f; + m_PicInfoBackVertex[1].tv = 1.f ; + + m_PicInfoBackVertex[2].pos.x = static_cast(m_nPicInfoBackLeft + m_nPicInfoBackWidth); + m_PicInfoBackVertex[2].pos.y = static_cast(m_nPicInfoBackUp); + m_PicInfoBackVertex[2].tu = 1.f; + m_PicInfoBackVertex[2].tv = 0.f; + + m_PicInfoBackVertex[3].pos.x = static_cast(m_nPicInfoBackLeft + m_nPicInfoBackWidth); + m_PicInfoBackVertex[3].pos.y = static_cast(m_nPicInfoBackUp + m_nPicInfoBackHeight); + m_PicInfoBackVertex[3].tu = 1.f ; + m_PicInfoBackVertex[3].tv = 1.f ; + + // Icon + pA = AttributesPointer->GetAttributeClass("PicInfoIcon"); + if (pA != nullptr) + { + m_idPicInfoIconTexture = rs->TextureCreate(pA->GetAttribute("TextureName")); + m_nPicInfoIconhorzDiv = pA->GetAttributeAsDword("horzQ", 1); + m_nPicInfoIconvertDiv = pA->GetAttributeAsDword("vertQ", 1); + m_nPicInfoIconWidth = pA->GetAttributeAsDword("width", 64); + m_nPicInfoIconHeight = pA->GetAttributeAsDword("height", 64); + m_nPicInfoIconLeft = pA->GetAttributeAsDword("left", 0); + m_nPicInfoIconUp = pA->GetAttributeAsDword("top", 0); + } + else + { + m_idPicInfoIconTexture = -1L; + m_nPicInfoIconhorzDiv = 1; + m_nPicInfoIconvertDiv = 1; + m_nPicInfoIconWidth = 64; + m_nPicInfoIconHeight = 64; + m_nPicInfoIconLeft = 0; + m_nPicInfoIconUp = 0; + } + + FRECT texRect; + CalculateTexturePos(texRect, m_nPicInfoIconhorzDiv, m_nPicInfoIconvertDiv, m_nPicInfoIconIndex); + + m_PicInfoIconVertex[0].w = m_PicInfoIconVertex[1].w = m_PicInfoIconVertex[2].w = m_PicInfoIconVertex[3].w = .5f; + m_PicInfoIconVertex[0].pos.z = m_PicInfoIconVertex[1].pos.z = m_PicInfoIconVertex[2].pos.z = m_PicInfoIconVertex[3].pos.z = 1.f; + m_PicInfoIconVertex[0].col = m_PicInfoIconVertex[1].col = m_PicInfoIconVertex[2].col = m_PicInfoIconVertex[3].col = m_dwPicInfoMinColor; + m_PicInfoIconVertex[0].pos.x = static_cast(m_nPicInfoIconLeft); + m_PicInfoIconVertex[0].pos.y = static_cast(m_nPicInfoIconUp); + m_PicInfoIconVertex[0].tu = texRect.left; + m_PicInfoIconVertex[0].tv = texRect.top; + + m_PicInfoIconVertex[1].pos.x = static_cast(m_nPicInfoIconLeft); + m_PicInfoIconVertex[1].pos.y = static_cast(m_nPicInfoIconUp + m_nPicInfoIconHeight); + m_PicInfoIconVertex[1].tu = texRect.left; + m_PicInfoIconVertex[1].tv = texRect.bottom; + + m_PicInfoIconVertex[2].pos.x = static_cast(m_nPicInfoIconLeft + m_nPicInfoIconWidth); + m_PicInfoIconVertex[2].pos.y = static_cast(m_nPicInfoIconUp); + m_PicInfoIconVertex[2].tu = texRect.right; + m_PicInfoIconVertex[2].tv = texRect.top; + + m_PicInfoIconVertex[3].pos.x = static_cast(m_nPicInfoIconLeft + m_nPicInfoIconWidth); + m_PicInfoIconVertex[3].pos.y = static_cast(m_nPicInfoIconUp + m_nPicInfoIconHeight); + m_PicInfoIconVertex[3].tu = texRect.right; + m_PicInfoIconVertex[3].tv = texRect.bottom; + + //second line + m_PicInfoBackVertex1[0].w = m_PicInfoBackVertex1[1].w = m_PicInfoBackVertex1[2].w = m_PicInfoBackVertex1[3].w = .5f; + m_PicInfoBackVertex1[0].pos.z = m_PicInfoBackVertex1[1].pos.z = m_PicInfoBackVertex1[2].pos.z = m_PicInfoBackVertex1[3].pos.z = 1.f; + m_PicInfoBackVertex1[0].col = m_PicInfoBackVertex[1].col = m_PicInfoBackVertex1[2].col = m_PicInfoBackVertex1[3].col = m_dwPicInfoMinColor; + m_PicInfoBackVertex1[0].pos.x = static_cast(m_nPicInfoBackLeft); + m_PicInfoBackVertex1[0].pos.y = static_cast(m_nPicInfoBackUp) + static_cast(m_nPicInfoStringOffset); + m_PicInfoBackVertex1[0].tu = 0.f; + m_PicInfoBackVertex1[0].tv = 0.f; + + m_PicInfoBackVertex1[1].pos.x = static_cast(m_nPicInfoBackLeft); + m_PicInfoBackVertex1[1].pos.y = static_cast(m_nPicInfoBackUp + m_nPicInfoBackHeight) + static_cast(m_nPicInfoStringOffset); + m_PicInfoBackVertex1[1].tu = 0.f; + m_PicInfoBackVertex1[1].tv = 1.f ; + + m_PicInfoBackVertex1[2].pos.x = static_cast(m_nPicInfoBackLeft + m_nPicInfoBackWidth); + m_PicInfoBackVertex1[2].pos.y = static_cast(m_nPicInfoBackUp) + static_cast(m_nPicInfoStringOffset); + m_PicInfoBackVertex1[2].tu = 1.f; + m_PicInfoBackVertex1[2].tv = 0.f; + + m_PicInfoBackVertex1[3].pos.x = static_cast(m_nPicInfoBackLeft + m_nPicInfoBackWidth); + m_PicInfoBackVertex1[3].pos.y = static_cast(m_nPicInfoBackUp + m_nPicInfoBackHeight) + static_cast(m_nPicInfoStringOffset); + m_PicInfoBackVertex1[3].tu = 1.f ; + m_PicInfoBackVertex1[3].tv = 1.f ; + + + CalculateTexturePos(texRect, m_nPicInfoIconhorzDiv, m_nPicInfoIconvertDiv, m_nPicInfoIconIndex); + + m_PicInfoIconVertex1[0].w = m_PicInfoIconVertex1[1].w = m_PicInfoIconVertex1[2].w = m_PicInfoIconVertex1[3].w = .5f; + m_PicInfoIconVertex1[0].pos.z = m_PicInfoIconVertex1[1].pos.z = m_PicInfoIconVertex1[2].pos.z = m_PicInfoIconVertex1[3].pos.z = 1.f; + m_PicInfoIconVertex1[0].col = m_PicInfoIconVertex1[1].col = m_PicInfoIconVertex1[2].col = m_PicInfoIconVertex1[3].col = m_dwPicInfoMinColor; + m_PicInfoIconVertex1[0].pos.x = static_cast(m_nPicInfoIconLeft); + m_PicInfoIconVertex1[0].pos.y = static_cast(m_nPicInfoIconUp) + static_cast(m_nPicInfoStringOffset); + m_PicInfoIconVertex1[0].tu = texRect.left; + m_PicInfoIconVertex1[0].tv = texRect.top; + + m_PicInfoIconVertex1[1].pos.x = static_cast(m_nPicInfoIconLeft); + m_PicInfoIconVertex1[1].pos.y = static_cast(m_nPicInfoIconUp + m_nPicInfoIconHeight) + static_cast(m_nPicInfoStringOffset); + m_PicInfoIconVertex1[1].tu = texRect.left; + m_PicInfoIconVertex1[1].tv = texRect.bottom; + + m_PicInfoIconVertex1[2].pos.x = static_cast(m_nPicInfoIconLeft + m_nPicInfoIconWidth); + m_PicInfoIconVertex1[2].pos.y = static_cast(m_nPicInfoIconUp) + static_cast(m_nPicInfoStringOffset); + m_PicInfoIconVertex1[2].tu = texRect.right; + m_PicInfoIconVertex1[2].tv = texRect.top; + + m_PicInfoIconVertex1[3].pos.x = static_cast(m_nPicInfoIconLeft + m_nPicInfoIconWidth); + m_PicInfoIconVertex1[3].pos.y = static_cast(m_nPicInfoIconUp + m_nPicInfoIconHeight) + static_cast(m_nPicInfoStringOffset); + m_PicInfoIconVertex1[3].tu = texRect.right; + m_PicInfoIconVertex1[3].tv = texRect.bottom; + + + //3d line + m_PicInfoBackVertex2[0].w = m_PicInfoBackVertex2[1].w = m_PicInfoBackVertex2[2].w = m_PicInfoBackVertex2[3].w = .5f; + m_PicInfoBackVertex2[0].pos.z = m_PicInfoBackVertex2[1].pos.z = m_PicInfoBackVertex2[2].pos.z = m_PicInfoBackVertex2[3].pos.z = 1.f; + m_PicInfoBackVertex2[0].col = m_PicInfoBackVertex[1].col = m_PicInfoBackVertex2[2].col = m_PicInfoBackVertex2[3].col = m_dwPicInfoMinColor; + m_PicInfoBackVertex2[0].pos.x = static_cast(m_nPicInfoBackLeft); + m_PicInfoBackVertex2[0].pos.y = static_cast(m_nPicInfoBackUp) + static_cast(m_nPicInfoStringOffset*2); + m_PicInfoBackVertex2[0].tu = 0.f; + m_PicInfoBackVertex2[0].tv = 0.f; + + m_PicInfoBackVertex2[1].pos.x = static_cast(m_nPicInfoBackLeft); + m_PicInfoBackVertex2[1].pos.y = static_cast(m_nPicInfoBackUp + m_nPicInfoBackHeight) + static_cast(m_nPicInfoStringOffset*2); + m_PicInfoBackVertex2[1].tu = 0.f; + m_PicInfoBackVertex2[1].tv = 1.f ; + + m_PicInfoBackVertex2[2].pos.x = static_cast(m_nPicInfoBackLeft + m_nPicInfoBackWidth); + m_PicInfoBackVertex2[2].pos.y = static_cast(m_nPicInfoBackUp) + static_cast(m_nPicInfoStringOffset*2); + m_PicInfoBackVertex2[2].tu = 1.f; + m_PicInfoBackVertex2[2].tv = 0.f; + + m_PicInfoBackVertex2[3].pos.x = static_cast(m_nPicInfoBackLeft + m_nPicInfoBackWidth); + m_PicInfoBackVertex2[3].pos.y = static_cast(m_nPicInfoBackUp + m_nPicInfoBackHeight) + static_cast(m_nPicInfoStringOffset*2); + m_PicInfoBackVertex2[3].tu = 1.f ; + m_PicInfoBackVertex2[3].tv = 1.f ; + + + CalculateTexturePos(texRect, m_nPicInfoIconhorzDiv, m_nPicInfoIconvertDiv, m_nPicInfoIconIndex); + + m_PicInfoIconVertex2[0].w = m_PicInfoIconVertex2[1].w = m_PicInfoIconVertex2[2].w = m_PicInfoIconVertex2[3].w = .5f; + m_PicInfoIconVertex2[0].pos.z = m_PicInfoIconVertex2[1].pos.z = m_PicInfoIconVertex2[2].pos.z = m_PicInfoIconVertex2[3].pos.z = 1.f; + m_PicInfoIconVertex2[0].col = m_PicInfoIconVertex2[1].col = m_PicInfoIconVertex2[2].col = m_PicInfoIconVertex2[3].col = m_dwPicInfoMinColor; + m_PicInfoIconVertex2[0].pos.x = static_cast(m_nPicInfoIconLeft); + m_PicInfoIconVertex2[0].pos.y = static_cast(m_nPicInfoIconUp) + static_cast(m_nPicInfoStringOffset*2); + m_PicInfoIconVertex2[0].tu = texRect.left; + m_PicInfoIconVertex2[0].tv = texRect.top; + + m_PicInfoIconVertex2[1].pos.x = static_cast(m_nPicInfoIconLeft); + m_PicInfoIconVertex2[1].pos.y = static_cast(m_nPicInfoIconUp + m_nPicInfoIconHeight) + static_cast(m_nPicInfoStringOffset*2); + m_PicInfoIconVertex2[1].tu = texRect.left; + m_PicInfoIconVertex2[1].tv = texRect.bottom; + + m_PicInfoIconVertex2[2].pos.x = static_cast(m_nPicInfoIconLeft + m_nPicInfoIconWidth); + m_PicInfoIconVertex2[2].pos.y = static_cast(m_nPicInfoIconUp) + static_cast(m_nPicInfoStringOffset*2); + m_PicInfoIconVertex2[2].tu = texRect.right; + m_PicInfoIconVertex2[2].tv = texRect.top; + + m_PicInfoIconVertex2[3].pos.x = static_cast(m_nPicInfoIconLeft + m_nPicInfoIconWidth); + m_PicInfoIconVertex2[3].pos.y = static_cast(m_nPicInfoIconUp + m_nPicInfoIconHeight) + static_cast(m_nPicInfoStringOffset*2); + m_PicInfoIconVertex2[3].tu = texRect.right; + m_PicInfoIconVertex2[3].tv = texRect.bottom; + + + // Time Speed + // text + pA = AttributesPointer->GetAttributeClass("timespeedtext"); + if (pA != nullptr) + { + m_nTimeSpeedLeft = pA->GetAttributeAsDword("left", -1); + m_nTimeSpeedUp = pA->GetAttributeAsDword("up", 0); + m_TimeSpeedfontID = rs->LoadFont(pA->GetAttribute("font")); + m_fTimeSpeedFontScale = pA->GetAttributeAsFloat("fontscale", 1.f); + m_dwTimeSpeedColor = pA->GetAttributeAsDword("color", 0x00FFFFFF); + } + else + { + + m_nTimeSpeedLeft = 64; + m_nTimeSpeedUp = 0; + m_TimeSpeedfontID = -1L; + m_fTimeSpeedFontScale = 1.f; + m_dwTimeSpeedColor = 0x00FFFFFF; + } + + // icon + pA = AttributesPointer->GetAttributeClass("timespeedicon"); + if (pA != nullptr) + { + m_idTimeSpeedIconTexture = rs->TextureCreate(pA->GetAttribute("texturename")); + m_nTimeSpeedIconWidth = pA->GetAttributeAsDword("width", 64); + m_nTimeSpeedIconHeight = pA->GetAttributeAsDword("height", 64); + m_nTimeSpeedIconLeft = pA->GetAttributeAsDword("left", 0); + m_nTimeSpeedIconUp = pA->GetAttributeAsDword("top", 0); + m_dwTimeSpeedIconColor = pA->GetAttributeAsDword("color", 0x00FFFFFF); + } + else + { + m_idTimeSpeedIconTexture = -1L; + m_nTimeSpeedIconWidth = 64; + m_nTimeSpeedIconHeight = 64; + m_nTimeSpeedIconLeft = 0; + m_nTimeSpeedIconUp = 0; + m_dwTimeSpeedIconColor = 0x00FFFFFF; + } + + m_TimeSpeedIconVertex[0].w = m_TimeSpeedIconVertex[1].w = m_TimeSpeedIconVertex[2].w = m_TimeSpeedIconVertex[3].w = .5f; + m_TimeSpeedIconVertex[0].pos.z = m_TimeSpeedIconVertex[1].pos.z = m_TimeSpeedIconVertex[2].pos.z = m_TimeSpeedIconVertex[3].pos.z = 1.f; + m_TimeSpeedIconVertex[0].col = m_TimeSpeedIconVertex[1].col = m_TimeSpeedIconVertex[2].col = m_TimeSpeedIconVertex[3].col = m_dwTimeSpeedIconColor; + m_TimeSpeedIconVertex[0].pos.x = static_cast(m_nTimeSpeedIconLeft); + m_TimeSpeedIconVertex[0].pos.y = static_cast(m_nTimeSpeedIconUp); + m_TimeSpeedIconVertex[0].tu = 0.f; + m_TimeSpeedIconVertex[0].tv = 0.f; + + m_TimeSpeedIconVertex[1].pos.x = static_cast(m_nTimeSpeedIconLeft); + m_TimeSpeedIconVertex[1].pos.y = static_cast(m_nTimeSpeedIconUp + m_nTimeSpeedIconHeight); + m_TimeSpeedIconVertex[1].tu = 0.f; + m_TimeSpeedIconVertex[1].tv = 1.f ; + + m_TimeSpeedIconVertex[2].pos.x = static_cast(m_nTimeSpeedIconLeft + m_nTimeSpeedIconWidth); + m_TimeSpeedIconVertex[2].pos.y = static_cast(m_nTimeSpeedIconUp); + m_TimeSpeedIconVertex[2].tu = 1.f; + m_TimeSpeedIconVertex[2].tv = 0.f; + + m_TimeSpeedIconVertex[3].pos.x = static_cast(m_nTimeSpeedIconLeft + m_nTimeSpeedIconWidth); + m_TimeSpeedIconVertex[3].pos.y = static_cast(m_nTimeSpeedIconUp + m_nTimeSpeedIconHeight); + m_TimeSpeedIconVertex[3].tu = 1.f ; + m_TimeSpeedIconVertex[3].tv = 1.f ; + + //level up + //backimage + pA = AttributesPointer->GetAttributeClass("levelupback"); + if (pA != nullptr) + { + m_idLUBackTexture = rs->TextureCreate(pA->GetAttribute("texturename")); + m_nLUBackWidth = pA->GetAttributeAsDword("width", 64); + m_nLUBackHeight = pA->GetAttributeAsDword("height", 64); + m_nLUBackLeft = pA->GetAttributeAsDword("left", 0); + m_nLUBackUp = pA->GetAttributeAsDword("top", 0); + m_dwLUBackColor = pA->GetAttributeAsDword("color", 0x00FFFFFF); + } + else + { + m_idLUBackTexture = -1L; + m_nLUBackWidth = 64; + m_nLUBackHeight = 64; + m_nLUBackLeft = 0; + m_nLUBackUp = 0; + m_dwLUBackColor = 0x00FFFFFF; + } + + m_LUBackVertex[0].w = m_LUBackVertex[1].w = m_LUBackVertex[2].w = m_LUBackVertex[3].w = .5f; + m_LUBackVertex[0].pos.z = m_LUBackVertex[1].pos.z = m_LUBackVertex[2].pos.z = m_LUBackVertex[3].pos.z = 1.f; + m_LUBackVertex[0].col = m_LUBackVertex[1].col = m_LUBackVertex[2].col = m_LUBackVertex[3].col = m_dwLUBackColor; + m_LUBackVertex[0].pos.x = static_cast(m_nLUBackLeft); + m_LUBackVertex[0].pos.y = static_cast(m_nLUBackUp); + m_LUBackVertex[0].tu = 0.f; + m_LUBackVertex[0].tv = 0.f; + + m_LUBackVertex[1].pos.x = static_cast(m_nLUBackLeft); + m_LUBackVertex[1].pos.y = static_cast(m_nLUBackUp + m_nLUBackHeight); + m_LUBackVertex[1].tu = 0.f; + m_LUBackVertex[1].tv = 1.f ; + + m_LUBackVertex[2].pos.x = static_cast(m_nLUBackLeft + m_nLUBackWidth); + m_LUBackVertex[2].pos.y = static_cast(m_nLUBackUp); + m_LUBackVertex[2].tu = 1.f; + m_LUBackVertex[2].tv = 0.f; + + m_LUBackVertex[3].pos.x = static_cast(m_nLUBackLeft + m_nLUBackWidth); + m_LUBackVertex[3].pos.y = static_cast(m_nLUBackUp + m_nLUBackHeight); + m_LUBackVertex[3].tu = 1.f ; + m_LUBackVertex[3].tv = 1.f ; + + //string + pA = AttributesPointer->GetAttributeClass("levelupstring"); + if (pA != nullptr) + { + m_nLUStringLeft = pA->GetAttributeAsDword("left", -1); + m_fLUStringSpeed = pA->GetAttributeAsFloat("color_speed", 1.f / 50.f); + m_nLUStringUp = pA->GetAttributeAsDword("up", 0); + m_LUStringfontID = rs->LoadFont(pA->GetAttribute("font")); + m_fLUStringFontScale = pA->GetAttributeAsFloat("fontscale", 1.f); + m_dwLUStringColor = pA->GetAttributeAsDword("color", 0x00FFFFFF); + } + else + { + + m_nLUStringLeft = 64; + m_nLUStringUp = 0; + m_LUStringfontID = -1L; + m_fLUStringFontScale = 1.f; + m_dwLUStringColor = 0x00FFFFFF; + m_fLUStringSpeed = 1.f / 50.f; + } + + //rank + pA = AttributesPointer->GetAttributeClass("leveluprank"); + if (pA != nullptr) + { + m_nLURankLeft = pA->GetAttributeAsDword("left", -1); + m_nLURankUp = pA->GetAttributeAsDword("up", 0); + m_LURankfontID = rs->LoadFont(pA->GetAttribute("font")); + m_fLURankFontScale = pA->GetAttributeAsFloat("fontscale", 1.f); + m_dwLURankColor = pA->GetAttributeAsDword("color", 0x00FFFFFF); + } + else + { + + m_nLURankLeft = 64; + m_nLURankUp = 0; + m_LURankfontID = -1L; + m_fLURankFontScale = 1.f; + m_dwLURankColor = 0x00FFFFFF; + } + + AlphaLU = 0.f; } void ILogAndActions::ActionChange(bool bFastComShow, bool bLogStringShow) @@ -395,11 +1023,70 @@ void ILogAndActions::ActionChange(bool bFastComShow, bool bLogStringShow) m_IconVertex[2].tu = m_IconVertex[3].tu = 1.f / static_cast(m_horzDiv); m_IconVertex[0].tv = m_IconVertex[2].tv = 0.f; m_IconVertex[1].tv = m_IconVertex[3].tv = 1.f / static_cast(m_vertDiv); + + //backimage + pA = AttributesPointer->GetAttributeClass("ActiveActionsBack"); + if (pA != nullptr) + { + m_idActionBackTexture = rs->TextureCreate(pA->GetAttribute("TextureName")); + m_nActionBackWidth = pA->GetAttributeAsDword("width", 64); + m_nActionBackHeight = pA->GetAttributeAsDword("height", 64); + m_nActionBackCentr = pA->GetAttributeAsDword("centr", 0); + m_nActionBackUp = pA->GetAttributeAsDword("top", 0); + m_dwActionBackColor = pA->GetAttributeAsDword("color", 0x00FFFFFF); + } + else + { + m_idActionBackTexture = -1L; + m_nActionBackWidth = 64; + m_nActionBackHeight = 64; + m_nActionBackCentr = 0; + m_nActionBackUp = 0; + m_dwActionBackColor = 0x00FFFFFF; + } + + m_ActionBackVertex[0].w = m_ActionBackVertex[1].w = m_ActionBackVertex[2].w = m_ActionBackVertex[3].w = .5f; + m_ActionBackVertex[0].pos.z = m_ActionBackVertex[1].pos.z = m_ActionBackVertex[2].pos.z = m_ActionBackVertex[3].pos.z = 1.f; + m_ActionBackVertex[0].col = m_ActionBackVertex[1].col = m_ActionBackVertex[2].col = m_ActionBackVertex[3].col = m_dwActionBackColor; + m_ActionBackVertex[0].pos.x = static_cast(m_nActionBackCentr); + m_ActionBackVertex[0].pos.y = static_cast(m_nActionBackUp); + m_ActionBackVertex[0].tu = 0.f; + m_ActionBackVertex[0].tv = 0.f; + + m_ActionBackVertex[1].pos.x = static_cast(m_nActionBackCentr); + m_ActionBackVertex[1].pos.y = static_cast(m_nActionBackUp + m_nActionBackHeight); + m_ActionBackVertex[1].tu = 0.f; + m_ActionBackVertex[1].tv = 1.f ; + + m_ActionBackVertex[2].pos.x = static_cast(m_nActionBackCentr + m_nActionBackWidth); + m_ActionBackVertex[2].pos.y = static_cast(m_nActionBackUp); + m_ActionBackVertex[2].tu = 1.f; + m_ActionBackVertex[2].tv = 0.f; + + m_ActionBackVertex[3].pos.x = static_cast(m_nActionBackCentr + m_nActionBackWidth); + m_ActionBackVertex[3].pos.y = static_cast(m_nActionBackUp + m_nActionBackHeight); + m_ActionBackVertex[3].tu = 1.f ; + m_ActionBackVertex[3].tv = 1.f ; + + const int32_t nOffset = rs->StringWidth(m_ActionHint2.sText.c_str(), m_ActionHint2.nFont, m_ActionHint2.fScale, 0); + m_ActionBackVertex[0].pos.x = static_cast(m_nActionBackCentr) - static_cast(nOffset/2) - static_cast(m_nActionBackWidth); + + m_ActionBackVertex[1].pos.x = static_cast(m_nActionBackCentr) - static_cast(nOffset/2) - static_cast(m_nActionBackWidth); + + m_ActionBackVertex[2].pos.x = static_cast(m_nActionBackCentr) + static_cast(nOffset/2) + static_cast(m_nActionBackWidth); + + m_ActionBackVertex[3].pos.x = static_cast(m_nActionBackCentr) + static_cast(nOffset/2) + static_cast(m_nActionBackWidth); } void ILogAndActions::Release() { TEXTURE_RELEASE(rs, m_idIconTexture); + TEXTURE_RELEASE(rs, m_idPicInfoBackTexture); + TEXTURE_RELEASE(rs, m_idPicInfoIconTexture); + TEXTURE_RELEASE(rs, m_idTimeSpeedIconTexture); + TEXTURE_RELEASE(rs, m_idLUBackTexture); + TEXTURE_RELEASE(rs, m_idActionBackTexture); + rs->UnloadFont(m_fontID); while (m_sRoot != nullptr) @@ -409,9 +1096,25 @@ void ILogAndActions::Release() STORM_DELETE(p->str); delete p; } + + rs->UnloadFont(m_PicInfofontID); + while (m_pRoot != nullptr) + { + STRING_DESCR *pp = m_pRoot; + m_pRoot = pp->next; + STORM_DELETE(pp->str); + delete pp; + } + + rs->UnloadFont(m_TimeSpeedfontID); + m_ActionHint1.Release(); m_ActionHint2.Release(); rs = nullptr; + + PIstage = 0; + + bShowTimeSpeed = false; } void ILogAndActions::SetString(const char *str, bool immortal) @@ -445,7 +1148,7 @@ void ILogAndActions::SetString(const char *str, bool immortal) } strcpy_s(newDescr->str, len, str); // set the maximum visibility - if (immortal) + if (immortal) newDescr->alpha = 10000.f; else newDescr->alpha = 255.f; @@ -480,6 +1183,149 @@ void ILogAndActions::SetString(const char *str, bool immortal) } } +void ILogAndActions::SetPicInfo(const char *str) +{ + if (str == nullptr) + return; + + // find the last element of the list + STRING_DESCR *last = m_pRoot; + if (last != nullptr) + while (last->next != nullptr) + last = last->next; + + // Return if such a line already exists and it is last + if (last != nullptr && last->str != nullptr && storm::iEquals(last->str, str)) + return; + + PIstage++; + FRECT texRect; + if(PIstage == 1) + { + if(AlphaBI < 0.1f) + { + AlphaBI = 255.f; + m_PicInfoBackVertex[0].col = m_PicInfoBackVertex[1].col = m_PicInfoBackVertex[2].col = m_PicInfoBackVertex[3].col = m_dwPicInfoMaxColor; + m_PicInfoIconVertex[0].col = m_PicInfoIconVertex[1].col = m_PicInfoIconVertex[2].col = m_PicInfoIconVertex[3].col = m_dwPicInfoMaxColor; + + + CalculateTexturePos(texRect, m_nPicInfoIconhorzDiv, m_nPicInfoIconvertDiv, m_nPicInfoIconIndex); + + m_PicInfoIconVertex[0].tu = texRect.left; + m_PicInfoIconVertex[0].tv = texRect.top; + + m_PicInfoIconVertex[1].tu = texRect.left; + m_PicInfoIconVertex[1].tv = texRect.bottom; + + m_PicInfoIconVertex[2].tu = texRect.right; + m_PicInfoIconVertex[2].tv = texRect.top; + + m_PicInfoIconVertex[3].tu = texRect.right; + m_PicInfoIconVertex[3].tv = texRect.bottom; + } + } + + if(PIstage == 2) + { + if(AlphaBI2 < 0.1f) + { + AlphaBI2 = 255.f; + m_PicInfoBackVertex1[0].col = m_PicInfoBackVertex1[1].col = m_PicInfoBackVertex1[2].col = m_PicInfoBackVertex1[3].col = m_dwPicInfoMaxColor; + m_PicInfoIconVertex1[0].col = m_PicInfoIconVertex1[1].col = m_PicInfoIconVertex1[2].col = m_PicInfoIconVertex1[3].col = m_dwPicInfoMaxColor; + + CalculateTexturePos(texRect, m_nPicInfoIconhorzDiv, m_nPicInfoIconvertDiv, m_nPicInfoIconIndex); + + m_PicInfoIconVertex1[0].tu = texRect.left; + m_PicInfoIconVertex1[0].tv = texRect.top; + + m_PicInfoIconVertex1[1].tu = texRect.left; + m_PicInfoIconVertex1[1].tv = texRect.bottom; + + m_PicInfoIconVertex1[2].tu = texRect.right; + m_PicInfoIconVertex1[2].tv = texRect.top; + + m_PicInfoIconVertex1[3].tu = texRect.right; + m_PicInfoIconVertex1[3].tv = texRect.bottom; + } + } + + if(PIstage == 3) + { + if(AlphaBI3 < 0.1f) + { + AlphaBI3 = 255.f; + m_PicInfoBackVertex2[0].col = m_PicInfoBackVertex2[1].col = m_PicInfoBackVertex2[2].col = m_PicInfoBackVertex2[3].col = m_dwPicInfoMaxColor; + m_PicInfoIconVertex2[0].col = m_PicInfoIconVertex2[1].col = m_PicInfoIconVertex2[2].col = m_PicInfoIconVertex2[3].col = m_dwPicInfoMaxColor; + + CalculateTexturePos(texRect, m_nPicInfoIconhorzDiv, m_nPicInfoIconvertDiv, m_nPicInfoIconIndex); + + m_PicInfoIconVertex2[0].tu = texRect.left; + m_PicInfoIconVertex2[0].tv = texRect.top; + + m_PicInfoIconVertex2[1].tu = texRect.left; + m_PicInfoIconVertex2[1].tv = texRect.bottom; + + m_PicInfoIconVertex2[2].tu = texRect.right; + m_PicInfoIconVertex2[2].tv = texRect.top; + + m_PicInfoIconVertex2[3].tu = texRect.right; + m_PicInfoIconVertex2[3].tv = texRect.bottom; + } + } + // create a new line descriptor + auto *newDescr = new STRING_DESCR; + if (newDescr == nullptr) + { + throw std::runtime_error("Allocate memory error"); + } + // it will be the last on the list + newDescr->next = nullptr; + // add the specified string to it + const auto len = strlen(str) + 1; + if ((newDescr->str = new char[len]) == nullptr) + { + throw std::runtime_error("Allocate memory error"); + } + strcpy_s(newDescr->str, len, str); + // set the maximum visibility + newDescr->alpha = 255.f; + + // if the list is empty, put the string as the root + if (last == nullptr) + { + newDescr->offset = static_cast(m_nPicInfoStringBegin); + m_pRoot = newDescr; + } + // otherwise add it to the end of the list + else + { + newDescr->offset = last->offset + m_nPicInfoStringOffset; + last->next = newDescr; + if (newDescr->offset + m_nPicInfoStringOffset > m_nPicInfoWindowHeight) + { + const int32_t offsetDelta = static_cast(newDescr->offset) + m_nPicInfoStringOffset - m_nPicInfoWindowHeight; + for (STRING_DESCR *tmpDescr = m_pRoot; tmpDescr != nullptr;) + { + if ((tmpDescr->offset -= offsetDelta) < 0) + { + m_pRoot = tmpDescr->next; + STORM_DELETE(tmpDescr->str); + delete tmpDescr; + tmpDescr = m_pRoot; + continue; + } + tmpDescr = tmpDescr->next; + } + } + } + +} + +void ILogAndActions::SetLevelUp() +{ + AlphaLU = 255.f; +} + void ILogAndActions::SetAction(const char *actionName) { ATTRIBUTES *pA; @@ -523,4 +1369,14 @@ void ILogAndActions::SetAction(const char *actionName) m_ActionHint1.Init(rs, nullptr); m_ActionHint2.Init(rs, nullptr); } + + const int32_t nOffset = rs->StringWidth(m_ActionHint2.sText.c_str(), m_ActionHint2.nFont, m_ActionHint2.fScale, 0); + m_ActionBackVertex[0].pos.x = static_cast(m_nActionBackCentr) - static_cast(nOffset/2) - static_cast(m_nActionBackWidth); + + m_ActionBackVertex[1].pos.x = static_cast(m_nActionBackCentr) - static_cast(nOffset/2) - static_cast(m_nActionBackWidth); + + m_ActionBackVertex[2].pos.x = static_cast(m_nActionBackCentr) + static_cast(nOffset/2) + static_cast(m_nActionBackWidth); + + m_ActionBackVertex[3].pos.x = static_cast(m_nActionBackCentr) + static_cast(nOffset/2) + static_cast(m_nActionBackWidth); + } diff --git a/src/libs/battle_interface/src/log_and_action.h b/src/libs/battle_interface/src/log_and_action.h new file mode 100644 index 000000000..79cad8a42 --- /dev/null +++ b/src/libs/battle_interface/src/log_and_action.h @@ -0,0 +1,205 @@ +#pragma once + +#include "bi_utils.h" + +class ILogAndActions : public Entity +{ + VDX9RENDER *rs; + + struct STRING_DESCR + { + char *str; + float offset; + float alpha; + STRING_DESCR *next; + }; + + public: + ILogAndActions(ILogAndActions &&) = delete; + ILogAndActions(const ILogAndActions &) = delete; + ILogAndActions(); + ~ILogAndActions() override; + bool Init() override; + void Execute(uint32_t delta_time); + void Realize(uint32_t delta_time); + uint64_t ProcessMessage(MESSAGE &message) override; + + void ProcessStage(Stage stage, uint32_t delta) override + { + switch (stage) + { + case Stage::execute: + Execute(delta); + break; + case Stage::realize: + Realize(delta); + break; + /*case Stage::lost_render: + LostRender(delta); break; + case Stage::restore_render: + RestoreRender(delta); break;*/ + } + } + + protected: + void Create(bool bFastComShow, bool bLogStringShow); + void ActionChange(bool bFastComShow, bool bLogStringShow); + void Release(); + + void SetString(const char *str, bool immortal); + void SetPicInfo(const char *str); + void SetLevelUp(); + void SetAction(const char *actionName); + + protected: + // log stings parameters + // ----------------------- + int32_t m_nWindowWidth; // X window size + int32_t m_nWindowHeight; // Y window size + int32_t m_nWindowLeft; + int32_t m_nWindowRight; + int32_t m_nWindowUp; + int32_t m_fontID; + float m_fFontScale; + uint32_t m_dwColor; + int32_t m_nStringBegin; + int32_t m_nStringOffset; + float m_fShiftSpeed; + float m_fBlendSpeed; + STRING_DESCR *m_sRoot; + + // Action parameters + //------------------- + bool m_bThatRealAction; + int32_t m_nIconWidth; // X icon size + int32_t m_nIconHeight; // Y icon size + int32_t m_nIconLeft; + int32_t m_nIconUp; + int32_t m_idIconTexture; + int32_t m_horzDiv; + int32_t m_vertDiv; + BI_ONETEXTURE_VERTEX m_IconVertex[4]; + char m_sActionName[64]; + char m_sOldActionName[64]; + + bool m_bShowActiveCommand; + bool m_bShowLogStrings; + bool m_bDontShowAll; + + int32_t m_nTimeCounter; + + BITextInfo m_ActionHint1; + BITextInfo m_ActionHint2; + + // backimage for actions + int32_t m_nActionBackWidth; // X texture size + int32_t m_nActionBackHeight; // Y texture size + int32_t m_nActionBackCentr; + int32_t m_nActionBackUp; + int32_t m_idActionBackTexture; + uint32_t m_dwActionBackColor; + std::string ALtype; + BI_COLOR_VERTEX m_ActionBackVertex[4]; + + + + // pic info + // strings parameters----------------------- + int32_t m_nPicInfoWindowWidth; // X window size + int32_t m_nPicInfoWindowHeight; // Y window size + int32_t m_nPicInfoWindowLeft; + int32_t m_nPicInfoWindowRight; + int32_t m_nPicInfoWindowUp; + int32_t m_PicInfofontID; + float m_fPicInfoFontScale; + uint32_t m_dwPicInfoColor; + int32_t m_nPicInfoStringBegin; + int32_t m_nPicInfoStringOffset; + float m_fPicInfoShiftSpeed; + float m_fPicInfoBlendSpeed; + STRING_DESCR *m_pRoot; + + // backimage param + uint32_t m_dwPicInfoMaxColor; + uint32_t m_dwPicInfoMinColor; + int32_t m_nPicInfoBackWidth; // X texture size + int32_t m_nPicInfoBackHeight; // Y texture size + int32_t m_nPicInfoBackLeft; + int32_t m_nPicInfoBackUp; + int32_t m_idPicInfoBackTexture; + BI_COLOR_VERTEX m_PicInfoBackVertex[4]; + BI_COLOR_VERTEX m_PicInfoBackVertex1[4]; + BI_COLOR_VERTEX m_PicInfoBackVertex2[4]; + float AlphaBI; + float AlphaBI2; + float AlphaBI3; + + // icon param + int32_t m_nPicInfoIconWidth; // X texture size + int32_t m_nPicInfoIconHeight; // Y texture size + int32_t m_nPicInfoIconLeft; + int32_t m_nPicInfoIconUp; + int32_t m_idPicInfoIconTexture; + int32_t m_nPicInfoIconhorzDiv; + int32_t m_nPicInfoIconvertDiv; + int8_t m_nPicInfoIconIndex; + BI_COLOR_VERTEX m_PicInfoIconVertex[4]; + BI_COLOR_VERTEX m_PicInfoIconVertex1[4]; + BI_COLOR_VERTEX m_PicInfoIconVertex2[4]; + + int8_t PIstage; + + // time speed + // texture + bool bShowTimeSpeed; + int32_t m_nTimeSpeedIconWidth; // X icon size + int32_t m_nTimeSpeedIconHeight; // Y icon size + int32_t m_nTimeSpeedIconLeft; + //int32_t m_nTimeSpeedIconRight; + int32_t m_nTimeSpeedIconUp; + int32_t m_idTimeSpeedIconTexture; + uint32_t m_dwTimeSpeedIconColor; + BI_COLOR_VERTEX m_TimeSpeedIconVertex[4]; + // text + int32_t m_nTimeSpeedLeft; + //int32_t m_nTimeSpeedRight; + int32_t m_nTimeSpeedUp; + int32_t m_TimeSpeedfontID; + float m_fTimeSpeedFontScale; + uint32_t m_dwTimeSpeedColor; + std::string TimeSpeedText; + + + // level up + //backimage + uint32_t m_dwLUBackColor; + //uint32_t m_dwPicInfoMinColor; + int32_t m_nLUBackWidth; // X texture size + int32_t m_nLUBackHeight; // Y texture size + int32_t m_nLUBackLeft; + int32_t m_nLUBackUp; + int32_t m_idLUBackTexture; + BI_COLOR_VERTEX m_LUBackVertex[4]; + float AlphaLU; + + // string + int32_t m_nLUStringLeft; + int32_t m_nLUStringUp; + int32_t m_LUStringfontID; + float m_fLUStringFontScale; + uint32_t m_dwLUStringColor; + float m_fLUStringSpeed; + std::string LUStringText; + + //rank + int32_t m_nLURankLeft; + int32_t m_nLURankUp; + int32_t m_LURankfontID; + float m_fLURankFontScale; + uint32_t m_dwLURankColor; + //float m_fLURankSpeed; + std::string LURankText; + + + +}; diff --git a/src/libs/battle_interface/src/message_icons.cpp b/src/libs/battle_interface/src/message_icons.cpp index 7de51a666..4f21ae904 100644 --- a/src/libs/battle_interface/src/message_icons.cpp +++ b/src/libs/battle_interface/src/message_icons.cpp @@ -1,5 +1,5 @@ #include "message_icons.h" -#include "utils.h" +#include "bi_utils.h" MESSAGE_ICONS::MESSAGE_ICONS() { diff --git a/src/libs/battle_interface/include/message_icons.h b/src/libs/battle_interface/src/message_icons.h similarity index 100% rename from src/libs/battle_interface/include/message_icons.h rename to src/libs/battle_interface/src/message_icons.h diff --git a/src/libs/battle_interface/src/sea/battle_navigator.cpp b/src/libs/battle_interface/src/sea/battle_navigator.cpp index 35675f2f3..15437f62f 100644 --- a/src/libs/battle_interface/src/sea/battle_navigator.cpp +++ b/src/libs/battle_interface/src/sea/battle_navigator.cpp @@ -3,7 +3,7 @@ #include "core.h" -#include "utils.h" +#include "bi_utils.h" #include "entity.h" #include "island_base.h" #include "math_inlines.h" @@ -13,10 +13,10 @@ #define NAVBACKGROUND_SIZESCALE 1.3f -#define MAP_TEXTURE_WIDTH 256 -#define MAP_TEXTURE_HEIGHT 256 -#define BIGMAP_TEXTURE_WIDTH 1024 -#define BIGMAP_TEXTURE_HEIGHT 1024 +#define MAP_TEXTURE_WIDTH 4096 +#define MAP_TEXTURE_HEIGHT 4096 +#define BIGMAP_TEXTURE_WIDTH 4096 +#define BIGMAP_TEXTURE_HEIGHT 4096 inline bool FloatCompare(float a, float b) { @@ -154,19 +154,57 @@ void BATTLE_NAVIGATOR::Draw() const "%.1f", m_fShipSpeed); // show current charge - if (m_curCharge >= 0) + if (m_curBalls >= 0) { - rs->TextureSet(0, m_idChargeTexture); - rs->SetRenderState(D3DRS_TEXTUREFACTOR, (BIUtils::g_dwBlinkColor << 24L) | 0xFFFFFF); - rs->DrawPrimitive(D3DPT_TRIANGLESTRIP, m_idCurChargeVBuf, sizeof(BI_ONETEXTURE_VERTEX), 0, 2, - m_bNotEnoughBallFlag ? "battle_texure_blend_tf" : "battle_rectangle"); + rs->TextureSet(0, m_idBallsTexture); + rs->DrawPrimitive(D3DPT_TRIANGLESTRIP, m_idCurChargeVBuf, sizeof(BI_ONETEXTURE_VERTEX), 0, 2, "battle_rectangle"); + } + + if (m_curGrapes >= 0) + { + rs->TextureSet(0, m_idGrapesTexture); + rs->DrawPrimitive(D3DPT_TRIANGLESTRIP, m_idCurChargeVBuf, sizeof(BI_ONETEXTURE_VERTEX), 16, 2, "battle_rectangle"); + } + + if (m_curKnippels >= 0) + { + rs->TextureSet(0, m_idKnippelsTexture); + rs->DrawPrimitive(D3DPT_TRIANGLESTRIP, m_idCurChargeVBuf, sizeof(BI_ONETEXTURE_VERTEX), 20, 2, "battle_rectangle"); + } + + if (m_curBombs >= 0) + { + rs->TextureSet(0, m_idBombsTexture); + rs->DrawPrimitive(D3DPT_TRIANGLESTRIP, m_idCurChargeVBuf, sizeof(BI_ONETEXTURE_VERTEX), 24, 2, "battle_rectangle"); } if (m_idPowderTexture >= 0 && m_curPowder >= 0) { rs->TextureSet(0, m_idPowderTexture); - rs->SetRenderState(D3DRS_TEXTUREFACTOR, (BIUtils::g_dwBlinkColor << 24L) | 0xFFFFFF); - rs->DrawPrimitive(D3DPT_TRIANGLESTRIP, m_idCurChargeVBuf, sizeof(BI_ONETEXTURE_VERTEX), 12, 2, - m_bPowderRunOut ? "battle_texure_blend_tf" : "battle_rectangle"); + rs->DrawPrimitive(D3DPT_TRIANGLESTRIP, m_idCurChargeVBuf, sizeof(BI_ONETEXTURE_VERTEX), 12, 2, "battle_rectangle"); + } + + if (m_curWeapon >= 0) + { + rs->TextureSet(0, m_idWeaponTexture); + rs->DrawPrimitive(D3DPT_TRIANGLESTRIP, m_idCurChargeVBuf, sizeof(BI_ONETEXTURE_VERTEX), 28, 2, "battle_rectangle"); + } + + if (m_curSailcloth >= 0) + { + rs->TextureSet(0, m_idSailclothTexture); + rs->DrawPrimitive(D3DPT_TRIANGLESTRIP, m_idCurChargeVBuf, sizeof(BI_ONETEXTURE_VERTEX), 32, 2, "battle_rectangle"); + } + + if (m_curPlanks >= 0) + { + rs->TextureSet(0, m_idPlanksTexture); + rs->DrawPrimitive(D3DPT_TRIANGLESTRIP, m_idCurChargeVBuf, sizeof(BI_ONETEXTURE_VERTEX), 36, 2, "battle_rectangle"); + } + + if (m_curCannonsG >= 0) + { + rs->TextureSet(0, m_idCannonsGTexture); + rs->DrawPrimitive(D3DPT_TRIANGLESTRIP, m_idCurChargeVBuf, sizeof(BI_ONETEXTURE_VERTEX), 40, 2, "battle_rectangle"); } // show wind icon rs->TextureSet(0, m_idWindTexture); @@ -213,87 +251,79 @@ void BATTLE_NAVIGATOR::Update() if (!FloatCompare(m_fCurAnglLeftCharge, m_fCurAnglLeftDamage)) { - SetRectangleSegVertexPos(pV, static_cast(m_XNavigator), static_cast(m_YNavigator), - static_cast(m_NavigationWidth), static_cast(m_NavigationWidth), + SetRectangleSegVertexPos(pV, static_cast(m_CannonsChargePos.x), static_cast(m_CannonsChargePos.y), + static_cast(m_CannonsChargeSize.x), static_cast(m_CannonsChargeSize.y), m_fBegAnglLeftCharge, m_fCurAnglLeftCharge); m_nvCannonCharge = SetRectangleSegVertexTex(pV, .5f, .5f, 1.f, 1.f, m_fBegAnglLeftCharge, m_fCurAnglLeftCharge); } if (!FloatCompare(m_fCurAnglRightCharge, m_fCurAnglRightDamage)) { - SetRectangleSegVertexPos(&pV[m_nvCannonCharge], static_cast(m_XNavigator), - static_cast(m_YNavigator), static_cast(m_NavigationWidth), - static_cast(m_NavigationWidth), m_fCurAnglRightCharge, + SetRectangleSegVertexPos(&pV[m_nvCannonCharge], static_cast(m_CannonsChargePos.x), static_cast(m_CannonsChargePos.y), + static_cast(m_CannonsChargeSize.x), static_cast(m_CannonsChargeSize.y), m_fCurAnglRightCharge, m_fBegAnglRightCharge); m_nvCannonCharge += SetRectangleSegVertexTex(&pV[m_nvCannonCharge], .5f, .5f, 1.f, 1.f, m_fCurAnglRightCharge, m_fBegAnglRightCharge); } if (!FloatCompare(m_fCurAnglForwardCharge, m_fCurAnglForwardDamage)) { - SetRectangleSegVertexPos(&pV[m_nvCannonCharge], static_cast(m_XNavigator), - static_cast(m_YNavigator), static_cast(m_NavigationWidth), - static_cast(m_NavigationWidth), m_fBegAnglForwardCharge, + SetRectangleSegVertexPos(&pV[m_nvCannonCharge], static_cast(m_CannonsChargePos.x), static_cast(m_CannonsChargePos.y), + static_cast(m_CannonsChargeSize.x), static_cast(m_CannonsChargeSize.y), m_fBegAnglForwardCharge, m_fCurAnglForwardCharge); m_nvCannonCharge += SetRectangleSegVertexTex(&pV[m_nvCannonCharge], .5f, .5f, 1.f, 1.f, m_fBegAnglForwardCharge, m_fCurAnglForwardCharge); } if (!FloatCompare(m_fCurAnglBackCharge, m_fCurAnglBackDamage)) { - SetRectangleSegVertexPos(&pV[m_nvCannonCharge], static_cast(m_XNavigator), - static_cast(m_YNavigator), static_cast(m_NavigationWidth), - static_cast(m_NavigationWidth), m_fCurAnglBackCharge, m_fBegAnglBackCharge); + SetRectangleSegVertexPos(&pV[m_nvCannonCharge], static_cast(m_CannonsChargePos.x), static_cast(m_CannonsChargePos.y), + static_cast(m_CannonsChargeSize.x), static_cast(m_CannonsChargeSize.y), m_fCurAnglBackCharge, m_fBegAnglBackCharge); m_nvCannonCharge += SetRectangleSegVertexTex(&pV[m_nvCannonCharge], .5f, .5f, 1.f, 1.f, m_fCurAnglBackCharge, m_fBegAnglBackCharge); } if (FloatCompare(m_fCurAnglLeftCharge, m_fCurAnglLeftDamage)) { - SetRectangleSegVertexPos(&pV[m_nvCannonCharge], static_cast(m_XNavigator), - static_cast(m_YNavigator), static_cast(m_NavigationWidth), - static_cast(m_NavigationWidth), m_fBegAnglLeftCharge, m_fCurAnglLeftCharge); + SetRectangleSegVertexPos(&pV[m_nvCannonCharge], static_cast(m_CannonsChargePos.x), static_cast(m_CannonsChargePos.y), + static_cast(m_CannonsChargeSize.x), static_cast(m_CannonsChargeSize.y), m_fBegAnglLeftCharge, m_fCurAnglLeftCharge); m_nvCannonReady = SetRectangleSegVertexTex(&pV[m_nvCannonCharge], .5f, .5f, 1.f, 1.f, m_fBegAnglLeftCharge, m_fCurAnglLeftCharge); } if (FloatCompare(m_fCurAnglRightCharge, m_fCurAnglRightDamage)) { - SetRectangleSegVertexPos(&pV[m_nvCannonCharge + m_nvCannonReady], static_cast(m_XNavigator), - static_cast(m_YNavigator), static_cast(m_NavigationWidth), - static_cast(m_NavigationWidth), m_fCurAnglRightCharge, + SetRectangleSegVertexPos(&pV[m_nvCannonCharge + m_nvCannonReady], static_cast(m_CannonsChargePos.x), static_cast(m_CannonsChargePos.y), + static_cast(m_CannonsChargeSize.x), static_cast(m_CannonsChargeSize.y), m_fCurAnglRightCharge, m_fBegAnglRightCharge); m_nvCannonReady += SetRectangleSegVertexTex(&pV[m_nvCannonCharge + m_nvCannonReady], .5f, .5f, 1.f, 1.f, m_fCurAnglRightCharge, m_fBegAnglRightCharge); } if (FloatCompare(m_fCurAnglForwardCharge, m_fCurAnglForwardDamage)) { - SetRectangleSegVertexPos(&pV[m_nvCannonCharge + m_nvCannonReady], static_cast(m_XNavigator), - static_cast(m_YNavigator), static_cast(m_NavigationWidth), - static_cast(m_NavigationWidth), m_fBegAnglForwardCharge, + SetRectangleSegVertexPos(&pV[m_nvCannonCharge + m_nvCannonReady], static_cast(m_CannonsChargePos.x), static_cast(m_CannonsChargePos.y), + static_cast(m_CannonsChargeSize.x), static_cast(m_CannonsChargeSize.y), m_fBegAnglForwardCharge, m_fCurAnglForwardCharge); m_nvCannonReady += SetRectangleSegVertexTex(&pV[m_nvCannonCharge + m_nvCannonReady], .5f, .5f, 1.f, 1.f, m_fBegAnglForwardCharge, m_fCurAnglForwardCharge); } if (FloatCompare(m_fCurAnglBackCharge, m_fCurAnglBackDamage)) { - SetRectangleSegVertexPos(&pV[m_nvCannonCharge + m_nvCannonReady], static_cast(m_XNavigator), - static_cast(m_YNavigator), static_cast(m_NavigationWidth), - static_cast(m_NavigationWidth), m_fCurAnglBackCharge, m_fBegAnglBackCharge); + SetRectangleSegVertexPos(&pV[m_nvCannonCharge + m_nvCannonReady], static_cast(m_CannonsChargePos.x), static_cast(m_CannonsChargePos.y), + static_cast(m_CannonsChargeSize.x), static_cast(m_CannonsChargeSize.y), m_fCurAnglBackCharge, m_fBegAnglBackCharge); m_nvCannonReady += SetRectangleSegVertexTex(&pV[m_nvCannonCharge + m_nvCannonReady], .5f, .5f, 1.f, 1.f, m_fCurAnglBackCharge, m_fBegAnglBackCharge); } if (!FloatCompare(m_fCurAnglLeftDamage, m_fEndAnglLeftCharge)) { - SetRectangleSegVertexPos(&pV[m_nvCannonCharge + m_nvCannonReady], static_cast(m_XNavigator), - static_cast(m_YNavigator), static_cast(m_NavigationWidth), - static_cast(m_NavigationWidth), m_fCurAnglLeftDamage, m_fEndAnglLeftCharge); + SetRectangleSegVertexPos(&pV[m_nvCannonCharge + m_nvCannonReady], static_cast(m_CannonsChargePos.x), static_cast(m_CannonsChargePos.y), + static_cast(m_CannonsChargeSize.x), static_cast(m_CannonsChargeSize.y), m_fCurAnglLeftDamage, m_fEndAnglLeftCharge); m_nvCannonDamage = SetRectangleSegVertexTex(&pV[m_nvCannonCharge + m_nvCannonReady], .5f, .5f, 1.f, 1.f, m_fCurAnglLeftDamage, m_fEndAnglLeftCharge); } if (!FloatCompare(m_fCurAnglRightDamage, m_fEndAnglRightCharge)) { SetRectangleSegVertexPos(&pV[m_nvCannonCharge + m_nvCannonReady + m_nvCannonDamage], - static_cast(m_XNavigator), static_cast(m_YNavigator), - static_cast(m_NavigationWidth), static_cast(m_NavigationWidth), + static_cast(m_CannonsChargePos.x), static_cast(m_CannonsChargePos.y), + static_cast(m_CannonsChargeSize.x), static_cast(m_CannonsChargeSize.y), m_fEndAnglRightCharge, m_fCurAnglRightDamage); m_nvCannonDamage += SetRectangleSegVertexTex(&pV[m_nvCannonCharge + m_nvCannonReady + m_nvCannonDamage], .5f, .5f, 1.f, 1.f, @@ -302,8 +332,8 @@ void BATTLE_NAVIGATOR::Update() if (!FloatCompare(m_fCurAnglForwardDamage, m_fEndAnglForwardCharge)) { SetRectangleSegVertexPos(&pV[m_nvCannonCharge + m_nvCannonReady + m_nvCannonDamage], - static_cast(m_XNavigator), static_cast(m_YNavigator), - static_cast(m_NavigationWidth), static_cast(m_NavigationWidth), + static_cast(m_CannonsChargePos.x), static_cast(m_CannonsChargePos.y), + static_cast(m_CannonsChargeSize.x), static_cast(m_CannonsChargeSize.y), m_fCurAnglForwardDamage, m_fEndAnglForwardCharge); m_nvCannonDamage += SetRectangleSegVertexTex(&pV[m_nvCannonCharge + m_nvCannonReady + m_nvCannonDamage], .5f, .5f, 1.f, 1.f, @@ -312,8 +342,8 @@ void BATTLE_NAVIGATOR::Update() if (!FloatCompare(m_fCurAnglBackDamage, m_fEndAnglBackCharge)) { SetRectangleSegVertexPos(&pV[m_nvCannonCharge + m_nvCannonReady + m_nvCannonDamage], - static_cast(m_XNavigator), static_cast(m_YNavigator), - static_cast(m_NavigationWidth), static_cast(m_NavigationWidth), + static_cast(m_CannonsChargePos.x), static_cast(m_CannonsChargePos.y), + static_cast(m_CannonsChargeSize.x), static_cast(m_CannonsChargeSize.y), m_fEndAnglBackCharge, m_fCurAnglBackDamage); m_nvCannonDamage += SetRectangleSegVertexTex(&pV[m_nvCannonCharge + m_nvCannonReady + m_nvCannonDamage], .5f, .5f, 1.f, 1.f, @@ -510,11 +540,29 @@ void BATTLE_NAVIGATOR::Init(VDX9RENDER *RenderService, Entity *pOwnerEI) else m_idBestCourseTex = rs->TextureCreate(tmpstr); - tmpstr = BIUtils::GetStringFromAttr(pARoot, "chargeTexture", nullptr); + tmpstr = BIUtils::GetStringFromAttr(pARoot, "BallsTexture", nullptr); + if (tmpstr == nullptr) + m_idBallsTexture = -1; + else + m_idBallsTexture = rs->TextureCreate(tmpstr); + + tmpstr = BIUtils::GetStringFromAttr(pARoot, "GrapesTexture", nullptr); if (tmpstr == nullptr) - m_idChargeTexture = -1; + m_idGrapesTexture = -1; else - m_idChargeTexture = rs->TextureCreate(tmpstr); + m_idGrapesTexture = rs->TextureCreate(tmpstr); + + tmpstr = BIUtils::GetStringFromAttr(pARoot, "KnippelsTexture", nullptr); + if (tmpstr == nullptr) + m_idKnippelsTexture = -1; + else + m_idKnippelsTexture = rs->TextureCreate(tmpstr); + + tmpstr = BIUtils::GetStringFromAttr(pARoot, "BombsTexture", nullptr); + if (tmpstr == nullptr) + m_idBombsTexture = -1; + else + m_idBombsTexture = rs->TextureCreate(tmpstr); tmpstr = BIUtils::GetStringFromAttr(pARoot, "powderTexture", nullptr); if (tmpstr == nullptr) @@ -522,6 +570,30 @@ void BATTLE_NAVIGATOR::Init(VDX9RENDER *RenderService, Entity *pOwnerEI) else m_idPowderTexture = rs->TextureCreate(tmpstr); + tmpstr = BIUtils::GetStringFromAttr(pARoot, "WeaponTexture", nullptr); + if (tmpstr == nullptr) + m_idWeaponTexture = -1; + else + m_idWeaponTexture = rs->TextureCreate(tmpstr); + + tmpstr = BIUtils::GetStringFromAttr(pARoot, "PlanksTexture", nullptr); + if (tmpstr == nullptr) + m_idPlanksTexture = -1; + else + m_idPlanksTexture = rs->TextureCreate(tmpstr); + + tmpstr = BIUtils::GetStringFromAttr(pARoot, "SailclothTexture", nullptr); + if (tmpstr == nullptr) + m_idSailclothTexture = -1; + else + m_idSailclothTexture = rs->TextureCreate(tmpstr); + + tmpstr = BIUtils::GetStringFromAttr(pARoot, "CannonsGTexture", nullptr); + if (tmpstr == nullptr) + m_idCannonsGTexture = -1; + else + m_idCannonsGTexture = rs->TextureCreate(tmpstr); + tmpstr = BIUtils::GetStringFromAttr(pARoot, "sailstateTexture", nullptr); if (tmpstr == nullptr) m_idSailTexture = -1; @@ -551,6 +623,15 @@ void BATTLE_NAVIGATOR::Init(VDX9RENDER *RenderService, Entity *pOwnerEI) m_fEndAnglBackCharge = static_cast(BIUtils::GetIntFromAttr(pARoot, "backwardChargeEndAngle", 0)) / 180.f * PI; + m_CannonsChargePos.x = m_XNavigator; + m_CannonsChargePos.y = m_YNavigator; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "CannonsChargePos", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_CannonsChargePos.x, &m_CannonsChargePos.y); + m_CannonsChargeSize.x = m_NavigationWidth; + m_CannonsChargeSize.y = m_NavigationWidth; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "CannonsChargePictureSize", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_CannonsChargeSize.x, &m_CannonsChargeSize.y); + // get speed angles m_fBegAnglShipSpeed = static_cast(BIUtils::GetIntFromAttr(pARoot, "shipSpeedBegAngle", 0)) / 180.f * PI; m_fCurAnglShipSpeed = m_fEndAnglShipSpeed = @@ -560,24 +641,74 @@ void BATTLE_NAVIGATOR::Init(VDX9RENDER *RenderService, Entity *pOwnerEI) static_cast(BIUtils::GetIntFromAttr(pARoot, "windSpeedEndAngle", 0)) / 180.f * PI; // current charge type - m_ChargeGreed.x = 1; - m_ChargeGreed.y = 1; - if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "chargeTextureGreed", nullptr)) != nullptr) - sscanf(tmpstr, "%d,%d", &m_ChargeGreed.x, &m_ChargeGreed.y); - if (m_ChargeGreed.x < 1) - m_ChargeGreed.x = 1; - if (m_ChargeGreed.y < 1) - m_ChargeGreed.y = 1; - m_ChargePos.x = 160; - m_ChargePos.y = 160; - if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "chargePos", nullptr)) != nullptr) - sscanf(tmpstr, "%d,%d", &m_ChargePos.x, &m_ChargePos.y); - m_ChargePos.x += m_XNavigator; // - m_NavigationWidth/2; - m_ChargePos.y += m_YNavigator; // - m_NavigationHeight/2; - m_ChargeSize.x = 32; - m_ChargeSize.y = 32; - if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "chargePictureSize", nullptr)) != nullptr) - sscanf(tmpstr, "%d,%d", &m_ChargeSize.x, &m_ChargeSize.y); + + m_BallsGreed.x = 1; + m_BallsGreed.y = 1; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "BallsTextureGreed", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_BallsGreed.x, &m_BallsGreed.y); + if (m_BallsGreed.x < 1) + m_BallsGreed.x = 1; + if (m_BallsGreed.y < 1) + m_BallsGreed.y = 1; + m_BallsPos.x = 160; + m_BallsPos.y = 160; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "BallsPos", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_BallsPos.x, &m_BallsPos.y); + m_BallsSize.x = 32; + m_BallsSize.y = 32; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "BallsPictureSize", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_BallsSize.x, &m_BallsSize.y); + + m_GrapesGreed.x = 1; + m_GrapesGreed.y = 1; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "GrapesTextureGreed", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_GrapesGreed.x, &m_GrapesGreed.y); + if (m_GrapesGreed.x < 1) + m_GrapesGreed.x = 1; + if (m_GrapesGreed.y < 1) + m_GrapesGreed.y = 1; + m_GrapesPos.x = 160; + m_GrapesPos.y = 160; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "GrapesPos", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_GrapesPos.x, &m_GrapesPos.y); + m_GrapesSize.x = 32; + m_GrapesSize.y = 32; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "GrapesPictureSize", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_GrapesSize.x, &m_GrapesSize.y); + + m_KnippelsGreed.x = 1; + m_KnippelsGreed.y = 1; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "KnippelsTextureGreed", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_KnippelsGreed.x, &m_KnippelsGreed.y); + if (m_KnippelsGreed.x < 1) + m_KnippelsGreed.x = 1; + if (m_KnippelsGreed.y < 1) + m_KnippelsGreed.y = 1; + m_KnippelsPos.x = 160; + m_KnippelsPos.y = 160; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "KnippelsPos", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_KnippelsPos.x, &m_KnippelsPos.y); + m_KnippelsSize.x = 32; + m_KnippelsSize.y = 32; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "KnippelsPictureSize", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_KnippelsSize.x, &m_KnippelsSize.y); + + m_BombsGreed.x = 1; + m_BombsGreed.y = 1; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "BombsTextureGreed", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_BombsGreed.x, &m_BombsGreed.y); + if (m_BombsGreed.x < 1) + m_BombsGreed.x = 1; + if (m_BombsGreed.y < 1) + m_BombsGreed.y = 1; + m_BombsPos.x = 160; + m_BombsPos.y = 160; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "BombsPos", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_BombsPos.x, &m_BombsPos.y); + m_BombsSize.x = 32; + m_BombsSize.y = 32; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "BombsPictureSize", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_BombsSize.x, &m_BombsSize.y); // powder m_PowderGreed.x = 1; @@ -592,13 +723,79 @@ void BATTLE_NAVIGATOR::Init(VDX9RENDER *RenderService, Entity *pOwnerEI) m_PowderPos.y = 160; if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "powderPos", nullptr)) != nullptr) sscanf(tmpstr, "%d,%d", &m_PowderPos.x, &m_PowderPos.y); - m_PowderPos.x += m_XNavigator; // - m_NavigationWidth/2; - m_PowderPos.y += m_YNavigator; // - m_NavigationHeight/2; m_PowderSize.x = 32; m_PowderSize.y = 32; if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "powderPictureSize", nullptr)) != nullptr) sscanf(tmpstr, "%d,%d", &m_PowderSize.x, &m_PowderSize.y); + m_WeaponGreed.x = 1; + m_WeaponGreed.y = 1; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "WeaponTextureGreed", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_WeaponGreed.x, &m_WeaponGreed.y); + if (m_WeaponGreed.x < 1) + m_WeaponGreed.x = 1; + if (m_WeaponGreed.y < 1) + m_WeaponGreed.y = 1; + m_WeaponPos.x = 160; + m_WeaponPos.y = 160; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "WeaponPos", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_WeaponPos.x, &m_WeaponPos.y); + m_WeaponSize.x = 32; + m_WeaponSize.y = 32; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "WeaponPictureSize", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_WeaponSize.x, &m_WeaponSize.y); + + m_SailclothGreed.x = 1; + m_SailclothGreed.y = 1; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "SailclothTextureGreed", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_SailclothGreed.x, &m_SailclothGreed.y); + if (m_SailclothGreed.x < 1) + m_SailclothGreed.x = 1; + if (m_SailclothGreed.y < 1) + m_SailclothGreed.y = 1; + m_SailclothPos.x = 160; + m_SailclothPos.y = 160; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "SailclothPos", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_SailclothPos.x, &m_SailclothPos.y); + m_SailclothSize.x = 32; + m_SailclothSize.y = 32; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "SailclothPictureSize", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_SailclothSize.x, &m_SailclothSize.y); + + m_PlanksGreed.x = 1; + m_PlanksGreed.y = 1; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "PlanksTextureGreed", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_PlanksGreed.x, &m_PlanksGreed.y); + if (m_PlanksGreed.x < 1) + m_PlanksGreed.x = 1; + if (m_PlanksGreed.y < 1) + m_PlanksGreed.y = 1; + m_PlanksPos.x = 160; + m_PlanksPos.y = 160; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "PlanksPos", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_PlanksPos.x, &m_PlanksPos.y); + m_PlanksSize.x = 32; + m_PlanksSize.y = 32; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "PlanksPictureSize", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_PlanksSize.x, &m_PlanksSize.y); + + m_CannonsGGreed.x = 1; + m_CannonsGGreed.y = 1; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "CannonsGTextureGreed", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_CannonsGGreed.x, &m_CannonsGGreed.y); + if (m_CannonsGGreed.x < 1) + m_CannonsGGreed.x = 1; + if (m_CannonsGGreed.y < 1) + m_CannonsGGreed.y = 1; + m_CannonsGPos.x = 160; + m_CannonsGPos.y = 160; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "CannonsGPos", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_CannonsGPos.x, &m_CannonsGPos.y); + m_CannonsGSize.x = 32; + m_CannonsGSize.y = 32; + if ((tmpstr = BIUtils::GetStringFromAttr(pARoot, "CannonsGPictureSize", nullptr)) != nullptr) + sscanf(tmpstr, "%d,%d", &m_CannonsGSize.x, &m_CannonsGSize.y); + // wind icon m_curSailState = 0; m_WindGreed.x = 1; @@ -780,13 +977,13 @@ void BATTLE_NAVIGATOR::Init(VDX9RENDER *RenderService, Entity *pOwnerEI) pV = static_cast(rs->LockVertexBuffer(m_idCurChargeVBuf)); if (pV != nullptr) { - for (i = 0; i < 4 * 4; i++) + for (i = 0; i < 4 * 11; i++) { pV[i].pos.z = 1.f; pV[i].w = .5f; } - SetRectangleVertexPos(&pV[0], static_cast(m_ChargePos.x), static_cast(m_ChargePos.y), - static_cast(m_ChargeSize.x), static_cast(m_ChargeSize.y)); + SetRectangleVertexPos(&pV[0], static_cast(m_BallsPos.x), static_cast(m_BallsPos.y), + static_cast(m_BallsSize.x), static_cast(m_BallsSize.y)); SetRectangleVertexPos(&pV[4], static_cast(m_WindPos.x), static_cast(m_WindPos.y), static_cast(m_WindSize.x), static_cast(m_WindSize.y)); SetRectangleVertexPos(&pV[8], static_cast(m_SailPos.x), static_cast(m_SailPos.y), @@ -794,6 +991,27 @@ void BATTLE_NAVIGATOR::Init(VDX9RENDER *RenderService, Entity *pOwnerEI) SetRectangleVertexPos(&pV[12], static_cast(m_PowderPos.x), static_cast(m_PowderPos.y), static_cast(m_PowderSize.x), static_cast(m_PowderSize.y)); rs->UnLockVertexBuffer(m_idCurChargeVBuf); + + SetRectangleVertexPos(&pV[16], static_cast(m_GrapesPos.x), static_cast(m_GrapesPos.y), + static_cast(m_GrapesSize.x), static_cast(m_GrapesSize.y)); + + SetRectangleVertexPos(&pV[20], static_cast(m_KnippelsPos.x), static_cast(m_KnippelsPos.y), + static_cast(m_KnippelsSize.x), static_cast(m_KnippelsSize.y)); + + SetRectangleVertexPos(&pV[24], static_cast(m_BombsPos.x), static_cast(m_BombsPos.y), + static_cast(m_BombsSize.x), static_cast(m_BombsSize.y)); + + SetRectangleVertexPos(&pV[28], static_cast(m_WeaponPos.x), static_cast(m_WeaponPos.y), + static_cast(m_WeaponSize.x), static_cast(m_WeaponSize.y)); + + SetRectangleVertexPos(&pV[32], static_cast(m_SailclothPos.x), static_cast(m_SailclothPos.y), + static_cast(m_SailclothSize.x), static_cast(m_SailclothSize.y)); + + SetRectangleVertexPos(&pV[36], static_cast(m_PlanksPos.x), static_cast(m_PlanksPos.y), + static_cast(m_PlanksSize.x), static_cast(m_PlanksSize.y)); + + SetRectangleVertexPos(&pV[40], static_cast(m_CannonsGPos.x), static_cast(m_CannonsGPos.y), + static_cast(m_CannonsGSize.x), static_cast(m_CannonsGSize.y)); } } @@ -1074,8 +1292,15 @@ void BATTLE_NAVIGATOR::ReleaseAll() TEXTURE_RELEASE(rs, m_idCannonTex); TEXTURE_RELEASE(rs, m_idEmptyTex); TEXTURE_RELEASE(rs, m_idIslandTexture); - TEXTURE_RELEASE(rs, m_idChargeTexture); + TEXTURE_RELEASE(rs, m_idBallsTexture); + TEXTURE_RELEASE(rs, m_idGrapesTexture); + TEXTURE_RELEASE(rs, m_idKnippelsTexture); + TEXTURE_RELEASE(rs, m_idBombsTexture); TEXTURE_RELEASE(rs, m_idPowderTexture); + TEXTURE_RELEASE(rs, m_idWeaponTexture); + TEXTURE_RELEASE(rs, m_idSailclothTexture); + TEXTURE_RELEASE(rs, m_idPlanksTexture); + TEXTURE_RELEASE(rs, m_idCannonsGTexture); TEXTURE_RELEASE(rs, m_idWindTex); TEXTURE_RELEASE(rs, m_idBestCourseTex); TEXTURE_RELEASE(rs, m_idWindTexture); @@ -1420,26 +1645,58 @@ void BATTLE_NAVIGATOR::UpdateCurrentCharge() VDATA *pVD = core.Event("GetCurrentCharge"); if (pVD == nullptr) return; - int32_t curCharge = m_curCharge; + int32_t curBalls = m_curBalls; + int32_t curGrapes = m_curGrapes; + int32_t curKnippels = m_curKnippels; + int32_t curBombs = m_curBombs; int32_t curSailState = m_curSailState; int32_t curWindPic = m_curWindPic; int32_t curPowder = m_curPowder; - int32_t isPowderRunOut = 0; - pVD->Get(curCharge, 0); - pVD->Get(curSailState, 1); - pVD->Get(curWindPic, 2); - pVD->Get(curPowder, 3); - pVD->Get(isPowderRunOut, 4); - m_bPowderRunOut = isPowderRunOut; - if (curCharge == m_curCharge && curSailState == m_curSailState && curWindPic == m_curWindPic && - curPowder == m_curPowder) + int32_t curWeapon = m_curWeapon; + int32_t curSailcloth = m_curSailcloth; + int32_t curPlanks = m_curPlanks; + int32_t curCannonsG = m_curCannonsG; + pVD->Get(curBalls, 0); + pVD->Get(curGrapes, 1); + pVD->Get(curKnippels, 2); + pVD->Get(curBombs, 3); + pVD->Get(curSailState, 4); + pVD->Get(curWindPic, 5); + pVD->Get(curPowder, 6); + pVD->Get(curWeapon, 7); + pVD->Get(curPlanks, 8); + pVD->Get(curSailcloth, 9); + pVD->Get(curCannonsG, 10); + + if (curSailState == m_curSailState && curWindPic == m_curWindPic && + curPowder == m_curPowder && curBalls == m_curBalls && curGrapes == m_curGrapes && + curKnippels == m_curKnippels && curBombs == m_curBombs && m_curWeapon == curWeapon && + m_curSailcloth == curSailcloth && m_curPlanks == curPlanks && m_curCannonsG == curCannonsG) return; - m_curCharge = curCharge; + m_curBalls = curBalls; + m_curGrapes = curGrapes; + m_curKnippels = curKnippels; + m_curBombs = curBombs; m_curSailState = curSailState; m_curWindPic = curWindPic; m_curPowder = curPowder; - if (m_curCharge < 0) - m_curCharge = 0; + m_curWeapon = curWeapon; + m_curPlanks = curPlanks; + m_curCannonsG = curCannonsG; + m_curSailcloth = curSailcloth; + + if (m_curBalls < 0) + m_curBalls = 0; + + if (m_curGrapes < 0) + m_curGrapes = 0; + + if (m_curKnippels < 0) + m_curKnippels = 0; + + if (m_curBombs < 0) + m_curBombs = 0; + if (m_curSailState < 0) m_curSailState = 0; if (m_curWindPic < 0) @@ -1447,11 +1704,23 @@ void BATTLE_NAVIGATOR::UpdateCurrentCharge() if (m_curPowder < 0) m_curPowder = 0; + if (m_curWeapon < 0) + m_curWeapon = 0; + + if (m_curPlanks < 0) + m_curPlanks = 0; + + if (m_curSailcloth < 0) + m_curSailcloth = 0; + + if (m_curCannonsG < 0) + m_curCannonsG = 0; + auto *pV = static_cast(rs->LockVertexBuffer(m_idCurChargeVBuf)); if (pV != nullptr) { FRECT texRect; - CalculateTextureRect(texRect, m_curCharge, m_ChargeGreed.x, m_ChargeGreed.y); + CalculateTextureRect(texRect, m_curBalls, m_BallsGreed.x, m_BallsGreed.y); pV[0].tu = texRect.left; pV[0].tv = texRect.top; pV[1].tu = texRect.left; @@ -1491,6 +1760,76 @@ void BATTLE_NAVIGATOR::UpdateCurrentCharge() pV[15].tu = texRect.right; pV[15].tv = texRect.bottom; + CalculateTextureRect(texRect, m_curGrapes, m_GrapesGreed.x, m_GrapesGreed.y); + pV[16].tu = texRect.left; + pV[16].tv = texRect.top; + pV[17].tu = texRect.left; + pV[17].tv = texRect.bottom; + pV[18].tu = texRect.right; + pV[18].tv = texRect.top; + pV[19].tu = texRect.right; + pV[19].tv = texRect.bottom; + + CalculateTextureRect(texRect, m_curKnippels, m_KnippelsGreed.x, m_KnippelsGreed.y); + pV[20].tu = texRect.left; + pV[20].tv = texRect.top; + pV[21].tu = texRect.left; + pV[21].tv = texRect.bottom; + pV[22].tu = texRect.right; + pV[22].tv = texRect.top; + pV[23].tu = texRect.right; + pV[23].tv = texRect.bottom; + + CalculateTextureRect(texRect, m_curBombs, m_BombsGreed.x, m_BombsGreed.y); + pV[24].tu = texRect.left; + pV[24].tv = texRect.top; + pV[25].tu = texRect.left; + pV[25].tv = texRect.bottom; + pV[26].tu = texRect.right; + pV[26].tv = texRect.top; + pV[27].tu = texRect.right; + pV[27].tv = texRect.bottom; + + CalculateTextureRect(texRect, m_curWeapon, m_WeaponGreed.x, m_WeaponGreed.y); + pV[28].tu = texRect.left; + pV[28].tv = texRect.top; + pV[29].tu = texRect.left; + pV[29].tv = texRect.bottom; + pV[30].tu = texRect.right; + pV[30].tv = texRect.top; + pV[31].tu = texRect.right; + pV[31].tv = texRect.bottom; + + CalculateTextureRect(texRect, m_curSailcloth, m_SailclothGreed.x, m_SailclothGreed.y); + pV[32].tu = texRect.left; + pV[32].tv = texRect.top; + pV[33].tu = texRect.left; + pV[33].tv = texRect.bottom; + pV[34].tu = texRect.right; + pV[34].tv = texRect.top; + pV[35].tu = texRect.right; + pV[35].tv = texRect.bottom; + + CalculateTextureRect(texRect, m_curPlanks, m_PlanksGreed.x, m_PlanksGreed.y); + pV[36].tu = texRect.left; + pV[36].tv = texRect.top; + pV[37].tu = texRect.left; + pV[37].tv = texRect.bottom; + pV[38].tu = texRect.right; + pV[38].tv = texRect.top; + pV[39].tu = texRect.right; + pV[39].tv = texRect.bottom; + + CalculateTextureRect(texRect, m_curCannonsG, m_CannonsGGreed.x, m_CannonsGGreed.y); + pV[40].tu = texRect.left; + pV[40].tv = texRect.top; + pV[41].tu = texRect.left; + pV[41].tv = texRect.bottom; + pV[42].tu = texRect.right; + pV[42].tv = texRect.top; + pV[43].tu = texRect.right; + pV[43].tv = texRect.bottom; + rs->UnLockVertexBuffer(m_idCurChargeVBuf); } } diff --git a/src/libs/battle_interface/src/sea/battle_navigator.h b/src/libs/battle_interface/src/sea/battle_navigator.h index 5b1008702..b89c7c71a 100644 --- a/src/libs/battle_interface/src/sea/battle_navigator.h +++ b/src/libs/battle_interface/src/sea/battle_navigator.h @@ -158,8 +158,15 @@ class BATTLE_NAVIGATOR int32_t m_idIslandTexture{-1}; // Isle int32_t m_idWindTex{-1}; // wind int32_t m_idBestCourseTex{-1}; // best direction pointers - int32_t m_idChargeTexture{-1}; // current cannon charge type + int32_t m_idBallsTexture{-1}; // balls charge type + int32_t m_idGrapesTexture{-1}; // grapes charge type + int32_t m_idKnippelsTexture{-1}; // knippels charge type + int32_t m_idBombsTexture{-1}; // bombs charge type int32_t m_idPowderTexture{-1}; // current gunpowder + int32_t m_idWeaponTexture{-1}; // Weapon + int32_t m_idSailclothTexture{-1}; // Sailcloth + int32_t m_idPlanksTexture{-1}; // Planks + int32_t m_idCannonsGTexture{-1}; // Cannons int32_t m_idWindTexture{-1}; // wind speed int32_t m_idSailTexture{-1}; // sail position / ship speed IDirect3DTexture9 *m_pIslandTexture{}; @@ -182,6 +189,10 @@ class BATTLE_NAVIGATOR int32_t m_nvCannonCharge{}; int32_t m_nvCannonReady{}; int32_t m_nvCannonDamage{}; + + POINT m_CannonsChargePos{}; + POINT m_CannonsChargeSize{}; + //-------------------- int32_t m_idSpeedVBuf{-1}; int32_t m_nvSpeed{}; @@ -203,16 +214,53 @@ class BATTLE_NAVIGATOR ATTRIBUTES *m_pAWeather{}; // icon of the current cannon charge type - POINT m_ChargeGreed{}; - POINT m_ChargePos{}; - POINT m_ChargeSize{}; - int32_t m_curCharge{-1}; + + POINT m_BallsGreed{}; + POINT m_BallsPos{}; + POINT m_BallsSize{}; + int32_t m_curBalls{-1}; + + POINT m_GrapesGreed{}; + POINT m_GrapesPos{}; + POINT m_GrapesSize{}; + int32_t m_curGrapes{-1}; + + POINT m_KnippelsGreed{}; + POINT m_KnippelsPos{}; + POINT m_KnippelsSize{}; + int32_t m_curKnippels{-1}; + + POINT m_BombsGreed{}; + POINT m_BombsPos{}; + POINT m_BombsSize{}; + int32_t m_curBombs{-1}; + // gunpowder icon POINT m_PowderGreed{}; POINT m_PowderPos{}; POINT m_PowderSize{}; int32_t m_curPowder{}; - bool m_bPowderRunOut{}; // for blinking + + POINT m_WeaponGreed{}; + POINT m_WeaponPos{}; + POINT m_WeaponSize{}; + int32_t m_curWeapon{-1}; + + POINT m_SailclothGreed{}; + POINT m_SailclothPos{}; + POINT m_SailclothSize{}; + int32_t m_curSailcloth{-1}; + + POINT m_PlanksGreed{}; + POINT m_PlanksPos{}; + POINT m_PlanksSize{}; + int32_t m_curPlanks{-1}; + + POINT m_CannonsGGreed{}; + POINT m_CannonsGPos{}; + POINT m_CannonsGSize{}; + int32_t m_curCannonsG{-1}; + // wind icon int32_t m_curWindPic{}; POINT m_WindGreed{}; diff --git a/src/libs/battle_interface/src/sea/battle_ship_command.h b/src/libs/battle_interface/src/sea/battle_ship_command.h index 314db2e97..a96abc762 100644 --- a/src/libs/battle_interface/src/sea/battle_ship_command.h +++ b/src/libs/battle_interface/src/sea/battle_ship_command.h @@ -1,6 +1,6 @@ #pragma once -#include "battle_command.h" +#include "../battle_command.h" class BIShipCommandList : public BICommandList { diff --git a/src/libs/battle_interface/src/sea/battle_ship_sign.cpp b/src/libs/battle_interface/src/sea/battle_ship_sign.cpp index 80494ff2c..d08fcd2eb 100644 --- a/src/libs/battle_interface/src/sea/battle_ship_sign.cpp +++ b/src/libs/battle_interface/src/sea/battle_ship_sign.cpp @@ -2,7 +2,7 @@ #include "core.h" -#include "utils.h" +#include "bi_utils.h" #include "battle_ship_command.h" #include "controls.h" #include "shared/battle_interface/msg_control.h" @@ -17,11 +17,16 @@ BIShipIcon::BIShipIcon(entid_t BIEntityID, VDX9RENDER *pRS) m_nVBufID = -1; m_nIBufID = -1; + m_nBackMCTextureID = -1; m_nBackTextureID = -1; + m_nShipStateBackTextureID = -1; m_nShipTextureID = -1; m_nShipStateTextureID = -1; + m_nShipStateMCTextureID = -1; m_nShipClassTextureID = -1; m_nBackSquareQ = 0; + m_nShipStateBackSquareQ = 0; + m_nBackMCSquareQ = 0; m_nShipSquareQ = 0; m_nShipStateSquareQ = 0; m_nShipClassSquareQ = 0; @@ -73,8 +78,24 @@ void BIShipIcon::Draw() m_nShipSquareQ * 2, "battle_colorRectangle"); } nStartV += m_nShipSquareQ * 4; - + + if (m_nShipStateBackSquareQ > 0) + { + m_pRS->TextureSet(0, m_nShipStateBackTextureID); + m_pRS->DrawBuffer(m_nVBufID, sizeof(BI_COLOR_VERTEX), m_nIBufID, nStartV, m_nShipStateBackSquareQ * 4, nStartI, + m_nShipStateBackSquareQ * 2, "battle_colorRectangle"); + } + nStartV += m_nShipStateBackSquareQ * 4; + // back + if (m_nBackMCSquareQ > 0) + { + m_pRS->TextureSet(0, m_nBackMCTextureID); + m_pRS->DrawBuffer(m_nVBufID, sizeof(BI_COLOR_VERTEX), m_nIBufID, nStartV, m_nBackMCSquareQ * 4, nStartI, + m_nBackMCSquareQ * 2, "battle_colorRectangle"); + } + nStartV += m_nBackMCSquareQ * 4; + if (m_nBackSquareQ > 0) { m_pRS->TextureSet(0, m_nBackTextureID); @@ -82,10 +103,21 @@ void BIShipIcon::Draw() m_nBackSquareQ * 2, "battle_colorRectangle"); } nStartV += m_nBackSquareQ * 4; + + // ship state (hp & sp) - if (m_nShipStateSquareQ > 0) + if (m_nMCShipStateSquareQ > 0) { + // MC ship state (hp & sp) + + m_pRS->TextureSet(0, m_nShipStateMCTextureID); + m_pRS->DrawBuffer(m_nVBufID, sizeof(BI_COLOR_VERTEX), m_nIBufID, nStartV, m_nMCShipStateSquareQ * 4, nStartI, + m_nMCShipStateSquareQ * 2, "battle_colorRectangle"); + } + nStartV += m_nMCShipStateSquareQ * 4; + if (m_nShipStateSquareQ > 0) + { m_pRS->TextureSet(0, m_nShipStateTextureID); m_pRS->DrawBuffer(m_nVBufID, sizeof(BI_COLOR_VERTEX), m_nIBufID, nStartV, m_nShipStateSquareQ * 4, nStartI, m_nShipStateSquareQ * 2, "battle_colorRectangle"); @@ -97,27 +129,28 @@ void BIShipIcon::Draw() { m_pRS->TextureSet(0, m_nShipClassTextureID); m_pRS->DrawBuffer(m_nVBufID, sizeof(BI_COLOR_VERTEX), m_nIBufID, nStartV, m_nShipClassSquareQ * 4, nStartI, - m_nShipClassSquareQ * 2, "battle_alphacutcolor"); + m_nShipClassSquareQ * 2, "battle_colorRectangle"); } nStartV += m_nShipClassSquareQ * 4; + } for (int32_t n = 0; n < m_nShipQuantity; n++) { if (m_Ship[n].pASailorQuantity) { - m_pRS->ExtPrint(m_idSailorFont, m_dwSailorFontColor, 0, PR_ALIGN_CENTER, true, m_fSailorFontScale, 0, 0, + m_pRS->ExtPrint(m_idSailorFont, m_dwSailorFontColor, 0, PR_ALIGN_CENTER, true, n == 0 ? m_fMCSailorFontScale : m_fSailorFontScale, 0, 0, // shadow - static_cast(m_Ship[n].pntPos.x) + m_SailorFontOffset.x, - static_cast(m_Ship[n].pntPos.y) + m_SailorFontOffset.y, "%d", + n == 0 ? static_cast(m_Ship[n].pntPos.x) + m_MCSailorFontOffset.x : static_cast(m_Ship[n].pntPos.x) + m_SailorFontOffset.x, + n == 0 ? static_cast(m_Ship[n].pntPos.y) + m_MCSailorFontOffset.y : static_cast(m_Ship[n].pntPos.y) + m_SailorFontOffset.y, "%d", static_cast(atof(m_Ship[n].pASailorQuantity->GetThisAttr()))); } - if (!m_Ship[n].sShipName.empty()) + if (!m_Ship[n].sShipName.empty()) { - m_pRS->ExtPrint(m_idShipNameFont, m_dwShipNameFontColor, 0, PR_ALIGN_CENTER, true, m_fShipNameFontScale, 0, + m_pRS->ExtPrint(m_idShipNameFont, n == 0 ? m_dwShipNameFontColorMC : m_dwShipNameFontColor, 0, PR_ALIGN_CENTER, true, n == 0 ? m_fShipNameFontScaleMC : m_fShipNameFontScale, 0, 0, // font shadow - static_cast(m_Ship[n].pntPos.x) + m_ShipNameFontOffset.x, - static_cast(m_Ship[n].pntPos.y) + m_ShipNameFontOffset.y, "%s", + n == 0 ? static_cast(m_Ship[n].pntPos.x) + m_ShipNameFontOffsetMC.x : static_cast(m_Ship[n].pntPos.x) + m_ShipNameFontOffset.x, + n == 0 ? static_cast(m_Ship[n].pntPos.y) + m_ShipNameFontOffsetMC.y : static_cast(m_Ship[n].pntPos.y) + m_ShipNameFontOffset.y, "%s", m_Ship[n].sShipName.c_str()); } } @@ -142,41 +175,72 @@ void BIShipIcon::Init(ATTRIBUTES *pRoot, ATTRIBUTES *pA) FULLRECT(m_rBackUV); ZERROPOINT(m_pntBackOffset); FILLPOINT(m_pntBackIconSize, 128, 128); - + // belamour + m_nBackMCTextureID = -1; + m_dwBackMCColor = ARGB(255, 128, 128, 128); + FULLRECT(m_rBackMCUV); + ZERROPOINT(m_pntBackMCOffset); + FILLPOINT(m_pntBackMCIconSize, 128, 128); + + m_nShipStateBackTextureID = -1; + m_dwShipStateBackColor = ARGB(255, 128, 128, 128); + FULLRECT(m_rShipStateBackUV); + ZERROPOINT(m_pntShipStateBackOffset); + FILLPOINT(m_pntShipStateBackIconSize, 128, 128); + + m_nShipStateMCTextureID = -1; m_nShipStateTextureID = -1; + m_dwShipStateMCColor = ARGB(255, 128, 128, 128); m_dwShipStateColor = ARGB(255, 128, 128, 128); + FULLRECT(m_rShipHPMCUV); FULLRECT(m_rShipHPUV); + ZERROPOINT(m_pntShipHPMCOffset); ZERROPOINT(m_pntShipHPOffset); + FILLPOINT(m_pntShipHPMCIconSize, 128, 128); FILLPOINT(m_pntShipHPIconSize, 128, 128); + FULLRECT(m_rShipSPMCUV); FULLRECT(m_rShipSPUV); + ZERROPOINT(m_pntShipSPMCOffset); ZERROPOINT(m_pntShipSPOffset); + FILLPOINT(m_pntShipSPMCIconSize, 128, 128); FILLPOINT(m_pntShipSPIconSize, 128, 128); m_nShipClassTextureID = -1; m_dwShipClassColor = ARGB(255, 128, 128, 128); FULLRECT(m_rShipClassUV); + ZERROPOINT(m_pntMCShipClassOffset); ZERROPOINT(m_pntShipClassOffset); + FILLPOINT(m_pntMCShipClassIconSize, 128, 128); FILLPOINT(m_pntShipClassIconSize, 128, 128); m_nShipTextureID = -1; m_dwShipColor = ARGB(255, 128, 128, 128); // FULLRECT( m_rShipUV ); ZERROPOINT(m_pntShipOffset); + FILLPOINT(m_pntMCShipIconSize, 128, 128); FILLPOINT(m_pntShipIconSize, 128, 128); m_idSailorFont = -1; m_dwSailorFontColor = ARGB(255, 64, 64, 64); - m_fSailorFontScale = 1.f; - m_SailorFontOffset.x = -14; + m_fMCSailorFontScale = 1.f; + m_MCSailorFontOffset.x = -14; + m_MCSailorFontOffset.y = 18; + m_fSailorFontScale = 1.f; + m_SailorFontOffset.x = -14; m_SailorFontOffset.y = 18; m_idShipNameFont = -1; + m_dwShipNameFontColorMC = ARGB(255, 64, 64, 64); m_dwShipNameFontColor = ARGB(255, 64, 64, 64); + m_fShipNameFontScaleMC = 1.f; m_fShipNameFontScale = 1.f; + m_ShipNameFontOffsetMC.x = -14; + m_ShipNameFontOffsetMC.y = 40; m_ShipNameFontOffset.x = -14; m_ShipNameFontOffset.y = 40; m_nCommandListVerticalOffset = -48; + m_nCommandListVerticalOffsetMC = -48; for (n = 0; n < MAX_SHIP_QUANTITY; n++) { @@ -190,8 +254,13 @@ void BIShipIcon::Init(ATTRIBUTES *pRoot, ATTRIBUTES *pA) if (pcTmp) m_idSailorFont = m_pRS->LoadFont(pcTmp); m_dwSailorFontColor = pA->GetAttributeAsDword("sailorfontcolor", m_dwSailorFontColor); + m_fMCSailorFontScale = pA->GetAttributeAsFloat("mcsailorfontscale", m_fMCSailorFontScale); m_fSailorFontScale = pA->GetAttributeAsFloat("sailorfontscale", m_fSailorFontScale); - + + pcTmp = pA->GetAttribute("mcsailorfontoffset"); + if (pcTmp) + sscanf(pcTmp, "%ld,%ld", &m_MCSailorFontOffset.x, &m_MCSailorFontOffset.y); + // ugeen 150920 pcTmp = pA->GetAttribute("sailorfontoffset"); if (pcTmp) @@ -200,10 +269,15 @@ void BIShipIcon::Init(ATTRIBUTES *pRoot, ATTRIBUTES *pA) pcTmp = pA->GetAttribute("shipnamefontid"); if (pcTmp) m_idShipNameFont = m_pRS->LoadFont(pcTmp); + m_dwShipNameFontColorMC = pA->GetAttributeAsDword("shipnamefontcolorMC", m_dwShipNameFontColorMC); m_dwShipNameFontColor = pA->GetAttributeAsDword("shipnamefontcolor", m_dwShipNameFontColor); + m_fShipNameFontScaleMC = pA->GetAttributeAsFloat("shipnamefontscaleMC", m_fShipNameFontScaleMC); m_fShipNameFontScale = pA->GetAttributeAsFloat("shipnamefontscale", m_fShipNameFontScale); - pcTmp = pA->GetAttribute("shipnamefontoffset"); + pcTmp = pA->GetAttribute("shipnamefontoffsetMC"); + if (pcTmp) + sscanf(pcTmp, "%ld,%ld", &m_ShipNameFontOffsetMC.x, &m_ShipNameFontOffsetMC.y); + pcTmp = pA->GetAttribute("shipnamefontoffset"); if (pcTmp) sscanf(pcTmp, "%ld,%ld", &m_ShipNameFontOffset.x, &m_ShipNameFontOffset.y); @@ -220,7 +294,36 @@ void BIShipIcon::Init(ATTRIBUTES *pRoot, ATTRIBUTES *pA) pcTmp = pA->GetAttribute("backiconsize"); if (pcTmp) sscanf(pcTmp, "%f,%f", &m_pntBackIconSize.x, &m_pntBackIconSize.y); - + // belamour --> + pcTmp = pA->GetAttribute("backmctexturename"); + if (pcTmp) + m_nBackMCTextureID = m_pRS->TextureCreate(pcTmp); + m_dwBackMCColor = pA->GetAttributeAsDword("backmccolor", m_dwBackMCColor); + pcTmp = pA->GetAttribute("backmcuv"); + if (pcTmp) + sscanf(pcTmp, "%f,%f,%f,%f", &m_rBackMCUV.left, &m_rBackMCUV.top, &m_rBackMCUV.right, &m_rBackMCUV.bottom); + pcTmp = pA->GetAttribute("backmcoffset"); + if (pcTmp) + sscanf(pcTmp, "%f,%f", &m_pntBackMCOffset.x, &m_pntBackMCOffset.y); + pcTmp = pA->GetAttribute("backmciconsize"); + if (pcTmp) + sscanf(pcTmp, "%f,%f", &m_pntBackMCIconSize.x, &m_pntBackMCIconSize.y); + + //MC ship state backtexture + pcTmp = pA->GetAttribute("shipstatebacktexturename"); + if (pcTmp) + m_nShipStateBackTextureID = m_pRS->TextureCreate(pcTmp); + m_dwShipStateBackColor = pA->GetAttributeAsDword("shipstatebackcolor", m_dwShipStateBackColor); + pcTmp = pA->GetAttribute("shipstatebackuv"); + if (pcTmp) + sscanf(pcTmp, "%f,%f,%f,%f", &m_rShipStateBackUV.left, &m_rShipStateBackUV.top, &m_rShipStateBackUV.right, &m_rShipStateBackUV.bottom); + pcTmp = pA->GetAttribute("shipstatebackoffset"); + if (pcTmp) + sscanf(pcTmp, "%f,%f", &m_pntShipStateBackOffset.x, &m_pntShipStateBackOffset.y); + pcTmp = pA->GetAttribute("shipstatebackiconsize"); + if (pcTmp) + sscanf(pcTmp, "%f,%f", &m_pntShipStateBackIconSize.x, &m_pntShipStateBackIconSize.y); + // <--- pcTmp = pA->GetAttribute("shipstatetexturename"); if (pcTmp) m_nShipStateTextureID = m_pRS->TextureCreate(pcTmp); @@ -243,6 +346,29 @@ void BIShipIcon::Init(ATTRIBUTES *pRoot, ATTRIBUTES *pA) pcTmp = pA->GetAttribute("shipspiconsize"); if (pcTmp) sscanf(pcTmp, "%f,%f", &m_pntShipSPIconSize.x, &m_pntShipSPIconSize.y); + // belamour + pcTmp = pA->GetAttribute("shipstatemctexturename"); + if (pcTmp) + m_nShipStateMCTextureID = m_pRS->TextureCreate(pcTmp); + m_dwShipStateMCColor = pA->GetAttributeAsDword("shipstatemccolor", m_dwShipStateMCColor); + pcTmp = pA->GetAttribute("shiphpmcuv"); + if (pcTmp) + sscanf(pcTmp, "%f,%f,%f,%f", &m_rShipHPMCUV.left, &m_rShipHPMCUV.top, &m_rShipHPMCUV.right, &m_rShipHPMCUV.bottom); + pcTmp = pA->GetAttribute("shiphpmcoffset"); + if (pcTmp) + sscanf(pcTmp, "%f,%f", &m_pntShipHPMCOffset.x, &m_pntShipHPMCOffset.y); + pcTmp = pA->GetAttribute("shiphpmciconsize"); + if (pcTmp) + sscanf(pcTmp, "%f,%f", &m_pntShipHPMCIconSize.x, &m_pntShipHPMCIconSize.y); + pcTmp = pA->GetAttribute("shipspmcuv"); + if (pcTmp) + sscanf(pcTmp, "%f,%f,%f,%f", &m_rShipSPMCUV.left, &m_rShipSPMCUV.top, &m_rShipSPMCUV.right, &m_rShipSPMCUV.bottom); + pcTmp = pA->GetAttribute("shipspmcoffset"); + if (pcTmp) + sscanf(pcTmp, "%f,%f", &m_pntShipSPMCOffset.x, &m_pntShipSPMCOffset.y); + pcTmp = pA->GetAttribute("shipspmciconsize"); + if (pcTmp) + sscanf(pcTmp, "%f,%f", &m_pntShipSPMCIconSize.x, &m_pntShipSPMCIconSize.y); pcTmp = pA->GetAttribute("shipclasstexturename"); if (pcTmp) @@ -251,10 +377,16 @@ void BIShipIcon::Init(ATTRIBUTES *pRoot, ATTRIBUTES *pA) pcTmp = pA->GetAttribute("shipclassuv"); if (pcTmp) sscanf(pcTmp, "%f,%f,%f,%f", &m_rShipClassUV.left, &m_rShipClassUV.top, &m_rShipClassUV.right, - &m_rShipClassUV.bottom); + &m_rShipClassUV.bottom); + pcTmp = pA->GetAttribute("mcshipclassoffset"); + if (pcTmp) + sscanf(pcTmp, "%f,%f", &m_pntMCShipClassOffset.x, &m_pntMCShipClassOffset.y); pcTmp = pA->GetAttribute("shipclassoffset"); if (pcTmp) sscanf(pcTmp, "%f,%f", &m_pntShipClassOffset.x, &m_pntShipClassOffset.y); + pcTmp = pA->GetAttribute("mcshipclassiconsize"); + if (pcTmp) + sscanf(pcTmp, "%f,%f", &m_pntMCShipClassIconSize.x, &m_pntMCShipClassIconSize.y); pcTmp = pA->GetAttribute("shipclassiconsize"); if (pcTmp) sscanf(pcTmp, "%f,%f", &m_pntShipClassIconSize.x, &m_pntShipClassIconSize.y); @@ -267,6 +399,7 @@ void BIShipIcon::Init(ATTRIBUTES *pRoot, ATTRIBUTES *pA) } while (pcTmp[0]); } + m_nCommandListVerticalOffsetMC = pA->GetAttributeAsDword("commandlistverticaloffsetMC"); m_nCommandListVerticalOffset = pA->GetAttributeAsDword("commandlistverticaloffset"); pcTmp = pA->GetAttribute("shiptexturename"); @@ -282,6 +415,10 @@ void BIShipIcon::Init(ATTRIBUTES *pRoot, ATTRIBUTES *pA) pcTmp = pA->GetAttribute("shipiconsize"); if (pcTmp) sscanf(pcTmp, "%f,%f", &m_pntShipIconSize.x, &m_pntShipIconSize.y); + + pcTmp = pA->GetAttribute("mcshipiconsize"); + if (pcTmp) + sscanf(pcTmp, "%f,%f", &m_pntMCShipIconSize.x, &m_pntMCShipIconSize.y); m_dwShipNCols = pA->GetAttributeAsDword("xsize"); m_dwShipNRows = pA->GetAttributeAsDword("ysize"); @@ -423,8 +560,11 @@ void BIShipIcon::Release() SetActive(false); // disable control STORM_DELETE(m_pCommandList); + TEXTURE_RELEASE(m_pRS, m_nBackMCTextureID); TEXTURE_RELEASE(m_pRS, m_nBackTextureID); + TEXTURE_RELEASE(m_pRS, m_nShipStateBackTextureID); TEXTURE_RELEASE(m_pRS, m_nShipTextureID); + TEXTURE_RELEASE(m_pRS, m_nShipStateMCTextureID); TEXTURE_RELEASE(m_pRS, m_nShipStateTextureID); TEXTURE_RELEASE(m_pRS, m_nShipClassTextureID); VERTEX_BUFFER_RELEASE(m_pRS, m_nVBufID); @@ -432,8 +572,11 @@ void BIShipIcon::Release() FONT_RELEASE(m_pRS, m_idSailorFont); m_nMaxSquareQ = 0; + m_nBackMCSquareQ = 0; m_nBackSquareQ = 0; + m_nShipStateBackSquareQ = 0; m_nShipSquareQ = 0; + m_nMCShipStateSquareQ = 0; m_nShipStateSquareQ = 0; m_nShipClassSquareQ = 0; } @@ -455,7 +598,7 @@ int32_t BIShipIcon::CalculateShipQuantity() m_Ship[n].sShipName.clear(); } - // take the ship of the main character + // take the ship of the main character pSD = g_ShipList.GetMainCharacterShip(); if (pSD) { @@ -466,11 +609,13 @@ int32_t BIShipIcon::CalculateShipQuantity() m_Ship[0].nMaxSP = pSD->maxSP; m_Ship[0].nShipClass = GetShipClass(m_Ship[0].nCharacterIndex); GetShipUVFromPictureIndex(pSD->pictureNum, m_Ship[0].rUV); + //belamour + GetShipClassUVFromPictureIndex(GetShipClass(m_Ship[0].nCharacterIndex), m_Ship[0].ShipClassUV); m_Ship[0].sShipName = pSD->pAttr ? pSD->pAttr->GetAttribute("name") : "noname"; m_nShipQuantity++; } - // take the following "our" ships + // take the following "our" ships for (pSD = g_ShipList.GetShipRoot(); pSD; pSD = pSD->next) { if (m_Ship[0].nCharacterIndex == pSD->characterIndex) @@ -484,6 +629,8 @@ int32_t BIShipIcon::CalculateShipQuantity() m_Ship[m_nShipQuantity].nMaxSP = pSD->maxSP; m_Ship[m_nShipQuantity].nShipClass = GetShipClass(m_Ship[m_nShipQuantity].nCharacterIndex); GetShipUVFromPictureIndex(pSD->pictureNum, m_Ship[m_nShipQuantity].rUV); + // belamour + GetShipClassUVFromPictureIndex(GetShipClass(m_Ship[m_nShipQuantity].nCharacterIndex), m_Ship[m_nShipQuantity].ShipClassUV); m_Ship[m_nShipQuantity].sShipName = pSD->pAttr ? pSD->pAttr->GetAttribute("name") : "noname"; m_nShipQuantity++; } @@ -494,13 +641,16 @@ int32_t BIShipIcon::CalculateShipQuantity() void BIShipIcon::UpdateBuffers(int32_t nShipQ) { - const auto nBackSquareQ = nShipQ; - const auto nShipStateSquareQ = nShipQ * 2; + const auto nBackSquareQ = nShipQ-1; + const int32_t nShipStateBackSquareQ = 1; + const int32_t nBackMCSquareQ = 1; + const auto nShipStateSquareQ = (nShipQ-1) * 2; + const int32_t nMCShipStateSquareQ = 2; const int32_t nShipClassSquareQ = nShipQ; const int32_t nShipSquareQ = nShipQ; const int32_t nMaxSquareQ = - BIUtils::GetMaxFromFourLong(nBackSquareQ, nShipStateSquareQ, nShipClassSquareQ, nShipSquareQ); + std::max({nBackSquareQ, nBackMCSquareQ, nShipStateBackSquareQ, nShipStateSquareQ, nMCShipStateSquareQ, nShipClassSquareQ, nShipSquareQ}); if (m_nMaxSquareQ != nMaxSquareQ) { m_nMaxSquareQ = nMaxSquareQ; @@ -509,17 +659,20 @@ void BIShipIcon::UpdateBuffers(int32_t nShipQ) FillIndexBuffer(); } - if ((nBackSquareQ + nShipStateSquareQ + nShipClassSquareQ + nShipSquareQ) != - (m_nBackSquareQ + m_nShipStateSquareQ + m_nShipClassSquareQ + m_nShipSquareQ)) + if ((nBackSquareQ + nBackMCSquareQ + nShipStateSquareQ + nShipStateBackSquareQ + nMCShipStateSquareQ + nShipClassSquareQ + nShipSquareQ) != + (m_nBackSquareQ + m_nBackMCSquareQ + m_nShipStateBackSquareQ + m_nShipStateSquareQ + m_nMCShipStateSquareQ + m_nShipClassSquareQ + m_nShipSquareQ)) { m_nBackSquareQ = nBackSquareQ; + m_nShipStateBackSquareQ = nShipStateBackSquareQ; + m_nBackMCSquareQ = nBackMCSquareQ; + m_nMCShipStateSquareQ = nMCShipStateSquareQ; m_nShipStateSquareQ = nShipStateSquareQ; m_nShipClassSquareQ = nShipClassSquareQ; m_nShipSquareQ = nShipSquareQ; VERTEX_BUFFER_RELEASE(m_pRS, m_nVBufID); m_nVBufID = m_pRS->CreateVertexBuffer( BI_COLOR_VERTEX_FORMAT, - (m_nBackSquareQ + m_nShipStateSquareQ + m_nShipClassSquareQ + m_nShipSquareQ) * 4 * sizeof(BI_COLOR_VERTEX), + (m_nBackSquareQ + m_nBackMCSquareQ + m_nShipStateBackSquareQ + m_nShipStateSquareQ + m_nMCShipStateSquareQ + m_nShipClassSquareQ + m_nShipSquareQ) * 4 * sizeof(BI_COLOR_VERTEX), D3DUSAGE_WRITEONLY); } FillVertexBuffer(); @@ -560,29 +713,55 @@ void BIShipIcon::FillVertexBuffer() for (n = 0; n < m_nShipQuantity; n++) { vn += WriteSquareToVBuff(&pV[vn], m_Ship[n].rUV, m_dwShipColor, m_Ship[n].pntPos + m_pntShipOffset, - m_pntShipIconSize); + n == 0 ? m_pntMCShipIconSize : m_pntShipIconSize); } for (n = 0; n < m_nShipQuantity; n++) - vn += WriteSquareToVBuff(&pV[vn], m_rBackUV, m_dwBackColor, m_Ship[n].pntPos + m_pntBackOffset, + { + if(n == 0) + { + vn += WriteSquareToVBuff(&pV[vn], m_rShipStateBackUV, m_dwShipStateBackColor, m_Ship[n].pntPos + m_pntShipStateBackOffset, + m_pntShipStateBackIconSize); + vn += WriteSquareToVBuff(&pV[vn], m_rBackMCUV, m_dwBackMCColor, m_Ship[n].pntPos + m_pntBackMCOffset, + m_pntBackMCIconSize); + } + else + { + vn += WriteSquareToVBuff(&pV[vn], m_rBackUV, m_dwBackColor, m_Ship[n].pntPos + m_pntBackOffset, m_pntBackIconSize); - + } + } for (n = 0; n < m_nShipQuantity; n++) { - vn += WriteSquareToVBuffWithProgress(&pV[vn], m_rShipHPUV, m_dwShipStateColor, + if(n == 0) + { + vn += WriteSquareToVBuffWithProgress(&pV[vn], m_rShipHPMCUV, m_dwShipStateMCColor, + m_Ship[n].pntPos + m_pntShipHPMCOffset, m_pntShipHPMCIconSize, + 0.f, 0.f, 0.f, GetProgressShipHP(n)); + vn += WriteSquareToVBuffWithProgress(&pV[vn], m_rShipSPMCUV, m_dwShipStateMCColor, + m_Ship[n].pntPos + m_pntShipSPMCOffset, m_pntShipSPMCIconSize, + 0.f, 0.f, 0.f, GetProgressShipSP(n)); + } + else + { + vn += WriteSquareToVBuffWithProgress(&pV[vn], m_rShipHPUV, m_dwShipStateColor, m_Ship[n].pntPos + m_pntShipHPOffset, m_pntShipHPIconSize, GetProgressShipHP(n), 0.f, 0.f, 0.f); - vn += WriteSquareToVBuffWithProgress(&pV[vn], m_rShipSPUV, m_dwShipStateColor, + vn += WriteSquareToVBuffWithProgress(&pV[vn], m_rShipSPUV, m_dwShipStateColor, m_Ship[n].pntPos + m_pntShipSPOffset, m_pntShipSPIconSize, GetProgressShipSP(n), 0.f, 0.f, 0.f); + } } - + for (n = 0; n < m_nShipQuantity; n++) - vn += WriteSquareToVBuffWithProgress(&pV[vn], m_rShipClassUV, m_dwShipClassColor, + /* vn += WriteSquareToVBuffWithProgress(&pV[vn], m_rShipClassUV, m_dwShipClassColor, m_Ship[n].pntPos + m_pntShipClassOffset, m_pntShipClassIconSize, 0.f, - 0.f, 0.f, 1.f - GetProgressShipClass(n)); - // vn += WriteSquareToVBuff( &pV[vn], m_rShipClassUV, m_dwShipClassColor, m_Ship[n].pntPos+m_pntShipClassOffset, - // m_pntShipClassIconSize ); + 0.f, 0.f, 1.f - GetProgressShipClass(n)); */ + // belamour + vn += n == 0 ? WriteSquareToVBuff( &pV[vn], m_Ship[n].ShipClassUV, m_dwShipClassColor, m_Ship[n].pntPos+m_pntMCShipClassOffset, + m_pntMCShipClassIconSize ) + : WriteSquareToVBuff( &pV[vn], m_Ship[n].ShipClassUV, m_dwShipClassColor, m_Ship[n].pntPos+m_pntShipClassOffset, + m_pntShipClassIconSize ); m_pRS->UnLockVertexBuffer(m_nVBufID); } @@ -705,6 +884,7 @@ int32_t BIShipIcon::GetCurrentCommandTopLine() if (n < 0 || n >= m_nShipQuantity) n = 0; m_nCurrentShipIndex = n; + if (n == 0) return static_cast(m_Ship[0].pntPos.y) + m_nCommandListVerticalOffsetMC; return static_cast(m_Ship[n].pntPos.y) + m_nCommandListVerticalOffset; } @@ -781,6 +961,18 @@ void BIShipIcon::GetShipUVFromPictureIndex(int32_t nPicIndex, FRECT &rUV) rUV.bottom = rUV.top + pictureHeight; // boal } +// belamour +void BIShipIcon::GetShipClassUVFromPictureIndex(int32_t nPicIndex, FRECT &ShipClassUV) +{ + + const float pw = 1.f/8.f; + + ShipClassUV.left = pw*(nPicIndex); + ShipClassUV.top = 0.f; + ShipClassUV.right = ShipClassUV.left + pw; + ShipClassUV.bottom = 1.f; +} + int32_t BIShipIcon::GetShipClass(int32_t nCharIdx) { VDATA *pVDat = core.Event("evntGetCharacterShipClass", "l", nCharIdx); diff --git a/src/libs/battle_interface/src/sea/battle_ship_sign.h b/src/libs/battle_interface/src/sea/battle_ship_sign.h index 4cbaa27be..b3540a4dc 100644 --- a/src/libs/battle_interface/src/sea/battle_ship_sign.h +++ b/src/libs/battle_interface/src/sea/battle_ship_sign.h @@ -68,6 +68,8 @@ class BIShipIcon float GetProgressShipSP(int32_t nShipNum); float GetProgressShipClass(int32_t nShipNum); void GetShipUVFromPictureIndex(int32_t nPicIndex, FRECT &rUV); + //belamour + void GetShipClassUVFromPictureIndex(int32_t nPicIndex, FRECT &ShipClassUV); int32_t GetShipClass(int32_t nCharIdx); @@ -77,29 +79,54 @@ class BIShipIcon int32_t m_nIBufID; int32_t m_nMaxSquareQ; - - int32_t m_nBackTextureID; + // belamour + int32_t m_nBackMCTextureID; + int32_t m_nBackMCSquareQ; + uint32_t m_dwBackMCColor; + FRECT m_rBackMCUV; + BIFPOINT m_pntBackMCOffset; + FPOINT m_pntBackMCIconSize; + + int32_t m_nBackTextureID; int32_t m_nBackSquareQ; uint32_t m_dwBackColor; FRECT m_rBackUV; BIFPOINT m_pntBackOffset; FPOINT m_pntBackIconSize; - + + int32_t m_nShipStateBackTextureID; + int32_t m_nShipStateBackSquareQ; + uint32_t m_dwShipStateBackColor; + FRECT m_rShipStateBackUV; + BIFPOINT m_pntShipStateBackOffset; + FPOINT m_pntShipStateBackIconSize; + + int32_t m_nShipStateMCTextureID; int32_t m_nShipStateTextureID; + int32_t m_nMCShipStateSquareQ; int32_t m_nShipStateSquareQ; + uint32_t m_dwShipStateMCColor; uint32_t m_dwShipStateColor; + FRECT m_rShipHPMCUV; FRECT m_rShipHPUV; BIFPOINT m_pntShipHPOffset; + BIFPOINT m_pntShipHPMCOffset; + FPOINT m_pntShipHPMCIconSize; FPOINT m_pntShipHPIconSize; + FRECT m_rShipSPMCUV; FRECT m_rShipSPUV; + BIFPOINT m_pntShipSPMCOffset; BIFPOINT m_pntShipSPOffset; + FPOINT m_pntShipSPMCIconSize; FPOINT m_pntShipSPIconSize; int32_t m_nShipClassTextureID; int32_t m_nShipClassSquareQ; uint32_t m_dwShipClassColor; FRECT m_rShipClassUV; + BIFPOINT m_pntMCShipClassOffset; BIFPOINT m_pntShipClassOffset; + FPOINT m_pntMCShipClassIconSize; FPOINT m_pntShipClassIconSize; std::vector m_aClassProgress; @@ -108,6 +135,7 @@ class BIShipIcon uint32_t m_dwShipColor; // FRECT m_rShipUV; BIFPOINT m_pntShipOffset; + FPOINT m_pntMCShipIconSize; FPOINT m_pntShipIconSize; uint32_t m_dwShipNCols; uint32_t m_dwShipNRows; @@ -123,20 +151,28 @@ class BIShipIcon FRECT rUV; std::string sShipName; int32_t nShipClass; + //belamour + FRECT ShipClassUV; } m_Ship[MAX_SHIP_QUANTITY]; int32_t m_nShipQuantity; int32_t m_nCurrentShipIndex; int32_t m_nCommandListVerticalOffset; + int32_t m_nCommandListVerticalOffsetMC; int32_t m_idSailorFont; uint32_t m_dwSailorFontColor; float m_fSailorFontScale; POINT m_SailorFontOffset; + float m_fMCSailorFontScale; + POINT m_MCSailorFontOffset; int32_t m_idShipNameFont; + uint32_t m_dwShipNameFontColorMC; uint32_t m_dwShipNameFontColor; + float m_fShipNameFontScaleMC; float m_fShipNameFontScale; + POINT m_ShipNameFontOffsetMC; POINT m_ShipNameFontOffset; bool m_bMakeUpdate; diff --git a/src/libs/battle_interface/src/sea/i_battle.cpp b/src/libs/battle_interface/src/sea/i_battle.cpp index 6b7216d36..1c7a8cd5a 100644 --- a/src/libs/battle_interface/src/sea/i_battle.cpp +++ b/src/libs/battle_interface/src/sea/i_battle.cpp @@ -13,8 +13,8 @@ #include "../land/i_boarding_status.h" #include "../land/battle_land.h" -#include "active_perk_shower.h" -#include "log_and_action.h" +#include "../active_perk_shower.h" +#include "../log_and_action.h" #include "../item_entity/item_entity.h" #include "../world_map_interface/interface.h" #include "../spyglass/spyglass.h" diff --git a/src/libs/battle_interface/src/sea/i_battle.h b/src/libs/battle_interface/src/sea/i_battle.h index 891b4c9b0..747f860a3 100644 --- a/src/libs/battle_interface/src/sea/i_battle.h +++ b/src/libs/battle_interface/src/sea/i_battle.h @@ -1,6 +1,6 @@ #pragma once -#include "utils.h" +#include "bi_utils.h" #include "bi_defines.h" #include "battle_navigator.h" #include "dx9render.h" diff --git a/src/libs/battle_interface/src/sea/ship_info_images.cpp b/src/libs/battle_interface/src/sea/ship_info_images.cpp index a55ccefcc..e6b74d3d0 100644 --- a/src/libs/battle_interface/src/sea/ship_info_images.cpp +++ b/src/libs/battle_interface/src/sea/ship_info_images.cpp @@ -1,5 +1,5 @@ #include "ship_info_images.h" -#include "utils.h" +#include "bi_utils.h" #include "ship_base.h" // define the vertices diff --git a/src/libs/battle_interface/src/spyglass/spyglass.cpp b/src/libs/battle_interface/src/spyglass/spyglass.cpp index b5a29939f..11fff1457 100644 --- a/src/libs/battle_interface/src/spyglass/spyglass.cpp +++ b/src/libs/battle_interface/src/spyglass/spyglass.cpp @@ -1,5 +1,5 @@ #include "spyglass.h" -#include "utils.h" +#include "bi_utils.h" #include "../image/image.h" #include "../image/img_render.h" #include "../sea/ships_list.h" diff --git a/src/libs/battle_interface/src/timer/timer.cpp b/src/libs/battle_interface/src/timer/timer.cpp index 7b5818ace..3d3c0c1ee 100644 --- a/src/libs/battle_interface/src/timer/timer.cpp +++ b/src/libs/battle_interface/src/timer/timer.cpp @@ -1,5 +1,5 @@ #include "timer.h" -#include "utils.h" +#include "bi_utils.h" #include "../image/img_render.h" #include "core.h" #include "message.h" diff --git a/src/libs/battle_interface/src/world_map_interface/ship_command.h b/src/libs/battle_interface/src/world_map_interface/ship_command.h index 308ae25ee..63d035c32 100644 --- a/src/libs/battle_interface/src/world_map_interface/ship_command.h +++ b/src/libs/battle_interface/src/world_map_interface/ship_command.h @@ -1,6 +1,6 @@ #pragma once -#include "battle_command.h" +#include "../battle_command.h" class WMShipCommandList : public BICommandList { diff --git a/src/libs/battle_interface/src/world_map_interface/ship_sign.cpp b/src/libs/battle_interface/src/world_map_interface/ship_sign.cpp index 542fa97d2..95ff62d93 100644 --- a/src/libs/battle_interface/src/world_map_interface/ship_sign.cpp +++ b/src/libs/battle_interface/src/world_map_interface/ship_sign.cpp @@ -1,5 +1,5 @@ #include "ship_sign.h" -#include "utils.h" +#include "bi_utils.h" #include "platform/platform.hpp" WMShipIcon::WMShipIcon(entid_t BIEntityID, VDX9RENDER *pRS) : BISignIcon(BIEntityID, pRS) diff --git a/src/libs/battle_interface/src/world_map_interface/ship_sign.h b/src/libs/battle_interface/src/world_map_interface/ship_sign.h index 8b03bd658..d32bd64fd 100644 --- a/src/libs/battle_interface/src/world_map_interface/ship_sign.h +++ b/src/libs/battle_interface/src/world_map_interface/ship_sign.h @@ -1,6 +1,6 @@ #pragma once -#include "battle_sign.h" +#include "../battle_sign.h" #include "bi_defines.h" #define MAX_SHIP_QUANTITY 8 diff --git a/src/libs/core/include/attributes.h b/src/libs/core/include/attributes.h index 8841c52ba..fca185d54 100644 --- a/src/libs/core/include/attributes.h +++ b/src/libs/core/include/attributes.h @@ -12,11 +12,12 @@ class VSTRING_CODEC { public: VSTRING_CODEC() = default; - virtual ~VSTRING_CODEC() noexcept = default; + virtual ~VSTRING_CODEC() = default; - [[nodiscard]] virtual uint32_t GetNum() const = 0; - virtual uint32_t Convert(const std::string_view &pString) = 0; - [[nodiscard]] virtual std::string_view Convert(uint32_t code) const = 0; + virtual uint32_t GetNum() = 0; + virtual uint32_t Convert(const char *pString) = 0; + virtual uint32_t Convert(const char *pString, int32_t iLen) = 0; + virtual const char *Convert(uint32_t code) = 0; virtual void VariableChanged() = 0; }; @@ -39,14 +40,15 @@ class ATTRIBUTES final ~ATTRIBUTES(); void SetBreak(bool set_break); - [[nodiscard]] ATTRIBUTES *GetParent() const; - bool operator==(const std::string_view &str) const; - [[nodiscard]] std::string_view GetThisName() const; + [[nodiscard]] ATTRIBUTES* GetParent() const; + bool operator==(const char *str) const; + [[nodiscard]] const char* GetThisName() const; [[nodiscard]] bool HasValue() const noexcept; [[nodiscard]] const std::string &GetValue() const; [[nodiscard]] LegacyProxy GetThisAttr() const; void SetName(const std::string_view &new_name); - [[deprecated("Pass attribute value by string_view instead")]] void SetValue(const char *new_value); + [[deprecated("Pass attribute value by string_view instead")]] + void SetValue(const char *new_value); void SetValue(const std::string_view &new_value); [[nodiscard]] size_t GetAttributesNum() const; [[nodiscard]] ATTRIBUTES *GetAttributeClass(const std::string_view &name) const; @@ -54,7 +56,7 @@ class ATTRIBUTES final [[nodiscard]] ATTRIBUTES *VerifyAttributeClass(const std::string_view &name); [[nodiscard]] LegacyProxy GetAttribute(size_t n) const; [[nodiscard]] LegacyProxy GetAttribute(const std::string_view &name) const; - [[nodiscard]] std::string_view GetAttributeName(size_t n) const; + [[nodiscard]] const char *GetAttributeName(size_t n) const; [[nodiscard]] uint32_t GetAttributeAsDword(const char *name = nullptr, uint32_t def = 0) const; [[nodiscard]] uintptr_t GetAttributeAsPointer(const char *name = nullptr, uintptr_t def = 0) const; [[nodiscard]] float GetAttributeAsFloat(const char *name = nullptr, float def = 0) const; @@ -62,8 +64,8 @@ class ATTRIBUTES final bool SetAttributeUseFloat(const char *name, float val); ATTRIBUTES &CreateAttribute(const std::string_view &name); ATTRIBUTES *CreateAttribute(const std::string_view &name, const char *attribute); - [[deprecated("Pass attribute value by string_view instead")]] size_t SetAttribute(const std::string_view &name, - const char *attribute); + [[deprecated("Pass attribute value by string_view instead")]] + size_t SetAttribute(const std::string_view &name, const char *attribute); size_t SetAttribute(const std::string_view &name, const std::string_view &attribute); [[nodiscard]] ATTRIBUTES Copy() const; bool DeleteAttributeClassX(ATTRIBUTES *pA); @@ -72,14 +74,14 @@ class ATTRIBUTES final [[nodiscard]] ATTRIBUTES *GetAttributeClassByCode(uint32_t name_code) const; [[nodiscard]] ATTRIBUTES *VerifyAttributeClassByCode(uint32_t name_code); ATTRIBUTES *CreateAttribute(uint32_t name_code, const char *attribute); - [[deprecated("Pass attribute value by string_view instead")]] size_t SetAttribute(uint32_t name_code, - const char *attribute); + [[deprecated("Pass attribute value by string_view instead")]] + size_t SetAttribute(uint32_t name_code, const char *attribute); size_t SetAttribute(uint32_t name_code, const std::string_view &attribute); [[nodiscard]] uint32_t GetThisNameCode() const noexcept; void SetNameCode(uint32_t n) noexcept; [[nodiscard]] VSTRING_CODEC &GetStringCodec() const noexcept; - private: +private: ATTRIBUTES(VSTRING_CODEC &string_codec, ATTRIBUTES *parent, const std::string_view &name); ATTRIBUTES(VSTRING_CODEC &string_codec, ATTRIBUTES *parent, uint32_t name_code); @@ -92,7 +94,7 @@ class ATTRIBUTES final std::vector> attributes_; ATTRIBUTES *parent_{nullptr}; bool break_{false}; - + class LegacyProxy { using value_t = decltype(value_); @@ -101,11 +103,11 @@ class ATTRIBUTES final public: LegacyProxy(const LegacyProxy &other) = delete; LegacyProxy(LegacyProxy &&other) = delete; - LegacyProxy &operator=(const LegacyProxy &other) = delete; - LegacyProxy &operator=(LegacyProxy &&other) = delete; + LegacyProxy & operator=(const LegacyProxy &other) = delete; + LegacyProxy & operator=(LegacyProxy &&other) = delete; LegacyProxy() : proxy_value_(null_value) - { + { } LegacyProxy(proxy_value_t value) : proxy_value_(value) @@ -134,3 +136,4 @@ class ATTRIBUTES final proxy_value_t proxy_value_; }; }; + diff --git a/src/libs/core/include/core.h b/src/libs/core/include/core.h index dea6703f1..37b6f5ce2 100644 --- a/src/libs/core/include/core.h +++ b/src/libs/core/include/core.h @@ -118,7 +118,9 @@ class Core virtual void EraseEntity(entid_t entity) = 0; virtual entid_t CreateEntity(const char *name, ATTRIBUTES *attr = nullptr) = 0; virtual entptr_t GetEntityPointer(entid_t entity) const = 0; + virtual entptr_t GetEntityPointerSafe(entid_t entity) const = 0; virtual entid_t GetEntityId(const char *name) const = 0; + virtual bool IsEntityValid(entid_t entity) const = 0; virtual entity_container_cref GetEntityIds(layer_type_t index) const = 0; virtual entity_container_cref GetEntityIds(layer_index_t index) const = 0; virtual entity_container_cref GetEntityIds(const char *name) const = 0; diff --git a/src/libs/core/include/v_file_service.h b/src/libs/core/include/v_file_service.h index ab2e5c5d5..672690538 100644 --- a/src/libs/core/include/v_file_service.h +++ b/src/libs/core/include/v_file_service.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include diff --git a/src/libs/core/src/attributes.cpp b/src/libs/core/src/attributes.cpp index 8eca6a619..2844875e3 100644 --- a/src/libs/core/src/attributes.cpp +++ b/src/libs/core/src/attributes.cpp @@ -3,7 +3,7 @@ #include "string_compare.hpp" #include "platform/platform.hpp" -ATTRIBUTES::ATTRIBUTES(VSTRING_CODEC *p) : ATTRIBUTES(*p) +ATTRIBUTES::ATTRIBUTES(VSTRING_CODEC *p): ATTRIBUTES(*p) { } @@ -13,7 +13,7 @@ ATTRIBUTES::ATTRIBUTES(ATTRIBUTES &&other) noexcept { } -ATTRIBUTES &ATTRIBUTES::operator=(ATTRIBUTES &&other) noexcept +ATTRIBUTES & ATTRIBUTES::operator=(ATTRIBUTES &&other) noexcept { stringCodec_ = other.stringCodec_; // Do not update name code @@ -41,12 +41,14 @@ ATTRIBUTES *ATTRIBUTES::GetParent() const return parent_; } -bool ATTRIBUTES::operator==(const std::string_view &str) const +bool ATTRIBUTES::operator==(const char *str) const { + if (!str || !str[0]) + return false; return storm::iEquals(stringCodec_.Convert(nameCode_), str); } -std::string_view ATTRIBUTES::GetThisName() const +const char *ATTRIBUTES::GetThisName() const { return stringCodec_.Convert(nameCode_); } @@ -56,7 +58,7 @@ bool ATTRIBUTES::HasValue() const noexcept return value_.has_value(); } -const std::string &ATTRIBUTES::GetValue() const +const std::string & ATTRIBUTES::GetValue() const { return *value_; } @@ -64,11 +66,12 @@ const std::string &ATTRIBUTES::GetValue() const ATTRIBUTES::LegacyProxy ATTRIBUTES::GetThisAttr() const { return value_; + } void ATTRIBUTES::SetName(const std::string_view &new_name) { - nameCode_ = stringCodec_.Convert(new_name); + nameCode_ = stringCodec_.Convert(new_name.data()); } void ATTRIBUTES::SetValue(const char *new_value) @@ -77,8 +80,7 @@ void ATTRIBUTES::SetValue(const char *new_value) { value_.reset(); } - else - { + else { value_ = new_value; } @@ -99,7 +101,7 @@ size_t ATTRIBUTES::GetAttributesNum() const return attributes_.size(); } -ATTRIBUTES *ATTRIBUTES::GetAttributeClass(const std::string_view &name) const +ATTRIBUTES * ATTRIBUTES::GetAttributeClass(const std::string_view &name) const { for (const auto &attribute : attributes_) if (storm::iEquals(name, attribute->GetThisName())) @@ -107,7 +109,7 @@ ATTRIBUTES *ATTRIBUTES::GetAttributeClass(const std::string_view &name) const return nullptr; } -ATTRIBUTES *ATTRIBUTES::GetAttributeClass(uint32_t n) const +ATTRIBUTES * ATTRIBUTES::GetAttributeClass(uint32_t n) const { return n >= attributes_.size() ? nullptr : attributes_[n].get(); } @@ -118,7 +120,7 @@ ATTRIBUTES *ATTRIBUTES::VerifyAttributeClass(const std::string_view &name) return (pTemp) ? pTemp : CreateAttribute(name, ""); } -std::string_view ATTRIBUTES::GetAttributeName(size_t n) const +const char *ATTRIBUTES::GetAttributeName(size_t n) const { if (n < attributes_.size()) { @@ -126,28 +128,25 @@ std::string_view ATTRIBUTES::GetAttributeName(size_t n) const } else { - throw std::runtime_error( - fmt::format("Cannot get attribute name, attribute index ({}) out of range ({})", n, attributes_.size())); + return nullptr; } } ATTRIBUTES::LegacyProxy ATTRIBUTES::GetAttribute(size_t n) const { - if (n < attributes_.size()) - { + if (n < attributes_.size()) { return attributes_[n]->value_; } - else - { + else { return {}; } } + ATTRIBUTES::LegacyProxy ATTRIBUTES::GetAttribute(const std::string_view &name) const { for (const auto &attribute : attributes_) - if (storm::iEquals(name, attribute->GetThisName())) - { + if (storm::iEquals(name, attribute->GetThisName())) { return attribute->value_; } return {}; @@ -164,7 +163,7 @@ uint32_t ATTRIBUTES::GetAttributeAsDword(const char *name, uint32_t def) const } else { - vDword = atol(value_->c_str()); + vDword = atol( value_->c_str()); } return vDword; } @@ -221,13 +220,13 @@ bool ATTRIBUTES::SetAttributeUseFloat(const char *name, float val) return true; } -ATTRIBUTES &ATTRIBUTES::CreateAttribute(const std::string_view &name) +ATTRIBUTES & ATTRIBUTES::CreateAttribute(const std::string_view &name) { const auto &attr = attributes_.emplace_back(new ATTRIBUTES(stringCodec_, this, name)); return *attr; } -ATTRIBUTES *ATTRIBUTES::CreateAttribute(const std::string_view &name, const char *attribute) +ATTRIBUTES * ATTRIBUTES::CreateAttribute(const std::string_view &name, const char *attribute) { const auto &attr = attributes_.emplace_back(new ATTRIBUTES(stringCodec_, this, name)); @@ -241,12 +240,12 @@ ATTRIBUTES *ATTRIBUTES::CreateAttribute(const std::string_view &name, const char size_t ATTRIBUTES::SetAttribute(const std::string_view &name, const char *attribute) { - return SetAttribute(stringCodec_.Convert(name), attribute); + return SetAttribute(stringCodec_.Convert(name.data()), attribute); } size_t ATTRIBUTES::SetAttribute(const std::string_view &name, const std::string_view &attribute) { - return SetAttribute(stringCodec_.Convert(name), attribute); + return SetAttribute(stringCodec_.Convert(name.data()), attribute); } bool ATTRIBUTES::DeleteAttributeClassX(ATTRIBUTES *pA) @@ -281,7 +280,7 @@ bool ATTRIBUTES::DeleteAttributeClassX(ATTRIBUTES *pA) return false; } -ATTRIBUTES *ATTRIBUTES::CreateSubAClass(ATTRIBUTES *pRoot, const char *access_string) +ATTRIBUTES * ATTRIBUTES::CreateSubAClass(ATTRIBUTES *pRoot, const char *access_string) { uint32_t dwNameCode; uint32_t n = 0; @@ -297,7 +296,7 @@ ATTRIBUTES *ATTRIBUTES::CreateSubAClass(ATTRIBUTES *pRoot, const char *access_st switch (access_string[n]) { case '.': - dwNameCode = stringCodec_.Convert(std::string_view(access_string, n)); + dwNameCode = stringCodec_.Convert(access_string, n); pTemp = pRoot->GetAttributeClassByCode(dwNameCode); if (!pTemp) pTemp = pRoot->CreateNewAttribute(dwNameCode); @@ -308,14 +307,14 @@ ATTRIBUTES *ATTRIBUTES::CreateSubAClass(ATTRIBUTES *pRoot, const char *access_st dwNameCode = stringCodec_.Convert(access_string); pResult = pRoot->GetAttributeClassByCode(dwNameCode); return (pResult) ? pResult : pRoot->CreateNewAttribute(dwNameCode); - default:; + default: ; } n++; } return nullptr; } -ATTRIBUTES *ATTRIBUTES::FindAClass(ATTRIBUTES *pRoot, const char *access_string) +ATTRIBUTES * ATTRIBUTES::FindAClass(ATTRIBUTES *pRoot, const char *access_string) { uint32_t n = 0; ATTRIBUTES *pResult = nullptr; @@ -331,7 +330,7 @@ ATTRIBUTES *ATTRIBUTES::FindAClass(ATTRIBUTES *pRoot, const char *access_string) switch (access_string[n]) { case '.': - pTemp = pRoot->GetAttributeClassByCode(stringCodec_.Convert(std::string_view(access_string, n))); + pTemp = pRoot->GetAttributeClassByCode(stringCodec_.Convert(access_string, n)); if (!pTemp) return nullptr; pResult = FindAClass(pTemp, &access_string[n + 1]); @@ -339,14 +338,14 @@ ATTRIBUTES *ATTRIBUTES::FindAClass(ATTRIBUTES *pRoot, const char *access_string) case 0: pResult = pRoot->GetAttributeClassByCode(stringCodec_.Convert(access_string)); return pResult; - default:; + default: ; } n++; } return nullptr; } -ATTRIBUTES *ATTRIBUTES::GetAttributeClassByCode(uint32_t name_code) const +ATTRIBUTES * ATTRIBUTES::GetAttributeClassByCode(uint32_t name_code) const { for (const auto &attribute : attributes_) if (name_code == attribute->nameCode_) @@ -354,7 +353,7 @@ ATTRIBUTES *ATTRIBUTES::GetAttributeClassByCode(uint32_t name_code) const return nullptr; } -ATTRIBUTES *ATTRIBUTES::VerifyAttributeClassByCode(uint32_t name_code) +ATTRIBUTES * ATTRIBUTES::VerifyAttributeClassByCode(uint32_t name_code) { ATTRIBUTES *pTemp = GetAttributeClassByCode(name_code); if (pTemp) @@ -362,7 +361,7 @@ ATTRIBUTES *ATTRIBUTES::VerifyAttributeClassByCode(uint32_t name_code) return CreateAttribute(name_code, ""); } -ATTRIBUTES *ATTRIBUTES::CreateAttribute(uint32_t name_code, const char *attribute) +ATTRIBUTES * ATTRIBUTES::CreateAttribute(uint32_t name_code, const char *attribute) { const auto &attr = attributes_.emplace_back(new ATTRIBUTES(stringCodec_, this, name_code)); @@ -399,8 +398,7 @@ size_t ATTRIBUTES::SetAttribute(uint32_t name_code, const char *attribute) { attributes_[n]->value_ = attribute; } - else - { + else { attributes_[n]->value_.reset(); } @@ -436,12 +434,12 @@ void ATTRIBUTES::SetNameCode(uint32_t n) noexcept nameCode_ = n; } -VSTRING_CODEC &ATTRIBUTES::GetStringCodec() const noexcept +VSTRING_CODEC & ATTRIBUTES::GetStringCodec() const noexcept { return stringCodec_; } -ATTRIBUTES *ATTRIBUTES::CreateNewAttribute(uint32_t name_code) +ATTRIBUTES * ATTRIBUTES::CreateNewAttribute(uint32_t name_code) { const std::unique_ptr &attr = attributes_.emplace_back(new ATTRIBUTES(stringCodec_, this, name_code)); return attr.get(); @@ -452,7 +450,7 @@ ATTRIBUTES::ATTRIBUTES(VSTRING_CODEC &p) : ATTRIBUTES(p, nullptr, "root") } ATTRIBUTES::ATTRIBUTES(VSTRING_CODEC &string_codec, ATTRIBUTES *parent, const std::string_view &name) - : ATTRIBUTES(string_codec, parent, string_codec.Convert(name)) + : ATTRIBUTES(string_codec, parent, string_codec.Convert(name.data())) { } diff --git a/src/libs/core/src/compiler.cpp b/src/libs/core/src/compiler.cpp index c88a871f3..3ffe29702 100644 --- a/src/libs/core/src/compiler.cpp +++ b/src/libs/core/src/compiler.cpp @@ -176,6 +176,7 @@ void COMPILER::Release() SStack.Release(); EventTab.Release(); EventMsg.Release(); + SCodec.Release(); LibriaryFuncs.clear(); delete[] pDebExpBuffer; @@ -2581,6 +2582,12 @@ bool COMPILER::CompileBlock(SEGMENT_DESC &Segment, bool &bFunctionBlock, uint32_ // CompileToken(Segment,EX); CompileToken(Segment, POP_EXPRESULT); // pop + + if (bound_type == IF_BLOCK) + { + return true; + } + break; case ELSE_BLOCK: update_offset = Segment.BCode_Program_size + 2; @@ -2595,7 +2602,8 @@ bool COMPILER::CompileBlock(SEGMENT_DESC &Segment, bool &bFunctionBlock, uint32_ else { Token.StepBack(); - if (!CompileBlock(Segment, bFunctionBlock, inout, SEPARATOR, continue_jump, break_offset, BreakTable)) + if (!CompileBlock(Segment, bFunctionBlock, inout, Token_type == IF_BLOCK ? IF_BLOCK : SEPARATOR, + continue_jump, break_offset, BreakTable)) return false; } memcpy(&Segment.pCode[update_offset], &Segment.BCode_Program_size, sizeof(uint32_t)); @@ -5716,11 +5724,7 @@ bool COMPILER::BC_Execute(uint32_t function_code, DATA *&pVReturnResult, const c else rAP = rAP->GetAttributeClassByCode(*((int32_t *)&pRunCodeBase[TLR_DataOffset])); if (!rAP) - { - std::string error_message = fmt::format( - "missed attribute: {}", SCodec.Convert(*((int32_t *)&pRunCodeBase[TLR_DataOffset]))); - SetError(error_message.c_str()); - } + SetError("missed attribute: %s", SCodec.Convert(*((int32_t *)&pRunCodeBase[TLR_DataOffset]))); break; case VARIABLE: real_var = VarTab.GetVar(*((int32_t *)&pRunCodeBase[TLR_DataOffset])); @@ -6139,13 +6143,11 @@ ATTRIBUTES *COMPILER::TraceARoot(ATTRIBUTES *pA, const char *&pAccess) if (pA->GetThisNameCode() == 0) return nullptr; // fix crash at NewGame start - const std::string_view attr_name = pA->GetThisName(); - const int32_t slen = attr_name.length() + 1; + const int32_t slen = strlen(pA->GetThisName()) + 1; char *pAS = new char[slen]; - std::copy(std::begin(attr_name), std::end(attr_name), pAS); - pAS[slen - 1] = '\0'; + memcpy(pAS, pA->GetThisName(), slen); if (pAccess == nullptr) { @@ -7266,42 +7268,38 @@ void COMPILER::PrintoutUsage() core.Controls->GetDebugAsyncKeyState(VK_SHIFT) < 0) { logTrace_->debug("Script Function Time Usage[func name/code(release mode) : ticks]"); - for (size_t m = 0; m < FuncTab.GetFuncNum(); m++) + FuncInfo fi; + for (size_t n = 0; n < FuncTab.GetFuncNum(); n++) { - FuncInfo fi; - for (size_t n = 0; n < FuncTab.GetFuncNum(); n++) + FuncTab.GetFuncX(fi, n); + if (fi.number_of_calls == 0) { - FuncTab.GetFuncX(fi, n); - if (fi.number_of_calls == 0) - { - continue; - } - - FuncTab.GetFunc(fi, n); - if (!fi.name.empty()) - { - logTrace_->debug(" {}", fi.name); - } - else - { - logTrace_->debug(" {}", n); - } - logTrace_->debug(" ticks summary : {}", fi.usage_time); - logTrace_->debug(" calls : {}", fi.number_of_calls); - if (fi.number_of_calls != 0) - { - logTrace_->debug(" average ticks : {}", static_cast(fi.usage_time) / fi.number_of_calls); - } + continue; + } - FuncTab.AddTime(n, ~fi.usage_time); - logTrace_->debug(""); + FuncTab.GetFunc(fi, n); + if (!fi.name.empty()) + { + logTrace_->debug(" {}", fi.name); + } + else + { + logTrace_->debug(" {}", n); + } + logTrace_->debug(" ticks summary : {}", fi.usage_time); + logTrace_->debug(" calls : {}", fi.number_of_calls); + if (fi.number_of_calls != 0) + { + logTrace_->debug(" average ticks : {}", static_cast(fi.usage_time) / fi.number_of_calls); } + logTrace_->debug(""); } + FuncTab.ResetTimeAndCalls(); logTrace_->debug("Script Run Time Log [sec : ms]"); for (size_t n = 0; n < nRuntimeLogEventsNum; n++) { - logTrace_->debug(" %d : %d", n, pRuntimeLogEvent[n]); + logTrace_->debug(" {} : {}", n, pRuntimeLogEvent[n]); } } } diff --git a/src/libs/core/src/compiler.h b/src/libs/core/src/compiler.h index fca8241bd..63eab800f 100644 --- a/src/libs/core/src/compiler.h +++ b/src/libs/core/src/compiler.h @@ -4,9 +4,7 @@ #include #include "data.h" -#include "logging.hpp" #include "message.h" -#include "platform/platform.hpp" #include "s_deftab.h" #include "s_eventmsg.h" #include "s_eventtab.h" @@ -14,11 +12,13 @@ #include "s_postevents.h" #include "s_stack.h" #include "s_vartab.h" -#include "script_cache.h" #include "script_libriary.h" -#include "string_codec.hpp" +#include "string_codec.h" #include "strings_list.h" #include "token.h" +#include "logging.hpp" +#include "script_cache.h" +#include "platform/platform.hpp" #include "ringbuffer_stack.hpp" diff --git a/src/libs/core/src/core_impl.cpp b/src/libs/core/src/core_impl.cpp index c19751831..4f1b45e8f 100644 --- a/src/libs/core/src/core_impl.cpp +++ b/src/libs/core/src/core_impl.cpp @@ -10,7 +10,7 @@ #include "string_compare.hpp" #include -Core& core = core_internal; +Core &core = core_internal; uint64_t get_performance_counter() { @@ -104,21 +104,21 @@ void CoreImpl::Init() Compiler = new COMPILER; /* TODO: place this outside CoreImpl */ - core.SetLayerType(EXECUTE, layer_type_t::execute); - core.SetLayerType(REALIZE, layer_type_t::realize); - core.SetLayerType(SEA_EXECUTE, layer_type_t::execute); - core.SetLayerType(SEA_REALIZE, layer_type_t::realize); - core.SetLayerType(INTERFACE_EXECUTE, layer_type_t::execute); - core.SetLayerType(INTERFACE_REALIZE, layer_type_t::realize); - core.SetLayerType(FADER_EXECUTE, layer_type_t::execute); - core.SetLayerType(FADER_REALIZE, layer_type_t::realize); - core.SetLayerType(LIGHTER_EXECUTE, layer_type_t::execute); - core.SetLayerType(LIGHTER_REALIZE, layer_type_t::realize); - core.SetLayerType(VIDEO_EXECUTE, layer_type_t::execute); - core.SetLayerType(VIDEO_REALIZE, layer_type_t::realize); - core.SetLayerType(EDITOR_REALIZE, layer_type_t::realize); - core.SetLayerType(INFO_REALIZE, layer_type_t::realize); - core.SetLayerType(SOUND_DEBUG_REALIZE, layer_type_t::realize); + SetLayerType(EXECUTE, layer_type_t::execute); + SetLayerType(REALIZE, layer_type_t::realize); + SetLayerType(SEA_EXECUTE, layer_type_t::execute); + SetLayerType(SEA_REALIZE, layer_type_t::realize); + SetLayerType(INTERFACE_EXECUTE, layer_type_t::execute); + SetLayerType(INTERFACE_REALIZE, layer_type_t::realize); + SetLayerType(FADER_EXECUTE, layer_type_t::execute); + SetLayerType(FADER_REALIZE, layer_type_t::realize); + SetLayerType(LIGHTER_EXECUTE, layer_type_t::execute); + SetLayerType(LIGHTER_REALIZE, layer_type_t::realize); + SetLayerType(VIDEO_EXECUTE, layer_type_t::execute); + SetLayerType(VIDEO_REALIZE, layer_type_t::realize); + SetLayerType(EDITOR_REALIZE, layer_type_t::realize); + SetLayerType(INFO_REALIZE, layer_type_t::realize); + SetLayerType(SOUND_DEBUG_REALIZE, layer_type_t::realize); } void CoreImpl::InitBase() @@ -330,7 +330,7 @@ void CoreImpl::Exit() Exit_flag = true; } -storm::OSWindow * CoreImpl::GetWindow() +storm::OSWindow *CoreImpl::GetWindow() { return window_.get(); } @@ -353,7 +353,7 @@ void CoreImpl::SetTimeScale(float _scale) uint64_t CoreImpl::Send_Message(entid_t Destination, const char *Format, ...) { MESSAGE message; - auto *const ptr = core.GetEntityPointer(Destination); // check for valid destination + auto *const ptr = GetEntityPointerSafe(Destination); // check for valid destination if (!ptr) return 0; @@ -439,7 +439,7 @@ VDATA *CoreImpl::Event(const std::string_view &event_name) return Compiler->ProcessEvent(event_name.data(), message); } -VDATA *CoreImpl::Event(const std::string_view &event_name, MESSAGE& message) +VDATA *CoreImpl::Event(const std::string_view &event_name, MESSAGE &message) { return Compiler->ProcessEvent(event_name.data(), message); } @@ -537,7 +537,7 @@ void CoreImpl::ProcessExecute() const auto &entIds = core.GetEntityIds(layer_type_t::execute); for (auto id : entIds) { - if (auto *ptr = core.GetEntityPointer(id)) + if (auto *ptr = core.GetEntityPointerSafe(id)) { ptr->ProcessStage(Entity::Stage::execute, deltatime); } @@ -555,7 +555,7 @@ void CoreImpl::ProcessRealize() const auto &entIds = core.GetEntityIds(layer_type_t::realize); for (auto id : entIds) { - if (auto *ptr = core.GetEntityPointer(id)) + if (auto *ptr = core.GetEntityPointerSafe(id)) { ptr->ProcessStage(Entity::Stage::realize, deltatime); } @@ -677,7 +677,7 @@ uint32_t CoreImpl::GetRDeltaTime() ATTRIBUTES *CoreImpl::Entity_GetAttributeClass(entid_t id_PTR, const char *name) { - Entity *pE = core.GetEntityPointer(id_PTR); + Entity *pE = GetEntityPointer(id_PTR); if (pE == nullptr) return nullptr; if (pE->AttributesPointer == nullptr) @@ -687,7 +687,7 @@ ATTRIBUTES *CoreImpl::Entity_GetAttributeClass(entid_t id_PTR, const char *name) const char *CoreImpl::Entity_GetAttribute(entid_t id_PTR, const char *name) { - Entity *pE = core.GetEntityPointer(id_PTR); + Entity *pE = GetEntityPointer(id_PTR); if (pE == nullptr) return nullptr; if (pE->AttributesPointer == nullptr) @@ -697,7 +697,7 @@ const char *CoreImpl::Entity_GetAttribute(entid_t id_PTR, const char *name) uint32_t CoreImpl::Entity_GetAttributeAsDword(entid_t id_PTR, const char *name, uint32_t def) { - Entity *pE = core.GetEntityPointer(id_PTR); + Entity *pE = GetEntityPointer(id_PTR); if (pE == nullptr) return def; if (pE->AttributesPointer == nullptr) @@ -707,7 +707,7 @@ uint32_t CoreImpl::Entity_GetAttributeAsDword(entid_t id_PTR, const char *name, FLOAT CoreImpl::Entity_GetAttributeAsFloat(entid_t id_PTR, const char *name, FLOAT def) { - Entity *pE = core.GetEntityPointer(id_PTR); + Entity *pE = GetEntityPointer(id_PTR); if (pE == nullptr) return def; if (pE->AttributesPointer == nullptr) @@ -717,7 +717,7 @@ FLOAT CoreImpl::Entity_GetAttributeAsFloat(entid_t id_PTR, const char *name, FLO bool CoreImpl::Entity_SetAttribute(entid_t id_PTR, const char *name, const char *attribute) { - Entity *pE = core.GetEntityPointer(id_PTR); + Entity *pE = GetEntityPointer(id_PTR); if (pE == nullptr) return false; if (pE->AttributesPointer == nullptr) @@ -727,7 +727,7 @@ bool CoreImpl::Entity_SetAttribute(entid_t id_PTR, const char *name, const char bool CoreImpl::Entity_SetAttributeUseDword(entid_t id_PTR, const char *name, uint32_t val) { - Entity *pE = core.GetEntityPointer(id_PTR); + Entity *pE = GetEntityPointer(id_PTR); if (pE == nullptr) return false; if (pE->AttributesPointer == nullptr) @@ -737,7 +737,7 @@ bool CoreImpl::Entity_SetAttributeUseDword(entid_t id_PTR, const char *name, uin bool CoreImpl::Entity_SetAttributeUseFloat(entid_t id_PTR, const char *name, FLOAT val) { - Entity *pE = core.GetEntityPointer(id_PTR); + Entity *pE = GetEntityPointer(id_PTR); if (pE == nullptr) return false; if (pE->AttributesPointer == nullptr) @@ -747,7 +747,7 @@ bool CoreImpl::Entity_SetAttributeUseFloat(entid_t id_PTR, const char *name, FLO void CoreImpl::Entity_SetAttributePointer(entid_t id_PTR, ATTRIBUTES *pA) { - Entity *pE = core.GetEntityPointer(id_PTR); + Entity *pE = GetEntityPointer(id_PTR); if (pE == nullptr) return; pE->AttributesPointer = pA; @@ -755,7 +755,7 @@ void CoreImpl::Entity_SetAttributePointer(entid_t id_PTR, ATTRIBUTES *pA) uint32_t CoreImpl::Entity_AttributeChanged(entid_t id_PTR, ATTRIBUTES *pA) { - Entity *pE = core.GetEntityPointer(id_PTR); + Entity *pE = GetEntityPointer(id_PTR); if (pE == nullptr) return 0; return pE->AttributeChanged(pA); @@ -763,7 +763,7 @@ uint32_t CoreImpl::Entity_AttributeChanged(entid_t id_PTR, ATTRIBUTES *pA) ATTRIBUTES *CoreImpl::Entity_GetAttributePointer(entid_t id_PTR) { - Entity *pE = core.GetEntityPointer(id_PTR); + Entity *pE = GetEntityPointer(id_PTR); if (pE == nullptr) return nullptr; return pE->AttributesPointer; @@ -960,11 +960,21 @@ entptr_t CoreImpl::GetEntityPointer(entid_t id) const return entity_manager_.GetEntityPointer(id); } +entptr_t CoreImpl::GetEntityPointerSafe(entid_t id) const +{ + return entity_manager_.IsEntityValid(id) ? GetEntityPointer(id) : nullptr; +} + entid_t CoreImpl::GetEntityId(const char *name) const { return entity_manager_.GetEntityId(name); } +bool CoreImpl::IsEntityValid(entid_t id) const +{ + return entity_manager_.IsEntityValid(id); +} + entity_container_cref CoreImpl::GetEntityIds(layer_type_t type) const { return entity_manager_.GetEntityIds(type); @@ -1010,7 +1020,7 @@ void CoreImpl::ForEachEntity(const std::function &f) entity_manager_.ForEachEntity(f); } -void CoreImpl:: collectCrashInfo() const +void CoreImpl::collectCrashInfo() const { Compiler->CollectCallStack(); } diff --git a/src/libs/core/src/core_impl.h b/src/libs/core/src/core_impl.h index 349de2008..a46ba4d3c 100644 --- a/src/libs/core/src/core_impl.h +++ b/src/libs/core/src/core_impl.h @@ -8,8 +8,6 @@ #include "timer.h" #include "vma.hpp" -#include - #define ENGINE_SCRIPT_VERSION 54128 class CoreImpl final : public CorePrivate @@ -122,7 +120,9 @@ class CoreImpl final : public CorePrivate void EraseEntity(entid_t entity) override; entid_t CreateEntity(const char *name, ATTRIBUTES *attr) override; entptr_t GetEntityPointer(entid_t id) const override; + entptr_t GetEntityPointerSafe(entid_t id) const override; entid_t GetEntityId(const char *name) const override; + bool IsEntityValid(entid_t id) const override; entity_container_cref GetEntityIds(layer_type_t type) const override; entity_container_cref GetEntityIds(layer_index_t index) const override; entity_container_cref GetEntityIds(const char *name) const override; diff --git a/src/libs/core/src/entity_manager.cpp b/src/libs/core/src/entity_manager.cpp index 0e0b8fda0..f8bf3f4f6 100644 --- a/src/libs/core/src/entity_manager.cpp +++ b/src/libs/core/src/entity_manager.cpp @@ -21,21 +21,20 @@ using invalid_entity_idx_t = std::integral_constant> i & 1) { RemoveFromLayer(i, data); } } - delete data.ptr; } -void EntityManager::MarkDeleted(const entid_t id) +void EntityManager::MarkDeleted(EntityInternalData &data) { - const auto index = static_cast(id); - entities_[index].valid = false; + data.state = kExists; + const auto index = static_cast(data.id); deletedIndices_.push(index); } @@ -52,7 +51,7 @@ hash_t EntityManager::GetClassCode(const entid_t id) const void EntityManager::AddToLayer(const layer_index_t index, EntityInternalData &data, const priority_t priority) { - assert(index < max_layers_num); + assert(index < kMaxLayerNum); // set info about layer data.mask |= 1 << index; @@ -65,8 +64,7 @@ void EntityManager::AddToLayer(const layer_index_t index, EntityInternalData &da // duplicate assert assert(std::ranges::find(entity_ids, data.id) == std::end(entity_ids)); - const auto targetIdx = - std::distance(std::begin(priorities), std::ranges::upper_bound(priorities, priority)); + const auto targetIdx = std::distance(std::begin(priorities), std::ranges::upper_bound(priorities, priority)); priorities.insert(std::begin(priorities) + targetIdx, priority); entity_ids.insert(std::begin(entity_ids) + targetIdx, data.id); @@ -74,7 +72,7 @@ void EntityManager::AddToLayer(const layer_index_t index, EntityInternalData &da void EntityManager::RemoveFromLayer(const layer_index_t index, EntityInternalData &data) { - assert(index < max_layers_num); + assert(index < kMaxLayerNum); auto &mask = data.mask; @@ -150,10 +148,11 @@ entid_t EntityManager::CreateEntity(const char *name, ATTRIBUTES *attr) cache_.UpdateErase(hash, id); // delete if fail - MarkDeleted(id); + const auto index = static_cast(id); + MarkDeleted(entities_[index]); return invalid_entity; } - + return id; } @@ -165,10 +164,10 @@ void EntityManager::EraseEntity(const entid_t id) return; } - const auto &data = entities_[idx]; + auto &data = entities_[idx]; // check if already erased - if (data.valid == false) + if (data.state != kValid) { return; } @@ -181,22 +180,23 @@ void EntityManager::EraseEntity(const entid_t id) // remove from cache cache_.UpdateErase(data.hash, id); - - MarkDeleted(id); + MarkDeleted(data); } void EntityManager::EraseAll() { for (auto it = std::begin(entities_); it != std::end(entities_); ++it) { - const auto index = static_cast(it->id); - - // release - EraseAndFree(entities_[index]); - entities_[index] = {}; + it->state = kNotExists; + delete it->ptr; } // clear containers + for (auto &layer : layers_) + { + layer.entity_ids.clear(); + layer.priorities.clear(); + } entities_.clear(); freeIndices_.clear(); deletedIndices_.clear(); @@ -213,33 +213,6 @@ entptr_t EntityManager::GetEntityPointer(const entid_t id) const return nullptr; } - // This check was intentionally removed to workaround some rare corner cases that are not handled properly. - // - // Here's an example of such a corner case that leads to crash due to missing sanity checks: - // Location entity is being destroyed (marked as invalid) from scripts. Therefore in the next frame its - // destructor is called, invoking Supervisor destructor which in turn destroys (marks as invalid) all the - // Player entities. - // Here's how it looks like: - // + - exists and operates; ! - invalidated (marked as invalid); x - deleted - // | Frame 0 | Frame 1 | Frame 2 | Frame 3 | - // Location | + | ! | x | x | - // Supervisor | + | + | x | x | - // Players[s] | + | + | ! | x | - // - // As it's shown, while Player[s] exists Location is always marked as invalid and doesn't return its pointer. - // At this point using an existing pointer to Location without check for validity would work (despite the - // inadmissibility of such); but calling GetEntityPointer legally returns nullptr due to `valid` flag unset. - // This case is exacerbated by the fact that in this corner case calls to `Player` are done via PostEvent. - // - // Although in this case it would be more consistent with introducing sanity checks over the code, - // such issues are very difficult to catch. And since this workaround doesn't introduce any harm except for - // encouraging inconsistency code, it makes sense to left it as a lifebuoy for the existing issues. - // - // if (!entities_[idx].valid) - // { - // return nullptr; - // } - return entities_[idx].ptr; } @@ -249,7 +222,7 @@ entity_container_cref EntityManager::GetEntityIds(const layer_type_t type) const static std::vector result; result.reserve(entities_.size()); result.clear(); - + for (auto it = std::begin(layers_); it != std::end(layers_); ++it) { if (it->frozen) @@ -262,7 +235,7 @@ entity_container_cref EntityManager::GetEntityIds(const layer_type_t type) const std::ranges::copy(it->entity_ids, std::back_inserter(result)); } } - + // TODO: Investigate: // Some entities are referenced in multiple layers of same type // therefore there are getting processed multiple times. @@ -290,7 +263,7 @@ entity_container_cref EntityManager::GetEntityIds(const uint32_t hash) const { for (auto it = std::begin(entities_); it != std::end(entities_); ++it) { - if (it->hash == hash && it->valid) + if (it->hash == hash && it->state == kValid) { cache_.Add(hash, it->id); empty = false; @@ -303,7 +276,7 @@ entity_container_cref EntityManager::GetEntityIds(const uint32_t hash) const entity_container_cref EntityManager::GetEntityIds(const layer_index_t index) const { - assert(index < max_layers_num); + assert(index < kMaxLayerNum); return layers_[index].entity_ids; } @@ -313,11 +286,17 @@ entid_t EntityManager::GetEntityId(const char *name) const return GetEntityId(MakeHashValue(name)); } +bool EntityManager::IsEntityValid(entid_t id) const +{ + const auto index = GetEntityDataIdx(id); + return EntIdxValid(index) && entities_[index].state == kValid; +} + entid_t EntityManager::GetEntityId(const uint32_t hash) const { for (auto it = std::begin(entities_); it != std::end(entities_); ++it) { - if (it->hash == hash && it->valid) + if (it->hash == hash && it->state == kValid) { return it->id; } @@ -349,28 +328,28 @@ entid_t EntityManager::CalculateEntityId(const size_t idx) layer_type_t EntityManager::GetLayerType(const layer_index_t index) const { - assert(index < max_layers_num); + assert(index < kMaxLayerNum); return layers_[index].type; } void EntityManager::SetLayerType(const layer_index_t index, const layer_type_t type) { - assert(index < max_layers_num); + assert(index < kMaxLayerNum); layers_[index].type = type; } void EntityManager::SetLayerFrozen(const layer_index_t index, const bool freeze) { - assert(index < max_layers_num); + assert(index < kMaxLayerNum); layers_[index].frozen = freeze; } bool EntityManager::IsLayerFrozen(const layer_index_t index) const { - assert(index < max_layers_num); + assert(index < kMaxLayerNum); return layers_[index].frozen; } @@ -408,10 +387,11 @@ void EntityManager::NewLifecycle() assert(entity_idx < entities_.size()); deletedIndices_.pop(); + auto &data = entities_[entity_idx]; // release - EraseAndFree(entities_[entity_idx]); + EraseAndFree(data); // erase entity data - entities_[entity_idx] = {}; + data = {}; // push free index to stack instead of shifting freeIndices_.push(entity_idx); } @@ -433,7 +413,32 @@ size_t EntityManager::GetEntityDataIdx(const entid_t id) const // check validity auto &data = entities_[index]; - if(data.valid == false) + // This check was intentionally removed to workaround some rare corner cases that are not handled properly. + // + // Here's an example of such a corner case that leads to crash due to missing sanity checks: + // Location entity is being destroyed (marked as invalid) from scripts. Therefore in the next frame its + // destructor is called, invoking Supervisor destructor which in turn destroys (marks as invalid) all the + // Player entities. + // Here's how it looks like: + // + - exists and operates; ! - invalidated (marked as invalid); x - deleted + // | Frame 0 | Frame 1 | Frame 2 | Frame 3 | + // Location | + | ! | x | x | + // Supervisor | + | + | x | x | + // Players[s] | + | + | ! | x | + // + // As it's shown, while Player[s] exists Location is always marked as invalid and doesn't return its pointer. + // At this point using an existing pointer to Location without check for validity would work (despite the + // inadmissibility of such); but calling GetEntityPointer legally returns nullptr due to `valid` flag unset. + // This case is exacerbated by the fact that in this corner case calls to `Player` are done via PostEvent. + // + // Although in this case it would be more consistent with introducing sanity checks over the code, + // such issues are very difficult to catch. And since this workaround doesn't introduce any harm except for + // encouraging inconsistency code, it makes sense to left it as a lifebuoy for the existing issues. + // if (data.valid == false) + // { + // return invalid_entity_idx_t{}; + // } + if (data.state == kNotExists) { return invalid_entity_idx_t{}; } @@ -443,7 +448,6 @@ size_t EntityManager::GetEntityDataIdx(const entid_t id) const { return invalid_entity_idx_t{}; } - return index; } @@ -455,14 +459,14 @@ entid_t EntityManager::InsertEntity(entptr_t ptr, hash_t hash) { const entid_index_t index = std::size(entities_); id = CalculateEntityId(index); - entities_.emplace_back(EntityInternalData{true, {}, {}, ptr, id, hash}); + entities_.emplace_back(EntityInternalData{{}, {}, kValid, ptr, id, hash}); } else { const entid_index_t index = freeIndices_.top(); id = CalculateEntityId(index); freeIndices_.pop(); - entities_[index] = {true, {}, {}, ptr, id, hash}; + entities_[index] = {{}, {}, kValid, ptr, id, hash}; } return id; @@ -470,10 +474,13 @@ entid_t EntityManager::InsertEntity(entptr_t ptr, hash_t hash) void EntityManager::ForEachEntity(const std::function &f) { - std::ranges::for_each(entities_, [&](const EntityInternalData& data) { - if (const auto entity_ptr = GetEntityPointer(data.id)) + std::ranges::for_each(entities_, [&](const EntityInternalData &data) { + if (data.state == kValid) + { + if (const auto entity_ptr = GetEntityPointer(data.id)) { f(entity_ptr); } - }); + } + }); } diff --git a/src/libs/core/src/entity_manager.h b/src/libs/core/src/entity_manager.h index 49c79ed03..a16d49583 100644 --- a/src/libs/core/src/entity_manager.h +++ b/src/libs/core/src/entity_manager.h @@ -1,9 +1,8 @@ #pragma once -#include - #include #include +#include #include #include "plf_stack.h" @@ -11,22 +10,52 @@ #include "entity.h" #include "entity_container_cache.h" - class EntityManager final { - constexpr static size_t max_layers_num = 32; // cannot exceed 32 + public: + hash_t GetClassCode(entid_t id) const; + entptr_t GetEntityPointer(entid_t id) const; + entity_container_cref GetEntityIds(layer_type_t type) const; + entity_container_cref GetEntityIds(const char *name) const; + entity_container_cref GetEntityIds(uint32_t hash) const; + entity_container_cref GetEntityIds(layer_index_t index) const; + entid_t GetEntityId(const char *name) const; + bool IsEntityValid(entid_t id) const; + layer_type_t GetLayerType(layer_index_t index) const; + bool IsLayerFrozen(layer_index_t index) const; + + void AddToLayer(layer_index_t layer_idx, entid_t entity_id, priority_t priority); // no bounds check + void RemoveFromLayer(layer_index_t layer_idx, entid_t entity_id); // no bounds check + entid_t CreateEntity(const char *name, ATTRIBUTES *attr = nullptr); + void EraseEntity(entid_t id); + void EraseAll(); + void SetLayerType(layer_index_t index, layer_type_t type); + void SetLayerFrozen(layer_index_t index, bool freeze); + void NewLifecycle(); + void ForEachEntity(const std::function &f); + + private: + constexpr static size_t kMaxLayerNum = sizeof(uint32_t) * 8; using entid_index_t = uint32_t; using entid_stamp_t = uint32_t; using entity_index_t = uint32_t; + enum EntityState : uint8_t + { + kNotExists = 0, + kExists = 1, + kValid = 2 + }; + struct EntityInternalData { using layer_mask_t = uint32_t; - bool valid; layer_mask_t mask; - priority_t priorities[max_layers_num]; + priority_t priorities[kMaxLayerNum]; + EntityState state; + entptr_t ptr; entid_t id; hash_t hash; @@ -40,28 +69,7 @@ class EntityManager final layer_type_t type; bool frozen; }; - public: - hash_t GetClassCode(entid_t id) const; - entptr_t GetEntityPointer(entid_t id) const; - entity_container_cref GetEntityIds(layer_type_t type) const; - entity_container_cref GetEntityIds(const char *name) const; - entity_container_cref GetEntityIds(uint32_t hash) const; - entity_container_cref GetEntityIds(layer_index_t index) const; - entid_t GetEntityId(const char *name) const; - layer_type_t GetLayerType(layer_index_t index) const; - bool IsLayerFrozen(layer_index_t index) const; - - void AddToLayer(layer_index_t layer_idx, entid_t entity_id, priority_t priority); // no bounds check - void RemoveFromLayer(layer_index_t layer_idx, entid_t entity_id); // no bounds check - entid_t CreateEntity(const char *name, ATTRIBUTES *attr = nullptr); - void EraseEntity(entid_t id); - void EraseAll(); - void SetLayerType(layer_index_t index, layer_type_t type); - void SetLayerFrozen(layer_index_t index, bool freeze); - void NewLifecycle(); - void ForEachEntity(const std::function &f); - private: static bool EntIdxValid(size_t idx); static entid_t CalculateEntityId(size_t idx); @@ -71,13 +79,13 @@ class EntityManager final void AddToLayer(layer_index_t index, EntityInternalData &data, priority_t priority); // no bounds check void RemoveFromLayer(layer_index_t index, EntityInternalData &data); // no bounds check void EraseAndFree(EntityInternalData &data); - void MarkDeleted(entid_t id); + void MarkDeleted(EntityInternalData &data); entid_t InsertEntity(entptr_t ptr, hash_t hash); mutable EntityContainerCache cache_; // array of layers - std::array layers_{}; + std::array layers_{}; // array of all entities std::vector entities_; diff --git a/src/libs/core/src/expression.cpp b/src/libs/core/src/expression.cpp index 94406c50c..1085776dc 100644 --- a/src/libs/core/src/expression.cpp +++ b/src/libs/core/src/expression.cpp @@ -757,9 +757,7 @@ void COMPILER::BC_ProcessExpression_L7(DATA *value, bool bSkip) if (pRoot == nullptr) { value->Set(""); - std::string error_message = fmt::format( - "missed attribute: {}", SCodec.Convert(*((int32_t *)&pRunCodeBase[TLR_DataOffset]))); - SetError(error_message.c_str()); + SetError("missed attribute: %s", SCodec.Convert(*((int32_t *)&pRunCodeBase[TLR_DataOffset]))); while (TokenType() == ACCESS_WORD_CODE || TokenType() == ACCESS_WORD || TokenType() == ACCESS_VAR) { BC_TokenGet(); @@ -770,9 +768,7 @@ void COMPILER::BC_ProcessExpression_L7(DATA *value, bool bSkip) if (pRoot == nullptr) { value->Set(""); - std::string error_message = fmt::format( - "missed attribute: {}", SCodec.Convert(*((int32_t *)&pRunCodeBase[TLR_DataOffset]))); - SetError(error_message.c_str()); + SetError("missed attribute: %s", SCodec.Convert(*((int32_t *)&pRunCodeBase[TLR_DataOffset]))); while (TokenType() == ACCESS_WORD_CODE || TokenType() == ACCESS_WORD || TokenType() == ACCESS_VAR) { BC_TokenGet(); diff --git a/src/libs/core/src/internal_functions.cpp b/src/libs/core/src/internal_functions.cpp index 5b3a3cf97..8a5df1cd1 100644 --- a/src/libs/core/src/internal_functions.cpp +++ b/src/libs/core/src/internal_functions.cpp @@ -709,7 +709,7 @@ DATA *COMPILER::BC_CallIntFunction(uint32_t func_code, DATA *&pVResult, uint32_t pV2->SetType(VAR_AREFERENCE); pV2->SetAReference(core_internal.Entity_GetAttributePointer(ent)); - if (core.GetEntityPointer(ent)) + if (core.IsEntityValid(ent)) TempLong1 = 1; else TempLong1 = 0; @@ -754,7 +754,7 @@ DATA *COMPILER::BC_CallIntFunction(uint32_t func_code, DATA *&pVResult, uint32_t pV2->SetType(VAR_AREFERENCE); pV2->SetAReference(core_internal.Entity_GetAttributePointer(ent)); - if (core.GetEntityPointer(ent)) + if (core.IsEntityValid(ent)) TempLong1 = 1; else TempLong1 = 0; @@ -786,7 +786,7 @@ DATA *COMPILER::BC_CallIntFunction(uint32_t func_code, DATA *&pVResult, uint32_t pV2->SetType(VAR_AREFERENCE); pV2->SetAReference(core_internal.Entity_GetAttributePointer(ent)); - if (core.GetEntityPointer(ent)) + if (core.IsEntityValid(ent)) TempLong1 = 1; else TempLong1 = 0; @@ -1511,7 +1511,7 @@ DATA *COMPILER::BC_CallIntFunction(uint32_t func_code, DATA *&pVResult, uint32_t pV = pV->GetVarPointer(); pV->Get(TempEid); pV = SStack.Push(); - if (core.GetEntityPointer(TempEid) != nullptr) + if (core.IsEntityValid(TempEid)) TempLong1 = 1; else TempLong1 = 0; @@ -1859,7 +1859,7 @@ DATA *COMPILER::BC_CallIntFunction(uint32_t func_code, DATA *&pVResult, uint32_t CreateMessage(&ms, s_off, 1); uint64_t mresult = 0; - pE = core.GetEntityPointer(ent); + pE = core.GetEntityPointerSafe(ent); if (pE) { ms.Move2Start(); @@ -2452,16 +2452,11 @@ DATA *COMPILER::BC_CallIntFunction(uint32_t func_code, DATA *&pVResult, uint32_t } pA = pV->GetAClass(); if (pA) - { - const auto attr_name = std::string(pA->GetThisName()); - pV = SStack.Push(); - pV->Set(attr_name.c_str()); - } + pChar = pA->GetThisName(); else - { - pV = SStack.Push(); - pV->Set("AClass ERROR n1"); - } + pChar = "AClass ERROR n1"; + pV = SStack.Push(); + pV->Set(pChar); pVResult = pV; return pV; case FUNC_DUMP_ATTRIBUTES: @@ -2571,7 +2566,7 @@ DATA *COMPILER::BC_CallIntFunction(uint32_t func_code, DATA *&pVResult, uint32_t std::sort(std::execution::seq, std::begin(pA->attributes_), std::end(pA->attributes_), [](const std::unique_ptr &lhs, const std::unique_ptr &rhs) { - return lhs->GetThisName().compare(rhs->GetThisName()) < 0; + return strcmp(lhs->GetThisName(), rhs->GetThisName()) < 0; }); break; @@ -2593,9 +2588,7 @@ void COMPILER::DumpAttributes(ATTRIBUTES *pA, int32_t level) for (uint32_t n = 0; n < pA->GetAttributesNum(); n++) { - const auto attr_name = std::string(pA->GetAttributeName(n)); - const auto attr_value = to_string(pA->GetAttribute(n)); - DTrace("%s%s = %s", buffer, attr_name.c_str(), attr_value.c_str()); + DTrace("%s%s = %s", buffer, pA->GetAttributeName(n), static_cast(pA->GetAttribute(n))); DumpAttributes(pA->GetAttributeClass(pA->GetAttributeName(n)), level + 2); } } diff --git a/src/libs/core/src/s_functab.cpp b/src/libs/core/src/s_functab.cpp index 540a03c9c..2980411f2 100644 --- a/src/libs/core/src/s_functab.cpp +++ b/src/libs/core/src/s_functab.cpp @@ -232,6 +232,15 @@ bool FuncTable::AddCall(size_t func_index) return true; } +void FuncTable::ResetTimeAndCalls() +{ + for (auto &func : funcs_) + { + func.usage_time = 0; + func.number_of_calls = 0; + } +} + void FuncTable::Release() { funcs_.clear(); diff --git a/src/libs/core/src/s_functab.h b/src/libs/core/src/s_functab.h index ea4be8ffb..e77b9c016 100644 --- a/src/libs/core/src/s_functab.h +++ b/src/libs/core/src/s_functab.h @@ -91,6 +91,7 @@ class FuncTable bool AddTime(size_t func_index, uint64_t time); bool AddCall(size_t func_index); + void ResetTimeAndCalls(); void Release(); // clear table diff --git a/src/libs/core/src/string_codec.cpp b/src/libs/core/src/string_codec.cpp deleted file mode 100644 index 842d11bc4..000000000 --- a/src/libs/core/src/string_codec.cpp +++ /dev/null @@ -1,116 +0,0 @@ -#include "string_codec.hpp" - -namespace -{ - -constexpr size_t HASH_TABLE_SIZE = 512; // must be power of 2 -constexpr size_t MAX_TABLE_ENTRY_SIZE = 1 << 16; // 0x10000 - -constexpr uint32_t MakeHashValue(const std::string_view &ps) -{ - uint32_t hval = 0; - for (char v : ps) - { - if ('A' <= v && v <= 'Z') - v += 'a' - 'A'; // case independent - hval = (hval << 4) + (uint32_t)v; - uint32_t g = hval & ((uint32_t)0xf << (32 - 4)); - if (g != 0) - { - hval ^= g >> (32 - 8); - hval ^= g; - } - } - return hval; -} - -uint32_t MakeStringCode(const uint32_t table_index, const uint32_t element_index) -{ - Assert(table_index < HASH_TABLE_SIZE); - Assert(element_index < MAX_TABLE_ENTRY_SIZE); - return (table_index << 16) | (element_index & (MAX_TABLE_ENTRY_SIZE - 1)); -} - -} // namespace - -STRING_CODEC::STRING_CODEC() : hashTable_(HASH_TABLE_SIZE) -{ -} - -STRING_CODEC::~STRING_CODEC() noexcept = default; - -uint32_t STRING_CODEC::GetNum() const -{ - return totalStringCount_; -} - -uint32_t STRING_CODEC::Convert(const std::string_view &pString) -{ - uint32_t hash_code = MakeHashValue(pString); - uint32_t table_index = hash_code & (HASH_TABLE_SIZE - 1); - - HTELEMENT &table_entry = hashTable_[table_index]; - - for (size_t n = 0; n < table_entry.elements.size(); n++) - { - const auto &element = table_entry.elements[n]; - if (element.hashCode == hash_code && storm::iEquals(pString, element.string)) - { - return MakeStringCode(table_index, n); - } - } - - const size_t n = table_entry.elements.size(); - table_entry.elements.push_back(HTSUBELEMENT{ - .string = std::string(pString), - .hashCode = hash_code, - }); - totalStringCount_++; - return MakeStringCode(table_index, n); -} - -std::string_view STRING_CODEC::Convert(uint32_t code) const -{ - uint32_t table_index = code >> 16; - if (table_index >= HASH_TABLE_SIZE) - { - return "ERROR: invalid SCCT index"; - } - uint32_t n = code & (MAX_TABLE_ENTRY_SIZE - 1); - if (n >= hashTable_[table_index].elements.size()) - { - return "INVALID SCC"; - } - return hashTable_[table_index].elements[n].string; -} - -const char *STRING_CODEC::Get() -{ - tableIndex_ = 0; - for (tableIndex_ = 0; tableIndex_ < HASH_TABLE_SIZE; tableIndex_++) - { - if (!hashTable_[tableIndex_].elements.empty()) - { - tableElementIndex_ = 0; - return hashTable_[tableIndex_].elements[tableElementIndex_].string.c_str(); - } - } - return nullptr; -} - -const char *STRING_CODEC::GetNext() -{ - tableElementIndex_++; - for (; tableIndex_ < HASH_TABLE_SIZE; tableIndex_++) - { - if (hashTable_[tableIndex_].elements.empty()) - continue; - if (tableElementIndex_ >= hashTable_[tableIndex_].elements.size()) - { - tableElementIndex_ = 0; - continue; - } - return hashTable_[tableIndex_].elements[tableElementIndex_].string.c_str(); - } - return nullptr; -} diff --git a/src/libs/core/src/string_codec.h b/src/libs/core/src/string_codec.h new file mode 100644 index 000000000..425718957 --- /dev/null +++ b/src/libs/core/src/string_codec.h @@ -0,0 +1,188 @@ +#pragma once + +#include "platform/platform.hpp" + +#define HASH_TABLE_SIZE 512 // must be power of 2 + +struct HTSUBELEMENT +{ + char *pStr; + uint32_t dwHashCode; +}; + +struct HTELEMENT +{ + HTSUBELEMENT *pElements; + uint32_t nStringsNum; +}; + +class STRING_CODEC : public VSTRING_CODEC +{ + uint32_t nHTIndex; + uint32_t nHTEIndex; + uint32_t nStringsNum; + + HTELEMENT HTable[HASH_TABLE_SIZE]{}; + + public: + STRING_CODEC() : nHTIndex(0), nHTEIndex(0) + { + nStringsNum = 0; + } + + ~STRING_CODEC() override + { + Release(); + } + + uint32_t GetNum() override + { + return nStringsNum; + } + + void Release() + { + for (uint32_t m = 0; m < HASH_TABLE_SIZE; m++) + { + if (HTable[m].pElements) + { + for (uint32_t n = 0; n < HTable[m].nStringsNum; n++) + delete HTable[m].pElements[n].pStr; + free(HTable[m].pElements); + } + HTable[m].pElements = nullptr; + HTable[m].nStringsNum = 0; + } + } + + uint32_t Convert(const char *pString, int32_t iLen) override + { + if (pString == nullptr) + return 0xffffffff; + + char cTemp[1024]; + strncpy_s(cTemp, pString, iLen); + cTemp[iLen] = 0; + + bool bNew; + return Convert(cTemp, bNew); + } + + uint32_t Convert(const char *pString) override + { + if (pString == nullptr) + return 0xffffffff; + bool bNew; + return Convert(pString, bNew); + } + + inline uint32_t GetNum(uint32_t dwNum, uint32_t dwAlign = 8) + { + return (1 + dwNum / dwAlign) * dwAlign; + } + + uint32_t Convert(const char *pString, bool &bNew) + { + uint32_t nStringCode; + uint32_t n; + if (pString == nullptr) + return 0xffffffff; + uint32_t nHash = MakeHashValue(pString); + uint32_t nTableIndex = nHash & (HASH_TABLE_SIZE - 1); + + HTELEMENT *pE = &HTable[nTableIndex]; + + for (n = 0; n < pE->nStringsNum; n++) + { + if (pE->pElements[n].dwHashCode == nHash && storm::iEquals(pString, pE->pElements[n].pStr)) + { + nStringCode = (nTableIndex << 16) | (n & 0xffff); + bNew = false; + return nStringCode; + } + } + + n = pE->nStringsNum; + pE->nStringsNum++; + pE->pElements = (HTSUBELEMENT *)realloc(pE->pElements, GetNum(pE->nStringsNum) * sizeof(HTSUBELEMENT)); + + const auto len = strlen(pString) + 1; + pE->pElements[n].pStr = new char[len]; + memcpy(pE->pElements[n].pStr, pString, len); + pE->pElements[n].dwHashCode = nHash; + + nStringCode = (nTableIndex << 16) | (n & 0xffff); + nStringsNum++; + bNew = true; + return nStringCode; + } + + void VariableChanged() override; + + const char *Convert(uint32_t code) override + { + uint32_t nTableIndex = code >> 16; + if (nTableIndex >= HASH_TABLE_SIZE) + { + return "ERROR: invalid SCCT index"; + } + uint32_t n = code & 0xffff; + if (n >= HTable[nTableIndex].nStringsNum) + { + return "INVALID SCC"; + } + return HTable[nTableIndex].pElements[n].pStr; + } + + uint32_t MakeHashValue(const char *ps) + { + uint32_t hval = 0; + while (*ps != 0) + { + char v = *ps++; + if ('A' <= v && v <= 'Z') + v += 'a' - 'A'; // case independent + hval = (hval << 4) + (uint32_t)v; + uint32_t g = hval & ((uint32_t)0xf << (32 - 4)); + if (g != 0) + { + hval ^= g >> (32 - 8); + hval ^= g; + } + } + return hval; + } + + char *Get() + { + nHTIndex = 0; + for (nHTIndex = 0; nHTIndex < HASH_TABLE_SIZE; nHTIndex++) + { + if (HTable[nHTIndex].nStringsNum > 0) + { + nHTEIndex = 0; + return HTable[nHTIndex].pElements[nHTEIndex].pStr; + } + } + return nullptr; + } + + char *GetNext() + { + nHTEIndex++; + for (; nHTIndex < HASH_TABLE_SIZE; nHTIndex++) + { + if (HTable[nHTIndex].nStringsNum == 0) + continue; + if (nHTEIndex >= HTable[nHTIndex].nStringsNum) + { + nHTEIndex = 0; + continue; + } + return HTable[nHTIndex].pElements[nHTEIndex].pStr; + } + return nullptr; + } + + //*/ +}; diff --git a/src/libs/core/src/string_codec.hpp b/src/libs/core/src/string_codec.hpp deleted file mode 100644 index 54fe44cda..000000000 --- a/src/libs/core/src/string_codec.hpp +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include "attributes.h" -#include -#include - -struct HTSUBELEMENT -{ - std::string string{}; - uint32_t hashCode{}; -}; - -struct HTELEMENT -{ - std::vector elements; -}; - -class STRING_CODEC final : public VSTRING_CODEC -{ - public: - STRING_CODEC(); - ~STRING_CODEC() noexcept override; - - [[nodiscard]] uint32_t GetNum() const override; - uint32_t Convert(const std::string_view &pString) override; - [[nodiscard]] std::string_view Convert(uint32_t code) const override; - - void VariableChanged() override; - - // For iteration - const char *Get(); - const char *GetNext(); - - private: - std::vector hashTable_{}; - - uint32_t totalStringCount_ = 0; - - // For iteration - uint32_t tableIndex_ = 0; - uint32_t tableElementIndex_ = 0; -}; diff --git a/src/libs/dialog/src/dialog.cpp b/src/libs/dialog/src/dialog.cpp index c5f3285fa..f54d1daa6 100644 --- a/src/libs/dialog/src/dialog.cpp +++ b/src/libs/dialog/src/dialog.cpp @@ -1099,12 +1099,15 @@ uint32_t DIALOG::AttributeChanged(ATTRIBUTES *pA) ATTRIBUTES *par = pA->GetParent(); if (par != nullptr) { - if (storm::iEquals(par->GetThisName(), "Links")) + const char *parname = par->GetThisName(); + if (parname != nullptr && storm::iEquals(parname, "Links")) parLinks = true; } + const char *nm = pA->GetThisName(); + // play sound d.speech - if (!parLinks && storm::iEquals(pA->GetThisName(), "greeting")) // was "snd" + if (!parLinks && nm && storm::iEquals(nm, "greeting")) // was "snd" { strcpy_s(soundName, pA->GetThisAttr()); if (start) diff --git a/src/libs/geometry/include/geos.h b/src/libs/geometry/include/geos.h index b2b324f5b..068bf0d94 100644 --- a/src/libs/geometry/include/geos.h +++ b/src/libs/geometry/include/geos.h @@ -99,8 +99,8 @@ class GEOS struct LABEL { + alignas(16) float m[4][4]; int32_t flags; // combination of LABEL_FLAG - float m[4][4]; char *group_name; char *name; int32_t bones[4]; diff --git a/src/libs/island/src/island.cpp b/src/libs/island/src/island.cpp index 452932e94..8b69652d2 100644 --- a/src/libs/island/src/island.cpp +++ b/src/libs/island/src/island.cpp @@ -97,6 +97,8 @@ void ISLAND::Realize(uint32_t Delta_Time) auto *pModel = static_cast(core.GetEntityPointer(model_id)); Assert(pModel); + auto *pSeaBed = static_cast(core.GetEntityPointer(seabed_id)); // !! + uint32_t bFogEnable; uint32_t bLighting; pRS->GetRenderState(D3DRS_FOGENABLE, &bFogEnable); @@ -143,6 +145,10 @@ void ISLAND::Realize(uint32_t Delta_Time) pRS->SetNearFarPlane((j == 0) ? fOldNear : fOldFar * static_cast(j), fOldFar * static_cast(j + 1)); pModel->ProcessStage(Stage::realize, Delta_Time); + + if (pSeaBed) + pSeaBed->ProcessStage(Stage::realize, Delta_Time); // !! + pRS->SetRenderState(D3DRS_LIGHTING, true); D3DLIGHT9 lt, ltold; pRS->GetLight(0, <old); @@ -184,7 +190,7 @@ void ISLAND::Realize(uint32_t Delta_Time) pRS->SetRenderState(D3DRS_ZWRITEENABLE, true); } pRS->SetRenderState(D3DRS_FOGDENSITY, F2DW(fOldFogDensity)); - +/* pRS->SetNearFarPlane(fOldNear, fOldFar / 2.0f); if (!bDrawReflections) { @@ -197,7 +203,7 @@ void ISLAND::Realize(uint32_t Delta_Time) } pRS->SetNearFarPlane(fOldNear, fOldFar); - +*/ pRS->SetRenderState(D3DRS_LIGHTING, false); pRS->SetRenderState(D3DRS_FOGENABLE, bFogEnable); pRS->SetRenderState(D3DRS_AMBIENT, dwAmbientOld); diff --git a/src/libs/lighter/src/l_geometry.cpp b/src/libs/lighter/src/l_geometry.cpp index 3907f1a65..ef37a114b 100644 --- a/src/libs/lighter/src/l_geometry.cpp +++ b/src/libs/lighter/src/l_geometry.cpp @@ -199,7 +199,7 @@ bool LGeometry::Process(VDX9RENDER *rs, int32_t numLights) } // Copy uint8_t *pnt = nullptr; - if (vbuf->Lock(0, desc.Size, (VOID **)&pnt, 0) != D3D_OK) + if (vbuf->Lock(0, desc.Size, (void **)&pnt, 0) != D3D_OK) { core.Trace("Location lighter: vertex buffer no locked, model %s, vbID %i", object[i].nameReal, vbID); return false; diff --git a/src/libs/location/src/character.cpp b/src/libs/location/src/character.cpp index 0403dc430..e85a15275 100644 --- a/src/libs/location/src/character.cpp +++ b/src/libs/location/src/character.cpp @@ -836,7 +836,7 @@ uint32_t Character::AttributeChanged(ATTRIBUTES *apnt) { if (deadName || liveValue < 0) return 0; - if (!apnt) + if (!apnt || !apnt->GetThisName()) return 0; if (storm::iEquals(apnt->GetThisName(), "model")) { @@ -4605,6 +4605,11 @@ void Character::UpdateAnimation() { fgtCurType = fgtSetType; fgtCurIndex = fgtSetIndex; + + if (fgtCurType == fgt_block || fgtCurType == fgt_blockhit) + { + blockStart = std::chrono::steady_clock::now(); + } } fgtSetType = fgt_none; fgtSetIndex = -1; @@ -5082,13 +5087,20 @@ inline void Character::CheckAttackHit(bool isGunBlade) } } fc.c->Hit(hitReaction); - core.Event("Location_CharacterAttack", "iisll", GetId(), fc.c->GetId(), aname, - static_cast(isBlocked), static_cast(isGunBlade)); + int blockTime = -1; + if (isBlocked) + { + blockTime = std::chrono::duration_cast(std::chrono::steady_clock::now() - + fc.c->blockStart) + .count(); + } + core.Event("Location_CharacterAttack", "iislll", GetId(), fc.c->GetId(), aname, + static_cast(isBlocked), static_cast(isGunBlade), blockTime); // boal 09/12/06 energy consumption after impact --> if (isUseEnergy && fgtCurType != fgt_attack_feintc) { - // for fgt_attack_feintc there is an overexertion in the animation, and here will be a "feint", and it - // costs 0 + // for fgt_attack_feintc there is an overexertion in the animation, and here will be a "feint", and + // it costs 0 core.Event("ChrFgtActApply", "is", GetId(), aname); isUseEnergy = false; } diff --git a/src/libs/location/src/character.h b/src/libs/location/src/character.h index 377560dac..16e76246f 100644 --- a/src/libs/location/src/character.h +++ b/src/libs/location/src/character.h @@ -10,12 +10,14 @@ #pragma once +#include +#include + #include "animation.h" #include "matrix.h" #include "model.h" #include "string_compare.hpp" #include "vma.hpp" -#include class Location; class MODEL; @@ -714,6 +716,8 @@ class Character : public Entity private: // The location the character is in entid_t loc_id; + + std::chrono::steady_clock::time_point blockStart{}; }; inline void Character::AlreadyDeleted() diff --git a/src/libs/location/src/fader.cpp b/src/libs/location/src/fader.cpp index 96bb2f4e8..25426aec7 100644 --- a/src/libs/location/src/fader.cpp +++ b/src/libs/location/src/fader.cpp @@ -127,11 +127,12 @@ bool Fader::Init() drawbuf_back[i] = {drawbuf_base[i].x, drawbuf_base[i].y, drawbuf_base[i].z, drawbuf_base[i].rhw, {}, drawbuf_base[i].u, drawbuf_base[i].v}; drawbuf_front[i] = drawbuf_back[i]; + drawbuf_tips[i] = drawbuf_back[i]; } if ((w - (4.0f * h / 3.0f)) / 2.0f >= 10.0f) { - float dy = 25.0f; + float dy = 0.025f * h; float dx = (w - (4.0f * (h - 2.0f * dy) / 3.0f)) / 2.0f; drawbuf_front[0].x = 0.0f + dx; @@ -154,14 +155,13 @@ bool Fader::Init() auto ini = fio->OpenIniFile(core.EngineIniFileName()); if (ini) { - numberOfTips = ini->GetInt(nullptr, "ProgressFrame", 1); + //numberOfTips = ini->GetInt(nullptr, "ProgressFrame", 1); + numberOfTips = ini->GetInt(nullptr, "numoftips", -1); } else numberOfTips = -1; - if (numberOfTips > 1) - numberOfTips = 1; - if (numberOfTips < 0) - numberOfTips = 0; + if (numberOfTips > 9999) + numberOfTips = 9999; } return true; } @@ -215,17 +215,20 @@ uint64_t Fader::ProcessMessage(MESSAGE &message) const std::string &_name = message.String(); textureID = rs->TextureCreate(_name.c_str()); rs->SetProgressImage(_name.c_str()); + // Hint texture if (numberOfTips > 0) { - const std::string texturePath = "interfaces\\int_border.tga"; + char _name[MAX_PATH]; + sprintf_s(_name, "tips\\tips_%.4u.tga", rand() % numberOfTips); if (tipsID >= 0) { rs->TextureRelease(tipsID); } - tipsID = rs->TextureCreate(texturePath.c_str()); - rs->SetTipsImage(texturePath.c_str()); + tipsID = rs->TextureCreate(_name); + rs->SetTipsImage(_name); } + break; } case FADER_PICTURE0: { @@ -233,22 +236,7 @@ uint64_t Fader::ProcessMessage(MESSAGE &message) rs->TextureRelease(textureBackID); const std::string &_name = message.String(); textureBackID = rs->TextureCreate(_name.c_str()); - rs->SetProgressBackImage(_name.c_str()); - // Hint texture - if (numberOfTips > 0) - { - // sprintf_s(_name, "tips\\tips_%.4u.tga", rand() % numberOfTips); - auto *const pTipsName = rs->GetTipsImage(); - if (pTipsName) - { - if (tipsID >= 0) - { - rs->TextureRelease(tipsID); - } - tipsID = rs->TextureCreate(pTipsName); - // rs->SetTipsImage(_name); - } - } + rs->SetProgressBackImage(_name.c_str()); break; } } @@ -258,7 +246,7 @@ uint64_t Fader::ProcessMessage(MESSAGE &message) // Work void Fader::Execute(uint32_t delta_time) { - // core.Trace("fader frame"); +// core.Trace("fader frame"); if (deleteMe) { deleteMe++; @@ -271,12 +259,12 @@ void Fader::Execute(uint32_t delta_time) if (!fadeIn) { core.PostEvent("FaderEvent_StartFade", 0, "li", fadeIn, GetId()); - // core.Trace("FaderEvent_StartFade"); +// core.Trace("FaderEvent_StartFade"); } else { core.PostEvent("FaderEvent_StartFadeIn", 0, "li", fadeIn, GetId()); - // core.Trace("FaderEvent_StartFadeIn"); +// core.Trace("FaderEvent_StartFadeIn"); } } if (eventEnd) @@ -286,12 +274,12 @@ void Fader::Execute(uint32_t delta_time) if (!fadeIn) { core.PostEvent("FaderEvent_EndFade", 0, "li", fadeIn, GetId()); - // core.Trace("FaderEvent_EndFade"); +// core.Trace("FaderEvent_EndFade"); } else { core.PostEvent("FaderEvent_EndFadeIn", 0, "li", fadeIn, GetId()); - // core.Trace("FaderEvent_EndFadeIn"); +// core.Trace("FaderEvent_EndFadeIn"); } } } @@ -315,7 +303,8 @@ void Fader::Realize(uint32_t delta_time) core.Trace("Fader: GetRenderTargetAsTexture failed"); } } - else { + else + { rs->SetTexture(0, tex); rs->DrawPrimitiveUP(D3DPT_TRIANGLELIST, D3DFVF_XYZRHW | D3DFVF_TEX1 | D3DFVF_TEXTUREFORMAT2, 2, drawbuf_base, sizeof(drawbuf_base[0]), "Fader"); @@ -360,19 +349,49 @@ void Fader::Realize(uint32_t delta_time) drawbuf_front[5].color = color; rs->TextureSet(0, textureID); - if (tipsID >= 0) - { - rs->TextureSet(1, tipsID); - rs->DrawPrimitiveUP(D3DPT_TRIANGLELIST, - D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1 | D3DFVF_TEXTUREFORMAT2, 2, drawbuf_front, - sizeof(drawbuf_front[0]), "FaderWithTips"); - } - else - { - rs->DrawPrimitiveUP(D3DPT_TRIANGLELIST, + rs->DrawPrimitiveUP(D3DPT_TRIANGLELIST, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1 | D3DFVF_TEXTUREFORMAT2, 2, drawbuf_front, sizeof(drawbuf_front[0]), "Fader"); + } + + if (tipsID >= 0) + { + drawbuf_tips[0].color = color; + drawbuf_tips[1].color = color; + drawbuf_tips[2].color = color; + drawbuf_tips[3].color = color; + drawbuf_tips[4].color = color; + drawbuf_tips[5].color = color; + + float dy = 0.0f; + float dx = 0.0f; + float dxx = 0.0; + + if ((w - (4.0f * h / 3.0f)) / 2.0f >= 10.0f) + { + dy = 0.025f * h; + dx = (w - (4.0f * (h - 2.0f * dy) / 3.0f)) / 2.0f; +// dxx = (w - 2.0 * dx) * 0.125f; } + dxx = (w - 2.0 * dx) * 0.125f; + + drawbuf_tips[0].x = 0.0f + dx + dxx; + drawbuf_tips[0].y = 0.0f + 0.787f * h; + drawbuf_tips[1].x = w - dx - dxx; + drawbuf_tips[1].y = 0.0f + 0.787f * h; + drawbuf_tips[2].x = 0.0f + dx + dxx; + drawbuf_tips[2].y = h - 0.094f * h; + drawbuf_tips[3].x = 0.0f + dx + dxx; + drawbuf_tips[3].y = h - 0.094f * h; + drawbuf_tips[4].x = w - dx - dxx; + drawbuf_tips[4].y = 0.0f + 0.787f * h; + drawbuf_tips[5].x = w - dx - dxx; + drawbuf_tips[5].y = h - 0.094f * h; + + rs->TextureSet(0, tipsID); + rs->DrawPrimitiveUP(D3DPT_TRIANGLELIST, + D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1 | D3DFVF_TEXTUREFORMAT2, 2, drawbuf_tips, + sizeof(drawbuf_tips[0]), "Fader"); } // Increase alpha diff --git a/src/libs/location/src/fader.h b/src/libs/location/src/fader.h index c1638e10e..d76d461df 100644 --- a/src/libs/location/src/fader.h +++ b/src/libs/location/src/fader.h @@ -76,7 +76,7 @@ class Fader : public Entity float x, y, z, rhw; uint32_t color; float u, v; - } drawbuf_back[6], drawbuf_front[6]; + } drawbuf_back[6], drawbuf_front[6], drawbuf_tips[6]; bool eventStart; bool eventEnd; diff --git a/src/libs/location/src/location.cpp b/src/libs/location/src/location.cpp index a4550bb40..a5648e26d 100644 --- a/src/libs/location/src/location.cpp +++ b/src/libs/location/src/location.cpp @@ -233,6 +233,7 @@ uint64_t Location::ProcessMessage(MESSAGE &message) { int32_t i; float u0, v0, u1, v1; + float ax, ay, az; int32_t level; LocatorArray *la; switch (message.Long()) @@ -285,6 +286,14 @@ uint64_t Location::ProcessMessage(MESSAGE &message) u1 = message.Float(); // rz model.SetRotation(lastLoadStaticModel, u0, v0, u1); return 1; + case MSG_LOCATION_MODEL_SET_ROT_ANGLE: + if (lastLoadStaticModel < 0) + return 0; + ax = message.Float(); // ax + ay = message.Float(); // ay + az = message.Float(); // az + model.SetRotationAngle(lastLoadStaticModel, ax, ay, az); + return 1; case MSG_LOCATION_MODEL_SET_UVS: if (lastLoadStaticModel < 0) return 0; diff --git a/src/libs/location/src/model_array.cpp b/src/libs/location/src/model_array.cpp index 093117df5..edad2e2f7 100644 --- a/src/libs/location/src/model_array.cpp +++ b/src/libs/location/src/model_array.cpp @@ -255,6 +255,18 @@ void ModelArray::SetRotation(int32_t modelIndex, float rx, float ry, float rz) model[modelIndex].rotator->rz = rz; } +// Set base rotation angle +void ModelArray::SetRotationAngle(int32_t modelIndex, float ax, float ay, float az) +{ + Assert(modelIndex >= 0 && modelIndex < numModels); + auto *mdl = static_cast(core.GetEntityPointer(model[modelIndex].id)); + if (mdl) + { + CMatrix mtr(ax, ay, az); + mdl->mtx = CMatrix(mtr, mdl->mtx); + } +} + // Set the reflection matrix generation mode to the model void ModelArray::SetReflection(int32_t modelIndex, float scale) { diff --git a/src/libs/location/src/model_array.h b/src/libs/location/src/model_array.h index 9773aba0a..76714e2b7 100644 --- a/src/libs/location/src/model_array.h +++ b/src/libs/location/src/model_array.h @@ -103,6 +103,8 @@ class ModelArray void SetUVSlide(int32_t modelIndex, float u0, float v0, float u1, float v1); // Set a rotation animation to the model void SetRotation(int32_t modelIndex, float rx, float ry, float rz); + // Set base rotation angle + void SetRotationAngle(int32_t modelIndex, float ax, float ay, float az); // Set the reflection matrix generation mode to the model void SetReflection(int32_t modelIndex, float scale); diff --git a/src/libs/location/src/np_character.cpp b/src/libs/location/src/np_character.cpp index fb98633e5..b5c4ebc09 100644 --- a/src/libs/location/src/np_character.cpp +++ b/src/libs/location/src/np_character.cpp @@ -314,10 +314,11 @@ void NPCharacter::Update(float dltTime) { for (int32_t i = atr->GetAttributesNum() - 1; i >= 0; i--) { - const auto attr_name = std::string(atr->GetAttributeName(i)); - const auto attr_value = to_string(atr->GetAttribute(i)); - location->Print(curPos + CVECTOR(0.0f, height, 0.0f), rad, line++, 1.0f, 0xffffff, 0.5f, - "tmpl.%s(%s)", attr_name.c_str(), attr_value.c_str()); + fid = atr->GetAttributeName(i); + id = atr->GetAttribute(i); + if (fid && id) + location->Print(curPos + CVECTOR(0.0f, height, 0.0f), rad, line++, 1.0f, 0xffffff, 0.5f, + "tmpl.%s(%s)", fid, id); } if (atr->HasValue()) { @@ -330,11 +331,11 @@ void NPCharacter::Update(float dltTime) { for (int32_t i = atr->GetAttributesNum() - 1; i >= 0; i--) { - const auto attr_name = std::string(atr->GetAttributeName(i)); - const auto attr_value = to_string(atr->GetAttribute(i)); + fid = atr->GetAttributeName(i); + id = atr->GetAttribute(i); if (fid && id) location->Print(curPos + CVECTOR(0.0f, height, 0.0f), rad, line++, 1.0f, 0xffffff, 0.5f, - "type.%s(%s)", attr_name.c_str(), attr_value.c_str()); + "type.%s(%s)", fid, id); } if (atr->HasValue()) location->Print(curPos + CVECTOR(0.0f, height, 0.0f), rad, line++, 1.0f, 0xffffff, 0.5f, "type(%s)", diff --git a/src/libs/location/src/supervisor.h b/src/libs/location/src/supervisor.h index eb8fdc691..93df9a0d7 100644 --- a/src/libs/location/src/supervisor.h +++ b/src/libs/location/src/supervisor.h @@ -9,6 +9,7 @@ // ============================================================================================ #pragma once +#include #include class Character; diff --git a/src/libs/model/src/model.cpp b/src/libs/model/src/model.cpp index cb594c6fa..d7d4ca387 100644 --- a/src/libs/model/src/model.cpp +++ b/src/libs/model/src/model.cpp @@ -67,7 +67,7 @@ void *VBTransform(void *vb, int32_t startVrt, int32_t nVerts, int32_t totVerts) auto *src = static_cast(vb); GEOS::VERTEX0 *dst; - dest_vb->Lock(0, 0, (VOID **)&dst, D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK); + dest_vb->Lock(0, 0, (void **)&dst, D3DLOCK_DISCARD | D3DLOCK_NOSYSLOCK); #ifndef _WIN32 // FIX_LINUX DirectXMath CMatrix mtx; diff --git a/src/libs/particles/src/k2_wrapper/particles.cpp b/src/libs/particles/src/k2_wrapper/particles.cpp index c02ba8d8c..68296d8c5 100644 --- a/src/libs/particles/src/k2_wrapper/particles.cpp +++ b/src/libs/particles/src/k2_wrapper/particles.cpp @@ -323,7 +323,6 @@ void PARTICLES::PauseAllActive(bool bPaused) { for (uint32_t n = 0; n < CreatedSystems.size(); n++) { - CreatedSystems[n].pSystem->GetSystem()->Restart(0); CreatedSystems[n].pSystem->Pause(bPaused); } } diff --git a/src/libs/renderer/include/dx9render.h b/src/libs/renderer/include/dx9render.h index 2a778468b..656f370ca 100644 --- a/src/libs/renderer/include/dx9render.h +++ b/src/libs/renderer/include/dx9render.h @@ -203,7 +203,7 @@ class VDX9RENDER : public SERVICE virtual void SaveShoot() = 0; // DX9Render: Clip Planes Section - virtual HRESULT SetClipPlane(uint32_t Index, CONST float *pPlane) = 0; + virtual HRESULT SetClipPlane(uint32_t Index, const float *pPlane) = 0; virtual PLANE *GetPlanes() = 0; // DX9Render: Camera Section @@ -279,7 +279,8 @@ class VDX9RENDER : public SERVICE virtual void ReleaseVideoTexture(CVideoTexture *pVTexture) = 0; // DX9Render: Vertex/Index Buffers Section - virtual int32_t CreateVertexBuffer(int32_t type, size_t nverts, uint32_t usage) = 0; + virtual int32_t CreateVertexBuffer(int32_t type, size_t nverts, uint32_t usage, + uint32_t dwPool = D3DPOOL_DEFAULT) = 0; virtual int32_t CreateIndexBuffer(size_t ntrgs, uint32_t dwUsage = D3DUSAGE_WRITEONLY) = 0; virtual IDirect3DVertexBuffer9 *GetVertexBuffer(int32_t id) = 0; @@ -342,32 +343,32 @@ class VDX9RENDER : public SERVICE virtual HRESULT GetLevelDesc(IDirect3DTexture9 *ppTexture, UINT Level, D3DSURFACE_DESC *pDesc) = 0; virtual HRESULT GetLevelDesc(IDirect3DCubeTexture9 *ppCubeTexture, UINT Level, D3DSURFACE_DESC *pDesc) = 0; virtual HRESULT LockRect(IDirect3DCubeTexture9 *ppCubeTexture, D3DCUBEMAP_FACES FaceType, UINT Level, - D3DLOCKED_RECT *pLockedRect, CONST RECT *pRect, uint32_t Flags) = 0; - virtual HRESULT LockRect(IDirect3DTexture9 *ppTexture, UINT Level, D3DLOCKED_RECT *pLockedRect, CONST RECT *pRect, + D3DLOCKED_RECT *pLockedRect, const RECT *pRect, uint32_t Flags) = 0; + virtual HRESULT LockRect(IDirect3DTexture9 *ppTexture, UINT Level, D3DLOCKED_RECT *pLockedRect, const RECT *pRect, uint32_t Flags) = 0; virtual HRESULT UnlockRect(IDirect3DCubeTexture9 *pCubeTexture, D3DCUBEMAP_FACES FaceType, UINT Level) = 0; virtual HRESULT UnlockRect(IDirect3DTexture9 *pTexture, UINT Level) = 0; virtual HRESULT GetSurfaceLevel(IDirect3DTexture9 *ppTexture, UINT Level, IDirect3DSurface9 **ppSurfaceLevel) = 0; - virtual HRESULT UpdateSurface(IDirect3DSurface9 *pSourceSurface, CONST RECT *pSourceRectsArray, UINT cRects, - IDirect3DSurface9 *pDestinationSurface, CONST POINT *pDestPointsArray) = 0; + virtual HRESULT UpdateSurface(IDirect3DSurface9 *pSourceSurface, const RECT *pSourceRectsArray, UINT cRects, + IDirect3DSurface9 *pDestinationSurface, const POINT *pDestPointsArray) = 0; virtual HRESULT StretchRect(IDirect3DSurface9 *pSourceSurface, const RECT *pSourceRect, IDirect3DSurface9 *pDestSurface, const RECT *pDestRect, D3DTEXTUREFILTERTYPE Filter) = 0; virtual HRESULT GetRenderTargetData(IDirect3DSurface9 *pRenderTarget, IDirect3DSurface9 *pDestSurface) = 0; // D3D Pixel/Vertex Shaders Section - virtual HRESULT CreateVertexDeclaration(CONST D3DVERTEXELEMENT9 *pVertexElements, + virtual HRESULT CreateVertexDeclaration(const D3DVERTEXELEMENT9 *pVertexElements, IDirect3DVertexDeclaration9 **ppDecl) = 0; virtual HRESULT SetVertexDeclaration(IDirect3DVertexDeclaration9 *pDecl) = 0; - virtual HRESULT CreatePixelShader(CONST uint32_t *pFunction, IDirect3DPixelShader9 **ppShader) = 0; - virtual HRESULT CreateVertexShader(CONST uint32_t *pFunction, IDirect3DVertexShader9 **ppShader) = 0; + virtual HRESULT CreatePixelShader(const uint32_t *pFunction, IDirect3DPixelShader9 **ppShader) = 0; + virtual HRESULT CreateVertexShader(const uint32_t *pFunction, IDirect3DVertexShader9 **ppShader) = 0; virtual HRESULT DeletePixelShader(IDirect3DPixelShader9 *pShader) = 0; virtual HRESULT DeleteVertexShader(IDirect3DVertexShader9 *pShader) = 0; virtual HRESULT SetVertexShader(IDirect3DVertexShader9 *pShader) = 0; virtual HRESULT SetPixelShader(IDirect3DPixelShader9 *pShader) = 0; - /*virtual HRESULT SetFVFConstant(DWORD Register, CONST void * pConstantData, DWORD ConstantCount ) = 0;*/ - virtual HRESULT SetVertexShaderConstantF(UINT StartRegister, CONST float *pConstantData, UINT Vector4iCount) = 0; - virtual HRESULT SetPixelShaderConstantF(UINT StartRegister, CONST float *pConstantData, UINT Vector4iCount) = 0; + /*virtual HRESULT SetFVFConstant(DWORD Register, const void * pConstantData, DWORD ConstantCount ) = 0;*/ + virtual HRESULT SetVertexShaderConstantF(UINT StartRegister, const float *pConstantData, UINT Vector4iCount) = 0; + virtual HRESULT SetPixelShaderConstantF(UINT StartRegister, const float *pConstantData, UINT Vector4iCount) = 0; virtual HRESULT SetFVF(uint32_t handle) = 0; virtual HRESULT GetVertexShader(IDirect3DVertexShader9 **ppShader) = 0; virtual HRESULT GetPixelShader(IDirect3DPixelShader9 **ppShader) = 0; @@ -378,7 +379,7 @@ class VDX9RENDER : public SERVICE // D3D Render Target/Begin/End/Clear virtual HRESULT GetRenderTarget(IDirect3DSurface9 **ppRenderTarget) = 0; virtual HRESULT SetRenderTarget(IDirect3DSurface9 *pRenderTarget, IDirect3DSurface9 *pNewZStencil) = 0; - virtual HRESULT Clear(uint32_t Count, CONST D3DRECT *pRects, uint32_t Flags, D3DCOLOR Color, float Z, + virtual HRESULT Clear(uint32_t Count, const D3DRECT *pRects, uint32_t Flags, D3DCOLOR Color, float Z, uint32_t Stencil) = 0; virtual HRESULT BeginScene() = 0; virtual HRESULT EndScene() = 0; diff --git a/src/libs/renderer/src/font.cpp b/src/libs/renderer/src/font.cpp index 36bfc8f21..c857702fa 100644 --- a/src/libs/renderer/src/font.cpp +++ b/src/libs/renderer/src/font.cpp @@ -164,7 +164,7 @@ bool FONT::Init(const char *font_name, const char *iniName) nullptr); if (vertexBuffer_ == nullptr) throw std::runtime_error("vbuffer error"); - vertexBuffer_->Lock(0, sizeof(FONT_CHAR_VERTEX) * MAX_SYMBOLS * SYM_VERTEXS, (VOID **)&pVertex, 0); + vertexBuffer_->Lock(0, sizeof(FONT_CHAR_VERTEX) * MAX_SYMBOLS * SYM_VERTEXS, (void **)&pVertex, 0); for (codepoint = 0; codepoint < MAX_SYMBOLS * SYM_VERTEXS; codepoint++) { pVertex[codepoint].pos.z = 0.5f; @@ -229,7 +229,7 @@ int32_t FONT::UpdateVertexBuffer(int32_t x, int32_t y, char *data_PTR, int utf8l s_num = strlen(data_PTR); - vertexBuffer_->Lock(0, sizeof(FONT_CHAR_VERTEX) * utf8length * SYM_VERTEXS, (VOID **)&pVertex, 0); + vertexBuffer_->Lock(0, sizeof(FONT_CHAR_VERTEX) * utf8length * SYM_VERTEXS, (void **)&pVertex, 0); xoffset = 0; diff --git a/src/libs/renderer/src/s_device.cpp b/src/libs/renderer/src/s_device.cpp index bcb69decb..51897fe61 100644 --- a/src/libs/renderer/src/s_device.cpp +++ b/src/libs/renderer/src/s_device.cpp @@ -505,6 +505,8 @@ bool DX9RENDER::Init() #endif bShowFps = ini->GetInt(nullptr, "show_fps", 0) == 1; + fpsx = ini->GetInt(nullptr, "fps_posx", 0); + fpsy = ini->GetInt(nullptr, "fps_posy", 0); bShowExInfo = ini->GetInt(nullptr, "show_exinfo", 0) == 1; bSafeRendering = ini->GetInt(nullptr, "safe_render", 0) == 0; bDropVideoConveyor = ini->GetInt(nullptr, "DropVideoConveyor", 0) != 0; @@ -1207,7 +1209,7 @@ bool DX9RENDER::DX9EndScene() { if (bShowFps) { - Print(screen_size.x - 100, screen_size.y - 50, "FPS %d", core.EngineFps()); + Print(screen_size.x - fpsx, screen_size.y - fpsy, "FPS %d", core.EngineFps()); } if (bShowExInfo) @@ -1252,7 +1254,7 @@ bool DX9RENDER::DX9EndScene() if (bDropVideoConveyor && pDropConveyorVBuffer) { CVECTOR *pV; - pDropConveyorVBuffer->Lock(0, 0, (VOID **)&pV, 0); + pDropConveyorVBuffer->Lock(0, 0, (void **)&pV, 0); for (int32_t i = 0; i < 2; i++) pV[i] = CVECTOR(1e6f, 1e6f, 1e6f); pDropConveyorVBuffer->Unlock(); @@ -2179,7 +2181,7 @@ bool DX9RENDER::GetLight(uint32_t dwIndex, D3DLIGHT9 *pLight) //################################################################################ -int32_t DX9RENDER::CreateVertexBuffer(int32_t type, size_t size, uint32_t dwUsage) +int32_t DX9RENDER::CreateVertexBuffer(int32_t type, size_t size, uint32_t dwUsage, uint32_t dwPool) { if (size <= 0) return -1; // fix @@ -2192,7 +2194,8 @@ int32_t DX9RENDER::CreateVertexBuffer(int32_t type, size_t size, uint32_t dwUsag if (b == MAX_BUFFERS) return -1; - if (CHECKD3DERR(d3d9->CreateVertexBuffer(size, dwUsage, type, D3DPOOL_DEFAULT, &VertexBuffers[b].buff, NULL))) + if (CHECKD3DERR(d3d9->CreateVertexBuffer(size, dwUsage, type, static_cast(dwPool), + &VertexBuffers[b].buff, NULL))) return -1; VertexBuffers[b].type = type; @@ -2373,7 +2376,7 @@ void DX9RENDER::RenderAnimation(int32_t ib, void *src, int32_t numVrts, int32_t // Copy verteces uint8_t *ptr; RDTSC_B(_rdtsc); - if (CHECKD3DERR(aniVBuffer->Lock(0, size, (VOID **)&ptr, 0)) == true) + if (CHECKD3DERR(aniVBuffer->Lock(0, size, (void **)&ptr, 0)) == true) return; dwNumLV++; RDTSC_E(_rdtsc); @@ -2400,7 +2403,7 @@ void *DX9RENDER::LockVertexBuffer(int32_t id, uint32_t dwFlags) { uint8_t *ptr; VertexBuffers[id].dwNumLocks++; - if (CHECKD3DERR(VertexBuffers[id].buff->Lock(0, VertexBuffers[id].size, (VOID **)&ptr, dwFlags))) + if (CHECKD3DERR(VertexBuffers[id].buff->Lock(0, VertexBuffers[id].size, (void **)&ptr, dwFlags))) return nullptr; dwNumLV++; @@ -2423,7 +2426,7 @@ void *DX9RENDER::LockIndexBuffer(int32_t id, uint32_t dwFlags) { uint8_t *ptr = nullptr; IndexBuffers[id].dwNumLocks++; - if (CHECKD3DERR(IndexBuffers[id].buff->Lock(0, IndexBuffers[id].size, (VOID **)&ptr, dwFlags))) + if (CHECKD3DERR(IndexBuffers[id].buff->Lock(0, IndexBuffers[id].size, (void **)&ptr, dwFlags))) return nullptr; dwNumLI++; @@ -3429,7 +3432,7 @@ void DX9RENDER::DrawRects(RS_RECT *pRSR, uint32_t dwRectsNum, const char *cBlock drawCount = rectsVBuffer_SizeInRects; // Buffer RECT_VERTEX *data = nullptr; - if (rectsVBuffer->Lock(0, drawCount * 6 * sizeof(RECT_VERTEX), (VOID **)&data, D3DLOCK_DISCARD) != D3D_OK) + if (rectsVBuffer->Lock(0, drawCount * 6 * sizeof(RECT_VERTEX), (void **)&data, D3DLOCK_DISCARD) != D3D_OK) return; if (!data) return; @@ -3581,7 +3584,7 @@ HRESULT DX9RENDER::VBLock(IDirect3DVertexBuffer9 *pVB, UINT OffsetToLock, UINT S uint32_t Flags) { dwNumLV++; - return CHECKD3DERR(pVB->Lock(OffsetToLock, SizeToLock, (VOID **)ppbData, Flags)); + return CHECKD3DERR(pVB->Lock(OffsetToLock, SizeToLock, (void **)ppbData, Flags)); } void DX9RENDER::VBUnlock(IDirect3DVertexBuffer9 *pVB) @@ -3646,7 +3649,7 @@ HRESULT DX9RENDER::SetRenderTarget(IDirect3DSurface9 *pRenderTarget, IDirect3DSu return result ? D3D_OK : S_FALSE; } -HRESULT DX9RENDER::Clear(uint32_t Count, CONST D3DRECT *pRects, uint32_t Flags, D3DCOLOR Color, float Z, +HRESULT DX9RENDER::Clear(uint32_t Count, const D3DRECT *pRects, uint32_t Flags, D3DCOLOR Color, float Z, uint32_t Stencil) { return CHECKD3DERR(d3d9->Clear(Count, pRects, Flags, Color, Z, Stencil)); @@ -3676,7 +3679,7 @@ HRESULT DX9RENDER::EndScene() return D3D_OK; } -HRESULT DX9RENDER::SetClipPlane(uint32_t Index, CONST float *pPlane) +HRESULT DX9RENDER::SetClipPlane(uint32_t Index, const float *pPlane) { // return d3d9->SetClipPlane( Index, pPlane ); return D3D_OK; @@ -3707,7 +3710,7 @@ HRESULT DX9RENDER::CreateDepthStencilSurface(UINT Width, UINT Height, D3DFORMAT return CHECKD3DERR(d3d9->CreateDepthStencilSurface(Width, Height, Format, MultiSample, 0, TRUE, ppSurface, NULL)); } -HRESULT DX9RENDER::CreateVertexDeclaration(CONST D3DVERTEXELEMENT9 *pVertexElements, +HRESULT DX9RENDER::CreateVertexDeclaration(const D3DVERTEXELEMENT9 *pVertexElements, IDirect3DVertexDeclaration9 **ppDecl) { return CHECKD3DERR(d3d9->CreateVertexDeclaration(pVertexElements, ppDecl)); @@ -3718,12 +3721,12 @@ HRESULT DX9RENDER::SetVertexDeclaration(IDirect3DVertexDeclaration9 *pDecl) return CHECKD3DERR(d3d9->SetVertexDeclaration(pDecl)); } -HRESULT DX9RENDER::CreateVertexShader(CONST uint32_t *pFunction, IDirect3DVertexShader9 **ppShader) +HRESULT DX9RENDER::CreateVertexShader(const uint32_t *pFunction, IDirect3DVertexShader9 **ppShader) { return CHECKD3DERR(d3d9->CreateVertexShader((const DWORD *)pFunction, ppShader)); } -HRESULT DX9RENDER::CreatePixelShader(CONST uint32_t *pFunction, IDirect3DPixelShader9 **ppShader) +HRESULT DX9RENDER::CreatePixelShader(const uint32_t *pFunction, IDirect3DPixelShader9 **ppShader) { return CHECKD3DERR(d3d9->CreatePixelShader((const DWORD *)pFunction, ppShader)); } @@ -3779,12 +3782,12 @@ HRESULT DX9RENDER::GetLevelDesc(IDirect3DCubeTexture9 *ppCubeTexture, UINT Level } HRESULT DX9RENDER::LockRect(IDirect3DCubeTexture9 *ppCubeTexture, D3DCUBEMAP_FACES FaceType, UINT Level, - D3DLOCKED_RECT *pLockedRect, CONST RECT *pRect, uint32_t Flags) + D3DLOCKED_RECT *pLockedRect, const RECT *pRect, uint32_t Flags) { return CHECKD3DERR(ppCubeTexture->LockRect(FaceType, Level, pLockedRect, pRect, Flags)); } -HRESULT DX9RENDER::LockRect(IDirect3DTexture9 *ppTexture, UINT Level, D3DLOCKED_RECT *pLockedRect, CONST RECT *pRect, +HRESULT DX9RENDER::LockRect(IDirect3DTexture9 *ppTexture, UINT Level, D3DLOCKED_RECT *pLockedRect, const RECT *pRect, uint32_t Flags) { return CHECKD3DERR(ppTexture->LockRect(Level, pLockedRect, pRect, Flags)); @@ -3805,8 +3808,8 @@ HRESULT DX9RENDER::GetSurfaceLevel(IDirect3DTexture9 *ppTexture, UINT Level, IDi return CHECKD3DERR(ppTexture->GetSurfaceLevel(Level, ppSurfaceLevel)); } -HRESULT DX9RENDER::UpdateSurface(IDirect3DSurface9 *pSourceSurface, CONST RECT *pSourceRectsArray, UINT cRects, - IDirect3DSurface9 *pDestinationSurface, CONST POINT *pDestPointsArray) +HRESULT DX9RENDER::UpdateSurface(IDirect3DSurface9 *pSourceSurface, const RECT *pSourceRectsArray, UINT cRects, + IDirect3DSurface9 *pDestinationSurface, const POINT *pDestPointsArray) { return CHECKD3DERR(D3DXLoadSurfaceFromSurface(pDestinationSurface, nullptr, nullptr, pSourceSurface, nullptr, nullptr, D3DX_DEFAULT, 0)); @@ -3872,12 +3875,12 @@ HRESULT DX9RENDER::SetPixelShader(IDirect3DPixelShader9 *pShader) return CHECKD3DERR(d3d9->SetPixelShader(pShader)); } -HRESULT DX9RENDER::SetVertexShaderConstantF(UINT StartRegister, CONST float *pConstantData, UINT Vector4iCount) +HRESULT DX9RENDER::SetVertexShaderConstantF(UINT StartRegister, const float *pConstantData, UINT Vector4iCount) { return CHECKD3DERR(d3d9->SetVertexShaderConstantF(StartRegister, pConstantData, Vector4iCount)); } -HRESULT DX9RENDER::SetPixelShaderConstantF(UINT StartRegister, CONST float *pConstantData, UINT Vector4iCount) +HRESULT DX9RENDER::SetPixelShaderConstantF(UINT StartRegister, const float *pConstantData, UINT Vector4iCount) { return CHECKD3DERR(d3d9->SetPixelShaderConstantF(StartRegister, pConstantData, Vector4iCount)); } @@ -4224,13 +4227,17 @@ void DX9RENDER::ProgressView() float x, y, z, rhw; uint32_t color; float u, v; - } v[4]; + } v[4], t[4]; uint32_t i; for (i = 0; i < 4; i++) { v[i].z = 0.5; v[i].rhw = 2.0; v[i].color = 0xffffffff; + + t[i].z = 0.5; + t[i].rhw = 2.0; + t[i].color = 0xffffffff; } // Calculate the rectangle in which to draw D3DVIEWPORT9 vp; @@ -4264,13 +4271,16 @@ void DX9RENDER::ProgressView() float dy = 0.0f; float dx = ((float(vp.Width) - (4.0f * float(vp.Height) / 3.0f)) / 2.0f); + float dxx = 0.0f; if (dx < 10.0f) dx = 0.0f; else { - dy = 25.0f; + dy = float(vp.Height) * 0.025f; dx = ((float(vp.Width) - (4.0f * (float(vp.Height) - 2.0f * dy) / 3.0f)) / 2.0f); +// dxx = (float(vp.Width) - 2.0 * dx) * 0.125f; } + dxx = (float(vp.Width) - 2.0 * dx) * 0.125f; v[0].x = 0.0f + dx; v[0].y = 0.0f + dy; @@ -4297,28 +4307,49 @@ void DX9RENDER::ProgressView() } else { - if (progressTipsTexture >= 0) - { - TextureSet(1, progressTipsTexture); - DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1, 2, v, sizeof(v[0]), - "ProgressBackTechWithTips"); - } - else - { - DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1, 2, v, sizeof(v[0]), + DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1, 2, v, sizeof(v[0]), "ProgressBackTech"); - } } + + if (progressTipsTexture >= 0) + { + t[0].x = 0.0f + dx + dxx; + t[0].y = 0.0f + 0.787f * float(vp.Height); + t[1].x = float(vp.Width) - dx - dxx; + t[1].y = 0.0f + 0.787f * float(vp.Height); + t[2].x = 0.0f + dx + dxx; + t[2].y = float(vp.Height) - 0.094f * float(vp.Height); + t[3].x = float(vp.Width) - dx - dxx; + t[3].y = float(vp.Height) - 0.094f * float(vp.Height); + + t[0].u = 0.0f; + t[0].v = 0.0f; + t[1].u = 1.0f; + t[1].v = 0.0f; + t[2].u = 0.0f; + t[2].v = 1.0f; + t[3].u = 1.0f; + t[3].v = 1.0f; + + TextureSet(0, progressTipsTexture); + DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1, 2, t, sizeof(t[0]), + "ProgressBackTech"); + } + if (backTexture < 0) for (i = 0; i < 4; i++) v[i].color = 0xffffffff; // Animated object m_fHeightDeformator = ((float)vp.Height * 4.0f) / ((float)vp.Width * 3.0f); - // core.Trace(" size_x %f", (vp.Width - dx * 2.0f)*progressFramesWidth); - CVECTOR pos((vp.Width - dx * 2.0f) * progressFramesPosX + dx, (vp.Height - dy * 2.0f) * progressFramesPosY + dy, - 0.0f); - CVECTOR size((vp.Width - dx * 2.0f) * progressFramesWidth, - (vp.Height - dy * 2.0f) * progressFramesHeight * 4.0f / 3.0f, 0.0f); + +// core.Trace(" size_x %f size_y %f", (vp.Width - dx * 2.0f) * progressFramesWidth, (vp.Height - dy * 2.0f) * progressFramesHeight * 4.0f / 3.0f); + + CVECTOR pos(vp.Width * progressFramesPosX, vp.Height * progressFramesPosY, 0.0f); +// CVECTOR size(vp.Width * progressFramesWidth, vp.Width * progressFramesHeight * 4.0f / 3.0f, 0.0f); + +// CVECTOR pos((vp.Width - dx * 2.0f) * progressFramesPosX + dx, (vp.Height - dy * 2.0f) * progressFramesPosY + dy, 0.0f); + CVECTOR size((vp.Width - dx * 2.0f) * progressFramesWidth,(vp.Height - dy * 2.0f) * progressFramesHeight * 4.0f / 3.0f, 0.0f); + v[0].x = pos.x; v[0].y = pos.y; v[1].x = pos.x + size.x + 0.5f; diff --git a/src/libs/renderer/src/s_device.h b/src/libs/renderer/src/s_device.h index dec7747bc..60c932158 100644 --- a/src/libs/renderer/src/s_device.h +++ b/src/libs/renderer/src/s_device.h @@ -139,7 +139,7 @@ class DX9RENDER : public VDX9RENDER void SaveShoot() override; // DX9Render: Clip Planes Section - HRESULT SetClipPlane(uint32_t Index, CONST float *pPlane) override; + HRESULT SetClipPlane(uint32_t Index, const float *pPlane) override; PLANE *GetPlanes() override; // DX9Render: Camera Section @@ -211,8 +211,8 @@ class DX9RENDER : public VDX9RENDER void ReleaseVideoTexture(CVideoTexture *pVTexture) override; // DX9Render: Vertex/Index Buffers Section - int32_t CreateVertexBuffer(int32_t type, size_t nverts, uint32_t usage) override; - int32_t CreateIndexBuffer(size_t ntrgs, uint32_t dwUsage = D3DUSAGE_WRITEONLY) override; + int32_t CreateVertexBuffer(int32_t type, size_t nverts, uint32_t usage, uint32_t dwPool) override; + int32_t CreateIndexBuffer(size_t ntrgs, uint32_t dwUsage) override; IDirect3DVertexBuffer9 *GetVertexBuffer(int32_t id) override; int32_t GetVertexBufferFVF(int32_t id) override; @@ -281,31 +281,31 @@ class DX9RENDER : public VDX9RENDER HRESULT GetLevelDesc(IDirect3DTexture9 *ppTexture, UINT Level, D3DSURFACE_DESC *pDesc) override; HRESULT GetLevelDesc(IDirect3DCubeTexture9 *ppCubeTexture, UINT Level, D3DSURFACE_DESC *pDesc) override; HRESULT LockRect(IDirect3DCubeTexture9 *ppCubeTexture, D3DCUBEMAP_FACES FaceType, UINT Level, - D3DLOCKED_RECT *pLockedRect, CONST RECT *pRect, uint32_t Flags) override; - HRESULT LockRect(IDirect3DTexture9 *ppTexture, UINT Level, D3DLOCKED_RECT *pLockedRect, CONST RECT *pRect, + D3DLOCKED_RECT *pLockedRect, const RECT *pRect, uint32_t Flags) override; + HRESULT LockRect(IDirect3DTexture9 *ppTexture, UINT Level, D3DLOCKED_RECT *pLockedRect, const RECT *pRect, uint32_t Flags) override; HRESULT UnlockRect(IDirect3DCubeTexture9 *pCubeTexture, D3DCUBEMAP_FACES FaceType, UINT Level) override; HRESULT UnlockRect(IDirect3DTexture9 *pTexture, UINT Level) override; HRESULT GetSurfaceLevel(IDirect3DTexture9 *ppTexture, UINT Level, IDirect3DSurface9 **ppSurfaceLevel) override; - HRESULT UpdateSurface(IDirect3DSurface9 *pSourceSurface, CONST RECT *pSourceRectsArray, UINT cRects, - IDirect3DSurface9 *pDestinationSurface, CONST POINT *pDestPointsArray) override; + HRESULT UpdateSurface(IDirect3DSurface9 *pSourceSurface, const RECT *pSourceRectsArray, UINT cRects, + IDirect3DSurface9 *pDestinationSurface, const POINT *pDestPointsArray) override; HRESULT StretchRect(IDirect3DSurface9 *pSourceSurface, const RECT *pSourceRect, IDirect3DSurface9 *pDestSurface, const RECT *pDestRect, D3DTEXTUREFILTERTYPE Filter) override; HRESULT GetRenderTargetData(IDirect3DSurface9 *pRenderTarget, IDirect3DSurface9 *pDestSurface) override; // D3D Pixel/Vertex Shaders Section - HRESULT CreateVertexDeclaration(CONST D3DVERTEXELEMENT9 *pVertexElements, + HRESULT CreateVertexDeclaration(const D3DVERTEXELEMENT9 *pVertexElements, IDirect3DVertexDeclaration9 **ppDecl) override; HRESULT SetVertexDeclaration(IDirect3DVertexDeclaration9 *pDecl) override; - HRESULT CreatePixelShader(CONST uint32_t *pFunction, IDirect3DPixelShader9 **ppShader) override; - HRESULT CreateVertexShader(CONST uint32_t *pFunction, IDirect3DVertexShader9 **ppShader) override; + HRESULT CreatePixelShader(const uint32_t *pFunction, IDirect3DPixelShader9 **ppShader) override; + HRESULT CreateVertexShader(const uint32_t *pFunction, IDirect3DVertexShader9 **ppShader) override; HRESULT DeletePixelShader(IDirect3DPixelShader9 *pShader) override; HRESULT DeleteVertexShader(IDirect3DVertexShader9 *pShader) override; HRESULT SetVertexShader(IDirect3DVertexShader9 *pShader) override; HRESULT SetPixelShader(IDirect3DPixelShader9 *pShader) override; - /*virtual HRESULT SetFVFConstant(DWORD Register, CONST void* pConstantData, DWORD ConstantCount );*/ - HRESULT SetVertexShaderConstantF(UINT StartRegister, CONST float *pConstantData, UINT Vector4iCount) override; - HRESULT SetPixelShaderConstantF(UINT StartRegister, CONST float *pConstantData, UINT Vector4iCount) override; + /*virtual HRESULT SetFVFConstant(DWORD Register, const void* pConstantData, DWORD ConstantCount );*/ + HRESULT SetVertexShaderConstantF(UINT StartRegister, const float *pConstantData, UINT Vector4iCount) override; + HRESULT SetPixelShaderConstantF(UINT StartRegister, const float *pConstantData, UINT Vector4iCount) override; HRESULT SetFVF(uint32_t handle) override; HRESULT GetVertexShader(IDirect3DVertexShader9 **ppShader) override; HRESULT GetPixelShader(IDirect3DPixelShader9 **ppShader) override; @@ -316,7 +316,7 @@ class DX9RENDER : public VDX9RENDER // D3D Render Target/Begin/End/Clear HRESULT GetRenderTarget(IDirect3DSurface9 **ppRenderTarget) override; HRESULT SetRenderTarget(IDirect3DSurface9 *pRenderTarget, IDirect3DSurface9 *pNewZStencil) override; - HRESULT Clear(uint32_t Count, CONST D3DRECT *pRects, uint32_t Flags, D3DCOLOR Color, float Z, + HRESULT Clear(uint32_t Count, const D3DRECT *pRects, uint32_t Flags, D3DCOLOR Color, float Z, uint32_t Stencil) override; HRESULT BeginScene() override; HRESULT EndScene() override; @@ -488,6 +488,8 @@ class DX9RENDER : public VDX9RENDER bool bShowFps, bShowExInfo; bool bInsideScene; + int32_t fpsx, fpsy; + PLANE viewplane[4]; STEXTURE Textures[MAX_STEXTURES]{}; diff --git a/src/libs/renderer/src/storm_d3dx9.cpp b/src/libs/renderer/src/storm_d3dx9.cpp index 71d35a876..5ed9bdb54 100644 --- a/src/libs/renderer/src/storm_d3dx9.cpp +++ b/src/libs/renderer/src/storm_d3dx9.cpp @@ -2,6 +2,8 @@ #include "platform/d3dx9.hpp" +#include +#include // for memcpy #include #define WARN(...) fprintf(stdout, __VA_ARGS__) diff --git a/src/libs/rigging/src/sail.cpp b/src/libs/rigging/src/sail.cpp index 062e4897b..bfac76bb4 100644 --- a/src/libs/rigging/src/sail.cpp +++ b/src/libs/rigging/src/sail.cpp @@ -2084,13 +2084,16 @@ void sailPrint(VDX9RENDER *rs, const CVECTOR &pos3D, float rad, int32_t line, co static_cast(vrt.y), buf); } -SAILONE *SAIL::FindSailFromData(int gn, const std::string_view &nodeName, const std::string_view &grName) const +SAILONE *SAIL::FindSailFromData(int gn, const char *nodeName, const char *grName) const { - int grNum = std::stoi(std::string(grName)); + if (nodeName == nullptr || grName == nullptr) + return nullptr; + int grNum; + sscanf(grName, "%d", &grNum); for (int i = 0; i < gdata[gn].sailQuantity; i++) { const int sn = gdata[gn].sailIdx[i]; - if (slist[sn]->hostNode != nullptr && nodeName.compare(slist[sn]->hostNode->GetName()) == 0 && + if (slist[sn]->hostNode != nullptr && strcmp(slist[sn]->hostNode->GetName(), nodeName) == 0 && slist[sn]->groupNum == grNum) return slist[sn]; } diff --git a/src/libs/rigging/src/sail.h b/src/libs/rigging/src/sail.h index 05d3e5aa5..a500ff93d 100644 --- a/src/libs/rigging/src/sail.h +++ b/src/libs/rigging/src/sail.h @@ -187,7 +187,7 @@ class SAIL : public SAIL_BASE void DeleteSailGroup(); int FindGroupForCharacter(int chrIdx) const; int GetCharacterForGroup(int grNum) const; - SAILONE *FindSailFromData(int gn, const std::string_view &nodeName, const std::string_view &grName) const; + SAILONE *FindSailFromData(int gn, const char *nodeName, const char *grName) const; void SetSailTextures(int32_t grNum, VDATA *pvd) const; void DoRandomsSailsDmg(int chrIdx, int gn, float fDmg); void GetSailStatus(int chrIdx, int gn); diff --git a/src/libs/sea_ai/src/ai_balls.cpp b/src/libs/sea_ai/src/ai_balls.cpp index 837b1c2ea..cc88df422 100644 --- a/src/libs/sea_ai/src/ai_balls.cpp +++ b/src/libs/sea_ai/src/ai_balls.cpp @@ -3,12 +3,11 @@ #include "math_inlines.h" #include "shared/messages.h" - AIBalls *AIBalls::pAIBalls = nullptr; AIBalls::AIBalls() - : pSail(nullptr), pSea(nullptr), pFort(nullptr), pIsland(nullptr), - fDeltaTimeMultiplier(1.0f), fBallFlySoundDistance(1.0f), dwFireBallFromCameraTime(0) + : pSail(nullptr), pSea(nullptr), pFort(nullptr), pIsland(nullptr), fDeltaTimeMultiplier(1.0f), + fBallFlySoundDistance(1.0f), dwFireBallFromCameraTime(0) { pAIBalls = this; } @@ -141,10 +140,11 @@ void AIBalls::AddBall(ATTRIBUTES *pABall) const auto fDir = pABall->GetAttributeAsFloat("Dir"); pBall->fDirX = cosf(fDir); pBall->fDirZ = sinf(fDir); + pBall->fRawAng = pABall->GetAttributeAsFloat("RawAng"); pBall->pParticle = nullptr; pBall->sBallEvent = to_string(pABall->GetAttribute("Event")); - + if (aBallTypes[i].sParticleName.size()) { entid_t eidParticle; @@ -198,10 +198,21 @@ void AIBalls::Execute(uint32_t Delta_Time) pBall->fTime += fDeltaTime * fDeltaTimeMultiplier * pBall->fTimeSpeedMultiply; // update positions float fsX = pBall->fSpeedV0 * pBall->fTime * pBall->fCosAngle; - float fsY = pBall->fHeightMultiply * (pBall->fSpeedV0 * pBall->fTime * pBall->fSinAngle - - AIHelper::fGravity * SQR(pBall->fTime) / 2.0f); - pBall->vPos = CVECTOR(0.0f, fsY, fsX); + float fsY = + (pBall->fSpeedV0 * pBall->fTime * pBall->fSinAngle - AIHelper::fGravity * SQR(pBall->fTime) / 2.0f); + + // HeightMultiply + float fCosRaw = cosf(pBall->fRawAng); + float fSinRaw = sinf(pBall->fRawAng); + float fProjX = fsX * fCosRaw + fsY * fSinRaw; + float fProjY = -fsX * fSinRaw + fsY * fCosRaw; + fProjY *= pBall->fHeightMultiply; + float fX = fProjX * fCosRaw - fProjY * fSinRaw; + float fY = fProjX * fSinRaw + fProjY * fCosRaw; + + pBall->vPos = CVECTOR(0.0f, fY, fX); RotateAroundY(pBall->vPos.x, pBall->vPos.z, pBall->fDirX, pBall->fDirZ); + pBall->vPos += pBall->vFirstPos; vDst = pBall->vPos; @@ -240,7 +251,7 @@ void AIBalls::Execute(uint32_t Delta_Time) // sail trace if (pSail) pSail->Cannon_Trace(pBall->iBallOwner, vSrc, vDst); - + auto &&entities = core.GetEntityIds(SHIP_CANNON_TRACE); for (auto ent_id : entities) { @@ -375,18 +386,17 @@ uint32_t AIBalls::AttributeChanged(ATTRIBUTES *pAttributeChanged) // install balls ATTRIBUTES *pAPBalls = AttributesPointer->GetAttributeClass("Balls"); uint32_t dwIdx = 0; - while (pAPBalls != nullptr) + while (pAPBalls && true) { - if (dwIdx >= pAPBalls->GetAttributesNum()) { + const char *pName = pAPBalls->GetAttributeName(dwIdx); + if (!pName) break; - } - const std::string_view attr_name = pAPBalls->GetAttributeName(dwIdx); - ATTRIBUTES *pAP = pAPBalls->GetAttributeClass(attr_name); + ATTRIBUTES *pAP = pAPBalls->GetAttributeClass(pName); if (!pAP) break; BALL_TYPE ballType; - ballType.sName = attr_name; + ballType.sName = pName; ballType.dwSubTexIndex = pAP->GetAttributeAsDword("SubTexIndex"); ballType.dwGoodIndex = pAP->GetAttributeAsDword("GoodIndex"); ballType.fSize = pAP->GetAttributeAsFloat("Size"); @@ -441,6 +451,7 @@ void BALL_PARAMS::Save(CSaveLoad *pSL) pSL->SaveFloat(fSizeMultiply); pSL->SaveFloat(fTimeSpeedMultiply); pSL->SaveFloat(fMaxFireDistance); + pSL->SaveFloat(fRawAng); pSL->SaveDword(dwCannonType); } @@ -461,7 +472,7 @@ void BALL_PARAMS::Load(CSaveLoad *pSL) { vFirstPos = pSL->LoadVector(); vPos = pSL->LoadVector(); - //pParticle = reinterpret_cast(pSL->LoadDword()); + // pParticle = reinterpret_cast(pSL->LoadDword()); pParticle = reinterpret_cast(pSL->LoadQword()); sBallEvent = pSL->LoadString(); iBallOwner = pSL->LoadLong(); @@ -475,6 +486,7 @@ void BALL_PARAMS::Load(CSaveLoad *pSL) fSizeMultiply = pSL->LoadFloat(); fTimeSpeedMultiply = pSL->LoadFloat(); fMaxFireDistance = pSL->LoadFloat(); + fRawAng = pSL->LoadFloat(); dwCannonType = pSL->LoadDword(); } diff --git a/src/libs/sea_ai/src/ai_balls.h b/src/libs/sea_ai/src/ai_balls.h index d7e76afb2..aceadb77f 100644 --- a/src/libs/sea_ai/src/ai_balls.h +++ b/src/libs/sea_ai/src/ai_balls.h @@ -24,6 +24,7 @@ struct BALL_PARAMS float fSizeMultiply; // Size of ball multiply float fTimeSpeedMultiply; // Time speed multiply float fMaxFireDistance; + float fRawAng; uint32_t dwCannonType; // Additional parameter }; diff --git a/src/libs/sea_ai/src/ai_cannon.cpp b/src/libs/sea_ai/src/ai_cannon.cpp index 3f10b2bf4..643f784d8 100644 --- a/src/libs/sea_ai/src/ai_cannon.cpp +++ b/src/libs/sea_ai/src/ai_cannon.cpp @@ -4,8 +4,7 @@ uint64_t dwTmpRDTSC; -AICannon::AICannon() - : pAHolder(nullptr), eidParent(0), vPos(), vDir(), fSpeedV0(0), vEnemyPos() +AICannon::AICannon() : pAHolder(nullptr), eidParent(0), vPos(), vDir(), fSpeedV0(0), vEnemyPos() { bLoad = false; bEmpty = true; @@ -125,8 +124,15 @@ void AICannon::RealFire() const auto vDirTemp = mRot * vDir; const auto fDirY = NormalizeAngle(atan2f(vDirTemp.x, vDirTemp.z)); - core.Event(CANNON_FIRE, "affffffff", pAHolder->GetACharacter(), vPosTemp.x, vPosTemp.y, vPosTemp.z, fSpeedV0, - fFireDirection, fFireHeightAngle, fDirY, fMaxFireDistance); + + // raw angle + const CVECTOR vFlatEnemyDir = !(CVECTOR(vEnemyPos.x, vPosTemp.y, vEnemyPos.z) - vPosTemp); + float fAngle = acosf(vFlatEnemyDir | vEnemyDir); + if (vEnemyPos.y < vPosTemp.y) + fAngle = -fAngle; + + core.Event(CANNON_FIRE, "afffffffff", pAHolder->GetACharacter(), vPosTemp.x, vPosTemp.y, vPosTemp.z, fSpeedV0, + fFireDirection, fFireHeightAngle, fDirY, fMaxFireDistance, fAngle); pAIObj->Fire(*pAIObj->GetMatrix() * (vPos + vDir)); diff --git a/src/libs/sea_ai/src/ai_ship_cannon_controller.cpp b/src/libs/sea_ai/src/ai_ship_cannon_controller.cpp index dc92b39df..113854a80 100644 --- a/src/libs/sea_ai/src/ai_ship_cannon_controller.cpp +++ b/src/libs/sea_ai/src/ai_ship_cannon_controller.cpp @@ -7,6 +7,17 @@ float AIShipCannonController::fMaxCannonDamageDistance = 1.0f; float AIShipCannonController::fMaxCannonDamageRadiusPoint = 1.0f; +int AIShipCannonController::ColorA = 0; +int AIShipCannonController::ColorR = 0; +int AIShipCannonController::ColorNA = 0; +int AIShipCannonController::ColorNR = 0; +int AIShipCannonController::blinkcol = 0; +float alpha = 0.0f; +float AIShipCannonController::blinkUP = 0.0003f; +float AIShipCannonController::blinkDOWN = 0.003f; +bool AIShipCannonController::bShowCannonsRange = true; +bool bUp = true; + AIShipCannonController::AIShipCannonController(AIShip *_pShip) : bReload(false), bNotEnoughBalls(false) { SetAIShip(_pShip); @@ -560,77 +571,77 @@ void AIShipCannonController::Realize(float fDeltaTime) debugDrawToggle = !debugDrawToggle; std::this_thread::sleep_for(100ms); } - - if (!debugDrawToggle) - { - return; - } - - for (auto it = debugFirePositions.begin(); it != debugFirePositions.end();) + + if(!bShowCannonsRange) return; + + if (debugDrawToggle) { - constexpr auto kDebugFadeTime = 3.0f; - if (auto &[pos, color, dt] = *it; dt <= kDebugFadeTime) - { - dt += fDeltaTime; - - CVECTOR cPos; - CVECTOR cAng; - float cFov; - AIHelper::pRS->GetCamera(cPos, cAng, cFov); - - const auto dist = (pos - cPos).GetLength(); - - float radius = 0.3f; - if (dist > 1.0f) - { - radius *= sqrtf(dist); - } - AIHelper::pRS->DrawSphere(pos, radius, color); - ++it; - } - else - { - it = debugFirePositions.erase(it); - } - } - - static std::vector Lines; - Lines.clear(); - - for (const auto &bort : aShipBorts) - { - for (const auto &cannon : bort.aCannons) - { - if (!cannon.isDamaged()) - { - constexpr auto red = ARGB(0xFF, 0xDC, 0x14, 0x3C); - constexpr auto green = ARGB(0xFF, 0x7C, 0xFC, 0x00); - - const auto &&vPos = cannon.GetPos(); - Lines.emplace_back(RS_LINE{vPos, red}); - Lines.emplace_back(RS_LINE{vPos + 5.0f * cannon.GetDir(), red}); - Lines.emplace_back(RS_LINE{vPos, green}); - Lines.emplace_back(RS_LINE{vPos + CVECTOR{0.0f, cannon.GetDirY(), 0.0f}, green}); - } - } - } - - if (!Lines.empty()) - { - AIHelper::pRS->SetTransform(D3DTS_WORLD, CMatrix()); - AIHelper::pRS->DrawLines(Lines.data(), Lines.size() / 2, "Line"); - } - - if (GetAIShip()->isMainCharacter()) - { - std::string buf; - for (const auto &bort : aShipBorts) - { - buf += fmt::format("{:.3f} ", GetBortHeightAngle(bort)); - } - AIHelper::pRS->Print(200, 20, buf.c_str()); - } - + for (auto it = debugFirePositions.begin(); it != debugFirePositions.end();) + { + constexpr auto kDebugFadeTime = 3.0f; + if (auto &[pos, color, dt] = *it; dt <= kDebugFadeTime) + { + dt += fDeltaTime; + + CVECTOR cPos; + CVECTOR cAng; + float cFov; + AIHelper::pRS->GetCamera(cPos, cAng, cFov); + + const auto dist = (pos - cPos).GetLength(); + + float radius = 0.3f; + if (dist > 1.0f) + { + radius *= sqrtf(dist); + } + AIHelper::pRS->DrawSphere(pos, radius, color); + ++it; + } + else + { + it = debugFirePositions.erase(it); + } + } + + static std::vector Lines; + Lines.clear(); + + for (const auto &bort : aShipBorts) + { + for (const auto &cannon : bort.aCannons) + { + if (!cannon.isDamaged()) + { + constexpr auto red = ARGB(0xFF, 0xDC, 0x14, 0x3C); + constexpr auto green = ARGB(0xFF, 0x7C, 0xFC, 0x00); + + const auto &&vPos = cannon.GetPos(); + Lines.emplace_back(RS_LINE{vPos, red}); + Lines.emplace_back(RS_LINE{vPos + 5.0f * cannon.GetDir(), red}); + Lines.emplace_back(RS_LINE{vPos, green}); + Lines.emplace_back(RS_LINE{vPos + CVECTOR{0.0f, cannon.GetDirY(), 0.0f}, green}); + } + } + } + + if (!Lines.empty()) + { + AIHelper::pRS->SetTransform(D3DTS_WORLD, CMatrix()); + AIHelper::pRS->DrawLines(Lines.data(), Lines.size() / 2, "Line"); + } + + if (GetAIShip()->isMainCharacter()) + { + std::string buf; + for (const auto &bort : aShipBorts) + { + buf += fmt::format("{:.3f} ", GetBortHeightAngle(bort)); + } + AIHelper::pRS->Print(200, 20, buf.c_str()); + } + } + struct tr_vertex { CVECTOR vPos; @@ -646,6 +657,8 @@ void AIShipCannonController::Realize(float fDeltaTime) const CVECTOR vPosTemp = GetAIShip()->GetPos(); for (const auto &bort : aShipBorts) { + if(!GetAIShip()->isMainCharacter() && !debugDrawToggle) continue; + if(bort.isBortDamaged()) continue; if (!bort.aCannons.empty()) { // calc fire range @@ -672,10 +685,26 @@ void AIShipCannonController::Realize(float fDeltaTime) RotateAroundY(v[2].x, v[2].z, vZ.z, vZ.x); v[2] += v[0]; - constexpr auto color = ARGB(0x0F, 0x90, 0xEE, 0x90); - Verts.emplace_back(tr_vertex{v[0], color}); - Verts.emplace_back(tr_vertex{v[1], color}); - Verts.emplace_back(tr_vertex{v[2], color}); + if(debugDrawToggle) ColorA = ColorR = ColorNA = ColorNR = ARGB(0x0F, 0x90, 0xEE, 0x90); + if(!bort.isCharged()) + { + blinkcol = (ColorNR >> 24); + if(bUp) + { + alpha += blinkUP * core.GetDeltaTime(); + if(alpha > blinkcol) bUp = false; + } + else + { + alpha -= blinkDOWN * core.GetDeltaTime(); + if(alpha < 0) bUp = true; + } + blinkcol = ColorNA + (static_cast(alpha) << 24); + } + + Verts.emplace_back(tr_vertex{v[0], bort.isCharged() ? static_cast(ColorA) : static_cast(ColorNA)}); + Verts.emplace_back(tr_vertex{v[1], bort.isCharged() ? static_cast(ColorR) : static_cast(blinkcol)}); + Verts.emplace_back(tr_vertex{v[2], bort.isCharged() ? static_cast(ColorR) : static_cast(blinkcol)}); } } } diff --git a/src/libs/sea_ai/src/ai_ship_cannon_controller.h b/src/libs/sea_ai/src/ai_ship_cannon_controller.h index 468151caf..1d2cc0c7e 100644 --- a/src/libs/sea_ai/src/ai_ship_cannon_controller.h +++ b/src/libs/sea_ai/src/ai_ship_cannon_controller.h @@ -134,7 +134,6 @@ class AIShipCannonController // init section bool Init(ATTRIBUTES *_pAShip); - void SetAIShip(AIShip *pShip) { pOurAIShip = pShip; @@ -151,6 +150,12 @@ class AIShipCannonController static float fMaxCannonDamageDistance; static float fMaxCannonDamageRadiusPoint; + static int ColorA, ColorR, ColorNA, ColorNR, blinkcol; + static bool bShowCannonsRange; + float alpha; + static float blinkUP; + static float blinkDOWN; + void Save(CSaveLoad *pSL); void Load(CSaveLoad *pSL); }; \ No newline at end of file diff --git a/src/libs/sea_ai/src/locator_show.cpp b/src/libs/sea_ai/src/locator_show.cpp index 49affe211..7e6788208 100644 --- a/src/libs/sea_ai/src/locator_show.cpp +++ b/src/libs/sea_ai/src/locator_show.cpp @@ -44,15 +44,20 @@ CVECTOR SeaLocatorShow::GetLocatorPos(ATTRIBUTES *pA) return v; } -std::string_view SeaLocatorShow::GetLocatorName(ATTRIBUTES *pA) +const char *SeaLocatorShow::GetRealLocatorName(ATTRIBUTES *pA) +{ + return pA->GetThisName(); +} + +const char *SeaLocatorShow::GetLocatorName(ATTRIBUTES *pA) { const char *pName = pA->GetAttribute("name"); if (!pName) - return pA->GetThisName(); + pName = pA->GetThisName(); return pName; } -std::string_view SeaLocatorShow::GetLocatorGroupName(ATTRIBUTES *pA) +const char *SeaLocatorShow::GetLocatorGroupName(ATTRIBUTES *pA) { auto *const pAParent = pA->GetParent(); Assert(pAParent); @@ -100,11 +105,12 @@ void SeaLocatorShow::PrintLocator(ATTRIBUTES *pA) mtx.Projection(&vPos, &vrt, 1, fWidth, fHeight, sizeof(CVECTOR), sizeof(MTX_PRJ_VECTOR)); vPos = CVECTOR(vrt.x, vrt.y, vrt.z); - const auto pGName = std::string(GetLocatorGroupName(pA)); - const auto pName = std::string(GetLocatorName(pA)); + const char *pName, *pGName; - AIHelper::Print(vPos.x, vPos.y - fh * 0.8f, fScale, "grp: \"%s\"", pGName.c_str()); - AIHelper::Print(vPos.x, vPos.y, fScale, "loc: \"%s\"", pName.c_str()); + if (pGName = GetLocatorGroupName(pA)) + AIHelper::Print(vPos.x, vPos.y - fh * 0.8f, fScale, "grp: \"%s\"", pGName); + if (pName = GetLocatorName(pA)) + AIHelper::Print(vPos.x, vPos.y, fScale, "loc: \"%s\"", pName); auto fRadius = GetLocatorRadius(pA); AIHelper::Print(vPos.x, vPos.y + fh * 0.8f, fScale, "rad: %.2f", fRadius); if (fRadius > 0.0f) diff --git a/src/libs/sea_ai/src/locator_show.h b/src/libs/sea_ai/src/locator_show.h index 45aa382c5..003b868d1 100644 --- a/src/libs/sea_ai/src/locator_show.h +++ b/src/libs/sea_ai/src/locator_show.h @@ -26,8 +26,9 @@ class SeaLocatorShow : public Entity CVECTOR GetLocatorPos(ATTRIBUTES *pA); float GetLocatorAng(ATTRIBUTES *pA); float GetLocatorRadius(ATTRIBUTES *pA); - std::string_view GetLocatorName(ATTRIBUTES *pA); - std::string_view GetLocatorGroupName(ATTRIBUTES *pA); + const char *GetRealLocatorName(ATTRIBUTES *pA); + const char *GetLocatorName(ATTRIBUTES *pA); + const char *GetLocatorGroupName(ATTRIBUTES *pA); void PrintLocator(ATTRIBUTES *pA); void ProcessLocators(ATTRIBUTES *pA); diff --git a/src/libs/sea_ai/src/sea_ai.cpp b/src/libs/sea_ai/src/sea_ai.cpp index fc76860bc..a84a6e52a 100644 --- a/src/libs/sea_ai/src/sea_ai.cpp +++ b/src/libs/sea_ai/src/sea_ai.cpp @@ -338,6 +338,16 @@ uint64_t SEA_AI::ProcessMessage(MESSAGE &message) Assert(pAIShip); pAIShip->GetCannonController()->ResearchCannons(); } + break; + + case AI_MESSAGE_CANNONS_RANGE: + AIShipCannonController::ColorA = message.Long(); + AIShipCannonController::ColorR = message.Long(); + AIShipCannonController::ColorNA = message.Long(); + AIShipCannonController::ColorNR = message.Long(); + AIShipCannonController::blinkUP = message.Float(); + AIShipCannonController::blinkDOWN = message.Float(); + AIShipCannonController::bShowCannonsRange = (message.Long() != 0); break; // boal 08.08.06 method of recounting guns on the ship <-- case AI_MESSAGE_SEASAVE: //TODO: check these two diff --git a/src/libs/sea_foam/src/seafoam.cpp b/src/libs/sea_foam/src/seafoam.cpp index 34ebb0bbd..e92f7c3c0 100644 --- a/src/libs/sea_foam/src/seafoam.cpp +++ b/src/libs/sea_foam/src/seafoam.cpp @@ -561,7 +561,7 @@ void SEAFOAM::Execute(uint32_t dTime) //-------------------------------------------------------------------- uint32_t SEAFOAM::AttributeChanged(ATTRIBUTES *pA) { - const std::string_view nm = pA->GetThisName(); + const auto *const nm = pA->GetThisName(); if (storm::iEquals(nm, "storm")) { diff --git a/src/libs/sea_foam/src/t_carcass.cpp b/src/libs/sea_foam/src/t_carcass.cpp index 310588703..90e738a80 100644 --- a/src/libs/sea_foam/src/t_carcass.cpp +++ b/src/libs/sea_foam/src/t_carcass.cpp @@ -20,7 +20,7 @@ TCarcass::TCarcass(int _levelsCount, int _measurePointsCount, VDX9RENDER *_rende uSpeed = 15e-5f; iBuffer = renderer->CreateIndexBuffer(3 * 2 * (MEASURE_POINTS - 1) * (TRACE_STEPS_Z - 1) * sizeof(uint16_t)); vBuffer = renderer->CreateVertexBuffer( - CARCASS_VERTEX_FORMAT, MEASURE_POINTS * (TRACE_STEPS_Z + 1) * sizeof(tCarcassVertex), D3DUSAGE_WRITEONLY); + CARCASS_VERTEX_FORMAT, MEASURE_POINTS * (TRACE_STEPS_Z + 1) * sizeof(tCarcassVertex), 0, D3DPOOL_MANAGED); } //-------------------------------------------------------------------- diff --git a/src/libs/shared_headers/include/shared/battle_interface/log_msg.h b/src/libs/shared_headers/include/shared/battle_interface/log_msg.h index 2cf3a9baa..69bfb187c 100644 --- a/src/libs/shared_headers/include/shared/battle_interface/log_msg.h +++ b/src/libs/shared_headers/include/shared/battle_interface/log_msg.h @@ -9,3 +9,6 @@ #define LI_CLEAR_STRINGS 45028 // "" // "s..." for different messages "SetTimeScale", float fScale #define LI_OTHER_MSG 45029 +#define LOG_ADD_PIC 45030 +#define LOG_TIME_SPEED 45031 +#define LOG_LEVEL_UP 45032 \ No newline at end of file diff --git a/src/libs/shared_headers/include/shared/events.h b/src/libs/shared_headers/include/shared/events.h index 274f2a3e6..d4959f20b 100644 --- a/src/libs/shared_headers/include/shared/events.h +++ b/src/libs/shared_headers/include/shared/events.h @@ -19,4 +19,12 @@ // crosshair #define TELESCOPE_ACTIVE "TelescopeActive" +// Worldmap +#define WORLDMAP_ENCOUNTER_TYPE_UNKNOWN 0 +#define WORLDMAP_ENCOUNTER_TYPE_MERCHANT 1 +#define WORLDMAP_ENCOUNTER_TYPE_WARRING 2 +#define WORLDMAP_ENCOUNTER_TYPE_FOLLOW 3 +#define WORLDMAP_ENCOUNTER_TYPE_STORM 4 +#define WORLDMAP_ENCOUNTER_TYPE_INVALID 2147483647 // INT32_MAX = 0x7fffffff + #endif diff --git a/src/libs/shared_headers/include/shared/messages.h b/src/libs/shared_headers/include/shared/messages.h index 52b7b7140..b437f334a 100644 --- a/src/libs/shared_headers/include/shared/messages.h +++ b/src/libs/shared_headers/include/shared/messages.h @@ -99,6 +99,7 @@ #define MSG_LOCATION_MODEL_LAMPS 30113 // "l" add the current model to the ignore list for tracing rays from lamps // "lf" set the effect of generating the matrix for reflection, f is the scaling factor #define MSG_LOCATION_MODEL_REFLECTION 30114 +#define MSG_LOCATION_MODEL_SET_ROT_ANGLE 30115 // "lfff" set the base rotation angle of the last loaded model // Install patches #define MSG_LOCATION_SET_CHRS_PATCH 30120 // "ls" load the character patch #define MSG_LOCATION_SET_CAM_PATCH 30121 // "ls" load camera patch @@ -247,6 +248,8 @@ #define MSG_WORLDMAP_SET_NATION_FLAG 31150 // "ll" nation // Print line with coordinates #define MSG_WORLDMAP_SET_COORDINATES 31151 // "ls" coordinates string +// Show or hide WdmWindUI: wind, date, moral, supplies, coordinates, flag +#define MSG_WORLDMAP_WIND_UI_SET_SHOW 31152 // "l" // ============================================================================================ // Effects diff --git a/src/libs/shared_headers/include/shared/sea_ai/script_defines.h b/src/libs/shared_headers/include/shared/sea_ai/script_defines.h index 05eca325a..482073aa2 100644 --- a/src/libs/shared_headers/include/shared/sea_ai/script_defines.h +++ b/src/libs/shared_headers/include/shared/sea_ai/script_defines.h @@ -169,6 +169,8 @@ #define AI_MESSAGE_SEALOAD 51043 #define AI_MESSAGE_FORT_SET_LIGHTS 51044 #define AI_MESSAGE_FORT_UNSET_LIGHTS 51045 +// cannons range +#define AI_MESSAGE_CANNONS_RANGE 51046 // the method of recounting the guns on the ship SendMessage(&AISea, "la", AI_MESSAGE_RESEARCH_CANNONS, aCharacter) #define AI_MESSAGE_RESEARCH_CANNONS 51050 diff --git a/src/libs/sound_service/src/sound_service.cpp b/src/libs/sound_service/src/sound_service.cpp index 624338c3f..426484fd8 100644 --- a/src/libs/sound_service/src/sound_service.cpp +++ b/src/libs/sound_service/src/sound_service.cpp @@ -2,10 +2,10 @@ #include -#include "entity.h" #include "matrix.h" #include "rands.h" #include "v_file_service.h" +#include "vma.hpp" #include // for debugging @@ -270,29 +270,9 @@ bool SoundService::AllocateSound(TSD_ID &id) return true; } -const char *SoundService::GetRandomName(tAlias *_alias) const +const char *SoundService::GetRandomName(const tAlias *alias) const { - const auto randomFloat = rand(_alias->fMaxProbabilityValue); - auto currentNameIndex = 0; - auto currentFloat = 0.f; - - for (;;) - { - if (currentFloat > randomFloat) - break; - if ((currentNameIndex + 1) >= static_cast(_alias->SoundFiles.size())) - break; - - currentFloat += _alias->SoundFiles[currentNameIndex].fProbability; - currentNameIndex++; - } - - if (currentNameIndex >= static_cast(_alias->SoundFiles.size())) - { - currentNameIndex = static_cast(_alias->SoundFiles.size()) - 1; - } - - return _alias->SoundFiles[currentNameIndex].FileName.c_str(); + return alias->soundFiles.pickRandom().c_str(); } int SoundService::GetAliasIndexByName(const char *szAliasName) @@ -325,7 +305,7 @@ TSD_ID SoundService::SoundPlay(const char *_name, eSoundType _type, eVolumeType { // Trying to find in aliases const auto AliasIdx = GetAliasIndexByName(_name); - if (AliasIdx >= 0 && Aliases[AliasIdx].SoundFiles.size() > 0) + if (AliasIdx >= 0 && !Aliases[AliasIdx].soundFiles.empty()) { // play sound from the alias ... FileName = GetRandomName(&Aliases[AliasIdx]); @@ -1031,39 +1011,28 @@ void SoundService::SoundStop(TSD_ID _id, int32_t _time) void SoundService::AnalyseNameStringAndAddToAlias(tAlias *_alias, const char *in_string) const { - static char tempString2[COMMON_STRING_LENGTH]; - strncpy_s(tempString2, in_string, COMMON_STRING_LENGTH); + static char fileName[COMMON_STRING_LENGTH]; + strncpy_s(fileName, in_string, COMMON_STRING_LENGTH); - tAliasSound snd; + float probability = DEFAULT_PROBABILITY; - char *col = strchr(tempString2, ','); - if (!col) + char *col = strchr(fileName, ','); + if (col) { - // only name, without delays - _alias->fMaxProbabilityValue += DEFAULT_PROBABILITY; - snd.fProbability = DEFAULT_PROBABILITY; - snd.FileName = tempString2; - - if constexpr (TRACE_INFORMATION) - core.Trace(" -> sound %s", snd.FileName.c_str()); - _alias->SoundFiles.push_back(snd); - - return; - } + // try to convert forthcoming number + float flt; + if (sscanf(++col, "%f", &flt) == 1) + { + probability = flt; + } - // try to convert forthcoming number - float n1; - if (sscanf(++col, "%f", &n1) == 1) - { - snd.fProbability = n1; - _alias->fMaxProbabilityValue += n1; + *(--col) = '\0'; // truncate at first ',' } - *(--col) = 0; // truncate at first ',' - snd.FileName = tempString2; if constexpr (TRACE_INFORMATION) - core.Trace(" -> sound %s, %f", snd.FileName.c_str(), snd.fProbability); - _alias->SoundFiles.push_back(snd); + core.Trace(" -> sound %s, %f", fileName, probability); + + _alias->soundFiles.emplace(probability, fileName); } void SoundService::AddAlias(INIFILE &_iniFile, char *_sectionName) @@ -1082,7 +1051,6 @@ void SoundService::AddAlias(INIFILE &_iniFile, char *_sectionName) alias.fMinDistance = _iniFile.GetFloat(_sectionName, "minDistance", -1.0f); alias.fVolume = _iniFile.GetFloat(_sectionName, "volume", -1.0f); alias.iPrior = _iniFile.GetInt(_sectionName, "prior", 128); - alias.fMaxProbabilityValue = 0.0f; if (_iniFile.ReadString(_sectionName, "name", tempString, COMMON_STRING_LENGTH, "")) { diff --git a/src/libs/sound_service/src/sound_service.h b/src/libs/sound_service/src/sound_service.h index 0be77861a..dd428ef26 100644 --- a/src/libs/sound_service/src/sound_service.h +++ b/src/libs/sound_service/src/sound_service.h @@ -1,14 +1,15 @@ #pragma once +#include +#include + #include "c_vector.h" #include "dx9render.h" +#include "probability_table.hpp" #include "sound_defines.h" #include "v_sound_service.h" -#include "vma.hpp" -#include -#include -#include +#include #define MAX_SOUNDS_SLOTS 4095 @@ -107,23 +108,16 @@ class SoundService : public VSoundService void CreateEntityIfNeed(); // Aliases ------------------------------------------------------------ - struct tAliasSound - { - std::string FileName; - float fProbability; - }; - struct tAlias { std::string Name; uint32_t dwNameHash; - - float fMaxProbabilityValue; + float fMinDistance; float fMaxDistance; int32_t iPrior; float fVolume; - std::vector SoundFiles; + storm::ProbabilityTable soundFiles; tAlias() { @@ -132,7 +126,7 @@ class SoundService : public VSoundService std::vector Aliases; - const char *GetRandomName(tAlias *_alias) const; + const char *GetRandomName(const tAlias *alias) const; int GetAliasIndexByName(const char *szAliasName); void AnalyseNameStringAndAddToAlias(tAlias *_alias, const char *in_string) const; void AddAlias(INIFILE &_iniFile, char *_sectionName); diff --git a/src/libs/util/include/fs.h b/src/libs/util/include/fs.h index da3ba3e70..45940c327 100644 --- a/src/libs/util/include/fs.h +++ b/src/libs/util/include/fs.h @@ -22,11 +22,11 @@ inline path GetStashPath() wchar_t *str = nullptr; SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_SIMPLE_IDLIST, nullptr, &str); path = str; - path = path / "My Games" / "Sea Dogs"; + path = path / "My Games" / "Caribbean Legend"; CoTaskMemFree(str); #else char *pref_path = nullptr; - pref_path = SDL_GetPrefPath("Akella", "Sea Dogs"); + pref_path = SDL_GetPrefPath("BlackMark Studio", "Carribean Legend"); path = pref_path; #endif } diff --git a/src/libs/util/include/probability_table.hpp b/src/libs/util/include/probability_table.hpp new file mode 100644 index 000000000..b23194b48 --- /dev/null +++ b/src/libs/util/include/probability_table.hpp @@ -0,0 +1,69 @@ +#include +#include +#include +#include +#include +#include + +#include "rands.h" + +namespace storm +{ + +template struct RandCstd +{ + Type operator()(Type max) noexcept + { + return rand(max); + } +}; + +template struct EpsilonLessThan +{ + bool operator()(Type lhs, Type rhs) + { + return rhs - lhs > std::numeric_limits::epsilon(); + } +}; + +/** + * \brief Probability table quantizing generated random value according to its weight + * \tparam Type - containing type + * \tparam Resolution - resolution type + * \tparam RandProvider - functor returning 0..1 + */ +template > + requires std::is_floating_point_v +class ProbabilityTable +{ + using element = std::pair; + + public: + ProbabilityTable() = default; + + template void emplace(Resolution weight, Args &&...args) + { + weight_sum_ += weight; + table_.emplace_back(std::make_pair(weight_sum_, std::forward(args)...)); + } + + const Type &pickRandom() const + { + + const Resolution random_value = provider_(weight_sum_ - weight_sum_ * std::numeric_limits::epsilon()); + const auto it = std::ranges::upper_bound(table_, random_value, EpsilonLessThan{}, &element::first); + return it->second; + } + + bool empty() const + { + return table_.empty(); + } + + private: + mutable RandProvider provider_; + Resolution weight_sum_{0.0f}; + std::vector table_; +}; + +} // namespace storm \ No newline at end of file diff --git a/src/libs/util/include/rands.h b/src/libs/util/include/rands.h index db224816e..66e8ab06f 100644 --- a/src/libs/util/include/rands.h +++ b/src/libs/util/include/rands.h @@ -1,13 +1,11 @@ #pragma once -#include -#include +#include // returns random float inline float rand(float r) { - std::random_device rd; - return r * ((float)rd() / (float)UINT_MAX); + return r * ((float)rand() / (float)RAND_MAX); } // returns larger half of random float @@ -22,4 +20,4 @@ inline float randCentered(float r) { float half = r / 2.0f; return (rand(r) - half); -} +} \ No newline at end of file diff --git a/src/libs/util/include/utf8.h b/src/libs/util/include/utf8.h index a1719723e..84ff498c6 100644 --- a/src/libs/util/include/utf8.h +++ b/src/libs/util/include/utf8.h @@ -4,7 +4,9 @@ #include #include +#ifdef _WIN32 // for WideCharToMultiByte / MultiByteToWideChar #include +#endif namespace utf8 { diff --git a/src/libs/util/testsuite/probability_table.cpp b/src/libs/util/testsuite/probability_table.cpp new file mode 100644 index 000000000..cc5daa7c4 --- /dev/null +++ b/src/libs/util/testsuite/probability_table.cpp @@ -0,0 +1,128 @@ +#include "probability_table.hpp" + +#include + +using namespace storm; + +TEST_CASE("EpsilonLessThan", "[utils]") +{ + using Compare = EpsilonLessThan; + + constexpr auto eps = std::numeric_limits::epsilon(); + + SECTION("Less") + { + CHECK(Compare{}(0.0f, 1.0f)); + CHECK(Compare{}(1.0f - 2 * eps, 1.0f)); + CHECK(Compare{}(-1.0f, 0.0f)); + } + + SECTION("EqualOrGreater") + { + CHECK_FALSE(Compare{}(1.0f, 1.0f)); + CHECK_FALSE(Compare{}(1.5f, 1.0f)); + CHECK_FALSE(Compare{}(1.0f + eps, 1.0f)); + } +} + +template class RandProviderMock +{ + public: + T operator()(T max) + { + if (ret_max_) + { + return max; + } + return ret_; + } + + static void ret(T val) + { + ret_ = val; + } + + static void ret_max(bool val) + { + ret_max_ = val; + } + + private: + static inline bool ret_max_{false}; + static inline T ret_{}; +}; + +TEST_CASE("ProbabilityTable", "[utils]") +{ + using ProviderMock = RandProviderMock; + + ProbabilityTable table_; + table_.emplace(1.0f, 0); // 1.0 + table_.emplace(1.0f, 1); // 2.0 + table_.emplace(0.8f, 2); // 2.8 + table_.emplace(0.7f, 3); // 3.5 + table_.emplace(0.5f, 4); // 4.0 + + SECTION("0") + { + ProviderMock::ret_max(false); + ProviderMock::ret(0.0f); + CHECK(table_.pickRandom() == 0); + ProviderMock::ret(0.5f); + CHECK(table_.pickRandom() == 0); + ProviderMock::ret(0.99f); + CHECK(table_.pickRandom() == 0); + } + + SECTION("1") + { + ProviderMock::ret_max(false); + ProviderMock::ret(1.0f); + CHECK(table_.pickRandom() == 1); + ProviderMock::ret(1.5f); + CHECK(table_.pickRandom() == 1); + ProviderMock::ret(1.99f); + CHECK(table_.pickRandom() == 1); + } + + SECTION("2") + { + ProviderMock::ret_max(false); + ProviderMock::ret(2.0f); + CHECK(table_.pickRandom() == 2); + ProviderMock::ret(2.5f); + CHECK(table_.pickRandom() == 2); + ProviderMock::ret(2.79f); + CHECK(table_.pickRandom() == 2); + } + + SECTION("3") + { + ProviderMock::ret_max(false); + ProviderMock::ret(2.88f); + CHECK(table_.pickRandom() == 3); + ProviderMock::ret(3.0f); + CHECK(table_.pickRandom() == 3); + ProviderMock::ret(3.49f); + CHECK(table_.pickRandom() == 3); + } + + SECTION("4") + { + ProviderMock::ret_max(false); + ProviderMock::ret(3.5f); + CHECK(table_.pickRandom() == 4); + ProviderMock::ret(3.9f); + CHECK(table_.pickRandom() == 4); + ProviderMock::ret_max(true); + CHECK(table_.pickRandom() == 4); + } + + SECTION("5") + { + auto extended = table_; + extended.emplace(10000000.0f, 5); + ProviderMock::ret_max(true); + CHECK(extended.pickRandom() == 5); + } +} diff --git a/src/libs/weather/src/lightning.cpp b/src/libs/weather/src/lightning.cpp index 0c79c41f9..25ee3ff86 100644 --- a/src/libs/weather/src/lightning.cpp +++ b/src/libs/weather/src/lightning.cpp @@ -6,6 +6,7 @@ LIGHTNING::LIGHTNING() { iLightningTexture = -1; iFlashTexture = -1; + bLightningEnable = false; } LIGHTNING::~LIGHTNING() @@ -79,7 +80,7 @@ void LIGHTNING::Realize(uint32_t Delta_Time) uint32_t i; RS_RECT rs_rect; - if (iLightningTexture >= 0) + if (iLightningTexture >= 0 && bLightningEnable) { pRS->TextureSet(0, iLightningTexture); for (i = 0; i < aLightnings.size(); i++) @@ -97,7 +98,7 @@ void LIGHTNING::Realize(uint32_t Delta_Time) } } - if (iFlashTexture >= 0) + if (iFlashTexture >= 0 && bLightningEnable) { pRS->TextureSet(0, iFlashTexture); for (i = 0; i < aLightnings.size(); i++) @@ -198,6 +199,13 @@ uint32_t LIGHTNING::AttributeChanged(ATTRIBUTES *pAttribute) return 0; } + if (*pAttribute == "Enable") + { + bLightningEnable = pAttribute->GetAttributeAsDword() != 0; + core.Trace("bLightningEnable = %d", bLightningEnable); + return 0; + } + if (*pAttribute == "Texture") { if (iLightningTexture >= 0) diff --git a/src/libs/weather/src/lightning.h b/src/libs/weather/src/lightning.h index cc560f490..8407452ad 100644 --- a/src/libs/weather/src/lightning.h +++ b/src/libs/weather/src/lightning.h @@ -35,6 +35,7 @@ class LIGHTNING : public Entity std::vector aLightnings; + bool bLightningEnable; uint32_t dwSubTexX, dwSubTexY; int32_t iLightningTexture, iFlashTexture; diff --git a/src/libs/weather/src/planets.cpp b/src/libs/weather/src/planets.cpp index 5827f83cd..f0d97c158 100644 --- a/src/libs/weather/src/planets.cpp +++ b/src/libs/weather/src/planets.cpp @@ -47,7 +47,7 @@ void Astronomy::PLANETS::Init(ATTRIBUTES *pAP) auto *pAPlanet = pAPlanets->GetAttributeClass(i); auto *pAMag = pAPlanet->GetAttributeClass("Mag"); - const auto sName = std::string(pAPlanet->GetThisName()); + std::string sName = pAPlanet->GetThisName(); aPlanets.push_back(Planet{}); // Planet & p = aPlanets[aPlanets.Add()]; diff --git a/src/libs/weather/src/sky.cpp b/src/libs/weather/src/sky.cpp index 71b486760..e2bf9ff53 100644 --- a/src/libs/weather/src/sky.cpp +++ b/src/libs/weather/src/sky.cpp @@ -519,10 +519,10 @@ void SKY::FillSkyDirArray(ATTRIBUTES *pAttribute) { for (int32_t n = 0; n < q; n++) { - const auto attrName = std::string(pAttribute->GetAttributeName(n)); - if (attrName.length() >= 2 && attrName[0] == 'd' && attrName[1] >= '0' && attrName[1] <= '9') + const auto *const attrName = pAttribute->GetAttributeName(n); + if (attrName && attrName[0] == 'd' && attrName[1] >= '0' && attrName[1] <= '9') { - const auto i = atol(attrName.c_str() + 1); + const auto i = atol(&attrName[1]); if (i < q) aSkyDirArray[i] = to_string(pAttribute->GetAttribute(n)); } diff --git a/src/libs/weather/src/stars.cpp b/src/libs/weather/src/stars.cpp index 2acfda97a..8e43ace8b 100644 --- a/src/libs/weather/src/stars.cpp +++ b/src/libs/weather/src/stars.cpp @@ -279,7 +279,7 @@ void Astronomy::STARS::Realize(double dDeltaTime, double dHour) auto fMaxMag = Bring2Range(fTelescopeMagnitude, fVisualMagnitude, 0.14f, 1.285f, fFov); - if (fabsf(fFov - fPrevFov) > 1e-5f) +// if (fabsf(fFov - fPrevFov) > 1e-5f) { float fTmpK[5]; float fTmpRnd[7]; diff --git a/src/libs/weather/src/sun_glow.cpp b/src/libs/weather/src/sun_glow.cpp index 4746c5220..6b830ef30 100644 --- a/src/libs/weather/src/sun_glow.cpp +++ b/src/libs/weather/src/sun_glow.cpp @@ -306,7 +306,8 @@ void SUNGLOW::Realize(uint32_t Delta_Time) // RS_RECT * pRSR = &aRSR[aRSR.Add()]; RS_RECT rect; rect.dwColor = makeRGB(r, g, b); - rect.fAngle = 0.0f; + rect.fAngle = fAngle; + //rect.fAngle = 0.0f; rect.dwSubTexture = pF->dwSubTexIndex; rect.fSize = pF->fSize * Flares.fFlareScale; rect.vPos = vSun + vDelta * (1.0f - pF->fDist); diff --git a/src/libs/worldmap/src/wdm_enemy_ship.cpp b/src/libs/worldmap/src/wdm_enemy_ship.cpp index 0e9a22d69..75ca521f7 100644 --- a/src/libs/worldmap/src/wdm_enemy_ship.cpp +++ b/src/libs/worldmap/src/wdm_enemy_ship.cpp @@ -108,13 +108,13 @@ void WdmEnemyShip::Update(float dltTime) slowingAlfa = deleteAlpha; if (deleteAlpha < 0.0f) { - std::string delEnc = ""; + const auto *delEnc = ""; if (saveAttribute) { delEnc = saveAttribute->GetThisName(); } VDATA *pVDat = nullptr; - if (!killMe && delEnc.length() >= 1 && delEnc[0]) + if (!killMe && delEnc && delEnc[0]) { pVDat = core.Event("WorldMap_EncounterDelete", "s", delEnc); } @@ -416,7 +416,7 @@ void WdmEnemyShip::SetLiveTime(float time) } // Get attribute name -std::string_view WdmEnemyShip::GetAttributeName() const +const char *WdmEnemyShip::GetAttributeName() const { if (saveAttribute) { diff --git a/src/libs/worldmap/src/wdm_enemy_ship.h b/src/libs/worldmap/src/wdm_enemy_ship.h index b55a93bbe..7967c8ab5 100644 --- a/src/libs/worldmap/src/wdm_enemy_ship.h +++ b/src/libs/worldmap/src/wdm_enemy_ship.h @@ -48,7 +48,7 @@ class WdmEnemyShip : public WdmShip bool canSkip; // Get attribute name - std::string_view GetAttributeName() const; + const char *GetAttributeName() const; protected: // Find the pulling force in the desired direction diff --git a/src/libs/worldmap/src/wdm_islands.cpp b/src/libs/worldmap/src/wdm_islands.cpp index cd6c9c85d..6ea542ab3 100644 --- a/src/libs/worldmap/src/wdm_islands.cpp +++ b/src/libs/worldmap/src/wdm_islands.cpp @@ -382,8 +382,7 @@ void WdmIslands::SetIslandsData(ATTRIBUTES *apnt, bool isChange) // Check for sufficiency if (!id || !text || !locator || !locator[0]) { - const std::string message = fmt::format("World map: label \"{}\" will be skipping...", apnt->GetAttributeName(i)); - core.Trace(message.c_str()); + core.Trace("World map: label \"%s\" will be skipping...", apnt->GetAttributeName(i)); continue; } // looking for a label among existing @@ -393,9 +392,8 @@ void WdmIslands::SetIslandsData(ATTRIBUTES *apnt, bool isChange) { if (!LabelsFindLocator(locator, pos)) { - - const std::string message = fmt::format("World map: locator \"{}\" in label \"{}\" not found...", locator, apnt->GetAttributeName(i)); - core.Trace(message.c_str()); + core.Trace("World map: locator \"%s\" in label \"%s\" not found...", locator, + apnt->GetAttributeName(i)); continue; } // Adding a new label @@ -464,6 +462,12 @@ void WdmIslands::SetIslandsData(ATTRIBUTES *apnt, bool isChange) labels[index].textX = 0.0f; labels[index].textY = 0.0f; } + + // Store locator position as label attribute + auto* position_attr = a->VerifyAttributeClass("position"); + position_attr->SetAttributeUseFloat("x", pos.x); + position_attr->SetAttributeUseFloat("y", pos.y); + position_attr->SetAttributeUseFloat("z", pos.z); } } diff --git a/src/libs/worldmap/src/wdm_objects.cpp b/src/libs/worldmap/src/wdm_objects.cpp index 29180184c..f5a1b6a15 100644 --- a/src/libs/worldmap/src/wdm_objects.cpp +++ b/src/libs/worldmap/src/wdm_objects.cpp @@ -39,6 +39,7 @@ WdmObjects::WdmObjects() islands = nullptr; playerShip = nullptr; isDebug = false; + showWindUI = true; Clear(); enemyShip = nullptr; enableSkipEnemy = false; diff --git a/src/libs/worldmap/src/wdm_objects.h b/src/libs/worldmap/src/wdm_objects.h index 312098374..dcd7bd566 100644 --- a/src/libs/worldmap/src/wdm_objects.h +++ b/src/libs/worldmap/src/wdm_objects.h @@ -99,6 +99,7 @@ class WdmObjects bool isPause; bool isDebug; + bool showWindUI; void DrawCircle(const CVECTOR &pos, float radius, uint32_t color) const; void DrawCircle(CMatrix &mtx, float radius, uint32_t color) const; diff --git a/src/libs/worldmap/src/wdm_player_ship.cpp b/src/libs/worldmap/src/wdm_player_ship.cpp index 8992a9501..980d61c86 100644 --- a/src/libs/worldmap/src/wdm_player_ship.cpp +++ b/src/libs/worldmap/src/wdm_player_ship.cpp @@ -13,6 +13,7 @@ #include "core.h" #include "math_inlines.h" +#include "shared/events.h" #include "wdm_enemy_ship.h" #include "wdm_islands.h" #include "wdm_storm.h" @@ -208,19 +209,19 @@ void WdmPlayerShip::Update(float dltTime) switch (wdmObjects->enemyShip->shipType) { case wdmest_unknow: - wdmObjects->wm->AttributesPointer->SetAttributeUseDword("encounter_type", 0); + wdmObjects->wm->AttributesPointer->SetAttributeUseDword("encounter_type", WORLDMAP_ENCOUNTER_TYPE_UNKNOWN); break; case wdmest_merchant: - wdmObjects->wm->AttributesPointer->SetAttributeUseDword("encounter_type", 1); + wdmObjects->wm->AttributesPointer->SetAttributeUseDword("encounter_type", WORLDMAP_ENCOUNTER_TYPE_MERCHANT); break; case wdmest_warring: - wdmObjects->wm->AttributesPointer->SetAttributeUseDword("encounter_type", 2); + wdmObjects->wm->AttributesPointer->SetAttributeUseDword("encounter_type", WORLDMAP_ENCOUNTER_TYPE_WARRING); break; case wdmest_follow: - wdmObjects->wm->AttributesPointer->SetAttributeUseDword("encounter_type", 3); + wdmObjects->wm->AttributesPointer->SetAttributeUseDword("encounter_type", WORLDMAP_ENCOUNTER_TYPE_FOLLOW); break; default: - wdmObjects->wm->AttributesPointer->SetAttributeUseDword("encounter_type", -1); + wdmObjects->wm->AttributesPointer->SetAttributeUseDword("encounter_type", WORLDMAP_ENCOUNTER_TYPE_INVALID); } } else @@ -228,11 +229,11 @@ void WdmPlayerShip::Update(float dltTime) // mark hitting the storm if (wdmObjects->playarInStorm) { - wdmObjects->wm->AttributesPointer->SetAttributeUseDword("encounter_type", 4); + wdmObjects->wm->AttributesPointer->SetAttributeUseDword("encounter_type", WORLDMAP_ENCOUNTER_TYPE_STORM); } else { - wdmObjects->wm->AttributesPointer->SetAttributeUseDword("encounter_type", -1); + wdmObjects->wm->AttributesPointer->SetAttributeUseDword("encounter_type", WORLDMAP_ENCOUNTER_TYPE_INVALID); } } if (nOldIslandVal != wdmObjects->wm->AttributesPointer->GetAttributeAsDword("encounter_island", 0) || diff --git a/src/libs/worldmap/src/wdm_storm.cpp b/src/libs/worldmap/src/wdm_storm.cpp index ac2acb7f5..9f16f17da 100644 --- a/src/libs/worldmap/src/wdm_storm.cpp +++ b/src/libs/worldmap/src/wdm_storm.cpp @@ -379,7 +379,7 @@ void WdmStorm::UpdateSaveData() saveAttribute->SetAttribute("year", wdmObjects->attrYear); } -std::string_view WdmStorm::GetId() const +const char *WdmStorm::GetId() const { if (saveAttribute) { diff --git a/src/libs/worldmap/src/wdm_storm.h b/src/libs/worldmap/src/wdm_storm.h index e88a5f975..d2559d648 100644 --- a/src/libs/worldmap/src/wdm_storm.h +++ b/src/libs/worldmap/src/wdm_storm.h @@ -35,7 +35,7 @@ class WdmStorm : public WdmRenderObject void Update(float dltTime) override; void LRender(VDX9RENDER *rs) override; - std::string_view GetId() const; + const char *GetId() const; public: // Setting parameters diff --git a/src/libs/worldmap/src/wdm_wind_ui.cpp b/src/libs/worldmap/src/wdm_wind_ui.cpp index 9cd0a58e4..3d99d8f1e 100644 --- a/src/libs/worldmap/src/wdm_wind_ui.cpp +++ b/src/libs/worldmap/src/wdm_wind_ui.cpp @@ -352,6 +352,9 @@ void WdmWindUI::SetAttributes(ATTRIBUTES *apnt) // Rendering void WdmWindUI::LRender(VDX9RENDER *rs) { + if (!wdmObjects->showWindUI) + return; + if (wdmObjects->isNextDayUpdate) { auto *data = core.Event("WorldMap_GetMoral"); diff --git a/src/libs/worldmap/src/wdm_wind_ui.h b/src/libs/worldmap/src/wdm_wind_ui.h index 8ff846b30..4678a6f1b 100644 --- a/src/libs/worldmap/src/wdm_wind_ui.h +++ b/src/libs/worldmap/src/wdm_wind_ui.h @@ -11,7 +11,7 @@ #pragma once #include "wdm_interface_object.h" -#include "utils.h" +#include "bi_utils.h" #include diff --git a/src/libs/worldmap/src/world_map.cpp b/src/libs/worldmap/src/world_map.cpp index 7694a98d3..1becc87fc 100644 --- a/src/libs/worldmap/src/world_map.cpp +++ b/src/libs/worldmap/src/world_map.cpp @@ -604,6 +604,9 @@ uint64_t WorldMap::ProcessMessage(MESSAGE &message) case MSG_WORLDMAP_SET_COORDINATES: wdmObjects->coordinate = message.String(); break; + case MSG_WORLDMAP_WIND_UI_SET_SHOW: + wdmObjects->showWindUI = (message.Long() != 0); + break; } return 0; } @@ -683,7 +686,7 @@ uint32_t WorldMap::AttributeChanged(ATTRIBUTES *apnt) sprintf_s(buf, "%i", es->type); pa->SetAttribute("type", buf); pa->SetAttributeUseDword("select", es->isSelect); - pa->SetAttribute("id", static_cast(wdmObjects->ships[i])->GetAttributeName()); + pa->SetAttribute("id", (char *)static_cast(wdmObjects->ships[i])->GetAttributeName()); // If there is an attacker, get his index if (es->attack) { diff --git a/src/libs/xinterface/src/editor/editor_defines.cpp b/src/libs/xinterface/src/editor/editor_defines.cpp index 363e25768..02c5e5840 100644 --- a/src/libs/xinterface/src/editor/editor_defines.cpp +++ b/src/libs/xinterface/src/editor/editor_defines.cpp @@ -1,5 +1,7 @@ #include "editor_defines.h" +#include + void GIEditorObject::LinkEvent(GIEditorEventHandler *pEventHandler, const GIEditorEvent &pEventFunction) { pEventHandler->AddEventFunction(this, pEventFunction); diff --git a/src/libs/xinterface/src/info_handler.cpp b/src/libs/xinterface/src/info_handler.cpp index ef7b6434e..4e0597cce 100644 --- a/src/libs/xinterface/src/info_handler.cpp +++ b/src/libs/xinterface/src/info_handler.cpp @@ -4,6 +4,9 @@ #include "vma.hpp" +int32_t InfoHandler::numberOfTips = 0; +int32_t InfoHandler::currentTips = -1; + InfoHandler::InfoHandler() : m_rs(nullptr), tex(nullptr) { } @@ -140,6 +143,7 @@ bool InfoHandler::DoPreOut() const char *picTexureFile = AttributesPointer->GetAttribute("picfilename"); const char *picBackTexureFile = AttributesPointer->GetAttribute("picbackfilename"); + bool isTips = AttributesPointer ? AttributesPointer->GetAttributeAsDword("tips", 0) : 0; const uint32_t TMP_VERTEX_FORMAT = (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1 | D3DFVF_TEXTUREFORMAT2); struct TMP_VERTEX { @@ -228,8 +232,9 @@ bool InfoHandler::DoPreOut() pV[2].tv = 0.f; pV[3].tu = 1.f; pV[3].tv = 1.f; + m_rs->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, TMP_VERTEX_FORMAT, 2, &pV, sizeof(TMP_VERTEX), - "iInfoShowerPic"); + "Fader"); m_rs->TextureRelease(picBackID); m_rs->SetProgressBackImage(picBackTexureFile); } @@ -247,7 +252,7 @@ bool InfoHandler::DoPreOut() dx = 0.0f; else { - dy = 25.0f; + dy = float(desc.Height) * 0.025f; dx = ((float(desc.Width) - (4.0f * (float(desc.Height) - 2.0f * dy) / 3.0f)) / 2.0f); } @@ -269,21 +274,82 @@ bool InfoHandler::DoPreOut() pV[3].tu = 1.f; pV[3].tv = 1.f; - char _name[MAX_PATH]; - sprintf(_name, "interfaces\\int_border.tga"); - int tipsID = m_rs->TextureCreate(_name); - if (tipsID) - { - m_rs->SetTipsImage(_name); - m_rs->TextureSet(1, tipsID); - } - m_rs->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, TMP_VERTEX_FORMAT, 2, &pV, sizeof(TMP_VERTEX), - "iInfoShowerPicWithTips"); + "Fader"); + m_rs->TextureRelease(picID); m_rs->SetProgressImage(picTexureFile); } } + + if (isTips) + { + // read the number of tips, if necessary + if (!numberOfTips) + { + auto ini = fio->OpenIniFile(core.EngineIniFileName()); + if (ini) + { + numberOfTips = ini->GetInt(nullptr, "numoftips", -1); + } + else + numberOfTips = -1; + if (numberOfTips > 9999) + numberOfTips = 9999; + } + + if (numberOfTips > 0) + { + char tipsTexureFile[MAX_PATH]; + sprintf_s(tipsTexureFile, "tips\\tips_%.4u.tga", rand() % numberOfTips); + const int tipsID = m_rs->TextureCreate(tipsTexureFile); + + if (tipsID >= 0) + { + m_rs->TextureSet(0, tipsID); + + float dy = 0.0f; + float dx = 0.0f; + float dxx = 0.0f; + + if (((float)desc.Width - (4.0f * (float)desc.Height / 3.0f)) / 2.0f >= 10.0f) + { + dy = 0.025f * (float)desc.Height; + dx = ((float)desc.Width - (4.0f * ((float)desc.Height - 2.0f * dy) / 3.0f)) / 2.0f; + } + dxx = ((float)desc.Width - 2.0 * dx) * 0.125f; + + pV[0].col = pV[1].col = pV[2].col = pV[3].col = 0xFFFFFFFF; + + pV[0].pos.x = 0.0f + dx + dxx; + pV[0].pos.y = 0.0f + 0.787f * (float)desc.Height; + + pV[1].pos.x = (float)desc.Width - dx - dxx; + pV[1].pos.y = 0.0f + 0.787f * (float)desc.Height; + + pV[2].pos.x = 0.0f + dx + dxx; + pV[2].pos.y = (float)desc.Height - 0.094f * (float)desc.Height; + + pV[3].pos.x = (float)desc.Width - dx - dxx; + pV[3].pos.y = (float)desc.Height - 0.094f * (float)desc.Height; + + pV[0].tu = 0.f; + pV[0].tv = 0.f; + pV[1].tu = 1.f; + pV[1].tv = 0.f; + pV[2].tu = 0.f; + pV[2].tv = 1.f; + pV[3].tu = 1.f; + pV[3].tv = 1.f; + + m_rs->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, TMP_VERTEX_FORMAT, 2, &pV, sizeof(TMP_VERTEX), + "Fader"); + m_rs->TextureRelease(tipsID); + m_rs->SetTipsImage(tipsTexureFile); + } + } + + } if (inStrStart) { diff --git a/src/libs/xinterface/src/info_handler.h b/src/libs/xinterface/src/info_handler.h index cace4edff..e0699c756 100644 --- a/src/libs/xinterface/src/info_handler.h +++ b/src/libs/xinterface/src/info_handler.h @@ -13,6 +13,9 @@ class InfoHandler : public Entity void Execute(uint32_t delta_time); void Realize(uint32_t delta_time) const; uint64_t ProcessMessage(MESSAGE &message) override; + + static int32_t numberOfTips; + static int32_t currentTips; void ProcessStage(Stage stage, uint32_t delta) override { diff --git a/src/libs/xinterface/src/nodes/xi_quest_texts.cpp b/src/libs/xinterface/src/nodes/xi_quest_texts.cpp index 65bf61629..1fa9ab192 100644 --- a/src/libs/xinterface/src/nodes/xi_quest_texts.cpp +++ b/src/libs/xinterface/src/nodes/xi_quest_texts.cpp @@ -343,6 +343,9 @@ void CXI_QUESTTEXTS::StartQuestShow(ATTRIBUTES *pA, int qn) const auto cFlag = pAttr->GetAttributeAsDword("Complete", 0) != 0; auto *pATextList = pAttr->GetAttributeClass("Text"); + const char *questLogName = pAttr->GetAttribute("LogName"); + if (!questLogName) + questLogName = pAttr->GetThisName(); std::vector asStringList; if (ptrOwner->QuestFileReader() && pATextList) @@ -436,6 +439,15 @@ uint32_t CXI_QUESTTEXTS::MessageProc(int32_t msgcode, MESSAGE &message) return 0; } break; + + case 2: // set the font id + { + FONT_RELEASE(m_rs, m_idFont); + const std::string &fontName = message.String(); + m_idFont = m_rs->LoadFont(fontName.c_str()); + return 0; + } + break; } return -1; } diff --git a/src/libs/xinterface/src/nodes/xi_quest_titles.cpp b/src/libs/xinterface/src/nodes/xi_quest_titles.cpp index a6a5af902..f0685e8d5 100644 --- a/src/libs/xinterface/src/nodes/xi_quest_titles.cpp +++ b/src/libs/xinterface/src/nodes/xi_quest_titles.cpp @@ -367,10 +367,10 @@ void CXI_QUESTTITLE::SetNewTopQuest(ATTRIBUTES *pA, int topNum) } m_strList[i].dwSpecColor = pAttr->GetAttributeAsDword("color", 0); m_strList[i].complete = pAttr->GetAttributeAsDword("Complete", 0) != 0; - const char *pTmpQuestRecordID = pAttr->GetAttribute("LogName"); - std::string_view quest_record_id = pTmpQuestRecordID ? pTmpQuestRecordID : pAttr->GetThisName(); - if (ptrOwner->QuestFileReader()->GetQuestTitle(quest_record_id, pAttr->GetThisName(), param)) + if (!pTmpQuestRecordID) + pTmpQuestRecordID = pAttr->GetThisName(); + if (ptrOwner->QuestFileReader()->GetQuestTitle(pTmpQuestRecordID, pAttr->GetThisName(), param)) { const size_t titleSize = param.size(); if (titleSize == 0) @@ -412,6 +412,19 @@ void CXI_QUESTTITLE::ScrollerChanged(float fPos) { } +uint32_t CXI_QUESTTITLE::MessageProc(int32_t msgcode, MESSAGE &message) +{ + switch (msgcode) + { + case 0: + FONT_RELEASE(m_rs, m_idFont); + const std::string &fontName = message.String(); + m_idFont = m_rs->LoadFont(fontName.c_str()); + return 0; + } + return -1; +} + void CXI_QUESTTITLE::MouseThis(float fX, float fY) { const float left = static_cast(m_rect.left) - m_selectOffset; diff --git a/src/libs/xinterface/src/nodes/xi_quest_titles.h b/src/libs/xinterface/src/nodes/xi_quest_titles.h index 1fcd88799..61551fc2b 100644 --- a/src/libs/xinterface/src/nodes/xi_quest_titles.h +++ b/src/libs/xinterface/src/nodes/xi_quest_titles.h @@ -21,6 +21,7 @@ class CXI_QUESTTITLE : public CINODE void SaveParametersToIni() override; void SetNewTopQuest(ATTRIBUTES *pA, int topNum); + uint32_t MessageProc(int32_t msgcode, MESSAGE &message) override; float GetLineStep() const; void ScrollerChanged(float fPos); diff --git a/src/libs/xinterface/src/nodes/xi_table.cpp b/src/libs/xinterface/src/nodes/xi_table.cpp index 06b6c05d7..6c0ac9649 100644 --- a/src/libs/xinterface/src/nodes/xi_table.cpp +++ b/src/libs/xinterface/src/nodes/xi_table.cpp @@ -723,6 +723,9 @@ uint32_t CXI_TABLE::MessageProc(int32_t msgcode, MESSAGE &message) case 1: // get the line number on which the mouse pointer is located (-1 - the pointer is out of bounds) return GetLineByPoint(ptrOwner->GetMousePoint()); break; + case 2: + SelectLine(message.Long()); + break; } return 0; diff --git a/src/libs/xinterface/src/nodes/xi_text_button.cpp b/src/libs/xinterface/src/nodes/xi_text_button.cpp index 1fd52832d..52192cf6a 100644 --- a/src/libs/xinterface/src/nodes/xi_text_button.cpp +++ b/src/libs/xinterface/src/nodes/xi_text_button.cpp @@ -584,7 +584,6 @@ bool CXI_TEXTBUTTON::IsClick(int buttonID, int32_t xPos, int32_t yPos) void CXI_TEXTBUTTON::ChangePosition(XYRECT &rNewPos) { m_rect = rNewPos; - GetAbsoluteRect(m_rect, m_nAbsoluteRectVal); FillPositionIntoVertices(); } diff --git a/src/libs/xinterface/src/scr_shoter/scr_shoter.cpp b/src/libs/xinterface/src/scr_shoter/scr_shoter.cpp index 53471f70a..5ce0c02c0 100644 --- a/src/libs/xinterface/src/scr_shoter/scr_shoter.cpp +++ b/src/libs/xinterface/src/scr_shoter/scr_shoter.cpp @@ -4,8 +4,8 @@ #include "core.h" #include "string_compare.hpp" -#define SS_TEXTURE_WIDTH 128 -#define SS_TEXTURE_HEIGHT 128 +#define SS_TEXTURE_WIDTH 256 +#define SS_TEXTURE_HEIGHT 256 #define SS_TEXTURE_FONECOLOR 0xFF000000 uint32_t GetA8R8G8B8_FromFMT(void *p, uint32_t fmt) @@ -122,8 +122,7 @@ bool SCRSHOTER::MakeScreenShot() // create a new screen shot if (hr == D3D_OK) { - textureIndex_ = - rs->TextureCreate(SS_TEXTURE_WIDTH, SS_TEXTURE_HEIGHT, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED); + textureIndex_ = rs->TextureCreate(SS_TEXTURE_WIDTH, SS_TEXTURE_HEIGHT, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED); texture_ = static_cast(rs->GetTextureFromID(textureIndex_)); } @@ -168,9 +167,9 @@ bool SCRSHOTER::MakeScreenShot() pRenderTarg->Release(); // Add a texture with a frame to the shot - const int nTextureID = rs->TextureCreate("interfaces\\EmptyBorder.tga"); - if (nTextureID >= 0) - { + //const int nTextureID = core.GetTargetEngineVersion() >= storm::ENGINE_VERSION::TO_EACH_HIS_OWN ? -1 : rs->TextureCreate("interfaces\\EmptyBorder.tga"); + const int nTextureID = -1; + IDirect3DTexture9 *pScrShotTex = nullptr; if (D3D_OK == rs->CreateTexture(SS_TEXTURE_WIDTH, SS_TEXTURE_HEIGHT, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &pScrShotTex)) @@ -208,9 +207,12 @@ bool SCRSHOTER::MakeScreenShot() rs->TextureSet(0, textureIndex_); rs->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, BI_SCRSHOTER_VERTEX_FORMAT, 2, vert, sizeof(BI_SCRSHOTER_VERTEX), "battle_icons"); + if (nTextureID >= 0) + { rs->TextureSet(0, nTextureID); rs->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, BI_SCRSHOTER_VERTEX_FORMAT, 2, vert, sizeof(BI_SCRSHOTER_VERTEX), "battle_icons"); + } rs->SetRenderTarget(pOldRenderTarg, pStencil); } if (pRenderTarg) @@ -232,8 +234,7 @@ bool SCRSHOTER::MakeScreenShot() rs->Release(pScrShotTex); } - rs->TextureRelease(nTextureID); - } + if (nTextureID >= 0) rs->TextureRelease(nTextureID); return hr == D3D_OK; } diff --git a/src/libs/xinterface/src/storm/xinterface/options_parser.cpp b/src/libs/xinterface/src/storm/xinterface/options_parser.cpp index b59c9a635..1829eeaf8 100644 --- a/src/libs/xinterface/src/storm/xinterface/options_parser.cpp +++ b/src/libs/xinterface/src/storm/xinterface/options_parser.cpp @@ -1,5 +1,7 @@ #include "options_parser.hpp" +#include + namespace storm { diff --git a/src/libs/xinterface/src/string_service.h b/src/libs/xinterface/src/string_service.h index 11d46b4ac..871119545 100644 --- a/src/libs/xinterface/src/string_service.h +++ b/src/libs/xinterface/src/string_service.h @@ -15,7 +15,7 @@ class VSTRSERVICE : public SERVICE virtual void SetLanguage(const char *sLanguage) = 0; virtual char *GetLanguage() = 0; - virtual char *GetString(const char *stringName, char *sBuffer = nullptr, size_t bufferSize = 0) = 0; + virtual char *GetString(const char *stringName, char *sBuffer = nullptr, std::size_t bufferSize = 0) = 0; virtual int32_t GetStringNum(const char *stringName) = 0; virtual char *GetString(int32_t strNum) = 0; virtual char *GetStringName(int32_t strNum) = 0; diff --git a/src/libs/xinterface/src/string_service/str_service.h b/src/libs/xinterface/src/string_service/str_service.h index eb1f9b66a..479adb990 100644 --- a/src/libs/xinterface/src/string_service/str_service.h +++ b/src/libs/xinterface/src/string_service/str_service.h @@ -33,7 +33,7 @@ class STRSERVICE : public VSTRSERVICE void SetLanguage(const char *sLanguage) override; char *GetLanguage() override; - char *GetString(const char *stringName, char *sBuffer = nullptr, size_t bufferSize = 0) override; + char *GetString(const char *stringName, char *sBuffer = nullptr, std::size_t bufferSize = 0) override; int32_t GetStringNum(const char *stringName) override; char *GetString(int32_t strNum) override; char *GetStringName(int32_t strNum) override; diff --git a/src/libs/xinterface/src/xinterface.cpp b/src/libs/xinterface/src/xinterface.cpp index 538de7169..9b82018fd 100644 --- a/src/libs/xinterface/src/xinterface.cpp +++ b/src/libs/xinterface/src/xinterface.cpp @@ -1063,27 +1063,24 @@ void XINTERFACE::LoadIni() // GUARD(XINTERFACE::LoadIni()); char section[256]; - auto platform = "PC_SCREEN"; auto ini = fio->OpenIniFile(RESOURCE_FILENAME); if (!ini) throw std::runtime_error("ini file not found!"); + int sdlScreenWidth, sdlScreenHeight; #ifdef _WIN32 // FIX_LINUX GetWindowRect RECT Screen_Rect; GetWindowRect(static_cast(core.GetWindow()->OSHandle()), &Screen_Rect); + sdlScreenWidth = Screen_Rect.right - Screen_Rect.left; + sdlScreenHeight = Screen_Rect.bottom - Screen_Rect.top; #else - int sdlScreenWidth, sdlScreenHeight; SDL_GetWindowSize(reinterpret_cast(core.GetWindow()->OSHandle()), &sdlScreenWidth, &sdlScreenHeight); #endif fScale = 1.0f; const auto screenSize = core.GetScreenSize(); dwScreenHeight = screenSize.height; -#ifdef _WIN32 // FIX_LINUX GetWindowRect - dwScreenWidth = (Screen_Rect.right - Screen_Rect.left) * dwScreenHeight / (Screen_Rect.bottom - Screen_Rect.top); -#else dwScreenWidth = sdlScreenWidth * dwScreenHeight / sdlScreenHeight; -#endif if (dwScreenWidth < screenSize.width) dwScreenWidth = screenSize.width; GlobalScreenRect.top = 0; @@ -1091,6 +1088,32 @@ void XINTERFACE::LoadIni() GlobalScreenRect.left = (dwScreenWidth - screenSize.width) / 2; GlobalScreenRect.right = screenSize.width + GlobalScreenRect.left; + char platform[23]; + bool sectionFound = false; + if (ini->GetSectionName(platform, sizeof(platform) - 1)) + { + float windowRatio = (float)sdlScreenWidth / (float)sdlScreenHeight; + float iniRatio; + char splitPlatform[23], *platformW, *platformH; + do + { + if(starts_with(platform, "PC_SCREEN_")) + { + strcpy_s(splitPlatform, platform); + platformW = std::strtok(splitPlatform, "_:"); // PC + platformW = std::strtok(nullptr, "_:"); // SCREEN + platformW = std::strtok(nullptr, "_:"); // Width + platformH = std::strtok(nullptr, "_:"); // Height + iniRatio = (float)atoi(platformW) / (float)atoi(platformH); + // +- 3% + if (iniRatio*0.97 <= windowRatio && windowRatio <= iniRatio*1.03) + sectionFound = true; + } + } while (!sectionFound && ini->GetSectionNameNext(platform, sizeof(platform) - 1)); + } + if (!sectionFound) + strcpy_s(platform, "PC_SCREEN"); + core.Trace("Using %s parameters", platform); sprintf_s(section, "COMMON"); // set screen parameters @@ -1596,8 +1619,10 @@ void XINTERFACE::SetTooltip(const char *pcHeader, const char *pcText1, uint32_t CXI_BORDER *pNodFrame = pTmpNod ? pTmpNod->m_nNodeType == NODETYPE_BORDER ? static_cast(pTmpNod) : nullptr : nullptr; pTmpNod = FindNode("tooltip_titlerect", nullptr); - CXI_RECTANGLE *pNodTitleRect = - pTmpNod ? pTmpNod->m_nNodeType == NODETYPE_RECTANGLE ? static_cast(pTmpNod) : nullptr +// CXI_RECTANGLE *pNodTitleRect = + CXI_VIDEO *pNodTitleRect = +// pTmpNod ? pTmpNod->m_nNodeType == NODETYPE_RECTANGLE ? static_cast(pTmpNod) : nullptr + pTmpNod ? pTmpNod->m_nNodeType == NODETYPE_VIDEO ? static_cast(pTmpNod) : nullptr : nullptr; pTmpNod = FindNode("tooltip_picture", nullptr); CXI_PICTURE *pNodPic = @@ -2609,10 +2634,12 @@ uint32_t XINTERFACE::AttributeChanged(ATTRIBUTES *patr) { if (patr != nullptr && patr->GetParent() != nullptr && patr->GetParent()->GetParent() != nullptr) { - const std::string_view sParentName = patr->GetParent()->GetParent()->GetThisName(); - if (!storm::iEquals(sParentName, "pictures")) + const char *sParentName = patr->GetParent()->GetParent()->GetThisName(); + if (sParentName == nullptr || !storm::iEquals(sParentName, "pictures")) + return 0; + const char *sImageName = patr->GetParent()->GetThisName(); + if (sImageName == nullptr) return 0; - const std::string_view sImageName = patr->GetParent()->GetThisName(); // find this picture IMAGE_Entity *pImList = m_imgLists; while (pImList != nullptr) @@ -2630,17 +2657,18 @@ uint32_t XINTERFACE::AttributeChanged(ATTRIBUTES *patr) throw std::runtime_error("Allocation memory error"); } *pImList = {}; - const auto len = sImageName.length() + 1; + const auto len = strlen(sImageName) + 1; if ((pImList->sImageName = new char[len]) == nullptr) { throw std::runtime_error("Allocate memory error"); } - std::copy(std::begin(sImageName), std::end(sImageName), pImList->sImageName); - pImList->sImageName[len - 1] = '\0'; + memcpy(pImList->sImageName, sImageName, len); // insert that into images list pImList->next = m_imgLists; m_imgLists = pImList; } + if (patr->GetThisName() == nullptr) + return 0; // set picture if (storm::iEquals(patr->GetThisName(), "pic")) { @@ -3144,9 +3172,11 @@ void XINTERFACE::IncrementGameTime(uint32_t dwDeltaTime) core.Event("ievent_SetGameTime", "lll", m_dwGameTimeHour, m_dwGameTimeMin, m_dwGameTimeSec); } -std::string AddAttributesStringsToBuffer(ATTRIBUTES *pAttr, std::optional inBuffer = {}, std::optional prev_str = {}) +char *AddAttributesStringsToBuffer(char *inBuffer, char *prevStr, ATTRIBUTES *pAttr) { - std::string new_buffer = std::string(inBuffer.value_or("")); + size_t prevLen = 0; + if (prevStr != nullptr) + prevLen = strlen(prevStr) + std::size(".") - 1; const int q = pAttr->GetAttributesNum(); for (int k = 0; k < q; k++) @@ -3155,37 +3185,52 @@ std::string AddAttributesStringsToBuffer(ATTRIBUTES *pAttr, std::optionalGetThisAttr()); - const auto attrName = std::string(pA->GetThisName()); - - if (attrVal.length() >= 1 && attrVal[0]) + const char *attrVal = pA->GetThisAttr(); + const char *attrName = pA->GetThisName(); + if (attrName && attrVal && attrVal[0]) { - if (!new_buffer.empty()) { - new_buffer += "\n"; + int nadd = std::size("\n") - 1 + strlen(attrName) + std::size("=") - 1 + strlen(attrVal) + 1; + nadd += prevLen; + if (inBuffer != nullptr) + nadd += strlen(inBuffer); + + auto pNew = new char[nadd]; + if (pNew == nullptr) + continue; + pNew[0] = 0; + + if (inBuffer) + { + strcat_s(pNew, nadd, inBuffer); + strcat_s(pNew, nadd, "\n"); } - if (prev_str.has_value()) { - new_buffer += prev_str.value(); - new_buffer += "."; + if (prevStr) + { + strcat_s(pNew, nadd, prevStr); + strcat_s(pNew, nadd, "."); } - new_buffer += attrName; - new_buffer += "="; - new_buffer += attrVal; + strcat_s(pNew, nadd, attrName); + strcat_s(pNew, nadd, "="); + strcat_s(pNew, nadd, attrVal); + + delete inBuffer; + inBuffer = pNew; } if (pA->GetAttributesNum() != 0) { - std::string new_prev_str; - if (prev_str.has_value()) { - new_prev_str = fmt::format("{}.", prev_str.value()); - } - new_prev_str += pA->GetThisName(); - new_buffer = AddAttributesStringsToBuffer(pA, new_buffer.c_str(), new_prev_str); + char param[512]; + param[0] = 0; + if (prevStr) + sprintf_s(param, "%s.", prevStr); + strcat_s(param, pA->GetThisName()); + inBuffer = AddAttributesStringsToBuffer(inBuffer, param, pA); } } - return new_buffer; + return inBuffer; } void XINTERFACE::SaveOptionsFile(const char *fileName, ATTRIBUTES *pAttr) @@ -3199,19 +3244,25 @@ void XINTERFACE::SaveOptionsFile(const char *fileName, ATTRIBUTES *pAttr) strcpy_s(FullPath, fileName); PrecreateDirForFile(FullPath); + auto fileS = fio->_CreateFile(FullPath, std::ios::binary | std::ios::out); + if (!fileS.is_open()) + { + return; + } + + char *pOutBuffer = nullptr; if (pAttr) { - const std::string pOutBuffer = AddAttributesStringsToBuffer(pAttr); + pOutBuffer = AddAttributesStringsToBuffer(nullptr, nullptr, pAttr); + } - auto fileS = fio->_CreateFile(FullPath, std::ios::binary | std::ios::out); - if (!fileS.is_open()) - { - return; - } - fio->_WriteFile(fileS, pOutBuffer.c_str(), pOutBuffer.length()); - fio->_CloseFile(fileS); + if (pOutBuffer) + { + fio->_WriteFile(fileS, pOutBuffer, strlen(pOutBuffer)); + delete pOutBuffer; } + fio->_CloseFile(fileS); } void XINTERFACE::LoadOptionsFile(std::string_view fileName, ATTRIBUTES *pAttr) @@ -3500,14 +3551,16 @@ bool CONTROLS_CONTAINER::CreateConteinerList(ATTRIBUTES *pA) ATTRIBUTES *pAttr = pA->GetAttributeClass(i); if (!pAttr) continue; - const auto containerName = std::string(pAttr->GetThisName()); - AddContainer(containerName.c_str()); - SetContainerLimitVal(containerName.c_str(), static_cast(atof(pAttr->GetThisAttr()))); + const char *containerName = pAttr->GetThisName(); + if (!containerName) + continue; + AddContainer(containerName); + SetContainerLimitVal(containerName, static_cast(atof(pAttr->GetThisAttr()))); const int cntSize = pAttr->GetAttributesNum(); for (int n = 0; n < cntSize; n++) { - AddControlsToContainer(containerName.c_str(), pAttr->GetAttributeName(n), + AddControlsToContainer(containerName, pAttr->GetAttributeName(n), static_cast(atof(pAttr->GetAttribute(n)))); } } @@ -3547,9 +3600,9 @@ void CONTROLS_CONTAINER::SetContainerLimitVal(const char *container, float fLimi pCont->fMaxVal = fLimitVal; } -void CONTROLS_CONTAINER::AddControlsToContainer(const char *container, const std::string_view &controlName, float fValLimit) +void CONTROLS_CONTAINER::AddControlsToContainer(const char *container, const char *controlName, float fValLimit) { - if (!container) + if (!container || !controlName) return; CONTEINER_DESCR *pCont = FindContainer(container); @@ -3565,12 +3618,11 @@ void CONTROLS_CONTAINER::AddControlsToContainer(const char *container, const std pCont->pControls->fValLimit = fValLimit; pCont->pControls->next = pCtrl; - const auto len = controlName.length() + 1; + const auto len = strlen(controlName) + 1; pCont->pControls->controlName = new char[len]; if (!pCont->pControls->controlName) throw std::runtime_error("allocate memory error"); - std::copy(std::begin(controlName), std::end(controlName), pCont->pControls->controlName); - pCont->pControls->controlName[len - 1] = '\0'; + memcpy(pCont->pControls->controlName, controlName, len); } CONTROLS_CONTAINER::CONTEINER_DESCR *CONTROLS_CONTAINER::FindContainer(const char *sContainer) @@ -3585,8 +3637,10 @@ CONTROLS_CONTAINER::CONTEINER_DESCR *CONTROLS_CONTAINER::FindContainer(const cha } CONTROLS_CONTAINER::CONTEINER_DESCR::CONTROL_DESCR *CONTROLS_CONTAINER::CONTEINER_DESCR::FindControl( - const std::string_view &cntrlName) const + const char *cntrlName) { + if (!cntrlName) + return nullptr; CONTROL_DESCR *pCtrl = pControls; while (pCtrl) diff --git a/src/libs/xinterface/src/xinterface.h b/src/libs/xinterface/src/xinterface.h index ba43ef560..401464deb 100644 --- a/src/libs/xinterface/src/xinterface.h +++ b/src/libs/xinterface/src/xinterface.h @@ -411,7 +411,7 @@ class CONTROLS_CONTAINER : public Entity CONTEINER_DESCR *next; - CONTROL_DESCR *FindControl(const std::string_view &cntrlName) const; + CONTROL_DESCR *FindControl(const char *cntrlName); } * pContainers; public: @@ -441,7 +441,7 @@ class CONTROLS_CONTAINER : public Entity bool CreateConteinerList(ATTRIBUTES *pA); void AddContainer(const char *container); void SetContainerLimitVal(const char *container, float fLimitVal); - void AddControlsToContainer(const char *container, const std::string_view &controlName, float fValLimit); + void AddControlsToContainer(const char *container, const char *controlName, float fValLimit); CONTEINER_DESCR *FindContainer(const char *sContainer); }; diff --git a/src/libs/xinterface/testsuite/options_parser.cpp b/src/libs/xinterface/testsuite/options_parser.cpp index 31a3ada10..be090a40b 100644 --- a/src/libs/xinterface/testsuite/options_parser.cpp +++ b/src/libs/xinterface/testsuite/options_parser.cpp @@ -9,12 +9,12 @@ namespace class TestStringCodec : public VSTRING_CODEC { public: - uint32_t GetNum() const override + uint32_t GetNum() override { return map_.size(); } - uint32_t Convert(const std::string_view &pString) override + uint32_t Convert(const char *pString) override { std::string str(pString); const uint32_t hash = std::hash{}(str); @@ -22,9 +22,17 @@ class TestStringCodec : public VSTRING_CODEC return hash; } - [[nodiscard]] std::string_view Convert(uint32_t code) const override + uint32_t Convert(const char *pString, int32_t iLen) override { - return map_.at(code); + std::string str(pString, iLen); + const uint32_t hash = std::hash{}(str); + map_.emplace(hash, str); + return hash; + } + + const char *Convert(uint32_t code) override + { + return map_[code].c_str(); } void VariableChanged() override diff --git a/src/techniques/effects/maineffects.fx b/src/techniques/effects/maineffects.fx index 6ec4a6b58..482af33ac 100644 --- a/src/techniques/effects/maineffects.fx +++ b/src/techniques/effects/maineffects.fx @@ -10,11 +10,10 @@ technique Fader AlphaBlendEnable = true; SrcBlend = srcalpha; DestBlend = invsrcalpha; - ColorArg1[0] = diffuse; - ColorArg2[0] = texture; - ColorOp[0] = modulate; + ColorArg1[0] = texture; + ColorOp[0] = selectarg1; ColorOp[1] = disable; - AlphaArg1[0] = diffuse; + AlphaArg1[0] = texture; AlphaOp[0] = SelectArg1; AlphaOp[1] = disable; } @@ -33,17 +32,18 @@ technique FaderWithTips AlphaBlendEnable = true; SrcBlend = srcalpha; DestBlend = invsrcalpha; - ColorArg1[0] = diffuse; - ColorArg2[0] = texture; - ColorOp[0] = modulate; + ColorVertex = true; + ColorArg1[0] = texture; + ColorOp[0] = selectarg1; ColorArg1[1] = texture; ColorArg2[1] = current; ColorOp[1] = blendtexturealpha; ColorOp[2] = disable; - AlphaArg1[0] = diffuse; - AlphaOp[0] = SelectArg1; - AlphaArg1[1] = current; - AlphaOp[1] = SelectArg1; + AlphaArg1[0] = texture; + AlphaOp[0] = SelectArg1; + AlphaArg1[1] = texture; + AlphaArg2[1] = current; + AlphaOp[1] = blendtexturealpha; AlphaOp[2] = disable; } } @@ -148,9 +148,11 @@ technique ProgressTech AlphaBlendEnable = true; SrcBlend = srcalpha; DestBlend = invsrcalpha; + ColorArg1[0] = texture; ColorOp[0] = SelectArg1; ColorOp[1] = disable; + AlphaArg1[0] = texture; AlphaOp[0] = SelectArg1; AlphaOp[1] = disable; @@ -166,11 +168,15 @@ technique ProgressBackTech ZEnable = false; CullMode = none; AlphaTestEnable = false; - AlphaBlendEnable = false; + AlphaBlendEnable = true; + SrcBlend = srcalpha; + DestBlend = invsrcalpha; ColorArg1[0] = texture; - ColorOp[0] = SelectArg1; + ColorOp[0] = selectarg1; ColorOp[1] = disable; - AlphaOp[0] = disable; + AlphaArg1[0] = texture; + AlphaOp[0] = SelectArg1; + AlphaOp[1] = disable; } } @@ -184,14 +190,23 @@ technique ProgressBackTechWithTips CullMode = none; TexCoordIndex[1] = 0; AlphaTestEnable = false; - AlphaBlendEnable = false; + AlphaBlendEnable = true; + SrcBlend = srcalpha; + DestBlend = invsrcalpha; + ColorVertex = true; + ColorArg1[0] = diffuse; ColorArg1[0] = texture; - ColorOp[0] = SelectArg1; + ColorOp[0] = selectarg1; ColorArg1[1] = texture; ColorArg2[1] = current; ColorOp[1] = blendtexturealpha; ColorOp[2] = disable; - AlphaOp[0] = disable; + AlphaArg1[0] = texture; + AlphaOp[0] = SelectArg1; + AlphaArg1[1] = texture; + AlphaArg2[1] = current; + AlphaOp[1] = blendtexturealpha; + AlphaOp[2] = disable; } } diff --git a/src/techniques/interfaces/game_interface.fx b/src/techniques/interfaces/game_interface.fx index 5f3c988cd..fc0c62a63 100644 --- a/src/techniques/interfaces/game_interface.fx +++ b/src/techniques/interfaces/game_interface.fx @@ -783,16 +783,24 @@ technique iInfoShowerPic AlphaTestEnable = false; AlphaBlendEnable = true; ZEnable = false; - ColorVertex = true; - - ColorOp[0] = selectarg1; +// ColorVertex = true; + ColorArg1[0] = texture; - + ColorOp[0] = selectarg1; +// ColorOp[0] = blendtexturealpha; + AlphaArg1[0] = current; AlphaOp[0] = SelectArg1; - AlphaArg1[0] = texture; - - ColorOp[1] = disable; AlphaOp[1] = disable; + ColorOp[2] = disable; + +// ColorOp[0] = selectarg1; +// ColorArg1[0] = texture; + +// AlphaOp[0] = SelectArg1; +// AlphaArg1[0] = texture; + +// ColorOp[1] = disable; +// AlphaOp[1] = disable; } } diff --git a/src/techniques/location/maineffects.fx b/src/techniques/location/maineffects.fx index 56bdd126a..68dbed0e8 100644 --- a/src/techniques/location/maineffects.fx +++ b/src/techniques/location/maineffects.fx @@ -215,6 +215,29 @@ technique LocationModelBlend } } +technique LocationModelBlendLighting +{ + pass p0 + { + Lighting = true; + FogEnable = true; + AlphaTestEnable = false; + AlphaBlendEnable = true; + SrcBlend = srcalpha; + DestBlend = invsrcalpha; + ZEnable = true; + ZWriteEnable = false; + ColorArg1[0] = texture; + ColorArg2[0] = diffuse; + ColorOp[0] = modulate2x; + ColorOp[1] = disable; + AlphaArg1[0] = texture; + AlphaArg2[0] = diffuse; + AlphaOp[0] = modulate; + AlphaOp[1] = disable; + } +} + technique ShootParticles { pass p0