Print

Print


I've been working on saving and loading (checkpointing) a mason model.
Because of some weird objects I am using I can't use MASON serialization.
Not a big deal actually, and as long as I don't use the GUI I have no
problem saving to file, reading it and stepping.

However now I have this problem: I have a simple SimState I just finished
reading from file. How do I feed it to GUIState?
I can feed it a new state no problem:

        FishGUI vid = new FishGUI(new FishState());
        Console c = new Console(vid);
        c.setVisible(true);

But if I feed it something I read from file (or anything that has already
started) then the console still tries to start the state like it's new
(which I don't want as the model has already started and ran for a while):

        FishState state = Utilities.resumeFromFile("test.xml")
        FishGUI vid = new FishGUI(state);
        Console c = new Console(vid);
        c.setVisible(true);

Interestingly if I force it to load like this:

        FishState state = Utilities.resumeFromFile("test.xml")
        FishGUI vid = new FishGUI(state);
        Console c = ((Console) vid.createController());
        vid.load(state); //forcing
        c.setVisible(true);
        Thread.sleep(40000);

then the gui gets setup correctly (including functioning inspectors) but
the console is still wrong (and will still try to start the state object
when play is pressed). Also I need to sleep the caller thread as the GUI
thread doesn't keep the simulation open (hence the sleep call).

The only way to get the console to work so far has been to overwrite
the readNewStateFromCheckpoint(File file) on my FishGUI and call the
Console doOpen() in the main function but that creates a host of other
problems (I can't touch the SimState the way I want it before passing it to
the GUI, I need to change the file extension to .checkpoint, I still need
to call Thread.Sleep() to keep the gui running and so on).

Is there a better way to pass a pre-made SimState to GUIState?