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

add getPlayMode() for actor and anim interface #1647

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions direct/src/actor/Actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,13 @@ def getLOD(self, lodName):
else:
return None

def getPlayMode(self, animName=None, partName=None):
if self.__animControlDict:
controls = self.getAnimControls(animName, partName, onlyPlaying=False)
if controls:
return controls[0].getPlayMode()
return None

def hasLOD(self):
"""
Return 1 if the actor has LODs, 0 otherwise
Expand Down Expand Up @@ -1762,7 +1769,7 @@ def getAnimControl(self, animName, partName=None, lodName=None,
return None

def getAnimControls(self, animName=None, partName=None, lodName=None,
allowAsyncBind = True):
allowAsyncBind = True, onlyPlaying = True):
"""getAnimControls(self, string, string=None, string=None)

Returns a list of the AnimControls that represent the given
Expand Down Expand Up @@ -1840,7 +1847,7 @@ def getAnimControls(self, animName=None, partName=None, lodName=None,
# get all playing animations
for thisPart, animDict in animDictItems:
for anim in animDict.values():
if anim.animControl and anim.animControl.isPlaying():
if anim.animControl and (not onlyPlaying or anim.animControl.isPlaying()):
controls.append(anim.animControl)
else:
# get the named animation(s) only.
Expand Down Expand Up @@ -2660,3 +2667,4 @@ def renamePartBundles(self, partName, newBundleName):
get_base_frame_rate = getBaseFrameRate
remove_anim_control_dict = removeAnimControlDict
load_anims_on_all_lods = loadAnimsOnAllLODs
get_play_mode = getPlayMode
15 changes: 15 additions & 0 deletions panda/src/putil/animInterface.I
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,16 @@ is_playing() const {
return cdata->is_playing();
}

/**
* Returns the current play mode of the animation; whether the animation is
* playing normally, looping, posing, or in ping-pong mode.
*/
INLINE AnimInterface::PlayMode AnimInterface::
get_play_mode() const {
CDReader cdata(_cycler);
return cdata->get_play_mode();
}

/**
* Should be called by a derived class to specify the native frame rate of the
* animation. It is legal to call this after the animation has already
Expand Down Expand Up @@ -266,6 +276,11 @@ get_frac() const {
return get_full_fframe() - (double)get_full_frame(0);
}

INLINE AnimInterface::PlayMode AnimInterface::CData::
get_play_mode() const {
return _play_mode;
}

INLINE std::ostream &
operator << (std::ostream &out, const AnimInterface &ai) {
ai.output(out);
Expand Down
17 changes: 10 additions & 7 deletions panda/src/putil/animInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ class EXPCL_PANDA_PUTIL AnimInterface {
AnimInterface(const AnimInterface &copy);

PUBLISHED:
enum PlayMode {
PM_pose,
PM_play,
PM_loop,
PM_pingpong,
};

virtual ~AnimInterface();
INLINE void play();
INLINE void play(double from, double to);
Expand All @@ -59,6 +66,7 @@ class EXPCL_PANDA_PUTIL AnimInterface {
INLINE int get_full_frame() const;
INLINE double get_full_fframe() const;
INLINE bool is_playing() const;
INLINE PlayMode get_play_mode() const;

virtual void output(std::ostream &out) const;

Expand All @@ -73,20 +81,14 @@ class EXPCL_PANDA_PUTIL AnimInterface {
MAKE_PROPERTY(full_frame, get_full_frame);
MAKE_PROPERTY(full_fframe, get_full_fframe);
MAKE_PROPERTY(playing, is_playing);
MAKE_PROPERTY(play_mode, get_play_mode);

protected:
INLINE void set_frame_rate(double frame_rate);
INLINE void set_num_frames(int num_frames);
virtual void animation_activated();

private:
enum PlayMode {
PM_pose,
PM_play,
PM_loop,
PM_pingpong,
};

// This data is not cycled, because it is a semi-permanent part of the
// interface. Also, some derivatives of AnimInterface don't even use it.
int _num_frames;
Expand All @@ -112,6 +114,7 @@ class EXPCL_PANDA_PUTIL AnimInterface {
int get_full_frame(int increment) const;
double get_full_fframe() const;
bool is_playing() const;
INLINE PlayMode get_play_mode() const;

virtual void output(std::ostream &out) const;

Expand Down