English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

 
 
Thread Tools
Old 16 March 2020, 02:57   #1
AmiNju
Registered User

 
Join Date: Mar 2020
Location: Duesseldorf / Germany
Posts: 2
Question Tasks/Threads in BlitzBasic

Hi *,
is there a best practice way to use tasks (meaning threads) in BlitzBasic? I want to realize a little animated Shape (rotating Disc) on the screen while the game is loading some stuff in the background.


Best regards
Frank
AmiNju is offline  
Old 18 March 2020, 00:43   #2
E-Penguin
Banana

E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 882
You're probably best off putting a little update routine on the vblank interrupt. I don't think Blitz supports actual multi threading
E-Penguin is offline  
Old 18 March 2020, 10:47   #3
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 4,507
Indeed it doesn't. It's possible to do some funky stuff by messing around with the OS, but in the past I've found the simplest option is to just run another stand-alone executable. You can share information by passing messages containing pointers to objects so they can both access the same data, but there's no simple way to do it I'm afraid.
Daedalus is offline  
Old 19 March 2020, 00:37   #4
E-Penguin
Banana

E-Penguin's Avatar
 
Join Date: Jul 2016
Location: Darmstadt
Posts: 882
If you're happy with cooperative multi tasking or real-time style execution slots, you can knock up a task-based pseudo threading system pretty simply and use an interrupt to switch between tasks or raise an error if a task isn't yet in the suspended state by expected time.

Let's say you want to dedicate 1/3 of the runtime to animating your shape during loading. You split "load" and "rotate" into two functions, with a "state" variable. Let's say states 0 & 1 will correspond to Load, 2 = Rotate and 3 = suspended.

The main function does a loop with a select statement and calls either Load or Rotate depending on the state. At the end of the both functions the state is set to suspended. Each function call must complete within the interrupt period (ie Load does a stepwise read of data, fixed in length so as to complete in 1/50th of a second)

In your vblank interrupt, check for the state - if "suspended" then set the state to the next in the list of states, otherwise raise a "task overrun" error.

Congratulations you've written a real-time OS
E-Penguin is offline  
Old 20 March 2020, 02:11   #5
AmiNju
Registered User

 
Join Date: Mar 2020
Location: Duesseldorf / Germany
Posts: 2
Thanks for your answers and suggestions. This all sounds very strange.
I only asked myself this question because the manual in the appendix of BlitzBasic talks about "CreateProc" and "AddTask" (without really having an idea about it).
AmiNju is offline  
Old 20 March 2020, 12:47   #6
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 4,507
The Blitz manual lists the OS calls that are included with the default Blitz command libraries, including CreateProc and AddTask. They'll work, but you need to treat them as the OS calls they are, not Blitz commands. They're not Blitz commands so the manual doesn't cover them - they're in the main OS documentation instead. You can read the Autodocs for information about them - they're part of dos.library and exec.library respectively. But be warned, they're a little involved to use and directly affect the system, so expect lots of crashing until you get it right.
Daedalus is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Devices, Ports, Messages, Tasks, etc. Graz Coders. System 2 05 September 2014 02:29
[blitzbasic] contextual help ? demether Coders. Blitz Basic 1 22 May 2014 17:49
GUI Refresh Problem with Two Tasks AGS Coders. System 2 18 December 2013 21:19
BlitzBasic problem AlfaRomeo Coders. General 5 01 May 2009 11:58
BlitzBasic (PC) LaundroMat Coders. General 9 23 June 2003 10:14

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 10:14.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Page generated in 0.06298 seconds with 14 queries