Using MaxGUI for dynamic text based games?

BlitzMax Forums/MaxGUI Module/Using MaxGUI for dynamic text based games?

Ryan Burnside(Posted 2009) [#1]
I was wondering if it is possible to use the text area gadget to create a realtime TEXT based game? I'd need to have the screen updating automatically at 60 FPS. I want to make some dynamic text effects. This means adapting the text inside the box to act as images. Is MaxGUI capable of creating text based games that must be refreshed and drawn at 60 frames per second? I've tried using raster images of the font without GUI and bmax native graphics driver is simply too slow to handle 3000 letter images. The notion of using an actual text field would be more appealing if it is faster.

I need the game to update constantly, unlike a text adventure game.


Brucey(Posted 2009) [#2]
This is something I'm working on at the moment. (170kb rar)

It's obviously not complete (Line drawing, fov, bsp and mouse support still to implement), but it's all "text" based, and runs reasonably quickly.
By "text", that doesn't mean a real console, but one drawing to a graphics context (dx/ogl).


Ryan Burnside(Posted 2009) [#3]
That is very similar to what I want to do. I get a high of 23 FPS on that and a low of 14 FPS.


plash(Posted 2009) [#4]
Runs crap for me. Probably because it's using dx though, my card hates directx.


Bremer(Posted 2009) [#5]
On my system, using an image loaded with loadanimimage seems to be doing a 60x60 character area using 8x8 pixels letters just fine. About 8ms to draw the 3600 characters.

Try this piece of code with the image linked:

http://zac-interactive.dk/temp/8x8.bmp

Graphics 640,480

Global font = LoadAnimImage("8x8.bmp",8,8,0,96)

Global screenChar:Int[60,60]
Global screenColorR:Int[60,60]
Global screenColorG:Int[60,60]
Global screenColorB:Int[60,60]

For y=0 To 59
For x=0 To 59
	screenChar[x,y] = Rnd(33,65)
	screenColorR[x,y] = Rnd(255)
	screenColorG[x,y] = Rnd(255)
	screenColorB[x,y] = Rnd(255)
Next
Next

Local fpsCnt:Int = 0
Local fpsReal:Int = 0
Local fpsUpdate:Int = MilliSecs()

Local timeUpdate:Int = 0
Local timeCheck:Int = 0

Local upd:Int = MilliSecs()

While Not KeyHit(KEY_ESCAPE)
	Cls
	update = MilliSecs()
	drawScreen()
	timeCheck = MilliSecs()-update
	SetColor(255,255,255)
	DrawText("FPS: "+fpsReal,488,8)
	DrawText("DrawTime: "+timeCheck+"ms",488,24)
	Flip False

	fpsCnt :+ 1
	If MilliSecs() > fpsUpdate + 1000 Then
		fpsReal = fpsCnt
		fpsCnt = 0
		fpsUpdate = MilliSecs()
	End If

	If MilliSecs() > upd+15 Then
		upd = MilliSecs()
		rndScreen()
	End If

Wend
End

Function rndScreen()
	For Local y:Int = 0 To 59
		For Local x:Int = 0 To 59
			screenChar[x,y] = Rnd(33,65)
			screenColorR[x,y] = Rnd(255)
			screenColorG[x,y] = Rnd(255)
			screenColorB[x,y] = Rnd(255)
		Next
	Next
End Function

Function drawScreen()
	For Local y:Int = 0 To 59
	For Local x:Int = 0 To 59
		SetColor(screenColorR[x,y],screenColorG[x,y],screenColorB[x,y])
		DrawImage(font,x*8,y*8,screenChar[x,y])
	Next
	Next
End Function


[edit] Added fps and drawtime display.


Brucey(Posted 2009) [#6]
my card hates directx.

That's optional. I imagine it is picking that up by default. (thought I'd best enable both on Windows).

On my Mac Mini, I get 275 fps. I thought it would perform a bit better on Windows?


plash(Posted 2009) [#7]
Are you talking about the library or Max defaulting to DirectX?

I get 5 fps with the sample you posted. Is there a way to change the driver used in your sample?


Brucey(Posted 2009) [#8]
Sure.. you can specify the driver at the start (in the code). I think Max defaults to directx ?

I'll be uploading the module soonish.
Still dunno why it's so slow though. On my crap PC at work it tops out at 24fps - one of those HP's for business things.

The fact I'm employing my own renderer (instead of SDL) probably doesn't help too much though... but I'm sure there's some room for tweaking still.


plash(Posted 2009) [#9]
I think Max defaults to directx ?
Yes it does.

Still dunno why it's so slow though. On my crap PC at work it tops out at 24fps - one of those HP's for business things.
I don't know about Ryan's machine, but my card sucks at DirectX (5fps).

Looking forward to playing with the module.


Brucey(Posted 2009) [#10]
Still dunno why it's so slow though

The built-in draw routines are very inefficient if you need to do "batch" type drawing.
I was getting 94fps in debug... after some tweaks, and avoiding using the default drawing code, I've got that up to 150fps.
Interestingly, in release mode, the fps tops out at 275. I can't get it higher than that. I'm beginning to think it maybe is a hardware limit.

Of course, the default draw routines are generic, so they are good for everyday use. But if you want to double (or more) the drawing, you need to implement your own.


Brucey(Posted 2009) [#11]
Here is a new version of the sample. (170kb rar)
OpenGL only this time, using my heavily optimized code, as mentioned above. (about 2x the previous version).

It also includes line drawing and FOV. (bsp and mouse support left to sort out).


xlsior(Posted 2009) [#12]
Interesting.. Seems to work pretty well.

Odd thing to see the rotating skull 'graphics' in text mode. :-?

I did notice one problem: Under Vista 64, when trying the alt-enter to switch to full screen the application crashes. (Not sure if this is a true console screen or not -- Vista also won't do full-screen DOS command prompts. Perhaps check for Vista / Windows 7 and deny full screen mode?)


Retimer(Posted 2009) [#13]
Held 670+ fps on that one. Interesting library - extreme retro feel to it.

Looking forward to whatever you're working on Burnside.


Brucey(Posted 2009) [#14]
Under Vista 64, when trying the alt-enter to switch to full screen the application crashes.

Dunno what to do about that. I'm calling EndGraphics, then Graphics .... is there anything else I should be calling?

Not sure if this is a true console screen or not

Nah, just your everyday BlitzMax graphics context.



Well, I've just committed the module for now - tired of moving it around on my stick, and it's reasonably stable (and mostly complete).

If you have questions/etc about the module, better ask them in the other forum... I think I hijacked this thread enough.


plash(Posted 2009) [#15]
Nice! 120 fps, thanks for this Brucey.