• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天行健 君子當自強而不息

            Putting Together a Full Game(9)

             

            The Application init Function

            As the starting point of the game, the init function initializes the system (including
            the graphics, sound, and input systems), sets up the character and spell controllers,
            loads the master item list, pushes the main menu state, and carries out a few miscellaneous
            functions. Take a look at the Init function piece by piece to see what’s
            going on:

            bool cApp::init()
            {
                create_display(g_hwnd, CLIENT_WIDTH, CLIENT_HEIGHT, 16, 
            truetrue);
                set_perspective(0.6021124f, 1.3333f, 1.0f, 20000.0f);    

                ShowCursor(TRUE);

                create_font(&m_font, "Consolas", 16, 
            falsefalse);

                m_input.create(g_hwnd, get_window_inst());
                m_keyboard.create_keyboard(&m_input);
                m_mouse.create_mouse(&m_input, 
            true);

                m_sound.init(g_hwnd, 22050, 1, 16, DSSCL_PRIORITY);     
                m_sound_channel.create(&m_sound, 22050, 1, 16);
                m_music_channel.attach(&m_sound);

                
            // load the master item list

                FILE* fp = fopen("..\\Data\\Game.mil", "rb");

                
            if(fp == NULL)
                    
            return false;

                fread(m_mil, 1, 
            sizeof(m_mil), fp);
                fclose(fp);

                
            // initialize the character controller    

                m_game_chars.init(m_font, "..\\Data\\Game.mcl", m_mil, m_game_spells.get_spell_list(),
                                  array_num(g_char_mesh_files), g_char_mesh_files,
                                  "..\\Data\\", "..\\Data\\",
                                  array_num(g_char_anims), g_char_anims);    
                
                m_game_chars.attach_app(
            this);

                
            // initialize the spell controller

                
            if(! m_game_spells.init("..\\Data\\Game.msl", array_num(g_spell_mesh_files), g_spell_mesh_files, "..\\Data\\"))
                    
            return false;

                m_game_spells.attach_app(
            this);

                m_game_chars.attach(&m_game_spells);
                m_game_spells.attach(&m_game_chars);

                m_game_script.attach_app(
            this);

                
            if(! load_texture_from_file(&m_charge_bar, "..\\Data\\ChargeBar.bmp", 0, D3DFMT_UNKNOWN))
                    
            return false;

                
            // create the main, header, and stats text windows.
                m_text_window.create(m_font);
                m_text_header.create(m_font);
                m_text_stats.create(m_font);

                
            // position all text windows
                m_text_window.move(2, 2, 636, 476, -1, -1, COLOR_DARK_BLUE, COLOR_ARGENTINE);
                m_text_header.move(2, 2, 128, 32,  -1, -1, COLOR_HALF_RED,  COLOR_ARGENTINE);
                m_text_stats.move(2,  2, 128, 48,  -1, -1, COLOR_DARK_BLUE, COLOR_ARGENTINE);

                
            // push the main menu state, setting menu optios first.
                g_menu_options = MENU_LOAD;
                m_state_manager.push(menu_frame, 
            this);

                
            return true;
            }

            Graphics is the first order of business here—you initialize the graphics system and
            set the video mode.  You then set the perspective to match that of the 3-D modeler
            used to render the backdrops. Finally, you create a font to use throughout the
            game and display the mouse cursor.

            Next, you initialize the input system and create two device interfaces—one for the
            keyboard and the other for the mouse.

            Rounding out the Graphics Core initialization code, you initialize the sound system
            and create the sound and music channels.

            Now, you initialize the game-specific data and interfaces. You load the master item
            list and initialize the character controller and spell controllers.

            You're about halfway through the init function. At this point, you load a bitmap
            that display the player's charge meter, and you create and position the text windows.

            Rounding off the Init function, you make a call to the derived script class that tells
            the script which application class interface to use. Following that, you push the first
            of the game states, the main menu, onto the state stack.

             

            The shutdown Function

            What good is the Init function without a matching Shutdown function to shut down
            and free used resources in the game? The cApp::shutdown function does just that.

            void cApp::shutdown()
            {
                m_state_manager.pop_all(
            this);

                free_level();
            }

             

            Processing Frames with the frame Function

            For every frame that the game is updated, the application class’s frame function is
            called. To limit how often the game actually updates, however, a timer is maintained
            that limits further frame processing to 30 frames a second. This process of limiting
            the updates takes up the first half of the Frame function, as shown here:

            bool cApp::frame()
            {
                
            static DWORD update_timer = timeGetTime();

                
            // limit all frame updates to 30 fps
                if(timeGetTime() < update_timer + 33)
                    
            return true;

                update_timer = timeGetTime();

                m_keyboard.acquire();
                m_keyboard.read();
                m_mouse.acquire();
                m_mouse.read();

                
            return m_state_manager.process_top(this);
            }

            As I mentioned, the game is updated 30 times a second. Each frame that the game
            is updated, the keyboard and mouse’s states are read in, and the current state is
            processed.

            As states are inserted into the state stack, the uppermost
            state executes when cManager::process_top is called, as shown in the frame function.

            posted on 2007-12-29 21:04 lovedday 閱讀(269) 評論(0)  編輯 收藏 引用

            公告

            導航

            統計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關鏈接

            搜索

            最新評論

            一本久久a久久精品综合香蕉| 欧美精品丝袜久久久中文字幕 | 久久精品无码专区免费青青| 青草国产精品久久久久久| 91超碰碰碰碰久久久久久综合| 久久久久无码精品国产app| 日本强好片久久久久久AAA| 精品免费久久久久国产一区| 99久久综合国产精品免费| 色综合久久中文色婷婷| 欧美精品乱码99久久蜜桃| 91麻精品国产91久久久久| 久久亚洲私人国产精品vA| 久久只有这里有精品4| 91久久九九无码成人网站| 久久精品国产亚洲AV电影 | 中文字幕亚洲综合久久菠萝蜜| 精品久久久久久无码中文字幕一区| 欧美伊人久久大香线蕉综合69 | 久久精品国产一区二区三区日韩| 久久久亚洲AV波多野结衣| 精品久久久久久国产牛牛app| 国产精品九九九久久九九| 亚洲国产欧美国产综合久久| 亚洲精品97久久中文字幕无码| 久久91精品国产91久久户| 久久精品欧美日韩精品| 久久亚洲AV成人无码电影| 亚洲欧洲日产国码无码久久99| 亚洲国产精品成人AV无码久久综合影院 | 久久综合88熟人妻| 久久久久久亚洲Av无码精品专口 | 狠狠色丁香久久婷婷综合五月| 久久久久亚洲精品日久生情| 亚洲欧洲久久久精品| 2020久久精品亚洲热综合一本| 成人综合久久精品色婷婷| 久久久久久久波多野结衣高潮| 综合人妻久久一区二区精品| 中文字幕乱码久久午夜| 久久久SS麻豆欧美国产日韩|