Jump to content

  • Log In with Google      Sign In   
  • Create Account

lride

Member Since 16 Aug 2012
Offline Last Active Jan 18 2014 12:59 PM

Topics I've Started

Am I doing the interpolation correctly?

28 December 2013 - 11:31 PM

I'm trying to implement network entity interpolation described in this article: http://www.gabrielgambetta.com/fpm3.html

 

so far I have this and the circle's movement looks jittery. What did I do wrong?

struct Circle
{
	sf::Vector2f current;
	sf::Vector2f last;
	sf::CircleShape shape;
	Circle()
	{
		shape.setRadius(100);
	}
	void interpolate()
	{
		sf::Vector2f difference = current - last;
		current.x += difference.x * 0.1;
		current.y += difference.y * 0.1;
	}
	void draw(sf::RenderWindow & window)
	{
		shape.setPosition(current.x, current.y);
		window.draw(shape);
	}
	void setPosition(sf::Vector2f v)
	{
		last = current;
		current = v;
	}
};

//server 
void server()
{
	sf::TcpListener listener;
	sf::TcpSocket client;

	listener.listen(PORT);
	listener.accept(client);
	client.setBlocking(false);


	Circle circle;
	sf::RenderWindow window(sf::VideoMode(800, 600), "server");

	sf::Clock clock;
	sf::Time elapsed = sf::Time::Zero;
	sf::Time timePerFrame = sf::seconds(1 / 20.f);

	while (window.isOpen())
	{
		sf::Time dt = clock.restart();
		elapsed += dt;
		while (elapsed > timePerFrame)
		{
			elapsed -= timePerFrame;
			sf::Event event;
			while (window.pollEvent(event))
			{
				if (event.type == sf::Event::Closed)
					window.close();
			}

			sf::Packet packet;
			sf::Socket::Status s = client.receive(packet);
			while (s == sf::Socket::Done)
			{
				//new position sent from the client;
				float x, y;
				packet >> x >> y;
				circle.setPosition({ x, y });
				packet.clear();
				s = client.receive(packet);
			}
			circle.interpolate();
		}

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

what's wrong with my code?

 


memory leak dectector for vs 2013

21 December 2013 - 11:44 PM

What's a good memory leak detector for VS 2013?


java applet flickering

12 June 2013 - 11:20 AM

import java.applet.*;
import java.awt.*;

public class Game extends Applet implements Runnable
{
	Thread th;
	public void start()
	{
		th=new Thread(this);
		th.start();
	}
	public void run()
	{
		while(true)
		{
			try{
				repaint();
				th.sleep(0);
			}catch(Exception e)
			{
				e.printStackTrace();
			}
		}
	}
	public void paint(Graphics g)
	{
		Dimension d=getSize();
		g.fillRect(0, 0, d.width, d.height);
		g.setColor(Color.green);
		g.drawLine(0,  0,  100,  100);
	}
}

The applet flickers a lot so it's very disturbing.

Is there something I'm doing wrong?


distributing my program

09 June 2013 - 09:41 AM

I made an online chat program with SFML on Windows 7 and I am trying to distribute it to my friends who also have Windows 7.

 

I included the executable and msvcr110.dll but I'm getting the error  "MSVCR110.dll is either not designed to run on Windows or it contains an error. Try installing the program again..."

 

Is there something I'm doing wrong?


Quickly retrieving entities by position

31 May 2013 - 09:04 PM

In a tower defense game for example, I want to get all the entities within a splash tower's range. How is this usually implemented?


PARTNERS