mirror of
https://github.com/scp-fs2open/fs2open.github.com.git
synced 2026-11-08 07:28:22 -10:00
* Automatically generate the isValid() Lua API function for handle types If an ADE object's stored type has an isValid() member, ade_obj now registers an isValid function for it automatically. An explicit ADE_FUNC(isValid, ...) declared after the ADE_OBJ replaces the generated one, so types with special semantics (e.g. sound) keep their own. The 67 hand-written functions that merely delegated to the member are removed, and 26 types that previously exposed no isValid() gain one. Co-Authored-By: Claude Fable 5.1 <[email protected]> * Add ADE_OBJ_VALIDATOR for index-based Lua handles Int-index handles (shipclass, weaponclass, team, etc.) can now declare their validity predicate with a single ADE_OBJ_VALIDATOR or ADE_OBJ_VALIDATOR_RANGE line after the ADE_OBJ. The registered validator drives the generated isValid() function and is also honored by ade_set_args when the mod table asks for nil instead of invalid objects, which previously never applied to these handles. The 19 hand-written range-check functions are replaced, and loadout_ship, default_primary, default_secondary, and support_rearm_pool_team gain isValid(). Add a validator to HudGauge while we're at it. Also fully qualify the scripting namespace in LuaConvert.h so its templates can be instantiated from the unit tests. Co-Authored-By: Claude Fable 5.1 <[email protected]> --------- Co-authored-by: Claude Fable 5.1 <[email protected]>
176 lines
5.1 KiB
C++
176 lines
5.1 KiB
C++
|
|
#include "movie_player.h"
|
|
#include "time_obj.h"
|
|
|
|
namespace scripting {
|
|
namespace api {
|
|
|
|
movie_player_h::movie_player_h() = default;
|
|
movie_player_h::movie_player_h(std::unique_ptr<cutscene::Player>&& player) : _player(std::move(player)) {}
|
|
bool movie_player_h::isValid() const { return (bool)_player; }
|
|
cutscene::Player* movie_player_h::player() { return _player.get(); }
|
|
|
|
ADE_OBJ(l_MoviePlayer, movie_player_h, "movie_player", "A movie player instance");
|
|
|
|
ADE_VIRTVAR(Width, l_MoviePlayer, "number", "Determines the width in pixels of this movie <b>Read-only</b>", "number",
|
|
"The width of the movie or -1 if handle is invalid")
|
|
{
|
|
movie_player_h* ph = nullptr;
|
|
if (!ade_get_args(L, "o", l_MoviePlayer.GetPtr(&ph)))
|
|
return ade_set_args(L, "i", -1);
|
|
|
|
if (ph == nullptr || !ph->isValid()) {
|
|
return ade_set_args(L, "i", -1);
|
|
}
|
|
|
|
if (ADE_SETTING_VAR) {
|
|
LuaError(L, "Tried to modify read-only member!");
|
|
}
|
|
|
|
return ade_set_args(L, "i", (int)ph->player()->getMovieProperties().size.width);
|
|
}
|
|
|
|
ADE_VIRTVAR(Height, l_MoviePlayer, "number", "Determines the height in pixels of this movie <b>Read-only</b>", "number",
|
|
"The height of the movie or -1 if handle is invalid")
|
|
{
|
|
movie_player_h* ph = nullptr;
|
|
if (!ade_get_args(L, "o", l_MoviePlayer.GetPtr(&ph)))
|
|
return ade_set_args(L, "i", -1);
|
|
|
|
if (ph == nullptr || !ph->isValid()) {
|
|
return ade_set_args(L, "i", -1);
|
|
}
|
|
|
|
if (ADE_SETTING_VAR) {
|
|
LuaError(L, "Tried to modify read-only member!");
|
|
}
|
|
|
|
return ade_set_args(L, "i", (int)ph->player()->getMovieProperties().size.height);
|
|
}
|
|
|
|
ADE_VIRTVAR(FPS, l_MoviePlayer, "number", "Determines the frames per second of this movie <b>Read-only</b>", "number",
|
|
"The FPS of the movie or -1 if handle is invalid")
|
|
{
|
|
movie_player_h* ph = nullptr;
|
|
if (!ade_get_args(L, "o", l_MoviePlayer.GetPtr(&ph)))
|
|
return ade_set_args(L, "f", -1.0f);
|
|
|
|
if (ph == nullptr || !ph->isValid()) {
|
|
return ade_set_args(L, "f", -1.0f);
|
|
}
|
|
|
|
if (ADE_SETTING_VAR) {
|
|
LuaError(L, "Tried to modify read-only member!");
|
|
}
|
|
|
|
return ade_set_args(L, "f", ph->player()->getMovieProperties().fps);
|
|
}
|
|
|
|
ADE_VIRTVAR(Duration, l_MoviePlayer, "number", "Determines the duration in seconds of this movie <b>Read-only</b>", "number",
|
|
"The duration of the movie or -1 if handle is invalid")
|
|
{
|
|
movie_player_h* ph = nullptr;
|
|
if (!ade_get_args(L, "o", l_MoviePlayer.GetPtr(&ph)))
|
|
return ade_set_args(L, "f", -1.0f);
|
|
|
|
if (ph == nullptr || !ph->isValid()) {
|
|
return ade_set_args(L, "f", -1.0f);
|
|
}
|
|
|
|
if (ADE_SETTING_VAR) {
|
|
LuaError(L, "Tried to modify read-only member!");
|
|
}
|
|
|
|
return ade_set_args(L, "f", ph->player()->getMovieProperties().duration);
|
|
}
|
|
|
|
ADE_FUNC(update, l_MoviePlayer, "timespan step_time",
|
|
"Updates the current state of the movie and moves the internal timer forward by the specified time span.",
|
|
"boolean", "true if there is more to display, false otherwise")
|
|
{
|
|
movie_player_h* ph = nullptr;
|
|
int64_t time_diff = 0;
|
|
if (!ade_get_args(L, "oo", l_MoviePlayer.GetPtr(&ph), l_TimeSpan.Get(&time_diff)))
|
|
return ADE_RETURN_FALSE;
|
|
|
|
if (ph == nullptr || !ph->isValid()) {
|
|
return ADE_RETURN_FALSE;
|
|
}
|
|
|
|
auto ret = ph->player()->update(static_cast<uint64_t>(time_diff / 1000));
|
|
|
|
return ade_set_args(L, "b", ret);
|
|
}
|
|
|
|
ADE_FUNC(isPlaybackReady, l_MoviePlayer, nullptr,
|
|
"Determines if the player is ready to display the movie. Since the movie frames are loaded asynchronously "
|
|
"there is a short delay between the creation of a player and when it is possible to start displaying the "
|
|
"movie. This function can be used to determine if playback is possible at the moment.",
|
|
"boolean", "true if playback is ready, false otherwise")
|
|
{
|
|
movie_player_h* ph = nullptr;
|
|
if (!ade_get_args(L, "o", l_MoviePlayer.GetPtr(&ph)))
|
|
return ADE_RETURN_FALSE;
|
|
|
|
if (ph == nullptr || !ph->isValid()) {
|
|
return ADE_RETURN_FALSE;
|
|
}
|
|
|
|
auto ret = ph->player()->isPlaybackReady();
|
|
|
|
return ade_set_args(L, "b", ret);
|
|
}
|
|
|
|
ADE_FUNC(drawMovie, l_MoviePlayer, "number x1, number y1, [number x2, number y2]",
|
|
"Draws the current frame of the movie at the specified coordinates.", nullptr, "Returns nothing")
|
|
{
|
|
movie_player_h* ph = nullptr;
|
|
float x1;
|
|
float y1;
|
|
float x2 = -1.f;
|
|
float y2 = -1.f;
|
|
float alpha = 1.f;
|
|
|
|
if (!ade_get_args(L, "off|fff", l_MoviePlayer.GetPtr(&ph), &x1, &y1, &x2, &y2, &alpha))
|
|
return ADE_RETURN_NIL;
|
|
|
|
if (ph == nullptr || !ph->isValid()) {
|
|
return ADE_RETURN_NIL;
|
|
}
|
|
|
|
auto& props = ph->player()->getMovieProperties();
|
|
|
|
// Use equality here to check if it has been changed
|
|
if (x2 == -1.f) {
|
|
x2 = x1 + props.size.width;
|
|
}
|
|
if (y2 == -1.f) {
|
|
y2 = y1 + props.size.height;
|
|
}
|
|
|
|
ph->player()->draw(x1, y1, x2, y2, alpha);
|
|
|
|
return ADE_RETURN_NIL;
|
|
}
|
|
|
|
ADE_FUNC(stop, l_MoviePlayer, nullptr,
|
|
"Explicitly stops playback. This function should be called when the player isn't needed anymore to free up "
|
|
"some resources.",
|
|
nullptr, "Returns nothing")
|
|
{
|
|
movie_player_h* ph = nullptr;
|
|
if (!ade_get_args(L, "o", l_MoviePlayer.GetPtr(&ph)))
|
|
return ADE_RETURN_NIL;
|
|
|
|
if (ph == nullptr || !ph->isValid()) {
|
|
return ADE_RETURN_NIL;
|
|
}
|
|
|
|
ph->player()->stopPlayback();
|
|
|
|
return ADE_RETURN_NIL;
|
|
}
|
|
|
|
} // namespace api
|
|
} // namespace scripting
|