About auto hide invisible entitiesl

Posted By: 20BN

About auto hide invisible entitiesl - 09/07/18 16:11

Hi, all.
If every game levels has 3000-5000 entities,
need to hide outside of camera sight.
Do you have any plans?
Posted By: Dooley

Re: About auto hide invisible entitiesl - 09/26/18 03:19

camera.clip_near
camera.clip_far

Look these up in manual
Posted By: HellThunder

Re: About auto hide invisible entitiesl - 09/26/18 06:36

You could use the part of this while loop for hiding entities. Related to the camera position and the culling_distance, it will hide your entities or show them again. This code snippet was a part of AUM - original was C-Script.
Code:
var culling_distance = 4000;
action NULL_() 
{
 while(me)
 {
	if (vec_dist (my.x, camera.x) < culling_distance) // the player has come close to this entity?
	{
		reset(my, INVISIBLE); // then show it!
		while (my.alpha < 100) // run this loop until the entity becomes opaque again
		{
			my.alpha = minv(100, my.alpha + 15 * time_step); // increase my.alpha (15 = speed) and limit it to 100
			wait (1);
		}
		reset(my, TRANSLUCENT); // get rid of some nasty artifacts when the entity is completely visible
	}
	else // the player has moved away from this entity?
	{
		set(my, TRANSLUCENT);  // then set the "transparent" flag again
		while (my.alpha > 0) // run this loop until the entity becomes practically invisible (alpha = 0)
		{
			my.alpha = maxv(0, my.alpha - 15 * time_step); // decrease my.alpha (15 = speed) and limit it to 0
			wait (1);
		}
		set(my, INVISIBLE); // now hide the entity in order to increase the frame rate

	}
        wait(1);
 }
}

Posted By: 20BN

Re: About auto hide invisible entitiesl - 09/26/18 14:26

In other words, 1000 entities, there will be 1000 processes?
Posted By: Superku

Re: About auto hide invisible entitiesl - 09/26/18 15:06

I'm sorry but don't use that code quoted by HellThunder. Do not do this manually, esp. not with dedicated wait(1) loops per entity. This is an engine's task.

Entities not on screen in the sense of the camera's frustum are set to invisible/ CLIPPED automatically.


For distance based clipping camera.clip_far or LOD is the correct approach.
For special cases such as a building full of entities you can use region_set in A8 to hide all entities contained in that region manually.


If the entity count (and draw count) is a problem performance wise, you may want to think about combining multiple entities into one.
Posted By: HellThunder

Re: About auto hide invisible entitiesl - 09/26/18 20:43

Entity loops would result with additional tasks, true - But should this result in a bottleneck?

In order to validate the production quality of this method, I used the snippet within the main loop of a testlevel with over 600 Entities. Every entity got an action. Some models use normal maps. HDR + DOF and a screen resolution of 1920*1080.

Result:
Quote:
culling_distance: 10000 fps: about 80



Quote:
culling_distance: 3400 fps: 105-110



The fading works flawlessly, plus selection of entities which should be hidden and which should stay would be possible.
e.g. Would work fine for hiding vegetation or other environment entities, but could also be able to force mountains to stay visible.

Conclusion:
For grouping entities and hiding groups of entities, the snippet works very fine and results with a fps increase.
For just limiting the view I would suggest to use the approach of Superku, which is mentioned within the official manual for cases like this.

Posted By: 20BN

Re: About auto hide invisible entitiesl - 10/01/18 11:33

@HellThunder

your fuc = 8.(600 entities loop = 8?)
Posted By: HellThunder

Re: About auto hide invisible entitiesl - 10/01/18 20:02

I don't know, if I understand your question.
In my case it is just a single function, which will be started after the camera or player is moving. The function itself will be called within a mainloop, which runs all the time.
© 2024 lite-C Forums