The Ur-Quan Masters Home Page Welcome, Guest. Please login or register.
Did you miss your activation email?
January 25, 2025, 07:28:45 pm
Home Help Search Login Register
News: Celebrating 30 years of Star Control 2 - The Ur-Quan Masters

+  The Ur-Quan Masters Discussion Forum
|-+  The Ur-Quan Masters Re-Release
| |-+  Technical Issues (Moderator: Death 999)
| | |-+  Code question - (FRAME)COMMANDER_PMAP_ANIM
« previous next »
Pages: [1] Print
Author Topic: Code question - (FRAME)COMMANDER_PMAP_ANIM  (Read 2080 times)
ptx
Frungy champion
**
Offline Offline

Posts: 69


I love YaBB 1G - SP1!


View Profile
Code question - (FRAME)COMMANDER_PMAP_ANIM
« on: December 04, 2007, 05:28:08 pm »

Hi All,

This is more of a C question than anything.

I've been trying to figure out this piece of code:
Code:
comm/starbas/starbas.c:       (FRAME)COMMANDER_PMAP_ANIM, /* AlienFrame */

If I'm reading the code correctly:

* COMMANDER_PMAP_ANIM is a long value that doesn't change:
   
Code:
comm/comandr/igfxres.h:#define COMMANDER_PMAP_ANIM 0x00200002L

* FRAME is a pointer to a frame_desc structure
   
Code:
libs/gfxlib.h:typedef FRAME_DESC *FRAME;
   
Code:
libs/gfxlib.h:typedef struct frame_desc FRAME_DESC;
   
Code:
libs/graphics/drawable.h:
    struct frame_desc
    {
        DRAWABLE_TYPE Type;
        UWORD Index;
        HOT_SPOT HotSpot;
        EXTENT Bounds;
        TFB_Image *image;
        struct drawable_desc *parent;
    };

What does (FRAME)COMMANDER_PMAP_ANIM do? Pardon the silly question, I think I'm missing a key concept here.

Thanks,
-Pavel
« Last Edit: December 04, 2007, 05:30:11 pm by pc » Logged
meep-eep
Forum Admin
Enlightened
*****
Offline Offline

Posts: 2847



View Profile
Re: Code question - (FRAME)COMMANDER_PMAP_ANIM
« Reply #1 on: December 04, 2007, 06:48:25 pm »

That is very bad code. Something which should not be imitated and which we intend to remove from the UQM code in time.

Basically, the "AlienFrame" field, which has type "FRAME" (which through these typedefs is a "struct frame_desc *"), is abused to store something of a different type ("RESOURCE", which is a 32 bits integer). I assume that lateron this resource idenitifier is used to load the actual "frame_desc", which is then put in the field.

This sort of thing yields unreadable code, and can introduce bugs (what if the type of the stored data takes up more space than fits in the field?), especially when porting to different platforms where the sizes of the types may be different.

A better way to reuse the same space for storing two different things would be to use a union of the two types for the field.
Logged

“When Juffo-Wup is complete
when at last there is no Void, no Non
when the Creators return
then we can finally rest.”
ptx
Frungy champion
**
Offline Offline

Posts: 69


I love YaBB 1G - SP1!


View Profile
Re: Code question - (FRAME)COMMANDER_PMAP_ANIM
« Reply #2 on: December 04, 2007, 06:53:51 pm »

Whew! Thanks. I thought I was going crazy.

-pc
Logged
Pages: [1] Print 
« previous next »
Jump to:  


Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!