[Pogamut-list] Fast Traces in getSimpleRayCasting()

jacob.schrum pogamut-forum at diana.ms.mff.cuni.cz
Wed May 18 04:37:15 CEST 2011


Fast Traces in getSimpleRayCasting()

Author: jacob.schrum

I would like to use fast ray traces for something, and I don't mind 
having the bot do nothing while waiting for the FastTraceResponse.
Therefore, I would like one method that sends the fast trace message,
and blocks for the response, which is then returned by the method.
Of course, somewhere in here there has to be a listener for
FastTraceResponses as well. Here is what I'm trying:

{CODE()}
private final BlockingQueue pendingFastTraces = new ArrayBlockingQueue(1, true);
    
IWorldEventListener fastTraceResponseHandler = new IWorldEventListener() {

        @Override
        public void notify(FastTraceResponse ftr) {
            try {
                pendingFastTraces.put(ftr);
            } catch (InterruptedException ex) {
            }
        }
    };
{CODE}
This is added via:

{CODE()}
world.addEventListener(FastTraceResponse.class, fastTraceResponseHandler);
{CODE}

Then there is the method call to get the trace result.

{CODE()}
public Boolean quickTraceThroughWall(Location target) {
        String id = "Quick";
        body.getSimpleRayCasting().fastTrace(id, target);
        FastTraceResponse ftr;
        try {
            ftr = pendingFastTraces.take();
        } catch (InterruptedException ex) {
            return null;
        }
        return ftr.isResult();
    }
{CODE}

The BlockingQueue is supposed to automatically handle synchronization.
The take() method should make the Thread wait for the listener to put the trace response
in the queue, but what happens when I run this is the take() causes a the logic thread to
wait (I've looked at the profile) while the mediator (which handles the listener) continues
to run, but never actually executes the notify method.

Any advice for how to accomplish what I want?

-- 
Reply Link: <http://diana.ms.mff.cuni.cz/main/tiki-view_forum_thread.php?forumId=4&comments_parentId=761#form>





More information about the Pogamut-list mailing list