Homebrew Help! C++ question.

Discussion in 'NDS - Emulation and Homebrew' started by [GBATemp]~IceStorm, Aug 10, 2015.

  1. [GBATemp]~IceStorm
    OP

    [GBATemp]~IceStorm Banned

    Banned
    71
    5
    Oct 29, 2013
    United States
    yo mama's house
    Hi.

    I am new to DS Homebrew. I am planning on using C++ as the primary language for developing Homebrew. I also plan on using higher level aspects of C++ (such as the vtable for virtual methods). However, I am afraid that using high level concepts will cause an excess in overhead and ultimately a slowdown in the program. However, I have been told that the compiler you use can ultimately optimize away these high level constructs. Is this true?
     
  2. elhobbs

    elhobbs GBAtemp Advanced Fan

    Member
    783
    292
    Jul 28, 2008
    United States
    This is fine. I think the only thing that does not work is possibly exceptions. For the rest c++ is fine. Worry about optimization when it is a problem. Then use analysis to determine where the problem is. Don't guess or worry about the rest.
     
    Foxi4 likes this.
  3. TheToaster

    TheToaster Warrior of the Toast

    Member
    430
    160
    Aug 11, 2015
    United States
    USA
    @elhobbs
    Does the STL and generic programming work as well?
     
  4. Foxi4

    Foxi4 On the hunt...

    pip Reporter
    23,537
    21,496
    Sep 13, 2009
    Poland
    Gaming Grotto
    I wouldn't call C and C++ "high-level languages", at least not anymore. In the olden days any language that was more-or-less machine-independent (meaning "not Assembly for the particular platform") was considered "high level", but today "level" is put on large a spectrum, ranging from Assembly to interpreted languages. C and C++ are just one step above Assembly since they both provide low-level functionality, there's no need to worry, the DS is a modern platform with plenty of resources to spare. C and C++ programs are compiled directly into native binaries for the platform, the overhead is minimal, they're nothing like Java or C# programs that run on a virtual machine which in turn works on "an abstraction of an abstraction of an abstraction". Chances are that your C/C++ program will require no low-level optimization whatsoever, and if it will, then it'll be minimal. Go ahead and use C/C++, you don't have to code each and every mundane task in Assembly, somebody's done it for you already and chances are that your implementation won't be more efficient.

    Anywho, seeing that you're just starting, you might want to give my little guide a read - it'll familiarize you with some basic platform-specific concepts:

    https://gbatemp.net/threads/ds-programming-for-newbies.322106/

    For further resources, particularly low-level information, check out GBAtek - it'll help you find all the relevant registers. That, and be sure to check out libnds documentation.
     
    TheToaster likes this.
  5. TheToaster

    TheToaster Warrior of the Toast

    Member
    430
    160
    Aug 11, 2015
    United States
    USA
    Thank you,@Foxi4

    But your tutorial doesn't talk about 3D game creation! Does 3D game creation for the NDS use the same libraries as the ones in your tutorial? If so, what libraries specifically.
     
  6. Foxi4

    Foxi4 On the hunt...

    pip Reporter
    23,537
    21,496
    Sep 13, 2009
    Poland
    Gaming Grotto
    If you want to use 3D, I suggest using barebones libnds for efficiency, you'll find relevant code snippets in the Devkit Pro directory under Examples. As far as 3D on the DS is concerned, it's handled by VideoGL which is a clone of OpenGL 1.x, it should be familiar to you if you've ever coded anything using OpenGL. Keep in mind that the DS has very little VRAM (a little over 700kb IIRC) and RAM (4MB, including your code), so don't go nuts with complexity. I've been meaning to write a chapter about this, but in the advent of the 3DS it seemed pointless. Honestly, I suggest a 2D project for starters just to get the hang of platform-specific quirks, you can deal with 3D once you're comfortable with the DS.

    Here's a link to VideoGL docs: http://libnds.devkitpro.org/videoGL_8h.html
     
    TheToaster likes this.
  7. TheToaster

    TheToaster Warrior of the Toast

    Member
    430
    160
    Aug 11, 2015
    United States
    USA
    Thank you. I have done many OpenGL projects before so I think this would be good
     
  8. Foxi4

    Foxi4 On the hunt...

    pip Reporter
    23,537
    21,496
    Sep 13, 2009
    Poland
    Gaming Grotto
    Basic functionality is exactly the same, but there are some custom functions for setup, memory banks, screen modes, shading etc., so check the Examples folder for those. Good luck!

    EDIT: Something to keep in mind - the DS is capable of rendering a maximum of 6144 vertices/2048 triangles per second - be modest with your models. Culling helps cut down the number of polygons on-screen, but don't rely on it too much. ;)

    For texture creation use GRIT, it'll allow you to convert images into native DS bins with 8 or 16 bit colour depth. They should be formatted as multiples of 2 (32x32 for example) and preferably square to avoid issues. For models use NDS Mesh Converter and don't use any surface effects. :)
     
    TheToaster likes this.