Posting here as reservation for the idea. Right now this is plan A for a small and easy project
I’ll try to use some animations found on the web and adapting to the small footprint of Pokitto.
Thanksgiving to @FManga that already helped figure out some unexpected behavior of LibHotSwap
Little progress so far, but the thing should be doable. Another big thanks to @FManga that find a solution to allow use LibHotSwap even with big piece of data like mine.
In the video I’ve use async loading but sync loading is faster and so I my opt for that with some text.
@FManga implements a way to give priority to LibHotswap:
if (nextHook) return true;
nextHook = Pokitto::Core::updateHook;
Pokitto::Core::updateHook =
+[](bool isFrame){
if (isFrame) {
for (int i = 0; i < _priority; ++i) {
if (file && !loadPage(*file, page++)){
delete file;
file = nullptr;
onCompleteCB(swapData);
break;
}
}
}
nextHook(isFrame);
};
So now I can fine tune the loading different animations.
Moving data from SD to flash it’s a complex task, as the flashing mechanism for LPC11u68 is not documented.
At last always @FManga help me fix a nasty load problem by changing the aligned attribute for swap data, rising the sector from 4Kb to 32Kb. The animation used are quite big (up to 52 Kb each) and probably data was copied on some protected area/sector (this my feelings as I didn’t dig too much in the problem). Ensuring an alignment of 32 Kb fix corrupted animation but rise the swap data consumption up to 128 Kb (64 * 2) of precious flash.
This, together with some other images and assets, was really near to the maximum allowed for a bin size.
A little trick come to help, by changing the compiler option from -O3 to a less speed optimized -Os save a decent amount of space for make some real game. Now with sounds too
Still need to find a way to create a good background with low mem usage.
This will task FemtoIde to build the image and generate as a new file with the format i8
BTW the format was wrongly included in the file format processed for cpp image conversion, so ensure you’re using latest FemtoIde with this fix:
Remember to flag the file as Copy to SD if you plan to test this in the emulator. And actually copy it to the sd card of ypur Pokitto when testing on hardware… yes it happens to me…
And last a snippet of code that read from a path and trow the image to the screen.
//Method to load images from file in TAS mode
static void LoadImage(const char * img) {
File file;
file.openRO(img);
for (int i = 0; i < 176; ++i) {
unsigned char buffer[220];
file.read(buffer);
flushLine(PD::paletteptr, buffer); //flush the line to screen and increment line index
};
};
Hope this can help someone else to improve their jam entry, or any other game out there.
When it comes the need to organize your code, but you mostly use static methods in your project, it may happens it turns out in an swarming cup of if or switch and duplicated methods call.
Here it come some more interesting code my best pusher (you know who) turn out of the hat:
void init() {
StateMachine::setState<StateIntro >();
}
void update(){
StateMachine::Update();
StateMachine::Draw();
// if something (a butto, a time out) require to change the active state, it's enough to call
// StateMachine::setState<StateIWantToActivate>();
// and the Init will be call followed by respective Update method
}
setState will probably be call inside one of the various stateClass and will take care also to call its relative init().
This snippet really helps me to have better code and focus on some details of the gameplay like high score, ending and some minimal GUI.
Shouldn’t setState also be calling init?
Or is there some practical reason why it’s delayed?
It’s nice to see someone embracing templates at least.
It’s also quite rare to see an anonymous namespace being used.
(I can’t deny though, this sort of code is undoubtedly going to be very cryptic for people who don’t know C++ incredibly well…)
(If anyone who doesn’t know what an anonymous namespace is and wants to know: have a read of this.)
The idea is to avoid having two states conflicting with each other. You can call setState at any point and not have to worry about the current state becoming inconsistent (the next state’s Init deleting something used by the previous state) while it’s still being executed. It also ensures Init is only called once per state transition, even if you call setState multiple times.
It has been a funny experience and it make me discover new things till the end… at the moment of creating the pop file the bin was grow to 236 kb. Too much to handle also the loader in a safe way.
I’ve been carefully to check the size grow from the beginning as the two main characters animations were already quite huge and space was very tight. But something has happens towards the end and I had no idea of what it could be. No new sprites was added, no wave sounds, neither a copy of this famous video.
So I call my personal hotline with the Gran Pokitto Master and as request sent him the elf of my project. Elf is not a fantasy creature of the woods but some kind of gibberish binary file that is near to machine brain to track memory mapping in various stages of compilation. Using obscure divination the verdict was cruel: space is used by many little things and nothing is hidden using your flash. (terror in my mind) But try to avoid use float.
Float? Why am I using float anyway, could be that little fancy color animation in some text that cycle trough color using a sinusoidal increment?
It was that, and space dropped to 202 kb.
So as usual when I accomplish to finish a game, I have to thanks some people:
@FManga for great technical help, without really looking at my code but providing just the necessary knowledge and pointing me to the right path for my limited skills.
@Vampirics for early beta test with some nice feedback, and a sincere interest on my little attempts in the art of game creation.
My personal objective here was to complete a project (even a small one) to break a long succession of half finished ones. So I see this already with a personal win.
Please enjoy my entry for the game jam (and consider it targets a very young and few claims audience)