forward declare game
This commit is contained in:
parent
6b231230db
commit
2d9a42bdba
4
Makefile
4
Makefile
|
@ -17,8 +17,8 @@ SYSFWPATH = /Library/Frameworks
|
|||
INC = -Iglm -Isdl2-gfx
|
||||
|
||||
linux :
|
||||
g++ -c $(CFLAGS) $(INC) -D__LINUX__ main.cpp sdl2-gfx/SDL2_gfxPrimitives.c sdl2-gfx/SDL2_rotozoom.c
|
||||
g++ $(LFLAGS) SDL2_gfxPrimitives.o SDL2_rotozoom.o main.o -lSDL2_image -lSDL2_ttf -lGL -o main
|
||||
clang++-7 -c $(CFLAGS) $(INC) -D__LINUX__ main.cpp sdl2-gfx/SDL2_gfxPrimitives.c sdl2-gfx/SDL2_rotozoom.c
|
||||
clang++-7 $(LFLAGS) SDL2_gfxPrimitives.o SDL2_rotozoom.o main.o -lSDL2_image -lSDL2_ttf -lGL -o main
|
||||
|
||||
android :
|
||||
if [ ! -d $(BUILDDIR) ]; then mkdir $(BUILDDIR); fi;
|
||||
|
|
57
main.cpp
57
main.cpp
|
@ -7,6 +7,7 @@
|
|||
#include <cstdlib>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
|
||||
#define SDL_MAIN_HANDLED
|
||||
#include <SDL.h>
|
||||
|
@ -180,24 +181,58 @@ void set_framerate_indicator(int frame_count, GLuint id)
|
|||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
}
|
||||
|
||||
struct Sprite
|
||||
{
|
||||
std::list frames;
|
||||
struct Game;
|
||||
|
||||
Sprite()
|
||||
struct Node
|
||||
{
|
||||
|
||||
Node *parent = NULL;
|
||||
|
||||
Node() { std::cout << "Default constructing Node..." << std::endl; }
|
||||
|
||||
Node(Node *parent) : parent(parent)
|
||||
{
|
||||
std::cout << "Constructing Node with parent " << parent << std::endl;
|
||||
}
|
||||
|
||||
Game *get_root()
|
||||
{
|
||||
Node *current = parent;
|
||||
while (current->parent != NULL)
|
||||
{
|
||||
current = current->parent;
|
||||
}
|
||||
return (Game*) (current);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct Sprite : Node
|
||||
{
|
||||
|
||||
SDL_Texture *texture;
|
||||
SDL_Rect rect;
|
||||
|
||||
Sprite(Node *parent) : Node(parent)
|
||||
{
|
||||
std::cout << "Constructing Sprite with parent " << parent << std::endl;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct Mushroom : Sprite
|
||||
{
|
||||
Mushroom() : Sprite()
|
||||
|
||||
Mushroom(Node *parent) : Sprite(parent)
|
||||
{
|
||||
std::cout << "Constructing Mushroom with parent " << parent << std::endl;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct Game
|
||||
struct Game : Node
|
||||
{
|
||||
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer = NULL;
|
||||
SDL_GLContext glcontext = NULL;
|
||||
|
@ -213,9 +248,12 @@ struct Game
|
|||
float frame_length = 1000.0 / framerate;
|
||||
std::list<SDL_Surface*> frames;
|
||||
glm::mat4 projection, view, model = glm::mat4(1.0f), mvp;
|
||||
|
||||
|
||||
Game()
|
||||
{
|
||||
Mushroom mushroom(this);
|
||||
Game *root = mushroom.get_root();
|
||||
std::cout << root->sw << std::endl;
|
||||
setenv("SDL_VIDEO_X11_LEGACY_FULLSCREEN", "0", true);
|
||||
SDL_version version;
|
||||
SDL_GetVersion(&version);
|
||||
|
@ -245,7 +283,7 @@ struct Game
|
|||
}
|
||||
load_gl_context();
|
||||
}
|
||||
|
||||
|
||||
void print_sdl_error(std::string message)
|
||||
{
|
||||
std::cerr << message << " " << SDL_GetError() << std::endl;
|
||||
|
@ -589,9 +627,10 @@ struct Game
|
|||
|
||||
};
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
Game g = Game();
|
||||
Game g;
|
||||
g.run();
|
||||
g.quit();
|
||||
return 0;
|
||||
|
|
Loading…
Reference in New Issue