Пример #1
0
int main()
{
    using namespace std;

    cout<<"=====================================SERVER====================================="<<endl;
    cout<<"CROMGame Server version : "<<RC_FILEVERSION_STRING<<endl;


    //Chargement des images ===========================================
    cout<<"Loading data...";

    sf::Clock clkDateFrame;
    clkDateGame.Reset();

    //Init du random
    srand(time(NULL));

    cout<<"Done"<<endl;
    //==================================================================

    bool bRedFlag;
    bool bGreenFlag;
    bool bBlueFlag;

    do
    {
        string sInput("");
        bool bSuccess=false;
        do
        {
            cout<<"================================================================================"<<endl;
            cout<<"Quelle map charger ?   ";

            cin>>sInput;

            bSuccess = LoadMap(sInput);
        }while(!bSuccess);

        sMapName=sInput;

        cout<<"Scan de la map pour déterminer le type de jeu..."<<endl;
        bRedTeam=false;
        bGreenTeam=false;
        bBlueTeam=false;
        bRedFlag=false;
        bGreenFlag=false;
        bBlueFlag=false;
        nGameType=0;

        int i, j;
        for(i=0 ; i<WORLD_HEIGHT_CUBE ; i++)
        {
            for(j=0 ; j<WORLD_WIDTH_CUBE ; j++)
            {
                switch(nWorldSpe[i][j])
                {
                    case WORLD_SPEC_FLAG_RED:       bRedFlag=true;  break;
                    case WORLD_SPEC_FLAG_GREEN:     bGreenFlag=true;  break;
                    case WORLD_SPEC_FLAG_BLUE:      bBlueFlag=true;  break;
                    case WORLD_SPEC_SPAWN_RED:      bRedTeam=true;  break;
                    case WORLD_SPEC_SPAWN_GREEN:    bGreenTeam=true;  break;
                    case WORLD_SPEC_SPAWN_BLUE:     bBlueTeam=true;  break;
                }
            }
        }

        nTeamNb = bRedTeam+bGreenTeam+bBlueTeam;
        switch(nTeamNb)
        {
            //---------------------------------
            case 0:
                nGameType = GAMETYPE_DM;
                break;
            case 1:
                nGameType=0;
                break;
            //---------------------------------
            case 2:
                if(  (bRedTeam && bRedFlag && bGreenTeam && bGreenFlag)
                   ||(bRedTeam && bRedFlag && bBlueTeam && bBlueFlag)
                   ||(bGreenTeam && bGreenFlag && bBlueTeam && bBlueFlag))
                    nGameType = GAMETYPE_CTF;
                else
                    nGameType = GAMETYPE_TDM;
                break;
            //---------------------------------
            case 3:
                if(bRedFlag && bGreenFlag && bBlueFlag)
                    nGameType = GAMETYPE_CTF;
                else
                    nGameType = GAMETYPE_TDM;
                break;
        }
        if(nGameType == 0)
        {
            cout<<"Erreur : map incomplete, impossible de continuer !"<<endl;
        }
    }while(nGameType==0);

    cout<<"Equipes : "<<nTeamNb<<" (";
    if(bRedTeam)cout<<" Rouge";
    if(bGreenTeam)cout<<" Vert";
    if(bBlueTeam)cout<<" Bleu";
    cout<<" )"<<endl;

    switch(nGameType)
    {
        case GAMETYPE_DM: cout<<"Mode de jeu : Match classique"<<endl; break;
        case GAMETYPE_TDM: cout<<"Mode de jeu : Match en equipe"<<endl; break;
        case GAMETYPE_CTF: cout<<"Mode de jeu : Capture de drapeau"<<endl; break;
    }

    //Parametres dans le serverconfig.cfg
    ifstream stServerConfig("serverconfig.cfg");
    if(!stServerConfig)
    {
        cout<<"serverconfig.cfg non trouvé !"<<endl;
        sf::Sleep(2.0);
        return 0;
    }

    std::string sVar;
    char cChar;
    do
    {
        stServerConfig>>sVar;
        if(sVar == "ServerName")
        {
            stServerConfig.seekg(1, ios::cur);
            getline(stServerConfig, sServerName);
            stServerConfig.seekg(-1, ios::cur);
        }
        else if(sVar == "SecuredPort")
        {
            stServerConfig>>nSecuredPort;
        }
        else if(sVar == "UnsecuredPort")
        {
            stServerConfig>>nUnsecuredPort;
        }
Пример #2
0
int RaptorServer::RaptorServerThread( void *game_server )
{
	Rand::Seed( time(NULL) );
	
	((RaptorServer*) game_server)->Net.Initialize( ((RaptorServer*) game_server)->Port );
	
	char cstr[ 1024 ] = "";
	
	if( ((RaptorServer*) game_server)->Net.Listening )
	{
		snprintf( cstr, 1024, "%s server started on port %i.", ((RaptorServer*) game_server)->Game.c_str(), ((RaptorServer*) game_server)->Port );
		((RaptorServer*) game_server)->ConsolePrint( cstr );
		
		NetUDP ServerAnnouncer;
		ServerAnnouncer.Initialize();
		
		Clock GameClock;
		Clock AnnounceClock;
		bool sleep_longer = false;
		
		while( ((RaptorServer*) game_server)->Net.Listening )
		{
			// Process network input buffers (one packet per client).
			((RaptorServer*) game_server)->Net.ProcessTop();
			
			// Calculate the time elapsed for the "frame".
			double elapsed = GameClock.ElapsedSeconds();
			if( (((RaptorServer*) game_server)->MaxFPS <= 0.0) || ( (elapsed > 0.0) && ((1.0 / elapsed) <= ((RaptorServer*) game_server)->MaxFPS) ) )
			{
				((RaptorServer*) game_server)->FrameTime = GameClock.ElapsedSeconds();
				GameClock.Reset();
				
				// Update location.
				((RaptorServer*) game_server)->Update( ((RaptorServer*) game_server)->FrameTime );
				
				// Drop disconnected clients from the list.
				((RaptorServer*) game_server)->Net.RemoveDisconnectedClients();
				
				// Send periodic updates to clients.
				((RaptorServer*) game_server)->Net.SendUpdates();

				// Send periodic server announcements over UDP broadcast.
				if( ((RaptorServer*) game_server)->Announce && (AnnounceClock.ElapsedSeconds() > ((RaptorServer*) game_server)->AnnounceInterval) )
				{
					AnnounceClock.Reset();

					Packet info( Raptor::Packet::INFO );
					
					// Properties.
					info.AddUShort( 3 + ((RaptorServer*) game_server)->Data.Properties.size() );
					info.AddString( "game" );
					info.AddString( ((RaptorServer*) game_server)->Game );
					info.AddString( "version" );
					info.AddString( ((RaptorServer*) game_server)->Version );
					info.AddString( "port" );
					char port_str[ 32 ] = "";
					snprintf( port_str, 32, "%i", ((RaptorServer*) game_server)->Port );
					info.AddString( port_str );
					for( std::map<std::string,std::string>::iterator property_iter = ((RaptorServer*) game_server)->Data.Properties.begin(); property_iter != ((RaptorServer*) game_server)->Data.Properties.end(); property_iter ++ )
					{
						info.AddString( property_iter->first.c_str() );
						info.AddString( property_iter->second.c_str() );
					}
					
					// Players.
					info.AddUShort( ((RaptorServer*) game_server)->Data.Players.size() );
					for( std::map<uint16_t,Player*>::iterator player_iter = ((RaptorServer*) game_server)->Data.Players.begin(); player_iter != ((RaptorServer*) game_server)->Data.Players.end(); player_iter ++ )
						info.AddString( player_iter->second->Name.c_str() );
					
					ServerAnnouncer.Broadcast( &info, 7000 );
				}
				
				// Don't work very hard if nobody is connected.
				sleep_longer = ( ((RaptorServer*) game_server)->Net.Clients.size() < 1 );
			}
			
			// Let the thread rest a bit.
			SDL_Delay( sleep_longer ? 100 : 1 );
		}
		
		snprintf( cstr, 1024, "%s server stopped.", ((RaptorServer*) game_server)->Game.c_str() );
		((RaptorServer*) game_server)->ConsolePrint( cstr );
	}
	else
	{
		snprintf( cstr, 1024, "%s server failed to start.", ((RaptorServer*) game_server)->Game.c_str() );
		((RaptorServer*) game_server)->ConsolePrint( cstr, TextConsole::MSG_ERROR );
	}
	
	((RaptorServer*) game_server)->Thread = NULL;
	((RaptorServer*) game_server)->State = Raptor::State::DISCONNECTED;
	return 0;
}
Пример #3
0
int main()
{
    // Create main window
    WindowSettings Settings;
    //Settings.AntialiasingLevel = 4;
    RenderWindow application(VideoMode(800, 600), "Game", (Style::Close | Style::Resize), Settings);
    application.PreserveOpenGLStates(true);
    application.UseVerticalSync(true);

    // Setup rendering
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glClearColor(0.f, 0.f, 0.f, 0.f);

    // Setup an ortho projection
    glViewport(0, 0, 800, 600);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.f, 800.f, 600.f, 0.f, 0.f, 100.f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    // Gather a pointer to the input system
    const Input& input = application.GetInput();

    // Create a clock for measuring the time elapsed
    Clock clock;

    // Create the game object
    Game game(input);
    game.init();

    // Start game loop
    while (application.IsOpened())
    {
        // Give the game mouse screen related's position
        game.setMousePosition(input.GetMouseX(), input.GetMouseY());

        // Process events
        Event event;
        while (application.GetEvent(event))
        {
            // Close window : exit
            if (event.Type == Event::KeyPressed && event.Key.Code == Key::Escape)
            {
                application.Close();
            }

            switch (event.Type)
            {
                case Event::Closed:
                    application.Close();
                    break;

                case Event::Resized:
                    game.onEvent(&event);
                    onWindowResized(event.Size.Width, event.Size.Height);
                    break;

                case Event::MouseButtonPressed:
                    game.onEvent(&event);
                    break;

                case Event::LostFocus:
                case Event::GainedFocus:
                case Event::TextEntered:
                case Event::KeyPressed:
                case Event::KeyReleased:
                case Event::MouseWheelMoved:
                case Event::MouseButtonReleased:
                case Event::MouseMoved:
                case Event::MouseEntered:
                case Event::MouseLeft:
                case Event::JoyButtonPressed:
                case Event::JoyButtonReleased:
                case Event::JoyMoved:
                case Event::Count:
                    break;
            }
        }

        // Clear depth buffer
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        //Update
        game.update(clock.GetElapsedTime());
        clock.Reset();

        // Draw...
        game.draw();

        // Finally, display the rendered frame on screen
        application.Display();
    }

    return EXIT_SUCCESS;
}
Пример #4
0
// Engine
bool Game::Update() {
        while(GetEvent(_event)) {
            // FABRICATION DE LA JAUGE
            if ( _event.Type == Event::KeyPressed && _event.Key.Code == Key::Space ) {
                if ( space == false && refire == true) {
                    space = true;
                    fire = false;
                    refire = false;
                    ratio = 0.0;
                    btime.Reset();
                }
            }
            if ( _event.Type == Event::MouseButtonPressed && _event.MouseButton.Button == Mouse::Left ) {
                Projectile * p = new Projectile();
                Artillery * a = static_cast<Artillery*>(_units[0]);
                a->LoadProjectile(p);
                _projectiles.push_back(p);
                _world->AddObject(p);
            }
            if ( _event.Type == Event::MouseButtonPressed && _event.MouseButton.Button == Mouse::Right ) {
                for( vector<Projectile*>::iterator it = _projectiles.begin(); it != _projectiles.end();) {
                    _world->DelObject((*it));
                    delete (*it);
                    _projectiles.erase(it);
                }
            }
            if ( _event.Type == Event::KeyPressed && _event.Key.Code == Key::H )
                hitbox ^= 1;

            if ( _event.Type == Event::KeyPressed && _event.Key.Code == Key::P )
                pause ^= 1;

            if ( _event.Type == Event::KeyPressed && _event.Key.Code == Key::N )
                if ( pause ) _world->Update();
        }
        /* INPUTS */
        if ( _win->GetInput().IsKeyDown(Key::Right) ) CameraMove(20);
        else if ( _win->GetInput().IsKeyDown(Key::Left)) CameraMove(-20);

        /* [Camera] Zoom Control */
        if ( _win->GetInput().IsKeyDown(Key::Down ) ) {
            if ( _baseZoom - 0.1 >= 0.3) {
                _baseZoom -= 0.1;
                float tmpmv = 382 *(-_baseZoom + 1);
                _camera.SetFromRect( FloatRect(_baseMoveX, 0-tmpmv, _baseMoveX+1024, 768-tmpmv  ));
                _camera.Zoom(_baseZoom);
            }
        }

        if ( _win->GetInput().IsKeyDown(Key::Up ) ) {
            if ( _baseZoom + 0.1 <= 1.0) {
                _baseZoom += 0.1;
                float tmpmv = 382 *(-_baseZoom + 1);
                _camera.SetFromRect( FloatRect(_baseMoveX, 0-tmpmv, _baseMoveX+1024, 768-tmpmv));
                _camera.Zoom(_baseZoom);
            }
        }


        if ( _win->GetInput().IsKeyDown(Key::Space ) ) {
            if ( space == true && fire == false ) {
                ratio = btime.GetElapsedTime() / 2.0;
                if ( ratio >= 1.0 ) {
                    ratio = 1.0;
                    fire = true;
                    space = false;
                }
                float angle = 90.0 - ( 180 * ratio);
                _HUD.GetElement(_idArrow)->SetRotation(angle);
            }

        }  else { if ( space == true ) { space = false; fire = true; } refire = true;}

        if ( fire ) {
                fire = false;
                _motions->AddMotion( _db->GetMotion("Catapult_Attack"), _units[0]);
        }

        /* PHYS ENGINE */
        if ( !pause ) _world->Update();

        /* ANIMATIONS */
        MotionSystem::MResp * resp = _motions->Compute();
        if ( resp ) {
            if ( resp->_value == MotionSystem::Fire )
                resp->_unit->Fire(ratio);
                Artillery * a = static_cast<Artillery*>(resp->_unit);
                a->CanonRotate(0);
        }

        return 1;
}
Пример #5
0
int main()
{
    // Create main window
    WindowSettings Settings;
    Settings.AntialiasingLevel = 4;
    Settings.StencilBits = 8;
    RenderWindow application(VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT), "Game", (Style::Close | Style::Resize), Settings);
    application.PreserveOpenGLStates(true);
    application.UseVerticalSync(false);
    application.SetFramerateLimit(0);

    // Setup rendering
    glShadeModel(GL_SMOOTH);
    glCullFace(GL_FRONT);
    //glEnable(GL_POINT_SMOOTH);
    //glEnable(GL_LINE_SMOOTH);
    //glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
    //glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

    // Vertex buffer objects
    #if USE_VBO
    glEnableClientState(GL_COLOR_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
    glEnableClientState(GL_VERTEX_ARRAY);
    #endif

    // Default values
    glDisable(GL_CULL_FACE);
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_STENCIL_TEST);
    glDepthMask(GL_FALSE);
    glColorMask(GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO);

    // Clear values
    glClearDepth(GL_ONE);
    glClearStencil(GL_ZERO);
    glClearColor(GL_ZERO, GL_ZERO, GL_ZERO, GL_ZERO);

    // Setup window
    setupWindow(SCREEN_WIDTH, SCREEN_HEIGHT);

    // Gather a pointer to the input system
    const Input& input = application.GetInput();

    // Create a clocks for measuring the time elapsed
    Clock gameClock;
    Clock clock;

    // Create the game object
    Game game;
    game.init();

    // Start game loop
    while (application.IsOpened())
    {
        // Give the game mouse screen related's position
        game.setMousePosition(input.GetMouseX(), input.GetMouseY());

        // Process events
        Event event;
        while (application.GetEvent(event))
        {
            // Close window : exit
            if (event.Type == Event::KeyPressed && event.Key.Code == Key::Escape)
            {
                application.Close();
            }

            switch (event.Type)
            {
                case Event::Closed:
                    application.Close();
                    break;

                case Event::Resized:
                    game.onEvent(&event);
                    onWindowResized(event.Size.Width, event.Size.Height);
                    break;

                case Event::MouseButtonPressed:
                    game.onEvent(&event);
                    break;

                case Event::LostFocus:
                case Event::GainedFocus:
                case Event::TextEntered:
                case Event::KeyPressed:
                case Event::KeyReleased:
                case Event::MouseWheelMoved:
                case Event::MouseButtonReleased:
                case Event::MouseMoved:
                case Event::MouseEntered:
                case Event::MouseLeft:
                case Event::JoyButtonPressed:
                case Event::JoyButtonReleased:
                case Event::JoyMoved:
                case Event::Count:
                    break;
            }
        }

        // Reset matix
        glLoadIdentity();

        // Isometric angle
        glRotatef(30.f, 1.f, 0.f, 0.f);
        glRotatef(-45.f, 0.f, 1.f, 0.f);

        // Scale
        glScaled(sqrt(1/2.0), sqrt(1/3.0), sqrt(1/2.0));

        //Update
        game.update(gameClock.GetElapsedTime());
        gameClock.Reset();

        // Framerate
        frameCount ++;
        if (clock.GetElapsedTime() >= 1.f)
        {
            std::cout << "Framerate: " << (frameCount * clock.GetElapsedTime()) << " FPS" << std::endl;
            frameCount = 0;
            clock.Reset();
        }

        //Draw...
        game.draw();

        // Finally, display the rendered frame on screen
        application.Display();
    }

    return EXIT_SUCCESS;
}