2020-09-14 00:00:00 +00:00
|
|
|
#include "./context.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
#include "util/flasy/flasy.h"
|
2020-09-14 00:00:00 +00:00
|
|
|
#include "util/glyphas/context.h"
|
|
|
|
#include "util/jukebox/mixer.h"
|
|
|
|
#include "util/math/algorithm.h"
|
|
|
|
#include "util/math/vector.h"
|
|
|
|
|
|
|
|
#include "core/locommon/input.h"
|
2020-10-09 00:00:00 +00:00
|
|
|
#include "core/locommon/screen.h"
|
2020-09-14 00:00:00 +00:00
|
|
|
#include "core/locommon/ticker.h"
|
|
|
|
#include "core/loresource/set.h"
|
|
|
|
#include "core/loshader/set.h"
|
|
|
|
|
|
|
|
#include "./game.h"
|
|
|
|
#include "./param.h"
|
|
|
|
#include "./scene.h"
|
|
|
|
#include "./title.h"
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
#define MIXER_RESERVE_ 256
|
2020-09-14 00:00:00 +00:00
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
#define FLASY_BUFSIZE_ (1024*4) /* = 4 KB */
|
|
|
|
#define FLASY_HANDLERS_ 256
|
2020-09-14 00:00:00 +00:00
|
|
|
|
|
|
|
static const jukebox_format_t loscene_context_mixer_format_ = {
|
|
|
|
.sample_rate = 48000,
|
|
|
|
.channels = 2,
|
|
|
|
};
|
|
|
|
|
|
|
|
static loscene_t* loscene_context_create_start_scene_(loscene_context_t* ctx) {
|
|
|
|
assert(ctx != NULL);
|
|
|
|
|
|
|
|
if (ctx->param.skip_title) {
|
2020-10-09 00:00:00 +00:00
|
|
|
return loscene_game_new(ctx, true /* = load */);
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|
2020-10-09 00:00:00 +00:00
|
|
|
return loscene_title_new(ctx);
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
void loscene_context_initialize(
|
|
|
|
loscene_context_t* ctx, const loscene_param_t* param) {
|
|
|
|
assert(ctx != NULL);
|
2020-09-14 00:00:00 +00:00
|
|
|
assert(param != NULL);
|
|
|
|
|
|
|
|
*ctx = (typeof(*ctx)) {
|
|
|
|
.param = *param,
|
|
|
|
};
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
ctx->flasy = flasy_new(FLASY_BUFSIZE_, FLASY_HANDLERS_);
|
|
|
|
|
2020-09-14 00:00:00 +00:00
|
|
|
glyphas_context_initialize(&ctx->glyphas);
|
|
|
|
|
|
|
|
ctx->mixer = jukebox_mixer_new(
|
2020-10-09 00:00:00 +00:00
|
|
|
&loscene_context_mixer_format_, MIXER_RESERVE_);
|
2020-09-14 00:00:00 +00:00
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
ctx->screen = (typeof(ctx->screen)) {
|
|
|
|
.resolution = vec2(param->width, param->height),
|
|
|
|
.dpi = param->dpi,
|
|
|
|
};
|
2020-09-14 00:00:00 +00:00
|
|
|
locommon_ticker_initialize(&ctx->ticker, 0);
|
|
|
|
|
|
|
|
loresource_set_initialize(
|
|
|
|
&ctx->resources,
|
|
|
|
ctx->mixer,
|
|
|
|
&loscene_context_mixer_format_,
|
|
|
|
LORESOURCE_LANGUAGE_JP);
|
|
|
|
|
|
|
|
loshader_set_initialize(
|
|
|
|
&ctx->shaders,
|
2020-10-09 00:00:00 +00:00
|
|
|
&ctx->screen,
|
2020-09-14 00:00:00 +00:00
|
|
|
param->max_msaa);
|
|
|
|
|
|
|
|
ctx->scene = loscene_context_create_start_scene_(ctx);
|
|
|
|
}
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
void loscene_context_deinitialize(loscene_context_t* ctx) {
|
|
|
|
assert(ctx != NULL);
|
2020-09-14 00:00:00 +00:00
|
|
|
|
|
|
|
/* Firstly delete the mixer working in other thread. */
|
|
|
|
jukebox_mixer_delete(ctx->mixer);
|
|
|
|
|
|
|
|
loscene_delete(ctx->scene);
|
|
|
|
|
|
|
|
loshader_set_deinitialize(&ctx->shaders);
|
|
|
|
loresource_set_deinitialize(&ctx->resources);
|
|
|
|
|
|
|
|
locommon_ticker_deinitialize(&ctx->ticker);
|
|
|
|
|
|
|
|
glyphas_context_deinitialize(&ctx->glyphas);
|
|
|
|
|
2020-10-09 00:00:00 +00:00
|
|
|
flasy_delete(ctx->flasy);
|
2020-09-14 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool loscene_context_update(
|
|
|
|
loscene_context_t* ctx, const locommon_input_t* input, uint64_t uptime) {
|
|
|
|
assert(ctx != NULL);
|
|
|
|
assert(input != NULL);
|
|
|
|
|
|
|
|
locommon_ticker_tick(&ctx->ticker, uptime);
|
|
|
|
|
|
|
|
loscene_t* s = loscene_update(ctx->scene, input);
|
|
|
|
if (s != ctx->scene) {
|
|
|
|
loscene_delete(ctx->scene);
|
|
|
|
ctx->scene = s;
|
|
|
|
}
|
|
|
|
return ctx->scene != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void loscene_context_draw(loscene_context_t* ctx) {
|
|
|
|
assert(ctx != NULL);
|
|
|
|
|
|
|
|
loscene_draw(ctx->scene);
|
|
|
|
}
|