<i>In order to pass surfaces around, I need to be able to serialize them (as only scalars can be in shared variables).</i>
Been a while since I've Perl'd, but doesn't it make more sense to pass a reference around? or to have an imagemanager that your threads can query?
sorry but I didn't read your entire email. Just kinda skimmed through.
you're making a surface, then you're copying it's innards to a variable, then you're copying it onto another surface. That's 3 times the bloat you probably don't need if you can work out an imageManager system.
but again, I haven't Perl'd in a while, and I've never messed with multithreading in Perl, so feel free to correct me or tell me to stfu :)
If you don't know what I mean by image manager:
an image manager is a class(or what not) with methods for loading and returning images. So that all you need to do is pass the image manager an ID or file name. If it's not loaded, the image manager loads it and returns the reference, or, if it's already loaded, it just returns the reference. It's faster and takes less memory.
but, i'll stfu now. :P
I want to be able to save a surface to a scalar, and then recreate it. it seems like this should work, but it doesn't:
my $surf = new SDL::Surface( ... ); my $buffer = $surf->pixels(); my $newsurf = new SDL::Surface(-from=>$buffer, ... );
Where the ... are the same options for both calls to new for height and width and depth. If I blit $newsurf and $surf to my application surface, newsurf is screwed up. Calling display_format doesn't seem to do it.
Is there some other way I can serialize an SDL::Surface and later recreate it?
Also, it appears there might be a memory leak related to the use of -from, or this might be causing this problem, but I'm not sure because I'm not that familiar with the perl GC. Calling ->pixels returns a newly created scalar filled with the pixels data. Invoking new with -from just uses the scalar passed as the buffer ($src, first argument to SDL_CreateRGBSurfaceFrom. If the value passed for -from then goes out of scope in the caller and is then GC'ed, SDL_Surface->pixels points to free'd memory. I was going to experiment with creating a new buffer and copying the data in the scaler to it and passing that as the first argument to SDL_CreateRGBSurfaceFrom, but then I'll need a flag to signify that ->pixels should be free'd in FreeSurface (as the documentation for SDL_FreeSurface says that memory that ->pixels points to isn't freed if the surface was created with SDL_CreateRGBSurfaceFrom), and I'm not sure where to put this flag (as the value blessed as SDL::Surface is solely a scalar, pointing to the SDL_Surface structure).
Also, it would be pretty cool to have a function that returns an opaque scalar value containing the attributes of a surface so that surface attributes can be copied between surfaces created from buffers of pixel data (alternatively, a surface serializer might include that information). That is:
$surface->display_format()
might be shorthand for:
my $surfattr = $app->attributes_and_flags(); $surface->set_attributes_and_flags($surfattr);
(although better names are in order). Although this would be secondary to a surface serializer who's output can be used as input to recreate the surface, as that seems like a more useful interface.
FYI, one thing I'm trying to do here is write a multi-threaded program that has a number of worker threads update different small surfaces and have a single thread (which has control of the SDL::App object) that then blits all the smaller surfaces to the application window. In order to pass surfaces around, I need to be able to serialize them (as only scalars can be in shared variables). I also want to be able to store serialized surfaces, with all internal attributes/flags and such, in files (without having to write out a BITMAP and re-setup all the flags when I read it in) for reload later (and possibly generate some of those surfaces in other processes) and for temporary storage on disk or to be received via file descriptors.
_________________________________________________________________
MSN 9 Dial-up Internet Access fights spam and pop-ups � now 3 months FREE! http://join.msn.click-url.com/go/onm00200361ave/direct/01/
