Map Editor Questions

Blitz3D Forums/Blitz3D Beginners Area/Map Editor Questions

thalamus(Posted 2004) [#1]
Few more general questions:

a) Rather than use arrays to store tiles and maps, I was thinking of using Types for botht he tiles and the map data, allowing me to combine information. Is this more efficent/faster than using arrays? Or am I better off with separate collison maps/tiles?

b) I wish to implement a Zoom function, allowing the user to Zoom out from their map (probably -2x, -4x, and -8x) - is there a graceful way of doing this?


Rob Farley(Posted 2004) [#2]
What kind of map? Tile based? 2D? 3D?


CS_TBL(Posted 2004) [#3]
a) also consider banks .. (but then again, I'm the banktype :)

b) .. in Blitzplus it would be somewhat easier by having scalable canvasses .. but I assume you want blitz2d/3d :) So, dunno!


thalamus(Posted 2004) [#4]
It's a 2D map editor written in Blitz+ - at the moment I'm using arrays to store the maps, with tiles imported as a strip of images in a BMP...


WolRon(Posted 2004) [#5]
Well then just create an array of types...


RiK(Posted 2004) [#6]
I guess for your average 2d tilemapped game an array is safe enough, and by far the easiest format to parse at run time when you are moving around/rendering the map.

If the maps were *huge* with only a limited amount of the 'grid' populated with tiles then I guess you could look for a more optimal solution but I serious doubt that it would be a problem. Tn real terms the memory taken up storing a 2d map in an array is tiny compared to other resources such as graphics and samples.


thalamus(Posted 2004) [#7]
Ello Rik :)

I guess I'm just trying to refine the way I code, make things a little more efficient. I've seen a few editors which use Types for each tile and so forth - I just assumed it was a more efficient way of doing things.

I guess the format isn't that crucial - I can always put in export options to suit any requirement - but I get paranoid that my code is sloppy... :/


WolRon(Posted 2004) [#8]
You don't even need to make a 2D tile editor. Just use one of the many available ones. Here's a good one: www.blitzbase.de/_mapeditor/


thalamus(Posted 2004) [#9]
>> You don't even need to make a 2D tile editor.

You're kind of missing the point - why should anyone make a platform game when there are dozens out there already?

There are a number of reasons I chose to write my editor:

a) good for learning new techniques

b) useful to be able to change the way an editor exports data or add new features

c) I need an editor that will integrate with my game so I can make changes in real time.

So... back on topic... ;)


soja(Posted 2004) [#10]
As for me, I tend to favor the method that makes it easiest for the programmer. I really like types, so I make liberal use of them. Sometimes I use arrays of types, so that they can be indexed directly, but I don't often need to with the stuff I do; it's just as well to do an O(n/2) search through the list of types.

I suggest trying both (or all three, if you want to take CS_TBL's advice). Most likely, you'll probably end up with a nice mix. And you certainly will learn the differences, pros/cons, etc, which is a goal of yours, unless I'm mistaken.

As for the zoom thing, there is a graceful way. Basically, just resize the canvas. Check out this small example:
Global w=CreateWindow("Canvas Resize / Zoom", 200, 200, 400, 400, 0, 3)
Global c=CreateCanvas(0,0,ClientWidth(w),ClientHeight(w),w)

CreateTimer(60)
SetBuffer(CanvasBuffer(c))

Notify "Press mouse buttons to zoom in/out"

Repeat
	Select WaitEvent()
		Case $803 : End
		Case $201
			If EventData() = 1 Then
				zoom = zoom + 50
			Else
				zoom = zoom - 50
				If zoom < -150 Then zoom = -150 ; don't get too small
			EndIf
			SetGadgetShape(c,0-zoom,0-zoom,400+zoom*2,400+zoom*2)
		Case $4001
			Render()
	End Select
Forever

Function Render()
	;Cls ;if you want
	Color Rand(256), Rand(256), Rand(256)
	Rect(Rand(ClientWidth(c)), Rand(ClientHeight(c)), Rand(10), Rand(10), True)
	FlipCanvas(c)
End Function



thalamus(Posted 2004) [#11]
Cheers Soja :)

Back on the subject of Arrays and Types: in my editor, I wish to include a library of commonly-used brushes.

Each brush is an array, and I want to use an index to access the relevant brush.

Is it possible to have an array of arrays, or is this where Types come to the fore?


WolRon(Posted 2004) [#12]
An array of arrays is a multi-dimensional array.

Dim a(100)
Dim a(100, 100)
Dim a(100, 100, 100)
Dim a(100, 100, 100, 100)

Whatever you want.

I started a programming tutorial a while back (but didn't get very far). However, it just so happened that I started writing about arrays and types:
http://myweb.arvig.net/rwolbeck1/programmingtutorial/reference/arrays.htm


Here is some text on multi-dimensional arrays from the tutorial:

Think of your array as a chess board.
dim chess$(7,7)

will give you 0-7 across and 0-7 down (64 square in total). So you can reference a point and see what's there or set what's there.
chess$(5,5) = "Black Knight"
chess$(1,2) = "White Queen"
print chess$(3,3)

Then you can take it even further and stack several chess boards on top of one another.
dim chess$(7,7,2)

This has stacked 3 chess boards on top on each other. You can now reference any squre on any board.
This sets position 5,2 on chess board 1
chess$(5,2,1) = "White Bishop"
print chess$(5,2,1)

Sets position 2,1 on chess board 0...
chess$(2,1,0) = "Black Pawn"

You ready to take it even further...

Well, lets have our stacked chess boards spanning across different rooms...
dim chess$(7,7,2,9)

You getting the idea?

We now have 10 (0-9) rooms we are playing our 3 stacked chess games in. We can reference any square on any chess board in any room...
chess$(5,1,2,7) = "Black Rook"

So, in room 7, on board 2, at position 5,1 on that board there is now a black rook...

Expand it further... Lets add any building...
dim chess$(7,7,2,9,4)

we now have x,y on the board, board number, room number, and building number which we can instantly reference...
chess$(1,2,2,8,3) = "White Pawn"

So the piece at 1,2 on board 2 in room 8 in building 3 is a white pawn.


thalamus(Posted 2004) [#13]
Cheers WolRon, that's a very nice explanation :)

However, the problem still remains - what if I want to change the size of a particular element?

The chessboard example assumes that all of the boards are the same size, whereas I need to have ones that can change size.

I've been struggling with this for a couple of hours but can't find a way around it without using Types...


CS_TBL(Posted 2004) [#14]
Dim your array again to the size you want.. (note: the original contents will be lost)


What you could consider: make a bank of banks!

Each bankhandle costs you 4 bytes (1 int) .. if you create a bank of 40 bytes, then you can store 10 bankhandles in it.. each bankhandle is ofcourse a seperate bank of ANY size.
You can easily resize a bank using ResizeBank and the contents wont get lost then ..
But again, as I'm the banktype, I'm not exactly neutral in this advice :)


thalamus(Posted 2004) [#15]
Blimey - I never even knew Banks existed (someone somewhere take note and provide some comprehensive Blitz docs...!).

So how do Banks work? Presumably I just access them like arrays?


thalamus(Posted 2004) [#16]
Ah, just found a tutorial by Krylar... :)


CS_TBL(Posted 2004) [#17]
Once you start working with banks, you'll want to use this for sure!

http://www.blitzbasic.co.nz/Community/posts.php?topic=29266

(don't forget to include that minor SetCanvas function)


Strider Centaur(Posted 2004) [#18]
Arrays are wastefull for a tile map where you may have very little data in most tiles, so types can help a good bit there.

Also I find type much easier to use in a tile map, because it makes it alot easier to add new data to existing data without the need to x to the power of n the entire array.

Types are plenty fast enough and the for loops on types make itterating through them a snap. I created a editor game map engine that supported unlimitted layers, in the game I was working on I used 10. I could do this because unlike DIM I did not need to allocate all that memory for unused tile positions.

Im fairly sure I posted it to Blitz Coder at some time. It was over a year ago.


So IMHO you should go types over arrays, unless the map is very simple and will not change much.


Rob Farley(Posted 2004) [#19]
Wolron, I wrote that... It's nice to see you're taking credit for something you didn't write.
http://www.blitzbasic.com/Community/posts.php?topic=35512#388017


WolRon(Posted 2004) [#20]
Umm, I didn't take credit for it.

Here is some text on multi-dimensional arrays from the tutorial:
Nowhere here does it say that I wrote it.


Rob Farley(Posted 2004) [#21]
I started a programming tutorial a while back (but didn't get very far). However, it just so happened that I started writing about arrays and types:
"I started writing about arrays and types"

That sounds like you wrote it to me.


WolRon(Posted 2004) [#22]
"I started writing about arrays and types"
which I did...
but I didn't say that I wrote that particular text that I copied to the screen.

If you would like me to remove it from my tutorial then I will. I just thought that you did a well enough job explaining it that it wasn't necessary for me to rewrite it. Nor did I feel that it was necessary to include a page of names of people that I might have borrowed text from - people who to most readers would probably just be nobodys anyways.

However, if you would like me to still use it in my tutorial but give you credit somewhere, then I can do that too.


puki(Posted 2004) [#23]
I love arrays - they're cuter than types.


thalamus(Posted 2004) [#24]
So back on topic... how do i create a library of "brush" arrays? Use a type for each brush, then within the type itself include an array?