本文整理汇总了C++中CCharacterCore::Write方法的典型用法代码示例。如果您正苦于以下问题:C++ CCharacterCore::Write方法的具体用法?C++ CCharacterCore::Write怎么用?C++ CCharacterCore::Write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCharacterCore
的用法示例。
在下文中一共展示了CCharacterCore::Write方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Evolve
static void Evolve(CNetObj_Character *pCharacter, int Tick)
{
CWorldCore TempWorld;
CCharacterCore TempCore;
mem_zero(&TempCore, sizeof(TempCore));
TempCore.Init(&TempWorld, g_GameClient.Collision());
TempCore.Read(pCharacter);
while(pCharacter->m_Tick < Tick)
{
pCharacter->m_Tick++;
TempCore.Tick(false);
TempCore.Move();
TempCore.Quantize();
}
TempCore.Write(pCharacter);
}
示例2: Evolve
static void Evolve(CNetObj_Character *pCharacter, int Tick, bool PredictFreeze)
{
CWorldCore TempWorld;
CCharacterCore TempCore;
CTeamsCore TempTeams;
mem_zero(&TempCore, sizeof(TempCore));
mem_zero(&TempTeams, sizeof(TempTeams));
TempCore.Init(&TempWorld, g_GameClient.Collision(), &TempTeams);
TempCore.Read(pCharacter);
while(pCharacter->m_Tick < Tick)
{
pCharacter->m_Tick++;
TempCore.Tick(false, false, PredictFreeze);
TempCore.Move();
TempCore.Quantize();
}
TempCore.Write(pCharacter);
}
示例3: OnPredict
//.........这里部分代码省略.........
{
if(!m_Snap.m_aCharacters[i].m_Active || !m_Snap.m_paPlayerInfos[i])
continue;
g_GameClient.m_aClients[i].m_Predicted.Init(&World, Collision(), &m_Teams);
World.m_apCharacters[i] = &g_GameClient.m_aClients[i].m_Predicted;
World.m_apCharacters[i]->m_Id = m_Snap.m_paPlayerInfos[i]->m_ClientID;
g_GameClient.m_aClients[i].m_Predicted.Read(&m_Snap.m_aCharacters[i].m_Cur);
}
// predict
for(int Tick = Client()->GameTick()+1; Tick <= Client()->PredGameTick(); Tick++)
{
// fetch the local
if(Tick == Client()->PredGameTick() && World.m_apCharacters[m_Snap.m_LocalClientID])
m_PredictedPrevChar = *World.m_apCharacters[m_Snap.m_LocalClientID];
// first calculate where everyone should move
for(int c = 0; c < MAX_CLIENTS; c++)
{
if(!World.m_apCharacters[c])
continue;
mem_zero(&World.m_apCharacters[c]->m_Input, sizeof(World.m_apCharacters[c]->m_Input));
if(m_Snap.m_LocalClientID == c)
{
// apply player input
int *pInput = Client()->GetInput(Tick);
if(pInput)
World.m_apCharacters[c]->m_Input = *((CNetObj_PlayerInput*)pInput);
World.m_apCharacters[c]->Tick(true);
}
else
World.m_apCharacters[c]->Tick(false);
}
// move all players and quantize their data
for(int c = 0; c < MAX_CLIENTS; c++)
{
if(!World.m_apCharacters[c])
continue;
World.m_apCharacters[c]->Move();
World.m_apCharacters[c]->Quantize();
}
// check if we want to trigger effects
if(Tick > m_LastNewPredictedTick)
{
m_LastNewPredictedTick = Tick;
m_NewPredictedTick = true;
if(m_Snap.m_LocalClientID != -1 && World.m_apCharacters[m_Snap.m_LocalClientID])
{
vec2 Pos = World.m_apCharacters[m_Snap.m_LocalClientID]->m_Pos;
int Events = World.m_apCharacters[m_Snap.m_LocalClientID]->m_TriggeredEvents;
if(Events&COREEVENT_GROUND_JUMP) g_GameClient.m_pSounds->PlayAndRecord(CSounds::CHN_WORLD, SOUND_PLAYER_JUMP, 1.0f, Pos);
/*if(events&COREEVENT_AIR_JUMP)
{
GameClient.effects->air_jump(pos);
GameClient.sounds->play_and_record(SOUNDS::CHN_WORLD, SOUND_PLAYER_AIRJUMP, 1.0f, pos);
}*/
//if(events&COREEVENT_HOOK_LAUNCH) snd_play_random(CHN_WORLD, SOUND_HOOK_LOOP, 1.0f, pos);
//if(events&COREEVENT_HOOK_ATTACH_PLAYER) snd_play_random(CHN_WORLD, SOUND_HOOK_ATTACH_PLAYER, 1.0f, pos);
if(Events&COREEVENT_HOOK_ATTACH_GROUND) g_GameClient.m_pSounds->PlayAndRecord(CSounds::CHN_WORLD, SOUND_HOOK_ATTACH_GROUND, 1.0f, Pos);
if(Events&COREEVENT_HOOK_HIT_NOHOOK) g_GameClient.m_pSounds->PlayAndRecord(CSounds::CHN_WORLD, SOUND_HOOK_NOATTACH, 1.0f, Pos);
//if(events&COREEVENT_HOOK_RETRACT) snd_play_random(CHN_WORLD, SOUND_PLAYER_JUMP, 1.0f, pos);
}
}
if(Tick == Client()->PredGameTick() && World.m_apCharacters[m_Snap.m_LocalClientID])
m_PredictedChar = *World.m_apCharacters[m_Snap.m_LocalClientID];
}
if(g_Config.m_Debug && g_Config.m_ClPredict && m_PredictedTick == Client()->PredGameTick())
{
CNetObj_CharacterCore Before = {0}, Now = {0}, BeforePrev = {0}, NowPrev = {0};
BeforeChar.Write(&Before);
BeforePrevChar.Write(&BeforePrev);
m_PredictedChar.Write(&Now);
m_PredictedPrevChar.Write(&NowPrev);
if(mem_comp(&Before, &Now, sizeof(CNetObj_CharacterCore)) != 0)
{
Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client", "prediction error");
for(unsigned i = 0; i < sizeof(CNetObj_CharacterCore)/sizeof(int); i++)
if(((int *)&Before)[i] != ((int *)&Now)[i])
{
char aBuf[256];
str_format(aBuf, sizeof(aBuf), " %d %d %d (%d %d)", i, ((int *)&Before)[i], ((int *)&Now)[i], ((int *)&BeforePrev)[i], ((int *)&NowPrev)[i]);
Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client", aBuf);
}
}
}
m_PredictedTick = Client()->PredGameTick();
}
示例4: RenderPlayer
void CPlayers::RenderPlayer(
const CNetObj_Character *pPrevChar,
const CNetObj_Character *pPlayerChar,
const CNetObj_PlayerInfo *pPrevInfo,
const CNetObj_PlayerInfo *pPlayerInfo
)
{
CNetObj_Character Prev;
CNetObj_Character Player;
Prev = *pPrevChar;
Player = *pPlayerChar;
CNetObj_PlayerInfo pInfo = *pPlayerInfo;
CTeeRenderInfo RenderInfo = m_pClient->m_aClients[pInfo.m_ClientId].m_RenderInfo;
// check for teamplay modes
bool IsTeamplay = false;
bool NewTick = m_pClient->m_NewTick;
if(m_pClient->m_Snap.m_pGameobj)
IsTeamplay = (m_pClient->m_Snap.m_pGameobj->m_Flags&GAMEFLAG_TEAMS) != 0;
// check for ninja
if (Player.m_Weapon == WEAPON_NINJA)
{
// change the skin for the player to the ninja
int Skin = m_pClient->m_pSkins->Find("x_ninja");
if(Skin != -1)
{
if(IsTeamplay)
RenderInfo.m_Texture = m_pClient->m_pSkins->Get(Skin)->m_ColorTexture;
else
{
RenderInfo.m_Texture = m_pClient->m_pSkins->Get(Skin)->m_OrgTexture;
RenderInfo.m_ColorBody = vec4(1,1,1,1);
RenderInfo.m_ColorFeet = vec4(1,1,1,1);
}
}
}
// set size
RenderInfo.m_Size = 64.0f;
float IntraTick = Client()->IntraGameTick();
if(Player.m_Health < 0) // dont render dead players
return;
float Angle = mix((float)Prev.m_Angle, (float)Player.m_Angle, IntraTick)/256.0f;
//float angle = 0;
if(pInfo.m_Local && Client()->State() != IClient::STATE_DEMOPLAYBACK)
{
// just use the direct input if it's local player we are rendering
Angle = GetAngle(m_pClient->m_pControls->m_MousePos);
}
else
{
/*
float mixspeed = Client()->FrameTime()*2.5f;
if(player.attacktick != prev.attacktick) // shooting boosts the mixing speed
mixspeed *= 15.0f;
// move the delta on a constant speed on a x^2 curve
float current = g_GameClient.m_aClients[info.cid].angle;
float target = player.angle/256.0f;
float delta = angular_distance(current, target);
float sign = delta < 0 ? -1 : 1;
float new_delta = delta - 2*mixspeed*sqrt(delta*sign)*sign + mixspeed*mixspeed;
// make sure that it doesn't vibrate when it's still
if(fabs(delta) < 2/256.0f)
angle = target;
else
angle = angular_approach(current, target, fabs(delta-new_delta));
g_GameClient.m_aClients[info.cid].angle = angle;*/
}
// use preditect players if needed
if(pInfo.m_Local && g_Config.m_ClPredict && Client()->State() != IClient::STATE_DEMOPLAYBACK)
{
if(!m_pClient->m_Snap.m_pLocalCharacter || (m_pClient->m_Snap.m_pLocalCharacter->m_Health < 0) || (m_pClient->m_Snap.m_pGameobj && m_pClient->m_Snap.m_pGameobj->m_GameOver))
{
}
else
{
// apply predicted results
m_pClient->m_PredictedChar.Write(&Player);
m_pClient->m_PredictedPrevChar.Write(&Prev);
IntraTick = Client()->PredIntraGameTick();
NewTick = m_pClient->m_NewPredictedTick;
}
}
vec2 Direction = GetDirection((int)(Angle*256.0f));
vec2 Position = mix(vec2(Prev.m_X, Prev.m_Y), vec2(Player.m_X, Player.m_Y), IntraTick);
vec2 Vel = mix(vec2(Prev.m_VelX/256.0f, Prev.m_VelY/256.0f), vec2(Player.m_VelX/256.0f, Player.m_VelY/256.0f), IntraTick);
m_pClient->m_pFlow->Add(Position, Vel*100.0f, 10.0f);
//.........这里部分代码省略.........
示例5: OnPredict
void CGameClient::OnPredict()
{
// store the previous values so we can detect prediction errors
CCharacterCore BeforePrevChar = m_PredictedPrevChar;
CCharacterCore BeforeChar = m_PredictedChar;
// we can't predict without our own id or own character
if(m_LocalClientID == -1 || !m_Snap.m_aCharacters[m_LocalClientID].m_Active)
return;
// don't predict anything if we are paused or round/game is over
if(m_Snap.m_pGameData && m_Snap.m_pGameData->m_GameStateFlags&(GAMESTATEFLAG_PAUSED|GAMESTATEFLAG_ROUNDOVER|GAMESTATEFLAG_GAMEOVER))
{
if(m_Snap.m_pLocalCharacter)
m_PredictedChar.Read(m_Snap.m_pLocalCharacter);
if(m_Snap.m_pLocalPrevCharacter)
m_PredictedPrevChar.Read(m_Snap.m_pLocalPrevCharacter);
return;
}
// repredict character
CWorldCore World;
World.m_Tuning = m_Tuning;
// search for players
for(int i = 0; i < MAX_CLIENTS; i++)
{
if(!m_Snap.m_aCharacters[i].m_Active)
continue;
m_aClients[i].m_Predicted.Init(&World, Collision());
World.m_apCharacters[i] = &m_aClients[i].m_Predicted;
m_aClients[i].m_Predicted.Read(&m_Snap.m_aCharacters[i].m_Cur);
}
// predict
for(int Tick = Client()->GameTick()+1; Tick <= Client()->PredGameTick(); Tick++)
{
// fetch the local
if(Tick == Client()->PredGameTick() && World.m_apCharacters[m_LocalClientID])
m_PredictedPrevChar = *World.m_apCharacters[m_LocalClientID];
// first calculate where everyone should move
for(int c = 0; c < MAX_CLIENTS; c++)
{
if(!World.m_apCharacters[c])
continue;
mem_zero(&World.m_apCharacters[c]->m_Input, sizeof(World.m_apCharacters[c]->m_Input));
if(m_LocalClientID == c)
{
// apply player input
const int *pInput = Client()->GetInput(Tick);
if(pInput)
World.m_apCharacters[c]->m_Input = *((const CNetObj_PlayerInput*)pInput);
World.m_apCharacters[c]->Tick(true);
}
else
World.m_apCharacters[c]->Tick(false);
}
// move all players and quantize their data
for(int c = 0; c < MAX_CLIENTS; c++)
{
if(!World.m_apCharacters[c])
continue;
World.m_apCharacters[c]->Move();
World.m_apCharacters[c]->Quantize();
}
// check if we want to trigger effects
if(Tick > m_LastNewPredictedTick)
{
m_LastNewPredictedTick = Tick;
if(m_LocalClientID != -1 && World.m_apCharacters[m_LocalClientID])
ProcessTriggeredEvents(World.m_apCharacters[m_LocalClientID]->m_TriggeredEvents, World.m_apCharacters[m_LocalClientID]->m_Pos);
}
if(Tick == Client()->PredGameTick() && World.m_apCharacters[m_LocalClientID])
m_PredictedChar = *World.m_apCharacters[m_LocalClientID];
}
if(g_Config.m_Debug && g_Config.m_ClPredict && m_PredictedTick == Client()->PredGameTick())
{
CNetObj_CharacterCore Before = {0}, Now = {0}, BeforePrev = {0}, NowPrev = {0};
BeforeChar.Write(&Before);
BeforePrevChar.Write(&BeforePrev);
m_PredictedChar.Write(&Now);
m_PredictedPrevChar.Write(&NowPrev);
if(mem_comp(&Before, &Now, sizeof(CNetObj_CharacterCore)) != 0)
{
Console()->Print(IConsole::OUTPUT_LEVEL_DEBUG, "client", "prediction error");
for(unsigned i = 0; i < sizeof(CNetObj_CharacterCore)/sizeof(int); i++)
if(((int *)&Before)[i] != ((int *)&Now)[i])
{
char aBuf[256];
//.........这里部分代码省略.........