编程与软件工程lethalguitar.wordpress.com
用 C++17 重写一款老 DOS 游戏(2019)
Re-implementing an old DOS game in C++ 17 (2019)
2019 — 2024,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
作者用 C++17 重新实现了经典的 DOS 平台游戏《Duke Nukem》。为了追求还原度,他不仅阅读原版汇编代码,还在 DOSBox 和真实的 386/486 老机器上反复测试,逐帧对比录像来验证每个敌人和游戏机制的实现是否准确。
为什么经久不衰:它展示了逆向工程与软件复刻的完整方法论——从汇编分析到逐帧验证,这种严谨态度和怀旧情怀让它在多年间反复登上首页。
HN 评论精选
赞叹作者逐帧验证的严谨工作量,并感慨软件复刻成果可以被所有人共享
作者在 DOSBox 和从 eBay 买来的各种 386/486 原始硬件上做了大量测试,搭建专门关卡观察特定敌人和机制,用 DOSBox 录像并逐帧验证从汇编代码中得出的结论。实现每个机制后还会录制自己的版本,与原版逐帧对比。这位开发者投入了巨大的工作量!编程的美妙之处在于,你专注投入的成果可以分享给这么多人——就像有人造了超精细的铁路模型却只有去他家地下室才能看到,而软件几乎任何人都能构建、运行、玩上这个被精心复刻的游戏。
RcouF1uZ4gsC查看英文原文
> I also did a lot of testing with the original game, running it in DOSBox and on original hardware (various 386 and 486 machines which I got from eBay). I built test levels for focused observation of specific enemies and game mechanics, recorded video captures of these using DOSBox, and stepped through the recordings frame by frame to verify my findings from reading assembly code. Once I had implemented an enemy or game mechanic, I would also typically record footage from my version, and compare it to the original frame by frame to verify the accuracy of my implementation. The developer put in a tremendous amount of work! The wonderful thing about programming, is how the product of your intense focus can be shared with so many people. There are people who have built super detailed model railroads but you will never see them unless you visit their basement. With software, just about anybody can build/run/play this game that has been so lovingly and painstakingly recreated.
认同重写能让架构设计变得更好
一如既往,架构一个软件的最佳方式,总是在你写完这个软件之后才变得最清晰。我偶尔有机会重写软件,第二次的设计总是好得多。
nu11ptr查看英文原文
> as usual, the best way to architect a piece of software becomes most evident once you’re done writing said piece of software So much, this - I've occasionally gotten the opportunity to rewrite a piece of software and it is always a much better design the 2nd time.
解释为何现代重写版代码量比原版大:正确性、类型安全和现代 API 带来额外开销
务必读一下作者在文后的回复,其中解释了为什么用 C++17 反而代码量不小:现代版需要把数据转换成现代视频/音频 API 可用的格式、保证字节序无关、加入正确性检查以避免未定义行为;原版基本 memcpy 就能上屏,而作者需要 1000 行 OpenGL 代码;不用全局变量意味着更多依赖注入的样板代码;追求类型安全也需要更多代码和数据转换。
plq查看英文原文
Be sure to read author's response(s) to comments below the post. Some insights about why C++17 doesn't help with reducing the size of the codebase: > My version (...) has to convert the data into formats usable by modern video and audio APIs (...) in an endian-independent way, and adds quite a few correctness checks (...) instead of triggering undefined behavior > the original can basically do a memcpy to show something on screen, I need 1000 lines of OpenGL code… > I don’t have global variables, but this in turn means more boilerplate to inject dependencies into objects on construction etc., > I try to be fairly type-safe, which sometimes means needing more code, additional data transformations etc.
怀旧玩家对项目的喜爱
我超爱《Duke Nukem》,后来世界转向 FPS 游戏,我就不再玩游戏了。这个项目看起来真的很酷。
lkxijlewlf查看英文原文
I LOVED Duke Nukem. Then the world went FPS and ... I stopped playing games. This looks like a really cool project.
历次讨论
同类还值得读
开源应用架构
The Architecture of Open Source Applications
《开源软件架构》(AOSA)是一本在线免费书,邀请知名开源项目的作者亲自剖析其内部设计,涵盖 SQLAlchemy、LLVM、Audacity、Apache、Bash 等系统。
编程与软件工程上首页 9 次 · 2011–2024aosabook.org编辑精选编程语言简史:简短、不完整且多半错误
A Brief, Incomplete, and Mostly Wrong History of Programming Languages
一篇以戏谑、故意不准确的方式回顾编程语言史的博客文章,用夸张轶事和讽刺定义串起 Lisp、C、C++、Java、JavaScript、PHP 等语言。
编程与软件工程上首页 8 次 · 2009–2021james-iry.blogspot.comSQLite 是如何测试的
How SQLite is tested
SQLite 官方文档页,系统介绍 SQLite 的测试体系:多种测试方法(TCL 测试、模糊测试、回归测试、静态分析等)和海量测试用例,展示了这个小型开源项目如何靠极致测试获得…
编程与软件工程上首页 8 次 · 2009–2025sqlite.org编辑精选高级编程语言(2009)
Advanced programming languages (2009)
Matt Might 的经典文章,按用途推荐“高级编程语言”:如果追求就业就选主流语言,如果追求表达力、学术研究或创业,则推荐 Haskell、OCaml、Scala 等函数式语…
编程与软件工程上首页 8 次 · 2009–2022matt.might.net我的 Forth 与栈机器经历
Yosefk - My history with Forth & stack machines
作者以亲身经历回顾了使用 Forth 语言和栈式机器的历程:既赞叹其简洁优雅、代码量小、可自举的优点,也坦率指出栈操作在实际编程中的痛苦,以及 Forth 社区文化中的问题。
编程与软件工程上首页 8 次 · 2010–2024yosefk.com编辑精选