Better skin colors. Better game message translation

This commit is contained in:
Learath 2020-06-14 20:32:14 +03:00
parent 1514a6df85
commit 9e2434c65d
9 changed files with 134 additions and 55 deletions

View file

@ -40,6 +40,10 @@ def output_map(name, map):
print("inline int {0}(int a) {{ if(a < 0 || a >= {1}) return -1; return gs_{0}[a]; }}".format(name, len(map))) print("inline int {0}(int a) {{ if(a < 0 || a >= {1}) return -1; return gs_{0}[a]; }}".format(name, len(map)))
def main(): def main():
guard = "GAME_GENERATED_PROTOCOLGLUE"
print("#ifndef " + guard)
print("#define " + guard)
msgs = get_msgs() msgs = get_msgs()
msgs7 = get_msgs_7() msgs7 = get_msgs_7()
@ -51,5 +55,7 @@ def main():
output_map("Obj_SixToSeven", generate_map(objs, objs7)) output_map("Obj_SixToSeven", generate_map(objs, objs7))
output_map("Obj_SevenToSix", generate_map(objs7, objs)) output_map("Obj_SevenToSix", generate_map(objs7, objs))
print("#endif //" + guard)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View file

@ -115,6 +115,21 @@ if gen_network_header:
for l in create_enum_table(["NETMSG_INVALID"]+[o.enum_name for o in network.Messages], "NUM_NETMSGTYPES"): print(l) for l in create_enum_table(["NETMSG_INVALID"]+[o.enum_name for o in network.Messages], "NUM_NETMSGTYPES"): print(l)
print("") print("")
print("""
template<class...>
using void_t = void;
template<typename T, typename = void>
struct is_sixup {
constexpr static bool value = false;
};
template<typename T>
struct is_sixup<T, void_t<typename T::is_sixup>> {
constexpr static bool value = true;
};
""")
for item in network.Objects + network.Messages: for item in network.Objects + network.Messages:
for line in item.emit_declaration(): for line in item.emit_declaration():
print(line) print(line)

View file

@ -268,6 +268,7 @@ class NetMessage(NetObject):
return lines return lines
def emit_declaration(self): def emit_declaration(self):
extra = [] extra = []
extra += ["\tusing is_sixup = char;"]
extra += ["\tint MsgID() const { return %s; }" % self.enum_name] extra += ["\tint MsgID() const { return %s; }" % self.enum_name]
extra += ["\t"] extra += ["\t"]
extra += ["\tbool Pack(CMsgPacker *pPacker)"] extra += ["\tbool Pack(CMsgPacker *pPacker)"]

View file

@ -136,6 +136,20 @@ public:
else else
return color4_base::Pack(Alpha); return color4_base::Pack(Alpha);
} }
unsigned Pack7()
{
if(m_Lit)
{
float Darkest = 61.0f/255.0f;
ColorHSLA Dark = *this;
Dark.l = (l - Darkest)/(1 - Darkest);
Dark.m_Lit = false;
return Dark.Pack7();
}
else
return color4_base::Pack(false);
}
}; };
class ColorHSVA : public color4_base<ColorHSVA> class ColorHSVA : public color4_base<ColorHSVA>

View file

@ -11,7 +11,8 @@ class CMsgPacker : public CPacker
public: public:
int m_MsgID; int m_MsgID;
bool m_System; bool m_System;
CMsgPacker(int Type, bool System=false) : m_MsgID(Type), m_System(System) bool m_NoTranslate;
CMsgPacker(int Type, bool System = false, bool NoTranslate = false) : m_MsgID(Type), m_System(System), m_NoTranslate(NoTranslate)
{ {
Reset(); Reset();
} }

View file

@ -10,6 +10,7 @@
#include "message.h" #include "message.h"
#include <game/generated/protocol.h> #include <game/generated/protocol.h>
#include <game/generated/protocol7.h> #include <game/generated/protocol7.h>
#include <game/generated/protocolglue.h>
#include <engine/shared/protocol.h> #include <engine/shared/protocol.h>
struct CAntibotRoundData; struct CAntibotRoundData;
@ -118,7 +119,8 @@ public:
template<class T> template<class T>
int SendPackMsgOne(T *pMsg, int Flags, int ClientID) int SendPackMsgOne(T *pMsg, int Flags, int ClientID)
{ {
CMsgPacker Packer(pMsg->MsgID(), false); CMsgPacker Packer(pMsg->MsgID(), false, protocol7::is_sixup<T>::value);
if(pMsg->Pack(&Packer)) if(pMsg->Pack(&Packer))
return -1; return -1;
return SendMsg(&Packer, Flags, ClientID); return SendMsg(&Packer, Flags, ClientID);

View file

@ -652,7 +652,7 @@ static inline bool RepackMsg(const CMsgPacker *pMsg, CPacker &Packer, bool Sixup
Packer.Reset(); Packer.Reset();
if(MsgId < OFFSET_UUID) if(MsgId < OFFSET_UUID)
{ {
if(Sixup) if(Sixup && !pMsg->m_NoTranslate)
{ {
if(pMsg->m_System) if(pMsg->m_System)
{ {
@ -674,21 +674,13 @@ static inline bool RepackMsg(const CMsgPacker *pMsg, CPacker &Packer, bool Sixup
} }
else else
{ {
if(MsgId >= NETMSGTYPE_SV_MOTD && MsgId <= NETMSGTYPE_SV_CHAT) if(MsgId >= 0)
; MsgId = Msg_SixToSeven(MsgId);
else if(MsgId == NETMSGTYPE_SV_KILLMSG)
MsgId += 1; if(MsgId < 0)
else if(MsgId >= NETMSGTYPE_SV_TUNEPARAMS && MsgId <= NETMSGTYPE_SV_VOTESTATUS)
;
else if(MsgId < 0)
MsgId *= -1;
else
{
dbg_msg("net", "DROP send game %d", MsgId);
return true; return true;
} }
} }
}
Packer.AddInt((MsgId<<1)|(pMsg->m_System?1:0)); Packer.AddInt((MsgId<<1)|(pMsg->m_System?1:0));
} }

View file

@ -1127,56 +1127,68 @@ void CGameContext::OnClientEnter(int ClientID)
if(Server()->IsSixup(i)) if(Server()->IsSixup(i))
{ {
// new info for others // new info for others
CMsgPacker NewClientInfoMsg(-protocol7::NETMSGTYPE_SV_CLIENTINFO); // NETMSGTYPE_SV_CLIENTINFO protocol7::CNetMsg_Sv_ClientInfo NewClientInfoMsg;
NewClientInfoMsg.AddInt(ClientID); NewClientInfoMsg.m_ClientID = ClientID;
NewClientInfoMsg.AddInt(0); // m_Local NewClientInfoMsg.m_Local = 0;
NewClientInfoMsg.AddInt(pNewPlayer->GetTeam()); NewClientInfoMsg.m_Team = pNewPlayer->GetTeam();
NewClientInfoMsg.AddString(Server()->ClientName(ClientID), -1); NewClientInfoMsg.m_pName = Server()->ClientName(ClientID);
NewClientInfoMsg.AddString(Server()->ClientClan(ClientID), -1); NewClientInfoMsg.m_pClan = Server()->ClientClan(ClientID);
NewClientInfoMsg.AddInt(Server()->ClientCountry(ClientID)); NewClientInfoMsg.m_Country = Server()->ClientCountry(ClientID);
for(int p = 0; p < 6; p++) NewClientInfoMsg.AddString(pNewPlayer->m_TeeInfos.m_apSkinPartNames[p], -1); NewClientInfoMsg.m_Silent = false;
for(int p = 0; p < 6; p++) NewClientInfoMsg.AddInt(pNewPlayer->m_TeeInfos.m_aUseCustomColors[p]);
for(int p = 0; p < 6; p++) NewClientInfoMsg.AddInt(pNewPlayer->m_TeeInfos.m_aSkinPartColors[p]);
NewClientInfoMsg.AddInt(0); // m_Silent
Server()->SendMsg(&NewClientInfoMsg, MSGFLAG_VITAL|MSGFLAG_NORECORD, i); for(int p = 0; p < 6; p++)
{
NewClientInfoMsg.m_apSkinPartNames[p] = pNewPlayer->m_TeeInfos.m_apSkinPartNames[p];
NewClientInfoMsg.m_aUseCustomColors[p] = pNewPlayer->m_TeeInfos.m_aUseCustomColors[p];
NewClientInfoMsg.m_aSkinPartColors[p] = pNewPlayer->m_TeeInfos.m_aSkinPartColors[p];
}
Server()->SendPackMsgOne(&NewClientInfoMsg, MSGFLAG_VITAL|MSGFLAG_NORECORD, i);
} }
if(Server()->IsSixup(ClientID)) if(Server()->IsSixup(ClientID))
{ {
// existing infos for new player // existing infos for new player
CMsgPacker ClientInfoMsg(-protocol7::NETMSGTYPE_SV_CLIENTINFO); // NETMSGTYPE_SV_CLIENTINFO protocol7::CNetMsg_Sv_ClientInfo ClientInfoMsg;
ClientInfoMsg.AddInt(i); ClientInfoMsg.m_ClientID = i;
ClientInfoMsg.AddInt(0); // m_Local ClientInfoMsg.m_Local = 0;
ClientInfoMsg.AddInt(pPlayer->GetTeam()); ClientInfoMsg.m_Team = pPlayer->GetTeam();
ClientInfoMsg.AddString(Server()->ClientName(i), -1); ClientInfoMsg.m_pName = Server()->ClientName(i);
ClientInfoMsg.AddString(Server()->ClientClan(i), -1); ClientInfoMsg.m_pClan = Server()->ClientClan(i);
ClientInfoMsg.AddInt(Server()->ClientCountry(i)); ClientInfoMsg.m_Country = Server()->ClientCountry(i);
for(int p = 0; p < 6; p++) ClientInfoMsg.AddString(pPlayer->m_TeeInfos.m_apSkinPartNames[p], -1); ClientInfoMsg.m_Silent = 0;
for(int p = 0; p < 6; p++) ClientInfoMsg.AddInt(pPlayer->m_TeeInfos.m_aUseCustomColors[p]);
for(int p = 0; p < 6; p++) ClientInfoMsg.AddInt(pPlayer->m_TeeInfos.m_aSkinPartColors[p]);
ClientInfoMsg.AddInt(0); // m_Silent
Server()->SendMsg(&ClientInfoMsg, MSGFLAG_VITAL|MSGFLAG_NORECORD, ClientID); for(int p = 0; p < 6; p++)
{
ClientInfoMsg.m_apSkinPartNames[p] = pPlayer->m_TeeInfos.m_apSkinPartNames[p];
ClientInfoMsg.m_aUseCustomColors[p] = pPlayer->m_TeeInfos.m_aUseCustomColors[p];
ClientInfoMsg.m_aSkinPartColors[p] = pPlayer->m_TeeInfos.m_aSkinPartColors[p];
}
Server()->SendPackMsgOne(&ClientInfoMsg, MSGFLAG_VITAL|MSGFLAG_NORECORD, ClientID);
} }
} }
// local info // local info
if(Server()->IsSixup(ClientID)) if(Server()->IsSixup(ClientID))
{ {
CMsgPacker SelfClientInfoMsg(-protocol7::NETMSGTYPE_SV_CLIENTINFO); // NETMSGTYPE_SV_CLIENTINFO protocol7::CNetMsg_Sv_ClientInfo SelfClientInfoMsg;
SelfClientInfoMsg.AddInt(ClientID); SelfClientInfoMsg.m_ClientID = ClientID;
SelfClientInfoMsg.AddInt(1); // m_Local SelfClientInfoMsg.m_Local = 1;
SelfClientInfoMsg.AddInt(pNewPlayer->GetTeam()); SelfClientInfoMsg.m_Team = pNewPlayer->GetTeam();
SelfClientInfoMsg.AddString(Server()->ClientName(ClientID), -1); SelfClientInfoMsg.m_pName = Server()->ClientName(ClientID);
SelfClientInfoMsg.AddString(Server()->ClientClan(ClientID), -1); SelfClientInfoMsg.m_pClan = Server()->ClientClan(ClientID);
SelfClientInfoMsg.AddInt(Server()->ClientCountry(ClientID)); SelfClientInfoMsg.m_Country = Server()->ClientCountry(ClientID);
for(int p = 0; p < 6; p++) SelfClientInfoMsg.AddString(pNewPlayer->m_TeeInfos.m_apSkinPartNames[p], -1); SelfClientInfoMsg.m_Silent = 0;
for(int p = 0; p < 6; p++) SelfClientInfoMsg.AddInt(pNewPlayer->m_TeeInfos.m_aUseCustomColors[p]);
for(int p = 0; p < 6; p++) SelfClientInfoMsg.AddInt(pNewPlayer->m_TeeInfos.m_aSkinPartColors[p]);
SelfClientInfoMsg.AddInt(0); // m_Silent
Server()->SendMsg(&SelfClientInfoMsg, MSGFLAG_VITAL|MSGFLAG_NORECORD, ClientID); for(int p = 0; p < 6; p++)
{
SelfClientInfoMsg.m_apSkinPartNames[p] = pNewPlayer->m_TeeInfos.m_apSkinPartNames[p];
SelfClientInfoMsg.m_aUseCustomColors[p] = pNewPlayer->m_TeeInfos.m_aUseCustomColors[p];
SelfClientInfoMsg.m_aSkinPartColors[p] = pNewPlayer->m_TeeInfos.m_aSkinPartColors[p];
}
Server()->SendPackMsgOne(&SelfClientInfoMsg, MSGFLAG_VITAL|MSGFLAG_NORECORD, ClientID);
} }
} }
@ -1375,6 +1387,19 @@ void *CGameContext::PreProcessMsg(int *MsgID, CUnpacker *pUnpacker, int ClientID
Info.FromSixup(); Info.FromSixup();
pPlayer->m_TeeInfos = Info; pPlayer->m_TeeInfos = Info;
protocol7::CNetMsg_Sv_SkinChange Msg;
Msg.m_ClientID = ClientID;
for(int p = 0; p < 6; p++)
{
Msg.m_apSkinPartNames[p] = pMsg->m_apSkinPartNames[p];
Msg.m_aSkinPartColors[p] = pMsg->m_aSkinPartColors[p];
Msg.m_aUseCustomColors[p] = pMsg->m_aUseCustomColors[p];
}
for(int i = 0; i < MAX_CLIENTS; i++)
if(Server()->IsSixup(i))
Server()->SendPackMsgOne(&Msg, MSGFLAG_VITAL|MSGFLAG_NORECORD, i);
return 0; return 0;
} }
else if(*MsgID == protocol7::NETMSGTYPE_CL_SETSPECTATORMODE) else if(*MsgID == protocol7::NETMSGTYPE_CL_SETSPECTATORMODE)
@ -1945,6 +1970,25 @@ void CGameContext::OnMessage(int MsgID, CUnpacker *pUnpacker, int ClientID)
pPlayer->m_TeeInfos.m_ColorFeet = pMsg->m_ColorFeet; pPlayer->m_TeeInfos.m_ColorFeet = pMsg->m_ColorFeet;
pPlayer->m_TeeInfos.ToSixup(); pPlayer->m_TeeInfos.ToSixup();
protocol7::CNetMsg_Sv_SkinChange SkinChangeMsg;
SkinChangeMsg.m_ClientID = ClientID;
for(int p = 0; p < 6; p++)
{
SkinChangeMsg.m_apSkinPartNames[p] = pPlayer->m_TeeInfos.m_apSkinPartNames[p];
SkinChangeMsg.m_aSkinPartColors[p] = pPlayer->m_TeeInfos.m_aSkinPartColors[p];
SkinChangeMsg.m_aUseCustomColors[p] = pPlayer->m_TeeInfos.m_aUseCustomColors[p];
}
//TODO: Common pattern send-to-sixup could be abstracted out
for(int i = 0; i < MAX_CLIENTS; i++)
{
if(Server()->IsSixup(i))
{
dbg_msg("debug", "sending to %d", i);
Server()->SendPackMsgOne(&SkinChangeMsg, MSGFLAG_VITAL, i);
}
}
Server()->ExpireServerInfo(); Server()->ExpireServerInfo();
} }
else if (MsgID == NETMSGTYPE_CL_EMOTICON && !m_World.m_Paused) else if (MsgID == NETMSGTYPE_CL_EMOTICON && !m_World.m_Paused)

View file

@ -1,4 +1,5 @@
#include <base/system.h> #include <base/system.h>
#include <base/color.h>
#include "teeinfo.h" #include "teeinfo.h"
@ -73,16 +74,19 @@ void CTeeInfo::ToSixup()
if(m_UseCustomColor) if(m_UseCustomColor)
{ {
int ColorBody = ColorHSLA(m_ColorBody).Lighten().Pack7();
dbg_msg("color", "o=%d n=%d", m_ColorBody, ColorBody);
int ColorFeet = ColorHSLA(m_ColorFeet).Lighten().Pack7();
m_aUseCustomColors[0] = true; m_aUseCustomColors[0] = true;
m_aUseCustomColors[1] = true; m_aUseCustomColors[1] = true;
m_aUseCustomColors[2] = true; m_aUseCustomColors[2] = true;
m_aUseCustomColors[3] = true; m_aUseCustomColors[3] = true;
m_aUseCustomColors[4] = true; m_aUseCustomColors[4] = true;
m_aSkinPartColors[0] = m_ColorBody; m_aSkinPartColors[0] = ColorBody;
m_aSkinPartColors[1] = 0x22FFFFFF; m_aSkinPartColors[1] = 0x22FFFFFF;
m_aSkinPartColors[2] = m_ColorBody; m_aSkinPartColors[2] = ColorBody;
m_aSkinPartColors[3] = m_ColorBody; m_aSkinPartColors[3] = ColorBody;
m_aSkinPartColors[4] = m_ColorFeet; m_aSkinPartColors[4] = ColorFeet;
} }
} }