4795: Fix binds, fix sounds and demo playback for violent gametypes, do some small refactor r=def- a=Kaffeine

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [x] Tested the change ingame
- [x] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [x] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)

## Bug fixes

### Binds

Default binds (from `CBinds::SetDefaults()`) and the binds loaded from config file are stored in `m_aapKeyBindings[0][key]` while the menu binder store the new binds in `m_aapKeyBindings[1][key]` which results in this:

![image](https://user-images.githubusercontent.com/374839/157233980-a8445e9f-4198-4264-891e-ecb5b67c3210.png)


### Default tuning

It seems that:
1. DDNet re-set tuning params to what meets DDNet needs (e.g. for pulling-beam shotgun) 76cb097997/src/game/client/gameclient.cpp (L3010-L3014)
2. Tuning is saved to the demo if it is custom 76cb097997/src/game/client/gameclient.cpp (L1583-L1590)

This results in incorrect demo playback. Shotgun bullets look like this:

![image](https://user-images.githubusercontent.com/374839/157225950-c7ee31db-57be-41ec-80f6-b50f51576b03.png)

I don't see any negative effect on DDRace demo playback — there should not be any, because servers send DDNet tuning and the client correctly record them.

### Sounds

DDNet provides an option to disable jetpack and crying freezed tee sounds.
76cb097997/src/game/client/gameclient.cpp (L918-L923)

However we should not apply those options for DM/TDM and some other gametypes, because those sounds are critical and not any more annoying than others. E.g. `pain_long` is used if the taken damage is 3+: 93f5bf632a/src/game/server/entities/character.cpp (L777-L780)

## Refactor

[CI: Relax 'package-file' mask](df5c48d675) is my personal request — the file is changed regularly and I always have rebase conflicts here.
The relaxed mask 'll let me to *not* carry this commit in the fork, freeing my time for more fixes.

Co-authored-by: Alexander Akulich <akulichalexander@gmail.com>
This commit is contained in:
bors[bot] 2022-03-08 15:41:37 +00:00 committed by GitHub
commit 65a775b950
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 66 additions and 71 deletions

View file

@ -18,7 +18,7 @@ jobs:
include:
- os: ubuntu-latest
cmake-args: -G Ninja
package-file: DDNet-*-linux_x86_64.tar.xz
package-file: "*-linux_x86_64.tar.xz"
fancy: true
env:
CFLAGS: -Wdeclaration-after-statement -Werror
@ -26,7 +26,7 @@ jobs:
- os: ubuntu-18.04
cmake-path: /usr/bin/
cmake-args: -G Ninja
package-file: DDNet-*-linux_x86_64.tar.xz
package-file: "*-linux_x86_64.tar.xz"
fancy: false
env:
CFLAGS: -Wdeclaration-after-statement -Werror
@ -34,14 +34,14 @@ jobs:
GTEST_FILTER: -*SQLite*
- os: macOS-latest
cmake-args: -G Ninja
package-file: DDNet-*-macos.dmg
package-file: "*-macos.dmg"
fancy: false
env:
CFLAGS: -Wdeclaration-after-statement -Werror
CXXFLAGS: -Werror
- os: windows-latest
cmake-args: -A x64
package-file: DDNet-*-win64.zip
package-file: "*-win64.zip"
fancy: false
env:
CFLAGS: /WX

View file

@ -1902,14 +1902,13 @@ public:
virtual void OnWindowResize()
{
bool FoundTextContainer = false;
for(auto *pTextContainer : m_TextContainers)
if(pTextContainer->m_StringInfo.m_QuadBufferContainerIndex != -1)
FoundTextContainer = true;
if(FoundTextContainer)
{
dbg_msg("textrender", "%s", "Found non empty text container");
dbg_assert(false, "text container was not empty");
if(pTextContainer->m_StringInfo.m_QuadBufferContainerIndex != -1)
{
dbg_msg("textrender", "Found non empty text container with index %d", pTextContainer->m_StringInfo.m_QuadBufferContainerIndex);
dbg_assert(false, "text container was not empty");
}
}
for(auto &pFont : m_Fonts)

View file

@ -306,7 +306,7 @@ CServer::CServer() :
m_aShutdownReason[0] = 0;
for(int i = SIX; i <= SIXUP; i++)
for(int i = 0; i < NUM_MAP_TYPES; i++)
{
m_apCurrentMapData[i] = 0;
m_aCurrentMapSize[i] = 0;
@ -1150,9 +1150,9 @@ void CServer::SendRconType(int ClientID, bool UsernameReq)
void CServer::GetMapInfo(char *pMapName, int MapNameSize, int *pMapSize, SHA256_DIGEST *pMapSha256, int *pMapCrc)
{
str_copy(pMapName, GetMapName(), MapNameSize);
*pMapSize = m_aCurrentMapSize[SIX];
*pMapSha256 = m_aCurrentMapSha256[SIX];
*pMapCrc = m_aCurrentMapCrc[SIX];
*pMapSize = m_aCurrentMapSize[MAP_TYPE_SIX];
*pMapSha256 = m_aCurrentMapSha256[MAP_TYPE_SIX];
*pMapCrc = m_aCurrentMapCrc[MAP_TYPE_SIX];
}
void CServer::SendCapabilities(int ClientID)
@ -1165,25 +1165,25 @@ void CServer::SendCapabilities(int ClientID)
void CServer::SendMap(int ClientID)
{
int Sixup = IsSixup(ClientID);
int MapType = IsSixup(ClientID) ? MAP_TYPE_SIXUP : MAP_TYPE_SIX;
{
CMsgPacker Msg(NETMSG_MAP_DETAILS, true);
Msg.AddString(GetMapName(), 0);
Msg.AddRaw(&m_aCurrentMapSha256[Sixup].data, sizeof(m_aCurrentMapSha256[Sixup].data));
Msg.AddInt(m_aCurrentMapCrc[Sixup]);
Msg.AddInt(m_aCurrentMapSize[Sixup]);
Msg.AddRaw(&m_aCurrentMapSha256[MapType].data, sizeof(m_aCurrentMapSha256[MapType].data));
Msg.AddInt(m_aCurrentMapCrc[MapType]);
Msg.AddInt(m_aCurrentMapSize[MapType]);
SendMsg(&Msg, MSGFLAG_VITAL, ClientID);
}
{
CMsgPacker Msg(NETMSG_MAP_CHANGE, true);
Msg.AddString(GetMapName(), 0);
Msg.AddInt(m_aCurrentMapCrc[Sixup]);
Msg.AddInt(m_aCurrentMapSize[Sixup]);
if(Sixup)
Msg.AddInt(m_aCurrentMapCrc[MapType]);
Msg.AddInt(m_aCurrentMapSize[MapType]);
if(MapType == MAP_TYPE_SIXUP)
{
Msg.AddInt(Config()->m_SvMapWindow);
Msg.AddInt(1024 - 128);
Msg.AddRaw(m_aCurrentMapSha256[Sixup].data, sizeof(m_aCurrentMapSha256[Sixup].data));
Msg.AddRaw(m_aCurrentMapSha256[MapType].data, sizeof(m_aCurrentMapSha256[MapType].data));
}
SendMsg(&Msg, MSGFLAG_VITAL | MSGFLAG_FLUSH, ClientID);
}
@ -1193,30 +1193,30 @@ void CServer::SendMap(int ClientID)
void CServer::SendMapData(int ClientID, int Chunk)
{
int Sixup = IsSixup(ClientID);
int MapType = IsSixup(ClientID) ? MAP_TYPE_SIXUP : MAP_TYPE_SIX;
unsigned int ChunkSize = 1024 - 128;
unsigned int Offset = Chunk * ChunkSize;
int Last = 0;
// drop faulty map data requests
if(Chunk < 0 || Offset > m_aCurrentMapSize[Sixup])
if(Chunk < 0 || Offset > m_aCurrentMapSize[MapType])
return;
if(Offset + ChunkSize >= m_aCurrentMapSize[Sixup])
if(Offset + ChunkSize >= m_aCurrentMapSize[MapType])
{
ChunkSize = m_aCurrentMapSize[Sixup] - Offset;
ChunkSize = m_aCurrentMapSize[MapType] - Offset;
Last = 1;
}
CMsgPacker Msg(NETMSG_MAP_DATA, true);
if(!Sixup)
if(MapType == MAP_TYPE_SIX)
{
Msg.AddInt(Last);
Msg.AddInt(m_aCurrentMapCrc[SIX]);
Msg.AddInt(m_aCurrentMapCrc[MAP_TYPE_SIX]);
Msg.AddInt(Chunk);
Msg.AddInt(ChunkSize);
}
Msg.AddRaw(&m_apCurrentMapData[Sixup][Offset], ChunkSize);
Msg.AddRaw(&m_apCurrentMapData[MapType][Offset], ChunkSize);
SendMsg(&Msg, MSGFLAG_VITAL | MSGFLAG_FLUSH, ClientID);
if(Config()->m_Debug)
@ -1862,8 +1862,8 @@ void CServer::CacheServerInfo(CCache *pCache, int Type, bool SendClients)
if(Type == SERVERINFO_EXTENDED)
{
ADD_INT(p, m_aCurrentMapCrc[SIX]);
ADD_INT(p, m_aCurrentMapSize[SIX]);
ADD_INT(p, m_aCurrentMapCrc[MAP_TYPE_SIX]);
ADD_INT(p, m_aCurrentMapSize[MAP_TYPE_SIX]);
}
// gametype
@ -2334,11 +2334,11 @@ int CServer::LoadMap(const char *pMapName)
m_IDPool.TimeoutIDs();
// get the crc of the map
m_aCurrentMapSha256[SIX] = m_pMap->Sha256();
m_aCurrentMapCrc[SIX] = m_pMap->Crc();
m_aCurrentMapSha256[MAP_TYPE_SIX] = m_pMap->Sha256();
m_aCurrentMapCrc[MAP_TYPE_SIX] = m_pMap->Crc();
char aBufMsg[256];
char aSha256[SHA256_MAXSTRSIZE];
sha256_str(m_aCurrentMapSha256[SIX], aSha256, sizeof(aSha256));
sha256_str(m_aCurrentMapSha256[MAP_TYPE_SIX], aSha256, sizeof(aSha256));
str_format(aBufMsg, sizeof(aBufMsg), "%s sha256 is %s", aBuf, aSha256);
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "server", aBufMsg);
@ -2347,10 +2347,10 @@ int CServer::LoadMap(const char *pMapName)
// load complete map into memory for download
{
IOHANDLE File = Storage()->OpenFile(aBuf, IOFLAG_READ, IStorage::TYPE_ALL);
m_aCurrentMapSize[SIX] = (unsigned int)io_length(File);
free(m_apCurrentMapData[SIX]);
m_apCurrentMapData[SIX] = (unsigned char *)malloc(m_aCurrentMapSize[SIX]);
io_read(File, m_apCurrentMapData[SIX], m_aCurrentMapSize[SIX]);
m_aCurrentMapSize[MAP_TYPE_SIX] = (unsigned int)io_length(File);
free(m_apCurrentMapData[MAP_TYPE_SIX]);
m_apCurrentMapData[MAP_TYPE_SIX] = (unsigned char *)malloc(m_aCurrentMapSize[MAP_TYPE_SIX]);
io_read(File, m_apCurrentMapData[MAP_TYPE_SIX], m_aCurrentMapSize[MAP_TYPE_SIX]);
io_close(File);
}
@ -2368,23 +2368,23 @@ int CServer::LoadMap(const char *pMapName)
}
else
{
m_aCurrentMapSize[SIXUP] = (unsigned int)io_length(File);
free(m_apCurrentMapData[SIXUP]);
m_apCurrentMapData[SIXUP] = (unsigned char *)malloc(m_aCurrentMapSize[SIXUP]);
io_read(File, m_apCurrentMapData[SIXUP], m_aCurrentMapSize[SIXUP]);
m_aCurrentMapSize[MAP_TYPE_SIXUP] = (unsigned int)io_length(File);
free(m_apCurrentMapData[MAP_TYPE_SIXUP]);
m_apCurrentMapData[MAP_TYPE_SIXUP] = (unsigned char *)malloc(m_aCurrentMapSize[MAP_TYPE_SIXUP]);
io_read(File, m_apCurrentMapData[MAP_TYPE_SIXUP], m_aCurrentMapSize[MAP_TYPE_SIXUP]);
io_close(File);
m_aCurrentMapSha256[SIXUP] = sha256(m_apCurrentMapData[SIXUP], m_aCurrentMapSize[SIXUP]);
m_aCurrentMapCrc[SIXUP] = crc32(0, m_apCurrentMapData[SIXUP], m_aCurrentMapSize[SIXUP]);
sha256_str(m_aCurrentMapSha256[SIXUP], aSha256, sizeof(aSha256));
m_aCurrentMapSha256[MAP_TYPE_SIXUP] = sha256(m_apCurrentMapData[MAP_TYPE_SIXUP], m_aCurrentMapSize[MAP_TYPE_SIXUP]);
m_aCurrentMapCrc[MAP_TYPE_SIXUP] = crc32(0, m_apCurrentMapData[MAP_TYPE_SIXUP], m_aCurrentMapSize[MAP_TYPE_SIXUP]);
sha256_str(m_aCurrentMapSha256[MAP_TYPE_SIXUP], aSha256, sizeof(aSha256));
str_format(aBufMsg, sizeof(aBufMsg), "%s sha256 is %s", aBuf, aSha256);
Console()->Print(IConsole::OUTPUT_LEVEL_ADDINFO, "sixup", aBufMsg);
}
}
if(!Config()->m_SvSixup)
{
free(m_apCurrentMapData[SIXUP]);
m_apCurrentMapData[SIXUP] = 0;
free(m_apCurrentMapData[MAP_TYPE_SIXUP]);
m_apCurrentMapData[MAP_TYPE_SIXUP] = 0;
}
for(int i = 0; i < MAX_CLIENTS; i++)
@ -3137,7 +3137,7 @@ void CServer::DemoRecorder_HandleAutoStart()
char aDate[20];
str_timestamp(aDate, sizeof(aDate));
str_format(aFilename, sizeof(aFilename), "demos/%s_%s.demo", "auto/autorecord", aDate);
m_aDemoRecorder[MAX_CLIENTS].Start(Storage(), m_pConsole, aFilename, GameServer()->NetVersion(), m_aCurrentMap, &m_aCurrentMapSha256[SIX], m_aCurrentMapCrc[SIX], "server", m_aCurrentMapSize[SIX], m_apCurrentMapData[SIX]);
m_aDemoRecorder[MAX_CLIENTS].Start(Storage(), m_pConsole, aFilename, GameServer()->NetVersion(), m_aCurrentMap, &m_aCurrentMapSha256[MAP_TYPE_SIX], m_aCurrentMapCrc[MAP_TYPE_SIX], "server", m_aCurrentMapSize[MAP_TYPE_SIX], m_apCurrentMapData[MAP_TYPE_SIX]);
if(Config()->m_SvAutoDemoMax)
{
// clean up auto recorded demos
@ -3173,7 +3173,7 @@ void CServer::StartRecord(int ClientID)
{
char aFilename[IO_MAX_PATH_LENGTH];
str_format(aFilename, sizeof(aFilename), "demos/%s_%d_%d_tmp.demo", m_aCurrentMap, m_NetServer.Address().port, ClientID);
m_aDemoRecorder[ClientID].Start(Storage(), Console(), aFilename, GameServer()->NetVersion(), m_aCurrentMap, &m_aCurrentMapSha256[SIX], m_aCurrentMapCrc[SIX], "server", m_aCurrentMapSize[SIX], m_apCurrentMapData[SIX]);
m_aDemoRecorder[ClientID].Start(Storage(), Console(), aFilename, GameServer()->NetVersion(), m_aCurrentMap, &m_aCurrentMapSha256[MAP_TYPE_SIX], m_aCurrentMapCrc[MAP_TYPE_SIX], "server", m_aCurrentMapSize[MAP_TYPE_SIX], m_apCurrentMapData[MAP_TYPE_SIX]);
}
}
@ -3207,7 +3207,7 @@ void CServer::ConRecord(IConsole::IResult *pResult, void *pUser)
str_timestamp(aDate, sizeof(aDate));
str_format(aFilename, sizeof(aFilename), "demos/demo_%s.demo", aDate);
}
pServer->m_aDemoRecorder[MAX_CLIENTS].Start(pServer->Storage(), pServer->Console(), aFilename, pServer->GameServer()->NetVersion(), pServer->m_aCurrentMap, &pServer->m_aCurrentMapSha256[SIX], pServer->m_aCurrentMapCrc[SIX], "server", pServer->m_aCurrentMapSize[SIX], pServer->m_apCurrentMapData[SIX]);
pServer->m_aDemoRecorder[MAX_CLIENTS].Start(pServer->Storage(), pServer->Console(), aFilename, pServer->GameServer()->NetVersion(), pServer->m_aCurrentMap, &pServer->m_aCurrentMapSha256[MAP_TYPE_SIX], pServer->m_aCurrentMapCrc[MAP_TYPE_SIX], "server", pServer->m_aCurrentMapSize[MAP_TYPE_SIX], pServer->m_apCurrentMapData[MAP_TYPE_SIX]);
}
void CServer::ConStopRecord(IConsole::IResult *pResult, void *pUser)
@ -3490,7 +3490,7 @@ void CServer::ConchainSixupUpdate(IConsole::IResult *pResult, void *pUserData, I
pfnCallback(pResult, pCallbackUserData);
CServer *pThis = static_cast<CServer *>(pUserData);
if(pResult->NumArguments() >= 1 && pThis->m_aCurrentMap[0] != '\0')
pThis->m_MapReload |= (pThis->m_apCurrentMapData[SIXUP] != 0) != (pResult->GetInteger(0) != 0);
pThis->m_MapReload |= (pThis->m_apCurrentMapData[MAP_TYPE_SIXUP] != 0) != (pResult->GetInteger(0) != 0);
}
#if defined(CONF_FAMILY_UNIX)

View file

@ -235,15 +235,16 @@ public:
enum
{
SIX = 0,
SIXUP,
MAP_TYPE_SIX = 0,
MAP_TYPE_SIXUP,
NUM_MAP_TYPES
};
char m_aCurrentMap[IO_MAX_PATH_LENGTH];
SHA256_DIGEST m_aCurrentMapSha256[2];
unsigned m_aCurrentMapCrc[2];
unsigned char *m_apCurrentMapData[2];
unsigned int m_aCurrentMapSize[2];
SHA256_DIGEST m_aCurrentMapSha256[NUM_MAP_TYPES];
unsigned m_aCurrentMapCrc[NUM_MAP_TYPES];
unsigned char *m_apCurrentMapData[NUM_MAP_TYPES];
unsigned int m_aCurrentMapSize[NUM_MAP_TYPES];
CDemoRecorder m_aDemoRecorder[MAX_CLIENTS + 1];
CRegister m_Register;

View file

@ -101,9 +101,6 @@ int CBinds::GetModifierMask(IInput *i)
}
}
if(!Mask)
return 1 << CBinds::MODIFIER_NONE;
return Mask;
}
@ -137,8 +134,6 @@ bool CBinds::OnInput(IInput::CEvent e)
int Mask = GetModifierMask(Input());
int KeyModifierMask = GetModifierMaskOfKey(e.m_Key);
Mask &= ~KeyModifierMask;
if(!Mask)
Mask = 1 << MODIFIER_NONE;
bool ret = false;
for(int Mod = 1; Mod < MODIFIER_COMBINATION_COUNT; Mod++)

View file

@ -550,8 +550,6 @@ void CPlayers::RenderPlayer(
RenderTools()->RenderTee(&State, &Ghost, Player.m_Emote, Direction, GhostPosition, 0.5f); // render ghost
}
RenderInfo.m_Size = 64.0f; // force some settings
RenderTools()->RenderTee(&State, &RenderInfo, Player.m_Emote, Direction, Position, Alpha);
int QuadOffsetToEmoticon = NUM_WEAPONS * 2 + 2 + 2;

View file

@ -918,8 +918,13 @@ void CGameClient::ProcessEvents()
else if(Item.m_Type == NETEVENTTYPE_SOUNDWORLD)
{
CNetEvent_SoundWorld *ev = (CNetEvent_SoundWorld *)pData;
if(g_Config.m_SndGame && (ev->m_SoundID != SOUND_GUN_FIRE || g_Config.m_SndGun) && (ev->m_SoundID != SOUND_PLAYER_PAIN_LONG || g_Config.m_SndLongPain))
m_Sounds.PlayAt(CSounds::CHN_WORLD, ev->m_SoundID, 1.0f, vec2(ev->m_X, ev->m_Y));
if(!Config()->m_SndGame)
continue;
if(m_GameInfo.m_RaceSounds && ((ev->m_SoundID == SOUND_GUN_FIRE && !g_Config.m_SndGun) || (ev->m_SoundID == SOUND_PLAYER_PAIN_LONG && !g_Config.m_SndLongPain)))
continue;
m_Sounds.PlayAt(CSounds::CHN_WORLD, ev->m_SoundID, 1.0f, vec2(ev->m_X, ev->m_Y));
}
}
}
@ -996,6 +1001,7 @@ static CGameInfo GetGameInfo(const CNetObj_GameInfoEx *pInfoEx, int InfoExSize,
Info.m_UnlimitedAmmo = Race;
Info.m_DDRaceRecordMessage = DDRace && !DDNet;
Info.m_RaceRecordMessage = DDNet || (Race && !DDRace);
Info.m_RaceSounds = DDRace || FNG;
Info.m_AllowEyeWheel = DDRace || BlockWorlds || City || Plus;
Info.m_AllowHookColl = DDRace;
Info.m_AllowZoom = Race || BlockWorlds || City;
@ -3007,11 +3013,6 @@ void CGameClient::LoadMapSettings()
for(int i = 0; i < NUM_TUNEZONES; i++)
{
TuningList()[i] = TuningParams;
TuningList()[i].Set("gun_curvature", 0);
TuningList()[i].Set("gun_speed", 1400);
TuningList()[i].Set("shotgun_curvature", 0);
TuningList()[i].Set("shotgun_speed", 500);
TuningList()[i].Set("shotgun_speeddiff", 0);
}
// Load map tunings

View file

@ -63,6 +63,7 @@ public:
bool m_UnlimitedAmmo;
bool m_DDRaceRecordMessage;
bool m_RaceRecordMessage;
bool m_RaceSounds;
bool m_AllowEyeWheel;
bool m_AllowHookColl;