const AGTexture &TextureCache::get (const std::string &pTexture) { std::map<std::string,AGTexture>::iterator i=mTextures.find(pTexture); if(i==mTextures.end()) { // load std::string c=loadFile(pTexture); AGSurface ms(fromPNG(c)); AGTexture mTexture(ms); mTextures[pTexture]=mTexture; } return mTextures[pTexture]; }
bool Game::OnInit() { if (SDL_Init(SDL_INIT_EVERYTHING) != 0) { logSDLError(std::cout, "SDL_Init"); return false; } if (IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG != IMG_INIT_PNG) { logSDLError(std::cout, "IMG_Init"); SDL_Quit(); return false; } window = SDL_CreateWindow("Hello World!", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN); if (window == nullptr) { logSDLError(std::cout, "CreateWindow"); SDL_Quit(); return false; } renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); if (renderer == nullptr) { logSDLError(std::cout, "CreateRenderer"); SDL_DestroyWindow(window); SDL_Quit(); return false; } // LOAD TEXTURES // textures.push_back(mTexture(renderer)); textures[textures.size()-1].loadFromFile("rsz-india.png"); textures.push_back(mTexture(renderer)); textures[textures.size()-1].loadFromFile("circle.png"); // INIT GRAPH int basex = 700; int basey = 400; int base = 0; int distance = 100; nodes.push_back(graph.addNode("Base", basex, basey)); int points = 20; double slice = 2 * M_PI / points; for ( int j = 0; j < 2; j++) { for(int i = 0; i < points; i++) { double angle = slice*i; int newX = (int)(basex + distance * cos(angle)); int newY = (int)(basey + distance * sin(angle)); nodes.push_back(graph.addNode("sdf", newX, newY)); edges.push_back(graph.addEdge(nodes[base], nodes[nodes.size()-1], distance)); std::cout << "hi" << std::endl; } base = nodes.size()-1; basex = graph.nodes[nodes[rand()%points]].x; basey = graph.nodes[nodes[rand()%points]].y; distance /= j+2; points /= j+2; } return true; }