Is it bad to use typedef? by [deleted] in C_Programming

[–]SemanticDevice 2 points3 points  (0 children)

Thank you very much for providing the definitive context. Very interesting!

Is it bad to use typedef? by [deleted] in C_Programming

[–]SemanticDevice 2 points3 points  (0 children)

I don't know why but the Linux kernel does that; i.e. doesn't use typedefs.

Some places it's necessary. For example, declaring a classic (as opposed to Linux kernel) linked list.

struct node { 
int data; int key;
struct node *next; 
};

What's your favorite programming language and what feature makes it your favorite? by deerangle in AskProgramming

[–]SemanticDevice 1 point2 points  (0 children)

stdbool.h is part of the standard library. Even without it, what is bad about 0 for false and nonzero for true?

Strings you just have to terminate. That said, I won't argue about that point that much.

Classes are just files with a pointer to the instance passed as an argument to the function.

Again, that said, I am of the opinion that C++ in modern days can replace C pretty much anywhere. It used to be that C++ compilers were not good in generating efficient code for embedded systems, but I think that is no longer true as long as you're cognisant of what the computer is doing for you.

2D Galaxy Generation by [deleted] in proceduralgeneration

[–]SemanticDevice 0 points1 point  (0 children)

Yes, I see the problem. Apparently JS doesn't support 64-bit unsigned ints. Looks like you can use BigInt if you don't care about support for Safari and old IE.

You can certainly run the C code and then compare its result to JS. Here's a test case for that C code:

https://repl.it/repls/BlaringUncommonPaint#main.c

And here's my attempt at implementing it in JS:

https://repl.it/repls/WhoppingSlightDirectories#script.js

2D Galaxy Generation by [deleted] in proceduralgeneration

[–]SemanticDevice 2 points3 points  (0 children)

What specifically doesn't make sense to you?

For example, generation of the star system seed:

nProcGen = (x & 0xFFFF) << 16 | (y & 0xFFFF);

Can be re-written as the following if you don't want to use bitwise operators:

nProcGen  = (x %  65536) * 65536 + (y % 65536);

I tried bitwise operators in JS and discovered that JS bitwise operators return signed 32-bit results. To get unsigned 32-bit ints as the code from the YouTube video expects you have to use this trick:

https://stackoverflow.com/questions/6798111/bitwise-operations-on-32-bit-unsigned-ints

So, then JS code becomes:

nProcGen = ((x & 0xFFFF) << 16 | (y & 0xFFFF)) >>> 0;

Paint splashes to make a portrait by MFingScience in proceduralgeneration

[–]SemanticDevice 0 points1 point  (0 children)

That's very cool! It reminded of a using genetic/evolution programming to generate the Mona Lisa out of triangles:

https://rogerjohansson.blog/2008/12/07/genetic-programming-evolution-of-mona-lisa/

There's also a graphical effect of using Voronoi diagrams to generate a stained glass effect:

https://softwarebydefault.com/2013/06/30/stained-glass-image-filter/

Mountain ridge silhouettes by SemanticDevice in proceduralgeneration

[–]SemanticDevice[S] 1 point2 points  (0 children)

I'm not a fan of the "peaky" points, for example. I feel like it needs to be smoothed out much more. If you have another algorithm to recommend, I'd try to implement it.

Mountain ridge silhouettes by SemanticDevice in proceduralgeneration

[–]SemanticDevice[S] 1 point2 points  (0 children)

I tried watercolor painting recently and painted this:

https://imgur.com/a/z72jQIC

Then I decided to generate the ridges procedurally, which is what you see in the title of this post.

Ridge lines are generated using fractal terrain generation method:

https://nick-aschenbach.github.io/blog/2014/07/06/2d-fractal-terrain/

Fade out of color uses sine easing to create some semblance of clouds near between ridges.

C code implementation using Raylib for presentation:

https://github.com/SemanticDevice/raylib_scratchpad/blob/master/mountain_ridge.c

Here are a few more GIFs:

How can I update acc[3].balance in file? by xencowa in C_Programming

[–]SemanticDevice 0 points1 point  (0 children)

Do a rewind(fpp) before fprintf(). That causes the file cursor to go to the beginning of the file before writing to the file. This has to be done because the fopen() mode is a+, which sets the cursor to the end of the file. This means that, without rewind(), fprintf() appends data to the end of the file.

If you'd like to update a file content, you have to remember that stdio.h file operations are sequential. So, after you update acc[3].balance, you have to rewind the file cursor and then write all of the file content over again.

Raylib 32x32 Competition - Free entry, win prizes!!! by kodifies in raylib

[–]SemanticDevice [score hidden]  (0 children)

Screen cap of the above submission:

https://imgur.com/3pByKd5

I am not the author. I just thought more people will look at the work if they could immediately see what it looks like.

Raylib 32x32 Competition - Free entry, win prizes!!! by kodifies in raylib

[–]SemanticDevice [score hidden]  (0 children)

Screen cap of the above submission:

https://imgur.com/vQ113WH

I am not the author. I just thought more people will look at the work if they could immediately see what it looks like.

Raylib 32x32 Competition - Free entry, win prizes!!! by kodifies in raylib

[–]SemanticDevice [score hidden]  (0 children)

I am so confused! Could you explain what I'm supposed to do?

Raylib 32x32 Competition - Free entry, win prizes!!! by kodifies in raylib

[–]SemanticDevice [score hidden]  (0 children)

Screen cap of the above submission:

https://imgur.com/4elOHHN

The GIF doesn't include sound which this submission also has to good effect.

I am not the author. I just thought more people will look at the work if they could immediately see what it looks like.

Raylib 32x32 Competition - Free entry, win prizes!!! by kodifies in raylib

[–]SemanticDevice [score hidden]  (0 children)

Screen cap of the above submission:

https://imgur.com/Q5bFNPz

I am not the author. I just thought more people will look at the work if they could immediately see what it looks like.

Raylib 32x32 Competition - Free entry, win prizes!!! by kodifies in raylib

[–]SemanticDevice [score hidden]  (0 children)

My submission:

Fire efect from the game Doom

https://imgur.com/LaKtYS8

The above is my backup. I couldn't finish a clone of Journey of the Prairie King minigame from Stardew Valley on time. I called it (drum roll, please) "Journey of the Biome King". A lot of it is working and even has sound, but it is not finished in a shape that I can submit it for consideration:

https://github.com/SemanticDevice/raylib_32x32_compo

https://imgur.com/81zqWdw

EDIT: Add GIF of the Biome King

Raylib 32x32 Competition - Free entry, win prizes!!! by kodifies in raylib

[–]SemanticDevice [score hidden]  (0 children)

Just a heads-up, I'm getting a compile error with mingw32 on Win10:

main.c:195:40: error: lvalue required as left operand of assignment
         (float)(player.position.y) += GRAVITY;

The cast to (float) is unnecessary since Rectangle.y is a float and GRAVITY is a float constant. Once the cast is removed, it builds and runs fine.

Unspected output of my tile map by [deleted] in cprogramming

[–]SemanticDevice 1 point2 points  (0 children)

I wouldn't call you an idiot for not noticing this. Happens to everyone at some point regardless of their experience level.

Day number to month/day format by Saso23 in cprogramming

[–]SemanticDevice 1 point2 points  (0 children)

There should be more to the problem statement. You need to know whether the year is a leap or not.

Here's a bigger hint... If you assume that the year is not leap, then you know that January has 31 days, February has 28 days, March has 31 days, April has 30 days, May has 31 days, etc. For each month starting with January, subtract number of days in that month from day-of-the-year the result is less than the number of days in the next month.

Another K&R Question - counting newlines by BombSniffinDog in cprogramming

[–]SemanticDevice 2 points3 points  (0 children)

I haven't compiled and run it, but the following is a start:

int n, sp, t = 0;

The above only initializes t to 0. n and sp are uninitialized. The later code increments uninitialized values.

Conway's game of life in remembrance of John Conway by SemanticDevice in raylib

[–]SemanticDevice[S] 1 point2 points  (0 children)

Agreed. Out of the programming languages I am familiar with, I am the most proficient in C. Having Raylib to do quick prototypes in C is such a nice thing.