Skip to content

Commit

Permalink
- backend sync from gzdoom, again
Browse files Browse the repository at this point in the history
  • Loading branch information
madame-rachelle committed Apr 18, 2024
1 parent 6dcb8c0 commit d2b2092
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 112 deletions.
98 changes: 53 additions & 45 deletions source/common/cutscenes/movieplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,11 +322,11 @@ class VpxPlayer : public MoviePlayer
unsigned width, height;
TArray<uint8_t> Pic;
TArray<uint8_t> readBuf;
vpx_codec_iface_t *iface;
vpx_codec_ctx_t codec{};
vpx_codec_iter_t iter = nullptr;

uint32_t convnumer;
uint32_t convdenom;
double convrate;

uint64_t nsecsperframe;
uint64_t nextframetime;
Expand Down Expand Up @@ -362,10 +362,8 @@ class VpxPlayer : public MoviePlayer

Pic.Resize(width * height * 4);


// Todo: Support VP9 as well?
vpx_codec_dec_cfg_t cfg = { 1, width, height };
if (vpx_codec_dec_init(&codec, &vpx_codec_vp8_dx_algo, &cfg, 0))
if (vpx_codec_dec_init(&codec, iface, &cfg, 0))
{
error.Format("Error initializing VPX codec.\n");
failed = true;
Expand All @@ -388,7 +386,16 @@ class VpxPlayer : public MoviePlayer
uint16_t length = fr.ReadUInt16();
if (length != 32) return false;
fr.Read(&magic, 4);
if (magic != MAKE_ID('V', 'P', '8', '0')) return false;

switch (magic)
{
case MAKE_ID('V', 'P', '8', '0'):
iface = &vpx_codec_vp8_dx_algo; break;
case MAKE_ID('V', 'P', '9', '0'):
iface = &vpx_codec_vp9_dx_algo; break;
default:
return false;
}

width = fr.ReadUInt16();
height = fr.ReadUInt16();
Expand All @@ -398,15 +405,20 @@ class VpxPlayer : public MoviePlayer
if (numframes == 0) return false;
fr.Seek(4, FileReader::SeekCur);

if (fpsdenominator > 1000 || fpsnumerator == 0 || fpsdenominator == 0)
if (fpsnumerator == 0 || fpsdenominator == 0)
{
// default to 30 fps if the header does not provide useful info.
fpsdenominator = 30;
fpsnumerator = 1;
}

convnumer = 120 * fpsnumerator;
convdenom = fpsdenominator * origframedelay;
if (origframedelay < 1)
convrate = 0.0;
else
{
convrate = 120.0 * double(fpsnumerator);
convrate /= double(fpsdenominator) * double(origframedelay);
}

nsecsperframe = int64_t(fpsnumerator) * 1'000'000'000 / fpsdenominator;
nextframetime = 0;
Expand Down Expand Up @@ -475,32 +487,6 @@ class VpxPlayer : public MoviePlayer
dest[2] = v;
}

bool CreateNextFrame()
{
auto img = GetFrameData();
if (!img) return false;
uint8_t const* const yplane = img->planes[VPX_PLANE_Y];
uint8_t const* const uplane = img->planes[VPX_PLANE_U];
uint8_t const* const vplane = img->planes[VPX_PLANE_V];

const int ystride = img->stride[VPX_PLANE_Y];
const int ustride = img->stride[VPX_PLANE_U];
const int vstride = img->stride[VPX_PLANE_V];

for (unsigned int y = 0; y < height; y++)
{
for (unsigned int x = 0; x < width; x++)
{
uint8_t u = uplane[ustride * (y >> 1) + (x >> 1)];
uint8_t v = vplane[vstride * (y >> 1) + (x >> 1)];

SetPixel(&Pic[(x + y * width) << 2], yplane[ystride * y + x], u, v);
}
}

return true;
}

//---------------------------------------------------------------------------
//
//
Expand All @@ -525,7 +511,7 @@ class VpxPlayer : public MoviePlayer
Printf(PRINT_BOLD, "Failed to decode %s\n", fileSystem.GetFileFullName(soundtrack, false));
}
}
animtex.SetSize(AnimTexture::YUV, width, height);
animtex.SetSize(AnimTexture::VPX, width, height);
}

//---------------------------------------------------------------------------
Expand All @@ -534,6 +520,12 @@ class VpxPlayer : public MoviePlayer
//
//---------------------------------------------------------------------------

bool FormatSupported(vpx_img_fmt_t fmt)
{
return fmt == VPX_IMG_FMT_I420 || fmt == VPX_IMG_FMT_I444 || fmt == VPX_IMG_FMT_I422 || fmt == VPX_IMG_FMT_I440;
}


bool Frame(uint64_t clock) override
{
if (!AudioTrack.GetAudioStream() && MusicStream && clock != 0)
Expand Down Expand Up @@ -562,22 +554,38 @@ class VpxPlayer : public MoviePlayer
bool stop = false;
if (clock >= nextframetime)
{


nextframetime += nsecsperframe;

if (!CreateNextFrame())
{
Printf(PRINT_BOLD, "Failed reading next frame\n");
stop = true;
while(clock >= nextframetime)
{ // frameskipping
auto img = GetFrameData();
framenum++;
nextframetime += nsecsperframe;
if (framenum >= numframes || !img) break;
}
else

if (framenum < numframes)
{
animtex.SetFrame(nullptr, Pic.Data());
auto img = GetFrameData();

if (!img || !FormatSupported(img->fmt))
{
Printf(PRINT_BOLD, "Failed reading next frame\n");
stop = true;
}
else
{
animtex.SetFrame(nullptr, img);
}

framenum++;
}
framenum++;
if (framenum >= numframes) stop = true;

bool nostopsound = (flags & NOSOUNDCUTOFF);
int soundframe = convdenom ? Scale(framenum, convnumer, convdenom) : framenum;
int soundframe = (convrate > 0.0) ? int(convrate * framenum) : framenum;
if (soundframe > lastsoundframe)
{
if (soundtrack == -1)
Expand Down Expand Up @@ -895,7 +903,7 @@ MoviePlayer* OpenMovie(const char* filename, TArray<int>& ans, const int* framet
}
return anm;
}
else if (!memcmp(id, "DKIF\0\0 \0VP80", 12))
else if (!memcmp(id, "DKIF\0\0 \0VP80", 12) || !memcmp(id, "DKIF\0\0 \0VP90", 12))
{
auto anm = new VpxPlayer(fr, ans, frameticks ? frameticks[1] : 0, flags, error);
if (!anm->isvalid())
Expand Down
4 changes: 2 additions & 2 deletions source/common/models/models_iqm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,14 +599,14 @@ const TArray<VSMatrix> IQMModel::CalculateBones(int frame1, int frame2, float in

if(frame1 >= 0 && (frame1_prev >= 0 || inter1_prev < 0))
{
prev = inter1_prev < 0 ? animationFrames[offset1 + i] : InterpolateBone(animationFrames[offset1_1 + i], animationFrames[offset1 + i], inter1_prev, invt1);
prev = inter1_prev <= 0 ? animationFrames[offset1 + i] : InterpolateBone(animationFrames[offset1_1 + i], animationFrames[offset1 + i], inter1_prev, invt1);
}

TRS next;

if(frame2 >= 0 && (frame2_prev >= 0 || inter2_prev < 0))
{
next = inter2_prev < 0 ? animationFrames[offset2 + i] : InterpolateBone(animationFrames[offset2_1 + i], animationFrames[offset2 + i], inter2_prev, invt2);
next = inter2_prev <= 0 ? animationFrames[offset2 + i] : InterpolateBone(animationFrames[offset2_1 + i], animationFrames[offset2 + i], inter2_prev, invt2);
}

TRS bone;
Expand Down
4 changes: 0 additions & 4 deletions source/common/objects/dobjgc.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,6 @@ class TObjPtr
mutable DObject *o;
};
public:
// before doing a backend sync - this needs to be addressed: https://github.com/ZDoom/Raze/actions/runs/8727418834/job/23944876872
//TObjPtr() = default;

//TObjPtr(T t) : pp(t) {}

constexpr TObjPtr<T>& operator=(T q) noexcept
{
Expand Down
Loading

0 comments on commit d2b2092

Please sign in to comment.