How interested would the community be in a modern C++ partial rewrite/partial wrapper of libnx

noneuclideanmotion

Member
OP
Newcomer
Joined
Nov 1, 2022
Messages
13
Trophies
0
Age
21
XP
52
Country
United Kingdom
After using it for a little bit, it feels very old fashioned when writing with it using C++. This is not the fault of the developers, of course, it is written in C. I also noticed there were a lot of bugs and things that didn't work properly and the biggest thing: the lack of clear documentation! I spent just under a week trying to figure out how it handles fonts (turns out, it requires a literal 1-1 binary representation of the glyphs and that's all it can handle).

I'm very comfortable with C++, so I've been thinking about making my own library based off of libnx for modern C++, with object oriented, function concepts and as much clear documentation as I can cram into it, as I find that a lot easier to work with compared to endless functions which I barely know the function of (ironic). I've already started it, mainly for myself, but I'm just doing a litmus test to see if anybody else would be interested.

I've started with a console API, here is an example program

Code:
#import <lnxw/console.hpp>

int main() {
    lnxw::console default_console;             //no argument creates a default console
   
    //Alternative way of making a console
    lnxw::console::properties p;
    p.text_color = lnxw::color::BLUE;
    p.background_color = lnxw::color::RED;  //RGB values work as well
    lnxw::console other_console(p);
    //Obviously you could also use curly braces to define the properties within the constructor
    //properties have the following attibutes (more to come!)
    /* this is the definition with the default values
    struct properties {
            uint16_t        cursor_x           = 0;
            uint16_t        cursor_y           = 0;
            uint16_t        width              = 80;
            uint16_t        height             = 45;
            uint8_t         tab_width          = 5;
            uint8_t         text_size          = 16;
            color            text_color         = color::WHITE;
            color            background_color   = color::BLACK;
            console::font   font               = console::font::default_font;
        };
    */
   
    default_console.print<std::string>("Hello World!\n"); //will print white text on black background
    other_console.print<std::string>("Hello World too!\n");
    // You don't need the <> as it will automatically determine the type
   
    std::cout << "Hello world using cout";
    //Cout will be directed to the last used console I'm planning to add the following syntax:
    std::cout << console_to_print_to << "words";
    std::cout << nxlink << "print to pc screen";
   
    return 0;
}

Without all the comments, here would be a simple hello world program:

Code:
import <lnxw/console.hpp>;
import <iostream>;
int main() {
    lnxw::console::default::print("Hello world!");
    //or
    lnxw::console default;
    default.print("Hello World");
   
    //or or
    lnxw::console default;
    std::cout << "Hello world!"
}

Just one or two lines!

This is compared to libnx's hello world which is this:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <switch.h>

// Main program entrypoint
int main(int argc, char* argv[])
{
    consoleInit(NULL);
    padConfigureInput(1, HidNpadStyleSet_NpadStandard);
    printf("Hello World!\n");
    while (appletMainLoop())
    {
        consoleUpdate(NULL);
    }
    consoleExit(NULL);
    return 0;
}

My console class is just a wrapper right now, but I'm planning to just remake it completely since the libnx has quite a few bugs in it's console.h and I'm already using a custom version of the library to even be able to allow you to change the console at all. (In the official libnx, you are not able to change the colour, text size, etc due to what I think is a bug)

Any anyway, would anybody be interested?
 
  • Like
Reactions: white5pirit

white5pirit

New Member
Newbie
Joined
Oct 24, 2021
Messages
1
Trophies
0
Age
23
XP
26
Country
United Kingdom
After using it for a little bit, it feels very old fashioned when writing with it using C++. This is not the fault of the developers, of course, it is written in C. I also noticed there were a lot of bugs and things that didn't work properly and the biggest thing: the lack of clear documentation! I spent just under a week trying to figure out how it handles fonts (turns out, it requires a literal 1-1 binary representation of the glyphs and that's all it can handle).

I'm very comfortable with C++, so I've been thinking about making my own library based off of libnx for modern C++, with object oriented, function concepts and as much clear documentation as I can cram into it, as I find that a lot easier to work with compared to endless functions which I barely know the function of (ironic). I've already started it, mainly for myself, but I'm just doing a litmus test to see if anybody else would be interested.

I've started with a console API, here is an example program

Code:
#import <lnxw/console.hpp>

int main() {
    lnxw::console default_console;             //no argument creates a default console
  
    //Alternative way of making a console
    lnxw::console::properties p;
    p.text_color = lnxw::color::BLUE;
    p.background_color = lnxw::color::RED;  //RGB values work as well
    lnxw::console other_console(p);
    //Obviously you could also use curly braces to define the properties within the constructor
    //properties have the following attibutes (more to come!)
    /* this is the definition with the default values
    struct properties {
            uint16_t        cursor_x           = 0;
            uint16_t        cursor_y           = 0;
            uint16_t        width              = 80;
            uint16_t        height             = 45;
            uint8_t         tab_width          = 5;
            uint8_t         text_size          = 16;
            color            text_color         = color::WHITE;
            color            background_color   = color::BLACK;
            console::font   font               = console::font::default_font;
        };
    */
  
    default_console.print<std::string>("Hello World!\n"); //will print white text on black background
    other_console.print<std::string>("Hello World too!\n");
    // You don't need the <> as it will automatically determine the type
  
    std::cout << "Hello world using cout";
    //Cout will be directed to the last used console I'm planning to add the following syntax:
    std::cout << console_to_print_to << "words";
    std::cout << nxlink << "print to pc screen";
  
    return 0;
}

Without all the comments, here would be a simple hello world program:

Code:
import <lnxw/console.hpp>;
import <iostream>;
int main() {
    lnxw::console::default::print("Hello world!");
    //or
    lnxw::console default;
    default.print("Hello World");
  
    //or or
    lnxw::console default;
    std::cout << "Hello world!"
}

Just one or two lines!

This is compared to libnx's hello world which is this:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <switch.h>

// Main program entrypoint
int main(int argc, char* argv[])
{
    consoleInit(NULL);
    padConfigureInput(1, HidNpadStyleSet_NpadStandard);
    printf("Hello World!\n");
    while (appletMainLoop())
    {
        consoleUpdate(NULL);
    }
    consoleExit(NULL);
    return 0;
}

My console class is just a wrapper right now, but I'm planning to just remake it completely since the libnx has quite a few bugs in it's console.h and I'm already using a custom version of the library to even be able to allow you to change the console at all. (In the official libnx, you are not able to change the colour, text size, etc due to what I think is a bug)

Any anyway, would anybody be interested?
That would be super nice 👀
 

masagrator

The patches guy
Member
Joined
Oct 14, 2018
Messages
5,731
Trophies
3
XP
10,708
Country
Poland
Guy seems to stop coming here.
Beside his example is wrong. It's not in loop, so it would exit immediately before anybody would see what was printed in console.
I was curious how it would handle exiting from loop.
 
Last edited by masagrator,
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Skelletonike @ Skelletonike:
    1H left, such a slow week.
  • Sonic Angel Knight @ Sonic Angel Knight:
    Okay, I had spaghetti :P
  • SylverReZ @ SylverReZ:
    Hope they made lots of spaget
  • K3N1 @ K3N1:
    Chill dog
  • SylverReZ @ SylverReZ:
    Chilli dog
  • Skelletonike @ Skelletonike:
    Damn, I'm loving the new zelda.
  • xtremegamer @ xtremegamer:
    loving the new zelda, i started a game, it was so fucking good, so i
    am waiting on my friend to get home so we can start a new one together
  • Skelletonike @ Skelletonike:
    I just dislike that they don't let me choose the voices before the game starts. Happened with botw as well, had to change to japanese and restart.
  • K3N1 @ K3N1:
    But the important question is can you choose gender
  • Skelletonike @ Skelletonike:
    Same way you can choose Gerald's gender.
  • Skelletonike @ Skelletonike:
    *Geralt, damn autocorrect.
  • Psionic Roshambo @ Psionic Roshambo:
    But can he be trans? Lol
  • K3N1 @ K3N1:
    Zelda transforms into link
  • Psionic Roshambo @ Psionic Roshambo:
    Link I'm not the princess your looking for.... *Pulls a crying game*
  • K3N1 @ K3N1:
    *skirt up* it's exactly what I always wanted
  • Skelletonike @ Skelletonike:
    Just scanned all my zelda amiibos, took a while but didn't get anything that cool, did get the lon lon ranch hylian fabrics though.
  • Skelletonike @ Skelletonike:
    It was pretty funny when I scanned wolf link and got a shit load of meat.
  • K3N1 @ K3N1:
    @Skelletonike, btw I ran that custom for mgs4 on the deck I'm amazed it got that far in game
  • K3N1 @ K3N1:
    Plug in*
  • K3N1 @ K3N1:
    Your favorite activity
  • BentlyMods @ BentlyMods:
    My fav actvity is:

    mario-dancing.gif
    BentlyMods @ BentlyMods: My fav actvity is: