Can I modify Dynamic Sprites directly?

Started by Scavenger, Mon 27/04/2009 16:06:24

Previous topic - Next topic

Scavenger

Looking at the AGS documentation, it seems that dynamic sprites are stored in pointers, so potentially I thought, I might be able to address the data within the dynamic sprite directly, rather than using GetPixel and PutPixel to change the colours within the sprite, and thus speeding up the process tenfold.

So, can I access the data within Dynamic Sprites directly? And how are they structured, so that I don't accidentally overwrite their width/height entries?


((Just to give it some context, the effect I want to achieve initially is that of the Discworld inventory window - replacing the palette underneath the GUI with a small range of colours. To do this, a lookup table is needed, with the palette entries you want to change corresponding to the colour you want to change it to. Example:

Palette entries 250-255 are the range of blues we are using. The array Palettechange has 256 entries, with the alternate palette as the values of these variables (with 0 still being 0 - we don't want to remove the transparency from the sprites just in case).

Now, each time we create a dynamic sprite out of the screenshot, we process it (cropping it as necessary - though it seems it would be a bad idea to use this with Direct3D). If this was a raw image file that stored the data without width + height values before the main bulk of the image, the changing of the data would be just writing each byte as it's presented in memory back with the contents of the lookup table and just keep cycling that call until we reach the end of the array (which is width * height in bytes).

You should find that it turns into something like this:



How fast that would be I have no idea, especially in scrolling rooms. If there was a way to access the framebuffer directly to steal portions of it, it might be a little faster, but more complicated. I dread to think how much processing time it would actually take, even in a 320x240 8bit game.

Successfully pulling this off would open the doorway for other eye candy special effects such as translucency, tinting, and screening in an 8bit game. Simple transparency (50%) would just be comparing in a 2D array of two values (the background colour index and the index of the overlay). Now, I know that hi colour games can do this without all the technical workarounds and fancy coding, and in fact would be a lot easier. But I think the 8 bit colour depth is underutilised, and I just love working with it. The colour artifacts alone are worth it. That, and my game is set in a retrofuturistic early 90s, so it has to look the part.))

monkey0506

#1
You can use the DrawingSurface functions to access the raw surface of the DynamicSprite.

As far as tinting a specific section of the screen like you're doing in the screenshot, you could create a DynamicSprite of the specific size you need (DynamicSprite.Create(width, height)), then use the DrawingSurface of that sprite to fill the sprite with blue (DrawingSurface.Clear(blue color #)), release the DrawingSurface for that sprite, then you could use the DrawingSurface functions to transparently draw that sprite onto the screen image (to do this you could take the screenshot and then get the surface for that sprite).

Edit: I just realized you're using 8-bit so the transparency wouldn't work obviously. That does make things more complicated and AFAIK there's not really a good way for you to be able to do this without having to draw each pixel...

Scavenger

Quote from: monkey_05_06 on Mon 27/04/2009 16:46:37
Edit: I just realized you're using 8-bit so the transparency wouldn't work obviously. That does make things more complicated and AFAIK there's not really a good way for you to be able to do this without having to draw each pixel...

Which is why I want to do this by reducing the data I need to handle down to the raw values in memory - I'm thinking changing a value in memory from X to Y directly is exponentially faster than using GetPixel/PutPixel.

monkey0506

So if I understand what you're wanting to do, you're basically wanting to modify the palette associated with the cropped screenshot without effecting the palette of everything else...right?

Scavenger

Quote from: monkey_05_06 on Mon 27/04/2009 17:06:07
So if I understand what you're wanting to do, you're basically wanting to modify the palette associated with the cropped screenshot without effecting the palette of everything else...right?

Kind of. I want to modify the image inside the dynamic sprite so that the indexes inside that sprite point to a different part of the main palette. I'm not touching the palette itself, but what part of the palette is used for the image in the dynamic sprite. By changing the values inside the memory directly, it avoids the problem of using the slower pixel-only commands. (What it's doing, effectively, is changing the value of each variable in an array from 0-249 to values 250-255 without any other calculation. I just need to know whether Dynamic Sprites can be accessed like normal arrays.)

Pumaman

No, you cannot currently do this.

This sort of thing is easily possible from plugins, but to write a plugin you would need to know C++.

SMF spam blocked by CleanTalk