【Java】Minecraft这款游戏为何是用Java语言写的?

【Java】Minecraft这款游戏为何是用Java语言写的?

引用:
XD=

10-3:翻到一篇JAVA制作游戏入门教程的博文;JAVA制作游戏入门教程
———————————————————————————————————————————————

如我们所见,如果想玩Minecraft我们必须得安装有java,而且运行的时候Minecraft在任务管理器的进程名称是“javaw.exe”,而且Minecraft有内存占用的设置,因为java本身也可能有内存使用的限制——是的,Minecraft是用java语言编写的


除了外带的启动器是exe的,游戏本体根本没有exe的程序,大多数文件格式是jar和json,音乐/音效使用的ogg格式,还有些自定义后缀名的文件如语言文件(基本都是用txt就可以打开XD)


这显然和大多数游戏不同、这也引发了不少玩家和程序猿的兴♂趣


某国外论坛有疑问如下(访问原帖点此
Why java?
Most of us all know minecraft runs on java, but why? They aren't many other games that run/support java at all. That's why the aspect of minecraft is so limited. They're are only so much you can do with Javascript. Please, take a look at other popular games and tell me they run through java, most of them do not. I'm not sure if this would be possible, but minecraft should switch to another program. But like I said, minecraft was developed in java, so that may not be possible.
Tell me what your guys thoughts are.



【我默认你英语过四级了XD】

下面有诸多回复
当然首先是指出提问者的一个错误:Java和JavaScript是两码事(一看提问的就不是程序猿XD)

6L和7L给出了详实的回复
  • 6L
引用:
Permalink
by insomniac_lemon » 8/14/2013
Java =/= Javascript.

Minecraft was started and is still being developed in Java.

There's also no real reason to re-write/port the PC version of Minecraft to another language, because any "speed issues" are there because of poorly-written and un-optimized code (one of the reasons performance changes dramatically even between post-release versions), using another language would not help much, if at all (in fact, might be worse if Mojang tries developing for a language they are inexperienced with).

Not only that: Minecraft is cross platform. It works on any desktop OS that can run Java, and without much need for more effort besides OS-specific issues (mostly with OS X from what I've seen). It would be hard to replicate this in a language that is fast, not to mention most people even recommending not using Java would say just to develop it in C, which would result in Mojang either only supporting Windows, using some crappy port, or needing to make specific clients for each OS. Maybe they could use GIT somehow, but I still doubt it would be better than now.


Anyways: there's no real reason, Minecraft just needs more work and speeding up, it's not Java's fault. Java is better than it once was and is still getting better. Switching languages at this point does not make sense at all, would take more work than fixing Minecraft now, and is a whole other project in itself. If you want it in another language, try MC:PE or MC360 instead (hint: they're pretty much in "beta" mode like what the PC version had).


——哦这个签名XD
  • 7L
引用:
Permalink
by xer0 » 8/14/2013
Okay, you seem a bit misguided about these technologies, let's see if I can bring you up-to-speed in a clear and concise manner.
Java is an interpreted (meaning it's converted to machine language as it's being used, not prior, like other languages such as C/C++) programming language that runs off of a virtual machine. This makes Java inherently slower than the other languages, for reasons you'll come to understand later on in this reply. The Java Virtual Machine (JVM) is (simply put) a piece of software that converts Java code to native machine code, and executes it. This allows Java to run on all the platforms that support the machine's architecture (currently 6+ BILLION devices are compatible with the JVM.) This means that if I write an Java application on my Windows computer, I can run it on my Linux computer, and even my Macintosh, whenever I wish, without editing the code base. If i used C/C++ or any other native language (must be compiled for each device architecture that I wish to run it on), then I'd have to write a Windows version that supports Windows GUI APi's (Application Programming Interface), then I'd have to write a version for Macintosh that supports its GUI API, (The Cocoa framework) and then I'd have to write another version for Linux/Unix systems that support THEIR GUI APi's (Qt and GTK). All this could take weeks, and if Notch had written Minecraft this way, it could takes weeks or months just to get the Mac version of 1.6.2 after it was released for Windows.

Next up, Java and JavaScript are NOT the same language.
Java is a byte-code interpreted language running on a virtual machine
JavaSCRIPT is a client-side scripting language for the World Wide Web (and more recently, Windows 8 Apps, and some other platforms, as well.)

Lastly, Notch wrote Minecraft in Java because he is very familiar with the language. He had no idea that the game would end up generating millions in revenue,while gathering a cult-following, and becoming the most successful Indie game ever developed. And besides, even if he did, he would still have chosen Java for it's ease-of-use, portability, and the fact that with current processing power, only the really low-end machines would even have a problem with performance.

问题与回复中文梗概(楼主X有道)(我设了回复可见XD)
本帖隐藏的内容需要回复才可以浏览


大伙来一起讨论交♂流一下吧!

[ 本帖最后由 jmswzyk 于 2014-10-3 21:42 编辑 ]
说出你的故事吧      |   欢迎站短
                                  |
我想我很适合          |   或是邮箱
做一个聆听者          |   ncxxzyk@sina.com
我会望着你的双眼  |                                             
记住你明眸              |    更欢迎。。
和明眸里那              |   你请我吃点好的
浅浅的泪                  |  而我就静静地咬着苹果听 在 春·日光 里  |  冬未了 的 秋:故事  和期盼的  夏/狂热

TOP

B站脑残粉,最近几个月这个游戏好火的说(一直也很火的)。看了一些生存模式的视频。不过大型工程好厉害的样子(开创造的神之模式)。好期待会建成什么样子哦。总是虽不明但觉厉,前排支持!

TOP

好高端。。

TOP

= =、、、

TOP

身为准程序猿表示看到标题就进来了。。

TOP

表示路过

TOP

这两天MC刷屏了?!

TOP

先留名再说!
找不到对象吗? new 一个吧!

TOP

同意6L的观点,个人认为MC的运行时并不需要大量的运算。大多数时候,算法效率的重要性远远大于语言本身。只有当对效率的要求非常苛刻的时候,语言的优势才能体现出来,例如操作系统和大型游戏。而在很多大型游戏中,渲染仍然是由脚本完成的。
本帖最近评分记录
  • jmswzyk 蛋蛋币 +1 要不是我只能加一分XD 2014-10-3 21:00

TOP

当然,因节约成本而转投java,最终惨败的大型软件很多。

TOP

最近Minecraft是越来越火了。。

TOP

回复 10楼 的帖子

@senr 表示那个楼层里有人说:java是很好的游戏编程语言,我表示我不是程序猿并不理解其中的区别。。
就我现在读到的看来,java的一个最大优点是跨平台非常方便,用C语言开发到基本只能供给windows,而java就可以轻松的有MAC和LINUX版,我不知道和java关系如何,这个游戏现在还有树莓派版。。而且树莓派版是开源的,事实上如果你搜到一个MCPC的插件,它可以帮你反编译游戏的部分文件到可编辑的地步,用来方便大家MOD的开发

我不太清楚这个游戏的渲染是怎么做的,但是最近的1.8更新据说做了大幅的优化,在各种层面上,我也发现之前只能20-30+帧跑的画面设置,现在可以稳稳达到60帧

另外就我了解到的游戏运行机制,有这么几个特点
1.以16X16X256(水平的X,Z和高度Y)为一个区块,作为基础处理单位,只有周围16区块会被挂载到内存中,更远的区块会被卸载,储存在硬盘里。
2.玩家可以选择可见度,单位是区块,大小是2-16(64位1.8变成了2-32),影响渲染的区块数量,这个选项可以大幅影响性能,可见度为2的时候在大多数电脑上都会保持流畅,而可见度为16则需要强劲的显卡——至少我的HD3000根本跑不动16chunks下的最低配置,如果实体(Entity)多一些则会真的卡出翔
引用:
Minecraft的渲染器将一个区块分为8个16x16x16的渲染区块,并编译到OpenGL显示名单里用于加快渲染速率。任意一个渲染区块内的方块发生变动的话,渲染区块均需要重建。
——1.8的一个更新似乎是把视野不可见的地下部分变为部分渲染而非完全渲染,这对游戏体验没有多少影响但却对性能提升有了很大帮助

区块的介绍可以见wiki:区块——http://minecraft-zh.gamepedia.com/%E5%8C%BA%E5%9D%97

3.处理对象分为实体、物体和方块,拥有不同的属性标签
使用的文件格式也在变化,从最初的Region变成了ANVIL文件,使用NBT结构存储数据
(完全不懂是什么,只知道ANVIL文件是方便的玩家间传播建筑、红石装置的文件,里面可以只包含相应的建筑方块而不包括地形)
(同时这些数据格式就是使用指令召唤生物/物品时可修改的数据)
引用下wiki区块格式页面开头
引用:
区块(Chunks)以16*256*16立方块为单位存储地形和实体信息。为了提高Minecraft的运行效率,区块同时储存预处理的光照、等高线数据及其他元数据信息。
“区块”概念在Minecraft Infdev阶段时首次引进。 在Beta 1.3版本引进MCRegion之前, Minecraft以36进制编码的区块坐标为文件名,将区块信息储存在独立的“.dat”文件中(Alpha level format)。为了减少磁盘占用,MCRegion将地平面上32*32平方块内的所有区块打包存储在以十进制编码的区块坐标为文件名的“.mcr”文件中;这种存储方式降低了Minecraft运行时同时打开的文件数量。MCRegion后来被当下的Anvil文件格式取代,新格式沿用了MCRegion打包存储的方法,并使用了新的“.mca”文件格式。
Anvil文件格式相比MCRegion最大的改进是将区块分割,一个16*256*16大小的区块最多能分割出16个16*16*16的部分,所以全空区域的数据可以不被保存。支持的方块ID也从以前的0到255调整为0到4095,不过现在(2012年11月22日时)Minecraft还不能完美实现ID从0到4095的所有方块的存储,且256到4095的这些方块ID有很多已经被物品占用。
现在(2012年11月22日时),方块的辅助信息独立地被保存在区块信息内,特别的,天空光照(SkyLight)和(BlockLight)两个数组信息不在挂在方块ID后。Anvil文件格式出现后, 开发组在Notch原先设想的基础上对NBT格式(二进制命名标签格式)做出了改变,添加了一个和字节数组标签(byte array tag)相近的整数数组标签(integer array tag)——只有区块的等高线信息使用NBT格式存储。
区块格式页面见wiki:区块格式——http://minecraft-zh.gamepedia.co ... 7%E6%A0%BC%E5%BC%8F

总之这款游戏之所以用java编写主要是因为Notch一开始只是在写一个小游戏,那时候还可以在网页上玩,最初也只有不到百MB,即使现在,去掉音乐和其他语言文件,这款游戏还是小的可以
——但他没想到这游戏火了
说出你的故事吧      |   欢迎站短
                                  |
我想我很适合          |   或是邮箱
做一个聆听者          |   ncxxzyk@sina.com
我会望着你的双眼  |                                             
记住你明眸              |    更欢迎。。
和明眸里那              |   你请我吃点好的
浅浅的泪                  |  而我就静静地咬着苹果听 在 春·日光 里  |  冬未了 的 秋:故事  和期盼的  夏/狂热

TOP

过来看看

TOP

哦哦!看起来很厉害的样子!!

恩,回复回复

TOP