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"
|
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];
|
|
|
|
|
2019-11-24 12:59:36 +00:00
|
|
|
int ReadFrame(FileReader &fp)
|
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;
|
|
|
|
uint8_t palette[768];
|
|
|
|
|
|
|
|
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:
|
|
|
|
{
|
2019-11-24 12:59:36 +00:00
|
|
|
fp.Read(palette, sizeof(palette));
|
|
|
|
fp.Read(&var_1C, sizeof(var_1C));
|
2019-08-31 07:47:15 +00:00
|
|
|
|
2019-11-03 04:00:08 +00:00
|
|
|
for (auto &c : palette)
|
|
|
|
c <<= 2;
|
|
|
|
|
2019-10-12 21:09:55 +00:00
|
|
|
paletteSetColorTable(ANIMPAL, palette);
|
2020-01-26 09:58:00 +00:00
|
|
|
videoSetPalette(0, ANIMPAL, Pal_Fullscreen);
|
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)
|
|
|
|
{
|
|
|
|
DebugOut("SOUND BUF FULL!\n");
|
2019-11-24 12:59:36 +00:00
|
|
|
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:
|
|
|
|
{
|
2019-11-24 09:03:19 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-20 18:54:31 +00:00
|
|
|
tileInvalidate(kMovieTile, -1, -1);
|
2019-08-31 07:47:15 +00:00
|
|
|
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-02-29 11:55:12 +00:00
|
|
|
CurFrame = TileFiles.tileCreate(kMovieTile, 320, 200);
|
|
|
|
if (CurFrame == nullptr) return;
|
|
|
|
|
2019-12-05 21:18:34 +00:00
|
|
|
int bDoFade = kTrue;
|
|
|
|
int hFx = -1;
|
2019-12-13 20:01:14 +00:00
|
|
|
auto fp = fileSystem.OpenFileReader(fileName, 0);
|
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-01-26 09:58:00 +00:00
|
|
|
videoSetPalette(0, ANIMPAL, Pal_Fullscreen);
|
2019-10-12 21:09:55 +00:00
|
|
|
|
2019-12-05 21:18:34 +00:00
|
|
|
// Read a frame in first
|
2019-08-31 07:47:15 +00:00
|
|
|
if (ReadFrame(fp))
|
|
|
|
{
|
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
|
|
|
|
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-01-05 09:48:44 +00:00
|
|
|
twod->ClearScreen();
|
2019-08-31 07:47:15 +00:00
|
|
|
rotatesprite(160 << 16, 100 << 16, z, angle, kMovieTile, 0, 1, 2, 0, 0, xdim - 1, ydim - 1);
|
|
|
|
|
|
|
|
if (bDoFade) {
|
|
|
|
bDoFade = DoFadeIn();
|
|
|
|
}
|
|
|
|
|
|
|
|
videoNextPage();
|
|
|
|
|
|
|
|
if (ReadFrame(fp) == 0) {
|
|
|
|
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
|