牧遊社 牧有漢化翻譯
EU4 - Development Diary - 19th of February 2019
Duplo, Rookie GameDev
Fantastic bits and where to find them
神奇位數在哪裡
Hi everyone, I am Lorenzo aka Duplo aka The Battlepope aka The Caped Crusader and I am programmer on our beloved Europa Universalis 4. You may have seen me in the Dharma Dev Clash, struggling to spread Catholicism and occasionally getting betrayed by fellow Italians and wrecked up by Venice AI.
大家吼啊,本人Lorenzo,別名Duplo,外號The Battlepope,暱稱The Caped Crusader又回來了。我也是我們廣受愛戴的歐陸風雲4開發組的一名程序猿。你可能在達摩的開發人員大戰直播中見到過我遊玩教宗國,費盡心思擴大天主恩澤之地,卻間歇性被義大利二五仔背叛,持續性被威尼斯AI吊打的經歷。
In these last weeks we announced that 1.28.3 was the last Europa Universalis 4 release supporting 32-bit, since we are moving toward 64-bit. I thought it would be nice to give to all of you an insight of what this means, what to genuinely expect in the near future and what to definitely not expect.
在前幾周中,鑑於我們要向64位邁進,我們發布了最後一個支持32位系統的歐陸風雲版本號1.28.3。我尋思應該向全體玩家介紹這項工作的意義,讓大家知道在近期內要期待哪些玩意而哪些東西是不切實際的,這總歸是件好事。
There's been a lot of fuss about 64 vs 32-bit apps lately. But what is all of this about?
最近經常有很多關於64位和32位程序的爭論,但到底啥是位數?
It is no mystery that Apple decided to deprecate 32-bit apps in MacOS 10.14 "Mojave" (2018) in order to drop the support completely in the future: they are doing an amazing job reminding us about this every time we launch Steam or our beloved Europa Universalis 4.
蘋果公司在2018年發布的MacOS 10.14「莫哈維」系統中,已經決定不鼓勵使用32位應用程式,以此在未來完全停掉對其的維護,這已經不是什麼秘密了。每次我們啟動Steam或親愛的歐陸風雲4時,蘋果公司的大手筆都在提醒著我們關注這件事。
What may be less known is that while 32-bit apps may still run on the latest MacOS release the new development environment was stripped out of all the fancy 32-bit support, making it painful for the poor developers to even compile the game. They are trying hard to make everyone move to 64. But why?
大眾用戶常常不盡了解的是,儘管此時32位應用程式仍然可以在最新的MacOS系統上運行,但新的開發環境已經去掉了對美好32位系統的支持,這就導致可憐的開發者們陷入了深深的痛苦,更別提編譯遊戲了。
If I got your attention so far, we can finally dive into the topic. It's going to be great.
如果從開頭到現在,我的話能引起你的注意,那麼我們終於就可以開始進入話題了,接下來的內容會很棒的。
The fellowship of the bits
位數的歷史進程
When we say 64-bit, we are talking about x86-64, a CPU architecture designed by AMD of which the specifications were released in the year of our Lord 2000.
當我們說64位的時候,我們在說的實際上是x86-64,它是由AMD公司所設計的CPU架構,其規格在我主耶穌誕辰2000年時發布。
In the year 2001, the Linux kernel started supporting this new architecture, even if there were no processors available on the market yet.
2001年,Linux kernel作業系統也開始支持這種進行架構,即使當時市場上還沒有這種架構的處理器。
In the year 2003, the very first x86-64 processor is released: the AMD64 Opteron. Several Linux distributions were already supporting x86-64.
2003年,第一個採用x86-64架構的處理器發布,也就是大名鼎鼎的AMD64皓龍。隨後,幾個支持x86-64的Linux產品也隨之發布。
In the year 2005, Microsoft discontinued the IA-64 (another 64-bit architecture from Intel) version of Windows XP, and released Windows XP Professional x64 Edition.
2005年,微軟終止了利用IA-64(另一款英特爾的64位架構)開發的Windows XP,發布了正式的Windows XP 64位專業版。
In the year 2009, Apple latest state of the of art system, Mac OS X 10.6 "Snow Leopard", was released with full support for 64 bits on the x86-64 platform. Also Windows 7 started to be loaded by default in his 64 bit version on most new computers.
2009年,蘋果最新版的系統MacOS X 10.6「雪豹」帶著對x86-64平臺64位的完全支持發布。同時,Windows 7也開始在最新的電腦上默認安裝64位版本
In the year 2011, with Mac OS X 10.7 "Lion", Apple decided to drop the support for 32-bit CPUs, effectively starting that modernization process of their platform that last year resulted in the deprecation of 32-bit apps.
2011年,隨著Mac OS X 10.7「獅」的發布,蘋果決定停止支持32位CPU,有效開啟了自家平臺現代化的進程,最終導致了去年的對32位應用程式的停止支持。
Nice. But still, why should I care?
幹得漂亮。但是為什麼俺們要在乎這些呢?
Well, there are several reasons to actually move to 64-bit. The looming threat of deprecation on MacOS is maybe the most evident, but there is much more. The x86-64 architecture is better than its older brother, by far.
嗯,實際上轉向64位的確有一些原因。MacOS不支持32位的陰雲或許是最主要的,但還有更多因素在其中。目前為止x86-64架構的確比他的老哥強多了。
Without going too much into technical details, the advantages of going full 64-bit can be summarized in three main points:
不討論過多技術細節,全面使用64位的優點可以被概括成以下三點
1. Extended addresss pace
1. 擴展了地址空間
64-bit applications can break the hard limit of 4 GB of RAM. By several orders of magnitude. Do you like blobbing in Europa Universalis 4? Think about how happy the CPUs would be if they could do the same with RAM.
64位應用程式可以來打破RAM的4GB固定限制。二者不在一個數量級上。你希望歐陸風雲4中用二進位大對象嗎?想想如果這樣改進的話,CPU們在用RAM 做相同的工作時會有多開心。
2. Capacity increase
2. 性能增強
64-bit registers and 64-bit enabled operands that will allow the CPU to perform trivially operations that were costly in the 32-bit architecture. Didn’t you want to find your way from Paris to Beijing in the blink of an eye?
同樣是那些在32位中耗費性能的繁瑣操作,64位的寄存器和元運算就可以讓CPU正常運轉。你難道不想在眨眼之間就尋到巴黎到北京的路徑嗎?
3. Larger number of general-purpose registers
3. 更多的通用寄存器
In compute-intensive code, the 64-bit compiler will make use of these additional registers to better optimize the generated program. Russia will be able to recruit Streltsy even faster!
在計算密集型的代碼中,64位編譯器將利用這些額外的寄存器來更好地優化生成的程序。俄羅斯將能夠更快地招募射擊軍!
There is also another, non-technical, advantage: support. While Microsoft is not as zealous as Apple in its crusade against legacy technology, they are obviously putting most of their efforts in the new - and definitely more common - architecture. Of course the 32-bit tools are still doing an honest job, but having the chance to move to the new 64-bit ones will allow us to get advantage of the new hardware features, getting less bugs and better performances.
還有另一個,非「技術性」的優勢:技術支持。雖然微軟不是像蘋果那樣狂熱地反對傳統技術,但是他們也更多的致力於更新的以及顯然更常見的架構。當然32位架構下的工具仍然在忠實的履行自己的功能,但是轉移到新的64位架構能夠讓我們利用更多的硬體功能,更少的BUG,與更好的性能。
Wow! Great!
吼啊!支持!
That said, moving to 64-bits won’t magically make the game run twice as fast, nor it will make more content appear out of nothing. While the migration to the new architecture itself will have little impact on Europa Universalis 4 at the beginning, it will put the foundation for the future development, allowing us - the programmers - to gradually try to squeeze the most out of the CPUs! But important questions first…
也就是說,轉向64位不會神奇地使遊戲運行速度提高兩倍,也不會讓更多內容無中生有。雖然遷移到新架構本身一開始對EU4影響不大,但它將為未來的發展奠定基礎,讓我們的程式設計師逐漸嘗試更充分的利用CPU們! 但先談談重要的問題...
Multithreading when?
何時多線程?
Really? C’mon… The lack of multithreading in Europa Universalis 4 has been a common misconception for a long time.
講真?別搞我們...歐陸風雲4中缺少多線程是一個長期的普遍誤解。
What is multithreading about? Multithreading involves taking small pieces of logic and potentially execute them at the same time, getting advantage of the multiple cores of modern CPUs. The advantage of multithreading is that we can squeeze the most of the processor and get things done faster, because executed at the same time. The main problem of multithreading is that it’s impossible to predict when the Operating System is going to let them run, as the execution of threads is completely out of the application control. Working with multithreading is basically finding the proper balance between the potentially better performances given by running tasks at the same time and the performance loss due to the synchronization.
什麼是多線程?多線程涉及採用小塊邏輯並可能同時執行它們,從而充分利用現代CPU的多核心。多線程的優勢在於我們可以擠出儘可能多的處理器並更快地完成任務,得益於它們同時執行任務。多線程的主要問題是無法預測作業系統何時讓它們運行,因為線程的執行完全超出了應用程式控制。使用多線程基本上可以在同時運行任務所帶來的潛在更好性能與同步導致的性能損失之間找到適當的平衡。
This trade off isespecially noticeable in Europa Universalis 4 as the game has tons of small pieces of information to calculate, and each of them is heavily influencing the AI behavior.
這種權衡在歐陸風雲4中尤為明顯,因為遊戲中有大量的小塊信息需要計算,而且每一項都會嚴重影響AI的行為。
There are things that can be safely executed in parallel - and indeed they are executed that way - like loading and processing data, updating independent pieces of the gamestate, cache calculations, most of AI behaviors… But there are also things that definitely cannot: pieces of gamestate dependent on other pieces to be calculated before and so on... Trying to force those interdependent operations to be executed in parallel would produce non-deterministic results - different results even with exactly the same initial state - and inconsistent data. This non-deterministic behavior can lead to the game crashing, because the data dependent for an operation might be still in an incomplete state.
有些東西可以安全地並行執行,他們也確實已經被並行執行了,比如讀取與處理數據,刷新遊戲狀態中獨立的那些部分、緩存計算、大部分AI行為...但是也有一些部分絕對不能拿來並行處理:那些相互之間不那麼獨立的,需要進行先後計算的遊戲狀態等等讓這些非獨立的操作進行並行處理會產生不確定的狀態:同樣的初始條件會導出不一致乃至矛盾的結果。這種非確定行為可能導致遊戲崩潰,因為操作所依賴數據可能仍處於不完整狀態。
A mysterious and shady voice I can hear behind me explains this problem this way:
我能聽到一個神秘而陰暗的聲音以這種方式解釋了這個問題:
Imagine the data as existing as a quantum wave function. Until observed we can not know what state the data is in. When one thread needs to access and change that data the wave function collapses as it's being observed. If there were an expectation of that the data would be in a specific state before the wave function collapses it will just be garbled mess and the universe crashes.
想像一下,數據存在於量子波函數中。在觀察之前,我們無法知道數據處於什麼狀態。當一個線程需要訪問並更改該數據時,波函數會在觀察時崩潰。如果期望在波函數崩潰之前數據將處於特定狀態,那麼就會出現亂碼並且宇宙崩潰。
One of the focus of us, programmers, is to try to get the best performances possible, while adding new cool features. Multithreading is already a powerful tool in our toolbox. Multithreading is a thing in Europa Universalis 4, and it’s here to stay
我們程式設計師的一個焦點是嘗試獲得最佳性能,同時添加新的很酷®的內容。 多線程已經是我們工具箱中的強大工具。多線程已經是歐陸風雲4工具箱中的一個強大工具。EU4是多線程運行的,它就是這麼工作的。
This old, but still valid Development Diary is an example of our effort to get the best performances out of our game, and the charts show how multithreading is actually a fundamental part of this effort!
這個先前的但仍然有效的開發日誌是我們努力從遊戲中獲得最佳性能的一個例子,圖表顯示多線程實際上是這項工作的基本部分!
If you have any question, please write them in this thread. I'll follow the discussion and try to answer all of you!
如果您有任何疑問,請在論壇貼中回復。我會跟著討論,試著回答每個人的問題!
翻譯:坎寧 MatrixEssenes
校對:萬豪頓 三等文官猹中堂
歡迎關注鬥魚主播小牧Phenix!
歡迎關注牧遊社微信公眾號和知乎專欄!微信公眾號近期改版為信息流,歡迎置頂訂閱不迷路,即時獲得推送消息!
歡迎加入牧有漢化,致力於為玩家社群提供優質內容!翻譯人員募集中!