network items, interp boundaries
[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 typedef struct addon_reg addon_reg;
13 typedef struct addon_cache_entry addon_cache_entry;
14 typedef struct addon_alias addon_alias;
15
16 struct addon_alias {
17 enum addon_type type;
18 PublishedFileId_t workshop_id;
19 char foldername[ ADDON_FOLDERNAME_MAX ];
20 };
21
22 struct {
23 struct addon_reg{
24 addon_alias alias;
25 u32 foldername_hash;
26 u8 metadata[512]; /* vg_msg buffer */
27 u32 metadata_len;
28
29 u16 cache_id;
30
31 enum addon_state{
32 k_addon_state_none,
33 k_addon_state_indexed,
34 k_addon_state_indexed_absent /* gone but not forgotten */
35 }
36 state;
37 }
38 *registry;
39 u32 registry_count;
40
41 /* deffered: updates in main thread */
42 u32 registry_type_counts[k_addon_type_max];
43
44 struct addon_cache{
45 struct addon_cache_entry{
46 u32 reg_index;
47 addon_reg *reg_ptr; /* TODO: only use reg_index? */
48
49 vg_pool_node poolnode;
50
51 enum addon_cache_state{
52 k_addon_cache_state_none,
53 k_addon_cache_state_loaded,
54 k_addon_cache_state_load_request
55 }
56 state;
57 }
58 *allocs;
59 vg_pool pool;
60
61 void *items; /* the real data */
62 size_t stride;
63 }
64 cache[k_addon_type_max];
65 SDL_SpinLock sl_cache_using_resources;
66 }
67 static addon_system;
68
69 static void addon_system_init( void );
70 static u32 addon_count( enum addon_type type );
71 static addon_reg *get_addon_from_index( enum addon_type type, u32 index );
72 static u32 get_index_from_addon( enum addon_type type, addon_reg *a );
73 static int addon_get_content_folder( addon_reg *reg, vg_str *folder );
74
75 /* scanning routines */
76 static u32 addon_match( addon_alias *alias );
77 static int addon_alias_eq( addon_alias *a, addon_alias *b );
78 static void addon_alias_uid( addon_alias *alias, char buf[ADDON_UID_MAX] );
79 static int addon_uid_to_alias( char uid[ADDON_UID_MAX], addon_alias *alias );
80 static void invalidate_addon_alias( addon_alias *alias );
81 static void addon_mount_content_folder( enum addon_type type,
82 const char *base_folder,
83 const char *content_ext );
84 static void addon_mount_workshop_items(void);
85 static void async_addon_reg_update( void *data, u32 size );
86 static addon_reg *addon_mount_local_addon( const char *folder,
87 enum addon_type type,
88 const char *content_ext );
89 static u16 addon_cache_fetch( enum addon_type type, u32 reg_index );
90 static u16 addon_cache_alloc( enum addon_type type, u32 reg_index );
91 static void *addon_cache_item( enum addon_type type, u16 id );
92 static void *addon_cache_item_if_loaded( enum addon_type type, u16 id );
93 static void async_addon_setstate( void *data, u32 size );
94 static void addon_cache_load_loop(void);
95 static u16 addon_cache_create_viewer( enum addon_type type, u16 reg_id);
96
97 static void addon_cache_watch( enum addon_type type, u16 cache_id );
98 static void addon_cache_unwatch( enum addon_type type, u16 cache_id );
99 static u16 addon_cache_create_viewer_from_uid( enum addon_type type,
100 char uid[ADDON_UID_MAX] );
101
102 #endif /* ADDON_H */