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

Pages: 1 [2]
16
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.

17
Graphics / View and view moving
« on: August 03, 2010, 11:50:11 pm »
That code draws the things that are in the view and then goes back to the view's default position, right?

Isn't that CPU expensive? And wouldn't it draw the scrolling backgrond objects from the default position?


-- Thanks for the quick answer.

18
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?

19
General / [FIXED] CPU over 30%
« on: July 29, 2010, 05:00:10 pm »
I tested, it takes about 20 seconds to update the display and 100% CPU.

Is that how it should be or I'm still having a problem although I installed the driver and it seems that smaller projects work fine? :\

20
General / [FIXED] CPU over 30%
« on: July 29, 2010, 04:20:54 pm »
Athlon LE-1600 2.20 GHz
nVidia GeForce 7300 GT
1 GB RAM

That isn't enough? :-s

21
General / [FIXED] CPU over 30%
« on: July 29, 2010, 03:17:34 pm »
And on a related note:
Would a grid of 100x100 sf::Shape-s of 20x20 pixels take long to render to the screen? I mean would the program lag or the FPS drop? Example
Code: [Select]

std::vector< std::vector<sf::Shape> > Grid; // 2D array, 100x100
for ( unsigned short i = 0; i < 100; ++i ) {
    for ( unsigned short j = 0; j < 100; ++j ) {
        cWin.Draw(Grid[i][j]);
    }
}

22
General / [FIXED] CPU over 30%
« on: July 29, 2010, 02:56:27 pm »
Quote from: "Ceylo"
As no one else is having this problem, I think it's rather a driver issue (your code is also taking about 1% CPU for me).

It actually is a driver issue!
I could not remember if I installed the graphics driver after I installed windows 7 since it works without it too. But I downloaded the driver and installed, and now it takes < 1% CPU.

Thanks for the replay xD
[FIXED]

23
General / [FIXED] CPU over 30%
« on: July 29, 2010, 02:39:58 am »
I only get linker warnings
Code: [Select]

LINK : C:\Users\VjS\Documents\Visual Studio 2008\Projects\SFML\SFML test\Debug\SFML test.exe not found or not built by the last incremental link; performing full link
sfml-system-s-d.lib(Platform.obj) : warning LNK4099: PDB 'vc90.pdb' was not found with 'C:\Program Files\Microsoft Visual Studio 10.0\SFML-1.6\lib\sfml-system-s-d.lib' or at 'c:\Users\VjS\Documents\Visual Studio 2008\Projects\SFML\SFML test\Debug\vc90.pdb'; linking object as if no debug info
...
// And it goes on for every .obj

Has this anything to do with CPU usage? I think not...

24
General / [FIXED] CPU over 30%
« on: July 29, 2010, 02:03:31 am »
I had it
Code: [Select]

while ( cWin.GetEvent(Event) )

But change it to if, I thought it might be some wierd events incoming and maybe thats while it was taking that much CPU, but it doesn't and I forgot to change it back.

I compiled the libs for VS2010, that's what I'm currently using. Tried SFML2, same thing. And although I tried everything, I'm going to try SFML 1.6 on VS2008, maybe there is something wrong with the libs for VS2010.

And on a related note:
Would a grid of 100x100 sf::Shape-s of 20x20 pixels take long to render to the screen? I mean would the program lag or the FPS drop? Example
Code: [Select]

std::vector< std::vector<sf::Shape> > Grid; // 2D array, 100x100
for ( unsigned short i = 0; i < 100; ++i ) {
    for ( unsigned short j = 0; j < 100; ++j ) {
        cWin.Draw(Grid[i][j]);
    }
}

25
General / [FIXED] CPU over 30%
« on: July 29, 2010, 12:20:46 am »
So, no answer for this one?

26
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.

27
Graphics / Window coordinates
« on: June 19, 2010, 11:20:21 pm »
I saw that the initial arguments in sf::Shape::Circle are actually it's center position. Which is kind of confusing. If I put the center to 0 and put after the SetPosition to 100, 100, it seems almost right. The if statement with ChangeX/Y works fine, but the coordinates ar still off.

I think, and this is only a sugestion, the tutorials on shapes and views should be have more explications. I can't figure out what's wrong.


My main question: HOW DO I HANDLE POSITIONINGS AND COORDINATES IN SFML?
Thank you.

28
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 [2]
anything