Help with homebrew game development and (maybe) multithreading

Eguin

Active Member
OP
Newcomer
Joined
Apr 23, 2018
Messages
35
Trophies
0
Age
22
XP
104
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
685
Trophies
1
Website
wiibrew.org
XP
2,326
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
35
Trophies
0
Age
22
XP
104
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!
 
General chit-chat
Help Users
    Veho @ Veho: Yes.