欢迎光临散文网 会员登陆 & 注册

13-对part11-breakout-smp的翻译和搬运

2023-08-18 20:28 作者:Xdz-2333  | 我要投稿

非黑色字体均为我自己添加

原文放在文章末尾

把它们结合在一起

        坦率地讲,我不打算在这个部分写很多文档.我现在只提供一个Clang的Makefile.如果你使用gcc,可以参考之前的部分把Makefile合并起来.

        这个部分只是在我们之前的基础上建立起来的,并且提供了一个新的代码库:

  • 游戏前端运行在CPU0上

  • 图形更新在CPU1上

  • 循环8-bit背景音乐,在CPU2上

  • 蓝牙通信,在CPU3上

        我利用这个机会把代码组织的更好一些,所以你可以看到Makefile中间的一些变动,以及一个新的目录结构.整洁的代码库=整洁的思想!

重要的结论

        你也许会注意到一种非常不同的风格已经出现了.多核处理器增加了代码的复杂性,并且需要完全地转变思维方式.

        这里有许多的信号/信号量,所以内核可以确定它们在正确的时间做正确的事情.

        你不再需要"干跑",一个单独的顺序的线程.您必须从四个并发线程的相互作用中发现潜在的错误/意外行为!

        祝你探索代码的时候好运!

进展视频

        点击观看比赛的快速视频.

        这个视频链接如下:

        https://user-images.githubusercontent.com/68182575/173157526-2b22f9b2-0f55-42a0-87e1-b8278930fefe.mp4

PS:抱歉质量不好 -- 但实际生活中游戏音频听起来很棒,我保证!

原文如下:

Putting it all together

Frankly, I'm unlikely to write much documentation for this part. I'm also only providing a Clang _Makefile_ for now. If you're using gcc, have a go at putting your own _Makefile_ together, referencing the previous parts.


This part simply builds on the work we've done so far, and delivers a new Breakout codebase with:


 * Gameplay running in the foreground on the main CPU core 0

 * Graphics updated in the background on CPU core 1

 * Looped 8-bit music playing in the background on CPU core 2

 * Bluetooth communications managed in the background on CPU core 3


I've taken the opportunity to organise the code a little better and so you'll see some changes to the _Makefile_, and a new directory structure in place. Tidy codebase = tidy mind!


Important takeaway

As you read through this code, you'll maybe notice that a very different style has emerged. Multi-processing adds a dimension of complexity when coding and requires a total mindset shift.


There's a lot more signalling/semaphores, so the cores can be sure they're doing the right thing at the right time.


You're no longer "dry-running" a single, sequential thread. You're having to spot the potential for bugs/unexpected behaviour from the interplay of four concurrent threads!


_Good luck as you explore the code!_


Progress video

Click to watch a quick video of the game in action.


https://user-images.githubusercontent.com/68182575/173157526-2b22f9b2-0f55-42a0-87e1-b8278930fefe.mp4


PS: Sorry for the bad audio quality - the game itself sounds great in real life, I promise!



13-对part11-breakout-smp的翻译和搬运的评论 (共 条)

分享到微博请遵守国家法律