Refactoring code
You probably felt a little uncomfortable with the redundant code blocks we wrote in the previous chapters; for example, the PlayerAvatar
and Enemy
classes have some identical attribute variables and functions. Can we instead combine them and maintain only one copy of code for those replicated variables and functions? Yes, and this will require us to refactor the code.
Code refactoring helps improve the internal structure of code so that it becomes more readable, maintainable, and efficient. The process includes algorithm optimization, duplicate removal, and code simplification.
For the Pangaea project, we identified two refactoring tasks:
- Combining the two animation instance classes
- Adding a parent class for the
PlayerAvatar
andEnemy
classes
Let’s start with the first task.
Combining the PlayerAvatarAnimInstance and EnemyAnimInstance classes
Open and compare the PlayerAvatarAnimInstance.h
, PlayerAvatarAnimInstance.cpp
, EnemyAnimInstance...