天天看点

3D游戏引擎编写(4)--quake3代码分析笔记(2)

1. 基本框架

   win_main.c主程序文件,winMain入口函数,基本流程:

       创建错误输出控制台,

       初始化数据(变量操作、命令解释器、键盘映射、文件、运行脚本),

       初始化网络,

       进入游戏循环

       {

           Com_Frame 游戏逻辑处理

       }

2.  命令驱动,quake3是基于“命令驱动”来组合各个函数

    Cmd_AddCommand  注册指令

    //console

    Cmd_AddCommand ("toggleconsole", Con_ToggleConsole_f);

    Cmd_AddCommand ("messagemode", Con_MessageMode_f);

    Cmd_AddCommand ("messagemode2", Con_MessageMode2_f);

    Cmd_AddCommand ("messagemode3", Con_MessageMode3_f);

    Cmd_AddCommand ("messagemode4", Con_MessageMode4_f);

    Cmd_AddCommand ("clear", Con_Clear_f);

    Cmd_AddCommand ("condump", Con_Dump_f);

    //input

    Cmd_AddCommand ("centerview",IN_CenterView);

    Cmd_AddCommand ("+moveup",IN_UpDown);

    Cmd_AddCommand ("-moveup",IN_UpUp);

    Cmd_AddCommand ("+movedown",IN_DownDown);

    Cmd_AddCommand ("-movedown",IN_DownUp);

    Cmd_AddCommand ("+left",IN_LeftDown);

    Cmd_AddCommand ("-left",IN_LeftUp);

    Cmd_AddCommand ("+right",IN_RightDown);

    Cmd_AddCommand ("-right",IN_RightUp);

    Cmd_AddCommand ("+forward",IN_ForwardDown);

    Cmd_AddCommand ("-forward",IN_ForwardUp);

    Cmd_AddCommand ("+back",IN_BackDown);

    Cmd_AddCommand ("-back",IN_BackUp);

    Cmd_AddCommand ("+lookup", IN_LookupDown);

    Cmd_AddCommand ("-lookup", IN_LookupUp);

    Cmd_AddCommand ("+lookdown", IN_LookdownDown);

    Cmd_AddCommand ("-lookdown", IN_LookdownUp);

    Cmd_AddCommand ("+strafe", IN_StrafeDown);

    Cmd_AddCommand ("-strafe", IN_StrafeUp);

    Cmd_AddCommand ("+moveleft", IN_MoveleftDown);

    Cmd_AddCommand ("-moveleft", IN_MoveleftUp);

    Cmd_AddCommand ("+moveright", IN_MoverightDown);

    Cmd_AddCommand ("-moveright", IN_MoverightUp);

    Cmd_AddCommand ("+speed", IN_SpeedDown);

    Cmd_AddCommand ("-speed", IN_SpeedUp);

    Cmd_AddCommand ("+attack", IN_Button0Down);

    Cmd_AddCommand ("-attack", IN_Button0Up);

    Cmd_AddCommand ("+button0", IN_Button0Down);

    Cmd_AddCommand ("-button0", IN_Button0Up);

    Cmd_AddCommand ("+button1", IN_Button1Down);

    Cmd_AddCommand ("-button1", IN_Button1Up);

    Cmd_AddCommand ("+button2", IN_Button2Down);

    Cmd_AddCommand ("-button2", IN_Button2Up);

    Cmd_AddCommand ("+button3", IN_Button3Down);

    Cmd_AddCommand ("-button3", IN_Button3Up);

    Cmd_AddCommand ("+button4", IN_Button4Down);

    Cmd_AddCommand ("-button4", IN_Button4Up);

    Cmd_AddCommand ("+button5", IN_Button5Down);

    Cmd_AddCommand ("-button5", IN_Button5Up);

    Cmd_AddCommand ("+button6", IN_Button6Down);

    Cmd_AddCommand ("-button6", IN_Button6Up);

    Cmd_AddCommand ("+button7", IN_Button7Down);

    Cmd_AddCommand ("-button7", IN_Button7Up);

    Cmd_AddCommand ("+button8", IN_Button8Down);

    Cmd_AddCommand ("-button8", IN_Button8Up);

    Cmd_AddCommand ("+button9", IN_Button9Down);

    Cmd_AddCommand ("-button9", IN_Button9Up);

    Cmd_AddCommand ("+button10", IN_Button10Down);

    Cmd_AddCommand ("-button10", IN_Button10Up);

    Cmd_AddCommand ("+button11", IN_Button11Down);

    Cmd_AddCommand ("-button11", IN_Button11Up);

    Cmd_AddCommand ("+button12", IN_Button12Down);

    Cmd_AddCommand ("-button12", IN_Button12Up);

    Cmd_AddCommand ("+button13", IN_Button13Down);

    Cmd_AddCommand ("-button13", IN_Button13Up);

    Cmd_AddCommand ("+button14", IN_Button14Down);

    Cmd_AddCommand ("-button14", IN_Button14Up);

    Cmd_AddCommand ("+mlook", IN_MLookDown);

    Cmd_AddCommand ("-mlook", IN_MLookUp);

    //key

    Cmd_AddCommand ("bind",Key_Bind_f);

    Cmd_AddCommand ("unbind",Key_Unbind_f);

    Cmd_AddCommand ("unbindall",Key_Unbindall_f);

    Cmd_AddCommand ("bindlist",Key_Bindlist_f);

    //main

    Cmd_AddCommand ("cmd", CL_ForwardToServer_f);

    Cmd_AddCommand ("configstrings", CL_Configstrings_f);

    Cmd_AddCommand ("clientinfo", CL_Clientinfo_f);

    Cmd_AddCommand ("snd_restart", CL_Snd_Restart_f);

    Cmd_AddCommand ("vid_restart", CL_Vid_Restart_f);

    Cmd_AddCommand ("disconnect", CL_Disconnect_f);

    Cmd_AddCommand ("record", CL_Record_f);

    Cmd_AddCommand ("demo", CL_PlayDemo_f);

    Cmd_AddCommand ("cinematic", CL_PlayCinematic_f);

    Cmd_AddCommand ("stoprecord", CL_StopRecord_f);

    Cmd_AddCommand ("connect", CL_Connect_f);

    Cmd_AddCommand ("reconnect", CL_Reconnect_f);

    Cmd_AddCommand ("localservers", CL_LocalServers_f);

    Cmd_AddCommand ("globalservers", CL_GlobalServers_f);

    Cmd_AddCommand ("rcon", CL_Rcon_f);

    Cmd_AddCommand ("setenv", CL_Setenv_f );

    Cmd_AddCommand ("ping", CL_Ping_f );

    Cmd_AddCommand ("serverstatus", CL_ServerStatus_f );

    Cmd_AddCommand ("showip", CL_ShowIP_f );

    Cmd_AddCommand ("fs_openedList", CL_OpenedPK3List_f );

    Cmd_AddCommand ("fs_referencedList", CL_ReferencedPK3List_f );

    Cmd_AddCommand ("model", CL_SetModel_f );

    Cmd_AddCommand ("in_restart", Sys_In_Restart_f);

    Cmd_AddCommand ("net_restart", Sys_Net_Restart_f);

    //cmd

    Cmd_AddCommand ("cmdlist",Cmd_List_f);

    Cmd_AddCommand ("exec",Cmd_Exec_f);

    Cmd_AddCommand ("vstr",Cmd_Vstr_f);

    Cmd_AddCommand ("echo",Cmd_Echo_f);

    Cmd_AddCommand ("wait", Cmd_Wait_f);

    //common

    Cmd_AddCommand( "meminfo", Com_Meminfo_f );

    Cmd_AddCommand( "zonelog", Z_LogHeap );

    Cmd_AddCommand( "hunklog", Hunk_Log );

    Cmd_AddCommand( "hunksmalllog", Hunk_SmallLog );

    Cmd_AddCommand ("error", Com_Error_f);

    Cmd_AddCommand ("crash", Com_Crash_f );

    Cmd_AddCommand ("freeze", Com_Freeze_f);    

    Cmd_AddCommand ("quit", Com_Quit_f);

    Cmd_AddCommand ("changeVectors", MSG_ReportChangeVectors_f );

    Cmd_AddCommand ("writeconfig", Com_WriteConfig_f );    

    //var

    Cmd_AddCommand ("toggle", Cvar_Toggle_f);

    Cmd_AddCommand ("set", Cvar_Set_f);

    Cmd_AddCommand ("sets", Cvar_SetS_f);

    Cmd_AddCommand ("setu", Cvar_SetU_f);

    Cmd_AddCommand ("seta", Cvar_SetA_f);

    Cmd_AddCommand ("reset", Cvar_Reset_f);

    Cmd_AddCommand ("cvarlist", Cvar_List_f);

    Cmd_AddCommand ("cvar_restart", Cvar_Restart_f);

    Cmd_AddCommand( "midiinfo", MidiInfo_f );

    //file

    Cmd_AddCommand ("path", FS_Path_f);

    Cmd_AddCommand ("dir", FS_Dir_f );

    Cmd_AddCommand ("fdir", FS_NewDir_f );

    Cmd_AddCommand ("touchFile", FS_TouchFile_f );

    //dma

    Cmd_AddCommand("play", S_Play_f);

    Cmd_AddCommand("music", S_Music_f);

    Cmd_AddCommand("s_list", S_SoundList_f);

    Cmd_AddCommand("s_info", S_SoundInfo_f);

    Cmd_AddCommand("s_stop", S_StopAllSounds);

    //ccmd

    Cmd_AddCommand ("heartbeat", SV_Heartbeat_f);

    Cmd_AddCommand ("kick", SV_Kick_f);

    Cmd_AddCommand ("banUser", SV_Ban_f);

    Cmd_AddCommand ("banClient", SV_BanNum_f);

    Cmd_AddCommand ("clientkick", SV_KickNum_f);

    Cmd_AddCommand ("status", SV_Status_f);

    Cmd_AddCommand ("serverinfo", SV_Serverinfo_f);

    Cmd_AddCommand ("systeminfo", SV_Systeminfo_f);

    Cmd_AddCommand ("dumpuser", SV_DumpUser_f);

    Cmd_AddCommand ("map_restart", SV_MapRestart_f);

    Cmd_AddCommand ("sectorlist", SV_SectorList_f);

    Cmd_AddCommand ("map", SV_Map_f);

    Cmd_AddCommand ("devmap", SV_Map_f);

    Cmd_AddCommand ("spmap", SV_Map_f);

    Cmd_AddCommand ("spdevmap", SV_Map_f);

    Cmd_AddCommand ("killserver", SV_KillServer_f);

    Cmd_AddCommand ("say", SV_ConSay_f);

    各命令含义以后慢慢分析。

    Cbuf_AddText  添加指令到缓冲区

    Cbuf_Execute  执行一些列指令

继续阅读