Skip to content

Commit

Permalink
Engine: moved runtime functions out of CharacterInfo class
Browse files Browse the repository at this point in the history
These are part of a very old refactor attempt to bring functionality inside a "Character" class. But this refactor stopped at early stage, leaving these methods inconveniently part of a CharacterInfo struct and Common lib, where they are not supposed to be at all, complicate CharacterInfo and add unnecessary dependency.

Ideally these should become methods of a runtime "Character" class, but since we don't have atm, redefine these as global functions again, and pass CharacterInfo as an argument.
  • Loading branch information
ivan-mogilko committed Aug 29, 2024
1 parent 11b7da0 commit caf5850
Show file tree
Hide file tree
Showing 5 changed files with 194 additions and 183 deletions.
18 changes: 0 additions & 18 deletions Common/ac/characterinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ enum CharacterSvgVersion

// Predeclare a design-time Character extension
struct CharacterInfo2;
// Predeclare a runtime Character extension (TODO: refactor and remove this from here)
struct CharacterExtras;


// CharacterInfo is a design-time Character data.
Expand Down Expand Up @@ -176,22 +174,6 @@ struct CharacterInfo
((delay & 0xFF) << 8);
}

// [IKM] 2012-06-28: I still have to pass char_index to some of those functions
// either because they use it to set some variables with it,
// or because they pass it further to other functions, that are called from various places
// and it would be too much to change them all simultaneously
//
// [IKM] 2016-08-26: these methods should NOT be in CharacterInfo class,
// bit in distinct runtime character class!
void UpdateMoveAndAnim(int &char_index, CharacterExtras *chex, std::vector<int> &followingAsSheep);
void UpdateFollowingExactlyCharacter();

bool update_character_turning(CharacterExtras *chex);
void update_character_moving(int &char_index, CharacterExtras *chex, int &doing_nothing);
bool update_character_animating(int &char_index, int &doing_nothing);
void update_character_idle(CharacterExtras *chex, int &doing_nothing);
void update_character_follower(int &char_index, std::vector<int> &followingAsSheep, int &doing_nothing);

void ReadFromFile(Common::Stream *in, CharacterInfo2 &chinfo2, GameDataVersion data_ver);
void WriteToFile(Common::Stream *out) const;
// TODO: move to runtime-only class (?)
Expand Down
4 changes: 2 additions & 2 deletions Engine/ac/character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1921,7 +1921,7 @@ int has_hit_another_character(int sourceChar) {
// Does the next move from the character's movelist.
// Returns 1 if they are now waiting for another char to move,
// otherwise returns 0
int doNextCharMoveStep (CharacterInfo *chi, int &char_index, CharacterExtras *chex) {
int doNextCharMoveStep(CharacterInfo *chi, CharacterExtras *chex) {
int ntf=0, xwas = chi->x, ywas = chi->y;

if (do_movelist_move(chi->walking, chi->x, chi->y) == 2)
Expand All @@ -1930,7 +1930,7 @@ int doNextCharMoveStep (CharacterInfo *chi, int &char_index, CharacterExtras *ch
fix_player_sprite(&mls[chi->walking], chi);
}

ntf = has_hit_another_character(char_index);
ntf = has_hit_another_character(chi->index_id);
if (ntf >= 0) {
chi->walkwait = 30;
if (game.chars[ntf].walkspeed < 5)
Expand Down
15 changes: 14 additions & 1 deletion Engine/ac/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ void start_character_turning (CharacterInfo *chinf, int useloop, int no_diagonal
void fix_player_sprite(MoveList*cmls,CharacterInfo*chinf);
// Check whether two characters have walked into each other
int has_hit_another_character(int sourceChar);
int doNextCharMoveStep (CharacterInfo *chi, int &char_index, CharacterExtras *chex);
int doNextCharMoveStep(CharacterInfo *chi, CharacterExtras *chex);
// Tells if character is currently moving, in eWalkableAreas mode
bool is_char_walking_ndirect(CharacterInfo *chi);
int find_nearest_walkable_area_within(int *xx, int *yy, int range, int step);
Expand Down Expand Up @@ -228,6 +228,19 @@ Rect GetCharacterRoomBBox(int charid, bool use_frame_0 = false);
// or the one that is least far away from its camera; calculated as a perpendicular distance between two AABBs.
PViewport FindNearestViewport(int charid);

//
// Character update functions
// TODO: move these into a runtime Character class, when there will be a proper one,
// merging CharacterInfo and CharacterExtras.
//
void UpdateCharacterMoveAndAnim(CharacterInfo *chi, CharacterExtras *chex, std::vector<int> &followingAsSheep);
void UpdateFollowingExactlyCharacter(CharacterInfo *chi);
bool UpdateCharacterTurning(CharacterInfo *chi, CharacterExtras *chex);
void UpdateCharacterMoving(CharacterInfo *chi, CharacterExtras *chex, int &doing_nothing);
bool UpdateCharacterAnimating(CharacterInfo *chi, CharacterExtras *chex, int &doing_nothing);
void UpdateCharacterIdle(CharacterInfo *chi, CharacterExtras *chex, int &doing_nothing);
void UpdateCharacterFollower(CharacterInfo *chi, std::vector<int> &followingAsSheep, int &doing_nothing);

extern CharacterInfo*playerchar;
extern int32_t _sc_PlayerCharPtr;

Expand Down
Loading

0 comments on commit caf5850

Please sign in to comment.