Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
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
3 registered members (NnamueN, Akow, 1 invisible), 1,421 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: New kind of entities [Re: wdakfenixx] #408354
09/29/12 23:29
09/29/12 23:29
Joined: Jul 2001
Posts: 6,904
H
HeelX Offline
Senior Expert
HeelX  Offline
Senior Expert
H

Joined: Jul 2001
Posts: 6,904
Originally Posted By: wdakfenixx
I need to create a huge amount of entities, but i have to remove a lot of them at the same time, and that destroy the FPS


Caching is the key. The idea is to hold a cache of entities and to mark if they are active (visible objects acting in the world) or inactive (objects that are currently not acting and therefore invisible and passable). So, if you create a new entity, you first look into the cache if you already created an entity of that type and you just "switch" it on.

Following is some pseudo code which I took from a project in which I needed such a system.

First, the create function. The important thing is, that you don't create the entity with the desired entity action. You store the entity action in one skill, so that a "watchdog" function executes the function in a separate while loop and not the entity alone. This is by the way faster than the ususal per-entity-while(1)-wait(1) approach.

Code:
ENTITY* ent_createcached (char* filename, VECTOR* position, void* ev)
{
    // search if there is a free entity for the given filename in the cache
    
    if no entity found in cache
    {
        // create entity with NO event
        // make invisible and passable
        // put entity in cache
    }
    else // reset cached entity at desired position
    {
        // set position
        // set angle to 0
        // set scale to 1
        
        // reset skills
        
        // reset INVISIBLE | PASSABLE | TRANSLUCENT
    }

    // assign event to a skill
    
    // mark entity as active
        
    // return entity
}



Second thing is the manager function, which is started once (e.g. at startup) and runs infinitely. It runs through the cache and executes for each active entity the stored function. It switches the my pointer to the entity, so that you can use the my pointer in your event:

Code:
void ent_cache_startup ()
{
    // reset cache
    
    while (1)
    {
        // go through cache
        for (...)
        {
            if entity is active and has event stored in skill
            {
                // set my pointer to entity
                
                // load event function into function pointer
                // execute event
            }
        }

        wait(1);
    }
}



Third, the remove function. You simple search the entity in your cache and mark it as "inactive" and make it invisible, passable and static.

Code:
BOOL ent_removecached (ENTITY* e)
{
    // set entity in cache to inactive

    // make invisible and passable
    // make static and solid
    
    // set parent entity to NULL
    // set event in skill to 0
}



Please note, that in my pseudo-code, I assume a cache that caches the entities by filename. That is, if you have e.g. 10 items of "a.mdl" in your cache and all of them are active, you create a new entity. You could also do it that way, that you simply morph an inactive entity.

Last edited by HeelX; 09/29/12 23:31.
Re: New kind of entities [Re: lostclimate] #408475
10/02/12 00:56
10/02/12 00:56
Joined: Aug 2011
Posts: 58
Colombia/Bogotá
W
wdakfenixx Offline OP
Junior Member
wdakfenixx  Offline OP
Junior Member
W

Joined: Aug 2011
Posts: 58
Colombia/Bogotá
thanks recycling the entities is a lot more faster than removing them

Last edited by wdakfenixx; 10/02/12 00:58.

CAUTION :The content above could blow your mind
Page 2 of 2 1 2

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