2011-05-08 13:48:25 +02:00
|
|
|
/*
|
2019-08-03 19:43:48 +02:00
|
|
|
* This software is licensed under the terms of the MIT License.
|
2017-02-11 04:52:08 +01:00
|
|
|
* See COPYING for further information.
|
2011-05-08 13:48:25 +02:00
|
|
|
* ---
|
2024-05-16 23:30:41 +02:00
|
|
|
* Copyright (c) 2011-2024, Lukas Weber <laochailan@web.de>.
|
|
|
|
* Copyright (c) 2012-2024, Andrei Alexeyev <akari@taisei-project.org>.
|
2011-05-08 13:48:25 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "dialog.h"
|
2024-05-17 04:41:28 +02:00
|
|
|
|
2011-05-08 13:48:25 +02:00
|
|
|
#include "global.h"
|
2020-04-27 21:58:25 +02:00
|
|
|
#include "portrait.h"
|
2024-05-17 04:41:28 +02:00
|
|
|
#include "resource/font.h"
|
2011-05-08 13:48:25 +02:00
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
void dialog_init(Dialog *d) {
|
|
|
|
memset(d, 0, sizeof(*d));
|
|
|
|
d->state = DIALOG_STATE_IDLE;
|
|
|
|
d->text.current = &d->text.buffers[0];
|
|
|
|
d->text.fading_out = &d->text.buffers[1];
|
|
|
|
COEVENT_INIT_ARRAY(d->events);
|
2019-07-08 02:47:50 +02:00
|
|
|
}
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
void dialog_deinit(Dialog *d) {
|
|
|
|
COEVENT_CANCEL_ARRAY(d->events);
|
2019-08-22 21:43:34 +02:00
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
for(DialogActor *a = d->actors.first; a; a = a->next) {
|
|
|
|
if(a->composite.tex) {
|
|
|
|
r_texture_destroy(a->composite.tex);
|
|
|
|
}
|
|
|
|
}
|
2019-08-22 21:43:34 +02:00
|
|
|
}
|
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
void dialog_add_actor(Dialog *d, DialogActor *a, const char *name, DialogSide side) {
|
|
|
|
memset(a, 0, sizeof(*a));
|
|
|
|
a->name = name;
|
|
|
|
a->face = "normal";
|
|
|
|
a->side = side;
|
|
|
|
a->target_opacity = 1;
|
|
|
|
a->composite_dirty = true;
|
|
|
|
|
|
|
|
if(side == DIALOG_SIDE_RIGHT) {
|
|
|
|
a->speech_color = *RGB(0.6, 0.6, 1.0);
|
|
|
|
} else {
|
|
|
|
a->speech_color = *RGB(1.0, 1.0, 1.0);
|
|
|
|
}
|
2018-02-06 07:19:25 +01:00
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
alist_append(&d->actors, a);
|
2019-08-22 21:43:34 +02:00
|
|
|
}
|
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
void dialog_actor_set_face(DialogActor *a, const char *face) {
|
|
|
|
log_debug("[%s] %s --> %s", a->name, a->face, face);
|
|
|
|
if(a->face != face) {
|
|
|
|
a->face = face;
|
|
|
|
a->composite_dirty = true;
|
|
|
|
}
|
|
|
|
}
|
2019-08-22 21:43:34 +02:00
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
void dialog_actor_set_variant(DialogActor *a, const char *variant) {
|
|
|
|
log_debug("[%s] %s --> %s", a->name, a->variant, variant);
|
|
|
|
if(a->variant != variant) {
|
|
|
|
a->variant = variant;
|
|
|
|
a->composite_dirty = true;
|
|
|
|
}
|
|
|
|
}
|
2019-08-22 21:43:34 +02:00
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
void dialog_update(Dialog *d) {
|
|
|
|
if(d->text.current->text) {
|
|
|
|
fapproach_p(&d->text.current->opacity, 1, 1/120.0f);
|
|
|
|
} else {
|
|
|
|
d->text.current->opacity = 0;
|
2019-08-22 21:43:34 +02:00
|
|
|
}
|
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
if(d->text.fading_out->text) {
|
|
|
|
fapproach_p(&d->text.fading_out->opacity, 0, 1/60.0f);
|
|
|
|
} else {
|
|
|
|
d->text.fading_out->opacity = 0;
|
|
|
|
}
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
if(
|
|
|
|
d->state == DIALOG_STATE_FADEOUT ||
|
|
|
|
(
|
|
|
|
d->text.current->opacity == 0 &&
|
|
|
|
d->text.fading_out->opacity < 0.25
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
fapproach_asymptotic_p(&d->opacity, 0, 0.1, 1e-3);
|
2019-07-08 02:47:50 +02:00
|
|
|
} else {
|
2020-01-23 01:23:35 +01:00
|
|
|
fapproach_asymptotic_p(&d->opacity, 1, 0.05, 1e-3);
|
2019-08-22 21:43:34 +02:00
|
|
|
}
|
|
|
|
|
2020-05-05 10:47:42 +02:00
|
|
|
const float offset_per_actor = 32;
|
|
|
|
float target_offsets[2] = { 0 };
|
|
|
|
|
|
|
|
for(DialogActor *a = d->actors.last; a; a = a->prev) {
|
|
|
|
fapproach_asymptotic_p(&a->offset.x, target_offsets[a->side], 0.10, 1e-3);
|
|
|
|
target_offsets[a->side] += offset_per_actor;
|
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
if(d->state == DIALOG_STATE_FADEOUT) {
|
|
|
|
fapproach_asymptotic_p(&a->opacity, 0, 0.12, 1e-3);
|
|
|
|
} else {
|
|
|
|
fapproach_asymptotic_p(&a->opacity, a->target_opacity, 0.04, 1e-3);
|
|
|
|
}
|
2020-05-05 10:47:42 +02:00
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
fapproach_asymptotic_p(&a->focus, a->target_focus, 0.12, 1e-3);
|
|
|
|
}
|
|
|
|
}
|
2019-08-22 21:43:34 +02:00
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
void dialog_skippable_wait(Dialog *d, int timeout) {
|
|
|
|
CoEventSnapshot snap = coevent_snapshot(&d->events.skip_requested);
|
|
|
|
|
|
|
|
assert(d->state == DIALOG_STATE_IDLE);
|
|
|
|
d->state = DIALOG_STATE_WAITING_FOR_SKIP;
|
|
|
|
|
|
|
|
while(timeout > 0) {
|
|
|
|
dialog_update(d);
|
|
|
|
|
|
|
|
--timeout;
|
|
|
|
YIELD;
|
|
|
|
|
|
|
|
if(coevent_poll(&d->events.skip_requested, &snap) != CO_EVENT_PENDING) {
|
|
|
|
log_debug("Skipped with %i remaining", timeout);
|
|
|
|
break;
|
|
|
|
}
|
2019-07-08 02:47:50 +02:00
|
|
|
}
|
2019-08-22 21:43:34 +02:00
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
assert(d->state == DIALOG_STATE_WAITING_FOR_SKIP);
|
|
|
|
d->state = DIALOG_STATE_IDLE;
|
|
|
|
|
|
|
|
if(timeout == 0) {
|
|
|
|
log_debug("Timed out");
|
|
|
|
}
|
|
|
|
}
|
2019-08-22 21:43:34 +02:00
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
int dialog_util_estimate_wait_timeout_from_text(const char *text) {
|
|
|
|
return 1800;
|
2011-05-08 13:48:25 +02:00
|
|
|
}
|
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
static void dialog_set_text(Dialog *d, const char *text, const Color *clr) {
|
|
|
|
DialogTextBuffer *temp = d->text.current;
|
|
|
|
d->text.current = d->text.fading_out;
|
|
|
|
d->text.fading_out = temp;
|
2019-07-03 19:50:43 +02:00
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
d->text.current->color = *clr;
|
|
|
|
d->text.current->text = text;
|
|
|
|
}
|
|
|
|
|
|
|
|
void dialog_focus_actor(Dialog *d, DialogActor *actor) {
|
|
|
|
for(DialogActor *a = d->actors.first; a; a = a->next) {
|
|
|
|
a->target_focus = 0;
|
2019-07-03 19:50:43 +02:00
|
|
|
}
|
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
actor->target_focus = 1;
|
|
|
|
|
|
|
|
// make focused actor drawn on top of everyone else
|
|
|
|
alist_unlink(&d->actors, actor);
|
|
|
|
alist_append(&d->actors, actor);
|
|
|
|
}
|
|
|
|
|
|
|
|
void dialog_message_ex(Dialog *d, const DialogMessageParams *params) {
|
|
|
|
assume(params->actor != NULL);
|
|
|
|
assume(params->text != NULL);
|
|
|
|
|
|
|
|
log_debug("%s: %s", params->actor->name, params->text);
|
|
|
|
|
|
|
|
dialog_set_text(d, params->text, ¶ms->actor->speech_color);
|
|
|
|
dialog_focus_actor(d, params->actor);
|
|
|
|
|
|
|
|
if(params->implicit_wait) {
|
|
|
|
assume(params->wait_timeout > 0);
|
|
|
|
|
|
|
|
if(params->wait_skippable) {
|
|
|
|
dialog_skippable_wait(d, params->wait_timeout);
|
|
|
|
} else {
|
|
|
|
WAIT(params->wait_timeout);
|
|
|
|
}
|
2019-07-03 19:50:43 +02:00
|
|
|
}
|
2020-01-23 01:23:35 +01:00
|
|
|
}
|
2019-07-03 19:50:43 +02:00
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
static void _dialog_message(Dialog *d, DialogActor *actor, const char *text, bool skippable, int delay) {
|
|
|
|
DialogMessageParams p = { 0 };
|
|
|
|
p.actor = actor;
|
|
|
|
p.text = text;
|
|
|
|
p.implicit_wait = true;
|
|
|
|
p.wait_skippable = skippable;
|
|
|
|
p.wait_timeout = delay;
|
|
|
|
dialog_message_ex(d, &p);
|
2019-07-03 19:50:43 +02:00
|
|
|
}
|
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
void dialog_message(Dialog *d, DialogActor *actor, const char *text) {
|
|
|
|
_dialog_message(d, actor, text, true, dialog_util_estimate_wait_timeout_from_text(text));
|
|
|
|
}
|
|
|
|
|
|
|
|
void dialog_message_unskippable(Dialog *d, DialogActor *actor, const char *text, int delay) {
|
|
|
|
_dialog_message(d, actor, text, false, delay);
|
|
|
|
}
|
|
|
|
|
|
|
|
void dialog_end(Dialog *d) {
|
|
|
|
d->state = DIALOG_STATE_FADEOUT;
|
|
|
|
coevent_signal(&d->events.fadeout_began);
|
|
|
|
|
|
|
|
for(DialogActor *a = d->actors.first; a; a = a->next) {
|
|
|
|
a->target_opacity = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
wait_for_fadeout: {
|
|
|
|
if(d->opacity > 0) {
|
|
|
|
YIELD;
|
|
|
|
goto wait_for_fadeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(DialogActor *a = d->actors.first; a; a = a->next) {
|
|
|
|
if(a->opacity > 0) {
|
|
|
|
YIELD;
|
|
|
|
goto wait_for_fadeout;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
coevent_signal(&d->events.fadeout_ended);
|
|
|
|
dialog_deinit(d);
|
2011-05-08 13:48:25 +02:00
|
|
|
}
|
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
static void dialog_actor_update_composite(DialogActor *a) {
|
|
|
|
assume(a->name != NULL);
|
|
|
|
assume(a->face != NULL);
|
|
|
|
|
|
|
|
if(!a->composite_dirty) {
|
2019-08-22 21:43:34 +02:00
|
|
|
return;
|
2019-07-03 19:50:43 +02:00
|
|
|
}
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
log_debug("%s (%p) is dirty; face=%s; variant=%s", a->name, (void*)a, a->face, a->variant);
|
2019-08-22 21:43:34 +02:00
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
if(a->composite.tex != NULL) {
|
|
|
|
log_debug("destroyed texture at %p", (void*)a->composite.tex);
|
|
|
|
r_texture_destroy(a->composite.tex);
|
|
|
|
}
|
2019-08-22 21:43:34 +02:00
|
|
|
|
2020-04-27 21:58:25 +02:00
|
|
|
portrait_render_byname(a->name, a->variant, a->face, &a->composite);
|
2020-01-23 01:23:35 +01:00
|
|
|
log_debug("created texture at %p", (void*)a->composite.tex);
|
|
|
|
a->composite_dirty = false;
|
2011-05-08 13:48:25 +02:00
|
|
|
}
|
|
|
|
|
2019-07-08 02:47:50 +02:00
|
|
|
void dialog_draw(Dialog *dialog) {
|
2019-07-03 19:50:43 +02:00
|
|
|
if(dialog == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
float o = dialog->opacity;
|
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
for(DialogActor *a = dialog->actors.first; a; a = a->next) {
|
|
|
|
dialog_actor_update_composite(a);
|
2019-07-03 19:50:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
r_state_push();
|
|
|
|
r_state_push();
|
|
|
|
r_shader("sprite_default");
|
|
|
|
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_push();
|
|
|
|
r_mat_mv_translate(VIEWPORT_X, 0, 0);
|
2019-07-03 19:50:43 +02:00
|
|
|
|
|
|
|
const double dialog_width = VIEWPORT_W * 1.2;
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_push();
|
|
|
|
r_mat_mv_translate(dialog_width/2.0, 64, 0);
|
2019-07-03 19:50:43 +02:00
|
|
|
|
|
|
|
Color clr = { 0 };
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
for(DialogActor *a = dialog->actors.first; a; a = a->next) {
|
|
|
|
if(a->opacity <= 0) {
|
2019-07-08 02:47:50 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
dialog_actor_update_composite(a);
|
|
|
|
Sprite *portrait = &a->composite;
|
|
|
|
assume(portrait->tex != NULL);
|
|
|
|
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_push();
|
2018-04-12 16:08:48 +02:00
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
if(a->side == DIALOG_SIDE_LEFT) {
|
2018-04-12 16:08:48 +02:00
|
|
|
r_cull(CULL_FRONT);
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_scale(-1, 1, 1);
|
2018-04-12 16:08:48 +02:00
|
|
|
} else {
|
|
|
|
r_cull(CULL_BACK);
|
2011-05-08 13:48:25 +02:00
|
|
|
}
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
if(a->opacity < 1) {
|
|
|
|
r_mat_mv_translate(120 * (1 - a->opacity), 0, 0);
|
2019-07-03 19:50:43 +02:00
|
|
|
}
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
float ofs = 10 * (1 - a->focus);
|
|
|
|
r_mat_mv_translate(ofs, ofs, 0);
|
|
|
|
float brightness = 0.5 + 0.5 * a->focus;
|
|
|
|
clr.r = clr.g = clr.b = brightness;
|
|
|
|
clr.a = 1;
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
color_mul_scalar(&clr, a->opacity);
|
2019-07-08 02:47:50 +02:00
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
r_flush_sprites();
|
2019-08-22 21:43:34 +02:00
|
|
|
r_draw_sprite(&(SpriteParams) {
|
|
|
|
.blend = BLEND_PREMUL_ALPHA,
|
|
|
|
.color = &clr,
|
2022-11-27 20:08:24 +01:00
|
|
|
.pos.x = (dialog_width - portrait->w) / 2 + 32 + a->offset.x,
|
|
|
|
.pos.y = VIEWPORT_H - portrait->h / 2 + a->offset.y,
|
2019-08-22 21:43:34 +02:00
|
|
|
.sprite_ptr = portrait,
|
|
|
|
});
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_pop();
|
2011-05-08 13:48:25 +02:00
|
|
|
}
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_pop();
|
2019-07-03 19:50:43 +02:00
|
|
|
r_state_pop();
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2019-07-03 19:50:43 +02:00
|
|
|
FloatRect dialog_bg_rect = {
|
|
|
|
.extent = { VIEWPORT_W-40, 110 },
|
|
|
|
.offset = { VIEWPORT_W/2, VIEWPORT_H-55 },
|
|
|
|
};
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_push();
|
2019-07-03 19:50:43 +02:00
|
|
|
if(o < 1) {
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_translate(0, 100 * (1 - o), 0);
|
2019-07-03 19:50:43 +02:00
|
|
|
}
|
|
|
|
r_color4(0, 0, 0, 0.8 * o);
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_push();
|
|
|
|
r_mat_mv_translate(dialog_bg_rect.x, dialog_bg_rect.y, 0);
|
|
|
|
r_mat_mv_scale(dialog_bg_rect.w, dialog_bg_rect.h, 1);
|
2018-04-12 16:08:48 +02:00
|
|
|
r_shader_standard_notex();
|
|
|
|
r_draw_quad();
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_mv_pop();
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2020-06-09 03:33:22 +02:00
|
|
|
Font *font = res_font("standard");
|
2017-10-23 12:10:40 +02:00
|
|
|
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_tex_push();
|
2019-07-03 19:50:43 +02:00
|
|
|
|
|
|
|
dialog_bg_rect.w = VIEWPORT_W * 0.86;
|
|
|
|
dialog_bg_rect.x -= dialog_bg_rect.w * 0.5;
|
|
|
|
dialog_bg_rect.y -= dialog_bg_rect.h * 0.5;
|
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
if(dialog->text.fading_out->opacity > 0) {
|
|
|
|
clr = dialog->text.fading_out->color;
|
2019-07-03 19:50:43 +02:00
|
|
|
color_mul_scalar(&clr, o);
|
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
text_draw_wrapped(dialog->text.fading_out->text, dialog_bg_rect.w, &(TextParams) {
|
2019-07-03 19:50:43 +02:00
|
|
|
.shader = "text_dialog",
|
2020-06-09 03:33:22 +02:00
|
|
|
.aux_textures = { res_texture("cell_noise") },
|
2020-01-23 01:23:35 +01:00
|
|
|
.shader_params = &(ShaderCustomParams) {{ o * (1.0 - (0.2 + 0.8 * (1 - dialog->text.fading_out->opacity))), 1 }},
|
2019-07-03 19:50:43 +02:00
|
|
|
.color = &clr,
|
|
|
|
.pos = { VIEWPORT_W/2, VIEWPORT_H-110 + font_get_lineskip(font) },
|
|
|
|
.align = ALIGN_CENTER,
|
|
|
|
.font_ptr = font,
|
|
|
|
.overlay_projection = &dialog_bg_rect,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
if(dialog->text.current->opacity > 0) {
|
|
|
|
clr = dialog->text.current->color;
|
|
|
|
color_mul_scalar(&clr, o);
|
2019-07-03 19:50:43 +02:00
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
text_draw_wrapped(dialog->text.current->text, dialog_bg_rect.w, &(TextParams) {
|
|
|
|
.shader = "text_dialog",
|
2020-06-09 03:33:22 +02:00
|
|
|
.aux_textures = { res_texture("cell_noise") },
|
2020-01-23 01:23:35 +01:00
|
|
|
.shader_params = &(ShaderCustomParams) {{ o * dialog->text.current->opacity, 0 }},
|
|
|
|
.color = &clr,
|
|
|
|
.pos = { VIEWPORT_W/2, VIEWPORT_H-110 + font_get_lineskip(font) },
|
|
|
|
.align = ALIGN_CENTER,
|
|
|
|
.font_ptr = font,
|
|
|
|
.overlay_projection = &dialog_bg_rect,
|
|
|
|
});
|
|
|
|
}
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2019-10-12 14:02:15 +02:00
|
|
|
r_mat_tex_pop();
|
|
|
|
r_mat_mv_pop();
|
|
|
|
r_mat_mv_pop();
|
2019-07-03 19:50:43 +02:00
|
|
|
r_state_pop();
|
2011-05-08 13:48:25 +02:00
|
|
|
}
|
2017-02-11 04:52:08 +01:00
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
bool dialog_page(Dialog *d) {
|
|
|
|
if(d->state == DIALOG_STATE_WAITING_FOR_SKIP) {
|
|
|
|
coevent_signal(&d->events.skip_requested);
|
|
|
|
return true;
|
Give projectiles EVENT_BIRTH and call them with t==0 more consistently
The only case of t==0 being skipped is if the projectile was somehow
created after the projectile processing loop for this frame has been
finished. Currently that is only possible if a particle spawns a
non-particle projectile, which, ideally, should never happen. The same
problem exists with other types of entities. For example, if you have a
funny projectile rule that spawns an Enemy, that Enemy will have the 0th
frame skipped. One way to fix this is to maintain a list of all entities
in the game and process them all in a single loop, where newly spawned
entities would be appended to the tail of the list. This is also
probably the only good way to fix this, too.
Handling of all projectile events has been made mandatory to facilitate
easier debugging of subtle and/or hard to track bugs. If t<0, then the
projectile rule MUST return ACTION_ACK, signifying that it acknowledged
the event and handled it appropriately. Otherwise, it SHOULD return
ACTION_NONE or ACTION_DESTROY. In a perfect world, those just wouldn't
be conflated in the same function with update logic.
I've also cleaned up the stage_logic routine a bit. Moved most of the
dialog handling into dialog.c and gave higher priority to boss
processing. The later is currently necessary to let boss-spawned
projectiles and particles to get called with t==0.
2018-05-16 01:38:47 +02:00
|
|
|
}
|
2019-07-03 19:50:43 +02:00
|
|
|
|
2020-01-23 01:23:35 +01:00
|
|
|
return false;
|
2019-07-03 19:50:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool dialog_is_active(Dialog *d) {
|
2020-01-23 01:23:35 +01:00
|
|
|
return d && d->state != DIALOG_STATE_FADEOUT;
|
Give projectiles EVENT_BIRTH and call them with t==0 more consistently
The only case of t==0 being skipped is if the projectile was somehow
created after the projectile processing loop for this frame has been
finished. Currently that is only possible if a particle spawns a
non-particle projectile, which, ideally, should never happen. The same
problem exists with other types of entities. For example, if you have a
funny projectile rule that spawns an Enemy, that Enemy will have the 0th
frame skipped. One way to fix this is to maintain a list of all entities
in the game and process them all in a single loop, where newly spawned
entities would be appended to the tail of the list. This is also
probably the only good way to fix this, too.
Handling of all projectile events has been made mandatory to facilitate
easier debugging of subtle and/or hard to track bugs. If t<0, then the
projectile rule MUST return ACTION_ACK, signifying that it acknowledged
the event and handled it appropriately. Otherwise, it SHOULD return
ACTION_NONE or ACTION_DESTROY. In a perfect world, those just wouldn't
be conflated in the same function with update logic.
I've also cleaned up the stage_logic routine a bit. Moved most of the
dialog handling into dialog.c and gave higher priority to boss
processing. The later is currently necessary to let boss-spawned
projectiles and particles to get called with t==0.
2018-05-16 01:38:47 +02:00
|
|
|
}
|
2019-09-12 17:33:08 +02:00
|
|
|
|
2023-03-22 23:41:32 +01:00
|
|
|
void dialog_preload(ResourceGroup *rg) {
|
|
|
|
res_group_preload(rg, RES_SHADER_PROGRAM, RESF_DEFAULT, "text_dialog", NULL);
|
2019-09-12 17:33:08 +02:00
|
|
|
}
|