[squeak-dev] #saveOnFile won't do

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

[squeak-dev] #saveOnFile won't do

Aidan Gauland
Hello,

  I'm working on a game engine, and I found the #saveOnFile method in the
Object class, which I can use for saving the game state, but I also want to do
exactly the same thing for storing the initial game state (loaded when the
user starts a new game) with one exception: instead of writing to a file, I
want to store it internally (in the image).  I can't set up the game
programatically, because I use the Object Explorer for building the game
(which works very well for this purpose, I might add; you don't get that with
other programming languages).

  Is there a way I can do this?

Thanks,
Aidan

P.S.  Please let me know if I should have asked this on the newbies list; I've
only been posting there, until now.


Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] #saveOnFile won't do

Tapple Gao
On Fri, Dec 12, 2008 at 02:16:13PM +1300, Aidan Gauland wrote:

> Hello,
>
>   I'm working on a game engine, and I found the #saveOnFile method in the
> Object class, which I can use for saving the game state, but I also want to do
> exactly the same thing for storing the initial game state (loaded when the
> user starts a new game) with one exception: instead of writing to a file, I
> want to store it internally (in the image).  I can't set up the game
> programatically, because I use the Object Explorer for building the game
> (which works very well for this purpose, I might add; you don't get that with
> other programming languages).
>
>   Is there a way I can do this?

If you look at the implementation of saveOnFile:, most of the
work is done by ReadWriteStream >> fileOutClass:andObject:

so, you can use that method to write your object out to a
memory-backed ReadWriteStream rather than a disk-backed
FileStream. This will give you a ByteArray of the object, which
you can store as a class variable of your game or something.

If you go a little deeper, you will discover SmartRefStream,
which is the serializer responsible for this feature.


Other solutions:

you could create your game state, then send it the message #copy
to get another copy of the game state. You may have to customize
what copy does when sent to your game state instances, though.

you could just write out the initial game state to a file and
not worry about it.


If you want to distribute your game as a .mcz, you may want to
check out a brand new feature of monticello 1.5: the ability to
save resource files (like initial game state) inside .mcz
packages.

Or, you can just distribute the image with its initial state
inside, or in a bundled file

--
Matthew Fulmer -- http://mtfulmer.wordpress.com/

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] #saveOnFile won't do

Aidan Gauland
Matthew Fulmer wrote:

> If you look at the implementation of saveOnFile:, most of the
> work is done by ReadWriteStream >> fileOutClass:andObject:
>
> so, you can use that method to write your object out to a
> memory-backed ReadWriteStream rather than a disk-backed
> FileStream. This will give you a ByteArray of the object, which
> you can store as a class variable of your game or something.
>
> If you go a little deeper, you will discover SmartRefStream,
> which is the serializer responsible for this feature.

Ah ha!  SmartRefStream is what I want.  I saw that when I was poking around,
but I couldn't tell if that would just give me trouble if I tried to use it
for this.

Thanks,
Aidan

Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] #saveOnFile won't do

Rob Rothwell
You could also try SandstoneDb if you are creating instances of your objects and just want to save those instances to disk and have them automatically loaded when the image starts up...

Take care,

Rob

On Sat, Dec 13, 2008 at 10:42 PM, Aidan Gauland <[hidden email]> wrote:
Matthew Fulmer wrote:
If you look at the implementation of saveOnFile:, most of the
work is done by ReadWriteStream >> fileOutClass:andObject:

so, you can use that method to write your object out to a
memory-backed ReadWriteStream rather than a disk-backed
FileStream. This will give you a ByteArray of the object, which
you can store as a class variable of your game or something.

If you go a little deeper, you will discover SmartRefStream,
which is the serializer responsible for this feature.

Ah ha!  SmartRefStream is what I want.  I saw that when I was poking around, but I couldn't tell if that would just give me trouble if I tried to use it for this.

Thanks,
Aidan




Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] #saveOnFile won't do [SOLVED]

Aidan Gauland
In reply to this post by Aidan Gauland
Use SmartRefStream class>>streamedRepresentationOf: anObject.

Thanks for the help,
Aidan

Aidan Gauland wrote:

>  I'm working on a game engine, and I found the #saveOnFile method in the
> Object class, which I can use for saving the game state, but I also want
> to do exactly the same thing for storing the initial game state (loaded
> when the user starts a new game) with one exception: instead of writing
> to a file, I want to store it internally (in the image).  I can't set up
> the game programatically, because I use the Object Explorer for building
> the game (which works very well for this purpose, I might add; you don't
> get that with other programming languages).
>
>  Is there a way I can do this?