1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
#ifndef _FPS_H_
#define _FPS_H_
#include <iostream> /* I use std::cerr in my die() function; and I like std::strings */
#include <fstream> /* For extensibility; I like to use a config file so users can
* change things. I like programs that are configurable, and
* I like to make programs that are configurable.
*/
#include <vector> /* For the surface_stack vector (see below) */
/* The rest of this stuff is SDL and some SDL extension libraries: */
#include <SDL/SDL.h>
#include <SDL/SDL_mixer.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_ttf.h>
#define __init
/* OH NO GLOBALS ARE EVIL */
static std::vector <SDL_Surface*> surface_stack; /* Keep track of allocated
* surfaces; as the name may
* suggest; this is a LIFO stack
*/
/* Config file stuff: */
static std::string fontfile; /* Load this font to print text with */
static std::string imagefolder; /* Search this folder for images */
static bool fullscreen; /* Should the screen go fullscreen? */
static bool doublebuf; /* Should we double-buffer the screen? */
static size_t host_w; /* Desktop width */
static size_t host_h; /* Desktop height */
/* Easy way to distinguis between file formats and how to load them
* (e.g. should I use SDL_LoadBMP? No, the format says PNG, etc.)
*/
enum img_formats {
PNG,
GIF,
BMP,
JPG
};
class video {
public:
size_t height; /* Height of our screen */
size_t width; /* Width of our screen */
int color_depth; /* Colour depth (bits per pixel) */
public:
};
class audio {
public: /* Even I, not being a "sound engineer" of any kind, can understand these: */
int sampleRate; /* The rate (KHz) at which the sound is "sampled". Higher == better quality */
Uint16 sampleFormat; /* Format (8-/16-/32-bit */
int nChannels; /* Mono-/Stereo sound */
int nBuffers; /* Buffer the sound so it isn't just a raw stream.
* Unbuffered streams are retarded. */
};
/* Functions below are organised by file. */
/* Initialize SDL and the extension libraries; generally sets everything up for us
* and returns a pointer to our main surface; generically named screen
*/
SDL_Surface* __init init(void);
/* Although it is declared as __init (which is just a blank macro); I like to
* declare it with init because:
* 1. It's in init.cpp
* 2. It didn't seem to fit anything else
* 3. The name seemed to fit.
* It is declared with __init but really it does the opposite -- frees surfaces,
* exits SDL and then returns to main, which can thereafter return a number to the OS or whatever.
*/
void __init end(void);
/* Pretty self explanatory. Entry point. I heard the whole CLI args stuff was
* the only way to make the SDL program work properly; and while I have never
* experienced it's failure without; I like to err on the safe side.
*/
int main(int, char**);
void die(std::string); /* Like the PHP die -- print an error message (but with SDL_GetError()
* to stderr and exit with a status of 1 (failure, normally) */
/* Cleans up allocated surfaces; see std::vector above */
void cleanup(void);
/* Very simple -- place an image on the screen. The two int args refer to the x
* and y pos to blit them to. Remember that we're going down from the top-left;
* not at all like you're typical graph.
*/
void place_image(SDL_Surface*, SDL_Surface*, int, int);
#endif
|