用于实时图形编程的 C++ 的最佳替代品是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/72931/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 12:39:19  来源:igfitidea点击:

What's the best alternative to C++ for real-time graphics programming?

c++graphics3dreal-time

提问by Baxissimo

C++ just sucks too much of my time by making me micro-manage my own memory, making me type far too much (hello std::vector<Thingy>::const_iterator it = lotsOfThingys.begin()), and boring me with long compile times. What's the single best alternative for serious real-time graphics programming? Garbage collection is a must (as is the ability to avoid its use when necessary), and speed must be competitive with C++. A reasonable story for accessing C libs is also a must.

C++ 只是让我对自己的内存进行微观管理,让我打字太多(你好std::vector<Thingy>::const_iterator it = lotsOfThingys.begin()),以及冗长的编译时间让我厌烦。严肃的实时图形编程的最佳选择是什么?垃圾收集是必须的(以及在必要时避免使用它的能力),并且速度必须与 C++ 竞争。访问 C 库的合理故事也是必须的。

(Full disclosure: I have my own answer to this, but I'm interested to see what others have found to be good alternatives to C++ for real-time graphics work.)

(完全披露:我对此有自己的答案,但我很想知道其他人发现哪些是 C++ 的实时图形工作的良好替代品。)

Edit:Thanks everyone for the thoughtful replies. Given that there's really no "right" answer to this question I won't be selecting any particular answer. Besides I'd just pick the language I happen to like as a C++ alternative, which wouldn't really be fair.

编辑:感谢大家的深思熟虑的答复。鉴于这个问题确实没有“正确”的答案,我不会选择任何特定的答案。此外,我只是选择我碰巧喜欢的语言作为 C++ 的替代品,这并不公平。

回答by scable

What about D Programming Language?

什么d程序设计语言

Some links requested in the comment:

评论中要求的一些链接:

Win32 Api

Win32 API

Derelict (Multimedia lib)

废弃(多媒体库)

回答by Martin Cote

I wouldn't discard C++. In fact, I would consider adding Boost to your C++ library, which makes the language much more usable. Your example would become:

我不会丢弃 C++。事实上,我会考虑将 Boost 添加到您的 C++ 库中,这使得该语言更加可用。你的例子会变成:

BOOST_FOREACH( Thingy& t, lostOfThingys ) {
    // do something with 't'
}

Boost has tons of tools that help make C++ a better language.

Boost 有大量的工具可以帮助 C++ 成为一种更好的语言。

回答by Drealmer

C# is a nice language that fits your requirements, and it is definitely suited for graphics, thanks to the efforts of Microsoft to provide it with great tools and libraries like Visual Studio and XNA.

C# 是一种很好的语言,可以满足您的要求,而且它绝对适用于图形,这要归功于 Microsoft 努力为其提供出色的工具和库,例如 Visual Studio 和 XNA。

回答by Dima

I disagree with your premise. When used carefully and properly, C++ is a great language, especially for a domain like real-time graphics, where speed is of the essence.

我不同意你的前提。如果小心且正确地使用,C++ 是一种很棒的语言,尤其是对于像实时图形这样的领域,速度至关重要。

Memory management becomes easy if you design your system well, and use stl containers and smart pointers.

如果你设计好你的系统,并使用 stl 容器和智能指针,内存管理就会变得容易。

std::vector::const_iterator it = lotsOfThingys.begin())will become much shorter if you use

std::vector::const_iterator it = lotsOfThingys.begin())如果你使用,会变得更短

using namespace std;
typedef vector::const_iterator ThingyConstIter;

using namespace std;
typedef vector::const_iterator ThingyConstIter;

And you can shorten compile times significantly by breaking up your systems into reasonably self-contained modules, by using precompiled headers, or by using the PIMPL idiom.

您可以通过将系统分解为合理的自包含模块、使用预编译头文件或使用 PIMPL 习语来显着缩短编译时间。

回答by Pieter

Real-time + garbage collection don't match very well I'm afraid.

实时+垃圾收集恐怕不太匹配。

It's a bit hard to make any real-time response guarantees if a garbage collector can kick in at any time and spend an undefined amount of processing...

如果垃圾收集器可以随时启动并花费未定义的处理量,那么做出任何实时响应保证有点困难......

回答by James Hopkin

Perhaps a hybrid approach. Python and C++ make a good combination (see, for example, PyGame).

也许是一种混合方法。Python 和 C++ 是一个很好的组合(例如,参见 PyGame)。

回答by Nathan

Some variation of Lisp that compiles to machine code could be almost as fast as C++ for this kind of programming. The Naughty Dogteam created a version of Lisp called Game Oriented Assembly Lisp, which they used to create several AAA titles, including the Jak and Daxter series. The two major impediments to a Lisp approach in the game industry would be the entrenched nature of C/C++ development (both tools and human assets are heavily invested in C/C++), as well as the difficulty of finding talented engineers who are stars in both the game programming domain and the Lisp language.

对于这种编程,某些编译为机器码的 Lisp 变体几乎与 C++ 一样快。该顽皮狗团队创建Lisp语言的版本,称为以赛大会Lisp的,这是他们用来创建了AAA的冠军,包括Hyman与达斯特系列。在游戏行业采用 Lisp 方法的两个主要障碍是 C/C++ 开发的根深蒂固的性质(工具和人力资产都大量投资于 C/C++),以及难以找到有才华的工程师。游戏编程领域和 Lisp 语言。

Many programming teams in the industry are shifting to a hybrid approach wherein the real-time code, especially graphics and physics code, is written in C or C++, but game logic is done in a higher-level scripting language, which is accessible to and editable by programmers and non-programmers alike. Luaand Pythonare both popular for higher-level scripting.

业内的许多编程团队正在转向混合方法,其中实时代码,尤其是图形和物理代码,是用 C 或 C++ 编写的,但游戏逻辑是用高级脚本语言完成的,这种语言易于访问和使用。程序员和非程序员都可以编辑。LuaPython在高级脚本中都很流行。

回答by MSalters

Let's not forget to mention the new 'auto' use:

我们不要忘记提及新的“自动”用法:

auto it = lotsOfThingys.begin(); // Let the compiler figure it out.
auto it2 = lotsOfFoos.begin();
if (it==it2) // It's still strongly typed; a Thingy iter is not a Foo iter.

回答by MSalters

As a developer/researcher/professor of 3D VR applications for some 20 years I would suggest there is no alternative (except possibly C). The only way to reduce latency and enable real-time interaction is an optimized compiled language (eg C or C++) with access to a fast relaible 3D graphics library such as OpenGL. While I agree it is flustrating to have to code everything, this is also essential for performanc and optimization.

作为 3D VR 应用程序的开发人员/研究人员/教授大约 20 年,我建议别无选择(除了可能的 C)。减少延迟和启用实时交互的唯一方法是优化的编译语言(例如 C 或 C++),可以访问快速可靠的 3D 图形库,例如 OpenGL。虽然我同意必须对所有内容进行编码令人沮丧,但这对于性能和优化也是必不可少的。

回答by DevilDog

Sometimes, looking outside the beaten path you can find a real gem. You might want to consider PureBasic(Don't let the name mislead you). Here's some details:

有时,从人迹罕至的地方向外看,您会发现一颗真正的宝石。您可能需要考虑PureBasic(不要让名称误导您)。以下是一些详细信息:

PureBasic Features

PureBasic 功能

  • Machine Code (Assembly) executables (FASM)
    • In-line Assembly support
    • No run-times needed (no DLLs needed,etc.) 1 executable file
    • Tiny executables (as small or smaller/as fast or faster than C++ w/out the runtime)
    • You can write DLLs
    • Multi-thread support
    • Full OS API support
  • Multi-platform support
    • Windows 95-2003
    • Linux
    • Mac-OS X
    • Amiga
  • 2D & 3D game development
    • DirectX
    • OGRE
  • Generous Licensing
    • Inexpensive (79 Euros or about $112)
    • Life-time license (all future updates & versions included)
    • One price for all platforms
  • External Library support
    • 3rd party DLLs
    • User Libraries
  • On-line Support
    • Responsive development team led by it's creator
    • On-line forum
      • One place for answers (don't have to go all over the net)
      • Huge amount of sample code (try code out while in IE with IEtool)
      • Fast replies to questions
  • Bonus learning (alternative to learning C++)
    • API
    • Structures
    • Interfaces
    • Pointers
  • 机器代码(汇编)可执行文件 (FASM)
    • 在线组装支持
    • 不需要运行时(不需要 DLL 等) 1 个可执行文件
    • 微小的可执行文件(与没有运行时的 C++ 一样小或小/一样快或快)
    • 你可以写DLL
    • 多线程支持
    • 完整的操作系统 API 支持
  • 多平台支持
    • 视窗 95-2003
    • Linux
    • Mac-OS X
    • 阿米加
  • 2D 和 3D 游戏开发
    • DirectX
    • 食人魔
  • 慷慨的许可
    • 便宜(79 欧元或约 112 美元)
    • 终身许可证(包括所有未来的更新和版本)
    • 一价全平台
  • 外部库支持
    • 第 3 方 DLL
    • 用户库
  • 在线支持
    • 由其创建者领导的响应式开发团队
    • 在线论坛
      • 一处解答(不必走遍全网)
      • 大量示例代码(在 IE 中使用 IEtool 尝试代码)
      • 快速回复问题
  • 奖励学习(替代学习 C++)
    • 应用程序接口
    • 结构
    • 接口
    • 指针

Visit the online forum to get a better idea of PureBasic (http://www.purebasic.fr/english/index.php) or the main site: www.purebasic.com

访问在线论坛以更好地了解 PureBasic ( http://www.purebasic.fr/english/index.php) 或主站点:www.purebasic.com