liupu9 / CelestePubCode

基于蔚蓝的开源GamePlay 和 Monocle 框架, 包含学习过程中的中文注释.
0 stars 0 forks source link

蔚蓝 GamePlay 代码分析(1) #1

Closed liupu9 closed 1 year ago

liupu9 commented 1 year ago

在学习了 2D-Platform-Controller 这个开源工程, 为其增加了 700+行注释之后, 对其功能也有了初步的了解. 在这个基础上, 我开始对原版 Celeste Player.cs 源文件进行代码正向注释. 期望在注经的过程中, 记录自己的进步与感悟.

  1. 整个代码由 5471 行, 基本上没有什么注释.
  2. 代码被划分成 36 个代码块, 其中 12 个基本功能块, 23 个状态代码块, 1 个代码追踪块.
  3. 框架采用Monocle, 目前也有源代码, 共计 19197 行.
  4. 对 23 个状态进行中文注释(先完成, 后面如果发现不对,再进行修正)
  5. 整个逻辑由一个状态机控制. 每个状态可以注册 4 个 hook(开始,结束, 更新, 协程)
liupu9 commented 1 year ago

注 1: Celeste GamePlay 核心代码玩家控制开源, https://github.com/liupu9/Celeste/blob/master/Source/Player/Player.cs

liupu9 commented 1 year ago

注 2: 代码块详情 image

liupu9 commented 1 year ago

注 3: Monocle 框架提交记录. 没有任何修改的版本. https://github.com/liupu9/MonocleEngine/commit/9777be26119b21c870bb3c4c17a8a940218d8bd4

liupu9 commented 1 year ago

注 4: 后面的几个状态中文名明显是不太准确的, 如果有更好的翻译, 请在这里回复. :)

liupu9 commented 1 year ago

注 5: 提到了核心的状态机逻辑. 相关代码:

            StateMachine = new StateMachine(23);
            StateMachine.SetCallbacks(StNormal, NormalUpdate, null, NormalBegin, NormalEnd);
            StateMachine.SetCallbacks(StClimb, ClimbUpdate, null, ClimbBegin, ClimbEnd);
            StateMachine.SetCallbacks(StDash, DashUpdate, DashCoroutine, DashBegin, DashEnd);
            StateMachine.SetCallbacks(StSwim, SwimUpdate, null, SwimBegin, null);
            StateMachine.SetCallbacks(StBoost, BoostUpdate, BoostCoroutine, BoostBegin, BoostEnd);
            StateMachine.SetCallbacks(StRedDash, RedDashUpdate, RedDashCoroutine, RedDashBegin, RedDashEnd);
            StateMachine.SetCallbacks(StHitSquash, HitSquashUpdate, null, HitSquashBegin, null);
            StateMachine.SetCallbacks(StLaunch, LaunchUpdate, null, LaunchBegin, null);
            StateMachine.SetCallbacks(StPickup, null, PickupCoroutine, null, null);
            StateMachine.SetCallbacks(StDreamDash, DreamDashUpdate, null, DreamDashBegin, DreamDashEnd);
            StateMachine.SetCallbacks(StSummitLaunch, SummitLaunchUpdate, null, SummitLaunchBegin, null);
            StateMachine.SetCallbacks(StDummy, DummyUpdate, null, DummyBegin, null);
            StateMachine.SetCallbacks(StIntroWalk, null, IntroWalkCoroutine, null, null);
            StateMachine.SetCallbacks(StIntroJump, null, IntroJumpCoroutine, null, null);
            StateMachine.SetCallbacks(StIntroRespawn, null, null, IntroRespawnBegin, IntroRespawnEnd);
            StateMachine.SetCallbacks(StIntroWakeUp, null, IntroWakeUpCoroutine, null, null);
            StateMachine.SetCallbacks(StTempleFall, TempleFallUpdate, TempleFallCoroutine);
            StateMachine.SetCallbacks(StReflectionFall, ReflectionFallUpdate, ReflectionFallCoroutine, ReflectionFallBegin, ReflectionFallEnd);
            StateMachine.SetCallbacks(StBirdDashTutorial, BirdDashTutorialUpdate, BirdDashTutorialCoroutine, BirdDashTutorialBegin, null);
            StateMachine.SetCallbacks(StFrozen, FrozenUpdate, null, null, null);
            StateMachine.SetCallbacks(StStarFly, StarFlyUpdate, StarFlyCoroutine, StarFlyBegin, StarFlyEnd);
            StateMachine.SetCallbacks(StCassetteFly, CassetteFlyUpdate, CassetteFlyCoroutine, CassetteFlyBegin, CassetteFlyEnd);
            StateMachine.SetCallbacks(StAttract, AttractUpdate, null, AttractBegin, AttractEnd);
            Add(StateMachine);