update helpers/location to 'frosted' ui
[carveJwlIkooP6JGAAIwe30JlM.git] / addon.h
1 #pragma once
2 #include "vg/vg_steam_ugc.h"
3 #include "vg/vg_mem_pool.h"
4 #include "vg/vg_string.h"
5 #include "addon_types.h"
6
7 typedef struct addon_reg addon_reg;
8 typedef struct addon_cache_entry addon_cache_entry;
9 typedef struct addon_alias addon_alias;
10
11 struct addon_alias
12 {
13 enum addon_type type;
14 PublishedFileId_t workshop_id;
15 char foldername[ ADDON_FOLDERNAME_MAX ];
16 };
17
18 #define ADDON_REG_HIDDEN 0x1
19 #define ADDON_REG_MTZERO 0x2
20 #define ADDON_REG_CITY 0x4
21 #define ADDON_REG_PREMIUM 0x8
22
23 struct addon_system
24 {
25 struct addon_reg
26 {
27 addon_alias alias;
28 u32 foldername_hash;
29 u8 metadata[512]; /* vg_msg buffer */
30 u32 metadata_len;
31 u32 flags;
32
33 u16 cache_id;
34
35 enum addon_state{
36 k_addon_state_none,
37 k_addon_state_indexed,
38 k_addon_state_indexed_absent /* gone but not forgotten */
39 }
40 state;
41 }
42 *registry;
43 u32 registry_count;
44
45 /* deffered: updates in main thread */
46 u32 registry_type_counts[k_addon_type_max];
47
48 struct addon_cache
49 {
50 struct addon_cache_entry
51 {
52 u32 reg_index;
53 addon_reg *reg_ptr; /* TODO: only use reg_index? */
54
55 vg_pool_node poolnode;
56
57 enum addon_cache_state{
58 k_addon_cache_state_none,
59 k_addon_cache_state_loaded,
60 k_addon_cache_state_load_request
61 }
62 state;
63 }
64 *allocs;
65 vg_pool pool;
66
67 void *items; /* the real data */
68 size_t stride;
69 }
70 cache[k_addon_type_max];
71 SDL_SpinLock sl_cache_using_resources;
72 }
73 extern addon_system;
74
75 void addon_system_init( void );
76 u32 addon_count( enum addon_type type, u32 ignoreflags );
77 addon_reg *get_addon_from_index( enum addon_type type, u32 index,
78 u32 ignoreflags );
79 u32 get_index_from_addon( enum addon_type type, addon_reg *a );
80 int addon_get_content_folder( addon_reg *reg, vg_str *folder, int async);
81
82 /* scanning routines */
83 u32 addon_match( addon_alias *alias );
84 int addon_alias_eq( addon_alias *a, addon_alias *b );
85 void addon_alias_uid( addon_alias *alias, char buf[ADDON_UID_MAX] );
86 int addon_uid_to_alias( const char *uid, addon_alias *alias );
87 void invalidate_addon_alias( addon_alias *alias );
88 void addon_mount_content_folder( enum addon_type type,
89 const char *base_folder,
90 const char *content_ext );
91 void addon_mount_workshop_items(void);
92 void async_addon_reg_update( void *data, u32 size );
93 addon_reg *addon_mount_local_addon( const char *folder,
94 enum addon_type type,
95 const char *content_ext );
96 u16 addon_cache_fetch( enum addon_type type, u32 reg_index );
97 u16 addon_cache_alloc( enum addon_type type, u32 reg_index );
98 void *addon_cache_item( enum addon_type type, u16 id );
99 void *addon_cache_item_if_loaded( enum addon_type type, u16 id );
100 void async_addon_setstate( void *data, u32 size );
101
102 void addon_system_pre_update(void);
103 u16 addon_cache_create_viewer( enum addon_type type, u16 reg_id);
104
105 void addon_cache_watch( enum addon_type type, u16 cache_id );
106 void addon_cache_unwatch( enum addon_type type, u16 cache_id );
107 u16 addon_cache_create_viewer_from_uid( enum addon_type type,
108 char uid[ADDON_UID_MAX] );