Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Networking & Multiplayer / Re: [Kryonet] How to efficiently send movement updates? on: 2013-05-20 07:51:42
Wow! Thanks for all the replies Smiley
Learning network stuff is definitely a trial by fire for me, but you guys help is much appreciated. Smiley

Btw, cero, I'm doing the same thing. Tongue But after reading all this I'm gonna keep trying what I'm doing until I notice some issues.
2  Game Development / Networking & Multiplayer / [Kryonet] How to efficiently send movement updates? on: 2013-05-15 20:31:19
Hey all,

So I'm implementing multiplayer movement of other characters in my game now, I have the server getting new players logging in and storing them in a local copy of the player. My question now is how to do the movement updating. I know *how* to do it, just create a packet and send it over the server to everyone to update. But, I don't want to be sending a huge number of packets every second for every player. That just seems like it will overload my server and crash.

My question to you all is: how could I go about doing this efficiently?

I'm posting a snippet of my movement code below:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
    public void updatePlayer(int delta)
    {
        boolean isWalking = false;
        float xChange = 0, yChange = 0;
        Input input = gc.getInput();
 
        int runMod = 1;
        if (input.isKeyDown(Input.KEY_LSHIFT))
        {
            runMod = 2;
        }
        if(input.isKeyDown(Input.KEY_A))
        {
            //LEFT
           sprite = walkingAnimLeft;
            sprite.start();
            xChange -= speed * runMod * delta;
            isWalking = true;
            facing = "left";
        }
 
        if(input.isKeyDown(Input.KEY_D))
        {
            //RIGHT
           sprite = walkingAnimRight;
            sprite.start();
            xChange += speed * runMod * delta;
            isWalking = true;
            facing = "right";
        }
 
        if(input.isKeyDown(Input.KEY_W))
        {
            //UP
           sprite = walkingAnimUp;
            sprite.start();
            yChange -= speed * runMod * delta;
            isWalking = true;
            facing = "up";
        }
        if(input.isKeyDown(Input.KEY_S))
        {
            //DOWN
           sprite = walkingAnimDown;
            sprite.start();
            yChange += speed * runMod * delta;
            isWalking = true;
            facing = "down";
        }
        if (input.isKeyPressed(input.KEY_ENTER))
        {
            if (chat.isChatting())
            {
                chat.sendText();
            }
            else
            {
                chat.setChatting(true);
            }
            //chat.setChatting();
       }
        if(input.isKeyPressed(input.KEY_E))
        {
            toggleEquip();
        }
        //If the player is not walking, stop the animation
       if (isWalking && !currentMap.blocked(x+xChange, y+yChange, facing))
        {
            x += xChange;
            y += yChange;
            //Here's where I would put it, but as you can see updatePlayer is called all the time, so I'd be sending a packet all the time for each player.
           
        }
        if (!isWalking)
        {
            sprite.setCurrentFrame(1);
            sprite.stop();
        }
        isWalking = false;
    }


I was thinking of using some sort of timer and basically lumping the movements into one packet. I.e., aggregating movement updates across X milliseconds into one packet and sending those at once. But this would require a timer of some sort to count every, 20 milliseconds, let's say. The problem there is, I would need the timer to be accurate on each and every client. And no, I haven't just tried sending it every update, because I'm scared of it crashing hardcore.

Any advice?
3  Game Development / Newbie & Debugging Questions / Wobbly/Blurred Animations after capping framerate (Slick2D) on: 2013-05-09 00:09:38
Hey all,

I have a question about something that's puzzling me. Let me give you some details:

I have a simple game written in Slick2D presently with a player character and two NPCs that follow some simple pathfinding (and move on their own). My framerate was uncapped and in the thousands. Anyhow, I recently decided to cap my framerate via gc.setTargetFramerate to 60. Naturally, I had to alter some of my movement code to take into account delta (which I wasn't accounting for previously, as my framerate was unlimited...). So after doing that, I noticed my NPCs movement animations were displaying very wobbly (almost blurry), as if they were shaking as they were moving. Strangely enough, after editing my player movement code to account for delta, his movement remained smooth and natural.

My question to you all is, does anyone have any idea why my NPCs begin to wobble/blur on movement after I cap my framerate? Note this only happens during movement, and not while standing still.

I'm pasting some of my code below. The first one is a snippet from my NPC movement code. The second is a snippet from my player movement code.

NPC movement...was working before accounting for delta
Note that they are simply moving along a path found via a previous method.
Also note that setSpriteForPath is for determining with Animation the NPC will use (walking left, walking right, etc.) when moving.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
    public void moveAlongPath(int delta)
    {
        float newSpeed = speed * delta; //here is the only change after capping the FPS at 60. Previosuly this line was simply newSpeed = speed; (speed=.1f)
       if (movingAlongPath && !isDead)
        {
            if (path.getX(pathIndex) < (x/tileSize))
            {
                x-= newSpeed;
                stepDistX -= newSpeed;
            }
            else if (path.getX(pathIndex) > (x/tileSize))
            {
                //System.out.println("x>...x is" + x);
               x+= newSpeed;
                stepDistX -= newSpeed;
                //System.out.println("now x is..." + x);
           }
           
            if (path.getY(pathIndex) < (y/tileSize))
            {
                y -= newSpeed;
                stepDistY -= newSpeed;
            }
            else if (path.getY(pathIndex) > (y/tileSize))
            {
                y += newSpeed;
                stepDistY -= newSpeed;
            }
            //If the stepDist is like 0.0001, we're making sure that counts as zero.
           if ((stepDistY <= 0 || stepDistY-.1f <=0) && (stepDistX <= 0 || stepDistX-.1f <=0))
            {
                pathIndex++;
                if (pathIndex < path.getLength())
                {
                    stepDistX = Math.abs(path.getX(pathIndex) * tileSize - x);
                    stepDistY = Math.abs(path.getY(pathIndex) * tileSize - y);
                    setSpriteForPath();
                }
                else
                {
                    movingAlongPath = false; ///break out of the loop
                   pathIndex = 0;
                    stepDistX = 0;
                    stepDistY = 0;
                    path = null; //kill the path
                   setEndSprite();
                    trans();
                }

            }
        }
    }


Player Movement...
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
public void updatePlayer(int delta)
    {
        boolean isWalking = false;
        float xChange = 0, yChange = 0;
        Input input = gc.getInput();
 
        int runMod = 1;
        if (input.isKeyDown(Input.KEY_LSHIFT))
        {
            runMod = 2;
        }
        if(input.isKeyDown(Input.KEY_A))
        {
            //LEFT
           sprite = walkingAnimLeft;
            sprite.start();
            xChange -= speed * runMod * delta;
            isWalking = true;
            facing = "left";
        }
 
        if(input.isKeyDown(Input.KEY_D))
        {
            //RIGHT
           sprite = walkingAnimRight;
            sprite.start();
            xChange += speed * runMod * delta;
            isWalking = true;
            facing = "right";
        }
 
        if(input.isKeyDown(Input.KEY_W))
        {
            //UP
           sprite = walkingAnimUp;
            sprite.start();
            yChange -= speed * runMod * delta;
            isWalking = true;
            facing = "up";
        }
        if(input.isKeyDown(Input.KEY_S))
        {
            //DOWN
           sprite = walkingAnimDown;
            sprite.start();
            yChange += speed * runMod * delta;
            isWalking = true;
            facing = "down";
        }
        if(input.isKeyPressed(input.KEY_E))
        {
            toggleEquip();
        }
        //If the player is not walking, stop the animation
       if (isWalking && !currentMap.blocked(x+xChange, y+yChange, facing))
        {
            x += xChange;
            y += yChange;
            Transition tempTrans = currentMap.getTran(x+1, y+1);
            if (tempTrans!=null)
            {
                //System.out.println("transitioning...");
               this.trans(tempTrans);
                //transition code here
           }
           
        }
        if (!isWalking)
        {
            sprite.setCurrentFrame(1);
            sprite.stop();
        }
        isWalking = false;
    }


Any help would be immensely appreciated! Thanks!  Smiley
EDIT: I also took out the setTargetFramerate and kept the newSpeed = speed * delta, and it's also smooth. So it seems like it has to do with the framerate. Possibly something to do with Slick2D pathfinding? Maybe a wobbly path is not noticeable at a super high framerate?
EDIT2: I tried a with random movement (no pathfinding, just randomly moves places) and it seemed to move smoothly. Could this be like little "hiccups" with pathfinding?
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (26 views)
2014-07-24 01:59:36

Riven (25 views)
2014-07-23 21:16:32

Riven (20 views)
2014-07-23 21:07:15

Riven (22 views)
2014-07-23 20:56:16

ctomni231 (51 views)
2014-07-18 06:55:21

Zero Volt (46 views)
2014-07-17 23:47:54

danieldean (37 views)
2014-07-17 23:41:23

MustardPeter (40 views)
2014-07-16 23:30:00

Cero (56 views)
2014-07-16 00:42:17

Riven (55 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!