LavaLit

OpenBoR => Engine Center => Coding => Topic started by: Damon Caskey on May 16, 2011, 12:08:39 am

Title: Sprite Array
Post by: Damon Caskey on May 16, 2011, 12:08:39 am
In case anyone is interested in playing with it, I just opened up the sprite array to script access. We have always had the ability to get an entity's current sprite, but now we can select a specific animation and frame. Moreover, this gives us access to the other sprite properties, the biggest probably being current offset.

Aside from helping to get rid of a lot of "load sprite" calls (why bother when you can now use dummy animations as an engine managed sprite cache), this should really help with debugging and specialized graphic effects. I have tested all the get calls, but not changing. Let me know if you find any issues (except file name... I seriously doubt a change attempt will do anything but crash the engine, I just included it for posterity. No need to mention if it doesn't work.)

 ;)

DC

Title: Re: Sprite Array
Post by: volcanic on May 16, 2011, 01:14:08 am
Great.
No doubt this is an exciting feature.
But tell you the truth I really want the feature drawing a part of a sprite,
something like drawspritea(sprite,x,y,width,height)


Title: Re: Sprite Array
Post by: utunnels on May 16, 2011, 01:29:02 am
That is sprite clipping, which is very complex to do.
Take a look at sprite.c and you'll see a lot of duplicate functions (nearly 2000 lines) are there to serve the clipping purpose.

However, if you don't mind the performance, there's a workaround. You can create a smaller screen, draw your sprite on the screen and then draw the screen.



Edit*

If any developer wants to change the sprite clipping code, I suggest to add a clipping area to the screen, instead of the sprite itself.


For example:

set_clip_area(screen, 50, 50, 120, 120);

Then any draw action to the screen will be limited in this area, until it is cleared.

However, there'll involve a lot of changes in the draw/sprite code.
Title: Re: Sprite Array
Post by: MatMan on May 16, 2011, 07:17:14 am
Sounds interesting. Nothing at the moment that I need that might use this but will look into it and see what the imagination can conjure up with this  :steamroller:
Title: Re: Sprite Array
Post by: Damon Caskey on May 16, 2011, 08:04:43 am
Here is one use: Showing all on screen enemy life bars and icons instead of just the one you're fighting. You could do this already by getting handles from the default icons, and up until now that is exactly how I made it work. The problem came when you wanted to make playable alternates of these characters using the same model sheets while also displaying unique "player" icons. It got real messy real quick hacking up a work around. Now you just put the icons in an animation frame, pull them, draw them, and done.

(http://www.caskeys.com/dc/wp-content/uploads/2010/05/gahack0002.png)

It would also be useful for pretty much any kind of direct draw sprites you want to use. Currently when you use the loadsprite() command, the sprite is loaded and it never goes away; there is no "unload" capability. To add insult to injury, the engine even berates you in the log about it. Now, you can get those sprites from a model, and let the engine worry about managing them.

The offset thing is another big help. I'd be here all day listing the uses for that. Just having read access alone is going to eliminate a ton of code from my work.

DC
Title: Re: Sprite Array
Post by: MatMan on May 16, 2011, 08:15:29 am
Impressive :wow!:

Any chance of adding a feature to access a array list of enemies via script?
Title: Re: Sprite Array
Post by: Damon Caskey on May 16, 2011, 08:50:01 am
There is no such thing as an enemy array, so no. But in prinicipal what you are asking for is easy to do. Otherwise how could I have displayed enemy icons?

Just enumerate the entity collection and then evaluate to filter out what you do/don't want:

Code: [Select]
void main()
{
    void    vEnt;                                                                           //Entity placeholder.
    int     iType;                                                                          //Entity type.
    int     iValid;                                                                         //Entity valid.
    int     iDead;                                                                          //Entity death status.
    int     iECnt;                                                                          //Current # of entities in play.
int     iEnt;                                                                           //Entity counter.
 
    iECnt   = openborvariant("ent_max");                                                    //Get current entity count.
 
for(iEnt=0; iEnt<iECnt; iEnt++)                                                         //Loop entity collection.
{
vEnt    = getentity(iEnt);                                                          //Get entity handle.
       
        if(vEnt)                                                                            //Valid handle?
        {
            iValid  = getentityproperty(vEnt, "exists");                                    //Get exists confirmation.
            iDead   = getentityproperty(vEnt, "dead");                                      //Get death status.
            iType   = getentityproperty(vEnt, "type");                                      //Get type.
       
            if(vEnt                                                                         //Valid handle?
                && iValid                                                                   //Valid entity?
                && !iDead                                                                   //Alive?                                           
                && iType == openborconstant("TYPE_ENEMY"))                                  //Enemy type?
            {
                //Do some stuff.
            }
        }
}
}

DC








Title: Re: Sprite Array
Post by: MatMan on May 16, 2011, 10:41:32 am
Didn't know about openborvariant("ent_max"), knew about openborvariant("count_enemies"); which for obvious reasons wouldn't work as needed.

Thanx!
 :peace:
SimplePortal 2.3.3 © 2008-2010, SimplePortal