Futurescale, Inc. PureMVC Home

The PureMVC Framework Code at the Speed of Thought


Over 10 years of community discussion and knowledge are maintained here as a read-only archive.

New discussions should be taken up in issues on the appropriate projects at https://github.com/PureMVC

Pages: [1]
Print
Author Topic: Gaming using PureMVC  (Read 6882 times)
jsimpson


Email
« on: March 05, 2009, 07:50:27 »

I'm new, hi. I'm working to make a series of game components much more of an actual module that can be put in any new game I create and I'm hoping PureMVC can help. I'm using the AS3 port but have a few questions about how to best go about converting previous routines into the correct structure.

The following is a snippet from 8BitRocket, but it's the gameloop I've come to use:

:
private function runGame(e:TimerEvent) {
    _beforeTime = getTimer();
    _overSleepTime = (_beforeTime - _afterTime) - _sleepTime;


    checkKeys();
    updatePlayer();
    updateMissiles();
    checkCollisions();

    canvasBD.lock();
    drawBackground();
    drawPlayer();
    drawRocks();
    drawMissiles();
    drawParts();
    canvasBD.unlock();
   
    _afterTime = getTimer();
    _timeDiff = _afterTime - _beforeTime;
    _sleepTime = (_period - _timeDiff) - _overSleepTime;       
    if (_sleepTime <= 0) {
        _excess -= _sleepTime
        _sleepTime = 2;
    }       
    gameTimer.reset();
    gameTimer.delay = _sleepTime;
    gameTimer.start();

    while (_excess > _period) {
        checkKeys();
        updatePlayer();
        updateRocks();
        updateMissiles();
        checkCollisions();
        _excess -= _period;
    }
   
    frameTimer.countFrames();
    frameTimer.render();   
}

This does two main things. I keeps the framerate at a predetermined 30fps, assuming that's the timers setting, and controls the 'render' by checking the timer. If the computation took more time than is allowed for a frame, the frame is dropped and rendered on the next pass. In the previous post about games using PureMVC it mentioned a TimerPRoxy class. Is that a default or something to be implemented?

Another question regards location of collision detection code. I don't use events for my collision detection because of the small added overhead, but instead have an array of collidable objects that are checked against world, and in some cases each other. I also use an AABB to sweep and prune the collisions. What kind of speed comparision is there between evens and pureMVCs notifications? Also what would be the best way to find the collisions but keep response seperate from the actual detection.


My goal with using PureMVC is pretty complex(for me at least), mainly I'd like to be able to create a series of modules that allow me to plug them together and create new games quickly. For example having AI behaviors for a tiled world, a free roaming world, a world with waypoints... then be able to simply use preexisting classes to have quick basic AI. The same would go for having a quick foundation for a Tiled World, or a free roaming world. Ultimately I'd also like to do the same for the physics and collision detection. Thanks for any input!
Logged
puremvc
Global Moderator
Hero Member
*****
Posts: 2871



View Profile WWW Email
« Reply #1 on: March 05, 2009, 08:21:40 »

The TimerProxy would have to be implemented. You might start out by having a look at the AS2 game Chandima and I worked on called Balloonatroid for a few ideas, but I really like your thinking better. Instead of a purpose built game apparatus, a more general system. I haven't touched on gaming much since Balloonatroid, but MultiCore and modular stuff has arisen in the interim and change things a lot.

I'll be interested to hear your thoughts as you get going with this. Look into MultiCore and think about how you might separate functionality into modules.   

-=Cliff>
Logged
Pages: [1]
Print