Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - reethok

Pages: 1 [2]
16
Mmm, they game will be a visual novel, so i need it to escale :S

17
Thank you, but that isnt what I want to do exactly.

I dont want to mantain a specific size (for example, 800x600), but to resize mantaining the proportion, in that case 4:3, and just filling with black what dont fit. (As in the images I put in the post).

Greetings.

18
First at all, sorry for my bad english.

Now, what i want to do is... I create a render window, with... for example, 1024x576, that is 16:9, what can I do so when it switches to full screen, it scales mantaining the proportion and it stop when the width or heigh is filled, centring the image and filling the unoccuped space with black.

If i didnt explained it well, this is a graphic explanation:






Greetings.

19
General / Re: Any sugestions to optimize this code?
« on: March 27, 2013, 12:37:06 pm »
Well, I'm using an Intel Atom netbook with Linux, haha, they're updated but i seriously doubt they work properly... I'll make some test in a Windows machine just to look how the program behaves.

20
General / Re: Any sugestions to optimize this code?
« on: March 27, 2013, 10:25:05 am »
First, music goes "slow" and the CPU consumption es 3-4%, and when the music start to go faster, it rises to 70-80%.

By the way, I've used the -O3 optimization flag and it seems to be usefull, now it maintains 3-4% of CPU consumption.

I tryed with -O2 and -O1, but it dont seems to have any effect, I wonder why (I know -O3 is better, but -O1 and -O2 are the same if i dont use any optimization flag).

Thanks for answering.

21
General / Any sugestions to optimize this code?
« on: March 27, 2013, 05:20:48 am »
Well... it uses ~70-80% of my CPU (I'm using a netbook) when the music start to go "hard"

#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <SFML/System.hpp>

int main()
{
    // Ventana en la que se muestra todo el contenido del juego.
    sf::RenderWindow gameWindow(sf::VideoMode(1024, 600, 32), "Project Genesis",
                                sf::Style::Fullscreen);

    // Se establece el límite de frames por segundo a 60
    gameWindow.setFramerateLimit(60);

    enum Boton{NUEVO_JUEGO, CONTINUAR, OPCIONES, SALIR};
    Boton boton = NUEVO_JUEGO;

    // Música
    sf::SoundBuffer buffer;
    buffer.loadFromFile("main.wav");

    sf::SoundBuffer button;
    button.loadFromFile("button.wav");

    sf::SoundBuffer selection;
    selection.loadFromFile("selection.wav");

    sf::Sound sound;
    sound.setBuffer(buffer);
    sound.setLoop(true);

    sf::Sound buttons;
    buttons.setBuffer(button);

    sf::Sound selections;
    selections.setBuffer(selection);

    sf::Texture menu_i;
    if(!menu_i.loadFromFile("menu.png"))
        return EXIT_FAILURE;
    sf::Sprite menu_s;
    menu_s.setTexture(menu_i);

    sf::Texture nuevo_juego_i;
    if(!nuevo_juego_i.loadFromFile("nuevo_juego.png"))
        return EXIT_FAILURE;
    sf::Sprite nuevo_juego_s;
    nuevo_juego_s.setTexture(nuevo_juego_i);
    nuevo_juego_s.setPosition(700, 225);

    sf::Texture nuevo_juego2_i;
    if(!nuevo_juego2_i.loadFromFile("nuevo_juego2.png"))
        return EXIT_FAILURE;
    sf::Sprite nuevo_juego2_s;
    nuevo_juego2_s.setTexture(nuevo_juego2_i);
    nuevo_juego2_s.setPosition(700, 225);

    sf::Texture continuar_i;
    if(!continuar_i.loadFromFile("continuar.png"))
        return EXIT_FAILURE;
    sf::Sprite continuar_s;
    continuar_s.setTexture(continuar_i);
    continuar_s.setPosition(700, 275);

    sf::Texture continuar2_i;
    if(!continuar2_i.loadFromFile("continuar2.png"))
        return EXIT_FAILURE;
    sf::Sprite continuar2_s;
    continuar2_s.setTexture(continuar2_i);
    continuar2_s.setPosition(700, 275);

    sf::Texture opciones_i;
    if(!opciones_i.loadFromFile("opciones.png"))
        return EXIT_FAILURE;
    sf::Sprite opciones_s;
    opciones_s.setTexture(opciones_i);
    opciones_s.setPosition(700, 325);

    sf::Texture opciones2_i;
    if(!opciones2_i.loadFromFile("opciones2.png"))
        return EXIT_FAILURE;
    sf::Sprite opciones2_s;
    opciones2_s.setTexture(opciones2_i);
    opciones2_s.setPosition(700, 325);

    sf::Texture salir_i;
    if(!salir_i.loadFromFile("salir.png"))
        return EXIT_FAILURE;
    sf::Sprite salir_s;
    salir_s.setTexture(salir_i);
    salir_s.setPosition(700, 375);

    sf::Texture salir2_i;
    if(!salir2_i.loadFromFile("salir2.png"))
        return EXIT_FAILURE;
    sf::Sprite salir2_s;
    salir2_s.setTexture(salir2_i);
    salir2_s.setPosition(700, 375);

    gameWindow.draw(menu_s);
    gameWindow.draw(nuevo_juego2_s);
    gameWindow.draw(continuar_s);
    gameWindow.draw(opciones_s);
    gameWindow.draw(salir_s);
    gameWindow.display();

    sf::Image captura;
    captura = gameWindow.capture();
    captura.saveToFile("captura.png");
   
    sound.play();

    // Mientras la ventana esté abierta
    while(gameWindow.isOpen())
    {
        // Ciclo para procesar eventos

        // Variable para almacenar los eventos
        sf::Event Event;

        while(gameWindow.pollEvent(Event))
        {
            switch (Event.type)
            {
                case sf::Event::Closed:
                    gameWindow.close();
                    break;
                case sf::Event::KeyPressed:
                    if(Event.key.code == sf::Keyboard::Escape)
                        gameWindow.close();
                    if(Event.key.code == sf::Keyboard::Up)
                    {
                        buttons.play();
                        switch(boton)
                        {
                            case NUEVO_JUEGO:
                                boton = SALIR;
                                break;
                            case CONTINUAR:
                                boton = NUEVO_JUEGO;
                                break;
                            case OPCIONES:
                                boton = CONTINUAR;
                                break;
                            case SALIR:
                                boton = OPCIONES;
                                break;
                        }
                    }
                    if(Event.key.code == sf::Keyboard::Down)
                    {
                        buttons.play();
                        switch(boton)
                        {
                            case NUEVO_JUEGO:
                                boton = CONTINUAR;
                                break;
                            case CONTINUAR:
                                boton = OPCIONES;
                                break;
                            case OPCIONES:
                                boton = SALIR;
                                break;
                            case SALIR:
                                boton = NUEVO_JUEGO;
                                break;
                        }
                    }
                    if(Event.key.code == sf::Keyboard::Return)
                    {
                        switch(boton)
                        {
                            case SALIR:
                                selections.play();
                                while(selections.getStatus() == sf::SoundSource::Status::Playing)
                                    sf::sleep(sf::milliseconds(1));
                                gameWindow.close();
                                break;
                        }
                    }
                default:
                    break;
            }

            // Limpia la pantalla
            gameWindow.clear();

            switch(boton)
            {
                case NUEVO_JUEGO:
                    gameWindow.draw(menu_s);
                    gameWindow.draw(nuevo_juego2_s);
                    gameWindow.draw(continuar_s);
                    gameWindow.draw(opciones_s);
                    gameWindow.draw(salir_s);
                    break;
                case CONTINUAR:
                    gameWindow.draw(menu_s);
                    gameWindow.draw(nuevo_juego_s);
                    gameWindow.draw(continuar2_s);
                    gameWindow.draw(opciones_s);
                    gameWindow.draw(salir_s);
                    break;
                case OPCIONES:
                    gameWindow.draw(menu_s);
                    gameWindow.draw(nuevo_juego_s);
                    gameWindow.draw(continuar_s);
                    gameWindow.draw(opciones2_s);
                    gameWindow.draw(salir_s);
                    break;
                case SALIR:
                    gameWindow.draw(menu_s);
                    gameWindow.draw(nuevo_juego_s);
                    gameWindow.draw(continuar_s);
                    gameWindow.draw(opciones_s);
                    gameWindow.draw(salir2_s);
                    break;
            }

            // Redibuja la oantalla
            gameWindow.display();
        }
    }
}
 

I'll thank you if you can help me with ideas to optimize.

Greetings, and sorry for my bad english.

22
Network / Re: Failed to bind socket to port 2000
« on: January 24, 2013, 11:41:09 am »
I've try it whit a friend and it doesnt work either.

That I'm doing wrong? :/

Greetings.

23
Network / Failed to bind socket to port 2000
« on: January 23, 2013, 10:01:05 am »
Well, i have this problem. Hope somebody can help me.

Sender:

#include <SFML/Network.hpp>
#include <iostream>

int main()
{
    sf::IPAddress Address("XXX.XXX.XXX.XX"); // My public IP
    std::string ip = Address.ToString();
    sf::SocketTCP *sock = new sf::SocketTCP;
    sf::SocketTCP Listener;

    Listener.Accept(*sock, &Address);
    char toSend[] = "Hola, qué tal";
    Listener.Listen(2000);
    sock->Send(toSend, sizeof(toSend));

    return 0;
}
 

Receiver:

#include <iostream>
#include <SFML/Network.hpp>
int main()
{
    sf::IPAddress ip(sf::IPAddress::GetPublicAddress());
    std::cout << "Mi IP es " << ip.ToString() << "." << std::endl;
    sf::SocketTCP socket;
    sf::SocketTCP socketEntrada;
   std::size_t asdf;

    socketEntrada.Connect(2000,"XXX.XXX.XXX.XX"); // My public IP


    char recibidor[] = "asdasdasdasdfafgufbrfsifhbvrufbwufbwuvwufebwfnwjfvwuebfwhlbfvewf";

    if (!socket.Listen(2000)) {
        std::cout << "No se puede escuchar el puerto 2000." << std::endl;
        return 1;
    }

    while (!socket.Accept(socketEntrada, NULL));
    std::cout << "Se a conectado al puerto 2000." << std::endl;
    socketEntrada.Receive(recibidor, sizeof(recibidor), asdf);

    std::cout << recibidor << std::endl;
r    eturn 0;
}
 

I run first the reciever, then in another terminal the sender, and the sender oututs this:

"Failed to bind socket to port 2000".

Why is this happening?

Thank you, greetings.

EDIT:
I changed the ort to 1984, and now the sender runs, but nothing happens, it just ends in 1 milisecond (?), and the reciever just stay like "nikolov@rettask:~/Escritorio$ ./B
Mi IP es 201.141.136.35."

Pages: 1 [2]