2019-11-20 16:21:32 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
Copyright (C) 2010-2019 EDuke32 developers and contributors
|
|
|
|
Copyright (C) 2019 sirlemonhead, Nuke.YKT
|
|
|
|
This file is part of PCExhumed.
|
|
|
|
PCExhumed is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License version 2
|
|
|
|
as published by the Free Software Foundation.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
2019-11-22 23:11:37 +00:00
|
|
|
#include "ns.h"
|
2019-08-26 03:59:14 +00:00
|
|
|
#include "engine.h"
|
|
|
|
#include "exhumed.h"
|
|
|
|
#include "names.h"
|
|
|
|
#include "movie.h"
|
|
|
|
#include "light.h"
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstring>
|
|
|
|
#include "baselayer.h"
|
|
|
|
#include "typedefs.h"
|
2020-01-02 18:56:57 +00:00
|
|
|
#include "c_bind.h"
|
2019-12-05 21:18:34 +00:00
|
|
|
#include "sound.h"
|
2019-12-31 18:25:49 +00:00
|
|
|
#include "v_2ddrawer.h"
|
2020-04-12 05:46:53 +00:00
|
|
|
#include "animtexture.h"
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-11-22 23:11:37 +00:00
|
|
|
BEGIN_PS_NS
|
|
|
|
|
2019-08-26 03:59:14 +00:00
|
|
|
enum {
|
2019-08-31 07:47:15 +00:00
|
|
|
kFramePalette = 0,
|
|
|
|
kFrameSound,
|
|
|
|
kFrameImage,
|
|
|
|
kFrameDone
|
2019-08-26 03:59:14 +00:00
|
|
|
};
|
|
|
|
|
2019-12-05 21:18:34 +00:00
|
|
|
#define kSampleRate 22050
|
|
|
|
#define kSampleSize 2205
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-12-05 21:18:34 +00:00
|
|
|
uint8_t bankbuf[kSampleRate];
|
|
|
|
uint32_t bankptr = 0;
|
|
|
|
uint32_t banktail = 0;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-12-05 21:18:34 +00:00
|
|
|
uint32_t lSoundBytesRead = 0;
|
|
|
|
uint32_t lSoundBytesUsed = 0;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-12-05 21:18:34 +00:00
|
|
|
uint8_t lh[32] = { 0 };
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-12-05 21:18:34 +00:00
|
|
|
static uint8_t* CurFrame = NULL;
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-12-05 21:18:34 +00:00
|
|
|
bool bServedSample = false;
|
2019-10-12 21:09:55 +00:00
|
|
|
palette_t moviepal[256];
|
|
|
|
|
2020-04-12 05:46:53 +00:00
|
|
|
int ReadFrame(FileReader &fp, uint8_t *palette)
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
2019-08-31 07:47:15 +00:00
|
|
|
static int nFrame = 0;
|
2019-11-24 09:03:19 +00:00
|
|
|
Printf("Reading frame %d...\n", nFrame);
|
2019-08-31 07:47:15 +00:00
|
|
|
nFrame++;
|
|
|
|
|
|
|
|
uint8_t nType;
|
|
|
|
uint8_t var_1C;
|
|
|
|
int nSize;
|
2019-08-31 09:08:38 +00:00
|
|
|
uint16_t yOffset;
|
2019-08-31 07:47:15 +00:00
|
|
|
uint8_t xOffset;
|
|
|
|
uint8_t nPixels;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2019-11-24 12:59:36 +00:00
|
|
|
if (fp.Read(&nType, sizeof(nType)) == 0) {
|
2019-08-31 07:47:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-11-24 12:59:36 +00:00
|
|
|
fp.Read(&nSize, sizeof(nSize));
|
2019-08-31 07:47:15 +00:00
|
|
|
|
|
|
|
nType--;
|
|
|
|
if (nType > 3) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (nType)
|
|
|
|
{
|
|
|
|
case kFramePalette:
|
|
|
|
{
|
2020-04-12 05:46:53 +00:00
|
|
|
fp.Read(palette, 768);
|
2019-11-24 12:59:36 +00:00
|
|
|
fp.Read(&var_1C, sizeof(var_1C));
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2020-04-12 05:46:53 +00:00
|
|
|
for (unsigned i = 0; i < 768;i++)
|
|
|
|
palette[i] <<= 2;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
|
|
|
memset(CurFrame, overscanindex, 4); //sizeof(CurFrame));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
case kFrameSound:
|
|
|
|
{
|
2019-11-24 09:03:19 +00:00
|
|
|
Printf("Reading sound block size %d...\n", nSize);
|
2019-12-05 21:18:34 +00:00
|
|
|
|
|
|
|
if (lSoundBytesRead - lSoundBytesUsed >= kSampleRate)
|
|
|
|
{
|
2020-03-01 16:22:31 +00:00
|
|
|
//DebugOut("ReadFrame() - Sound buffer full\n");
|
|
|
|
fp.Seek(nSize, FileReader::SeekCur);
|
2019-12-05 21:18:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-12-25 23:21:04 +00:00
|
|
|
//mutex_lock(&mutex);
|
2019-12-05 21:18:34 +00:00
|
|
|
|
2019-12-12 23:19:34 +00:00
|
|
|
int nRead = fp.Read((char*)bankbuf + bankptr, nSize);
|
2019-12-05 21:18:34 +00:00
|
|
|
|
|
|
|
lSoundBytesRead += nRead;
|
|
|
|
bankptr += nSize;
|
|
|
|
|
|
|
|
assert(nSize == nRead);
|
|
|
|
assert(bankptr <= kSampleRate);
|
|
|
|
|
|
|
|
if (bankptr >= kSampleRate) {
|
|
|
|
bankptr -= kSampleRate; // loop back to start
|
|
|
|
}
|
|
|
|
|
2019-12-25 23:21:04 +00:00
|
|
|
//mutex_unlock(&mutex);
|
2019-12-05 21:18:34 +00:00
|
|
|
}
|
|
|
|
|
2019-08-31 07:47:15 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
case kFrameImage:
|
|
|
|
{
|
2020-03-01 16:22:31 +00:00
|
|
|
//Printf("Reading image block size %d...\n", nSize);
|
2019-08-31 07:47:15 +00:00
|
|
|
if (nSize == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t *pFrame = CurFrame;
|
|
|
|
|
2019-11-24 12:59:36 +00:00
|
|
|
int nRead = fp.Read(&yOffset, sizeof(yOffset));
|
2019-08-31 07:47:15 +00:00
|
|
|
nSize -= nRead;
|
|
|
|
|
|
|
|
pFrame += yOffset * 200; // row position
|
|
|
|
|
|
|
|
while (nSize > 0)
|
|
|
|
{
|
2019-11-24 12:59:36 +00:00
|
|
|
fp.Read(&xOffset, sizeof(xOffset));
|
|
|
|
fp.Read(&nPixels, sizeof(nPixels));
|
2019-08-31 07:47:15 +00:00
|
|
|
nSize -= 2;
|
|
|
|
|
|
|
|
pFrame += xOffset;
|
|
|
|
|
|
|
|
if (nPixels)
|
|
|
|
{
|
2019-11-24 12:59:36 +00:00
|
|
|
int nRead = fp.Read(pFrame, nPixels);
|
2019-08-31 07:47:15 +00:00
|
|
|
pFrame += nRead;
|
|
|
|
nSize -= nRead;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case kFrameDone:
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 21:45:10 +00:00
|
|
|
static void ServeSample(const char** ptr, uint32_t* length)
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
2019-12-25 23:21:04 +00:00
|
|
|
//mutex_lock(&mutex);
|
2019-12-05 21:18:34 +00:00
|
|
|
|
|
|
|
*ptr = (char*)bankbuf + banktail;
|
|
|
|
*length = kSampleSize;
|
|
|
|
|
|
|
|
banktail += kSampleSize;
|
|
|
|
if (banktail >= kSampleRate) {
|
|
|
|
banktail -= kSampleRate; // rotate back to start
|
|
|
|
}
|
|
|
|
|
|
|
|
lSoundBytesUsed += kSampleSize;
|
|
|
|
bServedSample = true;
|
|
|
|
|
2019-12-25 23:21:04 +00:00
|
|
|
//mutex_unlock(&mutex);
|
2019-12-05 21:18:34 +00:00
|
|
|
}
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2019-12-05 21:18:34 +00:00
|
|
|
void PlayMovie(const char* fileName)
|
|
|
|
{
|
2020-04-12 05:46:53 +00:00
|
|
|
uint8_t palette[768];
|
2020-03-01 17:32:43 +00:00
|
|
|
TArray<uint8_t> f(64000, true);
|
|
|
|
CurFrame = f.Data();
|
2020-02-29 11:55:12 +00:00
|
|
|
|
2019-12-05 21:18:34 +00:00
|
|
|
int bDoFade = kTrue;
|
|
|
|
int hFx = -1;
|
2020-04-11 21:54:33 +00:00
|
|
|
auto fp = fileSystem.OpenFileReader(fileName);
|
2019-11-24 12:59:36 +00:00
|
|
|
if (!fp.isOpen())
|
|
|
|
{
|
|
|
|
Printf("Unable to open %s\n", fileName);
|
|
|
|
return;
|
|
|
|
}
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2019-11-24 12:59:36 +00:00
|
|
|
fp.Read(lh, sizeof(lh));
|
2019-08-31 07:47:15 +00:00
|
|
|
|
|
|
|
// sound stuff
|
2019-12-05 21:18:34 +00:00
|
|
|
bankptr = 0;
|
|
|
|
banktail = 0;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
|
|
|
// clear keys
|
2020-01-01 10:35:47 +00:00
|
|
|
inputState.ClearAllInput();
|
2019-08-31 07:47:15 +00:00
|
|
|
|
|
|
|
if (bDoFade) {
|
|
|
|
StartFadeIn();
|
|
|
|
}
|
|
|
|
|
|
|
|
int angle = 1536;
|
|
|
|
int z = 0;
|
|
|
|
|
2020-04-12 05:46:53 +00:00
|
|
|
AnimTextures animtex;
|
|
|
|
animtex.SetSize(200, 320);
|
2019-10-12 21:09:55 +00:00
|
|
|
|
2019-12-05 21:18:34 +00:00
|
|
|
// Read a frame in first
|
2020-04-12 05:46:53 +00:00
|
|
|
if (ReadFrame(fp, palette))
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2019-12-25 22:37:16 +00:00
|
|
|
// start audio playback (fixme)
|
|
|
|
#if 0
|
2019-12-13 20:01:14 +00:00
|
|
|
hFx = FX_StartDemandFeedPlayback(ServeSample, kSampleRate, 0, snd_fxvolume, snd_fxvolume, snd_fxvolume, FX_MUSIC_PRIORITY, fix16_one, -1);
|
2019-12-25 22:37:16 +00:00
|
|
|
#else
|
|
|
|
hFx = -1;
|
|
|
|
#endif
|
2019-12-05 21:18:34 +00:00
|
|
|
|
2020-03-01 17:32:43 +00:00
|
|
|
int fn = 0;
|
2019-11-24 12:59:36 +00:00
|
|
|
while (!inputState.keyBufferWaiting())
|
2019-08-31 07:47:15 +00:00
|
|
|
{
|
2019-12-05 21:18:34 +00:00
|
|
|
HandleAsync();
|
|
|
|
|
|
|
|
// audio is king for sync - if the backend doesn't need any more samples yet,
|
|
|
|
// don't process any more movie file data.
|
2019-12-13 19:08:42 +00:00
|
|
|
if (!bServedSample && hFx > 0) {
|
2019-12-05 21:18:34 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
bServedSample = false;
|
2019-08-31 07:47:15 +00:00
|
|
|
|
|
|
|
if (z < 65536) { // Zoom - normal zoom is 65536.
|
|
|
|
z += 2048;
|
|
|
|
}
|
|
|
|
if (angle != 0) {
|
|
|
|
angle += 16;
|
|
|
|
if (angle == 2048) {
|
|
|
|
angle = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-01 17:32:43 +00:00
|
|
|
// I have no idea why this needs double buffering now.
|
|
|
|
fn ^= 1;
|
2020-04-12 05:46:53 +00:00
|
|
|
animtex.SetFrame(palette, CurFrame);
|
|
|
|
rotatesprite(160 << 16, 100 << 16, z, angle+512, -1, 0, 1, RS_AUTO | RS_YFLIP, 0, 0, xdim - 1, ydim - 1, animtex.GetFrame());
|
2019-08-31 07:47:15 +00:00
|
|
|
|
|
|
|
if (bDoFade) {
|
|
|
|
bDoFade = DoFadeIn();
|
|
|
|
}
|
|
|
|
|
|
|
|
videoNextPage();
|
|
|
|
|
2020-04-12 05:46:53 +00:00
|
|
|
if (ReadFrame(fp, palette) == 0) {
|
2019-08-31 07:47:15 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-05 21:18:34 +00:00
|
|
|
if (hFx > 0) {
|
2019-12-25 22:37:16 +00:00
|
|
|
//FX_StopSound(hFx);
|
2019-12-05 21:18:34 +00:00
|
|
|
}
|
|
|
|
|
2019-11-24 12:59:36 +00:00
|
|
|
if (inputState.keyBufferWaiting()) {
|
|
|
|
inputState.keyGetChar();
|
2019-08-31 07:47:15 +00:00
|
|
|
}
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
2019-11-22 23:11:37 +00:00
|
|
|
END_PS_NS
|