5 registered members (AndrewAMD, alibaba, Konsti, 2 invisible),
1,418
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
How to identify the type of a struct?
#382755
09/12/11 14:15
09/12/11 14:15
|
Joined: Sep 2003
Posts: 303 Germany
Clemens
OP
Senior Member
|
OP
Senior Member
Joined: Sep 2003
Posts: 303
Germany
|
Hi there, I'm looking for a way to find out which struct-type has been passed:
function draw_object(... void* Object ...) {
if (Object.type==PANEL) // ??? WHAT'S THE CORRECT CODE?
// code for PANEL-position change
else
// code for TEXT((/ViewENTITY))-position change
while (...) {
draw_obj(Object);
wait(1);
}
}
|
|
|
Re: How to identify the type of a struct?
[Re: Myrkling]
#382771
09/12/11 16:11
09/12/11 16:11
|
Joined: Jul 2008
Posts: 894
TechMuc
User
|
User
Joined: Jul 2008
Posts: 894
|
though handle does ofc only work for engine objects. dynamic_cast is not available for lite-c (or any other c language )
Last edited by TechMuc; 09/12/11 16:12.
|
|
|
Re: How to identify the type of a struct?
[Re: Clemens]
#382798
09/12/11 20:24
09/12/11 20:24
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
1) How has the code to look like, when I want to -> [converting the handle to a var that contains the index number,] right shift it by 24, then left shift the resulting int by 10? [/quote]
int type = (int)(((var)handle(myObject)) >> 24);
type = type << 10;
if(type == HBYTE_PANEL)
{
...
}
etc..
2) And for my function above I forget the problem of the following compiler error: 'pos_x': is not a member of 'VOID' Object.pos_x = PositionX; (something I don't know where to start finding the solution...) Short answer: Typecast it to the appropriate type Long answer: Void is a typeless type without any informations, the compiler doesn't know where the offset to the member with the name .x is. You have to tell the compiler what type you are working with so the compiler knows where the offset is.
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: How to identify the type of a struct?
[Re: WretchedSid]
#382800
09/12/11 21:04
09/12/11 21:04
|
Joined: Sep 2003
Posts: 303 Germany
Clemens
OP
Senior Member
|
OP
Senior Member
Joined: Sep 2003
Posts: 303
Germany
|
1) -> Sid, thx for that piece... but when I change my code into:
function draw_object(... void* Object ...) {
int Object_type = (int)(((var)handle(Object)) >> 24);
Object_type = Object_type << 10;
if (Object_type==HBYTE_PANEL)
printf("panel! with %.2f",(int)Object_type);
else if (Object_type==HBYTE_TEXT)
printf("text! with %.2f",(int)Object_type);
else
printf("nothing! with %.2f",(int)Object_type);
...
}
-> always the "nothing"-message (with 0.00) is appearing even when I pass a PANEL or TEXT object... 2) -> your long answer is the explanation of the error, which I already did understand - the short answer is the really interesting part: a solution. But a too short solution how do I tell the compiler what type I'm using -> how to typecast ?
Last edited by Clemens; 09/12/11 21:19.
|
|
|
Re: How to identify the type of a struct?
[Re: Clemens]
#382805
09/12/11 22:16
09/12/11 22:16
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
Thats strange, it shifts everything like the manual says. I have nothing to test it here, so maybe someone else can help you. Btw, you do already some, wrong, typecasting in your printing function, the format specifier %f specifies a floating point variable to be printed, you pass an integer. And while we are at typecasting and stuff: http://lmgtfy.com/?q=C+style+typecast
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
handle function -> HBYTE-type -> how to??
[Re: WretchedSid]
#382813
09/13/11 00:37
09/13/11 00:37
|
Joined: Sep 2003
Posts: 303 Germany
Clemens
OP
Senior Member
|
OP
Senior Member
Joined: Sep 2003
Posts: 303
Germany
|
Hehe, it's really time for me to read a c(++) book from begin to end! Type casting is in fact a nice - less simple as it looks in code - thing!! But it surprises me, that it doesn't matter if I use ((TEXT*)Object).pos_x = PositionX; or ((PANEL*)Object).pos_x = PositionX; in my code above. Both works independet from which type is passed... (?) Problem1 -> getting the right HBYTE-type I couldn't solve it on my own, yet. Has anybody an idea what's wrong with Sid's piece of code?
|
|
|
Re: handle function -> HBYTE-type -> how to??
[Re: Clemens]
#382828
09/13/11 08:22
09/13/11 08:22
|
Joined: Feb 2011
Posts: 135
Myrkling
Member
|
Member
Joined: Feb 2011
Posts: 135
|
If I remember well, there was something special about the typecasting bit shifting thing.
I can't test it right now, but you could try something like this: int type = (int)(handle(Object) >> 14);
Last edited by Myrkling; 09/13/11 08:27. Reason: Striked typecasting.
|
|
|
|