first parts of the updated movie code
Taylor Richards
mtrs at bellsouth.net
Sun Jun 8 21:33:51 EDT 2003
There are a few different parts to this patch but the basics are this:
- Command line support for not playing movies
- CFILE port
- use internal timer functions
- center movie on 1024x768 screen
- memory leak fixes
- built in to binary by default
- support for reading movies off of CD
Movies are compiled in by default but are still disabled at the moment.
Edit src/movie/movie.cpp and remove this line to enable movies
"Cmdline_play_movies = 0;". Headers have be rearranged to make a bit
more sense as part of the whole game. Although support for playing
movies off of the CDs is in support for the CDs themselves is not in the
game so this doesn't actually work yet. As part of the CD reading stuff
I added "strupr()" to src/platform/unix.cpp since files on the CD are
uppercase. The code for 8bit movies has been removed since it's not
used by us anyway. Audio support still does not exist.
Using OpenGL for the video is done but not yet tested on a Voodoo card.
Someone has volunteered but he can't do it until the middle of next
week. If anyone wants to try it out and has a Voodoo 3 or 5 let me know
and I'll send you the updated code.
For the audio, someone is going to have to pony up some ideas since all
I've managed to do is figure out how best to waste my time figuring out
what doesn't work.
This patch will go in tomorrow with the memory leak patch unless
problems are found.
Taylor
--
Taylor Richards <mtrs at bellsouth.net>
-------------- next part --------------
? movies.patch
Index: Makefile
===================================================================
RCS file: /cvs/cvsroot/freespace2/Makefile,v
retrieving revision 1.39
diff -u -r1.39 Makefile
--- Makefile 2003/05/25 02:30:42 1.39
+++ Makefile 2003/06/09 01:15:28
@@ -4,7 +4,6 @@
MACOSX=false
FS1=false
DEMO=false
-MVE=false
CC=g++
AR=ar
@@ -43,9 +42,6 @@
CFLAGS += -DRELEASE_REAL
endif
-ifeq ($(strip $(MVE)),true)
- CFLAGS += -DMVE
-endif
%.o: %.cpp
$(CC) -c -o $@ $< $(CFLAGS)
@@ -164,6 +160,11 @@
./src/model/modelinterp.cpp \
./src/model/modeloctant.cpp \
./src/model/modelread.cpp \
+ ./src/movie/movie.cpp \
+ ./src/movie/mveplayer.cpp \
+ ./src/movie/mvelib.cpp \
+ ./src/movie/decoder16.cpp \
+ ./src/movie/mve_audio.cpp \
./src/object/collidedebrisship.cpp \
./src/object/collidedebrisweapon.cpp \
./src/object/collideshipship.cpp \
@@ -278,16 +279,7 @@
./src/network/psnet.cpp \
./src/network/psnet2.cpp \
./src/network/stand_gui-unix.cpp \
- ./src/movie/movie.cpp \
./src/platform/unix.cpp
-
-ifeq ($(strip $(MVE)),true)
-CODE_SOURCES += \
- ./src/movie/mveplayer.cpp \
- ./src/movie/mvelib.cpp \
- ./src/movie/decoder16.cpp \
- ./src/movie/mve_audio.cpp
-endif
FS_SOURCES=./src/freespace2/freespace.cpp \
./src/freespace2/levelpaging.cpp \
Index: include/movie.h
===================================================================
RCS file: /cvs/cvsroot/freespace2/include/movie.h,v
retrieving revision 1.1
diff -u -r1.1 movie.h
--- include/movie.h 2002/07/24 00:20:41 1.1
+++ include/movie.h 2003/06/09 01:15:28
@@ -1,7 +1,9 @@
#ifndef MOVIE_H
#define MOVIE_H
-int movie_play(char *filename, int unknown = 0);
+#include "pstypes.h"
+
+int movie_play(char *filename, int cd_prompt = -1);
int movie_play_two(char *filename1, char *filename2);
#endif
Index: include/mvelib.h
===================================================================
RCS file: /cvs/cvsroot/freespace2/include/mvelib.h,v
retrieving revision 1.1
diff -u -r1.1 mvelib.h
--- include/mvelib.h 2002/07/27 21:05:15 1.1
+++ include/mvelib.h 2003/06/09 01:15:28
@@ -1,15 +1,17 @@
#ifndef INCLUDED_MVELIB_H
#define INCLUDED_MVELIB_H
-#include <stdio.h>
-#include <stdlib.h>
+#include "pstypes.h"
+
+struct CFILE;
+
/*
* structure for maintaining info on a MVEFILE stream
*/
typedef struct MVEFILE
{
- FILE *stream;
+ CFILE *stream;
unsigned char *cur_chunk;
int buf_size;
int cur_fill;
@@ -75,7 +77,7 @@
/*
* open an MVE stream
*/
-MVESTREAM *mve_open(const char *filename);
+MVESTREAM *mve_open(char *filename);
/*
* close an MVE stream
@@ -96,5 +98,9 @@
* play next chunk
*/
int mve_play_next_chunk(MVESTREAM *movie);
+
+void initializeMovie(MVESTREAM *mve);
+void playMovie(MVESTREAM *mve);
+void shutdownMovie();
#endif /* INCLUDED_MVELIB_H */
Index: include/unix.h
===================================================================
RCS file: /cvs/cvsroot/freespace2/include/unix.h,v
retrieving revision 1.17
diff -u -r1.17 unix.h
--- include/unix.h 2002/06/09 03:16:04 1.17
+++ include/unix.h 2003/06/09 01:15:28
@@ -42,6 +42,7 @@
#define CALLBACK
extern void strlwr (char *str);
+extern void strupr (char *str);
extern int filelength (int fd);
extern int MulDiv (int, int, int);
Index: src/movie/movie.cpp
===================================================================
RCS file: /cvs/cvsroot/freespace2/src/movie/movie.cpp,v
retrieving revision 1.3
diff -u -r1.3 movie.cpp
--- src/movie/movie.cpp 2003/01/30 19:56:52 1.3
+++ src/movie/movie.cpp 2003/06/09 01:15:29
@@ -1,57 +1,84 @@
-#include <stdio.h>
-#include <ctype.h>
+#include "pstypes.h"
#include "mvelib.h"
-#include "mve_audio.h"
+#include "movie.h"
#include "cutscenes.h"
#include "freespace.h"
+#include "mouse.h"
+#include "sound.h"
+#include "cmdline.h"
+#include "gamesequence.h"
+#include "mainhallmenu.h"
-extern void initializeMovie(MVESTREAM *mve);
-extern void playMovie(MVESTREAM *mve);
-extern void shutdownMovie(MVESTREAM *mve);
-
-int movie_play(char *filename, int unknown)
+int movie_play(char *filename, int cd_prompt)
{
- fprintf (stderr, "Playing MVE file %s\n",filename);
-
- // mark the mve as viewable in the techroom if in a campaign
+ // mark the movie as viewable in the techroom if in a campaign
if (Game_mode & GM_CAMPAIGN_MODE) {
cutscene_mark_viewable(filename);
}
-#ifdef MVE
- int i;
- char lower_name[MAX_FILENAME_LEN] = "";
-
- // lowercase filename to avoid loading problems from mixed case calls
- strcpy( lower_name, filename );
- for (i=0; i<(int)strlen(lower_name); i++ ){
- lower_name[i] = char(tolower(lower_name[i]));
- }
+ // REMOVE_ME: to enable movie playing remove this line
+ Cmdline_play_movies = 0;
+
+ if (Cmdline_play_movies) {
- char file[200];
-// snprintf (file, 200, "movies/%s", filename);
- snprintf (file, 200, "Data/Movies/%s", lower_name);
- MVESTREAM *mve = mve_open(file);
- if (mve == NULL)
- {
- fprintf(stderr, "can't open MVE file '%s'\n", file);
- return -1;
+ MVESTREAM *mve;
+
+ printf("Playing movie: %s\n", filename);
+
+ // umm, yeah
+ if ( cd_prompt == -1 )
+ cd_prompt = 0;
+
+ // look for correct CD when viewing movies in the tech room
+ if (gameseq_get_state() == GS_STATE_VIEW_CUTSCENES) {
+ cutscenes_validate_cd(filename, cd_prompt);
+ }
+
+ mve = mve_open(filename);
+
+ if (mve) {
+ // kill all background sounds
+ game_stop_looped_sounds();
+ main_hall_stop_music();
+ main_hall_stop_ambient();
+
+ // clear the screen and hide the mouse cursor
+ Mouse_hidden++;
+ gr_reset_clip();
+ gr_clear();
+ gr_flip();
+ gr_zbuffer_clear(1); // G400, blah
+
+ // ready to play...
+ initializeMovie(mve);
+ playMovie(mve);
+
+ // ...done playing, close the mve and show the cursor again
+ shutdownMovie();
+ mve_close(mve);
+
+ Mouse_hidden--;
+ main_hall_start_ambient();
+ } else {
+ printf("Can't open movie file: '%s'\n", filename);
+ return -1;
+ }
+
+ } else {
+ printf("Movies are disabled, skipping...\n");
}
- initializeMovie(mve);
- playMovie(mve);
- shutdownMovie(mve);
-
- mve_close(mve);
-#else
- fprintf(stderr, "STUB: if movie support existed, you'd be watching %s\n", filename);
-#endif
return 1;
}
int movie_play_two(char *filename1, char *filename2)
{
- fprintf(stderr, "STUB: if movie support existed, you'd be watching %s, followed by %s\n", filename1, filename2);
+ // make sure the first movie played correctly, then play the second one
+ if ((movie_play(filename1, 0)) > 0) {
+ movie_play(filename2, 0);
+ } else {
+ printf("Not playing additional movie: %s\n", filename2);
+ }
return 1;
}
Index: src/movie/mvelib.cpp
===================================================================
RCS file: /cvs/cvsroot/freespace2/src/movie/mvelib.cpp,v
retrieving revision 1.1
diff -u -r1.1 mvelib.cpp
--- src/movie/mvelib.cpp 2002/07/27 21:05:16 1.1
+++ src/movie/mvelib.cpp 2003/06/09 01:15:29
@@ -1,5 +1,6 @@
-#include <string.h>
+#include "pstypes.h"
#include "mvelib.h"
+#include "cfile.h"
static const char MVE_HEADER[] = "Interplay MVE File\x1A";
static const short MVE_HDRCONST1 = 0x001A;
@@ -17,7 +18,7 @@
*/
static MVEFILE *_mvefile_alloc(void);
static void _mvefile_free(MVEFILE *movie);
-static int _mvefile_open(MVEFILE *movie, const char *filename);
+static int _mvefile_open(MVEFILE *movie, char *filename);
static int _mvefile_read_header(MVEFILE *movie);
static void _mvefile_set_buffer_size(MVEFILE *movie, int buf_size);
static int _mvefile_fetch_next_chunk(MVEFILE *movie);
@@ -27,7 +28,7 @@
*/
static MVESTREAM *_mvestream_alloc(void);
static void _mvestream_free(MVESTREAM *movie);
-static int _mvestream_open(MVESTREAM *movie, const char *filename);
+static int _mvestream_open(MVESTREAM *movie, char *filename);
/************************************************************
* public MVEFILE functions
@@ -36,7 +37,7 @@
/*
* open an MVE file
*/
-MVEFILE *mvefile_open(const char *filename)
+MVEFILE *mvefile_open(char *filename)
{
MVEFILE *file;
@@ -174,7 +175,7 @@
/*
* open an MVE stream
*/
-MVESTREAM *mve_open(const char *filename)
+MVESTREAM *mve_open(char *filename)
{
MVESTREAM *movie;
@@ -278,7 +279,7 @@
{
/* free the stream */
if (movie->stream)
- fclose(movie->stream);
+ cfclose(movie->stream);
movie->stream = NULL;
/* free the buffer */
@@ -298,12 +299,49 @@
/*
* open the file stream in thie object
*/
-static int _mvefile_open(MVEFILE *file, const char *filename)
+static int _mvefile_open(MVEFILE *file, char *filename)
{
- if (! (file->stream = fopen(filename, "rb")))
- return 0;
-
- return 1;
+ int cf_opened;
+ char lower_name[MAX_FILENAME_LEN];
+ char upper_name[MAX_FILENAME_LEN];
+
+ // Frist, try to open lowercase filename (in case it's on the HD)
+ // Second, try to load upper case filename (will pick off of CD if not on HD)
+ // Third, try loading the filename passed, total overkill
+
+ // lower case filename for checking
+ strncpy(lower_name, filename, strlen(filename)+1);
+ strlwr(lower_name);
+ // upper case filename for checking
+ strncpy(upper_name, filename, strlen(filename)+1);
+ strupr(upper_name);
+
+ // NOTE: CF_TYPE *must* be ANY to get movies off of the CDs
+ while (1) {
+ // lower case filename check
+ if ( (file->stream = cfopen(lower_name, "rb", CFILE_NORMAL, CF_TYPE_ANY)) ) {
+ cf_opened = 1;
+ break;
+ }
+
+ // upper case filename check
+ if ( (file->stream = cfopen(upper_name, "rb", CFILE_NORMAL, CF_TYPE_ANY)) ) {
+ cf_opened = 1;
+ break;
+ }
+
+ // passed filename check
+ if ( (file->stream = cfopen(filename, "rb", CFILE_NORMAL, CF_TYPE_ANY)) ) {
+ cf_opened = 1;
+ break;
+ }
+
+ // uh-oh, couldn't open
+ cf_opened = 0;
+ break;
+ }
+
+ return cf_opened;
}
/*
@@ -318,7 +356,7 @@
return 0;
/* check the file is long enough */
- if (fread(buffer, 1, 26, movie->stream) < 26)
+ if (cfread(buffer, 1, 26, movie->stream) < 26)
return 0;
/* check the signature */
@@ -375,7 +413,7 @@
return 0;
/* fail if we can't read the next segment descriptor */
- if (fread(buffer, 1, 4, movie->stream) < 4)
+ if (cfread(buffer, 1, 4, movie->stream) < 4)
return 0;
/* pull out the next length */
@@ -385,7 +423,7 @@
_mvefile_set_buffer_size(movie, length);
/* read the chunk */
- if (fread(movie->cur_chunk, 1, length, movie->stream) < length)
+ if (cfread(movie->cur_chunk, 1, length, movie->stream) < length)
return 0;
movie->cur_fill = length;
movie->next_segment = 0;
@@ -436,12 +474,14 @@
/* clear context and handlers */
movie->context = NULL;
memset(movie->handlers, 0, sizeof(movie->handlers));
+
+ free(movie);
}
/*
* open an MVESTREAM object
*/
-static int _mvestream_open(MVESTREAM *movie, const char *filename)
+static int _mvestream_open(MVESTREAM *movie, char *filename)
{
movie->movie = mvefile_open(filename);
Index: src/movie/mveplayer.cpp
===================================================================
RCS file: /cvs/cvsroot/freespace2/src/movie/mveplayer.cpp,v
retrieving revision 1.2
diff -u -r1.2 mveplayer.cpp
--- src/movie/mveplayer.cpp 2002/07/27 21:46:18 1.2
+++ src/movie/mveplayer.cpp 2003/06/09 01:15:29
@@ -1,48 +1,16 @@
-#include <string.h>
-#include <errno.h>
-#include <time.h>
-#include <unistd.h>
-#include <sys/time.h>
-
-#include "mvelib.h"
#include "bmpman.h"
+#include "pstypes.h"
+#include "mvelib.h"
#include "2d.h"
#include "mve_audio.h"
#include "key.h"
#include "osapi.h"
-
-#ifndef MIN
-#define MIN(a,b) ((a)<(b)?(a):(b))
-#endif
+#include "timer.h"
static int g_spdFactorNum=0;
static int g_spdFactorDenom=10;
-static int playing = 1;
-
-void initializeMovie(MVESTREAM *mve);
-void playMovie(MVESTREAM *mve);
-void shutdownMovie(MVESTREAM *mve);
-
-#if 0
-static int doPlay(const char *filename)
-{
- MVESTREAM *mve = mve_open(filename);
- if (mve == NULL)
- {
- fprintf(stderr, "can't open MVE file '%s'\n", filename);
- return 1;
- }
-
- initializeMovie(mve);
- playMovie(mve);
- shutdownMovie(mve);
-
- mve_close(mve);
-
- return 0;
-}
-#endif
+static int mve_playing;
static short get_short(unsigned char *data)
{
@@ -88,7 +56,7 @@
*/
static int micro_frame_delay=0;
static int timer_started=0;
-static struct timeval timer_expire = {0, 0};
+static fix timer_expire;
static int create_timer_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context)
{
@@ -107,50 +75,27 @@
static void timer_start(void)
{
- int nsec=0;
- gettimeofday(&timer_expire, NULL);
- timer_expire.tv_usec += micro_frame_delay;
- if (timer_expire.tv_usec > 1000000)
- {
- nsec = timer_expire.tv_usec / 1000000;
- timer_expire.tv_sec += nsec;
- timer_expire.tv_usec -= nsec*1000000;
- }
+ timer_expire = timer_get_milliseconds();
+ timer_expire += micro_frame_delay / 1000;
+
timer_started=1;
}
static void do_timer_wait(void)
{
- int nsec=0;
- struct timespec ts, tsRem;
- struct timeval tv;
- if (! timer_started)
- return;
+ fix tv, ts;
- gettimeofday(&tv, NULL);
- if (tv.tv_sec > timer_expire.tv_sec)
- goto end;
- else if (tv.tv_sec == timer_expire.tv_sec && tv.tv_usec >= timer_expire.tv_usec)
+ tv = timer_get_milliseconds();
+
+ if (tv > timer_expire)
goto end;
- ts.tv_sec = timer_expire.tv_sec - tv.tv_sec;
- ts.tv_nsec = 1000 * (timer_expire.tv_usec - tv.tv_usec);
- if (ts.tv_nsec < 0)
- {
- ts.tv_nsec += 1000000000UL;
- --ts.tv_sec;
- }
- if (nanosleep(&ts, &tsRem) == -1 && errno == EINTR)
- exit(1);
+ ts = timer_expire - tv;
+
+ Sleep(ts);
end:
- timer_expire.tv_usec += micro_frame_delay;
- if (timer_expire.tv_usec > 1000000)
- {
- nsec = timer_expire.tv_usec / 1000000;
- timer_expire.tv_sec += nsec;
- timer_expire.tv_usec -= nsec*1000000;
- }
+ timer_expire += micro_frame_delay / 1000;
}
/*************************
@@ -361,11 +306,10 @@
* video handlers
*************************/
int g_width, g_height;
-void *g_vBackBuf1, *g_vBackBuf2;
+void *g_vBackBuf1 = NULL;
+void *g_vBackBuf2 = NULL;
+ushort *pixelbuf = NULL;
-#if 0
-static SDL_Surface *g_screen;
-#endif
static int g_screenWidth, g_screenHeight;
static unsigned char g_palette[768];
static unsigned char *g_pCurMap=NULL;
@@ -386,6 +330,7 @@
}
if (minor > 1) {
+ // all FS movies are truecolor
truecolor = get_short(data+6);
} else {
truecolor = 0;
@@ -395,12 +340,12 @@
g_height = h << 3;
/* TODO: * 4 causes crashes on some files */
- g_vBackBuf1 = malloc(g_width * g_height * 8);
- if (truecolor) {
+ // don't malloc more than once
+ if (g_vBackBuf1 == NULL)
+ g_vBackBuf1 = malloc(g_width * g_height * 8);
+ // don't do this more than once either
+ if (g_vBackBuf2 == NULL)
g_vBackBuf2 = (unsigned short *)g_vBackBuf1 + (g_width * g_height);
- } else {
- g_vBackBuf2 = (unsigned char *)g_vBackBuf1 + (g_width * g_height);
- }
memset(g_vBackBuf1, 0, g_width * g_height * 4);
@@ -411,77 +356,16 @@
return 1;
}
-#if 0
-static int do_sdl_events()
-{
- SDL_Event event;
- int retr = 0;
- while (SDL_PollEvent(&event)) {
- switch(event.type) {
- case SDL_QUIT:
- exit(0);
- case SDL_KEYDOWN:
- if (event.key.keysym.sym == SDLK_ESCAPE)
- exit(0);
- break;
- case SDL_KEYUP:
- retr = 1;
- break;
- case SDL_MOUSEBUTTONDOWN:
-/*
- if (event.button.button == SDL_BUTTON_LEFT) {
- printf("GRID: %d,%d (pix:%d,%d)\n",
- event.button.x / 16, event.button.y / 8,
- event.button.x, event.button.y);
- }
-*/
- break;
- default:
- break;
- }
- }
-
- return retr;
-}
-#endif
-
-static unsigned short stab[65536];
-static unsigned int itab[65536];
-static int table_inited;
-
-unsigned short *pixelbuf;
static void ConvertAndDraw()
{
- int i;
- unsigned short *pDests;
- unsigned int *pDesti;
- unsigned short *pSrcs;
+ ushort *pDests;
+ ushort *pSrcs;
unsigned char *pixels = (unsigned char *)g_vBackBuf1;
int x, y;
-if (g_truecolor) {
- pSrcs = (unsigned short *)pixels;
-
- /*
- if (table_inited == 0) {
- int r, g, b;
-
- table_inited = 1;
-
- for (i = 0; i < 65536; i++) {
- r = (i & 0x7c00) >> 10;
- g = (i & 0x03e0) >> 5;
- b = (i & 0x001f) >> 0;
-
- stab[i] = 1 << 15;
- stab[i] |= (r << 10)&0x7c00;
- stab[i] |= (g << 5)&0x03e0;
- stab[i] |= (b << 0)&0x001f;
- }
- }
- */
-
+ pSrcs = (ushort *)pixels;
+
pDests = pixelbuf;
if (g_screenWidth > g_width) {
@@ -493,83 +377,34 @@
for (y=0; y<g_height; y++) {
for (x = 0; x < g_width; x++) {
- //pDests[x] = stab[*pSrcs];
pDests[x] = (1<<15)|*pSrcs;
pSrcs++;
}
pDests += g_screenWidth;
}
-} else {
-#if 0
-/* original slow 8 bit code */
- int i;
- unsigned char *pal = g_palette;
- unsigned char *pDest;
- unsigned char *pixels = g_vBackBuf1;
- SDL_Surface *screenSprite, *initSprite;
- SDL_Rect renderArea;
- int x, y;
-
- initSprite = SDL_CreateRGBSurface(SDL_SWSURFACE, g_width, g_height, 8, 0, 0, 0, 0);
-
- if (!g_truecolor) {
- for(i = 0; i < 256; i++)
- {
- initSprite->format->palette->colors[i].r = (*pal++) << 2;
- initSprite->format->palette->colors[i].g = (*pal++) << 2;
- initSprite->format->palette->colors[i].b = (*pal++) << 2;
- initSprite->format->palette->colors[i].unused = 0;
- }
- }
-
- pDest = initSprite->pixels;
- for (i=0; i<g_height; i++)
- {
- memcpy(pDest, pixels, g_width * (g_truecolor?2:1));
- pixels += g_width* (g_truecolor?2:1);
- pDest += initSprite->pitch;
- }
-
- screenSprite = SDL_DisplayFormat(initSprite);
- SDL_FreeSurface(initSprite);
-
- if (g_screenWidth > screenSprite->w) x = (g_screenWidth - screenSprite->w) >> 1;
- else x=0;
- if (g_screenHeight > screenSprite->h) y = (g_screenHeight - screenSprite->h) >> 1;
- else y=0;
- renderArea.x = x;
- renderArea.y = y;
- renderArea.w = MIN(g_screenWidth - x, screenSprite->w);
- renderArea.h = MIN(g_screenHeight - y, screenSprite->h);
- SDL_BlitSurface(screenSprite, NULL, g_screen, &renderArea);
-
- SDL_FreeSurface(screenSprite);
-#endif
}
-}
-
static int display_video_handler(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context)
{
ConvertAndDraw();
-#if 0
-
- SDL_Flip(g_screen);
-
- do_sdl_events();
-#endif
+
/* DDOI - This is probably really fricking slow */
int bitmap = bm_create (16, g_screenWidth, g_screenHeight, pixelbuf, 0);
gr_set_bitmap (bitmap);
- gr_bitmap (0, 0);
+ // centers on 1024x768, fills on 640x480
+ gr_bitmap ((gr_screen.max_w - g_screenWidth) / 2, (gr_screen.max_h - g_screenHeight) / 2);
bm_release (bitmap);
gr_flip ();
#ifdef PLAT_UNIX
os_poll (); /* DDOI - run event loop(s) */
#endif
- if (key_check (KEY_ESC)) playing = 0;
+ int k = key_inkey();
+ if ( k == KEY_ESC ) {
+ mve_playing = 0;
+ }
+
return 1;
}
@@ -578,11 +413,11 @@
short width, height;
width = get_short(data);
height = get_short(data+2);
-#if 0
- g_screen = SDL_SetVideoMode(width, height, 16, SDL_ANYFORMAT|SDL_DOUBLEBUF);
-#endif
+
// DDOI - Allocate RGB565 pixel buffer
- pixelbuf = (unsigned short *)malloc (width * height * 2);
+ // don't malloc more than once
+ if (pixelbuf == NULL)
+ pixelbuf = (unsigned short *)malloc (width * height * 2);
g_screenWidth = width;
g_screenHeight = height;
memset(g_palette, 0, 768);
@@ -631,13 +466,7 @@
}
/* convert the frame */
- if (g_truecolor) {
decodeFrame16((unsigned char *)g_vBackBuf1, g_pCurMap, g_nMapLength, data+14, len-14);
-#if 0
- } else {
- decodeFrame8(g_vBackBuf1, g_pCurMap, g_nMapLength, data+14, len-14);
-#endif
- }
return 1;
}
@@ -669,13 +498,15 @@
mve_set_handler(mve, 0x0c, video_palette_handler);
mve_set_handler(mve, 0x0f, video_codemap_handler);
mve_set_handler(mve, 0x11, video_data_handler);
+
+ mve_playing = 1;
}
void playMovie(MVESTREAM *mve)
{
int init_timer=0;
int cont=1;
- while (cont && playing)
+ while (cont && mve_playing)
{
cont = mve_play_next_chunk(mve);
if (micro_frame_delay && !init_timer)
@@ -688,7 +519,21 @@
}
}
-void shutdownMovie(MVESTREAM *mve)
+void shutdownMovie()
{
- free (pixelbuf);
+ if (pixelbuf != NULL) {
+ free(pixelbuf);
+ pixelbuf = NULL;
+ }
+
+ // if g_vBackBuf2 gets free'd then that takes care of g_vBackBuf1 as well
+ if (g_vBackBuf2 != NULL && g_vBackBuf1 != NULL) {
+ free(g_vBackBuf2);
+ g_vBackBuf2 = NULL;
+ g_vBackBuf1 = NULL;
+ // depends on when you exit as to whether this is required
+ } else if (g_vBackBuf1 != NULL) {
+ free(g_vBackBuf1);
+ g_vBackBuf1 = NULL;
+ }
}
Index: src/platform/unix.cpp
===================================================================
RCS file: /cvs/cvsroot/freespace2/src/platform/unix.cpp,v
retrieving revision 1.17
diff -u -r1.17 unix.cpp
--- src/platform/unix.cpp 2003/05/04 05:00:12 1.17
+++ src/platform/unix.cpp 2003/06/09 01:15:29
@@ -17,6 +17,11 @@
while (*str) {*str = tolower (*str); str++; }
}
+void strupr (char * str)
+{
+ while (*str) {*str = toupper (*str); str++; }
+}
+
int filelength (int fd)
{
struct stat buf;
More information about the freespace2
mailing list