Help with homebrew game development and (maybe) multithreading

Eguin

Active Member
OP
Newcomer
Joined
Apr 23, 2018
Messages
36
Trophies
0
Age
23
XP
127
Country
United States
Hi! I semi recently started trying to develop homebrew wii games and so far it seems quite fun! I'm in the middle of making a small multiplayer game and have got player movement and some really rudimentary physics working. In the game I would like items to spawn at random intervals (meaning like every 10 seconds lets say) and was wondering how I could accomplish this without stopping the whole program? I could try and take advantage of the fact that it takes some time for each loop of the code to run and try and have it update based off that but that seems not so reliable. I would prefer to use a function like sleep(10) but if I do that the whole program will stop. I then thought that I could try multithreading but I can't get the windows api or pthread to work. Does anyone have experience with this that would be able to help? I feel like waiting for something to happen is common in video games but I couldn't find anything about it for wii homebrew online yet.

Thanks for any help!!
 
  • Like
Reactions: newo

newo

Well-Known Member
Member
Joined
Apr 7, 2011
Messages
814
Trophies
2
Website
wiibrew.org
XP
2,915
Country
Jamaica
Threading is a bit complicated and probably should be a last resort. There are some tips on here; https://wiibrew.org/wiki/Developer_tips
But personally I use this code;
Download my timer.h and timer.c then do something like this below;
//how to use #include "timer.h"; u64 wait_time=1000, u64 current_time; //you need separate vars for each instance u64 wait_time2=3000, u64 current_time2; void main(){ timer_reset(current_time); //not necessary timer_reset(current_time2); while(1){ //you need some kind of loop if( timer(wait_time, &current_time) ){ //does not block //do something after 1 second } if( timer(wait_time2, &current_time2) ){ //does not fire on first test //do something else after 3 seconds } } exit(0); }

good luck, happy coding
 

Eguin

Active Member
OP
Newcomer
Joined
Apr 23, 2018
Messages
36
Trophies
0
Age
23
XP
127
Country
United States
Threading is a bit complicated and probably should be a last resort. There are some tips on here; https://wiibrew.org/wiki/Developer_tips
But personally I use this code;
Download my timer.h and timer.c then do something like this below;
//how to use #include "timer.h"; u64 wait_time=1000, u64 current_time; //you need separate vars for each instance u64 wait_time2=3000, u64 current_time2; void main(){ timer_reset(current_time); //not necessary timer_reset(current_time2); while(1){ //you need some kind of loop if( timer(wait_time, &current_time) ){ //does not block //do something after 1 second } if( timer(wait_time2, &current_time2) ){ //does not fire on first test //do something else after 3 seconds } } exit(0); }

good luck, happy coding
Wow this is extremely helpful! I didn't think to use the current time to see how much time is passed (though now that I see what you did I feel rather silly for not looking for something like this)
Thanks so much! It's exactly what I needed!
 

You may also like...

General chit-chat
Help Users
  • No one is chatting at the moment.
  • Psionic Roshambo @ Psionic Roshambo:
    Psi has a new girlfriend but I have known her for like 28 years
    +1
  • The Catboy @ The Catboy:
    Is she you?
    +1
  • K3N1 @ K3N1:
    Psi just become a sparkling vampire already
    +1
  • Psionic Roshambo @ Psionic Roshambo:
    The Catboy it's weird there was always something between us.... But neither of us was single at the same time.... But last night we found out we both are... And hmmm 🥰
  • Psionic Roshambo @ Psionic Roshambo:
    She has all my weak points smart funny blonde and she lights up the room when she walks in and nothing else exists when she is there
  • Psionic Roshambo @ Psionic Roshambo:
    I would eat the corn out of her.... Lol
  • Veho @ Veho:
    Psi! You're alive!
  • Veho @ Veho:
    ...and you have yet another new
    girlfried :rolleyes:
  • Veho @ Veho:
    MAKE HER SIGH A PRENUP
  • cearp @ cearp:
    PSI <3 🌽
  • Psionic Roshambo @ Psionic Roshambo:
    Lol Veho I'm down to 3
  • Psionic Roshambo @ Psionic Roshambo:
    Dumping one soon
  • Psionic Roshambo @ Psionic Roshambo:
    My Facebook has like 120 women now or something lol
  • Psionic Roshambo @ Psionic Roshambo:
    Each one hotter than the last...
  • K3N1 @ K3N1:
    Ordered a new SSD
  • Psionic Roshambo @ Psionic Roshambo:
    Your mom's an SSD lol
  • K3N1 @ K3N1:
    Your mom writes to me fast
  • K3N1 @ K3N1:
    I haven't placed an order with Newegg since like 2016 lol
  • Psionic Roshambo @ Psionic Roshambo:
    Amazon Is better lol
  • K3N1 @ K3N1:
    Hard to find a fast 2tb SSD for 130
  • Peretti @ Peretti:
    lately I downloaded super mario galaxy for wii, but in the first phase, right in the first cutscene of the game, the game freezes in that part, with the image appearing but completely frozen. I already had this problem with pikmin 2 but in the end I couldn't fix the problem. Has anyone had this problem, and if so, did you find a solution?
  • K3N1 @ K3N1:
    Moms spaghetti
    K3N1 @ K3N1: Moms spaghetti