[RELEASE] u22-v04
This version is submitted for U22 final presentation. (squashed 158 commits)
This commit is contained in:
@@ -4,6 +4,7 @@ add_library(locommon
|
||||
null.c
|
||||
physics.c
|
||||
position.c
|
||||
screen.c
|
||||
ticker.c
|
||||
)
|
||||
target_link_libraries(locommon
|
||||
@@ -13,3 +14,6 @@ target_link_libraries(locommon
|
||||
math
|
||||
mpkutil
|
||||
)
|
||||
add_dependencies(locommon
|
||||
benum-generated
|
||||
)
|
||||
|
@@ -26,6 +26,12 @@ size_t locommon_counter_count(locommon_counter_t* counter) {
|
||||
return counter->next++;
|
||||
}
|
||||
|
||||
void locommon_counter_reset(locommon_counter_t* counter) {
|
||||
assert(counter != NULL);
|
||||
|
||||
counter->next = 0;
|
||||
}
|
||||
|
||||
void locommon_counter_pack(
|
||||
const locommon_counter_t* counter, msgpack_packer* packer) {
|
||||
assert(counter != NULL);
|
||||
|
@@ -25,6 +25,11 @@ locommon_counter_count(
|
||||
locommon_counter_t* counter
|
||||
);
|
||||
|
||||
void
|
||||
locommon_counter_reset(
|
||||
locommon_counter_t* counter
|
||||
);
|
||||
|
||||
void
|
||||
locommon_counter_pack(
|
||||
const locommon_counter_t* counter,
|
||||
|
@@ -5,15 +5,16 @@
|
||||
#include "util/math/vector.h"
|
||||
|
||||
typedef enum {
|
||||
LOCOMMON_INPUT_BUTTON_LEFT = 1 << 0,
|
||||
LOCOMMON_INPUT_BUTTON_RIGHT = 1 << 1,
|
||||
LOCOMMON_INPUT_BUTTON_UP = 1 << 2,
|
||||
LOCOMMON_INPUT_BUTTON_DOWN = 1 << 3,
|
||||
LOCOMMON_INPUT_BUTTON_DASH = 1 << 4,
|
||||
LOCOMMON_INPUT_BUTTON_JUMP = 1 << 5,
|
||||
LOCOMMON_INPUT_BUTTON_ATTACK = 1 << 6,
|
||||
LOCOMMON_INPUT_BUTTON_GUARD = 1 << 7,
|
||||
LOCOMMON_INPUT_BUTTON_MENU = 1 << 8,
|
||||
LOCOMMON_INPUT_BUTTON_LEFT = 1 << 0,
|
||||
LOCOMMON_INPUT_BUTTON_RIGHT = 1 << 1,
|
||||
LOCOMMON_INPUT_BUTTON_DODGE = 1 << 2,
|
||||
LOCOMMON_INPUT_BUTTON_JUMP = 1 << 3,
|
||||
LOCOMMON_INPUT_BUTTON_GUARD = 1 << 4,
|
||||
LOCOMMON_INPUT_BUTTON_SHOOT = 1 << 5,
|
||||
LOCOMMON_INPUT_BUTTON_MENU = 1 << 6,
|
||||
|
||||
LOCOMMON_INPUT_BUTTON_OK = LOCOMMON_INPUT_BUTTON_SHOOT,
|
||||
LOCOMMON_INPUT_BUTTON_CANCEL = LOCOMMON_INPUT_BUTTON_MENU,
|
||||
} locommon_input_button_t;
|
||||
|
||||
typedef uint16_t locommon_input_buttons_t;
|
||||
|
@@ -13,11 +13,17 @@
|
||||
#include "core/locommon/null.h"
|
||||
|
||||
/* THE FOLLOWING INCLUDES DESTROY DEPENDENCY STRUCTURE BETWEEN MODULES. :( */
|
||||
#include "core/lobullet/type.h"
|
||||
#include "core/lochara/state.h"
|
||||
#include "core/lochara/strategy.h"
|
||||
#include "core/lochara/type.h"
|
||||
#include "core/loeffect/effect.h"
|
||||
#include "core/loeffect/generic.h"
|
||||
#include "core/loeffect/recipient.h"
|
||||
#include "core/loeffect/stance.h"
|
||||
#include "core/loentity/entity.h"
|
||||
#include "core/loground/type.h"
|
||||
#include "core/loparticle/misc.h"
|
||||
#include "core/loresource/music.h"
|
||||
#include "core/loresource/sound.h"
|
||||
|
||||
#define LOCOMMON_MSGPACK_PACK_ANY_(packer, v) _Generic((v), \
|
||||
const int32_t*: locommon_msgpack_pack_int32_, \
|
||||
@@ -27,17 +33,30 @@
|
||||
const char*: locommon_msgpack_pack_str_, \
|
||||
const vec2_t*: locommon_msgpack_pack_vec2_, \
|
||||
const vec4_t*: locommon_msgpack_pack_vec4_, \
|
||||
\
|
||||
const lobullet_type_t*: locommon_msgpack_lobullet_type_pack_, \
|
||||
\
|
||||
const lochara_type_t*: locommon_msgpack_lochara_type_pack_, \
|
||||
const lochara_state_t*: locommon_msgpack_lochara_state_pack_, \
|
||||
const lochara_strategy_t*: locommon_msgpack_lochara_strategy_pack_, \
|
||||
\
|
||||
const locommon_counter_t*: locommon_counter_pack, \
|
||||
const locommon_null_t*: locommon_null_pack, \
|
||||
const locommon_position_t*: locommon_position_pack, \
|
||||
const locommon_ticker_t*: locommon_ticker_pack, \
|
||||
\
|
||||
const loeffect_t*: loeffect_pack, \
|
||||
const loeffect_id_t*: locommon_msgpack_loeffect_id_pack_, \
|
||||
const loeffect_t*: loeffect_pack, \
|
||||
const loeffect_generic_immediate_param_t*: loeffect_generic_immediate_param_pack, \
|
||||
const loeffect_generic_lasting_param_t*: loeffect_generic_lasting_param_pack, \
|
||||
const loeffect_recipient_effect_param_t*: loeffect_recipient_effect_param_pack, \
|
||||
const loeffect_stance_set_t*: loeffect_stance_set_pack \
|
||||
const loeffect_generic_lasting_param_t*: loeffect_generic_lasting_param_pack, \
|
||||
const loeffect_recipient_t*: loeffect_recipient_pack, \
|
||||
\
|
||||
const loground_type_t*: locommon_msgpack_loground_type_pack_, \
|
||||
\
|
||||
const loparticle_type_t*: locommon_msgpack_loparticle_type_pack_, \
|
||||
\
|
||||
const loresource_music_id_t*: locommon_msgpack_loresource_music_id_pack_, \
|
||||
const loresource_sound_id_t*: locommon_msgpack_loresource_sound_id_pack_ \
|
||||
)(v, packer)
|
||||
|
||||
#define LOCOMMON_MSGPACK_PACK_ANY(packer, v) \
|
||||
@@ -50,17 +69,30 @@
|
||||
bool*: locommon_msgpack_unpack_bool_, \
|
||||
vec2_t*: locommon_msgpack_unpack_vec2_, \
|
||||
vec4_t*: locommon_msgpack_unpack_vec4_, \
|
||||
\
|
||||
lobullet_type_t*: locommon_msgpack_lobullet_type_unpack_, \
|
||||
\
|
||||
lochara_type_t*: locommon_msgpack_lochara_type_unpack_, \
|
||||
lochara_state_t*: locommon_msgpack_lochara_state_unpack_, \
|
||||
lochara_strategy_t*: locommon_msgpack_lochara_strategy_unpack_, \
|
||||
\
|
||||
locommon_counter_t*: locommon_counter_unpack, \
|
||||
locommon_null_t*: locommon_null_unpack, \
|
||||
locommon_position_t*: locommon_position_unpack, \
|
||||
locommon_ticker_t*: locommon_ticker_unpack, \
|
||||
\
|
||||
loeffect_t*: loeffect_unpack, \
|
||||
loeffect_id_t*: locommon_msgpack_loeffect_id_unpack_, \
|
||||
loeffect_t*: loeffect_unpack, \
|
||||
loeffect_generic_immediate_param_t*: loeffect_generic_immediate_param_unpack, \
|
||||
loeffect_generic_lasting_param_t*: loeffect_generic_lasting_param_unpack, \
|
||||
loeffect_recipient_effect_param_t*: loeffect_recipient_effect_param_unpack, \
|
||||
loeffect_stance_set_t*: loeffect_stance_set_unpack \
|
||||
loeffect_generic_lasting_param_t*: loeffect_generic_lasting_param_unpack, \
|
||||
loeffect_recipient_t*: loeffect_recipient_unpack, \
|
||||
\
|
||||
loground_type_t*: locommon_msgpack_loground_type_unpack_, \
|
||||
\
|
||||
loparticle_type_t*: locommon_msgpack_loparticle_type_unpack_, \
|
||||
\
|
||||
loresource_music_id_t*: locommon_msgpack_loresource_music_id_unpack_, \
|
||||
loresource_sound_id_t*: locommon_msgpack_loresource_sound_id_unpack_ \
|
||||
)(v, obj)
|
||||
|
||||
static inline void locommon_msgpack_pack_int32_(
|
||||
@@ -116,3 +148,49 @@ static inline bool locommon_msgpack_unpack_vec4_(
|
||||
vec4_t* v, const msgpack_object* obj) {
|
||||
return mpkutil_get_vec4(obj, v);
|
||||
}
|
||||
|
||||
#define enum_packer_(name) \
|
||||
static inline void locommon_msgpack_##name##_pack_( \
|
||||
const name##_t* v, msgpack_packer* packer) { \
|
||||
mpkutil_pack_str(packer, name##_stringify(*v)); \
|
||||
}
|
||||
|
||||
#define enum_unpacker_(name) \
|
||||
static inline bool locommon_msgpack_##name##_unpack_( \
|
||||
name##_t* v, const msgpack_object* obj) { \
|
||||
const char* str; \
|
||||
size_t len; \
|
||||
return \
|
||||
mpkutil_get_str(obj, &str, &len) && \
|
||||
name##_unstringify(v, str, len); \
|
||||
}
|
||||
|
||||
enum_packer_(lobullet_type);
|
||||
enum_unpacker_(lobullet_type);
|
||||
|
||||
enum_packer_(lochara_state);
|
||||
enum_unpacker_(lochara_state);
|
||||
|
||||
enum_packer_(lochara_strategy);
|
||||
enum_unpacker_(lochara_strategy);
|
||||
|
||||
enum_packer_(lochara_type);
|
||||
enum_unpacker_(lochara_type);
|
||||
|
||||
enum_packer_(loeffect_id);
|
||||
enum_unpacker_(loeffect_id);
|
||||
|
||||
enum_packer_(loground_type);
|
||||
enum_unpacker_(loground_type);
|
||||
|
||||
enum_packer_(loparticle_type);
|
||||
enum_unpacker_(loparticle_type);
|
||||
|
||||
enum_packer_(loresource_music_id);
|
||||
enum_unpacker_(loresource_music_id);
|
||||
|
||||
enum_packer_(loresource_sound_id);
|
||||
enum_unpacker_(loresource_sound_id);
|
||||
|
||||
#undef enum_packer_
|
||||
#undef enum_unpacker_
|
||||
|
94
core/locommon/screen.c
Normal file
94
core/locommon/screen.c
Normal file
@@ -0,0 +1,94 @@
|
||||
#include "./screen.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "util/math/matrix.h"
|
||||
#include "util/math/vector.h"
|
||||
|
||||
#define CM_PER_INCH_ 2.54f
|
||||
|
||||
#define CHUNK_INCH_ 16
|
||||
#define MAX_SCALE_ (1/.5f)
|
||||
|
||||
bool locommon_screen_valid(const locommon_screen_t* screen) {
|
||||
return
|
||||
screen != NULL &&
|
||||
vec2_valid(&screen->resolution) &&
|
||||
vec2_valid(&screen->dpi) &&
|
||||
screen->resolution.x > 0 &&
|
||||
screen->resolution.y > 0 &&
|
||||
screen->dpi.x > 0 &&
|
||||
screen->dpi.y > 0;
|
||||
}
|
||||
|
||||
void locommon_screen_calc_pixels_from_cm(
|
||||
const locommon_screen_t* screen, vec2_t* pixels, const vec2_t* cm) {
|
||||
assert(locommon_screen_valid(screen));
|
||||
assert(pixels != NULL);
|
||||
assert(vec2_valid(cm));
|
||||
|
||||
locommon_screen_calc_pixels_from_inch(
|
||||
screen, pixels, &vec2(cm->x/CM_PER_INCH_, cm->y/CM_PER_INCH_));
|
||||
}
|
||||
|
||||
void locommon_screen_calc_pixels_from_inch(
|
||||
const locommon_screen_t* screen, vec2_t* pixels, const vec2_t* inch) {
|
||||
assert(locommon_screen_valid(screen));
|
||||
assert(pixels != NULL);
|
||||
assert(vec2_valid(inch));
|
||||
|
||||
*pixels = *inch;
|
||||
|
||||
pixels->x *= screen->dpi.x;
|
||||
pixels->y *= screen->dpi.y;
|
||||
}
|
||||
|
||||
void locommon_screen_calc_winpos_from_cm(
|
||||
const locommon_screen_t* screen, vec2_t* winpos, const vec2_t* cm) {
|
||||
assert(locommon_screen_valid(screen));
|
||||
assert(winpos != NULL);
|
||||
assert(vec2_valid(cm));
|
||||
|
||||
locommon_screen_calc_winpos_from_inch(
|
||||
screen, winpos, &vec2(cm->x/CM_PER_INCH_, cm->y/CM_PER_INCH_));
|
||||
}
|
||||
|
||||
void locommon_screen_calc_winpos_from_inch(
|
||||
const locommon_screen_t* screen, vec2_t* winpos, const vec2_t* inch) {
|
||||
assert(locommon_screen_valid(screen));
|
||||
assert(winpos != NULL);
|
||||
assert(vec2_valid(inch));
|
||||
|
||||
locommon_screen_calc_pixels_from_inch(screen, winpos, inch);
|
||||
winpos->x /= screen->resolution.x / 2;
|
||||
winpos->y /= screen->resolution.y / 2;
|
||||
}
|
||||
|
||||
void locommon_screen_calc_winpos_from_pixels(
|
||||
const locommon_screen_t* screen, vec2_t* winpos, const vec2_t* pixels) {
|
||||
assert(locommon_screen_valid(screen));
|
||||
assert(winpos != NULL);
|
||||
assert(vec2_valid(pixels));
|
||||
|
||||
*winpos = *pixels;
|
||||
winpos->x /= screen->resolution.x / 2;
|
||||
winpos->y /= screen->resolution.y / 2;
|
||||
}
|
||||
|
||||
void locommon_screen_build_projection_matrix(
|
||||
const locommon_screen_t* screen, mat4_t* proj) {
|
||||
assert(screen != NULL);
|
||||
assert(proj != NULL);
|
||||
|
||||
vec2_t scale;
|
||||
locommon_screen_calc_winpos_from_inch(
|
||||
screen, &scale, &vec2(CHUNK_INCH_, CHUNK_INCH_));
|
||||
|
||||
if (scale.x > MAX_SCALE_) {
|
||||
scale.y *= MAX_SCALE_/scale.x;
|
||||
scale.x = MAX_SCALE_;
|
||||
}
|
||||
*proj = mat4_scale(scale.x, scale.y, 1);
|
||||
}
|
57
core/locommon/screen.h
Normal file
57
core/locommon/screen.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "util/math/matrix.h"
|
||||
#include "util/math/vector.h"
|
||||
|
||||
typedef struct {
|
||||
vec2_t resolution;
|
||||
vec2_t dpi;
|
||||
} locommon_screen_t;
|
||||
|
||||
bool
|
||||
locommon_screen_valid(
|
||||
const locommon_screen_t* screen
|
||||
);
|
||||
|
||||
void
|
||||
locommon_screen_calc_pixels_from_cm(
|
||||
const locommon_screen_t* screen,
|
||||
vec2_t* pixels,
|
||||
const vec2_t* cm
|
||||
);
|
||||
|
||||
void
|
||||
locommon_screen_calc_pixels_from_inch(
|
||||
const locommon_screen_t* screen,
|
||||
vec2_t* pixels,
|
||||
const vec2_t* inch
|
||||
);
|
||||
|
||||
void
|
||||
locommon_screen_calc_winpos_from_cm(
|
||||
const locommon_screen_t* screen,
|
||||
vec2_t* winpos,
|
||||
const vec2_t* cm
|
||||
);
|
||||
|
||||
void
|
||||
locommon_screen_calc_winpos_from_inch(
|
||||
const locommon_screen_t* screen,
|
||||
vec2_t* winpos,
|
||||
const vec2_t* inch
|
||||
);
|
||||
|
||||
void
|
||||
locommon_screen_calc_winpos_from_pixels(
|
||||
const locommon_screen_t* screen,
|
||||
vec2_t* winpos,
|
||||
const vec2_t* pixels
|
||||
);
|
||||
|
||||
void
|
||||
locommon_screen_build_projection_matrix(
|
||||
const locommon_screen_t* screen,
|
||||
mat4_t* proj
|
||||
);
|
@@ -22,9 +22,11 @@ void locommon_ticker_tick(locommon_ticker_t* ticker, uint64_t time) {
|
||||
assert(ticker != NULL);
|
||||
assert(ticker->time <= time);
|
||||
|
||||
ticker->delta = time - ticker->time;
|
||||
ticker->delta = time - ticker->time;
|
||||
ticker->delta_f = ticker->delta*1.f / LOCOMMON_TICKER_UNIT;
|
||||
ticker->time = time;
|
||||
|
||||
ticker->prev_time = ticker->time;
|
||||
ticker->time = time;
|
||||
}
|
||||
|
||||
void locommon_ticker_pack(
|
||||
|
@@ -9,6 +9,7 @@
|
||||
|
||||
typedef struct {
|
||||
uint64_t time;
|
||||
uint64_t prev_time;
|
||||
|
||||
int64_t delta;
|
||||
float delta_f;
|
||||
|
Reference in New Issue
Block a user