mirror of
https://github.com/TerryCavanagh/VVVVVV.git
synced 2024-12-22 09:39: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:
parent
906e35244b
commit
5a316d65e6
12 changed files with 39 additions and 16 deletions
|
@ -113,9 +113,9 @@ bool GetButtonFromString(const char *pText, SDL_GameControllerButton *button)
|
|||
}
|
||||
|
||||
|
||||
Game::Game(void):
|
||||
mutebutton(0)
|
||||
void Game::init(void)
|
||||
{
|
||||
mutebutton = 0;
|
||||
infocus = true;
|
||||
paused = false;
|
||||
muted = false;
|
||||
|
|
|
@ -17,7 +17,7 @@ class musicclass;
|
|||
class Game
|
||||
{
|
||||
public:
|
||||
Game(void);
|
||||
void init(void);
|
||||
~Game(void);
|
||||
|
||||
|
||||
|
@ -362,4 +362,6 @@ public:
|
|||
bool skipfakeload;
|
||||
};
|
||||
|
||||
extern Game game;
|
||||
|
||||
#endif /* GAME_H */
|
||||
|
|
|
@ -4,8 +4,10 @@
|
|||
#include "Map.h"
|
||||
#include "Screen.h"
|
||||
|
||||
Graphics::Graphics()
|
||||
void Graphics::init()
|
||||
{
|
||||
grphx.init();
|
||||
|
||||
flipmode = false;
|
||||
setRect(tiles_rect, 0,0,8,8);
|
||||
setRect(sprites_rect, 0,0,32,32);
|
||||
|
|
|
@ -23,7 +23,7 @@ class map;
|
|||
class Graphics
|
||||
{
|
||||
public:
|
||||
Graphics();
|
||||
void init();
|
||||
~Graphics();
|
||||
|
||||
GraphicsResources grphx;
|
||||
|
@ -282,4 +282,6 @@ public:
|
|||
bool showmousecursor;
|
||||
};
|
||||
|
||||
extern Graphics graphics;
|
||||
|
||||
#endif /* GRAPHICS_H */
|
||||
|
|
|
@ -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_tiles2 = LoadImage("graphics/tiles2.png");
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
class GraphicsResources
|
||||
{
|
||||
public:
|
||||
GraphicsResources(void);
|
||||
void init(void);
|
||||
~GraphicsResources(void);
|
||||
|
||||
SDL_Surface* im_tiles;
|
||||
|
|
|
@ -81,5 +81,6 @@ private:
|
|||
Uint32 wasFullscreen;
|
||||
};
|
||||
|
||||
extern KeyPoll key;
|
||||
|
||||
#endif /* KEYPOLL_H */
|
||||
|
|
|
@ -179,4 +179,6 @@ public:
|
|||
int cursorstate, cursordelay;
|
||||
};
|
||||
|
||||
extern mapclass map;
|
||||
|
||||
#endif /* MAPGAME_H */
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include "Music.h"
|
||||
#include "BinaryBlob.h"
|
||||
|
||||
musicclass::musicclass()
|
||||
void musicclass::init()
|
||||
{
|
||||
soundTracks.push_back(SoundTrack( "sounds/jump.wav" ));
|
||||
soundTracks.push_back(SoundTrack( "sounds/jump2.wav" ));
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
class musicclass
|
||||
{
|
||||
public:
|
||||
musicclass();
|
||||
void init();
|
||||
|
||||
void play(int t);
|
||||
void loopmusic();
|
||||
|
@ -64,5 +64,6 @@ public:
|
|||
bool usingmmmmmm;
|
||||
};
|
||||
|
||||
extern musicclass music;
|
||||
|
||||
#endif /* MUSIC_H */
|
||||
|
|
|
@ -43,4 +43,6 @@ public:
|
|||
std::vector<int> splitseconds;
|
||||
};
|
||||
|
||||
extern UtilityClass help;
|
||||
|
||||
#endif /* UTILITYCLASS_H */
|
||||
|
|
|
@ -34,6 +34,14 @@ scriptclass script;
|
|||
|
||||
editorclass ed;
|
||||
|
||||
UtilityClass help;
|
||||
Graphics graphics;
|
||||
musicclass music;
|
||||
Game game;
|
||||
KeyPoll key;
|
||||
mapclass map;
|
||||
entityclass obj;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if(!FILESYSTEM_init(argv[0]))
|
||||
|
@ -90,16 +98,19 @@ int main(int argc, char *argv[])
|
|||
|
||||
|
||||
|
||||
UtilityClass help;
|
||||
//UtilityClass help;
|
||||
// Load Ini
|
||||
|
||||
|
||||
Graphics graphics;
|
||||
//Graphics graphics;
|
||||
graphics.init();
|
||||
|
||||
|
||||
|
||||
musicclass music;
|
||||
Game game;
|
||||
//musicclass music;
|
||||
music.init();
|
||||
//Game game;
|
||||
game.init();
|
||||
game.infocus = true;
|
||||
|
||||
graphics.MakeTileArray();
|
||||
|
@ -159,8 +170,8 @@ int main(int argc, char *argv[])
|
|||
game.menustart = false;
|
||||
game.mainmenu = 0;
|
||||
|
||||
KeyPoll key;
|
||||
mapclass map;
|
||||
//KeyPoll key;
|
||||
//mapclass map;
|
||||
|
||||
map.ypos = (700-29) * 8;
|
||||
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[5]>=3) NETWORK_unlockAchievement("vvvvvvtimetrial_final_fixed");
|
||||
|
||||
entityclass obj;
|
||||
//entityclass obj;
|
||||
obj.init();
|
||||
|
||||
//Quick hack to start in final level ---- //Might be useful to leave this commented in for testing
|
||||
|
|
Loading…
Reference in a new issue