int main_loop() { for (int i=0;i<256;i++) solid[i] = i != 0; //sync = 0; while(1) { //do {al_poll_duh(current_track);} while (sync<=0);//render music while waiting for next frame al_poll_duh(current_track); int stat = logic_loop(); render_loop(); showbuffer(); //sync--; switch (stat) { default: case 0: break; case 1: return 1; } } }
int main( int argc, char* argv[] ) { //get_settings read_settings; //create a settings reading object. int screenDataW = 1920; //put screen data into a temp var int screenDataH = 1080; if (SDL_Init( SDL_INIT_EVERYTHING ) < 0 ) { std::cout << "SDL init error: " << SDL_GetError(); return 0; } //start SDL SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); //set GL version of the window SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); SDL_Window* window = SDL_CreateWindow( "RainbowRPG - SDL2.0 - OpenGL2.1", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screenDataW, screenDataH, SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_OPENGL); //create OpenGL window SDL_GLContext glcontext = SDL_GL_CreateContext(window); //set context as OpenGL initGL(screenDataW, screenDataH); //init GL. GLenum err = glewInit(); if (GLEW_OK != err) { std::cout << "initialiseing GLEW failed." << glewGetErrorString(err); return 0 ; } std::cout << "Using GLEW - " << glewGetString(GLEW_VERSION) << "\n"; // glMatrixMode (GL_MODELVIEW); // glLoadIdentity(); // glScalef(scale, scale, scale); // glBegin(GL_QUADS); //draw quad. // glColor4f(1.0f, 0.0f, 0.0f, 1.0f); // //glColor3f(SQUARE::colour4f[0],SQUARE::colour4f[1],SQUARE::colour4f[2]); // //glColor4f(SQUARE::colour4f[0],SQUARE::colour4f[1],SQUARE::colour4f[2],SQUARE::colour4f[3]); // glVertex2f(-1.0f,1.0f); // glVertex2f(1.0f,1.0f); // glVertex2f(1.0f,-1.0f); // glVertex2f(-1.0f,-1.0f); // glEnd(); // // GLenum error = glGetError(); // if( error != GL_NO_ERROR ) // { // std::cout << "Error drawing! 177 " << gluErrorString( error ) << "\n"; // return false; // } // SDL_GL_SwapWindow(window); //show content. // SDL_Delay(1000); // return 0; //command_thread.detach(); // SDL_Delay(1000); std::string mapFile ("a.map"); std::cout << "Initialising map!\n\n"; map* ptrmap; //create a pointer of type map. map currentMap (screenDataW, screenDataH, mapFile); ptrmap = ¤tMap; //make pointer point to instance of map. std::cout << "checking for inputted commands...."; command* ptrCommand; //create a pointer of type command. command commandline; //create command line object. std::cout << "creating command line thread...\n"; boost::thread command_thread ( boost::bind (&command::start_command, &commandline) ); //create a thread of the command line. std::cout << "Command thread started\n\n"; ptrCommand = & commandline; //make pointer point to command object. int entities = ptrmap -> return_number_of_entities(); boost::thread logic_loop (boost::bind(&entity_logic_loop, entities, ptrmap)); //create logic loop thread. std::cout << "Running game loop func\n\n"; game_loop(ptrCommand, ptrmap, window); //game_loop( ptrmap, window); currentMap.destroy_map(); //destroy the map! SDL_GL_DeleteContext(glcontext); //clean up SDL_Quit(); //quit SDL logic_loop.join(); //join logic thread. std::cout << "\nQuited nicely, press any letter/number key then tap return to terminate \n(This is a problem with using threads and std::cin together, must find a better way of doing this safely\n\n"; // - Remember killing the thread causes recursive terminate >.<.)\n\n"; command_thread.join(); //detach both out threads. return 0; }