Skip to content

Commit

Permalink
Merge branch 'ddnet' into chillerbot
Browse files Browse the repository at this point in the history
  • Loading branch information
ChillerDragon committed Oct 15, 2024
2 parents fb5101b + 8290db9 commit 0bd6c30
Show file tree
Hide file tree
Showing 17 changed files with 470 additions and 262 deletions.
3 changes: 2 additions & 1 deletion src/engine/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3675,7 +3675,8 @@ void CClient::Con_AddFavorite(IConsole::IResult *pResult, void *pUserData)
{
CClient *pSelf = (CClient *)pUserData;
NETADDR Addr;
if(net_addr_from_str(&Addr, pResult->GetString(0)) != 0)

if(net_addr_from_url(&Addr, pResult->GetString(0), nullptr, 0) != 0 && net_addr_from_str(&Addr, pResult->GetString(0)) != 0)
{
char aBuf[128];
str_format(aBuf, sizeof(aBuf), "invalid address '%s'", pResult->GetString(0));
Expand Down
38 changes: 21 additions & 17 deletions src/engine/client/favorites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,21 @@ void CFavorites::OnConfigSave(IConfigManager *pConfigManager)
{
char aAddr[NETADDR_MAXSTRSIZE];
char aBuffer[128];
net_addr_str(&Entry.m_aAddrs[i], aAddr, sizeof(aAddr), true);
net_addr_str(&Entry.m_aAddrs[i], aBuffer, sizeof(aBuffer), true);

if(Entry.m_aAddrs[i].type & NETTYPE_TW7)
{
str_format(
aAddr,
sizeof(aAddr),
"tw-0.7+udp://%s",
aBuffer);
}
else
{
str_copy(aAddr, aBuffer);
}

if(!Entry.m_AllowPing)
{
str_format(aBuffer, sizeof(aBuffer), "add_favorite %s", aAddr);
Expand Down Expand Up @@ -135,16 +149,14 @@ void CFavorites::Add(const NETADDR *pAddrs, int NumAddrs)
// other favorite.
for(int i = 0; i < NumAddrs; i++)
{
NETADDR Addr = pAddrs[i];
Addr.type &= ~(NETTYPE_TW7);
CEntry *pEntry = Entry(Addr);
CEntry *pEntry = Entry(pAddrs[i]);
if(pEntry == nullptr)
{
continue;
}
for(int j = 0; j < pEntry->m_NumAddrs; j++)
{
if(pEntry->m_aAddrs[j] == Addr)
if(pEntry->m_aAddrs[j] == pAddrs[i])
{
pEntry->m_aAddrs[j] = pEntry->m_aAddrs[pEntry->m_NumAddrs - 1];
pEntry->m_NumAddrs -= 1;
Expand All @@ -164,10 +176,8 @@ void CFavorites::Add(const NETADDR *pAddrs, int NumAddrs)
NewEntry.m_NumAddrs = std::min(NumAddrs, (int)std::size(NewEntry.m_aAddrs));
for(int i = 0; i < NewEntry.m_NumAddrs; i++)
{
NETADDR Addr = pAddrs[i];
Addr.type &= ~(NETTYPE_TW7);
NewEntry.m_aAddrs[i] = Addr;
m_ByAddr[Addr] = m_vEntries.size();
NewEntry.m_aAddrs[i] = pAddrs[i];
m_ByAddr[pAddrs[i]] = m_vEntries.size();
}
NewEntry.m_AllowPing = false;
m_vEntries.push_back(NewEntry);
Expand Down Expand Up @@ -211,10 +221,7 @@ void CFavorites::AllEntries(const CEntry **ppEntries, int *pNumEntries)

CFavorites::CEntry *CFavorites::Entry(const NETADDR &Addr)
{
NETADDR AddrAnyProtocol = Addr;
AddrAnyProtocol.type &= ~(NETTYPE_TW7);

auto Entry = m_ByAddr.find(AddrAnyProtocol);
auto Entry = m_ByAddr.find(Addr);
if(Entry == m_ByAddr.end())
{
return nullptr;
Expand All @@ -224,10 +231,7 @@ CFavorites::CEntry *CFavorites::Entry(const NETADDR &Addr)

const CFavorites::CEntry *CFavorites::Entry(const NETADDR &Addr) const
{
NETADDR AddrAnyProtocol = Addr;
AddrAnyProtocol.type &= ~(NETTYPE_TW7);

auto Entry = m_ByAddr.find(AddrAnyProtocol);
auto Entry = m_ByAddr.find(Addr);
if(Entry == m_ByAddr.end())
{
return nullptr;
Expand Down
4 changes: 2 additions & 2 deletions src/engine/shared/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,8 @@ void CConfigManager::Init()
#undef MACRO_CONFIG_STR

m_pConsole->Register("reset", "s[config-name]", CFGFLAG_SERVER | CFGFLAG_CLIENT | CFGFLAG_STORE, Con_Reset, this, "Reset a config to its default value");
m_pConsole->Register("toggle", "s[config-option] i[value 1] i[value 2]", CFGFLAG_SERVER | CFGFLAG_CLIENT, Con_Toggle, this, "Toggle config value");
m_pConsole->Register("+toggle", "s[config-option] i[value 1] i[value 2]", CFGFLAG_CLIENT, Con_ToggleStroke, this, "Toggle config value via keypress");
m_pConsole->Register("toggle", "s[config-option] s[value 1] s[value 2]", CFGFLAG_SERVER | CFGFLAG_CLIENT, Con_Toggle, this, "Toggle config value");
m_pConsole->Register("+toggle", "s[config-option] s[value 1] s[value 2]", CFGFLAG_CLIENT, Con_ToggleStroke, this, "Toggle config value via keypress");
}

void CConfigManager::Reset(const char *pScriptName)
Expand Down
30 changes: 18 additions & 12 deletions src/engine/shared/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ bool CHttpRequest::ConfigureHandle(void *pHandle)
{
curl_easy_setopt(pH, CURLOPT_MAXFILESIZE_LARGE, (curl_off_t)m_MaxResponseSize);
}
if(m_IfModifiedSince >= 0)
{
curl_easy_setopt(pH, CURLOPT_TIMEVALUE_LARGE, (curl_off_t)m_IfModifiedSince);
curl_easy_setopt(pH, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
}

// ‘CURLOPT_PROTOCOLS’ is deprecated: since 7.85.0. Use CURLOPT_PROTOCOLS_STR
// Wait until all platforms have 7.85.0
Expand Down Expand Up @@ -378,7 +383,11 @@ void CHttpRequest::OnCompletionInternal(void *pHandle, unsigned int Result)
// or other threads may try to access the result of a completed HTTP request,
// before the result has been initialized/updated in OnCompletion.
OnCompletion(State);
m_State = State;
{
std::unique_lock WaitLock(m_WaitMutex);
m_State = State;
}
m_WaitCondition.notify_all();
}

void CHttpRequest::WriteToFile(IStorage *pStorage, const char *pDest, int StorageType)
Expand All @@ -402,18 +411,11 @@ void CHttpRequest::Header(const char *pNameColonValue)

void CHttpRequest::Wait()
{
using namespace std::chrono_literals;

// This is so uncommon that polling just might work
for(;;)
{
std::unique_lock Lock(m_WaitMutex);
m_WaitCondition.wait(Lock, [this]() {
EHttpState State = m_State.load(std::memory_order_seq_cst);
if(State != EHttpState::QUEUED && State != EHttpState::RUNNING)
{
return;
}
std::this_thread::sleep_for(10ms);
}
return State != EHttpState::QUEUED && State != EHttpState::RUNNING;
});
}

void CHttpRequest::Result(unsigned char **ppResult, size_t *pResultLength) const
Expand Down Expand Up @@ -604,6 +606,10 @@ void CHttp::RunLoop()
goto error_configure;
}

{
std::unique_lock WaitLock(pRequest->m_WaitMutex);
pRequest->m_State = EHttpState::RUNNING;
}
m_RunningRequests.emplace(pEH, std::move(pRequest));
NewRequests.pop_front();
continue;
Expand Down
4 changes: 4 additions & 0 deletions src/engine/shared/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class CHttpRequest : public IHttpRequest

CTimeout m_Timeout = CTimeout{0, 0, 0, 0};
int64_t m_MaxResponseSize = -1;
int64_t m_IfModifiedSince = -1;
REQUEST m_Type = REQUEST::GET;

SHA256_DIGEST m_ActualSha256 = SHA256_ZEROED;
Expand Down Expand Up @@ -116,6 +117,8 @@ class CHttpRequest : public IHttpRequest
char m_aErr[256]; // 256 == CURL_ERROR_SIZE
std::atomic<EHttpState> m_State{EHttpState::QUEUED};
std::atomic<bool> m_Abort{false};
std::mutex m_WaitMutex;
std::condition_variable m_WaitCondition;

int m_StatusCode = 0;
bool m_HeadersEnded = false;
Expand Down Expand Up @@ -150,6 +153,7 @@ class CHttpRequest : public IHttpRequest

void Timeout(CTimeout Timeout) { m_Timeout = Timeout; }
void MaxResponseSize(int64_t MaxResponseSize) { m_MaxResponseSize = MaxResponseSize; }
void IfModifiedSince(int64_t IfModifiedSince) { m_IfModifiedSince = IfModifiedSince; }
void LogProgress(HTTPLOG LogProgress) { m_LogProgress = LogProgress; }
void IpResolve(IPRESOLVE IpResolve) { m_IpResolve = IpResolve; }
void FailOnErrorStatus(bool FailOnErrorStatus) { m_FailOnErrorStatus = FailOnErrorStatus; }
Expand Down
8 changes: 8 additions & 0 deletions src/engine/shared/storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,14 @@ class CStorage : public IStorage
return pResult;
}

bool RetrieveTimes(const char *pFilename, int Type, time_t *pCreated, time_t *pModified) override
{
dbg_assert(Type == TYPE_ABSOLUTE || (Type >= TYPE_SAVE && Type < m_NumPaths), "Type invalid");

char aBuffer[IO_MAX_PATH_LENGTH];
return fs_file_time(GetPath(Type, pFilename, aBuffer, sizeof(aBuffer)), pCreated, pModified) == 0;
}

bool CalculateHashes(const char *pFilename, int Type, SHA256_DIGEST *pSha256, unsigned *pCrc) override
{
dbg_assert(pSha256 != nullptr || pCrc != nullptr, "At least one output argument required");
Expand Down
1 change: 1 addition & 0 deletions src/engine/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class IStorage : public IInterface
virtual bool FolderExists(const char *pFilename, int Type) = 0;
virtual bool ReadFile(const char *pFilename, int Type, void **ppResult, unsigned *pResultLen) = 0;
virtual char *ReadFileStr(const char *pFilename, int Type) = 0;
virtual bool RetrieveTimes(const char *pFilename, int Type, time_t *pCreated, time_t *pModified) = 0;
virtual bool CalculateHashes(const char *pFilename, int Type, SHA256_DIGEST *pSha256, unsigned *pCrc = nullptr) = 0;
virtual bool FindFile(const char *pFilename, const char *pPath, int Type, char *pBuffer, int BufferSize) = 0;
virtual size_t FindFiles(const char *pFilename, const char *pPath, int Type, std::set<std::string> *pEntries) = 0;
Expand Down
93 changes: 18 additions & 75 deletions src/game/client/components/maplayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@

using namespace std::chrono_literals;

CMapLayers::CMapLayers(int t, bool OnlineOnly)
CMapLayers::CMapLayers(int Type, bool OnlineOnly)
{
m_Type = t;
m_pLayers = 0;
m_CurrentLocalTick = 0;
m_LastLocalTick = 0;
m_EnvelopeUpdate = false;
m_Type = Type;
m_OnlineOnly = OnlineOnly;
}

Expand All @@ -45,17 +41,6 @@ CCamera *CMapLayers::GetCurCamera()
return &m_pClient->m_Camera;
}

void CMapLayers::EnvelopeUpdate()
{
if(Client()->State() == IClient::STATE_DEMOPLAYBACK)
{
const IDemoPlayer::CInfo *pInfo = DemoPlayer()->BaseInfo();
m_CurrentLocalTick = pInfo->m_CurrentTick;
m_LastLocalTick = pInfo->m_CurrentTick;
m_EnvelopeUpdate = true;
}
}

void CMapLayers::EnvelopeEval(int TimeOffsetMillis, int Env, ColorRGBA &Result, size_t Channels, void *pUser)
{
CMapLayers *pThis = (CMapLayers *)pUser;
Expand All @@ -75,73 +60,31 @@ void CMapLayers::EnvelopeEval(int TimeOffsetMillis, int Env, ColorRGBA &Result,
if(EnvelopePoints.NumPoints() == 0)
return;

const auto TickToNanoSeconds = std::chrono::nanoseconds(1s) / (int64_t)pThis->Client()->GameTickSpeed();

static std::chrono::nanoseconds s_Time{0};
static auto s_LastLocalTime = time_get_nanoseconds();
if(pThis->Client()->State() == IClient::STATE_DEMOPLAYBACK)
if(pThis->m_OnlineOnly && (pItem->m_Version < 2 || pItem->m_Synchronized))
{
const IDemoPlayer::CInfo *pInfo = pThis->DemoPlayer()->BaseInfo();

if(!pInfo->m_Paused || pThis->m_EnvelopeUpdate)
if(pThis->m_pClient->m_Snap.m_pGameInfoObj)
{
if(pThis->m_CurrentLocalTick != pInfo->m_CurrentTick)
{
pThis->m_LastLocalTick = pThis->m_CurrentLocalTick;
pThis->m_CurrentLocalTick = pInfo->m_CurrentTick;
}
if(pItem->m_Version < 2 || pItem->m_Synchronized)
{
if(pThis->m_pClient->m_Snap.m_pGameInfoObj)
{
// get the lerp of the current tick and prev
int MinTick = pThis->Client()->PrevGameTick(g_Config.m_ClDummy) - pThis->m_pClient->m_Snap.m_pGameInfoObj->m_RoundStartTick;
int CurTick = pThis->Client()->GameTick(g_Config.m_ClDummy) - pThis->m_pClient->m_Snap.m_pGameInfoObj->m_RoundStartTick;
s_Time = std::chrono::nanoseconds((int64_t)(mix<double>(
0,
(CurTick - MinTick),
(double)pThis->Client()->IntraGameTick(g_Config.m_ClDummy)) *
TickToNanoSeconds.count())) +
MinTick * TickToNanoSeconds;
}
}
else
{
int MinTick = pThis->m_LastLocalTick;
s_Time = std::chrono::nanoseconds((int64_t)(mix<double>(0,
pThis->m_CurrentLocalTick - MinTick,
(double)pThis->Client()->IntraGameTick(g_Config.m_ClDummy)) *
TickToNanoSeconds.count())) +
MinTick * TickToNanoSeconds;
}
// get the lerp of the current tick and prev
const auto TickToNanoSeconds = std::chrono::nanoseconds(1s) / (int64_t)pThis->Client()->GameTickSpeed();
const int MinTick = pThis->Client()->PrevGameTick(g_Config.m_ClDummy) - pThis->m_pClient->m_Snap.m_pGameInfoObj->m_RoundStartTick;
const int CurTick = pThis->Client()->GameTick(g_Config.m_ClDummy) - pThis->m_pClient->m_Snap.m_pGameInfoObj->m_RoundStartTick;
s_Time = std::chrono::nanoseconds((int64_t)(mix<double>(
0,
(CurTick - MinTick),
(double)pThis->Client()->IntraGameTick(g_Config.m_ClDummy)) *
TickToNanoSeconds.count())) +
MinTick * TickToNanoSeconds;
}
CRenderTools::RenderEvalEnvelope(&EnvelopePoints, s_Time + (int64_t)TimeOffsetMillis * std::chrono::nanoseconds(1ms), Result, Channels);
}
else
{
if(pThis->m_OnlineOnly && (pItem->m_Version < 2 || pItem->m_Synchronized))
{
if(pThis->m_pClient->m_Snap.m_pGameInfoObj) // && !(pThis->m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_PAUSED))
{
// get the lerp of the current tick and prev
int MinTick = pThis->Client()->PrevGameTick(g_Config.m_ClDummy) - pThis->m_pClient->m_Snap.m_pGameInfoObj->m_RoundStartTick;
int CurTick = pThis->Client()->GameTick(g_Config.m_ClDummy) - pThis->m_pClient->m_Snap.m_pGameInfoObj->m_RoundStartTick;
s_Time = std::chrono::nanoseconds((int64_t)(mix<double>(
0,
(CurTick - MinTick),
(double)pThis->Client()->IntraGameTick(g_Config.m_ClDummy)) *
TickToNanoSeconds.count())) +
MinTick * TickToNanoSeconds;
}
}
else
{
auto CurTime = time_get_nanoseconds();
s_Time += CurTime - s_LastLocalTime;
s_LastLocalTime = CurTime;
}
CRenderTools::RenderEvalEnvelope(&EnvelopePoints, s_Time + std::chrono::nanoseconds(std::chrono::milliseconds(TimeOffsetMillis)), Result, Channels);
const auto CurTime = time_get_nanoseconds();
s_Time += CurTime - s_LastLocalTime;
s_LastLocalTime = CurTime;
}
CRenderTools::RenderEvalEnvelope(&EnvelopePoints, s_Time + std::chrono::nanoseconds(std::chrono::milliseconds(TimeOffsetMillis)), Result, Channels);
}

void FillTmpTile(SGraphicTile *pTmpTile, SGraphicTileTexureCoords *pTmpTex, unsigned char Flags, unsigned char Index, int x, int y, const ivec2 &Offset, int Scale, CMapItemGroup *pGroup)
Expand Down
7 changes: 1 addition & 6 deletions src/game/client/components/maplayers.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,8 @@ class CMapLayers : public CComponent

CLayers *m_pLayers;
CMapImages *m_pImages;
int m_Type;
int m_CurrentLocalTick;
int m_LastLocalTick;
bool m_EnvelopeUpdate;

int m_Type;
bool m_OnlineOnly;

struct STileLayerVisuals
Expand Down Expand Up @@ -162,8 +159,6 @@ class CMapLayers : public CComponent
void RenderKillTileBorder(int LayerIndex, const ColorRGBA &Color, CMapItemLayerTilemap *pTileLayer, CMapItemGroup *pGroup);
void RenderQuadLayer(int LayerIndex, CMapItemLayerQuads *pQuadLayer, CMapItemGroup *pGroup, bool ForceRender = false);

void EnvelopeUpdate();

static void EnvelopeEval(int TimeOffsetMillis, int Env, ColorRGBA &Result, size_t Channels, void *pUser);
};

Expand Down
5 changes: 5 additions & 0 deletions src/game/client/components/menus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,11 @@ void CMenus::OnInit()
// load community icons
m_vCommunityIcons.clear();
Storage()->ListDirectory(IStorage::TYPE_ALL, "communityicons", CommunityIconScan, this);

// Quad for the direction arrows above the player
m_DirectionQuadContainerIndex = Graphics()->CreateQuadContainer(false);
RenderTools()->QuadContainerAddSprite(m_DirectionQuadContainerIndex, 0.f, 0.f, 22.f);
Graphics()->QuadContainerUpload(m_DirectionQuadContainerIndex);
}

void CMenus::OnConsoleInit()
Expand Down
2 changes: 2 additions & 0 deletions src/game/client/components/menus.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ class CMenus : public CComponent

bool m_SkinListNeedsUpdate = false;

int m_DirectionQuadContainerIndex;

// menus_settings_assets.cpp
public:
struct SCustomItem
Expand Down
4 changes: 0 additions & 4 deletions src/game/client/components/menus_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ void CMenus::HandleDemoSeeking(float PositionToSeek, float TimeToSeek)
else
DemoPlayer()->SeekPercent(PositionToSeek);
m_pClient->m_SuppressEvents = false;
m_pClient->m_MapLayersBackground.EnvelopeUpdate();
m_pClient->m_MapLayersForeground.EnvelopeUpdate();
if(!DemoPlayer()->BaseInfo()->m_Paused && PositionToSeek == 1.0f)
DemoPlayer()->Pause();
}
Expand All @@ -103,8 +101,6 @@ void CMenus::DemoSeekTick(IDemoPlayer::ETickOffset TickOffset)
DemoPlayer()->SeekTick(TickOffset);
m_pClient->m_SuppressEvents = false;
DemoPlayer()->Pause();
m_pClient->m_MapLayersBackground.EnvelopeUpdate();
m_pClient->m_MapLayersForeground.EnvelopeUpdate();
}

void CMenus::RenderDemoPlayer(CUIRect MainView)
Expand Down
Loading

0 comments on commit 0bd6c30

Please sign in to comment.