Commit graph

388 commits

Author SHA1 Message Date
Gered 148a24ca42 implement png saving
note that we only allow RgbaBitmaps to save RGBA colour format pngs.
likewise, IndexedBitmaps can only save indexed-colour format pngs.
2023-03-20 21:47:02 -04:00
Gered ac4df9e8ed merge functionality of PixelDecoder and ScanlineBuffer together 2023-03-20 17:47:18 -04:00
Gered 48c694192b maybe improve png decoding, sorta, kinda, i guess? 2023-03-20 17:14:38 -04:00
Gered d02b81b1fb extra tests for other unsupported png scenarios 2023-03-20 12:06:10 -04:00
Gered 76d0289a0f add png loading tests 2023-03-20 12:02:55 -04:00
Gered 6e09c84c4a implement working filter-aware png scanline decoding
this is all gross at the moment, but it works. which is the goal right
now.
2023-03-19 22:55:46 -04:00
Gered eb5869b600 initial and semi-incomplete png loading support
- no filters other than filter 0 right now
- no png file saving
- inefficiencies
- maybe some bugs, not a full test suite yet
2023-03-16 21:20:43 -04:00
Gered 6de4bf3ef0 add temporary (and wasteful) methods to load gif/iff/pcx to RgbaBitmaps
temporary measure until i feel like making the existing loading process
for all of these able to handle variable pixel bit-depth destinations.
not super high on my priority list so this may not happen for a while.
2023-03-13 13:03:55 -04:00
Gered bc59442311 add method to convert an IndexedBitmap to an RgbaBitmap
doing the reverse is a fair bit more complicated, so we'll leave that
alone for now!
2023-03-13 13:02:21 -04:00
Gered 99de921f64 fix solid_blit pointer stuff
i did not read the doc comments for pointer methods and mistakenly
thought i needed to calculate raw byte offsets here, but actually it
works in units of size T (where T in our case is either u8 or u32)
2023-03-11 21:14:01 -05:00
Gered 2cf763bb73 add Standard implementation of SystemResources
this uses 32-bit colour graphics via RgbaBitmap
2023-03-11 21:03:57 -05:00
Gered 503f822a87 make Bitmap::new private to force creation via concrete aliased types 2023-03-11 17:24:53 -05:00
Gered c1dcc39bc1 set up visual comparison graphics tests for indexed+rgb versions
the rgb versions are not yet present, however
2023-03-11 17:15:53 -05:00
Gered 07f2b13f68 large amount of bitmap graphics rework
this is an unfortunately large commit. probably should've been broken
up into multiple smaller ones.

i decided to revert some earlier preparatory work i had done to organize
graphics functionality into two main streams: "indexed" and "rgb". this
was going to result in two completely different Bitmap structs which
were going to be largely similar and as i thought about it more, i
realized my earlier thinking that i wouldn't be able to generify the
Bitmap struct based on pixel-depth was actually not correct.

so, this commit re-works things significantly in a way which i think
is better but probably still not perfect. basically, we have one
Bitmap struct which provides a lot of generic functionality, but also
specialized implementations based on pixel-depth and this is now what is
separated out into graphics::bitmap::indexed and graphics::bitmap::rgb.

but the rest of the graphics functionality is not separated out by
module like this any longer.

note that i've still kept the GeneralBitmap trait and implementations.
i was originally thinking i could get rid of this since i'd now made
Bitmap generic over pixel-depth, but doing so would require me to
rename the common/general blit methods to avoid a name collision with
the specialized implementations (since they would both exist on the
same types now). and i did not like that. i dunno, maybe i will change
my mind later.
2023-03-11 16:58:13 -05:00
Gered 2b414072bc move RGB/RGBA colour related functions into common module
these are obviously useful to new 32-bit graphics functionality, but
they are also useful to indexed colour functionality such as palettes
and blendmaps.
2023-03-10 11:11:04 -05:00
Gered 06f055c042 fix compiler warning 2023-03-09 19:10:31 -05:00
Gered 2e57311fe0 try to clean up module 'use' stuff with new prelude modules
though i am not sure how good an idea my approach was with a bunch of
intermediate preludes. i was thinking it might be nice to be able to
only pick out the preludes that you wanted (if not all), but ... would
i ever really need to do that? somehow i am thinking, no, but i will
give it some more thought
2023-03-09 19:10:11 -05:00
Gered 75401cb5c7 move repeated 'PixelType' type constraints to new Pixel trait 2023-03-09 16:32:46 -05:00
Gered 986a2a9677 make fonts generic over GeneralBitmap types
this also includes a semi-important change where the existing
BitmaskCharacter draw implementation will now not draw anything if
FontRenderOpts::None is passed in, instead of just substituting color 0.

this probably makes more sense this way anyway
2023-03-09 16:20:44 -05:00
Gered 434bd6dbed maybe, sortof, clean up CustomMouseCursor and DefaultMouseCursorBitmaps
i like this a bit more, but this still feels a bit icky to me ... sortof
2023-03-09 15:14:38 -05:00
Gered f3d213130d revert hackfix in GeneralBlitMethod. fix CustomMouseCursor rendering
at this point i am 99% certain that the previous issues i was having
with making GeneralBlitMethod generic over the bitmap PixelType was
because i was trying to specify a constant PixelType value in generic
code (CustomMouseCursor).

whether this was actually the problem or not i think is besides the
point however because while thinking about this i suddenly realized this
was incorrect anyway!

making CustomMouseCursor generic via GeneralBitmap means that specifying
constant colours was not going to produce expected results (e.g. '255'
has a very different meaning for indexed colour rendering versus for
32-bit RGBA colour format).

so, CustomMouseCursor now figures out the correct transparent colour
to use from the DefaultMouseCursorBitmaps implementation.

this allows us to make GeneralBlitMethod be generic over a bitmap's
PixelType again and i'm sure we won't have that previous issue again as
long as we don't try to specify constant colour values in our generic
rendering code ... which we should never be doing anyway!
2023-03-09 14:51:01 -05:00
Gered 696ed0bfb3 rename "BasicImage" to "GeneralBitmap"
this feels like a much, much, much better name to me. not sure what i
was thinking before!
2023-03-09 11:57:07 -05:00
Gered 2c2cf9dacd remove now unnecessary 'todo' comment 2023-03-08 21:11:12 -05:00
Gered 09ac68df66 add placeholder 'rgb' module 2023-03-08 21:08:05 -05:00
Gered f0095cf1dc make CustomMouseCursor generic over BasicImage types
this contains an unfortunate hacky change to the BasicBlitMethod enum
which used to be generic over a PixelType (same as BasicImage is
currently). i really do not like this, but i could not find any
solution to the problem.

admittedly it's not the worst hack solution in the world, but it does
technically allow calling code to pass colour values that are outside
the supported range which may lead to odd results at runtime.
2023-03-08 21:04:03 -05:00
Gered 3e8ec9f73e make BitmapAtlas generic for its type of bitmap 2023-03-08 17:23:49 -05:00
Gered bcb21bc2ba switch BasicImage to use an associated type for the pixel type
this ends up with less repetition when using BasicImage elsewhere
which is nice
2023-03-08 17:22:02 -05:00
Gered 144d4c395b add BasicImage 2023-03-08 17:04:22 -05:00
Gered aab19ba6b3 moved indexed (256 colour) graphics stuff into new "indexed" module
in preparation for adding 32-bit graphics stuff, i want to keep things
separate using modules
2023-03-08 14:16:54 -05:00
Gered 7896146914 add doc-comments 2023-03-07 22:41:21 -05:00
Gered d437755a9f important todo comment 2023-03-07 22:34:46 -05:00
Gered 28d1b7230e move custom mouse cursor functionality to separate struct
this is to not have the main Mouse struct be tied to our indexed-colour
Bitmap graphics implementation (i'm not currently ready to try to
generify this either ...)
2023-03-07 22:33:10 -05:00
Gered 888b5057e4 add doc-comments 2023-03-07 21:57:04 -05:00
Gered 9e06a13c6d move vsync and target_framerate options back into System
since i realized there is an SDL hint that can be used to toggle this

the reason why the rust-sdl "Canvas" struct (which abstracts an
"SDL_Renderer") is not being created in System directly (which would
allow vsync to be toggled on/off via System directly without the use of
a hint) is because not all future SystemResource implementations will
need it (e.g. a future OpenGL implementation definitely won't).
2023-03-07 17:33:42 -05:00
Gered 29628bf680 remove now unused InputDevice struct
SystemResources implementations have now kind of taken that role ...
i suppose. maybe i'll think differently in the future?
2023-03-07 16:52:09 -05:00
Gered f1c04d85e3 move video, audio and input to new SystemResources trait/structs
System now uses a generic SystemResources structure to provide video,
audio and input devices

the DosLike implementation of SystemResources provides the same
functionality that this library has had to date.

this change is to prepare for future addition of things like 32-bit
Bitmap support and other possible audio device implementations, etc.
the idea is a custom SystemResources implementation can be substituted
in to configure everything with the desired functionality.
2023-03-07 16:46:16 -05:00
Gered 43b2c9df7c minor cleanup 2023-03-07 11:39:04 -05:00
Gered 57eb364654 collapse some SystemError types into SDLError
i didn't really think i was gaining anything from the separate error
types because in basically every case these were being used to just
capture and return an underlying SDL error
2023-03-07 11:38:55 -05:00
Gered 58340c03fe rename from libretrogd to ggdt
i'll admit i never totally liked the name "libretrogd"
2023-03-02 16:11:59 -05:00
Gered eb6a363afd formatting
note that i'm intentionally not using rustfmt. i've tried to like that
tool, but in the end i just really don't like it. too many edge cases
and subjectivity and not enough customization. which is probably the
intent. which makes me hate it that much more. fuck you, rustfmt.
2023-03-02 15:10:27 -05:00
Gered 43333687a8 add audio queue playing into the base main_loop wrapper 2023-02-27 15:14:30 -05:00
Gered a6f2d43009 add convenience method for playing the system audio queue 2023-02-27 15:12:07 -05:00
Gered 624ca95a97 add no_run attribute to doc comments with an infinite main loop example 2023-02-27 14:55:50 -05:00
Gered f2f7ae5dee update examples with new input device and main loop event handling stuff 2023-02-27 14:51:55 -05:00
Gered 3dfb8fe466 improve event polling / processing
- the new InputDevices struct is added to simplify input device
  updating and event processing of input events for all input devices
  now available, as well as future proofing for new ones (e.g. gamepad).
  this also helps us out with implementing better ways of doing custom
  application main loop SystemEvent handling ...
- System::do_events_with has been removed. if custom event handling
  is needed by applications, they should now implement this themselves,
  as demonstrated by the example in the doc comment for
  System::do_events.
-
2023-02-27 14:38:51 -05:00
Gered 9cb333454a add SystemEventPump to wrap the sdl2 event pump struct 2023-02-19 18:04:00 -05:00
Gered addd92c1f2 not exactly sure what happened here
i did actually successfully compile and build the previous commit ... ?
2023-02-19 17:15:34 -05:00
Gered f6ca6f150a fix wording on method usage comment
kind of an important difference in intended usage!
2023-02-19 16:20:19 -05:00
Gered 4e43e9fbdd remove possibly error returns from sdl2 Event -> SystemEvent conversion
we just use a catch-all "Unimplemented" enum for the sdl2 event types we
have not mapped / don't care about yet.

this change is mainly just so that we don't need to use TryFrom anymore
as this simplifies making our own SystemEvent iterator

as well, it felt wrong to return an error (even if silently ignored)
whenever an unmapped sdl2 event was raised (since that could happen
fairly often)
2023-02-19 16:17:11 -05:00
Gered adbc0029f4 implement base core/support traits for slimed project
for it's main app context structs
2023-02-19 15:30:35 -05:00