int main(void) { Key_Def key; LED_Init(); Key_Init(); //Set_Keyint();//设置按键中断方式 while (1) { /* 按键查询方式 */ key = KEY_Scan(); switch (key) { case KEY1: LEDTog(LED1); break; case KEY2: LEDTog(LED2); break; case KEYNULL: break; default : break; } } }
int main(void) { SysTick_init(); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); uart_init(115200); Struct_Init(); Pid_Init(); MotoPwm_Init(); OLED_Init(); Key_Init(); I2cMaster_Init(); mpu_dmp_init(); GPIO_Config(); Filter_Init(); // NRF_Usart_Pin_Init();//无线初始化 // NRF_Read_Live_Init();//无线在线传输 // ReadData_Init(); Scheduler_Init(); while(1) { Scheduler_Loop(); } }
int main(void) { // uint32_t pre = 0 ; uint8_t* p = 0; timer_config(); SPIx_Init(); Led_Init(); Key_Init(); Usart2_Init(9600); // enc28j60_init(mac); install_uart_dev(); stack_init(); // test_hardhandler(2,(int*)1); my_tftp_init(); telnet_service_init(); // web_server_init(); // *p = 1 ; #if 0 while(1) { stack_process(); Led_Process(); shell(); } #endif bootstart(); return 0 ; }
void BSP_Init(void) { Key_Init(); LED_Init(); //MyLCD_Init(); Touch_Init(); SysTick_Init(); }
int main(void) { LED_Init(LED_2 | LED_3); Beep_Init(); SysTick_Init(1, SYSTICK_MS); LED_On(LED_2 | LED_3); Usart_Init(); //Beep_On(); SysTick_Delay(200, SYSTICK_MS); //Beep_Off(); LED_Off(LED_2 | LED_3); Key_Init(KEY_S1 | KEY_S2 | KEY_S3 | KEY_S4); Keyboard_Init(); //LCD_Init(); ADS1118_Init(); while(1) { printf("准备完毕 开始转换!\n"); ADS1118_CS_Reset(); while(!GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_6)); ConversionValue = ADS1118_Read(count);//8283 ADS1118_CS_Set(); printf(" The Value is 0X%08x ,%08d\n",ConversionValue,ConversionValue); ad= ConversionValue*4.096/32768; printf("AD=%fV\n",ad); SysTick_Delay(1000, SYSTICK_MS); // Keyboard_Loop(); // //LCD_Clear(Color_White); // //LCD_Set_ForeColor(Color_Red); // //if(Keyboard_Scan() == KEYBOARD_S1) { LCD_Show_String(30,50,200,16,16, "Key Board Test"); } // if(Keyboard_Detect(KEYBOARD_S1, KEYBOARD_DOWN)) { printf("S1\r\n"); } // if(Keyboard_Detect(KEYBOARD_S2, KEYBOARD_DOWN)) { printf("S2\r\n"); } // if(Keyboard_Detect(KEYBOARD_S3, KEYBOARD_DOWN)) { printf("S3\r\n"); } // if(Keyboard_Detect(KEYBOARD_S4, KEYBOARD_DOWN)) { printf("S4\r\n"); } // if(Keyboard_Detect(KEYBOARD_S5, KEYBOARD_DOWN)) { printf("S5\r\n"); } // if(Keyboard_Detect(KEYBOARD_S6, KEYBOARD_DOWN)) { printf("S6\r\n"); } // if(Keyboard_Detect(KEYBOARD_S7, KEYBOARD_DOWN)) { printf("S7\r\n"); } // if(Keyboard_Detect(KEYBOARD_S8, KEYBOARD_DOWN)) { printf("S8\r\n"); } // if(Keyboard_Detect(KEYBOARD_S9, KEYBOARD_DOWN)) { printf("S9\r\n"); } // if(Keyboard_Detect(KEYBOARD_S10, KEYBOARD_DOWN)) { printf("S10\r\n"); } // if(Keyboard_Detect(KEYBOARD_S11, KEYBOARD_DOWN)) { printf("S11\r\n"); } // if(Keyboard_Detect(KEYBOARD_S12, KEYBOARD_DOWN)) { printf("S12\r\n"); } // if(Keyboard_Detect(KEYBOARD_S13, KEYBOARD_DOWN)) { printf("S13\r\n"); } // if(Keyboard_Detect(KEYBOARD_S14, KEYBOARD_DOWN)) { printf("S14\r\n"); } // if(Keyboard_Detect(KEYBOARD_S15, KEYBOARD_DOWN)) { printf("S15\r\n"); } // if(Keyboard_Detect(KEYBOARD_S16, KEYBOARD_DOWN)) { printf("S16\r\n"); } // //LCD_Set_ForeColor(Color_Green); // //LCD_Show_String(30,70,200,16,16, "TFT-LCD test"); // //LCD_Set_ForeColor(Color_Blue); // //LCD_Show_String(30,90,200,16,16, "www.doflye.net"); // //LCD_Draw_Circle(100,180,20); // //SysTick_Delay(1000, SYSTICK_MS); } }
static void rt_thread_entry_led(void* parameter) { LED_Init(); Key_Init(); Set_Keyint(); while(1) { LEDTog(LED1); LEDTog(LED2); LEDTog(LED3); LEDTog(LED4); rt_thread_delay(RT_TICK_PER_SECOND/2); } }
void Task_KeyScan (void) { static INT8U ucKeyCodeHolder = 0X00; INT8U ucKeyCode = 0X00; CACTL1 = CARSEL + CAREF1 + CAON; CACTL2 = P2CA0 + CAF; switch (g_sKey.ScanState) { case KEY_STATE_UP: // See if need to look for a key pressed if (Key_Pressed()) { // See if key is pressed g_sKey.ScanState = KEY_STATE_DEBOUNCE; // Next call we will have debounced the key ucKeyCodeHolder = 0X00; } g_sKey.Time = 0; break; case KEY_STATE_DEBOUNCE: // Key pressed, get scan code and buffer if (Key_Pressed()) { // See if key is pressed ucKeyCode = Key_Decode(); // Determine the key scan code if (ucKeyCode != ucKeyCodeHolder) { Key_PushKey(ucKeyCode); // Input scan code in buffer ucKeyCodeHolder = ucKeyCode; } g_sKey.Time += KEY_SCAN_ALT; g_sKey.Pressed = 1; } else { g_sKey.ScanState = KEY_STATE_UP; // Key was not pressed after all! g_sKey.Pressed = 0; } break; default: Key_Init(); break; } CACTL1 &=~ (CAREF1 + CAREF0);//CAON); if (Key_Hit()) EnableBackLight(30); }
/******************************************************************************* 函数名: main 功能说明: 主函数 参 数: 无 返回值: 无 *******************************************************************************/ int main(void) { Key_Init(); KeyLowPowerHandle(); Thread_Init(); SysHard_Init(); //系统相关硬件初始化 FIFOInit(); //初始化队列缓冲区 Instruct_Init(); DeviceResetCheck_Init(); Test_Init(); Unit_Init(); KeyTimer_Init(); while(1) { Process_FIFOData(&rcv433fifo, &rcv_433); //处理接收FIFO Thread_Process(); } }
void keyTask(void *pdata) { Key_Init(); while(1) { OSTimeDlyHMSM(0,0,0,50); if(!KEY0)//按下变低电平 { OSTimeDlyHMSM(0,0,0,10); if(!KEY0)//消抖 { //发信号 OSSemPost(pkey); //等待按键抬起 while(!KEY0) OSTimeDlyHMSM(0,0,0,10); } } } }
/* * main.c */ int main(void) { //WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer Clock_Init(); WDT_Init(); WX315_Init(); led_init(); Init_HC05(); TimerA_Init(); Key_Init(); MQ2_Init(); Ir_Init(); Sound_Init(); // //__bis_SR_register(LPM0_bits + GIE); _EINT(); led0_off();//默认开蓝牙使能 delay_ms(1000); while(1){ if(temp_tx_flag==1){ for(i=0;i<8;i++){ UartPutchar(ch[i]); } temp_tx_flag=0; } if(flag_mq2==1){ flag_mq2=0; UartPutchar('V');//Vapour 烟雾传感器 有漏气 向APP发送指令'V' } if(flag_ir==1){ flag_ir=0; UartPutchar('I');//Ir 红外传感器 有漏气 向APP发送指令'I' } if(flag_sound==1){ flag_sound=0; UartPutchar('S');//Sound 声音传感器 有大风 向APP发送指令'S' } switch(uart_temp){ //color case 'r': RGB_r(); uart_temp=' '; break; case 'o': RGB_o(); uart_temp=' '; break; case 'y': RGB_y(); uart_temp=' '; break; case 'g': RGB_g(); uart_temp=' '; break; case 'b': RGB_b(); uart_temp=' '; break; case 'p': RGB_p(); uart_temp=' '; break; case 'w': RGB_w(); uart_temp=' '; break; case 'd'://关灯 dieout RGB_d(); uart_temp=' '; break; //*********************************************************** case 'm'://开窗 m motor Window_m(); uart_temp=' '; break; case 'n'://关窗 Window_n(); uart_temp=' '; break; //*********************************************************** case 'u'://加热 u up TempNew_u(); uart_temp=' '; break; case 'v'://制冷 TempNew_v(); uart_temp=' '; break; case 'x'://停止加热 TempNew_x(); uart_temp=' '; break; case 'z'://停止制冷 TempNew_z(); uart_temp=' '; break; //************************************************************ case 'c'://回家模式 Home_Mode_Backhome(); break; case 'e'://浪漫模式 Home_Mode_Romatic(); break; case 'f'://离家模式 Home_Mode_Awayhome(); break; default:break; } } //return 0; }
void Host_Init (int argc, char **argv, int default_memsize) { vfsfile_t *vf; cvar_t *v; char cfg[MAX_PATH] = {0}; int i; char *cfg_name; COM_InitArgv (argc, argv); COM_StoreOriginalCmdline(argc, argv); #ifdef WITH_DP_MEM Memory2_Init (); #endif Host_InitMemory (default_memsize); #ifdef WITH_TCL // interpreter should be initialized // before any cvar definitions TCL_InterpInit (); #endif Cbuf_Init (); Cmd_Init (); Cvar_Init (); COM_Init (); Key_Init (); #ifdef WITH_DP_MEM Memory2_Init_Commands (); #endif Cache_Init_Commands (); FS_InitFilesystem (); NET_Init (); Commands_For_Configs_Init (); ConfigManager_Init(); ResetBinds(); i = COM_CheckParm("+cfg_load"); if (i && (i + 1 < COM_Argc())) { cfg_name = COM_Argv(i + 1); } else { cfg_name = MAIN_CONFIG_FILENAME; } snprintf(cfg, sizeof(cfg), "%s", cfg_name); COM_ForceExtensionEx (cfg, ".cfg", sizeof (cfg)); Cbuf_AddText(va("cfg_load %s\n", cfg)); Cbuf_Execute(); Cbuf_AddEarlyCommands (); Cbuf_Execute (); Con_Init (); NET_InitClient (); Netchan_Init (); #if (!defined WITH_PNG_STATIC || !defined WITH_JPEG_STATIC || defined WITH_MP3_PLAYER) QLib_Init(); #endif Sys_Init (); CM_Init (); PM_Init (); Mod_Init (); SV_Init (); CL_Init (); Cvar_CleanUpTempVars (); SYSINFO_Init(); #ifdef WITH_TCL if (!TCL_InterpLoaded()) Com_Printf_State (PRINT_FAIL, "Could not load "TCL_LIB_NAME", embedded Tcl disabled\n"); #endif Hunk_AllocName (0, "-HOST_HUNKLEVEL-"); host_hunklevel = Hunk_LowMark (); host_initialized = true; // walk through all vars and forse OnChange event if cvar was modified, // also apply that to variables which mirrored in userinfo because of cl_parsefunchars was't applyed as this moment, // same for serverinfo and may be this fix something also. for ( v = NULL; (v = Cvar_Next ( v )); ) { char val[2048]; // if ( !v->modified ) // continue; // not modified even that strange at this moment if ( Cvar_GetFlags( v ) & (CVAR_ROM | CVAR_INIT) ) continue; snprintf(val, sizeof(val), "%s", v->string); Cvar_Set(v, val); } Hud_262LoadOnFirstStart(); Com_Printf_State (PRINT_INFO, "Exe: "__TIME__" "__DATE__"\n"); Com_Printf_State (PRINT_INFO, "Hunk allocation: %4.1f MB.\n", (float) host_memsize / (1024 * 1024)); Com_Printf ("\nezQuake %s\n\n", VersionString()); Com_Printf(Host_PrintBars("ezQuake\x9c" "SourceForge\x9c" "net", 38)); Com_Printf(Host_PrintBars("ezQuake Initialized", 38)); Com_Printf("\n"); Com_Printf ("\nType /help to access the manual.\nUse /describe to learn about commands.\n", VersionString()); if ((vf = FS_OpenVFS("autoexec.cfg", "rb", FS_ANY))) { Cbuf_AddText ("exec autoexec.cfg\n"); VFS_CLOSE(vf); } Cmd_StuffCmds_f (); // process command line arguments Cbuf_AddText ("cl_warncmd 1\n"); #ifdef WIN32 // // Verify that ezQuake is associated with the QW:// protocl handler. // { extern qbool CL_CheckIfQWProtocolHandler(); extern cvar_t cl_verify_qwprotocol; if (cl_verify_qwprotocol.integer >= 2) { // Always register the qw:// protocol. Cbuf_AddText("register_qwurl_protocol\n"); } else if (cl_verify_qwprotocol.integer == 1 && !CL_CheckIfQWProtocolHandler()) { // Check if the running exe is the one associated with the qw:// protocol. Com_PrintVerticalBar(0.8 * vid.conwidth / 8); Com_Printf("\n"); Com_Printf("This ezQuake is not associated with the "); Com_Printf("\x02QW:// protocol.\n"); Com_Printf("Register it using "); Com_Printf("\x02/register_qwurl_protocol\n"); Com_Printf("(set "); Com_Printf("\x02 cl_verify_qwprotocol "); Com_Printf("to 0 to hide this warning)\n"); Com_PrintVerticalBar(0.8 * vid.conwidth / 8); Com_Printf("\n"); } } #endif // WIN32 // Check if a qtv/demo file is specified as the first argument, in that case play that // otherwise, do some more checks of what to show at startup. { char cmd[1024] = {0}; if (COM_CheckArgsForPlayableFiles(cmd, sizeof(cmd))) { Cbuf_AddText(cmd); } else { Startup_Place(); } } #ifdef _WIN32 SetForegroundWindow(mainwindow); SetActiveWindow(mainwindow); #endif host_everything_loaded = true; }
/** * @brief Init function * @sa Com_ParseScripts * @sa Qcommon_Shutdown * @sa Sys_Init * @sa CL_Init */ void Qcommon_Init (int argc, char** argv) { logfile_active = nullptr; developer = nullptr; Sys_InitSignals(); /* random seed */ Com_SetRandomSeed(time(nullptr)); com_aliasSysPool = Mem_CreatePool("Common: Alias system for commands and enums"); com_cmdSysPool = Mem_CreatePool("Common: Command system"); com_cmodelSysPool = Mem_CreatePool("Common: Collision model"); com_cvarSysPool = Mem_CreatePool("Common: Cvar system"); com_fileSysPool = Mem_CreatePool("Common: File system"); com_genericPool = Mem_CreatePool("Generic"); com_networkPool = Mem_CreatePool("Network"); try { OBJZERO(csi); /* prepare enough of the subsystems to handle * cvar and command buffer management */ Com_InitArgv(argc, argv); Swap_Init(); Cbuf_Init(); Cmd_Init(); Cvar_Init(); uploadcrashdump = Cvar_Get("uploadcrashdump", "1", 0, "upload crashdumps to the developers"); Key_Init(); /* we need to add the early commands twice, because * a basedir needs to be set before executing * config files, but we want other parms to override * the settings of the config files */ Cbuf_AddEarlyCommands(false); Cbuf_Execute(); FS_InitFilesystem(true); Cbuf_AddText("exec default.cfg\n"); #ifdef DEDICATED_ONLY Cbuf_AddText("exec dedconfig.cfg\n"); #else Cbuf_AddText("exec config.cfg\n"); #endif Cbuf_AddEarlyCommands(true); Cbuf_Execute(); Com_SetRenderModified(false); Com_SetUserinfoModified(false); /* init commands and vars */ Cmd_AddCommand("saveconfig", Com_WriteConfig_f, "Write the configuration to file"); Cmd_AddCommand("gametypelist", Com_GameTypeList_f, "List all available multiplayer game types"); #ifdef DEBUG Cmd_AddCommand("debug_help", Com_DebugHelp_f, "Show some debugging help"); Cmd_AddCommand("debug_error", Com_DebugError_f, "Just throw a fatal error to test error shutdown procedures"); #endif Cmd_AddCommand("setdeveloper", Com_DeveloperSet_f, "Set the developer cvar to only get the debug output you want"); developer = Cvar_Get("developer", "0", 0, "Activate developer output to logfile and gameconsole"); #ifdef DEBUG 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"); #else 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"); #endif sv_gametype = Cvar_Get("sv_gametype", "fight1on1", CVAR_ARCHIVE | CVAR_SERVERINFO, "Sets the multiplayer gametype - see gametypelist command for a list of all gametypes"); http_proxy = Cvar_Get("http_proxy", "", CVAR_ARCHIVE, "Use this proxy for http transfers"); http_timeout = Cvar_Get("http_timeout", "3", CVAR_ARCHIVE, "Http connection and read timeout"); port = Cvar_Get("port", DOUBLEQUOTE(PORT_SERVER), CVAR_NOSET); masterserver_url = Cvar_Get("masterserver_url", MASTER_SERVER, CVAR_ARCHIVE, "URL of UFO:AI masterserver"); #ifdef DEDICATED_ONLY sv_dedicated = Cvar_Get("sv_dedicated", "1", CVAR_SERVERINFO | CVAR_NOSET, "Is this a dedicated server?"); /* don't allow to override this from commandline of config */ Cvar_ForceSet("sv_dedicated", "1"); #else sv_dedicated = Cvar_Get("sv_dedicated", "0", CVAR_SERVERINFO | CVAR_NOSET, "Is this a dedicated server?"); /* set this to false for client - otherwise Qcommon_Frame would set the initial values to multiplayer */ sv_gametype->modified = false; s_language = Cvar_Get("s_language", "", CVAR_ARCHIVE, "Game language - full language string e.g. en_EN.UTF-8"); s_language->modified = false; cl_maxfps = Cvar_Get("cl_maxfps", "50", CVAR_ARCHIVE); Cvar_SetCheckFunction("cl_maxfps", Com_CvarCheckMaxFPS); #endif // 5 is an i7 with a medium gfx-card // 3 dual core with 2 GB // 2 EeePc with 1 GB // 1 smartphone const char* hwclassVal = "5"; #ifdef __ANDROID__ /** get the hardware class of the machine we are running on. */ hwclassVal = "1"; #endif hwclass = Cvar_Get("hwclass", hwclassVal, 0, "Defines the hardware class of this machine. 1 is the lowest, 5 is the highest."); const char* s = va("UFO: Alien Invasion %s %s %s %s", UFO_VERSION, CPUSTRING, __DATE__, BUILDSTRING); Cvar_Get("version", s, CVAR_NOSET, "Full version string"); Cvar_Get("ver", UFO_VERSION, CVAR_SERVERINFO | CVAR_NOSET, "Version number"); if (sv_dedicated->integer) Cmd_AddCommand("quit", Com_Quit, "Quits the game"); Mem_Init(); Sys_Init(); NET_Init(); #ifndef NO_HTTP curl_global_init(CURL_GLOBAL_NOTHING); Com_Printf("%s initialized.\n", curl_version()); #endif SV_Init(); /* e.g. init the client hunk that is used in script parsing */ CL_Init(); Com_ParseScripts(sv_dedicated->integer); #ifndef DEDICATED_ONLY Cbuf_AddText("exec keys.cfg\n"); #endif if (!sv_dedicated->integer) Cbuf_AddText("init\n"); else Cbuf_AddText("dedicated_start\n"); Cbuf_Execute(); FS_ExecAutoexec(); /* add + commands from command line * if the user didn't give any commands, run default action */ if (Cbuf_AddLateCommands()) { /* the user asked for something explicit * so drop the loading plaque */ SCR_EndLoadingPlaque(); } const cvar_t* com_pipefile = Cvar_Get("com_pipefile", "", CVAR_ARCHIVE, "Filename of the pipe that is used to send commands to the game"); if (com_pipefile->string[0] != '\0') { FS_CreateOpenPipeFile(com_pipefile->string, &pipefile); } CL_InitAfter(); /* Check memory integrity */ Mem_CheckGlobalIntegrity(); #ifndef DEDICATED_ONLY if (!sv_dedicated->integer) { Schedule_Timer(cl_maxfps, &CL_Frame, nullptr, nullptr); Schedule_Timer(Cvar_Get("cl_slowfreq", "10", 0, nullptr), &CL_SlowFrame, nullptr, nullptr); /* now hide the console */ Sys_ShowConsole(false); } #endif Schedule_Timer(Cvar_Get("sv_freq", "10", CVAR_NOSET, nullptr), &SV_Frame, nullptr, nullptr); /** @todo This line wants to be removed */ Schedule_Timer(Cvar_Get("cbuf_freq", "10", 0, nullptr), &Cbuf_Execute_timer, nullptr, nullptr); Com_Printf("====== UFO Initialized ======\n"); Com_Printf("=============================\n"); } catch (comDrop_t const&) { Sys_Error("Error during initialization"); } }
/* ================= Qcommon_Init ================= */ void Qcommon_Init(int argc, char **argv) { if (setjmp(abortframe)) Sys_Error("Error during initialization: %s", com_errorMsg); com_argc = argc; com_argv = argv; Com_SetLastError(NULL); X86_SetFPCW(); // prepare enough of the subsystems to handle // cvar and command buffer management Z_Init(); MSG_Init(); Cbuf_Init(); Cmd_Init(); Cvar_Init(); Key_Init(); Prompt_Init(); Con_Init(); // // init commands and vars // z_perturb = Cvar_Get("z_perturb", "0", 0); #if USE_CLIENT host_speeds = Cvar_Get("host_speeds", "0", 0); #endif #ifdef _DEBUG developer = Cvar_Get("developer", "0", 0); #endif timescale = Cvar_Get("timescale", "1", CVAR_CHEAT); fixedtime = Cvar_Get("fixedtime", "0", CVAR_CHEAT); logfile_enable = Cvar_Get("logfile", "0", 0); logfile_flush = Cvar_Get("logfile_flush", "0", 0); logfile_name = Cvar_Get("logfile_name", "console", 0); logfile_prefix = Cvar_Get("logfile_prefix", "[%Y-%m-%d %H:%M] ", 0); #if USE_CLIENT dedicated = Cvar_Get("dedicated", "0", CVAR_NOSET); cl_running = Cvar_Get("cl_running", "0", CVAR_ROM); cl_paused = Cvar_Get("cl_paused", "0", CVAR_ROM); #else dedicated = Cvar_Get("dedicated", "1", CVAR_ROM); #endif sv_running = Cvar_Get("sv_running", "0", CVAR_ROM); sv_paused = Cvar_Get("sv_paused", "0", CVAR_ROM); com_timedemo = Cvar_Get("timedemo", "0", CVAR_CHEAT); com_date_format = Cvar_Get("com_date_format", "%Y-%m-%d", 0); #ifdef _WIN32 com_time_format = Cvar_Get("com_time_format", "%H.%M", 0); #else com_time_format = Cvar_Get("com_time_format", "%H:%M", 0); #endif #ifdef _DEBUG com_debug_break = Cvar_Get("com_debug_break", "0", 0); #endif com_fatal_error = Cvar_Get("com_fatal_error", "0", 0); com_version = Cvar_Get("version", com_version_string, CVAR_SERVERINFO | CVAR_ROM); allow_download = Cvar_Get("allow_download", COM_DEDICATED ? "0" : "1", CVAR_ARCHIVE); allow_download_players = Cvar_Get("allow_download_players", "1", CVAR_ARCHIVE); allow_download_models = Cvar_Get("allow_download_models", "1", CVAR_ARCHIVE); allow_download_sounds = Cvar_Get("allow_download_sounds", "1", CVAR_ARCHIVE); allow_download_maps = Cvar_Get("allow_download_maps", "1", CVAR_ARCHIVE); allow_download_textures = Cvar_Get("allow_download_textures", "1", CVAR_ARCHIVE); allow_download_pics = Cvar_Get("allow_download_pics", "1", CVAR_ARCHIVE); allow_download_others = Cvar_Get("allow_download_others", "0", 0); rcon_password = Cvar_Get("rcon_password", "", CVAR_PRIVATE); Cmd_AddCommand("z_stats", Z_Stats_f); //Cmd_AddCommand("setenv", Com_Setenv_f); Cmd_AddMacro("com_date", Com_Date_m); Cmd_AddMacro("com_time", Com_Time_m); Cmd_AddMacro("com_uptime", Com_Uptime_m); Cmd_AddMacro("com_uptime_long", Com_UptimeLong_m); Cmd_AddMacro("random", Com_Random_m); Cmd_AddMacro("com_maplist", Com_MapList_m); // add any system-wide configuration files Sys_AddDefaultConfig(); // we need to add the early commands twice, because // a basedir or cddir needs to be set before execing // config files, but we want other parms to override // the settings of the config files Com_AddEarlyCommands(qfalse); Sys_Init(); Sys_RunConsole(); FS_Init(); Sys_RunConsole(); // no longer allow CVAR_NOSET modifications com_initialized = qtrue; // after FS is initialized, open logfile logfile_enable->changed = logfile_enable_changed; logfile_flush->changed = logfile_param_changed; logfile_name->changed = logfile_param_changed; logfile_enable_changed(logfile_enable); // execute configs: default.cfg may come from the packfile, but config.cfg // and autoexec.cfg must be real files within the game directory Com_AddConfigFile(COM_DEFAULT_CFG, 0); Com_AddConfigFile(COM_CONFIG_CFG, FS_TYPE_REAL | FS_PATH_GAME); Com_AddConfigFile(COM_AUTOEXEC_CFG, FS_TYPE_REAL | FS_PATH_GAME); Com_AddConfigFile(COM_POSTEXEC_CFG, FS_TYPE_REAL); Com_AddEarlyCommands(qtrue); Cmd_AddCommand("lasterror", Com_LastError_f); Cmd_AddCommand("quit", Com_Quit_f); #if !USE_CLIENT Cmd_AddCommand("recycle", Com_Recycle_f); #endif srand(Sys_Milliseconds()); Netchan_Init(); NET_Init(); BSP_Init(); CM_Init(); SV_Init(); CL_Init(); TST_Init(); Sys_RunConsole(); // add + commands from command line if (!Com_AddLateCommands()) { // if the user didn't give any commands, run default action char *cmd = COM_DEDICATED ? "dedicated_start" : "client_start"; if ((cmd = Cmd_AliasCommand(cmd)) != NULL) { Cbuf_AddText(&cmd_buffer, cmd); Cbuf_Execute(&cmd_buffer); } } else { // the user asked for something explicit // so drop the loading plaque SCR_EndLoadingPlaque(); } // even not given a starting map, dedicated server starts // listening for rcon commands (create socket after all configs // are executed to make sure port number is properly set) if (COM_DEDICATED) { NET_Config(NET_SERVER); } Com_AddConfigFile(COM_POSTINIT_CFG, FS_TYPE_REAL); Com_Printf("====== " PRODUCT " initialized ======\n\n"); Com_LPrintf(PRINT_NOTICE, APPLICATION " " VERSION ", " __DATE__ "\n"); Com_Printf("http://skuller.net/q2pro/\n\n"); time(&com_startTime); com_eventTime = Sys_Milliseconds(); }
void main(void) { u16 i; u8 shortcut = KEY_INVALID; // RS485 Node init_var(); //init data structure // System Initialization Init_Port(); // Init_Timers(); // Init_Ex_Interrupt(); Init_UART(); Enable_XMEM(); Init_554(); InitLED(); Key_Init(); // Global enable interrupts WDTCR = 0x00; //disable dog watch #asm("sei") /*********************************************************************/ // System hardware dection /*********************************************************************/ // intialize LED. nextwin = 0; sleepms(20*ONEMS); LCD_Init(); wnd_msgbox(&bootup); //init the DMM nav_command(NAV_INIT); sleepms(200*ONEMS); navto1v(); nav_command(NAV_SLOWMODE); sleepms(200*ONEMS); nav_command(NAV_AFLTON); sleepms(200*ONEMS); sleepms(2*ONEMS); //wait until all the node is ready after power up State_Init(); SET_BORE_MODE; nextwin = PG_BOOTTYPE; key = KEY_INVALID; curr_ch = 1; //channel for display curr_dispch = 1; while(1) { if(nextwin != 0) { SwitchWindow(nextwin); (*curr_window)(MSG_INIT); nextwin = 0; } if(key != KEY_INVALID) { if((key == KEY_BTN1)||(key == KEY_BTN2)||(key == KEY_BTN3)||(key == KEY_BTN4)) { shortcut = key; //processing shortcut key if(curr_window == pgmain_handler) { LCD_Cls(); wnd_msgbox(&modify); } if(shortcut == KEY_BTN1) //mode switch { SET_TOP1MA; SET_TOPT1000; if(IS_BORE_MODE){ SET_THERM_MODE; }else{ SET_BORE_MODE; } dlg_cnt = 0; onesec_cnt = 0; phase = 0; //reset the state machine } if(shortcut == KEY_BTN2) //auto ktt or not { if(IS_BORE_MODE) { SET_TOP1MA; SET_TOPT1000; if((IS_MODE_KTT)){ CLR_MODE_KTT; SET_PKTT; }else{ SET_MODE_KTT; SET_PKTT; } dlg_cnt = 0; onesec_cnt = 0; phase = 0; //reset the state machine } } if(shortcut == KEY_BTN3) //thermal probe type { display_buttons(KEY_BTN3,1); if(IS_THERM_MODE) { i = sysdata.tid[curr_dispch-1]; if(i != INVALID_PROBE) { if((tprbdata.type[i] >= PRBTYPE_K) &&\ (tprbdata.type[i] <= PRBTYPE_R)) { if(tprbdata.type[i] == PRBTYPE_R) tprbdata.type[i] = PRBTYPE_K; else tprbdata.type[i] +=1; } if(rundata.reading[curr_dispch-1] > -9000) rundata.temperature[curr_dispch-1] = MValueToTValue(rundata.reading[curr_dispch-1], tprbdata.type[i]); } } display_buttons(KEY_BTN3,0); } if(shortcut == KEY_BTN4) //remove zero { display_buttons(KEY_BTN4,1); if(IS_BORE_MODE){ sysdata.R0 = rundata.Rx; }else{ //sysdata.V0 = nav_read(); nav_command(NAV_ZEROON); sleepms(1000*ONEMS); } display_buttons(KEY_BTN4,0); } if(curr_window == pgmain_handler) //redraw the running window { pgmain_handler(MSG_INIT); } shortcut = KEY_INVALID; }else{ (*curr_window)(key); } key = KEY_INVALID; }else{ if(curr_window != pgmain_handler) continue; if(dlg_cnt > 1) { onesec_cnt++; if(onesec_cnt == (ONESEC-10)) { updatestate(); } if(onesec_cnt == ONESEC) onesec_cnt = 0 ; dlg_cnt--; continue; } updatestate(); if((IS_THERM_MODE)) { if(therm_state() == 0) continue; }else{ if(bore_state() == 0) continue; } //shift to next channel while(true) { ch_to_search += 1; if(ch_to_search >= MAX_CH_NUM) { ch_to_search = 0; break; } if(IS_THERM_MODE) { i = sysdata.tid[ch_to_search]; }else{ i = sysdata.rid[ch_to_search]; } if(i == INVALID_PROBE) continue; if(IS_THERM_MODE) { if((tprbdata.type[i] >= PRBTYPE_K) && (tprbdata.type[i] <= PRBTYPE_R)) break; }else{ if((rprbdata.type[i] <= PRBTYPE_MAX) && (rprbdata.type[i] >= PRBTYPE_MIN)) break; } } } } }
int main( void) { int autoID,dispID,dispIndex; int timerval; U16 btnStat,oldStat; rGPACDH = rdGPACDH & ~(1<<5) | (0<<5); // RDATA_OEN : enable rGPHCON=rGPHCON&~(0xf<<26)|(0xa<<26); rMISCCR=rMISCCR&~((0x7<<8)|(0x7<<4))|(0x3<<8)|(0x2<<4); // test code start setting in option.h SetCLKDIV( Startup_ARMCLKdiv, Startup_PREdiv, Startup_HCLKdiv, Startup_PCLKdiv); SetMPLL( Startup_MDIV, Startup_PDIV, Startup_SDIV); SystemCLK(0); Isr_Init(); MMU_Init(); SPI_Init(); Console(); printf("\n\n***********TST-500_OTM1283+AUO5.7_720*1280 Test Program Ver 0.0***********\n"); //printf("MPLL=%.2fMHz, ARMCLK=%.2fMHz (%d:%d:%d), HCLK=%.2fMHz, PCLK=%.2fMHz\n\n", // (float)MPLL/1000000,(float)ARMCLK/1000000,ARMCLKdiv+1,(ARMCLKdiv+1)*(HCLKdiv+1),(ARMCLKdiv+1)*(HCLKdiv+1)*(PCLKdiv+1),(float)HCLK/1000000,(float)PCLK/1000000); Init_SSD2805_SPI(); //2805 spi初始化,位于/Peripheral/Video/LCD/Display.c文件 SetLcdPort(); //2443 RGB端口及相关寄存器配置,其中RGB参数位于Display.h文件 SPI_READ_ID(0xb0); Key_Init(); //按键初始化 dispID = 0; dispIndex = 1; autoID = 0; timerval = 0; btnStat=0; oldStat=0; while(1) // { if(dispIndex) { dispIndex = 0; switch(dispID) { case 0: disp_color(0xF800,0,0,XSIZE,YSIZE); break; //显示R颜色 case 1: disp_color(0x07E0,0,0,XSIZE,YSIZE); break; //显示G颜色 case 2: disp_color(0x001F,0,0,XSIZE,YSIZE); break; //显示B颜色 case 3: disp_9WB(); break; case 4: disp_color_table(); break; case 5: disp_gray(); break; case 6: disp_color(0xffff,0,0,XSIZE,YSIZE); break; //显示白色 case 7: disp_color(0x0000,0,0,XSIZE,YSIZE); K9S1208_RdBmp(TFT_RAM1,TFT_SMC_BLK1,TFT_BmpSize); break;//把图片数据拷贝到内存,TFT_RAM1,TFT_SMC_BLK1定义在Display.h文件 break;//Delay(10); //显示黑色 case 8: disp_bmp((U16 *)TFT_RAM1,0,0,XSIZE,YSIZE); K9S1208_RdBmp(TFT_RAM2,TFT_SMC_BLK2,TFT_BmpSize); break; //显示内存的图片的数据 case 9: disp_bmp((U16 *)TFT_RAM2,0,0,XSIZE,YSIZE); K9S1208_RdBmp(TFT_RAM3,TFT_SMC_BLK3,TFT_BmpSize); break; //显示内存的图片的数据 case 10: disp_bmp((U16 *)TFT_RAM3,0,0,XSIZE,YSIZE); K9S1208_RdBmp(TFT_RAM4,TFT_SMC_BLK4,TFT_BmpSize); break; //显示内存的图片的数据 case 11: disp_bmp((U16 *)TFT_RAM4,0,0,XSIZE,YSIZE); break; } // printf("\display id = %d\n",dispID); Delay_MS(400); } if(autoID) { timerval++; if(timerval>30) { timerval = 0; dispID++; if(dispID>BmpMAX) dispID=0; dispIndex = 1; //Init_SSD2805_SPI(); } } btnStat = rGPJDAT; btnStat = (~btnStat)&0x0007; //printf("\ndisplay btn = 0x%x\n",btnStat); if(btnStat) { if(((btnStat&0x01)==0x01) && ((oldStat&0x01)==0x00)) //GPJ0自动手动切换 { if(autoID) autoID = 0; else autoID = 1; } if(((btnStat&0x02)==0x02) && ((oldStat&0x02)==0x00)) //GPJ1画面向前翻 { dispID++; if(dispID>BmpMAX) dispID=0; dispIndex = 1; //Init_SSD2828(); } if(((btnStat&0x04)==0x04) && ((oldStat&0x04)==0x00)) //GPJ2画面向后翻 { // dispID++; if(dispID>0) dispID--; else dispID = BmpMAX; dispIndex = 1; } // Delay_MS(100); } Delay_MS(50); //延时,并且监视串口 oldStat = btnStat; } //-------------------------------------------------------------------------------------------- }
void Host_Init(quakeparms_t *parms) { if (standard_quake) minimum_memory = MINIMUM_MEMORY; else minimum_memory = MINIMUM_MEMORY_LEVELPAK; if (COM_CheckParm("-minmemory")) parms->memsize = minimum_memory; host_parms = *parms; if (parms->memsize < minimum_memory) Sys_Error("Only %4.1f megs of memory available, can't execute game", parms->memsize / (float) 0x100000); com_argc = parms->argc; com_argv = parms->argv; Memory_Init(parms->membase, parms->memsize); Cbuf_Init(); Cmd::Init(); V_Init(); NN_init(); COM_Init(); Host_InitLocal(); W_LoadWadFile("gfx.wad"); Key_Init(); Con_Init(); M_Init(); PR_Init(); Mod_Init(); NET_Init(); SV_Init(); Bot_Init(); Con_Printf("Exe: "__TIME__" "__DATE__"\n"); Con_Printf("%4.1f megabyte heap\n", parms->memsize / (1024 * 1024.0)); if (cls.state != ca_dedicated) { host_basepal = (byte *) COM_LoadHunkFile("gfx/palette.lmp"); if (!host_basepal) Sys_Error("Couldn't load gfx/palette.lmp"); host_colormap = (byte *) COM_LoadHunkFile("gfx/colormap.lmp"); if (!host_colormap) Sys_Error("Couldn't load gfx/colormap.lmp"); IN_Init(); VID_Init(host_basepal); Draw_Init(); SCR_Init(); R_Init(); TextureManager::Init(); S_Init(); CDAudio_Init(); Sbar_Init(); CL_Init(); } Cbuf_InsertText("exec quake.rc\n"); Hunk_AllocName(0, "-HOST_HUNKLEVEL-"); host_hunklevel = Hunk_LowMark(); host_initialized = true; Sys_Printf("========Quake Initialized=========\n"); }
/* ==================== Host_Init ==================== */ void Host_Init (int argc, char **argv, int default_memsize) { COM_InitArgv (argc, argv); #if !defined(CLIENTONLY) && !defined(SERVERONLY) if (COM_CheckParm("-dedicated")) dedicated = true; #endif Host_InitMemory (default_memsize); Cbuf_Init (); Cmd_Init (); Cvar_Init (); COM_Init (); Key_Init (); FS_InitFilesystem (); COM_CheckRegistered (); Con_Init (); if (!dedicated) { Cbuf_AddText ("exec default.cfg\n"); Cbuf_AddText ("exec config.cfg\n"); Cbuf_Execute (); } Cbuf_AddEarlyCommands (); Cbuf_Execute (); NET_Init (); Netchan_Init (); Sys_Init (); CM_Init (); PM_Init (); Host_InitLocal (); SV_Init (); CL_Init (); Cvar_CleanUpTempVars (); Hunk_AllocName (0, "-HOST_HUNKLEVEL-"); host_hunklevel = Hunk_LowMark (); host_initialized = true; Com_Printf ("Exe: "__TIME__" "__DATE__"\n"); Com_Printf ("%4.1f megs RAM used.\n", host_memsize / (1024*1024.0)); Com_Printf ("\n========= " PROGRAM " Initialized =========\n"); if (dedicated) { Cbuf_AddText ("exec server.cfg\n"); Cmd_StuffCmds_f (); // process command line arguments Cbuf_Execute (); // if a map wasn't specified on the command line, spawn start map if (!com_serveractive) Cmd_ExecuteString ("map start"); if (!com_serveractive) Host_Error ("Couldn't spawn a server"); } else { Cbuf_AddText ("exec autoexec.cfg\n"); Cmd_StuffCmds_f (); // process command line arguments Cbuf_AddText ("cl_warncmd 1\n"); } }
int main(void) { u8 len=0; u8 temp[100]; u8 t=0; u8 flag=0; char mode='O'; long value=0; u8 counter=0; //char val2str[]="50"; char SelfCheck='O'; int D_val=0; u8 SelfCheckCounter=0; /////////////////////以上变量定义/////////////////////////// delay_init(72); USART1_Init(19200);//与地面站传递命令 USART2_Init(115200);//与X86板子传递命令 USART3_Init(115200);//调试用 HCSR04_Init(); ResetOLED(); OLED_Init(); Key_Init(); ///////////////以上初始化/////////////////////// OLED_ShowString(35,20,"READY",24); OLED_Refresh_Gram(); delay_ms(1000); OLED_Clear(); /////////////////////////////欢迎界面,提示准备工作///////////////////////////////// while(KEY==1) { OLED_ShowString(0,0,"Self checking now...",12); OLED_Refresh_Gram(); if(USART_RX2_STA&0x8000) { len=USART_RX2_STA&0x3fff;//得到此次接收到的数据长度 for(t=0;t<len;t++) { temp[t]=Rx2Buf[t]; while((USART2->SR&0X40)==0);//等待发送结束 } flag=1; USART_RX2_STA=0; }//接受来自X86的命令,用于自检。 if(flag==1) { SelfCheck=TempOrPressure(temp); { if(SelfCheck=='C') { value=ValueOfMea(temp); if(value==1) { OLED_ShowString(0,15,"Environment ok",12); SelfCheckCounter++; } if(value==2) { OLED_ShowString(0,30,"The data chain ok",12); } if(value==0) { OLED_ShowString(0,42,"Checking fail...",12); } } } memset(temp,0,sizeof(u8)*100); flag=0; }//先对开发环境进行自检,在VS下下发ok标志即可。 OLED_Refresh_Gram(); if(SelfCheckCounter==1)//如果已经通过了开发环境自检 { while(KEY==1)//不按强制退出就一直自检,直到成功 { if(DataChain_SelfTest()==1)//数据链自检完成 break; else continue; } SelfCheckCounter=0; break;//在不按按键强制退出的情况下,只有自检成功了才能退出。 } } OLED_Clear(); /////////////////////////以上对上位机的自检,按键强制结束////////////////// OLED_ShowString(0,0,"Parameters",16); OLED_ShowString(0,16,"X=",12); OLED_ShowString(0,28,"Y=",12); OLED_ShowString(0,40,"S=",12); OLED_ShowString(0,52,"D=",12); OLED_Refresh_Gram(); flag=0;//复位flag ///////////显示参数//////////////////////////////// //AutoLaunch(); ////////////////////////以上开始起飞///////////////////////////////// while(1) { if(USART_RX2_STA&0x8000) { len=USART_RX2_STA&0x3fff;//得到此次接收到的数据长度 for(t=0;t<len;t++) { temp[t]=Rx2Buf[t]; while((USART2->SR&0X40)==0);//等待发送结束 } flag=1; USART_RX2_STA=0; //printf3("%s\r\n",temp); }//接受来自X86的命令 if(flag==1) { mode=TempOrPressure(temp); if(mode=='S') { value=ValueOfMea(temp); { #ifdef __TRANSPARENT_MODE printf1("\"S\":\"%ld\"\r\n",value); #endif #ifdef __COMMAND_MODE E17_SendMsg(CMD_S_PARAM,value); #endif } OLED_ShowNum(20,40,value,6,12); // counter++; } if(mode=='X') { value=ValueOfMea(temp); { #ifdef __TRANSPARENT_MODE printf1("\"X\":\"%ld\"\r\n",value); #endif #ifdef __COMMAND_MODE E17_SendMsg(CMD_X_PARAM,value); #endif } OLED_ShowNum(20,16,value,6,12); // counter++; } else if(mode=='Y') { value=ValueOfMea(temp); { #ifdef __TRANSPARENT_MODE printf1("\"Y\":\"%ld\"\r\n",value); #endif #ifdef __COMMAND_MODE E17_SendMsg(CMD_Y_PARAM,value); #endif } OLED_ShowNum(20,28,value,6,12); // counter++; } { delay_ms(10);//太小在透传情况下可能出问题? { D_val=HCSR04_GetDistance_Filter(); #ifdef __TRANSPARENT_MODE printf1("\"D\":\"%ld\"\r\n",D_val); #endif #ifdef __COMMAND_MODE E17_SendMsg(CMD_D_PARAM,value); #endif } OLED_ShowNum(20,52,D_val,6,12); // counter=0; }//去掉了判断,每个周期都要做判断,同时进行距离的pid调控。 OLED_Refresh_Gram(); memset(temp,0,sizeof(u8)*100); flag=0; } } }
/* ==================== Host_Init ==================== */ static void Host_Init (void) { int i; const char* os; char vabuf[1024]; if (COM_CheckParm("-profilegameonly")) Sys_AllowProfiling(false); // LordHavoc: quake never seeded the random number generator before... heh if (COM_CheckParm("-benchmark")) srand(0); // predictable random sequence for -benchmark else srand((unsigned int)time(NULL)); // FIXME: this is evil, but possibly temporary // LordHavoc: doesn't seem very temporary... // LordHavoc: made this a saved cvar // COMMANDLINEOPTION: Console: -developer enables warnings and other notices (RECOMMENDED for mod developers) if (COM_CheckParm("-developer")) { developer.value = developer.integer = 1; developer.string = "1"; } if (COM_CheckParm("-developer2") || COM_CheckParm("-developer3")) { developer.value = developer.integer = 1; developer.string = "1"; developer_extra.value = developer_extra.integer = 1; developer_extra.string = "1"; developer_insane.value = developer_insane.integer = 1; developer_insane.string = "1"; developer_memory.value = developer_memory.integer = 1; developer_memory.string = "1"; developer_memorydebug.value = developer_memorydebug.integer = 1; developer_memorydebug.string = "1"; } if (COM_CheckParm("-developer3")) { gl_paranoid.integer = 1;gl_paranoid.string = "1"; gl_printcheckerror.integer = 1;gl_printcheckerror.string = "1"; } // COMMANDLINEOPTION: Console: -nostdout disables text output to the terminal the game was launched from if (COM_CheckParm("-nostdout")) sys_nostdout = 1; // used by everything Memory_Init(); // initialize console command/cvar/alias/command execution systems Cmd_Init(); // initialize memory subsystem cvars/commands Memory_Init_Commands(); // initialize console and logging and its cvars/commands Con_Init(); // initialize various cvars that could not be initialized earlier u8_Init(); Curl_Init_Commands(); Cmd_Init_Commands(); Sys_Init_Commands(); COM_Init_Commands(); FS_Init_Commands(); // initialize console window (only used by sys_win.c) Sys_InitConsole(); // initialize the self-pack (must be before COM_InitGameType as it may add command line options) FS_Init_SelfPack(); // detect gamemode from commandline options or executable name COM_InitGameType(); // construct a version string for the corner of the console os = DP_OS_NAME; dpsnprintf (engineversion, sizeof (engineversion), "%s %s %s", gamename, os, buildstring); Con_Printf("%s\n", engineversion); // initialize process nice level Sys_InitProcessNice(); // initialize ixtable Mathlib_Init(); // initialize filesystem (including fs_basedir, fs_gamedir, -game, scr_screenshot_name) FS_Init(); // register the cvars for session locking Host_InitSession(); // must be after FS_Init Crypto_Init(); Crypto_Init_Commands(); NetConn_Init(); Curl_Init(); //PR_Init(); //PR_Cmd_Init(); PRVM_Init(); Mod_Init(); World_Init(); SV_Init(); V_Init(); // some cvars needed by server player physics (cl_rollangle etc) Host_InitCommands(); Host_InitLocal(); Host_ServerOptions(); Thread_Init(); if (cls.state == ca_dedicated) Cmd_AddCommand ("disconnect", CL_Disconnect_f, "disconnect from server (or disconnect all clients if running a server)"); else { Con_DPrintf("Initializing client\n"); R_Modules_Init(); Palette_Init(); #ifdef CONFIG_MENU MR_Init_Commands(); #endif VID_Shared_Init(); VID_Init(); Render_Init(); S_Init(); CDAudio_Init(); Key_Init(); CL_Init(); } // save off current state of aliases, commands and cvars for later restore if FS_GameDir_f is called // NOTE: menu commands are freed by Cmd_RestoreInitState Cmd_SaveInitState(); // FIXME: put this into some neat design, but the menu should be allowed to crash // without crashing the whole game, so this should just be a short-time solution // here comes the not so critical stuff if (setjmp(host_abortframe)) { return; } Host_AddConfigText(); Cbuf_Execute(); // if stuffcmds wasn't run, then quake.rc is probably missing, use default if (!host_stuffcmdsrun) { Cbuf_AddText("exec default.cfg\nexec " CONFIGFILENAME "\nexec autoexec.cfg\nstuffcmds\n"); Cbuf_Execute(); } // put up the loading image so the user doesn't stare at a black screen... SCR_BeginLoadingPlaque(true); #ifdef CONFIG_MENU if (cls.state != ca_dedicated) { MR_Init(); } #endif // check for special benchmark mode // COMMANDLINEOPTION: Client: -benchmark <demoname> runs a timedemo and quits, results of any timedemo can be found in gamedir/benchmark.log (for example id1/benchmark.log) i = COM_CheckParm("-benchmark"); if (i && i + 1 < com_argc) if (!sv.active && !cls.demoplayback && !cls.connect_trying) { Cbuf_AddText(va(vabuf, sizeof(vabuf), "timedemo %s\n", com_argv[i + 1])); Cbuf_Execute(); } // check for special demo mode // COMMANDLINEOPTION: Client: -demo <demoname> runs a playdemo and quits i = COM_CheckParm("-demo"); if (i && i + 1 < com_argc) if (!sv.active && !cls.demoplayback && !cls.connect_trying) { Cbuf_AddText(va(vabuf, sizeof(vabuf), "playdemo %s\n", com_argv[i + 1])); Cbuf_Execute(); } // COMMANDLINEOPTION: Client: -capturedemo <demoname> captures a playdemo and quits i = COM_CheckParm("-capturedemo"); if (i && i + 1 < com_argc) if (!sv.active && !cls.demoplayback && !cls.connect_trying) { Cbuf_AddText(va(vabuf, sizeof(vabuf), "playdemo %s\ncl_capturevideo 1\n", com_argv[i + 1])); Cbuf_Execute(); } if (cls.state == ca_dedicated || COM_CheckParm("-listen")) if (!sv.active && !cls.demoplayback && !cls.connect_trying) { Cbuf_AddText("startmap_dm\n"); Cbuf_Execute(); } if (!sv.active && !cls.demoplayback && !cls.connect_trying) { #ifdef CONFIG_MENU Cbuf_AddText("togglemenu 1\n"); #endif Cbuf_Execute(); } Con_DPrint("========Initialized=========\n"); //Host_StartVideo(); if (cls.state != ca_dedicated) SV_StartThread(); }
/* ==================== Host_Init ==================== */ void Host_Init (void) { if (standard_quake) minimum_memory = MINIMUM_MEMORY; else minimum_memory = MINIMUM_MEMORY_LEVELPAK; if (COM_CheckParm ("-minmemory")) host_parms->memsize = minimum_memory; if (host_parms->memsize < minimum_memory) Sys_Error ("Only %4.1f megs of memory available, can't execute game", host_parms->memsize / (float)0x100000); com_argc = host_parms->argc; com_argv = host_parms->argv; Memory_Init (host_parms->membase, host_parms->memsize); Cbuf_Init (); Cmd_Init (); LOG_Init (host_parms); Cvar_Init (); //johnfitz COM_Init (); COM_InitFilesystem (); Host_InitLocal (); W_LoadWadFile (); //johnfitz -- filename is now hard-coded for honesty if (cls.state != ca_dedicated) { Key_Init (); Con_Init (); } PR_Init (); Mod_Init (); NET_Init (); SV_Init (); Con_Printf ("Exe: "__TIME__" "__DATE__"\n"); Con_Printf ("%4.1f megabyte heap\n", host_parms->memsize/ (1024*1024.0)); if (cls.state != ca_dedicated) { host_colormap = (byte *)COM_LoadHunkFile ("gfx/colormap.lmp", NULL); if (!host_colormap) Sys_Error ("Couldn't load gfx/colormap.lmp"); V_Init (); Chase_Init (); M_Init (); ExtraMaps_Init (); //johnfitz Modlist_Init (); //johnfitz DemoList_Init (); //ericw VID_Init (); IN_Init (); TexMgr_Init (); //johnfitz Draw_Init (); SCR_Init (); R_Init (); S_Init (); CDAudio_Init (); BGM_Init(); Sbar_Init (); CL_Init (); } Hunk_AllocName (0, "-HOST_HUNKLEVEL-"); host_hunklevel = Hunk_LowMark (); host_initialized = true; Con_Printf ("\n========= Quake Initialized =========\n\n"); if (cls.state != ca_dedicated) { Cbuf_InsertText ("exec quake.rc\n"); // johnfitz -- in case the vid mode was locked during vid_init, we can unlock it now. // note: two leading newlines because the command buffer swallows one of them. Cbuf_AddText ("\n\nvid_unlock\n"); } if (cls.state == ca_dedicated) { Cbuf_AddText ("exec autoexec.cfg\n"); Cbuf_AddText ("stuffcmds"); Cbuf_Execute (); if (!sv.active) Cbuf_AddText ("map start\n"); } }
/* ================= Host_InitCommon ================= */ void Host_InitCommon( int argc, const char** argv, const char *progname, qboolean bChangeGame ) { char dev_level[4]; char *baseDir; // some commands may turn engine into infinite loop, // e.g. xash.exe +game xash -game xash // so we clear all cmd_args, but leave dbg states as well Sys_ParseCommandLine( argc, argv ); host.enabledll = !Sys_CheckParm( "-nodll" ); host.shutdown_issued = false; host.crashed = false; #ifdef DLL_LOADER if( host.enabledll ) Setup_LDT_Keeper( ); // Must call before any thread creating #endif #if defined(XASH_SDL) && !(defined(PANDORA) || defined(RPI)) if( SDL_Init( SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_EVENTS )) { Sys_Error( "SDL_Init: %s", SDL_GetError() ); } #endif if( ( baseDir = getenv( "XASH3D_BASEDIR" ) ) ) { Q_strncpy( host.rootdir, baseDir, sizeof(host.rootdir) ); } else { #if defined(PANDORA) || defined(RPI) Q_strncpy( host.rootdir, ".", sizeof( host.rootdir ) ); #else #if defined(XASH_SDL) if( !( baseDir = SDL_GetBasePath() ) ) Sys_Error( "couldn't determine current directory: %s", SDL_GetError() ); Q_strncpy( host.rootdir, baseDir, sizeof( host.rootdir ) ); #else if( !getcwd( host.rootdir, sizeof(host.rootdir) ) ) host.rootdir[0] = 0; #endif #endif } if( host.rootdir[Q_strlen( host.rootdir ) - 1] == '/' ) host.rootdir[Q_strlen( host.rootdir ) - 1] = 0; if( !Sys_CheckParm( "-noch" ) ) { Sys_SetupCrashHandler(); } host.change_game = bChangeGame; host.state = HOST_INIT; // initialization started host.developer = host.old_developer = 0; host.textmode = false; host.mempool = Mem_AllocPool( "Zone Engine" ); if( Sys_CheckParm( "-console" )) host.developer = 1; if( Sys_CheckParm( "-dev" )) { if( Sys_GetParmFromCmdLine( "-dev", dev_level )) { if( Q_isdigit( dev_level )) host.developer = abs( Q_atoi( dev_level )); else host.developer++; // -dev == 1, -dev -console == 2 } else host.developer++; // -dev == 1, -dev -console == 2 } #ifdef XASH_DEDICATED host.type = HOST_DEDICATED; // predict state #else if( Sys_CheckParm("-dedicated") || progname[0] == '#' ) host.type = HOST_DEDICATED; else host.type = HOST_NORMAL; #endif host.con_showalways = true; host.mouse_visible = false; #ifdef XASH_SDL if( SDL_Init( SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_EVENTS )) { SDL_Init( SDL_INIT_TIMER ); host.type = HOST_DEDICATED; } #endif if ( SetCurrentDirectory( host.rootdir ) != 0) MsgDev( D_INFO, "%s is working directory now\n", host.rootdir ); else Sys_Error( "Changing working directory to %s failed.\n", host.rootdir ); // set default gamedir if( progname[0] == '#' ) progname++; Q_strncpy( SI.ModuleName, progname, sizeof( SI.ModuleName )); if( host.type == HOST_DEDICATED ) { Sys_MergeCommandLine( ); if( host.developer < 3 ) host.developer = 3; // otherwise we see empty console } else { // don't show console as default if( host.developer < D_WARN ) host.con_showalways = false; } host.old_developer = host.developer; if( !Sys_CheckParm( "-nowcon" ) ) Con_CreateConsole(); // first text message into console or log MsgDev( D_NOTE, "Sys_LoadLibrary: Loading Engine Library - ok\n" ); // startup cmds and cvars subsystem Cmd_Init(); Cvar_Init(); // share developer level across all dlls Q_snprintf( dev_level, sizeof( dev_level ), "%i", host.developer ); Cvar_Get( "developer", dev_level, CVAR_INIT, "current developer level" ); Cmd_AddCommand( "exec", Host_Exec_f, "execute a script file" ); Cmd_AddCommand( "memlist", Host_MemStats_f, "prints memory pool information" ); Cmd_AddCommand( "userconfigd", Host_Userconfigd_f, "execute all scripts from userconfig.d" ); cmd_scripting = Cvar_Get( "cmd_scripting", "0", CVAR_ARCHIVE, "enable simple condition checking and variable operations" ); FS_Init(); Image_Init(); Sound_Init(); FS_LoadGameInfo( NULL ); Q_strncpy( host.gamefolder, GI->gamefolder, sizeof( host.gamefolder )); #if !(defined(PANDORA) || defined(RPI)) if( GI->secure ) { // clear all developer levels when game is protected Cvar_FullSet( "developer", "0", CVAR_INIT ); host.developer = host.old_developer = 0; host.con_showalways = false; } #endif HPAK_Init(); IN_Init(); Key_Init(); }
/* * Qcommon_Init */ void Qcommon_Init( int argc, char **argv ) { if( setjmp( abortframe ) ) Sys_Error( "Error during initialization: %s", com_errormsg ); QThreads_Init(); com_print_mutex = QMutex_Create(); // initialize memory manager Memory_Init(); // prepare enough of the subsystems to handle // cvar and command buffer management COM_InitArgv( argc, argv ); Cbuf_Init(); // initialize cmd/cvar/dynvar tries Cmd_PreInit(); Cvar_PreInit(); Dynvar_PreInit(); // create basic commands and cvars Cmd_Init(); Cvar_Init(); Dynvar_Init(); dynvars_initialized = qtrue; wswcurl_init(); Key_Init(); // we need to add the early commands twice, because // a basepath or cdpath needs to be set before execing // config files, but we want other parms to override // the settings of the config files Cbuf_AddEarlyCommands( qfalse ); Cbuf_Execute(); // wsw : aiwa : create dynvars (needs to be completed before .cfg scripts are executed) Dynvar_Create( "sys_uptime", qtrue, Com_Sys_Uptime_f, DYNVAR_READONLY ); Dynvar_Create( "frametick", qfalse, DYNVAR_WRITEONLY, DYNVAR_READONLY ); Dynvar_Create( "quit", qfalse, DYNVAR_WRITEONLY, DYNVAR_READONLY ); Dynvar_Create( "irc_connected", qfalse, Irc_GetConnected_f, Irc_SetConnected_f ); Sys_InitDynvars(); CL_InitDynvars(); #ifdef TV_SERVER_ONLY tv_server = Cvar_Get( "tv_server", "1", CVAR_NOSET ); Cvar_ForceSet( "tv_server", "1" ); #else tv_server = Cvar_Get( "tv_server", "0", CVAR_NOSET ); #endif #ifdef DEDICATED_ONLY dedicated = Cvar_Get( "dedicated", "1", CVAR_NOSET ); Cvar_ForceSet( "dedicated", "1" ); #else dedicated = Cvar_Get( "dedicated", "0", CVAR_NOSET ); #endif #ifdef MATCHMAKER mm_server = Cvar_Get( "mm_server", "1", CVAR_READONLY ); Cvar_ForceSet( "mm_server", "1" ); #else mm_server = Cvar_Get( "mm_server", "0", CVAR_READONLY ); #endif FS_Init(); Cbuf_AddText( "exec default.cfg\n" ); if( !dedicated->integer ) { Cbuf_AddText( "exec config.cfg\n" ); Cbuf_AddText( "exec autoexec.cfg\n" ); } else if( mm_server->integer ) { Cbuf_AddText( "exec mmaker_autoexec.cfg\n" ); } else if( tv_server->integer ) { Cbuf_AddText( "exec tvserver_autoexec.cfg\n" ); } else { Cbuf_AddText( "exec dedicated_autoexec.cfg\n" ); } Cbuf_AddEarlyCommands( qtrue ); Cbuf_Execute(); // // init commands and vars // Memory_InitCommands(); Qcommon_InitCommands(); host_speeds = Cvar_Get( "host_speeds", "0", 0 ); log_stats = Cvar_Get( "log_stats", "0", 0 ); developer = Cvar_Get( "developer", "0", 0 ); timescale = Cvar_Get( "timescale", "1.0", CVAR_CHEAT ); fixedtime = Cvar_Get( "fixedtime", "0", CVAR_CHEAT ); if( tv_server->integer ) logconsole = Cvar_Get( "logconsole", "tvconsole.log", CVAR_ARCHIVE ); else if( dedicated->integer ) logconsole = Cvar_Get( "logconsole", "wswconsole.log", CVAR_ARCHIVE ); else logconsole = Cvar_Get( "logconsole", "", CVAR_ARCHIVE ); logconsole_append = Cvar_Get( "logconsole_append", "1", CVAR_ARCHIVE ); logconsole_flush = Cvar_Get( "logconsole_flush", "0", CVAR_ARCHIVE ); logconsole_timestamp = Cvar_Get( "logconsole_timestamp", "0", CVAR_ARCHIVE ); com_showtrace = Cvar_Get( "com_showtrace", "0", 0 ); com_introPlayed3 = Cvar_Get( "com_introPlayed3", "0", CVAR_ARCHIVE ); Cvar_Get( "irc_server", "irc.quakenet.org", CVAR_ARCHIVE ); Cvar_Get( "irc_port", "6667", CVAR_ARCHIVE ); Cvar_Get( "irc_nick", APPLICATION "Player", CVAR_ARCHIVE ); Cvar_Get( "irc_user", APPLICATION "User", CVAR_ARCHIVE ); Cvar_Get( "irc_password", "", CVAR_ARCHIVE ); Cvar_Get( "gamename", APPLICATION, CVAR_READONLY ); versioncvar = Cvar_Get( "version", APP_VERSION_STR " " CPUSTRING " " __DATE__ " " BUILDSTRING, CVAR_SERVERINFO|CVAR_READONLY ); revisioncvar = Cvar_Get( "revision", SVN_RevString(), CVAR_READONLY ); Sys_Init(); NET_Init(); Netchan_Init(); CM_Init(); Steam_LoadLibrary(); Com_ScriptModule_Init(); MM_Init(); SV_Init(); CL_Init(); SCR_EndLoadingPlaque(); if( !dedicated->integer ) { Cbuf_AddText( "exec stuffcmds.cfg\n" ); } else if( mm_server->integer ) { Cbuf_AddText( "exec mmaker_stuffcmds.cfg\n" ); } else if( tv_server->integer ) { Cbuf_AddText( "exec tvserver_stuffcmds.cfg\n" ); } else { Cbuf_AddText( "exec dedicated_stuffcmds.cfg\n" ); } // add + commands from command line if( !Cbuf_AddLateCommands() ) { // if the user didn't give any commands, run default action if( !dedicated->integer ) { // only play the introduction sequence once if( !com_introPlayed3->integer ) { Cvar_ForceSet( com_introPlayed3->name, "1" ); #if !defined(__MACOSX__) && !defined(__ANDROID__) Cbuf_AddText( "cinematic intro.roq\n" ); #endif } } } else { // the user asked for something explicit // so drop the loading plaque SCR_EndLoadingPlaque(); } Com_Printf( "\n====== %s Initialized ======\n", APPLICATION ); Cbuf_Execute(); }
/* ================= Qcommon_Init ================= */ void Qcommon_Init (int argc, char **argv) { static const char *apVersion = APPLICATION " v" VERSION " " CPUSTRING " " __DATE__ " " BUILDSTRING; if (setjmp (abortframe) ) Sys_Error ("Error during initialization"); z_chain.next = z_chain.prev = &z_chain; // prepare enough of the subsystems to handle // cvar and command buffer management COM_InitArgv (argc, argv); Swap_Init (); Cbuf_Init (); Cmd_Init (); Cvar_Init (); Key_Init (); // we need to add the early commands twice, because // a basedir or cddir needs to be set before execing // config files, but we want other parms to override // the settings of the config files Cbuf_AddEarlyCommands (false); Cbuf_Execute(); FS_InitFilesystem (); Cbuf_AddText ("exec default.cfg\n"); Cbuf_Execute(); Cbuf_AddText ("exec aprconfig.cfg\n"); Cbuf_Execute(); FS_ExecConfig("autoexec.cfg"); Cbuf_Execute(); Cbuf_AddEarlyCommands (true); Cbuf_Execute(); Cmd_AddCommand ("echo", Cmd_Echo_f); // init commands and vars Cmd_AddCommand ("z_stats", Z_Stats_f); Cmd_AddCommand( "z_check", Z_Check ); host_speeds = Cvar_Get ("host_speeds", "0", 0); developer = Cvar_Get ("developer", "0", 0); timescale = Cvar_Get ("timescale", "1", CVAR_CHEAT); fixedtime = Cvar_Get ("fixedtime", "0", CVAR_CHEAT); logfile_active = Cvar_Get ("logfile", "0", 0); showtrace = Cvar_Get ("showtrace", "0", 0); #ifdef DEDICATED_ONLY dedicated = Cvar_Get ("dedicated", "1", CVAR_ROM); #else dedicated = Cvar_Get ("dedicated", "0", CVAR_NOSET); #endif timescale->OnChange = OnChange_Timescale; OnChange_Timescale(timescale, timescale->resetString); Cvar_Get ("version", apVersion, CVAR_SERVERINFO|CVAR_ROM); Cmd_AddMacro( "date", Com_Date_m ); Cmd_AddMacro( "time", Com_Time_m ); if (dedicated->integer) Cmd_AddCommand ("quit", Com_Quit); #ifndef NDEBUG Cmd_AddCommand( "error", Com_Error_f ); Cmd_AddCommand( "errordrop", Com_ErrorDrop_f ); Cmd_AddCommand( "freeze", Com_Freeze_f ); Cmd_AddCommand( "crash", Com_Crash_f ); #endif Sys_Init (); srand(Sys_Milliseconds()); NET_Init (); Netchan_Init (); SV_Init (); CL_Init (); ComInitialized = true; Cbuf_InsertFromDefer(); //Execute commands which was initialized after loading autoexec (ignore, highlight etc) FS_ExecConfig ("postinit.cfg"); Cbuf_Execute(); // add + commands from command line if (!Cbuf_AddLateCommands ()) { // if the user didn't give any commands, run default action if (!dedicated->integer) Cbuf_AddText ("toggleconsole\n"); else Cbuf_AddText ("dedicated_start\n"); Cbuf_Execute(); } else { // the user asked for something explicit // so drop the loading plaque SCR_EndLoadingPlaque(); } Com_Printf ("====== " APPLICATION " Initialized ======\n\n"); }
/* ==================== Host_Init ==================== */ void Host_Init (quakeparms_t *parms) { if (standard_quake) minimum_memory = MINIMUM_MEMORY; else minimum_memory = MINIMUM_MEMORY_LEVELPAK; if (COM_CheckParm ("-minmemory")) parms->memsize = minimum_memory; host_parms = *parms; if (parms->memsize < minimum_memory) Sys_Error ("Only %4.1f megs of memory available, can't execute game", parms->memsize / (float)0x100000); com_argc = parms->argc; com_argv = parms->argv; Memory_Init (parms->membase, parms->memsize); Cbuf_Init (); Cmd_Init (); V_Init (); // jkrige - removed chase //Chase_Init (); // jkrige - removed chase Host_InitVCR (parms); COM_Init (parms->basedir); Host_InitLocal (); W_LoadWadFile ("gfx.wad"); Key_Init (); Con_Init (); M_Init (); PR_Init (); Mod_Init (); NET_Init (); SV_Init (); Con_Printf ("Exe: "__TIME__" "__DATE__"\n"); Con_Printf ("%4.1f megabyte heap\n",parms->memsize/ (1024*1024.0)); R_InitTextures (); // needed even for dedicated servers if (cls.state != ca_dedicated) { host_basepal = (byte *)COM_LoadHunkFile ("gfx/palette.lmp"); if (!host_basepal) Sys_Error ("Couldn't load gfx/palette.lmp"); host_colormap = (byte *)COM_LoadHunkFile ("gfx/colormap.lmp"); if (!host_colormap) Sys_Error ("Couldn't load gfx/colormap.lmp"); #ifndef _WIN32 // on non win32, mouse comes before video for security reasons IN_Init (); #endif VID_Init (host_basepal); Draw_Init (); SCR_Init (); R_Init (); #ifndef _WIN32 // on Win32, sound initialization has to come before video initialization, so we // can put up a popup if the sound hardware is in use S_Init (); // jkrige - fmod sound system (system) FMOD_Init(); // jkrige - fmod sound system (system) #else #ifdef GLQUAKE // FIXME: doesn't use the new one-window approach yet S_Init (); // jkrige - fmod sound system (system) FMOD_Init(); // jkrige - fmod sound system (system) #endif #endif // _WIN32 // jkrige - fmod sound system (music) //CDAudio_Init (); // jkrige - fmod sound system (music) Sbar_Init (); CL_Init (); #ifdef _WIN32 // on non win32, mouse comes before video for security reasons IN_Init (); #endif } Cbuf_InsertText ("exec quake.rc\n"); Hunk_AllocName (0, "-HOST_HUNKLEVEL-"); host_hunklevel = Hunk_LowMark (); host_initialized = true; Sys_Printf ("========Quake Initialized=========\n"); }
/* ================= Host_InitCommon ================= */ void Host_InitCommon( const char* moduleName, const char* cmdLine, const char *progname, qboolean bChangeGame ) { char dev_level[4]; char szTemp[MAX_SYSPATH]; string szRootPath; #ifdef _WIN32 MEMORYSTATUS lpBuffer; lpBuffer.dwLength = sizeof( MEMORYSTATUS ); GlobalMemoryStatus( &lpBuffer ); #endif #ifndef __ANDROID__ if( !(SDL_GetBasePath()) ) Sys_Error( "couldn't determine current directory" ); Q_strncpy(host.rootdir, SDL_GetBasePath(), sizeof(host.rootdir)); if( host.rootdir[Q_strlen( host.rootdir ) - 1] == '/' ) host.rootdir[Q_strlen( host.rootdir ) - 1] = 0; #else Q_strncpy(host.rootdir, GAMEPATH, sizeof(host.rootdir)); #endif #ifdef _WIN32 host.oldFilter = SetUnhandledExceptionFilter( Sys_Crash ); host.hInst = GetModuleHandle( NULL ); #endif host.change_game = bChangeGame; host.state = HOST_INIT; // initialzation started host.developer = host.old_developer = 0; CRT_Init(); // init some CRT functions // some commands may turn engine into infinity loop, // e.g. xash.exe +game xash -game xash // so we clearing all cmd_args, but leave dbg states as well if( cmdLine ) Sys_ParseCommandLine( cmdLine ); #ifdef _WIN32 SetErrorMode( SEM_FAILCRITICALERRORS ); // no abort/retry/fail errors #endif host.mempool = Mem_AllocPool( "Zone Engine" ); if( Sys_CheckParm( "-console" )) host.developer = 1; if( Sys_CheckParm( "-dev" )) { if( Sys_GetParmFromCmdLine( "-dev", dev_level )) { if( Q_isdigit( dev_level )) host.developer = abs( Q_atoi( dev_level )); else host.developer++; // -dev == 1, -dev -console == 2 } else host.developer++; // -dev == 1, -dev -console == 2 } host.type = HOST_NORMAL; // predict state host.con_showalways = true; #ifdef PANDORA if( Sys_CheckParm( "-noshouldermb" )) noshouldermb = 1; #endif #ifdef __ANDROID__ if (chdir(host.rootdir) == 0) MsgDev(D_INFO,"%s is working directory now",host.rootdir); else MsgDev(D_ERROR,"%s is not exists",host.rootdir); #else // we can specified custom name, from Sys_NewInstance if( SDL_GetBasePath() && !host.change_game ) { Q_strncpy( szTemp, SDL_GetBasePath(), sizeof(szTemp) ); FS_FileBase( szTemp, SI.ModuleName ); } if(moduleName) Q_strncpy(SI.ModuleName, moduleName, sizeof(SI.ModuleName)); FS_ExtractFilePath( SI.ModuleName, szRootPath ); if( Q_stricmp( host.rootdir, szRootPath )) { Q_strncpy( host.rootdir, szRootPath, sizeof( host.rootdir )); #ifdef _WIN32 SetCurrentDirectory( host.rootdir ); #else chdir( host.rootdir ); #endif } #endif if( SI.ModuleName[0] == '#' ) host.type = HOST_DEDICATED; // determine host type if( progname[0] == '#' ) { Q_strncpy( SI.ModuleName, progname + 1, sizeof( SI.ModuleName )); host.type = HOST_DEDICATED; } else Q_strncpy( SI.ModuleName, progname, sizeof( SI.ModuleName )); if( host.type == HOST_DEDICATED ) { // check for duplicate dedicated server host.hMutex = SDL_CreateMutex( ); if( !host.hMutex ) { MSGBOX( "Dedicated server already running" ); Sys_Quit(); return; } Sys_MergeCommandLine( cmdLine ); SDL_DestroyMutex( host.hMutex ); host.hMutex = SDL_CreateSemaphore( 0 ); if( host.developer < 3 ) host.developer = 3; // otherwise we see empty console } else { // don't show console as default if( host.developer < D_WARN ) host.con_showalways = false; } host.old_developer = host.developer; Con_CreateConsole(); // first text message into console or log MsgDev( D_NOTE, "Sys_LoadLibrary: Loading xash.dll - ok\n" ); // startup cmds and cvars subsystem Cmd_Init(); Cvar_Init(); // share developer level across all dlls Q_snprintf( dev_level, sizeof( dev_level ), "%i", host.developer ); Cvar_Get( "developer", dev_level, CVAR_INIT, "current developer level" ); Cmd_AddCommand( "exec", Host_Exec_f, "execute a script file" ); Cmd_AddCommand( "memlist", Host_MemStats_f, "prints memory pool information" ); FS_Init(); Image_Init(); Sound_Init(); FS_LoadGameInfo( NULL ); Q_strncpy( host.gamefolder, GI->gamefolder, sizeof( host.gamefolder )); if( GI->secure ) { // clear all developer levels when game is protected Cvar_FullSet( "developer", "0", CVAR_INIT ); host.developer = host.old_developer = 0; host.con_showalways = false; } HPAK_Init(); IN_Init(); Key_Init(); }
bool Host_Init(quakeparms_t *parms) { if (standard_quake) minimum_memory = MINIMUM_MEMORY; else minimum_memory = MINIMUM_MEMORY_LEVELPAK; if (COM_CheckParm("-minmemory")) parms->memsize = minimum_memory; host_parms = *parms; if (parms->memsize < minimum_memory) return Sys_Error("Only %4.1f megs of memory reported, can't execute game", parms->memsize / (float)0x100000); com_argc = parms->argc; com_argv = parms->argv; Memory_Init(parms->membase, parms->memsize); Cbuf_Init(); Cmd_Init(); V_Init(); Chase_Init(); COM_Init(); Host_InitLocal(); if (!W_LoadWadFile("gfx.wad")) return false; Key_Init(); Con_Init(); M_Init(); PR_Init(); Mod_Init(R_ModelLoader()); NET_Init(); SV_Init(); Con_Printf("Exe: " __TIME__ " " __DATE__ "\n"); Con_Printf("%4.1f megabyte heap\n", parms->memsize / (1024 * 1024.0)); R_InitTextures(); // needed even for dedicated servers if (cls.state != ca_dedicated) { host_basepal = (byte*)COM_LoadHunkFile("gfx/palette.lmp"); if (!host_basepal) return Sys_Error("Couldn't load gfx/palette.lmp"); host_colormap = (byte*)COM_LoadHunkFile("gfx/colormap.lmp"); if (!host_colormap) return Sys_Error("Couldn't load gfx/colormap.lmp"); if (coloredlights) host_fullbrights = 256-host_colormap[16384]; // leilei - variable our fullbright counts if available VID_Init(host_basepal); Draw_Init(); SCR_Init(); R_Init(); S_Init(); CDAudio_Init(); BGM_Init(); Sbar_Init(); CL_Init(); IN_Init(); } Hunk_AllocName(0, "-HOST_HUNKLEVEL-"); host_hunklevel = Hunk_LowMark(); host_initialized = true; Sys_Printf("========Quake Initialized=========\n"); /* In case exec of quake.rc fails */ if (!setjmp(host_abort)) { Cbuf_InsertText("exec quake.rc\n"); Cbuf_Execute(); } return true; }
/* ==================== Host_Init ==================== */ void Host_Init (quakeparms_t *parms) { #if defined(_WIN32) && defined(GLQUAKE) FILE *fp = fopen("opengl32.dll","r"); if (fp) { // exists fclose(fp); Sys_Error ("OpenGL32.dll found in Quake folder. You must delete this file from your Quake folder to run this engine."); } #endif // Windows only if (standard_quake) minimum_memory = MINIMUM_MEMORY; else minimum_memory = MINIMUM_MEMORY_LEVELPAK; if (COM_CheckParm ("-minmemory")) parms->memsize = minimum_memory; host_parms = *parms; if (parms->memsize < minimum_memory) Sys_Error ("Only %4.1f megs of memory available, can't execute game and memsize = %i and minimum memory is %i", parms->memsize / (float)0x100000, parms->memsize, minimum_memory); com_argc = parms->argc; com_argv = parms->argv; #ifdef SUPPORTS_CHEATFREE // JPG 3.00 - moved this here #if defined(_WIN32) srand(time(NULL) ^ _getpid()); #else srand(time(NULL) ^ getpid()); #endif #endif Memory_Init (parms->membase, parms->memsize); Cbuf_Init (); Cmd_Init (); Cvar_Init (); V_Init (); Chase_Init (); Host_InitVCR (parms); COM_Init (parms->basedir); Host_InitLocal (); W_LoadWadFile ("gfx.wad"); Key_Init (); Con_Init (); M_Init (); PR_Init (); Mod_Init (); #ifdef PROQUAKE_EXTENSION Security_Init (); // JPG 3.20 - cheat free #endif NET_Init (); SV_Init (); #ifdef PROQUAKE_EXTENSION IPLog_Init (); // JPG 1.05 - ip address logging Con_Printf ("Exe: "__TIME__" "__DATE__"\n"); #endif #ifdef PSP_SYSTEM_STATS Con_Printf ("Insomnia ProQuake Engine v 4.71 Rev4\n"); //(EBOOT: "__TIME__" "__DATE__")\n"); int currentCPU = scePowerGetCpuClockFrequency(); int currentVRAM = sceGeEdramGetSize(); int currentVRAMADD = sceGeEdramGetAddr(); int currentRAMAVAIL = sceKernelTotalFreeMemSize(); #ifdef NORMAL_MODEL Con_Printf ("PSP Normal 32MB RAM Mode \n"); #endif #ifdef SLIM_MODEL Con_Printf ("PSP Slim 64MB RAM Mode \n"); #endif Con_Printf ("%4.1f megabyte heap \n",parms->memsize/ (1024*1024.0)); Con_Printf ("%4.1f PSP application heap \n",1.0f*PSP_HEAP_SIZE_MB); Con_Printf ("%d VRAM \n",currentVRAM); Con_Printf ("%d VRAM Address \n",currentVRAMADD); Con_Printf ("%d Current Total RAM \n",currentRAMAVAIL); Con_Printf ("CPU Speed %d MHz\n", currentCPU); Con_Printf ("%s \n", com_gamedir); R_InitTextures (); // needed even for dedicated servers #else Con_Printf ("%4.1f megabyte heap\n",parms->memsize/ (1024*1024.0)); #endif if (cls.state != ca_dedicated) { host_basepal = (byte *)COM_LoadHunkFile ("gfx/palette.lmp"); if (!host_basepal) Sys_Error ("Couldn't load gfx/palette.lmp"); host_colormap = (byte *)COM_LoadHunkFile ("gfx/colormap.lmp"); if (!host_colormap) Sys_Error ("Couldn't load gfx/colormap.lmp"); #ifndef _WIN32 // on non win32, mouse comes before video for security reasons IN_Init (); #endif VID_Init (host_basepal); Draw_Init (); SCR_Init (); R_Init (); #ifndef _WIN32 // on Win32, sound initialization has to come before video initialization, so we // can put up a popup if the sound hardware is in use S_Init (); #else #ifdef GLQUAKE // FIXME: doesn't use the new one-window approach yet S_Init (); #endif #endif // _WIN32 CDAudio_Init (); Sbar_Init (); CL_Init (); #ifdef _WIN32 // on non win32, mouse comes before video for security reasons IN_Init (); #endif #ifdef _WIN32 // Baker: 3.99m to get sys info // must be AFTER video init stuff Sys_InfoInit(); // We don't care about dedicated servers for this // Baker 3.76 - Autoplay demo if (com_argc >= 2) { char *infile = com_argv[1]; if (infile[0] && infile[0] != '-' && infile[0] != '+') { char tmp[1024] = {0}, *ext = COM_FileExtension(infile); if (!strncasecmp(ext, "dem", sizeof("dem"))) snprintf(tmp, sizeof(tmp), "playdemo \"%s\"\n", infile); if (tmp[0]) { nostartdemos = true; Cbuf_AddText(tmp); } } } #endif } Cbuf_InsertText ("exec quake.rc\n"); #ifdef PROQUAKE_EXTENSION // Baker 3.80x: this is a hack if (!isDedicated) { Cbuf_AddText ("\nsavefov\n"); Cbuf_AddText ("savesensitivity\n"); } #endif Hunk_AllocName (0, "-HOST_HUNKLEVEL-"); host_hunklevel = Hunk_LowMark (); host_initialized = true; Con_Printf ("Host Initialized\n"); Sys_Printf ("========Quake Initialized=========\n"); }