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

天行健 君子當自強而不息

創(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>
            老司机一区二区三区| 亚洲女人天堂成人av在线| 一本色道久久综合精品竹菊| 国产欧美在线观看| 国产精品日韩精品| 国产精品制服诱惑| 好吊色欧美一区二区三区视频| 国产精一区二区三区| 国产视频在线一区二区| 韩日精品视频| 亚洲精品久久视频| 亚洲午夜黄色| 久久精品国产v日韩v亚洲| 久久激情久久| 亚洲第一精品福利| 亚洲电影在线免费观看| 日韩西西人体444www| 午夜精彩视频在线观看不卡| 久久精品国产清自在天天线| 欧美成ee人免费视频| 欧美日韩精品欧美日韩精品一| 欧美性一区二区| 欧美精品激情在线| 国产精品成人在线观看| 国产主播一区二区三区| 亚洲免费久久| 久久精品观看| 亚洲日韩第九十九页| 亚洲欧美资源在线| 欧美精品国产| 国内外成人在线| 一本色道久久99精品综合| 久久久www| 一区二区三区精品| 暖暖成人免费视频| 国产主播精品在线| 亚洲欧美一区二区三区极速播放| 美女主播一区| 亚洲一级在线| 欧美日韩综合一区| 亚洲区免费影片| 久久亚洲精品欧美| 午夜视频在线观看一区| 欧美视频在线一区| 日韩亚洲精品在线| 亚洲第一毛片| 六月天综合网| 在线免费观看日本一区| 久久大逼视频| 亚洲欧美色一区| 国产精品久久久久久久浪潮网站| 91久久久在线| 亚洲大胆视频| 欧美国产精品久久| 亚洲美女在线一区| 最新国产成人av网站网址麻豆| 久久九九有精品国产23| 国产精品综合| 欧美在线中文字幕| 午夜精品三级视频福利| 国产精品久久久久久久久搜平片| 一区二区三区日韩| 99精品欧美一区二区蜜桃免费| 欧美电影免费| 在线视频精品一区| 亚洲精品视频在线| 欧美视频一区| 性欧美xxxx视频在线观看| 亚洲一区二区伦理| 国产日韩欧美在线播放| 久久久久综合| 狼狼综合久久久久综合网| 亚洲电影免费观看高清完整版在线| 免费的成人av| 欧美激情亚洲国产| 亚洲欧美区自拍先锋| 午夜伦欧美伦电影理论片| 国内精品久久国产| 欧美14一18处毛片| 欧美xxx在线观看| 亚洲天堂网在线观看| 亚洲欧美日韩精品在线| 亚洲精品一区二区三区四区高清| 欧美激情一区在线| 欧美日韩亚洲一区二区三区在线观看 | 亚洲一区黄色| 欧美一区国产在线| 亚洲欧洲久久| 亚洲午夜免费视频| 在线观看欧美一区| 在线视频欧美日韩| 精久久久久久| 在线一区二区三区四区五区| 国产一区二区剧情av在线| 亚洲国产另类精品专区 | 久久成人在线| 亚洲精品在线免费| 亚洲综合精品四区| 亚洲片在线观看| 午夜精品亚洲| 一区二区毛片| 久色成人在线| 久久xxxx| 欧美午夜大胆人体| 欧美国产免费| 国产一区二区欧美| 艳妇臀荡乳欲伦亚洲一区| 一区免费视频| 亚洲综合国产精品| 亚洲一区日韩在线| 欧美本精品男人aⅴ天堂| 久久精品国产在热久久| 麻豆亚洲精品| 久久精品99国产精品日本| 欧美精品一卡二卡| 欧美成人精品影院| 国产一区二区在线免费观看| 9人人澡人人爽人人精品| 在线观看日韩专区| 欧美一级视频免费在线观看| 亚洲小少妇裸体bbw| 另类酷文…触手系列精品集v1小说| 亚洲男人的天堂在线| 欧美精品一区二| 亚洲第一精品福利| 最新成人av网站| 麻豆精品在线观看| 亚洲国产高清一区| 亚洲精品在线一区二区| 麻豆91精品| 欧美成人一区二区三区片免费| 国模一区二区三区| 久久亚洲国产精品日日av夜夜| 久久精品一本久久99精品| 国产精品日日摸夜夜摸av| 亚洲天堂免费观看| 篠田优中文在线播放第一区| 国产精品xvideos88| 亚洲精品国产系列| 在线视频精品一| 国产精品国产三级国产aⅴ浪潮| 日韩一二三区视频| 欧美精品一区二区三区高清aⅴ| 欧美国产日韩一区| 亚洲免费观看在线视频| 欧美日韩蜜桃| 亚洲欧美成人| 久久婷婷丁香| 亚洲黄网站在线观看| 欧美大成色www永久网站婷| 亚洲国产视频a| 这里只有精品丝袜| 国产欧美日韩一区| 久久久水蜜桃av免费网站| 欧美激情第10页| 亚洲午夜日本在线观看| 国产精品免费网站在线观看| 午夜欧美不卡精品aaaaa| 久久蜜臀精品av| 亚洲欧洲日本mm| 欧美日韩一区二区在线视频| 亚洲一二三级电影| 麻豆av一区二区三区久久| 91久久亚洲| 国产精品久久久久久久第一福利| 先锋亚洲精品| 亚洲高清免费视频| 翔田千里一区二区| 亚洲国产一区二区三区a毛片| 免费亚洲婷婷| 中文日韩在线视频| 麻豆亚洲精品| 中文在线一区| 国内久久婷婷综合| 欧美电影免费观看高清| 亚洲欧美久久久久一区二区三区| 久热国产精品| 亚洲一级一区| 国产美女精品| 欧美丰满高潮xxxx喷水动漫| 亚洲精品视频在线观看网站| 日韩一区二区久久| 国产亚洲制服色| 欧美日韩综合| 欧美v国产在线一区二区三区| 亚洲三级电影全部在线观看高清| 一本色道久久综合亚洲精品小说 | 亚洲国产精品久久久久秋霞不卡| 在线亚洲观看| 亚洲精品美女久久久久| 国产日韩欧美高清| 欧美视频一区在线| 欧美激情中文字幕一区二区| 欧美影院视频| 亚洲一区国产| 亚洲麻豆av| 欧美激情成人在线| 久久深夜福利| 久久精品亚洲一区二区三区浴池| 亚洲一区二区成人|