2007-06-28 10:47:08 -07:00
|
|
|
/*
|
|
|
|
* Frame.h
|
|
|
|
*
|
|
|
|
* The framework library initialisation and shutdown routines.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#ifndef _frame_h
|
|
|
|
#define _frame_h
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
2006-08-26 08:21:40 -07:00
|
|
|
# include "config.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
#endif
|
|
|
|
|
2006-07-01 12:11:05 -07:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
# ifdef _DEBUG
|
|
|
|
# define _CRTDBG_MAP_ALLOC
|
|
|
|
# include <stdlib.h>
|
|
|
|
# include <crtdbg.h>
|
|
|
|
# endif // _DEBUG
|
|
|
|
#endif
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
#ifdef WIN32
|
2006-08-23 06:01:17 -07:00
|
|
|
# ifdef __MINGW32__
|
2006-08-23 05:19:17 -07:00
|
|
|
# include <w32api.h>
|
|
|
|
# define _WIN32_IE IE5
|
|
|
|
# endif
|
|
|
|
# include <windows.h>
|
2007-06-28 10:47:08 -07:00
|
|
|
#endif
|
|
|
|
|
2006-06-16 12:10:23 -07:00
|
|
|
#define MAX_MODS 100
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
/* Linux specific stuff */
|
|
|
|
#ifndef WIN32
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2006-08-23 05:19:17 -07:00
|
|
|
#define MAX_PATH 260
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
char *unix_path(const char *path);
|
|
|
|
FILE *unix_fopen(const char *filename, const char *mode);
|
|
|
|
|
|
|
|
#define fopen unix_fopen
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define InitializeCriticalSection(x)
|
|
|
|
#define DeleteCriticalSection(x)
|
|
|
|
#define EnterCriticalSection(x)
|
|
|
|
#define LeaveCriticalSection(x)
|
|
|
|
|
2006-08-21 09:49:32 -07:00
|
|
|
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
|
|
|
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
|
|
|
|
|
2006-03-17 17:59:59 -08:00
|
|
|
#include "macros.h"
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
#include "types.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "mem.h"
|
|
|
|
|
|
|
|
#include "input.h"
|
|
|
|
#include "font.h"
|
|
|
|
#include "heap.h"
|
|
|
|
#include "treap.h"
|
|
|
|
#include "fractions.h"
|
|
|
|
#include "trig.h"
|
|
|
|
#include "frameresource.h"
|
|
|
|
#include "strres.h"
|
|
|
|
#include "block.h"
|
|
|
|
#include "listmacs.h"
|
|
|
|
|
2006-06-16 12:10:23 -07:00
|
|
|
#ifdef _MSC_VER
|
2006-06-03 16:46:03 -07:00
|
|
|
#include "win32fixes.h"
|
|
|
|
#endif
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
/* Initialise the frame work library */
|
|
|
|
extern BOOL frameInitialise(HANDLE hInstance, // The windows application instance
|
|
|
|
STRING *pWindowName, // The text to appear in the window title bar
|
|
|
|
UDWORD width, // The display width
|
|
|
|
UDWORD height, // The display height
|
|
|
|
UDWORD bitDepth, // The display bit depth
|
|
|
|
BOOL fullScreen, // Whether to start full screen or windowed
|
|
|
|
BOOL bVidMem); // Whether to put surfaces in video memory
|
|
|
|
|
|
|
|
/* Shut down the framework library.
|
|
|
|
* This clears up all the Direct Draw stuff and ensures
|
|
|
|
* that Windows gets restored properly after Full screen mode.
|
|
|
|
*/
|
|
|
|
extern void frameShutDown(void);
|
|
|
|
|
|
|
|
/* The current status of the framework */
|
|
|
|
typedef enum _frame_status
|
|
|
|
{
|
|
|
|
FRAME_OK, // Everything normal
|
|
|
|
FRAME_KILLFOCUS, // The main app window has lost focus (might well want to pause)
|
|
|
|
FRAME_SETFOCUS, // The main app window has focus back
|
|
|
|
FRAME_QUIT, // The main app window has been told to quit
|
|
|
|
} FRAME_STATUS;
|
|
|
|
|
|
|
|
/* Call this each cycle to allow the framework to deal with
|
|
|
|
* windows messages, and do general house keeping.
|
|
|
|
*
|
|
|
|
* Returns FRAME_STATUS.
|
|
|
|
*/
|
|
|
|
extern FRAME_STATUS frameUpdate(void);
|
|
|
|
|
|
|
|
/* If cursor on is TRUE the windows cursor will be displayed over the game window
|
|
|
|
* (and in full screen mode). If it is FALSE the cursor will not be displayed.
|
|
|
|
*/
|
|
|
|
extern void frameShowCursor(BOOL cursorOn);
|
|
|
|
|
|
|
|
/* Set the current cursor from a cursor handle */
|
|
|
|
extern void frameSetCursor(HCURSOR hNewCursor);
|
|
|
|
|
|
|
|
/* Set the current cursor from a Resource ID
|
|
|
|
* This is the same as calling:
|
|
|
|
* frameSetCursor(LoadCursor(MAKEINTRESOURCE(resID)));
|
|
|
|
* but with a bit of extra error checking.
|
|
|
|
*/
|
|
|
|
extern void frameSetCursorFromRes(WORD resID);
|
|
|
|
|
|
|
|
/* Returns the current frame we're on - used to establish whats on screen */
|
|
|
|
extern UDWORD frameGetFrameNumber(void);
|
|
|
|
|
2006-08-27 12:01:34 -07:00
|
|
|
/**
|
|
|
|
* Average framerate of the last seconds
|
|
|
|
*
|
|
|
|
* \return Average framerate
|
|
|
|
*/
|
|
|
|
extern UDWORD frameGetAverageRate(void);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
/* The handle for the application window */
|
|
|
|
extern HANDLE frameGetWinHandle(void);
|
|
|
|
|
|
|
|
//enumerate all available direct draw devices
|
|
|
|
extern BOOL frameDDEnumerate(void);
|
|
|
|
|
|
|
|
extern SDWORD frameGetNumDDDevices(void);
|
|
|
|
|
|
|
|
extern char* frameGetDDDeviceName(SDWORD);
|
|
|
|
|
|
|
|
// Return a string for a windows error code
|
|
|
|
extern STRING *winErrorToString(SDWORD error);
|
|
|
|
|
|
|
|
/* The default window procedure for the library.
|
|
|
|
* This is initially set to the standard DefWindowProc, but can be changed
|
|
|
|
* by this function.
|
|
|
|
* Call this function with NULL to reset to DefWindowProc.
|
|
|
|
*/
|
|
|
|
typedef LRESULT (* DEFWINPROCTYPE)(HWND hWnd, UINT Msg,
|
|
|
|
WPARAM wParam, LPARAM lParam);
|
|
|
|
extern void frameSetWindowProc(DEFWINPROCTYPE winProc);
|
|
|
|
|
|
|
|
/* Load the file with name pointed to by pFileName into a memory buffer. */
|
|
|
|
BOOL loadFile(const char *pFileName, // The filename
|
2006-08-12 09:52:37 -07:00
|
|
|
char **ppFileData, // A buffer containing the file contents
|
2007-06-28 10:47:08 -07:00
|
|
|
UDWORD *pFileSize); // The size of this buffer
|
|
|
|
|
|
|
|
/* Save the data in the buffer into the given file */
|
|
|
|
extern BOOL saveFile(const char *pFileName, const char *pFileData, UDWORD fileSize);
|
|
|
|
|
|
|
|
// load a file from disk into a fixed memory buffer
|
2006-09-13 14:16:17 -07:00
|
|
|
BOOL loadFileToBuffer(const char *pFileName, char *pFileBuffer, UDWORD bufferSize, UDWORD *pSize);
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
// as above but returns quietly if no file found
|
2006-09-13 14:16:17 -07:00
|
|
|
BOOL loadFileToBufferNoError(const char *pFileName, char *pFileBuffer, UDWORD bufferSize,
|
2007-06-28 10:47:08 -07:00
|
|
|
UDWORD *pSize);
|
|
|
|
|
|
|
|
extern SDWORD ftol(float f);
|
|
|
|
|
2006-09-13 02:09:05 -07:00
|
|
|
UINT HashString( const char *String );
|
|
|
|
UINT HashStringIgnoreCase( const char *String );
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2006-08-12 03:45:49 -07:00
|
|
|
|
|
|
|
/* Endianness hacks */
|
|
|
|
|
2006-09-16 09:02:17 -07:00
|
|
|
static inline void endian_uword(UWORD *uword) {
|
2006-08-12 03:45:49 -07:00
|
|
|
#ifdef __BIG_ENDIAN__
|
|
|
|
UBYTE tmp, *ptr;
|
|
|
|
|
|
|
|
ptr = (UBYTE *) uword;
|
|
|
|
tmp = ptr[0];
|
|
|
|
ptr[0] = ptr[1];
|
|
|
|
ptr[1] = tmp;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-09-16 09:02:17 -07:00
|
|
|
static inline void endian_sword(SWORD *sword) {
|
2006-08-12 03:45:49 -07:00
|
|
|
#ifdef __BIG_ENDIAN__
|
|
|
|
UBYTE tmp, *ptr;
|
|
|
|
|
|
|
|
ptr = (UBYTE *) sword;
|
|
|
|
tmp = ptr[0];
|
|
|
|
ptr[0] = ptr[1];
|
|
|
|
ptr[1] = tmp;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-09-16 09:02:17 -07:00
|
|
|
static inline void endian_udword(UDWORD *udword) {
|
2006-08-12 03:45:49 -07:00
|
|
|
#ifdef __BIG_ENDIAN__
|
|
|
|
UBYTE tmp, *ptr;
|
|
|
|
|
|
|
|
ptr = (UBYTE *) udword;
|
|
|
|
tmp = ptr[0];
|
|
|
|
ptr[0] = ptr[3];
|
|
|
|
ptr[3] = tmp;
|
|
|
|
tmp = ptr[1];
|
|
|
|
ptr[1] = ptr[2];
|
|
|
|
ptr[2] = tmp;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-09-16 09:02:17 -07:00
|
|
|
static inline void endian_sdword(SDWORD *sdword) {
|
2006-08-12 03:45:49 -07:00
|
|
|
#ifdef __BIG_ENDIAN__
|
|
|
|
UBYTE tmp, *ptr;
|
|
|
|
|
|
|
|
ptr = (UBYTE *) sdword;
|
|
|
|
tmp = ptr[0];
|
|
|
|
ptr[0] = ptr[3];
|
|
|
|
ptr[3] = tmp;
|
|
|
|
tmp = ptr[1];
|
|
|
|
ptr[1] = ptr[2];
|
|
|
|
ptr[2] = tmp;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-09-16 09:02:17 -07:00
|
|
|
static inline void endian_fract(FRACT *fract) {
|
2006-08-12 03:45:49 -07:00
|
|
|
#ifdef __BIG_ENDIAN__
|
|
|
|
UBYTE tmp, *ptr;
|
|
|
|
|
|
|
|
ptr = (UBYTE *) fract;
|
|
|
|
tmp = ptr[0];
|
|
|
|
ptr[0] = ptr[3];
|
|
|
|
ptr[3] = tmp;
|
|
|
|
tmp = ptr[1];
|
|
|
|
ptr[1] = ptr[2];
|
|
|
|
ptr[2] = ptr[1];
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-28 10:47:08 -07:00
|
|
|
#endif
|