本文整理汇总了C++中TArray::Alloc方法的典型用法代码示例。如果您正苦于以下问题:C++ TArray::Alloc方法的具体用法?C++ TArray::Alloc怎么用?C++ TArray::Alloc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TArray
的用法示例。
在下文中一共展示了TArray::Alloc方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: P_PutMapSongLump
void P_PutMapSongLump(int map, VName lumpName)
{
guard(P_PutMapSongLump);
FMapSongInfo& ms = MapSongList.Alloc();
ms.MapName = va("map%02d", map);
ms.SongName = lumpName;
unguard;
}
示例2: P_GetMusicLumpNames
void P_GetMusicLumpNames(TArray<FReplacedString>& List)
{
guard(P_GetMusicLumpNames);
for (int i = 0; i < MapInfo.Num(); i++)
{
const char* MName = *MapInfo[i].SongLump;
if (MName[0] == 'd' && MName[1] == '_')
{
FReplacedString& R = List.Alloc();
R.Index = i;
R.Replaced = false;
R.Old = MName + 2;
}
}
unguard;
}
示例3: ReadNet
static void ReadNet()
{
char Buffer[MAX_MSGLEN];
// Check if there's any packet waiting.
if (recvfrom(AcceptSocket, Buffer, MAX_MSGLEN, MSG_PEEK, NULL, NULL) < 0)
{
return;
}
// Read packet.
sockaddr clientaddr;
socklen_t addrlen = sizeof(sockaddr);
int len = recvfrom(AcceptSocket, Buffer, MAX_MSGLEN, 0, &clientaddr, &addrlen);
if (len < 1)
{
return;
}
switch (Buffer[0])
{
case MCREQ_JOIN:
{
for (int i = 0; i < SrvList.Num(); i++)
{
if (!AddrCompare(&SrvList[i].Addr, &clientaddr))
{
SrvList[i].Time = time(0);
return;
}
}
TSrvItem& I = SrvList.Alloc();
I.Addr = clientaddr;
I.Time = time(0);
}
break;
case MCREQ_QUIT:
for (int i = 0; i < SrvList.Num(); i++)
{
if (!AddrCompare(&SrvList[i].Addr, &clientaddr))
{
SrvList.RemoveIndex(i);
break;
}
}
break;
case MCREQ_LIST:
{
Buffer[0] = MCREP_LIST;
int Len = 1;
for (int i = 0; i < SrvList.Num() && i < (MAX_MSGLEN - 1) / 6; i++)
{
memcpy(&Buffer[Len], SrvList[i].Addr.sa_data + 2, 4);
memcpy(&Buffer[Len + 4], SrvList[i].Addr.sa_data, 2);
Len += 6;
}
sendto(AcceptSocket, Buffer, Len, 0, &clientaddr, sizeof(sockaddr));
}
break;
}
}
示例4: RenameSprites
static void RenameSprites()
{
guard(RenameSprites);
VStream* Strm = FL_OpenFileRead("sprite_rename.txt");
if (!Strm)
{
return;
}
VScriptParser* sc = new VScriptParser("sprite_rename.txt", Strm);
TArray<VSpriteRename> Renames;
TArray<VSpriteRename> AlwaysRenames;
TArray<VLumpRename> LumpRenames;
TArray<VLumpRename> AlwaysLumpRenames;
while (!sc->AtEnd())
{
bool Always = sc->Check("always");
if (sc->Check("lump"))
{
sc->ExpectString();
VStr Old = sc->String.ToLower();
sc->ExpectString();
VStr New = sc->String.ToLower();
VLumpRename& R = Always ? AlwaysLumpRenames.Alloc() :
LumpRenames.Alloc();
R.Old = *Old;
R.New = *New;
continue;
}
sc->ExpectString();
if (sc->String.Length() != 4)
{
sc->Error("Sprite name must be 4 chars long");
}
VStr Old = sc->String.ToLower();
sc->ExpectString();
if (sc->String.Length() != 4)
{
sc->Error("Sprite name must be 4 chars long");
}
VStr New = sc->String.ToLower();
VSpriteRename& R = Always ? AlwaysRenames.Alloc() : Renames.Alloc();
R.Old[0] = Old[0];
R.Old[1] = Old[1];
R.Old[2] = Old[2];
R.Old[3] = Old[3];
R.New[0] = New[0];
R.New[1] = New[1];
R.New[2] = New[2];
R.New[3] = New[3];
}
delete sc;
sc = NULL;
bool RenameAll = !!GArgs.CheckParm("-oldsprites");
for (int i = 0; i < SearchPaths.Num(); i++)
{
if (RenameAll || i == IWadIndex)
{
SearchPaths[i]->RenameSprites(Renames, LumpRenames);
}
SearchPaths[i]->RenameSprites(AlwaysRenames, AlwaysLumpRenames);
}
unguard;
}
示例5: ParseBase
static void ParseBase(const VStr& name)
{
guard(ParseBase);
TArray<version_t> games;
bool select_game;
VStr UseName;
if (fl_savedir.IsNotEmpty() && Sys_FileExists(fl_savedir + "/" + name))
{
UseName = fl_savedir + "/" + name;
}
else if (Sys_FileExists(fl_basedir + "/" + name))
{
UseName = fl_basedir + "/" + name;
}
else
{
return;
}
select_game = false;
VScriptParser* sc = new VScriptParser(UseName, FL_OpenSysFileRead(UseName));
while (!sc->AtEnd())
{
version_t &dst = games.Alloc();
dst.ParmFound = 0;
dst.FixVoices = false;
sc->Expect("game");
sc->ExpectString();
dst.GameDir = sc->String;
if (sc->Check("iwad"))
{
sc->ExpectString();
dst.MainWad = sc->String;
}
while (sc->Check("addfile"))
{
sc->ExpectString();
dst.AddFiles.Append(sc->String);
}
if (sc->Check("param"))
{
sc->ExpectString();
dst.ParmFound = GArgs.CheckParm(*sc->String);
if (dst.ParmFound)
{
select_game = true;
}
}
if (sc->Check("fixvoices"))
{
dst.FixVoices = true;
}
sc->Expect("end");
}
delete sc;
sc = NULL;
for (int gi = games.Num() - 1; gi >= 0; gi--)
{
version_t& G = games[gi];
if (select_game && !G.ParmFound)
{
continue;
}
if (fl_mainwad.IsNotEmpty())
{
if (G.MainWad.IsEmpty() || G.MainWad == fl_mainwad || select_game)
{
if (!bIwadAdded)
{
IWadIndex = SearchPaths.Num();
VStr MainWadPath = FindMainWad(fl_mainwad);
W_AddFile(MainWadPath, fl_savedir, G.FixVoices);
bIwadAdded = true;
}
for (int j = 0; j < G.AddFiles.Num(); j++)
{
W_AddFile(fl_basedir + "/" + G.AddFiles[j], fl_savedir,
false);
}
SetupGameDir(G.GameDir);
return;
}
continue;
}
if (G.MainWad.IsEmpty())
{
continue;
}
// Look for the main wad file.
VStr MainWadPath = FindMainWad(G.MainWad);
if (MainWadPath.IsNotEmpty())
{
fl_mainwad = G.MainWad;
if (!bIwadAdded)
{
IWadIndex = SearchPaths.Num();
W_AddFile(MainWadPath, fl_savedir, G.FixVoices);
//.........这里部分代码省略.........
示例6: ParseMap
static void ParseMap(VScriptParser* sc, bool& HexenMode, mapInfo_t& Default)
{
guard(ParseMap);
mapInfo_t* info = NULL;
VName MapLumpName;
if (sc->CheckNumber())
{
// Map number, for Hexen compatibility
HexenMode = true;
if (sc->Number < 1 || sc->Number > 99)
{
sc->Error("Map number out or range");
}
MapLumpName = va("map%02d", sc->Number);
}
else
{
// Map name
sc->ExpectName8();
MapLumpName = sc->Name8;
}
// Check for replaced map info.
for (int i = 0; i < MapInfo.Num(); i++)
{
if (MapLumpName == MapInfo[i].LumpName)
{
info = &MapInfo[i];
break;
}
}
if (!info)
{
info = &MapInfo.Alloc();
}
// Copy defaults to current map definition
info->LumpName = MapLumpName;
info->LevelNum = Default.LevelNum;
info->Cluster = Default.Cluster;
info->WarpTrans = Default.WarpTrans;
info->NextMap = Default.NextMap;
info->SecretMap = Default.SecretMap;
info->SongLump = Default.SongLump;
info->CDTrack = Default.CDTrack;
info->Sky1Texture = Default.Sky1Texture;
info->Sky2Texture = Default.Sky2Texture;
info->Sky1ScrollDelta = Default.Sky1ScrollDelta;
info->Sky2ScrollDelta = Default.Sky2ScrollDelta;
info->SkyBox = Default.SkyBox;
info->FadeTable = Default.FadeTable;
info->Fade = Default.Fade;
info->OutsideFog = Default.OutsideFog;
info->Gravity = Default.Gravity;
info->AirControl = Default.AirControl;
info->Flags = Default.Flags;
info->Flags2 = Default.Flags2;
info->TitlePatch = Default.TitlePatch;
info->ParTime = Default.ParTime;
info->SuckTime = Default.SuckTime;
info->HorizWallShade = Default.HorizWallShade;
info->VertWallShade = Default.VertWallShade;
info->Infighting = Default.Infighting;
info->SpecialActions = Default.SpecialActions;
info->RedirectType = Default.RedirectType;
info->RedirectMap = Default.RedirectMap;
info->ExitPic = Default.ExitPic;
info->EnterPic = Default.EnterPic;
info->InterMusic = Default.InterMusic;
if (HexenMode)
{
info->Flags |= MAPINFOF_NoIntermission |
MAPINFOF_FallingDamage |
MAPINFOF_MonsterFallingDamage |
MAPINFOF_NoAutoSndSeq |
MAPINFOF_ActivateOwnSpecial |
MAPINFOF_MissilesActivateImpact |
MAPINFOF_InfiniteFlightPowerup;
}
// Map name must follow the number
if (sc->Check("lookup"))
{
info->Flags |= MAPINFOF_LookupName;
sc->ExpectString();
info->Name = sc->String.ToLower();
}
else
{
info->Flags &= ~MAPINFOF_LookupName;
sc->ExpectString();
info->Name = sc->String;
}
// Set song lump name from SNDINFO script
for (int i = 0; i < MapSongList.Num(); i++)
{
if (MapSongList[i].MapName == info->LumpName)
{
//.........这里部分代码省略.........
示例7: ParseMapCommon
static void ParseMapCommon(VScriptParser* sc, mapInfo_t* info, bool& HexenMode)
{
guard(ParseMapCommon);
// Process optional tokens
while (1)
{
if (sc->Check("levelnum"))
{
sc->ExpectNumber();
info->LevelNum = sc->Number;
}
else if (sc->Check("cluster"))
{
sc->ExpectNumber();
info->Cluster = sc->Number;
if (P_GetClusterDef(info->Cluster) == &DefaultClusterDef)
{
// Add empty cluster def if it doesn't exist yet.
VClusterDef& C = ClusterDefs.Alloc();
C.Cluster = info->Cluster;
C.Flags = 0;
C.EnterText = VStr();
C.ExitText = VStr();
C.Flat = NAME_None;
C.Music = NAME_None;
C.CDTrack = 0;
C.CDId = 0;
if (HexenMode)
{
C.Flags |= CLUSTERF_Hub;
}
}
}
else if (sc->Check("warptrans"))
{
sc->ExpectNumber();
info->WarpTrans = sc->Number;
}
else if (sc->Check("next"))
{
info->NextMap = ParseNextMapName(sc, HexenMode);
}
else if (sc->Check("secret") || sc->Check("secretnext"))
{
info->SecretMap = ParseNextMapName(sc, HexenMode);
}
else if (sc->Check("sky1"))
{
sc->ExpectName8();
info->Sky1Texture = GTextureManager.NumForName(
sc->Name8, TEXTYPE_Wall, true, false);
sc->ExpectFloat();
if (HexenMode)
{
sc->Float /= 256.0;
}
info->Sky1ScrollDelta = sc->Float * 35.0;
}
else if (sc->Check("sky2"))
{
sc->ExpectName8();
info->Sky2Texture = GTextureManager.NumForName(
sc->Name8, TEXTYPE_Wall, true, false);
sc->ExpectFloat();
if (HexenMode)
{
sc->Float /= 256.0;
}
info->Sky2ScrollDelta = sc->Float * 35.0;
}
else if (sc->Check("skybox"))
{
sc->ExpectString();
info->SkyBox = *sc->String;
}
else if (sc->Check("doublesky"))
{
info->Flags |= MAPINFOF_DoubleSky;
}
else if (sc->Check("lightning"))
{
info->Flags |= MAPINFOF_Lightning;
}
else if (sc->Check("forcenoskystretch"))
{
info->Flags |= MAPINFOF_ForceNoSkyStretch;
}
else if (sc->Check("fadetable"))
{
sc->ExpectName8();
info->FadeTable = sc->Name8;
}
else if (sc->Check("fade"))
{
sc->ExpectString();
info->Fade = M_ParseColour(sc->String);
}
else if (sc->Check("outsidefog"))
{
sc->ExpectString();
//.........这里部分代码省略.........
示例8: ParseSkillDef
static void ParseSkillDef(VScriptParser* sc)
{
guard(ParseSkillDef);
VSkillDef* SDef = NULL;
sc->ExpectString();
// Check for replaced skill.
for (int i = 0; i < SkillDefs.Num(); i++)
{
if (!sc->String.ICmp(SkillDefs[i].Name))
{
SDef = &SkillDefs[i];
break;
}
}
if (!SDef)
{
SDef = &SkillDefs.Alloc();
SDef->Name = sc->String;
}
// Set defaults.
SDef->AmmoFactor = 1.0;
SDef->DoubleAmmoFactor = 2.0;
SDef->DamageFactor = 1.0;
SDef->RespawnTime = 0.0;
SDef->RespawnLimit = 0;
SDef->Aggressiveness = 1.0;
SDef->SpawnFilter = 0;
SDef->AcsReturn = SkillDefs.Num() - 1;
SDef->MenuName.Clean();
SDef->PlayerClassNames.Clear();
SDef->ConfirmationText.Clean();
SDef->Key.Clean();
SDef->TextColour.Clean();
SDef->Flags = 0;
while (1)
{
if (sc->Check("AmmoFactor"))
{
sc->ExpectFloat();
SDef->AmmoFactor = sc->Float;
}
else if (sc->Check("DoubleAmmoFactor"))
{
sc->ExpectFloat();
SDef->DoubleAmmoFactor = sc->Float;
}
else if (sc->Check("DamageFactor"))
{
sc->ExpectFloat();
SDef->DamageFactor = sc->Float;
}
else if (sc->Check("FastMonsters"))
{
SDef->Flags |= SKILLF_FastMonsters;
}
else if (sc->Check("DisableCheats"))
{
SDef->Flags |= SKILLF_DisableCheats;
}
else if (sc->Check("EasyBossBrain"))
{
SDef->Flags |= SKILLF_EasyBossBrain;
}
else if (sc->Check("AutoUseHealth"))
{
SDef->Flags |= SKILLF_AutoUseHealth;
}
else if (sc->Check("RespawnTime"))
{
sc->ExpectFloat();
SDef->RespawnTime = sc->Float;
}
else if (sc->Check("RespawnLimit"))
{
sc->ExpectNumber();
SDef->RespawnLimit = sc->Number;
}
else if (sc->Check("Aggressiveness"))
{
sc->ExpectFloat();
SDef->Aggressiveness = 1.0 - MID(0.0, sc->Float, 1.0);
}
else if (sc->Check("SpawnFilter"))
{
if (sc->CheckNumber())
{
if (sc->Number > 0)
{
SDef->SpawnFilter = 1 << (sc->Number - 1);
}
}
else
{
if (sc->Check("Baby"))
{
SDef->SpawnFilter = 1;
}
//.........这里部分代码省略.........
示例9: ParseEpisodeDef
static void ParseEpisodeDef(VScriptParser* sc)
{
guard(ParseEpisodeDef);
VEpisodeDef* EDef = NULL;
int EIdx = 0;
sc->ExpectName8();
// Check for replaced episode.
for (int i = 0; i < EpisodeDefs.Num(); i++)
{
if (sc->Name8 == EpisodeDefs[i].Name)
{
EDef = &EpisodeDefs[i];
EIdx = i;
break;
}
}
if (!EDef)
{
EDef = &EpisodeDefs.Alloc();
EIdx = EpisodeDefs.Num() - 1;
}
// Check for removal of an episode.
if (sc->Check("remove"))
{
EpisodeDefs.RemoveIndex(EIdx);
return;
}
// Set defaults.
EDef->Name = sc->Name8;
EDef->TeaserName = NAME_None;
EDef->Text = VStr();
EDef->PicName = NAME_None;
EDef->Flags = 0;
EDef->Key = VStr();
if (sc->Check("teaser"))
{
sc->ExpectName8();
EDef->TeaserName = sc->Name8;
}
while (1)
{
if (sc->Check("name"))
{
if (sc->Check("lookup"))
{
EDef->Flags |= EPISODEF_LookupText;
sc->ExpectString();
EDef->Text = sc->String.ToLower();
}
else
{
EDef->Flags &= ~EPISODEF_LookupText;
sc->ExpectString();
EDef->Text = sc->String;
}
}
else if (sc->Check("picname"))
{
sc->ExpectName8();
EDef->PicName = sc->Name8;
}
else if (sc->Check("key"))
{
sc->ExpectString();
EDef->Key = sc->String.ToLower();
}
else if (sc->Check("noskillmenu"))
{
EDef->Flags |= EPISODEF_NoSkillMenu;
}
else if (sc->Check("optional"))
{
EDef->Flags |= EPISODEF_Optional;
}
else
{
break;
}
}
unguard;
}
示例10: ParseClusterDef
static void ParseClusterDef(VScriptParser* sc)
{
guard(ParseClusterDef);
VClusterDef* CDef = NULL;
sc->ExpectNumber();
// Check for replaced cluster def.
for (int i = 0; i < ClusterDefs.Num(); i++)
{
if (sc->Number == ClusterDefs[i].Cluster)
{
CDef = &ClusterDefs[i];
break;
}
}
if (!CDef)
{
CDef = &ClusterDefs.Alloc();
}
// Set defaults.
CDef->Cluster = sc->Number;
CDef->Flags = 0;
CDef->EnterText = VStr();
CDef->ExitText = VStr();
CDef->Flat = NAME_None;
CDef->Music = NAME_None;
CDef->CDTrack = 0;
CDef->CDId = 0;
while (1)
{
if (sc->Check("hub"))
{
CDef->Flags |= CLUSTERF_Hub;
}
else if (sc->Check("entertext"))
{
if (sc->Check("lookup"))
{
CDef->Flags |= CLUSTERF_LookupEnterText;
sc->ExpectString();
CDef->EnterText = sc->String.ToLower();
}
else
{
CDef->Flags &= ~CLUSTERF_LookupEnterText;
sc->ExpectString();
CDef->EnterText = sc->String;
}
}
else if (sc->Check("entertextislump"))
{
CDef->Flags |= CLUSTERF_EnterTextIsLump;
}
else if (sc->Check("exittext"))
{
if (sc->Check("lookup"))
{
CDef->Flags |= CLUSTERF_LookupExitText;
sc->ExpectString();
CDef->ExitText = sc->String.ToLower();
}
else
{
CDef->Flags &= ~CLUSTERF_LookupExitText;
sc->ExpectString();
CDef->ExitText = sc->String;
}
}
else if (sc->Check("exittextislump"))
{
CDef->Flags |= CLUSTERF_ExitTextIsLump;
}
else if (sc->Check("flat"))
{
sc->ExpectName8();
CDef->Flat = sc->Name8;
CDef->Flags &= ~CLUSTERF_FinalePic;
}
else if (sc->Check("pic"))
{
sc->ExpectName8();
CDef->Flat = sc->Name8;
CDef->Flags |= CLUSTERF_FinalePic;
}
else if (sc->Check("music"))
{
sc->ExpectName8();
CDef->Music = sc->Name8;
}
else if (sc->Check("cdtrack"))
{
sc->ExpectNumber();
CDef->CDTrack = sc->Number;
}
else if (sc->Check("cdid"))
{
sc->ExpectNumber();
CDef->CDId = sc->Number;
//.........这里部分代码省略.........