36#define MAXPRINTMSG 4096
37#define MAX_NUM_ARGVS 50
75#define TIMER_CHECK_INTERVAL 100
76#define TIMER_CHECK_LAG 3
77#define TIMER_LATENESS_HIGH 200
78#define TIMER_LATENESS_LOW 50
79#define TIMER_LATENESS_HISTORY 32
129 void *library =
nullptr;
134 library = SDL_LoadObject(fullPath);
141 Com_Printf(
"Library '%s' loaded from %s\n", prefix, fullPath);
144 Com_Printf(
"Library '%s' could not be loaded from %s\n", prefix, path);
278 const float h = at[2] - from[2];
290 const float gd2 = g * d * d;
291 const float len = sqrt(h * h + d * d);
296 const float rollAngle = 3.0;
297 alpha = rollAngle *
torad;
298 const float theta = atan2(d, -h) - 2 * alpha;
299 const float k = gd2 / (
len * cos(theta) - h);
306 const float k = (
v *
v * h + gd2) / (
v *
v *
len);
309 if (launched && k >= -1 && k <= 1) {
311 alpha = 0.5 * (atan2(d, -h) - acos(k));
314 alpha = 0.5 * atan2(d, -h);
315 v = sqrt(gd2 / (
len - h));
320 const float vx =
v * cos(alpha);
321 const float vy =
v * sin(alpha);
352 if (!buffer || !buffersize)
411 const char* output = msg;
413 if (output[strlen(output) - 1] ==
'\n') {
463 static bool recursive =
false;
466 Sys_Error(
"recursive error after: %s", msg);
469 va_start(argptr, fmt);
515 SDL_MessageBoxData
data;
516 SDL_MessageBoxButtonData okButton;
517 SDL_MessageBoxButtonData cancelButton;
523 okButton.flags |= SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
524 okButton.text =
"Yes";
525 okButton.buttonid = 1;
527 cancelButton.flags |= SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
528 cancelButton.text =
"No";
529 cancelButton.buttonid = 2;
531 const SDL_MessageBoxButtonData
buttons[] = {okButton, cancelButton};
532 data.flags = SDL_MESSAGEBOX_ERROR;
533 data.title =
"Error";
534 data.message =
"Break into the debugger?";
537 data.window =
nullptr;
540 SDL_ShowMessageBox(&
data, &buttonid);
632 for (
int i = 0;
i < argc;
i++) {
640#define MACRO_CVAR_ID_LENGTH 6
651 const char* scan = text;
655 const int len = strlen(scan);
661 bool inquote =
false;
664 char* pos = expanded;
667 assert(scan[
len] ==
'\0');
668 for (
int i = 0;
i <=
len;
i++) {
691 Com_Printf(
"Could not get cvar value for cvar: %s\n", token);
695 const int j = strlen(cvarvalue);
706 if (++
count == 100) {
707 Com_Printf(
"Macro expansion loop, discarded.\n");
713 Com_Printf(
"Line has unmatched quote, discarded.\n");
736 const char* cmd =
nullptr, *cvar =
nullptr, *use =
nullptr;
741 if (!s[0] || s[0] ==
' ')
744 if (s[0] ==
'\\' || s[0] ==
'/') {
756 if (strstr(s,
" ")) {
759 cmdLine[strlen(cmdLine) - 1] =
'\0';
770 tmp = strrchr(cmdLine,
' ');
779 Q_strcat(cmdLine,
sizeof(cmdLine),
" %s", cmd);
789 Q_strncpyz(cmdBackup, cmd,
sizeof(cmdBackup));
793 if (cntCmd > 0 && !cntCvar) {
797 }
else if (!cntCmd && cntCvar > 0) {
801 }
else if (cmd && cvar) {
802 const int maxLength = std::min(strlen(cmdBackup),strlen(cvar));
805 Q_strncpyz(cmdLine, cmdBackup,
sizeof(cmdLine));
806 for (; idx < maxLength; idx++) {
807 if (cmdBackup[idx] != cvar[idx]) {
812 if (idx == maxLength)
821 *pos = strlen(target);
823 target[(*pos)++] =
' ';
836 for (
i = 0;
i <
csi.numGTs;
i++) {
843 for (j = 0, list = gt->
cvars; j < gt->num_cvars; j++, list++) {
860 for (
int i = 0;
i <
csi.numGTs;
i++) {
867 for (j = 0, list = gt->
cvars; j < gt->num_cvars; j++, list++)
896static void Com_DebugHelp_f (
void)
898 Cvar_PrintDebugCvars();
900 Cmd_PrintDebugCommands();
906static void Com_DebugError_f (
void)
909 const char* errorType =
Cmd_Argv(1);
910 if (
Q_streq(errorType,
"ERR_DROP"))
912 else if (
Q_streq(errorType,
"ERR_FATAL"))
914 else if (
Q_streq(errorType,
"ERR_DISCONNECT"))
922typedef struct debugLevel_s {
947 int newValue = oldValue;
951 const char* debugLevel =
Cmd_Argv(1);
963 Com_Printf(
"No valid debug mode parameter\n");
967 Com_Printf(
"Currently selected debug print levels\n");
984#ifndef DEDICATED_ONLY
1008 FS_Printf(&
f,
"// generated by ufo, do not modify\n");
1025 const int mask = 1 << 7;
1028 for (
int cnt = 1; cnt <= 8; ++cnt) {
1029 *b++ = ((x & mask) == 0) ?
'0' :
'1';
1040 static char buf[37];
1041 const int mask = 1 << 31;
1044 for (
int cnt = 1; cnt <= 32; ++cnt) {
1045 *b++ = ((x & mask) == 0) ?
'0' :
'1';
1047 if (cnt % 8 == 0 && cnt != 32)
1139#ifdef DEDICATED_ONLY
1155 Cmd_AddCommand(
"debug_help", Com_DebugHelp_f,
"Show some debugging help");
1156 Cmd_AddCommand(
"debug_error", Com_DebugError_f,
"Just throw a fatal error to test error shutdown procedures");
1160 developer =
Cvar_Get(
"developer",
"0", 0,
"Activate developer output to logfile and gameconsole");
1162 logfile_active =
Cvar_Get(
"logfile",
"2", 0,
"0 = deactivate logfile, 1 = write normal logfile, 2 = flush on every new line, 3 = always append to existing file");
1164 logfile_active =
Cvar_Get(
"logfile",
"1", 0,
"0 = deactivate logfile, 1 = write normal logfile, 2 = flush on every new line, 3 = always append to existing file");
1171#ifdef DEDICATED_ONLY
1191 const char* hwclassVal =
"5";
1196 hwclass =
Cvar_Get(
"hwclass", hwclassVal, 0,
"Defines the hardware class of this machine. 1 is the lowest, 5 is the highest.");
1206 Mem_InitCallbacks();
1213 curl_global_init(CURL_GLOBAL_NOTHING);
1214 Com_Printf(
"%s initialized.\n", curl_version());
1223#ifndef DEDICATED_ONLY
1243 const cvar_t* com_pipefile =
Cvar_Get(
"com_pipefile",
"",
CVAR_ARCHIVE,
"Filename of the pipe that is used to send commands to the game");
1244 if (com_pipefile->
string[0] !=
'\0') {
1253#ifndef DEDICATED_ONLY
1268 Com_Printf(
"====== UFO Initialized ======\n");
1269 Com_Printf(
"=============================\n");
1271 Sys_Error(
"Error during initialization");
1385 event->check = check;
1386 event->clean = clean;
1388 event->delayFollowing = 0;
1389 event->delay =
nullptr;
1405 EventPriorityQueue::iterator itEnd =
eventQueue.end();
1406 for (;
i != itEnd;) {
1408 if (tmpEvent->
func != event->func) {
1412 if (tmpEvent->
delay !=
nullptr && !tmpEvent->
delay(now, tmpEvent->
data)){
1417 tmpEvent->
when +=
event->delayFollowing;
1418 reOrder.insert(tmpEvent);
1421 for (EventPriorityQueue::iterator r = reOrder.begin(); r != reOrder.end(); ++r) {
1424 return reOrder.size();
1437 if (event->when > now)
1440 if (event->check ==
nullptr || event->check(now, event->data)) {
1446 if (event->delayFollowing > 0) {
1448 if (event->notifyDelay !=
nullptr) {
1449 event->notifyDelay(now, event->notifyDelayUserData, event->delayFollowing);
1472 const bool keep = filter(event->when, event->func, event->check, event->data);
1478 if (event->clean !=
nullptr)
1479 event->clean(event->data);
1481 EventPriorityQueue::iterator removeIter =
i++;
1518 event->func(event->when, event->data);
1525 if (restart.
gamedir !=
nullptr) {
1526 const char* restartArgv[] = {
"",
"+set",
"fs_gamedir", restart.
gamedir};
1541 if (time_to_next < 0)
1545 }
while (time_to_next > 0);
1558 Mem_ShutdownCallbacks();
void Sys_ShowConsole(bool show)
void Sys_ConsoleOutput(const char *string)
void Sys_Backtrace(void)
On platforms supporting it, print a backtrace.
void Con_Print(const char *txt)
Handles cursor positioning, line wrapping, etc All console printing must go through this in order to ...
void FS_CloseFile(qFILE *f)
void CL_Drop(void)
Ensures the right menu cvars are set after error drop or map change.
void CL_SlowFrame(int now, void *data)
void CL_Frame(int now, void *data)
void CL_Shutdown(void)
Saves configuration file and shuts the client systems down.
void CL_InitAfter(void)
Init function for clients - called after menu was initialized and ufo-scripts were parsed.
void SCR_EndLoadingPlaque(void)
bool operator()(const ScheduleEventPtr &e1, const ScheduleEventPtr &e2) const
void Cmd_ExecuteString(const char *text,...)
A complete command line has been parsed, so try to execute it.
const char * Cmd_Argv(int arg)
Returns a given argument.
void Cmd_WriteAliases(qFILE *f)
Write lines containing "aliasa alias value" for all aliases with the archive flag set to true.
void Cbuf_Execute(void)
Pulls off terminated lines of text from the command buffer and sends them through Cmd_ExecuteString...
int Cmd_CompleteCommandParameters(const char *command, const char *partial, const char **match)
Unix like tab completion for console commands parameters.
void Cbuf_AddEarlyCommands(bool clear)
Adds command line parameters as script statements Commands lead with a +, and continue until another ...
void Cbuf_Init(void)
allocates an initial text buffer that will grow as needed
int Cmd_Argc(void)
Return the number of arguments of the current command. "command parameter" will result in a argc of 2...
void Cmd_AddCommand(const char *cmdName, xcommand_t function, const char *desc)
Add a new command to the script interface.
bool Cbuf_AddLateCommands(void)
Adds command line parameters as script statements.
void Cbuf_AddText(const char *format,...)
Adds command text at the end of the buffer.
int Cmd_CompleteCommand(const char *partial, const char **match)
Unix like tab completion for console commands.
static void Com_WriteConfig_f(void)
Write the config file to a specific name.
const char * Com_ByteToBinary(byte x)
static struct net_stream * rd_stream
bool Com_ConsoleCompleteCommand(const char *s, char *target, size_t bufSize, uint32_t *pos, uint32_t offset)
Console completion for command and variables.
memPool_t * com_cmdSysPool
static EventPriorityQueue eventQueue
int Com_Argc(void)
Returns the script commandline argument count.
#define TIMER_CHECK_INTERVAL
void Qcommon_Frame(void)
This is the function that is called directly from main().
#define TIMER_LATENESS_LOW
static const debugLevel_t debugLevels[]
memPool_t * com_cvarSysPool
void Com_SetServerState(int state)
ScheduleEventPtr Dequeue_Event(int now)
Finds and returns the first event in the event_queue that is due. If the event has a check function,...
static const char * com_argv[MAX_NUM_ARGVS+1]
static void Schedule_Timer(cvar_t *freq, event_func *func, event_check_func *check, void *data)
#define TIMER_LATENESS_HIGH
void Com_ReadFromPipe(void)
Read whatever is in com_pipefile, if anything, and execute it.
void Com_vPrintf(const char *fmt, va_list ap)
void Com_DPrintf(int level, const char *fmt,...)
A Com_Printf that only shows up if the "developer" cvar is set.
int Com_ServerState(void)
Check whether we are the server or have a singleplayer tactical mission.
#define MACRO_CVAR_ID_LENGTH
static bool Com_CvarCheckMaxFPS(cvar_t *cvar)
Watches that the cvar cl_maxfps is never getting lower than 10.
void Qcommon_Init(int argc, char **argv)
Init function.
static void Com_DeveloperSet_f(void)
static vPrintfPtr_t vPrintfPtr
float Com_GrenadeTarget(const vec3_t from, const vec3_t at, float speed, bool launched, bool rolled, vec3_t v0)
Calculates parabola-type shot.
void Com_WriteConfigToFile(const char *filename)
vPrintfPtr_t Qcommon_GetPrintFunction(void)
static const char * libNameSuffix[]
Dynamic library filename suffix list.
void * Com_LoadLibrary(const char *path, const char *prefix)
Attempts to load a library using a filename suffix list.
void Com_Error(int code, const char *fmt,...)
void Com_SetGameType(void)
memPool_t * com_aliasSysPool
const char * Com_UnsignedIntToBinary(uint32_t x)
static void Com_GameTypeList_f(void)
void Com_SetRandomSeed(unsigned int seed)
void Com_Printf(const char *const fmt,...)
memPool_t * com_networkPool
const char * Com_MacroExpandString(const char *text)
Expands strings with cvar values that are dereferenced by a '*cvar'.
std::multiset< ScheduleEventPtr, CompareScheduleEvent > EventPriorityQueue
static unsigned int rd_buffersize
static void Com_InitArgv(int argc, char **argv)
cvar_t * masterserver_url
ScheduleEventPtr Schedule_Event(int when, event_func *func, event_check_func *check, event_clean_func *clean, void *data)
Schedules an event to run on or after the given time, and when its check function returns true.
int CL_FilterEventQueue(event_filter *filter)
Filters every event in the queue using the given function. Keeps all events for which the function re...
void Com_BeginRedirect(struct net_stream *stream, char *buffer, int buffersize)
Redirect packets/output from server to client.
void Com_ClearArgv(int arg)
Reset com_argv entry to empty string.
bool Com_CheckConfigStringIndex(int index)
void Com_EndRedirect(void)
End the redirection of packets/output.
static const char * consoleLogName
static cvar_t * logfile_active
static void tick_timer(int now, void *data)
static size_t Delay_Events(int now, EventPriorityQueue::iterator i)
Delay the following events and return the amount of events delayed.
void Com_BreakIntoDebugger(void)
static bool Event_FilterAll(int when, event_func *func, event_check_func *check, void *data)
Eventfilter that filter out all events.
memPool_t * com_genericPool
void Qcommon_SetPrintFunction(vPrintfPtr_t func)
memPool_t * com_cmodelSysPool
static void Cbuf_Execute_timer(int now, void *data)
memPool_t * com_fileSysPool
static cvar_t * cl_maxfps
#define TIMER_LATENESS_HISTORY
const char * Com_Argv(int arg)
Returns an argument of script commandline.
void Qcommon_Shutdown(void)
definitions common between client and server, but not game lib
void event_clean_func(void *data)
void(* vPrintfPtr_t)(const char *fmt, va_list ap)
void SV_Frame(int now, void *)
void Cvar_WriteVariables(qFILE *f)
appends lines containing "set variable value" for all variables with the archive flag set to true.
SharedPtr< scheduleEvent_t > ScheduleEventPtr
void event_func(int now, void *data)
void SV_Shutdown(const char *finalmsg, bool reconnect)
Called when each game quits, before Sys_Quit or Sys_Error.
bool event_check_func(int now, void *data)
void SV_Clear(void)
Cleanup when the whole game process is shutting down.
void SV_Init(void)
Only called once at startup, not for each game.
bool event_filter(int when, event_func *func, event_check_func *check, void *data)
cvar_t * Cvar_ForceSet(const char *varName, const char *value)
Will set the variable even if NOSET or LATCH.
void Com_SetRenderModified(bool modified)
void Cvar_SetValue(const char *varName, float value)
Expands value to a string and calls Cvar_Set.
cvar_t * Cvar_Set(const char *varName, const char *value,...)
Sets a cvar value.
bool Cvar_SetCheckFunction(const char *varName, bool(*check)(cvar_t *cvar))
Set a checker function for cvar values.
int Cvar_GetInteger(const char *varName)
Returns the int value of a cvar.
bool Cvar_AssertValue(cvar_t *cvar, float minVal, float maxVal, bool shouldBeIntegral)
Checks cvar values.
void Cvar_Init(void)
Reads in all archived cvars.
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags, const char *desc)
Init or return a cvar.
const char * Cvar_GetString(const char *varName)
Returns the value of cvar as string.
void Com_SetUserinfoModified(bool modified)
int Cvar_CompleteVariable(const char *partial, const char **match)
Unix like tab completion for console variables.
int FS_Read2(void *buffer, int len, qFILE *f, bool failOnEmptyRead)
Read a file into a given buffer in memory.
int FS_Printf(qFILE *f, const char *msg,...)
Can print chunks for 1024 chars into a file.
void FS_InitFilesystem(bool writeToHomeDir)
void FS_RemoveFile(const char *osPath)
int FS_Write(const void *buffer, int len, qFILE *f)
Properly handles partial writes.
void FS_Shutdown(void)
Cleanup function.
void FS_CreateOpenPipeFile(const char *filename, qFILE *f)
int FS_OpenFile(const char *filename, qFILE *file, filemode_t mode)
Finds and opens the file in the search path.
const char * FS_Gamedir(void)
Called to find where to write a file (savegames, etc).
void FS_ExecAutoexec(void)
void Sys_Error(const char *error,...)
void HTTP_Cleanup(void)
UFO is exiting or we're changing servers. Clean up.
vec_t VectorLength(const vec3_t v)
Calculate the length of a vector.
void VectorNormalizeFast(vec3_t v)
fast vector normalize routine that does not check to make sure that length != 0, nor does it return l...
#define Mem_CreatePool(name)
#define Mem_PoolAllocType(type, pool)
#define Mem_CheckGlobalIntegrity()
void NET_Wait(int timeout)
void NET_OOB_Printf(struct net_stream *s, const char *format,...)
Out of band print.
const char * Com_Parse(const char *data_p[], char *target, size_t size, bool replaceWhitespaces)
Parse a token out of a string.
Shared parsing functions.
#define MAX_CONFIGSTRINGS
QGL_EXTERN GLuint GLchar GLuint * len
QGL_EXTERN int GLboolean GLfloat * v
QGL_EXTERN GLsizei const GLvoid * data
QGL_EXTERN GLuint GLsizei bufSize
void Com_ParseScripts(bool onlyServer)
Main server include file.
server_state_t SV_GetServerState(void)
serverInstanceGame_t * sv
void Q_strncpyz(char *dest, const char *src, size_t destsize)
Safe strncpy that ensures a trailing zero.
void Com_DefaultExtension(char *path, size_t len, const char *extension)
Sets a default extension if there is none.
int Q_vsnprintf(char *str, size_t size, const char *format, va_list ap)
Safe (null terminating) vsnprintf implementation.
void Q_strcat(char *dest, size_t destsize, const char *format,...)
Safely (without overflowing the destination buffer) concatenates two strings.
void Com_MakeTimestamp(char *ts, const size_t tslen)
Creates a timestamp with date and time at the specified location.
bool Com_sprintf(char *dest, size_t size, const char *fmt,...)
copies formatted string with buffer-size checking
const char * va(const char *format,...)
does a varargs printf into a temp buffer, so I don't need to have varargs versions of all text functi...
The csi structure is the client-server-information structure which contains all the static data neede...
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
cvarlist_t cvars[MAX_CVARLISTINGAMETYPE]
event_delay_func * delay
Called when the check failed and we have to delay events in the queue.
int recent_lateness[TIMER_LATENESS_HISTORY]
void Sys_Breakpoint(void)
void Sys_InitSignals(void)
int Sys_Milliseconds(void)
#define VectorSubtract(a, b, dest)
#define VectorScale(in, scale, out)