Popping?


(DiaZ) #1

I am trying to make func_static entities toggle existance depending on the player’s distance if the flag “start_invis” is checked on the entity. This is the only thing remaining to complete my rain effects (would be used to fade rain impacts to avoid huge framerate loss), and I don’t think my C experience level is enough. Please if someone knows how to make it happen let me know, it’s just about the only thing that remains in my todo list. This is what I’ve tried to do, with no luck:

void SP_func_static( gentity_t *ent ) {

float distance, values ;

gentity_t *player;


if ( ent->model2 ) {
	ent->s.modelindex2 = G_ModelIndex( ent->model2 );
}
trap_SetBrushModel( ent, ent->model );
InitMover( ent );
VectorCopy( ent->s.origin, ent->s.pos.trBase );
VectorCopy( ent->s.origin, ent->r.currentOrigin );
//ent->use = Use_Static;


player = AICast_FindEntityForName( "player" );

if ( ent->spawnflags & 1 ) {
	
if (player)
	{
		values = (player -> r.currentOrigin[0]* ent->r.currentOrigin [0]) + (player -> r.currentOrigin[1]* ent->r.currentOrigin [1]) + (player -> r.currentOrigin[2]* ent->r.currentOrigin [2]); 

		distance = sqrt (values);

		if (distance > 6000)
		{		
			trap_UnlinkEntity( ent );
		}

		else	
		{
			trap_LinkEntity (ent);
		}
	}


}

Probably this is not the correct way to make an entity appear or disappear. What am I doing wrong?


(DiaZ) #2

Oh and by the way, doing this will need an increase in max_entities - but the code says it can’t be increased “without changing drawsurf bit packing”. What does it mean?


(DiaZ) #3

Well seeing as no one seems to know what I am talking about here… Does anyone know a way to make map objects disappear when far away? If it has to be models it’s OK, but whatever way, even though my map is a benchmark one, the framerates are getting alarming and I haven’t been able to find a way to do it :wink:


(kat) #4

you might be able to put in a couple of trigger fields that connect to a target_relay and then to the ‘model’ in question. In theory when a player passes thru the trigger field it’ll make a call to the relay and then the model, if it start as ‘off’ (you may need to use the ‘model2’ key/value and make it object a script_mover) it’ll spawn.

You might find it works better as a scripted event rather than a ‘physical’ one in the map (the player trigger runs the script which in turn spawn the entity). In either case you’ll probably need to turn the model into a script_mover if you want to spawn/remove it on an event

HTH