Skip to content

Commit

Permalink
Merge branch 'insta' of https://github.com/ZillyInsta/ddnet-insta int…
Browse files Browse the repository at this point in the history
…o insta
  • Loading branch information
M0REKZ committed May 17, 2024
2 parents 37ca38d + 19c8abe commit d291d84
Show file tree
Hide file tree
Showing 22 changed files with 166 additions and 161 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3095,6 +3095,7 @@ if(TOOLS)
demo_extract_chat
dilate
map_convert_07
map_create_pixelart
map_diff
map_extract
)
Expand Down
2 changes: 1 addition & 1 deletion scripts/integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ then
echo "[-] Error: demo playback of client demo in client 2 was not started/finished"
fi

ranks="$(sqlite3 ddnet-server.sqlite < <(echo "select * from record_race;"))"
ranks="$(sqlite3 -cmd '.timeout 10000' ddnet-server.sqlite < <(echo "select * from record_race;"))"
rank_time="$(echo "$ranks" | awk -F '|' '{ print "player:", $2, "time:", $4, "cps:", $6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28 }')"
expected_times="\
player: client2 time: 1020.98 cps: 0.02 0.1 0.2 0.26 0.32 600.36 600.42 600.46 600.5 1020.54 1020.58 1020.6 1020.64 1020.66 1020.7 1020.72 1020.76 1020.78 1020.8 1020.84 1020.86 1020.88 1020.9
Expand Down
6 changes: 2 additions & 4 deletions scripts/languages/copy_fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ def copy_fix(infile, delete_unused, append_missing, delete_empty):
with open(infile, encoding="utf-8") as f:
content = f.readlines()
trans = twlang.translations(infile)
if delete_unused or append_missing:
local = twlang.localizes()
if append_missing:
supported = []
local = twlang.localizes()
supported = []
for tran, (start, expr, end) in trans.items():
if delete_unused and tran not in local:
content[start:end] = [None]*(end-start)
Expand Down
2 changes: 1 addition & 1 deletion src/base/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2613,7 +2613,7 @@ int net_socket_read_wait(NETSOCKET sock, int time)
return 0;
}

int time_timestamp()
int64_t time_timestamp()
{
return time(0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/base/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,7 @@ int64_t time_freq();
*
* @return The time as a UNIX timestamp
*/
int time_timestamp();
int64_t time_timestamp();

/**
* Retrieves the hours since midnight (0..23)
Expand Down
78 changes: 37 additions & 41 deletions src/engine/client/backend/vulkan/backend_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,8 +986,6 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase
std::vector<VkSemaphore> m_vWaitSemaphores;
std::vector<VkSemaphore> m_vSigSemaphores;

std::vector<VkSemaphore> m_vMemorySemaphores;

std::vector<VkFence> m_vFrameFences;
std::vector<VkFence> m_vImagesFences;

Expand Down Expand Up @@ -1053,7 +1051,7 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase
std::vector<SStreamMemory<SFrameBuffers>> m_vStreamedVertexBuffers;
std::vector<SStreamMemory<SFrameUniformBuffers>> m_vStreamedUniformBuffers;

uint32_t m_CurFrames = 0;
uint32_t m_CurFrameSyncObject = 0;
uint32_t m_CurImageIndex = 0;

uint32_t m_CanvasWidth;
Expand Down Expand Up @@ -2275,7 +2273,7 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase
return false;
}

VkSemaphore WaitSemaphore = m_vWaitSemaphores[m_CurFrames];
VkSemaphore WaitSemaphore = m_vWaitSemaphores[m_CurFrameSyncObject];

VkSubmitInfo SubmitInfo{};
SubmitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
Expand Down Expand Up @@ -2304,13 +2302,13 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase
SubmitInfo.pWaitSemaphores = aWaitSemaphores.data();
SubmitInfo.pWaitDstStageMask = aWaitStages.data();

std::array<VkSemaphore, 1> aSignalSemaphores = {m_vSigSemaphores[m_CurFrames]};
std::array<VkSemaphore, 1> aSignalSemaphores = {m_vSigSemaphores[m_CurFrameSyncObject]};
SubmitInfo.signalSemaphoreCount = aSignalSemaphores.size();
SubmitInfo.pSignalSemaphores = aSignalSemaphores.data();

vkResetFences(m_VKDevice, 1, &m_vFrameFences[m_CurFrames]);
vkResetFences(m_VKDevice, 1, &m_vFrameFences[m_CurFrameSyncObject]);

VkResult QueueSubmitRes = vkQueueSubmit(m_VKGraphicsQueue, 1, &SubmitInfo, m_vFrameFences[m_CurFrames]);
VkResult QueueSubmitRes = vkQueueSubmit(m_VKGraphicsQueue, 1, &SubmitInfo, m_vFrameFences[m_CurFrameSyncObject]);
if(QueueSubmitRes != VK_SUCCESS)
{
const char *pCritErrorMsg = CheckVulkanCriticalError(QueueSubmitRes);
Expand All @@ -2321,7 +2319,7 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase
}
}

std::swap(m_vWaitSemaphores[m_CurFrames], m_vSigSemaphores[m_CurFrames]);
std::swap(m_vWaitSemaphores[m_CurFrameSyncObject], m_vSigSemaphores[m_CurFrameSyncObject]);

VkPresentInfoKHR PresentInfo{};
PresentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
Expand All @@ -2348,7 +2346,7 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase
}
}

m_CurFrames = (m_CurFrames + 1) % m_SwapChainImageCount;
m_CurFrameSyncObject = (m_CurFrameSyncObject + 1) % m_vWaitSemaphores.size();
return true;
}

Expand All @@ -2364,7 +2362,7 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase
RecreateSwapChain();
}

auto AcqResult = vkAcquireNextImageKHR(m_VKDevice, m_VKSwapChain, std::numeric_limits<uint64_t>::max(), m_vSigSemaphores[m_CurFrames], VK_NULL_HANDLE, &m_CurImageIndex);
auto AcqResult = vkAcquireNextImageKHR(m_VKDevice, m_VKSwapChain, std::numeric_limits<uint64_t>::max(), m_vSigSemaphores[m_CurFrameSyncObject], VK_NULL_HANDLE, &m_CurImageIndex);
if(AcqResult != VK_SUCCESS)
{
if(AcqResult == VK_ERROR_OUT_OF_DATE_KHR || m_RecreateSwapChain)
Expand Down Expand Up @@ -2395,13 +2393,13 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase
}
}
}
std::swap(m_vWaitSemaphores[m_CurFrames], m_vSigSemaphores[m_CurFrames]);
std::swap(m_vWaitSemaphores[m_CurFrameSyncObject], m_vSigSemaphores[m_CurFrameSyncObject]);

if(m_vImagesFences[m_CurImageIndex] != VK_NULL_HANDLE)
{
vkWaitForFences(m_VKDevice, 1, &m_vImagesFences[m_CurImageIndex], VK_TRUE, std::numeric_limits<uint64_t>::max());
}
m_vImagesFences[m_CurImageIndex] = m_vFrameFences[m_CurFrames];
m_vImagesFences[m_CurImageIndex] = m_vFrameFences[m_CurFrameSyncObject];

// next frame
m_CurFrame++;
Expand Down Expand Up @@ -5333,12 +5331,12 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase

[[nodiscard]] bool CreateSyncObjects()
{
m_vWaitSemaphores.resize(m_SwapChainImageCount);
m_vSigSemaphores.resize(m_SwapChainImageCount);

m_vMemorySemaphores.resize(m_SwapChainImageCount);
// Create one more sync object than there are frames in flight
auto SyncObjectCount = m_SwapChainImageCount + 1;
m_vWaitSemaphores.resize(SyncObjectCount);
m_vSigSemaphores.resize(SyncObjectCount);

m_vFrameFences.resize(m_SwapChainImageCount);
m_vFrameFences.resize(SyncObjectCount);
m_vImagesFences.resize(m_SwapChainImageCount, VK_NULL_HANDLE);

VkSemaphoreCreateInfo CreateSemaphoreInfo{};
Expand All @@ -5348,11 +5346,10 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase
FenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
FenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;

for(size_t i = 0; i < m_SwapChainImageCount; i++)
for(size_t i = 0; i < SyncObjectCount; i++)
{
if(vkCreateSemaphore(m_VKDevice, &CreateSemaphoreInfo, nullptr, &m_vWaitSemaphores[i]) != VK_SUCCESS ||
vkCreateSemaphore(m_VKDevice, &CreateSemaphoreInfo, nullptr, &m_vSigSemaphores[i]) != VK_SUCCESS ||
vkCreateSemaphore(m_VKDevice, &CreateSemaphoreInfo, nullptr, &m_vMemorySemaphores[i]) != VK_SUCCESS ||
vkCreateFence(m_VKDevice, &FenceInfo, nullptr, &m_vFrameFences[i]) != VK_SUCCESS)
{
SetError(EGfxErrorType::GFX_ERROR_TYPE_INIT, "Creating swap chain sync objects(fences, semaphores) failed.");
Expand All @@ -5365,21 +5362,20 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase

void DestroySyncObjects()
{
for(size_t i = 0; i < m_SwapChainImageCount; i++)
for(size_t i = 0; i < m_vWaitSemaphores.size(); i++)
{
vkDestroySemaphore(m_VKDevice, m_vWaitSemaphores[i], nullptr);
vkDestroySemaphore(m_VKDevice, m_vSigSemaphores[i], nullptr);
vkDestroySemaphore(m_VKDevice, m_vMemorySemaphores[i], nullptr);
vkDestroyFence(m_VKDevice, m_vFrameFences[i], nullptr);
}

m_vWaitSemaphores.clear();
m_vSigSemaphores.clear();

m_vMemorySemaphores.clear();

m_vFrameFences.clear();
m_vImagesFences.clear();

m_CurFrameSyncObject = 0;
}

void DestroyBufferOfFrame(size_t ImageIndex, SFrameBuffers &Buffer)
Expand Down Expand Up @@ -5433,7 +5429,7 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase
}

template<bool IsLastCleanup>
void CleanupVulkan()
void CleanupVulkan(size_t SwapchainCount)
{
if(IsLastCleanup)
{
Expand Down Expand Up @@ -5471,7 +5467,7 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase
m_vStreamedVertexBuffers.clear();
m_vStreamedUniformBuffers.clear();

for(size_t i = 0; i < m_SwapChainImageCount; ++i)
for(size_t i = 0; i < SwapchainCount; ++i)
{
ClearFrameData(i);
}
Expand All @@ -5480,11 +5476,11 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase
m_vvFrameDelayedTextureCleanup.clear();
m_vvFrameDelayedTextTexturesCleanup.clear();

m_StagingBufferCache.DestroyFrameData(m_SwapChainImageCount);
m_StagingBufferCacheImage.DestroyFrameData(m_SwapChainImageCount);
m_VertexBufferCache.DestroyFrameData(m_SwapChainImageCount);
m_StagingBufferCache.DestroyFrameData(SwapchainCount);
m_StagingBufferCacheImage.DestroyFrameData(SwapchainCount);
m_VertexBufferCache.DestroyFrameData(SwapchainCount);
for(auto &ImageBufferCache : m_ImageBufferCaches)
ImageBufferCache.second.DestroyFrameData(m_SwapChainImageCount);
ImageBufferCache.second.DestroyFrameData(SwapchainCount);

if(IsLastCleanup)
{
Expand Down Expand Up @@ -5562,7 +5558,7 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase

if(OldSwapChainImageCount != m_SwapChainImageCount)
{
CleanupVulkan<false>();
CleanupVulkan<false>(OldSwapChainImageCount);
InitVulkan<false>();
}

Expand Down Expand Up @@ -6116,20 +6112,20 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase
template<bool IsFirstInitialization>
int InitVulkan()
{
if(!CreateDescriptorSetLayouts())
return -1;
if(IsFirstInitialization)
{
if(!CreateDescriptorSetLayouts())
return -1;

if(!CreateTextDescriptorSetLayout())
return -1;
if(!CreateTextDescriptorSetLayout())
return -1;

if(!CreateSpriteMultiUniformDescriptorSetLayout())
return -1;
if(!CreateSpriteMultiUniformDescriptorSetLayout())
return -1;

if(!CreateQuadUniformDescriptorSetLayout())
return -1;
if(!CreateQuadUniformDescriptorSetLayout())
return -1;

if(IsFirstInitialization)
{
VkSwapchainKHR OldSwapChain = VK_NULL_HANDLE;
if(InitVulkanSwapChain(OldSwapChain) != 0)
return -1;
Expand Down Expand Up @@ -6626,7 +6622,7 @@ class CCommandProcessorFragment_Vulkan : public CCommandProcessorFragment_GLBase
DestroyIndexBuffer(m_IndexBuffer, m_IndexBufferMemory);
DestroyIndexBuffer(m_RenderIndexBuffer, m_RenderIndexBufferMemory);

CleanupVulkan<true>();
CleanupVulkan<true>(m_SwapChainImageCount);

return true;
}
Expand Down
7 changes: 0 additions & 7 deletions src/engine/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,6 @@ class CImageInfo
{
return m_Width * m_Height * PixelSize(m_Format);
}

static EImageFormat ImageFormatFromInt(int Format)
{
if(Format < (int)FORMAT_RGB || Format > (int)FORMAT_SINGLE_COMPONENT)
return FORMAT_ERROR;
return (EImageFormat)Format;
}
};

/*
Expand Down
1 change: 1 addition & 0 deletions src/engine/shared/config_variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ MACRO_CONFIG_INT(ClShowNotifications, cl_shownotifications, 1, 0, 1, CFGFLAG_CLI
MACRO_CONFIG_INT(ClShowEmotes, cl_showemotes, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Show tee emotes")
MACRO_CONFIG_INT(ClShowChat, cl_showchat, 1, 0, 2, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Show chat (2 to always show large chat area)")
MACRO_CONFIG_INT(ClShowChatFriends, cl_show_chat_friends, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Show only chat messages from friends")
MACRO_CONFIG_INT(ClShowChatTeamMembersOnly, cl_show_chat_team_members_only, 0, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Show only chat messages from team members")
MACRO_CONFIG_INT(ClShowChatSystem, cl_show_chat_system, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Show chat messages from the server")
MACRO_CONFIG_INT(ClShowKillMessages, cl_showkillmessages, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Show kill messages")
MACRO_CONFIG_INT(ClShowFinishMessages, cl_show_finish_messages, 1, 0, 1, CFGFLAG_CLIENT | CFGFLAG_SAVE, "Show finish messages")
Expand Down
6 changes: 3 additions & 3 deletions src/engine/shared/netban.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ int CNetBan::Ban(T *pBanPool, const typename T::CDataType *pData, int Seconds, c
return -1;
}

int Stamp = Seconds > 0 ? time_timestamp() + Seconds : CBanInfo::EXPIRES_NEVER;
int64_t Stamp = Seconds > 0 ? time_timestamp() + Seconds : static_cast<int64_t>(CBanInfo::EXPIRES_NEVER);

// set up info
CBanInfo Info = {0};
Expand Down Expand Up @@ -290,7 +290,7 @@ void CNetBan::Init(IConsole *pConsole, IStorage *pStorage)

void CNetBan::Update()
{
int Now = time_timestamp();
int64_t Now = time_timestamp();

// remove expired bans
char aBuf[256], aNetStr[256];
Expand Down Expand Up @@ -522,7 +522,7 @@ void CNetBan::ConBansSave(IConsole::IResult *pResult, void *pUser)
return;
}

int Now = time_timestamp();
int64_t Now = time_timestamp();
char aAddrStr1[NETADDR_MAXSTRSIZE], aAddrStr2[NETADDR_MAXSTRSIZE];
for(CBanAddr *pBan = pThis->m_BanAddrPool.First(); pBan; pBan = pBan->m_pNext)
{
Expand Down
2 changes: 1 addition & 1 deletion src/engine/shared/netban.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class CNetBan
EXPIRES_NEVER = -1,
REASON_LENGTH = 64,
};
int m_Expires;
int64_t m_Expires;
char m_aReason[REASON_LENGTH];
};

Expand Down
27 changes: 21 additions & 6 deletions src/game/client/components/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ CCamera::CCamera()
m_ZoomSet = false;
m_Zoom = 1.0f;
m_Zooming = false;
m_ForceFreeviewPos = vec2(-1, -1);
m_ForceFreeview = false;
m_GotoSwitchOffset = 0;
m_GotoTeleOffset = 0;
m_GotoSwitchLastPos = ivec2(-1, -1);
Expand Down Expand Up @@ -177,11 +177,14 @@ void CCamera::OnRender()
m_Center = m_pClient->m_LocalCharacterPos + s_aCurrentCameraOffset[g_Config.m_ClDummy];
}

if(m_ForceFreeviewPos != vec2(-1, -1) && m_CamType == CAMTYPE_SPEC)
if(m_ForceFreeview && m_CamType == CAMTYPE_SPEC)
{
m_Center = m_pClient->m_Controls.m_aMousePos[g_Config.m_ClDummy] = m_ForceFreeviewPos;
m_ForceFreeviewPos = vec2(-1, -1);
m_ForceFreeview = false;
}
else
m_ForceFreeviewPos = m_Center;

m_PrevCenter = m_Center;
}

Expand All @@ -191,6 +194,7 @@ void CCamera::OnConsoleInit()
Console()->Register("zoom-", "", CFGFLAG_CLIENT, ConZoomMinus, this, "Zoom decrease");
Console()->Register("zoom", "?i", CFGFLAG_CLIENT, ConZoom, this, "Change zoom");
Console()->Register("set_view", "i[x]i[y]", CFGFLAG_CLIENT, ConSetView, this, "Set camera position to x and y in the map");
Console()->Register("set_view_relative", "i[x]i[y]", CFGFLAG_CLIENT, ConSetViewRelative, this, "Set camera position relative to current view in the map");
Console()->Register("goto_switch", "i[number]?i[offset]", CFGFLAG_CLIENT, ConGotoSwitch, this, "View switch found (at offset) with given number");
Console()->Register("goto_tele", "i[number]?i[offset]", CFGFLAG_CLIENT, ConGotoTele, this, "View tele found (at offset) with given number");
}
Expand Down Expand Up @@ -238,6 +242,12 @@ void CCamera::ConSetView(IConsole::IResult *pResult, void *pUserData)
// wait until free view camera type to update the position
pSelf->SetView(ivec2(pResult->GetInteger(0), pResult->GetInteger(1)));
}
void CCamera::ConSetViewRelative(IConsole::IResult *pResult, void *pUserData)
{
CCamera *pSelf = (CCamera *)pUserData;
// wait until free view camera type to update the position
pSelf->SetView(ivec2(pResult->GetInteger(0), pResult->GetInteger(1)), true);
}
void CCamera::ConGotoSwitch(IConsole::IResult *pResult, void *pUserData)
{
CCamera *pSelf = (CCamera *)pUserData;
Expand All @@ -249,11 +259,16 @@ void CCamera::ConGotoTele(IConsole::IResult *pResult, void *pUserData)
pSelf->GotoTele(pResult->GetInteger(0), pResult->NumArguments() > 1 ? pResult->GetInteger(1) : -1);
}

void CCamera::SetView(ivec2 Pos)
void CCamera::SetView(ivec2 Pos, bool Relative)
{
vec2 RealPos = vec2(Pos.x * 32.0, Pos.y * 32.0);
vec2 UntestedViewPos = Relative ? m_ForceFreeviewPos + RealPos : RealPos;

m_ForceFreeview = true;

m_ForceFreeviewPos = vec2(
clamp(Pos.x * 32.0f, 200.0f, Collision()->GetWidth() * 32 - 200.0f),
clamp(Pos.y * 32.0f, 200.0f, Collision()->GetWidth() * 32 - 200.0f));
clamp(UntestedViewPos.x, 200.0f, Collision()->GetWidth() * 32 - 200.0f),
clamp(UntestedViewPos.y, 200.0f, Collision()->GetWidth() * 32 - 200.0f));
}

void CCamera::GotoSwitch(int Number, int Offset)
Expand Down
Loading

0 comments on commit d291d84

Please sign in to comment.