Skip to content

Conversation

Sigmarik
Copy link

Formatted the code to match commonly used C style

Added file format extension to indicate it is written in GLSL

Renamed global specific-use seed variable to __RNG_SEED__ to indicate it is being treated as a used-inaccessible variable.
Also freed frequently used variable name seed.

Removed unused input parameter s from macro random_get_seed(). Also made it non-modifiable L-value, so syntax like random_get_seed() = 5.0 would be invalid.

Fixed many macro inconveniences that would have made them unusable in most cases.

For example, there was this beautiful transition in macro angle_difference(d,s):

#define angle_difference(d,s)   (mod(d-s+180.0, 360.0)-180.0)

So parameter s can only contain multiplication, but any exposed addition or subtraction would be inversed as soon at it is passed into macro?

Lets also take a look at the next macro

#define mean2(a,b)          ((a)+(b))/2.0

Now imagine it would be passed into the code like this:

float some_variable = 1.0 / mean2(alpha, beta);

The code above would be transformed into

float some_variable = 1.0 / ((alpha)+(beta))/2.0;

which would indeed be equivalent of

float some_variable = 0.5 / (alpha + beta);

which is not the result the user would expect from a code that originally read

float some_variable = 1.0 / mean2(alpha, beta);  // e.g. 1.0 / ((alpha + beta) / 2.0) = 2.0 / (alpha + beta)

@Sigmarik
Copy link
Author

Oh, and, by the way, there is still some work to be done. There are three macros that will not work unless you rewrite them without parameter duplication, but at this point, I think, it would be easier and more convenient to just make them all functions already.

I marked these issued macros with TODOs.

@Sigmarik Sigmarik changed the title Formatted code to match google C code style, fixed some sketchy macro transitions Many macro-related bug fixes, more convenient global variable names, code style changes Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant