26#include "../shared/autoptr.h"
29#include "../server/server.h"
30#include "../shared/parse.h"
31#include "../ports/system.h"
36#define MAXPRINTMSG 4096
37#define MAX_NUM_ARGVS 50
76#define TIMER_CHECK_INTERVAL 100
77#define TIMER_CHECK_LAG 3
78#define TIMER_LATENESS_HIGH 200
79#define TIMER_LATENESS_LOW 50
80#define TIMER_LATENESS_HISTORY 32
99 return e1->when < e2->when;
236 const float h = at[2] - from[2];
248 const float gd2 = g * d * d;
249 const float len = sqrt(h * h + d * d);
254 const float rollAngle = 3.0;
255 alpha = rollAngle *
torad;
256 const float theta = atan2(d, -h) - 2 * alpha;
257 const float k = gd2 / (
len * cos(theta) - h);
264 const float k = (
v *
v * h + gd2) / (
v *
v *
len);
267 if (launched && k >= -1 && k <= 1) {
269 alpha = 0.5 * (atan2(d, -h) - acos(k));
272 alpha = 0.5 * atan2(d, -h);
273 v = sqrt(gd2 / (
len - h));
278 const float vx =
v * cos(alpha);
279 const float vy =
v * sin(alpha);
310 if (!buffer || !buffersize)
369 const char* output = msg;
371 if (output[strlen(output) - 1] ==
'\n') {
421 static bool recursive =
false;
424 Sys_Error(
"recursive error after: %s", msg);
427 va_start(argptr, fmt);
473#if SDL_VERSION_ATLEAST(2, 0, 0)
474 SDL_MessageBoxData
data;
475 SDL_MessageBoxButtonData okButton;
476 SDL_MessageBoxButtonData cancelButton;
482 okButton.flags |= SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT;
483 okButton.text =
"Yes";
484 okButton.buttonid = 1;
486 cancelButton.flags |= SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT;
487 cancelButton.text =
"No";
488 cancelButton.buttonid = 2;
490 const SDL_MessageBoxButtonData
buttons[] = {okButton, cancelButton};
491 data.flags = SDL_MESSAGEBOX_ERROR;
492 data.title =
"Error";
493 data.message =
"Break into the debugger?";
496 data.window =
nullptr;
499 SDL_ShowMessageBox(&
data, &buttonid);
592 for (
int i = 0;
i < argc;
i++) {
600#define MACRO_CVAR_ID_LENGTH 6
611 const char* scan = text;
615 const int len = strlen(scan);
621 bool inquote =
false;
624 char* pos = expanded;
627 assert(scan[
len] ==
'\0');
628 for (
int i = 0;
i <=
len;
i++) {
651 Com_Printf(
"Could not get cvar value for cvar: %s\n", token);
655 const int j = strlen(cvarvalue);
666 if (++
count == 100) {
667 Com_Printf(
"Macro expansion loop, discarded.\n");
673 Com_Printf(
"Line has unmatched quote, discarded.\n");
690 const char* crashDumpURL =
"https://ufoai.org/CrashDump.php";
692 paramUser.
name =
"user";
694 paramUser.
next = ¶mVersion;
695 paramVersion.
name =
"version";
697 paramVersion.
next = ¶mOS;
700 paramOS.
next =
nullptr;
702 HTTP_PutFile(
"crashdump", crashDumpFile, crashDumpURL, ¶mUser);
719 const char* cmd =
nullptr, *cvar =
nullptr, *use =
nullptr;
724 if (!s[0] || s[0] ==
' ')
727 if (s[0] ==
'\\' || s[0] ==
'/') {
739 if (strstr(s,
" ")) {
742 cmdLine[strlen(cmdLine) - 1] =
'\0';
753 tmp = strrchr(cmdLine,
' ');
762 Q_strcat(cmdLine,
sizeof(cmdLine),
" %s", cmd);
772 Q_strncpyz(cmdBackup, cmd,
sizeof(cmdBackup));
776 if (cntCmd > 0 && !cntCvar) {
780 }
else if (!cntCmd && cntCvar > 0) {
784 }
else if (cmd && cvar) {
785 const int maxLength = std::min(strlen(cmdBackup),strlen(cvar));
788 Q_strncpyz(cmdLine, cmdBackup,
sizeof(cmdLine));
789 for (; idx < maxLength; idx++) {
790 if (cmdBackup[idx] != cvar[idx]) {
795 if (idx == maxLength)
804 *pos = strlen(target);
806 target[(*pos)++] =
' ';
826 for (j = 0, list = gt->
cvars; j < gt->num_cvars; j++, list++) {
850 for (j = 0, list = gt->
cvars; j < gt->num_cvars; j++, list++)
879static void Com_DebugHelp_f (
void)
881 Cvar_PrintDebugCvars();
883 Cmd_PrintDebugCommands();
889static void Com_DebugError_f (
void)
892 const char* errorType =
Cmd_Argv(1);
893 if (
Q_streq(errorType,
"ERR_DROP"))
895 else if (
Q_streq(errorType,
"ERR_FATAL"))
897 else if (
Q_streq(errorType,
"ERR_DISCONNECT"))
905typedef struct debugLevel_s {
930 int newValue = oldValue;
934 const char* debugLevel =
Cmd_Argv(1);
938 newValue &= ~debugLevels[
i].debugLevel;
946 Com_Printf(
"No valid debug mode parameter\n");
950 Com_Printf(
"Currently selected debug print levels\n");
967#ifndef DEDICATED_ONLY
991 FS_Printf(&
f,
"// generated by ufo, do not modify\n");
1008 const int mask = 1 << 7;
1011 for (
int cnt = 1; cnt <= 8; ++cnt) {
1012 *b++ = ((x & mask) == 0) ?
'0' :
'1';
1023 static char buf[37];
1024 const int mask = 1 << 31;
1027 for (
int cnt = 1; cnt <= 32; ++cnt) {
1028 *b++ = ((x & mask) == 0) ?
'0' :
'1';
1030 if (cnt % 8 == 0 && cnt != 32)
1123#ifdef DEDICATED_ONLY
1139 Cmd_AddCommand(
"debug_help", Com_DebugHelp_f,
"Show some debugging help");
1140 Cmd_AddCommand(
"debug_error", Com_DebugError_f,
"Just throw a fatal error to test error shutdown procedures");
1144 developer =
Cvar_Get(
"developer",
"0", 0,
"Activate developer output to logfile and gameconsole");
1146 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");
1148 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");
1155#ifdef DEDICATED_ONLY
1175 const char* hwclassVal =
"5";
1180 hwclass =
Cvar_Get(
"hwclass", hwclassVal, 0,
"Defines the hardware class of this machine. 1 is the lowest, 5 is the highest.");
1195 curl_global_init(CURL_GLOBAL_NOTHING);
1196 Com_Printf(
"%s initialized.\n", curl_version());
1205#ifndef DEDICATED_ONLY
1225 const cvar_t* com_pipefile =
Cvar_Get(
"com_pipefile",
"",
CVAR_ARCHIVE,
"Filename of the pipe that is used to send commands to the game");
1226 if (com_pipefile->
string[0] !=
'\0') {
1235#ifndef DEDICATED_ONLY
1250 Com_Printf(
"====== UFO Initialized ======\n");
1251 Com_Printf(
"=============================\n");
1253 Sys_Error(
"Error during initialization");
1367 event->check = check;
1368 event->clean = clean;
1370 event->delayFollowing = 0;
1371 event->delay =
nullptr;
1387 EventPriorityQueue::iterator itEnd =
eventQueue.end();
1388 for (;
i != itEnd;) {
1390 if (tmpEvent->func != event->func) {
1394 if (tmpEvent->delay !=
nullptr && !tmpEvent->delay(now, tmpEvent->data)){
1399 tmpEvent->when +=
event->delayFollowing;
1400 reOrder.insert(tmpEvent);
1403 for (EventPriorityQueue::iterator r = reOrder.begin(); r != reOrder.end(); ++r) {
1406 return reOrder.size();
1419 if (event->when > now)
1422 if (event->check ==
nullptr || event->check(now, event->data)) {
1428 if (event->delayFollowing > 0) {
1430 if (event->notifyDelay !=
nullptr) {
1431 event->notifyDelay(now, event->notifyDelayUserData, event->delayFollowing);
1454 const bool keep = filter(event->when, event->func, event->check, event->data);
1460 if (event->clean !=
nullptr)
1461 event->clean(event->data);
1463 EventPriorityQueue::iterator removeIter =
i++;
1500 event->func(event->when, event->data);
1507 if (restart.
gamedir !=
nullptr) {
1508 const char* restartArgv[] = {
"",
"+set",
"fs_gamedir", restart.
gamedir};
1523 if (time_to_next < 0)
1527 }
while (time_to_next > 0);
void Sys_ShowConsole(bool show)
void Sys_ConsoleOutput(const char *string)
void Sys_Backtrace(void)
On platforms supporting it, print a backtrace.
const char * Sys_GetCurrentUser(void)
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
static cvar_t * uploadcrashdump
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.
void Com_UploadCrashDump(const char *crashDumpFile)
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)
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,...)
bool HTTP_PutFile(const char *formName, const char *fileName, const char *url, const upparam_t *params)
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.
#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)
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.
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...
gametype_t gts[MAX_GAMETYPES]
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
cvarlist_t cvars[MAX_CVARLISTINGAMETYPE]
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)