Commit graph

52 commits

Author SHA1 Message Date
Alice D
778146ed60
More compiler warning fixes (#273)
* fix small compile issue with coroutine.c and gcc

* fix 'potential nullpointer dereference' warning

* fix more potential nullpointers

* fix more potential nullpointers - part 2

* a handful of small fixes to silence gcc compiler warnings, mostly potentiall null pointers and style deficiencies

* PR changes, bump meson to 0.53.0

* fix potential null error in YoumuB

* bump meson version, change initialization

* no longer version-splitting meson
2020-12-26 01:40:08 +02:00
Andrei Alexeyev
6415217a25
Improve coroutine scheduler shutdown sequence
Before canceling tasks, find all events with subscribers and cancel
them. This wakes the subscribers, allowing them to run additional
cleanup code if necessary.

Coroutines are also taken down earlier in the stage shutdown sequence,
before removing any entities. This avoids the problem of entity removal
code waking up coroutines by cancelling events, which in turn may spawn
more entities. This issue sometimes caused the elusive "%i entities were
not properly unregistered" bug.
2020-10-10 09:41:44 +03:00
Andrei Alexeyev
4c38f1b0ba
Hide coroutine stats when no coroutines are active 2020-08-25 04:56:22 +03:00
Andrei Alexeyev
52baad241a
Disable CO_TASK_STATS_STACK by default 2020-08-25 04:56:22 +03:00
Andrei Alexeyev
9f050bf9b6
coroutine: increase stack size for non-emscripten builds
Fixes #243
2020-08-16 14:11:09 +03:00
Andrei Alexeyev
55d8fa7fbc
Disable coroutine stack usage tracking on windows
It crashes there
2020-07-31 17:23:48 +03:00
Andrei Alexeyev
89ecc0c55e
Establish more-or-less consistent resource getter functions
Deprecate old ad-hoc stuff like get_sprite, r_texture_get, etc.
2020-06-09 04:33:22 +03:00
Andrei Alexeyev
556ba2ee6f
Cancel hosted events before unregistering hosted entity 2020-05-02 01:19:15 +03:00
Andrei Alexeyev
31adaa7e0f
Add WAIT_EVENT_ONCE(event)
Waits for event if it hasn't been signaled yet. It if has, returns
without waiting, as if the event has just been signaled.
2020-04-30 21:49:10 +03:00
Andrei Alexeyev
e16e2184a3
Refactor entity system (#214)
* Smarter generic entity macros

The list of "core" entities is now defined in one macro, and hardcoded
_Generic dispatch tables are eliminated

* Get rid of "custom" entities

All entities are now "first-class". The list of known entity types has
been moved to known_entities.h. The system no longer needs to know the
definition of all entity structs.

* Refactor guts of ENT_BOX/ENT_UNBOX

Made the functions inline, Box::ent is now a proper pointer type (but
please don't use it directly), ENT_UNBOX returns NULL if the box is
"empty" (references NULL entity)

* Merge TASK_BIND_UNBOXED with TASK_BIND

* s/YoumuMyon/YoumuAMyon for consistency
2020-04-17 10:18:53 +03:00
Andrei Alexeyev
fe3aabcdc1
Add TASK_HOST_CUSTOM_ENT and TASK_HOST_EVENTS APIs (#208)
TASK_HOST_CUSTOM_ENT(type) allocates a custom entity from a reserved
region on the task's stack (same as TASK_MALLOC) and registers it. The
entity will be automatically unregistered when the task terminates for
any reason. Only one entity can be hosted by any particular task. This
macro returns a pointer to the hosted entity.

TASK_HOST_EVENTS(events) associates a custom array of events (created
with COEVENTS_ARRAY) with the task. All events in the array are
automatically initialized when this macro is called, and cancelled when
the task terminates for any reason. Only one array of events can be
hosted by any particular task.
2020-04-06 04:34:13 +03:00
Andrei Alexeyev
7fbe987b94
Add API for task-bound dynamic memory allocation (#201)
TASK_MALLOC(size) allocates a memory region with a lifetime bound to the
active task. It can't be free'd manually.

Allocation requests are served from a dedicated region on the task's
stack whenever possible, which is fast and essentially free. If there is
not enough free space to serve the request, then the memory is allocated
on the heap. Such heap allocations are automatically free'd when the
task expires.

The allocated memory is zero-initialized and aligned as strictly as
max_align_t.
2020-04-06 04:30:52 +03:00
Andrei Alexeyev
0cbc86c66e
Add generic type-safe facility for dynamic arrays (#207)
Replace most ad-hoc opencoded dynamic arrays across the codebase
2020-04-05 05:51:00 +03:00
Andrei Alexeyev
b902e90229
Add alist_merge_tail to efficiently merge two lists
Empties the "source" list, moving its contents to the tail of the
"destination" list.
2020-03-31 22:16:10 +03:00
Andrei Alexeyev
09d1a65faf
Fixup scheduling order of tasks
Previously tasks that were invoked by an initial invocation of another
task were scheduler before that parent task. Now they are scheduled
after the parent task, following the sequential order of invocation
2020-03-31 22:16:04 +03:00
Andrei Alexeyev
adeca742ec
Fix CoEvents overflowing with zombie subscribers 2020-03-08 23:25:37 +02:00
Andrei Alexeyev
673a73cf76
Fix invalid free in edge case of coevent_cancel 2020-03-08 13:47:41 +02:00
Andrei Alexeyev
35e0721cd1
Let ent-bound tasks wait for their own "finished" event 2020-03-08 03:41:02 +02:00
Andrei Alexeyev
d54c58a7bc
Add ability to wait for task's "finished" event
This works even if the scheduler is shutting down, allowing reliable
"cleanup" routines to be registered.
2020-03-08 02:35:53 +02:00
Andrei Alexeyev
92222f8888
Move most cotask control data to the task's stack 2020-03-04 22:26:55 +02:00
Andrei Alexeyev
e3d5518e9b
Remove coroutine finalizers 2020-03-04 22:26:50 +02:00
Andrei Alexeyev
4bfe8fccbb
Make coroutine stack usage tracking compatible with ASan 2020-03-04 22:26:49 +02:00
Andrei Alexeyev
260b29d4ee
Track peak coroutine stack usage (approximate)
Also reduced CO_TASK_SIZE back to 64kb
2020-03-04 22:26:49 +02:00
Andrei Alexeyev
d756790b6e
show num. of context swiches/frame in coroutine stats 2020-03-04 22:26:48 +02:00
Andrei Alexeyev
80f3728390
clean up some dead code 2020-03-04 22:26:47 +02:00
Andrei Alexeyev
3d1c0eee4e
WIP proj draw rule revamp; YoumuB revamp; misc changes; giant mess
cursed commit
2020-03-04 22:26:45 +02:00
Andrei Alexeyev
5c6b7671ef
fixup some post-rebase chaos 2020-03-04 22:26:45 +02:00
Andrei Alexeyev
75744681ed
update koishi 2020-03-04 22:26:45 +02:00
Andrei Alexeyev
9868fbcaa4
display number of active/allocated tasks 2020-03-04 22:26:44 +02:00
Andrei Alexeyev
d118204a2e
fix regression: subtasks not immediatelly cancelled after parent dies 2020-03-04 22:26:43 +02:00
Andrei Alexeyev
de5b821010
Experimental coroutine waiting optimization (WIP)
Avoids unnecessary back and forth context switches when waiting for a
delay or an event. Should be helpful for Emscripten, but needs
benchmarking.
2020-03-04 22:26:43 +02:00
Andrei Alexeyev
afd9d492dc
more verbose coroutine debugging output 2020-03-04 22:26:42 +02:00
Andrei Alexeyev
7ca54ec350
Add CANCEL_TASK_AFTER and macros for boss attacks
Also document various coroutine system macros
2020-03-04 22:25:44 +02:00
Andrei Alexeyev
20a417da97
remake Cirno's snowflake non 2020-03-04 22:06:40 +02:00
Andrei Alexeyev
75e99fa5c8
fix another subtask corruption 2020-03-04 22:06:40 +02:00
Andrei Alexeyev
490b224bd7
run upkeep 2020-03-04 22:06:39 +02:00
Andrei Alexeyev
953ac1c97b
macro fuckery for boxed ent arrays 2020-03-04 22:06:39 +02:00
Andrei Alexeyev
56aebcd921
fix corruption when subtask ends before its parent 2020-03-04 22:06:39 +02:00
Andrei Alexeyev
a846e4598f
event-based way to wait for boss defeat and retrieve the waiting time 2020-03-04 22:06:39 +02:00
Andrei Alexeyev
63c55ba09b
remove some bad assertions 2020-03-04 22:06:38 +02:00
Andrei Alexeyev
6596b76641
Add dependent subtasks; fix finalization bugs 2020-03-04 22:06:38 +02:00
Andrei Alexeyev
e14eb36e5c
implement some infrastructure for coroutine bosses 2020-03-04 22:06:37 +02:00
Andrei Alexeyev
c9ab42dc02
wip stage 1 progress 2020-03-04 21:52:53 +02:00
Andrei Alexeyev
4e4224dc59
task system tweaks and early Stage 1 port attempt 2020-03-04 21:50:51 +02:00
Andrei Alexeyev
76aef22e23
integrate task scheduling into the stage loop 2020-03-04 21:50:51 +02:00
Andrei Alexeyev
5b0b676c0e
INVOKE_TASK_DELAYED; CANCEL_TASK_WHEN; event robustness fixes 2020-03-04 21:50:51 +02:00
Andrei Alexeyev
13b5e33b0c
add 'killed' event for projectiles 2020-03-04 21:50:51 +02:00
Andrei Alexeyev
2a34f7bad4
generalize common bullet motion rules; add some math helpers 2020-03-04 21:50:50 +02:00
Andrei Alexeyev
3f99739d62
coroutines: task finalizers; fix enemy death event 2020-03-04 21:50:50 +02:00
Andrei Alexeyev
9fe54e0335
experimental event system for coroutine-based stages 2020-03-04 21:50:50 +02:00