how to quickly find 10x10 map location 54?

Discuss any general programming issues here
Post Reply
Bugala
Posts: 917
Joined: Sun Feb 14, 2010 7:11 pm

how to quickly find 10x10 map location 54?

Post by Bugala »

I decided to give a try for having one dimensional map data instead of my usual 2 dimensional.

2 dimensional would be: mapdata[x][y], but now mapdata is just mapdata = {1, 2, 3, 4, 5...}

Suppose I have 10x10 map and i now know that location 54 is the one in question that i need to find.

of course i know it is x = 4 and y = 5, but how do i make hollywood figure it out the quickest?

do i just divide by 10 and see the whole number, or is there some quicker way?

SamuraiCrow
Posts: 309
Joined: Fri May 15, 2015 5:15 pm
Location: Waterville, Minnesota USA

Re: how to quickly find 10x10 map location 54?

Post by SamuraiCrow »

Integer divide by 10 and modulo by 10 to get y and x respectively.

If you want sequential slab arrays you can allocate them yourself using memory.library routines. They are generally smaller and faster than tables when you need multiple dimensions. The only limitation is that there's no "table poke" nor "pointer poke" commands when accessing memory directly.
I'm on registered MorphOS using FlowStudio.

Bugala
Posts: 917
Joined: Sun Feb 14, 2010 7:11 pm

Re: how to quickly find 10x10 map location 54?

Post by Bugala »

Thanks, I will keep that memory library in mind. Didnt notice that until you mentioned. I might need it as I am planning to make this small game where there be perhaps thousands little moving people, so checking what they each do might need even that memory library to make it fast enough. No idea yet how much power they take, but I guess I will soon know. Of course there are still other options too, like dividing them into 10 groups, and checking only one group each cycle etc.

Post Reply