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