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

天行健 君子當自強而不息

創(chuàng)建游戲內(nèi)核(1)【OO改良版】

 

這是面向?qū)ο笥螒騼?nèi)核的改良版,主要對原來游戲內(nèi)核對象組織一些不合理之處做出了改良,并且遵循以下原則:

1、淺分層、薄膠合的原則,對于簡單的功能只用函數(shù)封裝,如果需要實現(xiàn)的功能模塊較復雜,并且需要用到較多的輔助數(shù)據(jù)結(jié)構(gòu)則用類封裝,以減少對象的使用。

2、本版本不使用模板,盡量減少封裝層數(shù),最大限度地增加透明度。

3、盡量不在構(gòu)造函數(shù)內(nèi)用表達式初始化任何數(shù)據(jù),以使用memet簡化類數(shù)據(jù)成員的初始化,只使用默認構(gòu)造函數(shù),不使用其他任何形式的構(gòu)造函數(shù)。

4、盡量不在類內(nèi)部保存冗余的數(shù)據(jù),如果這個數(shù)據(jù)真正存儲在另一個地方,則不在其他類中做多余的保存,保證數(shù)據(jù)存儲的唯一性。

5、不重載函數(shù),不使用參數(shù)默認值。  


關(guān)于該內(nèi)核的細節(jié)說明請參閱創(chuàng)建游戲內(nèi)核(1)

 

公共頭文件:

/**************************************************
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(); x = NULL; } }
#define free_memory(x)  { free(x); (x) = NULL; }

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

typedef unsigned 
char uchar;
typedef unsigned 
long ulong;

#endif

游戲框架頭文件:

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


#ifndef _CORE_FRAMEWORK_H_
#define _CORE_FRAMEWORK_H_

extern HWND g_hwnd;

HINSTANCE get_window_inst();
void get_class_name(char* class_name, int length);
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);

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

class FRAMEWORK
{
public:
    
virtual BOOL init()         { return TRUE; }
    
virtual BOOL frame()        { return TRUE; }
    
virtual BOOL shutdown()     { return TRUE; }

    
void run();
};

static FRAMEWORK* g_framework = NULL;

#endif

 

框架實現(xiàn)代碼:

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


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

HWND g_hwnd;

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

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

//-----------------------------------------------------------------------------
// 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 FRAMEWORK::run()
{
    MSG _msg;

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

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

測試代碼:
 
/*****************************************************************************
PURPOSE:
    Test for class FRAMEWORK.
*****************************************************************************/


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

class APP : public FRAMEWORK
{
public:
    BOOL init();
    BOOL frame();
    BOOL shutdown();
    
private:
    
char* m_name;
};

//-----------------------------------------------------------------------------
// Initialize application.
//-----------------------------------------------------------------------------
BOOL APP::init()
{
    
if((m_name = new char[9]))
    {
        strcpy(m_name, "no_name");
        
return TRUE;
    }

    
return FALSE;
}

//-----------------------------------------------------------------------------
// Do a frame.
//-----------------------------------------------------------------------------
BOOL APP::frame()
{
    
// If user clicks button CANCEL, then exit application.
    if(MessageBox(g_hwnd, m_name, "My name is", MB_OKCANCEL) == IDCANCEL)
        
return FALSE;

    
return TRUE;
}

//-----------------------------------------------------------------------------
// shutdown application.
//-----------------------------------------------------------------------------
BOOL APP::shutdown()
{
    delete[] m_name;
    m_name = NULL;

    
return TRUE;
}

//--------------------------------------------------------------------------------
// Main function, routine entry.
//--------------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE inst, HINSTANCE pre_inst, LPSTR cmd_line, int cmd_show)
{
    APP app;

    
if(! build_window(inst, "MainClass", "MainWindow", WS_OVERLAPPEDWINDOW, 0, 0, 640, 480))
        
return -1;
    
    app.run();

    
return 0;
}

posted on 2007-10-06 13:11 lovedday 閱讀(438) 評論(0)  編輯 收藏 引用


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


公告

導航

統(tǒng)計

常用鏈接

隨筆分類(178)

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

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            老牛影视一区二区三区| 久久婷婷久久| 久久久国产精品一区二区中文 | 国产一区视频在线观看免费| 国产女精品视频网站免费| 国产美女精品| 国产真实乱偷精品视频免| 狠狠色狠狠色综合日日五| 亚洲第一久久影院| 亚洲午夜激情网页| 久久精品中文| 亚洲国产精品成人一区二区| 免费在线观看日韩欧美| 亚洲精品久久久久中文字幕欢迎你 | 亚洲国产你懂的| 亚洲少妇诱惑| 欧美一区亚洲| 欧美日韩成人| 国产一区视频网站| 99re热这里只有精品免费视频| 亚洲天堂av高清| 久久只有精品| 一区二区三区欧美在线| 久久人人超碰| 国产精品啊啊啊| 黄色亚洲网站| 亚洲欧美日韩国产成人| 欧美77777| 亚洲免费一区二区| 欧美激情第8页| 国产一区二区在线观看免费| 在线一区二区三区做爰视频网站| 久久网站免费| 亚洲欧美高清| 欧美日本一区二区三区| 激情欧美一区二区| 性欧美xxxx大乳国产app| 欧美va亚洲va国产综合| 亚洲欧美激情诱惑| 久久精品视频亚洲| 99综合视频| 欧美激情一区二区三区在线视频观看| 国产日韩在线亚洲字幕中文| 一区二区三区欧美激情| 欧美国产三级| 欧美在线视频观看免费网站| 国产精品国色综合久久| 正在播放欧美视频| 亚洲国产精品久久久久秋霞蜜臀| 欧美一区二区三区在线| 国产精品综合久久久| 一区二区日韩伦理片| 亚洲第一中文字幕| 久久综合色婷婷| 精品成人久久| 美女91精品| 久久人人超碰| 亚洲国产日韩欧美综合久久| 美女999久久久精品视频| 久久精品国产欧美亚洲人人爽| 国产精品一卡二| 性色一区二区三区| 亚洲欧美视频一区二区三区| 国产精品免费看片| 亚洲欧美在线免费| 亚洲在线观看免费| 国产色综合天天综合网| 久久爱91午夜羞羞| 欧美一区二区三区在线视频| 狠狠色丁香婷婷综合久久片| 久久夜色精品国产| 美女久久网站| av成人动漫| 一区二区三区蜜桃网| 国产欧美一区二区精品秋霞影院| 欧美资源在线观看| 久久久久久色| 日韩一本二本av| 一区二区不卡在线视频 午夜欧美不卡在 | 午夜精品一区二区在线观看| 亚洲一区二区三区激情| 国产精品视频网| 久久久亚洲综合| 免费观看一级特黄欧美大片| 一本一本大道香蕉久在线精品| 99国内精品久久| 国产亚洲人成网站在线观看| 欧美v日韩v国产v| 欧美久久综合| 久久精品成人一区二区三区| 久久亚洲欧美| 国产精品videossex久久发布| 亚洲欧美日韩综合| 久久久久国产一区二区三区四区| 亚洲精品欧美日韩| 亚洲欧美日韩视频一区| 亚洲激情视频在线播放| a4yy欧美一区二区三区| 国产亚洲欧美另类中文| 亚洲日本无吗高清不卡| 国产午夜精品在线| 亚洲人成在线免费观看| 国产原创一区二区| 99re热精品| 亚洲国产精品一区在线观看不卡| 在线中文字幕日韩| 亚洲激情在线| 欧美综合第一页| 亚洲一区二区免费视频| 美日韩丰满少妇在线观看| 午夜精品成人在线视频| 欧美极品一区二区三区| 久久综合导航| 国产精品网站在线播放| 亚洲欧洲综合另类| 狠狠色狠狠色综合人人| 亚洲欧美日韩一区二区在线| 在线亚洲自拍| 欧美国产成人在线| 欧美成人免费全部| 国产综合色在线| 亚洲一区亚洲| 亚洲欧美清纯在线制服| 欧美日韩一二三区| 亚洲国产日韩美| 亚洲国产另类久久精品| 久久久亚洲高清| 久久久久国产精品麻豆ai换脸| 欧美午夜在线| 一本色道久久88综合日韩精品| 亚洲精品偷拍| 欧美电影在线观看完整版| 免费成人在线观看视频| 黄色一区二区在线观看| 久久综合网络一区二区| 麻豆成人小视频| 影音先锋日韩精品| 久久精品人人做人人爽电影蜜月| 久久精品免费电影| 国模套图日韩精品一区二区| 欧美一区二区三区四区在线观看 | 欧美在线亚洲综合一区| 国产精品免费看久久久香蕉| 亚洲免费视频成人| 欧美在线视频观看| 国产欧美一区视频| 亚洲一区欧美一区| 性欧美videos另类喷潮| 黄色精品一区| 欧美不卡视频一区发布| 最新亚洲激情| 午夜精彩视频在线观看不卡| 国产婷婷色一区二区三区| 欧美一区视频| 欧美成人精品一区二区| 欧美亚一区二区| 亚洲视频一区二区免费在线观看| 一区二区三区产品免费精品久久75 | 日韩亚洲在线| 午夜伦欧美伦电影理论片| 国产亚洲毛片| 美女网站久久| 日韩午夜免费视频| 久久国产免费看| 亚洲级视频在线观看免费1级| 欧美日韩国产综合视频在线观看中文| 99精品国产高清一区二区| 欧美在线中文字幕| 亚洲国产一区二区在线| 欧美四级电影网站| 欧美一区二区三区四区在线| 亚洲国产精品一区二区www在线| 亚洲天堂网在线观看| 国产真实精品久久二三区| 欧美美女福利视频| 亚洲欧美综合网| 91久久久久| 欧美影片第一页| 亚洲人体1000| 国语自产精品视频在线看抢先版结局 | 午夜在线不卡| 亚洲第一综合天堂另类专| 国产精品入口福利| 欧美大片在线观看一区| 亚洲欧美日韩第一区| 亚洲精品黄色| 欧美承认网站| 久久久久国产精品一区二区| 亚洲视频精品在线| 亚洲人成人一区二区在线观看| 国产日韩一区欧美| 国产精品豆花视频| 欧美成人精品一区二区三区| 欧美一区二区三区电影在线观看| 亚洲另类一区二区| 欧美激情二区三区| 久久亚洲精品伦理| 久久久福利视频| 欧美综合国产| 欧美一区二区三区免费观看视频|