Simultaneous load files and do stuff

BlitzMax Forums/BlitzMax Programming/Simultaneous load files and do stuff

This is BlitzPlus/3d code but it demonstartes anyway.
You could get 1000 bytes in a frame even while doing alot of stuff:

;
;REQUIRES
;
;an image called s.png, prefferably 256*256 or smaller: My Size 4.47 KB: Demo suited to run at 60 fps withough filr reading to observe effects.
;
;a file called "file.txt". Here its 232 KB.


Graphics 640,480,0,2

SetBuffer BackBuffer()
SeedRnd MilliSecs()

img=LoadImage("s.png")
If( Not img) RuntimeError"U Need an image called s.png!, or else change it to w~ever"
MaskImage img,$FF,$FF,$FF

tmr=CreateTimer(60)

ClsColor 128,0,0


FILE=OpenFile("File.txt")
If(Not FILE) RuntimeError"U Need a file called File.txt!, or else change it to w~ever"



fps#=0
Dontrefreshfps=False
ex=False
While Not KeyHit(1)

	Cls
	
	For u=0 To 1000
		If(Eof(FILE))
			Notify"Finished reading file"
			ex=True
			Exit
		EndIf
		ReadByte(FILE)
		Read_Bytes=Read_Bytes+1
	Next
	If ex Exit
	
	;STUFF TO SIMULATE...STUFF GOING ON BEGINS HERE
	
	;to simulate stuff happening=>realtime stuff, lots of commands as well as code=>instead of looping cause they rep. individual commands
	
	For u=0 To 2	;any more and it runs less than 60 fps WITHOUGHT file streaming
	DrawImage img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img))
	DrawImage img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img))
	DrawImage img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img))
	DrawImage img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img))
	DrawImage img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img))
	DrawImage img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img))
	DrawImage img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img))
	DrawImage img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img))
	DrawImage img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img))
	DrawImage img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img))
	DrawImage img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img))
	DrawImage img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img))
	DrawImage img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img))
	DrawImage img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img))
	DrawImage img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img))
	
	If(ImagesCollide(img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img)),0,img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img)),0))hohoho=0
	If(ImagesCollide(img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img)),0,img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img)),0))hohoho=0
	If(ImagesCollide(img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img)),0,img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img)),0))hohoho=0
	If(ImagesCollide(img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img)),0,img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img)),0))hohoho=0
	If(ImagesCollide(img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img)),0,img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img)),0))hohoho=0
	If(ImagesCollide(img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img)),0,img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img)),0))hohoho=0
	If(ImagesCollide(img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img)),0,img,Rnd(640-ImageWidth(img)),Rnd(480-ImageHeight(img)),0))hohoho=0

	For t=0 To 50
		x=x*b+Sin(3)*Cos(3454+ef)/(Rnd(2)+3556)
		x=x+1
		x=x*1
		b=12
		x=x*(b Shl 1)
		x=x*b+Sin(3)*Cos(3454+ef)/(Rnd(2)+3556)
		x=x+1
		x=x*1
		b=12
		x=x*(b Shl 1)
		x=x*b+Sin(3)*Cos(3454+ef)/(Rnd(2)+3556)
		x=x+1
		x=x*1
		b=12
		x=x*(b Shl 1)
		x=x*b+Sin(3)*Cos(3454+ef)/(Rnd(2)+3556)
		x=x+1
		x=x*1
		b=12
		x=x*(b Shl 1)
	Next
	
	Next
	
	;STUFF TO SIMULATE...STUFF GOING ON ENDS HERE
		
	lengthOfFrame=MilliSecs()-LastFrame
	LastFrame=MilliSecs()
	
	If Not Dontrefreshfps
		;as a fraction of a second
		fps#=1000.0/lengthOfFrame
	EndIf
	
	Text 0,0,"fps("+Int%(fps)+");"
	Text 0,20,"Read :"+Read_Bytes+"Bytes of File"
	
	Dontrefreshfps=Dontrefreshfps+1
	If(Dontrefreshfps>30)Dontrefreshfps=False ;and so it'll refresh
	
	Flip()
	
	If(KeyDown(56) And KeyDown(62))Exit
	
	WaitTimer(tmr)
Wend

CloseFile(FILE)
FreeTimer(tmr)
FreeImage(img)

End

Not exactly five years lol.