Performance Improvements
Pass theme list & its entries around by reference rather than copying them. Fix bug in async icon loading that caused icons to be loaded multiple times. Original PR by @LiquidFenrir
This commit is contained in:
@@ -30,7 +30,7 @@
|
||||
#include "common.h"
|
||||
|
||||
typedef struct {
|
||||
u16* camera_buffer;
|
||||
u16 * camera_buffer;
|
||||
|
||||
Handle event_stop;
|
||||
Thread cam_thread, ui_thread;
|
||||
@@ -45,7 +45,7 @@ typedef struct {
|
||||
|
||||
bool any_update;
|
||||
|
||||
struct quirc* context;
|
||||
struct quirc * context;
|
||||
} qr_data;
|
||||
|
||||
bool init_qr(void);
|
||||
|
||||
@@ -38,9 +38,19 @@
|
||||
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
|
||||
#define POS() DEBUG("%s (line %d)...\n", __func__, __LINE__)
|
||||
|
||||
#define DEBUGPOS(...) \
|
||||
#define DEBUGPOS(...) do {\
|
||||
POS(); \
|
||||
DEBUG(__VA_ARGS__)
|
||||
DEBUG(__VA_ARGS__); \
|
||||
} while(0)
|
||||
|
||||
static inline int min(const int a, const int b)
|
||||
{
|
||||
return a > b ? b : a;
|
||||
}
|
||||
static inline int max(const int a, const int b)
|
||||
{
|
||||
return a < b ? b : a;
|
||||
}
|
||||
|
||||
#define FASTSCROLL_WAIT 1e8
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
|
||||
#define MAX_LINES 10
|
||||
|
||||
typedef enum {
|
||||
typedef enum InstallType_e {
|
||||
INSTALL_LOADING_THEMES,
|
||||
INSTALL_LOADING_SPLASHES,
|
||||
INSTALL_LOADING_ICONS,
|
||||
@@ -149,8 +149,8 @@ typedef struct {
|
||||
const char * instructions[BUTTONS_INFO_LINES][BUTTONS_INFO_COLUNMNS];
|
||||
} Instructions_s;
|
||||
|
||||
extern C3D_RenderTarget* top;
|
||||
extern C3D_RenderTarget* bottom;
|
||||
extern C3D_RenderTarget * top;
|
||||
extern C3D_RenderTarget * bottom;
|
||||
extern C2D_TextBuf staticBuf, dynamicBuf;
|
||||
|
||||
extern C2D_Text text[TEXT_AMOUNT];
|
||||
@@ -162,8 +162,8 @@ void start_frame(void);
|
||||
void end_frame(void);
|
||||
void set_screen(C3D_RenderTarget * screen);
|
||||
|
||||
void throw_error(const char* error, ErrorLevel level);
|
||||
bool draw_confirm(const char* conf_msg, Entry_List_s* list);
|
||||
void throw_error(const char * error, ErrorLevel level);
|
||||
bool draw_confirm(const char * conf_msg, Entry_List_s * list);
|
||||
|
||||
void draw_preview(C2D_Image preview, int preview_offset);
|
||||
|
||||
@@ -177,7 +177,7 @@ void draw_text_center(gfxScreen_t target, float y, float z, float scaleX, float
|
||||
void draw_home(u64 start_time, u64 cur_time);
|
||||
|
||||
void draw_base_interface(void);
|
||||
void draw_grid_interface(Entry_List_s* list, Instructions_s instructions);
|
||||
void draw_interface(Entry_List_s* list, Instructions_s instructions);
|
||||
void draw_grid_interface(Entry_List_s * list, Instructions_s instructions);
|
||||
void draw_interface(Entry_List_s * list, Instructions_s instructions);
|
||||
|
||||
#endif
|
||||
|
||||
106
include/entries_list.h
Normal file
106
include/entries_list.h
Normal file
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* This file is part of Anemone3DS
|
||||
* Copyright (C) 2016-2020 Contributors in CONTRIBUTORS.md
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#ifndef ENTRIES_LIST_H
|
||||
#define ENTRIES_LIST_H
|
||||
|
||||
#include "common.h"
|
||||
#include <jansson.h>
|
||||
|
||||
typedef enum {
|
||||
SORT_NONE,
|
||||
|
||||
SORT_NAME,
|
||||
SORT_AUTHOR,
|
||||
SORT_PATH,
|
||||
} SortMode;
|
||||
|
||||
typedef struct {
|
||||
u16 path[0x106];
|
||||
bool is_zip;
|
||||
bool in_shuffle;
|
||||
bool no_bgm_shuffle;
|
||||
bool installed;
|
||||
u32 placeholder_color; // doubles as not-info-loaded when == 0
|
||||
|
||||
json_int_t tp_download_id;
|
||||
u16 name[0x41];
|
||||
u16 desc[0x81];
|
||||
u16 author[0x41];
|
||||
} Entry_s;
|
||||
|
||||
typedef struct {
|
||||
Tex3DS_SubTexture subtex;
|
||||
u16 x, y;
|
||||
} Entry_Icon_s;
|
||||
|
||||
typedef struct {
|
||||
Entry_s * entries;
|
||||
int entries_count;
|
||||
int entries_capacity;
|
||||
|
||||
C3D_Tex icons_texture;
|
||||
Entry_Icon_s * icons_info;
|
||||
|
||||
int previous_scroll;
|
||||
int scroll;
|
||||
|
||||
int previous_selected;
|
||||
int selected_entry;
|
||||
|
||||
int shuffle_count;
|
||||
|
||||
EntryMode mode;
|
||||
int entries_per_screen_v; // rows of entries on 1 screen
|
||||
int entries_per_screen_h; // columns of entries on 1 screen
|
||||
int entries_loaded; // amount of entries on 1 screen
|
||||
int entry_size; // size in pixels of an entry icon
|
||||
|
||||
SortMode current_sort;
|
||||
|
||||
json_int_t tp_current_page;
|
||||
json_int_t tp_page_count;
|
||||
char * tp_search;
|
||||
const char * loading_path;
|
||||
} Entry_List_s;
|
||||
|
||||
void sort_by_name(Entry_List_s * list);
|
||||
void sort_by_author(Entry_List_s * list);
|
||||
void sort_by_filename(Entry_List_s * list);
|
||||
|
||||
void delete_entry(Entry_s * entry, bool is_file);
|
||||
// assumes list has been memset to 0
|
||||
typedef enum InstallType_e InstallType;
|
||||
Result load_entries(const char * loading_path, Entry_List_s * list, const InstallType loading_screen);
|
||||
u32 load_data(const char * filename, const Entry_s * entry, char ** buf);
|
||||
C2D_Image get_icon_at(Entry_List_s * list, size_t index);
|
||||
|
||||
// assumes list doesn't have any elements yet
|
||||
void list_init_capacity(Entry_List_s * list, const int init_capacity);
|
||||
// assumes list has been inited with a non zero capacity
|
||||
ssize_t list_add_entry(Entry_List_s * list);
|
||||
|
||||
#endif
|
||||
12
include/fs.h
12
include/fs.h
@@ -56,13 +56,13 @@ Result open_archives(void);
|
||||
Result close_archives(void);
|
||||
Result load_parental_controls(Parental_Restrictions_s *restrictions);
|
||||
|
||||
u32 file_to_buf(FS_Path path, FS_Archive archive, char** buf);
|
||||
u32 zip_memory_to_buf(char *file_name, void * zip_memory, size_t zip_size, char ** buf);
|
||||
u32 zip_file_to_buf(char *file_name, u16 *zip_path, char **buf);
|
||||
u32 decompress_lz_file(FS_Path file_name, FS_Archive archive, char **buf);
|
||||
u32 compress_lz_file_fast(FS_Path path, FS_Archive archive, char *in_buf, u32 size);
|
||||
u32 file_to_buf(FS_Path path, FS_Archive archive, char ** buf);
|
||||
u32 zip_memory_to_buf(const char * file_name, void * zip_memory, size_t zip_size, char ** buf);
|
||||
u32 zip_file_to_buf(const char * file_name, const u16 * zip_path, char ** buf);
|
||||
u32 decompress_lz_file(FS_Path file_name, FS_Archive archive, char ** buf);
|
||||
u32 compress_lz_file_fast(FS_Path path, FS_Archive archive, char * in_buf, u32 size);
|
||||
|
||||
Result buf_to_file(u32 size, FS_Path path, FS_Archive archive, char *buf);
|
||||
Result buf_to_file(u32 size, FS_Path path, FS_Archive archive, char * buf);
|
||||
void remake_file(FS_Path path, FS_Archive archive, u32 size);
|
||||
void save_zip_to_sd(char * filename, u32 size, char * buf, EntryMode mode);
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#define LOADING_H
|
||||
|
||||
#include "common.h"
|
||||
#include "entries_list.h"
|
||||
#include "music.h"
|
||||
#include <jansson.h>
|
||||
|
||||
@@ -45,14 +46,6 @@ enum ICON_IDS_OFFSET {
|
||||
ICONS_OFFSET_AMOUNT,
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
SORT_NONE,
|
||||
|
||||
SORT_NAME,
|
||||
SORT_AUTHOR,
|
||||
SORT_PATH,
|
||||
} SortMode;
|
||||
|
||||
typedef struct {
|
||||
u8 _padding1[4 + 2 + 2];
|
||||
|
||||
@@ -61,76 +54,26 @@ typedef struct {
|
||||
u16 author[0x40];
|
||||
|
||||
u8 _padding2[0x2000 - 0x200 + 0x30 + 0x8];
|
||||
u16 small_icon[24*24];
|
||||
u16 small_icon[24 * 24];
|
||||
|
||||
u16 big_icon[48*48];
|
||||
u16 big_icon[48 * 48];
|
||||
} Icon_s;
|
||||
|
||||
typedef struct {
|
||||
u16 name[0x41];
|
||||
u16 desc[0x81];
|
||||
u16 author[0x41];
|
||||
|
||||
u32 placeholder_color;
|
||||
|
||||
u16 path[0x106];
|
||||
bool is_zip;
|
||||
|
||||
bool in_shuffle;
|
||||
bool no_bgm_shuffle;
|
||||
bool installed;
|
||||
|
||||
json_int_t tp_download_id;
|
||||
} Entry_s;
|
||||
|
||||
typedef struct {
|
||||
Entry_s * entries;
|
||||
int entries_count;
|
||||
|
||||
C2D_Image ** icons;
|
||||
|
||||
int previous_scroll;
|
||||
int scroll;
|
||||
|
||||
int previous_selected;
|
||||
int selected_entry;
|
||||
|
||||
int shuffle_count;
|
||||
|
||||
EntryMode mode;
|
||||
int entries_per_screen_v;
|
||||
int entries_per_screen_h;
|
||||
int entries_loaded;
|
||||
int entry_size;
|
||||
|
||||
SortMode current_sort;
|
||||
|
||||
json_int_t tp_current_page;
|
||||
json_int_t tp_page_count;
|
||||
char * tp_search;
|
||||
} Entry_List_s;
|
||||
|
||||
typedef struct {
|
||||
void ** thread_arg;
|
||||
volatile bool run_thread;
|
||||
} Thread_Arg_s;
|
||||
|
||||
C2D_Image * loadTextureIcon(Icon_s *icon);
|
||||
void parse_smdh(Icon_s *icon, Entry_s * entry, const u16 * fallback_name);
|
||||
void copy_texture_data(C3D_Tex * texture, const u16 * src, const Entry_Icon_s * current_icon);
|
||||
void parse_smdh(Icon_s * icon, Entry_s * entry, const u16 * fallback_name);
|
||||
|
||||
void sort_by_name(Entry_List_s * list);
|
||||
void sort_by_author(Entry_List_s * list);
|
||||
void sort_by_filename(Entry_List_s * list);
|
||||
|
||||
void delete_entry(Entry_s * entry, bool is_file);
|
||||
Result load_entries(const char * loading_path, Entry_List_s * list);
|
||||
bool load_preview_from_buffer(char * row_pointers, u32 size, C2D_Image * preview_image, int * preview_offset);
|
||||
bool load_preview(Entry_List_s list, C2D_Image * preview_image, int * preview_offset);
|
||||
bool load_preview(const Entry_List_s * list, C2D_Image * preview_image, int * preview_offset);
|
||||
void free_preview(C2D_Image preview_image);
|
||||
Result load_audio(Entry_s, audio_s *);
|
||||
Result load_audio(const Entry_s *, audio_s *);
|
||||
void load_icons_first(Entry_List_s * current_list, bool silent);
|
||||
void handle_scrolling(Entry_List_s * list);
|
||||
void load_icons_thread(void * void_arg);
|
||||
u32 load_data(char * filename, Entry_s entry, char ** buf);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -42,7 +42,7 @@ typedef struct {
|
||||
float mix[12];
|
||||
u8 buf_pos;
|
||||
long data_read;
|
||||
char *filebuf;
|
||||
char * filebuf;
|
||||
u32 filesize;
|
||||
|
||||
volatile bool stop;
|
||||
@@ -50,6 +50,6 @@ typedef struct {
|
||||
} audio_s;
|
||||
|
||||
void play_audio(audio_s *);
|
||||
void stop_audio(audio_s**);
|
||||
void stop_audio(audio_s **);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -52,6 +52,6 @@
|
||||
#define CACHE_PATH_FORMAT "/3ds/" APP_TITLE "/cache/%" JSON_INTEGER_FORMAT
|
||||
|
||||
bool themeplaza_browser(EntryMode mode);
|
||||
Result http_get(const char *url, char ** filename, char ** buf, u32 * size, InstallType install_type, const char * acceptable_mime_types);
|
||||
Result http_get(const char * url, char ** filename, char ** buf, u32 * size, InstallType install_type, const char * acceptable_mime_types);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#include "loading.h"
|
||||
|
||||
void splash_delete(void);
|
||||
void splash_install(Entry_s splash);
|
||||
void splash_install(const Entry_s * splash);
|
||||
|
||||
void splash_check_installed(void * void_arg);
|
||||
|
||||
|
||||
@@ -64,17 +64,17 @@ typedef struct {
|
||||
u32 dlc_theme_content_index;
|
||||
u32 use_theme_cache;
|
||||
|
||||
u8 _padding1[0x338 - 8*sizeof(u32)];
|
||||
u8 _padding1[0x338 - 8 * sizeof(u32)];
|
||||
|
||||
u32 shuffle_body_sizes[MAX_SHUFFLE_THEMES];
|
||||
u32 shuffle_music_sizes[MAX_SHUFFLE_THEMES];
|
||||
} ThemeManage_bin_s;
|
||||
|
||||
Result theme_install(Entry_s theme);
|
||||
Result no_bgm_install(Entry_s theme);
|
||||
Result bgm_install(Entry_s theme);
|
||||
Result theme_install(Entry_s * theme);
|
||||
Result no_bgm_install(Entry_s * theme);
|
||||
Result bgm_install(Entry_s * theme);
|
||||
|
||||
Result shuffle_install(Entry_List_s themes);
|
||||
Result shuffle_install(const Entry_List_s * themes);
|
||||
|
||||
Result dump_current_theme(void);
|
||||
Result dump_all_themes(void);
|
||||
|
||||
@@ -29,9 +29,9 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
ssize_t strulen(const u16*, ssize_t);
|
||||
void struacat(u16 *input, const char *addition);
|
||||
void printu(u16 *input);
|
||||
u16 *strucat(u16 *destination, const u16 *source);
|
||||
ssize_t strulen(const u16 *, ssize_t);
|
||||
void struacat(u16 * input, const char * addition);
|
||||
void printu(u16 * input);
|
||||
u16 * strucat(u16 * destination, const u16 * source);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user