青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

天行健 君子當(dāng)自強(qiáng)而不息

創(chuàng)建游戲內(nèi)核(1) 【C風(fēng)格版】

 

該版本根據(jù)接口與實(shí)現(xiàn)分離版改的, 因?yàn)榻涌谂c實(shí)現(xiàn)分離寫起來(lái)太煩瑣,所以直接使用結(jié)構(gòu)體。由于結(jié)構(gòu)體的數(shù)據(jù)成員可以直接訪問(wèn),可以減少編寫大量的接口函數(shù),同時(shí)對(duì)于簡(jiǎn)單的數(shù)據(jù)結(jié)構(gòu)采用函數(shù)封裝, 只對(duì)復(fù)雜的功能模塊采用結(jié)構(gòu)體封裝,減少抽象對(duì)象的使用以最大限度增加代碼的透明度。


共同頭文件:

/**************************************************
PURPOSE:
    Include common game core header file.
**************************************************/


#ifndef _CORE_COMMON_H_
#define _CORE_COMMON_H_

#define DIRECTINPUT_VERSION 0x0800

// Windows includes
#include <windows.h>

// Standard ANSI-C includes
#include <stdio.h>
#include <
string.h>

// DirectX includes
#include <d3d9.h>
#include <d3dx9.h>
#include <dmusici.h>
#include <dsound.h>
#include <dplay8.h>
#include <dpaddr.h>
#include <dinput.h>
#include <dshow.h>
#include <dxfile.h>

#pragma warning(disable : 4996)

#define release_com(x)  { if(x) (x)->Release(); }

#define STREQ(a, b) (*(a) == (*b) && strcmp((a), (b)) == 0)

////////////////////////////// typedef for built-in data type //////////////////////////////

typedef unsigned 
char   uchar;
typedef unsigned 
long   ulong;

typedef 
void*           void_ptr;
typedef 
const char*     pcstr;
typedef 
char*           pstr;
typedef 
char*           char_ptr;
typedef uchar*          uchar_ptr;
typedef 
ulong*          ulong_ptr;
typedef 
float*          float_ptr;

typedef void_ptr&       void_ptr_ref;
typedef 
ulong&          ulong_ref;
typedef uchar&          uchar_ref;
typedef 
float&          float_ref;

////////////////////////////// typedef for D3D data type //////////////////////////////

typedef D3DMATERIAL9*   D3DMATERIAL9_PTR;
typedef D3DLIGHT9*      D3DLIGHT9_PTR;

#endif

工具函數(shù)接口與實(shí)現(xiàn):

void show_error_msg(BOOL is_fatal, char* text, );
void move_window(HWND hwnd, long x_pos, long y_pos);
void resize_window(HWND hwnd, long width, long height);
long get_client_width(HWND hwnd);
long get_client_height(HWND hwnd);
long get_window_width(HWND hwnd);
long get_window_height(HWND hwnd);
long get_screen_width();
long get_screen_height();

//-----------------------------------------------------------------------------
// Show error message box.
//-----------------------------------------------------------------------------
void show_error_msg(BOOL is_fatal, char* text, )
{
    
char _caption_text[12];
    
char _error_text[2048];
    va_list _valist;

    
// Build the message box caption based on fatal flag
    strcpy(_caption_text, is_fatal ? "Fatal error" : "error");

    
// Build variable text buffer
    va_start(_valist, text);
    vsprintf(_error_text, text, _valist);
    va_end(_valist);

    
// display the message box
    MessageBox(NULL, _error_text, _caption_text, MB_OK | MB_ICONEXCLAMATION);

    
// Post a quit message if error was fatal.
    if(is_fatal)
        PostQuitMessage(0);
}

//-----------------------------------------------------------------------------
// move window to new position.
//-----------------------------------------------------------------------------
void move_window(HWND hwnd, long x_pos, long y_pos)
{
    RECT client_rect;

    GetClientRect(hwnd, &client_rect);
    MoveWindow(hwnd, x_pos, y_pos, client_rect.right, client_rect.bottom, TRUE);
}

//-----------------------------------------------------------------------------
// Resize window to new width and height.
//-----------------------------------------------------------------------------
void resize_window(HWND hwnd, long width, long height)
{
    RECT window_rect, client_rect;
    
long new_window_width, new_window_height;

    
// Retrieves the dimensions of the bounding rectangle of the specified window. 
    // The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen. 
    GetWindowRect(hwnd, &window_rect);

    
// Retrieves the coordinates of a window's client area. 
    // 
    // The client coordinates specify the upper-left and lower-right corners of the client area.
    // Because client coordinates are relative to the upper-left corner of a window's client area, 
    // the coordinates of the upper-left corner are (0,0). 
    GetClientRect(hwnd, &client_rect);

    new_window_width  = (window_rect.right - window_rect.left) - client_rect.right + width;
    new_window_height = (window_rect.bottom - window_rect.top) - client_rect.bottom + height;

    
// Changes the position and dimensions of the specified window. 
    // 
    // For a top-level window, the position and dimensions are relative to the upper-left corner of the screen. 
    // For a child window, they are relative to the upper-left corner of the parent window's client area. 
    MoveWindow(hwnd, window_rect.left, window_rect.top, new_window_width, new_window_height, TRUE);
}

//-----------------------------------------------------------------------------
// Get window client width.
//-----------------------------------------------------------------------------
long get_client_width(HWND hwnd)
{
    RECT client_rect;

    GetClientRect(hwnd, &client_rect);

    
return (client_rect.right - client_rect.left);
}

//-----------------------------------------------------------------------------
// Get window client height.
//-----------------------------------------------------------------------------
long get_client_height(HWND hwnd)
{
    RECT client_rect;

    GetClientRect(hwnd, &client_rect);

    
return (client_rect.bottom - client_rect.top);
}

//-----------------------------------------------------------------------------
// Get window width.
//-----------------------------------------------------------------------------
long get_window_width(HWND hwnd)
{
    RECT window_rect;

    GetWindowRect(hwnd, &window_rect);

    
return (window_rect.right - window_rect.left);
}

//-----------------------------------------------------------------------------
// Get window height.
//-----------------------------------------------------------------------------
long get_window_height(HWND hwnd)
{
    RECT window_rect;

    GetWindowRect(hwnd, &window_rect);

    
return (window_rect.bottom - window_rect.top);
}

//-----------------------------------------------------------------------------
// Return width of the screen of the primary display monitor, in pixels. 
//-----------------------------------------------------------------------------
long get_screen_width()
{
    
return GetSystemMetrics(SM_CXSCREEN);
}

//-----------------------------------------------------------------------------
// Return height of the screen of the primary display monitor, in pixels. 
//-----------------------------------------------------------------------------
long get_screen_height()
{
    
return GetSystemMetrics(SM_CYSCREEN);
}

游戲框架接口與實(shí)現(xiàn):

extern HWND g_hwnd;

typedef BOOL (*FRAMEWORK_FUNC)();

BOOL build_window(HINSTANCE inst, 
const char* class_name, const char* caption, 
                  DWORD style, DWORD x_pos, DWORD y_pos, DWORD width, DWORD height);

void run_game(FRAMEWORK_FUNC game_init, FRAMEWORK_FUNC game_frame, FRAMEWORK_FUNC game_shutdown);

HINSTANCE get_window_inst();
void get_class_name(char* class_name, int length);

HWND g_hwnd;

//-----------------------------------------------------------------------------
// The message procedure.
//-----------------------------------------------------------------------------
LRESULT CALLBACK window_proc(HWND hwnd, UINT msg_id, WPARAM w_param, LPARAM l_param)
{
    
switch(msg_id)
    {
    
case WM_DESTROY:
        PostQuitMessage(0);
        
return 0;
    }

    
return DefWindowProc(hwnd, msg_id, w_param, l_param);
}

//-----------------------------------------------------------------------------
// Register window aclas, create window and show it.
//-----------------------------------------------------------------------------
BOOL build_window(HINSTANCE inst, const char* class_name, const char* caption, 
                  DWORD style, DWORD x_pos, DWORD y_pos, DWORD width, DWORD height)
{    
    WNDCLASSEX win_class;

    
// create window class and register it
    win_class.cbSize        = sizeof(win_class);
    win_class.style         = CS_CLASSDC;
    win_class.lpfnWndProc   = window_proc;
    win_class.cbClsExtra    = 0;
    win_class.cbWndExtra    = 0;
    win_class.hInstance     = inst;
    win_class.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
    win_class.hCursor       = LoadCursor(NULL, IDC_ARROW);
    win_class.hbrBackground = NULL;
    win_class.lpszMenuName  = NULL;
    win_class.lpszClassName = class_name;
    win_class.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);

    
if(! RegisterClassEx(&win_class))
        
return FALSE;
    
    
// create the main window
    g_hwnd = CreateWindow(class_name, caption, style, x_pos, y_pos, width, height, NULL, NULL, inst, NULL);

    
if(g_hwnd == NULL)
        
return FALSE;

    ShowWindow(g_hwnd, SW_NORMAL);
    UpdateWindow(g_hwnd);

    
return TRUE;
}

//-----------------------------------------------------------------------------
// Run game framework.
//-----------------------------------------------------------------------------
void run_game(FRAMEWORK_FUNC game_init, FRAMEWORK_FUNC game_frame, FRAMEWORK_FUNC game_shutdown)
{
    MSG msg;

    
// intialize game
    if(! game_init())
        
return;

    
// start message pump, waiting for signal to quit.
    ZeroMemory(&msg, sizeof(MSG));

    
while(msg.message != WM_QUIT)
    {
        
if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        
        
// draw a frame
        if(! game_frame())
            
break;
    }

    
// run shutdown function
    game_shutdown();

    
// get window class name
    char class_name[MAX_PATH];
    get_class_name(class_name, 
sizeof(class_name));

    
// unregister window class
    UnregisterClass(class_name, get_window_inst());
}

//-----------------------------------------------------------------------------
// Return window instnace.
//-----------------------------------------------------------------------------
HINSTANCE get_window_inst()
{
    
return GetModuleHandle(NULL);
}

//-----------------------------------------------------------------------------
// Get window class name.
//-----------------------------------------------------------------------------
void get_class_name(char* class_name, int length)
{
    GetClassName(g_hwnd, class_name, length);
}

posted on 2007-10-25 19:41 lovedday 閱讀(483) 評(píng)論(0)  編輯 收藏 引用


只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問(wèn)   Chat2DB   管理


公告

導(dǎo)航

統(tǒng)計(jì)

常用鏈接

隨筆分類(178)

3D游戲編程相關(guān)鏈接

搜索

最新評(píng)論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            久久裸体艺术| 亚洲欧美成人一区二区三区| 久久精品国产77777蜜臀| 亚洲欧美激情视频| 国产三区二区一区久久| 久久高清国产| 久久久精品2019中文字幕神马| 国产综合欧美在线看| 麻豆freexxxx性91精品| 欧美成年网站| 亚洲欧美国产日韩天堂区| 亚洲欧洲99久久| 亚洲国产成人在线| 99视频在线观看一区三区| 国产精品影音先锋| 欧美激情成人在线| 国产精品大全| 欧美成人69av| 国产精品超碰97尤物18| 久久久久国产成人精品亚洲午夜| 欧美影院成年免费版| 亚洲精品欧洲| 亚洲欧美日韩国产综合精品二区| 在线精品视频一区二区| 一区二区高清在线观看| 激情欧美一区二区三区| 日韩视频免费观看高清在线视频| 国产日韩专区在线| 亚洲精品一区二区在线| 国产一级精品aaaaa看| 亚洲精品一区二区三区婷婷月| 国产日韩精品入口| 亚洲精品视频免费观看| 狠狠色狠狠色综合人人| 一区二区欧美视频| 亚洲国产激情| 久久国产免费看| 午夜精品视频在线观看| 欧美高清免费| 美女黄网久久| 国产午夜精品视频| 一区二区三区鲁丝不卡| 亚洲日本免费| 久久三级视频| 久久精品国产视频| 国产精品美女www爽爽爽| 亚洲国产日韩欧美一区二区三区| 国产一区二区三区免费在线观看| 夜夜嗨av一区二区三区中文字幕| 亚洲日本一区二区| 久久躁狠狠躁夜夜爽| 久久精品夜色噜噜亚洲aⅴ| 国产精品av免费在线观看| 亚洲国产精品精华液2区45| 欲色影视综合吧| 久久国产福利| 久久手机免费观看| 国产无一区二区| 欧美亚洲一区二区在线观看| 午夜天堂精品久久久久| 国产精品毛片大码女人| 在线中文字幕一区| 中文一区字幕| 欧美性jizz18性欧美| 99热精品在线观看| 亚洲永久在线| 国产精品一区二区久久精品| 中文在线一区| 欧美综合国产| 国产一区二区三区在线免费观看 | 亚洲视频欧洲视频| 欧美日韩二区三区| 一本色道久久| 欧美一区二区女人| 国内精品久久久久久久影视蜜臀| 久久国产精品免费一区| 狂野欧美激情性xxxx欧美| 在线精品观看| 欧美精品精品一区| 一区二区三区免费网站| 欧美一区二区网站| 一区久久精品| 欧美日产国产成人免费图片| 中文在线一区| 久久免费高清| 99视频热这里只有精品免费| 国产精品久久久久久模特| 午夜日韩电影| 亚洲高清精品中出| 亚洲欧美日韩精品综合在线观看| 国产午夜精品视频| 欧美v日韩v国产v| 亚洲特级片在线| 另类欧美日韩国产在线| 99热这里只有精品8| 国产精品区免费视频| 久久亚洲春色中文字幕| 日韩亚洲欧美综合| 久久精品欧洲| 一本到12不卡视频在线dvd| 国产伦精品免费视频| 欧美1区视频| 亚洲欧美日韩一区二区在线| 欧美大片免费久久精品三p| 亚洲无线视频| 亚洲成色777777女色窝| 国产精品久久久久久久久久久久久久 | 亚洲国产欧美日韩| 中文日韩在线| 一区在线免费| 国产精品草草| 欧美大片第1页| 亚洲视频网在线直播| 欧美88av| 欧美在线不卡视频| 一二三区精品| 亚洲黄一区二区| 国产主播一区二区三区| 国产精品久久久久毛片软件| 欧美不卡三区| 久久国产66| 亚洲欧美日韩精品综合在线观看| 日韩午夜精品视频| 欧美成人精品1314www| 久久久99国产精品免费| 亚洲欧美日韩精品久久亚洲区| 亚洲精品一区二| 在线观看欧美激情| 国产主播精品在线| 国产免费成人在线视频| 国产精品久久久久影院亚瑟 | av成人免费观看| 亚洲人成在线播放| 亚洲高清不卡一区| 欧美成人精品在线观看| 久久亚洲欧美| 久久人体大胆视频| 久久精品夜色噜噜亚洲aⅴ| 欧美在线观看视频一区二区| 午夜欧美精品| 久久国产精品久久久| 欧美一区二区三区啪啪| 欧美制服丝袜第一页| 久久狠狠亚洲综合| 久久久99精品免费观看不卡| 久久久蜜桃一区二区人| 久久亚裔精品欧美| 美日韩精品免费观看视频| 蜜桃久久精品一区二区| 麻豆久久婷婷| 亚洲二区视频在线| 亚洲人成网站在线播| 亚洲伦理在线观看| 一区二区欧美在线观看| 亚洲男人的天堂在线观看| 性亚洲最疯狂xxxx高清| 欧美专区在线观看一区| 蜜臀久久99精品久久久画质超高清 | 亚洲激情av| 亚洲国产中文字幕在线观看| 亚洲欧洲一区二区三区| 亚洲精品日韩综合观看成人91| 日韩视频一区二区在线观看 | 男人的天堂亚洲在线| 亚洲福利视频一区| 亚洲精选一区二区| 亚洲欧美日韩国产中文| 久久综合久色欧美综合狠狠| 欧美啪啪成人vr| 国产欧美精品日韩精品| 亚洲第一福利在线观看| 亚洲天堂av电影| 久久精品99无色码中文字幕| 亚洲丁香婷深爱综合| 在线亚洲免费| 久久综合色天天久久综合图片| 欧美精品一区二区精品网| 国产日韩欧美二区| 亚洲精品人人| 欧美专区在线| 亚洲黄色视屏| 久久xxxx精品视频| 欧美精品一区二区视频| 国产亚洲va综合人人澡精品| 亚洲精品一区二区三区婷婷月 | 麻豆av一区二区三区久久| 99国产精品久久久久久久成人热| 欧美在线www| 国产精品xvideos88| 亚洲激情视频在线观看| 欧美在线视频在线播放完整版免费观看| 欧美日韩成人综合| 国产揄拍国内精品对白| 一区二区三区四区五区视频| 久久亚洲私人国产精品va| 99视频一区二区| 免费成人高清视频| 韩国av一区二区三区四区| 亚洲自拍16p| 亚洲精品一区二区在线观看|