1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-22 17:49:43 +01:00

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.
This commit is contained in:
Info Teddy 2020-01-28 23:35:03 -08:00 committed by Ethan Lee
parent 906e35244b
commit 5a316d65e6
12 changed files with 39 additions and 16 deletions

View file

@ -113,9 +113,9 @@ bool GetButtonFromString(const char *pText, SDL_GameControllerButton *button)
} }
Game::Game(void): void Game::init(void)
mutebutton(0)
{ {
mutebutton = 0;
infocus = true; infocus = true;
paused = false; paused = false;
muted = false; muted = false;

View file

@ -17,7 +17,7 @@ class musicclass;
class Game class Game
{ {
public: public:
Game(void); void init(void);
~Game(void); ~Game(void);
@ -362,4 +362,6 @@ public:
bool skipfakeload; bool skipfakeload;
}; };
extern Game game;
#endif /* GAME_H */ #endif /* GAME_H */

View file

@ -4,8 +4,10 @@
#include "Map.h" #include "Map.h"
#include "Screen.h" #include "Screen.h"
Graphics::Graphics() void Graphics::init()
{ {
grphx.init();
flipmode = false; flipmode = false;
setRect(tiles_rect, 0,0,8,8); setRect(tiles_rect, 0,0,8,8);
setRect(sprites_rect, 0,0,32,32); setRect(sprites_rect, 0,0,32,32);

View file

@ -23,7 +23,7 @@ class map;
class Graphics class Graphics
{ {
public: public:
Graphics(); void init();
~Graphics(); ~Graphics();
GraphicsResources grphx; GraphicsResources grphx;
@ -282,4 +282,6 @@ public:
bool showmousecursor; bool showmousecursor;
}; };
extern Graphics graphics;
#endif /* GRAPHICS_H */ #endif /* GRAPHICS_H */

View file

@ -80,7 +80,7 @@ SDL_Surface* LoadImage(const char *filename, bool noBlend = true, bool noAlpha =
} }
} }
GraphicsResources::GraphicsResources(void) void GraphicsResources::init(void)
{ {
im_tiles = LoadImage("graphics/tiles.png"); im_tiles = LoadImage("graphics/tiles.png");
im_tiles2 = LoadImage("graphics/tiles2.png"); im_tiles2 = LoadImage("graphics/tiles2.png");

View file

@ -6,7 +6,7 @@
class GraphicsResources class GraphicsResources
{ {
public: public:
GraphicsResources(void); void init(void);
~GraphicsResources(void); ~GraphicsResources(void);
SDL_Surface* im_tiles; SDL_Surface* im_tiles;

View file

@ -81,5 +81,6 @@ private:
Uint32 wasFullscreen; Uint32 wasFullscreen;
}; };
extern KeyPoll key;
#endif /* KEYPOLL_H */ #endif /* KEYPOLL_H */

View file

@ -179,4 +179,6 @@ public:
int cursorstate, cursordelay; int cursorstate, cursordelay;
}; };
extern mapclass map;
#endif /* MAPGAME_H */ #endif /* MAPGAME_H */

View file

@ -3,7 +3,7 @@
#include "Music.h" #include "Music.h"
#include "BinaryBlob.h" #include "BinaryBlob.h"
musicclass::musicclass() void musicclass::init()
{ {
soundTracks.push_back(SoundTrack( "sounds/jump.wav" )); soundTracks.push_back(SoundTrack( "sounds/jump.wav" ));
soundTracks.push_back(SoundTrack( "sounds/jump2.wav" )); soundTracks.push_back(SoundTrack( "sounds/jump2.wav" ));

View file

@ -10,7 +10,7 @@
class musicclass class musicclass
{ {
public: public:
musicclass(); void init();
void play(int t); void play(int t);
void loopmusic(); void loopmusic();
@ -64,5 +64,6 @@ public:
bool usingmmmmmm; bool usingmmmmmm;
}; };
extern musicclass music;
#endif /* MUSIC_H */ #endif /* MUSIC_H */

View file

@ -43,4 +43,6 @@ public:
std::vector<int> splitseconds; std::vector<int> splitseconds;
}; };
extern UtilityClass help;
#endif /* UTILITYCLASS_H */ #endif /* UTILITYCLASS_H */

View file

@ -34,6 +34,14 @@ scriptclass script;
editorclass ed; editorclass ed;
UtilityClass help;
Graphics graphics;
musicclass music;
Game game;
KeyPoll key;
mapclass map;
entityclass obj;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
if(!FILESYSTEM_init(argv[0])) if(!FILESYSTEM_init(argv[0]))
@ -90,16 +98,19 @@ int main(int argc, char *argv[])
UtilityClass help; //UtilityClass help;
// Load Ini // Load Ini
Graphics graphics; //Graphics graphics;
graphics.init();
musicclass music; //musicclass music;
Game game; music.init();
//Game game;
game.init();
game.infocus = true; game.infocus = true;
graphics.MakeTileArray(); graphics.MakeTileArray();
@ -159,8 +170,8 @@ int main(int argc, char *argv[])
game.menustart = false; game.menustart = false;
game.mainmenu = 0; game.mainmenu = 0;
KeyPoll key; //KeyPoll key;
mapclass map; //mapclass map;
map.ypos = (700-29) * 8; map.ypos = (700-29) * 8;
map.bypos = map.ypos / 2; map.bypos = map.ypos / 2;
@ -217,7 +228,7 @@ int main(int argc, char *argv[])
if(game.bestrank[4]>=3) NETWORK_unlockAchievement("vvvvvvtimetrial_warp_fixed"); if(game.bestrank[4]>=3) NETWORK_unlockAchievement("vvvvvvtimetrial_warp_fixed");
if(game.bestrank[5]>=3) NETWORK_unlockAchievement("vvvvvvtimetrial_final_fixed"); if(game.bestrank[5]>=3) NETWORK_unlockAchievement("vvvvvvtimetrial_final_fixed");
entityclass obj; //entityclass obj;
obj.init(); obj.init();
//Quick hack to start in final level ---- //Might be useful to leave this commented in for testing //Quick hack to start in final level ---- //Might be useful to leave this commented in for testing