Re: MVC Pattern or antipattern?




"Daniel Pitts" <googlegroupie@xxxxxxxxxxxxx> wrote in message
news:1161643137.322074.227760@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I have a domain model which is a simulation. I want to display the
state of the simulation at any given time, basically animated.

Since the Swing threading model requires all GUI work to be done on the
EventDispatcher thread, and all other long-running work to be done on
some other thread, I have a delima.

It might take some time to render a single "frame" (snapshot of the
domain model), and its desirable that rending doesn't interfere too
much with the simulation (not a strict requirement). Similarly,
updating the domain could take some time, and is not in any way atomic.
I'm trying to decide one the best approach to this problem...

I can think of three approaches:
A: Atomize the simulation thread. Make the simulation "pause" when the
painting starts.
B: Inline the simulation thread. Make the "updateSimulation" occure in
the event dispatcher thread.
C: Create a seperate immutable model that is a snapshot of the
simulation at reasonable time boundries, and pass this to the rendering
code through the event dispatchers.

I think solution C is the best solution, but I think there would be a
lot of overhead, as every simulation "snapshot" might not be used, and
isn't necessarily cheap to create. I'm sure I could work around this,
but if there is a better approach, I'd like to know about it before I
continue.

How about C, but instead of the simulation creating a snapshot at
regular intervals, the View requests a snapshot, and the simulation will
respond to it at the next convenient point in time? I'm assuming the
simulation is running in a seperate thread from the whatever powers the
view. I'm also assuming that it's more important for the simulation to run
undisturb than it is to get nice smooth framerates for your animation.

If this solution isn't acceptable, you should probably mention what kind
of time scales you're talking about. The solution is obviously different if
your simulation's time boundries occur once every 2 hours, and rendering
takes 3 minutes, versus your simulation's time boundries occur every 50
milliseconds, and rendering takes 1 second.


Question part 2:
My model really would know how to represent itself in the view, so
might it be useful to have my business objects implement a paint()
method (or the equivelent).

Wouldn't this defeat the whole purpose of using MVC? The idea is to
isolate the view from the model so that you can very the view. If you know
you're never going to vary the view, there isn't much to gain from using
MVC.

- Oliver


.



Relevant Pages

  • Re: MVC Pattern or antipattern?
    ... state of the simulation at any given time, ... It might take some time to render a single "frame" (snapshot of the ... undisturb than it is to get nice smooth framerates for your animation. ... Wouldn't this defeat the whole purpose of using MVC? ...
    (comp.lang.java.gui)
  • Re: is there a user mode way to flush disk cache
    ... > snapshot is consistent. ... If the pause time is on the order of 5 ... this eats into the time before the simulation ... disk, and even if it took 5 minutes, it wouldn't hold up the main ...
    (comp.os.linux.development.system)
  • save snapshot in simvision... cant view waveform in wavescan
    ... I am running a simulation that takes about a week to finish. ... debugger mode, so simvision popped up. ... results past the point where I saved the snapshot. ... I will only load ...
    (comp.cad.cadence)
  • Re: How to speed up a simple paintComponent()
    ... > instance) since it is the display of some type of discrete simulations, ... Assuming that youv'e already taken obvious steps like only updating cells that ... is needed by one step of the simulation, verses that needed by updating the ... ask for the latest "snapshot" about once a second, ...
    (comp.lang.java.programmer)
  • Re: Nvidia says Intels Larrabee is a reaction to CUDA
    ... especially rendering) is embarassingly parallel, ... forseeable future. ... more simulation is also easy to see. ...
    (comp.arch)