« Return to Thread: Re: mtasc Digest, Vol 50, Issue 3

Re: Re: mtasc Digest, Vol 50, Issue 3

by Luke Bayes :: Rate this Message:

Reply to Author | View in Thread

Background threads....

First thing is that you're in a single-threaded environment and you're
not really getting out of that.

The good news is that downloads do happen in a separate process, so
they don't lock up the UI.

In the past, we have built Finite State Machines, and Asynchronous
Command Queues for long-running background-ish processes.

Given these two patterns, I'd say the Command Queue proved most
flexible and useful for us.


Pseudocode for CommandQueue with clients:


// Dispatches a COMPLETED event
interface Command {
    function execute():void;
}

// Dispatches a COMPLETED event whenever queue is empty
class CommandQueue {
    public function push(command:Command):void {
        // add listeners and execute
    }
}


class Main {

    public static function main() {
        var queue:CommandQueue = new CommandQueue();
        queue.addEventListener(COMPLETED, queueCompletedHandler);
        var assetLoader:Command = new AssetLoader('assets/foo.png');
        var xmlLoader:Command = new XMLLoader('xml/foo.xml');
        queue.push(assetLoader);
        queue.push(xmlLoader);
    }

    private function queueCompletedHandler(event:Event):void {
        // Queue is complete, do other work
    }
}


Good Luck,


Luke Bayes
http://www.asserttrue.com


On Wed, Jan 14, 2009 at 4:37 PM, Scott Christensen <sukosuko11@...> wrote:

> Thanks for info on the flag.  It does make sense that the default is to
> either allow only access to the file system OR the internet.
>
> I've set the flag on my system to allow global access, but good to
> know users on the internet won't need to change it as everything on the
> internet for them.
>
> I will take a look at projectsprouts.org
>
> Another question, it appears Actionscript doesn't have any background
> threads? Any thoughts on loading assets in the background for a MMORPG to
> minimize delays?
>

--
MTASC : no more coffee break while compiling

 « Return to Thread: Re: mtasc Digest, Vol 50, Issue 3