常用鏈接留言簿(5)我參與的團隊隨筆分類隨筆檔案文章檔案搜索最新評論
閱讀排行榜評論排行榜 |
2010年8月11日 #
采用這種形式即可突破限制: erl -env ERL_MAX_PORTS 2048
2008年12月5日 #
c/c++中的宏不是語法中的一部分, 是在編譯器開始編譯之前的一種文本替換行為, 因此可以利用c/c++中的編譯器中的選項來預處理其他沒有預處理功能的語言
比如, 利用微軟的cl.exe 編譯器來預處理文本, 命令: cl.exe /EP test.vb 這樣如果test.vb中有類似#define 的語句, 會被刪除, 而后一些用到該宏的地方, 會被真實的值替換 2008年11月14日 #
google的protobuf是一個對結構的序列化和反序列化的中間語言, 可以跨多個語言使用, 值得關注
2008年11月12日 # 最近在游戲編程精粹4(Game Programming Gems 4)中看到了對于XDS的介紹,解開了我對于XML低效的困惑。也許在小型的XML應用中不覺得,但是在大數據量的應用中XML的速度甚至無法和普通的.ini相提并論。首先讓我們來看看XDS是什么吧。 XDS技術由DSD和XDS兩種文件格式組成。前者跟XSD相似,后者跟XML相似,只不過這兩種格式都是二進制的。正是采用了二進制格式,無論是在體積還是在速度上XDS的性能比XML都有明顯的提升。目前支持XDS的免費庫主要有XDSToolkit,現在可以下載到1.03版本。這是一個開源項目,解壓后我們可以看到它由兩個工具一個API包組成,另外還附一個例子。兩個工具的名字分別叫做xdsConvert和xdsMakeSchema,分別是用來進行XML和XDS相互轉換,以及生成DSD文件的。 在一個C/C++項目中,我們經常需要用struct定義一系列數據結構。xdsMakeSchema就可以通過輸入數據結構的定義文件.h來生成DSD和相應的c頭文件。在一個項目的初期,你可能需要用XML編輯器來編寫這個項目所需要的XML數據,然后在程序中通過XDSLiteAPI來進行解析。這套API有兩個Paser,一個服務于XML,另一個服務于XDS。當你的項目完全可以自動生成XML的時候就可以由XML轉向XDS了。游戲編程精粹中解釋的很詳細,這邊就說說需要注意的地方了。 要利用API對XDS進行解析需要以下步驟: ① 以struct定義的C數據類型 ② XDS的數據類型定義,可以在DSD中,也可以在程序中定義 ③ 回調函數的編寫,主要是XDS_PROCESSNODE函數 以該工具包附帶的Powerup為例,struct看起來是這樣的: struct PowerUp_t { char szName[10]; // display name char szImage[16]; // image file name // health increase/decrease (-128 to 127) signed char iHealth; // temporary abilities/penalties // (value is duration in seconds) unsigned char iInvulnerability; unsigned char iFastMove; unsigned char iHighJump; unsigned char iStunPlayer; // extra life (count) unsigned char iLifeUp; }; // global power-up definition cache extern struct PowerUp_t *g_PowerUps; 可以通過使用xdsMakeSchema來生成dsd,同時生成的xxxx_dsd.h只是為了免除將dsd文件讀入內存,查看它的內容就可以看到它定義了一個dsd數組: // XDS DSD literal -- use this in calls to xdsInit() // #ifdef DEFINE_DSD const unsigned char XDSDSD_Powerups[216] = { 0x58, 0x44, 0x53, 0x21, 0x30, 0x33, 。。。 }; #else extern const unsigned char XDSDSD_Powerups[216]; #endif // XDS DSD IDs -- use these in implementation of XDS_PROCESSNODE() // #define XDS_Powerups_Powerup 0x0100 // Record #define XDS_Powerups_PowerUp_t 0x0101 // Type #define XDS_Powerups__xdsType1 0x0102 // Type #define XDS_Powerups_g_PowerUps 0x0103 // Element 同時還定義了一些常量,這些常量在解析xds中會用到。 除了在dsd中對于xds格式的定義之外,我們還可以在main.cpp中看到程序內的定義: #ifdef XDS_SUPPORT_DEFTYPE void regDsd(struct xdsHandle *hXds) { // Register my types (test only) xdsDefRecord(hXds, "Powerup", 2); unsigned short iStructType = xdsDefStructType(hXds, "PowerUp_t"); xdsDefStructField(hXds, iStructType, "szName", XDS_TYPE_CHAR, 10); xdsDefStructField(hXds, iStructType, "szImage", XDS_TYPE_CHAR, 16); xdsDefStructField(hXds, iStructType, "iHealth", XDS_TYPE_CHAR, 0); xdsDefStructField(hXds, iStructType, "iInvulnerability", XDS_TYPE_BYTE, 0); xdsDefStructField(hXds, iStructType, "iFastMove", XDS_TYPE_BYTE, 0); xdsDefStructField(hXds, iStructType, "iHighJump", XDS_TYPE_BYTE, 0); xdsDefStructField(hXds, iStructType, "iStunPlayer", XDS_TYPE_BYTE, 0); xdsDefStructField(hXds, iStructType, "iLifeUp", XDS_TYPE_BYTE, 0); xdsDefStructDone(hXds, iStructType); unsigned short iArrayType = xdsDefArrayType(hXds, "_xdsType1", iStructType, 0, 2); xdsDefElement(hXds, "g_PowerUps", iArrayType, 0); } #endif 注意:交叉使用dsd定義和程序定義容易造成一個錯誤,就是在程序和dsd可能在定義的時候沖突,數據類型沖突,或者數據長度沖突,從而導致程序的崩潰。附帶的例子中程序定義數據類型如下: #ifdef XDS_SUPPORT_DEFTYPE void regDsd(struct xdsHandle *hXds) { // Register my types (test only) xdsDefRecord(hXds, "Powerup", 4); unsigned short iStructType = xdsDefStructType(hXds, "PowerUp_t"); xdsDefStructField(hXds, iStructType, "szName", XDS_TYPE_CHAR, 10); xdsDefStructField(hXds, iStructType, "szImage", XDS_TYPE_CHAR, 16); xdsDefStructField(hXds, iStructType, "iHealth", XDS_TYPE_CHAR, 0); xdsDefStructField(hXds, iStructType, "iInvulnerability", XDS_TYPE_BYTE, 0); xdsDefStructField(hXds, iStructType, "iFastMove", XDS_TYPE_BYTE, 0); xdsDefStructField(hXds, iStructType, "iHighJump", XDS_TYPE_BYTE, 0); xdsDefStructField(hXds, iStructType, "iStunPlayer", XDS_TYPE_BYTE, 0); xdsDefStructField(hXds, iStructType, "iLifeUp", XDS_TYPE_BYTE, 0); xdsDefStructDone(hXds, iStructType); unsigned short iArrayType = xdsDefArrayType(hXds, "_xdsType1", iStructType, 0, 2); xdsDefElement(hXds, "g_PowerUps", iArrayType, 0); } #endif 要是在生成dsd時用參數-r Powerup:2而這里用xdsDefRecord(hXds, "Powerup", 4)的話就會導致沖突。
2008年10月15日 #
推薦一款比較好用的python的IDE, 就是ActiveState 的Komodo
2008年9月19日 # int main() { char *errorFormat = "%s(%d): error\n"; printf(errorFormat, __FILE__, __LINE__); return 0; } 關鍵就是%s(%d), 只要賦值為文件名和行號, 雙擊即可定位到代碼處, 當然, 想要printf到Output窗口, 那就在工程屬性的BuildEvents->Post-Build Event 的CommandLine中填寫$(TargetPath), 即可
2008年9月11日 # 要集成Mantis和SVN,需要幾個工具:
bugtraq:label = issue 到對應的SVN版本庫里,找到hooks目錄,建立一個post-commit.bat文件,將以下內容拷入: REM Post-commit hook for MantisBT integration rem REPOS svn版本庫的路徑 rem 拷貝了 checkin.php 進行修改,重新命名 為 checkin_svn.php 如果有中文傳輸,需要修改 checkin_svn.php
SET REPOS=%1
echo SVN 修改人: >>%DETAILS_FILE% echo SVN 修改日期: >>%DETAILS_FILE% echo SVN 版本: >>%DETAILS_FILE% echo SVN 提交注釋: >>%DETAILS_FILE% echo SVN 修改明細: >>%DETAILS_FILE%
del %DETAILS_FILE%
$g_source_control_notes_view_status = VS_PUBLIC; 完成這些步驟后,就可以在SVN提交新版本時,同時發布內容到對應的缺陷跟蹤系統了。 比如,修改了一個源文件,svn commit時,在右上的issue欄目里輸入要提交到的具體的 issue/bug 編號, 完成以上工作后使用過程中還存在一些問題 REM pre-commit.bat hook for MantisBT integration rem 把注釋信息寫入到 DETAILS_FILE rem 執行checkin_svn_pre_commit.php 進行校驗缺陷單號 是否在缺陷系統中存在,如果不存在,返回輸出信息到 log_file中 rem 校驗log_file中是否有內容,如果有內容,轉入到出錯提示 del %DETAILS_FILE% :err 二、創建checkin_svn_pre_commit.php 到數據庫中校驗缺陷單信息 # add note to each bug only once
2008年9月9日 #
c++的協程庫, 一個是boost::coroutine, 一個是http://www.akira.ruc.dk/~keld/research/COROUTINE/
2008年8月20日 #
找到一個比較好的c++ 的MockObject庫, amop(http://code.google.com/p/amop/), 該庫很容易根據接口定制一個Mock object, 比Mockpp好用多了
2008年3月26日 # Windows上的圖形繪制是基于GDI的, 而Direct3D并不是, 所以, 要在3D窗口中顯示一些Windows中的控件會有很多問題 那么, 有什么辦法讓GDI繪制的內容在3D中顯示出來?反正都是圖像, 總有辦法實現的嘛! 前段時間在研究瀏覽器在游戲中的嵌入, 基本的思路就是在后臺打開一個瀏覽窗口, 然后把它顯示的內容拷貝到一張紋理上, 再把紋理在D3D中繪制出來, 至于事件處理就要另做文章了. 所以, 其它的Windows里的GDI繪制的東西都可以這樣來實現! 1. 取得控件的DC: GetDC(hWnd) BOOL BitBlt(
HDC hdcDest, // handle to destination DC int nXDest, // x-coord of destination upper-left corner int nYDest, // y-coord of destination upper-left corner int nWidth, // width of destination rectangle int nHeight, // height of destination rectangle HDC hdcSrc, // handle to source DC int nXSrc, // x-coordinate of source upper-left corner int nYSrc, // y-coordinate of source upper-left corner DWORD dwRop // raster operation code ); 如果是OLE控件那就更簡單啦: WINOLEAPI OleDraw(
IUnknown * pUnk, //Pointer to the view object to be drawn DWORD dwAspect, //How the object is to be represented HDC hdcDraw, //Device context on which to draw LPCRECT lprcBounds //Pointer to the rectangle in which the object // is drawn ); 比如我有一個IWebBrowser2的指針, 想把它顯示的內容拷貝到紋理上, 可以這么干: IDirect3DSurface9* pSurface = NULL;
this->mTexture->GetSurfaceLevel(0, &pSurface); if (NULL != pSurface) { HDC hdcTexture; HRESULT hr = pSurface->GetDC(&hdcTexture); if(FAILED(hr)) return; ::SetMapMode(hdcTexture, MM_TEXT); ::OleDraw(pBrowser, DVASPECT_CONTENT, hdcTexture, &rect); pSurface->ReleaseDC(hdcTexture); pSurface->Release(); } Show一下: 不光是瀏覽器啦, 任何OLE控件都可以, 可以發揮你的想像力: |