讓vcmi支援英雄無敵3中文版

來源:互聯網
上載者:User

標籤:validator   sts   binary   1.0   art   encoding   idea   字串   開源   

Table of Contents
  • 1 Hack 日誌
  • 2 Changes
  • 3 Install by compiling
  • 4 reply of Ivan
1 Hack 日誌
  • 8月22日開始動手修改改vcmi(英雄無敵3的開源遊戲引擎)的源碼, 讓它支援簡體中文版的遊戲資料。
  • 8月25日,已經有一個可工作的修改版,但自己不滿意。這個版本的原理是每次要顯 示文本的時候,都用自己寫的編碼轉換函式將字串從GBK編碼轉為UTF8編碼,從而 能正常地顯示中文。但每次顯式都轉換,每秒遊戲要10幀以上,每幀要顯示的字串 可以多達數十個,這樣每秒要做數百次字串轉換,效率很低。雖然這樣的計算量對 現代CPU來說不算啥,但心裡覺得彆扭。高效的做法應該是將遊戲資料中的GBK編碼的 字串載入記憶體的時候只做一次編碼轉換,轉換為UTF8編碼。
  • 這時開始置疑PC遊戲相關工作的意義,所以工作中斷了。
  • 中斷一個月後,覺得開始的事情沒做完,心裡彆扭,就決定來個收場。於是9月27號, 開始做一個高效的修改。9月28日算大功告成。這個事可以告一段落了。

以下是對源碼所做的修改,和怎麼編譯安裝,當時用英文做的記錄,懶得再翻譯回中文了。

2 Changes
  1. client/CMessage.cpp

    in function CMessage::breakText(), line 153

                // added by [email protected], 2013-08-28            // If the text[z] is less than 0, it is the first byte of a UTF8 Chinese word.#ifdef ZH_CN            else if (text[z] < 0){                z++;                z++;             lineLength += graphics->fonts[font]->getSymbolWidth(text[z]);            }#endif
  2. client/gui/Fonts.cpp

    in function CTrueTypeFont::getStringWidth(), line 255

        // added by [email protected], 2013-08-28    // If we are handling simplified chinese, it is a UTF8 string#ifdef ZH_CN    TTF_SizeUTF8(font.get(), data.c_str(), &width, NULL);#else    TTF_SizeText(font.get(), data.c_str(), &width, NULL);#endif

    in function CTrueTypeFont::renderText(), line 279

         if (blended)            // added by [email protected], 2013-09-28 Sat            // If we are handling simplified chinese game data, it is a UTF8 string#ifdef ZH_CN         rendered = TTF_RenderUTF8_Blended(font.get(), data.c_str(), color);#else         rendered = TTF_RenderText_Blended(font.get(), data.c_str(), color);#endif     else            // added by [email protected], 2013-09-28 Sat            // If we are handling simplified chinese game data, it is a UTF8 string#ifdef ZH_CN         rendered = TTF_RenderUTF8_Solid(font.get(), data.c_str(), color);#else         rendered = TTF_RenderText_Solid(font.get(), data.c_str(), color);#endif
  3. add lib/ConvertEncoding.cpp and lib/ConvertEncoding.h

    The content of ConvertEncoding.h is:

    char * convert_enc(char *src_enc, char *dest_enc, const char * src_string);

    The content of ConvertEncoding.cpp is:

    /* * ConvertEncoding.cpp, for vcmi using CJK(China/Japan/Korea) data. * * Authors: Wu Jiqing ([email protected]) * * License: GNU General Public License v2.0 or later * */// added by jiqingwu([email protected])// 2013-09-27 Fri#include <stdio.h>#include <iconv.h>#include <string.h>// added by [email protected], 2013-09-27 Frichar * convert_enc(char *src_enc, char *dest_enc, const char * src_string){#define UTF8_STR_LEN 5000    static char out_string[UTF8_STR_LEN], *sin, *sout;    int  in_len, out_len, ret;    iconv_t c_pt;    if ((c_pt = iconv_open(dest_enc, src_enc)) == (iconv_t)-1)    {        printf("iconv open failed!\n");        return NULL;    }    // iconv(c_pt, NULL, NULL, NULL, NULL);    in_len  = strlen(src_string) + 1;    out_len = UTF8_STR_LEN;    sin = (char *)src_string;    sout = out_string;    ret = iconv(c_pt, &sin, (size_t *)&in_len, &sout, (size_t *)&out_len);    if (ret == -1)    {        return NULL;    }    iconv_close(c_pt);    return out_string;}

    to link ConvertEncoding.o into library, add two lines into lib/CMakeLists.txt:

    set(lib_SRCS        ...        ConvertEncoding.cpp)set(lib_HEADERS        ...        ConvertEncoding.h)
  4. lib/CGeneralTextHandler.cpp,

    To include "ConvertEncoding.h"

    // added by jiqingwu([email protected])// 2013-09-27 Fri#include "ConvertEncoding.h"

    in function CLegacyConfigParser::readString(), line 112

        // added by [email protected], 2013-09-27 Fri    // convert gbk string to utf-8 string.    // (For simplified Chinese game data, the string is GBK encoded)#ifdef ZH_CN    char * utf8_str = convert_enc("GBK", "UTF8", ret.c_str());    return std::string((const char*)utf8_str);#else    return ret;#endif
  5. lib/filesystem/CBinaryReader.cpp,

    to include "ConvertEncoding.h":

    // added by <[email protected]>, 2013-09-28 Sat#include "../ConvertEncoding.h"

    in function CBinaryReader::readString(), line 95

        // added by [email protected], 2013-08-22    // If we are handling chinese data, convert gbk string to utf-8 string.#ifdef ZH_CN    char * utf8_str = convert_enc("GBK", "UTF8", ret.c_str());    return std::string((const char*)utf8_str);#else    return ret;#endif
3 Install by compiling
  1. add such a line into ./CMakeLists.txt to enable supporting Simplifed Chinese Game Data
    add_definitions(-DZH_CN)
  2. make a directory build under the source dir
    mkdir build
  3. create makefiles
    cd buildcmake ..

    This may take a short while.

  4. compile
    make
  5. install (root privilege is needed)
    make install

    Check the directories of vcmi

    vcmiclient -v

    You will see the result like this:

    Starting... VCMI 0.93  data directory:    /usr/local/share/vcmi  library directory: /usr/local/lib/vcmi  path to server:    /usr/local/bin/vcmiserver

    Here, vcmi is installed under /usr/local

  6. Use the Data from the chinese version of Death of Shadow. Link the ‘Data‘, ‘Maps‘, ‘Mp3‘ directories under /usr/local/share/vcmi like this (You need have root privilege):
    cd /usr/local/share/vcmiln -s /Data/Dir/of/ChineseGame Dataln -s /Maps/Dir/of/ChineseGame Mapsln -s /Mp3/Dir/of/ChineseGame Mp3
  7. To show chinese characters in this game, you need put a true type font which supports Chinese into /usr/local/share/vcmi/Data.
    cp /chinese/font/path /usr/local/share/vcmi/Data

    Edit the /usr/local/share/vcmi/config/fonts.json, modify the truetype font section like this:

    "trueType":{    "BIGFONT"  : { "file" : "ChineseFont.ttf", "size" : 22, "blend" : true},    "CALLI10R" : { "file" : "ChineseFont.ttf", "size" : 10, "blend" : true},    "CREDITS"  : { "file" : "ChineseFont.ttf", "size" : 28, "blend" : true},    "HISCORE"  : { "file" : "ChineseFont.ttf", "size" : 13, "blend" : true},    "MEDFONT"  : { "file" : "ChineseFont.ttf", "size" : 16, "blend" : true},    "SMALFONT" : { "file" : "ChineseFont.ttf", "size" : 13, "blend" : true},    "TIMES08R" : { "file" : "ChineseFont.ttf", "size" : 11, "blend" : true},    "TINY"     : { "file" : "ChineseFont.ttf", "size" : 11, "blend" : true},    "VERD10B"  : { "file" : "ChineseFont.ttf", "size" : 13, "blend" : true}}

    Where ChineseFont.ttf is your true type font.

  8. Play Game
    vcmiclient
4 reply of Ivan
(0004091) Ivan (developer) - 2013-10-20 13:09http://bugs.vcmi.eu/view.php?id=1420#c4091----------------------------------------------------------------------Thanks. I‘ll take a look on this. I don‘t like idea of using ifdef‘s to enablesome functionality but you‘ve tracked every place that needs changes - that willhelp.

Date: 2013-10-21T19:48+0800

Author: Jiqing Wu

Org version 7.9.3f with Emacs version 24

Validate XHTML 1.0

 

http://www.cnblogs.com/jiqingwu/p/let_vcmi_support_chinese.html

讓vcmi支援英雄無敵3中文版

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.