[RELEASE] u22-v04
This version is submitted for U22 final presentation. (squashed 158 commits)
This commit is contained in:
@@ -16,8 +16,10 @@ target_link_libraries(loscene
|
||||
locommon
|
||||
loentity
|
||||
loground
|
||||
loparticle
|
||||
loplayer
|
||||
loresource
|
||||
loshader
|
||||
loui
|
||||
loworld
|
||||
)
|
||||
|
@@ -5,13 +5,14 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "util/flasy/flasy.h"
|
||||
#include "util/glyphas/context.h"
|
||||
#include "util/jukebox/mixer.h"
|
||||
#include "util/math/algorithm.h"
|
||||
#include "util/math/vector.h"
|
||||
#include "util/memory/memory.h"
|
||||
|
||||
#include "core/locommon/input.h"
|
||||
#include "core/locommon/screen.h"
|
||||
#include "core/locommon/ticker.h"
|
||||
#include "core/loresource/set.h"
|
||||
#include "core/loshader/set.h"
|
||||
@@ -21,21 +22,10 @@
|
||||
#include "./scene.h"
|
||||
#include "./title.h"
|
||||
|
||||
struct loscene_context_t {
|
||||
glyphas_context_t glyphas;
|
||||
jukebox_mixer_t* mixer;
|
||||
#define MIXER_RESERVE_ 256
|
||||
|
||||
locommon_ticker_t ticker;
|
||||
|
||||
loresource_set_t resources;
|
||||
loshader_set_t shaders;
|
||||
|
||||
loscene_t* scene;
|
||||
|
||||
loscene_param_t param;
|
||||
};
|
||||
|
||||
#define loscene_context_mixer_reserve_ 256
|
||||
#define FLASY_BUFSIZE_ (1024*4) /* = 4 KB */
|
||||
#define FLASY_HANDLERS_ 256
|
||||
|
||||
static const jukebox_format_t loscene_context_mixer_format_ = {
|
||||
.sample_rate = 48000,
|
||||
@@ -45,29 +35,32 @@ static const jukebox_format_t loscene_context_mixer_format_ = {
|
||||
static loscene_t* loscene_context_create_start_scene_(loscene_context_t* ctx) {
|
||||
assert(ctx != NULL);
|
||||
|
||||
/* Unless the context is deleted, scenes can hold a pointer to ctx->param. */
|
||||
|
||||
if (ctx->param.skip_title) {
|
||||
return loscene_game_new(
|
||||
&ctx->param, &ctx->resources, &ctx->shaders, &ctx->ticker, true);
|
||||
return loscene_game_new(ctx, true /* = load */);
|
||||
}
|
||||
return loscene_title_new(
|
||||
&ctx->param, &ctx->resources, &ctx->shaders, &ctx->ticker);
|
||||
return loscene_title_new(ctx);
|
||||
}
|
||||
|
||||
loscene_context_t* loscene_context_new(const loscene_param_t* param) {
|
||||
void loscene_context_initialize(
|
||||
loscene_context_t* ctx, const loscene_param_t* param) {
|
||||
assert(ctx != NULL);
|
||||
assert(param != NULL);
|
||||
|
||||
loscene_context_t* ctx = memory_new(sizeof(*ctx));
|
||||
*ctx = (typeof(*ctx)) {
|
||||
.param = *param,
|
||||
};
|
||||
|
||||
ctx->flasy = flasy_new(FLASY_BUFSIZE_, FLASY_HANDLERS_);
|
||||
|
||||
glyphas_context_initialize(&ctx->glyphas);
|
||||
|
||||
ctx->mixer = jukebox_mixer_new(
|
||||
&loscene_context_mixer_format_, loscene_context_mixer_reserve_);
|
||||
&loscene_context_mixer_format_, MIXER_RESERVE_);
|
||||
|
||||
ctx->screen = (typeof(ctx->screen)) {
|
||||
.resolution = vec2(param->width, param->height),
|
||||
.dpi = param->dpi,
|
||||
};
|
||||
locommon_ticker_initialize(&ctx->ticker, 0);
|
||||
|
||||
loresource_set_initialize(
|
||||
@@ -78,17 +71,14 @@ loscene_context_t* loscene_context_new(const loscene_param_t* param) {
|
||||
|
||||
loshader_set_initialize(
|
||||
&ctx->shaders,
|
||||
param->width,
|
||||
param->height,
|
||||
¶m->dpi,
|
||||
&ctx->screen,
|
||||
param->max_msaa);
|
||||
|
||||
ctx->scene = loscene_context_create_start_scene_(ctx);
|
||||
return ctx;
|
||||
}
|
||||
|
||||
void loscene_context_delete(loscene_context_t* ctx) {
|
||||
if (ctx == NULL) return;
|
||||
void loscene_context_deinitialize(loscene_context_t* ctx) {
|
||||
assert(ctx != NULL);
|
||||
|
||||
/* Firstly delete the mixer working in other thread. */
|
||||
jukebox_mixer_delete(ctx->mixer);
|
||||
@@ -102,7 +92,7 @@ void loscene_context_delete(loscene_context_t* ctx) {
|
||||
|
||||
glyphas_context_deinitialize(&ctx->glyphas);
|
||||
|
||||
memory_delete(ctx);
|
||||
flasy_delete(ctx->flasy);
|
||||
}
|
||||
|
||||
bool loscene_context_update(
|
||||
|
@@ -3,23 +3,44 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "util/flasy/flasy.h"
|
||||
#include "util/glyphas/context.h"
|
||||
#include "util/jukebox/mixer.h"
|
||||
#include "util/math/vector.h"
|
||||
|
||||
#include "core/locommon/input.h"
|
||||
#include "core/locommon/ticker.h"
|
||||
#include "core/loresource/set.h"
|
||||
#include "core/loshader/set.h"
|
||||
|
||||
#include "./param.h"
|
||||
#include "./scene.h"
|
||||
|
||||
struct loscene_context_t;
|
||||
typedef struct loscene_context_t loscene_context_t;
|
||||
typedef struct {
|
||||
flasy_t* flasy;
|
||||
glyphas_context_t glyphas;
|
||||
jukebox_mixer_t* mixer;
|
||||
|
||||
loscene_context_t* /* OWNERSHIP */
|
||||
loscene_context_new(
|
||||
locommon_screen_t screen;
|
||||
locommon_ticker_t ticker;
|
||||
|
||||
loresource_set_t resources;
|
||||
loshader_set_t shaders;
|
||||
|
||||
loscene_t* scene;
|
||||
|
||||
loscene_param_t param;
|
||||
} loscene_context_t;
|
||||
|
||||
void
|
||||
loscene_context_initialize(
|
||||
loscene_context_t* ctx,
|
||||
const loscene_param_t* param
|
||||
);
|
||||
|
||||
void
|
||||
loscene_context_delete(
|
||||
loscene_context_t* ctx /* OWNERSHIP */
|
||||
loscene_context_deinitialize(
|
||||
loscene_context_t* ctx
|
||||
);
|
||||
|
||||
bool
|
||||
|
@@ -18,23 +18,21 @@
|
||||
#include "util/mpkutil/get.h"
|
||||
#include "util/mpkutil/pack.h"
|
||||
|
||||
#include "core/lobullet/pool.h"
|
||||
#include "core/locharacter/pool.h"
|
||||
#include "core/lochara/pool.h"
|
||||
#include "core/lochara/player.h"
|
||||
#include "core/locommon/counter.h"
|
||||
#include "core/locommon/screen.h"
|
||||
#include "core/locommon/ticker.h"
|
||||
#include "core/loentity/store.h"
|
||||
#include "core/loground/pool.h"
|
||||
#include "core/loplayer/camera.h"
|
||||
#include "core/loplayer/player.h"
|
||||
#include "core/loresource/set.h"
|
||||
#include "core/loshader/set.h"
|
||||
#include "core/loui/ui.h"
|
||||
#include "core/loworld/environment.h"
|
||||
#include "core/loworld/generator.h"
|
||||
#include "core/loworld/poolset.h"
|
||||
#include "core/loworld/store.h"
|
||||
#include "core/loworld/template.h"
|
||||
#include "core/loworld/view.h"
|
||||
|
||||
#include "./context.h"
|
||||
#include "./param.h"
|
||||
#include "./scene.h"
|
||||
#include "./title.h"
|
||||
@@ -42,10 +40,7 @@
|
||||
typedef struct {
|
||||
loscene_t header;
|
||||
|
||||
const loscene_param_t* param;
|
||||
const locommon_ticker_t* app_ticker;
|
||||
loresource_set_t* res;
|
||||
loshader_set_t* shaders;
|
||||
loscene_context_t* ctx;
|
||||
|
||||
uint64_t app_begin_time;
|
||||
uint64_t begin_time;
|
||||
@@ -54,7 +49,6 @@ typedef struct {
|
||||
locommon_ticker_t ticker;
|
||||
|
||||
loentity_store_t* entities;
|
||||
|
||||
loplayer_t player;
|
||||
loworld_poolset_t pools;
|
||||
|
||||
@@ -63,42 +57,21 @@ typedef struct {
|
||||
loworld_view_t* view;
|
||||
loworld_environment_t environment;
|
||||
|
||||
/* temporary parameters */
|
||||
loui_t ui;
|
||||
|
||||
bool updated;
|
||||
mat4_t proj;
|
||||
mat4_t camera;
|
||||
} loscene_game_t;
|
||||
|
||||
#define LOSCENE_GAME_MAX_DELTA_TIME 500
|
||||
#define MAX_DELTA_TIME_ 500
|
||||
|
||||
#define LOSCENE_GAME_SCALE 4.0f
|
||||
#define ENTITY_STORE_RESERVE_ 256
|
||||
#define WORLD_STORE_CHUNK_RESERVE_ 64
|
||||
|
||||
#define LOSCENE_GAME_ENTITY_STORE_RESERVE 256
|
||||
#define LOSCENE_GAME_WORLD_STORE_CHUNK_RESERVE 64
|
||||
#define LOSCENE_GAME_BULLETS_PER_CHUNK 64
|
||||
|
||||
#define LOSCENE_GAME_DATA_BASEPATH "./data/"
|
||||
|
||||
#define LOSCENE_GAME_DATA_FILE_PATH \
|
||||
(LOSCENE_GAME_DATA_BASEPATH"game.msgpack")
|
||||
#define LOSCENE_GAME_WORLD_STORE_BASEPATH \
|
||||
(LOSCENE_GAME_DATA_BASEPATH"world/")
|
||||
|
||||
static void loscene_game_build_projection_matrix_(loscene_game_t* s) {
|
||||
assert(s != NULL);
|
||||
|
||||
static const float chunk_inch = 16;
|
||||
static const float max_scale = 1/.5f;
|
||||
|
||||
float yscale = s->shaders->dpi.y*chunk_inch/s->shaders->resolution.y*2;
|
||||
float xscale = s->shaders->dpi.x*chunk_inch/s->shaders->resolution.x*2;
|
||||
|
||||
if (xscale > max_scale) {
|
||||
yscale *= max_scale/xscale;
|
||||
xscale = max_scale;
|
||||
}
|
||||
|
||||
s->proj = mat4_scale(xscale, yscale, 1);
|
||||
}
|
||||
#define DATA_BASEPATH_ "./data/"
|
||||
#define DATA_FILE_PATH_ DATA_BASEPATH_"game.msgpack"
|
||||
#define WORLD_STORE_BASEPATH_ DATA_BASEPATH_"world/"
|
||||
|
||||
static void loscene_game_convert_viewport_pos_to_chunk_pos_(
|
||||
loscene_game_t* s, locommon_position_t* pos, const vec2_t* vpos) {
|
||||
@@ -106,7 +79,7 @@ static void loscene_game_convert_viewport_pos_to_chunk_pos_(
|
||||
assert(locommon_position_valid(pos));
|
||||
|
||||
mat4_t m, inv;
|
||||
mat4_mul(&m, &s->proj, &s->player.camera.matrix);
|
||||
mat4_mul(&m, &s->proj, &mat4_identity());
|
||||
mat4_inv(&inv, &m);
|
||||
|
||||
vec4_t disp4;
|
||||
@@ -117,9 +90,8 @@ static void loscene_game_convert_viewport_pos_to_chunk_pos_(
|
||||
locommon_position_reduce(pos);
|
||||
}
|
||||
|
||||
static bool loscene_game_load_(loscene_game_t* scene) {
|
||||
assert(scene != NULL);
|
||||
/* ! Please note that world and view objects may be invalid now. ! */
|
||||
static bool loscene_game_load_(loscene_game_t* s) {
|
||||
assert(s != NULL);
|
||||
|
||||
bool ret = false;
|
||||
|
||||
@@ -129,7 +101,7 @@ static bool loscene_game_load_(loscene_game_t* scene) {
|
||||
msgpack_unpacked unpacked;
|
||||
msgpack_unpacked_init(&unpacked);
|
||||
|
||||
FILE* fp = fopen(LOSCENE_GAME_DATA_FILE_PATH, "rb");
|
||||
FILE* fp = fopen(DATA_FILE_PATH_, "rb");
|
||||
if (fp == NULL) goto FINALIZE;
|
||||
|
||||
const bool loaded =
|
||||
@@ -141,10 +113,22 @@ static bool loscene_game_load_(loscene_game_t* scene) {
|
||||
|
||||
# define item_(v) mpkutil_get_map_item_by_str(root, v)
|
||||
|
||||
if (!loplayer_unpack(&scene->player, item_("player")) ||
|
||||
!loworld_generator_unpack(scene->generator, item_("generator")) ||
|
||||
!locommon_ticker_unpack(&scene->ticker, item_("ticker")) ||
|
||||
!locommon_counter_unpack(&scene->idgen, item_("idgen"))) {
|
||||
const msgpack_object* player = item_("player");
|
||||
s->player.entity = lochara_pool_unpack_item(
|
||||
s->pools.chara,
|
||||
mpkutil_get_map_item_by_str(mpkutil_get_map(player), "entity"));
|
||||
if (s->player.entity == NULL) goto FINALIZE;
|
||||
|
||||
if (s->player.entity->param.type != LOCHARA_TYPE_PLAYER) {
|
||||
loentity_delete(&s->player.entity->super.super);
|
||||
s->player.entity = NULL;
|
||||
goto FINALIZE;
|
||||
}
|
||||
|
||||
if (!loplayer_unpack(&s->player, player) ||
|
||||
!loworld_generator_unpack(s->generator, item_("generator")) ||
|
||||
!locommon_ticker_unpack(&s->ticker, item_("ticker")) ||
|
||||
!locommon_counter_unpack(&s->idgen, item_("idgen"))) {
|
||||
goto FINALIZE;
|
||||
}
|
||||
|
||||
@@ -155,7 +139,7 @@ FINALIZE:
|
||||
msgpack_unpacked_destroy(&unpacked);
|
||||
msgpack_unpacker_destroy(&unpacker);
|
||||
|
||||
scene->begin_time = scene->ticker.time;
|
||||
s->begin_time = s->ticker.time;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -167,7 +151,7 @@ static bool loscene_game_save_(loscene_game_t* scene) {
|
||||
loworld_view_flush_store(scene->view);
|
||||
if (loworld_store_is_error_happened(scene->world)) ret = false;
|
||||
|
||||
FILE* fp = fopen(LOSCENE_GAME_DATA_FILE_PATH, "wb");
|
||||
FILE* fp = fopen(DATA_FILE_PATH_, "wb");
|
||||
if (fp == NULL) return false;
|
||||
|
||||
msgpack_packer pk;
|
||||
@@ -199,19 +183,16 @@ static void loscene_game_delete_(loscene_t* scene) {
|
||||
fprintf(stderr, "failed to save game data\n");
|
||||
}
|
||||
|
||||
loui_deinitialize(&s->ui);
|
||||
|
||||
loworld_environment_deinitialize(&s->environment);
|
||||
loworld_view_delete(s->view);
|
||||
loworld_store_delete(s->world);
|
||||
loworld_generator_delete(s->generator);
|
||||
|
||||
loentity_store_clear(s->entities);
|
||||
|
||||
locharacter_pool_delete(s->pools.character);
|
||||
loworld_poolset_deinitialize(&s->pools);
|
||||
loplayer_deinitialize(&s->player);
|
||||
|
||||
lobullet_pool_delete(s->pools.bullet);
|
||||
loground_pool_delete(s->pools.ground);
|
||||
|
||||
loentity_store_delete(s->entities);
|
||||
|
||||
locommon_ticker_deinitialize(&s->ticker);
|
||||
@@ -228,26 +209,34 @@ static loscene_t* loscene_game_update_(
|
||||
loscene_game_t* s = (typeof(s)) scene;
|
||||
s->updated = false;
|
||||
|
||||
const uint64_t t = s->app_ticker->time - s->app_begin_time + s->begin_time;
|
||||
const uint64_t t =
|
||||
s->ctx->ticker.time - s->app_begin_time + s->begin_time;
|
||||
locommon_ticker_tick(&s->ticker, t);
|
||||
if (s->ticker.delta > LOSCENE_GAME_MAX_DELTA_TIME) {
|
||||
if (s->ticker.delta > MAX_DELTA_TIME_) {
|
||||
fprintf(stderr, "1 tick took too long (%"PRId64" ms)\n", s->ticker.delta);
|
||||
return scene;
|
||||
}
|
||||
|
||||
s->player.camera.base_brightness = s->ctx->param.brightness;
|
||||
loplayer_camera_build_matrix(&s->player.camera, &s->camera);
|
||||
|
||||
locommon_position_t cursor = s->player.camera.pos;
|
||||
loscene_game_convert_viewport_pos_to_chunk_pos_(s, &cursor, &input->cursor);
|
||||
|
||||
loplayer_update(&s->player, input, &cursor);
|
||||
if (loplayer_menu_is_exit_requested(s->player.menu)) {
|
||||
return loscene_title_new(s->param, s->res, s->shaders, s->app_ticker);
|
||||
}
|
||||
const bool grabbed = loui_is_grabbing_input(&s->ui);
|
||||
loplayer_update(
|
||||
&s->player,
|
||||
grabbed? NULL: input,
|
||||
grabbed? NULL: &cursor);
|
||||
|
||||
loworld_view_look(s->view, &s->player.camera.pos);
|
||||
loworld_view_update(s->view);
|
||||
|
||||
loworld_environment_update(&s->environment);
|
||||
|
||||
loui_update(&s->ui, input);
|
||||
if (s->ui.menu.request_exit) return loscene_title_new(s->ctx);
|
||||
|
||||
s->updated = true;
|
||||
return scene;
|
||||
}
|
||||
@@ -258,51 +247,42 @@ static void loscene_game_draw_(loscene_t* scene) {
|
||||
loscene_game_t* s = (typeof(s)) scene;
|
||||
if (!s->updated) return;
|
||||
|
||||
const loshader_uniblock_param_t p = {
|
||||
.proj = s->proj,
|
||||
.cam = s->player.camera.matrix,
|
||||
.pos = s->player.camera.pos,
|
||||
.time = s->ticker.time%60000/1000.0f,
|
||||
};
|
||||
loshader_uniblock_update_param(s->shaders->uniblock, &p);
|
||||
loshader_posteffect_drawer_set_param(
|
||||
&s->ctx->shaders.drawer.posteffect,
|
||||
&(loshader_posteffect_drawer_param_t) { .brightness_whole = 1, });
|
||||
|
||||
loshader_set_clear_all(s->shaders);
|
||||
loshader_uniblock_update_param(
|
||||
&s->ctx->shaders.uniblock,
|
||||
&(loshader_uniblock_param_t) {
|
||||
.proj = s->proj,
|
||||
.cam = s->camera,
|
||||
.pos = s->player.camera.pos,
|
||||
.time = s->ticker.time%60000/1000.f,
|
||||
});
|
||||
|
||||
loshader_set_clear_all(&s->ctx->shaders);
|
||||
|
||||
s->ctx->shaders.drawer.pixsort.intensity = s->player.camera.pixsort;
|
||||
loshader_posteffect_drawer_set_param(
|
||||
&s->ctx->shaders.drawer.posteffect, &s->player.camera.posteffect);
|
||||
|
||||
loworld_environment_draw(&s->environment);
|
||||
loworld_view_draw(s->view);
|
||||
loplayer_draw(&s->player);
|
||||
|
||||
loshader_set_draw_all(s->shaders);
|
||||
}
|
||||
loui_draw(&s->ui);
|
||||
|
||||
static void loscene_game_execute_tests_(
|
||||
const loscene_game_t* scene, const loscene_param_t* param) {
|
||||
assert(scene != NULL);
|
||||
assert(param != NULL);
|
||||
|
||||
if (param->test.loworld_poolset_packing) {
|
||||
loworld_poolset_test_packing(&scene->pools);
|
||||
}
|
||||
if (param->test.loplayer_packing) {
|
||||
loplayer_test_packing(&scene->player);
|
||||
}
|
||||
loshader_set_draw_all(&s->ctx->shaders);
|
||||
}
|
||||
|
||||
loscene_t* loscene_game_new(
|
||||
const loscene_param_t* param,
|
||||
loresource_set_t* res,
|
||||
loshader_set_t* shaders,
|
||||
const locommon_ticker_t* ticker,
|
||||
bool load) {
|
||||
assert(param != NULL);
|
||||
assert(shaders != NULL);
|
||||
assert(res != NULL);
|
||||
assert(ticker != NULL);
|
||||
loscene_context_t* ctx,
|
||||
bool load) {
|
||||
assert(ctx != NULL);
|
||||
|
||||
loshader_set_drop_cache(shaders);
|
||||
loshader_set_drop_cache(&ctx->shaders);
|
||||
|
||||
loscene_game_t* scene = memory_new(sizeof(*scene));
|
||||
*scene = (typeof(*scene)) {
|
||||
loscene_game_t* s = memory_new(sizeof(*s));
|
||||
*s = (typeof(*s)) {
|
||||
.header = {
|
||||
.vtable = {
|
||||
.delete = loscene_game_delete_,
|
||||
@@ -310,89 +290,80 @@ loscene_t* loscene_game_new(
|
||||
.draw = loscene_game_draw_,
|
||||
},
|
||||
},
|
||||
.param = param,
|
||||
.app_ticker = ticker,
|
||||
.res = res,
|
||||
.shaders = shaders,
|
||||
.app_begin_time = ticker->time,
|
||||
.ctx = ctx,
|
||||
.app_begin_time = ctx->ticker.time,
|
||||
};
|
||||
loscene_game_build_projection_matrix_(scene);
|
||||
locommon_screen_build_projection_matrix(&s->ctx->screen, &s->proj);
|
||||
|
||||
locommon_counter_initialize(&scene->idgen, 0);
|
||||
locommon_ticker_initialize(&scene->ticker, 0);
|
||||
locommon_counter_initialize(&s->idgen, 0);
|
||||
locommon_ticker_initialize(&s->ticker, 0);
|
||||
|
||||
scene->entities = loentity_store_new(
|
||||
LOSCENE_GAME_ENTITY_STORE_RESERVE);
|
||||
|
||||
scene->pools.ground = loground_pool_new(
|
||||
scene->shaders->drawer.ground,
|
||||
&scene->idgen,
|
||||
LOSCENE_GAME_WORLD_STORE_CHUNK_RESERVE*
|
||||
LOWORLD_TEMPLATE_MAX_CHARACTERS_PER_CHUNK);
|
||||
|
||||
scene->pools.bullet = lobullet_pool_new(
|
||||
res,
|
||||
scene->shaders->drawer.bullet,
|
||||
&scene->idgen,
|
||||
&scene->ticker,
|
||||
scene->entities,
|
||||
LOSCENE_GAME_WORLD_STORE_CHUNK_RESERVE*
|
||||
LOSCENE_GAME_BULLETS_PER_CHUNK);
|
||||
s->entities = loentity_store_new(ENTITY_STORE_RESERVE_);
|
||||
|
||||
loplayer_initialize(
|
||||
&scene->player,
|
||||
locommon_counter_count(&scene->idgen), /* = Absolutely 0 */
|
||||
res,
|
||||
scene->shaders,
|
||||
&scene->ticker,
|
||||
scene->pools.bullet,
|
||||
scene->entities,
|
||||
&scene->proj);
|
||||
scene->player.camera.brightness = param->brightness/1000.f;
|
||||
&s->player,
|
||||
&s->ctx->screen,
|
||||
&s->ticker,
|
||||
s->entities);
|
||||
|
||||
scene->pools.character = locharacter_pool_new(
|
||||
res,
|
||||
scene->shaders->drawer.character,
|
||||
&scene->idgen,
|
||||
&scene->ticker,
|
||||
scene->pools.bullet,
|
||||
scene->entities,
|
||||
&scene->player,
|
||||
LOSCENE_GAME_WORLD_STORE_CHUNK_RESERVE*
|
||||
LOWORLD_TEMPLATE_MAX_CHARACTERS_PER_CHUNK);
|
||||
loworld_poolset_initialize(
|
||||
&s->pools,
|
||||
&s->ctx->resources,
|
||||
&s->ctx->shaders,
|
||||
&s->idgen,
|
||||
&s->ticker,
|
||||
s->entities,
|
||||
&s->player,
|
||||
WORLD_STORE_CHUNK_RESERVE_);
|
||||
|
||||
scene->generator = loworld_generator_new(
|
||||
&scene->pools,
|
||||
scene->app_ticker->time*98641 /* = prime number */);
|
||||
/* id is always 0 */
|
||||
|
||||
s->generator = loworld_generator_new(
|
||||
&s->pools,
|
||||
s->ctx->ticker.time*98641 /* = prime number */);
|
||||
|
||||
if (load) {
|
||||
if (!loscene_game_load_(scene)) {
|
||||
fprintf(stderr, "failed to load game data\n");
|
||||
}
|
||||
load = loscene_game_load_(s);
|
||||
if (!load) fprintf(stderr, "failed to load game data\n");
|
||||
}
|
||||
if (!load) {
|
||||
locommon_counter_reset(&s->idgen);
|
||||
s->player.entity = lochara_pool_create(s->pools.chara);
|
||||
lochara_player_build(s->player.entity);
|
||||
}
|
||||
s->player.entity->super.super.dont_save = true;
|
||||
loentity_store_add(s->entities, &s->player.entity->super.super);
|
||||
|
||||
scene->world = loworld_store_new(
|
||||
&scene->pools,
|
||||
scene->generator,
|
||||
LOSCENE_GAME_WORLD_STORE_CHUNK_RESERVE,
|
||||
LOSCENE_GAME_WORLD_STORE_BASEPATH,
|
||||
strlen(LOSCENE_GAME_WORLD_STORE_BASEPATH));
|
||||
s->world = loworld_store_new(
|
||||
s->ctx->flasy,
|
||||
&s->pools,
|
||||
s->generator,
|
||||
WORLD_STORE_CHUNK_RESERVE_,
|
||||
WORLD_STORE_BASEPATH_,
|
||||
strlen(WORLD_STORE_BASEPATH_));
|
||||
|
||||
scene->view = loworld_view_new(
|
||||
scene->world,
|
||||
scene->entities,
|
||||
&scene->player.camera.pos);
|
||||
s->view = loworld_view_new(
|
||||
s->world,
|
||||
s->entities,
|
||||
&locommon_position(0, 0, vec2(.5f, .5f)));
|
||||
|
||||
loworld_environment_initialize(
|
||||
&scene->environment,
|
||||
res,
|
||||
scene->shaders,
|
||||
&scene->ticker,
|
||||
scene->view,
|
||||
&scene->player,
|
||||
¶m->environment);
|
||||
&s->environment,
|
||||
&s->ctx->resources,
|
||||
&s->ctx->shaders,
|
||||
&s->ticker,
|
||||
&s->player,
|
||||
s->view,
|
||||
&s->ctx->param.environment);
|
||||
|
||||
loscene_game_execute_tests_(scene, param);
|
||||
loui_initialize(
|
||||
&s->ui,
|
||||
&s->ctx->resources,
|
||||
&s->ctx->shaders,
|
||||
&s->ctx->screen,
|
||||
&s->ticker,
|
||||
&s->player,
|
||||
s->view);
|
||||
|
||||
return &scene->header;
|
||||
return &s->header;
|
||||
}
|
||||
|
@@ -1,17 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "core/locommon/ticker.h"
|
||||
#include "core/loresource/set.h"
|
||||
#include "core/loshader/set.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "./param.h"
|
||||
#include "./context.h"
|
||||
#include "./scene.h"
|
||||
|
||||
loscene_t* /* OWNERSHIP */
|
||||
loscene_game_new(
|
||||
const loscene_param_t* param,
|
||||
loresource_set_t* res,
|
||||
loshader_set_t* shaders,
|
||||
const locommon_ticker_t* ticker,
|
||||
bool load
|
||||
loscene_context_t* ctx,
|
||||
bool load
|
||||
);
|
||||
|
@@ -18,9 +18,4 @@ typedef struct {
|
||||
loworld_environment_config_t environment;
|
||||
|
||||
bool skip_title;
|
||||
|
||||
struct {
|
||||
bool loworld_poolset_packing;
|
||||
bool loplayer_packing;
|
||||
} test;
|
||||
} loscene_param_t;
|
||||
|
@@ -9,7 +9,6 @@
|
||||
#include <msgpack.h>
|
||||
#include <msgpack/fbuffer.h>
|
||||
|
||||
#include "util/chaos/xorshift.h"
|
||||
#include "util/glyphas/block.h"
|
||||
#include "util/glyphas/cache.h"
|
||||
#include "util/jukebox/amp.h"
|
||||
@@ -22,13 +21,12 @@
|
||||
#include "core/locommon/input.h"
|
||||
#include "core/locommon/position.h"
|
||||
#include "core/loresource/music.h"
|
||||
#include "core/loresource/set.h"
|
||||
#include "core/loresource/text.h"
|
||||
#include "core/loshader/backwall.h"
|
||||
#include "core/loshader/fog.h"
|
||||
#include "core/loshader/menu_text.h"
|
||||
#include "core/loshader/set.h"
|
||||
|
||||
#include "./context.h"
|
||||
#include "./game.h"
|
||||
#include "./param.h"
|
||||
#include "./scene.h"
|
||||
@@ -44,10 +42,7 @@ typedef enum {
|
||||
typedef struct {
|
||||
loscene_t header;
|
||||
|
||||
const loscene_param_t* param;
|
||||
loresource_set_t* res;
|
||||
loshader_set_t* shaders;
|
||||
const locommon_ticker_t* ticker;
|
||||
loscene_context_t* ctx;
|
||||
|
||||
struct {
|
||||
vec2_t fontsz_large;
|
||||
@@ -68,7 +63,7 @@ typedef struct {
|
||||
glyphas_block_t* buttons;
|
||||
} text;
|
||||
|
||||
loresource_music_player_t* music;
|
||||
loresource_music_t* music;
|
||||
|
||||
loscene_title_state_t state;
|
||||
uint64_t since;
|
||||
@@ -80,29 +75,25 @@ typedef struct {
|
||||
static void loscene_title_calculate_geometry_(loscene_title_t* s) {
|
||||
assert(s != NULL);
|
||||
|
||||
const vec2_t* dpi = &s->shaders->dpi;
|
||||
const vec2_t* reso = &s->shaders->resolution;
|
||||
|
||||
s->geo.fontpx_large = *dpi;
|
||||
vec2_muleq(&s->geo.fontpx_large, .8f);
|
||||
|
||||
s->geo.fontpx_small = *dpi;
|
||||
vec2_muleq(&s->geo.fontpx_small, .14f);
|
||||
|
||||
# define px_to_disp_(v) vec2((v).x/reso->x*2, (v).y/reso->y*2)
|
||||
|
||||
s->geo.fontsz_large = px_to_disp_(s->geo.fontpx_large);
|
||||
s->geo.fontsz_small = px_to_disp_(s->geo.fontpx_small);
|
||||
|
||||
# undef px_to_disp_
|
||||
locommon_screen_calc_pixels_from_inch(
|
||||
&s->ctx->screen, &s->geo.fontpx_large, &vec2(.8f, .8f));
|
||||
locommon_screen_calc_pixels_from_inch(
|
||||
&s->ctx->screen, &s->geo.fontpx_small, &vec2(.14f, .14f));
|
||||
locommon_screen_calc_winpos_from_pixels(
|
||||
&s->ctx->screen, &s->geo.fontsz_large, &s->geo.fontpx_large);
|
||||
locommon_screen_calc_winpos_from_pixels(
|
||||
&s->ctx->screen, &s->geo.fontsz_small, &s->geo.fontpx_small);
|
||||
}
|
||||
|
||||
static void loscene_title_create_text_block_(loscene_title_t* s) {
|
||||
assert(s != NULL);
|
||||
|
||||
const char* title = loresource_text_get(s->res->lang, "app_name");
|
||||
const char* author = loresource_text_get(s->res->lang, "title_authors");
|
||||
const char* buttons = loresource_text_get(s->res->lang, "title_buttons");
|
||||
const char* title =
|
||||
loresource_text_get(s->ctx->resources.lang, "app_name");
|
||||
const char* author =
|
||||
loresource_text_get(s->ctx->resources.lang, "title_authors");
|
||||
const char* buttons =
|
||||
loresource_text_get(s->ctx->resources.lang, "title_buttons");
|
||||
|
||||
static const vec4_t color = vec4(1, 1, 1, 1);
|
||||
|
||||
@@ -132,7 +123,7 @@ static void loscene_title_create_text_block_(loscene_title_t* s) {
|
||||
s->text.buttons, s->font.small, &color, buttons, strlen(buttons));
|
||||
|
||||
const vec2_t scale = vec2(
|
||||
2/s->shaders->resolution.x, 2/s->shaders->resolution.y);
|
||||
2/s->ctx->screen.resolution.x, 2/s->ctx->screen.resolution.y);
|
||||
glyphas_block_scale(s->text.title, &scale);
|
||||
glyphas_block_scale(s->text.author, &scale);
|
||||
glyphas_block_scale(s->text.buttons, &scale);
|
||||
@@ -152,16 +143,17 @@ static void loscene_title_update_uniblock_(loscene_title_t* s) {
|
||||
|
||||
static const uint64_t camspeed = 5000;
|
||||
|
||||
const uint64_t chunk = s->ticker->time/camspeed;
|
||||
const float fract = s->ticker->time%camspeed*1.f/camspeed;
|
||||
const uint64_t chunk = s->ctx->ticker.time/camspeed;
|
||||
const float fract = s->ctx->ticker.time%camspeed*1.f/camspeed;
|
||||
|
||||
const loshader_uniblock_param_t p = {
|
||||
.proj = mat4_identity(),
|
||||
.cam = mat4_identity(),
|
||||
.pos = locommon_position(chunk, 0, vec2(fract, 0)),
|
||||
.time = s->ticker->time%60000/1000.0f,
|
||||
};
|
||||
loshader_uniblock_update_param(s->shaders->uniblock, &p);
|
||||
loshader_uniblock_update_param(
|
||||
&s->ctx->shaders.uniblock,
|
||||
&(loshader_uniblock_param_t) {
|
||||
.proj = mat4_identity(),
|
||||
.cam = mat4_identity(),
|
||||
.pos = locommon_position(chunk, 0, vec2(fract, 0)),
|
||||
.time = s->ctx->ticker.time%60000/1000.0f,
|
||||
});
|
||||
}
|
||||
|
||||
static void loscene_title_delete_(loscene_t* scene) {
|
||||
@@ -189,47 +181,47 @@ static loscene_t* loscene_title_update_(
|
||||
loscene_title_t* s = (typeof(s)) scene;
|
||||
|
||||
if (s->music == NULL) {
|
||||
s->music = &s->res->music.title;
|
||||
s->music = loresource_music_set_get(
|
||||
&s->ctx->resources.music, LORESOURCE_MUSIC_ID_TITLE);
|
||||
jukebox_decoder_play(s->music->decoder, &rational(0, 1), true);
|
||||
jukebox_amp_change_volume(&s->music->amp, 1, &rational(1, 1));
|
||||
}
|
||||
|
||||
switch (s->state) {
|
||||
case LOSCENE_TITLE_STATE_EXPECT_BUTTON_RELEASE:
|
||||
s->fade = 1 - (s->ticker->time - s->since)*1.f / fadedur;
|
||||
s->fade = 1 - (s->ctx->ticker.time - s->since)*1.f / fadedur;
|
||||
if (s->fade < 0) s->fade = 0;
|
||||
if (input->buttons == 0 && s->fade <= 0) {
|
||||
s->state = LOSCENE_TITLE_STATE_EXPECT_BUTTON_PRESS;
|
||||
}
|
||||
break;
|
||||
case LOSCENE_TITLE_STATE_EXPECT_BUTTON_PRESS:
|
||||
if (input->buttons & LOCOMMON_INPUT_BUTTON_ATTACK) {
|
||||
if (input->buttons & LOCOMMON_INPUT_BUTTON_OK) {
|
||||
jukebox_amp_change_volume(&s->music->amp, 0, &rational(fadedur, 1000));
|
||||
jukebox_decoder_stop_after(s->music->decoder, &rational(fadedur, 1000));
|
||||
|
||||
s->state = LOSCENE_TITLE_STATE_FADING_TO_GAME;
|
||||
s->since = s->ticker->time;
|
||||
s->since = s->ctx->ticker.time;
|
||||
} else if (input->buttons & LOCOMMON_INPUT_BUTTON_MENU) {
|
||||
jukebox_amp_change_volume(&s->music->amp, 0, &rational(fadedur, 1000));
|
||||
jukebox_decoder_stop_after(s->music->decoder, &rational(fadedur, 1000));
|
||||
|
||||
s->state = LOSCENE_TITLE_STATE_FADING_TO_EXIT;
|
||||
s->since = s->ticker->time;
|
||||
s->since = s->ctx->ticker.time;
|
||||
}
|
||||
break;
|
||||
case LOSCENE_TITLE_STATE_FADING_TO_GAME:
|
||||
if (s->since + fadedur < s->ticker->time) {
|
||||
return loscene_game_new(
|
||||
s->param, s->res, s->shaders, s->ticker, true /* = load data */);
|
||||
if (s->since + fadedur < s->ctx->ticker.time) {
|
||||
return loscene_game_new(s->ctx, true /* = load data */);
|
||||
} else {
|
||||
s->fade = (s->ticker->time - s->since)*1.f/fadedur;
|
||||
s->fade = (s->ctx->ticker.time - s->since)*1.f/fadedur;
|
||||
}
|
||||
break;
|
||||
case LOSCENE_TITLE_STATE_FADING_TO_EXIT:
|
||||
if (s->since + fadedur < s->ticker->time) {
|
||||
if (s->since + fadedur < s->ctx->ticker.time) {
|
||||
return NULL;
|
||||
} else {
|
||||
s->fade = (s->ticker->time - s->since)*1.f/fadedur;
|
||||
s->fade = (s->ctx->ticker.time - s->since)*1.f/fadedur;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -242,63 +234,56 @@ static void loscene_title_draw_(loscene_t* scene) {
|
||||
loscene_title_t* s = (typeof(s)) scene;
|
||||
loscene_title_update_uniblock_(s);
|
||||
|
||||
loshader_set_clear_all(s->shaders);
|
||||
loshader_set_clear_all(&s->ctx->shaders);
|
||||
|
||||
loshader_backwall_drawer_set_param(
|
||||
s->shaders->drawer.backwall,
|
||||
&s->ctx->shaders.drawer.backwall,
|
||||
&(loshader_backwall_drawer_param_t) {
|
||||
.type = LOSHADER_BACKWALL_TYPE_JAIL,
|
||||
.transition = 1,
|
||||
});
|
||||
|
||||
loshader_fog_drawer_set_param(
|
||||
s->shaders->drawer.fog,
|
||||
&s->ctx->shaders.drawer.fog,
|
||||
&(loshader_fog_drawer_param_t) {
|
||||
.type = LOSHADER_FOG_TYPE_WHITE_CLOUD,
|
||||
.transition = 1,
|
||||
});
|
||||
|
||||
loshader_pixsort_drawer_set_intensity(s->shaders->drawer.pixsort, 0);
|
||||
s->ctx->shaders.drawer.pixsort.intensity = 0;
|
||||
|
||||
loshader_posteffect_drawer_set_param(
|
||||
s->shaders->drawer.posteffect,
|
||||
&s->ctx->shaders.drawer.posteffect,
|
||||
&(loshader_posteffect_drawer_param_t) {
|
||||
.whole_blur = 1,
|
||||
.radial_displacement = .05f,
|
||||
.amnesia_displacement = .1f,
|
||||
.radial_fade = .5f + s->fade*.3f,
|
||||
.brightness = s->param->brightness/1000.f,
|
||||
.blur_whole = 1,
|
||||
.distortion_radial = .05f,
|
||||
.distortion_amnesia = .1f,
|
||||
.fade_radial = .5f + s->fade*.3f,
|
||||
.brightness_whole = s->ctx->param.brightness/1000.f,
|
||||
});
|
||||
|
||||
s->shaders->drawer.menu_text.alpha = 1;
|
||||
s->ctx->shaders.drawer.menu_text.alpha = 1;
|
||||
loshader_menu_text_drawer_add_block(
|
||||
&s->shaders->drawer.menu_text, s->text.title);
|
||||
&s->ctx->shaders.drawer.menu_text, s->text.title);
|
||||
loshader_menu_text_drawer_add_block(
|
||||
&s->shaders->drawer.menu_text, s->text.author);
|
||||
&s->ctx->shaders.drawer.menu_text, s->text.author);
|
||||
loshader_menu_text_drawer_add_block(
|
||||
&s->shaders->drawer.menu_text, s->text.buttons);
|
||||
&s->ctx->shaders.drawer.menu_text, s->text.buttons);
|
||||
|
||||
loshader_cinescope_drawer_set_param(
|
||||
s->shaders->drawer.cinescope,
|
||||
&s->ctx->shaders.drawer.cinescope,
|
||||
&(loshader_cinescope_drawer_param_t) {0});
|
||||
|
||||
loshader_set_draw_all(s->shaders);
|
||||
loshader_set_draw_all(&s->ctx->shaders);
|
||||
}
|
||||
|
||||
loscene_t* loscene_title_new(
|
||||
const loscene_param_t* param,
|
||||
loresource_set_t* res,
|
||||
loshader_set_t* shaders,
|
||||
const locommon_ticker_t* ticker) {
|
||||
assert(param != NULL);
|
||||
assert(res != NULL);
|
||||
assert(shaders != NULL);
|
||||
assert(ticker != NULL);
|
||||
loscene_t* loscene_title_new(loscene_context_t* ctx) {
|
||||
assert(ctx != NULL);
|
||||
|
||||
loshader_set_drop_cache(shaders);
|
||||
loshader_set_drop_cache(&ctx->shaders);
|
||||
|
||||
loscene_title_t* scene = memory_new(sizeof(*scene));
|
||||
*scene = (typeof(*scene)) {
|
||||
loscene_title_t* s = memory_new(sizeof(*s));
|
||||
*s = (typeof(*s)) {
|
||||
.header = {
|
||||
.vtable = {
|
||||
.delete = loscene_title_delete_,
|
||||
@@ -306,28 +291,25 @@ loscene_t* loscene_title_new(
|
||||
.draw = loscene_title_draw_,
|
||||
},
|
||||
},
|
||||
.param = param,
|
||||
.res = res,
|
||||
.shaders = shaders,
|
||||
.ticker = ticker,
|
||||
.ctx = ctx,
|
||||
|
||||
.state = LOSCENE_TITLE_STATE_EXPECT_BUTTON_RELEASE,
|
||||
.since = ticker->time,
|
||||
.since = ctx->ticker.time,
|
||||
};
|
||||
loscene_title_calculate_geometry_(scene);
|
||||
loscene_title_calculate_geometry_(s);
|
||||
|
||||
scene->font = (typeof(scene->font)) {
|
||||
s->font = (typeof(s->font)) {
|
||||
.large = glyphas_cache_new(
|
||||
shaders->tex.menu_text,
|
||||
&res->font.sans,
|
||||
scene->geo.fontpx_large.x,
|
||||
scene->geo.fontpx_large.y),
|
||||
s->ctx->shaders.tex.menu_text,
|
||||
&s->ctx->resources.font.sans,
|
||||
s->geo.fontpx_large.x,
|
||||
s->geo.fontpx_large.y),
|
||||
.small = glyphas_cache_new(
|
||||
shaders->tex.menu_text,
|
||||
&res->font.sans,
|
||||
scene->geo.fontpx_small.x,
|
||||
scene->geo.fontpx_small.y),
|
||||
s->ctx->shaders.tex.menu_text,
|
||||
&s->ctx->resources.font.sans,
|
||||
s->geo.fontpx_small.x,
|
||||
s->geo.fontpx_small.y),
|
||||
};
|
||||
loscene_title_create_text_block_(scene);
|
||||
return &scene->header;
|
||||
loscene_title_create_text_block_(s);
|
||||
return &s->header;
|
||||
}
|
||||
|
@@ -1,16 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "core/locommon/ticker.h"
|
||||
#include "core/loresource/set.h"
|
||||
#include "core/loshader/set.h"
|
||||
|
||||
#include "./param.h"
|
||||
#include "./context.h"
|
||||
#include "./scene.h"
|
||||
|
||||
loscene_t* /* OWNERSHIP */
|
||||
loscene_title_new(
|
||||
const loscene_param_t* param,
|
||||
loresource_set_t* res,
|
||||
loshader_set_t* shaders,
|
||||
const locommon_ticker_t* ticker
|
||||
loscene_context_t* ctx
|
||||
);
|
||||
|
Reference in New Issue
Block a user