透過您的圖書館登入
IP:52.14.22.250
  • 學位論文

CWT - 跨平台Java遊戲開發之AWT/Swing架構

CWT - An AWT/Swing Architecture for Cross-Platform Java Game Development

指導教授 : 吳毅成 蔡文能

摘要


近年來,Java平台在效能上的長足進步,使其達到開發遊戲之所需。然而,實際應用Java開發遊戲之後,我們發現Java標準內建的視窗工具組AWT及Swing在各種不同的執行環境組態中存在繪圖效能不一致的問題,這些執行環境的組合包含下列四項:一、Java執行環境版本(JRE);二、繪圖應用程式界面(API);三、Java執行期系統參數;四、常用的作業系統,如Windows XP、Windows Vista、Fedora及Mac OS X。這種效能不一致的現象使得遊戲開發人員難以預測Java遊戲在使用者電腦的繪圖效能,也降低了Java倡言的「撰寫一次即可隨處運行(Write-Once-Run-Anywhere)」的跨平台優勢。 為了解決繪圖效能不一致的問題,使遊戲在不同平台上執行皆能達到高速且一致的繪圖效能,我們提出了一套AWT/Swing架構,稱為CYC視窗工具組(CYC Window Toolkit),簡稱CWT,具有下述數項特性。首先,CWT架構支援多種常用的高速繪圖函式庫,如DirectX及OpenGL,為了相容於沒有硬體加速的環境,CWT也使用Java AWT來繪圖。CWT架構也維持Java的跨平台特性,支援各Java虛擬機器(Java VM)、.NET公共語言執行環境(.NET CLR)以及各種不同的作業系統。再者,CWT提供與Java AWT/Swing 1.1版相同API的元件,降低將既有Java遊戲移植到CWT的難度。對於需要進一步調整遊戲效能的程式設計師來說,CWT提供一對一對應的API,以便直接操作CWT內部的DirectX與OpenGL物件,以及遊戲相關的各種參數。此外,CWT也可以應用於3D應用程式,這對於現在流行的3D遊戲設計十分重要。 我們依照CWT架構實作了三種CWT工具組,並開放於專屬網站 (http://java.csie.nctu.edu.tw/cwt/) [15]。這三種實作各自使用AWT、DirectX及OpenGL來繪製使用者介面,尤其是後二項實作,可以在支援的作業系統中,得到繪圖加速卡的硬體加速支援。為了測試並比較原本Java AWT/Swing與CWT的繪圖效能,我們設計了兩支測試程式,用來測試基本繪圖能力(Micro-benchmark)與綜合繪圖能力(Macro-benchmark)。測試程式執行於常用的JRE,如MSVM及JRE 1.4至1.6版,以及前面提到的四個作業系統中,其結果顯示:CWT比Java AWT/Swing更能在這些不同的組態中達到更好且更一致的繪圖效能。由於CWT提供Java AWT/Swing 1.1版的介面,也可以在Java 1.1版的環境下運行,因此,CWT的API數量及Java執行期系統參數都較Java AWT/Swing少,較少的測試組合有助於提升程式設計師的生產力。 我們將實作CWT以及測試效能的經驗,歸納出三點方向,使Java在未來成為更好的跨平台遊戲的開發平台。一、由於繪圖加速卡的快速演進,Java應開放內部的DirectX與OpenGL物件,讓遊戲程式設計師能夠直接存取新功能或調整繪圖行為。二、Java AWT/Swing的繪圖管線應該與JRE分開發行,有助於更快速地升級、除錯該繪圖管線,並支援舊版本的JRE。三、複用現有的DirectX與OpenGL綁定(Bindings)以降低開發成本、提高可維護性、簡化運用Java AWT/Swing於Java 3D及JOGL應用程式中的難度,並提高效能。

關鍵字

CYC Window Toolkit CWT Java遊戲 DirectX OpenGL

並列摘要


In recent years, the performance of Java platforms has been greatly improved, which makes Java satisfy the requirements for developing games. However, after practicing in real game development, we observe that a phenomenon of performance inconsistency exists in the graphics of Java AWT/Swing with different combinations of JREs, graphics APIs, system properties, and operating systems (OSs), including Windows XP, Windows Vista, Fedora and Mac OS X. This phenomenon makes it hard to predict the rendering performance of Java games and weakens the merits of the Write-Once-Run-Anywhere feature of Java. In order to solve the above problems, we propose a portable AWT/Swing architecture, called CYC Window Toolkit (CWT), for developing cross-platform Java games with high and consistent rendering performance. CWT has the following features. First, the CWT architecture supports multiple graphics libraries such as AWT, DirectX and OpenGL, multiple virtual machines such as Java VM and .NET CLR, and multiple OSs. Next, CWT supports AWT/Swing 1.1 compatible widgets, so it can be easily applied to existing Java games. For programmers who want to fine tune their games, CWT supports one-to-one mapping APIs to directly manipulate DirectX and OpenGL objects and other game-related properties. In addition, CWT supports interoperability with 3D applications, which is an important feature for 3D game design. We implemented three versions of CWT – AWT, DirectX, and OpenGL, to take advantage of graphics hardware acceleration on all supported OSs. The implementations of CWT are available on our website (http://java.csie.nctu.edu.tw/cwt/) [15]. Two testing programs, including micro-benchmark and macro-benchmark, are also designed to evaluate the rendering performance of the original Java AWT/Swing and CWT. The benchmarking results show that CWT achieves more consistent and higher rendering performance than Java AWT/Swing does in commonly used JRES, including MSVM and JREs 1.4 to 1.6, on the four OSs. Moreover, CWT needs fewer efforts to test the combinations of graphics APIs and system properties, which greatly improves programmers’ productivity. Based on the benchmarking results and our experience, we propose three approaches to make Java be a better platform for developing cross-platform games in the future. First, since the video hardware evolves quickly, Java should open direct access to the internal DirectX and OpenGL objects for game programmers who need to access up-to-date hardware features or change the rendering behaviors. Second, Java should decouple the rendering pipelines of Java AWT/Swing from the JREs for faster upgrading and supporting old JREs. Third, Java should reuse existing DirectX and OpenGL bindings for lower developing cost, better maintainability, easier interoperability among Java AWT/Swing, Java 3D, and JOGL applications.

並列關鍵字

CYC Window Toolkit CWT Java Game DirectX OpenGL

參考文獻


[41] D. Shreiner, M. Woo, J. Neider and T. Davis. OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 1.4, Fourth Edition. Addison-Wesley Professional, November 2003.
[6] A. L. Burrows and D. England. Java 3D, 3D Graphical Environments and Behaviour. Software Practice and Experience, Vol. 32, Issue 4, April 2002; 359–376.
[9] P. C. Chu and J. E. Beasley. A Genetic Algorithm for the Multidimensional Knapsack Problem. Journal of Heuristics, Vol. 4, Number 1, 1998; 63-86.
[10] A. Denault and J. Kienzle, Avoid Common Pitfalls When Programming 2D Graphics in Java: Lessons Learnt from Implementing the Minueto Toolkit. ACM Crossroads, Volume 13 Issue 3, March 2007.
[13] C.-C. Hsu and I.-C. Wu. An Event-driven Framework for Inter-user Communication Applications. Information and Software Technology, Vol.48, July 2006; 471-483.

延伸閱讀