-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
64 lines (62 loc) · 1.84 KB
/
Copy pathmain.cpp
File metadata and controls
64 lines (62 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
#include <stdexcept>
#include <vector>
#include <fstream>
#include <SDL.h>
#include <SDL_mixer.h>
#include <Python.h>
#include "Core.h"
#include "Utility.h"
int main(int argc, char* args[]){
bool audioEnabled = true;
try{
if( Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) < 0 ){
SDL_Log("Can't init sdl_mixer: %s", Mix_GetError());
throw std::runtime_error("Can't init sdl mixer!");
}
}catch(std::runtime_error& e){
std::cout << "Run time error: " << e.what() << std::endl;
audioEnabled = false;
}
Mix_Init(MIX_INIT_OGG);
std::vector<std::string> musics;
{
std::ifstream songsFile(Utility::getPath("music", "songs.txt"));
std::string musicName;
while(std::getline(songsFile, musicName)){
musics.push_back(musicName);
}
songsFile.close();
}
if(musics.empty()){
SDL_Log("Can't init audio: songs.txt is empty or not exist!");
audioEnabled = false;
}
MusicPlayer musicPlayer(musics);
Core* core = nullptr;
bool successInit = true;
try{
core = new Core("PyDesert", 800, 600, (audioEnabled ? &musicPlayer : NULL), audioEnabled);
}catch(std::runtime_error& e){
std::cout << "Run time error when init core: " << e.what() << std::endl;
successInit = false;
}catch(...){
std::cout << "Undefined error when init core!" << std::endl;
successInit = false;
}
if(successInit){
try{
core->loadFont("font.ttf");
core->run();
}catch(std::runtime_error& e){
std::cout << "Run time error: " << e.what() << std::endl;
}catch(...){
std::cout << "Undefined error!" << std::endl;
}
}
Mix_Quit();
if(core){
delete core;
}
return 0;
}