Destroying Entities
Displaying 1-8 of 8 total.
1
Please enter a numerical value for the importance of this sticky.
Enter 0 to unsticky.
ustor

As things stand, I am currently using EntitySpawn() to create new entities on the fly in game, which is all good and well. The trouble comes in when I realized how quickly the upper limit of 256 entities could be reached (and exceeded, bringing about certain doom). The good news is that I will never need more than 256 entites on a map at any one time, but I'm looking for a way to 'destroy' an entity (FreeEntity(), where are you?) so that entities are created and destroyed over the course of the game, freeing up those precious entity indexes for future entities and causing the total to dance between the 0 and 256 limits. I realize that a (potentially messy) workaround is what I'm likely looking at(which I haven't yet started on), but I'm interested to know what others think about what the simplest/best route to go would be.

Posted on 2005-01-26 21:09:16

Omni

Workaround is the way to go.

Technically you don't need to destroy an entity. If you ever need to take a different entity and turn it off, make a function like

void DisableEntityIndex(int index)

Which could turn off movement on an entity and also make it invisible.

Then, make something like

void ReclaimEntity(int index, int x, int y, string file)

That would take one of the disabled indexes, change the CHR file, give it a new X and Y position, and essentially reincarnate as a new Entity.

Since we don't have a FreeEntity(), yes, I'd say a workaround would do fine here. It shouldn't be too difficult to just reincarnate an entity, right?

Posted on 2005-01-26 21:53:03

Overkill


void EntityDestroy(int ent)
{
EntityStop(ent);
entity.visible[ent]=0;
entity.obstruct[ent]=0;
entity.obstructable[ent]=0;
}

void EntityReclaim(int ent, int x, int y, string chr)
{
ChangeCHR(ent,chr);
entity.visible[ent]=1;
entity.x[ent]=x*16;
entity.y[ent]=y*16;

//I *think* the below is the default values given to EntitySpawn()'d characters...
entity.obstruct[ent]=1;
entity.obstructable[ent]=1;
}

Posted on 2005-01-27 06:58:33 (last edited on 2005-01-27 14:44:29)

Omni

Beautiful. Maybe these functions would be good candidates for the Code Vault? So simple, and so useful I think.

Posted on 2005-01-27 07:56:34

ustor

What a painless solution! The only real adjustment that I might suggest for it is that, in EntityDestroy(), moving the disabled entity to an offmap location (such as entity.x = -16, entity.y = -16) might not be a bad idea. It may be a little too specific to my project, but I did this for mine because I was running checks to see if there had been a collision between the player and an entity (though not causing obstruction) by comparing their locations, so simply hiding/making non-obstructive wasn't enough.

One small question remains after all of this: though it hasn't given me any trouble yet, are there any potential problems with placing entities at negative map coordinates?

Posted on 2005-01-27 16:02:57

Omni

Most likely not. Entities can Wander off the map (upper-left corner) during normal movement, so negative coordinates shouldn't be a problem.

Posted on 2005-01-27 16:33:00

blues_zodiakos

One thing that might make it easier on you, if you don't want to manually figure out which entity to 'reclaim', and if you can make the assumption that any stopped, invisible entity is probably not being used, you could reprogram EntityReclaim to loop through the 256 available entities and use the first one that is both stopped and invisible. In this way, you would only need to use 3 variables when calling it instead of 4, and it would be more practical as well.

Posted on 2005-01-28 01:52:02

Omni

Or, even simpler, so you don't have to make the invisibility assumption.

Set aside a special 'reclaimable' coordinate.

For example, put all destroyed entities at -132, -132 or something.

Then, when you're looking for a new entity, do something like

int GetReclaimableIndex()

Which would loop through all entities and return only an index that is at the reclaimable coordinate. Then you can use that index for ReclaimEntity().

Posted on 2005-01-28 08:06:38


Displaying 1-8 of 8 total.
1
 
Newest messages

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.