Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, Quad, 1 invisible), 721 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
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 Offline OP
Senior Member
Clemens  Offline 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:

Code:
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: Clemens] #382769
09/12/11 15:43
09/12/11 15:43
Joined: Feb 2010
Posts: 320
TANA/Madagascar
3dgs_snake Offline
Senior Member
3dgs_snake  Offline
Senior Member

Joined: Feb 2010
Posts: 320
TANA/Madagascar
I don't kow if there is a function to what you want to do but I think that overloading draw_object would be a solution.

Best regards.

Re: How to identify the type of a struct? [Re: 3dgs_snake] #382770
09/12/11 15:53
09/12/11 15:53
Joined: Feb 2011
Posts: 135
Myrkling Offline
Member
Myrkling  Offline
Member

Joined: Feb 2011
Posts: 135
"The handle can be used to identify the type of the object."
See here: http://www.conitec.net/beta/ain-handle.htm

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
T
TechMuc Offline
User
TechMuc  Offline
User
T

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 wink )

Last edited by TechMuc; 09/12/11 16:12.
Re: How to identify the type of a struct? [Re: TechMuc] #382791
09/12/11 19:11
09/12/11 19:11
Joined: Sep 2003
Posts: 303
Germany
Clemens Offline OP
Senior Member
Clemens  Offline OP
Senior Member

Joined: Sep 2003
Posts: 303
Germany
Thanks for the manual hint - didn't know that handle is good for that.

But cause I'm far away from beeing a struct/pointer/bit-shifting expert... there are two problems appearing for me:

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?
(something I probably would be able to find out with enough time...)

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...)

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 Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Originally Posted By: Clemens
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]
Code:
int type = (int)(((var)handle(myObject)) >> 24);
type = type << 10;

if(type == HBYTE_PANEL)
{
   ...
}
etc..



Originally Posted By: Clemens
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 Offline OP
Senior Member
Clemens  Offline OP
Senior Member

Joined: Sep 2003
Posts: 303
Germany
1) -> Sid, thx for that piece... but when I change my code into:
Code:
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 wink 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 Offline
Expert
WretchedSid  Offline
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 wink


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 Offline OP
Senior Member
Clemens  Offline 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! wink
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 Offline
Member
Myrkling  Offline
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.
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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