Doom3 execution unrolled by Fabien Sanglard

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
{
    Sys_SetPhysicalWorkMemory( 192 << 20, 1024 << 20 ); //Min = 201,326,592  Max = 1,073,741,824

    Sys_GetCurrentMemoryStatus( exeLaunchMemoryStats );

    Sys_CreateConsole();

    SetErrorMode( SEM_FAILCRITICALERRORS );

    for ( int i = 0; i < MAX_CRITICAL_SECTIONS; i++ ) {
        InitializeCriticalSection( &win32.criticalSections[i] );
    }

    Sys_Milliseconds();

    common->Init( 0, NULL, lpCmdLine )
    {
        idLib::Init();

        ParseCommandLine( argc, argv );

        cmdSystem->Init();               // init console command system

        cvarSystem->Init();              // init CVar system

        idCVar::RegisterStaticVars();    // register all static CVars

        idKeyInput::Init();              // initialize key input/binding, done early so bind command exists

        console->Init();                 // init the console so we can take prints

        Sys_Init();                      // get architecture info

        Sys_InitNetworking();            // initialize networking

        if ( !idAsyncNetwork::serverDedicated.GetInteger() && Sys_AlreadyRunning() )
            Sys_Quit();

        InitSIMD();                      // initialize processor specific SIMD implementation

        InitCommands();                  // init commands

        InitGame();                      // game specific initialization

        ClearCommandLine();

        com_fullyInitialized = true;

    }

    Sys_StartAsyncThread();
    {
        // Create a thread that will block on hTimer in order to run at 60Hz (every 16 milliseconds).
        // The Thread calls common->Async over and over for Sound mixing and input generation.

        while ( 1 )
        {
            usleep( 16666 );
            common->Async();
            Sys_TriggerEvent( TRIGGER_EVENT_ONE );
            pthread_testcancel();
        }
    }

    Sys_ShowConsole

    // main game loop
    while( 1 )
    {
        Win_Frame();      //Show or hide the console

        // Called repeatedly as the foreground thread for rendering and game logic.
        common->Frame()  // All of Doom3 beef is here.
        {
            Sys_GenerateEvents();    // pump all the events
            WriteConfiguration();    // write config file if anything changed
            eventLoop->RunEventLoop();

            com_frameTime = com_ticNumber * USERCMD_MSEC;
            idAsyncNetwork::RunFrame(); 

            session->Frame()
            {
                Sys_GrabMouseCursor

                while( 1 ) {
                    latchedTicNumber = com_ticNumber;
                    if ( latchedTicNumber >= minTic ) {
                        break;
                    }
                    Sys_WaitForEvent( TRIGGER_EVENT_ONE );
                }

                GuiFrameEvents

                for ( i = 0 ; i < gameTicsToRun ; i++ )
                RunGameTic()
                {
                    //From this point execution jumps in the GameX86.dll address space.
                    game->RunFrame( &cmd );
                    {
                        GetLocalPlayer
                        ComputeSlowMsec

                        random.RandomInt

                        ServerProcessEntityNetworkEventQueue
                        UpdateGravity
                        SetupPlayerPVS
                        SortActiveEntityList

                        timer_think.Start

                        // let entities think
                        for( ent = activeEntities.Next(); ent != NULL; ent = ent->activeNode.Next() )
                            ent->GetPhysics()->UpdateTime( time );

                        // remove any entities that have stopped thinking
                        for( ent = activeEntities.Next(); ent != NULL; ent = next_ent )
                            if ( !ent->thinkFlags )
                                ent->activeNode.Remove();

                        timer_think.Stop();

                        idEvent::ServiceEvents();
                        idEvent::ServiceFastEvents();

                    }
                }
            }
            session->UpdateScreen( false ); // normal, in-sequence screen update
            {
                renderSystem->BeginFrame( renderSystem->GetScreenWidth(), renderSystem->GetScreenHeight() );

                // Doesn‘t actually communicate with the GPU
                // but generate Doom cmd for later.
                // DOOM3 FRONTEND
                - idGame::Draw
                 - idPlayerView::RenderPlayerView
                  - idPlayerView::SingleView
                    - idRenderWorld::RenderScene
                    |  - build params
                    |  - ::R_RenderView(params)
                    |    {
                    |        R_SetViewMatrix      //Setup the modelview Matrix (GL_MODELVIEW)
                    |        R_SetupViewFrustum   //Setup the perspective projection Matrix (GL_PROJECTION). Set Zfar to MAX_WORLD_SIZE (256*1024), this is adjusted in R_ConstrainViewFrustum
                    |        R_SetupProjection
                    |
                    |        // Populate:
                    |        //    - tr.viewDef->viewLights
                    |        //    - tr.viewDef->viewEntitys
                    |        static_cast(parms->renderWorld)->FindViewLightsAndEntities();
                    |            PointInArea
                    |            BuildConnectedAreas        //Just follow the graph or portal interconnection in order to mark all area potentially visible (mark tr.viewDef->connectedAreas array)
                    |            FlowViewThroughPortals
                    |                FloodViewThroughArea_r
                    |                 {
	                |                      AddAreaRefs
                    |                      {
                    |                        AddAreaEntityRefs( areaNum, ps );  //Use tr.viewDef->connectedAreas. Even if an entity is not in light IT MUST be rendered because
                                                                                //It may be in front of a lighted area (silhouette effect).
                    |                        AddAreaLightRefs( areaNum, ps );
                    |                      }
                    |                 }
                    |
                    |        R_ConstrainViewFrustum         // Adjust Z Far in order to gain precision (ZFar = MAX_WORLD_SIZE from R_SetupViewFrustum) (constrain the view frustum to the view lights and entities).
                    |
                    |        // make sure that interactions exist for all light / entity combinations
                    |        // that are visible
                    |        // add any pre-generated light shadows, and calculate the light shader values
                    |        R_AddLightSurfaces();
                    |
                    |        // adds ambient surfaces and create any necessary interaction surfaces to add to the light
                    |        // lists. Removes lights from the viewLights list if they are completely turned off, or completely off screen.
                    |        R_AddModelSurfaces();
                    |
                    |        // any viewLight that didn‘t have visible surfaces can have it‘s shadows removed
                    |        R_RemoveUnecessaryViewLights();
                    |
                    |        // sort all the ambient surfaces for translucency ordering using C qsort. Would have been faster to use C++ template for inlining.
                    |        R_SortDrawSurfs();
                    |
                    |        R_GenerateSubViews    // Generate GUI elements on surfaces.
                    |
                    |        R_AddDrawViewCmd      // Send everything to the backend
                    |    }
                    |
                    - idPlayer::DrawHUD

                // All commands are picked up here and GPU is actually instructed to
                // render stuff.
                renderSystem->EndFrame
                {
                    R_IssueRenderCommands
                      RB_ExecuteBackEndCommands
                       RB_DrawView
                        RB_ShowOverdraw
                        RB_STD_DrawView
                        {
                          RB_BeginDrawingView     // clear the z buffer, set the projection matrix, etc
                          RB_DetermineLightScale

                           RB_STD_FillDepthBuffer  // fill the depth buffer and clear color buffer to black except on

                          _DrawInteractions
                          {
                              5 GPU specific path
                              R10 (GeForce256)
                              R20 (geForce3)
                              R200 (Radeon 8500)
                              ARB
                              ARB2
                          }

                          // disable stencil shadow test
                          qglStencilFunc( GL_ALWAYS, 128, 255 );

                          RB_STD_LightScale

                          RB_STD_DrawShaderPasses   //draw any non-light dependent shading passes

                          RB_STD_FogAllLights

                          RB_STD_DrawShaderPasses

                      }
                }
            }

        }
    }
}
时间: 2024-10-26 06:29:28

Doom3 execution unrolled by Fabien Sanglard的相关文章

BumpMapping [转]

http://fabiensanglard.net/bumpMapping/index.php Fabien Sanglard's Website Home About FAQ Email Rss Twitter March 19th, 2009 BumpMapping with GLSL When I got started learning bump mapping and parallax mapping, I found a lot of tutorial involving a sim

程序设计基石与实践系列之成为一名Top的C语言程序员

英文出处:Fabien Sanglard -To become a good C programmer 问题的提出 每过一段时间我总会收到一些程序员发来的电子邮件,他们会问我是用什么编程语言来编写自己的游戏的,以及我是如何学习这种编程语言的.因此,我认为在这篇博文里列出一些有关C语言的最佳读物应该能帮到不少人.如果你知道其它的优秀读物,请给我发邮件或者直接在评论栏中告诉我吧. 问题的解答 我在之前的一篇博文中已经提到过了,目前为止,所有我所编写的商业3D引擎95%都是C89(也称作标准C,或AN

Beginning OpenGL ES 2.0 with GLKit Part 1

Update 10/24/12: If you’d like a new version of this tutorial fully updated for iOS 6 and Xcode 4.5, check out iOS 5 by Tutorials Second Edition! Note from Ray: This is the fourth iOS 5 tutorial in the iOS 5 Feast! This tutorial is a free preview cha

Android Studio 中 FAILURE: Build failed with an exception. * What went wrong: Execution failed for task &#39;:compileDebugAidl&#39;.的问题解答

Android Studio 中 FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':compileDebugAidl'.的问题解答 完整的问题提示 Gradle: FAILURE:Build failed with an exception.*What went wrong:Execution failed for task ':compileDebugAidl'.>No

Controlling Execution

同上一章,本章依然比较简单.基础,因此只是做一些总结性的笔记. 1.不像C和C++那样(0是假,非零为真),Java不允许用一个数字作为boolean值. 2.C中,为了给变量分配空间,所有变量的定义必须在代码块前面.而C++和Java中没 有这个限制,它允许更加自然的代码风格,而且使得代码更容易理解. 3.使用Foreach语法,我们不比创建一个用来遍历各个项的整型值,foreach自动的为我们提供每一个项. 4.如果在返回值为void的方法中没有return语句,那么它隐式地在方法的结尾处返

gradle编译出错:Execution failed for task &#39;:app:compileTestDebugJava&#39;.

今天更新了android studio,从0.5.3升级到0.6.1版本,结果在IDE中编译时没有问题,但是在命令行时编译就会出现以下错误: :app:compileTestDebugJava FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:compileTestDebugJava'. > No signature of method: com.a

Home Web Server 1.9.1 build 164 - CGI Remote Code Execution复现

一.  Home Web Server 1.9.1 build 164 - CGI Remote Code Execution复现 漏洞描述: Home Web Server允许调用CGI程序来通过POST请求访问位于/cgi-bin下的文件,然后通过目录遍历,就有可能执行远程主机的任意可执行程序. 漏洞影响范围: Home Web Server 1.9.1 build 164 漏洞复现: 利用原理: NC连接发送打开计算器请求,安装Home Web Server 1.9.1 build 164

CVE-2010-0483分析 Microsoft Internet Explorer 6/7/8 - &#39;winhlp32.exe&#39; &#39;MsgBox()&#39; Remote Code Execution

相关资料:https://www.exploit-db.com/exploits/11615/ 目的是为了了解漏洞执行的流程. 根据资料准备服务端环境: 用一台win7当做是服务器,需要在win7上共享一个文件夹用于客户端访问.我的测试环境共享的文件夹是www. (1)启用Guest来宾账户,共享文件夹时将Guest添加读权限.此时在win7本机上应能访问,但在局域网的XP虚拟机无法访问  \\192.168.0.11\www\ (2)运行 secpol.msc 打开本地安全策略->本地策略->

Spring execution 表达式

execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern) throws-pattern?)除了返回类型模式(上面代码片断中的ret-type-pattern),名字模式和参数模式以外,所有的部分都是可选的. 返回类型模式决定了方法的返回类型必须依次匹配一个连接点. 你会使用的最频繁的返回类型模式是 *,它代表了匹配任意的返回类型. 一个全称限定的类型名将只会匹