Commit graph

67 commits

Author SHA1 Message Date
Andrei Alexeyev
b6978178b1
memory: use custom memory allocation wrappers
Introduces wrappers around memory allocation functions in `memory.h`
that should be used instead of the standard C ones.

These never return NULL and, with the exception of `mem_realloc()`,
zero-initialize the allocated memory like `calloc()` does.

All allocations made with the memory.h API must be deallocated with
`mem_free()`. Although standard `free()` will work on some platforms,
it's not portable (currently it won't work on Windows). Likewise,
`mem_free()` must not be used to free foreign allocations.

The standard C allocation functions are now diagnosed as deprecated.
They are, however, available with the `libc_` prefix in case interfacing
with foreign APIs is required. So far they are only used to implement
`memory.h`.

Perhaps the most important change is the introduction of the `ALLOC()`,
`ALLOC_ARRAY()`, and `ALLOC_FLEX()` macros. They take a type as a
parameter, and allocate enough memory with the correct alignment for
that type. That includes overaligned types as well. In most
circumstances you should prefer to use these macros. See the `memory.h`
header for some usage examples.
2023-01-18 13:23:22 +01:00
Andrei Alexeyev
74f07d67bb
gamepad: use dynarray for devices 2023-01-09 01:14:19 +01:00
Andrei Alexeyev
a1142b1ffd
gamepad: don't panic when unknown button is encountered
This should only happen if SDL adds support for new buttons in the
future.
2022-01-08 18:28:21 +02:00
Andrei Alexeyev
4661c9609c
gamepad: support extra buttons 2022-01-08 18:22:44 +02:00
Andrei Alexeyev
c3382e6b05
gamepad: fix accidental gigantic array 2022-01-08 18:15:27 +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
383234efe7
random cleanup 2019-11-08 20:53:43 +02: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
ailin-nemui
6b8efb4457 Update gamepads unconditionally, once (#169)
* Update gamepads unconditionally, once

The commit of #168 was incomplete in that it did not enable the device by setting active_dev_num

* Set update_needed instead
2019-06-19 21:44:13 +03:00
ailin-nemui
48bd6063ad always update gamepad device list at least once (#168) 2019-06-11 03:23:00 +03:00
Andrei Alexeyev
b3a0128be6
gamepad: support hotplug, any-device option 2019-04-19 14:28:32 +03:00
Andrei Alexeyev
89b8f1d502
fix gamepad input repeat regression 2019-02-15 02:04:02 +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
1a0751cafd
fix memory leak in gamepad code 2018-11-10 03:02:02 +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
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
bc0d6795a3
gamepad: make back/select act as skip in-game 2018-01-18 14:25:13 +02:00
Andrei Alexeyev
797878b2bb
gamepad: fix stuck movement after pause in restricted mode; remove dead code 2018-01-18 11:30:42 +02:00
Andrei Alexeyev
479d20e081
simplify gamepad_button_pressed() 2018-01-18 11:25:12 +02:00
Andrei Alexeyev
b48248ef7a
gamepad: support input repeat for analog sticks as well as buttons 2018-01-18 11:13:25 +02:00
Andrei Alexeyev
677d866f9b
gamepad: no keyrepeat during transitions (same as keyboard input) 2018-01-16 14:01:50 +02:00
Andrei Alexeyev
78e9d3cb9e
gamepad: implement button repeat 2018-01-16 13:51:19 +02:00
Andrei Alexeyev
5056e04c29
formatting 2018-01-14 05:20:16 +02:00
Andrei Alexeyev
d6cec62519
gamepad: attempt to improve analog input, especially restricted mode 2018-01-14 05:16:29 +02:00
Andrei Alexeyev
3ed200f8ed
shutdown gamepad subsystem properly if it fails to init 2018-01-13 05:07:54 +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
485c9a8ed6
Happy New Year! 2018-01-04 19:14:31 +02:00
Andrei Alexeyev
b88128cff3
gamepad: properly initialize axis states 2017-12-30 18:22:30 +02:00
Andrei Alexeyev
990f45a08c
fix -Wenum-compare warnings 2017-12-30 17:54:09 +02:00
Andrei Alexeyev
5b7de7d8a2
gamepad: basic support for trigger buttons (analog and digital) 2017-12-30 17:39:42 +02:00
Andrei Alexeyev
29acd5f58a meson: intel intrinsics, various improvements 2017-12-21 03:58:54 +01:00
Andrei Alexeyev
fea9a5ee31
fix gamepad input braindeath 2017-12-16 23:19:49 +02:00
Andrei Alexeyev
6bafaaaf32
fix gamepad crash 2017-10-25 02:02:39 +03:00
Andrei Alexeyev
f21e35f459
minor options menu improvements 2017-10-22 02:50:15 +03:00
Andrei Alexeyev
063807870e
simplify condition 2017-10-22 02:29:04 +03:00
Andrei Alexeyev
7440315281
untested fix for restricted mode on some gamepads 2017-10-22 02:16:52 +03:00
Andrei Alexeyev
ba29da405f
fixed menu input issues 2017-10-01 01:09:07 +03:00
Andrei Alexeyev
ef67a16867
WIP event system rewrite. text input missing 2017-10-01 00:43:18 +03:00
Andrei "Akari" Alexeyev
e01c0d91f2
support loading gamepad mappings; readme updates 2017-09-22 13:32:01 +03:00
Andrei "Akari" Alexeyev
d9611b0831
player input, gamepad, and replay improvements
may break existing replays
2017-09-20 00:32:58 +03:00
Andrei "Akari" Alexeyev
dce663c5ed
fix qualified void return 2017-09-16 09:44:39 +03:00
Andrei "Akari" Alexeyev
7c9e54a71d
update copyright and credits 2017-09-12 04:28:15 +03:00
Andrei "Akari" Alexeyev
644757a65a
gamepad settings improvements
GUIDs are now used to identify devices. this allows reliable persistent
configuration on multi-gamepad systems.

changed the way the device listing in the options menu works. it's
inactive when the gamepad system is disabled, and dynamically updated
when it's enabled. as a result, the "bare" init state is now finally
gone. this should work with minimal or no changes when the hotplugging
events are properly handled.

the "enable gamepad support" toggle is now effective immediately. the
gamepad system is no longer restarted every time the user leaves the
gamepad menu, unless they have changed the device.
2017-08-28 14:56:43 +03:00
Andrei "Akari" Alexeyev
57a138c1d1
improved gamepad support using SDL GameController API
still WIP, but it's better than it was

todo (maybe):
    - handle hotplugging
    - enable gamepad support by default
    - treat analog triggers as buttons
    - better way of saving which device to use to the config, the index
    is virtually useless
2017-07-15 06:22:56 +03:00
Andrei "Akari" Alexeyev
cd921d0bf5 clamp deadzone to sane values 2017-03-18 06:51:56 +02:00
Andrei "Akari" Alexeyev
8258f6f17e better gamepad deadzone handling 2017-03-18 06:44:42 +02:00
Andrei "Akari" Alexeyev
45da155cb2 Implemented a simple and consistent logging subsystem
The goal of this change is mainly to clean up Taisei's codebase and
improve its console output. I've been frustrated by files littered with
inconsistent printf/fprintf/warnx/errx calls for a long time, and now I
actually did something about it.

All the above functions are now considered deprecated and result in a
compile-time warning when used. Instead, the following macros should be
used:

    log_debug(format, ...)
    log_info(format, ...)
    log_warn(format, ...)
    log_err(format, ...)

As you can see, all of them have the same printf-like interface. But
they have different functionality and purpose:

    log_debug is intended for very verbose and specific information. It
    does nothing in release builds, much like assert(), so don't use
    expressions with side-effects in its arguments.

    log_info is for various status updates that are expected during
    normal operation of the program.

    log_warn is for non-critical failures or other things that may be
    worth investigating, but don't inherently render the program
    non-functional.

    log_err is for when the only choice is to give up. Like errx, it
    also terminates the program. Unlike errx, it actually calls abort(),
    which means the cleanup functions are not ran -- but on the other
    hand, you get a debuggable backtrace. However, if you're trying to
    catch programming errors, consider using assert() instead.

All of them produce output that contains a timestamp, the log level
identifier, the calling function's name, and the formatted message.

The newline at the end of the format string is not required -- no, it is
actually *prohibited*. The logging system will take care of the line
breaks by itself, don't litter the code with that shit.

Internally, the logging system is based on the SDL_RWops abstraction,
and may have multiple, configurable destinations. This makes it easily
extensible. Currently, log_debug and log_info are set to write to
stdout, log_warn and log_err to stderr, and all of them also to the file
log.txt in the Taisei config directory.

Consequently, the nasty freopen hacks we used to make Taisei write to
log files on Windows are no longer needed -- which is a very good thing,
considering they probably would break if the configdir path contains
UTF-8 characters. SDL_RWFromFile does not suffer this limitation.

As an added bonus, it's also thread-safe.

Note about printf and fprintf: in very few cases, the logging system is
not a good substitute for these functions. That is, when you care about
writing exactly to stdout/stderr and about exactly how the output looks.

However, I insist on keeping the deprecation warnings on them to not
tempt anyone to use them for logging/debugging out of habit and/or
laziness.

For this reason, I've added a tsfprintf function to util.c. It is
functionally identical to fprintf, except it returns void. Yes, the name
is deliberately ugly. Avoid using it if possible, but if you must, only
use it to write to stdout or stderr. Do not write to actual files with
it, use SDL_RWops.
2017-03-13 07:45:01 +02:00
Andrei "Akari" Alexeyev
22314f9582 converted SIGN into a function 2017-03-06 17:32:51 +02:00