13 June 2012

Stress: appraisal, coping, and physiology

Notes from the first few weeks of a class on stress by Sally Dickerson taught throughout Spring 2012.

Basics

Eustress = positive/healthy stress. Example: wedding, vacation. As opposed to distress. Three phases of stress: stressor, appraisal, and response.

The stressor is the eliciting event; examples are being stuck in traffic, having an exam, or arguing with your partner. Stressors break homeostasis, our stability with the environment. A stressor can be acute or chronic. Durations of exposure to stressor vs duration of perceived threat vs duration of stress response.

The response happens at all levels: emotional (e.g. fear), physiological (e.g. BP increases), and behavioral (e.g. running away). The response aims at bringing back homeostasis. If it lasts for too long, sickness appears because of the general adaptation syndrome.

Appraisal

Evaluation/interpretation of the harm, threat, and overwhelmingness of the stressor to determine the response. Individual- and context-specific. Individuals who are told beforehand that "pain is going to happen" have stronger physiological response to a stressor than individuals told "it's just a formality, nothing too big". Appraisal consists of the primary appraisal and coping.

Primary appraisal

The individual estimates the importance/meaning of the stressor, and its implications on her well-being. "This is the most important day of my life" vs "No big deal". Three types of primary appraisals:

Type Description Emotions generated Physiological response Example with stressor = "just got fired"
Harm/loss The damage has already been done sadness, anger damaging "Everyone looked at me packing my stuff"
Threat Possibility of future damage anxiety, fear damaging "How am I going to pay the rent?"
Challenge Potential to overcome and profit. excitement positive/healthy,
smaller than harm or threat
"Let's find a better job"

Primary appraisal moderators:

  • sense of control. If the individual feels (no need to actually be) in control = less stress. But inappropriate sense of control increases stress: individuals blame themselves for an event they actually could not influence, especially if the event is big: "it's my fault if my car's brakes broke and it caused an accident".
  • predictability. Know when stressor happens (and/or does not happen) reduces stress. Unless stressor very frequent or very rare, or horrible outcome (e.g. earthquake).
  • ambiguity. If information on the stressor is vague, stress increases.
  • centrality. If the outcome is important to the individual, stress increases.
- Optimists Pessimists
Face problems actively passively
Receive positive events wrt themselves, in general and absolute terms wrt other people, in specific and relative terms
Receive negative events wrt other people, in specific and relative terms wrt themselves, in general and absolute terms
Example: just got fired "my skills were not a good match for that company" (external) "i am a failure" (internal), "I can't do anything" (global), "I'll never get another job" (absolute)

Coping

The individual estimates how well she can cope with the stressor. If she estimates she does not have enough resources to cope with the stressor, the stress response will be bigger. Coping can happen before, during, or after a stressor, and it varies in time. When it happens before, it is called proactive coping (e.g. keep water bottle packs and a torch light at hand in case of a disaster). Even when given information, if people feel like they can not change the outcome, or if they underestimate the problem, they may not pro-actively cope.

Avoidance or minimization are effective coping strategies for short-term stressors. Vigilance and confrontation consist of gathering information or take direct action, and are more effective in the long-run, but fail if the information is of poor quality (e.g. individual googles "soar throat" symptoms and finds herself on a page about a deadly disease). Social support from others is a form of coping; the individual reduces her stress response by receiving moral support, information about the stressor, or tangible resources (money, workforce, ...) to overcome the stressor.

Coping can be problem-focused, emotion-focused, or both. Problem-focused coping is constructive (e.g. studying for an exam), and effective when the individual can have an impact on the stressor. Emotion-focused coping does not address the problem, but rather regulates the individual's emotions cognitively (how people think about the stressor, e.g. "it could be worse"), or behaviorally (doing something, e.g. jogging or eating chocolate to feel better). Emotion-focused coping is effective when the individual does not have control on the stressor.

In general, optimists deny less and cope better than pessimists. For instance, Type A individuals are competitive, easily provoked, fast-paced, and impatient. They have more risky behaviors, are less likely to receive social support, and have bigger physiological responses. Hence, they are more sensitive to stress. Moreover, according to a 2006 study (see also the pdf), Big 5's Neuroticism is related to distress and emotion-focused coping, while Conscientiousness is related to task-focused coping.

Methods for assessing stress

  • After an unpredictable/random trauma (e.g. a disaster): from groups or individuals. Problem: getting a baseline before the stressor happened. Solution: compare with similar groups or individuals who were not exposed to the trauma.
  • Life events: go through individual's recent events to assess her current stress level. Depending on the category of the individual, each event has a standard weight (e.g. for undergrad students, "death of relative" = 100 points, "got a ticket" = 20 points).
  • Daily stressors: going over recent events or maintaining daily diary (prompted by researchers every day at the same hour).
  • Lab experiments: standardized stressor, influence on appraisal (but appraisal ultimately depends on the individual), can measure physiological response, but not generalizable.

Physiologically

Cortisol is a hormone released by the adrenal gland in response to stress. Its function is to have the body generate energy by breaking body fat into glucose. In the circadian rhythm, it naturally peaks at wake up, and falls at sleep time.

Cognitive tasks such as mental arithmetic increase the concentration of cortisol in the blood. Public speaking increases it even more. The two combined generate more than the sum of each. Public speaking exposes our differences with other people, and invites criticism: it is a social evaluative threat. This threat is increased if we are captured on permanent record, in front of a critical audience, or compared to others negatively. On the other hand, emotion induction (such as watching a scary movie) or exposure to noise do not influence the cortisol level.

Uncontrollability increases the cortisol level. Hence, false feedback to a stressful task will increase the cortisol level. Changing the task difficulty on the fly, harassing the individual under stress, or adding noise and distractions increases stress. An uncontrollable social-evaluative threat generates the biggest cortisol response, and a slow stress recovery: the cortisol level remains high longer.

Novelty and diversity also seem to increase the cortisol response. Facing many stressors at a time seems to increase the cortisol level logarithmically with the number of stressors. On the other hand, facing a stressor as a group reduces the individuals' cortisol response. Similarly, in a 1991 study, women's stress response was found to be smaller if their pet rather than their friend was with them: as opposed to the friend, the pet provides support without judging.

07 June 2012

Starcraft2: e-sport design - Bowder 2011

Notes from a talk given at UCI by Dustin Browder on April 18 2012, titled "The Game Design of STARCRAFT II: Designing an E-Sport". You can also see the GDC 2011 video.

For a game to be an e-sport, it needs to be watchable, simple, and clear. It should show player skills, and there should be uncertainty about the outcome. The audience should try to guess the players' next moves.

An e-sport needs few units, so that people don't have to know so much about the game. Plus, with too many units, the expert players figure out which unit is the best for a particular situation. With few units, each unit has more varied types of gameplay; for instance, the Collosus has a strong attack and walks slowly, so it is best used with other units in front of it. However, it also climbs cliffs, so it could be used for taking a base from behind. Similarly, the Force Field spell can be used to protect, split armies, or channel enemies into choke points.

Micro-management is important: that's the R of RTS.

The unit size is important: if Ultralisks or effects were larger than buildings, they would hide zerg rushes, and also make the whole game less clear.

There are standard openings, but there's no standard "5-min building phase" happening in every Starcraft 2 game.

In a "big-army game", units die often, so they can't have a name. Unlike in Warcraft, there's very few heroes. There's also less story.

04 June 2012

TERA's free-targetting combat: server-side

In the May 2012 issue of GD mag, Seungmo Koo, the server architect for TERA, wrote about how their studio implemented the server back-end for the game's free-targeting combat system. Some parts of the technical solution described in the article were unclear, or the problems were not obvious, so I filled the gaps by guessing their approach.

Basics

During fights, the player uses various kinds of attacks and skills. For the player, free-targeting means paying attention to the avatar's orientation and position. There is no monster selection like in WoW. Looking at actual gameplay footage, the combat feels more lively, but there is a lot of hit and run.

From a system perspective, free-targeting means the server does not know which enemy the avatar is targeting. Hence, the server has to detect if a skill's volume of effect collides with any of the monsters around the avatar. To ensure quick computation of the collision, the server runs at 60 FPS. These features are similar to traditional multiplayer FPS requirements, except that for security and simplicity, there is no lag compensation running on the client-side. All the computations happen on the server-side. However, for an MMO to reach a gameplay as responsive as an FPS, the client should be able to execute the player's actions immediately, account for lag, and eventually run some of the NPCs. TERA accounts for lag like an MMO: in PvE, NPCs are slow to give players time to react. In PvP, however, players with a lower ping to the server have an advantage.

Game design

Every creature in the game world is made of cylinders. A skill reaches its target when the skill's volume of effect collides with one of the target's cylinders. A skill's volume of effect can be a cylinder (e.g. usual AoE around a target or self), a portion of a cylinder (e.g. rotating attack using an axe), a portion of a cone (e.g. a frontal attack using a spear), and so on.

Since skills may last for some time, they are discretized in two to more than a dozen targeting times, and each targeting time is associated with a particular volume of effect. Each targeting time consists of two phases: a search (read) phase, and an update (write) phase. For instance, using a rotating attack, the avatar spins for 360 degrees in 300ms, inflicting damage during its turn. The first targeting time fires at 50ms: in the search phase, the server searches for a target standing in a particular volume in front of the avatar, and, in the update phase, inflicts that target 200 damage. The second targeting time fires at 100ms: the server searches for a target standing in another particular volume on the left of the avatar, and inflicts that target 100 damage. And so on for the remaining targeting times.

Multi-threading and performance

Task Example
Timer Damage over time or NPC AI movement scripts
Region update Add/remove/update the position of a creature in a region
Creature update Update HP, status, position of a creature

Each TERA server runs the whole world for approximately 6k concurrent players. The server has a few things to do in the main loop. First, it processes client packets, and generates timer, region, and/or creature tasks from them. That is when the search-for-target phase happens. Then, it executes scheduled timer tasks, which will likely themselves generate region and creature tasks. And finally, it executes region tasks. The update phase happens in the creature tasks, and also in the region task in case of creature movement, spawn, or death events.

To come up with their final design, the TERA engineers may have followed this train of thoughts:

  • Problem: an 8-core server running Windows reaches 100% CPU with 3k players. How can this be improved?
  • Solution: use asynchronous IO such as Window's IOCP. It automatically creates a task queue for client packets and a worker thread pool to process that packet queue in parallel.
  • New problem: The threads spend too much time waiting for locks when trying to read or update region data (e.g. list of creatures in the region, or creature position).
  • Solution: Avoid contention by replicating the world in each thread. No lock: the thread searches in its own version of the world.
  • New search-phase problem: When executing a region task, the region data of a particular thread becomes inconsistent with other threads.
  • Solution: The thread pushes the region tasks it generates into a queue shared between all threads, so that each thread processes all the region tasks. As an example, when an 8-core server receives a client movement packet, one thread processes it and generates (for instance) one region task from that packet. The thread pushes this region task to the end of the queue with an execution counter of 8. Each of the 8 threads processes the task queue at its own pace. When a thread processes a task, it decrements the task's counter. When the counter reaches 0, the thread deletes the task from the queue. Hence, the task mentioned above will be removed from the queue when all the threads have processed it.
  • New update-phase problem: frequently updating a particular creature causes lock contention.
  • Solution: The world replica of each thread stores creature pointers. When a thread processes a packet or a timer task that results in a creature update, it pushes the creature's function to run (e.g. Creature.receiveDamage), with particular arguments (e.g. 200) to that creature's task queue. If the creature task queue is currently being iterated over by another thread, then the current thread returns to what it was doing before (e.g. main loop). Otherwise, the current thread iterates over the creature's task queue. The queue starts with the task the thread just pushed, but other threads may push tasks to the queue while the current thread is processing its task. The current thread will process those extra tasks too, until the queue is empty. Then, the thread will go back to its main loop. Hence, creature tasks are executed asynchronously; getting a return value for the task execution requires the active object pattern.

The resulting high-level architecture is something like the following:

Questions

Seugmo replied to my original questions (see the comment below); here are some more!

  • How much CPU is caused by packet processing? How much does the CPU increase when 1000 players gather together versus when players are homogeneously scattered?
  • When lots of creatures gather in the same region, the search phase (happening on only one thread) may consume a lot of that thread's CPU. Could the search phase happen faster if the regions were smaller? Could it happen faster if the regions were using Binary Space Partitioning?

03 June 2012

Spline: Locales and Beacons - Barrus 1996

Locales and Beacons by Barrus et al in 1996

  • Locales are regions of the world containing objects and split statically by designers. Locales can be children of another locale. Ex: car locale contains rear-view mirror + tires + ..., and the car's parent locale can switch from garage to street.
  • Absolute object positions in the world are obtained by converting their position in their locale's frame of reference into the world's locale by a series of transformations between locales. Ex: make a locale neighbor of itself using a reflection transformation gives a mirror effect.
  • A locale is run by only one server, and users in that locale belong to that locale's multicast address. Objects push updates to their locale's multicast.
  • A beacon maps a tag to a locale's mutlicast address. A beacon is handled by its beacon server (not a locale server). That beacon server is found by hashing the beacon's tag.
  • Beacon usages:
    • If someone creates a part of a virtual world and wants other people to visit, he can mark the area with a beacon and publish the tag.
    • Private tag only seen by people in the object's locale; people that run into the beacon can subsequently keep track of it no matter where it moves. Useful to follow an object across locales.
    • Someone who wants to provide a service can publish a tag, without creating a beacon. For example, suggest the tag "car", and car-makers tag their cars with "car". All the cars are addressable from that beacon's multicast.
  • Demo: Tour Diamond Park

01 June 2012

Design patterns in games

A workshop held at FDG 2012 with a dozen people.

Game patterns needed for: sharing a common vocabulary, recording design decisions, exploring the design space (survey), and procedurally generating content.

Problems:

  • How to navigate and teach through 100s of patterns? How to be generic yet not too vague?
  • Which theories can be used to back up the effectiveness of patterns? Methods to collect patterns?
  • Descriptive vs prescriptive? Should a pattern hold values/ethics?

Patterns are solutions to problems, or gameplay experience?

Patterns differ across levels of expertise, and across game genres.

Different granularity levels: for example in FPS, weapon patterns (e.g. short range + slow fire rate + high damage) are at a lower level than gameplay/behavior patterns (e.g. push-pull or search-and-destroy). Need to combine low-level patterns (e.g. weapon or NPC or level-design patterns) to create higher-level gameplay/behavior patterns (e.g. push-and-pull or secure play).

Patterns are generally from the designer's perspective; what about from the player's perspective? Should a pattern take into account player's feelings and emotions (e.g. feel badass when holding a shotgun or sneaky with a sniper)?

Dimensions of design: is the design space (e.g. weapon range, load, fire speed, damage ...) completely explored?