Gamestudio Links
Zorro Links
Newest Posts
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
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Trading Journey
by howardR. 04/24/24 20:04
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
5 registered members (Petra, AndrewAMD, VoroneTZ, 2 invisible), 822 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
fixed vs. fixv #416207
01/29/13 03:47
01/29/13 03:47
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline OP
Expert
Uhrwerk  Offline OP
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Hello Mr. Lotter,

I guess the manual page concerning fixed(float) isn't correct.

http://www.conitec.net/beta/afixed.htm

The functions name should be "fixv", not "fixed", right? At least that's what the example on that page suggests and what actually compiles. Using "fixed" results in an compile time error.

The type of the parameter should also be float, not var.


Always learn from history, to be sure you make the same mistakes again...
Re: fixed vs. fixv [Re: Uhrwerk] #416221
01/29/13 10:37
01/29/13 10:37
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
This macro is certainly confusing, even to programmers, so I've written the description a little more clearly. You can see in its #define in acknex.h what it does. And yes, the name is indeed 'fixv' and not 'fixed'.

Re: fixed vs. fixv [Re: jcl] #416237
01/29/13 16:25
01/29/13 16:25
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline OP
Expert
Uhrwerk  Offline OP
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
I can only speak for myself here, but for me the changes you did have not made the description any clearer. Especially the term "'real' var" might confuse beginners even more. In the end it comes down to a format conversion from the IEEE floating point format to the fixed format gamestudio uses, right?

Maybe you could cure my curiosity and explain how this monstrum works:
Code:
*((float*)&(x))


Casting the address of the var to float* and dereferencing it again does not make sense on a first glance to me. ^^ I had expected something like
Code:
((float)(x))



Always learn from history, to be sure you make the same mistakes again...
Re: fixed vs. fixv [Re: Uhrwerk] #416245
01/29/13 17:10
01/29/13 17:10
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
That's what I feared - fixv() and floatv() are really hard to explain and to understand because they go against the 'normal' C use. C freaks will know the methods, but in scripts they are fortunately very, very rarely used, so if you do not understand them, you'll certainly never need them. Anyway I try again:

floatv() stores a float in the memory space of a var.

fixv() converts a float stored in the memory space of a var to a var. The fixv macro is needed to tell the compiler that the var is in fact a float, not a var.

That explanation is probably not much better, but the only example I know that uses floatv and fixv is the water.c script.


Re: fixed vs. fixv [Re: jcl] #416251
01/29/13 18:50
01/29/13 18:50
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline OP
Expert
Uhrwerk  Offline OP
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
This explanation is perfectly fine for me. So, more precisely it is not a conversion that takes place but instead a hint to the compiler concerning the actual number representation format the number is encoded in, isn't it?

The scenario in water.c corresponds exactly to my use case with the exception that I use material skills instead of entity skills.

Thanks for taking the time to explain. Your patience is highly appreciated.


Always learn from history, to be sure you make the same mistakes again...
Re: fixed vs. fixv [Re: Uhrwerk] #416264
01/29/13 20:27
01/29/13 20:27
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
Originally Posted By: Uhrwerk
This explanation is perfectly fine for me. So, more precisely it is not a conversion that takes place but instead a hint to the compiler concerning the actual number representation format the number is encoded in, isn't it?

Correct, that's why a simple cast ala ((float)x) won't work here, because then the compiler would attempt to convert the variable into a float, which it already is. By taking the address of the variable and casting it to a float pointer, no conversion is done, and dereferencing a float pointer won't do any conversion either.

imho this is pretty dirty since it actively tries to "outsmart" the compilers typesystem. Wouldn't it be better to make at least the material skills float by default and then use an implicit type cast? (As far as I can see, they are expected to be float anyways)

Quote:
That explanation is probably not much better

It should be noted that there is no actual conversion happening (with the exception being var -> float), but instead that the functions are used to force a float into a var without any implicit conversion that would occur if one would just type 'x = y'


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: fixed vs. fixv [Re: WretchedSid] #416287
01/30/13 08:27
01/30/13 08:27
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
It is indeed a dirty method, resulting from WDL legacy. WDL had only one variable type, so when floats were needed they had to be stored in the memory space of vars.

Re: fixed vs. fixv [Re: jcl] #416299
01/30/13 10:32
01/30/13 10:32
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
hmm what about changing the type of the material skills to float?
you won't brake old code if the fixv, floatv defines will be changed to just
#define fixv(x) x


Visit my site: www.masterq32.de
Re: fixed vs. fixv [Re: MasterQ32] #416396
01/30/13 23:32
01/30/13 23:32
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
You will since the invocation of fixv() and floatv() isn't guaranteed to be exclusive for material skills.


Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com
Re: fixed vs. fixv [Re: WretchedSid] #416397
01/31/13 00:23
01/31/13 00:23
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline OP
Expert
Uhrwerk  Offline OP
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
@JustSid: Thanks, your posts are always helpful.

@MasterQ32: I don't think that this is a good suggestion. Tons of code might break with this change. Apart from that: there is no need to change. The discussion we're doing here is very interesting for me. But you don't need to understand a word of what's being written here in order to successfully apply the concept.

@jcl: In the end it can be brought down to: Use floatv when you want to pass something to a shader, use fixv for the inverse operation. I'm the living proof for that as I applied the technique correctly without even knowing fixv was a macro and how it worked. I guess this is even the most important message for the manual page. I don't know if the background information about memory space and casting is really required there. If however you want to include advanced info the JustSid is absolutely right with:
Originally Posted By: JustSid
It should be noted that there is no actual conversion happening (with the exception being var -> float), but instead that the functions are used to force a float into a var without any implicit conversion that would occur if one would just type 'x = y'

The example provided on the manual page does not do a good job from my point of view. Just showing the inverse function does not make the purpose or the usage of the function any clearer. It's quite the opposite for. When there are two functions and one reverses the other you might expect that both of them do a conversion.


Always learn from history, to be sure you make the same mistakes again...

Moderated by  aztec, Inestical, Matt_Coles, Tobias 

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