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

天行健 君子當自強而不息

創建游戲內核(1) 【接口與實現分離版】

 
關于該內核的細節說明請參考創建游戲內核(1),這個版本主要是按功能劃分模塊的思想,并嚴格按照接口與實現相分離的原則來寫的,沒有用面向對象的思想來寫,沒有繼承沒有多態。大家可以對比兩個版本,比較優劣。

以下是游戲框架的接口:

/*************************************************************************
PURPOSE:
    Defines for main window framework.
*************************************************************************/


#ifndef _CORE_FRAMEWORK_H_
#define _CORE_FRAMEWORK_H_

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 do_init, FRAMEWORK_FUNC do_frame, FRAMEWORK_FUNC do_shutdown);

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

#endif

接著是游戲框架的實現:

/*************************************************************************
PURPOSE:
    Implenents for main window framework.
*************************************************************************/


#include "core_common.h"
#include "core_framework.h"
#include "window_func.h"

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 do_init, FRAMEWORK_FUNC do_frame, FRAMEWORK_FUNC do_shutdown)
{
    MSG msg;

    
// intialize game
    if(! do_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(! do_frame())
            
break;
    }

    
// run shutdown function
    do_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);
}


這是公共頭文件core_common.h的定義:

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

// 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(); x = NULL; } }

#endif
 

我還將公用的windows窗口操作函數封裝在了1個文件中:

/***********************************************************************************
PURPOSE:
    Interface for windows draw.
***********************************************************************************/


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

/***********************************************************************************
PURPOSE:
    Capsulates for windows draw.
***********************************************************************************/


#include <windows.h>
#include <stdio.h>
#include <
string.h>

#pragma warning(disable : 4996)

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

posted on 2007-09-30 23:56 lovedday 閱讀(298) 評論(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>
            亚洲免费视频在线观看| 久久高清免费观看| 国产精品久久影院| 欧美国产日韩一区二区在线观看| 久久人体大胆视频| 免费视频一区二区三区在线观看| 久久久久久久999| 免费人成精品欧美精品| 国产精品扒开腿爽爽爽视频 | 最新中文字幕亚洲| a91a精品视频在线观看| 在线日韩成人| 狠狠久久婷婷| 国产日韩专区在线| 国产一区二区三区四区五区美女| 国产综合色在线| 国产亚洲欧美日韩精品| 亚洲国产99精品国自产| 日韩视频在线播放| 女女同性女同一区二区三区91| 欧美二区视频| 夜夜嗨av色综合久久久综合网| 亚洲少妇自拍| 亚洲电影免费在线| 欧美激情亚洲自拍| 精品69视频一区二区三区| 亚洲国产三级| 欧美在线播放一区| 亚洲激情第一区| 久久精品免费电影| 欧美特黄视频| 亚洲福利一区| 欧美中文在线免费| 性视频1819p久久| 免费成人在线视频网站| 亚洲人成免费| 麻豆成人在线播放| 久久久久久999| 国产精品第三页| 亚洲精品小视频在线观看| 欧美成人免费小视频| 国产欧美短视频| 亚洲永久视频| 欧美精品久久99| 在线观看欧美激情| 欧美自拍丝袜亚洲| 亚洲作爱视频| 欧美极品在线播放| 亚洲精选国产| 亚洲国产一区二区在线| 久久国产精品久久久久久电车| 欧美日韩中文字幕在线视频| 亚洲国产精品一区在线观看不卡| 久久综合综合久久综合| 欧美一区影院| 国产乱码精品一区二区三区五月婷 | 久久三级福利| 国内一区二区三区在线视频| 午夜精品久久久久| 亚洲在线成人精品| 国产精品狼人久久影院观看方式| 一区二区三区你懂的| 国产日韩欧美a| 国内伊人久久久久久网站视频| 午夜精品区一区二区三| av成人国产| 欧美日韩一区二区三区四区五区| 亚洲国产欧美久久| 亚洲国产一区二区a毛片| 欧美电影免费| aⅴ色国产欧美| 亚洲系列中文字幕| 国产日韩欧美成人| 卡一卡二国产精品| 免费看精品久久片| 中日韩美女免费视频网址在线观看 | 国产精品亚洲综合一区在线观看| 午夜日韩视频| 久久国产精品99精品国产| 亚洲第一免费播放区| 亚洲国产精品久久久久秋霞影院| 欧美日韩精品免费观看视频| 羞羞答答国产精品www一本| 性亚洲最疯狂xxxx高清| 亚洲缚视频在线观看| 亚洲精品综合久久中文字幕| 国产乱码精品| 亚洲国产精品久久久久婷婷老年| 欧美日韩免费看| 久久婷婷麻豆| 欧美人成在线视频| 久久久久综合网| 欧美精品一区三区在线观看| 久久成人精品一区二区三区| 久久久一二三| 欧美一区视频| 欧美国产精品v| 久久久成人网| 欧美日韩精品在线| 免费观看成人www动漫视频| 欧美日韩精品二区| 蜜臀久久久99精品久久久久久| 欧美日韩综合在线免费观看| 久久这里只精品最新地址| 欧美手机在线| 欧美激情亚洲国产| 国内成+人亚洲| 在线亚洲电影| 亚洲精品欧美激情| 久久久久久穴| 欧美一区亚洲一区| 欧美日韩在线直播| 亚洲国产成人精品久久久国产成人一区 | 亚洲作爱视频| 亚洲国产成人精品视频| 亚洲欧美国产高清| 亚洲视频一区二区| 欧美高清视频在线播放| 久久天天躁狠狠躁夜夜av| 国产精品久久久久婷婷| 国产在线精品二区| 一区二区三区视频在线观看| 欧美在线资源| 亚洲在线成人精品| 欧美国产精品v| 欧美韩国一区| 1769国产精品| 久久精品30| 久久久久成人精品免费播放动漫| 久久精品一区蜜桃臀影院| 亚洲女同同性videoxma| 欧美日本高清| 亚洲日本理论电影| 亚洲精品美女在线观看| 蜜桃久久av| 亚洲国产另类久久精品| 亚洲人成网站在线观看播放| 欧美成人国产一区二区| 欧美激情一区二区三区全黄 | 欧美日韩精品综合在线| 亚洲电影视频在线| 日韩视频第一页| 欧美日韩成人在线观看| 日韩视频一区二区三区| 亚洲一区二区三区精品动漫| 欧美视频在线一区二区三区| 中文欧美字幕免费| 欧美在线观看视频在线| 黄色成人小视频| 乱码第一页成人| 亚洲精品欧美日韩| 欧美一激情一区二区三区| 国产九色精品成人porny| 欧美一区二区三区四区高清 | 亚洲一区国产一区| 国产精品高潮粉嫩av| 亚洲免费一级电影| 久久全国免费视频| 亚洲欧洲精品一区二区三区波多野1战4| 麻豆av福利av久久av| 亚洲国产精品欧美一二99| 亚洲一区二区成人在线观看| 国产欧美日韩在线观看| 久久综合给合| 日韩视频一区| 久久久久一区二区三区| 亚洲狼人综合| 国产美女精品| 蜜桃av噜噜一区| 亚洲无玛一区| 毛片av中文字幕一区二区| 99re6热在线精品视频播放速度| 欧美日韩在线影院| 久久久久国产一区二区| 亚洲精品一区二区在线| 久久成人在线| 日韩视频第一页| 国内久久视频| 久久久成人精品| 99在线精品免费视频九九视| 欧美专区在线观看| 99riav国产精品| 国外成人免费视频| 欧美涩涩网站| 老司机成人在线视频| 亚洲夜间福利| 亚洲国产毛片完整版| 欧美精品在线视频| 亚洲福利电影| 香蕉久久夜色| 日韩视频在线一区| 黄网站免费久久| 欧美性猛交一区二区三区精品| 久久久久久网址| 性欧美精品高清| 亚洲一区二区免费看| 日韩午夜剧场| 亚洲激情在线观看| 免费一级欧美片在线播放| 久久综合给合久久狠狠色 |