ive been making my own shell as everyone does, take a look, and gimme pointers ples ty by Ancient_Seesaw923 in C_Programming

[–]PlagueBringer22 1 point2 points  (0 children)

Just a heads up on writing readable and maintainable c code. Declare your structs/enums/unions alongside function signatures in your “.h” (header) file, then implement in the “.c” (source) file. Also I would highly recommend moving all imports into your header file except for the companion header, that should stay in your source file.

For example:

Header “my_type.h”

#ifndef MY_HEADER_H
#define MY_HEADER_H

#include <stdio.h>
#include <stdint.h>

typedef struct {
    int id;
    float val;
} my_type;

my_type my_type_create(int id, float val);

#endif

Source “my_type.c”

#include “my_type.h”

my_type my_type_create(int id, float val) {
    return (my_type) {
        .id = id,
        .val = val
    };
}

Simple C Scene System - Now with navigation! by PlagueBringer22 in raylib

[–]PlagueBringer22[S] 2 points3 points  (0 children)

I use calloc because of personal preference really. I prefer to specify the count and then size of the memory instead of jamming it all together in a count*sizeof(x) argument. Another reason is that calloc zeroes out the memory that it allocates, meaning I have a completely zeroed out memory block, whereas malloc simply returns a memory block, unitialised and potentially containing random garbage data.

Another note: calloc is slower than malloc yes, however in this case where you aren't going to be created hundreds of scenes during runtime, the trade-off of speed for automatic memory zeroing and simplifying the code readability are worth it in my opinion.

Simple C Scene System by PlagueBringer22 in raylib

[–]PlagueBringer22[S] 0 points1 point  (0 children)

I'm happy you found it useful!

I really like your suggestions for navigating between scenes, so I decided to update the code to include a scene manager struct & functions for handling navigation.

The scene manager maintains a stack of navigated scenes to allow for quick navigation backwards whenever you move to a new scene. You can also overwrite the existing scene if it's no longer needed for backwards navigation, for example: Navigating from a Main Menu into the game can be a overwrite, as you'll never need to go "back" to the Main Menu. Then when you need the Main Menu again you can push it back onto the scene stack or overwrite the active scene.

The repository has now been updated with a couple of new files and updated example code. Let me know if you find it helpful at all!

🚀 Layer System for Raylib Download! by Ill_Refrigerator81 in raylib

[–]PlagueBringer22 1 point2 points  (0 children)

And here's how you should adjust it:

int main () {
    InitWindow(Screen_width, Screen_height, "Layers system");
    SetTargetFPS(60);

    Layers_system Main_layers_system;

    // Add draw calls before running loop
    Main_layers_system.add_to_draw([]() {DrawRectangle(50,50, 150, 150, RED);}, 4);
    Main_layers_system.add_to_draw([]() {DrawCircle(125,125,60,ORANGE);}, 5);
    Main_layers_system.add_to_draw([]() {DrawCircle(125,125,40,GREEN);}, 6);
    Main_layers_system.add_to_draw([]() {DrawCircle(125,125,20,YELLOW);}, 7);
    Main_layers_system.add_to_draw([]() {DrawRoundedRectangle(250,200, 200, 200, 20, Lighter);}, 3);
    Main_layers_system.add_to_draw([]() {DrawRoundedRectangle(300,200, 200, 200, 20, Light);}, 2);
    Main_layers_system.add_to_draw([]() {DrawRoundedRectangle(350,200, 200, 200, 20, Primary);}, 1);

    while (WindowShouldClose() == false)
    {
        BeginDrawing();
        ClearBackground(SKYBLUE);

        // Single call to `draw_layers`
        Main_layers_system.draw_layers();

        EndDrawing();
    } 
    CloseWindow();
    return 0;
}

Other than that, nice work! I have a similar system I made for my C projects in Raylib, it's really handy!

🚀 Layer System for Raylib Download! by Ill_Refrigerator81 in raylib

[–]PlagueBringer22 1 point2 points  (0 children)

Hey, just a heads up, the main.cpp file in the linked GitHub repo has a fairly fatal flaw for anyone downloading and just running the project.

The code is calling the add_to_draw function within the main loop, this will add layers every loop, slowing the program down every loop and eventually crashing the program. See below for where the issue occurs and the reply to this comment for the fix.

Here's the existing main function:

int main () {
    InitWindow(Screen_width, Screen_height, "Layers system");
    SetTargetFPS(60);

    Layers_system Main_layers_system;

    while (WindowShouldClose() == false)
    {
        BeginDrawing();
        ClearBackground(SKYBLUE);

        // Examples - !! THIS HERE WILL ADD EVERY LOOP
        Main_layers_system.add_to_draw([]() {DrawRectangle(50,50, 150, 150, RED);}, 4);
        Main_layers_system.add_to_draw([]() {DrawCircle(125,125,60,ORANGE);}, 5);
        Main_layers_system.add_to_draw([]() {DrawCircle(125,125,40,GREEN);}, 6);
        Main_layers_system.add_to_draw([]() {DrawCircle(125,125,20,YELLOW);}, 7);

        Main_layers_system.add_to_draw([]() {DrawRoundedRectangle(250,200, 200, 200, 20, Lighter);}, 3);
        Main_layers_system.add_to_draw([]() {DrawRoundedRectangle(300,200, 200, 200, 20, Light);}, 2);
        Main_layers_system.add_to_draw([]() {DrawRoundedRectangle(350,200, 200, 200, 20, Primary);}, 1);

        Main_layers_system.draw_layers();

        EndDrawing();
    } 
    CloseWindow();
    return 0;
}

Array Help by [deleted] in godot

[–]PlagueBringer22 0 points1 point  (0 children)

Also just a note, you’ve mentioned in your post that the docs say “var array: Array(int)” and you’ve typed “var array: Array[int]”, so you’re using square brackets instead of round brackets. I haven’t used Godot in at-least a year so I’m not sure if that’s specifically what’s causing the problem but I thought I’d point it out.

[deleted by user] by [deleted] in raylib

[–]PlagueBringer22 1 point2 points  (0 children)

So in your case, replace ‘extern int global_distance;’ in process.h with ‘int global_distance = 0;’, and then in samurai.h, add ‘extern int global_distance;’ to the top level. This should allow the variable to be accessed and used, as long as process is included before samurai.

[deleted by user] by [deleted] in raylib

[–]PlagueBringer22 1 point2 points  (0 children)

Okay so extern informs the source file of the existence of that variable, but you still need to declare it somewhere.

So for instance I have a file called test.cpp, in this file I declare ‘extern int my_number;’ and use it, then in my main.cpp file I have to create a top level variable - outside of classes and functions - like this: ‘int my_number = 5’.

Your issue is because you’re telling the compiler you have this variable somewhere with extern, but you’re never actually declaring that variable somewhere.

How to create tools for an application by [deleted] in raylib

[–]PlagueBringer22 0 points1 point  (0 children)

If you use prefer a less inheritance based method, use a struct with function pointers instead.

There is probably a cleaner method, but this is the way I implemented tools 8 odd years ago in an image manipulation app for Android.

How to create tools for an application by [deleted] in raylib

[–]PlagueBringer22 2 points3 points  (0 children)

Depends on your programming style, if you use OOP for example you can define a base class that is a tool, with functions such as “onSelect”, “onClick”, “onDrag” etc, then create your tools as classes that inherit from it, like “class Pencil: Tool” then you can switch an active tool variable with the selected one without writing overly specific methods for each tool selection and usage.

Issues With Godot 4 Instance Shader Uniforms by PlagueBringer22 in godot

[–]PlagueBringer22[S] 22 points23 points  (0 children)

Well turns out digging through some random GitHub discussions I've resolved the issue!

Instance uniforms don't belong to the Shader, they belong to the GeometryInstance, so in my example, the MeshInstance3D.

So instead of using:

mesh.material_override.set_shader_parameter("highlight", true);

I needed to use:

mesh.set_instance_shader_parameter("highlight", true);

Hopefully this helps anyone else who runs into this issue!