How do video games solve the “two people shoot at the same time” dilemma?

I’ve always wondered how multiplayer video games – that is, those involving players distributed across a network – decide upon a winner in this typical situation: Player A and Player B fire one-shot-kills bullets at each other at nearly the same time (Player A’s fires 1/1000th of a second first). Being that each player is on their own machine across a network and that the time on their machines is not necessarily correct (a bit fast or a bit slow), the game server cannot simply trust the received data. How are these life or death decisions made?

I posed the question to Quora and only received unhelpful answers. Elsewhere, however, I was provided two good sources that each answered the question. First, from The Valve Developer Community – Source Multiplayer Networking page:

Multiplayer games based on the Source Engine use a Client-Server networking architecture. Usually a server is a dedicated host that runs the game and is authoritative about world simulation, game rules, and player input processing. A client is a player’s computer connected to a game server. The client and server communicate with each other by sending small data packets at a high frequency (usually 20 to 30 packets per second).

A client receives the current world state from the server and generates video and audio output based on these updates. The client also samples data from input devices (keyboard, mouse, microphone, etc.) and sends these input samples back to the server for further processing. Clients only communicate with the game server and not between each other (like in a peer-to-peer application). In contrast with a single player game, a multiplayer game has to deal with a variety of new problems caused by packet-based communication.

Basic Networking

The server simulates the game in discrete time steps called ticks. By default, the timestep is 15ms, so 66.666… ticks per second are simulated, but mods can specify their own tickrate. During each tick, the server processes incoming user commands, runs a physical simulation step, checks the game rules, and updates all object states. If the game is large or the servers busy dealing with a roblox hack, this may interfere with gameplay.

After simulating a tick, the server decides if any client needs a world update and takes a snapshot of the current world state if necessary. A higher tickrate increases the simulation precision, but also requires more CPU power and available bandwidth on both server and client.

Lag Compensation

Let’s say a player shoots at a target at client time 10.5. The firing information is packed into a user command and sent to the server. While the packet is on its way through the network, the server continues to simulate the world, and the target might have moved to a different position. The user command arrives at server time 10.6 and the server wouldn’t detect the hit, even though the player has aimed exactly at the target. This error is corrected by the server-side lag compensation)

The lag compensation system keeps a history of all recent player positions for one second. If a user command is executed, the server estimates at what time the command was created as follows:

Command Execution Time = Current Server Time – Packet Round-Trip-Time – Client View Interpolation

Then the server moves all other players – only players – back to where they were at the command execution time. The user command is executed and the hit is detected correctly. After the user command has been processed, the players revert to their original positions.

Client and server hitboxes don’t exactly match because of small precision errors in time measurement. Even a small difference of a few milliseconds can cause an error of several inches for fast-moving objects. Multiplayer hit detection is not pixel perfect and has known precision limitations based on the tickrate and the speed of moving objects. Increasing the tickrate does improve the precision of hit detection, but also requires more CPU, memory, and bandwidth capacity for server and clients.

The question arises, why is hit detection so complicated on the server? Doing the back tracking of player positions and dealing with precision errors while hit detection could be done client-side way easier and with pixel precision. The client would just tell the server with a “hit” message what player has been hit and where.

We can’t allow that simply because a game server can’t trust the clients on such important decisions. Even if the client is “clean” and protected by Valve Anti-Cheat, the packets could be still modified on a 3rd machine while routed to the game server. These “cheat proxies” could inject “hit” messages into the network packet without being detected by VAC (a “man-in-the-middle” attack).

Another great article on the subject is Gamasutra – 1500 Archers on a 28.8: Network Programming in Age of Empires and Beyond, which talks about the same subject from the perspective of a RTS game and in the age of dial up.

Building strength, power, muscle mass, and muscular endurance

Men’s Journal – Everything You Know About Fitness is a Lie

It all starts with understanding the four basic muscular aptitudes: strength, power, muscle mass, and muscular endurance.

Strength means how much you can lift once, and it’s the backbone of every sport on Earth, from the crouch-holding power of a skier to the one-finger pull-up of a climber.

Power is a more slippery term that means “speed strength,” or how much you can lift very, very quickly, and it gives you the explosive paddling speed to catch a big wave or the pedaling burst to fire your mountain bike up a grade.

Muscle mass can be a liability in sports like climbing, where it’s all about strength-to-weight ratio, but mass helps enormously with games like rugby and football, and it can support strength and power — not to mention make you look better in a T-shirt.

Muscular endurance means how many times you can lift a given weight in a row without stopping, and it’s the essence of running, swimming, and even a kayaker’s long-haul paddling.

Read More

Performance reviews that work

Samuel A. Culbert, a professor in the Anderson School of Management at the University of California has this advice about the use of performance evaluations in the workplace:

The New York Times – Why Your Boss Is Wrong About You

Performance reviews are held up as objective assessments by the boss, with the assumption that the boss has all the answers.

Now, maybe your boss is all-knowing. But I’ve never seen one that was. In a self-interested world, where imperfect people are judging other imperfect people, anybody reviewing somebody else’s performance — whether as an actor, a writer, a spouse, a friend or a worker — is subjective. It’s why when employees switch bosses, more often than not their evaluation changes as well.

Under such a system, in which one’s livelihood can be destroyed by a self-serving boss trying to meet a budget or please the higher-ups, what employee would ever speak his mind? What employee would ever say that the boss is wrong, and offer an idea on how something might get done better?

Only an employee looking for trouble.

Is there a way out? I believe there is, and it works for both government and business. It’s something I call the performance preview. Instead of top-down reviews, both boss and subordinate are held responsible for setting goals and achieving results. No longer will only the subordinate be held accountable for the often arbitrary metrics that the boss creates. Instead, bosses are taught how to truly manage, and learn that it’s in their interest to listen to their subordinates to get the results the taxpayer is counting on.

Instead of the bosses merely handing out A’s and C’s, they work to make sure everyone can earn an A. And the word goes out: “No more after-the-fact disappointments. Tell me your problems as they happen; we’re in it together and it’s my job to ensure results.”

Performance reviews aren’t the only ways to measure effectiveness, to be sure. Workers whose output is tangible and measurable — how much garbage is picked up, how many streets are cleared of snow — are increasingly evaluated according to numerical goals. I’d argue these measurements are similarly flawed. Workers are almost always better at coming up with metrics that lead to systemwide gains than bosses alone are. The key to systemwide success (as opposed to individual success) is still employees working together under the leadership of good managers.

Rings don’t come much cooler than this one

Keep watching until the second half of the video – it’ll make you do a double-take.

The history of the skyscrapers + what makes modern cities so expensive

By way of Market Urbanism is a feature article in The Atlantic by Edward Glaeser about the history of tall cities like New York, Chicago, Paris and Mumbai. Glaeser is an economist by trade and thus talks at length about the incentives and disincentives of building height restrictions and the challenges of preserving historical architecture while simultaneously serving the need for new housing spaces.

The Atlantic – How Skyscrapers Can Save the City

In the late Middle Ages, the wool-making center of Bruges became one of the first places where a secular structure, a 354-foot belfry built to celebrate cloth-making, towered over nearby churches. But elsewhere another four or five centuries passed before secular structures surpassed religious ones. With its 281-foot spire, Trinity Church was the tallest building in New York City until 1890. Perhaps that year, when Trinity’s spire was eclipsed by a skyscraper built to house Joseph Pulitzer’s New York World, should be seen as the true start of the irreligious 20th century. At almost the same time, Paris celebrated its growing wealth by erecting the 1,000-foot Eiffel Tower, which was 700 feet taller than the Cathedral of Notre-Dame.

Read More

The best fixed-width programming font for Windows OSes: Inconsolata

As I round into the last year of a solid decade of being a professional software developer, I’m becoming more and more aware of how important it is to make your working environment as comfortable as possible. This extends beyond your keyboard, mouse and chair into the realm of software: Is your development environment making you log more keystrokes and mouse movements than needed? Are you taking it easy on your eyes by providing a high-contrast interface with a decent font size?

That last question, spurred mostly by my transition to a MacBook Pro as my development machine, had me settle on Menlo. Back on my Windows machines at home, after sifting through a number of options mentioned here by Jeff Atwood I decided on Inconsolata. Tracking down a TrueType (TTF) version took a few more minutes but eventually led to success – I’ve mirrored the file I found locally here for others to download – enjoy.

Inconsolata TrueType (TTF) Font

The radically improbable series of events that led to modern spaceflight/rocketry

Author Neal Stephenson (of Snow Crash fame) wrote a piece on the strange set of coincidences that occurred in the last half-century to lead to modern society’s expertise in rocketry and space travel. It’s one of those Catch-22 pieces of writing that make you wonder at how crazy the world history we take for granted actually was.

Slate.com – Space Stasis: What the strange persistence of rockets can teach us about innovation

The phenomena of path dependence and lock-in can be illustrated with many examples, but one of the most vivid is the gear we use to launch things into space. Rockets are a very old invention. The Chinese have had them for something like 1,000 years. Francis Scott Key wrote about them during the War of 1812 and we sing about them at every football game. As late as the 1930s, however, they remained small, experimental, and failure-prone.

There is no way, of course, to guess how rockets might have developed, or failed to, were it not for the fact that, during the 1940s, the world’s most technically sophisticated nation was under the absolute control of a crazy dictator who decreed that vast physical and intellectual resources should be hurled into the project of creating rockets of hitherto unimagined size.

These rockets, which were known as V-2s, were worse than useless from a military standpoint, in the sense that the same resources would have produced a much greater effect had they been devoted instead to the production of U-boats or Messerschmitts. Accordingly, the victorious nations showed only modest interest in their development immediately following the war. It is reasonable to suppose that little more would have been done with them, had it not been for another event, happening at the same time, even more bizarre and incredible than the seizure of absolute control over a modern nation-state by a genocidal madman. I refer, of course, to the sudden and completely unexpected development of nuclear weapons, undertaken over the course of a very few years by a top-secret crash program atop a mesa in New Mexico.

Read More

Getting XenonMKV to work with Windows 7 64-bit

XenonMKV is a terrific program for converting videos in the MKV format to an MP4 that an Xbox 360 can play.

After upgrading my desktop PC to Windows 7 (64-bit), I found that the MP4 files I was outputting only worked if I changed the version of MP4Box.exe used to 0.4.5 (defaults to 0.4.6). After that I had no problems.

Study: All net job growth in the U.S. since 1977 has come from startups

There was an interesting piece in the HBR blogs a few days ago that was written in response to President Obama’s State of the Union speech – specifically, the part about job creation. The author takes note of how job creation in since 1977 has been entirely due to startups, but that the President’s go-to crew for ideas on how to foster growth consist of all the wrong people for the job.

Harvard Business Review: Looking for Jobs in All the Wrong Places: Memo to the President

According to a recent study by the Kauffman Foundation, for example, all net job growth in the U.S. since 1977 has been due to start-ups. The data show that if you took start-ups out of the picture and looked only at large established firms, job growth in the U.S. over the last 34 years would actually be negative.

“When it comes to U.S. job growth,” said Kauffman Foundation economist Tim Kane in his report, “start-up companies aren’t everything. They’re the only thing.”

In your address last night, Mr. President, you correctly noted that, “The first step in winning the future is encouraging American innovation.” Here, too, start-ups are the driving engine of our nation’s global innovation leadership.

It is startups who have generated virtually all of our nation’s major technological breakthroughs in the last hundred years — from cars and planes to semiconductors, PCs, software, and the Internet — and in the process sparked the creation of whole new industries and millions of new jobs. And as economists have demonstrated, this kind of start-up-led innovation is the source of virtually all economic growth and increases in living standards in the U.S.

In other words, Mr. President, everything depends upon start-ups: Job creation. Our standard of living. Our prosperity as a nation. The American Dream itself.

So if the target of national policy is job creation, then the bullseye of that policy must be centered on startups. Yet policy makers in both parties continue to aim at the wrong target.

Last month, Mr. President, you held a summit meeting with 20 of the nation’s top CEOs to look for ways to spur job creation. But Fortune 100 CEOs are exactly the wrong people to talk to about jobs. Big Business is not a major job creator. Indeed, as one commentator put it, the guest list at this summit meeting represented “a who’s who of outsourcing American jobs.”

Build a subway under Queen St.

The National Post’s Lawrence Solomon brought up a topic I read about recently on Market Urbanism – the fact that mass transit doesn’t have to equate to public transit, even if it’s only the operating part of the puzzle in private hands.

In specific, replacing the road-clogging streetcars of Queen St. with a subway line sounds like the best idea for the TTC I’ve heard in a decade. The density is there, as is a solution to the streetcar problem. Let’s get it built!

National Post – Let private enterprise build subways

As urban guru Jane Jacobs advocated, public transit is a business that should be in private hands. But Mr. Ford would be wrong to give the TTC away. He should instead sell it to the highest bidder — the TTC would fetch $2-billion or more if put on the market, depending on the conditions attached (a decade ago, a U.K. company did try to purchase the TTC, but was rebuffed by the province).

Or, if Mr. Ford didn’t want to sell off the TTC holus bolus, he could auction off different routes, as did London, where contracting out was an instant success — the quality of service soared and costs dropped as companies offering everything from minibuses and double-deckers to subways and later trams competed for customers.

This is where a suggestion from Mr. Smith comes in. Instead of building the money-sucking subway that Mayor Ford suggests, Mr. Smith argues that Toronto should instead build a subway under Queen Street, one of Toronto’s busiest downtown streets. His argument — that Toronto would get more bang for the buck by putting a subway along a route rich with people and businesses — is indisputable.

I agree that a Queen Street subway, which would replace the now-crowded Queen streetcar, makes great sense. I further believe it could be built on a free-market basis, and some history bears me out.

A century ago, before governments across the continent took over transit systems, private companies ran streetcars for profit, and even paid cities a franchise fee for the right to use city streets. When traffic later became too heavy for the streetcars to handle, a subway would be built under the streetcar route, and the streetcars would be retired.

This was the formula for success that existed before transit systems became politicized and nationalized, and sometimes afterward, too: Toronto’s transit system, though it became city-owned by 1921, retained its business-like culture for decades.

Early operators of the Toronto transit system, in fact, had plans to build a subway under Queen, and in a 1946 referendum, Torontonians overwhelmingly voted to build a Queen Street streetcar-subway line that would have risen above ground at Logan to the east and Trinity Park to the west. (Unbeknownst to most Torontonians, one subway station of this east-west line would soon be built beneath the existing north-south Queen subway station.) A few years later, the proposed east-west streetcar-subway route was upgraded to a full-fledged subway route.

Then politicians got into the act, following the creation of Metropolitan Toronto in 1954. The TTC, which until then had profitably operated the City of Toronto’s dense urban routes, suddenly was required to also service Metro Toronto’s low-density suburban areas. Metro Toronto marked the beginning of the end of the TTC as a financially self-supporting business.

The viable Queen line was shelved — temporarily at first — in favour of an east-west Bloor-Danforth line that would reach the suburbs. Then temporary became permanent as the suburban politicians now dictating TTC policy gave priority to developing suburban routes, unconcerned that the Queen subway was viable while suburban projects were not. In the end, the TTC — easily the best and most profitable transit system on the continent — became a money-loser, like transit systems everywhere that are run by politicians.

Mr. Ford can end that sad history of wasteful public transit projects by marketing the Queen Street line to the private sector. Private operators would not only value the revenues that passengers would leave behind at the farebox but also the revenues to flow from the Queen stations’ retail potential, given that Queen is one of Toronto’s premier shopping streets and that station operators are increasingly capitalizing on the shopping potential of street-level stations.

An auction of new subway-related surface and sub-surface zoning rights to Queen Street property owners allied with would-be station operators would not only help Mr. Ford meet his budget targets, it would also let Mr. Ford fulfil other campaign promises — reducing the number of city employees, removing streetcars from city streets, and truly making Toronto a “Transportation City.”