Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-21-2011, 09:18 PM
Hezzy002 Hezzy002 is offline
Registered User
Join Date: Jul 2011
Posts: 247
Hezzy002 is a jewel in the roughHezzy002 is a jewel in the rough
Better interpolation.

For some simple time-based interpolation I didn't like the way move() worked (It's not time based, it's updated based on when you send the request), and this method had so many issues and was grossly overcomplicated, so I wrote my own.

Anyway, just do your movement as normal on the server and do this at the end of your timeout loop:

PHP Code:
this.attr[1] = "x" this.newX;
this.attr[2] = "x" this.newY;
this.attr[5] = (this.attr[5] + 1)%200
I wouldn't suggest writing anything to this.x directly, because if this.x updates, it'll send it to the client and might cause the NPC to jump around on the client. I don't think there's a way around this, at least I haven't thought of it.

In the clientside portion, add this. The lerpBufferSize value dictates how much movement information should be buffered as the server sends it over, and then it's "played back" as if it was a movie. The best way I can relate this is as if you were streaming a video on YouTube and on your **** connection didn't pause it to buffer at the beginning, and instead it has to pause every few seconds while waiting for the server. Similar concept, this smooths it out.

PHP Code:
//#CLIENTSIDE
function onCreated() {
  
this.lerpBufferSize .3;
  
this.firstLerp true;
  
onTimeOut();
}

function 
onTimeOut() {
  
setTimer(.05);
  
  for (
i=0;i<this.frames.size()-1;i++) {
    
this.frames[i];
    
nf this.frames[i+1];
    if (
timevar2 >= f.time) {
      if (
timevar2 <= nf.time) {
        if (!
this.firstLerp) {
          
temp.lerp = (timevar2-f.time)/(nf.time-f.time);
      
          
this.linearInterpolateValue(f.xnf.xtemp.lerp);
          
this.linearInterpolateValue(f.ynf.ytemp.lerp);
        }
      } else {
        
this.firstLerp false;
        
f.delete true;
      }
    }
  }
  
  for (
i=0;i<this.frames.size();i++) {
    if (
this.frames[i].delete) {
      
this.frames.delete(i);
      
i=0;
    }
  }
  
  if (
this.attr[5] != this.lupdate) {
    
temp.newFrame = new TStaticVar();
    
    
temp.newFrame.this.attr[1].substring(1);
    
temp.newFrame.this.attr[2].substring(1);
    
temp.newFrame.time timevar2 + ((this.firstLerp) ? this.lerpBufferSize);
    
    
this.frames.add(temp.newFrame);
    
    
this.lupdate this.attr[5];
  }
}

function 
linearInterpolateValue(temp.ovtemp.nvtemp.l) {
  return (
temp.ov*(1-temp.l)+temp.nv*temp.l);

Here's a video demonstrating it real quickly, I toggle it frequently throughout the video. The NPC is just moving around with a .5 timeout on the server using cos/sin, and the interpolation smooths it out to 20 FPS even though the script is running at 2 FPS on the server. Save bandwidth, time, and money! Even if it was running at a .1 timeout on the server, it'd still look really crappy. Interpolation keeps everybody synchronized without looking like garbage.



Thanks! If anybody knows a way to force floating point accuracy into an attr[] without "casting" it as a string, do tell.
Reply With Quote
  #2  
Old 08-21-2011, 09:33 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by Hezzy002 View Post
Thanks! If anybody knows a way to force floating point accuracy into an attr[] without "casting" it as a string, do tell.
Never had any problems with this previously. This stuff is pretty awesome, though. I'll use this for sure. Rep++ and a big thanks, sir!
Reply With Quote
  #3  
Old 08-21-2011, 10:06 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
You fool us not Downsider, but nifty script otherwise. I wish the client would do this on it's own though.
__________________
Quote:
Reply With Quote
  #4  
Old 08-21-2011, 10:20 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by fowlplay4 View Post
You fool us not Downsider, but nifty script otherwise. I wish the client would do this on it's own though.
This would be great if the client did it, and way more efficient. You'll be hard-pressed to find even the crappiest online games have interpolation.
Reply With Quote
  #5  
Old 08-21-2011, 10:30 PM
Hezzy002 Hezzy002 is offline
Registered User
Join Date: Jul 2011
Posts: 247
Hezzy002 is a jewel in the roughHezzy002 is a jewel in the rough
Quote:
Originally Posted by DustyPorViva View Post
This would be great if the client did it, and way more efficient. You'll be hard-pressed to find even the crappiest online games have interpolation.
Completely agree. Would be great to be able to toggle and configure a built-in interpolation.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:32 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.