本文整理汇总了C++中CArrayPushBack函数的典型用法代码示例。如果您正苦于以下问题:C++ CArrayPushBack函数的具体用法?C++ CArrayPushBack怎么用?C++ CArrayPushBack使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CArrayPushBack函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadStaticCharacters
static void LoadStaticCharacters(Mission *m, json_t *node, char *name)
{
CArrayInit(&m->u.Static.Characters, sizeof(CharacterPositions));
json_t *chars = json_find_first_label(node, name);
if (!chars || !chars->child)
{
return;
}
chars = chars->child;
for (chars = chars->child; chars; chars = chars->next)
{
CharacterPositions cp;
LoadInt(&cp.Index, chars, "Index");
CArrayInit(&cp.Positions, sizeof(Vec2i));
json_t *positions = json_find_first_label(chars, "Positions");
if (!positions || !positions->child)
{
continue;
}
positions = positions->child;
for (positions = positions->child;
positions;
positions = positions->next)
{
Vec2i pos;
json_t *position = positions->child;
pos.x = atoi(position->text);
position = position->next;
pos.y = atoi(position->text);
CArrayPushBack(&cp.Positions, &pos);
}
CArrayPushBack(&m->u.Static.Characters, &cp);
}
}
示例2: LoadStaticKeys
static void LoadStaticKeys(Mission *m, json_t *node, char *name)
{
CArrayInit(&m->u.Static.Keys, sizeof(KeyPositions));
json_t *keys = json_find_first_label(node, name);
if (!keys || !keys->child)
{
return;
}
keys = keys->child;
for (keys = keys->child; keys; keys = keys->next)
{
KeyPositions kp;
LoadInt(&kp.Index, keys, "Index");
CArrayInit(&kp.Positions, sizeof(Vec2i));
json_t *positions = json_find_first_label(keys, "Positions");
if (!positions || !positions->child)
{
continue;
}
positions = positions->child;
for (positions = positions->child;
positions;
positions = positions->next)
{
Vec2i pos;
json_t *position = positions->child;
pos.x = atoi(position->text);
position = position->next;
pos.y = atoi(position->text);
CArrayPushBack(&kp.Positions, &pos);
}
CArrayPushBack(&m->u.Static.Keys, &kp);
}
}
示例3: MissionStaticTryAddCharacter
bool MissionStaticTryAddCharacter(Mission *m, int ch, Vec2i pos)
{
assert(m->Type == MAPTYPE_STATIC && "invalid map type");
unsigned short tile = MissionGetTile(m, pos);
// Remove any characters already there
MissionStaticTryRemoveCharacterAt(m, pos);
if (IsClear(tile))
{
// Check if the character already has an entry, and add to its list
// of positions
bool hasAdded = false;
CA_FOREACH(CharacterPositions, cp, m->u.Static.Characters)
if (cp->Index == ch)
{
CArrayPushBack(&cp->Positions, &pos);
hasAdded = true;
break;
}
CA_FOREACH_END()
// If not, create a new entry
if (!hasAdded)
{
CharacterPositions cp;
cp.Index = ch;
CArrayInit(&cp.Positions, sizeof(Vec2i));
CArrayPushBack(&cp.Positions, &pos);
CArrayPushBack(&m->u.Static.Characters, &cp);
}
return true;
}
return false;
}
示例4: MapObjectsLoadJSON
void MapObjectsLoadJSON(CArray *classes, json_t *root)
{
int version;
LoadInt(&version, root, "Version");
if (version > VERSION || version <= 0)
{
CASSERT(false, "cannot read map objects file version");
return;
}
json_t *pickupsNode = json_find_first_label(root, "MapObjects")->child;
for (json_t *child = pickupsNode->child; child; child = child->next)
{
MapObject m;
LoadMapObject(&m, child);
CArrayPushBack(classes, &m);
}
ReloadDestructibles(&gMapObjects);
// Load blood objects
CArrayClear(&gMapObjects.Bloods);
for (int i = 0;; i++)
{
char buf[CDOGS_FILENAME_MAX];
sprintf(buf, "blood%d", i);
if (StrMapObject(buf) == NULL)
{
break;
}
char *tmp;
CSTRDUP(tmp, buf);
CArrayPushBack(&gMapObjects.Bloods, &tmp);
}
}
示例5: WeaponLoadJSON
void WeaponLoadJSON(GunClasses *g, CArray *classes, json_t *root)
{
int version;
LoadInt(&version, root, "Version");
if (version > VERSION || version <= 0)
{
CASSERT(false, "cannot read guns file version");
return;
}
GunDescription *defaultDesc = &g->Default;
json_t *defaultNode = json_find_first_label(root, "DefaultGun");
if (defaultNode != NULL)
{
LoadGunDescription(defaultDesc, defaultNode->child, NULL);
for (int i = 0; i < GUN_COUNT; i++)
{
CArrayPushBack(&g->Guns, defaultDesc);
}
}
json_t *gunsNode = json_find_first_label(root, "Guns")->child;
for (json_t *child = gunsNode->child; child; child = child->next)
{
GunDescription gd;
LoadGunDescription(&gd, child, defaultDesc);
int idx = -1;
LoadInt(&idx, child, "Index");
CASSERT(
!(idx >= 0 && idx < GUN_COUNT && classes != &g->Guns),
"Cannot load gun with index as custom gun");
if (idx >= 0 && idx < GUN_COUNT && classes == &g->Guns)
{
memcpy(CArrayGet(&g->Guns, idx), &gd, sizeof gd);
}
else
{
CArrayPushBack(classes, &gd);
}
}
json_t *pseudoGunsNode = json_find_first_label(root, "PseudoGuns");
if (pseudoGunsNode != NULL)
{
for (json_t *child = pseudoGunsNode->child->child;
child;
child = child->next)
{
GunDescription gd;
LoadGunDescription(&gd, child, defaultDesc);
gd.IsRealGun = false;
CArrayPushBack(classes, &gd);
}
}
}
示例6: GameLoopResult
static PlayerList *PlayerListNew(
GameLoopResult (*updateFunc)(GameLoopData *, LoopRunner *),
void (*drawFunc)(void *), void *data,
const bool hasMenu, const bool showWinners)
{
PlayerList *pl;
CMALLOC(pl, sizeof *pl);
pl->pos = svec2i_zero();
pl->size = gGraphicsDevice.cachedConfig.Res;
pl->scroll = 0;
pl->updateFunc = updateFunc;
pl->drawFunc = drawFunc;
pl->data = data;
pl->hasMenu = hasMenu;
pl->showWinners = showWinners;
CArrayInit(&pl->playerUIDs, sizeof(int));
// Collect all players, then order by score descending
int playersAlive = 0;
CA_FOREACH(const PlayerData, p, gPlayerDatas)
CArrayPushBack(&pl->playerUIDs, &p->UID);
if (p->Lives > 0)
{
playersAlive++;
}
CA_FOREACH_END()
qsort(
pl->playerUIDs.data,
pl->playerUIDs.size,
pl->playerUIDs.elemSize,
ComparePlayerScores);
pl->showLastMan = playersAlive == 1;
return pl;
}
示例7: BulletLoadJSON
void BulletLoadJSON(
BulletClasses *bullets, CArray *classes, json_t *bulletNode)
{
int version;
LoadInt(&version, bulletNode, "Version");
if (version > VERSION || version <= 0)
{
CASSERT(false, "cannot read bullets file version");
return;
}
// Defaults
json_t *defaultNode = json_find_first_label(bulletNode, "DefaultBullet");
if (defaultNode != NULL)
{
BulletClassFree(&bullets->Default);
LoadBullet(&bullets->Default, defaultNode->child, NULL);
}
json_t *bulletsNode = json_find_first_label(bulletNode, "Bullets")->child;
for (json_t *child = bulletsNode->child; child; child = child->next)
{
BulletClass b;
LoadBullet(&b, child, &bullets->Default);
CArrayPushBack(classes, &b);
}
bullets->root = bulletNode;
}
示例8: DrawWallsAndThings
static void DrawWallsAndThings(DrawBuffer *b, Vec2i offset)
{
Vec2i pos;
Tile *tile = &b->tiles[0][0];
pos.y = b->dy + cWallOffset.dy + offset.y;
for (int y = 0; y < Y_TILES; y++, pos.y += TILE_HEIGHT)
{
CArrayClear(&b->displaylist);
pos.x = b->dx + cWallOffset.dx + offset.x;
for (int x = 0; x < b->Size.x; x++, tile++, pos.x += TILE_WIDTH)
{
if (tile->flags & MAPTILE_IS_WALL)
{
if (!(tile->flags & MAPTILE_DELAY_DRAW))
{
DrawWallColumn(y, pos, tile);
}
}
else if (tile->flags & MAPTILE_OFFSET_PIC)
{
// Drawing doors
// Doors may be offset; vertical doors are drawn centered
// horizontal doors are bottom aligned
Vec2i doorPos = pos;
doorPos.x += (TILE_WIDTH - tile->picAlt->pic.size.x) / 2;
if (tile->picAlt->pic.size.y > 16)
{
doorPos.y +=
TILE_HEIGHT - (tile->picAlt->pic.size.y % TILE_HEIGHT);
}
BlitMasked(
&gGraphicsDevice,
&tile->picAlt->pic,
doorPos,
GetTileLOSMask(tile),
0);
}
// Draw the items that are in LOS
if (tile->flags & MAPTILE_OUT_OF_SIGHT)
{
continue;
}
CA_FOREACH(ThingId, tid, tile->things)
const TTileItem *ti = ThingIdGetTileItem(tid);
// Don't draw debris, they are drawn later
if (TileItemIsDebris(ti))
{
continue;
}
CArrayPushBack(&b->displaylist, &ti);
CA_FOREACH_END()
}
DrawBufferSortDisplayList(b);
CA_FOREACH(const TTileItem *, tp, b->displaylist)
DrawThing(b, *tp, offset);
CA_FOREACH_END()
tile += X_TILES - b->Size.x;
}
}
示例9: DrawDebris
static void DrawDebris(DrawBuffer *b, Vec2i offset)
{
Tile *tile = &b->tiles[0][0];
for (int y = 0; y < Y_TILES; y++)
{
CArrayClear(&b->displaylist);
for (int x = 0; x < b->Size.x; x++, tile++)
{
if (tile->flags & MAPTILE_OUT_OF_SIGHT)
{
continue;
}
CA_FOREACH(ThingId, tid, tile->things)
const TTileItem *ti = ThingIdGetTileItem(tid);
if (TileItemIsDebris(ti))
{
CArrayPushBack(&b->displaylist, &ti);
}
CA_FOREACH_END()
}
DrawBufferSortDisplayList(b);
CA_FOREACH(const TTileItem *, tp, b->displaylist)
DrawThing(b, *tp, offset);
CA_FOREACH_END()
tile += X_TILES - b->Size.x;
}
}
示例10: memset
Action *TriggerAddAction(Trigger *t)
{
Action a;
memset(&a, 0, sizeof a);
CArrayPushBack(&t->actions, &a);
return CArrayGet(&t->actions, t->actions.size - 1);
}
示例11: HighScoresInit
void HighScoresInit(void)
{
CArrayInit(&HighScores, sizeof(HighScore));
char buf[MAX_PATH];
get_user_config_file(buf, MAX_PATH, HIGH_SCORE_FILE);
if (strlen(buf) == 0)
{
printf("Error: cannot find config file path\n");
return;
}
FILE *f = fopen(buf, "r");
if (f == NULL)
{
printf("Error: cannot open config file %s\n", buf);
return;
}
while (fgets(buf, sizeof buf, f))
{
HighScore hs;
struct tm tm;
sscanf(
buf, "%d %04d-%02d-%02d %02d:%02d:%02d",
&hs.Score, &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
&tm.tm_hour, &tm.tm_min, &tm.tm_sec);
// Time correction
tm.tm_year -= 1900;
tm.tm_mon--;
hs.Time = mktime(&tm);
CArrayPushBack(&HighScores, &hs);
}
fclose(f);
}
示例12: memset
Condition *WatchAddCondition(TWatch *w)
{
Condition c;
memset(&c, 0, sizeof c);
CArrayPushBack(&w->conditions, &c);
return CArrayGet(&w->conditions, w->conditions.size - 1);
}
示例13: DrawDebris
static void DrawDebris(DrawBuffer *b, struct vec2i offset)
{
Tile *tile = &b->tiles[0][0];
for (int y = 0; y < Y_TILES; y++)
{
CArrayClear(&b->displaylist);
for (int x = 0; x < b->Size.x; x++, tile++)
{
if (tile->outOfSight)
{
continue;
}
CA_FOREACH(ThingId, tid, tile->things)
const Thing *ti = ThingIdGetThing(tid);
if (ThingDrawLast(ti))
{
CArrayPushBack(&b->displaylist, &ti);
}
CA_FOREACH_END()
}
DrawBufferSortDisplayList(b);
CA_FOREACH(const Thing *, tp, b->displaylist)
DrawThing(b, *tp, offset);
CA_FOREACH_END()
tile += X_TILES - b->Size.x;
}
}
示例14: UIObjectDraw
void UIObjectDraw(
UIObject *o, GraphicsDevice *g, Vec2i pos, Vec2i mouse, CArray *drawObjs)
{
// Draw this UIObject and its children in BFS order
// Maintain a queue of UIObjects to draw
if (drawObjs->elemSize == 0)
{
CArrayInit(drawObjs, sizeof(UIObjectDrawContext));
UIObjectDrawContext c;
c.obj = o;
c.pos = pos;
CArrayPushBack(drawObjs, &c);
for (int i = 0; i < (int)drawObjs->size; i++)
{
UIObjectDrawContext *cPtr = CArrayGet(drawObjs, i);
UIObjectDrawAndAddChildren(
cPtr->obj, g, cPtr->pos, mouse, drawObjs);
}
}
else
{
for (int i = 0; i < (int)drawObjs->size; i++)
{
UIObjectDrawContext *cPtr = CArrayGet(drawObjs, i);
UIObjectDrawAndAddChildren(
cPtr->obj, g, cPtr->pos, mouse, NULL);
}
}
}
示例15: SetupMission
void SetupMission(
int buildTables, Mission *m, struct MissionOptions *mo, int missionIndex)
{
int i;
MissionOptionsInit(mo);
mo->index = missionIndex;
mo->missionData = m;
mo->doorPics =
doorStyles[abs(m->DoorStyle) % DOORSTYLE_COUNT];
mo->keyPics = keyStyles[abs(m->KeyStyle) % KEYSTYLE_COUNT];
for (i = 0; i < (int)m->Items.size; i++)
{
CArrayPushBack(
&mo->MapObjects,
MapObjectGet(*(int32_t *)CArrayGet(&m->Items, i)));
}
mo->exitPic = exitPics[2 * (abs(m->ExitStyle) % EXIT_COUNT)];
mo->exitShadow = exitPics[2 * (abs(m->ExitStyle) % EXIT_COUNT) + 1];
ActorsInit();
ObjsInit();
MobObjsInit();
SetupObjectives(mo, m);
SetupBadguysForMission(m);
SetupWeapons(gPlayerDatas, &m->Weapons);
SetPaletteRanges(m->WallColor, m->FloorColor, m->RoomColor, m->AltColor);
if (buildTables)
{
BuildTranslationTables(gPicManager.palette);
}
}