e_parse.c
Go to the documentation of this file.00001
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #include "../../client.h"
00041 #include "e_parse.h"
00042 #include "e_time.h"
00043 #include "e_main.h"
00044
00045 #include "../cl_localentity.h"
00046 #include "../../cl_screen.h"
00047 #include "../../cl_game.h"
00048 #include "../../cl_team.h"
00049 #include "../cl_particle.h"
00050 #include "../cl_actor.h"
00051 #include "../cl_view.h"
00052 #include "../cl_hud.h"
00053 #include "../../ui/ui_main.h"
00054 #include "../../renderer/r_mesh_anim.h"
00055
00056 cvar_t *cl_log_battlescape_events;
00057
00058 typedef struct evTimes_s {
00059 event_t eType;
00060 struct dbuffer *msg;
00061 } evTimes_t;
00062
00063
00064
00065
00066
00070 static void CL_LogEvent (const eventRegister_t *eventData)
00071 {
00072 qFILE f;
00073
00074 if (!cl_log_battlescape_events->integer)
00075 return;
00076
00077 FS_OpenFile("events.log", &f, FILE_APPEND);
00078 if (!f.f)
00079 return;
00080 else {
00081 char tbuf[32];
00082
00083 Com_MakeTimestamp(tbuf, sizeof(tbuf));
00084
00085 FS_Printf(&f, "%s - %s: %10i %s\n", tbuf, CL_GetConfigString(CS_MAPTITLE), cl.time, eventData->name);
00086 FS_CloseFile(&f);
00087 }
00088 }
00089
00096 void CL_BlockBattlescapeEvents (qboolean block)
00097 {
00098 cl.eventsBlocked = block;
00099 }
00100
00104 static qboolean CL_AreBattlescapeEventsBlocked (void)
00105 {
00106 return cl.eventsBlocked;
00107 }
00108
00116 static qboolean CL_CheckBattlescapeEvent (int now, void *data)
00117 {
00118 if (CL_AreBattlescapeEventsBlocked()) {
00119 return qfalse;
00120 } else {
00121 const evTimes_t *event = (evTimes_t *)data;
00122 const eventRegister_t *eventData = CL_GetEvent(event->eType);
00123
00124 if (eventData->eventCheck == NULL)
00125 return qtrue;
00126
00127 return eventData->eventCheck(eventData, event->msg);
00128 }
00129 }
00130
00134 static void CL_ExecuteBattlescapeEvent (int now, void *data)
00135 {
00136 evTimes_t *event = (evTimes_t *)data;
00137 const eventRegister_t *eventData = CL_GetEvent(event->eType);
00138
00139 if (event->eType <= EV_START || cls.state == ca_active) {
00140 Com_DPrintf(DEBUG_EVENTSYS, "event(dispatching at %d): %s %p\n", now, eventData->name, event);
00141
00142 CL_LogEvent(eventData);
00143
00144 if (!eventData->eventCallback)
00145 Com_Error(ERR_DROP, "Event %i doesn't have a callback", event->eType);
00146
00147 eventData->eventCallback(eventData, event->msg);
00148 } else {
00149 Com_DPrintf(DEBUG_EVENTSYS, "event(not executed): %s %p\n", eventData->name, event);
00150 }
00151
00152 free_dbuffer(event->msg);
00153 Mem_Free(event);
00154 }
00155
00156 static void CL_FreeBattlescapeEvent (void *data)
00157 {
00158 evTimes_t *event = (evTimes_t *)data;
00159 free_dbuffer(event->msg);
00160 Mem_Free(event);
00161 }
00162
00163 static qboolean CL_FilterBattlescapeEvents (int when, event_func *func, event_check_func *check, void *data)
00164 {
00165 return (func != &CL_ExecuteBattlescapeEvent);
00166 }
00167
00168 void CL_ClearBattlescapeEvents (void)
00169 {
00170 CL_FilterEventQueue(&CL_FilterBattlescapeEvents);
00171 }
00172
00178 void CL_ParseEvent (struct dbuffer *msg)
00179 {
00180 qboolean now;
00181 const eventRegister_t *eventData;
00182 event_t eType = NET_ReadByte(msg);
00183 if (eType == EV_NULL)
00184 return;
00185
00186
00187 if (eType & EVENT_INSTANTLY) {
00188 now = qtrue;
00189 eType &= ~EVENT_INSTANTLY;
00190 } else
00191 now = qfalse;
00192
00193
00194 if (eType < EV_NULL || eType >= EV_NUM_EVENTS)
00195 Com_Error(ERR_DROP, "CL_ParseEvent: invalid event %i", eType);
00196
00197 eventData = CL_GetEvent(eType);
00198 if (!eventData->eventCallback)
00199 Com_Error(ERR_DROP, "CL_ParseEvent: no handling function for event %i", eType);
00200
00201 if (now) {
00202
00203 CL_LogEvent(eventData);
00204 Com_DPrintf(DEBUG_EVENTSYS, "event(now): %s\n", eventData->name);
00205 eventData->eventCallback(eventData, msg);
00206 } else {
00207 evTimes_t *cur = Mem_PoolAlloc(sizeof(*cur), cl_genericPool, 0);
00208 static int lastFrame = 0;
00209 const int delta = cl.time - lastFrame;
00210 int when;
00211
00212
00213 cur->msg = dbuffer_dup(msg);
00214 cur->eType = eType;
00215
00216
00217 when = CL_GetEventTime(cur->eType, msg, delta);
00218 Schedule_Event(when, &CL_ExecuteBattlescapeEvent, &CL_CheckBattlescapeEvent, &CL_FreeBattlescapeEvent, cur);
00219
00220 lastFrame = cl.time;
00221
00222 Com_DPrintf(DEBUG_EVENTSYS, "event(at %d): %s %p\n", when, eventData->name, cur);
00223 }
00224 }