probably not deleted memory

Posted By: CocaCola

probably not deleted memory - 10/02/16 04:16

Hi all,
I have a problem with my ent_create function.
the "ms/frame" "fnc" in the [F11] menue ist kritical.
---please try to understand me, my englisch is not good, but its trick to explane these problem---

the code:
Code:
#include <acknex.h>
#include <default.c> 
VECTOR temp_old;
function placelevelobj(){
	VECTOR temp;
	var i;
	result=c_trace(temp.x,vector(temp.x,temp.y,temp.z-1000),IGNORE_ME);
	if(result<=0)
	{
		for(i=800;i>0;i--)
		ent_create("plane.mdl",temp_old,NULL);	//under the player model
	}
}
function player_ent(){
	player=my;
	vec_set(temp_old,player.x);
	while(1)
	{
		if(key_space)player.x+=time_step;
		camera.x=-25+player.x;camera.y=-25+player.y;
		if(player.x>temp_old.x+3)
		{
			temp_old.x+=3;
			placelevelobj();
		}
		wait(1);
	}
}
function main()
{
	video_mode=9;
	max_entities = 100000;
	level_load(NULL);
	vec_set(camera.x,vector(-40,0,40));
	vec_set(camera.pan,vector(45,-45,0));
	ent_create("cube.mdl",vector(0,0,0),player_ent);
}



the code create a cube as a player entity. with [space] you can move the player, if no plane under the player, placelevelobj() will start and create 600 planes, because with 600 planes you can see the problem.

how to see the problem:<-----------!
press [F11] to see ms/frame fnc value.
at start fnc is at 1 or 2 or betwen...
if you hold on, on [space] fnc will get higher value(thats ok)
if you hold on space still fnc is higher, you can see the problem.
for example, at first start i have to hold on space key for 5secunds to get fnc over 50, if I relase the space key, fnc go to 1 or 2
BUT is i press space key again, fnc is over 50 in 1 sec.

thanks for reading
if you hold on [space]
Posted By: txesmi

Re: probably not deleted memory - 10/02/16 05:48

Hi,
I think that is the normal behaviour of the engine. Entities are arranged into an internal list. When you create an entity the list becomes a bit longer. When you perform a c_trace the engine takes that list and checks if their bounding boxes intersect with the trace ray one by one. So the longer the entity list is the slower the c_trace will be.

Salud!
Posted By: CocaCola

Re: probably not deleted memory - 10/02/16 05:54

wow, you are right, i have to think aout ist, but for my game i will use a arry, with positins to locate the planes, i have only the same z valve
Posted By: CocaCola

Re: probably not deleted memory - 10/02/16 08:30

i have sloved the problem, with scanning only for a group in 25 steps Distance
© 2024 lite-C Forums