Developing a Multiplayer RTS with the Unreal Engine 3
Marcel Köhler, Nick Prühs
Faculty of Design, Media and Information
H...
Outline
1.
2.
3.
4.
5.
6.
7.

Unreal Engine Basics
Controller & Pawn
Camera
Unit Selection & Orders
Weapon Fire
Network
Mi...
Unreal Engine Basics
• Core
– C++
– Rendering, Sound, Gameloop, Collision, Physics,
Threading, Low Level Network

• Virtua...
Unreal Engine Basics
• Unreal Script
– Similar to C++ and Java
– High-level object-oriented language
– Bytecode based (pla...
Controller & Pawn
Controller & Pawn
Controller & Pawn
Controller & Pawn
Controller & Pawn
Controller & Pawn
Unit Selection & Orders
Short left click
• < 15 ms
• Single unit selection
• Unit order

Long left click
• >= 15 ms
• Mult...
Weapon Fire
Weapon Fire
Weapon Fire
Weapon Fire
Weapon Fire
Weapon Fire
Weapon Fire
Weapon Fire
Weapon Fire
Weapon Fire
Weapon Fire
Weapon Fire
Network
„Unreal views the general problem of
coordinating a reasonable approximation of a
shared reality between the serve...
Network
• Generalized Client-Server Model
– Authoritative server (Dedicated, Listen)
– Predicting and simulating clients
–...
Network - Basic Terminology
• Actor
– Object that can move and interact with other
actors

• Level
– Object which contains...
Network – Update Loop
1. if (server)
Send(Gamestate) to all clients
2. if (client)
Send(RequestedMovement) to server
Recei...
Actor Roles
• Describes how much control the machine
(server or client) has over an actor
• Controls the actors function c...
Bandwidth Optimization: Actor Relevancy
• Eight prioritized rules
• An actor is relevant, if…
– Actor.RemoteRole != None
–...
Bandwidth Optimization: Actor Relevancy
• Eight prioritized rules
• An actor is relevant, if…
– Actor.RemoteRole != None
–...
Bandwidth Optimization: Actor Relevancy
• Eight prioritized rules
• An actor is relevant, if…
– Actor.RemoteRole != None
–...
Bandwidth Optimization: Prioritization
• Actor.NetPriority
– Regulates share of the bandwidth based on how
important the A...
Replication
• Actor Replication
– Only Location, Rotation valid on spawn

• Variable Replication
–
–
–
–
–

Regulated by c...
Where‘s Waldo?
simulated event ReplicatedEvent(name VarName)
{
if (VarName == 'TeamIndex')
{
ChangeColor(TeamIndex);
}
}

...
Where‘s Waldo?
simulated event ReplicatedEvent(name VarName)
{
if (VarName == 'TeamIndex')
{
ChangeColor(TeamIndex);
}
els...
Replication
• Function Call Replication
– Keywords:
• server, client
• reliable, unreliable

– Server -> Client: only to c...
Fog of War
• hides any enemy units
that aren‘t within the
sight radius of a friendly
unit
• needs to be computed
efficient...
Visibility Mask

class HWVisibilityMask extends Object;
/** The tiles the map consists of. */
var array<bool> MapTiles;
/*...
Visibility Mask

class HWVisibilityMask extends Object;
/** The tiles the map consists of. */
var array<bool> MapTiles;
/*...
Visibility Mask

class HWVisibilityMask extends Object;
/** The tiles the map consists of. */
var array<byte> MapTiles;
/*...
Updating the Visibility Mask
/** Updates this visibility mask, re-computing the vision for
the team this mask belongs to. ...
Updating the Visibility Mask
• …is done less frequently than the frame-rate
– whenever an own unit moves, spawns, dies or ...
Translating World Space into Tile Space
𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = (

𝑃𝑜𝑠

− 𝑀𝑎𝑝𝐶𝑒𝑛𝑡𝑒𝑟
+ 0.5) ∙ 𝑇𝑖𝑙𝑒𝑠
𝑀𝑎𝑝𝐷𝑖𝑚

𝑊𝑜𝑟𝑙𝑑
Translating World Space into Tile Space
𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = (

𝑃𝑜𝑠

− 𝑀𝑎𝑝𝐶𝑒𝑛𝑡𝑒𝑟
+ 0.5) ∙ 𝑇𝑖𝑙𝑒𝑠
𝑀𝑎𝑝𝐷𝑖𝑚

𝑊𝑜𝑟𝑙𝑑

Maybe we should take ...
Translating World Space into Tile Space
𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = (

𝑃𝑜𝑠

− 𝑀𝑎𝑝𝐶𝑒𝑛𝑡𝑒𝑟
+ 0.5) ∙ 𝑇𝑖𝑙𝑒𝑠
𝑀𝑎𝑝𝐷𝑖𝑚

𝑊𝑜𝑟𝑙𝑑

• in
– position of an...
Translating World Space into Tile Space
𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = (

𝑃𝑜𝑠

− 𝑀𝑎𝑝𝐶𝑒𝑛𝑡𝑒𝑟
+ 0.5) ∙ 𝑇𝑖𝑙𝑒𝑠
𝑀𝑎𝑝𝐷𝑖𝑚

𝑊𝑜𝑟𝑙𝑑

• in
– position of an...
Translating World Space into Tile Space
𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = (

𝑃𝑜𝑠

− 𝑀𝑎𝑝𝐶𝑒𝑛𝑡𝑒𝑟
+ 0.5) ∙ 𝑇𝑖𝑙𝑒𝑠
𝑀𝑎𝑝𝐷𝑖𝑚

𝑊𝑜𝑟𝑙𝑑

• in
– position of an...
Translating World Space into Tile Space
𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = (

𝑃𝑜𝑠

− 𝑀𝑎𝑝𝐶𝑒𝑛𝑡𝑒𝑟
+ 0.5) ∙ 𝑇𝑖𝑙𝑒𝑠
𝑀𝑎𝑝𝐷𝑖𝑚

𝑊𝑜𝑟𝑙𝑑

• in
– position of an...
Translating World Space into Tile Space
𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = (

𝑃𝑜𝑠

− 𝑀𝑎𝑝𝐶𝑒𝑛𝑡𝑒𝑟
+ 0.5) ∙ 𝑇𝑖𝑙𝑒𝑠
𝑀𝑎𝑝𝐷𝑖𝑚

𝑊𝑜𝑟𝑙𝑑

• in
– position of an...
Translating World Space into Tile Space
𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = (

𝑃𝑜𝑠

Step 1:
Compute the object‘s
offset from the map
center.

− 𝑀𝑎𝑝...
Translating World Space into Tile Space
𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = (

𝑃𝑜𝑠

− 𝑀𝑎𝑝𝐶𝑒𝑛𝑡𝑒𝑟
+ 0.5) ∙ 𝑇𝑖𝑙𝑒𝑠
𝑀𝑎𝑝𝐷𝑖𝑚

𝑊𝑜𝑟𝑙𝑑

Step 2:
Transform the...
Translating World Space into Tile Space
𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = (

𝑃𝑜𝑠

− 𝑀𝑎𝑝𝐶𝑒𝑛𝑡𝑒𝑟
+ 0.5) ∙ 𝑇𝑖𝑙𝑒𝑠
𝑀𝑎𝑝𝐷𝑖𝑚

𝑊𝑜𝑟𝑙𝑑

Step 3:
Normalize the...
Translating World Space into Tile Space
𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = (

𝑃𝑜𝑠

− 𝑀𝑎𝑝𝐶𝑒𝑛𝑡𝑒𝑟
+ 0.5) ∙ 𝑇𝑖𝑙𝑒𝑠
𝑀𝑎𝑝𝐷𝑖𝑚

𝑊𝑜𝑟𝑙𝑑

Step 3:
Normalize the...
Translating World Space into Tile Space
𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = (

𝑃𝑜𝑠

− 𝑀𝑎𝑝𝐶𝑒𝑛𝑡𝑒𝑟
+ 0.5) ∙ 𝑇𝑖𝑙𝑒𝑠
𝑀𝑎𝑝𝐷𝑖𝑚

𝑊𝑜𝑟𝑙𝑑

Step 4:
Translate the...
Translating World Space into Tile Space
𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = (

𝑃𝑜𝑠

− 𝑀𝑎𝑝𝐶𝑒𝑛𝑡𝑒𝑟
+ 0.5) ∙ 𝑇𝑖𝑙𝑒𝑠
𝑀𝑎𝑝𝐷𝑖𝑚

𝑊𝑜𝑟𝑙𝑑

Step 5:
Compute the p...
Applying Fog of War Logic
• iterate all units not belonging to the own team
– translate their position into tile space
– c...
Next Steps
• consider high ground
– discretize the z-axis, too, defining different height
levels
– units can only see tile...
Minimap

The minimap of StarCraft II.

• gives the player an
overview of the entire
map at a glance
• allows issuing order...
Minimap
• consists of three layers:
1. landscape layer
2. fog of war layer
3. unit layer

The minimap of StarCraft II.

• ...
Minimap: Landscape Layer
• orthogonal rendering of
the terrain without any
camera culling
• updated when the
terrain itsel...
Minimap: Fog of War Layer
• visibility mask is
rendered to an offscreen texture
• updated whenever the
visibility is updat...
Minimap: Unit Layer
• shows the positions and
owners of all visible
units and game objects
• updated whenever a
unit moves...
Minimap: View Frustum
• shows the player which part of the map he or
she is looking at
• can be drawn as follows:
– cast a...
Minimap Interaction
• requires converting the location on the
minimap to a location in world space
• can be used for…
– sc...
Bibliography
1. Carl Granberg. Programming an RTS Game
with Direct3D. Charles River Media, pages
265-307, 2007.
2. http://...
Thank you for your attention!

www.hostile-worlds.com
Upcoming SlideShare
Loading in …5
×

Developing a Multiplayer RTS with the Unreal Engine 3

3,652 views

Published on

Post-Mortem of Hostile Worlds, a real-time tactics game developed with the UDK, featuring unit selection & orders, weapons system, networking, minimap and fog of war.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
3,652
On SlideShare
0
From Embeds
0
Number of Embeds
12
Actions
Shares
0
Downloads
24
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Developing a Multiplayer RTS with the Unreal Engine 3

  1. 1. Developing a Multiplayer RTS with the Unreal Engine 3 Marcel Köhler, Nick Prühs Faculty of Design, Media and Information Hamburg University of Applied Sciences January 17, 2011
  2. 2. Outline 1. 2. 3. 4. 5. 6. 7. Unreal Engine Basics Controller & Pawn Camera Unit Selection & Orders Weapon Fire Network Minimap & Fog of War
  3. 3. Unreal Engine Basics • Core – C++ – Rendering, Sound, Gameloop, Collision, Physics, Threading, Low Level Network • Virtual Machine – Runs in Core – Executes Unreal Script
  4. 4. Unreal Engine Basics • Unreal Script – Similar to C++ and Java – High-level object-oriented language – Bytecode based (platform independent) – Pointerless environment with automatic garbage collection – Simple single-inheritance class graph – Strong compile-time type checking – Safe client-side execution "sandbox"
  5. 5. Controller & Pawn
  6. 6. Controller & Pawn
  7. 7. Controller & Pawn
  8. 8. Controller & Pawn
  9. 9. Controller & Pawn
  10. 10. Controller & Pawn
  11. 11. Unit Selection & Orders Short left click • < 15 ms • Single unit selection • Unit order Long left click • >= 15 ms • Multiple unit selection (selection box) on release
  12. 12. Weapon Fire
  13. 13. Weapon Fire
  14. 14. Weapon Fire
  15. 15. Weapon Fire
  16. 16. Weapon Fire
  17. 17. Weapon Fire
  18. 18. Weapon Fire
  19. 19. Weapon Fire
  20. 20. Weapon Fire
  21. 21. Weapon Fire
  22. 22. Weapon Fire
  23. 23. Weapon Fire
  24. 24. Network „Unreal views the general problem of coordinating a reasonable approximation of a shared reality between the server and clients as a problem of replication. That is, a problem of determining a set of data and commands that flow between the client and server in order to achieve that approximate shared reality. “ - Tim Sweeney, Epic Games Inc.
  25. 25. Network • Generalized Client-Server Model – Authoritative server (Dedicated, Listen) – Predicting and simulating clients – Decoupling of Network and Gamelogic facilitates extensibility • The Network code can coordinate any game which can be described by the language • Network is controlled on language level through keywords & variables • Low level network (Serialization, Reliable UDP) done by Core – “Hybrid” Code • Client and Server execute same code on approximately the same data -> minimizes traffic
  26. 26. Network - Basic Terminology • Actor – Object that can move and interact with other actors • Level – Object which contains a set of actors • Game State – The complete set of all actors that exist in a level – The current values of all actor variables
  27. 27. Network – Update Loop 1. if (server) Send(Gamestate) to all clients 2. if (client) Send(RequestedMovement) to server Receive(Gamestate) from server Render(ApproximateWorldView) to screen 3. if (server || client) Tick(DeltaTime) to update Gamestate Update(Actors) Execute(Physics) Receive(GameEvents) Execute(ScriptCode)
  28. 28. Actor Roles • Describes how much control the machine (server or client) has over an actor • Controls the actors function call permissions // Net variables. enum ENetRole { ROLE_None, ROLE_SimulatedProxy, ROLE_AutonomousProxy, ROLE_Authority, }; // // // // No role at all. Locally simulated proxy of this actor. Locally autonomous proxy of this actor. Authoritative control over the actor. var ENetRole RemoteRole, Role; Source: Actor.uc.
  29. 29. Bandwidth Optimization: Actor Relevancy • Eight prioritized rules • An actor is relevant, if… – Actor.RemoteRole != None – Actor.bAlwaysRelevant == true – Actor.Owner == Player – the Actor is visible according to a line-of-sight check between the actor's Location and the player's Location
  30. 30. Bandwidth Optimization: Actor Relevancy • Eight prioritized rules • An actor is relevant, if… – Actor.RemoteRole != None – Actor.bAlwaysRelevant == true – Actor.Owner == Player – the Actor is visible according to a line-of-sight check between the actor's Location and the player's Location
  31. 31. Bandwidth Optimization: Actor Relevancy • Eight prioritized rules • An actor is relevant, if… – Actor.RemoteRole != None – Actor.bAlwaysRelevant == true – Actor.Owner == Player – the Actor is visible according to a line-of-sight check between the actor's Location and the player's Location
  32. 32. Bandwidth Optimization: Prioritization • Actor.NetPriority – Regulates share of the bandwidth based on how important the Actor is to gameplay – Always relative to all other Actors NetPriority
  33. 33. Replication • Actor Replication – Only Location, Rotation valid on spawn • Variable Replication – – – – – Regulated by condition in Class Replication Statement Server to Client only Always reliable Subject to bandwidth optimization Keyword: repnotify replication { // replicate if server if (Role == ROLE_Authority && (bNetInitial || bNetDirty)) Armor, Range, AttackDamage; } Source: HWPawn.uc.
  34. 34. Where‘s Waldo? simulated event ReplicatedEvent(name VarName) { if (VarName == 'TeamIndex') { ChangeColor(TeamIndex); } } Source: HWSelectable.uc, before January 11, 2011.
  35. 35. Where‘s Waldo? simulated event ReplicatedEvent(name VarName) { if (VarName == 'TeamIndex') { ChangeColor(TeamIndex); } else { super.ReplicatedEvent(VarName); } } Source: HWSelectable.uc. Never forget super calls when overloading engine class functions!
  36. 36. Replication • Function Call Replication – Keywords: • server, client • reliable, unreliable – Server -> Client: only to client who owns that Actor – Client -> Server: only on owned Actor – Immediately sent, d1sregarding bandwidth reliable server function ServerIssueAbilityOrder(HWAIController C, HWAbility Ability, HWSelectable Target) Source: HWPlayerController.uc.
  37. 37. Fog of War • hides any enemy units that aren‘t within the sight radius of a friendly unit • needs to be computed efficiently Fog of War in StarCraft II.
  38. 38. Visibility Mask class HWVisibilityMask extends Object; /** The tiles the map consists of. */ var array<bool> MapTiles; /** The map this visibility mask is imposed on. */ var HWMapInfoActor Map; /** The team this visibility mask manages the vision of. */ var int Team; Source: HWVisibilityMask.uc. • is computed tile-based to reduce the perfomance impact • map needs to tell us its extents to translate world space into tile space • one mask per team
  39. 39. Visibility Mask class HWVisibilityMask extends Object; /** The tiles the map consists of. */ var array<bool> MapTiles; /** The map this visibility mask is imposed on. */ var HWMapInfoActor Map; /** The team this visibility mask manages the vision of. */ var int Team; Source: HWVisibilityMask.uc. • is computed tile-based to reduce the perfomance impact • map needs to tell us its extents to translate world space into tile space • one mask per team SrcHostileWorldsClassesHWVisibilityMask.uc(14) : Error, Bool arrays are not allowed Failure - 1 error(s), 0 warning(s)
  40. 40. Visibility Mask class HWVisibilityMask extends Object; /** The tiles the map consists of. */ var array<byte> MapTiles; /** The map this visibility mask is imposed on. */ var HWMapInfoActor Map; /** The team this visibility mask manages the vision of. */ var int Team; Source: HWVisibilityMask.uc. • is computed tile-based to reduce the perfomance impact • map needs to tell us its extents to translate world space into tile space • one mask per team
  41. 41. Updating the Visibility Mask /** Updates this visibility mask, re-computing the vision for the team this mask belongs to. */ simulated function Update() { local HWSelectable s; local IntPoint Tile; local array<IntPoint> Tiles; // reset visibility foreach Map.DynamicActors(class'HWSelectable', s) { if (s.TeamIndex == Team) { HideMapTiles(s); } } // compute new visibility foreach Map.DynamicActors(class'HWSelectable', s) { if (s.TeamIndex == Team) { Tile = Map.GetMapTileFromLocation(s.Location); Tiles = Map.GetListOfCircleTiles (Tile, s.SightRadiusTiles); RevealMapTiles(Tiles, s); } } } Source: HWVisibilityMask.uc 1. reset mask – no memset in Unreal: units remember the tiles they can see 2. compute new mask 1. iterate team‘s units 2. translate their positions into tile space 3. compute sight circle 4. reveal tiles
  42. 42. Updating the Visibility Mask • …is done less frequently than the frame-rate – whenever an own unit moves, spawns, dies or has its sight radius changed
  43. 43. Translating World Space into Tile Space 𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = ( 𝑃𝑜𝑠 − 𝑀𝑎𝑝𝐶𝑒𝑛𝑡𝑒𝑟 + 0.5) ∙ 𝑇𝑖𝑙𝑒𝑠 𝑀𝑎𝑝𝐷𝑖𝑚 𝑊𝑜𝑟𝑙𝑑
  44. 44. Translating World Space into Tile Space 𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = ( 𝑃𝑜𝑠 − 𝑀𝑎𝑝𝐶𝑒𝑛𝑡𝑒𝑟 + 0.5) ∙ 𝑇𝑖𝑙𝑒𝑠 𝑀𝑎𝑝𝐷𝑖𝑚 𝑊𝑜𝑟𝑙𝑑 Maybe we should take a closer look…
  45. 45. Translating World Space into Tile Space 𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = ( 𝑃𝑜𝑠 − 𝑀𝑎𝑝𝐶𝑒𝑛𝑡𝑒𝑟 + 0.5) ∙ 𝑇𝑖𝑙𝑒𝑠 𝑀𝑎𝑝𝐷𝑖𝑚 𝑊𝑜𝑟𝑙𝑑 • in – position of an object in world space – position of the map center in world space – width and height of the map, in UU – width and height of the map, in tiles • out – position of the object in tile space
  46. 46. Translating World Space into Tile Space 𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = ( 𝑃𝑜𝑠 − 𝑀𝑎𝑝𝐶𝑒𝑛𝑡𝑒𝑟 + 0.5) ∙ 𝑇𝑖𝑙𝑒𝑠 𝑀𝑎𝑝𝐷𝑖𝑚 𝑊𝑜𝑟𝑙𝑑 • in – position of an object in world space – position of the map center in world space – width and height of the map, in UU – width and height of the map, in tiles • out – position of the object in tile space
  47. 47. Translating World Space into Tile Space 𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = ( 𝑃𝑜𝑠 − 𝑀𝑎𝑝𝐶𝑒𝑛𝑡𝑒𝑟 + 0.5) ∙ 𝑇𝑖𝑙𝑒𝑠 𝑀𝑎𝑝𝐷𝑖𝑚 𝑊𝑜𝑟𝑙𝑑 • in – position of an object in world space – position of the map center in world space – width and height of the map, in UU – width and height of the map, in tiles • out – position of the object in tile space
  48. 48. Translating World Space into Tile Space 𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = ( 𝑃𝑜𝑠 − 𝑀𝑎𝑝𝐶𝑒𝑛𝑡𝑒𝑟 + 0.5) ∙ 𝑇𝑖𝑙𝑒𝑠 𝑀𝑎𝑝𝐷𝑖𝑚 𝑊𝑜𝑟𝑙𝑑 • in – position of an object in world space – position of the map center in world space – width and height of the map, in UU – width and height of the map, in tiles • out – position of the object in tile space
  49. 49. Translating World Space into Tile Space 𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = ( 𝑃𝑜𝑠 − 𝑀𝑎𝑝𝐶𝑒𝑛𝑡𝑒𝑟 + 0.5) ∙ 𝑇𝑖𝑙𝑒𝑠 𝑀𝑎𝑝𝐷𝑖𝑚 𝑊𝑜𝑟𝑙𝑑 • in – position of an object in world space – position of the map center in world space – width and height of the map, in UU – width and height of the map, in tiles • out – position of the object in tile space
  50. 50. Translating World Space into Tile Space 𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = ( 𝑃𝑜𝑠 Step 1: Compute the object‘s offset from the map center. − 𝑀𝑎𝑝𝐶𝑒𝑛𝑡𝑒𝑟 + 0.5) ∙ 𝑇𝑖𝑙𝑒𝑠 𝑀𝑎𝑝𝐷𝑖𝑚 𝑊𝑜𝑟𝑙𝑑
  51. 51. Translating World Space into Tile Space 𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = ( 𝑃𝑜𝑠 − 𝑀𝑎𝑝𝐶𝑒𝑛𝑡𝑒𝑟 + 0.5) ∙ 𝑇𝑖𝑙𝑒𝑠 𝑀𝑎𝑝𝐷𝑖𝑚 𝑊𝑜𝑟𝑙𝑑 Step 2: Transform the object‘s position into offset space.
  52. 52. Translating World Space into Tile Space 𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = ( 𝑃𝑜𝑠 − 𝑀𝑎𝑝𝐶𝑒𝑛𝑡𝑒𝑟 + 0.5) ∙ 𝑇𝑖𝑙𝑒𝑠 𝑀𝑎𝑝𝐷𝑖𝑚 𝑊𝑜𝑟𝑙𝑑 Step 3: Normalize the object‘s offset by dividing by the map dimension.
  53. 53. Translating World Space into Tile Space 𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = ( 𝑃𝑜𝑠 − 𝑀𝑎𝑝𝐶𝑒𝑛𝑡𝑒𝑟 + 0.5) ∙ 𝑇𝑖𝑙𝑒𝑠 𝑀𝑎𝑝𝐷𝑖𝑚 𝑊𝑜𝑟𝑙𝑑 Step 3: Normalize the object‘s offset by dividing by the map dimension.
  54. 54. Translating World Space into Tile Space 𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = ( 𝑃𝑜𝑠 − 𝑀𝑎𝑝𝐶𝑒𝑛𝑡𝑒𝑟 + 0.5) ∙ 𝑇𝑖𝑙𝑒𝑠 𝑀𝑎𝑝𝐷𝑖𝑚 𝑊𝑜𝑟𝑙𝑑 Step 4: Translate the coordinate system by moving the origin to the upper left corner of the map.
  55. 55. Translating World Space into Tile Space 𝑃𝑜𝑠 𝑇𝑖𝑙𝑒 = ( 𝑃𝑜𝑠 − 𝑀𝑎𝑝𝐶𝑒𝑛𝑡𝑒𝑟 + 0.5) ∙ 𝑇𝑖𝑙𝑒𝑠 𝑀𝑎𝑝𝐷𝑖𝑚 𝑊𝑜𝑟𝑙𝑑 Step 5: Compute the position in tile space by multiplying with the number of tiles, rounding down.
  56. 56. Applying Fog of War Logic • iterate all units not belonging to the own team – translate their position into tile space – check whether the tile is visible in the visibility mask • hide and deselect all enemy units that get hidden by fog of war • cancel all orders of the own team targeting these units • do server-side checks for all orders or abilities
  57. 57. Next Steps • consider high ground – discretize the z-axis, too, defining different height levels – units can only see tiles on their own height level or below • render fog of war in 3D space – render the visibility mask to an off-screen texture – use this texture as lightmap for everything in the game
  58. 58. Minimap The minimap of StarCraft II. • gives the player an overview of the entire map at a glance • allows issuing orders targeting locations outside the current view frustrum
  59. 59. Minimap • consists of three layers: 1. landscape layer 2. fog of war layer 3. unit layer The minimap of StarCraft II. • all are rendered to different textures that are blended together
  60. 60. Minimap: Landscape Layer • orthogonal rendering of the terrain without any camera culling • updated when the terrain itself changes only
  61. 61. Minimap: Fog of War Layer • visibility mask is rendered to an offscreen texture • updated whenever the visibility is updated
  62. 62. Minimap: Unit Layer • shows the positions and owners of all visible units and game objects • updated whenever a unit moves from one map tile to another
  63. 63. Minimap: View Frustum • shows the player which part of the map he or she is looking at • can be drawn as follows: – cast a ray from the eye of the camera to each of the frustum corners in the far plane – translate the point of their intersection with the terrain from world space to minimap space – draw lines between the four corners on the minimap
  64. 64. Minimap Interaction • requires converting the location on the minimap to a location in world space • can be used for… – scrolling: just set the camera focus to the world location – issuing orders
  65. 65. Bibliography 1. Carl Granberg. Programming an RTS Game with Direct3D. Charles River Media, pages 265-307, 2007. 2. http://udn.epicgames.com/Three/UDKProgra mmingHome.html 3. Unreal Development Kit (August 2010) Source Code
  66. 66. Thank you for your attention! www.hostile-worlds.com

×