Tackle Box, a fishing adventure -- now available!


(Simon) #61

Tell me how it goes … ! I had some great savings with Lode Runner and Space Cab but I has the room to expand the levels out into RAM and then read from RAM each time.


(Matt) #62

It saved about 250 bytes, but the performance is so bad the game is unplayable.

It’s because I’m decompressing each tile each frame. If you move to the upper left of the map, it’s fine. And the lower right is probably getting oh a frame every 5 seconds :sweat_smile:

For Ardynia I decompressed into memory like you did, and that worked great. But with a map that is not room based, it’s more complex to pull off. Will need some kind of circular buffer.

But the circular buffer eats into that 250 byte savings. Probably won’t save too much space in the end :confused:

EDIT: hmmm, maybe have known markers in the RLE. Like “x is over 1000? start at index 50”


(Miloslav Číž) #63

Wait wait your generated code is size inefficient. There has to be a function to check if the point is inside the rect, it mustn’t be expanded into each condition, that generates a big code. Even though actually I dunno. If I have some time I’ll try to compress the map.

Also it seems to me there is too many rectangles, you’d probably be able to do much better doing it by hand.

Also I don’t know if arduino is already doing it, but you could try -Os compiler flag.


(Matt) #64

I’ll keep playing with it. Function calls are pretty expensive too, but maybe cheaper than if statements.

I think I can get the RLE approach to work too. But at the end of the day not sure the savings will be much. With RLE I get 40% compression rate, a shame the decompression code eats up most of the savings.


(Matt) #65

I’m not sure about this. The map is quite rich, there’s 43 tile types.

Like I said earlier, I can reduce the rects by not building rects for the most common tile. That will help for sure.


(Miloslav Číž) #66

Yep, you want to trade memory for computational efficiency, you can’t have both, but you don’t seem to be having trouble with performance.

Try other primitives and techniques as well: squares (saves one parameter compared to rect), lines, randomness, different set operations (union, difference, intersection, complements). Here you probably won’t be able to do this automatically because the space to search is too big, a human brain will be needed, but that’s okay.


(Matt) #67

This game doesn’t push the cpu at all. Always happy to get more space at the cost of cpu.

What I’d really like to do is write a program that can automatically explore all the approaches and report on their savings.


(Miloslav Číž) #68

Creating a program that takes a 2D array and compresses it into a function automatically would be a project of its own. But it could be reused in other games as well. Could be worth a try. You’ll need to think of some clever heuristics, I think this will be an NP complete problem.


(Matt) #69

I’ve already done this. Just a matter of improving the program. I’m interested in exploring squeezing bytes as much as possible. I’d really like to fit a lot more stuff into Ardynia 2, that’s my motivation.

It’s interesting because finding the right balance is tricky.


(Miloslav Číž) #70

You know what would be best? Instead of creating an array and then trying to convert it into a “vector” representation, start with the vector representation right away. I.e. create a tool that will let you draw a map (a general 2D array of numbers) using these primitives – that is you’ll be able to draw rectangles/squares/lines/whatever with your mouse, and the program will be showing you the code for that, in real time. Almost trivial to make and very effective. Hell, I wanna make this tool right now.

An advanced feature could then be to allow to put an existing map on the background which would let you “redraw” it (convert from bitmap to vector representation) – that is it wouldn’t be an automatic process, but the tool would help you compress the map easily by simply drawing shapes over the map.

Would be good to create a new thread for this, because it would be a general tool, and I think a very useful one for creating large maps for any game.


(Scott) #71

Arduino sets -Os when compiling using avr-g++


(Matt) #72

That would be a neat tool and would be great for games with large worlds. You’d probably be pretty limited in the graphical fidelity of the map. For example, you’d probably only really be able to have one water tile, one ground tile, etc. It’s really the corners, edges, etc that kill the compression.

Probably pretty easy to build the tool using svg libraries.


(Matt) #73

Actually, Tiled has pretty decent vector support. The real time aspect is probably not doable, but exporting Tiled to c++ isn’t hard.


(Miloslav Číž) #74

No, the borders have their rules that the function could apply as well! The function can see if it’s returning a tile that’s an edge and return a transition tile instead.

Very much doable, there’s nothing difficult about it. The map will be represented as a tree of set operations on the basic primitives (this is how it’s done e.g. on 3D models in CAD systems, I can’t remember the name for it right now). This tree will directly imply the C++ code and will be computable in no time.


But it won’t really be trivial as I said above, that was wrong.

The biggest challenge would be the GUI really. It would have to be like a basic paint program and offer undo etc. in order to be comfortable. I’ll be thinking about this some more.

Also there should be probably an intermediate format to save the maps in and load them from (C++ code is not good for that). Something like:

map_width: 10
map_height: 7
default_tile: 0
tile_1: rect(2,3,5,6) + rect(6,5,3,3) - lineH(1,1,7)
tile_2: point(9,3) + point(2,7)

A bigger project indeed.


(Matt) #75

My point being, any additional logic like this eats the compression savings.

I meant doable within Tiled.


(Miloslav Číž) #76

I’ve been testing this a bit and have created a 1024 x 1024 map taking a very small amount of space.

out

There is only one problem, but it only happens with such large and complex maps – the computation demand becomes quite heavy, so you have to create a cache to precompute the nearby area into, and this introduces kind of “loading times” when moving across the map. They’re very short but it creates a small tearing which is a bit distracting.

However from my experiments with maps even several times larger than yours there is no need for cache and everything runs smoothly.

I think I could release the sketch and my quick tools for people who’d like to expand on it. Maybe even a tutorial. I’ll see about that.


(Matt) #77

Awesome! Please do release the code, would love to check it out!


#78

Ahhh this is so cute and good! I love fishing games/mini-games and you’ve managed to pack so much into this game!

Really does remind me of Legend of the river king (just without the random RPG battles which I was never really into!)

Again, great job :smiley: .


(Matt) #79

Thanks! Glad you like it!