Tip of the Week #12: ent_pvs for multiple views

Posted By: Superku

Tip of the Week #12: ent_pvs for multiple views - 12/16/16 08:41

My code uses ent_pvs() a lot for gameplay, AI and effects but it broke when I changed the view rendering chain recently. ent_pvs only lists the entities of the last rendered view so "this week's tip" deals with ent_pvs for multiple views:
http://opserver.de/swik10/index.php?title=Ent_pvs
Posted By: Reconnoiter

Re: Tip of the Week #12: ent_pvs for multiple views - 12/16/16 12:11

Thanks, this may prove usefull laugh
Posted By: alibaba

Re: Tip of the Week #12: ent_pvs for multiple views - 12/16/16 17:51

Thank you for the effort! It's a very interesting way to solve this problem!
Posted By: Superku

Re: Tip of the Week #12: ent_pvs for multiple views - 12/16/16 18:12

Thanks, may it come in useful (or not)!
Posted By: Superku

Re: Tip of the Week #12: ent_pvs for multiple views - 12/17/16 13:42

There was a bug or oversight in that approach which caused my game to behave strangely and crash while debugging it:
Because of timing issues some entities might be (ptr_)removed already before you access the ent_pvs2 list which is why you will need to add an (or extend your) on_ent_remove event:

Code:
void on_ent_remove_event(ENTITY* ent)
{
	int i,j;
	
	for(j = 0; j < 2; j++)
	{
		for(i = 0; i < ent_pvs2_list_max[j]; i++)
		{
			if(ent == ent_pvs2_list[j][i])
			{
				ent_pvs2_list_max[j]--;
				ent_pvs2_list[j][i] = ent_pvs2_list[j][ent_pvs2_list_max[j]];
				ent_pvs2_list[j][ent_pvs2_list_max[j]] = NULL;
			}
		}
	}
}




EDIT: And
"num > ent_pvs2_list_max[mode]"
has to be strictly greater than, otherwise you will skip the last element. Both issues have been fixed on the wiki page.
Posted By: KingHeroov333

Re: Tip of the Week #12: ent_pvs for multiple views - 12/17/16 22:43

I didn't even know that this function existed LOL
© 2024 lite-C Forums