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