util/callchain: split from eventloop
This commit is contained in:
parent
f0deb86937
commit
886ba290a9
15 changed files with 75 additions and 59 deletions
|
@ -17,6 +17,7 @@
|
|||
#include "util/fbmgr.h"
|
||||
#include "util/glm.h"
|
||||
#include "dynarray.h"
|
||||
#include "eventloop/eventloop.h"
|
||||
|
||||
typedef struct CreditsEntry {
|
||||
char **data;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#pragma once
|
||||
#include "taisei.h"
|
||||
|
||||
#include "eventloop/eventloop.h"
|
||||
#include "util/callchain.h"
|
||||
|
||||
void credits_enter(CallChain next);
|
||||
void credits_preload(void);
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "util/fbmgr.h"
|
||||
#include "util/glm.h"
|
||||
#include "video.h"
|
||||
#include "eventloop/eventloop.h"
|
||||
|
||||
#define SKIP_DELAY 3
|
||||
#define AUTO_ADVANCE_TIME_BEFORE_TEXT FPS * 2
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#pragma once
|
||||
#include "taisei.h"
|
||||
|
||||
#include "eventloop/eventloop.h"
|
||||
#include "util/callchain.h"
|
||||
|
||||
typedef enum CutsceneID {
|
||||
// NOTE: These IDs are used for progress tracking, do not reorder!
|
||||
|
|
|
@ -33,34 +33,6 @@ typedef struct FrameTimes {
|
|||
hrtime_t next;
|
||||
} FrameTimes;
|
||||
|
||||
#ifdef DEBUG_CALLCHAIN
|
||||
#include "util/debug.h"
|
||||
#include "log.h"
|
||||
#endif
|
||||
|
||||
typedef struct CallChainResult {
|
||||
void *ctx;
|
||||
void *result;
|
||||
} CallChainResult;
|
||||
|
||||
typedef struct CallChain {
|
||||
void (*callback)(CallChainResult result);
|
||||
void *ctx;
|
||||
#ifdef DEBUG_CALLCHAIN
|
||||
DebugInfo _debug_;
|
||||
#endif
|
||||
} CallChain;
|
||||
|
||||
#ifdef DEBUG_CALLCHAIN
|
||||
#define CALLCHAIN(callback, ctx) ((CallChain) { (callback), (ctx), _DEBUG_INFO_INITIALIZER_ })
|
||||
#else
|
||||
#define CALLCHAIN(callback, ctx) ((CallChain) { (callback), (ctx) })
|
||||
#endif
|
||||
|
||||
#define NO_CALLCHAIN CALLCHAIN(NULL, NULL)
|
||||
|
||||
#define CALLCHAIN_RESULT(ctx, result) ((CallChainResult) { (ctx), (result) })
|
||||
|
||||
void eventloop_enter(
|
||||
void *context,
|
||||
LogicFrameFunc frame_logic,
|
||||
|
@ -72,27 +44,3 @@ void eventloop_enter(
|
|||
void eventloop_run(void);
|
||||
|
||||
FrameTimes eventloop_get_frame_times(void);
|
||||
|
||||
#ifdef DEBUG_CALLCHAIN
|
||||
INLINE attr_nonnull(1) void run_call_chain(CallChain *cc, void *result, DebugInfo caller_dbg) {
|
||||
if(cc->callback != NULL) {
|
||||
log_debug("Calling CC set in %s (%s:%u)",
|
||||
cc->_debug_.func, cc->_debug_.file, cc->_debug_.line);
|
||||
log_debug(" from %s (%s:%u)",
|
||||
caller_dbg.func, caller_dbg.file, caller_dbg.line);
|
||||
cc->callback(CALLCHAIN_RESULT(cc->ctx, result));
|
||||
} else {
|
||||
log_debug("Dead end at %s (%s:%u)",
|
||||
caller_dbg.func, caller_dbg.file, caller_dbg.line
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#define run_call_chain(cc, result) run_call_chain(cc, result, _DEBUG_INFO_)
|
||||
#else
|
||||
INLINE attr_nonnull(1) void run_call_chain(CallChain *cc, void *result) {
|
||||
if(cc->callback != NULL) {
|
||||
cc->callback(CALLCHAIN_RESULT(cc->ctx, result));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include "replay/struct.h"
|
||||
#include "filewatch/filewatch.h"
|
||||
#include "dynstage.h"
|
||||
#include "eventloop/eventloop.h"
|
||||
|
||||
attr_unused
|
||||
static void taisei_shutdown(void) {
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
#include "taisei.h"
|
||||
|
||||
#include "eventloop/eventloop.h"
|
||||
#include "util/callchain.h"
|
||||
#include "menu/menu.h"
|
||||
#include "cutsceneview.h"
|
||||
#include "common.h"
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "menu.h"
|
||||
#include "global.h"
|
||||
#include "video.h"
|
||||
#include "eventloop/eventloop.h"
|
||||
|
||||
MenuEntry *add_menu_entry(MenuData *menu, const char *name, MenuAction action, void *arg) {
|
||||
MenuEntry *e = dynarray_append(&menu->entries);
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
#include "transition.h"
|
||||
#include "events.h"
|
||||
#include "eventloop/eventloop.h"
|
||||
#include "util/callchain.h"
|
||||
#include "dynarray.h"
|
||||
|
||||
#define IMENU_BLUR 0.05
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include "taisei.h"
|
||||
|
||||
#include "menu.h"
|
||||
#include "eventloop/eventloop.h"
|
||||
#include "util/callchain.h"
|
||||
#include "replay/replay.h"
|
||||
|
||||
void ask_save_replay(Replay *rpy, CallChain next)
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#pragma once
|
||||
#include "taisei.h"
|
||||
|
||||
#include "eventloop/eventloop.h"
|
||||
#include "util/callchain.h"
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "renderer/common/backend.h"
|
||||
#include "taskmanager.h"
|
||||
#include "video.h"
|
||||
#include "eventloop/eventloop.h"
|
||||
|
||||
#include "animation.h"
|
||||
#include "bgm.h"
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include "util/miscmath.h"
|
||||
// #include "util/pngcruft.h"
|
||||
#include "util/stringops.h"
|
||||
#include "util/callchain.h"
|
||||
|
||||
// FIXME: might not be the best place for these
|
||||
#include "log.h"
|
||||
|
|
62
src/util/callchain.h
Normal file
62
src/util/callchain.h
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* This software is licensed under the terms of the MIT License.
|
||||
* See COPYING for further information.
|
||||
* ---
|
||||
* Copyright (c) 2011-2019, Lukas Weber <laochailan@web.de>.
|
||||
* Copyright (c) 2012-2019, Andrei Alexeyev <akari@taisei-project.org>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "taisei.h"
|
||||
|
||||
#ifdef DEBUG_CALLCHAIN
|
||||
#include "util/debug.h"
|
||||
#include "log.h"
|
||||
#endif
|
||||
|
||||
typedef struct CallChainResult {
|
||||
void *ctx;
|
||||
void *result;
|
||||
} CallChainResult;
|
||||
|
||||
typedef struct CallChain {
|
||||
void (*callback)(CallChainResult result);
|
||||
void *ctx;
|
||||
#ifdef DEBUG_CALLCHAIN
|
||||
DebugInfo _debug_;
|
||||
#endif
|
||||
} CallChain;
|
||||
|
||||
#ifdef DEBUG_CALLCHAIN
|
||||
#define CALLCHAIN(callback, ctx) ((CallChain) { (callback), (ctx), _DEBUG_INFO_INITIALIZER_ })
|
||||
#else
|
||||
#define CALLCHAIN(callback, ctx) ((CallChain) { (callback), (ctx) })
|
||||
#endif
|
||||
|
||||
#define NO_CALLCHAIN CALLCHAIN(NULL, NULL)
|
||||
|
||||
#define CALLCHAIN_RESULT(ctx, result) ((CallChainResult) { (ctx), (result) })
|
||||
|
||||
#ifdef DEBUG_CALLCHAIN
|
||||
INLINE attr_nonnull(1) void run_call_chain(CallChain *cc, void *result, DebugInfo caller_dbg) {
|
||||
if(cc->callback != NULL) {
|
||||
log_debug("Calling CC set in %s (%s:%u)",
|
||||
cc->_debug_.func, cc->_debug_.file, cc->_debug_.line);
|
||||
log_debug(" from %s (%s:%u)",
|
||||
caller_dbg.func, caller_dbg.file, caller_dbg.line);
|
||||
cc->callback(CALLCHAIN_RESULT(cc->ctx, result));
|
||||
} else {
|
||||
log_debug("Dead end at %s (%s:%u)",
|
||||
caller_dbg.func, caller_dbg.file, caller_dbg.line
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#define run_call_chain(cc, result) run_call_chain(cc, result, _DEBUG_INFO_)
|
||||
#else
|
||||
INLINE attr_nonnull(1) void run_call_chain(CallChain *cc, void *result) {
|
||||
if(cc->callback != NULL) {
|
||||
cc->callback(CALLCHAIN_RESULT(cc->ctx, result));
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -15,7 +15,7 @@
|
|||
#include "union_public.h"
|
||||
#include "zipfile_public.h"
|
||||
#include "readonly_wrapper_public.h"
|
||||
#include "eventloop/eventloop.h"
|
||||
#include "util/callchain.h"
|
||||
|
||||
typedef struct VFSInfo {
|
||||
uchar error : 1;
|
||||
|
|
Loading…
Reference in a new issue