Animating on the Interrupts?
Blitz3D Forums/Blitz3D Programming/Animating on the Interrupts?
| ||
In the good ol' days of the amiga version of blitz (sigh), it was possible to animate a sprite on the interrupts. This meant that the clock cycles left to give the o.s. a breather were used to run the animation. This allowed (for example) a loading animation to show whilst files were being loaded etc. I always liked this feature, any idea how to replicate it in blitz? |
| ||
Not possible as far as I know. There's no support for threading. |
| ||
Would it possible to emulate interrupts in software using the Millisecs() command? eg. every 10ms run through a list of functions, the same for every 250ms.. Anyone tried anything like this? |
| ||
I didn't think blitz supported threading, but thought maybe someone had created a nifty and clever solution. Beyond me what it would be though. I was wondering if maybe I could use banks and load my objects in bytes with a periodic call to update the anim. |
| ||
http://www.blitzbasic.com/Community/posts.php?topic=44366 Use that concept, and use BlitzSys (which I can't find, sorry :( If I ever do I'll post it up for easy reference... and I'll email it to you if you want) to find the window x y position without the use of crazy pointer stuff which blitz doesn't support. The embedded application would have to be a child window of the main window, with the start window removed using one of the many blitz start window removal tools, and it can run anything you want it to that blitz can possibly run. To kill it off, use api_destroywindow in user32 to destroy the child window (the child window is found like this: Const GW_CHILD = 5 api_GetWindow(hWnd,GW_CHILD)) I have an example of this "nifty" solution as used in my application posted here: http://www.blitzbasic.com/Community/posts.php?topic=45982 No, the window will not lose focus, because as long as it has the style attribute "WS_POPUP" or something similar, the child will stay on top of its parent (in fact, it seems to stay on top of its parent no matter what). It's all a bit weird to get used to, but once you do, it's all very straight-forward and useful. I bet if you were really crazy and had loads of time to search through the win32 command reference (http://www.mentalis.org/agnet/apiguide.shtml) you could actually make the embedded window force the main window to animate... |
| ||
You can simulate multithreading in Blitz, if you're interested. But it's very complicated. It's basically a process of calling a function every frame, doing a little bit of the total work, and then returning when your time has expired. You loop until the job is finished. Inside your operation function you'll need to do frequent time checks, to determine when to exit. If these aren't small enough it may turn out to be jerky. This won't be anywhere near as clean and easy to follow as multi-threaded programming, but it's as close as you'll get. But then, on the other hand, if you know enough about networking, you might literally start another program, having the second program do the work you need in the background. You could use UDP messages between the programs to trade information, tasks, etc. But of course this probably wouldn't be what you want for a media loading bar. Just something to think about. |
| ||
This multithreading simulation is what I am using to create a geo-mod system in my game. It's difficult to visualise, but once you get to coding, as long as you plan it well it's not too hard. |
| ||
Thanks guys. Mr picklesworths solution sounds promising as I work as a windows software developer so am familiar with the api. I will definitely look into the subject in more depth.. |
| ||
You can emulate virtual threading, but you'll have to create your own loading code.Global thread_branch=0 Global thread_count=0 Global thread_percent=0 Global filecount Global file_in$="image.img" Global file_out$="image.img" Global filein Global fileout Global x=0 Global y=0 ; Create the file you are loading later savefile(file_out$) Graphics 800,600 ; Setup imagebuffer Global img=CreateImage(640,480) ; Setup mousepointer Global mouseimg=CreateImage(10,10) SetBuffer ImageBuffer(mouseimg) Color 250,250,250 For q= 0 To 9 Plot q,q Plot 0,q Next Color 5,5,5 For q= 1 To 9 Plot q+1,q Plot 1,q Next ; setup doublebuffering SetBuffer BackBuffer() ; Starting values thread_branch=1 ; main loop While Not KeyHit(1) ; branch to file loading If thread_branch=1 Then loadfile(file_in$) EndIf ; draw on backbuffer SetBuffer BackBuffer() Cls Color 255,255,255 Text 360,230,"Loading..." ; draw the slider If thread_branch=1 Then thread_percent=((filecount*100)/FileSize(file_in$)) Color 255,255,255 Rect 150,250,500,25,0 Rect 150,250,thread_percent*5,25,1 EndIf ; Draw the image when loaded If thread_branch=2 Then DrawBlock img, 250,200 Text 360,450,"Esc to quit" EndIf ; draw mouse pointer DrawImage mouseimg, MouseX(), MouseY() Flip False Wend End ; saving file Function savefile(file_out$) fileout = WriteFile(file_out$) For x=0 To 319 For y=0 To 199 WriteByte( fileout, Rnd(0,255)) WriteByte( fileout, Rnd(0,255)) WriteByte( fileout, Rnd(0,255)) Next Next CloseFile( fileout ) End Function ; loading file in logical steps Function loadfile(file_in$) ; step one - open file for reading If thread_count=0 Then filein = ReadFile(file_in$) thread_count=1 filecount=0 x=0 y=0 EndIf ; step two - read data and write to imagebuffer If thread_count =1 Then y=y+1 If y=200 Then x=x+1 y=0 EndIf Read1 = ReadByte( filein ) Read2 = ReadByte( filein ) Read3 = ReadByte( filein ) filecount=filecount+3 ; draw to imagebuffer SetBuffer ImageBuffer(img) Color read1,read2,read3 Plot x,y ; check for end of file If Eof(filein) Then thread_count=2 EndIf EndIf ; step three - close file If thread_count=2 Then CloseFile( filein ) thread_branch=2 EndIf End Function This is Crap Code TM, so you can do much better, but you get the idea. Andy |
| ||
That's pretty good, Andy :) |
| ||
EDIT: Thanks Mr. Picklesworth. I'm doing this in a few projects, even with tweening and I haven't really got any problems with it, although it needs to be planned and I have opted for proprietary fileformats instead of redoing what Blitz3D already does. I think there's a tendency for many people to perceive Blitz as a closed box. ie. if it's not built-in, then they don't think it's possible and they end up using dll's etc. doing what can be done in blitz with a small amount of effort. I'm still working on a terrainsystem with dynamic resource loading using virtual threading(similar in theory to the above) and spanning the whole globe simply by normalizing positions every once in a while. I think that we can use alot more discussion about how to circumvent the limitations of Blitz without using dll's. Simple beats complex almost every time. Andy |