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

天行健 君子當自強而不息

創建游戲內核(1) 【C風格版】

 

該版本根據接口與實現分離版改的, 因為接口與實現分離寫起來太煩瑣,所以直接使用結構體。由于結構體的數據成員可以直接訪問,可以減少編寫大量的接口函數,同時對于簡單的數據結構采用函數封裝, 只對復雜的功能模塊采用結構體封裝,減少抽象對象的使用以最大限度增加代碼的透明度。


共同頭文件:

/**************************************************
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

工具函數接口與實現:

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);
}

游戲框架接口與實現:

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 閱讀(486) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導航

統計

常用鏈接

隨筆分類(178)

3D游戲編程相關鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            欧美在线视频免费| 久久9热精品视频| 一区二区三区四区国产精品| 久久午夜视频| 国产性色一区二区| 欧美在线视屏| 久久在线免费观看| 久久精品亚洲乱码伦伦中文| 亚洲欧美高清| 巨胸喷奶水www久久久免费动漫| 欧美一级在线亚洲天堂| 先锋影音久久| 美女久久网站| 欧美成人一区二区三区| 欧美jizz19hd性欧美| 欧美精品v日韩精品v国产精品 | 一区二区精品国产| 亚洲国产婷婷香蕉久久久久久| 亚洲国产天堂久久综合| 亚洲精品日韩精品| 亚洲国产高潮在线观看| 亚洲五月六月| 一区二区成人精品 | 亚洲国产欧美久久| 欧美国产日韩一二三区| 亚洲人成网站在线观看播放| 亚洲一区影音先锋| 欧美一区二区精品久久911| 欧美一区二区性| 欧美精品在线免费播放| 国产精品a久久久久久| 国产精品日韩一区二区| 亚洲精品久久久久久一区二区| 最新国产拍偷乱拍精品| 在线亚洲观看| 久久在线免费观看| 99riav1国产精品视频| 亚洲自拍另类| 欧美日韩在线不卡一区| 国产欧亚日韩视频| 亚洲黄页一区| 久久一区二区三区国产精品| 亚洲国产高清在线| 国产精品99久久久久久人| 老司机精品福利视频| 国产精品久久久久久久9999| 亚洲电影免费观看高清完整版在线观看| 亚洲午夜一二三区视频| 久久久久久久一区二区| 亚洲人在线视频| 老司机精品福利视频| 国产精品日韩久久久| 亚洲精品乱码久久久久久| 国产美女精品视频| 香蕉视频成人在线观看| 欧美成人精品在线| 国产日产精品一区二区三区四区的观看方式 | 国产婷婷97碰碰久久人人蜜臀| 伊人色综合久久天天| 一区二区三区免费在线观看| 久久一二三四| 久久久国产精品一区二区中文| 欧美日韩天天操| 亚洲国产成人不卡| 欧美激情第三页| 久久超碰97人人做人人爱| 国产精品多人| 欧美一级理论性理论a| 日韩亚洲视频| 欧美经典一区二区| 亚洲午夜一二三区视频| 亚洲精品乱码久久久久| 亚洲欧美激情视频| 国产手机视频一区二区| 欧美一区二区三区久久精品茉莉花 | 亚洲在线一区二区三区| 欧美激情偷拍| 欧美女人交a| 亚洲精品欧美在线| 亚洲电影欧美电影有声小说| 欧美韩国一区| 亚洲精品一区二区在线| 欧美国内亚洲| 国产精品久久77777| 亚洲深夜福利视频| 亚洲免费av观看| 国产精品男女猛烈高潮激情| 亚洲一二三区在线观看| 久久久久综合| 欧美中文字幕在线视频| 国内精品国语自产拍在线观看| 欧美在线观看视频一区二区三区| 亚洲一区二区三区四区视频| 狠狠色综合网| 欧美成年人在线观看| 亚洲摸下面视频| 亚洲国产精品一区在线观看不卡 | 亚洲视频在线看| 欧美精品激情在线观看| 欧美一区二区三区精品电影| 午夜精品亚洲| 国产精品福利在线观看网址| 美日韩精品免费观看视频| 美女黄网久久| 欧美日韩黄色一区二区| 国产亚洲一二三区| 国语自产在线不卡| 亚洲国产专区| 国产综合色产在线精品| 日韩一级视频免费观看在线| 韩国三级在线一区| 中国日韩欧美久久久久久久久| 在线观看视频欧美| 亚洲欧美一区二区在线观看| 亚洲美女精品成人在线视频| 久久久xxx| 久久噜噜亚洲综合| 国产欧美三级| 一区二区三区产品免费精品久久75 | 欧美日韩在线精品| 欧美大胆成人| 国产日韩欧美三级| av成人激情| 一区二区三区欧美成人| 久久综合色一综合色88| 久久久久久尹人网香蕉| 国产农村妇女精品一二区| 日韩视频一区二区三区在线播放| 国产亚洲精品久久久久久| 一区二区三区精品| 亚洲网站在线看| 欧美日韩国产丝袜另类| 亚洲黄色成人久久久| 亚洲片国产一区一级在线观看| 久久精品国产综合精品| 久久爱www久久做| 国产视频一区免费看| 亚洲免费在线观看| 久久精品国产77777蜜臀| 国产精品视频免费在线观看| 夜夜嗨av色一区二区不卡| 亚洲性感美女99在线| 国产精品magnet| 亚洲一级片在线看| 性欧美暴力猛交另类hd| 国产午夜一区二区三区| 欧美一区二区三区男人的天堂 | 国产精品亚洲精品| 亚洲欧美大片| 美日韩在线观看| 亚洲国产影院| 欧美日韩精品一区视频| 中文亚洲欧美| 久久深夜福利免费观看| 亚洲福利视频网站| 欧美喷水视频| 亚洲一区在线看| 久久婷婷人人澡人人喊人人爽| 亚洲国产精品美女| 欧美色123| 久久久国产精彩视频美女艺术照福利| 快she精品国产999| 99在线|亚洲一区二区| 国产精品视频一区二区高潮| 亚洲精品在线一区二区| 亚洲在线观看视频| 欧美一级电影久久| 欧美成人性网| 先锋影音国产一区| 国产精品一区二区你懂得 | 一本色道久久综合狠狠躁篇的优点| 久久不射中文字幕| 免费亚洲一区二区| 国产日韩欧美中文| 一本色道久久综合亚洲91| 久久网站免费| 欧美主播一区二区三区美女 久久精品人| 久久亚洲一区| 亚洲欧洲精品一区| 欧美r片在线| 欧美三级乱人伦电影| 欧美淫片网站| 久久综合狠狠综合久久综青草| 国产一区 二区 三区一级| 99国产精品久久久久久久久久| 午夜亚洲激情| 亚洲一区在线免费| 久久精品99国产精品日本| 中文有码久久| 国产精品久久毛片a| 亚洲五月婷婷| 国产精品啊啊啊| 久久在线精品| 老色批av在线精品| 亚洲欧美日产图| 亚洲欧美日韩另类| 国产美女一区二区| 91久久久一线二线三线品牌| 亚洲激情欧美激情| 噜噜噜在线观看免费视频日韩|