Commit graph

61 commits

Author SHA1 Message Date
Andrei Alexeyev
8b37d1cbf2
src: the great #include massacre of 2024 2024-05-17 14:11:48 +02:00
Andrei Alexeyev
be7905d6a3
src: run upkeep 2024-05-17 04:58:47 +02:00
Andrei Alexeyev
d03b2eb38c
video: add "framedump" mode; use async readback for screenshots;
The framedump mode captures every frame and saves it as a .png image.
This can be useful for rendering videos.

To activate, set the `TAISEI_FRAMEDUMP` environment variable to a
prefix. A 8-digit frame number followed by ".png" will be appended to
this string to form the filename of each frame.

Example:
	$ mkdir /var/tmp/taisei
	$ export TAISEI_FRAMEDUMP="/var/tmp/taisei/frame-"
	$ taisei -f1 -r /foo/some-replay.tsr
	$ ls /var/tmp/taisei
	frame-00000000.png  frame-00000001.png frame-00000002.png
	...

`TAISEI_FRAMEDUMP_SOURCE` can be set to either "screen" or "viewport".
The default is "screen", which records the whole game screen as it
appears (minus the letterboxing borders). "viewport" makes it record the
stage viewport only. The image is taken directly from the viewport
framebuffer, so elements that are drawn over the viewport will be
missing, such as the dialogue or the pause menu.

`TAISEI_FRAMEDUMP_COMPRESSION` can be set to change the quality of zlib
compression of the png images, ranging from 0 to 9. The default is 1.

Additionally, it's now possible to take screenshots of the game viewport
by pressing Alt+P (by default). This works on the same principle as
`TAISEI_FRAMEDUMP_SOURCE=viewport`, so the same caveats apply. This can
be used to take a clean screenshot of the viewport while the game is
paused.
2024-04-29 01:15:15 +02:00
Andrei Alexeyev
2e6e890e34
events: fix possible use-after-free
Can happen when a global handler is added during events_poll() if the
array must be resized.
2024-04-27 15:04:06 +02:00
Andrei Alexeyev
c15934f666
dynarray: get rid of memset and add optional initializer arg to dynarray_append 2023-09-28 17:43:14 +02:00
Andrei Alexeyev
91528ae8f4
menu/options: don't instantly disable gamepad when option is switched off 2023-06-20 01:13:50 +02:00
Andrei Alexeyev
ad295005db
resource: more consistent API function names 2023-04-29 20:01:50 +02:00
Andrei Alexeyev
f0deb86937
events: fix events_unregister_handler()
It's still a stupid API, but at least it's possible to remove multiple
handlers that have the same callback address reliably.
2023-04-07 16:08:49 +02:00
Andrei Alexeyev
d3d363e8cb
events: assert events initialized in events_register_handler 2022-01-27 09:03:03 +02:00
Andrei Alexeyev
b39c9ba78e
resource: partial support for resource reloading 2022-01-02 08:28:02 +02:00
Andrei Alexeyev
d126eba2d2
events: reduce processing overhead
This is mostly aimed at speeding up TAISEI_SKIP_TO_BOOKMARK mode

- Store global handlers in a dynamic array
- Merge global and local handlers more efficiently, and only do it once
  per events_poll() call
- Do not pump SDL events while skipping through stages
- Avoid expensive system call when pushing custom events to the queue
- Process SDL events in batches; do not pump after every event
- Simplify handling of EventPriority enum - EPRIO_DEFAULT equals to 0,
  no remapping required
2021-05-06 12:41:40 +03:00
Andrei Alexeyev
ae8194ae78
Various fixes & improvements for concurrent loading (#235)
- RESF_UNSAFE is removed.
- Resources that don't have to be finalized on the main thread can load
completely asynchronously.
- A thread waiting for a concurrent task to complete can start executing
that task itself if it hasn't started yet.
- Refactor the resource loading interface, add support for load-time
dependencies.
- Main-thread finalization of asynchronously loaded resources is now
spread out across multiple frames to mitigate frametime spikes.
- Remove some archaisms from the resource management code.
- Fix potential hashtable synchronization issue.
- Fix some deadlock edge cases.
- Don't spawn more worker threads than there are CPU cores (degrades
performance).
- Add TAISEI_AGGRESSIVE_PRELOAD env variable to attempt to aggressively
discover and preload every possible resource.
- Make r_texture_fill{,_region} expect optimal pixmaps, so that it's
never forced to convert them on the main thread. The optimal format may
be queried with the new r_texture_optimal_pixmap_format_for_type API.
These functions will also no longer needlessly copy the entire image
into a staging buffer - previously they did this even if no conversion
was needed.
- Other random changes to facilitate the stuff above.

The overall effect is somewhat faster load times.

Of course it's still all terrible and full of lock contention because I
suck at concurrent programming, but it's not worse than it was.
Probably.
2020-06-09 03:01:53 +03:00
Andrei Alexeyev
28ba4dc955
Make video struct private
Also display actual window size in settings when no known mode is
selected
2019-09-11 18:42:13 +03:00
Andrei Alexeyev
5a23fb95fc
make upkeep script preserve existing copyrights 2019-08-03 20:44:22 +03:00
Andrei Alexeyev
3055901998
update my email 2019-07-03 21:00:56 +03:00
Andrei Alexeyev
c2c1794c14
fix bogus sort stabilization 2019-03-11 19:20:38 +02:00
Andrei Alexeyev
add8469b06
refactor crazy memory allocations in events 2019-03-11 17:45:15 +02:00
Andrei Alexeyev
180f9e3856
Emscripten compatibility (#161)
* Major refactoring of the main loop(s) and control flow (WIP)

run_at_fps() is gone 🦀

Instead of nested blocking event loops, there is now an eventloop API
that manages an explicit stack of scenes. This makes Taisei a lot more
portable to async environments where spinning a loop forever without
yielding control simply is not an option, and that is the entire point
of this change.

A prime example of such an environment is the Web (via emscripten).
Taisei was able to run there through a terrible hack: inserting
emscripten_sleep calls into the loop, which would yield to the browser.
This has several major drawbacks: first of all, every function that
could possibly call emscripten_sleep must be compiled into a special
kind of bytecode, which then has to be interpreted at runtime, *much*
slower than JITed WebAssembly. And that includes *everything* down the
call stack, too! For more information, see
https://emscripten.org/docs/porting/emterpreter.html

Even though that method worked well enough for experimenting, despite
suboptimal performance, there is another obvious drawback:
emscripten_sleep is implemented via setTimeout(), which can be very
imprecise and is generally not reliable for fluid animation. Browsers
actually have an API specifically for that use case:
window.requestAnimationFrame(), but Taisei's original blocking control
flow style is simply not compatible with it. Emscripten exposes this API
with its emscripten_set_main_loop(), which the eventloop backend now
uses on that platform.

Unfortunately, C is still C, with no fancy closures or coroutines.
With blocking calls into menu/scene loops gone, the control flow is
reimplemented via so-called (pun intended) "call chains". That is
basically an euphemism for callback hell. With manual memory management
and zero type-safety. Not that the menu system wasn't shitty enough
already. I'll just keep telling myself that this is all temporary and
will be replaced with scripts in v1.4.

* improve build system for emscripten + various fixes

* squish menu bugs

* improve emscripten event loop; disable EMULATE_FUNCTION_POINTER_CASTS

Note that stock freetype does not work without
EMULATE_FUNCTION_POINTER_CASTS; use a patched version from the
"emscripten" branch here:

    https://github.com/taisei-project/freetype2/tree/emscripten

* Enable -Wcast-function-type

Calling functions through incompatible pointers is nasal demons and
doesn't work in WASM.

* webgl: workaround a crash on some browsers

* emscripten improvements:

    * Persist state (config, progress, replays, ...) in local IndexDB
    * Simpler HTML shell (temporary)
    * Enable more optimizations

* fix build if validate_glsl=false

* emscripten: improve asset packaging, with local cache

Note that even though there are rules to build audio bundles, audio
does *not* work yet. It looks like SDL2_mixer can not work without
threads, which is a problem. Yet another reason to write an OpenAL
backend - emscripten supports that natively.

* emscripten: customize the html shell

* emscripten: force "show log" checkbox unchecked initially

* emscripten: remove quit shortcut from main menu (since there's no quit)

* emscripten: log area fixes

* emscripten/webgl: workaround for fullscreen viewport issue

* emscripten: implement frameskip

* emscripter: improve framerate limiter

* align List to at least 8 bytes (shut up warnings)

* fix non-emscripten builds

* improve fullscreen handling, mainly for emscripten

* Workaround to make audio work in chromium

emscripten-core/emscripten#6511

* emscripten: better vsync handling; enable vsync & disable fxaa by default
2019-03-09 21:32:32 +02:00
Andrei Alexeyev
b91b85c42a
Logging: colors, non-fatal error level, alt. format for log file
Also removed traceback support entirely as it never produced useful
output.
2019-02-15 01:58:40 +02:00
Andrei Alexeyev
4159ea1249
'upkeep' target for maintenance tasks; back to include guards; happy new year! 2019-01-23 22:10:43 +02:00
Andrei Alexeyev
69079f245a
dubious timing optimizations; try to sleep between frames; skip at constant speed 2019-01-09 05:25:10 +02:00
Andrei Alexeyev
ebd8344382
workaround to allow safely unregistering event handlers from within event handlers
fixes #153
2018-11-10 02:58:37 +02:00
Andrei Alexeyev
5548b6d65a
Don't emit TE_MENU_ACCEPT events from repeated inputs
Fixes #150 and potentially other input issues
2018-10-02 04:44:33 +03:00
holycleugh
10046ff9c7 Add option and keybinding to toggle audio mute. (#147) 2018-09-15 18:48:03 +03:00
Andrei Alexeyev
b9262d80ab
fix various issues discovered by scan-build 2018-07-31 11:50:04 +03:00
Andrei Alexeyev
b16f402040
Refactor framebuffer-related stuff (#130)
* Renderer: rename render targets to framebuffers

* Refactor framebuffer pair helper and some of the video API

* Remove hardcoded dimensions from draw_framebuffer_tex

* Make viewport a per-framebuffer property rather than a global one

* Handle config updates via the events system. React to viewport fg/bg quality change requests.
2018-07-04 11:36:16 +03:00
Andrei Alexeyev
83a8961df6
use "anchored" lists for most game objects
these have a pointer to the last element, thus appending is fast
2018-06-01 21:40:18 +03:00
Andrei Alexeyev
fdfc2de543
attempt to ensure clean exit by external request (window closed, process terminated, etc.) 2018-05-19 05:01:16 +03:00
Andrei Alexeyev
78e9d3cb9e
gamepad: implement button repeat 2018-01-16 13:51:19 +02:00
Andrei Alexeyev
513d613387
Consistent indentation: indent with tabs, align with spaces (#104)
I would've preferred to just go with 4-spaces for indent and no tabs,
but lao is a bit conservative about it. :^)

Still, this is a ton better than mixing different styles all over the
place, especially within the same file.
2018-01-12 20:26:07 +02:00
Andrei Alexeyev
d73f8d28a3
add head version of list_insert_at_priority, use it for proj_insert_colorprio (slightly faster) 2018-01-09 21:54:03 +02:00
Andrei Alexeyev
485c9a8ed6
Happy New Year! 2018-01-04 19:14:31 +02:00
Andrei Alexeyev
e355e57fb5
make the list api require less insane casts all over the place
by sealing the spirit of insanity in its header file, that is
2017-12-24 08:16:25 +02:00
Andrei Alexeyev
29acd5f58a meson: intel intrinsics, various improvements 2017-12-21 03:58:54 +01:00
Andrei Alexeyev
7b53d9e731
redesign list api 2017-11-21 16:45:01 +02:00
Andrei Alexeyev
499259512b
fix fullscreen/window management issues 2017-11-11 20:47:32 +02:00
Andrei Alexeyev
b61ef0bffc
more strict warnings; fixed some subtle bugs 2017-11-11 19:33:44 +02:00
Andrei Alexeyev
f21e35f459
minor options menu improvements 2017-10-22 02:50:15 +03:00
Andrei Alexeyev
551260d6eb
remove events_print_handlers 2017-10-01 00:43:22 +03:00
Andrei Alexeyev
4e2e050baa
basic utf8 text input, with clipboard support 2017-10-01 00:43:22 +03:00
Andrei Alexeyev
ef67a16867
WIP event system rewrite. text input missing 2017-10-01 00:43:18 +03:00
Andrei "Akari" Alexeyev
8aa6f8ea64
video hacks 2017-09-19 15:13:04 +03:00
Andrei "Akari" Alexeyev
c199ce6fa6
use desktop mode fullscreen by default
also fixed the userevent in resources to use the correct id
2017-09-18 14:19:50 +03:00
Andrei "Akari" Alexeyev
7c9e54a71d
update copyright and credits 2017-09-12 04:28:15 +03:00
Andrei "Akari" Alexeyev
74b0259e25 prevent accidentally overriding the basic menu controls (arrows, enter, escape) 2017-04-08 19:37:36 +03:00
Andrei "Akari" Alexeyev
df90733c8f WIP async loading 2017-03-14 02:46:06 +02:00
Andrei "Akari" Alexeyev
dacbf96427 moved util functions from global to where they make a bit more sense 2017-03-06 03:24:47 +02:00
Andrei "Akari" Alexeyev
57053210dd Refactored and improved menus and transitions 2017-02-24 23:58:27 +02:00
Andrei "Akari" Alexeyev
802cacb799 Config callback system
No more hacks in options menu code to update stuff when a setting
changes
2017-02-17 20:23:22 +02:00
Andrei "Akari" Alexeyev
32f7edd24e Refactored config into a macro hell 2017-02-17 18:03:49 +02:00