MVE: Refactoring code

Merge libmve.h into mvelib.h
This commit is contained in:
Azamat H. Hackimov 2024-05-05 01:24:44 +03:00
parent b94458f561
commit 99ec2e3a5e
4 changed files with 81 additions and 148 deletions

View File

@ -1,62 +0,0 @@
/*
* Copyright (C) 2002-2024 D2X Project
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef _LIBMVE_H
#define _LIBMVE_H
#include "SystemInterfaces.h"
#define MVE_ERR_EOF 1
typedef struct {
int screenWidth;
int screenHeight;
int width;
int height;
int truecolor;
} MVE_videoSpec;
int MVE_rmPrepMovie(void *stream, int x, int y, int track);
int MVE_rmStepMovie(void);
void MVE_rmHoldMovie(void);
void MVE_rmEndMovie(void);
void MVE_getVideoSpec(MVE_videoSpec *vSpec);
void MVE_sndInit(ISoundDevice *lpDS);
void MVE_sndInit(int x);
typedef unsigned int (*mve_cb_Read)(void *stream, void *buffer, unsigned int count);
typedef void *(*mve_cb_Alloc)(unsigned int size);
typedef void (*mve_cb_Free)(void *ptr);
typedef void (*mve_cb_ShowFrame)(unsigned char *buffer, unsigned int bufw, unsigned int bufh, unsigned int sx,
unsigned int sy, unsigned int w, unsigned int h, unsigned int dstx, unsigned int dsty,
unsigned int hicolor);
typedef void (*mve_cb_SetPalette)(unsigned char *p, unsigned int start, unsigned int count);
void MVE_ioCallbacks(mve_cb_Read io_read);
void MVE_memCallbacks(mve_cb_Alloc mem_alloc, mve_cb_Free mem_free);
void MVE_sfCallbacks(mve_cb_ShowFrame showframe);
void MVE_palCallbacks(mve_cb_SetPalette setpalette);
void MVE_ReleaseMem(void);
#endif /* _LIBMVE_H */

View File

@ -21,7 +21,22 @@
#include <cstdio>
#include <cstdlib>
#include "libmve.h"
#include "SystemInterfaces.h"
/* callback for reading stream */
typedef unsigned int (*mve_cb_Read)(void *stream, void *buffer, unsigned int count);
/* callback for memore allocating */
typedef void *(*mve_cb_Alloc)(unsigned int size);
/* callback for memory freeing */
typedef void (*mve_cb_Free)(void *ptr);
/* callback for showing frame */
typedef void (*mve_cb_ShowFrame)(unsigned char *buffer, unsigned int bufw, unsigned int bufh, unsigned int sx,
unsigned int sy, unsigned int w, unsigned int h, unsigned int dstx, unsigned int dsty,
unsigned int hicolor);
/* callback for setting palette */
typedef void (*mve_cb_SetPalette)(unsigned char *p, unsigned int start, unsigned int count);
/* callback for segment type */
typedef int (*MVESEGMENTHANDLER)(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context);
extern mve_cb_Read mve_read;
extern mve_cb_Alloc mve_alloc;
@ -29,9 +44,17 @@ extern mve_cb_Free mve_free;
extern mve_cb_ShowFrame mve_showframe;
extern mve_cb_SetPalette mve_setpalette;
/*
* structure for maintaining info on a MVEFILE stream
*/
#define MVE_ERR_EOF 1
typedef struct {
int screenWidth;
int screenHeight;
int width;
int height;
int truecolor;
} MVE_videoSpec;
/* structure for maintaining info on a MVEFILE stream */
typedef struct MVEFILE {
void *stream;
unsigned char *cur_chunk;
@ -40,89 +63,71 @@ typedef struct MVEFILE {
int next_segment;
} MVEFILE;
/*
* open a .MVE file
*/
MVEFILE *mvefile_open(void *stream);
/*
* close a .MVE file
*/
void mvefile_close(MVEFILE *movie);
/*
* get size of next segment in chunk (-1 if no more segments in chunk)
*/
int mvefile_get_next_segment_size(MVEFILE *movie);
/*
* get type of next segment in chunk (0xff if no more segments in chunk)
*/
unsigned char mvefile_get_next_segment_major(MVEFILE *movie);
/*
* get subtype (version) of next segment in chunk (0xff if no more segments in
* chunk)
*/
unsigned char mvefile_get_next_segment_minor(MVEFILE *movie);
/*
* see next segment (return NULL if no next segment)
*/
unsigned char *mvefile_get_next_segment(MVEFILE *movie);
/*
* advance to next segment
*/
void mvefile_advance_segment(MVEFILE *movie);
/*
* fetch the next chunk (return 0 if at end of stream)
*/
int mvefile_fetch_next_chunk(MVEFILE *movie);
/*
* callback for segment type
*/
typedef int (*MVESEGMENTHANDLER)(unsigned char major, unsigned char minor, unsigned char *data, int len, void *context);
/*
* structure for maintaining an MVE stream
*/
/* structure for maintaining an MVE stream */
typedef struct MVESTREAM {
MVEFILE *movie;
void *context;
MVESEGMENTHANDLER handlers[32];
} MVESTREAM;
/*
* open an MVE stream
*/
int MVE_rmPrepMovie(void *stream, int x, int y, int track);
int MVE_rmStepMovie();
void MVE_rmHoldMovie();
void MVE_rmEndMovie();
void MVE_getVideoSpec(MVE_videoSpec *vSpec);
void MVE_sndInit(ISoundDevice *lpDS);
void MVE_sndInit(int x);
void MVE_ioCallbacks(mve_cb_Read io_read);
void MVE_memCallbacks(mve_cb_Alloc mem_alloc, mve_cb_Free mem_free);
void MVE_sfCallbacks(mve_cb_ShowFrame showframe);
void MVE_palCallbacks(mve_cb_SetPalette setpalette);
// Low-level functions
/* open an MVE file */
MVEFILE *mvefile_open(void *stream);
/* close an MVE file */
void mvefile_close(MVEFILE *movie);
/* get size of next segment in chunk (-1 if no more segments in chunk) */
int mvefile_get_next_segment_size(MVEFILE *movie);
/* get type of next segment in chunk (0xff if no more segments in chunk) */
unsigned char mvefile_get_next_segment_major(MVEFILE *movie);
/* get subtype (version) of next segment in chunk (0xff if no more segments in chunk) */
unsigned char mvefile_get_next_segment_minor(MVEFILE *movie);
/* see next segment (return NULL if no next segment) */
unsigned char *mvefile_get_next_segment(MVEFILE *movie);
/* advance to next segment */
void mvefile_advance_segment(MVEFILE *movie);
/* fetch the next chunk (return 0 if at end of stream) */
int mvefile_fetch_next_chunk(MVEFILE *movie);
/* open an MVE stream */
MVESTREAM *mve_open(void *stream);
/*
* close an MVE stream
*/
/* close an MVE stream */
void mve_close(MVESTREAM *movie);
/*
* reset an MVE stream
*/
/* reset an MVE stream */
void mve_reset(MVESTREAM *movie);
/*
* set segment type handler
*/
/* set segment type handler */
void mve_set_handler(MVESTREAM *movie, unsigned char major, MVESEGMENTHANDLER handler);
/*
* set segment handler context
*/
/* set segment handler context */
void mve_set_handler_context(MVESTREAM *movie, void *context);
/*
* play next chunk
*/
/* play next chunk */
int mve_play_next_chunk(MVESTREAM *movie);
#endif /* INCLUDED_MVELIB_H */

View File

@ -32,7 +32,6 @@
#endif
#include "decoders.h"
#include "libmve.h"
#include "mvelib.h"
#include "mve_audio.h"
#include "SystemInterfaces.h"
@ -480,7 +479,8 @@ static int display_video_handler(unsigned char major, unsigned char minor, unsig
if (g_destY == -1) // center it
g_destY = (g_screenHeight - g_height) >> 1;
mve_showframe((unsigned char *)g_vBackBuf1, g_width, g_height, 0, 0, g_width, g_height, g_destX, g_destY, g_truecolor);
mve_showframe((unsigned char *)g_vBackBuf1, g_width, g_height, 0, 0, g_width, g_height, g_destX, g_destY,
g_truecolor);
g_frameUpdated = 1;
@ -574,16 +574,7 @@ void MVE_sfCallbacks(mve_cb_ShowFrame showframe) { mve_showframe = showframe; }
void MVE_palCallbacks(mve_cb_SetPalette setpalette) { mve_setpalette = setpalette; }
void MVE_ReleaseMem() {
MVE_rmEndMovie();
// ioRelease();
// sndRelease();
// nfRelease();
}
int MVE_rmPrepMovie(void *src, int x, int y, int track) {
int i;
if (mve) {
mve_reset(mve);
return 0;
@ -597,7 +588,7 @@ int MVE_rmPrepMovie(void *src, int x, int y, int track) {
g_destX = x;
g_destY = y;
for (i = 0; i < 32; i++)
for (int i = 0; i < 32; i++)
mve_set_handler(mve, i, default_seg_handler);
mve_set_handler(mve, MVE_OPCODE_ENDOFSTREAM, end_movie_handler);

View File

@ -33,7 +33,7 @@
#include "movie.h"
//#include "mvelibw.h"
#include "libmve.h"
#include "mvelib.h"
#include "pserror.h"
#include "renderer.h"
#include "application.h"
@ -377,7 +377,6 @@ int mve_PlayMovie(const char *pMovieName, oeApplication *pApp) {
// cleanup and shutdown
MVE_rmEndMovie();
MVE_ReleaseMem();
// reset sound
mve_CloseSound(soundDevice);
@ -618,7 +617,7 @@ bool mve_SequenceClose(intptr_t hMovie, void *hFile) {
return false;
// TODO MVE_frClose((MVE_frStream)hMovie);
MVE_ReleaseMem();
MVE_rmEndMovie();
fclose((FILE *)hFile);
// free our bitmap