1. Dani24f

    Dani24f Member
    Newcomer

    Joined:
    Apr 20, 2020
    Messages:
    13
    Country:
    Italy
    The struct object is inside the system.h file, trying to declare it gives me an "already declared inside file system.h"-sort of error.
     
  2. IC_

    IC_ gbaTemp Fan
    Member

    Joined:
    Aug 24, 2017
    Messages:
    1,078
    Country:
    Poland
    Even if you use a name different from the struct name?
     
  3. Dani24f

    Dani24f Member
    Newcomer

    Joined:
    Apr 20, 2020
    Messages:
    13
    Country:
    Italy
    Yes, I tried using it as a normal variable too
     
  4. Foxi4

    OP Foxi4 On the hunt...
    Global Moderator

    Joined:
    Sep 13, 2009
    Messages:
    26,150
    Country:
    Poland
    I suggest using time.h instead and getting seconds as such:

    secs = timeStruct->tm_sec;

    Relevant libnds example:
    https://github.com/devkitPro/nds-examples/blob/master/time/RealTimeClock/source/main.c

    You may be able to use the built-in RTC function in the same way, but at this stage I have no idea what does or doesn't work as expected in libnds, so I tend to go by what libnds creators themselves suggest.

    Structure reference:
    http://www.cplusplus.com/reference/ctime/tm/

    I'm not at my PC right now so I can't compile on my end, but when in doubt, standardised functions come to the rescue.

    EDIT: Did this resolve your issue @Dani24f, or should I start up my PC and look at your source? I'm back at my workstation if you need a hand.
     
  5. Dani24f

    Dani24f Member
    Newcomer

    Joined:
    Apr 20, 2020
    Messages:
    13
    Country:
    Italy
    Hi, I tried using time.h as you said, but I get a "'timeStruct' was not declared in this scope" error.

    Here's my code, so you check it out (thanks for helping me btw!):
    Code:
    #include <nds.h>
    #include <stdio.h>
    #include <time.h>
    
    u8 secs=0;
    float fps=0;
    
    
    int main(){
        consoleDemoInit();
        while(1){
            printf("Initializing..."); /*This displays while waiting for the first second to pass*/
            fps = fps + 1; /*This increases the fps counter every frame*/
            secs = timeStruct->tm_sec; /*This gives a "timeStruct' was not declared in this scope" error when compiling*/
            if (( timeStruct->tm_sec - secs ) == 1 ) { /*If a second is passed*/
                iprintf("\rHello world by Dani24f! FPS: %.2f ", fps);
                fps = 0; /*Resets the fps variable and waits for another second to display the current fps*/
                if ( secs == 58 ) { secs = 0; } /*This prevents any error in the subtraction tm_sec - secs*/
            }
            swiWaitForVBlank();  
        }
    }
     
  6. Foxi4

    OP Foxi4 On the hunt...
    Global Moderator

    Joined:
    Sep 13, 2009
    Messages:
    26,150
    Country:
    Poland
    You need a timeStruct first. :P

    time_t unixTime = time(NULL);
    struct tm* timeStruct = gmtime((const time_t *)&unixTime);

    This will create a time structure "tm" in UTC format. Admittedly a bit overcomplicated, this would be used for something like a clock, so I'll see if it can done in a simpler way (it can be). Honestly, you should be able to get framerate by comparing CPU ticks vs. screen refreshes with acceptable accuracy.
     
  7. SkilLP

    SkilLP Member
    Newcomer

    Joined:
    May 2, 2020
    Messages:
    21
    Country:
    Germany
    Thanks for this awesome guide! I wanted to start making NDS homebrew a while back, but I just didn't know where to look for a guide or sth like that, but about 2 months ago, PolyMars led me here. Nice work!
     
    PolyMars likes this.
  8. SkilLP

    SkilLP Member
    Newcomer

    Joined:
    May 2, 2020
    Messages:
    21
    Country:
    Germany
    I have a question: As you may know, updating too many sprites while also having the DS calculate a lot can lead to sprites not getting properly deleted and staying on the screen even in the same position even after moving or even deleting. They don't do anything there, they just don't do anything. I had that problem when I made a game where you had to dodge falling meteors and the only way around that issue was deleting those sprites after they were off screen so you couldn't see the artifacts. Do you know how to fix this?
     
  9. Foxi4

    OP Foxi4 On the hunt...
    Global Moderator

    Joined:
    Sep 13, 2009
    Messages:
    26,150
    Country:
    Poland
    This shouldn't be the case, once you refresh the screen they should be gone. Can you provide a snippet?
     
  10. SkilLP

    SkilLP Member
    Newcomer

    Joined:
    May 2, 2020
    Messages:
    21
    Country:
    Germany
    I'm not sure what you mean, but if you mean what my update looks like, here it is:
    Code:
    NF_SpriteOamSet(0);
    NF_ResetSpriteBuffers();
    swiWaitForVBlank();
    oamUpdate(&oamMain);
    I may have misunderstood the question though
     
  11. Foxi4

    OP Foxi4 On the hunt...
    Global Moderator

    Joined:
    Sep 13, 2009
    Messages:
    26,150
    Country:
    Poland
    The maximum number of sprites the DS can handle is pre-set - if they stay on the screen after being destroyed/deleted one of a couple of things might be happening - you've created more than the maximum number allowed (NFLib should stop you from doing that, so it's unlikely), you've overflown some kind of buffer or the DS is unable to properly refresh for some reason. It shouldn't display anything that's not actively loaded and within the bounds of the screen, so there's an error somewhere along the line. Your screen update routine is correct, but I would review everything else as this should not be happening.

    A good way to test this is to create a test environment. Isolate all the code relating to sprite generation, set one button to create a new sprite and one to destroy the last one you've made, and keep creating them until the error triggers - that will help you narrow things down.
     
  12. SkilLP

    SkilLP Member
    Newcomer

    Joined:
    May 2, 2020
    Messages:
    21
    Country:
    Germany
    I'll do that, thanks!
     
  13. Foxi4

    OP Foxi4 On the hunt...
    Global Moderator

    Joined:
    Sep 13, 2009
    Messages:
    26,150
    Country:
    Poland
    You will also see graphical glitches like this if you send more data into the screen buffer than the screen can handle, but normally NFLib handles that automatically as long as you refresh it at the end of the loop, if there are any errors in this regard it should dump them into the console, which you should be able to pull up.
     
  14. Arrie

    Arrie Newbie
    Newcomer

    Joined:
    May 12, 2020
    Messages:
    2
    Country:
    Netherlands
    This link doesn't work anymore and it's also not in the wayback machine's web archive.

    pern . drunkencoders . com /download-wiz
     
    Last edited by Arrie, May 12, 2020
  15. Foxi4

    OP Foxi4 On the hunt...
    Global Moderator

    Joined:
    Sep 13, 2009
    Messages:
    26,150
    Country:
    Poland
    The wizard is not necessary, you can compile with just the devkit. :D
     
  16. Arrie

    Arrie Newbie
    Newcomer

    Joined:
    May 12, 2020
    Messages:
    2
    Country:
    Netherlands
    Oh, thanks for the quick reply! Also, I was wondering, is this still the most up-to-date tutorial? Since it's from 2012..
     
  17. Foxi4

    OP Foxi4 On the hunt...
    Global Moderator

    Joined:
    Sep 13, 2009
    Messages:
    26,150
    Country:
    Poland
    Well, nothing concerning DS development is really up-to-date since the platform was phased out, but the guide was written at the tail end of the life cycle, not to mention that the coding concepts are applicable regardless of the platform - C is C. Just keep in mind that many links might be dead and I have no backups of the software, so you may have to get creative sometimes. The forum has migrated since this was posted as well and I did my best to clean up the code since, but some fragments may be poorly formatted. Still, if you read thoroughly, you'll figure it out. :)
     
  18. Sammy6

    Sammy6 Member
    Newcomer

    Joined:
    Feb 28, 2020
    Messages:
    26
    Country:
    Canada
    I'm very new to libnds and I'm not sure how to compile my code with programmer's notepad
     
  19. Foxi4

    OP Foxi4 On the hunt...
    Global Moderator

    Joined:
    Sep 13, 2009
    Messages:
    26,150
    Country:
    Poland
    You should be able to find a template inside the devkitPro folder - save your code as the main file and then go to Tools - - > Make in PN. There are various templates available depending on what hardware you need to use, but if you're a newbie, you can just grab the Hello World example and start from there. :)
     
    PolyMars likes this.
  20. Sammy6

    Sammy6 Member
    Newcomer

    Joined:
    Feb 28, 2020
    Messages:
    26
    Country:
    Canada
    Thankyou for the help!
     
Draft saved Draft deleted
Loading...

Hide similar threads Similar threads with keywords - Programming, Newbies,