- Fixed: DCajunMaster::End was missing a write barrier for getspawned. The

same problem in D_DoomMain.
- Made bglobal a pointer because it was causing problems with the garbage 
  collector.


SVN r859 (trunk)
This commit is contained in:
Christoph Oelckers 2008-03-27 22:37:13 +00:00
parent 39940fe20a
commit 997533e0c8
22 changed files with 131 additions and 97 deletions

View file

@ -1,3 +1,9 @@
March 27, 2008 (Changes by Graf Zahl)
- Fixed: DCajunMaster::End was missing a write barrier for getspawned. The
same problem in D_DoomMain.
- Made bglobal a pointer because it was causing problems with the garbage
collector.
March 26, 2008
- Added FMOD_OPENONLY to the callback version of CreateStream() to prevent it
from doing prebuffering of the song. This was causing the Linux version to
@ -14388,7 +14394,7 @@ July 21, 1999
damage.
- Changed bot observer mode to use noclip instead of noblockmap. Otherwise,
the player is unable to ride lifts while observing.
- The bot code spawns bglobal.body1 and bglobal.body2 actors to help with
- The bot code spawns bglobal->body1 and bglobal->body2 actors to help with
aiming. The original code would carry pointers to these over between
levels, even though all actors disappear when travelling between levels.
Not a good thing. Fixed.
@ -14438,7 +14444,7 @@ July 14, 1999
the for loop.
July 12, 1999
- Enclosed the bot thinking code inside if (bglobal.botnum) {} blocks so that
- Enclosed the bot thinking code inside if (bglobal->botnum) {} blocks so that
no bot thinking occurs when there are no bots. Also defaulted bot_calcnodes
to 0. If a bot is spawned, and there are no nodes loaded, bot_calcnodes
will automatically be set to 1. Now the bots don't eat up any time if none

View file

@ -43,9 +43,9 @@ CCMD (addbot)
}
if (argv.argc() > 1)
bglobal.SpawnBot (argv[1]);
bglobal->SpawnBot (argv[1]);
else
bglobal.SpawnBot (NULL);
bglobal->SpawnBot (NULL);
}
void DCajunMaster::ClearPlayer (int i, bool keepTeam)
@ -92,7 +92,7 @@ CCMD (freeze)
CCMD (listbots)
{
botinfo_t *thebot = bglobal.botinfo;
botinfo_t *thebot = bglobal->botinfo;
int count = 0;
while (thebot)
@ -116,6 +116,9 @@ AT_GAME_SET(BotStuff)
AWeapon * w;
AActor * a;
bglobal = new DCajunMaster;
GC::WriteBarrier(bglobal);
w = (AWeapon*)GetDefaultByName ("Pistol");
if (w != NULL)
{

View file

@ -78,6 +78,7 @@ class DCajunMaster : public DObject
DECLARE_CLASS (DCajunMaster, DObject)
HAS_OBJECT_POINTERS
public:
DCajunMaster();
~DCajunMaster();
void ClearPlayer (int playernum, bool keepTeam);
@ -148,7 +149,7 @@ protected:
//Externs
extern DCajunMaster bglobal;
extern DCajunMaster *bglobal;
EXTERN_CVAR (Float, bot_flag_return_time)
EXTERN_CVAR (Int, bot_next_color)

View file

@ -63,7 +63,7 @@ static bool PTR_Reachable (intercept_t *in)
fixed_t ceilingheight = s->ceilingplane.ZatPoint (hitx, hity);
fixed_t floorheight = s->floorplane.ZatPoint (hitx, hity);
if (!bglobal.IsDangerous (s) && //Any nukage/lava?
if (!bglobal->IsDangerous (s) && //Any nukage/lava?
(floorheight <= (last_z+MAXMOVEHEIGHT)
&& ((ceilingheight == floorheight && line->special)
|| (ceilingheight - floorheight) >= looker->height))) //Does it fit?
@ -369,7 +369,7 @@ AActor *DCajunMaster::Choose_Mate (AActor *bot)
//Make a introducing to mate.
if(target && target!=bot->player->last_mate)
{
if((P_Random()%(200*bglobal.botnum))<3)
if((P_Random()%(200*bglobal->botnum))<3)
{
bot->player->chat = c_teamup;
if(target->bot)
@ -527,7 +527,7 @@ angle_t DCajunMaster::FireRox (AActor *bot, AActor *enemy, ticcmd_t *cmd)
bot->y + FixedMul(bot->momy, 5*FRACUNIT),
bot->z + (bot->height / 2), 2);
actor = bglobal.body2;
actor = bglobal->body2;
dist = P_AproxDistance (actor->x-enemy->x, actor->y-enemy->y);
if (dist < SAFE_SELF_MISDIST)
@ -537,15 +537,15 @@ angle_t DCajunMaster::FireRox (AActor *bot, AActor *enemy, ticcmd_t *cmd)
SetBodyAt (enemy->x + FixedMul (enemy->momx, (m+2*FRACUNIT)),
enemy->y + FixedMul(enemy->momy, (m+2*FRACUNIT)), ONFLOORZ, 1);
dist = P_AproxDistance(actor->x-bglobal.body1->x, actor->y-bglobal.body1->y);
dist = P_AproxDistance(actor->x-bglobal->body1->x, actor->y-bglobal->body1->y);
//try the predicted location
if (P_CheckSight (actor, bglobal.body1, 1)) //See the predicted location, so give a test missile
if (P_CheckSight (actor, bglobal->body1, 1)) //See the predicted location, so give a test missile
{
if (SafeCheckPosition (bot, actor->x, actor->y))
{
if (FakeFire (actor, bglobal.body1, cmd) >= SAFE_SELF_MISDIST)
if (FakeFire (actor, bglobal->body1, cmd) >= SAFE_SELF_MISDIST)
{
ang = R_PointToAngle2 (actor->x, actor->y, bglobal.body1->x, bglobal.body1->y);
ang = R_PointToAngle2 (actor->x, actor->y, bglobal->body1->x, bglobal->body1->y);
return ang;
}
}

View file

@ -61,7 +61,7 @@ Everything that is changed is marked (maybe commented) with "Added by MC"
static FRandom pr_botspawn ("BotSpawn");
//Externs
DCajunMaster bglobal;
DCajunMaster *bglobal;
cycle_t BotThinkCycles, BotSupportCycles, BotWTG;
@ -88,6 +88,26 @@ enum
static bool waitingforspawn[MAXPLAYERS];
DCajunMaster::DCajunMaster()
{
firstthing = NULL;
body1 = NULL;
body2 = NULL;
getspawned = NULL;
memset(botingame, 0, sizeof(botingame));
freeze = false;
changefreeze = false;
botnum = 0;
botinfo = NULL;
spawn_tries = 0;
wanted_botnum = NULL;
m_Thinking = false;
ctf = false;
loaded_bots = 0;
t_join = 0;
observer = false;
}
DCajunMaster::~DCajunMaster()
{
ForgetBots();
@ -218,7 +238,10 @@ void DCajunMaster::End ()
if (getspawned)
getspawned->FlushArgs ();
else
{
getspawned = new DArgs;
GC::WriteBarrier(this, getspawned);
}
for (i = 0; i < MAXPLAYERS; i++)
{
if (playeringame[i] && players[i].isbot)
@ -509,7 +532,7 @@ bool DCajunMaster::LoadBots ()
FString tmp;
bool gotteam = false;
bglobal.ForgetBots ();
bglobal->ForgetBots ();
#ifndef unix
tmp = progdir;
tmp += "zcajun/" BOTFILENAME;
@ -639,12 +662,12 @@ bool DCajunMaster::LoadBots ()
appendinfo (newinfo->info, "team");
appendinfo (newinfo->info, "255");
}
newinfo->next = bglobal.botinfo;
newinfo->next = bglobal->botinfo;
newinfo->lastteam = TEAM_None;
bglobal.botinfo = newinfo;
bglobal.loaded_bots++;
bglobal->botinfo = newinfo;
bglobal->loaded_bots++;
}
Printf ("%d bots read from %s\n", bglobal.loaded_bots, BOTFILENAME);
Printf ("%d bots read from %s\n", bglobal->loaded_bots, BOTFILENAME);
return true;
}

View file

@ -329,7 +329,7 @@ void DCajunMaster::WhatToGet (AActor *actor, AActor *item)
}
int weapgiveammo = (alwaysapplydmflags || deathmatch) && !(dmflags & DF_WEAPONS_STAY);
//if(pos && !bglobal.thingvis[pos->id][item->id]) continue;
//if(pos && !bglobal->thingvis[pos->id][item->id]) continue;
// if (item->IsKindOf (RUNTIME_CLASS(AArtifact)))
// return; // don't know how to use artifacts
if (item->IsKindOf (RUNTIME_CLASS(AWeapon)))

View file

@ -718,7 +718,7 @@ void D_Display ()
void D_ErrorCleanup ()
{
screen->Unlock ();
bglobal.RemoveAllBots (true);
bglobal->RemoveAllBots (true);
D_QuitNetGame ();
if (demorecording || demoplayback)
G_CheckDemoStatus ();
@ -772,7 +772,7 @@ void D_DoomLoop ()
players[i].savedpitch = players[i].mo->pitch;
}
}
bglobal.Main (maketic%BACKUPTICS);
bglobal->Main (maketic%BACKUPTICS);
for (i = 0; i < MAXPLAYERS; i++)
{
if (playeringame[i] && players[i].isbot && players[i].mo)
@ -2433,16 +2433,17 @@ void D_DoomMain (void)
}
//Added by MC:
bglobal.getspawned = Args->GatherFiles ("-bots", "", false);
if (bglobal.getspawned->NumArgs() == 0)
bglobal->getspawned = Args->GatherFiles ("-bots", "", false);
if (bglobal->getspawned->NumArgs() == 0)
{
bglobal.getspawned->Destroy();
bglobal.getspawned = NULL;
bglobal->getspawned->Destroy();
bglobal->getspawned = NULL;
}
else
{
bglobal.spawn_tries = 0;
bglobal.wanted_botnum = bglobal.getspawned->NumArgs();
GC::WriteBarrier(bglobal, bglobal->getspawned);
bglobal->spawn_tries = 0;
bglobal->wanted_botnum = bglobal->getspawned->NumArgs();
}
Printf ("M_Init: Init miscellaneous info.\n");

View file

@ -641,7 +641,7 @@ void PlayerIsGone (int netnode, int netconsole)
FBehavior::StaticStartTypedScripts (SCRIPT_Disconnect, NULL, true, netconsole);
if (netconsole == Net_Arbitrator)
{
bglobal.RemoveAllBots (true);
bglobal->RemoveAllBots (true);
Printf ("Removed all bots\n");
// Pick a new network arbitrator
@ -966,7 +966,7 @@ void NetUpdate (void)
if (maketic % ticdup == 0)
{
//Added by MC: For some of that bot stuff. The main bot function.
bglobal.Main ((maketic / ticdup) % BACKUPTICS);
bglobal->Main ((maketic / ticdup) % BACKUPTICS);
}
maketic++;
@ -2048,12 +2048,12 @@ void Net_DoCommand (int type, BYTE **stream, int player)
case DEM_ADDBOT:
{
BYTE num = ReadByte (stream);
bglobal.DoAddBot (num, s = ReadString (stream));
bglobal->DoAddBot (num, s = ReadString (stream));
}
break;
case DEM_KILLBOTS:
bglobal.RemoveAllBots (true);
bglobal->RemoveAllBots (true);
Printf ("Removed all bots\n");
break;

View file

@ -1135,7 +1135,7 @@ void DDecalFader::Tick ()
}
else
{
if (level.maptime < TimeToStartDecay || bglobal.freeze)
if (level.maptime < TimeToStartDecay || bglobal->freeze)
{
return;
}
@ -1218,7 +1218,7 @@ void DDecalStretcher::Tick ()
Destroy ();
return;
}
if (level.maptime < TimeToStart || bglobal.freeze)
if (level.maptime < TimeToStart || bglobal->freeze)
{
return;
}
@ -1287,7 +1287,7 @@ void DDecalSlider::Tick ()
Destroy ();
return;
}
if (level.maptime < TimeToStart || bglobal.freeze)
if (level.maptime < TimeToStart || bglobal->freeze)
{
return;
}
@ -1353,7 +1353,7 @@ void DDecalColorer::Tick ()
}
else
{
if (level.maptime < TimeToStartDecay || bglobal.freeze)
if (level.maptime < TimeToStartDecay || bglobal->freeze)
{
return;
}

View file

@ -312,8 +312,7 @@ static void MarkRoot()
}
Mark(SectorMarker);
{ // Silly bots
DObject *foo = &bglobal;
Mark(foo);
Mark(bglobal);
}
// Add soft roots
if (SoftRoots != NULL)

View file

@ -1218,8 +1218,8 @@ void G_PlayerReborn (int player)
}
//Added by MC: Init bot structure.
if (bglobal.botingame[player])
bglobal.CleanBotstuff (p);
if (bglobal->botingame[player])
bglobal->CleanBotstuff (p);
else
p->isbot = false;
@ -1764,7 +1764,7 @@ void G_DoLoadGame ()
// Read intermission data for hubs
G_ReadHubInfo(png);
bglobal.RemoveAllBots (true);
bglobal->RemoveAllBots (true);
text = M_GetPNGText (png, "Important CVARs");
if (text != NULL)

View file

@ -1693,7 +1693,7 @@ void G_InitNew (const char *mapname, bool bTitleLevel)
//Added by MC: Initialize bots.
if (!deathmatch)
{
bglobal.Init ();
bglobal->Init ();
}
if (mapname != level.mapname)
@ -1761,7 +1761,7 @@ void G_ChangeLevel(const char * levelname, int position, bool keepFacing, int ne
gameaction = ga_completed;
resetinventory = resetinv;
bglobal.End(); //Added by MC:
bglobal->End(); //Added by MC:
// [RH] Give scripts a chance to do something
unloading = true;
@ -2109,7 +2109,7 @@ void G_DoLoadLevel (int position, bool autosave)
//Added by MC: Initialize bots.
if (deathmatch)
{
bglobal.Init ();
bglobal->Init ();
}
if (timingdemo)

View file

@ -403,8 +403,8 @@ void cht_DoCheat (player_t *player, int cheat)
break;
case CHT_FREEZE:
bglobal.changefreeze ^= 1;
if (bglobal.freeze ^ bglobal.changefreeze)
bglobal->changefreeze ^= 1;
if (bglobal->freeze ^ bglobal->changefreeze)
{
msg = "Freeze mode on";
}

View file

@ -561,10 +561,10 @@ void AActor::Die (AActor *source, AActor *inflictor)
player->respawn_time = level.time + TICRATE;
//Added by MC: Respawn bots
if (bglobal.botnum && consoleplayer == Net_Arbitrator && !demoplayback)
if (bglobal->botnum && consoleplayer == Net_Arbitrator && !demoplayback)
{
if (player->isbot)
player->t_respawn = (pr_botrespawn()%15)+((bglobal.botnum-1)*2)+TICRATE+1;
player->t_respawn = (pr_botrespawn()%15)+((bglobal->botnum-1)*2)+TICRATE+1;
//Added by MC: Discard enemies.
for (int i = 0; i < MAXPLAYERS; i++)

View file

@ -1739,7 +1739,7 @@ bool P_TryMove (AActor *thing, fixed_t x, fixed_t y,
if (thing->player && thing->player->isbot && thing->flags & MF_SHOOTABLE)
{
if (tmsector != thing->Sector
&& bglobal.IsDangerous (tmsector))
&& bglobal->IsDangerous (tmsector))
{
thing->player->prev = thing->player->dest;
thing->player->dest = NULL;

View file

@ -2558,7 +2558,7 @@ void AActor::Tick ()
}
//Added by MC: Freeze mode.
if (bglobal.freeze && !(player && !player->isbot))
if (bglobal->freeze && !(player && !player->isbot))
{
return;
}
@ -2637,11 +2637,11 @@ void AActor::Tick ()
}
}
if (bglobal.botnum && consoleplayer == Net_Arbitrator && !demoplayback &&
if (bglobal->botnum && consoleplayer == Net_Arbitrator && !demoplayback &&
(flags & (MF_SPECIAL|MF_MISSILE)) || (flags3 & MF3_ISMONSTER))
{
clock (BotSupportCycles);
bglobal.m_Thinking = true;
bglobal->m_Thinking = true;
for (i = 0; i < MAXPLAYERS; i++)
{
if (!playeringame[i] || !players[i].isbot)
@ -2661,7 +2661,7 @@ void AActor::Tick ()
else if (flags & MF_SPECIAL)
{ //Item pickup time
//clock (BotWTG);
bglobal.WhatToGet (players[i].mo, this);
bglobal->WhatToGet (players[i].mo, this);
//unclock (BotWTG);
BotWTG++;
}
@ -2669,12 +2669,12 @@ void AActor::Tick ()
{
if (!players[i].missile && (flags3 & MF3_WARNBOT))
{ //warn for incoming missiles.
if (target != players[i].mo && bglobal.Check_LOS (players[i].mo, this, ANGLE_90))
if (target != players[i].mo && bglobal->Check_LOS (players[i].mo, this, ANGLE_90))
players[i].missile = this;
}
}
}
bglobal.m_Thinking = false;
bglobal->m_Thinking = false;
unclock (BotSupportCycles);
}
@ -3158,7 +3158,7 @@ AActor *AActor::StaticSpawn (const PClass *type, fixed_t ix, fixed_t iy, fixed_t
actor->z = actor->PrevZ = iz;
actor->picnum = 0xffff;
FRandom &rng = bglobal.m_Thinking ? pr_botspawnmobj : pr_spawnmobj;
FRandom &rng = bglobal->m_Thinking ? pr_botspawnmobj : pr_spawnmobj;
if (actor->isFast() && actor->flags3 & MF3_ISMONSTER)
actor->reactiontime = 0;

View file

@ -230,7 +230,7 @@ static void CopyPlayer (player_t *dst, player_t *src, const char *name)
if (dst->isbot)
{
botinfo_t *thebot = bglobal.botinfo;
botinfo_t *thebot = bglobal->botinfo;
while (thebot && stricmp (name, thebot->name))
{
thebot = thebot->next;
@ -239,8 +239,8 @@ static void CopyPlayer (player_t *dst, player_t *src, const char *name)
{
thebot->inuse = true;
}
bglobal.botnum++;
bglobal.botingame[dst - players] = true;
bglobal->botnum++;
bglobal->botingame[dst - players] = true;
}
else
{

View file

@ -496,7 +496,7 @@ sightcounts[0]++;
// Cannot see an invisible object
if ((flags & 1) == 0 && ((t2->renderflags & RF_INVISIBLE) || !t2->RenderStyle.IsVisible(t2->alpha)))
{ // small chance of an attack being made anyway
if ((bglobal.m_Thinking ? pr_botchecksight() : pr_checksight()) > 50)
if ((bglobal->m_Thinking ? pr_botchecksight() : pr_checksight()) > 50)
{
res = false;
goto done;

View file

@ -78,10 +78,10 @@ void P_Ticker (void)
// [RH] Frozen mode is only changed every 4 tics, to make it work with A_Tracer().
if ((level.time & 3) == 0)
{
if (bglobal.changefreeze)
if (bglobal->changefreeze)
{
bglobal.freeze ^= 1;
bglobal.changefreeze = 0;
bglobal->freeze ^= 1;
bglobal->changefreeze = 0;
}
}
@ -102,7 +102,7 @@ void P_Ticker (void)
// Since things will be moving, it's okay to interpolate them in the renderer.
r_NoInterpolate = false;
if (!bglobal.freeze && !(level.flags & LEVEL_FROZEN))
if (!bglobal->freeze && !(level.flags & LEVEL_FROZEN))
{
P_ThinkParticles (); // [RH] make the particles think
}
@ -110,14 +110,14 @@ void P_Ticker (void)
for (i = 0; i<MAXPLAYERS; i++)
if (playeringame[i] &&
/*Added by MC: Freeze mode.*/!(bglobal.freeze && players[i].isbot))
/*Added by MC: Freeze mode.*/!(bglobal->freeze && players[i].isbot))
P_PlayerThink (&players[i]);
level.Tick (); // [RH] let the level tick
DThinker::RunThinkers ();
//if added by MC: Freeze mode.
if (!bglobal.freeze && !(level.flags & LEVEL_FROZEN))
if (!bglobal->freeze && !(level.flags & LEVEL_FROZEN))
{
P_UpdateSpecials ();
P_RunEffects (); // [RH] Run particle effects

View file

@ -132,6 +132,7 @@ void STACK_ARGS call_terms ()
static void FinalGC()
{
Args = NULL;
bglobal = NULL;
GC::FullGC();
}

View file

@ -1039,7 +1039,7 @@ void WI_End ()
//Added by mc
if (deathmatch)
{
bglobal.RemoveAllBots (consoleplayer != Net_Arbitrator);
bglobal->RemoveAllBots (consoleplayer != Net_Arbitrator);
}
}