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.
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 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?
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
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.)
As you can see there is literally nothing but empty files (even the INO file is just an empty setup and loop functions with no includes or anything). Going to try and commit each stage from project init, setting up includes and dependencies, and make commits each step of the way so you’ll be able to somewhat follow along with my process (though it’s been a bit).
That and the attitude that all customers are going to have 3GHz 8-core CPUs and 16GB of RAM to burn through, and that the software being written is somehow entitled to actually use all of that and it doesn’t have to share it with other software.
I’d best stop there, lest I climb on a soapbox and rant on for 8 more paragraphs.
Emphasis on anyone. (I’m really not that picky…)
This is true.
Paradoxically I’m actually quite quiet in person.
I find typing much easier than talking.
That’s a fork of Eried’s repo presumably created to upload or update one of the games on it.
@lyellick, I’ve written a preliminary wall of text.
I’m on the fence about whether to post it now or wait a bit in case more things occur to me.
Well it’s coming along nicely so far at least. I’ve got the generator working to create an infinite sequence requiring only 8 bytes of data (2 uint32_t variables one for the initial seed to repeat the sequence from the beginning and one for the current value in the sequence).
I removed that blur from that post because I noticed it was really a fork a few moments ago.
I’ll take it. :P
This struck a cord in me for some reason. More so from the standpoint of applying that to different industries, which would be an interesting discussion.
Disclaimer: I didn't take this personally, hope you don't read this as that. Just talkin' with ya.
I do get complacent in development by leaning on the vast memory and processing power a server(s) provides. I work in automating cloud infrastructures and use frameworks and a higher level language, higher not implying superior, to complete tasks. I don’t have to worrying about the lower level processes/resource handling. Allowing the framework to handle things way better than I could build within a sprint or direct my team to complete within the scope and on time. I do rely on the fact the code being run on a system has more than enough resources to handle it even though the code is not optimized to a T.
To me it comes down to:
Is it maintainable and inline to what the framework provides and does well?
Did we build something that wont cause another developer to say WTF?
Now, if I were a developer who only worked on systems with a finite amount of resources I would have a totally different mentality on how the code was written. With developing on the Arduboy I do have the incentive to build light software to the best of my knowledge until I learn a better way. I have to else I get memory leaks or use resources too quickly.
To your point…
Is it really entitlement or is that comment more for development on finite systems? By developers who come into it with the mentality it will be run with the 3GHz 8-core CPUs and 16GB of RAM to burn?
I think the disconnect between your comment and how I took it is which customer/scope are you focusing on. Not saying striving to develop the leanest application to run on any system can’t be applied to any industry. That being said is it really transferable to all industries in a way it positively affects velocity?
I personally would like to hear your soapbox/perspective. From what I have seen in your code is you have a mature and polished knowledge of development practices and a solid philosophy based off people who built the foundation.
It would be refreshing to hear your soapbox/perspective and you have a eager ear.
Thanks it was kind of fun to make something really basic and simple. Your theme got me thinking about the old classic Simon Says and the idea just popped in my head to have a figure do a different pose for each button press to give it some life (ie. make it look like a random dance). Then I wanted to keep it incredibly simple so as to help be a good demonstration for beginners and newcomers.