-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sprite Color Replacement #14
Comments
If we use the table based approach to draw sprites (where the output of the pixel is pre-calculated), we could have several tables, so that colors can be changed... It would cost 256 bytes per color-schema, so depending on the number of sprites, it might be too much. Other way to do so might be to restrict the sprite to a given number of colors, so that the look up table becomes significantly smaller. |
What I would do would be define swap color tables. For example if I want to change 3 colors of a sprite, pass an array of 6 chars indicating each color and its replacement to the function to draw sprites. I don't know it this may lead to a slow implementation, but from the user point of view (me :) ) that would be very easy and intuitive to use. |
I think your feature request is clear. In fact, something similar was already on the TODO list for CPCtelera. AugustoRuiz is pointing to possible implementations, as replacing pixels of a sprite while drawing is very very slow unless some programming tricks are used (just look at the difference betweeen drawing ROM characters and drawing sprites. It's really huge). In fact, this is a feature quite difficult to generalize. I think we should think of several cost/effective approaches and let the user select the most appropriate for each concrete project. We will require some time to think of it and come with some prototypes for testing. |
I leave the implementation to experts. If I knew how to implement this efficiently I would have created a pull request, not an issue. :) Thank you. |
Created new branch named |
This issue is currently under development in the |
Hi, |
Hi @Arnaud6128, Last time I look at your routines they were working well, and I stopped in the middle of reviewing them along with their documentation. I think your routines are great and they should be added to development branch. Maybe, it would be more interesting if all contributors have a chance to look at them and see if they can improve them, fix any typo or things like that. I will have a diagonal look again at all of them and proceed to merge with the development branch for other contributors to have the oportunity to look at them :) Thanks for all your contributions, @Arnaud6128, and please, excuse me for taking so long to answer and review your latest contributions. Cheers! |
Hi @Arnaud6128 and others: After some thoughts I've finally found a way to perform the pixel-colour-replacement operation using only bit operations, effectively parallelizing it 4-by-4-pixels in Mode 1. Last time I tried it I was unable to find a way, but I somehow knew it should be possible. I have not tried this tecnique on Mode 0 pixels yet, but I assume it can be easily translated. This can make colour replacement much much faster and simpler, which will make it more usable in actual games. At the end of this post you can finde a little concept demo you can analyze to better get the idea. Just paste it into a freshly new ASM CPCtelera project replacing main.s. I think it would be really nice to convert all functions to this technique to get better performance and less memory footprint. Hope you enjoy this idea and we can have great Colourizing functions in CPCtelera soon :). @Arnaud6128, thanks very much for all your work. You founded the basis for this functionality and deserve much of the credit. It was your original code which suggested me this possiblity. Thanks mate :)
|
I have performed some tests replacing the code in cpct_spriteColourizeM1.asm with this proposal and these are the resulting measures:
I have also created 2 new functions I am now cleaning up the changes and I will upload them shortly. I will need help to propagate this changes to the other Mode 1 functions. Who is available for help? |
Hi, @Arnaud6128 Doing only 2 RRCAs is not enough for the algorithm to perform the same operation. That part of the algoritms what does is to mix all the bits of a single pixel into 0 (if all of them are 0) or 1 (if at least one of them is one) to create a mask. Therefore, as mode 0 has 4 bits, it is not enough mixing 2 pairs of 2 bits. I haven't analyzed it properly, but the first valid sequence I can thing of is this one:
It probably might be improved by rethinking it. Additionally, dt_mode0_ct might not be appropriate as conversion table. Need to check it previously. I'll try to upload the first complete version of spriteColourizeM1 ASAP so that we can extend it to the other M1 functions. I will probably think of merging the branch with development and we can then continue there. It might be a good time to rethink CPCtelera branches to simplify contribution workflow. I think it is too slow if contributions are big and have to wait for me to review. It might be a good time to decide on some foundational principles, and roadmap to produce a more open contribution model :) Thank you very much, @Arnaud6128 :) Cheers! |
Hi, @lronaldo I will wait for your function spriteColourizeM1 to use it to the other M1 functions. I will do the same for M0 functions, i am losing time to debug potentialy obsolete M0 functions. And yes a roadmap will be really useful to know what will be done and when (and have a version release date ?) |
Hi all again (@Arnaud6128 @AugustoRuiz @AmstradGamer),
Right now, only the functions cpct_spriteColourizeM1 and cpct_spriteMaskedColourizeM1 contain the most recent code, with the latest optimization proposed 4 days ago. However, both of them have been fully developed, commented, tested and documented. Both of them are production-ready, as far as i can tell. Now, we need to propagate these changes to the other M1 Colourize functions and fix the M0 version. With respect to the M0 version that @Arnaud6128 has been testing, the only problem that remains in the last example is that the dc_mode0_ct table is not valid for the purposes of this function. That table holds bytes representing 1 pixel coloured and the other zeroed, but required values should have both pixels coloured with same colour. That's the reason for the resulting sprites being stripped: only 1 out of each 2 pixels is changed. That's easy to solve :) Therefore, I propose continuing developing this functions againts development branch to leave all of them production ready. I suggest doing individual Pull Requests for each function: that will be easier to review and merge. Of course, I mean a PR per function, not per file. Changing one function usually affects several files :). After solving current PRs we can then define a roadmap to finally publish 1.5 as stable version. Then we will be able to proceed setting up the new organization for CPCtelera to continue evolving :). Thanks you all :) |
Thanks for doing this and sorry for not being able to help right now. |
No worries, @ToniRamirezM :). I'm the first one who has been out for months. Whenever you can, be it tomorrow or next year, it would be nice if you can test the functions. No hurries at all, just enjoy ;). |
All functions colourize converted and example updated to test all functions. Waiting for review on M0 functions to work on cpct_drawSpriteColorizeXXXM1. |
All draw sprite colourize for M1 are coded / tested and here a small example to test it. Now all functions for colourize sprites M0 and M1 are coded and are waiting to be merged. |
Tested M0 functions and they work as expected. Good work! @Arnaud6128 |
It would be very useful to have a function to draw sprites beeing able to change colors on them.
For example for beeing able to have differente enemy sprites that only differ on color, so we only need one sprite in memory.
The text was updated successfully, but these errors were encountered: