taisei/src/global.h

201 lines
3.5 KiB
C
Raw Normal View History

/*
* This software is licensed under the terms of the MIT-License
* See COPYING for further information.
* ---
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
*/
#ifndef GLOBAL_H
#define GLOBAL_H
2017-02-04 03:56:40 +01:00
#include <SDL.h>
#include <SDL_platform.h>
#include <stdbool.h>
#include <math.h>
2017-02-07 19:34:55 +01:00
#include "tscomplex.h"
#include "resource/audio.h"
2017-01-24 14:40:57 +01:00
#include "resource/bgm.h"
#include "resource/shader.h"
#include "resource/font.h"
#include "resource/animation.h"
#include "menu/menu.h"
Refactored the gl loader into a polyglot macro monstrosity We no longer link to libGL by default. All GL functions are loaded dynamically through SDL apis. Use -DLINK_TO_LIBGL to enable linking, in which case Taisei won't try to dynamically load any of the gl functions. Previously we used a strange inconsistent setup where some functions were loaded dynamically and others pulled from the linked library. We also no longer link to libGLU even if LINK_TO_LIBGL is set. The only function we used from that library was gluPerspective. taiseigl now provides a simple substitute via glFrustum. The SDL2 gl headers are now used instead of the system ones, this should be more portable. The taiseigl.h header contains generated code partially based on content from those headers. It also doubles as a python3 script that actually generates that code and inserts it into itself. It scans the Taisei source tree for gl* calls and generates code only for the functions we use, and a few manually specified ones that are called indirectly. Assumptions such as "linux = glx" are no longer made. SDL takes care of platform specifics, as it should. The GL_EXT_draw_instanced/GL_ARB_draw_instanced extension detection has been improved. Taisei should be able to figure out which one to use without a compile-time check, and support for the ARB version has been actually implemented for the laser snippet loader. I've tested it on Windows 8 with Intel drivers that don't support the EXT version but do support the ARB one, instanced drawing works and the lasers don't lag! OSX should benefit from this change as well, although I've not yet tested the OSX build, beyond simply compiling it.
2017-02-24 01:54:28 +01:00
#include "taiseigl.h"
#include "player.h"
#include "projectile.h"
#include "enemy.h"
2011-04-29 10:26:37 +02:00
#include "item.h"
#include "boss.h"
#include "laser.h"
#include "dialog.h"
#include "list.h"
#include "config.h"
#include "fbo.h"
2011-12-25 08:18:03 +01:00
#include "vbo.h"
#include "resource/resource.h"
#include "replay.h"
2012-07-27 19:11:45 +02:00
#include "random.h"
2012-08-13 17:50:28 +02:00
#include "events.h"
#include "taisei_err.h"
2017-02-22 21:52:25 +01:00
#include "rwops/all.h"
#define FILE_PREFIX PREFIX "/share/taisei/"
2011-06-26 20:23:28 +02:00
#define CONFIG_FILE "config"
2012-07-28 22:53:53 +02:00
enum {
// defaults
2012-07-20 21:24:12 +02:00
RESX = 800,
2012-07-28 22:53:53 +02:00
RESY = 600,
SCREEN_W = 800,
SCREEN_H = 600,
VIEWPORT_X = 40,
VIEWPORT_Y = 20,
VIEWPORT_W = 480,
VIEWPORT_H = 560,
POINT_OF_COLLECT = VIEWPORT_H/4,
ATTACK_START_DELAY = 40,
BOMB_RECOVERY = 300,
DEATHBOMB_TIME = 10,
2011-07-04 14:21:36 +02:00
DEATH_DELAY = 70,
PLR_MAXPOWER = 400,
PLR_START_LIVES = 2,
PLR_START_BOMBS = 3,
2012-08-08 19:09:04 +02:00
MAX_CONTINUES = 3,
ACTION_DESTROY,
EVENT_DEATH = -8999,
EVENT_BIRTH,
FPS = 60,
GAMEOVER_DEFEAT = 1,
GAMEOVER_WIN,
2012-08-04 06:37:59 +02:00
GAMEOVER_ABORT,
2012-08-16 15:50:28 +02:00
GAMEOVER_REWATCH,
GAMEOVER_RESTART
};
typedef struct {
int fpstime; // frame counter
2012-07-29 13:11:44 +02:00
int fps;
int show_fps;
2012-07-29 13:11:44 +02:00
double stagebg_fps;
} FPSCounter;
typedef struct {
Difficulty diff;
Player plr;
Projectile *projs;
Enemy *enemies;
2011-04-29 10:26:37 +02:00
Item *items;
Laser *lasers;
Projectile *particles;
int frames;
int stageuiframes;
int lasttime; // frame limiter
int timer;
int frameskip;
Boss *boss;
Dialog *dialog;
2012-08-03 17:06:25 +02:00
RefArray refs;
int game_over;
FPSCounter fps;
bool nostagebg;
Replay replay;
ReplayMode replaymode;
ReplayStage *replay_stage;
2012-08-01 17:32:11 +02:00
float shake_view;
2012-07-27 19:11:45 +02:00
RandomState rand_game;
RandomState rand_visual;
StageInfo *stage;
} Global;
extern Global global;
void print_state_checksum(void);
2012-08-07 21:27:32 +02:00
void init_global(void);
2011-12-29 09:37:17 +01:00
void frame_rate(int *lasttime);
void calc_fps(FPSCounter *fps);
void set_ortho(void);
void colorfill(float r, float g, float b, float a);
2011-07-05 15:20:19 +02:00
void fade_out(float f);
void take_screenshot(void);
2012-08-03 16:57:29 +02:00
// needed for mingw compatibility:
#undef min
#undef max
// NOTE: do NOT convert these to macros please.
// max(frand(), 0.5);
// min(huge_costly_expression, another_huge_costly_expression)
2012-07-18 19:19:14 +02:00
double min(double, double);
double max(double, double);
2012-08-05 03:36:55 +02:00
double clamp(double, double, double);
2012-07-29 13:11:44 +02:00
double approach(double v, double t, double d);
double psin(double);
bool strendswith(const char *s, const char *e);
char* difficulty_name(Difficulty diff);
void difficulty_color(Color *c, Difficulty diff);
void stralloc(char **dest, const char *src);
2017-02-17 17:03:49 +01:00
bool gamekeypressed(KeyIndex key);
2017-02-16 07:00:28 +01:00
int getenvint(const char *v);
2012-07-29 13:11:44 +02:00
2012-08-15 16:36:39 +02:00
#define SIGN(x) ((x > 0) - (x < 0))
// this is used by both player and replay code
enum {
EV_PRESS,
EV_RELEASE,
2012-08-15 16:36:39 +02:00
EV_OVER, // replay-only
EV_AXIS_LR,
EV_AXIS_UD,
2017-02-05 03:58:27 +01:00
EV_CHECK_DESYNC, // replay-only
};
#undef strlcat
#undef strlcpy
#define strlcat SDL_strlcat
#define strlcpy SDL_strlcpy
#undef strncat
#undef strncpy
#define strncat DO_NOT_USE_strncat_USE_strlcat
#define strncpy DO_NOT_USE_strncpy_USE_strlcpy
#endif
//
// These definitions are common but non-standard, so we provide our own
//
#undef M_PI
#undef M_PI_2
#define M_PI 3.14159265358979323846
#define M_PI_2 1.57079632679489661923