Lecture 8 Announcements.

Slides:



Advertisements
Similar presentations
Transport Layer3-1 Transport Overview and UDP. Transport Layer3-2 Goals r Understand transport services m Multiplexing and Demultiplexing m Reliable data.
Advertisements

Umut Girit  One of the core members of the Internet Protocol Suite, the set of network protocols used for the Internet. With UDP, computer.
Channel Access Protocol Andrew Johnson Computer Scientist, AES Controls Group.
Network synchronization of Online Games Li, Zetan.
UDP - User Datagram Protocol UDP – User Datagram Protocol Author : Nir Shafrir Reference The TCP/IP Guide - ( Version Version.
1 Java Networking – Part I CS , Spring 2008/9.
CS3771 Today: network programming with sockets  Previous class: network structures, protocols  Next: network programming Sockets (low-level API) TODAY!
Networking Support In Java Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Online Chess Project 3 Due date: April 17 th. Introduction Third in series of three projects This project focuses on adding online support –2 players.
© Lethbridge/Laganière 2001 Chap. 3: Basing Development on Reusable Technology 1 Let’s get started. Let’s start by selecting an architecture from among.
User Datagram Protocol UDP. Remember, UDP is Not reliable; data may be dropped No guarantee of in-order delivery Duplicate data is possible No built-in.
What Is TCP/IP? The large collection of networking protocols and services called TCP/IP denotes far more than the combination of the two key protocols.
Networking with Java. Basic Concepts A Network exists when two or more computers are connected such that they can communicate data back and forth. There.
Gursharan Singh Tatla Transport Layer 16-May
TCP Sockets Reliable Communication. TCP As mentioned before, TCP sits on top of other layers (IP, hardware) and implements Reliability In-order delivery.
L ECTURE 9 Announcements. Initial M3 Feedback These all looks really good! Lots of creative ideas this week You’re now done with all the standard projects.
Process-to-Process Delivery:
Day15 IP Space/Setup. IP Suite of protocols –TCP –UDP –ICMP –GRE… Gives us many benefits –Routing of packets over internet –Fragmentation/Reassembly of.
TCP/IP protocols Communication over Internet is mostly TCP/IP (Transmission Control Protocol over Internet Protocol) TCP/IP "stack" is software which allows.
Lecture 2 TCP/IP Protocol Suite Reference: TCP/IP Protocol Suite, 4 th Edition (chapter 2) 1.
1 Chapter Client-Server Interaction. 2 Functionality  Transport layer and layers below  Basic communication  Reliability  Application layer.
Jozef Goetz, Application Layer PART VI Jozef Goetz, Position of application layer The application layer enables the user, whether human.
Scalability Don McGregor Research Associate MOVES Institute
Outline Overview Video Format Conversion Connection with An authentication Streaming media Transferring media.
ICOM 6115©Manuel Rodriguez-Martinez ICOM 6115 – Computer Networks and the WWW Manuel Rodriguez-Martinez, Ph.D. Lecture 26.

Lecture91 Administrative Things r Return homework # 1 r Review some problems in homework # 1 r Questions about grading? Yona r WebCT for CSE245 is working!
Dr. John P. Abraham Professor University of Texas Pan American Internet Applications and Network Programming.
1. I NTRODUCTION TO N ETWORKS Network programming is surprisingly easy in Java ◦ Most of the classes relevant to network programming are in the java.net.
1 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Dynamic Host Configuration Protocol (DHCP)
IP addresses IPv4 and IPv6. IP addresses (IP=Internet Protocol) Each computer connected to the Internet must have a unique IP address.
L ECTURE 9 Announcements. Initial M3 Feedback These all look really good! Lots of creative ideas this week You’re now done with all the standard projects.
Enterprise Network Systems TCP Mark Clements. 3 March 2008ENS 2 Last Week – Client/ Server Cost effective way of providing more computing power High specs.
1 Network Communications A Brief Introduction. 2 Network Communications.
Process-to-Process Delivery:
Chapter 9 The Transport Layer The Internet Protocol has three main protocols that run on top of IP: two are for data, one for control.
1 Chapter 1 INTRODUCTION TO WEB. 2 Objectives In this chapter, you will: Become familiar with the architecture of the World Wide Web Learn about communication.
Vocabulary Prototype: A preliminary sketch of an idea or model for something new. It’s the original drawing from which something real might be built or.
Chapter 3 Transport Layer
The Transport Layer Implementation Services Functions Protocols
Chapter 9: Transport Layer
Chapter 3 outline 3.1 Transport-layer services
Instructor Materials Chapter 9: Transport Layer
User-Written Functions
Lecture 9 Announcements.
Vocabulary Prototype: A preliminary sketch of an idea or model for something new. It’s the original drawing from which something real might be built or.
06- Transport Layer Transport Layer.
PART 5 Transport Layer Computer Networks.
Beyond HTTP Up to this point we have been dealing with software tools that run on browsers and communicate to a server that generates files that can be.
Introduction to Computers
Vocabulary Prototype: A preliminary sketch of an idea or model for something new. It’s the original drawing from which something real might be built or.
Fight Game Brian Kessler.
NET323 D: Network Protocols
Subject Name: Computer Communication Networks Subject Code: 10EC71
Congestion Control, Internet transport protocols: udp
Transport Layer Our goals:
I. Basic Network Concepts
NET323 D: Network Protocols
Process-to-Process Delivery:
Starting TCP Connection – A High Level View
CPEG514 Advanced Computer Networkst
Net 323 D: Networks Protocols
CSCD 330 Network Programming
Chapter 5 Transport Layer Introduction
Process-to-Process Delivery: UDP, TCP
Computer Networks Protocols
Message Passing Systems Version 2
Exceptions and networking
Transport Layer Our goals:
Layering and the TCP/IP protocol Suite
Presentation transcript:

Lecture 8 Announcements

Final TAs Jeff Tyler Ben David Ben, Carmen, Audrey Ruiqi Mason Loudon Jordan, Nick David Trent Vijay

Final Design Checks Optional this week Required for Final III

Playtesting Feedback Need three people to playtest your game One will be in class Two will be out of class (friends, SunLab, etc.) Should watch your victim volunteer play your game Don’t comment unless necessary Take notes Pay special attention to when the player is lost and when the player is having the most fun

Lecture 8 Networking

STRATEGIES Networking * Multiple players playing the same game on different machines

The Illusion All players are playing in real-time on the same machine This isn’t possible We need to emulate this as much as possible * What we’d like to do for a networked game

The Illusion What the player should see: Things working against us: Consistent game state Responsive controls Difficult to cheat Things working against us: Game state > bandwidth Variable or high latency Antagonistic users * How can we give the appearance of this illusion

Send the Entire World! Players take turns modifying the game world and pass it back and forth Works alright for turn-based games …but usually it’s bad RTS: there are a million units FPS: there are a million bullets Fighter: timing is crucial Let’s talk about some specific networking strategies, and how well they accomplish the outlined goals One way that we can accomplish a networked game is to send game state between clients

Modeling the World If we’re sending everything, we’re modeling the world as if everything is equally important But it really isn’t! Composed of entities, only some of which react to the player We need a better model to solve these problems Player 1 My turn Player 2 Not my turn State 1 Read-only World World * That’s a pretty naïve strategy

Client-Server Model One process is the authoritative server Now we don’t have to wait for slow players, just the server Server can either be hosted by a player or on a separate computer Other processes are “dumb terminals” Sends all input to server Server updates the world and sends it back Problem: client has to wait for server to respond to perform even basic actions Player 1 (server) State 1 processP1Inputs() processP2Inputs() sendState() State 2 Player 2 (client) State 1 sendInputs() receiveState() State 2 Clients only send inputs to the server Server only sends only parts of the game state that have been updated

Client-side Prediction Client responds to player input immediately When the server sends back the authoritative game state, client state is overwritten Server State 1 processP1Inputs() processP2Inputs() sendState() State 2 Client State 1 sendInputs() processP2Inputs() receiveState() State 2 * Again, the server should only send back parts of the game state

Rollback But the server just sent a state that was 100ms in the past! We can’t just replace our game world or we’ll lose commands from the local player Client has to roll back the world and integrate commands since the last known good state

Masking the Timewarp Problem: laggy players experience this jump often Solution: if the server usually sends states from 100ms ago, run the client 100ms behind Turns a jumpy experience into a smooth, only slightly slow one Very useful if relative timing of commands is important Timewarp is the rollback + subsequent prediction This is undesirable, since game state is not accurate for a while So you’re immediately applying inputs to the current game state, and sending the inputs to the server However, you’re displaying the resulting game state 100ms later to give the server time to have responded to the inputs How to accomplish this? Some sort of queue of game states Add game state to queue Update game state in queue when server responds Display game states ~100ms after they were created The “”

What about the server? Without rollback and with masking: In an FPS, would need to lead shots because the game state displayed is in the past With rollback and without masking: The target could be shot after they think they’ve taken cover (by a less laggy player i.e. the server player) Or we could delay the server player as well… Need to think carefully about both technical requirements and game impacts of any networking model Designing a good networking system for your game is a challenging, but potentially rewarding task Think about What you should send between client and server How you should accomplish a smooth / as responsive as possible experience using rollback, and running the game behind

Networking Strategies Questions?

Networking IMPLEMENTATION

TCP: Transmission Control Protocol Abstracts over IP All packets are guaranteed to be received and in the correct order Good for sending important, permanent data (connecting to server, initial game state, etc.)

UDP: User Datagram Protocol A very thin shell around IP Much faster than TCP, but no guarantees about reception or order Good for information where only the most recent state matters (e.g., current game state)

TCP vs UDP (Very) generally: action games use UDP and turn-based games use TCP World state updates can be lost without worry, commands not so much Can potentially combine them TCP sends one-time messages UDP streams updates Best choice varies by project

Java Sockets Very good for most purposes Read and write objects to sockets UDP is deprecated for sockets; for UDP use DatagramSocket

Settings Up Sockets Open a connection on a port Open an input/output stream from the socket Read and write to the streams (which use the socket’s protocol) Close the streams and sockets String host = “127.0.0.1”; int port = 10800; Socket in = new Socket(ip, port); ObjectInputStream stream; stream = new ObjectInputStream( in.getStream()); System.out.println( stream.readObject()); stream.close(); in.close(); String host = “127.0.0.1”; int port = 10800; Socket out = new Socket(ip, port); ObjectOutputStream stream; stream = new ObjectOutputStream( out.getStream()); stream.writeObject(“HelloWorld”); stream.close(); out.close();

Edge Cases What if… Handling errors well is vital to player experience The client disconnects The server dies The client goes insane and sends gibberish The client loses internet for 30 seconds The client is malicious The client changes IP address Handling errors well is vital to player experience

Elegant Disconnects Handle and respond to IO exceptions Don’t just dump a stack trace Display informative status messages Send heartbeat packets every few seconds Then respond if server/client hasn’t received a heartbeat in a while Never let the game continue to run in an unrecoverable state!

Networking Questions?

Procedural Generation Lecture 8 Procedural Generation

Procedural Generation White Noise

What is noise? Randomness e.g. From 0 to 14 take a random number between 0 and 1 By itself, it is jagged and not useful

White Noise // returns a pseudorandom noise value for a given position float noise(Vec2i vec) { Random r = new Random(); r.setSeed(vec.hashCode()); return r.nextFloat(); }

Procedural Generation Value Noise

Value Noise Smooth white noise by taking an average of neighbors Turns white noise into something useful

Value Noise // returns a weighted average of the 9 points around the Vec2i v float valueNoise(Vec2i vec){ // four corners, each multiplied by 1/16 corners = ( noise(vec.x-1, vec.y-1) + noise(vec.x+1, vec.y-1) + noise(vec.x-1, vec.y+1) + noise(vec.x+1, vec.y+1) ) / 16 // four sides, each multiplied by 1/8 sides = ( noise(vec.x-1, vec.y) + noise(vec.x+1, vec.y) + noise(vec.x, vec.y-1) + noise(vec.x, vec.y+1) ) / 8 // center, multiplied by 1/4 center = noise(vec.x, vec.y) / 4 return center + sides + corners }

Procedural Generation Interpolation

Interpolation Most interpolation functions take three arguments. a and b, the value to interpolate between. t, a value between 0 and 1. When t is 0, function returns a When t is 1, function returns b

Interpolation Option 1: linear interpolation For values a and b and interpolation parameter t: f = a * (1 - t) + b * t

Interpolation Option 2: cosine interpolation t’ = (1 - cos(t * pi)) / 2 f = a * (1 - t’) + b * t’ Slower, but much smoother

Interpolation Option 3: cubic interpolation t’ = 3t2 - 2t3 f = a * (1 - t’) + b * t’ Similar to cosine

Interpolation Option 4: Perlin interpolation t’ = 6t5 - 15t4 - 10t3 f = a * (1 - t’) + b * t’ Slightly slower than cubic Super smooth

Fractional Coordinates What if our x and y aren’t integers? Just find the values along the vertices of the unit square and interpolate x0, y0 x1, y0 x, y x0, y1 x1, y1

Fractional Coordinates // returns the noise interpolated from the four nearest vertices float interpolatedNoise(Vec2f vec){ Vec2i topLeft = Vec2i((int) vec.x, (int) vec.y); Vec2i topRight = Vec2i((int) vec.x + 1, (int) vec.y); Vec2i botLeft = Vec2i((int) vec.x, (int) vec.y + 1); Vec2i botRight = Vec2i(int) vec.x + 1, (int) vec.y + 1); float dx = vec.x – ((int) vec.x); float dy = vec.y – ((int) vec.y); float topNoise = interpolate(valueNoise(topLeft), valueNoise(topRight), dx); float botNoise = interpolate(valueNoise(botLeft), valueNoise(botRight), dx); return interpolate(topNoise, botNoise, dy); }

Procedural Generation Perlin noise

Perlin Noise Named for its creator, this guy, Ken Perlin. It’s a great way to make smooth, natural noise which can be used to create terrain, cloud patterns, wood grain, and more! But you’ll probably use it for terrain…

Recall: Value Noise Smooth white noise by taking an average of neighbors Turns white noise into something useful

Perlin Noise Assign each vertex a pseudorandom gradient Vec2f gradient(Vec2i vec) { float theta = noise(vec) * 6.2832; return new Vec2f(cos(theta), sin(theta)); }

Perlin Noise The noise value of each vertex is the dot product of its gradient and the vertex to the target point

Perlin Noise Interpolate between the noise values of the four vertices (just like for value noise)

Perlin noise vs value noise Procedural Generation Perlin noise vs value noise

Perlin Noise vs Value Noise Value noise is easier Perlin noise has fewer plateaus

Procedural Generation Adding noise

Adding Noise Functions Freq. 1 2 4 8 Amp. 1/2 1/4 1/8 result Noise + =

A Good Noise Function What does our noise function need? Given an (x,y) pair and a seed, returns the same value between 0 and 1every time Random.setSeed() only takes a single seed as an argument

A Good Noise Function TA suggestion: use the Vec2f.hashcode() method Returns a single integer that is unique to each pair Will return the same integer every time Use this number to generate your seed for Random.nextFloat() call

Noise // returns a pseudorandom noise value for a given position float noise(Vec2i vec) { Random r = new Random(); r.setSeed(vec.hashCode()); return r.nextFloat(); }

References What follows is a lot of pseudocode that contains concepts that we haven’t discussed Persistence, octaves, etc. Use this website as a reference for value noise: https://web.archive.org/web/20160310084426/http://freespace.virgin.net/hugo.elias/models/m_perlin.htm Also covers an even smoother version of cubic interpolation Use this website as a reference for Perlin noise: http://flafla2.github.io/2014/08/09/perlinnoise.html We stole our Perlin noise pictures from them

Procedural Generation Questions?

M III / Tac V Playtesting!!! :D