1
0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-06-26 14:38:30 +02:00
VVVVVV/desktop_version/src/Graphics.h
Info Teddy 5a316d65e6 Allow using help/graphics/music/game/key/map/obj everywhere
This commit makes `help`, `graphics`, `music`, `game`, `key`, `map`, and
`obj` essentially static global objects that can be used everywhere.
This is useful in case we ever need to add a new function in the future,
so we don't have to bother with passing a new argument in which means we
have to pass a new argument in to the function that calls that function
which means having to pass a new argument into the function that calls
THAT function, etc. which is a real headache when working on fan mods of
the source code.

Note that this changes NONE of the existing function signatures, it
merely just makes those variables accessible everywhere in the same way
`script` and `ed` are.

Also note that some classes had to be initialized after the filesystem
was initialized, but C++ would keep initializing them before the
filesystem got initialized, because I *had* to put them at the top of
`main.cpp`, or else they wouldn't be global variables.

The only way to work around this was to use entityclass's initialization
style (which I'm pretty sure entityclass of all things doesn't need to
be initialized this way), where you actually initialize the class in an
`init()` function, and so then you do `graphics.init()` after the
filesystem initialization, AFTER doing `Graphics graphics` up at the
top.

I've had to do this for `graphics` (but only because its child
GraphicsResources `grphx` needs to be initialized this way), `music`,
and `game`. I don't think this will affect anything. Other than that,
`help`, `key`, and `map` are still using the C++-intended method of
having ClassName::ClassName() functions.
2020-01-29 07:58:23 -05:00

288 lines
6.2 KiB
C++

#ifndef GRAPHICS_H
#define GRAPHICS_H
#include "GraphicsResources.h"
#include <vector>
#include "Maths.h"
#include "Textbox.h"
#include "UtilityClass.h"
#include "Game.h"
#include <string>
#include <algorithm>
#include "GraphicsUtil.h"
#include "Screen.h"
class map;
class Graphics
{
public:
void init();
~Graphics();
GraphicsResources grphx;
void Makebfont();
void drawhuetile(int x, int y, int t, int c);
void drawgravityline(int t, entityclass& obj);
void MakeTileArray();
void MakeSpriteArray();
void maketelearray();
void drawcoloredtile(int x, int y, int t, int r, int g, int b);
void drawmenu(Game& game, int cr, int cg, int cb, int division = 30);
void drawlevelmenu(Game& game, int cr, int cg, int cb, int division = 30);
void processfade();
void drawfade();
void setwarprect(int a, int b, int c, int d);
void createtextbox(std::string t, int xp, int yp, int r= 255, int g= 255, int b = 255);
void textboxcleanup();
void textboxcenter();
void textboxcenterx();
int textboxwidth();
void textboxmove(int xo, int yo);
void textboxmoveto(int xo);
void textboxcentery();
void textboxadjust();
void addline(std::string t);
void textboxtimer(int t);
void textboxremove();
void textboxremovefast();
void textboxactive();
void drawtextbox(int x, int y, int w, int h, int r, int g, int b);
void drawpixeltextbox(int x, int y, int w, int h, int w2, int h2, int r, int g, int b, int xo, int yo);
void drawcustompixeltextbox(int x, int y, int w, int h, int w2, int h2, int r, int g, int b, int xo, int yo);
void drawcrewman(int x, int y, int t, bool act, UtilityClass& help, bool noshift =false);
int crewcolour(const int t);
void cutscenebars();
void drawpartimage(int t, int xp, int yp, int wp, int hp);
void drawimage(int t, int xp, int yp, bool cent=false);
void drawimagecol(int t, int xp, int yp, int r, int g, int b, bool cent= false);
void drawgui(UtilityClass& help);
void drawsprite(int x, int y, int t, int r, int g, int b);
void printcrewname(int x, int y, int t);
void printcrewnamestatus(int x, int y, int t);
void printcrewnamedark(int x, int y, int t);
void Print(int _x, int _y, std::string _s, int r, int g, int b, bool cen = false);
void RPrint(int _x, int _y, std::string _s, int r, int g, int b, bool cen = false);
void PrintOff(int _x, int _y, std::string _s, int r, int g, int b, bool cen = false);
void bprint(int x, int y, std::string t, int r, int g, int b, bool cen = false);
int len(std::string t);
void bigprint( int _x, int _y, std::string _s, int r, int g, int b, bool cen = false, int sc = 2 );
void drawspritesetcol(int x, int y, int t, int c, UtilityClass& help);
void flashlight();
void screenshake();
void render();
bool Hitest(SDL_Surface* surface1, point p1, int col, SDL_Surface* surface2, point p2, int col2);
void drawentities(mapclass& map, entityclass& obj, UtilityClass& help);
void drawtrophytext(entityclass&, UtilityClass& help);
void bigrprint(int x, int y, std::string& t, int r, int g, int b, bool cen = false, float sc = 2);
void drawtele(int x, int y, int t, int c, UtilityClass& help);
Uint32 getRGB(Uint8 r, Uint8 g, Uint8 b);
Uint32 getBGR(Uint8 r, Uint8 g, Uint8 b);
Uint32 getRGB(Uint32 _col);
Uint32 RGBflip(Uint8 r, Uint8 g, Uint8 b);
Uint32 RGBf(int r, int g, int b);
void setcolreal(Uint32 t);
void drawbackground(int t, mapclass& map);
void drawtile3( int x, int y, int t, int off );
void drawentcolours( int x, int y, int t);
void drawtile2( int x, int y, int t, int r, int g, int b );
void drawtile( int x, int y, int t, int r, int g, int b );
void drawtowertile( int x, int y, int t );
void drawtowertile3( int x, int y, int t, int off );
void drawtile(int x, int y, int t);
void drawmap(mapclass& map);
void drawforetile(int x, int y, int t);
void drawforetile2(int x, int y, int t);
void drawforetile3(int x, int y, int t, int off);
void drawrect(int x, int y, int w, int h, int r, int g, int b);
void drawtowermap(mapclass& map);
void drawtowermap_nobackground(mapclass& map);
void drawtowerspikes(mapclass& map);
void drawtowerentities(mapclass& map, entityclass& obj, UtilityClass& help);
bool onscreen(int t);
void drawtowerbackgroundsolo(mapclass& map);
void menuoffrender();
void drawtowerbackground(mapclass& map);
void setcol(int t, UtilityClass& help);
void drawfinalmap(mapclass & map);
colourTransform ct;
std::string tempstring;
int bcol, bcol2, rcol;
int j, k, m;
std::vector <SDL_Surface*> backgrounds;
std::vector <SDL_Surface*> images;
std::vector <SDL_Surface*> tele;
std::vector <SDL_Surface*> tiles;
std::vector <SDL_Surface*> tiles2;
std::vector <SDL_Surface*> tiles3;
std::vector <SDL_Surface*> entcolours;
std::vector <SDL_Surface*> sprites;
std::vector <SDL_Surface*> flipsprites;
std::vector <SDL_Surface*> bfont;
std::vector <SDL_Surface*> bfontmask;
std::vector <SDL_Surface*> flipbfont;
std::vector <SDL_Surface*> flipbfontmask;
std::vector <int> bfontlen;
bool flipmode;
bool setflipmode;
bool notextoutline;
point tl;
//buffer objects. //TODO refactor buffer objects
SDL_Surface* backBuffer;
Screen* screenbuffer;
SDL_Surface* menubuffer;
SDL_Surface* towerbuffer;
SDL_Surface* foregroundBuffer;
SDL_Surface* tempBuffer;
SDL_Rect bfont_rect;
SDL_Rect tiles_rect;
SDL_Rect sprites_rect;
SDL_Rect bfontmask_rect;
SDL_Rect images_rect;
SDL_Rect bg_rect;
SDL_Rect line_rect;
SDL_Rect tele_rect;
SDL_Rect foot_rect;
SDL_Rect prect;
SDL_Rect footerrect;
SDL_Surface* footerbuffer;
int linestate, linedelay;
int backoffset;
bool backgrounddrawn, foregrounddrawn;
int menuoffset;
bool resumegamemode;
SDL_Rect warprect;
int crewframe;
int crewframedelay;
int fademode;
int fadeamount;
std::vector <int> fadebars;
bool trinketcolset;
int trinketr, trinketg, trinketb;
std::vector <textboxclass> textbox;
int ntextbox;
bool showcutscenebars;
int cutscenebarspos;
std::vector<SDL_Rect> stars;
std::vector<int> starsspeed;
int spcol, spcoldel;
std::vector<SDL_Rect> backboxes;
std::vector<int> backboxvx;
std::vector<int> backboxvy;
std::vector<float> backboxint;
SDL_Rect backboxrect;
int warpskip, warpfcol, warpbcol;
bool translucentroomname;
bool showmousecursor;
};
extern Graphics graphics;
#endif /* GRAPHICS_H */