diff --git a/src/base/system.h b/src/base/system.h index 26d58a078..378765491 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -2505,15 +2505,6 @@ int secure_rand(); */ int secure_rand_below(int below); -/* - Function: set_console_msg_color - Sets the console color. - - Parameters: - rgb - If NULL it will reset the console color to default, else it will transform the rgb color to a console color -*/ -void set_console_msg_color(const void *rgbvoid); - /* Function: os_version_str Returns a human-readable version string of the operating system diff --git a/src/base/vmath.h b/src/base/vmath.h index 2b621c4b9..84f97b179 100644 --- a/src/base/vmath.h +++ b/src/base/vmath.h @@ -84,7 +84,7 @@ public: }; template -inline vector2_base rotate(const vector2_base &a, float angle) +constexpr inline vector2_base rotate(const vector2_base &a, float angle) { angle = angle * pi / 180.0f; float s = sinf(angle); @@ -99,17 +99,17 @@ inline T distance(const vector2_base a, const vector2_base &b) } template -inline T dot(const vector2_base a, const vector2_base &b) +constexpr inline T dot(const vector2_base a, const vector2_base &b) { return a.x * b.x + a.y * b.y; } inline float length(const vector2_base &a) { - return sqrtf(a.x * a.x + a.y * a.y); + return sqrtf(dot(a, a)); } -inline float angle(const vector2_base &a) +constexpr inline float angle(const vector2_base &a) { if(a.x == 0 && a.y == 0) return 0.0f; @@ -122,7 +122,7 @@ inline float angle(const vector2_base &a) } template -inline vector2_base normalize_pre_length(const vector2_base &v, T len) +constexpr inline vector2_base normalize_pre_length(const vector2_base &v, T len) { if(len == 0) return vector2_base(); @@ -131,14 +131,14 @@ inline vector2_base normalize_pre_length(const vector2_base &v, T len) inline vector2_base normalize(const vector2_base &v) { - float divisor = sqrtf(v.x * v.x + v.y * v.y); + float divisor = length(v); if(divisor == 0.0f) return vector2_base(0.0f, 0.0f); float l = (float)(1.0f / divisor); return vector2_base(v.x * l, v.y * l); } -inline vector2_base direction(float angle) +constexpr inline vector2_base direction(float angle) { return vector2_base(cosf(angle), sinf(angle)); } @@ -148,7 +148,7 @@ typedef vector2_base bvec2; typedef vector2_base ivec2; template -inline bool closest_point_on_line(vector2_base line_pointA, vector2_base line_pointB, vector2_base target_point, vector2_base &out_pos) +constexpr inline bool closest_point_on_line(vector2_base line_pointA, vector2_base line_pointB, vector2_base target_point, vector2_base &out_pos) { vector2_base AB = line_pointB - line_pointA; T SquaredMagnitudeAB = dot(AB, AB); @@ -182,12 +182,12 @@ public: T z, b, l, w; }; - vector3_base() : + constexpr vector3_base() : x(T()), y(T()), z(T()) { } - vector3_base(T nx, T ny, T nz) : + constexpr vector3_base(T nx, T ny, T nz) : x(nx), y(ny), z(nz) { } @@ -254,13 +254,13 @@ inline T distance(const vector3_base &a, const vector3_base &b) } template -inline T dot(const vector3_base &a, const vector3_base &b) +constexpr inline T dot(const vector3_base &a, const vector3_base &b) { return a.x * b.x + a.y * b.y + a.z * b.z; } template -inline vector3_base cross(const vector3_base &a, const vector3_base &b) +constexpr inline vector3_base cross(const vector3_base &a, const vector3_base &b) { return vector3_base( a.y * b.z - a.z * b.y, @@ -271,12 +271,12 @@ inline vector3_base cross(const vector3_base &a, const vector3_base &b) // inline float length(const vector3_base &a) { - return sqrtf(a.x * a.x + a.y * a.y + a.z * a.z); + return sqrtf(dot(a, a)); } inline vector3_base normalize(const vector3_base &v) { - float divisor = sqrtf(v.x * v.x + v.y * v.y + v.z * v.z); + float divisor = length(v); if(divisor == 0.0f) return vector3_base(0.0f, 0.0f, 0.0f); float l = (float)(1.0f / divisor); @@ -310,12 +310,12 @@ public: T w, a; }; - vector4_base() : + constexpr vector4_base() : x(T()), y(T()), z(T()), w(T()) { } - vector4_base(T nx, T ny, T nz, T nw) : + constexpr vector4_base(T nx, T ny, T nz, T nw) : x(nx), y(ny), z(nz), w(nw) { } @@ -378,6 +378,7 @@ public: } bool operator==(const vector4_base &vec) const { return x == vec.x && y == vec.y && z == vec.z && w == vec.w; } //TODO: do this with an eps instead + bool operator!=(const vector4_base &vec) const { return x != vec.x || y != vec.y || z != vec.z || w != vec.w; } }; typedef vector4_base vec4; diff --git a/src/engine/client/serverbrowser.cpp b/src/engine/client/serverbrowser.cpp index 0f8964678..bf3059b5a 100644 --- a/src/engine/client/serverbrowser.cpp +++ b/src/engine/client/serverbrowser.cpp @@ -1505,6 +1505,7 @@ int CServerInfo::EstimateLatency(int Loc1, int Loc2) } return 99; } + bool CServerInfo::ParseLocation(int *pResult, const char *pString) { *pResult = LOC_UNKNOWN; @@ -1534,3 +1535,16 @@ bool CServerInfo::ParseLocation(int *pResult, const char *pString) } return true; } + +void CServerInfo::InfoToString(char *pBuffer, int BufferSize) const +{ + str_format( + pBuffer, + BufferSize, + "%s\n" + "Address: ddnet://%s\n" + "My IGN: %s\n", + m_aName, + m_aAddress, + g_Config.m_PlayerName); +} diff --git a/src/engine/serverbrowser.h b/src/engine/serverbrowser.h index 1e9032036..a4b194b1d 100644 --- a/src/engine/serverbrowser.h +++ b/src/engine/serverbrowser.h @@ -83,6 +83,7 @@ public: static int EstimateLatency(int Loc1, int Loc2); static bool ParseLocation(int *pResult, const char *pString); + void InfoToString(char *pBuffer, int BufferSize) const; }; class IServerBrowser : public IInterface diff --git a/src/game/client/components/menus_browser.cpp b/src/game/client/components/menus_browser.cpp index 99f4066b2..4f8082321 100644 --- a/src/game/client/components/menus_browser.cpp +++ b/src/game/client/components/menus_browser.cpp @@ -1030,8 +1030,7 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View) const CServerInfo *pSelectedServer = ServerBrowser()->SortedGet(m_SelectedIndex); // split off a piece to use for scoreboard - ServerDetails.HSplitTop(90.0f, &ServerDetails, &ServerScoreBoard); - ServerDetails.HSplitBottom(2.5f, &ServerDetails, 0x0); + ServerDetails.HSplitTop(110.0f, &ServerDetails, &ServerScoreBoard); // server details CTextCursor Cursor; @@ -1043,8 +1042,7 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View) if(pSelectedServer) { - ServerDetails.VSplitLeft(5.0f, 0, &ServerDetails); - ServerDetails.Margin(3.0f, &ServerDetails); + ServerDetails.Margin(5.0f, &ServerDetails); CUIRect Row; static CLocConstString s_aLabels[] = { @@ -1052,17 +1050,28 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View) "Game type", "Ping"}; - CUIRect LeftColumn; - CUIRect RightColumn; + // copy info button + { + CUIRect Button; + ServerDetails.HSplitBottom(15.0f, &ServerDetails, &Button); + static CButtonContainer s_CopyButton; + if(DoButton_Menu(&s_CopyButton, Localize("Copy info"), 0, &Button)) + { + char aInfo[256]; + pSelectedServer->InfoToString(aInfo, sizeof(aInfo)); + Input()->SetClipboardText(aInfo); + } + } - // + ServerDetails.HSplitBottom(2.5f, &ServerDetails, nullptr); + + // favorite checkbox { CUIRect Button; ServerDetails.HSplitBottom(20.0f, &ServerDetails, &Button); CUIRect ButtonAddFav; CUIRect ButtonLeakIp; Button.VSplitMid(&ButtonAddFav, &ButtonLeakIp); - ButtonAddFav.VSplitLeft(5.0f, 0, &ButtonAddFav); static int s_AddFavButton = 0; static int s_LeakIpButton = 0; if(DoButton_CheckBox_Tristate(&s_AddFavButton, Localize("Favorite"), pSelectedServer->m_Favorite, &ButtonAddFav)) @@ -1091,7 +1100,7 @@ void CMenus::RenderServerbrowserServerDetail(CUIRect View) } } - ServerDetails.VSplitLeft(5.0f, 0x0, &ServerDetails); + CUIRect LeftColumn, RightColumn; ServerDetails.VSplitLeft(80.0f, &LeftColumn, &RightColumn); for(auto &Label : s_aLabels) diff --git a/src/game/client/components/menus_ingame.cpp b/src/game/client/components/menus_ingame.cpp index 798e12714..2630293c5 100644 --- a/src/game/client/components/menus_ingame.cpp +++ b/src/game/client/components/menus_ingame.cpp @@ -415,6 +415,21 @@ void CMenus::RenderServerInfo(CUIRect MainView) TextRender()->Text(0, ServerInfo.x + x, ServerInfo.y + y, 20, aBuf, 250.0f); + // copy info button + { + CUIRect Button; + ServerInfo.HSplitBottom(20.0f, &ServerInfo, &Button); + Button.VSplitRight(200.0f, &ServerInfo, &Button); + static CButtonContainer s_CopyButton; + if(DoButton_Menu(&s_CopyButton, Localize("Copy info"), 0, &Button)) + { + char aInfo[256]; + CurrentServerInfo.InfoToString(aInfo, sizeof(aInfo)); + Input()->SetClipboardText(aInfo); + } + } + + // favorite checkbox { CUIRect Button; NETADDR ServerAddr = Client()->ServerAddress(); diff --git a/src/game/client/prediction/entities/character.cpp b/src/game/client/prediction/entities/character.cpp index aef21437e..9cc02f654 100644 --- a/src/game/client/prediction/entities/character.cpp +++ b/src/game/client/prediction/entities/character.cpp @@ -489,7 +489,7 @@ void CCharacter::GiveNinja() { m_Core.m_Ninja.m_ActivationTick = GameWorld()->GameTick(); m_Core.m_aWeapons[WEAPON_NINJA].m_Got = true; - if(!m_FreezeTime) + if(m_FreezeTime > 0) m_Core.m_aWeapons[WEAPON_NINJA].m_Ammo = -1; if(m_Core.m_ActiveWeapon != WEAPON_NINJA) m_LastWeapon = m_Core.m_ActiveWeapon; @@ -952,12 +952,9 @@ void CCharacter::DDRaceTick() m_Input.m_Jump = 0; //Hook and weapons are possible in live freeze } - if(m_FreezeTime > 0 || m_FreezeTime == -1) + if(m_FreezeTime > 0) { - if(m_FreezeTime > 0) - m_FreezeTime--; - else - m_Core.m_Ninja.m_ActivationTick = GameWorld()->GameTick(); + m_FreezeTime--; if(!m_CanMoveInFreeze) { m_Input.m_Direction = 0; @@ -1046,11 +1043,11 @@ bool CCharacter::Freeze(int Seconds) { if(!GameWorld()->m_WorldConfig.m_PredictFreeze) return false; - if((Seconds <= 0 || m_Core.m_Super || m_FreezeTime == -1 || m_FreezeTime > Seconds * GameWorld()->GameTickSpeed()) && Seconds != -1) + if(Seconds <= 0 || m_Core.m_Super || m_FreezeTime > Seconds * GameWorld()->GameTickSpeed()) return false; - if(m_Core.m_FreezeStart < GameWorld()->GameTick() - GameWorld()->GameTickSpeed() || Seconds == -1) + if(m_Core.m_FreezeStart < GameWorld()->GameTick() - GameWorld()->GameTickSpeed()) { - m_FreezeTime = Seconds == -1 ? Seconds : Seconds * GameWorld()->GameTickSpeed(); + m_FreezeTime = Seconds * GameWorld()->GameTickSpeed(); m_Core.m_FreezeStart = GameWorld()->GameTick(); return true; } diff --git a/src/game/gamecore.cpp b/src/game/gamecore.cpp index 408924d02..2ecc932b9 100644 --- a/src/game/gamecore.cpp +++ b/src/game/gamecore.cpp @@ -251,7 +251,6 @@ void CCharacterCore::Tick(bool UseInput, bool DoDeferredTick) if(m_HookState == HOOK_IDLE) { SetHookedPlayer(-1); - m_HookState = HOOK_IDLE; m_HookPos = m_Pos; } else if(m_HookState >= HOOK_RETRACT_START && m_HookState < HOOK_RETRACT_END) diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp index 3d6f8fff5..d5e7b31d0 100644 --- a/src/game/server/entities/character.cpp +++ b/src/game/server/entities/character.cpp @@ -976,12 +976,12 @@ void CCharacter::SnapCharacter(int SnappingClient, int ID) } // change eyes and use ninja graphic if player is frozen - if(m_Core.m_DeepFrozen || m_FreezeTime > 0 || m_FreezeTime == -1 || m_Core.m_LiveFrozen) + if(m_Core.m_DeepFrozen || m_FreezeTime > 0 || m_Core.m_LiveFrozen) { if(Emote == EMOTE_NORMAL) Emote = (m_Core.m_DeepFrozen || m_Core.m_LiveFrozen) ? EMOTE_PAIN : EMOTE_BLINK; - if((m_Core.m_DeepFrozen || m_FreezeTime > 0 || m_FreezeTime == -1) && SnappingClientVersion < VERSION_DDNET_NEW_HUD) + if((m_Core.m_DeepFrozen || m_FreezeTime > 0) && SnappingClientVersion < VERSION_DDNET_NEW_HUD) Weapon = WEAPON_NINJA; } @@ -1008,8 +1008,7 @@ void CCharacter::SnapCharacter(int SnappingClient, int ID) } // change eyes, use ninja graphic and set ammo count if player has ninjajetpack - if(m_pPlayer->m_NinjaJetpack && m_Core.m_Jetpack && m_Core.m_ActiveWeapon == WEAPON_GUN && !m_Core.m_DeepFrozen && - !(m_FreezeTime > 0 || m_FreezeTime == -1) && !m_Core.m_HasTelegunGun) + if(m_pPlayer->m_NinjaJetpack && m_Core.m_Jetpack && m_Core.m_ActiveWeapon == WEAPON_GUN && !m_Core.m_DeepFrozen && m_FreezeTime == 0 && !m_Core.m_HasTelegunGun) { if(Emote == EMOTE_NORMAL) Emote = EMOTE_HAPPY; @@ -1023,12 +1022,12 @@ void CCharacter::SnapCharacter(int SnappingClient, int ID) Health = m_Health; Armor = m_Armor; if(m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo > 0) - AmmoCount = (!m_FreezeTime) ? m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo : 0; + AmmoCount = (m_FreezeTime > 0) ? m_Core.m_aWeapons[m_Core.m_ActiveWeapon].m_Ammo : 0; } if(GetPlayer()->IsAfk() || GetPlayer()->IsPaused()) { - if(m_FreezeTime > 0 || m_FreezeTime == -1 || m_Core.m_DeepFrozen || m_Core.m_LiveFrozen) + if(m_FreezeTime > 0 || m_Core.m_DeepFrozen || m_Core.m_LiveFrozen) Emote = EMOTE_NORMAL; else Emote = EMOTE_BLINK; @@ -1084,7 +1083,7 @@ void CCharacter::SnapCharacter(int SnappingClient, int ID) pCharacter->m_Weapon = Weapon; pCharacter->m_AmmoCount = AmmoCount; - if(m_FreezeTime > 0 || m_FreezeTime == -1 || m_Core.m_DeepFrozen) + if(m_FreezeTime > 0 || m_Core.m_DeepFrozen) pCharacter->m_AmmoCount = m_Core.m_FreezeStart + g_Config.m_SvFreezeDelay * Server()->TickSpeed(); else if(Weapon == WEAPON_NINJA) pCharacter->m_AmmoCount = m_Core.m_Ninja.m_ActivationTick + g_pData->m_Weapons.m_Ninja.m_Duration * Server()->TickSpeed() / 1000; @@ -1999,7 +1998,7 @@ void CCharacter::SetRescue() void CCharacter::DDRaceTick() { mem_copy(&m_Input, &m_SavedInput, sizeof(m_Input)); - m_Armor = (m_FreezeTime >= 0) ? clamp(10 - (m_FreezeTime / 15), 0, 10) : 0; + m_Armor = clamp(10 - (m_FreezeTime / 15), 0, 10); if(m_Input.m_Direction != 0 || m_Input.m_Jump != 0) m_LastMove = Server()->Tick(); @@ -2009,16 +2008,13 @@ void CCharacter::DDRaceTick() m_Input.m_Jump = 0; // Hook is possible in live freeze } - if(m_FreezeTime > 0 || m_FreezeTime == -1) + if(m_FreezeTime > 0) { - if(m_FreezeTime % Server()->TickSpeed() == Server()->TickSpeed() - 1 || m_FreezeTime == -1) + if(m_FreezeTime % Server()->TickSpeed() == Server()->TickSpeed() - 1) { GameServer()->CreateDamageInd(m_Pos, 0, (m_FreezeTime + 1) / Server()->TickSpeed(), TeamMask() & GameServer()->ClientsMaskExcludeClientVersionAndHigher(VERSION_DDNET_NEW_HUD)); } - if(m_FreezeTime > 0) - m_FreezeTime--; - else - m_Core.m_Ninja.m_ActivationTick = Server()->Tick(); + m_FreezeTime--; m_Input.m_Direction = 0; m_Input.m_Jump = 0; m_Input.m_Hook = 0; @@ -2137,12 +2133,12 @@ void CCharacter::DDRacePostCoreTick() bool CCharacter::Freeze(int Seconds) { - if((Seconds <= 0 || m_Core.m_Super || m_FreezeTime == -1 || m_FreezeTime > Seconds * Server()->TickSpeed()) && Seconds != -1) + if(Seconds <= 0 || m_Core.m_Super || m_FreezeTime > Seconds * Server()->TickSpeed()) return false; - if(m_Core.m_FreezeStart < Server()->Tick() - Server()->TickSpeed() || Seconds == -1) + if(m_Core.m_FreezeStart < Server()->Tick() - Server()->TickSpeed()) { m_Armor = 0; - m_FreezeTime = Seconds == -1 ? Seconds : Seconds * Server()->TickSpeed(); + m_FreezeTime = Seconds * Server()->TickSpeed(); m_Core.m_FreezeStart = Server()->Tick(); return true; }