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

Pages: [1]
1
Network / Can someone help me with this simple client/server test?
« on: May 10, 2011, 10:23:51 pm »
alright, I've been working on this for about 5 hours today alone, and I still can't get anything working. Can someone tell me what I'm doing wrong? I'm getting no output from the server at all, nor the client.

Client:
Code: [Select]

#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <iostream>
#include <sstream>
using namespace std;

int main()
{
    // Create the main rendering window
    sf::IPAddress addy("76.121.76.188");


    sf::SocketUDP Socket;

    // Create bytes to send
    char Buffer[] = "Player joining.";

    // Send data to "192.168.0.2" on port 4444
    if (Socket.Send(Buffer, sizeof(Buffer), addy, 4444) != sf::Socket::Done)
    {
        cout << "Sending failed." << endl;
    }

    while (true)
    {
        // Process events
        if (addy.IsValid()){
            //recieve enemy posititon
            sf::SocketUDP receiverSocket;

            // Bind it (listen) to the port 4444
            if (!receiverSocket.Bind(4444))
            {
                cout << "binding failed" << endl;
            }

            //get data
            char buffer[128];
            std::size_t Received;
            sf::IPAddress Sender;
            unsigned short Port;

            if (receiverSocket.Receive(buffer, sizeof(buffer), Received, Sender, Port) != sf::Socket::Done)
            {
                cout << "error receiveing packet" << endl;
            }

            else{
                cout<<buffer<<endl;
            }

            //send player position
            sf::SocketUDP Socket;
            ostringstream sin;
            sin << "Goodbye.";
            sin.str().c_str();

            // Send data to "192.168.0.2" on port 4444
            if (Socket.Send(sin.str().c_str(), sizeof(sin.str().c_str()), addy, 4444) != sf::Socket::Done)
            {
                cout << "Sending failed" << endl;
            }

        }
    }

    return EXIT_SUCCESS;
}


Server:
Code: [Select]

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

#include "player.h"
#include "playerthread.h"

using namespace std;

int main()
{
    bool done = false;
    int numConnected = 0;
    sf::IPAddress playerIP[2];
    Playerthread *pthread[2];
    // Start game loop
    while (!done)
{
        sf::SocketUDP receiverSocket;

        // Bind it (listen) to the port 4444
        if (!receiverSocket.Bind(4444))
        {
            cout << "binding failed" << endl;
        }

        //get data
        char buffer[128];
        std::size_t Received;
        sf::IPAddress Sender;
        unsigned short Port;

        if (receiverSocket.Receive(buffer, sizeof(buffer), Received, Sender, Port) != sf::Socket::Done)
        {
            cout << "error receiveing packet" << endl;
        }

        else{
            playerIP[numConnected] = Sender;
            pthread[numConnected] = new Playerthread(playerIP[numConnected]);
            pthread[numConnected]->startThread();
            numConnected++;
        }

        // Show the address of the sender
        std::cout << Sender << std::endl;

        // Show the message
        std::cout << buffer << std::endl; // "Hi guys !"

        //close socket
        receiverSocket.Close();
    }

    return EXIT_SUCCESS;
}



Server Thread:
Code: [Select]

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

using namespace std;

class Playerthread : private sf::Thread{
public:
int get_RetLevel();

sf::IPAddress playerIP;

Playerthread(sf::IPAddress &nplayerIP){
        playerIP = nplayerIP;
}
void startThread(){
        Launch();
    }
private:
virtual void Run(){
while(true){
if (playerIP.IsValid()){
                    //send enemy position

                        sf::SocketUDP Socket;
                        ostringstream sin;

                        sin << "enemy local";
                        sin.str().c_str();

                        // Send data to "192.168.0.2" on port 4444
                        if (Socket.Send(sin.str().c_str(), sizeof(sin.str().c_str()), playerIP, 4444) != sf::Socket::Done)
                        {
                            cout << "Sending failed" << endl;
                        }
                    }

                    //recieve player posititon
                    sf::SocketUDP receiverSocket;

                    // Bind it (listen) to the port 4444
                    if (!receiverSocket.Bind(4444))
                    {
                        cout << "binding failed" << endl;
                    }

                    //get data
                    char buffer[128];
                    std::size_t Received;
                    sf::IPAddress Sender;
                    unsigned short Port;

                    if (receiverSocket.Receive(buffer, sizeof(buffer), Received, Sender, Port) != sf::Socket::Done)
                    {
                        cout << "error receiveing packet" << endl;
                    }

                    else{
                        if(Sender.ToString().compare(playerIP.ToString())){
                            cout << "thread" << buffer << endl;
                        }
                    }

}
}
};


2
General / load a array of sprites using 1 sf::Image?
« on: April 07, 2011, 11:20:39 am »
I want to load a array of sf::Sprites using only 1 sf::Image, and loading images to that image over and over. I don't want to create a array of images because I'm worried about ram usage. But I can't get anything to work. It aether loads every sprite as 1 image, or gives me a white box. How would I go about doing this?

edit: my code: http://pastebin.com/RW0ZeySP

3
General / Drawing tilemap is lowering my fps to a crawl
« on: April 03, 2011, 04:41:27 pm »
Okay, I'm trying to get my fps to 60, but right now it's at around 20. What can I do to this code to speed it up? Note: this is c++ using sfml.

Code: [Select]
       App.Clear();
        for(int x = 0; x < lv.width; x++){
            for(int y = 0; y < lv.height; y++){
 
                int tileXCoord = 0;
                int tileYCoord = 0;
                int tileSheetWidth = tilemapImage.GetWidth() / lv.tileSize;
 
                if (lv.tile[x][y] != 0)
                {
                    tileXCoord = lv.tile[x][y] % tileSheetWidth;
                    tileYCoord = lv.tile[x][y] / tileSheetWidth;
                }
 
                tilemap.SetSubRect(sf::IntRect(tileXCoord * lv.tileSize, tileYCoord * lv.tileSize, (tileXCoord * lv.tileSize) + lv.tileSize, (tileYCoord * lv.tileSize) + lv.tileSize));
                tilemap.SetPosition(x * lv.tileSize, y * lv.tileSize);
                App.Draw(tilemap);
            }
        }
 
        playerSprite.SetSubRect(sf::IntRect(player.width * player.frame, player.height * player.state,
                                       (player.width * player.frame) + player.width, (player.height * player.state) + player.height));
        playerSprite.SetPosition(player.x, player.y);
 
        App.Draw(playerSprite);
 
        if(player.walking){
            if(player.frameDelay >= 0)
                player.frameDelay--;
 
            if(player.frameDelay <= 0){
 
                player.frame++;
                player.frameDelay = 10;
 
                if(player.frame >= 4)
                    player.frame = 0;
            }
        }
 
 
        for(int x = 0; x < lv.width; x++){
            for(int y = 0; y < lv.height; y++){
 
                int tileXCoord = 0;
                int tileYCoord = 0;
                int tileSheetWidth = tilemapImage.GetWidth() / lv.tileSize;
 
                if (lv.ftile[x][y] != 0)
                {
                    tileXCoord = lv.ftile[x][y] % tileSheetWidth;
                    tileYCoord = lv.ftile[x][y] / tileSheetWidth;
                }
 
                tilemap.SetSubRect(sf::IntRect(tileXCoord * lv.tileSize, tileYCoord * lv.tileSize, (tileXCoord * lv.tileSize) + lv.tileSize, (tileYCoord * lv.tileSize) + lv.tileSize));
                tilemap.SetPosition(x * lv.tileSize, y * lv.tileSize);
                App.Draw(tilemap);
            }
        }
 
 
        App.Display();

4
General / How to test if the Joystick POV is at angle 90?
« on: March 31, 2011, 05:34:19 am »
How would I do that?
I tried

Code: [Select]

if((Event.Type == sf::Event::JoyMoved) && (Event.JoyMove.Axis == 0) && (Event.JoyMove.Position == 90))


But that didn't work.

5
General / Problem making SFML Window (And any other SFML)
« on: October 09, 2010, 02:02:48 am »
Okay, so when I open the workspace in sfml2/build/codeblocks I can make the System just fine, and I see lib/mingw/libsfml-system-d.a and the .dll with it, but when I  double  click on the Window project in the workspace I get this error:

Code: [Select]
Linking dynamic library: ..\..\lib\mingw\sfml2-window-d.dll
mingw32-g++.exe: ..\..\lib\mingw\libsfml2-system-d.a: No such file or directory


Anyone know why? It's right where it should be, so I don't know why I get this error.

6
General discussions / Game Maker flooding the market with crap?
« on: June 08, 2010, 08:00:52 pm »
Now I'm a C++ programmer (Also Java, C#, HTML, and PHP) and when I make a game I like making it from scratch, and with real code. Not drag and drop /scripting crap. I dislike Game Maker games and RPG Maker games because they're half-assed. It's like using a templet, or Dreamweaver for a website. Sure, a Game Maker game can be good, but is it worth it at that point? No, it isn't. you could have took two weeks more to learn C++ and make the game all on your own, and made it eat a lot less resources. There's just no excuse for half-assing  a game with Game Maker or RPG Maker.

Not only that, but because of Game Maker and RPG maker the market is over saturated with crap. Remember what happened to the mainstream game market when this happened? That's right. The Game Crash in the 80's. We could be looking at a Indie Game Crash because of Engines that encourage half-assed development.

Remember kids: Just say no to Game Maker.

7
SFML projects / Feedback wanted for Project MoonSeed ARPG engine.
« on: June 06, 2010, 09:46:00 pm »
So I've been working on this for like a week or two now, and I finally have something I wanna show off.

It's a action RPG engine made from scratch.




Download it here.

The kind of feedback I want is simple:
Is it fun?
What are some ideas that could make it more fun?
were there any bugs?
have any ideas to improve the graphics?

I'm only looking for constructive criticism, and please remember that this is just a engine test build at this time, so don't be too harsh on it.

Pages: [1]
anything