本文整理汇总了C++中NETbeginDecode函数的典型用法代码示例。如果您正苦于以下问题:C++ NETbeginDecode函数的具体用法?C++ NETbeginDecode怎么用?C++ NETbeginDecode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NETbeginDecode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: recvDestroyFeature
// process a destroy feature msg.
bool recvDestroyFeature(NETQUEUE queue)
{
FEATURE *pF;
uint32_t id;
NETbeginDecode(queue, GAME_DEBUG_REMOVE_FEATURE);
NETuint32_t(&id);
NETend();
if (!getDebugMappingStatus() && bMultiPlayer)
{
debug(LOG_WARNING, "Failed to remove feature for player %u.", NetPlay.players[queue.index].position);
return false;
}
pF = IdToFeature(id,ANYPLAYER);
if (pF == NULL)
{
debug(LOG_FEATURE, "feature id %d not found (probably already destroyed)", id);
return false;
}
debug(LOG_FEATURE, "p%d feature id %d destroyed (%s)", pF->player, pF->id, pF->psStats->pName);
// Remove the feature locally
turnOffMultiMsg(true);
destroyFeature(pF, gameTime - deltaGameTime + 1); // deltaGameTime is actually 0 here, since we're between updates. However, the value of gameTime - deltaGameTime + 1 will not change when we start the next tick.
turnOffMultiMsg(false);
return true;
}
示例2: recvProcessDebugMappings
void recvProcessDebugMappings(NETQUEUE queue)
{
bool val = false;
NETbeginDecode(queue, GAME_DEBUG_MODE);
NETbool(&val);
NETend();
bool oldDebugMode = getDebugMappingStatus();
processDebugMappings(queue.index, val);
bool newDebugMode = getDebugMappingStatus();
char const *cmsg;
if (val)
{
sasprintf((char**)&cmsg, _("%s wants to enable debug mode. Enabled: %s, Disabled: %s."), getPlayerName(queue.index), getWantedDebugMappingStatuses(true).c_str(), getWantedDebugMappingStatuses(false).c_str());
}
else
{
sasprintf((char**)&cmsg, _("%s wants to disable debug mode. Enabled: %s, Disabled: %s."), getPlayerName(queue.index), getWantedDebugMappingStatuses(true).c_str(), getWantedDebugMappingStatuses(false).c_str());
}
addConsoleMessage(cmsg, DEFAULT_JUSTIFY, SYSTEM_MESSAGE);
if (!oldDebugMode && newDebugMode)
{
addConsoleMessage(_("Debug mode now enabled!"), DEFAULT_JUSTIFY, SYSTEM_MESSAGE);
}
else if (oldDebugMode && !newDebugMode)
{
addConsoleMessage(_("Debug mode now disabled!"), DEFAULT_JUSTIFY, SYSTEM_MESSAGE);
}
}
示例3: recvMultiPlayerFeature
void recvMultiPlayerFeature(NETQUEUE queue)
{
FEATURE_TYPE subType = FEAT_TREE; // Dummy initialisation.
uint32_t x, y, id;
unsigned int i;
NETbeginDecode(queue, GAME_FEATURES);
{
NETenum(&subType);
NETuint32_t(&x);
NETuint32_t(&y);
NETuint32_t(&id);
}
NETend();
// Find the feature stats list that contains the feature type we want to build
for (i = 0; i < numFeatureStats; ++i)
{
// If we found the correct feature type
if (asFeatureStats[i].subType == subType)
{
// Create a feature of the specified type at the given location
FEATURE *result = buildFeature(&asFeatureStats[i], x, y, false);
result->id = id;
break;
}
}
}
示例4: recvMultiStats
void recvMultiStats(NETQUEUE queue)
{
uint32_t playerIndex;
NETbeginDecode(queue, NET_PLAYER_STATS);
// Retrieve the ID number of the player for which we need to
// update the stats
NETuint32_t(&playerIndex);
if (playerIndex >= MAX_PLAYERS)
{
return;
}
// we don't what to update ourselves, we already know our score (FIXME: rewrite setMultiStats())
if (!myResponsibility(playerIndex))
{
// Retrieve the actual stats
NETuint32_t(&playerStats[playerIndex].played);
NETuint32_t(&playerStats[playerIndex].wins);
NETuint32_t(&playerStats[playerIndex].losses);
NETuint32_t(&playerStats[playerIndex].totalKills);
NETuint32_t(&playerStats[playerIndex].totalScore);
NETuint32_t(&playerStats[playerIndex].recentKills);
NETuint32_t(&playerStats[playerIndex].recentScore);
NETuint32_t(&playerStats[playerIndex].killsToAdd);
NETuint32_t(&playerStats[playerIndex].scoreToAdd);
}
NETend();
}
示例5: recvPlayerGameTime
void recvPlayerGameTime(NETQUEUE queue)
{
uint32_t latencyTicks = 0;
uint32_t checkTime = 0;
uint32_t checkCrc = 0;
NETbeginDecode(queue, GAME_GAME_TIME);
NETuint32_t(&latencyTicks);
NETuint32_t(&checkTime);
NETuint32_tLarge(&checkCrc);
NETuint16_t(&wantedLatencies[queue.index]);
NETend();
gameQueueTime[queue.index] = checkTime + latencyTicks * GAME_TICKS_PER_UPDATE; // gameTime when future messages shall be processed.
gameQueueCheckTime[queue.index] = checkTime;
gameQueueCheckCrc[queue.index] = checkCrc;
if (!checkDebugSync(checkTime, checkCrc))
{
crcError = true;
if (NetPlay.players[queue.index].allocated)
{
NETsetPlayerConnectionStatus(CONNECTIONSTATUS_DESYNC, queue.index);
}
}
if (updateReadyTime == 0 && checkPlayerGameTime(NET_ALL_PLAYERS))
{
updateReadyTime = wzGetTicks(); // This is the time we were able to tick.
}
}
示例6: recvMultiPlayerFeature
void recvMultiPlayerFeature(NETQUEUE queue)
{
uint32_t ref = 0xff, x = 0, y = 0, id = 0;
unsigned int i;
NETbeginDecode(queue, GAME_DEBUG_ADD_FEATURE);
{
NETuint32_t(&ref);
NETuint32_t(&x);
NETuint32_t(&y);
NETuint32_t(&id);
}
NETend();
if (!getDebugMappingStatus() && bMultiPlayer)
{
debug(LOG_WARNING, "Failed to add feature for player %u.", NetPlay.players[queue.index].position);
return;
}
// Find the feature stats list that contains the feature type we want to build
for (i = 0; i < numFeatureStats; ++i)
{
// If we found the correct feature type
if (asFeatureStats[i].ref == ref)
{
// Create a feature of the specified type at the given location
FEATURE *result = buildFeature(&asFeatureStats[i], x, y, false);
result->id = id;
break;
}
}
}
示例7: recvLasSat
// recv lassat info on the receiving end.
BOOL recvLasSat(NETQUEUE queue)
{
BASE_OBJECT *psObj;
UBYTE player,targetplayer;
STRUCTURE *psStruct;
uint32_t id,targetid;
// TODO Add some kind of checking, so that things don't get lasatted by bunkers.
NETbeginDecode(queue, GAME_LASSAT);
NETuint8_t(&player);
NETuint32_t(&id);
NETuint32_t(&targetid);
NETuint8_t(&targetplayer);
NETend();
psStruct = IdToStruct (id, player);
psObj = IdToPointer(targetid, targetplayer);
if (psStruct && psObj)
{
// Give enemy no quarter, unleash the lasat
proj_SendProjectile(&psStruct->asWeaps[0], NULL, player, psObj->pos, psObj, true, 0);
psStruct->asWeaps[0].lastFired = gameTime;
// Play 5 second countdown message
audio_QueueTrackPos( ID_SOUND_LAS_SAT_COUNTDOWN, psObj->pos.x, psObj->pos.y, psObj->pos.z);
}
return true;
}
示例8: recvDestroyStructure
// ////////////////////////////////////////////////////////////////////////////
// acknowledge the destruction of a structure, from another player.
bool recvDestroyStructure(NETQUEUE queue)
{
uint32_t structID;
STRUCTURE *psStruct;
NETbeginDecode(queue, GAME_DEBUG_REMOVE_STRUCTURE);
NETuint32_t(&structID);
NETend();
if (!getDebugMappingStatus() && bMultiPlayer)
{
debug(LOG_WARNING, "Failed to remove structure for player %u.", NetPlay.players[queue.index].position);
return false;
}
// Struct to destory
psStruct = IdToStruct(structID, ANYPLAYER);
if (psStruct)
{
turnOffMultiMsg(true);
// Remove the struct from remote players machine
destroyStruct(psStruct, gameTime - deltaGameTime + 1); // deltaGameTime is actually 0 here, since we're between updates. However, the value of gameTime - deltaGameTime + 1 will not change when we start the next tick.
turnOffMultiMsg(false);
// NOTE: I do not think this should be here!
technologyGiveAway(psStruct);
}
return true;
}
示例9: recvDemolishFinished
BOOL recvDemolishFinished(NETQUEUE queue)
{
STRUCTURE *psStruct;
DROID *psDroid;
uint32_t structID, droidID;
NETbeginDecode(queue, GAME_DEMOLISH);
NETuint32_t(&structID);
NETuint32_t(&droidID);
NETend();
psStruct = IdToStruct(structID, ANYPLAYER);
if (!IdToDroid(droidID, ANYPLAYER, &psDroid))
{
debug(LOG_ERROR, "recvDemolishFinished: Packet with bad droid ID received. Discarding!");
return false;
}
if (psStruct)
{
// Demolish it
// Should never get here, if in synch.
removeStruct(psStruct, true);
if (psDroid && psDroid->psTarStats)
{
// Update droid if reqd
psDroid->psTarStats = NULL;
}
}
return true;
}
示例10: recvDroidEmbark
/** Receive droid and transporter loading information
*
* \sa sendDroidEmbark(),sendDroidDisEmbark(),recvDroidDisEmbark()
*/
BOOL recvDroidEmbark(NETQUEUE queue)
{
DROID* psDroid;
DROID* psTransporterDroid;
BOOL bDroidRemoved;
NETbeginDecode(queue, GAME_DROIDEMBARK);
{
uint8_t player;
uint32_t droidID;
uint32_t transporterID;
NETuint8_t(&player);
NETuint32_t(&droidID);
NETuint32_t(&transporterID);
// we have to find the droid on our (local) list first.
if (!IdToDroid(droidID, player, &psDroid))
{
NETend();
// Possible it already died? (sync error?)
debug(LOG_WARNING, "player's %d droid %d wasn't found?", player,droidID);
return false;
}
if (!IdToDroid(transporterID, player, &psTransporterDroid))
{
NETend();
// Possible it already died? (sync error?)
debug(LOG_WARNING, "player's %d transport droid %d wasn't found?", player,transporterID);
return false;
}
if (psDroid == NULL)
{
// how can this happen?
return true;
}
// Take it out of the world without destroying it (just removes it from the droid list)
bDroidRemoved = droidRemove(psDroid, apsDroidLists);
// Init the order for when disembark
psDroid->order = DORDER_NONE;
setDroidTarget(psDroid, NULL);
psDroid->psTarStats = NULL;
if (bDroidRemoved)
{
// and now we need to add it to their transporter group!
grpJoin(psTransporterDroid->psGroup, psDroid);
}
else
{
// possible sync error?
debug(LOG_WARNING, "Eh? Where did unit %d go? Couldn't load droid onto transporter.", droidID);
}
}
NETend();
return true;
}
示例11: recvDestroyDroid
// ////////////////////////////////////////////////////////////////////////////
// Accept a droid which was destroyed on another machine
BOOL recvDestroyDroid(NETQUEUE queue)
{
DROID* psDroid;
NETbeginDecode(queue, GAME_DROIDDEST);
{
uint32_t id;
// Retrieve the droid
NETuint32_t(&id);
if (!IdToDroid(id, ANYPLAYER, &psDroid))
{
debug(LOG_DEATH, "droid %d on request from player %d can't be found? Must be dead already?",
id, queue.index );
return false;
}
}
NETend();
// If the droid has not died on our machine yet, destroy it
if(!psDroid->died)
{
turnOffMultiMsg(true);
debug(LOG_DEATH, "Killing droid %d on request from player %d - huh?", psDroid->id, queue.index);
destroyDroid(psDroid);
turnOffMultiMsg(false);
}
else
{
debug(LOG_DEATH, "droid %d is confirmed dead by player %d.", psDroid->id, queue.index);
}
return true;
}
示例12: recvAlliance
BOOL recvAlliance(BOOL allowAudio)
{
uint8_t to, from, state;
int32_t value;
NETbeginDecode(NET_ALLIANCE);
NETuint8_t(&from);
NETuint8_t(&to);
NETuint8_t(&state);
NETint32_t(&value);
NETend();
switch (state)
{
case ALLIANCE_NULL:
break;
case ALLIANCE_REQUESTED:
requestAlliance(from, to, false, allowAudio);
break;
case ALLIANCE_FORMED:
formAlliance(from, to, false, allowAudio, true);
break;
case ALLIANCE_BROKEN:
breakAlliance(from, to, false, allowAudio);
break;
default:
debug(LOG_ERROR, "Unknown alliance state recvd.");
return false;
break;
}
return true;
}
示例13: recvDroidSecondary
// recv
BOOL recvDroidSecondary(NETQUEUE queue)
{
DROID* psDroid;
SECONDARY_ORDER sec = DSO_ATTACK_RANGE;
SECONDARY_STATE state = DSS_NONE;
NETbeginDecode(queue, GAME_SECONDARY);
{
uint8_t player;
uint32_t droid;
NETuint8_t(&player);
NETuint32_t(&droid);
NETenum(&sec);
NETenum(&state);
// If we can not find the droid should we not ask for it?
if (!IdToDroid(droid, player, &psDroid))
{
NETend();
return false;
}
}
NETend();
// Set the droids secondary order
turnOffMultiMsg(true);
secondarySetState(psDroid, sec, state);
turnOffMultiMsg(false);
return true;
}
示例14: NETcoder
static void NETcoder(PACKETDIR dir)
{
static const char original[] = "THIS IS A TEST STRING";
char str[sizeof(original)];
BOOL b = true;
uint32_t u32 = 32;
uint16_t u16 = 16;
uint8_t u8 = 8;
int32_t i32 = -32;
int16_t i16 = -16;
int8_t i8 = -8;
test_enum te = test_b;
sstrcpy(str, original);
if (dir == PACKET_ENCODE)
NETbeginEncode(0, 0);
else
NETbeginDecode(0);
NETbool(&b); assert(b == true);
NETuint32_t(&u32); assert(u32 == 32);
NETuint16_t(&u16); assert(u16 == 16);
NETuint8_t(&u8); assert(u8 == 8);
NETint32_t(&i32); assert(i32 == -32);
NETint16_t(&i16); assert(i16 == -16);
NETint8_t(&i8); assert(i8 == -8);
NETstring(str, sizeof(str)); assert(strncmp(str, original, sizeof(str) - 1) == 0);
NETenum(&te); assert(te == test_b);
}
示例15: recvGift
bool recvGift(NETQUEUE queue)
{
uint8_t type, from, to;
int audioTrack;
uint32_t droidID;
NETbeginDecode(queue, GAME_GIFT);
NETuint8_t(&type);
NETuint8_t(&from);
NETuint8_t(&to);
NETuint32_t(&droidID);
NETend();
if (!canGiveOrdersFor(queue.index, from))
{
debug(LOG_WARNING, "Gift (%d) from %d, to %d, queue.index %d", (int)type, (int)from, (int)to, (int)queue.index);
syncDebug("Wrong player.");
return false;
}
// Handle the gift depending on what it is
switch (type)
{
case RADAR_GIFT:
audioTrack = ID_SENSOR_DOWNLOAD;
giftRadar(from, to, false);
break;
case DROID_GIFT:
audioTrack = ID_UNITS_TRANSFER;
recvGiftDroids(from, to, droidID);
break;
case STRUCTURE_GIFT:
audioTrack = ID_GIFT;
recvGiftStruct(from, to, droidID);
break;
case RESEARCH_GIFT:
audioTrack = ID_TECHNOLOGY_TRANSFER;
giftResearch(from, to, false);
break;
case POWER_GIFT:
audioTrack = ID_POWER_TRANSMIT;
giftPower(from, to, droidID, false);
break;
case AUTOGAME_GIFT:
audioTrack = ID_SOUND_NEXUS_SYNAPTIC_LINK;
giftAutoGame(from, to, false);
break;
default:
debug(LOG_ERROR, "recvGift: Unknown Gift recvd");
return false;
break;
}
// If we are on the receiving end play an audio alert.
if (bMultiPlayer && to == selectedPlayer)
{
audio_QueueTrack(audioTrack);
}
return true;
}