Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
liupu9 opened this issue Apr 16, 2023 · 5 comments
Closed

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

liupu9 opened this issue Apr 16, 2023 · 5 comments
Assignees

Comments

@liupu9
Copy link
Owner

liupu9 commented Apr 16, 2023

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

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

liupu9 commented Apr 16, 2023

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

@liupu9
Copy link
Owner Author

liupu9 commented Apr 16, 2023

注 2: 代码块详情
image

@liupu9
Copy link
Owner Author

liupu9 commented Apr 16, 2023

注 3: Monocle 框架提交记录. 没有任何修改的版本. liupu9/MonocleEngine@9777be2

@liupu9
Copy link
Owner Author

liupu9 commented Apr 16, 2023

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

@liupu9
Copy link
Owner Author

liupu9 commented Apr 16, 2023

注 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);

@liupu9 liupu9 self-assigned this Apr 17, 2023
@liupu9 liupu9 closed this as completed Apr 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant