Presentation is loading. Please wait.

Presentation is loading. Please wait.

Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is.

Similar presentations


Presentation on theme: "Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is."— Presentation transcript:

1 Levels and Scripts

2 Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is a function that converts a character stream (i.e. the source file) into tokens (i.e. keywords, operators, etc.) A parser, which takes the token stream and builds a syntax tree from it. A semantic checker, which checks the syntax tree for semantic errors An intermediate code generator, which converts the syntax tree into intermediate code An optimizer (optional) which optimizes the intermediate code A code generator, which generates bytecode from the intermediate code Last but not least, the virtual machine on which the bytecode is to be executed.

3 http://www.flipcode.com/archives/Implementing_A_Scripting_Engine-Part_1_Overview.shtml

4 4 Layered Avatar Behavior Model and Script Overall structure Task-Level Behavior Script Task-Level Behavior Script Avatar-Object Interaction Model Avatar-Object Interaction Model High-level Motion Script High-level Motion Script Primitive Motion Script Primitive Motion Script 1 st Translator (Task-to-High) 1 st Translator (Task-to-High) Geometric Information Geometric Information 2 nd Translator (High-to-Primitive) 2 nd Translator (High-to-Primitive) Primitive Motion Script Primitive Motion Script Avatar Low-level Animation Data Avatar Low-level Animation Data Object Low-level Animation Data Object Low-level Animation Data Avatar Low-level Animation Data Avatar Low-level Animation Data Object Low-level Animation Data Object Low-level Animation Data Application Context Menu Interface (Display) Context Menu Interface (Display) User Domain Interface Layer Motion Sequence Layer Recording Translating Application Layer

5 5 Avatar-Object Interaction Model(1/2) Basic Object Structure – Proposed model has multiple objects below the ObjectList element – An object is composed of three elements Context : object state, access privilege, controlpoint and domain type ExecutableBehaviors : all executable behaviors for user interface menu MotionList : motion sequence to complete a behavior Executable Behaviors Object+ ObjectList ContextMotionList Basic XML DTD sturcture

6 Avatar-Object Interaction Model(2/2) 6 Avatar-Object Interaction Model Context Executable Behaviors MotionList Domain AcessGroup ControlPoint State User Behaviors Selection Task Planning Selectable Behaviors Behaviors List Motion List Select a Behavior Generating Motions …

7 7 Context Element(1/5) State Element – Describes internal object states by pair of variable and value attributes – Variable has affective motion and current state methods Affective motion defines post-state value, and corresponding motion which changes the state Current state function is defined in XSLT script that processes state element to make boolean result output of current state value – Behavior menu and motion sequence are decided according to changes of state variables value

8 8 Affective Motion Post State closed State Functions IsClosed Variable : DoorState Event Motion Result State V V VV V Door Object InteractionState Changes IF – (1) Event Motion = Affective Motion – (2) State Function = TRUE THEN – (1) Make up of Variable list which satisfy conditions – (2) Set each variable Value to Post_State – (3) Output boolean result by State Function Value closed Motion Name close ‘close’ ‘True’ Context Element(2/5)

9 9 Context Element(3/5) ControlPoint Element – Spatial reference points around a object where avatar stands and interact with it – Depending on the behaviors and object states, a object may have various points – A point is consisted of position, direction and contact elements – The elements has coarse references to represent spatial location at high-level Human readable Independent from physical geometric object models – Used for behavior sub-tasking and motion sequencing

10 10 Context Element(4/5) – Position Relative 5 basic and 4 composed positions for each objects Standard axis is –z for front on zy-plane – Direction Object relative 4 basic and composed directions to determine avatar’s orientation Rotation axis is y and zero degree for forward direction – Contact designate a specific part of the object when the avatar makes contact with the object The corners of the bounding box of 3D objects and the center point of the surface ElementReference Values Position Front, Behind, Left, Right, Center Left&Front, Right&Front, Left&Behind, Right&Behind Direction Backward, Forward, Left, Right Left&Forward, Right&forward, Left&Backward, Right&backward Contact Front, Behind, Left, Right, Top, Bottom, Center Left&Front&Center, Left&Front&Top, Left&Front&Bottom, Right&Front&Center …. Position Direction x z y Contact

11 11 Access Group Element – Object behavior can be accessed by several user types – Each user type has different purpose and usage – Each group has different access to behavior interface DomainType Element – Not only internal state of object, but also external domain state can effect behavior interaction. – The same object can behave as a different semantic object e.g. A car object in traffic simulation domain and assembly training domain – DomainType element defines name of domain for checking current domain type. Context Element(5/5)

12 12 Layered Script Language Overall structure Task-Level Behavior Script Task-Level Behavior Script Avatar-Object Interaction Model Avatar-Object Interaction Model High-level Motion Script High-level Motion Script Primitive Motion Script Primitive Motion Script 1 st Translator (Task-to-High) 1 st Translator (Task-to-High) Geometric Information Geometric Information 2 nd Translator (High-to-Primitive) 2 nd Translator (High-to-Primitive) Primitive Motion Script Primitive Motion Script Avatar Low-level Animation Data Avatar Low-level Animation Data Object Low-level Animation Data Object Low-level Animation Data Avatar Low-level Animation Data Avatar Low-level Animation Data Object Low-level Animation Data Object Low-level Animation Data Application Context Menu Interface (Display) Context Menu Interface (Display) User Domain Interface Layer Motion Sequence Layer Recording Translating Application Layer

13 13 Task-level Behavior Script(1/2) Task-level Behavior Script – Presents object and avatar behaviors using XML DTD – Records and saves user action in temporal sequence – Extensible representation for behavior set Objects in a domain makeup the usable behavior set Cf) existing script which has pre-defined behavior DTD – Independent from rendering environments Doesn’t present appearance of avatar model, positional information of virtual objects, so on.

14 14 Task-level Behavior Script(2/2) Definition of Task-level Avatar-Object Behavior Script – Template-based Avatar-Object Behavior Representation Domain behavior set is flexibly defined by object instances Task-level Behavior = (Object, Executable-Behavior, Narration) Object Behavior Narration Task-level Behavior Script = DoorEnter Text Highlight Computer Prev.page Screen Point Computer Next page Hello I’m... Domain Object Pool User Selection User Text Typing

15 15 High-level Motion Script(1/2) High-level Motion Script – Bridges between task-level script and primitive motion script – Independent from both interface domain and application domain – Parameterized motion support Synchronization, speed, target, repeat, intensity, decay, etc Abstract values rather than physical

16 16 High-level Motion Script(2/2) Structure of high-level script DTD

17 Primitive Motion Script Primitive motion – Supported by rendering engine or motion library – Represented in physical parameter values ex) Geometric values such as coordinates of avatar and objects, radian value of avatar direction, etc – Parameters are transmitted to animation engine to play animation scenario on screen

18 18 Task-level Behavior Script Translator – Translates task-level behavior script into high-level motion script – Consisted of motion sequences to perform task-level behaviors Motion planning by task planner and generate the sequences ex) 1. 2. 3. – Uses logical application domain knowledge – According to formal translation model, script of each domains is converted to a high-level motion script Script Translators(1/4)

19 19 Script Translators(2/4) Formal Task Translation Model – Identification of target find location of target object(L o ) – Locomotive motion (M l ) identification of present avatar location (L a ) spatial distance between L a and L o generate L m, if L a ≠ L o – Manipulative motion (M m ) generate M m for L o – Verbal information (V i ) generate verbal speech for avatar behavior if available Speed and intensity parameters parameterize M m and M l for speed, intensity and duration

20 20 Script Translators(3/4) – Procedure modules Spatial Information Generator Spatial Information Generator Temporal Information Generator Temporal Information Generator Locomotion Generator Locomotion Generator Intensity Controller Intensity Controller Task-level Behavior Task-level Script Translator Ex) task-level behavior script Let's do it next time! High-level Motion Ex) Generated high-level motion students normal default normal default normal Let's do it next time!

21 21 High-level Motion Script Translator – Major module : Object geometric information analyzer Calculates location, size, and direction of virtual objects Current status of avatar position and posture – Translates abstract parameters of high-level script to physical values Script Translators(4/4) Object Geometry Analyzer Object Geometry Analyzer Virtual Space Object Geometry High-level Motion Script High-level Motion Trasnlator High-level Motion Trasnlator Primitive Motion Script -143 15 1 40 this is …

22 22 System Implementation(1/2) Creating a scenario script

23 23 System Implementation(2/2) Running a scenario script in different environments – Different physical properties of virtual objects – Applying same task-level script to other applications OpenGL Application 2D Web Application(MSAgent)

24 Script Compiler print "Please enter your name > "; input name; if (name == "Jan") { // string comparison name = "my creator"; // string assignment happy = "yes"; } print "Thank you, " + name + "!\n" + // string concatenation "You've just made a simple program very happy!"; "if" {return IF;} "=" {return ASSIGN;} ";" {return END_STMT;} {IDENT} {Identifier (); /* identifier: copy name */ return ID;} {STR} {StringConstant (); /* string constant: copy contents */ return STRING;} "//" {EatComment();} /* comment: skip */ \n {lineno++;} /* newline: count lines */ {WSPACE} {} /* whitespace: (do nothing) */. {return ERROR_TOKEN;} /* other char: error, illegal token */

25 Challenge: Design Levels 60 levels = 6 groups of 10 Easy to hard within a group Each group features different devices 60 levels, structured as 6 ramps of 10 puzzles each. Puzzles within a ramp start easy and get harder. Each ramp has a different visual theme and emphasizes a different mix of features, to keep the game from getting too repetitive.

26 Building Levels Tell a Story Paint a Picture Create a Mood Use Math Exploit features Lay a Trap

27 Building Levels: Tell a Story #17 Run Like Crazy Some puzzles are structured as a linear sequence of events. For this puzzle started by drawing a board that wraps a long narrow corridor into a small space.

28 Building Levels: Tell a Story #17 Run Like Crazy This puzzle features an autodetonator, shown in red here, which blows up automatically in a preset amount of time unless you touch it to reset it. The basic drama of this puzzle is that you must run to the autodetonator, then push it back a long way so it blows up a bomb.

29 Building Levels: Tell a Story #17 Run Like Crazy I then compounded the puzzle by adding obstacles along the three legs of the journey. Moving spikes that raise and lower out of the game cause you to have to wait a bit before you can get to the autodetonator -- frustrating when you have to get there quickly.

30 Building Levels: Tell a Story #17 Run Like Crazy Next you must push the autodetonator onto a moving platform that travels slowly to the right, then push it off. Again, timing is critical if you are to execute this move before the autodetonator blows up.

31 Building Levels: Tell a Story #17 Run Like Crazy I added one more spike in the right leg of the journey..

32 Building Levels: Tell a Story #17 Run Like Crazy Finally there is the end game. One bombs only blow up themselves, so the ending position must be an autodetonator surrounded by one bombs. Because two of the 1 bombs are against walls they cannot be pushed away from, there is only one possible ending position.

33 Building Levels: Paint a Picture #48 Ice Rink. Initial pattern. Another way to invent a puzzle is to start with a pretty pattern, then try playing it. Here are three opening positions I considered for the puzzle Ice Rink. They look similar, but behave very differently. You cannot stop moving on ice until you hit a wall or reach solid ground.

34 Building Levels: Paint a Picture #49 Diamond. Initial pattern. Here are three patterns I considered for a puzzle called Diamond, which features a patch of ice surrounded by solid ground. After drawing the opening patterns I played them to see if they could be solved. If they were not solvable, I then had to decide how to modify the pattern.

35 Building Levels: Paint a Picture #60 The… Final pattern. For the final puzzle I decided to aim for a pretty final position that would spell the word “End”. This is what I originally hoped for..

36 Building Levels: Paint a Picture #60 The… Initial pattern. The actual final puzzle required many modifications to the boards and pieces to make sure that the puzzle only had one solution. Shown here is the final beginning position.

37 Building Levels: Paint a Picture #57 Pinball. Overall picture. One of the features of Charlie Blast is bumpers, which rebound bombs pushed into them. Bumpers reminded me of pinball bumpers, so I built this puzzle to look like a pinball machine, complete with a moving beltway for returning a queue of balls into play.

38 Building Levels: Create a Mood #16 Long Haul Some puzzles create distinct moods. Long haul, for instance, creates a frantic suspenseful mood as you must run further and further away from an autodetonator with a very short fuse in order to reposition bombs that are further and further away.

39 Building Levels: Create a Mood #16 Long Haul It is easy to see that the autodetonator and 1 bomb cannot move, so the solution must be to create a chain of 3 bombs reaching from one end to the other.

40 Building Levels: Create a Mood #16 Long Haul Or is it really that easy? A bit of analysis will show that the previous solution cannot be achieved, so a modified chain like this is necessary.

41 Building Levels: Use Math #39 Peninsula Puzzle designers often mine mathematics for ideas. Shown above is a puzzle based on the mathematical idea of a tour. The goal is to draw a closed path that visits every square once, using all the red lines. The unique solution is shown at right.

42 Building Levels: Use Math #39 Peninsula I decided to make a puzzle for Charlie Blast that used the idea of a tour. Suppose the tiles above are all breakaway tiles, which means you can only step on them once. How would you push all three one bombs off the bottom edge of the square? One solution is shown at right.

43 Building Levels: Use Math #39 Peninsula After a bit of work I came up with this more difficult tour puzzle. The goal is to push all three 1 bombs off the bottom edge of the square by walking a single path. The unique solution requires that you visit every square exactly once.

44 Building Levels: Use Math #39 Peninsula Here’s the final puzzle. The purple electric bombs act like 2 bombs, except if one electric bomb blows up, the other also blows up. Since the electric bomb along the bottom edge cannot be pushed up toward the 1 bombs, the three 1 bombs must be pushed down to surround it.

45 Building Levels: Exploit Features #30 Moving Ground Another strategy is to exploit a feature. Shown above are two states of the same board, built entirely of moving platforms. The tall rectangles move left and right, while the wide rectangles move up and down. The green arrows show how the 2 bomb could be pushed.

46 Building Levels: Exploit Features #30 Moving Ground Here is the final puzzle. The ground at the bottom is stable, while the ground at the top is moving. The goal is clear: build a chain of bombs between the immovable detonator at left and 1 bomb at right. But getting there requires a hair-raising ride around the platforms.

47 Building Levels: Exploit Features #30 Moving Ground This puzzle is easier to analyze if we collapse time and push all the platforms together so all adjacencies are present at the once. The green arrows show all paths that bombs can follow as they move around the platforms. Removing the dead ends, we discover the loop at right.

48 Building Levels: Lay a Trap #58 Tadpole Finally, puzzles can trick you into pursuing the wrong line of reasoning. For the puzzle Tadpole, I started by observing that a puzzle involving a 2 bomb, detonator and six 1 bombs must end with the 2 bomb and detonator surrounded by the 1 bombs.

49 Building Levels: Lay a Trap #58 Tadpole With that analysis in mind, this puzzle appears to be simple: push the autodetonator into the pocket, seal the opening with a 1 bomb, then sit back and watch the fireworks.

50 Building Levels: Lay a Trap #58 Tadpole By adding a couple of spikes I gave the puzzle a new wrinkle.

51 Building Levels: Lay a Trap #58 Tadpole Now you can only push the autodetonator as far as shown above by the green line. You cannot push the autodetonator any further because the spikes prevent you from getting to the square to the right of the final position of the autodetonator.

52 Building Levels: Lay a Trap #58 Tadpole The real solution requires that you rebuild the entire hexagonal pattern of 1 bombs up and to the right one square.

53 Building Levels: Lay a Trap #58 Tadpole To complete the puzzle, I added some blocks and breakaway tiles.. These complications add difficulty to the puzzle, but are not integral to the central theme of the puzzle.

54 What is a tile (generally speaking)? A building block of a game board Piece together tiles to create a world Why use tiles? – to conserve memory – graphics reuse – dynamic content

55 Are there any other background alternatives? Large background images – can provide rich, full detail Combination of large images and tiling

56 A memory comparison Ex: Warcraft III map (assume 32-bit color, 4 byte/pixel) – 6,400 pixels x 6,400 pixels – Option 1: Large Background Image (no tiles) Memory requirements: a single image – 6,400 x 6,400 x 4 bytes/pixel = 163,840,000 bytes – Option 2: 100 tile set each tile: 64 pixels x 64 pixels = 4,096 pixels per tile map layout: 100 tiles x 100 tiles = 10,000 tiles Memory requirements – a tile engine to store the 100 tiles » 100 tiles x 4,096 pixels/tile x 4 bytes/pixel = 1,638,400 bytes – An array to specify where tiles are to be placed » 10,000 tiles x 1 byte per tile = 10,000 bytes – Total memory usage = 1,638,300 + 10,000 bytes = 1,648,300 bytes

57 Why else is graphics reuse important? Because artist time is expensive Level designers can layout a map

58 How can tiles be dynamic? Random map generator – adds to game re-playability – a different game each time you play it

59 Identify tiles needed Terrain – grass, dirt, sand, snow, water, mountains, etc. Walls Roads Buildings etc. And don’t forget terrain borders?

60 Layout Level Map Generate a map file to describe layout What format? Many used – tools like MapMaker just for this purposeMapMaker Criteria for format: – easy to edit by a non-programmer (i.e. level designer) – easy to read in and use by game program One option: use a CSV file. What’s CSV? – comma separated value How? – denote a tile number or tile string in each cell Alternative: create a level design program – a GUI to graphically pick & place tiles

61 Map Editing Example (3x5 world) Map drawn using a 10 piece tile set – T refers to top, B refers to bottom – L refers to left, R refers to left – Ex: TSHORE refers to top shore – Ex: BRSHORE refers to bottom right shore

62 What is a tile (practically speaking)? An image Can be created by Paint, Photoshop, etc. Decide on tile size, which depends on: – size of map – memory restrictions Common to use powers of 2: – 2 6 = 32 – 2 7 = 64 – 2 8 = 128 Danger: a map with many different large tiles

63 What are Textures? Used for tiling games elements – backgrounds, sprites, and 3D models DirectX has a class for storing textures: – LPDIRECT3DTEXTURE9 Provides fast access to image data Common file types: –.tga,.dds – image files can be converted by Texture Tool

64 Image vs. Texture Files What’s the advantage to keeping tiles in image files? – artists can tweak images – good during game development stage What’s the advantage to converting tiles from image files to texture files (.tga or.dds)? – speed of execution (loading levels) – good after game has been deployed

65 Color Key Color to represent transparency – when a tile or sprite is drawn, pixels with the color key are ignored – Why? because those pixels should not be drawn Specify this precise shade of blue as color key when: reading file drawing object

66 Multi-layering Tiles Most worlds require layering. Ex: – place grass – place flowers on grass – place cloud over flowers Other common objects: – trees – rocks – treasure To edit: – use multiple CSV files, one for each layer – map file may join & order CSV files

67 How should we manage our layers? Different types of layers: – TiledLayer – SparseLayer – IsometricLayer (we’ll see this later this semester) We can layer them on top of one another, ex: – TiledLayer first, then SparseLayer

68 TiledLayer Background is wall-to-wall tiles Images loaded into texture manager Each image gets an id, layout using ids Ex: 0,1,2,3,0,0,1,2 etc.

69 Implementing TiledLayer A 2D grid of Tiles class TiledLayer: public WorldLayer { protected: vector *tileLayout; int columns; int rows; int tileWidth; int tileHeight; int layerWidth; int layerHeight; int z; struct Tile { int textureID; bool collidable; };

70 Rendering via render list Again, only render that which is visible More on this when we talk about scrolling

71 SparseLayer Tiles (overlay images) here and there Spaces in between Tiles of various sizes

72 Implementing SparseLayer struct OverlayImage { int imageID;// INDEX OF IMAGE IN TEXTURE MANAGER int x;// X LOCATION int y;// Y LOCATION int z;// Z LAYER int alpha;// TRANSPARENCY int width;// TEXTURE WIDTH TO USE int height;// TEXTURE HEIGHT TO USE }; class SparseLayer : public WorldLayer { private: vector *sparseTiles; …

73 So how do we render our world? Depends on what we are viewing – game world scrolls Each frame: – add visible tiles to level render list – render contents or render list like any other texture


Download ppt "Levels and Scripts. Script Engine A symbol table, which contains all the symbols and information about type, scope, etc. A lexical analyzer, which is."

Similar presentations


Ads by Google