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 - Dante12129

Pages: [1] 2
1
SFML projects / Re: Thor 2.0
« on: February 23, 2014, 07:16:15 am »
I have compiled SFML and Thor before, but I am having issues with the latest versions. I got SFML to compile fine, but whenever I try to configure Thor in Cmake, it gives me this message:
Could NOT find SFML (missing:  SFML_AUDIO_LIBRARY SFML_GRAPHICS_LIBRARY SFML_WINDOW_LIBRARY SFML_SYSTEM_LIBRARY)

-> SFML directory not found. Set SFML_ROOT to SFML's top-level path (containing "include" and "lib" directories).
-> Make sure the SFML libraries with the same configuration (Release/Debug, Static/Dynamic) exist.

I have all my SFML stuff in C:/SFML-2.1, and have set the SFML_ROOT in Cmake to there. I have SFML_INCLUDE_DIR set to C:/SFML-2.1/include. I compiled SFML into debug and release dynamic libraries, and have THOR_SHARED_LIBS set to do the same. I am using Windows 7 and TDM GCC 4.8.1.

2
Graphics / Problem with Texture::create in custom class
« on: November 29, 2013, 02:44:44 am »
I am creating a custom class, called TexturedSprite, to ease the process of loading textures/ setting a sprite's texture/ drawing the sprite. It basically holds a Texture pointer and sprite and autmatically takes care of the relations between them. The problem is when I try to load a file into the texture.

Here are the definitions of my loadFromFile function and constructor that takes a string parameter:

bool TexturedSprite::loadFromFile(const std::string& filename, const sf::IntRect& area) { return m_texture->loadFromFile(filename, area); m_sprite.setTexture(*m_texture); }
TexturedSprite::TexturedSprite(const std::string& filename)
    {
        //Load the texture
        if(!m_texture->loadFromFile(filename))
           std::cout << "Failed to load file for textured sprite: " << filename << std::endl;
        m_sprite.setTexture(*m_texture); //Set the sprite to the texture
    }

I ran my program in gdb and the call stack says the problem is at sf::Texture::create, specifically line 125:
m_size.x        = width;
Here is my call stack:
#0 68ED9585     sf::Texture::create(this=0xbaadf00dbaadf00d, width=950, height=600) (C:\SFML-2.1\src\SFML\Graphics\Texture.cpp:125)
#1 68ED9A2A     sf::Texture::loadFromImage(this=0xbaadf00dbaadf00d, image=..., area=...) (C:\SFML-2.1\src\SFML\Graphics\Texture.cpp:192)
#2 68ED97F7     sf::Texture::loadFromFile(this=0xbaadf00dbaadf00d, filename=..., area=...) (C:\SFML-2.1\src\SFML\Graphics\Texture.cpp:160)
#3 00402349     whack::TexturedSprite::TexturedSprite(this=0x6f7708, filename=...) (C:\Users\Main\Documents\Programs\WhackGame\src\TexturedSprite.cpp:12)
#4 00401A73     whack::IntroState::IntroState(this=0x6f76f0, window=...) (C:\Users\Main\Documents\Programs\WhackGame\src\IntroState.cpp:12)
#5 004016DA     whack::Game::Game(this=0x22fbf0) (C:\Users\Main\Documents\Programs\WhackGame\src\Game.cpp:8)
#6 00401512     main() (C:\Users\Main\Documents\Programs\WhackGame\main.cpp:5)
 

Here is the code I'm calling it from (it crashes whether I use the initializer list or loadFromFile function:
IntroState::IntroState(sf::RenderWindow& window) : m_window(&window), m_needs_change(false, dte::StateChangeType::Next) //,m_background("Resources/Images/intro_background.png"), m_logo("Resources/Images/logo.png")
    {
        if(!m_background.loadFromFile("Resources/Images/intro_background.png"))
            std::cerr << "Unable to load background texture for intro state." << std::endl;
        if(!m_logo.loadFromFile("Resources/Images/logo.png"))
            std::cerr << "Unable to load background texture for intro state." << std::endl;
    }

It works fine if I do the textures and sprites separately. I am using TDM gcc 4.8.1, Windows 7 64-bit, and CB 12.11. I have included my TexturedSprite files and IntroState files in case you need any more information.

3
Graphics / Re: Strange problem
« on: November 13, 2013, 02:43:15 am »
I did some debugging and found that I get a crash in the RtlFreeHeap function in Windows.

Call Stack:
#0 76EE3290     ntdll!RtlFreeHeap() (C:\Windows\system32\ntdll.dll:??)
#1 006A0000     ?? () (??:??)
#2 00000001     ?? () (??:??)
#3 05E16680     ?? () (??:??)
#4 05E16690     ?? () (??:??)
#5 ??   ?? () (??:??)

And gdb output at the time:
Program received signal SIGSEGV, Segmentation fault.
In ntdll!RtlFreeHeap () (C:\Windows\system32\ntdll.dll)

It'll also now not work wherever I try to run it from.

4
Graphics / Re: Strange problem
« on: November 12, 2013, 03:50:46 am »
I compiled SFML and replaced all my dlls, but now it'll work flawlessly in CB in debug but still crash when run in release and outside of CB.

5
Graphics / Strange problem
« on: November 11, 2013, 11:32:51 pm »
I am having a problem drawing both a texture and the ball in my Pong game. When I don't load something into the texture and draw the ball, it will work. If I load something into the texture but don't draw the ball, it still works. But if I try to do them both, it'll crash after I close the window and the program is exiting. I have all my linking right and the image for the texture is in the right place.
Here's my code:

main.cpp
#include <SFML/Graphics.hpp>
#include "include/Ball.hpp"

int main()
{
    //Create the main window
    sf::RenderWindow main_window(sf::VideoMode(950, 600), "Epicyoobed Pong");
    main_window.setKeyRepeatEnabled(false);
    main_window.setFramerateLimit(60);

    //Load the background
    sf::Texture background_tex;
    if(!background_tex.loadFromFile("background.png"))
        return EXIT_FAILURE;
    sf::Sprite background(background_tex);

    //Create the ball
    pong::Ball main_ball(sf::Vector2f(50, 50));

    //Create the stuff for frame tracking
    sf::Clock delta_clock;
    sf::Time delta_time;

        //Start the game loop
    while (main_window.isOpen())
    {
        //Update the delta
        delta_time = delta_clock.getElapsedTime();
        delta_clock.restart();

        //Process events
        sf::Event event;
        while(main_window.pollEvent(event))
        {
            if(event.type == sf::Event::Closed)
                main_window.close();
        }

        //Logic
        main_ball.ScreenCollide(main_window);
        main_ball.update(delta_time);

        //Render
        main_window.clear();
        main_window.draw(background);
        main_window.draw(main_ball);
        main_window.display();
    }

    return EXIT_SUCCESS;
}
Ball.hpp
#ifndef BALL_HPP
#define BALL_HPP

#include <SFML/Graphics.hpp>

namespace pong
{
    class Ball : public sf::Drawable
    {
        public:
            Ball();
            Ball(sf::Vector2f start_pos);
            ~Ball();

            //Setters
            void setVelocity(sf::Vector2f new_vel);

            //Collision Handling
            void ScreenCollide(const sf::RenderWindow& screen);

            //Main loop methods
            void update(const sf::Time& dt);
            void draw(sf::RenderTarget& target, sf::RenderStates states) const;

        private:
            //Position and velocity of the ball
            sf::Vector2f m_pos = {0, 0};
            sf::Vector2f m_vel = {500, 500};

            //The visual representation
            sf::CircleShape m_circle;
    };
}

#endif // BALL_HPP
Ball.cpp
#include "../include/Ball.hpp"

#include <iostream>

namespace pong
{
    Ball::Ball() = default;
    Ball::Ball(sf::Vector2f start_pos) : m_pos(start_pos), m_circle(15) { m_circle.setFillColor(sf::Color::Blue); }
    Ball::~Ball() = default;

    void Ball::setVelocity(sf::Vector2f new_vel) { m_vel = new_vel; }

    void Ball::ScreenCollide(const sf::RenderWindow& screen)
    {
        if(m_pos.x < 0 || (m_pos.x > screen.getSize().x - m_circle.getRadius() * 2))
            m_vel.x = -m_vel.x;
        if(m_pos.y < 0 || (m_pos.y > screen.getSize().y - m_circle.getRadius() * 2))
            m_vel.y = -m_vel.y;
    }

    void Ball::update(const sf::Time& dt) { m_circle.setPosition(m_pos += (m_vel * dt.asSeconds())); }
    void Ball::draw(sf::RenderTarget& target, sf::RenderStates states) const { target.draw(m_circle, states); }
}

I am on Windows 7 with with the TDM MinGW 4.8.1 and I'm using CB as my IDE.

6
Window / Re: Backspace not erasing last char?
« on: June 24, 2013, 04:23:37 am »
You should clear the window in the game loop before you draw anything.

7
General / Re: Error with multidimensional array
« on: June 23, 2013, 03:38:20 am »
I have now determined that it isn't my loading code that is messing up, but my drawing code. I used the debugger and saw that it was putting the correct numbers in the correct spot in the array. I also added some debugging output to the loops to confirm this. Now here's my drawing code:

void Map::draw(sf::RenderTarget& target, sf::RenderStates states) const
    {
        sf::Sprite current_sprite;
        static int once_flag = 0;

        if(!once_flag)
        {
            std::cout << m_map.GetHeight() << ", " << m_map.GetWidth() << std::endl;
            std::cout <<  m_map_dimensions.x << ", " <<  m_map_dimensions.y << std::endl;
            for(unsigned int i = 0; i < m_map_dimensions.y; i++)
            {
                for(unsigned int j = 0; j < m_map_dimensions.x; j++)
                {
                    std::cout << m_map(i, j) << " ";
                }
                std::cout << std::endl;
            }
            std::cout << std::endl;
            once_flag = 1;
        }

        for(unsigned int i = 0; i < m_map_dimensions.y; i++)
        {
            for(unsigned int j = 0; j < m_map_dimensions.x; j++)
            {
                try
                {
                    current_sprite.setTexture(m_spritesheet.GetTexture());
                    current_sprite.setTextureRect(m_spritesheet.GetRect(m_map(i, j)));

                    current_sprite.setPosition(j * m_tile_dimensions.x, i * m_tile_dimensions.y);

                    target.draw(current_sprite, states);
                }
                catch(std::exception& e)
                {
                    std::cerr << "Vector overflow in map drawing. Error: " << e.what() << std::endl;
                }
            }
        }
    }

As far as I can see, the loops are the same as the loading loop, but they both produce the same output, which is the skewed version of the map.

8
General / Re: Error with multidimensional array
« on: June 23, 2013, 02:19:33 am »
I've gone back to my original code as it gets me closest to what I intend to do, but I did add a check to see if the input operation succeeds. And by modifying my map file I discovered that it is loading the 16th-20th tiles as the first few tiles of the next line.

9
General / Re: Error with multidimensional array
« on: June 22, 2013, 06:05:01 pm »
I tried changing my code to use a normal vector but is still giving me messed up output. This is my new code:

int current_tile, i = 0, j = 0;
            while(map_file >> current_tile)
            {
                try
                {
                    //m_map.at(i * m_map_dimensions.y + j) = current_tile;
                    m_map.push_back(current_tile);
                }
                catch(std::exception& e)
                {
                    std::cerr << "Vector overflow in map loading. Error: " << e.what() << std::endl;
                }

                if(j < m_map_dimensions.y)
                    j++;
                else
                {
                    j = 0;
                    if(i < m_map_dimensions.x)
                        i++;
                    else
                        i = 0;
                }
            }

I also did a comparison between my MultiArray and a normal vector and they both worked the same (with MultiArray's one and two parameter access operator).

10
General / Error with multidimensional array
« on: June 22, 2013, 04:28:39 am »
I am having trouble accessing a one-dimensional vector as a multi-dimensional one.
I have a MultiArray template class, and it is accessed using the function operator. It accesses elements through the expression row * m_columns + col. The row and col are the two inputs to the operator while the m_columns is the width/number of columns in the array. There is also a version that accesses the array with one number. Its underlying representation is a one-dimensional vector.

The problem is when I try to load a level:
void Map::LoadFromFile(const std::string& filename)
    {
        std::ifstream map_file(filename);

        std::cout << m_map.GetHeight() << ", " << m_map.GetWidth() << std::endl;
        std::cout <<  m_map_dimensions.y << ", " <<  m_map_dimensions.x << std::endl;
        if(map_file.is_open())
        {
            for(unsigned int i = 0; i < m_map_dimensions.y; i++)
            {
                for(unsigned int j = 0; j < m_map_dimensions.x; j++)
                {
                    int current_tile;
                    map_file >> current_tile;

                    try
                    {
                            m_map(i, j) = current_tile;
                    }
                    catch(std::exception& e)
                    {
                        std::cerr << "Vector overflow in map loading." << std::endl;
                        exit(EXIT_FAILURE);
                    }
                }
            }
        }
        else
            std::cerr << "Couldn't load map file: " << filename << "." << std::endl;
    }

(The m_map is a MultiArray<int> and the m_map_dimensions an sf::Vector2u)

The dimensions of the level are 20 * 15 (screen dimensions divided by height dimensions), so I made a map file that looks like this:
Quote
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00


but it loads it skewed and only ever accesses up to element 229 in the MultiArray.

This is how it loads the file:
Quote
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

The graphical output code is outputting this messed-up array in the graphical representation of this using a spritesheet, so I know it is working correctly.

11
Graphics / Re: Creating a font in initializer list
« on: June 15, 2013, 08:20:04 pm »
The state manager already is part of my game class, and it wouldn't work properly because I couldn't initialize the game class' font in the initialzer list before it.

12
Graphics / Re: Creating a font in initializer list
« on: June 15, 2013, 03:26:35 am »
I'm adding a method to my state manager to allow it to be initialized with a state after construction.

13
Graphics / Creating a font in initializer list
« on: June 14, 2013, 09:30:51 am »
I have a state machine in my game in order to handle different menus, gameplay sequences, credits and etc. Each state stores a reference to the main font in the game. The problem is that I am using a game class so that I can keep the code in my main down to a minimum. This class stores the actual font. The thing is that I initialize my state manager with the first state, so I use the initializer list. The thing is that I have to initialize the font before it, but I can't get it to work.

The variables are declared like this:
sf::RenderWindow main_window;
sf::Font main_font;

dte::StateManager m_state_manager;
 

And the game class' constructor looks like this:
Game::Game() : main_window(sf::VideoMode(640, 480), "Animal Instincts"), main_font(), m_state_manager(new MenuState(main_window, main_font)) { main_font.loadFromFile("Unispacerg.ttf"); }
 
The state manager has to take its first state in its constructor in order to work properly, as I have no function to initialize it later.

And the MenuState's constructor:
MenuState::MenuState(sf::RenderWindow& window, sf::Font& font) : m_window_ptr(&window), m_font(font), m_needs_change(false), m_welcome_message("Welcome", m_font, 30)
    {
        m_welcome_message.setColor(sf::Color::White);
        dte::CenterTextHor(m_welcome_message, *m_window_ptr);

        std::cout << "Menu state created." << std::endl;
    }
 

The problem is that this code will only show the text if I cause a new Menustate to be created. How would I go about initializing the font in the initializer list so that it will work the first time?

14
Network / Trouble connecting to remote computer
« on: June 14, 2013, 07:58:35 am »
I was working on a simple client/server test where a server sends a message to the client. The problem is that it'll work fine when I use localhost, but when me and my friend try it using each others' IPs it doesn't work. I am reading the IP and port from a text file. We are only changing the IP of the client since the server only uses the port. I also tried connecting to the server running on his machine with Telnet, but it still wouldn't work. We tried both the public and IPv4 IP addresses of our computers. What does it take to connect to a remote computer?

Client Code:
#include <fstream>
#include <iostream>
#include <sstream>
#include <boost/lexical_cast.hpp>
#include <SFML/Network.hpp>

int main()
{
    std::fstream connection_info_file("AP.txt");

    std::string server_ip;
    std::string port;
    std::getline(connection_info_file, server_ip);
    std::getline(connection_info_file, port);

    std::stringstream ip_buffer;
    for(auto itr = server_ip.find("=") + 2; itr < server_ip.size(); itr++)
    {
        ip_buffer << server_ip.at(itr);
    }
    server_ip = ip_buffer.str();

    std::stringstream port_buffer;
    for(auto itr = port.find("=") + 2; itr < port.size(); itr++)
    {
        port_buffer << port.at(itr);
    }
    port = port_buffer.str();

    std::cout << server_ip << std::endl;
    std::cout << port << std::endl;

    std::cout << "Welcome to the client." << std::endl;

    sf::TcpSocket server;
    sf::Socket::Status status = server.connect(server_ip, boost::lexical_cast<unsigned short>(port));
    if(status != sf::Socket::Done)
    {
        std::cerr << "Error connecting." << std::endl;
        return EXIT_FAILURE;
    }

    sf::Packet data;
    server.receive(data);

    std::string message;
    if(data)
    {
        std::cout << "Getting data from: " << server.getRemoteAddress() << std::endl;
        data >> message;
        std::cout << message << std::endl;
    }
    else
    {
        std::cerr << "Data received not valid." << std::endl;
        return EXIT_FAILURE;
    }

    sf::Clock delay;
    while(delay.getElapsedTime().asMilliseconds() < 5000);
    return EXIT_SUCCESS;
}
 
Server Code:
#include <fstream>
#include <iostream>
#include <sstream>
#include <boost/lexical_cast.hpp>
#include <SFML/Network.hpp>

int main()
{
    std::fstream connection_info_file("AP.txt");

    std::string server_ip;
    std::string port;
    std::getline(connection_info_file, server_ip);
    std::getline(connection_info_file, port);

    std::stringstream ip_buffer;
    for(auto itr = server_ip.find("=") + 2; itr < server_ip.size(); itr++)
    {
        ip_buffer << server_ip.at(itr);
    }
    server_ip = ip_buffer.str();

    std::stringstream port_buffer;
    for(auto itr = port.find("=") + 2; itr < port.size(); itr++)
    {
        port_buffer << port.at(itr);
    }
    port = port_buffer.str();

    std::cout << server_ip << std::endl;
    std::cout << port << std::endl;

    std::cout << "Welcome to the server." << std::endl;

    sf::TcpListener listener;
    if (listener.listen(boost::lexical_cast<unsigned short>(port)) != sf::Socket::Done)
    {
        std::cerr << "Error listening to socket." << std::endl;
        return EXIT_FAILURE;
    }

    sf::TcpSocket client;
    if (listener.accept(client) != sf::Socket::Done)
    {
        std::cerr << "Couldn't connect to client." << std::endl;
        return EXIT_FAILURE;
    }
    else
    {
        sf::Packet data;
        data << "Hello there.";

        std::cout << "Connected to: " << client.getRemoteAddress() << std::endl;
        client.send(data);
        std::cout << "Data sent." << std::endl;
    }

    sf::Clock delay;
    while(delay.getElapsedTime().asMilliseconds() < 5000);
    return EXIT_SUCCESS;
}
 

15
SFML wiki / Re: CodingMadeEasy Tutorials
« on: May 30, 2013, 11:34:33 pm »
Ok, It has been updated.

Pages: [1] 2