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.


Topics - spacechase0

Pages: [1]
1
SFML projects / One Chance
« on: May 20, 2015, 09:23:16 pm »
This is a game I made back in Ludum Dare 26. About a month ago I made some changes to it, and at the beginning of this month I got it working with iOS. (The name was already taken though so I had to go through the review process twice. :P)



Not much is changed from the original LD version. Just the easy/hard mode, balance tweaks, and a few other minor details.

The Windows version is here (I haven't gotten around to building the new Mac/Linux versions yet).
The iOS version is here.

2
When NSHighResolutionCapable is set to true in the application plist, sf::Touch::getPosition is returning values that don't match the corresponding events. It doesn't seem to take the retina display into account.

#include <iostream>
#include <SFML/Graphics.hpp>
#include <SFML/Main.hpp>

int main( int argc, char* argv[] )
{
        sf::RenderWindow window( sf::VideoMode::getDesktopMode(), "Test" );

        while ( window.isOpen() )
        {
                sf::Event event;
                while ( window.pollEvent( event ) )
                {
                        if ( event.type == sf::Event::TouchBegan )
                        {
                                std::cout << "A: " << event.touch.x << ", " << event.touch.y << std::endl;
                                sf::Vector2i pos = sf::Touch::getPosition( event.touch.finger );
                                std::cout << "B: " << pos.x << ", " << pos.y << std::endl;
                        }
                }

                window.clear();
                window.display();
        }

        return 0;
}

I tested it in both the 4s and 6+ simulators (target SDK 8.1), using the bugfix/gles branch.

3
SFML projects / QuickSnap - Screenshot program
« on: October 25, 2012, 06:17:29 pm »
(Not sure if anything else uses that name. It was the first thing I thought of. :P)

This is just a quick little tool to take screenshots. An IM program called Trillian allows me to directly paste an image from my clipboard into chat. I got tired doing this every time I wanted to screenshot something:

  • PrintScreen
  • G2 (I have a Logitech G19, I set this key to open MS-Paint)
  • Find the newly-opened Paint window
  • Ctrl+V
  • Crop
  • Ctrl+A
  • Ctrl+C

So, I made this. :) It works with multiple monitors (or at least, two same-sized monitors).

Starting the program appears to do nothing. Instead, it needs to be activated by a key combination:

Pressing Ctrl+PAGE_UP will lighten the entire screen, and a small black circle will follow your mouse. Now, click and drag, and a black rectangle will show the selection area. If you aren't happy with that rectangle, you can choose another. Once you've chosen an area, press enter. The white area and black rectangle should disappear, and the new screenshot will appear in your clipboard. It is also saved to "%APPDATA%/quicksnap".

If you want to close it for some reason, press Ctrl+PAGE_DOWN. A window should show up like this:



Pressing the red "No" button will let it continue running, and pressing the green "Yes" button will close it. Once it is closed, you can't do Ctrl+PAGE_UP anymore.

If you hadn't guessed by the "%APPDATA%" comment earlier, it's Windows-only (although it should be fairly easy to port). It would probably work great as a startup program though!

Download
Version 0.1.1: Download
Version 0.1.0: Download

The source code is here.

Changelog
Quote
[10/25/2012] Initial Release
[11/5/2012] Fixed issue with images being washed out on some computers.

4
This adds a "DOCS" link to the navigation bar leading to the SFML 2.0 2.4..2 class list (in a new tab).

(10/21/2012: Added search box)
(05/07/2013: Fixed for new forum header, fixed bug with going to main forum page on form submit.)
(05/09/2017: Fixed for https and changed docs version to 2.4.2)

I just thought other people might find it useful. :P

(Old version for slightly larger search box here.)
(Old version for old forum header here.)
(Old version with just the link here.)

5
General / SFML Port Problem: Textures Not Displayed
« on: April 15, 2012, 09:19:00 pm »
I've been sporadically working on an SFML port for a while, and I almost have every module (except audio) working. The main problem is that the graphics module won't work with textures.

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

int main()
{
        std::streambuf* coutBuf = std::cout.rdbuf();
        std::streambuf* errBuf = sf::err().rdbuf();
        sf::err().rdbuf( coutBuf );
       
        sf::RenderWindow window( sf::VideoMode( 320, 240, 24 ),"Window" );
        window.setFramerateLimit( 1 );
       
        sf::Font font;
        std::cout << "Loading \"resources/sansation.ttf\"... " << ( font.loadFromFile("resources/sansation.ttf") ? "Success" : "Failure" ) << std::endl;

        sf::Texture tex;
        std::cout << "Loading \"resources/image.png\"... " << ( tex.loadFromFile( "resources/image.png" ) ? "Success" : "Failure" ) << std::endl;
       
        std::cout<<"SC\n\n";
        sf::Text text( "String", font, 20.f );
        std::cout<<"MC\n\n";
        sf::Sprite spr;
        spr.setTexture( tex, true );
        spr.setPosition( sf::Vector2f( 100, 100 ) );
        std::cout << "EC\n\n";
       
        while ( window.isOpen() )
        {
                sf::Event event;
                while ( window.pollEvent( event ) )
                {
                        if ( event.type == sf::Event::Closed )
                        {
                                window.close();
                        }
                        else if ( event.type == sf::Event::KeyPressed )
                        {
                                std::cout << "Key pressed" << std::endl;
                                if ( event.key.code == sf::Keyboard::Menu )
                                {
                                        window.close();
                                }
                        }
                }
               
                window.clear();
                window.draw( text );
                window.draw( spr );
                window.display();
        }
       
        std::cout.rdbuf( coutBuf );
        sf::err().rdbuf( errBuf );
}
This works fine on my computer, but on the GP2X Wiz (what I'm porting to), it doesn't.

Whether I use sf::Sprite or sf::Text (or both), nothing gets displayed. If I use sf::Sprite, there is a segmentation fault after the main loop (maybe from sf::Texture?).

sf::*Shape works fine though. :) I haven't tested it with a texture.

The logs (minus a bunch of unrelated stuff):
Code: [Select]
Loading "resources/sansation.ttf"... Success
Loading "resources/image.png"... Success
SC

Failed to create texture, invalid size (0x0)
Failed to create texture, invalid size (0x0)
Trying to access the pixels of an empty image
MC

EC

Key pressed
Key pressed
Segmentation fault

So, I'm completely lost. :P Any ideas?

EDIT: Oops, forgot to mention the code is here: https://github.com/spacechase0/SFML/tree/wiz

6
SFML projects / Tower Defense
« on: March 30, 2012, 10:55:26 pm »
Since it's "technically" in a playable state now, I thought I'd go ahead and post this. :P

I've been working on this for a little over a week and a half. I've been using SFML and SFGUI, and once it's further along, I might use Thor for particles.


The black rotating squares are damage-over-time effects.

Obviously it still has a long way to go. Here's a couple of the things I want to do:
  • More levels/enemies/towers/traps (traps not implemented yet)
  • Highscores (online?)
  • Map Editor
  • Ability to record and watch a level.
  • More!

I have no idea what I'll do with it once I finish. :P

Download (0.08):
Windows
I'll add Linux/Mac once it's more playable.

Website: Tower Defense

7
Network / sf::SocketTCP::SetBlocking Causes Memory Usage to Skyrocket
« on: April 14, 2010, 05:34:47 pm »
I'm finally trying the networking package again, but I'm having another problem, which is probably another silly mistake. :(

I'm using SFML 1.5 (dynamically linked) (going to upgrade soon) on Windows XP with Code::Blocks.

When I open task manager and go under processes, the far right column is Mem Usage, and processes usually have something like 4,484 K. This number goes up by around 10,000 (for the application I'm trying to make) every half-a-second-ish. I've been playing around with commenting stuff, and I found the problem (I think).

I make a pointer to a socket, and it points to one made with new. At first I thought it happened because I didn't delete it, but when all I had was new and delete, it worked fine.

Earlier, it was only going up when I used SetBlocking to false, but now it does it if I use SetBlocking at all...

Don't bother asking for a minimal example, I already made one! :D

Code: [Select]

#include <SFML/Network.hpp>

using namespace sf;

int main()
{
    bool isTesting = true;
    while ( isTesting )
    {
        sf::SocketTCP *testSocket = new sf::SocketTCP;
        testSocket->SetBlocking( true );
        delete testSocket;
    }
    return 0;
}


For once, I would be happy if it was a silly mistake. :P



Unrelated note: I just recently noticed that the tutorial for setting SFML up said that if I use it dynamically linked I have to define SFML_DYNAMIC in the project settings... I've never done that before! :lol: When I add it in, it works just the same.

8
System / Problems with a Class Inheriting from sf::Thread
« on: March 29, 2010, 03:50:24 am »
I'm using SFML 1.5 linked dynamically, on Microsoft Windows XP Professional (Version 2002, Service Pack 3).

Compiler Errors:
Quote
C:\Documents and Settings\Chase\Desktop\C++\Puzzle Game\source\main.cpp|24|error: no matching function for call to `LoadingThread::LoadingThread()'|
C:\Documents and Settings\Chase\Desktop\C++\Puzzle Game\source\Thread_Class.h|10|note: candidates are: LoadingThread::LoadingThread(const LoadingThread&)|


I have a pretty good feeling that I'm not supposed to define anything of my own that's public (when inheriting public sf::Thread), because commenting that out makes it compile fine (except for the 'LoadingThread has no member X ' errors).

Relevant Part of main.cpp
Code: [Select]
   LoadingThread loading;
    loading.images = gameImages;
    loading.images = gameFonts;
    loading.Launch();



Thread_Class.h:
Code: [Select]
#ifndef THREAD_CLASS_H
#define THREAD_CLASS_H

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <string>
#include <map>

class LoadingThread : public sf::Thread
{
    private:
        int loadedSoFar;
        virtual void Run();

    public:
        int GetLoadedSoFar();
        std::map<std::string, sf::Image>& images;
        std::map<std::string, sf::Font>& fonts;
};

#endif

9
Network / Send() goes to... which executable?
« on: January 04, 2010, 03:29:33 am »
I am getting thoroughly confused. I am trying to make a (semi-simple) chat program, but it seems random which application it chooses to send it to (when multiple are open) (usually the second one opened, sometimes the first). It also doesn't necessarily send it to one in server mode, even when I changed the 'to server' and 'to client' ports! I have been (mostly) trying this on one computer. When I opened the server on one computer and a client on another, I sent a message and it gave me the error message (on the server). Now when I open another on the server computer and send something, it sends it to itself, A LOT. It doesn't give me the error, either. Can someone point out where in my code I am going wrong?

(By the way, I already know what happens when a message is sent while you are typing, I plan on moving to a normal window later.)

Code: [Select]

//Includes
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>

//Namespaces
using namespace std;
using namespace sf;

//Constants
const int CONNECT = 1;
const int HOST = 2;
const int UNKNOWN = 3;    //This part will be implemented later.

//Classes
class client_receive : public sf::Thread
{
    public:
        bool receiving;
        sf::Packet packet;
        sf::IPAddress sender;
        sf::SocketUDP socket;
        string buffer;
        unsigned short port;

    private:

        virtual void Run()
        {
            while (receiving == true)
            {
                if (socket.Receive(packet,sender,port) != sf::Socket::Done)
                {
                    cout << "Odd... It seems there was an error receiving the message.\n";
                }
                string buffer;
                packet >> buffer;
                cout << buffer << "\n";
                packet.Clear();
            }
        }
};

int main()
{
    cout << "Welcome to the SGM Chat! Please wait for the program to load...\n";
    cout << "CAUTION: Program uses UDP, so some messages may not be received.\n\n";
    sf::SocketUDP socket;
    if (!socket.Bind(54358))
    {
        cout << "ERROR BINDING SOCKET\n";
    }
    sf::IPAddress ip = sf::IPAddress::GetLocalAddress();
    bool answ_ques = false;
    string answ_to;
    int answ_res;
    while (answ_ques == false)
    {
        cout << "Would you like to:\n";
        cout << "\tA. Connect to a Server\n";
        cout << "\tB. Host a Server\n";
        getline(cin,answ_to);
        if (answ_to == "A" or answ_to == "a")
        {
            cout << "\nWell goody! Please enter the IP address.\n";
            answ_res = CONNECT;
            answ_ques = true;
        }
        else if (answ_to == "B" or answ_to == "b")
        {
            cout << "\nTell people on your network to connect to " << ip << ", if they are in your network. You can go to whatismyip.org to get your external IP address, but using that you will probably need to port forward.\n\n";
            answ_res = HOST;
            answ_ques = true;

        }
        else
        {
            cout << "\nUh, you need to pick one of the two choices. Try READING them this time.\n\n";
            answ_res = UNKNOWN;
        }
    }
    if (answ_res == HOST)
    //Host will be separated later.
    {
        cout << "Open another window if you want to talk, depending on how busy your server is you might not get to read much.\n\n";
        //sf::SelectorUDP selector;
        std::vector<sf::IPAddress> clients;
        bool not_canc = true;
        sf::IPAddress sender;
        unsigned short port;
        bool client_found = false;
        while (not_canc == true)
        {
            sf::Packet packet;
            if (socket.Receive(packet,sender,port) != sf::Socket::Done)
            {
                cout << "Odd... It seems there was an error receiving the message.\n";
            }
            string buffer;
            packet >> buffer;
            cout << buffer << "\n";
            packet.Clear();
            packet << buffer;

            for (unsigned int i = 0; i < clients.size(); i++)
            {
                if (clients[i] == sender)
                {
                    client_found = true;
                }
                else
                {
                    socket.Send(packet, clients[i], 54359);
                }
            }
            if (client_found == false)
            {
                clients.push_back(sender);
            }
            packet.Clear();
            client_found = false;
        }
    }
    else if (answ_res == CONNECT)
    {
        string str_tocon;
        bool inc_ip = true;
        while (inc_ip == true)
        {
            getline(cin,str_tocon);
            sf::IPAddress ip_tocon(str_tocon);
            if (ip_tocon./*sf::IPAddress::*/IsValid() and str_tocon != "" and str_tocon != " ")
            {
                cout << "\nYay! The IP is valid!\n";
                inc_ip = false;
            }
            else
            {
                cout << "\nYou are very naughty. That IP is NOT valid. Please try again.\n";
                inc_ip = true;
            }
        }
        string str_tosen;
        cout <<"Now, what is your name?\n";
        string user;
        getline(cin,user);
        bool sen_msg = true;
        sf::Packet packet;
        cout << "\n";
        sf::IPAddress sender;
        client_receive thread;
        thread.receiving = true;
        thread.port = 54359;
        thread.socket = socket;
        thread.Launch();
        while (sen_msg == true)
        {
            getline(cin,str_tosen);
            std::stringstream stri_stre;
            stri_stre << user << ": " << str_tosen;
            packet << stri_stre.str();
            sf::IPAddress ip_tocon(str_tocon);
            /*if (*/socket.Send(packet, ip_tocon, 54358)/* != )
            {
                cout << "Error sending message.";
            }*/;
            packet.Clear();
        }
    }
    socket.Close();
    return 0;
}


(I am using SFML 1.5)

10
System / Is there anything wrong with a WHILE statement in a thread?
« on: January 04, 2010, 02:05:38 am »
Also, would it be bad to put a blocking function (i.e Receive() in sf::Socket) in that while loop?

Pages: [1]
anything