Skip to main content


No replies
Joined: 2010-08-02
Points: 0

Is there a time limit for the number of changes a single Behavior can
make during a single processStimulus() invocation?

In my traffic simulator I have a single Behavior that calls a method in
all vehicles that have moved or changed appearance. Here is the process:

1) The main processing loop changes the lights and moves the vehicles.
2) The vehicles save a pointer in the Behavior's (synchronized)
ArrayList when they need to move or change appearance. The ArrayList
checks for duplicates (move+appearance) and only saves unique pointers.
3) The main processing loop calls Behavior.postId() (synchronized so
that vehicle movement updates should be complete).
4) The main processing loop sleeps (to control the simulation speed).

5) The Behavior saves the (synchronized) ArrayList to an array and
clears the ArrayList.
6) The Behavior iterates through the array and calls the vehicles.
7) Each Vehicle updates it's Text3D, Material and TransformGroup with
any new label, color or location.
8) repeat as needed.

This works fine for all of my maps except the largest (44 intersections,
33 one-way streets, lots of cars). Cars vanish, re-appear and show up in
the wrong places. Showing up in the wrong place seems like a data
problem, but vanishing and re-appearing seem like scene graph update

I've tried returning a boolean from the vehicle method so that the
processStimulus() would wait until each method finished before calling
the next and thereby delaying the final wakeupOn() method call.

I've tried various forms of synchronization to make sure that I'm not
stepping on the location data during the TransformGroup update.

I've tried slowing the main processing loop down until the updates only
occur once a second, which should eliminate the possibility of a
processStimulus() invocation stepping on the previous one, but the
problem persists.

In the olden days I had a Behavior for every vehicle and didn't have
this problem (I had memory problems instead). I'm thinking of creating a
Behavior for every street fragment as a compromise solution.

(a city has N streets,
a street has N street fragments,
a street fragment has N vehicles)