Levels (Maps) - best way to store them

Blitz3D Forums/Blitz3D Programming/Levels (Maps) - best way to store them

PaulJG(Posted 2003) [#1]
Hi Guys,

I was wondering how you'd recommend that I use maps on my little game.

At the mo, I'm loading in around 30+ 3DS static and animated mesh objects - which form my level.

I've been putting out each object in my little world by hand, I guess there must be some sort of free 'world placement editor' or something I could use to visually see how things go together more quickly ?.

Also, loading up that amount of objects for each level of the game is a pain - should I think about loading them up in some sort of complete map file ?. I need to use collisions on most of the objects, so I guess I'm limited as to what I can do ??. (do they take on the one mesh fits all profile ?, or are they still treated as single objects ?)

Any help here would be very welcome, I've got a feeling I'm doing it the hard way.

Thanks Paul.


Sunteam Software(Posted 2003) [#2]
In the interests of fairness there are several Blitz user created world editors. Do a search in the forums for any of the following:

LightBulb
Worldspin
Quill3D

Sorry if i've omitted any.


PaulJG(Posted 2003) [#3]
Thanks, I have looked at em. But at the mo I want to use something that is free and will let me get on with it.

Thats not to say I wont be buying one of them when I get to such lovely things as lightmapping :( but at the mo I just need something that will let me place objects visually.

Reading through the posts on the forum, there seems to be a bit of a battle over which one is better.. Not sure where that leaves me ?

I am still alittle worried about how they treat objects, are they still single objects or combined into one ?.

btw.. the BUY button on Worldspin gives out a 'page cannot be found error'


jhocking(Posted 2003) [#4]
You can just construct the level in any modeling tool (eg. 3D Studio Max, Milkshape.) If you really want a world editor you could write your own placement editor. More complex stuff like lightmapping and CSG level editing would take a while to write but just a simple placement editor (to place pre-made objects together into a scene) is simple.

You can represent the data as a single model or you can keep the various objects as separate model files and represent the assembled scene in a custom file format. All you really need there is a text file which contains the name and position/rotation of every object.

Unless the objects to load are all hard-coded (and even then you only have to list everything once) there's no reason loading and placing a whole bunch of objects should be painful. Just create a loop which loads an object and keep looping until all the objects are loaded.


Doggie(Posted 2003) [#5]
HomeSpun is FREE. Go get it at the Blitz Showcase.

It will do exactly what you want. Sorry though, it too will load each of your objects one at a time unless they are copies.

Doggie


superqix(Posted 2003) [#6]
Here's a freebie for you... This is the code I use for my level editor to load and save ".LED" files. LED files store the location and rotation of all meshes loaded using the ImportMesh(ImportFilename$) command.

Type LevelItem
	Field Mesh
	Field File$
End Type

Function ImportMesh(ImportFilename$)
	DebugLog "Import: " + Filename$
	Mesh = LoadMesh(ImportFilename$)
	If Mesh Then
		Level.LevelItem = New LevelItem
		Level\Mesh = Mesh 
		Level\File$ = ExtractFilename$(ImportFilename$)
		EntityPickMode Level\Mesh,2
		PositionEntity Level\Mesh,0,0,0
	EndIf 
	Return Mesh
End Function

Function FindLevelItemFile$(Entity)
	For Level.LevelItem = Each LevelItem
		If Level\Mesh = Entity Then Return Level\File$
	Next
End Function

Function DeleteLevelItem(Entity)
	For Level.LevelItem = Each LevelItem
		If Level\Mesh = Entity Then Delete Level
	Next
End Function

Function SaveLevel(Filename$)
If Lower(Right(Filename$,4)) <> ".led" Then Filename$=Filename$+".led"
	LevelFile=WriteFile(Filename$)
	If LevelFile Then
		WriteInt LevelFile, (76 Shl 24) + (69 Shl 16) + (68 Shl 8) + 49; LED1
		For Level.LevelItem = Each LevelItem
			WriteString LevelFile, Level\File$
			WriteFloat LevelFile, EntityX(Level\Mesh,1)
			WriteFloat LevelFile, EntityY(Level\Mesh,1)
			WriteFloat LevelFile, EntityZ(Level\Mesh,1)
			WriteFloat LevelFile, EntityPitch(Level\Mesh,1)
			WriteFloat LevelFile, EntityYaw(Level\Mesh,1)
			WriteFloat LevelFile, EntityRoll(Level\Mesh,1)
		Next
		CloseFile LevelFile
		Return True
	Else
		Return False
	EndIf
End Function

Function ClearLevel()
	For Level.LevelItem = Each LevelItem
		If Level\Mesh Then FreeEntity(Level\Mesh)
		Delete Level
	Next
End Function

Function LoadLevel(Filename$)
	DebugLog "Load: " + Filename$	
	LevelFile=ReadFile(Filename$)
	If LevelFile Then
		LevelDirectory$ = Left$(Filename$,Len(Filename$)-Len(ExtractFilename$(Filename$))) + "\"
		If (ReadInt(LevelFile) = (76 Shl 24) + (69 Shl 16) + (68 Shl 8) + 49) Then ; LED1
			ClearLevel()
			Repeat
				Mesh = ImportMesh(LevelDirectory$ + ReadString$(LevelFile))
				x# = ReadFloat(LevelFile)
				y# = ReadFloat(LevelFile)
				z# = ReadFloat(LevelFile)
				p# = ReadFloat(LevelFile)
				w# = ReadFloat(LevelFile)
				r# = ReadFloat(LevelFile)
				If Mesh Then PositionEntity Mesh,x,y,z
				If Mesh Then RotateEntity Mesh,p,w,r
				If Mesh Then EntityType Mesh,2
				If Mesh Then EntityPickMode Mesh,0
			Until Eof(LevelFile)
			CloseFile LevelFile
			Return True
		Else
			RuntimeError("File Not Found")
		EndIf
	Else
		Return False
	EndIf
End Function

Function FindLevelItem(file$="")
	For Level.LevelItem = Each LevelItem
		If Level\File$ = Upper$(file$) Then Return Level\Mesh
	Next
	Return False
End Function

Function ExtractFilename$(FileName$)
	FileName$="\"+FileName$
	LastBackSlash = 1
	Repeat
		NextBackSlash = Instr(filename$,"\",LastBackSlash)
		If NextBackSlash > 0 Then LastBackSlash = NextBackSlash + 1
	Until NextBackSlash = 0
	tmp$ = Right$(FileName$,Len(FileName$)-LastBackSlash+1)
	Return tmp$
End Function


Now all you need to do is write something to load and move your objects around....

UPDATE: I had to hack out some level editing code, let me know if there is any problems using it...


Ice9(Posted 2003) [#7]
Writing your own editor is half the fun of making the game.
feature rich all inclusive and fun to use. To some the editor is the most enjoyable part of the game.


JoshK(Posted 2003) [#8]
Ummmm, hello?


Michael Reitzenstein(Posted 2003) [#9]
Hello what?


PaulJG(Posted 2003) [#10]
err.. Halo - click on the DOWNLOAD button on your cart. site, lil problem. ;)

I got the cart2 demo a couple of weeks ago to play around with but without a feature to load in 3d objects, its hard to see how I'd use it.

Quill was 'interesting'.. I'd had a few beers before looking at it - thought I was in a plane cockpit with the amount of buttons it was throwing at me. Couldnt get lights to point where I wanted very easily ?.

Mark's Maplet and the other proggies, droplet etc.. where good fun. Problem is when you've created the level, textured it, put down your entities, placed your objects, you want to recalc the lightmap. :(

Doggie, had a problem with homespun - starts off with a readymade level which I cant clear ???.

Superqix, thanks matey - looks like I just might have to write my own, and thats a good start.

(although not at the mo, since I wanna get this game finished up first. I've taken Joe's advice and grouped everything together in my 3d program.)

Anyway, cheers for all the help guys, so much has changed with Blitz over the last year - but its nice to be back !.


superqix(Posted 2003) [#11]
No prob,

This is what I'm working on with it...