summaryrefslogtreecommitdiffstats
path: root/main.cpp
diff options
context:
space:
mode:
authorpiernov <piernov@piernov.org>2016-08-18 14:13:40 +0200
committerpiernov <piernov@piernov.org>2016-08-18 14:13:40 +0200
commit823a82611d37e618a4734ea480fab4c60b73f5b7 (patch)
treead26261abe2c2cf976f3ca38c00f0fefb4373fbd /main.cpp
downloadMaiMai-C++-master.tar.gz
MaiMai-C++-master.tar.bz2
MaiMai-C++-master.tar.xz
MaiMai-C++-master.zip
Initial ImportHEADmaster
Diffstat (limited to 'main.cpp')
-rwxr-xr-xmain.cpp126
1 files changed, 126 insertions, 0 deletions
diff --git a/main.cpp b/main.cpp
new file mode 100755
index 0000000..bc00afd
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,126 @@
+#include <SDL.h>
+
+#include "logging.h"
+#include "files.h"
+#include "display.h"
+#include "music.h"
+#include "game.h"
+#include "menu.h"
+
+#ifdef __cplusplus
+extern "C"
+#endif
+
+int main(int argc, char *argv[]) {
+
+ if (SDL_Init(SDL_INIT_EVERYTHING) != 0){
+ logSDLError("SDL_Init");
+ return 1;
+ }
+
+ if (TTF_Init()== -1){
+ logTTFError("TTF_Init");
+ return 1;
+ }
+
+ screen.font=TTF_OpenFont("/sdcard/LiberationMono-Regular.ttf", 14);
+ if(!screen.font) {
+ logTTFError("TTF_OpenFont: ");
+ }
+
+ screen.window = SDL_CreateWindow(screen.name, 100, 100, screen.width, screen.height, SDL_WINDOW_SHOWN);
+ if (screen.window == nullptr){
+ logSDLError("CreateWindow");
+ return 2;
+ }
+
+ screen.renderer = SDL_CreateRenderer(screen.window, -1,
+ SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
+ if(screen.renderer == nullptr)
+ screen.renderer = SDL_CreateRenderer(screen.window, -1, 0);
+
+ if (screen.renderer == nullptr){
+ logSDLError("CreateRenderer");
+ return 3;
+ }
+
+ if(Mix_OpenAudio(MIX_SAMPLERATE, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 1024) == -1) //Initialisation de l'API Mixer
+ logMixError("OpenAudio");
+
+ SDL_Event e;
+ bool quit = false;
+ bool playing;
+
+ std::vector<SDL_TouchFingerEvent> touchEvents;
+
+ while (!quit)
+ {
+ while (SDL_PollEvent(&e)){
+ switch (e.type ) {
+ case SDL_QUIT:
+ SDL_Log("SDL_QUIT");
+ quit = true;
+ break;
+ case SDL_KEYDOWN:
+ SDL_Log("SDL_KEYDOWN");
+ quit = true;
+ break;
+ case SDL_FINGERDOWN:
+ SDL_Log("SDL_FINGERDOWN");
+ touchEvents.push_back(e.tfinger);
+ break;
+ case SDL_WINDOWEVENT:
+ if(e.window.event == SDL_WINDOWEVENT_RESIZED)
+ {
+ screen.width = e.window.data1;
+ screen.height = e.window.data2;
+ SDL_DestroyWindow(screen.window);
+ screen.window = SDL_CreateWindow(screen.name, 100, 100, screen.width, screen.height, SDL_WINDOW_SHOWN);
+ if (screen.window == nullptr){
+ logSDLError("CreateWindow");
+ return 2;
+ }
+ }
+ break;
+ }
+ }
+
+ if(screen.state == STATE_INIT)
+ {
+ menu::init_menu();
+ } else if(screen.state == STATE_MENU)
+ {
+ menu::update_menu();
+ } else if(screen.state == STATE_PLAYING)
+ {
+// game::update();
+ }
+// if(!playing)
+// {
+// if(!init_game())
+// playing=true;
+// }
+// else if(quit)
+// quit_game();
+// else
+// update_game();
+ }
+
+ SDL_Log("Exited main loop");
+
+ Mix_CloseAudio();
+ SDL_Log("SDL_Mixer closed");
+ SDL_DestroyRenderer(screen.renderer);
+ SDL_Log("Renderer destroyed");
+ SDL_DestroyWindow(screen.window);
+ SDL_Log("Window destroyed");
+ TTF_CloseFont(screen.font);
+ screen.font=NULL;
+ SDL_Log("Font closed");
+ TTF_Quit();
+ SDL_Log("SDL_TTF closed");
+ SDL_Quit();
+ SDL_Log("SDL closed");
+
+ return 0;
+}