How do companies like Valve manage to release games to all three major gaming platforms? I am interested in the best-practices regarding code sharing specifically between Windows, Xbox360 and PS3, since the ideal solution is to reuse as much code as possible instead of rewriting the whole thing for every platform.
像Valve这样的公司如何设法向所有三个主要游戏平台发布游戏?我对Windows,Xbox360和PS3之间的代码共享的最佳实践感兴趣,因为理想的解决方案是尽可能多地重用代码而不是为每个平台重写整个代码。
7 个解决方案
#1
It's not any different than writing platform-independent code in other contexts. Hide platform-specific details (input, window interaction, the main event loop, threading, etc) behind generic interfaces, and test regularly on all the platforms you intend to support.
与在其他环境中编写与平台无关的代码没有任何不同。隐藏通用接口背后的特定于平台的详细信息(输入,窗口交互,主事件循环,线程等),并定期测试您打算支持的所有平台。
Note that the Cell's threading model is unusual enough that doing threading "generically" takes some care. I am not a Valve employee and I know none of their secrets, but it's my understanding that most game developers who want to target the PS3 use a job queue that the individual cell processors grab tasks off of as needed. This isn't necessarily the best way to use the Cell, but it generalizes nicely to more conventional threading models (like, frex, the one that thet PC and the 360 both use).
请注意,Cell的线程模型非常不寻常,以至于“一般”执行线程需要注意。我不是Valve的员工,我不知道他们的秘密,但我的理解是,大多数想要以PS3为目标的游戏开发人员使用一个工作队列,个别单元处理器根据需要抓取任务。这不一定是使用Cell的最佳方式,但它很好地概括为更传统的线程模型(例如,frex,PC和360都使用的那种)。
#2
There's a bunch of Game Developer Magazine articles and GDC talks on the subject. In fact, since you mentioned Valve, they delivered a talk describing their approach at GDC08.
有很多关于这个主题的游戏开发者杂志文章和GDC讲座。事实上,自从你提到Valve之后,他们发表了一篇讲话,描述了他们在GDC08上的方法。
This is really a huge subject that I could (and have) talk about for hours upon hours, but elevator summary is:
这真是一个巨大的主题,我可以(并且有)谈论几个小时,但电梯摘要是:
- Determine which parts of the engine are completely platform-specific and put them behind an abstraction. File and asset loading, for example, need to be rewritten for each console; but you can hide that behind an IFileSystem interface which provides a uniform API that the game code talks to.
- The PS3 makes this hard because its abstraction point has to be someplace completely different from the other platforms. Even game features like collision and nav will have to be written differently for the Cell.
- Try to keep leaf game code (entities, AI, sim) as platform-agnostic as possible...
- But accept that even the leafiest of game code will sometimes need some platform-specific #ifdefs for perf or memory or TCR reasons. A lot of UI will have to be rewritten because the manufacturers have conflicting certification requirements.
- Anyone who says the words "I'm not worried about performance" or "memory isn't an issue" shouldn't be on the payroll.
确定引擎的哪些部分完全是特定于平台的,并将它们放在抽象之后。例如,需要为每个控制台重写文件和资产加载;但是你可以隐藏在IFileSystem接口后面,它提供游戏代码与之对话的统一API。
PS3使得这很难,因为它的抽象点必须与其他平台完全不同。甚至像碰撞和导航这样的游戏功能也必须以不同的方式为Cell编写。
尝试将叶子游戏代码(实体,AI,sim)尽可能地与平台无关......
但是接受即使是最叶的游戏代码有时也需要一些特定于平台的#ifdef用于性能或内存或TCR原因。由于制造商的认证要求存在冲突,因此必须重写大量UI。
任何说“我不担心表现”或“记忆不是问题”的人都不应该在工资单上。
#3
This question can be divided up into two separate questions. "How can I write portable code?" and "What are the divergent requirements of mainstream gaming platforms?".
这个问题可以分为两个单独的问题。 “我怎么写可移植代码?”和“主流游戏平台有哪些不同的要求?”。
The first question is relatively easy to answer. Best practices for abstracting your non-portable code are covered in Write Portable Code: http://books.google.ca/books?id=4VOKcEAPPO0C&printsec=frontcover
第一个问题相对容易回答。 Write Portable Code中包含了抽象非可移植代码的最佳做法:http://books.google.ca/books?id = 4VOKcEAPPO0C&printsec = frontcover
Turning theory into practice, the Quake 3 source code does a pretty good job of dividing out different platforms into separate areas for a C codebase, available at http://www.idsoftware.com/business/techdownloads/ However, it does not demonstrate C++ patterns such as abstract interfaces, implemented once per platform.
将理论付诸实践,Quake 3源代码可以很好地将不同的平台划分为C代码库的不同区域,可从http://www.idsoftware.com/business/techdownloads/获得。但是,它没有演示C ++模式,如抽象接口,每个平台实现一次。
The second part of your question, "What are the divergent requirements of mainstream gaming platforms?" is tougher. However, it is notable that your largest areas of change are still your renderer, your audio subsystem and your networking.
问题的第二部分,“主流游戏平台的不同要求是什么?”更加强硬。但是,值得注意的是,您最大的变化领域仍然是渲染器,音频子系统和网络。
Each console platform has a series of certification requirements, available under an agreement with the respective console owners. The requirements drive consistency in user experience and are not focused on gameplay or qualitative, high level issues. For instance, your game may need to display a reasonably interesting animating loading screen, and black screens are unacceptable.
每个控制台平台都有一系列认证要求,可根据与各自控制台所有者的协议提供。这些要求推动了用户体验的一致性,并没有关注游戏玩法或定性的高级问题。例如,您的游戏可能需要显示一个相当有趣的动画加载屏幕,并且黑屏是不可接受的。
Getting your hands on this documentation as soon as possible is key to making the right choices in developing for a specific console platform.
尽快掌握本文档对于在特定控制台平台的开发中做出正确选择至关重要。
Finally, if you can't get your hands on a console devkit, I suggest you port your code to the Mac from Windows. The Mac gets you an OS port ensuring you are not tied to Windows as well as a processor port if you support universal binaries. This ensures your code is endian agnostic.
最后,如果您无法使用控制台devkit,我建议您将代码从Windows移植到Mac。如果您支持通用二进制文件,Mac会为您提供一个操作系统端口,以确保您不依赖于Windows以及处理器端口。这可确保您的代码与endian无关。
If you support both PC and Mac, you will be well positioned to support a third platform, should you gain access to it in the future.
如果您同时支持PC和Mac,那么如果您将来可以访问它,您将能够很好地支持第三个平台。
Addendum You wrote:
附录你写道:
the ideal solution is to reuse as much code as possible instead of rewriting the whole thing for every platform
理想的解决方案是尽可能多地重用代码,而不是为每个平台重写整个代码
In many game porting scenarios, the ideal solution is not to reuse as much code as possible, but to write the optimal code for each platform. Code can be reused between projects and is relatively inexpensive as compared to the content that the engine takes in. A more reasonable goal is to aim for lowest common denominator content that runs on all platforms without modification (a build phase that packs the content for media is okay).
在许多游戏移植场景中,理想的解决方案不是尽可能多地重用代码,而是为每个平台编写最佳代码。代码可以在项目之间重用,并且与引擎引入的内容相比相对便宜。更合理的目标是针对在所有平台上运行而无需修改的最低公分母内容(包含媒体内容的构建阶段)没关系)。
#4
It's great to do simultaneous development. You find all kinds of bugs you wouldn't find doing just one platform.
同时开发很棒。你会发现你在一个平台上找不到的各种错误。
I remember that programmers in DOS had null pointers all the time because writing to low memory didn't immediately crash them. When you ported to an Amiga, Atari ST, or Macintosh, boom! I remember telling a DOS programmer that he had a couple null pointers on an aready-shipped game. He thought for a couple seconds and grinned, "That explains a few things."
我记得DOS中的程序员一直都有空指针,因为写入低内存并没有立即崩溃。当您移植到Amiga,Atari ST或Macintosh时,繁荣!我记得告诉过一个DOS程序员,他在一个正在运送的游戏中有几个空指针。他想了几秒钟,露齿而笑,“这解释了一些事情。”
Now that games have such large budgets, it's important to ship them all at the same time so you don't waste marketing and ad budgets.
既然游戏预算如此庞大,那么同时发送它们非常重要,这样您就不会浪费营销和广告预算。
My advice on simultaneous development is to pick one lead platform, but never let the other platform(s) get more than a week behind. It will become obvious as you program which parts of the code are common to all platforms and which are different. Pull out the differences into one or more platform-specific areas.
我对同步开发的建议是选择一个主导平台,但绝不让其他平台落后一周以上。当您编写代码的哪些部分对所有平台都是通用的并且哪些不同时,这将变得很明显。将差异拉出到一个或多个平台特定区域。
My experience is in C/C++. It's a bigger problem if you have to port against different languages (say, Java and Objective-c).
我的经验是用C / C ++。如果你不得不针对不同的语言(比如Java和Objective-c)进行移植,这是一个更大的问题。
#5
A few years ago the Opera CEO said in an interview that the key to developing for independent platforms is to move away from any single OS/platform libraries. He went on and said that they developed their own libraries that improve OS performance.
几年前,Opera首席执行官在接受采访时表示,开发独立平台的关键是摆脱任何单一的操作系统/平台库。他接着说,他们开发了自己的库来提高操作系统的性能。
My assumption is that big companies will have a common, Xbox, PS, windows, FooOS, separate teams. Each platform needs to be tweaked differently and requires different implementation methods. I don't think they do one source for all platforms; rather, they build one for each OS thereby, improving efficiencies. I remember EA used to release some console games earlier than the PC versions and vice versa.
我的假设是,大公司将有一个共同的,Xbox,PS,Windows,FooOS,独立的团队。每个平台需要以不同方式进行调整,并且需要不同的实现方法。我不认为他们为所有平台做过一个来源;相反,他们为每个操作系统构建一个,从而提高效率。我记得EA曾经比PC版早发布一些主机游戏,反之亦然。
Another issue is that different consoles have different hardware thus requiring different programming techniques.
另一个问题是不同的控制台具有不同的硬件,因此需要不同的编程技术。
there are two extremes, build one source that fits all (java for instance) but you run the risk of inefficiency or write 40 versions; one optimized for each platform
有两个极端,构建一个适合所有的源(例如java),但你冒低效率的风险或写40个版本;为每个平台优化的一个
#6
Back when I had a friend into educational computer games (before The Learning Company gutted the field), he was a great fan of creating cross-platform libraries for doing everything.
当我有一个朋友参加教育电脑游戏时(在学习公司扼杀了这个领域之前),他非常喜欢创建跨平台库来做所有事情。
This is easier for games than other apps. If you have a word processing app to run on the Mac and Windows, for example, it really does need to look and behave like a Mac app on the Mac, and a Windows app on Windows. Write a game, and it doesn't have to conform to the native behavior, look, and feel.
这比其他应用程序更容易游戏。例如,如果您有在Mac和Windows上运行的文字处理应用程序,它确实需要在Mac上看起来和行为类似于Mac应用程序,在Windows上看起来像Windows应用程序。写一个游戏,它不必符合本机行为,外观和感觉。
#7
If you want open source examples, you could look at source code of Quake 1, 2 and 3 engines. They are structured quite portably. (Of course, no ps3 or xbox360 support, but same principles apply)
如果您想要开源示例,您可以查看Quake 1,2和3引擎的源代码。它们结构相当便宜。 (当然,没有ps3或xbox360支持,但同样的原则适用)
#1
It's not any different than writing platform-independent code in other contexts. Hide platform-specific details (input, window interaction, the main event loop, threading, etc) behind generic interfaces, and test regularly on all the platforms you intend to support.
与在其他环境中编写与平台无关的代码没有任何不同。隐藏通用接口背后的特定于平台的详细信息(输入,窗口交互,主事件循环,线程等),并定期测试您打算支持的所有平台。
Note that the Cell's threading model is unusual enough that doing threading "generically" takes some care. I am not a Valve employee and I know none of their secrets, but it's my understanding that most game developers who want to target the PS3 use a job queue that the individual cell processors grab tasks off of as needed. This isn't necessarily the best way to use the Cell, but it generalizes nicely to more conventional threading models (like, frex, the one that thet PC and the 360 both use).
请注意,Cell的线程模型非常不寻常,以至于“一般”执行线程需要注意。我不是Valve的员工,我不知道他们的秘密,但我的理解是,大多数想要以PS3为目标的游戏开发人员使用一个工作队列,个别单元处理器根据需要抓取任务。这不一定是使用Cell的最佳方式,但它很好地概括为更传统的线程模型(例如,frex,PC和360都使用的那种)。
#2
There's a bunch of Game Developer Magazine articles and GDC talks on the subject. In fact, since you mentioned Valve, they delivered a talk describing their approach at GDC08.
有很多关于这个主题的游戏开发者杂志文章和GDC讲座。事实上,自从你提到Valve之后,他们发表了一篇讲话,描述了他们在GDC08上的方法。
This is really a huge subject that I could (and have) talk about for hours upon hours, but elevator summary is:
这真是一个巨大的主题,我可以(并且有)谈论几个小时,但电梯摘要是:
- Determine which parts of the engine are completely platform-specific and put them behind an abstraction. File and asset loading, for example, need to be rewritten for each console; but you can hide that behind an IFileSystem interface which provides a uniform API that the game code talks to.
- The PS3 makes this hard because its abstraction point has to be someplace completely different from the other platforms. Even game features like collision and nav will have to be written differently for the Cell.
- Try to keep leaf game code (entities, AI, sim) as platform-agnostic as possible...
- But accept that even the leafiest of game code will sometimes need some platform-specific #ifdefs for perf or memory or TCR reasons. A lot of UI will have to be rewritten because the manufacturers have conflicting certification requirements.
- Anyone who says the words "I'm not worried about performance" or "memory isn't an issue" shouldn't be on the payroll.
确定引擎的哪些部分完全是特定于平台的,并将它们放在抽象之后。例如,需要为每个控制台重写文件和资产加载;但是你可以隐藏在IFileSystem接口后面,它提供游戏代码与之对话的统一API。
PS3使得这很难,因为它的抽象点必须与其他平台完全不同。甚至像碰撞和导航这样的游戏功能也必须以不同的方式为Cell编写。
尝试将叶子游戏代码(实体,AI,sim)尽可能地与平台无关......
但是接受即使是最叶的游戏代码有时也需要一些特定于平台的#ifdef用于性能或内存或TCR原因。由于制造商的认证要求存在冲突,因此必须重写大量UI。
任何说“我不担心表现”或“记忆不是问题”的人都不应该在工资单上。
#3
This question can be divided up into two separate questions. "How can I write portable code?" and "What are the divergent requirements of mainstream gaming platforms?".
这个问题可以分为两个单独的问题。 “我怎么写可移植代码?”和“主流游戏平台有哪些不同的要求?”。
The first question is relatively easy to answer. Best practices for abstracting your non-portable code are covered in Write Portable Code: http://books.google.ca/books?id=4VOKcEAPPO0C&printsec=frontcover
第一个问题相对容易回答。 Write Portable Code中包含了抽象非可移植代码的最佳做法:http://books.google.ca/books?id = 4VOKcEAPPO0C&printsec = frontcover
Turning theory into practice, the Quake 3 source code does a pretty good job of dividing out different platforms into separate areas for a C codebase, available at http://www.idsoftware.com/business/techdownloads/ However, it does not demonstrate C++ patterns such as abstract interfaces, implemented once per platform.
将理论付诸实践,Quake 3源代码可以很好地将不同的平台划分为C代码库的不同区域,可从http://www.idsoftware.com/business/techdownloads/获得。但是,它没有演示C ++模式,如抽象接口,每个平台实现一次。
The second part of your question, "What are the divergent requirements of mainstream gaming platforms?" is tougher. However, it is notable that your largest areas of change are still your renderer, your audio subsystem and your networking.
问题的第二部分,“主流游戏平台的不同要求是什么?”更加强硬。但是,值得注意的是,您最大的变化领域仍然是渲染器,音频子系统和网络。
Each console platform has a series of certification requirements, available under an agreement with the respective console owners. The requirements drive consistency in user experience and are not focused on gameplay or qualitative, high level issues. For instance, your game may need to display a reasonably interesting animating loading screen, and black screens are unacceptable.
每个控制台平台都有一系列认证要求,可根据与各自控制台所有者的协议提供。这些要求推动了用户体验的一致性,并没有关注游戏玩法或定性的高级问题。例如,您的游戏可能需要显示一个相当有趣的动画加载屏幕,并且黑屏是不可接受的。
Getting your hands on this documentation as soon as possible is key to making the right choices in developing for a specific console platform.
尽快掌握本文档对于在特定控制台平台的开发中做出正确选择至关重要。
Finally, if you can't get your hands on a console devkit, I suggest you port your code to the Mac from Windows. The Mac gets you an OS port ensuring you are not tied to Windows as well as a processor port if you support universal binaries. This ensures your code is endian agnostic.
最后,如果您无法使用控制台devkit,我建议您将代码从Windows移植到Mac。如果您支持通用二进制文件,Mac会为您提供一个操作系统端口,以确保您不依赖于Windows以及处理器端口。这可确保您的代码与endian无关。
If you support both PC and Mac, you will be well positioned to support a third platform, should you gain access to it in the future.
如果您同时支持PC和Mac,那么如果您将来可以访问它,您将能够很好地支持第三个平台。
Addendum You wrote:
附录你写道:
the ideal solution is to reuse as much code as possible instead of rewriting the whole thing for every platform
理想的解决方案是尽可能多地重用代码,而不是为每个平台重写整个代码
In many game porting scenarios, the ideal solution is not to reuse as much code as possible, but to write the optimal code for each platform. Code can be reused between projects and is relatively inexpensive as compared to the content that the engine takes in. A more reasonable goal is to aim for lowest common denominator content that runs on all platforms without modification (a build phase that packs the content for media is okay).
在许多游戏移植场景中,理想的解决方案不是尽可能多地重用代码,而是为每个平台编写最佳代码。代码可以在项目之间重用,并且与引擎引入的内容相比相对便宜。更合理的目标是针对在所有平台上运行而无需修改的最低公分母内容(包含媒体内容的构建阶段)没关系)。
#4
It's great to do simultaneous development. You find all kinds of bugs you wouldn't find doing just one platform.
同时开发很棒。你会发现你在一个平台上找不到的各种错误。
I remember that programmers in DOS had null pointers all the time because writing to low memory didn't immediately crash them. When you ported to an Amiga, Atari ST, or Macintosh, boom! I remember telling a DOS programmer that he had a couple null pointers on an aready-shipped game. He thought for a couple seconds and grinned, "That explains a few things."
我记得DOS中的程序员一直都有空指针,因为写入低内存并没有立即崩溃。当您移植到Amiga,Atari ST或Macintosh时,繁荣!我记得告诉过一个DOS程序员,他在一个正在运送的游戏中有几个空指针。他想了几秒钟,露齿而笑,“这解释了一些事情。”
Now that games have such large budgets, it's important to ship them all at the same time so you don't waste marketing and ad budgets.
既然游戏预算如此庞大,那么同时发送它们非常重要,这样您就不会浪费营销和广告预算。
My advice on simultaneous development is to pick one lead platform, but never let the other platform(s) get more than a week behind. It will become obvious as you program which parts of the code are common to all platforms and which are different. Pull out the differences into one or more platform-specific areas.
我对同步开发的建议是选择一个主导平台,但绝不让其他平台落后一周以上。当您编写代码的哪些部分对所有平台都是通用的并且哪些不同时,这将变得很明显。将差异拉出到一个或多个平台特定区域。
My experience is in C/C++. It's a bigger problem if you have to port against different languages (say, Java and Objective-c).
我的经验是用C / C ++。如果你不得不针对不同的语言(比如Java和Objective-c)进行移植,这是一个更大的问题。
#5
A few years ago the Opera CEO said in an interview that the key to developing for independent platforms is to move away from any single OS/platform libraries. He went on and said that they developed their own libraries that improve OS performance.
几年前,Opera首席执行官在接受采访时表示,开发独立平台的关键是摆脱任何单一的操作系统/平台库。他接着说,他们开发了自己的库来提高操作系统的性能。
My assumption is that big companies will have a common, Xbox, PS, windows, FooOS, separate teams. Each platform needs to be tweaked differently and requires different implementation methods. I don't think they do one source for all platforms; rather, they build one for each OS thereby, improving efficiencies. I remember EA used to release some console games earlier than the PC versions and vice versa.
我的假设是,大公司将有一个共同的,Xbox,PS,Windows,FooOS,独立的团队。每个平台需要以不同方式进行调整,并且需要不同的实现方法。我不认为他们为所有平台做过一个来源;相反,他们为每个操作系统构建一个,从而提高效率。我记得EA曾经比PC版早发布一些主机游戏,反之亦然。
Another issue is that different consoles have different hardware thus requiring different programming techniques.
另一个问题是不同的控制台具有不同的硬件,因此需要不同的编程技术。
there are two extremes, build one source that fits all (java for instance) but you run the risk of inefficiency or write 40 versions; one optimized for each platform
有两个极端,构建一个适合所有的源(例如java),但你冒低效率的风险或写40个版本;为每个平台优化的一个
#6
Back when I had a friend into educational computer games (before The Learning Company gutted the field), he was a great fan of creating cross-platform libraries for doing everything.
当我有一个朋友参加教育电脑游戏时(在学习公司扼杀了这个领域之前),他非常喜欢创建跨平台库来做所有事情。
This is easier for games than other apps. If you have a word processing app to run on the Mac and Windows, for example, it really does need to look and behave like a Mac app on the Mac, and a Windows app on Windows. Write a game, and it doesn't have to conform to the native behavior, look, and feel.
这比其他应用程序更容易游戏。例如,如果您有在Mac和Windows上运行的文字处理应用程序,它确实需要在Mac上看起来和行为类似于Mac应用程序,在Windows上看起来像Windows应用程序。写一个游戏,它不必符合本机行为,外观和感觉。
#7
If you want open source examples, you could look at source code of Quake 1, 2 and 3 engines. They are structured quite portably. (Of course, no ps3 or xbox360 support, but same principles apply)
如果您想要开源示例,您可以查看Quake 1,2和3引擎的源代码。它们结构相当便宜。 (当然,没有ps3或xbox360支持,但同样的原则适用)