Threads Are there Meta in the gamebuino meta?

General

hiveplay12345

3 months ago


Hello, today I wanted to create a game
I need a second thread, but I can not do it because an error has occurred
compilation with the gamebuino board

#include <leOS.h>

#include <Gamebuino-Meta.h>
 leOS myOS;
void setup() {

  myOS.begin();
  myOS.addTask(clocktime,100);
  gb.begin();

}

void loop(){
  // wait until the gamebuino is ready to update at stable 25 FPS
  // this also updates sounds, button presses... everything!
  while(!gb.update());
  int timeclock = 1;
  // clear the previous screen
  gb.display.clear();
  gb.display.setCursorX(0);
  gb.display.println(timeclock);

}
void clocktime
{

}

Sorunome

NEW 3 months ago

Hi, mind posting what error you are having?


First off, i'd recommend putting gb.begin(); as first in your setup() function as it initialized the entire board


In general, I'd recommend against multithreading on the gamebuino META, as I see little reason as to why that would be needed. What about having to update multiple things at once? Do them one after another! Something like this:

void loop() {
    while(!gb.udpate());

    // update player positions

    // update enemies

    // interact between players and enemies

    // render stuff
}

The multithreading library you are using may also be dysfunctional due to using timers that the library itself uses for other stuff (sound, etc.)

Insajd

NEW 3 months ago

I'm also curious what design approach you took so that you need multiple threads/processes happening at the same time. Would you mind sharing? We may try to help you with some design decisions if you do.

Also I kind of agree with Sorunome as I don't really see any reason to go with multi thread approach for gamebuino games, but I might be missing something ;)


hiveplay12345

3 months ago

The game will be similar to the Tiny Tower game
I would like to create a system of time that will be at night during the day
And I need Delay (125);
And you can not do it in an  and during (! Gb.update)

but probably because the idea is in a minimal state because I'm just creating the engine and graphics
But there, I would like to do a game saves

hiveplay12345

NEW 3 months ago

Insajd Insajd

The game will be similar to the Tiny Tower game
I would like to create a system of time that will be at night during the day
And I need Delay (125);
And you can not do it in an  and during (! Gb.update)

but probably because the idea is in a minimal state because I'm just creating the engine and graphics
But there, I would like to do a game saves

Insajd

NEW 3 months ago

For saving the game you can check docs: https://gamebuino.com/academy/reference There is SAVE section, it may be useful.

As for your design problem: I have never played tiny towers so I don't know which gimmick you want to implement. If you simply want to count real time, then you can count frames. 25 frames makes one second. For the problem with delays, why can't you simply make your day/night cycle equal to 250 and count it from 0? If the value is lower than 125 there is a day. Else it's night. Third possibility I see is that you may want to know real time of the day. I don't know if this is possible, @Sorunome may help you with that.

hiveplay12345

3 months ago

Actually I'm on vacation and not thinking :)

hiveplay12345

NEW 3 months ago

Insajd Insajd

Actually I'm on vacation and not thinking :)

Sorunome

NEW 3 months ago

And I need Delay (125);

You could actually call arduinos delay(125); in your code, the updating stuff will still happen. That is not recommended however. Instead, try what @Insajd suggested: instead of pausing 125 milliseconds, why not wait for six frames?

dreamer3

NEW 3 months ago

Hiveplay, if you look you'll also see the M0+ ARM CPU we use isn't supported by the library you're trying to use (LeOS).  As most people have mentioned to do most simple timing things you really don't need a scheduler like that at all.

You must be logged in in order to post a message on the forum

Log in