Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,089 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
removing large sprite entities all at once #309939
02/12/10 05:57
02/12/10 05:57
Joined: Dec 2009
Posts: 71
N
ncc1701d Offline OP
Junior Member
ncc1701d  Offline OP
Junior Member
N

Joined: Dec 2009
Posts: 71
is their a way to create and/or remove large number of sprite entities without naming them one by one in code.
Say I want to create a forest of sprite trees. They are all the same sprite just repeated but in different locations. Is there way to say plant them in many locations without refering to each tree code line by code line?
Is their a way to remove these entities all at once using ent_remove but many all at once as opposed to each one by one.
follow?

I can potentially imagine using random and ent_create to make more than one tree even if I dont know how yet but then what to do to rem_ entity all at once as opposed to one by one.?
thanks

Re: removing large sprite entities all at once [Re: ncc1701d] #309941
02/12/10 06:41
02/12/10 06:41
Joined: Mar 2009
Posts: 112
Germany
K
KDuke Offline
Member
KDuke  Offline
Member
K

Joined: Mar 2009
Posts: 112
Germany
Well random and ent_create is the way to go. You simply use a loop with which you create the sprites.
If you use an array to store these created entities you can easily remove them with a loop of the same kind, using the array which stores the pointers to the sprite entities and removing them with ent_remove.
If you would like a dynamic number of these sprites you can use sys_malloc for dynamically creating an array with a given number of space to handle the sprites.


Using A7 Free
Click and join the 3dgs irc community!
Room: #3dgs
Re: removing large sprite entities all at once [Re: KDuke] #309950
02/12/10 09:07
02/12/10 09:07
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Another way would be to loop generating all the sprites.
This loop also gives each entity a simple action that watches one particular
global variable.
If this global variable equals a set number, the entities then self-destruct.

EG
Code:
var trees_on = 1;

action tree_alive()
{  while(trees_on==1)
   {   wait(1);   }
   ent_remove(me);
}

function create_trees()
{  ...
   for(i=0; i<150; i++)
   {  
      ent_create("tree.tga", vector(random(2000)-1000,random(2000)-1000,0), tree_alive);
   }
   ...
}


// then just set "trees_on == 0" for one frame and all the trees will remove themselves.




"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: removing large sprite entities all at once [Re: EvilSOB] #309954
02/12/10 09:57
02/12/10 09:57
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
I preferer the Solution from KDude. With the solution from EvilSOB you have a lot entities that use a action (are dynamic) and are in a while loop. That is bad for your fps.

Re: removing large sprite entities all at once [Re: Widi] #309985
02/12/10 13:59
02/12/10 13:59
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Widi does have a point.
Mine will be a little bit fps-hungry if youve got a hell of a lot of trees.
But seeing as the tree-action is so small theres not going to be that fps-intensive.

BUT, if you are just using this process for a "remove trees at end of level"
type system, then mine is seriously in-efficient and KDukes is far more appropriate.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: removing large sprite entities all at once [Re: EvilSOB] #309989
02/12/10 14:18
02/12/10 14:18
Joined: Oct 2009
Posts: 149
Germany
M
muffel Offline
Member
muffel  Offline
Member
M

Joined: Oct 2009
Posts: 149
Germany
"Entities created by ent_create are always dynamic." (from Manual)

I would use EvilSOB solution.
You can always remove all trees if you want.
And the point that KDukes method saves fps because of static Entitys is wrong because they are not static.
I guess that you can set them static in a action(reset(me,DYNAMIC);)

muffel

Re: removing large sprite entities all at once [Re: muffel] #309993
02/12/10 15:04
02/12/10 15:04
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
i think he was talking about the action code which consumes execution time, not to the entity being dynamic or static.

i would use a mixture of both: save the entities into an array and assign an action which resets their dynamic flag. then you can delete them from within the array.

like that you could even do some culling tree algorithm if you don't use a plain array but a tree structure, saving even more performance.

Re: removing large sprite entities all at once [Re: Joey] #310012
02/12/10 17:08
02/12/10 17:08
Joined: Jul 2008
Posts: 1,178
England
M
MrGuest Offline
Serious User
MrGuest  Offline
Serious User
M

Joined: Jul 2008
Posts: 1,178
England
I'd just store all the trees handles in an array,

Code:
#include <acknex.h>
#include <default.c>

#define trees_max 50

var hnd_trees[3][trees_max];

void trees_remove(int group){
	
	ENTITY* ent;
	
	int i;
	for(i = 0; i < trees_max; i++){
		
		you = ptr_for_handle(hnd_trees[group][i]);
		if(you){
			
			ent_remove(you);
		}else{
			
			break;
		}
	}
}


void trees_create(VECTOR* offset, int group, int count){
	
	if(count > trees_max){
		printf("TOO MANY TREES, Increase #define on line 6");
		return;
	}
	
	int i;
	VECTOR pos;
	
	pos.z = 0;
	
	int i;
	for(i = 0; i <= count; i++){
		
		pos.x = offset.x + (random(500)-250); //-250 to 249.99
		pos.y = offset.y + (random(500)-250);
		
		hnd_trees[group][i] = handle(ent_create("tree.mdl", pos, NULL));
	}
	
	
}

void main(){
	
	wait(1);
	
	
	level_load(NULL);

	vec_set(camera.x, vector(0, 0, 5000));
	camera.tilt = -90;
	
	trees_create(vector(0, 0, 0), 0, 10);
	trees_create(vector(-1000, 1000, 0), 1, 10);
	trees_create(vector(1000, 1000, 0), 2, 10);
	
	random_seed(0);
	
	int i;
	while(1){
		
		i = random(3);
		trees_remove(i);
		trees_create(vector(random(2000)-1000, random(2000)-1000, 0), i, integer(random(25)));
		
		wait(-2);
	}
}



make sure your tree model exists
doesn't stop trees spawning in each other
doesn't choose more than 1 model

hope this helps

Re: removing large sprite entities all at once [Re: MrGuest] #310222
02/13/10 19:40
02/13/10 19:40
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
@muffel: Yes, entities with ent_create are dynamic, but you can reset the DYNAMIC flag at the end of the action. That saves a lot of fps. wink


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1