]> git.xonotic.org Git - xonotic/darkplaces.git/blob - host.h
sys: improve error and crash handling
[xonotic/darkplaces.git] / host.h
1 #ifndef HOST_H
2 #define HOST_H
3
4 #include <setjmp.h>
5 #include "qtypes.h"
6 #include "qdefs.h"
7 #include "cmd.h"
8 #include "cvar.h"
9
10 extern cvar_t developer;
11 extern cvar_t developer_entityparsing;
12 extern cvar_t developer_extra;
13 extern cvar_t developer_insane;
14 extern cvar_t developer_loadfile;
15 extern cvar_t developer_loading;
16 extern cvar_t host_isclient;
17 extern cvar_t sessionid;
18
19 struct cmd_state_s;
20
21 typedef enum host_state_e
22 {
23         host_shutdown,
24         host_init,
25         host_loading,
26         host_active,
27         host_failed ///< crashed or aborted, SDL dialog open
28 } host_state_t;
29
30 typedef struct host_static_s
31 {
32         jmp_buf abortframe;
33         int state;
34         unsigned int framecount; // incremented every frame, never reset (checked by Host_Error and Host_SaveConfig_f)
35         double realtime; // the accumulated mainloop time since application started (with filtering), without any slowmo or clamping
36         double dirtytime; // the main loop wall time for this frame, equal to Sys_DirtyTime() at the start of this host frame
37         double sleeptime; // time spent sleeping after the last frame
38         qbool restless; // don't sleep
39         qbool paused; // global paused state, pauses both client and server
40         cmd_buf_t *cbuf;
41
42         struct
43         {
44                 void (*ConnectLocal)(void);
45                 void (*Disconnect)(qbool, const char *, ... );
46                 void (*ToggleMenu)(void);
47                 qbool (*CL_Intermission)(void); // Quake compatibility
48                 void (*CL_SendCvar)(struct cmd_state_s *);
49                 void (*SV_SendCvar)(struct cmd_state_s *);
50                 void (*SV_Shutdown)(void);
51         } hook;
52 } host_static_t;
53
54 extern host_static_t host;
55
56 void Host_Main(void);
57 void Host_Shutdown(void);
58 void Host_Error(const char *error, ...) DP_FUNC_PRINTF(1) DP_FUNC_NORETURN;
59 void Host_LockSession(void);
60 void Host_UnlockSession(void);
61 void Host_AbortCurrentFrame(void) DP_FUNC_NORETURN;
62 void Host_SaveConfig(const char *file);
63
64 #endif