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

Pages: [1]
1
General / Build custom GUI for basic Linux
« on: July 06, 2014, 03:15:38 pm »
I'm wondering if I could use SFML to build a GUI for Linux (let's say Ubuntu Server, or any Ubuntu without it's default graphic interface), to build a custom desktop interface.

If it's possible, what are the actual steps require to do this?

2
Network / FTP: find out if it's a file or a folder
« on: March 25, 2014, 05:57:26 pm »
Hello,

Is there any way to find out if a path is directory or file?
The only way I figured is to try and changeDirectory() into every item of the listing returned, if it doesn't work, it's a file.

Is there any other, more applicable, check I could do?

Checking for a .extension of the string won't always work, folders can have dots, files may not have dots.

3
Network / Back and forth and closing.
« on: February 03, 2011, 07:04:49 pm »
Trying to make a console chat system on which to test my networking skills. I'm going with TCP for now. The chat system isn't much of a problem. The only things I'm having trouble with is server sending data to clients and shutting down the server/client.

The server checks for incomming connection and incoming packeges, like in the tutorial. The client sends packeges to the server.

This is a function with which the chat system gets messages over the internet:
Code: [Select]

while ( m_Open ) {
nw::Network::packetVec Packets = nw::NetworkAccessor::GetNetwork()->ReceiveData();

for ( nw::Network::packetVec::iterator it = Packets.begin(), itEnd = Packets.end(); it != itEnd; ++it ) {
std::string Message;
(*it) >> Message;

m_Mutex.Lock();
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Coords);
std::cout << "                                             ";
etConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), Coords);
std::cout << Message;
m_Mutex.Unlock();

if ( Coords.Y < 31 )
++Coords.Y;
else
Coords.Y = 11;
}
}

Packets is a vector of sf::Packet (in case you are the server and receive several packeges a time).

Here's the Receive function for client:
Code: [Select]

nw::Network::packetVec nw::Client::ReceiveData() {

nw::Network::packetVec Packets;

sf::Packet Packet;
if ( m_Socket.Receive(Packet) == sf::Socket::Done ) {
Packets.push_back(Packet);
}
else {
std::string Message = "An error occured.";
Packet << Message;
Packets.push_back(Packet);
}


return Packets;
}

There's only one packet because there's only one socket. (One packet at a time).

The Receive function is the function that receives packets - calling the Wait function on the selector - if server, or calling the receive function on the socket - if client (both are blocking so it's the same). And as soon as a packege (or more if you are server) arrive, it will receive it and continue with the while (m_Open) loop.
The problem is that this loop only loops if there is an incoming packege, which is fine because I don't want it to loop like crazy if there's nothing to process. But now the program only closes if - after I hit Q for close - someone sends a packet to me. Which is stupid. (I know, I did it this way.)
So I was wondering if I'm client, doing "Socket.Close()" will close the socket and the Receive funtion ends so the loop continues with Packets size 0 and break? Or that won't help at all, maybe even breaking stuff?

As for server side - clearing the selector will make the Wait function return? Maybe even closing the listening socket...
All this done with threads.


And the last part.
All the clients that are connected to the server have a socket in the selector. How can I use them to send from the server to the clients? I can't acces them in the selector. Or I need an additional socket to connect to the client, doing some sort of server-server stuff?

Ok, I think the post is long enough. Let me know if I know something wrong, or doing wrong, or just wrong.
And sorry for my bad English...
And sorry if this is already posted somewhere else. I haven't found anything specific, or I'm bad at searching.

Thanks for reading.

4
Graphics / View and view moving
« on: August 03, 2010, 11:16:02 pm »
Is there any way to make an object stick to the window, like saying in a RTS game a menu bar and minmap are in the same position related to the window's coordinates even though the background is moving.

I know that the mouse's coordinates dosen't depend on the view's transformation, but I don't see how I could use that...


So, besides moving the menu with the view, is there an other way?

5
General / [FIXED] CPU over 30%
« on: July 27, 2010, 04:59:46 pm »
I have a basic SFML program running on my computer and it takes about 30% of CPU even when I don't input anything in the program.
Here's the code:
Code: [Select]

#include <SFML\Graphics.hpp>

void MoveView(const sf::Input *Input, sf::View &View);
void MoveShape(const sf::Input *Input, sf::Shape &Box);

int main() {

sf::RenderWindow cWin(sf::VideoMode(800, 600), "Camera test");
cWin.SetFramerateLimit(30);
sf::Event Event;

sf::Shape Box = sf::Shape::Rectangle(0.0f, 0.0f, 150.0f, 150.0f, sf::Color::Red);
Box.SetCenter(75.0f, 75.0f);

sf::View View(sf::Vector2f(400, 300), sf::Vector2f(400, 300));

while ( cWin.IsOpened() ) {
if ( cWin.GetEvent(Event) ) {
if ( Event.Type == sf::Event::Closed )
cWin.Close();
if ( cWin.GetInput().IsKeyDown(sf::Key::Escape) )
cWin.Close();
}

MoveShape(&cWin.GetInput(), Box);

MoveView(&cWin.GetInput(), View);
cWin.SetView(View);


cWin.Clear(sf::Color::White);

cWin.Draw(Box);

cWin.Display();
}

return 0;
}


void MoveView(const sf::Input *Input, sf::View &View) {

if ( Input->IsKeyDown(sf::Key::Left) )
View.Move(-20.0f, 0.0f);
else if ( Input->IsKeyDown(sf::Key::Right) )
View.Move(20.0f, 0.0f);

if ( Input->IsKeyDown(sf::Key::Up) )
View.Move(0.0f, -10.0f);
else if ( Input->IsKeyDown(sf::Key::Down) )
View.Move(0.0f, 10.0f);
}

void MoveShape(const sf::Input *Input, sf::Shape &Box) {

if ( Input->IsKeyDown(sf::Key::A) )
Box.Move(-10.0f, 0.0f);
else if ( Input->IsKeyDown(sf::Key::D) )
Box.Move(10.0f, 0.0f);

if ( Input->IsKeyDown(sf::Key::W) )
Box.Move(0.0f, -10.0f);
else if ( Input->IsKeyDown(sf::Key::S) )
Box.Move(0.0f, 10.0f);
}

Using SFML 1.6 build for VS2010. But it's the same with SFML 1.6 with VS2008 and C::B. Realese or debug, same thing.

Can anyone tell me why does this little program use so much CPU? I have a larger project, if I run that it never goes lower then 50%.
Even a basic program like displaying the window without rendering anything does take more then it should.
If I try to display more then 100x100 sf::Shape-s it takes about 20 seconds to update the frame.
Should it work that slow? :\

I tested it on other computers too and the result is the same.
Thanks in advance.

6
Graphics / Window coordinates
« on: June 19, 2010, 02:13:24 am »
Can somebody tell me if there is something wrong with my code?
Code: [Select]

// Ball.hpp

#ifndef BALL_HEADER
#define BALL_HEADER

#include <SFML/Graphics.hpp>

class Ball {

public:
Ball();
~Ball();

void Update(float ElapsedTime);
void ChangeX();
void ChangeY();
void Draw(sf::RenderWindow &cWin);

float GetX() const { return X; }
float GetY() const { return Y; }

private:
sf::Shape cBall;
float X;
float XSpeed;
float Y;
float YSpeed;

};

#endif


Code: [Select]

//Ball.cpp

#include "Ball.hpp"
#include <iostream>

Ball::Ball(): X(0.0f), XSpeed(50.0f), Y(0.0f), YSpeed(50.0f) {

   cBall = sf::Shape::Circle(100, 100, 10, sf::Color(100, 100, 100));
}

Ball::~Ball() {

}

void Ball::Update(float ElapsedTime) {

   cBall.Move(XSpeed * ElapsedTime, YSpeed * ElapsedTime);
   sf::Vector2f Pos = cBall.GetPosition();
   X = Pos.x;
   Y = Pos.y;

   std::cout << X << " " << Y << " - " << XSpeed << " " << YSpeed << std::endl;
}

void Ball::ChangeX() {

   XSpeed *= -1.0f;
}

void Ball::ChangeY() {

   YSpeed *= -1.0f;
}

void Ball::Draw(sf::RenderWindow &cWin) {

   cWin.Draw(cBall);
}


Code: [Select]

// Main.cpp

#include "Ball.hpp"

int main() {

sf::RenderWindow cWin(sf::VideoMode(800, 600), "test");
cWin.SetFramerateLimit(60);
sf::Event Event;

Ball cBall;

while ( cWin.IsOpened() ) {
while ( cWin.GetEvent(Event) ) {
if ( Event.Type == sf::Event::Closed )
cWin.Close();
}

cBall.Update(cWin.GetFrameTime());
if ( cBall.GetX() > 780.0f || cBall.GetX() < 20.0f )
cBall.ChangeX();
if ( cBall.GetY() > 580.0f || cBall.GetY() < 20.0f )
cBall.ChangeY();

cBall.Draw(cWin);

cWin.Display();
cWin.Clear();
}

return 0;
}

It compiles and runs. But it runs wierd.
The ball moves +50 on X and +50 on Y the first frame, then it goes -50, -50 on the next frame and repeats until I click the window and hold for 2-3 secs, then when I let go, the ball starts moving. Although the coordinates printed in the console seem fine, the ball is render off by some pixels. Also, the limits are off, everything is off!

I searched the forum for some time now, I couldn't find anything relevant. So I decided to make a new post.

Sorry for my bad English, hopefully everybody understands what I'm saying.

Pages: [1]
anything