From 4972e4091cd7f0660589a790e6e1a12b4ca35b3b Mon Sep 17 00:00:00 2001 From: korenkonder Date: Sun, 8 Oct 2023 13:39:44 +0300 Subject: [PATCH] Small refactor --- src/CRE/object.cpp | 14 +- src/CRE/shader.cpp | 4 +- src/CRE/task_effect.cpp | 4 +- src/CRE/texture.cpp | 42 +-- src/KKdLib/dds.cpp | 14 +- src/KKdLib/dds.hpp | 2 + src/KKdLib/default.hpp | 108 ++++--- src/KKdLib/key_val.cpp | 2 +- src/KKdLib/obj.cpp | 10 +- src/KKdLib/pv_db.hpp | 401 +++++++++++++------------- src/KKdLib/txp.cpp | 6 +- src/KKdLib/txp.hpp | 2 + src/ReDIVA/classes/glitter_editor.cpp | 30 +- 13 files changed, 322 insertions(+), 317 deletions(-) diff --git a/src/CRE/object.cpp b/src/CRE/object.cpp index 104f18d5..cad538a9 100644 --- a/src/CRE/object.cpp +++ b/src/CRE/object.cpp @@ -1037,11 +1037,11 @@ void object_material_msgpack_read(const char* path, const char* set_name, do for (uint32_t i = 0; i < tex->mipmaps_count; i++) { txp_mipmap tex_mip; - tex_mip.width = max_def(d.width >> i, 1); - tex_mip.height = max_def(d.height >> i, 1); + tex_mip.width = max_def(d.width >> i, 1u); + tex_mip.height = max_def(d.height >> i, 1u); tex_mip.format = d.format; - uint32_t size = txp::get_size(tex_mip.format, tex_mip.width, tex_mip.height); + uint32_t size = tex_mip.get_size(); tex_mip.size = size; tex_mip.data.resize(size); memcpy(tex_mip.data.data(), d.data[index], size); @@ -1108,11 +1108,11 @@ void object_material_msgpack_read(const char* path, const char* set_name, do for (uint32_t i = 0; i < tex->mipmaps_count; i++) { txp_mipmap tex_mip; - tex_mip.width = max_def(d.width >> i, 1); - tex_mip.height = max_def(d.height >> i, 1); + tex_mip.width = max_def(d.width >> i, 1u); + tex_mip.height = max_def(d.height >> i, 1u); tex_mip.format = d.format; - uint32_t size = txp::get_size(tex_mip.format, tex_mip.width, tex_mip.height); + uint32_t size = tex_mip.get_size(); tex_mip.size = size; tex_mip.data.resize(size); memcpy(tex_mip.data.data(), d.data[index], size); @@ -1433,7 +1433,7 @@ void object_material_msgpack_write(const char* path, const char* set_name, uint3 uint32_t index = 0; do for (uint32_t j = 0; j < tex.mipmaps_count; j++) { - uint32_t size = txp::get_size(format, max_def(width >> j, 1), max_def(height >> j, 1)); + uint32_t size = txp::get_size(format, max_def(width >> j, 1u), max_def(height >> j, 1u)); void* data = force_malloc(size); memcpy(data, tex.mipmaps[index].data.data(), size); d.data.push_back(data); diff --git a/src/CRE/shader.cpp b/src/CRE/shader.cpp index 11c0d595..d4280c2a 100644 --- a/src/CRE/shader.cpp +++ b/src/CRE/shader.cpp @@ -665,7 +665,7 @@ void shader_set_data::load(farc* f, bool ignore_cache, size_t bin_count = program_data_binary.size(); size_t bin_size = sizeof(uint64_t) * 2 + bin_count * sizeof(program_binary); for (program_binary& k : program_data_binary) - bin_size += align_val(k.length, 0x04ULL); + bin_size += align_val(k.length, 0x04); shader_cache_file->data = force_malloc(bin_size); shader_cache_file->size = bin_size; shader_cache_file->data_changed = true; @@ -681,7 +681,7 @@ void shader_set_data::load(farc* f, bool ignore_cache, bin->binary = bin_data - bin_data_base; memcpy((void*)bin_data, (void*)k.binary, k.length); bin_data_base += sizeof(program_binary); - bin_data += align_val(k.length, 0x04ULL); + bin_data += align_val(k.length, 0x04); void* binary = (void*)k.binary; free_def(binary); k.binary = 0; diff --git a/src/CRE/task_effect.cpp b/src/CRE/task_effect.cpp index bffbe177..55b3af89 100644 --- a/src/CRE/task_effect.cpp +++ b/src/CRE/task_effect.cpp @@ -2816,7 +2816,7 @@ void rain_particle_draw() { float_t tangent_size = -rain->psize.y * (float_t)(1.0 / 30.0); int32_t first = 0; - int32_t count = min_def(rain->num_rain, rain_ptcl_count) / 2 / 4 * 6; + int32_t count = min_def(rain->num_rain, (int32_t)rain_ptcl_count) / 2 / 4 * 6; vec4 color = rain->color; float_t color_a = color.w; @@ -2973,7 +2973,7 @@ void snow_particle_draw() { snow_gpu_ssbo.Bind(0); int32_t count = snow->num_snow_gpu / 4; - count = min_def(count, snow_ptcl_count / 4) * 6; + count = min_def(count, (int32_t)snow_ptcl_count / 4) * 6; int32_t first = 0; for (particle_data& i : snow_ptcl_gpu) { diff --git a/src/CRE/texture.cpp b/src/CRE/texture.cpp index a27acbbe..f3f60f29 100644 --- a/src/CRE/texture.cpp +++ b/src/CRE/texture.cpp @@ -13,12 +13,10 @@ static void texture_bind(GLenum target, GLuint texture); static void texture_get_format_type_by_internal_format(GLenum internal_format, GLenum* format, GLenum* type); -static uint32_t texture_get_height_align_mip_level(texture* tex, int32_t mip_level); static uint32_t texture_get_height_mip_level(texture* tex, int32_t mip_level); static GLuint texture_get_working_internal_format(GLuint internal_format); static int32_t texture_get_size(GLenum internal_format, int32_t width, int32_t height); static int32_t texture_get_size_mip_level(texture* tex, int32_t mip_level); -static uint32_t texture_get_width_align_mip_level(texture* tex, int32_t mip_level); static uint32_t texture_get_width_mip_level(texture* tex, int32_t mip_level); static int32_t texture_load(GLenum target, GLenum internal_format, int32_t width, int32_t height, int32_t level, void* data); @@ -35,19 +33,17 @@ tex(), target(), internal_format(), max_mipmap_level(), size() { } uint32_t texture::get_height_align_mip_level(uint8_t mip_level) { - uint32_t height = this->height >> mip_level; if (flags & TEXTURE_BLOCK_COMPRESSION) - return max_def(height, 4); + return max_def((uint32_t)height >> mip_level, 4u); else - return max_def(height, 1); + return max_def((uint32_t)height >> mip_level, 1u); } uint32_t texture::get_width_align_mip_level(uint8_t mip_level) { - uint32_t width = this->width >> mip_level; if (flags & TEXTURE_BLOCK_COMPRESSION) - return max_def(width, 4); + return max_def((uint32_t)width >> mip_level, 4u); else - return max_def(width, 1); + return max_def((uint32_t)width >> mip_level, 1u); } texture* texture_init(texture_id id) { @@ -69,8 +65,8 @@ void texture_apply_color_tone(texture* chg_tex, if (!data) break; - int32_t width_align = texture_get_width_align_mip_level(org_tex, i); - int32_t height_align = texture_get_height_align_mip_level(org_tex, i); + int32_t width_align = org_tex->get_width_align_mip_level(i); + int32_t height_align = org_tex->get_height_align_mip_level(i); if (org_tex->flags & TEXTURE_BLOCK_COMPRESSION) { texture_bind(org_tex->target, org_tex->tex); glGetCompressedTexImage(org_tex->target, i, data); @@ -560,16 +556,8 @@ static void texture_get_format_type_by_internal_format(GLenum internal_format, G *type = _type; } -inline static uint32_t texture_get_height_align_mip_level(texture* tex, int32_t mip_level) { - uint32_t height = tex->height >> mip_level; - if (tex->flags & TEXTURE_BLOCK_COMPRESSION) - return max_def(height, 4); - return max_def(height, 1); -} - inline static uint32_t texture_get_height_mip_level(texture* tex, int32_t mip_level) { - uint32_t height = tex->height >> mip_level; - return max_def(height, 1); + return max_def((uint32_t)tex->height >> mip_level, 1u); } inline static GLuint texture_get_working_internal_format(GLuint internal_format) { @@ -633,21 +621,13 @@ static int32_t texture_get_size(GLenum internal_format, int32_t width, int32_t h } inline static int32_t texture_get_size_mip_level(texture* tex, int32_t mip_level) { - int32_t width = tex->width >> mip_level; - int32_t height = tex->height >> mip_level; - return texture_get_size(tex->internal_format, max_def(width, 1), max_def(height, 1)); -} - -inline static uint32_t texture_get_width_align_mip_level(texture* tex, int32_t mip_level) { - uint32_t width = tex->width >> mip_level; - if (tex->flags & TEXTURE_BLOCK_COMPRESSION) - return max_def(width, 4); - return max_def(width, 1); + return texture_get_size(tex->internal_format, + texture_get_width_mip_level(tex, mip_level), + texture_get_height_mip_level(tex, mip_level)); } inline static uint32_t texture_get_width_mip_level(texture* tex, int32_t mip_level) { - uint32_t width = tex->width >> mip_level; - return max_def(width, 1); + return max_def((uint32_t)tex->width >> mip_level, 1u); } static int32_t texture_load(GLenum target, GLenum internal_format, diff --git a/src/KKdLib/dds.cpp b/src/KKdLib/dds.cpp index 597bdb51..c5519989 100644 --- a/src/KKdLib/dds.cpp +++ b/src/KKdLib/dds.cpp @@ -265,10 +265,7 @@ void dds::read(const wchar_t* path) { do for (uint32_t i = 0; i < mipmaps_count; i++) { - uint32_t width = max_def(this->width >> i, 1); - uint32_t height = max_def(this->height >> i, 1); - uint32_t size = txp::get_size(format, - max_def(this->width >> i, 1), max_def(this->height >> i, 1)); + uint32_t size = get_size(i); void* data = force_malloc(size); s.read(data, size); if (reverse) @@ -370,8 +367,7 @@ void dds::write(const wchar_t* path) { uint32_t index = 0; do for (uint32_t i = 0; i < mipmaps_count; i++) { - uint32_t size = txp::get_size(format, - max_def(width >> i, 1), max_def(height >> i, 1)); + uint32_t size = get_size(i); void* data = force_malloc(size); memcpy(data, this->data[index], size); dds_reverse_rgb(format, size, (uint8_t*)data); @@ -384,6 +380,12 @@ void dds::write(const wchar_t* path) { free_def(path_dds); } +uint32_t dds::get_size(uint32_t mip_level) { + return txp::get_size(format, + max_def(width >> mip_level, 1u), + max_def(height >> mip_level, 1u)); +} + static void dds_reverse_rgb(txp_format format, size_t size, uint8_t* data) { uint8_t l, r, g, b, a; switch (format) { diff --git a/src/KKdLib/dds.hpp b/src/KKdLib/dds.hpp index ef83e401..a2c8c009 100644 --- a/src/KKdLib/dds.hpp +++ b/src/KKdLib/dds.hpp @@ -23,4 +23,6 @@ struct dds { void read(const wchar_t* path); void write(const char* path); void write(const wchar_t* path); + + uint32_t get_size(uint32_t mip_level = 0); }; diff --git a/src/KKdLib/default.hpp b/src/KKdLib/default.hpp index f3474a21..84251d3b 100644 --- a/src/KKdLib/default.hpp +++ b/src/KKdLib/default.hpp @@ -20,74 +20,100 @@ #pragma warning( push ) #pragma warning( disable: 26812 ) -#define free_def(ptr) \ -{ \ - if (ptr) \ - free(ptr); \ - (ptr) = 0; \ +template +inline void free_def(T& ptr) { + if (ptr) + free(ptr); + ptr = 0; } -#define null(t) \ -struct null_##t { \ - bool has_value; \ - t value; \ +template +struct null_def { + bool has_value; + T value; }; -null(bool) -null(int8_t) -null(uint8_t) -null(int16_t) -null(uint16_t) -null(int32_t) -null(uint32_t) -null(int64_t) -null(uint64_t) -null(float_t) -null(double_t) -null(size_t) -null(ssize_t) +template +inline T max_def(const T left, const U right) { + return left > right ? left : right; +} -#define max_def(a, b) (((a) > (b)) ? (a) : (b)) +template +inline T min_def(const T left, const U right) { + return left < right ? left : right; +} -#define min_def(a, b) (((a) < (b)) ? (a) : (b)) +template +inline T mult_min_max_def(const T value, const U pos_scale, const U neg_scale) { + return (value >= (T)0) ? (value * pos_scale) : (value * neg_scale); +} -#define mult_min_max_def(a, b, c) (((a) >= 0) ? ((a) * (b)) : ((a) * (c))) +template +inline T div_min_max_def(const T value, const U pos_scale, const U neg_scale) { + return (value >= (T)0) ? (value / pos_scale) : (value / neg_scale); +} -#define div_min_max_def(a, b, c) (((a) >= 0) ? ((a) / (b)) : ((a) / (c))) +template +inline T clamp_def(const T value, const U min, const V max) { + return min_def(max_def(value, min), max); +} -#define clamp_def(a, b, c) (((((a) > (b)) ? (a) : (b)) < (c)) ? (((a) > (b)) ? (a) : (b)) : (c)) +template +inline T align_val(const T value, const U align) { + return (value + align - (T)1) / align * align; +} -#define align_val(a, b) ((((a) + (b) - 1) / (b)) * (b)) - -#define align_val_divide(a, b, c) (((a) + (b) - 1) / (c)) +template +inline T align_val_divide(const T value, const U align, const V div) { + return (value + align - (T)1) / div; +} #define BUF_SIZE 4096 -#define RAD_TO_DEG (180.0 / M_PI) +#define RAD_TO_DEG ((double_t)(180.0 / M_PI)) -#define DEG_TO_RAD (M_PI / 180.0) +#define DEG_TO_RAD ((double_t)(M_PI / 180.0)) #define RAD_TO_DEG_FLOAT ((float_t)(180.0 / M_PI)) #define DEG_TO_RAD_FLOAT ((float_t)(M_PI / 180.0)) -#define ctgf(x) (1.0f / tanf(x)) +inline float __CRTDECL ctgf(float _X) { + return 1.0f / tanf(_X); +} -#define ctghf(x) (1.0f / tanhf(x)) +inline float __CRTDECL ctghf(float _X) { + return 1.0f / tanhf(_X); +} -#define actgf(x) (1.0f / atanf(x)) +inline float __CRTDECL actgf(float _X) { + return 1.0f / atanf(_X); +} -#define actghf(x) (1.0f / atanhf(x)) +inline float __CRTDECL actghf(float _X) { + return 1.0f / atanhf(_X); +} -#define ctg(x) (1.0 / tan(x)) +inline double __CRTDECL ctg(double _X) { + return 1.0 / tan(_X); +} -#define ctgh(x) (1.0 / tanh(x)) +inline double __CRTDECL ctgh(double _X) { + return 1.0 / tanh(_X); +} -#define actg(x) (1.0 / atan(x)) +inline double __CRTDECL actg(double _X) { + return 1.0 / atan(_X); +} -#define actgh(x) (1.0 / atanh(x)) +inline double __CRTDECL actgh(double _X) { + return 1.0 / atanh(_X); +} -#define lerp_def(x, y, blend) ((1.0f - (blend)) * (x) + (blend) * (y)) +template +inline T lerp_def(T x, T y, U blend) { + return ((U)1 - blend) * x + blend * y; +} extern void* force_malloc(size_t size); diff --git a/src/KKdLib/key_val.cpp b/src/KKdLib/key_val.cpp index a84ab3f1..248bb5e5 100644 --- a/src/KKdLib/key_val.cpp +++ b/src/KKdLib/key_val.cpp @@ -283,7 +283,7 @@ void key_val::parse(const void* data, size_t size) { curr_scope->count = key.size(); key_val_sort(this); - free_def(lines) + free_def(lines); } bool key_val::read(bool& value) { diff --git a/src/KKdLib/obj.cpp b/src/KKdLib/obj.cpp index 33b79de3..79b4414e 100644 --- a/src/KKdLib/obj.cpp +++ b/src/KKdLib/obj.cpp @@ -1117,7 +1117,7 @@ static obj_skin_block_expression* obj_move_data_skin_block_expression(const obj_ exp_dst->name_index = exp_src->name_index; uint32_t num_expression = exp_src->num_expression; - num_expression = min_def(num_expression, 9); + num_expression = min_def(num_expression, 9u); exp_dst->num_expression = num_expression; for (uint32_t i = 0; i < num_expression; i++) exp_dst->expression_array[i] = obj_move_data_string(exp_src->expression_array[i], alloc); @@ -3189,7 +3189,7 @@ static obj_skin_block_expression* obj_classic_read_skin_block_expression( free_def(name); uint32_t num_expression = s.read_uint32_t(); - num_expression = min_def(num_expression, 9); + num_expression = min_def(num_expression, 9u); exp->num_expression = num_expression; for (uint32_t i = 0; i < num_expression; i++) { uint32_t expression_offset = s.read_uint32_t(); @@ -3213,7 +3213,7 @@ static void obj_classic_write_skin_block_expression(obj_skin_block_expression* e s.write_uint32_t((uint32_t)name_offset); uint32_t num_expression = exp->num_expression; - num_expression = min_def(num_expression, 9); + num_expression = min_def(num_expression, 9u); s.write_int32_t(num_expression); for (uint32_t i = 0; i < num_expression; i++) { int64_t expression_offset = obj_skin_strings_get_string_offset(strings, @@ -7263,7 +7263,7 @@ static obj_skin_block_expression* obj_modern_read_skin_block_expression( free_def(name); uint32_t num_expression = s.read_uint32_t_reverse_endianness(); - num_expression = min_def(num_expression, 9); + num_expression = min_def(num_expression, 9u); exp->num_expression = num_expression; if (!is_x) for (uint32_t i = 0; i < num_expression; i++) { @@ -7295,7 +7295,7 @@ static void obj_modern_write_skin_block_expression(obj_skin_block_expression* ex s.write_offset(name_offset, 0x20, is_x); uint32_t num_expression = exp->num_expression; - num_expression = min_def(num_expression, 9); + num_expression = min_def(num_expression, 9u); s.write_int32_t_reverse_endianness(num_expression); if (!is_x) { for (uint32_t i = 0; i < num_expression; i++) { diff --git a/src/KKdLib/pv_db.hpp b/src/KKdLib/pv_db.hpp index 86946ccb..d8f313c6 100644 --- a/src/KKdLib/pv_db.hpp +++ b/src/KKdLib/pv_db.hpp @@ -147,26 +147,22 @@ struct pv_db_another_song_aft500 { }; struct pv_db_auth_replace_by_module { - null_int32_t id; - null_int32_t module_id; + null_def id; + null_def module_id; std::string name; std::string org_name; }; -null(chara_index) - struct pv_db_chrcam { - null_chara_index chara; + null_def chara; - null_int32_t id; + null_def id; std::string name; std::string org_name; }; -null(pv_db_chreff_type) - struct pv_db_chreff_data { - null_pv_db_chreff_type type; + null_def type; std::string Name; }; @@ -174,52 +170,50 @@ struct pv_db_chreff_data { struct pv_db_chreff { std::vector data; - null_int32_t id; + null_def id; std::string name; }; struct pv_db_chrmot { - null_chara_index chara; + null_def chara; - null_int32_t id; + null_def id; std::string name; std::string org_name; }; struct pv_db_disp2d_ac200 { std::string set_name; - null_int32_t target_shadow_type; - null_int32_t title_end_2d_field; - null_int32_t title_end_2d_low_field; // not AC200 - null_int32_t title_end_3d_field; - null_int32_t title_start_2d_field; - null_int32_t title_start_2d_low_field; // not AC200 - null_int32_t title_start_3d_field; + null_def target_shadow_type; + null_def title_end_2d_field; + null_def title_end_2d_low_field; // not AC200 + null_def title_end_3d_field; + null_def title_start_2d_field; + null_def title_start_2d_low_field; // not AC200 + null_def title_start_3d_field; }; struct pv_db_disp2d_aft210 { std::string set_name; - null_int32_t target_shadow_type; - null_int32_t title_2d_layer; - null_int32_t title_end_2d_field; - null_int32_t title_end_2d_low_field; - null_int32_t title_end_3d_field; - null_int32_t title_start_2d_field; - null_int32_t title_start_2d_low_field; - null_int32_t title_start_3d_field; + null_def target_shadow_type; + null_def title_2d_layer; + null_def title_end_2d_field; + null_def title_end_2d_low_field; + null_def title_end_3d_field; + null_def title_start_2d_field; + null_def title_start_2d_low_field; + null_def title_start_3d_field; }; -null(pv_db_duet_type) - struct pv_db_duet { - null_pv_db_duet_type type; - null_int32_t num; + null_def type; + null_def num; }; struct pv_db_eyes_rot_rate { - null_chara_index chr; - null_float_t xn_rate; - null_float_t xp_rate; + null_def chr; + null_def xn_rate; + null_def xp_rate; }; struct pv_db_ex_auth { @@ -228,17 +222,17 @@ struct pv_db_ex_auth { }; struct pv_db_ex_song_ac101 { - null_chara_index chara; + null_def chara; std::string file; std::string name; }; struct pv_db_ex_song_aft101 { - null_chara_index chara; - null_chara_index chara2P; // not AFT101 - null_chara_index chara3P; // not AFT101 - null_chara_index chara4P; // not AFT101 + null_def chara; + null_def chara2P; // not AFT101 + null_def chara3P; // not AFT101 + null_def chara4P; // not AFT101 std::string file; std::string name; @@ -247,12 +241,12 @@ struct pv_db_ex_song_aft101 { struct pv_db_ex_song_aft300 { std::vector ex_auth; // AFT621/AFT622/AFT701/FT/M39 - null_chara_index chara; - null_chara_index chara2P; - null_chara_index chara3P; - null_chara_index chara4P; - null_chara_index chara5P; // not AFT300/AFT310/AFT400 - null_chara_index chara6P; // not AFT300/AFT310/AFT400 + null_def chara; + null_def chara2P; + null_def chara3P; + null_def chara4P; + null_def chara5P; // not AFT300/AFT310/AFT400 + null_def chara6P; // not AFT300/AFT310/AFT400 std::string file; std::string name; @@ -284,7 +278,7 @@ struct pv_db_field_ac200 { std::string ex_stage; // AC500/AC510/AC511/AC520/AC521/AC600 std::string spr_set_back; std::string stage; - null_int32_t stage_flag; // AC520/AC521/AC600 + null_def stage_flag; // AC520/AC521/AC600 }; struct pv_db_field_ac500 { @@ -301,7 +295,7 @@ struct pv_db_field_ac500 { std::string ex_stage; std::string spr_set_back; std::string stage; - null_int32_t stage_flag; // AC520/AC521/AC600 + null_def stage_flag; // AC520/AC521/AC600 }; struct pv_db_field_aft101 { @@ -316,15 +310,15 @@ struct pv_db_field_aft101 { std::string aet_id_front; std::string aet_id_front_low; std::string auth_3d; - null_int32_t cam_blur; // AFT110/AFT120/AFT200 + null_def cam_blur; // AFT110/AFT120/AFT200 std::string ex_auth_3d; std::string ex_stage; std::string light; // AFT100 - null_int32_t npr_type; // AFT110/AFT120/AFT200 - null_int32_t sdw_off; // AFT110/AFT120/AFT200 + null_def npr_type; // AFT110/AFT120/AFT200 + null_def sdw_off; // AFT110/AFT120/AFT200 std::string spr_set_back; std::string stage; - null_int32_t stage_flag; + null_def stage_flag; }; struct pv_db_field_aft210 { @@ -354,16 +348,16 @@ struct pv_db_field_aft210 { std::string aet_id_front; std::string aet_id_front_low; std::string auth_3d; - null_int32_t cam_blur; + null_def cam_blur; std::string ex_auth_3d; std::string ex_stage; std::string light; - null_int32_t light_frame; - null_int32_t npr_type; - null_int32_t sdw_off; + null_def light_frame; + null_def npr_type; + null_def sdw_off; std::string spr_set_back; std::string stage; - null_int32_t stage_flag; + null_def stage_flag; }; struct pv_db_field_aft500 { @@ -400,21 +394,21 @@ struct pv_db_field_aft500 { std::string aet_id_front_3d_surf; std::string aet_id_front_low; std::string auth_3d; - null_int32_t cam_blur; + null_def cam_blur; std::string ex_auth_3d; std::string ex_stage; std::string light; - null_int32_t light_frame; - null_int32_t npr_type; - null_int32_t sdw_off; + null_def light_frame; + null_def npr_type; + null_def sdw_off; std::string spr_set_back; std::string stage; - null_int32_t stage_flag; + null_def stage_flag; }; struct pv_db_mdata_ac110 { std::string directory; - null_int32_t flag; + null_def flag; std::string gam_aet; std::string gam_aet_id; std::string gam_spr; @@ -425,48 +419,45 @@ struct pv_db_mdata_ac110 { struct pv_db_mdata_ac200 { std::string directory; - null_int32_t flag; + null_def flag; }; struct pv_db_osage_init { - null_int32_t frame; + null_def frame; std::string motion; std::string stage; }; -null(pv_db_performer_size) -null(pv_db_performer_type) - struct pv_db_performer_aft101 { - null_chara_index chara; - null_pv_db_performer_size size; - null_pv_db_performer_type type; + null_def chara; + null_def size; + null_def type; - null_int32_t costume; - null_int32_t exclude; - null_int32_t fixed; - null_int32_t item_back; - null_int32_t item_face; - null_int32_t item_neck; - null_int32_t item_zujo; - null_int32_t pv_costume; + null_def costume; + null_def exclude; + null_def fixed; + null_def item_back; + null_def item_face; + null_def item_neck; + null_def item_zujo; + null_def pv_costume; }; struct pv_db_performer_aft500 { - null_chara_index chara; - null_pv_db_performer_size size; - null_pv_db_performer_type type; + null_def chara; + null_def size; + null_def type; - null_int32_t costume; - null_int32_t exclude; - null_int32_t fixed; - null_int32_t item_back; - null_int32_t item_face; - null_int32_t item_kami; // FT - null_int32_t item_neck; - null_int32_t item_zujo; - null_int32_t pv_costume; - null_int32_t pseudo_same_id; + null_def costume; + null_def exclude; + null_def fixed; + null_def item_back; + null_def item_face; + null_def item_kami; // FT + null_def item_neck; + null_def item_zujo; + null_def pv_costume; + null_def pseudo_same_id; }; struct pv_db_pv_expression { @@ -474,8 +465,8 @@ struct pv_db_pv_expression { }; struct pv_db_sabi { - null_float_t play_time; - null_float_t start_time; + null_def play_time; + null_def start_time; }; struct pv_db_sel_2d { @@ -512,7 +503,7 @@ struct pv_db_stage_param_ac200 { struct pv_db_stage_param_aft210 { std::string collision_file; - null_int32_t mhd_id; + null_def mhd_id; std::string stage; std::string wind_file; }; @@ -522,13 +513,13 @@ struct pv_db_title_image_ac101 { std::vector file_name; // AC101 std::string aet_name; - null_float_t time; + null_def time; }; struct pv_db_title_image_ac200 { std::string aet_name; - null_float_t end_time; - null_float_t time; + null_def end_time; + null_def time; }; struct pv_db_diff_ac101 { @@ -540,11 +531,11 @@ struct pv_db_diff_ac101 { pv_db_song_info_ac101 song_info; pv_db_title_image_ac101 title_image; - null_int32_t level; + null_def level; std::string movie_file_name; std::string script_file_name; std::string se_name; - null_int32_t version; + null_def version; }; struct pv_db_diff_ac200 { @@ -559,16 +550,14 @@ struct pv_db_diff_ac200 { pv_db_song_info_ac200 song_info; pv_db_title_image_ac200 title_image; - null_float_t edit_chara_scale; - null_int32_t level; + null_def edit_chara_scale; + null_def level; std::string movie_file_name; std::string script_file_name; std::string se_name; - null_int32_t version; + null_def version; }; -null(pv_db_movie_surface) - struct pv_db_diff_aft101 { std::vector field; @@ -581,7 +570,7 @@ struct pv_db_diff_aft101 { std::vector pv_item; pv_db_pv_level level; - null_pv_db_movie_surface movie_surface; + null_def movie_surface; pv_db_song_info_ac200 song_info; pv_db_title_image_ac200 title_image; @@ -589,9 +578,9 @@ struct pv_db_diff_aft101 { std::string chainslide_first_name; std::string chainslide_sub_name; std::string chainslide_success_name; - null_float_t edit_chara_scale; + null_def edit_chara_scale; std::string effect_se_file_name; - null_int32_t level_sort_index; + null_def level_sort_index; std::string movie_file_name; std::string pvbranch_success_se_name; std::string script_file_name; @@ -599,13 +588,13 @@ struct pv_db_diff_aft101 { std::string se_name; std::string slide_name; std::string slidertouch_name; - null_int32_t version; + null_def version; }; struct pv_db_diff_attr { - null_int32_t extra; - null_int32_t original; - null_int32_t slide; + null_def extra; + null_def original; + null_def slide; }; struct pv_db_diff_aft300 { @@ -627,7 +616,7 @@ struct pv_db_diff_aft300 { pv_db_diff_attr attribute; pv_db_pv_level level; - null_pv_db_movie_surface movie_surface; + null_def movie_surface; pv_db_song_info_ac200 song_info; pv_db_title_image_ac200 title_image; @@ -635,13 +624,13 @@ struct pv_db_diff_aft300 { std::string chainslide_first_name; std::string chainslide_sub_name; std::string chainslide_success_name; - null_int32_t edition; - null_int32_t is_ps4dlc; // FT/M39 - null_float_t edit_chara_scale; + null_def edition; + null_def is_ps4dlc; // FT/M39 + null_def edit_chara_scale; std::string effect_se_file_name; - null_float_t hidden_timing; - null_float_t high_speed_rate; - null_int32_t level_sort_index; + null_def hidden_timing; + null_def high_speed_rate; + null_def level_sort_index; std::string movie_file_name; std::string pvbranch_success_se_name; std::string script_file_name; @@ -649,8 +638,8 @@ struct pv_db_diff_aft300 { std::string se_name; std::string slide_name; std::string slidertouch_name; - null_float_t sudden_timing; - null_int32_t version; + null_def sudden_timing; + null_def version; }; struct pv_db_difficulty_aft300 { @@ -677,7 +666,7 @@ struct pv_db_diff_aft500 { pv_db_diff_attr attribute; pv_db_pv_level level; - null_pv_db_movie_surface movie_surface; + null_def movie_surface; pv_db_song_info_ac200 song_info_en; // FT/M39 pv_db_song_info_ac200 song_info; pv_db_title_image_ac200 title_image; @@ -686,13 +675,13 @@ struct pv_db_diff_aft500 { std::string chainslide_first_name; std::string chainslide_sub_name; std::string chainslide_success_name; - null_int32_t edition; - null_float_t edit_chara_scale; + null_def edition; + null_def edit_chara_scale; std::string effect_se_file_name; - null_float_t hidden_timing; - null_float_t high_speed_rate; - null_int32_t is_ps4_dlc; // FT/M39 - null_int32_t level_sort_index; + null_def hidden_timing; + null_def high_speed_rate; + null_def is_ps4_dlc; // FT/M39 + null_def level_sort_index; std::string movie_file_name; std::string pvbranch_success_se_name; std::string script_file_name; @@ -700,8 +689,8 @@ struct pv_db_diff_aft500 { std::string se_name; std::string slide_name; std::string slidertouch_name; - null_float_t sudden_timing; - null_int32_t version; + null_def sudden_timing; + null_def version; }; struct pv_db_difficulty_aft500 { @@ -723,12 +712,12 @@ struct pv_db_pv_ac101 { pv_db_sel_2d sel_2d; // AC101 pv_db_song_info_ac200 song_info; pv_db_title_image_ac200 title_image; - null_chara_index unlock; + null_def unlock; - null_int32_t bpm; - null_int32_t date; - null_int32_t demo_flag; // AC110/AC120/AC130 - null_int32_t m_data_flag; // AC101 + null_def bpm; + null_def date; + null_def demo_flag; // AC110/AC120/AC130 + null_def m_data_flag; // AC101 std::string movie_file_name; std::string se_name; std::string song_file_name; @@ -756,24 +745,22 @@ struct pv_db_pv_ac200 { pv_db_sabi sabi; pv_db_song_info_ac200 song_info; pv_db_title_image_ac200 title_image; - null_chara_index unlock1p; - null_chara_index unlock2p; + null_def unlock1p; + null_def unlock2p; - null_int32_t bpm; - null_int32_t date; - null_int32_t edit; - null_float_t edit_chara_scale; + null_def bpm; + null_def date; + null_def edit; + null_def edit_chara_scale; std::string movie_file_name; - null_int32_t remix_parent; + null_def remix_parent; std::string se_name; std::string song_file_name; std::string song_name; std::string song_name_reading; - null_bool use_osage_play_data; // not AC200 + null_def use_osage_play_data; // not AC200 }; -null(pv_db_eyes_base_adjust_type) - struct pv_db_pv_aft101 { std::vector chreff; std::vector ex_song; @@ -795,36 +782,36 @@ struct pv_db_pv_aft101 { pv_db_diff_aft101 difficulty[5]; pv_db_disp2d_ac200 disp2d; - null_pv_db_eyes_base_adjust_type eyes_base_adjust_type; // AFT200 + null_def eyes_base_adjust_type; // AFT200 pv_db_mdata_ac200 mdata; - null_pv_db_movie_surface movie_surface; + null_def movie_surface; pv_db_pv_expression pv_expression; pv_db_sabi sabi; pv_db_song_info_ac200 song_info; pv_db_title_image_ac200 title_image; - null_int32_t bpm; + null_def bpm; std::string chainslide_failure_name; std::string chainslide_first_name; std::string chainslide_sub_name; std::string chainslide_success_name; - null_int32_t date; - null_int32_t disable_calc_motfrm_limit; + null_def date; + null_def disable_calc_motfrm_limit; std::string effect_se_file_name; - null_int32_t edit; - null_float_t edit_chara_scale; - null_int32_t eyes_xrot_adjust; - null_int32_t is_old_pv; // AFT200 + null_def edit; + null_def edit_chara_scale; + null_def eyes_xrot_adjust; + null_def is_old_pv; // AFT200 std::string movie_file_name; std::string pvbranch_success_se_name; - null_int32_t remix_parent; + null_def remix_parent; std::string se_name; std::string slide_name; std::string slidertouch_name; std::string song_file_name; std::string song_name; std::string song_name_reading; - null_bool use_osage_play_data; + null_def use_osage_play_data; }; struct pv_db_pv_aft210 { @@ -848,36 +835,36 @@ struct pv_db_pv_aft210 { pv_db_diff_aft101 difficulty[5]; pv_db_disp2d_aft210 disp2d; - null_pv_db_eyes_base_adjust_type eyes_base_adjust_type; + null_def eyes_base_adjust_type; pv_db_mdata_ac200 mdata; - null_pv_db_movie_surface movie_surface; + null_def movie_surface; pv_db_pv_expression pv_expression; pv_db_sabi sabi; pv_db_song_info_ac200 song_info; pv_db_title_image_ac200 title_image; - null_int32_t bpm; + null_def bpm; std::string chainslide_failure_name; std::string chainslide_first_name; std::string chainslide_sub_name; std::string chainslide_success_name; - null_int32_t date; - null_int32_t disable_calc_motfrm_limit; + null_def date; + null_def disable_calc_motfrm_limit; std::string effect_se_file_name; - null_int32_t edit; - null_float_t edit_chara_scale; - null_int32_t eyes_xrot_adjust; - null_int32_t is_old_pv; + null_def edit; + null_def edit_chara_scale; + null_def eyes_xrot_adjust; + null_def is_old_pv; std::string movie_file_name; std::string pvbranch_success_se_name; - null_int32_t remix_parent; + null_def remix_parent; std::string se_name; std::string slide_name; std::string slidertouch_name; std::string song_file_name; std::string song_name; std::string song_name_reading; - null_bool use_osage_play_data; + null_def use_osage_play_data; }; struct pv_db_pv_aft300 { @@ -906,44 +893,42 @@ struct pv_db_pv_aft300 { pv_db_difficulty_aft300 difficulty; pv_db_disp2d_aft210 disp2d; - null_pv_db_eyes_base_adjust_type eyes_base_adjust_type; + null_def eyes_base_adjust_type; pv_db_mdata_ac200 mdata; - null_pv_db_movie_surface movie_surface; + null_def movie_surface; pv_db_pv_expression pv_expression; pv_db_sabi sabi; pv_db_song_info_ac200 song_info; pv_db_title_image_ac200 title_image; - null_int32_t bpm; + null_def bpm; std::string chainslide_failure_name; std::string chainslide_first_name; std::string chainslide_sub_name; std::string chainslide_success_name; - null_int32_t date; - null_int32_t disable_calc_motfrm_limit; + null_def date; + null_def disable_calc_motfrm_limit; std::string effect_se_file_name; - null_int32_t edit; - null_float_t edit_chara_scale; - null_int32_t eyes_xrot_adjust; - null_float_t hidden_timing; - null_float_t high_speed_rate; - null_int32_t is_old_pv; + null_def edit; + null_def edit_chara_scale; + null_def eyes_xrot_adjust; + null_def hidden_timing; + null_def high_speed_rate; + null_def is_old_pv; std::string movie_file_name; std::string pvbranch_success_se_name; - null_int32_t pre_play_script; // AFT410 - null_int32_t remix_parent; + null_def pre_play_script; // AFT410 + null_def remix_parent; std::string se_name; std::string slide_name; std::string slidertouch_name; std::string song_file_name; std::string song_name; std::string song_name_reading; - null_float_t sudden_timing; - null_bool use_osage_play_data; + null_def sudden_timing; + null_def use_osage_play_data; }; -null(pv_db_frame_texture_type) - struct pv_db_pv_aft500 { std::vector another_song; std::vector auth_replace_by_module; // AFT600/AFT601/AFT610/AFT620/AFT621/AFT622/AFT701/FT/M39 @@ -974,49 +959,49 @@ struct pv_db_pv_aft500 { pv_db_difficulty_aft300 difficulty; pv_db_disp2d_aft210 disp2d; - null_pv_db_eyes_base_adjust_type eyes_base_adjust_type; - null_pv_db_frame_texture_type frame_texture_a_type; - null_pv_db_frame_texture_type frame_texture_b_type; - null_pv_db_frame_texture_type frame_texture_c_type; - null_pv_db_frame_texture_type frame_texture_d_type; - null_pv_db_frame_texture_type frame_texture_e_type; - null_pv_db_frame_texture_type frame_texture_type; + null_def eyes_base_adjust_type; + null_def frame_texture_a_type; + null_def frame_texture_b_type; + null_def frame_texture_c_type; + null_def frame_texture_d_type; + null_def frame_texture_e_type; + null_def frame_texture_type; pv_db_mdata_ac200 mdata; - null_pv_db_movie_surface movie_surface; + null_def movie_surface; pv_db_pv_expression pv_expression; pv_db_sabi sabi; pv_db_song_info_ac200 song_info_en; // FT/M39 pv_db_song_info_ac200 song_info; pv_db_title_image_ac200 title_image; - null_int32_t bpm; + null_def bpm; std::string chainslide_failure_name; std::string chainslide_first_name; std::string chainslide_sub_name; std::string chainslide_success_name; - null_int32_t date; - null_int32_t disable_calc_motfrm_limit; + null_def date; + null_def disable_calc_motfrm_limit; std::string effect_se_file_name; - null_int32_t edit; - null_float_t edit_chara_scale; - null_int32_t eyes_xrot_adjust; + null_def edit; + null_def edit_chara_scale; + null_def eyes_xrot_adjust; std::string frame_texture; std::string frame_texture_a; std::string frame_texture_b; std::string frame_texture_c; std::string frame_texture_d; std::string frame_texture_e; - null_float_t hidden_timing; - null_float_t high_speed_rate; - null_int32_t is_old_pv; + null_def hidden_timing; + null_def high_speed_rate; + null_def is_old_pv; std::string movie_file_name; std::string pvbranch_success_se_name; - null_int32_t pack; // FT/M39 - null_int32_t pre_play_script; - null_int32_t rank_board_id; // FT/M39 - null_int32_t remix_parent; - null_float_t resolution_scale; // FT/M39 - null_float_t resolution_scale_neo; // FT/M39 + null_def pack; // FT/M39 + null_def pre_play_script; + null_def rank_board_id; // FT/M39 + null_def remix_parent; + null_def resolution_scale; // FT/M39 + null_def resolution_scale_neo; // FT/M39 std::string se_name; std::string slide_name; std::string slidertouch_name; @@ -1025,6 +1010,6 @@ struct pv_db_pv_aft500 { std::string song_name_en; // FT/M39 std::string song_name_reading; std::string song_name_reading_en; // FT/M39 - null_float_t sudden_timing; - null_bool use_osage_play_data; + null_def sudden_timing; + null_def use_osage_play_data; }; diff --git a/src/KKdLib/txp.cpp b/src/KKdLib/txp.cpp index 2db21266..36b41f89 100644 --- a/src/KKdLib/txp.cpp +++ b/src/KKdLib/txp.cpp @@ -15,6 +15,10 @@ txp_mipmap::~txp_mipmap() { } +uint32_t txp_mipmap::get_size() { + return txp::get_size(format, width, height); +} + txp::txp() : has_cube_map(), array_size(), mipmaps_count() { } @@ -404,7 +408,7 @@ bool txp_set::unpack_file(const void* data, bool big_endian) { tex_mipmap->size = *(uint32_t*)(mipmap_d + 20); } - ssize_t size = txp::get_size(tex_mipmap->format, tex_mipmap->width, tex_mipmap->height); + ssize_t size = tex_mipmap->get_size(); tex_mipmap->data.resize(max_def(size, tex_mipmap->size)); memcpy(tex_mipmap->data.data(), (void*)(mipmap_d + 24), tex_mipmap->size); size -= tex_mipmap->size; diff --git a/src/KKdLib/txp.hpp b/src/KKdLib/txp.hpp index 68e6a5fc..7be18ca3 100644 --- a/src/KKdLib/txp.hpp +++ b/src/KKdLib/txp.hpp @@ -35,6 +35,8 @@ struct txp_mipmap { txp_mipmap(); ~txp_mipmap(); + + uint32_t get_size(); }; struct txp { diff --git a/src/ReDIVA/classes/glitter_editor.cpp b/src/ReDIVA/classes/glitter_editor.cpp index 24591122..b3f67f0d 100644 --- a/src/ReDIVA/classes/glitter_editor.cpp +++ b/src/ReDIVA/classes/glitter_editor.cpp @@ -2025,11 +2025,11 @@ static bool glitter_editor_resource_import(GlitterEditor* glt_edt) { do for (uint32_t i = 0; i < tex->mipmaps_count; i++) { txp_mipmap tex_mip; - tex_mip.width = max_def(d.width >> i, 1); - tex_mip.height = max_def(d.height >> i, 1); + tex_mip.width = max_def(d.width >> i, 1u); + tex_mip.height = max_def(d.height >> i, 1u); tex_mip.format = d.format; - uint32_t size = txp::get_size(tex_mip.format, tex_mip.width, tex_mip.height); + uint32_t size = tex_mip.get_size(); tex_mip.size = size; tex_mip.data.resize(size); memcpy(tex_mip.data.data(), d.data[index], size); @@ -2092,7 +2092,7 @@ static bool glitter_editor_resource_export(GlitterEditor* glt_edt) { uint32_t index = 0; do for (uint32_t i = 0; i < tex.mipmaps_count; i++) { - uint32_t size = txp::get_size(format, max_def(width >> i, 1), max_def(height >> i, 1)); + uint32_t size = d.get_size(i); void* data = force_malloc(size); memcpy(data, tex.mipmaps[index].data.data(), size); d.data.push_back(data); @@ -4210,20 +4210,24 @@ static void glitter_editor_property_particle(GlitterEditor* glt_edt, class_data* obj* obj = 0; if (handler && handler->obj_set) { obj_set* set = handler->obj_set; - for (uint32_t i = 0; i < set->obj_num; i++) - if (set->obj_data[i]->id == obj_id) { - obj = set->obj_data[i]; - break; - } + if (set->obj_data) { + ::obj** obj_data = set->obj_data; + for (uint32_t i = 0; i < set->obj_num; i++) + if (obj_data[i]->id == obj_id) { + obj = obj_data[i]; + break; + } + } } ImGui::StartPropertyColumn("Object"); if (ImGui::BeginCombo("##Object", obj ? obj->name : "None", 0)) { - if (set_id != -1 && handler && handler->set_id == set_id && handler->obj_set) { + if (set_id != -1 && handler && handler->set_id == set_id && handler->obj_set && handler->obj_set->obj_data) { obj_set* set = handler->obj_set; + ::obj** obj_data = set->obj_data; ssize_t obj_index = -1; for (uint32_t i = 0; i < set->obj_num; i++) - if (set->obj_data[i]->id == obj_id) { + if (obj_data[i]->id == obj_id) { obj_index = i; break; } @@ -4237,7 +4241,7 @@ static void glitter_editor_property_particle(GlitterEditor* glt_edt, class_data* for (uint32_t i = 0; i < set->obj_num; i++) { ImGui::PushID(i); - ::obj* obj = set->obj_data[i]; + ::obj* obj = obj_data[i]; if (ImGui::Selectable(obj->name, obj->id == obj_id) || ImGui::ItemKeyPressed(ImGuiKey_Enter) || (ImGui::IsItemFocused() && obj->id != obj_id)) @@ -4248,7 +4252,7 @@ static void glitter_editor_property_particle(GlitterEditor* glt_edt, class_data* if (obj_index == -1 || obj_index >= set->obj_num) obj_id = -1; else - obj_id = set->obj_data[obj_index]->id; + obj_id = obj_data[obj_index]->id; if (mesh->object_name_hash != obj_id) { mesh->object_name_hash = obj_id;