[Closed] Pre-Games Jam 5 Warm Up

Anyone want to join me this coming week to pump out a small game to get warmed up for Games Jam 5? This would be a individual or team activity if you choose to work as a team.

I personally haven’t done much in the ways of Arduboy games development and want to get back into the mindset again.

Required Criteria

  • Must implement a class
  • Tones or a small music ditty
  • A title screen image

Theme

A simple memory game where the more you play the faster it goes.


Duration July 27, 2020 5:00 AMAugust 1, 2020 4:59 AM

Will have a basic poll at the end and the winner and participants will just get the satisfaction of dusting off that coding atrophy.

I will be participating, but wont be within the poll since I created this ad-hoc post.

Jump To:

2 Likes

Is this an offer to join you in creating said game or a kind of challenge/activity to create a similar game with similar constraints separately to the one you’re planning to create?

Just a simple challenge and then fun poll to see who made the best technically.

People can collaborate, but I won’t be. Don’t really have the schedule to be a good lab partner. :P

In what time zone?

When specifying dates and times in this forum you can click on the “Insert date / time” (calendar) icon near the right side of the editing window toolbar. This will allow you to enter a time, or time span, for your local or other specific time zone, which will be corrected to the viewer’s zone when viewed. For example:

For zone “America/Toronto” from July 27, 2020 12:00AM to July 31, 2020 12:00AM you get:

2020-07-27T04:00:00Z2020-07-31T04:00:00Z

There are also many other options that can be set in the “Advanced” mode.

2 Likes

Fixed. Thanks for tip.

I’m in the Chicago timezone btw

2 Likes

You specified a date but not a time.
Presumably you meant to set the time to midnight on both?

1 Like

Would be cool if people submitted there GitHub/GitLab so we can all learn from each other. Possibly a small retrospective afterwards and code review.

I know @MLXXXp and @Pharap are awesome at sharing there Arduboy/Development experience for the greater good.

I’ll start it off.

Edit: Added license (CC0 1.0) per @MLXXXp recommendation.

1 Like

If you’re going to publicly announce the location of code for viewing, you should include a LICENSE file, so people will know what they can do with it.

2 Likes

There is actually a way to link your GitHub to your forum account but I’ve never tried it (and probably won’t bother - I don’t like linking/combining accounts more than I have to).

I just link to my GitHub in my profile (which could do with an update) since people are probably going to end up there at some point.


I probably won’t join in the practice/warm up because I’m already juggling other things, but I’m happy to help anyone with any code-related problems (and that extends to the actual jam when it happens, and after the jam).


@lyellick, I had a quick peek at your code.
If you haven’t done so yet, have a read of the end of this post.
It very briefly discusses passing by value vs passing by reference.
If you need more info (and can’t find anything useful via a search engine) ask me and I’ll go into more detail.
(Ordinarily I’d go into detail now, but I have things to do.)
The bottom line: the way Game is using Arduboy2 might cause issues, or at the very least wastes memory.

1 Like

Thanks @Pharap! Just messing around tonight with the title screen and the any key selection, but I will try to apply the link you provided and Game class naming suggestion.

Now that I have chance I can explain further…

In C++, by default all objects are passed around by value rather than by reference, which means the whole object is copied.
(To put it into C# terminology, it’s as if every C++ class and struct were a C# struct - they have value semantics rather than reference semantics.)

Fortunately that’s not the only option.
If you want to create a reference to an object, be it a reference variable or a reference parameter, you can opt to do so by using &.

In your case that means instead of doing:

class Game {
   public:
    Game(Arduboy2 arduboy);

   private:
    Arduboy2 arduboy;
};

Game::Game(Arduboy2 arduboy) : arduboy(arduboy) {};

You can instead do:

class Game {
   public:
    Game(Arduboy2  & arduboy);

   private:
    Arduboy2 & arduboy;
};

Game::Game(Arduboy2 & arduboy) : arduboy(arduboy) {}

And then rather than creating a copy of the Arduboy2 object, you’re creating a reference to it, which means any state changes made via the reference are made to the original object rather than to a copy of that object.

You can also achieve a similar effect with pointers, but I’d advise against using pointers when references are an option because references are safer, easier to understand and don’t need as much special syntax (e.g. you can use . as normal, wheras pointers would require you to use ->).

If you have any questions or want any more info feel free to ask.

What naming suggestion?

1 Like

This is the reason my random() wasn’t being random in my Game class. I was initializing the class with the Arduboy object and then in startup() adding the arduboy.initRandomSeed(). No wonder this wasn’t working and I actually bricked my Arduboy when I moved arduboy.begin() into my Game class without having anything in startup(). I was able to reset it fine.

Thanks! This was the missing piece to my issue without even having to reach out and ask why.


I misread your previous post that night and through Game is already being used in the Arduboy library and I needed to rename it.

That seems unlikely, initRandomSeed doesn’t actually use any of the Arduboy2 object’s state, it just reads some noise from an unconnected pin, mixes that with the time returned by millis and then feeds that into randomSeed.

If you had an issue, chances are something else fixed it.

Where exactly were you calling it from?
If it was in the constructor I can see why that might cause an issue.

(Personally I give my Game classes a setup and loop of their own and use Arduino’s setup and loop to forward to game.setup() and game.loop().)

1 Like

I have the base game created here. It’s bigger than any code I have request for a code review, but if you have a few moments; do you mind running and giving any feedback?

This is my first full game minus sound. :slight_smile: Proud of it, but don’t hold back on constructive criticism.

I was only going to have a quick skim and wait until I could do a proper review before discussing any of it, but I think the fact you have a memory leak is a big enough of an issue to address immediate.

When you use new to dynamically allocate something,
you always have to delete it when you’re done with it.
But you’re not deleting sequence, you’re just allocating more memory and storing the pointer, meaning the original pointer pointing to the memory that needs to be deallocated is then unreachable, which is practically the textbook example of a memory leak.

But even if you didn’t have the leak and you were deleting things properly,
I’d be advising you to get rid of new and delete.
The Arduboy only has 2.5KB of RAM, of which 1KB is taken up by Arduboy2’s statically allocated frame buffer, and an unspecified chunk is required for the call stack, which basically means there’s not enough memory to reliably support dynamic alloction.
If you try to use dynamic allocation, you’re likely to hit a memory fragmentation issue very quickly, hence it’s not really viable.

Use a fixed size array instead, it’s much safer.

There’s a number of other things I’d like to address when I get chance, but this one is really important because it actually has the potential to cause the Arduboy to crash (or worse, start behaving oddly whilst still running) after a certain number of calls to resetGame.

1 Like

I was trying to allow for the ability to increase the sequences via sequenceLength by incrementing it each win. I suppose I could make it the size of 10 and only check the first 5 and increment the max index till the length of the array.

I saw a post about cleaning up a dynamic array or not using them at all. I ignored it out of convenience laziness ignorance, but I was aware of this. I was not aware of the memory leak issue, so thank you for pointing that out.

I would really like to learn what you find if you have time. :)

1 Like

I thought of a very quick and simple memory game. Will see how it turns out. I’ve got a basic stick figure drawn with 1 frame per animation, but it should be interesting. Once I’ve got everything done if an artist (such as @Vampirics) wants to step in and do some simple, but better, animations they’d be more than welcome to.

Should I share the overall concept or leave it as a surprise for when it’s done?

2 Likes

This post kinda is turning into a more free form warm up and discussion. I would be floored to see your code for a simple game. A repo link to follow progression would be choice.

There are a lot of amazing developers on here and going through their code is great, but my experience to traverse C++ code in a educational manner is limited. A small game with tight code is what I secretly was hoping from this post. :P

P.S.

Seeing animation in a simple game would also be very educational for me.

That’s actually what C#'s List<T> and C++'s std::vector<T> do internally.
They allocate enough memory to store N objects (where N is usually a power of two), even if they don’t need to store that many objects, and then gradually increase their Count/size until they hit their Capacity/capacity.
Then when they finally reach the end and another Add/push_back is requested, they finally allocate a new buffer that’s twice the size of the old one and copy the old memory across.
(std::vector<T> actually often uses pointers rather than tracking the number of elements for some reason. I’ve always assumed it’s believed to be more portable but I don’t know for sure.)

In this case though you wouldn’t be allocating more.
It might seem strange to have a fixed upper maximum,
but remember that all computers (even desktops) have a hard limit on how much memory they have,
so in reality you always have a fixed upper maximum.
It just happens to be that in this case the programmer chooses the maximum and can detect when it’s been reached.

You could probably fit more than 10 if you want.

The former link is a bit muddled, but the latter link is a good one.
(Particularly my follow up comment… mainly because it features that neat little doodle about heap fragmentation from “Munificent” Bob Nystom’s Game Programming Patterns book.)

And not the good kind.

Will do.

You could do both by putting it in a [details] block so people can choose whether to read it or not.

I really enjoy this type of in depth back and forth on the nuts n’ bolts of C++/ and what is happening in the back end you provide.

Honestly, learning C++ has given me a much greater understanding of programming in an efficient manner and not the hey it works, on to the next feature mentality I get into while at work.

1 Like