News:

One Minute Game Review by The Happy Friar: https://ugetube.com/@OneMinteGameReviews
Also on Rumble: https://rumble.com/c/c-1115371

idTech 4 (aka Doom 3 tech) Discord Server! https://discord.gg/9wtCGHa

Main Menu

Game Code That Removes idDebris

Started by spamclark15, June 17, 2017, 03:40:59 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

spamclark15

I'm looking through the game code for where entities that are considered idDebris are removed so that I can add in an exception. Would anyone know where this is?

Phrozo

I don't believe the game code looks for the class type info idDebris specifically when removing entities, only when spawning them. What are you trying to do exactly?

spamclark15

#2
I'm trying to disable the removal of barrelpiece, barrelpiece2, barreltop, and barreltop2 which are all idDebris that are created when an exploding barrel explodes, and then the "fuse" value in moveable.def for it decides how long until it's removed. Commenting out line 1012 in Moveable.cpp stops the burnaway effect on those 4 debris pieces, but they're still removed, and trying to work backwards by looking for where fuse is mentioned in the code has me stuck.

I do have Entity.cpp up in another tab which seems like the place where removal of entities might occur but fuse isn't mentioned in it at all.

The Happy Friar

You would need to change the debris from idDebris to idMovable in the code.  The wile loop @ line 1013 in movables.cpp contains the declariation of idDebris.

spamclark15

while ( kv ) {
const idDict *debris_args = gameLocal.FindEntityDefDict( kv->GetValue(), false );
if ( debris_args ) {
idEntity *ent;
idVec3 dir;
idDebris *debris;
//if ( first ) {
dir = physicsObj.GetAxis()[1];
// first = false;
//} else {
dir.x += gameLocal.random.CRandomFloat() * 4.0f;
dir.y += gameLocal.random.CRandomFloat() * 4.0f;
//dir.z = gameLocal.random.RandomFloat() * 8.0f;
//}
dir.Normalize();

gameLocal.SpawnEntityDef( *debris_args, &ent, false );
if ( !ent || !ent->IsType( idDebris::Type ) ) {
gameLocal.Error( "'projectile_debris' is not an idDebris" );
}

debris = static_cast<idDebris *>(ent);
debris->Create( this, physicsObj.GetOrigin(), dir.ToMat3() );
debris->Launch();
//                 debris->GetRenderEntity()->shaderParms[ SHADERPARM_TIME_OF_DEATH ] = ( gameLocal.time + 1500 ) * 0.001f;
debris->UpdateVisuals();

}
kv = spawnArgs.MatchPrefix( "def_debris", kv );
}


Is replacing all instances of idDebris in the loop enough?

Phrozo

In that code snippet yes, at least it's worth a try. You should also change the "spawnclass" value to "idMoveable" as well for all the debris in the .def file if you do.

spamclark15

Changed loop to the following:

while ( kv ) {
const idDict *debris_args = gameLocal.FindEntityDefDict( kv->GetValue(), false );
if ( debris_args ) {
idEntity *ent;
idVec3 dir;
//RPS idDebris *debris;
idMoveable *debris;
//if ( first ) {
dir = physicsObj.GetAxis()[1];
// first = false;
//} else {
dir.x += gameLocal.random.CRandomFloat() * 4.0f;
dir.y += gameLocal.random.CRandomFloat() * 4.0f;
//dir.z = gameLocal.random.RandomFloat() * 8.0f;
//}
dir.Normalize();

gameLocal.SpawnEntityDef( *debris_args, &ent, false );
//RPS if ( !ent || !ent->IsType( idDebris::Type ) ) {
if ( !ent || !ent->IsType( idMoveable::Type ) ) {
gameLocal.Error( "'projectile_debris' is not an idDebris" );
}

//RPS debris = static_cast<idDebris *>(ent);
debris = static_cast<idMoveable *>(ent);
debris->Create( this, physicsObj.GetOrigin(), dir.ToMat3() );
debris->Launch();
//RPS debris->GetRenderEntity()->shaderParms[ SHADERPARM_TIME_OF_DEATH ] = ( gameLocal.time + 1500 ) * 0.001f;
debris->UpdateVisuals();

}
kv = spawnArgs.MatchPrefix( "def_debris", kv );
}

physicsObj.PutToRest();
CancelEvents( &EV_Explode );
CancelEvents( &EV_Activate );

f = spawnArgs.GetFloat( "respawn" );
if ( f > 0.0f ) {
PostEventSec( &EV_Respawn, f );
} else {
PostEventMS( &EV_Remove, 5000 );
}

if ( spawnArgs.GetBool( "triggerTargets" ) ) {
ActivateTargets( this );
}
}


It produces errors upon trying to build though:

Error    3   error C2039: 'Create' : is not a member of 'idMoveable'   1013   1   Game
Error    4   error C2039: 'Launch' : is not a member of 'idMoveable'   1014   1   Game

Phrozo

Ahh shoot. I shouldn't have assumed it would have been that easy. Apparently idMoveable doesn't have those methods defined. It is also missing members idDebris needs for it's effects. It's going to be a little bit more complicated than copying and pasting idDebris code into idMoveable. You'll have to declare and define these methods:

void Spawn( void );
void Create( idEntity *owner, const idVec3 &start, const idMat3 &axis );
void Launch( void );
void Fizzle( void );

You'll also have to add these data members from idDebris to idMovable:

idEntityPtr<idEntity> owner;
idPhysics_RigidBody physicsObj;
const idDeclParticle * smokeFly;
int smokeFlyTime;
const idSoundShader * sndBounce;


And you'll also have refactor some of idMovable's methods idDebris has as well, like Think() for instance.
/*
================
idDebris::Think
================
*/
void idDebris::Think( void ) {

// run physics
RunPhysics();
Present();

if ( smokeFly && smokeFlyTime ) {
if ( !gameLocal.smokeParticles->EmitSmoke( smokeFly, smokeFlyTime, gameLocal.random.CRandomFloat(), GetPhysics()->GetOrigin(), GetPhysics()->GetAxis() ) ) {
smokeFlyTime = 0;
}
}
}


versus

/*
================
idMoveable::Think
================
*/
void idMoveable::Think( void ) {
if ( thinkFlags & TH_THINK ) {
if ( !FollowInitialSplinePath() ) {
BecomeInactive( TH_THINK );
}
}
idEntity::Think();
}


It may be better to find out what causes debris to be removed so quickly then to refactor all of that. Perhaps set owner to NULL or to world object?

spamclark15

Thanks for the help. I replaced the code for think, but where do the other parts go?

Phrozo

The new methods and data members need to be added to where idMoveable is declared in Movable.h. Put the method definitions in Moveable.cpp.
Note that copying idDebris code into idMoveable might inadvertently change the behavior of all idMoveables so this isn't advised unless you add code to remedy the differences.

spamclark15

Error   582   error LNK2005: "public: virtual void __thiscall idDebris::Think(void)" (?Think@idDebris@@UAEXXZ) already defined in Moveable.obj Projectile.obj
Error   583   error LNK2001: unresolved external symbol "public: virtual void __thiscall idMoveable::Think(void)" (?Think@idMoveable@@UAEXXZ) Moveable.obj
Error   584   error LNK1120: 1 unresolved externals gamex86.dll



Phrozo

Make sure there aren't multiple definitions of idDebris::Think, especially if you aren't going to being using idDebris anymore. The second error means idMoveable::Think was declared but never defined. That shouldn't happen as it already is defined in source code. Check your code.

spamclark15

#12
Commented out copy in Projectile.cpp. The second error I'll show you the files for.

Phrozo

at line 405 in Moveable.cpp, you defined Think for idDebris, not idMoveable. idDebris::Think is being defined twice here and in projectile.cpp

Change this:
void idDebris::Think( void ) { //RPS

// run physics
RunPhysics();
Present();

if ( smokeFly && smokeFlyTime ) {
if ( !gameLocal.smokeParticles->EmitSmoke( smokeFly, smokeFlyTime, gameLocal.random.CRandomFloat(), GetPhysics()->GetOrigin(), GetPhysics()->GetAxis() ) ) {
smokeFlyTime = 0;
}
}
}


to this
void idMoveable::Think( void ) { // HERE -Phrozo

// run physics
RunPhysics();
Present();

if ( smokeFly && smokeFlyTime ) {
if ( !gameLocal.smokeParticles->EmitSmoke( smokeFly, smokeFlyTime, gameLocal.random.CRandomFloat(), GetPhysics()->GetOrigin(), GetPhysics()->GetAxis() ) ) {
smokeFlyTime = 0;
}
}
}

spamclark15

Sorry about that.  :-[ It builds now. When I destroy the barrel I get:

loaded collision model models/mapobjects/fuel_barrel/exp_barrel2c.lwo
script\weapon_fists.script : weapon_fists::Fire
script\weapon_fists.script : weapon_fists::Fire
<NO FUNCTION>
--------- Game Map Shutdown ----------
--------------------------------------
********************
ERROR: script\weapon_fists.script(64): Thread 'thread_7': 'projectile_debris'
is not an idDebris

********************


I changed debris_barrelpiece, debris_barrelpiece2, debris_barreltop, and debris_barreltop2 spawnclass to idMoveable in moveable.def.