Inside3D!
     

fteqcc structures

 
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming
View previous topic :: View next topic  
Author Message
mike



Joined: 14 Jan 2007
Posts: 4

PostPosted: Sun Jan 14, 2007 5:58 am    Post subject: fteqcc structures Reply with quote

Hey,

I've read that fteqcc supports structures, but I can't seem to find
out how to use them.
I'm using fteqcc compiler build 2770.

example:

struct
{
float type;
} type_t;

void () testfunction =
{
local float i;
.....
i->type = 1;
};

I've tried the . and -> operands,
using type_t *i (as in C)
float *i,
using the .struct { float type } ;
and more that I've probably forgotton.

I'm new to these newer functions of quakec, I've modded basic
quakec for awhile to make simple mods for quakeworld, and some
new basic weapons, so I'm not really that new to quakec in general.

Could someone show me the way with a basic example like I had?
Thanks.
Back to top
View user's profile Send private message
Spike



Joined: 05 Nov 2004
Posts: 944
Location: UK

PostPosted: Sun Jan 14, 2007 6:29 am    Post subject: Reply with quote

the quakec virtual machine isn't very advanced, unfortunately.

.union
{
struct
{
float teamkills;
}; //player fields
struct
{
float nextrespawn;
}; //pickup ents
//etc
};

Then use them as normal entity fields.
eg: self.teamkills += 1;

Each field in the structs in the unions are maped over each other, creating a handy field reuse. This syntax is actually derived from HexenC. You can use as many structs / unions as you want. You should also be able to nest them lots (just lots of .unions without fields might be cleaner, depends on your coding style, unfortunatly).
Please, try very hard to not mix up variable types. Saved games will malfunction if you do mix them badly.

Note the equivelent frikqcc notation (also supported):
.float teamkills; //player only field
.float nextrespawn = teamkills; //pickup only field
This is probably more useful, and is supported on other qccs also.
Use whichever you prefer.





The more complicated struct stuff is along the lines of:

typedef struct
{
float blob;
} mystruct_t;

mystruct_t bloby;

void somefunc()
{
bloby.blob = 4;
}

Although really this use is fairly pointless. Still, if bloby was defined as an array it would clarify some code (I hope that works properly...).

Passing structures is not supported due to limitations of the quakec vm, so yeah, structs of this sort are of bugger all use.

If you're using -TFTE on the qcc comandline, you should gain access to additional functionality:

float somefunc2(mystruct_t *s)
{
return s.blob;
}
void somefunc3()
{
bprint("bloby.blob = ", stof(somefunc(&bloby)), "\n");
}

(I think fteqcc uses '.' all over, even for *struct... I don't remember, I also don't remember how well this was tested, and you still need to have the struct as a global in the first place to get a pointer to it)

But yeah, all this stuff is under tested. There's not been much interest in FTE-only mods (bah), as well as noone crazy enough to write a reasonable test mod, including me.




But yeah, fte nameless structs are a behaviour cloned from hexenc. They serve to merge fields in a non-explicit way. Hexen2 has many faults resulting from this usage (including the invincible spiders/scorpions bug at the start of many maps), due to forgetting that fields were specific to one entity (the damage code uses a player-only field for any entity).



I would recommend the class notation instead... But its buggy crap. So just use the frikqcc notation where you specify which fields are aliases of others.

.float teamkills; //player only field
.float nextrespawn = teamkills; //pickup only field

By using explicit notation, there's no mismatched field types, and you're reminded of the h2 issue each time you add a new field.
Throw it into a single comment and you have something like the .union / struct solution.
_________________
What's a signature?
Back to top
View user's profile Send private message Visit poster's website
mike



Joined: 14 Jan 2007
Posts: 4

PostPosted: Sun Jan 14, 2007 6:55 am    Post subject: Reply with quote

Thanks for the quick reply Spike.

You've helped clarify many issues about the quakec structures and
better ways to code.

Thanks again.
(keep up the good work on the fteqcc compiler & engine :p)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Inside3d Forums Forum Index -> QuakeC Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2004 phpBB Group