70萬行代碼、歷時20年,一名開發人員寫出的史詩般的計算機程序

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如果要問有史以來最史詩般的計算機程序是什麼,《矮人要塞》一定榜上有名。這是一款 2006 年面世的遊戲,開創性地將“先設定好基本規則,剩下的就讓遊戲和玩家自己去發掘”的理念帶到了電子遊戲領域。《我的世界》開發者曾表示《矮人要塞》深刻啓發了他的遊戲設計思路。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"整個遊戲自始至終只有一名開發者:Tarn Adams,又名 Toady One。20 年來,他一直沒有停止過開發。到目前爲止,這款遊戲的代碼量已經多達 70 萬行。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"最近 Adams 在採訪中分享了他對遊戲創作以及如何管理一個不斷增長的代碼庫的思考和經驗。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"一套自然增長 20 年、從不重構的代碼"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"《矮人要塞》這款遊戲由 Tarn Adams 及其兄弟 Zach 一起設計,其中 Adams 負責開發,Zach 負責劇情。Adams 原本是大學數學教授,最初只是將這款遊戲當作一個副業進行,2002 年辭職開始全職開發,直到現在都沒有停下過前進的腳步。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"截至 2020 年 2 月,遊戲最新"},{"type":"link","attrs":{"href":"https:\/\/en.wikipedia.org\/wiki\/Dwarf_Fortress","title":"xxx","type":null},"content":[{"type":"text","text":"更新爲 0.47.05 版本"}]},{"type":"text","text":"。按照 Adams 設置的“用進度代替版本號”的命名規則,這個遊戲目前完成度是 47%。Adams 表示,“現階段,我們制定的計劃很可能已經超出了我們的能力,需要花更長時間才能完成。”"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這款作品支持三種不同遊戲模式,包括堡壘建設模式,由玩家指揮一羣矮人在荒地上建設一座城市;冒險模式,類似於傳統的 rouguelike 地下城探索遊戲,收集充滿中世紀韻味的武器、幹掉危險的怪物;最後則是傳奇模式,你可以觀看由遊戲本身精心整理出的傳奇歷史,回顧你操作過的每一位英雄人物、跨越幾代人的史詩戰爭。這三種模式之間還會相互影響。當你的矮人定居點年久失修之後,就可以以冒險家的身份進行探索,將兩種玩法的成果納入同一個世界背景下的傳奇當中。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"另外,由於整個環境都是用 ASCII 字符的形式呈現,所以一切就變得更光怪陸離了。矮人用小小的笑臉表示,盔甲架對應一個音符,日元標誌則代表着洞穴裏的邪惡龍蝦人。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/wechat\/images\/41\/41d8001da9dc029434bc615d0ac65a76.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Adams 開發遊戲使用的編程語言主要是 C 和 C++,開發工具此前是 Microsoft Visual Studio,現在改爲 Visual Studio 社區版,用 OpenGL 和 SDL 作爲遊戲引擎。“只使用 Windows 10 Toshiba 筆記本電腦”,而且“不確定 Linux\/Mac 版本中發生了什麼”。在遊戲的機制方面,幾乎不使用外部庫,只偶爾會使用一些隨機數生成器——“很久以前我放入了一個 Mersenne Twister,最近我採用了 SplitMix64。”"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在遊戲的最初版本中,Adams 就已經完成了所有編程工作,如今使用的代碼庫還是 2003 年構建的那套。整個遊戲的後臺需要一刻不停地瘋狂運轉,這也讓《矮人要塞》這款其貌不揚的遊戲成爲有名的處理器“殺手”。有人開玩笑說,用於娛樂目的的高性能處理器的最佳用途之一是《矮人要塞》。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"初版遊戲如今被稱爲《矮人要塞經典版》,通過 "},{"type":"link","attrs":{"href":"http:\/\/www.bay12games.com\/dwarves\/index.html","title":"xxx","type":null},"content":[{"type":"text","text":"Bay 12 網站"}]},{"type":"text","text":"免費提供。對於各個版本,Adams 需要根據原始代碼進行大約 12 次相應編譯,包括面向不同平臺的 32 位與 64 位操作系統版本。版本更新的間隔,最快的一次是 26 個月。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"從開始到現在,項目幾乎就沒怎麼經歷過大的、"},{"type":"link","attrs":{"href":"https:\/\/stackoverflow.blog\/2021\/07\/28\/700000-lines-of-code-20-years-and-one-developer-how-dwarf-fortress-is-built\/","title":"xxx","type":null},"content":[{"type":"text","text":"嚴格意義上的重構"}]},{"type":"text","text":",在 Adams 看來,花幾個月重做某些數據結構就是他爲項目所做的最大的改變。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"而隨着編碼知識和技能不斷更新換代,Adams 還得推動遊戲的機制向前發展。與《我的世界》的 3D 界面比較起來,《矮人要塞》顯得很古老。雖然現在的 3D 遊戲開發已經很成熟了,但對於類似 Unity 或 Unreal 之類的庫,Adams 表示就算到現在,他也不確定自己是否會使用。《矮人要塞》實現 3D 的方式只是通過添加 Z 座標來完成。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"歷經 20 年的開發,這款遊戲的代碼庫已經非常龐大,多達 711,000 行。靠人類的大腦,已經不可能完全記得住,就算這些全是 Adams 自己一行行實現的。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"漫長的開發過程中面臨的一個問題是遺忘。項目出了問題怎麼進行維護,Adams 表示只能靠“搜索”:“我有一個一致的命名方式,而且我不會吝嗇更長的變量和函數名稱,這樣即使在多年之後,一切仍然可讀。同時也需要留下足夠的註釋,來表示某個代碼點發生了什麼。一般來說,我會注意對未來的自己更友善。”"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"“這是個規模巨大的項目,我們沒捷徑可走……”"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"這 20 年是如何度過的?"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"《矮人要塞》是一款免費遊戲。十幾年以來,《矮人要塞》的開發者拒絕讓這款遊戲在任何平臺發售。Adams 認爲《矮人要塞》和市面上那些商業化的遊戲都完全不同,這款遊戲要以十年爲單位一直更新、發展下去,他擔心一旦商業化,會沒法自己把握遊戲更新的節奏。爲此,兩人拒絕了很多發行商的合作請求。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"不上游戲平臺銷售遊戲,自然就沒有穩定的收入。Adams 這麼多年全靠玩家捐贈維生,據他們所說每個月能有幾千美元的捐款收入,足以維持生活和開發。通過 Bay 12 公司公司的官網頁面,粉絲可以設置一次性或定期的 PayPal 捐贈。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/wechat\/images\/b1\/b1e57fc3c1dd065de0e063054ce86568.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"向 Bay 12 Games 捐款的粉絲們,有機會獲得由 Tarn and Zach Adams 親自用蠟筆繪製的手工藝作品。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在 2006 年對外發布之前的幾年裏 Adams 是沒有收入的, 各種花銷完全靠當教授時積攢下來的 15,000 美元。2010 年,依靠粉絲捐贈,他總共掙到了 5 萬美元。2014 年 11 月爲 3,400 美元。2013 年 10 月爲 4,727 美元。2014 年 12 月躍升至 8,181 美元。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Adams 將生活開支安排得很低,以滿足他“理想狀態中的開發者生活”。每月只花費 860 美元的租金,幾百美元的水電費和購買食物的費用,只要能自給自足就行。他對物質也沒有什麼要求,甚至在 2019 年纔開始使用智能手機,在此之前,Adams 對自己的翻蓋手機很滿意。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https:\/\/www.nytimes.com\/2011\/07\/24\/magazine\/the-brilliance-of-dwarf-fortress.html","title":"xxx","type":null},"content":[{"type":"text","text":"根據《紐約時報》的記載"}]},{"type":"text","text":",Adams 的開發生活是這樣的:每天下午 3 點左右醒來,然後通宵編碼,早上 6 點左右睡覺,週而復始。房間窗戶用膠合板遮起來,阻擋陽光以免影響睡眠。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Adams 還在 2011 年拒絕了一家頭部遊戲開發商的工作邀請,以及另一家開發商 30 萬美元的遊戲許可報價,只希望用自己的方式開發自己的遊戲。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這種理想主義的開發生活,讓許多遊戲玩家憤憤不平,但 Adams 卻表示,“我們只是不想成爲商人,賺錢對我們來說沒有意義”。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"“開發到死,永不停更”"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"過去 20 年當中,Adams 一直忙於爲《矮人要塞》編程,甚至根本沒有時間顧得上圖形設計。爲了最大程度削減圖形設計帶來的工作量,他甚至直接從已經三十歲高齡的 MS-DOS 中搬出了 ASCII 字符圖像。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"Adams 坦言,“有些菜單確實很粗糙,我在設計功能鍵時基本就是亂選的。所以很多玩家抱怨,「爲什麼得在這個界面裏按 U、H、J、K 來實現對應功能?」好吧,有些設計已經是 15 年前的東西了,但出於種種原因我一直沒來得及做出調整。”"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"由於遊戲太過複雜,同時缺少現代遊戲中常見的種種便利性設置,使得《矮人要塞》對新手玩家特別不友好。除了簡短的介紹動畫之外,遊戲中沒有任何圖形元素,就連鼠標都不支持。新人在看着老鳥通過神祕的鍵盤輸入控制界面時,感覺就像在觀察上世紀八十年代初操盤手們使用的早期股票交易軟件。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"但所有這一切,讓《矮人要塞》在遊戲評論者及愛好者心中獲得了獨特的地位。它最近還被收錄至紐約現代藝術博物館中,改變了館方對於藝術的審視方式。這款遊戲的巨大影響力既體現在講故事的方式上,也體現在對其他遊戲開發者的啓發上。如果沒有《矮人要塞》,可能就不會有《我的世界》。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https:\/\/static001.geekbang.org\/wechat\/images\/d6\/d68d737d930fe5d2601ba5aeaa04f923.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":false,"pastePass":false}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":"center","origin":null},"content":[{"type":"text","text":"Steam 上的《矮人要塞》藝術展示圖。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"雖然《矮人要塞》的開發工作已經持續了相當長時間,但 Bay 12 給遊戲打下的底子確實很好,後續更新一直相當順利。Adams 會在社區內以博文的形式發佈更新、討論下一階段的開發目標並說明自己在發佈前如何進行代碼測試。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"幾年前,他的兄弟 Zach 被診斷出患有癌症。雖然已經買了比較全面的醫療保險,但後期費用仍然不低。這時候的 Adams 重新審視自己的開發計劃,突然被嚇了一跳。“我們一起認真研究起治療價格。如果換作是我,那我絕對會傾家蕩產。”"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"出於對家族遺傳性癌症的恐懼,且粉絲的捐贈並不足以幫他們消化掉美國重症醫療帶來的沉重負擔。Adams 這才做出了一個“違背初心的決定”——在 2019 年正式啓動遊戲的商業化運營計劃。這對他來說也是一種“道德挑戰”。但登陸 Steam 市場的確幫助他渡過了危機,Adams 總結道,“或者應該說是躲過了一劫。現在我們打算儲備一點能應付緊急狀況的資源,然後安心回到創作中來。”"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"目前他正在開發一個改進了 UI 的 Steam 付費版本。對於未來的開發計劃,在將遊戲打磨至完美之前,Adams 還有另外一項重要的更新任務得完成——在遊戲裏添加邪惡一派的非玩家角色。他以實事求是地態度向媒體講述了開發目標,在記者看來他的想法只能用超現實來形容。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"這些反派們將在更龐大的遊戲世界中由 AI 負責控制。他們會有自己的動機,策劃建立邪惡聯盟或者逐步滲透政府。Adams 還強調,這些反派甚至能夠囚禁英雄、暗殺國王。當然,反派們也會世代更迭,成爲傳奇模式中世界歷史的一部分。最後,反派也將在要塞與冒險模式中閃亮登場,給玩家們製造或大或小的各種麻煩。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"現在遠遠不是終點,《矮人要塞》還是希望更多玩家加入其中,爲了牢牢抓住用戶的心,Adams 需要花時間打磨這款作品。當然,Steam 版本的推出也讓 Tarn Adams 和他的好兄弟 Zach Adams(兄弟二人創立了 Bay 12 Games 公司開展業務)實現了財務自由。所以只要他們的健康狀況還允許,兩位就會繼續更新《矮人要塞》。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"事實上,如果這樣一款遊戲宣佈“徹底完成”,對於粉絲們反而不是什麼好消息。這款遊戲的獨特之處與核心吸引力,正在於極高的複雜性。它的遊戲內容堪稱包羅萬象、無所不有。也正因爲如此,當問到這款自 2003 年起就一直處於開發狀態的遊戲什麼時候能最終完成時,Adams 給出的答案近乎瘋狂:“完成代表着止步,止步代表着缺憾。”"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在 Adams 看來,這條更新之路應該永遠走下去:“開發到死,永不停更。”"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"參考鏈接:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https:\/\/stackoverflow.blog\/2021\/07\/28\/700000-lines-of-code-20-years-and-one-developer-how-dwarf-fortress-is-built\/","title":"","type":null},"content":[{"type":"text","text":"https:\/\/stackoverflow.blog\/2021\/07\/28\/700000-lines-of-code-20-years-and-one-developer-how-dwarf-fortress-is-built\/"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https:\/\/www.polygon.com\/features\/2019\/3\/14\/18264569\/dwarf-fortress-steam-tarn-adams-villains-health-care","title":"","type":null},"content":[{"type":"text","text":"https:\/\/www.polygon.com\/features\/2019\/3\/14\/18264569\/dwarf-fortress-steam-tarn-adams-villains-health-care"}]}]}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章