mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Improved ghost skin handling a bit
This commit is contained in:
parent
456a67fe2d
commit
ffaa077c72
|
@ -14,6 +14,14 @@
|
||||||
|
|
||||||
CGhost::CGhost() : m_StartRenderTick(-1), m_LastDeathTick(-1), m_Rendering(false), m_Recording(false) {}
|
CGhost::CGhost() : m_StartRenderTick(-1), m_LastDeathTick(-1), m_Rendering(false), m_Recording(false) {}
|
||||||
|
|
||||||
|
void CGhost::GetGhostSkin(CGhostSkin *pSkin, const char *pSkinName, int UseCustomColor, int ColorBody, int ColorFeet)
|
||||||
|
{
|
||||||
|
StrToInts(&pSkin->m_Skin0, 6, pSkinName);
|
||||||
|
pSkin->m_UseCustomColor = UseCustomColor;
|
||||||
|
pSkin->m_ColorBody = ColorBody;
|
||||||
|
pSkin->m_ColorFeet = ColorFeet;
|
||||||
|
}
|
||||||
|
|
||||||
void CGhost::GetGhostCharacter(CGhostCharacter *pGhostChar, const CNetObj_Character *pChar)
|
void CGhost::GetGhostCharacter(CGhostCharacter *pGhostChar, const CNetObj_Character *pChar)
|
||||||
{
|
{
|
||||||
pGhostChar->m_X = pChar->m_X;
|
pGhostChar->m_X = pChar->m_X;
|
||||||
|
@ -63,14 +71,7 @@ void CGhost::AddInfos(const CNetObj_Character *pChar)
|
||||||
{
|
{
|
||||||
Client()->GhostRecorder_Start();
|
Client()->GhostRecorder_Start();
|
||||||
|
|
||||||
const CGameClient::CClientData *pClientData = &m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientID];
|
GhostRecorder()->WriteData(GHOSTDATA_TYPE_SKIN, (const char*)&m_CurGhost.m_Skin, sizeof(CGhostSkin));
|
||||||
CGhostSkin Skin;
|
|
||||||
StrToInts(&Skin.m_Skin0, 6, pClientData->m_aSkinName);
|
|
||||||
Skin.m_UseCustomColor = pClientData->m_UseCustomColor;
|
|
||||||
Skin.m_ColorBody = pClientData->m_ColorBody;
|
|
||||||
Skin.m_ColorFeet = pClientData->m_ColorFeet;
|
|
||||||
GhostRecorder()->WriteData(GHOSTDATA_TYPE_SKIN, (const char*)&Skin, sizeof(Skin));
|
|
||||||
|
|
||||||
for(int i = 0; i < NumTicks; i++)
|
for(int i = 0; i < NumTicks; i++)
|
||||||
GhostRecorder()->WriteData(GHOSTDATA_TYPE_CHARACTER, (const char*)&m_CurGhost.m_lPath[i], sizeof(CGhostCharacter));
|
GhostRecorder()->WriteData(GHOSTDATA_TYPE_CHARACTER, (const char*)&m_CurGhost.m_lPath[i], sizeof(CGhostCharacter));
|
||||||
}
|
}
|
||||||
|
@ -185,9 +186,13 @@ void CGhost::OnRender()
|
||||||
StopRender();
|
StopRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGhost::InitRenderInfos(CTeeRenderInfo *pRenderInfo, const char *pSkinName, int UseCustomColor, int ColorBody, int ColorFeet)
|
void CGhost::InitRenderInfos(CGhostItem *pGhost)
|
||||||
{
|
{
|
||||||
int SkinId = m_pClient->m_pSkins->Find(pSkinName);
|
char aSkinName[64];
|
||||||
|
IntsToStr(&pGhost->m_Skin.m_Skin0, 6, aSkinName);
|
||||||
|
CTeeRenderInfo *pRenderInfo = &pGhost->m_RenderInfo;
|
||||||
|
|
||||||
|
int SkinId = m_pClient->m_pSkins->Find(aSkinName);
|
||||||
if(SkinId < 0)
|
if(SkinId < 0)
|
||||||
{
|
{
|
||||||
SkinId = m_pClient->m_pSkins->Find("default");
|
SkinId = m_pClient->m_pSkins->Find("default");
|
||||||
|
@ -195,11 +200,12 @@ void CGhost::InitRenderInfos(CTeeRenderInfo *pRenderInfo, const char *pSkinName,
|
||||||
SkinId = 0;
|
SkinId = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pRenderInfo->m_ColorBody = m_pClient->m_pSkins->GetColorV4(ColorBody);
|
if(pGhost->m_Skin.m_UseCustomColor)
|
||||||
pRenderInfo->m_ColorFeet = m_pClient->m_pSkins->GetColorV4(ColorFeet);
|
{
|
||||||
|
|
||||||
if(UseCustomColor)
|
|
||||||
pRenderInfo->m_Texture = m_pClient->m_pSkins->Get(SkinId)->m_ColorTexture;
|
pRenderInfo->m_Texture = m_pClient->m_pSkins->Get(SkinId)->m_ColorTexture;
|
||||||
|
pRenderInfo->m_ColorBody = m_pClient->m_pSkins->GetColorV4(pGhost->m_Skin.m_ColorBody);
|
||||||
|
pRenderInfo->m_ColorFeet = m_pClient->m_pSkins->GetColorV4(pGhost->m_Skin.m_ColorFeet);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pRenderInfo->m_Texture = m_pClient->m_pSkins->Get(SkinId)->m_OrgTexture;
|
pRenderInfo->m_Texture = m_pClient->m_pSkins->Get(SkinId)->m_OrgTexture;
|
||||||
|
@ -216,9 +222,10 @@ void CGhost::StartRecord()
|
||||||
{
|
{
|
||||||
m_Recording = true;
|
m_Recording = true;
|
||||||
m_CurGhost.Reset();
|
m_CurGhost.Reset();
|
||||||
|
|
||||||
const CGameClient::CClientData *pClientData = &m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientID];
|
const CGameClient::CClientData *pData = &m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientID];
|
||||||
InitRenderInfos(&m_CurGhost.m_RenderInfo, pClientData->m_aSkinName, pClientData->m_UseCustomColor, pClientData->m_ColorBody, pClientData->m_ColorFeet);
|
GetGhostSkin(&m_CurGhost.m_Skin, pData->m_aSkinName, pData->m_UseCustomColor, pData->m_ColorBody, pData->m_ColorFeet);
|
||||||
|
InitRenderInfos(&m_CurGhost);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGhost::StopRecord(int Time)
|
void CGhost::StopRecord(int Time)
|
||||||
|
@ -306,41 +313,39 @@ int CGhost::Load(const char *pFilename)
|
||||||
int Index = 0;
|
int Index = 0;
|
||||||
bool FoundSkin = false;
|
bool FoundSkin = false;
|
||||||
bool NoTick = false;
|
bool NoTick = false;
|
||||||
|
bool Error = false;
|
||||||
|
|
||||||
int Type;
|
int Type;
|
||||||
while(GhostLoader()->ReadNextType(&Type))
|
while(!Error && GhostLoader()->ReadNextType(&Type))
|
||||||
{
|
{
|
||||||
if(Index == NumTicks && (Type == GHOSTDATA_TYPE_CHARACTER || Type == GHOSTDATA_TYPE_CHARACTER_NO_TICK))
|
if(Index == NumTicks && (Type == GHOSTDATA_TYPE_CHARACTER || Type == GHOSTDATA_TYPE_CHARACTER_NO_TICK))
|
||||||
{
|
{
|
||||||
Index = -1;
|
Error = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Type == GHOSTDATA_TYPE_SKIN)
|
if(Type == GHOSTDATA_TYPE_SKIN && !FoundSkin)
|
||||||
{
|
{
|
||||||
CGhostSkin Skin;
|
FoundSkin = true;
|
||||||
if(GhostLoader()->ReadData(Type, (char*)&Skin, sizeof(Skin)) && !FoundSkin)
|
if(!GhostLoader()->ReadData(Type, (char*)&pGhost->m_Skin, sizeof(CGhostSkin)))
|
||||||
{
|
Error = true;
|
||||||
FoundSkin = true;
|
|
||||||
char aSkinName[64];
|
|
||||||
IntsToStr(&Skin.m_Skin0, 6, aSkinName);
|
|
||||||
InitRenderInfos(&pGhost->m_RenderInfo, aSkinName, Skin.m_UseCustomColor, Skin.m_ColorBody, Skin.m_ColorFeet);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if(Type == GHOSTDATA_TYPE_CHARACTER_NO_TICK)
|
else if(Type == GHOSTDATA_TYPE_CHARACTER_NO_TICK)
|
||||||
{
|
{
|
||||||
NoTick = true;
|
NoTick = true;
|
||||||
GhostLoader()->ReadData(Type, (char*)&pGhost->m_lPath[Index++], sizeof(CGhostCharacter_NoTick));
|
if(!GhostLoader()->ReadData(Type, (char*)&pGhost->m_lPath[Index++], sizeof(CGhostCharacter_NoTick)))
|
||||||
|
Error = true;
|
||||||
}
|
}
|
||||||
else if(Type == GHOSTDATA_TYPE_CHARACTER)
|
else if(Type == GHOSTDATA_TYPE_CHARACTER)
|
||||||
{
|
{
|
||||||
GhostLoader()->ReadData(Type, (char*)&pGhost->m_lPath[Index++], sizeof(CGhostCharacter));
|
if(!GhostLoader()->ReadData(Type, (char*)&pGhost->m_lPath[Index++], sizeof(CGhostCharacter)))
|
||||||
|
Error = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GhostLoader()->Close();
|
GhostLoader()->Close();
|
||||||
|
|
||||||
if(Index != NumTicks)
|
if(Error || Index != NumTicks)
|
||||||
{
|
{
|
||||||
pGhost->Reset();
|
pGhost->Reset();
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -357,7 +362,8 @@ int CGhost::Load(const char *pFilename)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!FoundSkin)
|
if(!FoundSkin)
|
||||||
InitRenderInfos(&pGhost->m_RenderInfo, "default", 0, 0, 0);
|
GetGhostSkin(&pGhost->m_Skin, "default", 0, 0, 0);
|
||||||
|
InitRenderInfos(pGhost);
|
||||||
|
|
||||||
return Slot;
|
return Slot;
|
||||||
}
|
}
|
||||||
|
@ -382,14 +388,7 @@ void CGhost::SaveGhost(CMenus::CGhostItem *pItem)
|
||||||
int NumTicks = m_aActiveGhosts[Slot].m_lPath.size();
|
int NumTicks = m_aActiveGhosts[Slot].m_lPath.size();
|
||||||
Client()->GhostRecorder_Start(pItem->m_Time);
|
Client()->GhostRecorder_Start(pItem->m_Time);
|
||||||
|
|
||||||
const CGameClient::CClientData *pClientData = &m_pClient->m_aClients[m_pClient->m_Snap.m_LocalClientID];
|
GhostRecorder()->WriteData(GHOSTDATA_TYPE_SKIN, (const char*)&m_aActiveGhosts[Slot].m_Skin, sizeof(CGhostSkin));
|
||||||
CGhostSkin Skin;
|
|
||||||
StrToInts(&Skin.m_Skin0, 6, pClientData->m_aSkinName);
|
|
||||||
Skin.m_UseCustomColor = pClientData->m_UseCustomColor;
|
|
||||||
Skin.m_ColorBody = pClientData->m_ColorBody;
|
|
||||||
Skin.m_ColorFeet = pClientData->m_ColorFeet;
|
|
||||||
GhostRecorder()->WriteData(GHOSTDATA_TYPE_SKIN, (const char*)&Skin, sizeof(Skin));
|
|
||||||
|
|
||||||
for(int i = 0; i < NumTicks; i++)
|
for(int i = 0; i < NumTicks; i++)
|
||||||
GhostRecorder()->WriteData(GHOSTDATA_TYPE_CHARACTER, (const char*)&m_aActiveGhosts[Slot].m_lPath[i], sizeof(CGhostCharacter));
|
GhostRecorder()->WriteData(GHOSTDATA_TYPE_CHARACTER, (const char*)&m_aActiveGhosts[Slot].m_lPath[i], sizeof(CGhostCharacter));
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,7 @@ private:
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CTeeRenderInfo m_RenderInfo;
|
CTeeRenderInfo m_RenderInfo;
|
||||||
|
CGhostSkin m_Skin;
|
||||||
array<CGhostCharacter> m_lPath;
|
array<CGhostCharacter> m_lPath;
|
||||||
int m_PlaybackPos;
|
int m_PlaybackPos;
|
||||||
|
|
||||||
|
@ -81,6 +82,7 @@ private:
|
||||||
bool m_Recording;
|
bool m_Recording;
|
||||||
bool m_Rendering;
|
bool m_Rendering;
|
||||||
|
|
||||||
|
static void GetGhostSkin(CGhostSkin *pSkin, const char *pSkinName, int UseCustomColor, int ColorBody, int ColorFeet);
|
||||||
static void GetGhostCharacter(CGhostCharacter *pGhostChar, const CNetObj_Character *pChar);
|
static void GetGhostCharacter(CGhostCharacter *pGhostChar, const CNetObj_Character *pChar);
|
||||||
static void GetNetObjCharacter(CNetObj_Character *pChar, const CGhostCharacter *pGhostChar);
|
static void GetNetObjCharacter(CNetObj_Character *pChar, const CGhostCharacter *pGhostChar);
|
||||||
|
|
||||||
|
@ -92,7 +94,7 @@ private:
|
||||||
void StartRender();
|
void StartRender();
|
||||||
void StopRender();
|
void StopRender();
|
||||||
|
|
||||||
void InitRenderInfos(CTeeRenderInfo *pRenderInfo, const char *pSkinName, int UseCustomColor, int ColorBody, int ColorFeet);
|
void InitRenderInfos(CGhostItem *pGhost);
|
||||||
|
|
||||||
static void ConGPlay(IConsole::IResult *pResult, void *pUserData);
|
static void ConGPlay(IConsole::IResult *pResult, void *pUserData);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue