Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

11855 Posts in 1569 Topics- by 3045 Members - Latest Member: lensreslai

10. February 2012, 05:24:02 AM
Xith3D CommunityGeneral CategoryFeature Requests & Brilliant Ideas (Moderators: Marvin Fröhlich, 'n ddrylliog)Priority Classes for Scheduled Operations
Pages: [1]
Print
Author Topic: Priority Classes for Scheduled Operations  (Read 1277 times)
Michael Schreiner
Enjoying the stay
*
Offline Offline

Posts: 91


View Profile
« on: 21. September 2008, 01:25:25 PM »

Hello,

for my application, I use (within one render path) scheduled operations for the individual behavior of objects and the control of the camera. Since the camera behavior depends on the position of the objects, it is desired that within the update-calls the camera's update is the last. To implement this, it would be of advantage to have e.g. three classes of scheduled operations, so that it is clear that the one of class 3 are called AFTER the ones of class 1 and 2.

I am not sure, if this is something useful for others or if this functionality is already contained in xith ..... Just an idea.

Michael
Logged
Marvin Fröhlich
Xith Lord
Administrator
Guru
*****
Offline Offline

Posts: 4337


May the 4th, be with you...


View Profile
« Reply #1 on: 21. September 2008, 01:54:18 PM »

Well, I would not want to complicate the ScheduledOperation management with additional checks to keep it as cheap as possible. The bahavior, that you desire is already possible through a different approach. Please see this testcase:

Code:
public class OpSchedTest extends InputAdapterRenderLoop
{
    @Override
    public void onKeyPressed( KeyPressedEvent e, Key key )
    {
        this.end();
    }
   
    @Override
    protected void prepareNextFrame( long gameTime, long frameTime, TimingMode timingMode )
    {
        System.out.println( "new frame: " + gameTime );
       
        super.prepareNextFrame( gameTime, frameTime, timingMode );
    }
   
    public OpSchedTest() throws Throwable
    {
        super();
       
        Xith3DEnvironment env = new Xith3DEnvironment( this );
       
        /*
         * These schedulers should take the RenderLoop as a parameter
         * to the constructor.
         * The RenderLoop is a GameTimeHost. The Scheduler uses the given
         * GameTimeHost to "synchronize" time.
         */
        OperationSchedulerImpl opSchederFirst = new OperationSchedulerImpl( this );
        OperationSchedulerImpl opSchederLast = new OperationSchedulerImpl( this );
       
        /*
         * This order is important!
         */
        this.addUpdatable( opSchederFirst );
        this.addUpdatable( opSchederLast );
       
        /*
         * We add this operation first to emphesize,
         * that is is executed last, no matter where
         * and when it is added.
         */
        opSchederLast.scheduleOperation( new ScheduledOperationImpl( true )
        {
            public void update( long gameTime, long frameTime, TimingMode timingMode )
            {
                System.out.println( "Opearation LAST: " + gameTime );
            }
        } );
       
        /*
         * The following operations will always be executed _before_ the LAST one!
         */
       
        opSchederFirst.scheduleOperation( new ScheduledOperationImpl( true )
        {
            public void update( long gameTime, long frameTime, TimingMode timingMode )
            {
                System.out.println( "Opearation 0: " + gameTime );
            }
        } );
       
        opSchederFirst.scheduleOperation( new ScheduledOperationImpl( true )
        {
            public void update( long gameTime, long frameTime, TimingMode timingMode )
            {
                System.out.println( "Opearation 1: " + gameTime );
            }
        } );
       
        opSchederFirst.scheduleOperation( new ScheduledOperationImpl( true )
        {
            public void update( long gameTime, long frameTime, TimingMode timingMode )
            {
                System.out.println( "Opearation 2: " + gameTime );
            }
        } );
       
        opSchederFirst.scheduleOperation( new ScheduledOperationImpl( true )
        {
            public void update( long gameTime, long frameTime, TimingMode timingMode )
            {
                System.out.println( "Opearation 3: " + gameTime );
            }
        } );
       
        Canvas3D canvas = Canvas3DFactory.createWindowed( OpenGLLayer.LWJGL, 800, 600, "test" );
        env.addCanvas( canvas );
       
        InputSystem.getInstance().registerNewKeyboard( canvas.getPeer() );
       
        this.begin();
    }
}

You could of course create an implementation of OperationScheduler (or an extension of OperationSchedulerImpl) called PriorizedOperationScheduler and override the appropriate methods to realize this bahavior. Then you would need a new interface called PriorizedScheduledOperation with one additional method
int getPriority()
which would return an integer (lower number -> higher prio).

One way it use this number, would be to read out this number in the schedulerOperation() method and push the operations into different lists. Another way would be to read out this number each frame in the update() method and sort the operations appropriately.

If you like this more than the way in the above testcase, and you want to implement it, I would happily take this for the xith codebase Smiley. But I believe, the above testcase shows the simpler and cheaper way.

Marvin
Logged
Michael Schreiner
Enjoying the stay
*
Offline Offline

Posts: 91


View Profile
« Reply #2 on: 21. September 2008, 04:26:40 PM »

Hello Marvin,

thanks. For me, your testcase is more flexible than that was I need. In the moment, I just make sure, that the camera behavior is the last in the list...

Michael

Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic