460 likes | 535 Views
Lecture 10. Announcements. Next week doesn’t exist. Monday 19 th – Sunday 25 th Nothing is due There is no lecture There are no hours. cs195u – 3D Game Engines. requires cs123 lots of fun make Minecraft ! shop it!. Announcements. Questions?. Lecture 10. Embedded Scripting.
E N D
Lecture 10 Announcements
Next week doesn’t exist • Monday 19th – Sunday 25th • Nothing is due • There is no lecture • There are no hours
cs195u – 3D Game Engines • requires cs123 • lots of fun • make Minecraft! • shop it!
Announcements Questions?
Lecture 10 Embedded Scripting
Content Management • Designer can make content • Iterate without recompiling • Reload content at runtime • change MMO rules with no downtime
Representing Behavior • How to encode AI or map-specific gameplay? • could use Entity I/O • could use FSMs • Coulduse code to express behavior
Lots of choices • General-purpose • Python (Jython) • Javascript (Rhino) • Ruby (JRuby) • Designed for embedding • Lua • Designed for games • UnrealScript • roll your own
Jython • Create an interpreter • Convert Java objects into Python objects (marshaling) • can also be automatic using reflection • Run Python scripts PythonInterpreter py = newPythonInterpreter(); py.set(“x”, newPyInteger(42)); py.exec(“y = x / 6”); PyObject y = py.get(“y”); py.execfile(“myscript.py”);
Why use 2 languages? • One language would be simpler • no marshaling • Could just use Python • Could just use Java • already can dynamically load code • Core engine needs to be fast • collision detection • physics • rendering • Scripts need to be sandboxed • security • convenience
Complementary Features C++ Scripting language dynamically typed flexible interpreted slower at runtime protection from machine details no memory corruption • statically typed • maintainable • compiled • long build times • direct control of memory • good for CPU-intensive code
Lua • simple for beginners • almost everything is a (hash)table • first-class functions • light and efficient • relatively simple C integration players = { “Peter”, “Paul”, “Mary” } scores = { Mary = 10, Paul = 7, Peter = 8 } table.sort(players, function(i, j) return scores[i] > scores[j] end)
UnrealScript • used in the Unreal Engine (proprietary) • static types • networking concepts • replication • simulation • editor integration • function calls can last several frames • each Entity gets its own logical thread (not OS thread) • much easier than callbacks classFlashLightextendsSpotLightMovable; varFlashLightMyFlashLight; varrepnotifyboolbIsOn; simulatedfunction Toggle() { PlaySound(FlashLightSound); // ... } var() Color CaseColor; reliable server function Pulse() { Toggle(); sleep(0.5); Toggle(); }
YourOwnLanguage • Take cs173 • Implement Python • Learn about language design tradeoffs • Mostly ignores performance • Take a compilers course • Focus more on performance • Implement optimizations • Prof. Reiss has run cs126 in the past C++ Python Haskell Java
Embedded Scripting Questions?
Lecture 10 Procedural Content
Procedural Content WHY PROCEDURAL CONTENT?
What is procedural content? • Procedural content: game content generated in an algorithmic way rather than by a designer • Procedural content generation: the generation of this content via a semi-random process
Generated Content • Procedurally generated content usually implies content generated randomly • All procedural content need not be generated • Content inferred from manual designs • Common to save memory
Classifying Procedural Content • Online vs offline • Necessary vs optional • Random vs parameterized • Constructed vs verified
Why use procedural content? • Historically: memory restrictions required it • Generating by hand is tedious and/or expensive • In the case of procedurally generated content, provide a new experience with every game
Procedural Content Questions?
Procedural Content APPLICATIONS
Procedural Animation • Animating every pose of a character can be difficult • Generate poses by joints and constraints • Can even animate each portion separately
Dynamic Lightmaps • Lightmaps are used to store lighting information separate from textures • Provides significant graphical speedup • Rather than defining them for each object, generate them algorithmically
Natural Textures and Terrain • Perlin noise: generated visual effect that simulates natural texture • Even used in CGI for flames, smoke, clouds etc • Computed by calculating distance to grid vertices then interpolating
Level Generation • Create random level layouts at runtime • Can be used to make dungeons, interiors, cities, maps, etc • Algorithms are numerous and vary by purpose • Popular dungeon algorithm: subdivide dungeon in a binary tree, add a room to each
Design of Level Content • Generate many enemies or weapons with different attributes, then pick those that most satisfy the scenario • Alternatively, generate many levels then evaluate them via a fitness function • Underpins most sandbox games
Dynamic World Generation • Entire game world is generated on the fly • No part of the world is written to disk • Unneeded parts are immediately disposed • Hinges on deterministic generation and a single RNG seed • Used in EVE Online as well as a variety of older games
Instancing In-Game Entities • Each entity has some value randomized • All entities are similar, but have some distinguishing feature • Usually used to create names, faces, item or weapon properties
Dynamic Systems • Model complex behaviors with simple sets of rules • Used for weather, crowds, spreading fire, and other bottom-up effects • Starting to merge with some areas of AI, such as swarm intelligence
Plot and Puzzle Generation • Think of a game’s storyline as a dependency graph • Graph dependencies can be changed • For example, move a key to a random accessible location • Graph structure can be changed • Alters order of events • Can also use natural language processing to create characters and stories
Procedural Content Questions?
Lecture 10 Tips for Final 2
Tips for Final 2 EFFECTIVE PLAYTESTING
Finding Playtesters • CS students are easy targets, try the sun lab or MS lab • Ask nicely • Don’t ask busy people • Keep your audience in mind, however • It probably isn’t all CS students
Don’t Interrupt! • Be a fly on the wall • Say as little as possible • Don’t offer hints or instructions • Your game should speak for itself • You won’t be there to offer instructions when your game is released
When to Interrupt • Player is frustrated or taking too long in a single area • You’re no longer getting good feedback • If the player moves on, you will resume getting good feedback
Keep a Log • What is the player getting stuck on? • Make it smoother • What is the player enjoying? • Emphasize it • What is the player ignoring? • Take it out if it’s unnecessary • Consider having the game keep an automated log
Tips for Final 2 Questions?
Tips for Final 2 JAVA TIP OF THE WEEK
Default Visibility • You already know public, private, protected • What happens when there’s no visibility modifier? • Then the field/method is visible to anything in the same package
Some General Visibility Tips • Use private wherever possible • “Encapsulation” • If you have a large amount of protected methods you want truly protected, consider separating them into an interface
Tips for Final 2 Questions?
No Playtesting? Playtest with random people this week!