Beispiel #1
0
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;
    

    
    SDL_Init( SDL_INIT_EVERYTHING ); //start SDL
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); //set GL version of the window
    
    SDL_Window* window = SDL_CreateWindow( "RainbowRPG - SDL2.0 - OpenGL2.1", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screenDataW, screenDataH, SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_OPENGL | SDL_WINDOW_INPUT_GRABBED); //create OpenGL window

    SDL_GLContext glcontext = SDL_GL_CreateContext(window); //set context as OpenGL
//    SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
        initGL(screenDataW, screenDataH); //init GL.


    //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 = &currentMap; //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.
    
    //boost::thread logic_loop (boost::bind(&entity_logic_loop, 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   
    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.
    //logic_loop.join();


    return 0;
    
    }
Beispiel #2
0
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 = &currentMap; //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;
    
    }
int main(int argc, char* argv[])
{
	thread_t command_t;
	char* tmp;
	int i;

	logger_set_limit(1);
	logger_set_instant_func(print_message_cli);

	if((timer = timer_init()) == NULL)
	{
		printf("Failed to create timer!\n");
		return 1;
	}

	common_init();
	
	read_config();

#ifdef USE_READLINE

	rl_catch_signals = 0;

#endif
	
	for(i = 1 ; i < argc ; i++)
	{
		if(!strcmp(argv[i], "-h"))
			help();
		else if(!strcmp(argv[i], "-c"))
		{
			information();
			exit(0);
		}
	}
	
	signal(SIGINT , &ctrl_c);//&signalHandler);
	exit_time = 0;

#ifndef DISABLE_PHYSICS

	space = NULL;
	staticBody = NULL;
	
	lInit(&to_remove_array, NULL);
	lInit(&chipmunk_data_array, NULL);
	pthread_mutex_init(&text_lock, NULL);
	
	physics_exit_time = 0;

	simple_lock_init(&physics_lock);

#endif

#ifndef DISABLE_PHYSICS

	/* Set the functions for the network_lib library. */
	nlServerSetFuncs(&send_server_name,
					 &fill_info,
					 &new_chipmunk_data,
					 &mark_for_delete,
					 &key_press,
					 &key_release,
					 &get_exit_state,
					 NULL,
					 &logger_new_message);

#else

	nlServerSetFuncs(&send_server_name,
	                 NULL,
			 NULL,
			 NULL,
			 NULL,
			 NULL,
			 &get_exit_state,
			 NULL,
			 &logger_new_message);

#endif

	nlServerInit();
	
	if(argc > 2)
	{
		int i;
		
		for(i = 1; i < argc ; i++)
		{
			if(!strcmp(argv[i], "-u") && i+1 < argc)
			{
				mfree(IGD_URL);
				IGD_URL = m_strdup(argv[++i]);
				LOG("IGD Path: %s", IGD_URL);
			}
			else if(!strcmp(argv[i], "-p") && i+1 < argc)
			{
				#warning Check for errors.
				int port = 0;
				
				sscanf(argv[++i], "%d", &port);
				LOG("New port: %d", port);
				nlServerBindPort(port);
			}
		}
	}
		
	/* Start everything that has to do with the thread starting! */
	nlServerStart();

#ifndef DISABLE_PHYSICS

	pthread_create(&command_t, NULL, command_thread, NULL);
	physics_thread();
	
	/* If we arrive here, it is that an exit demand was
	 * performed (certainly ^C or ^D).
	 * We now clean everything up. */
	pthread_cancel(command_t);

#else

	command_thread(NULL);

#endif

	quit();

	return 0;
}