Applets Video Games Comp Sci 4 Applets Video

  • Slides: 19
Download presentation
Applets & Video Games Comp. Sci 4 Applets & Video Games 6. 1

Applets & Video Games Comp. Sci 4 Applets & Video Games 6. 1

The Plan v Applets q q v Demo on making and running a simple

The Plan v Applets q q v Demo on making and running a simple applet from scratch Demo on making and running a simple application from scratch Video Games q q q Comp. Sci 4 Measurements Frame rates Threads Applets & Video Games 6. 2

Applets v v v Definition Differences from applications Download process Use of html Use

Applets v v v Definition Differences from applications Download process Use of html Use of jar files Example Comp. Sci 4 Applets & Video Games 6. 3

Definition From the Java 5. 0 API An applet is a small program that

Definition From the Java 5. 0 API An applet is a small program that is intended not to be run on its own, but rather to be embedded inside another application. The name Applet is derived from the name Application. Comp. Sci 4 Applets & Video Games 6. 4

Applet vs. Application Applets v Run in web browser v Often downloaded from untrusted

Applet vs. Application Applets v Run in web browser v Often downloaded from untrusted site v Restricted from file system access v Restricted from outside network communication Comp. Sci 4 Applications v Run independently v Typically obtained through trusted source v Allow creation and modifications of files v Allow outside network communication v Must have a main method Applets & Video Games 6. 5

Running an Applet 1. 2. 3. Load a web page with an <applet> tag

Running an Applet 1. 2. 3. Load a web page with an <applet> tag embedded in the HTML Load the compiled applet from website to local machine Run the compiled applet on the local machine Comp. Sci 4 Applets & Video Games 6. 6

HTML for Applet <applet code=“pong/Pong. class” archive=“pong. jar” width=200 height=200></applet> v v code is

HTML for Applet <applet code=“pong/Pong. class” archive=“pong. jar” width=200 height=200></applet> v v code is the name of the class that extends JApplet archive is the name of the jar file containing all classes Comp. Sci 4 Applets & Video Games 6. 7

Jar files Jar is short for Java Archive v Compresses files and directories into

Jar files Jar is short for Java Archive v Compresses files and directories into a single file v Can be executed in compressed format v Files and directories can be extracted v Can contain any combination of source code, byte code, and other files Comp. Sci 4 Applets & Video Games 6. 8

Demo Applet Demo v Make an applet in Eclipse v Make the html in

Demo Applet Demo v Make an applet in Eclipse v Make the html in composer v Save both to network drive v View from the web Application Demo v Make an application in Eclipse v Run in Eclipse Comp. Sci 4 Applets & Video Games 6. 9

Video Games v v v v Simulation Measurement units Discrete/Continuous Monitor frame rate limitation

Video Games v v v v Simulation Measurement units Discrete/Continuous Monitor frame rate limitation Model frame rate limitation User interaction rate Threads overview Comp. Sci 4 Applets & Video Games 6. 10

Video Game as Simulation Video games are simulations of the real world and worlds

Video Game as Simulation Video games are simulations of the real world and worlds that do not exist. These simulations are built for our pleasure, but may serve other purposes as well. Examples v Flight simulator v Oregon trail v Pinball Comp. Sci 4 Applets & Video Games 6. 11

Measurement Units v Initial setup in coordinate system with origin at top left and

Measurement Units v Initial setup in coordinate system with origin at top left and (1, 1) at bottom right q q v v v Allows simple scaling to varying screen resolutions Can be done hierarchically Distances in pixels Time in seconds Velocity in pixels/second Comp. Sci 4 Applets & Video Games 6. 12

Discrete vs. Continuous Time Discrete v Used to approximate continuous v Simple conceptually for

Discrete vs. Continuous Time Discrete v Used to approximate continuous v Simple conceptually for good rough estimates v Causes problems when modeling continuous functions with too coarse grain estimates Comp. Sci 4 Continuous v Requires abstract representation or infinite precision v Requires analytical reasoning v Conceptually difficult to model directly Applets & Video Games 6. 13

Monitor Frame Rate Why 75 -85 Hz (Frames/second)? Because we don’t actually visually process

Monitor Frame Rate Why 75 -85 Hz (Frames/second)? Because we don’t actually visually process continuously Smooth fast movement? Consider a rate of 1 pixel a second would take more than 8 seconds to move across the screen. For fast movement there must be jumps in location. Comp. Sci 4 Applets & Video Games 6. 14

Model Frame Rate Model is continuous. Frame rate is discrete. The granularity of frame

Model Frame Rate Model is continuous. Frame rate is discrete. The granularity of frame rate is too coarse for our continuous model. How do we solve this problem? Two separates: q q Comp. Sci 4 Monitor frame rate Model frame rate Applets & Video Games 6. 15

User Interaction Rate Devices such as the keyboard and mouse must also be polled

User Interaction Rate Devices such as the keyboard and mouse must also be polled at regular intervals. At what rate should they be polled? Depends on: v Available compute power q q v In contention with monitor frame rate In contention with model frame rate Which thread has priority Comp. Sci 4 Applets & Video Games 6. 16

How it happens “all at once” Threads! v v v Threads are like programs

How it happens “all at once” Threads! v v v Threads are like programs within programs Seem to run all at once, but typically share resources, primarily the processor Cost overhead for switching the thread running Comp. Sci 4 Applets & Video Games 6. 17

Summary v v v User interaction, model frame rate, and monitor frame rate all

Summary v v v User interaction, model frame rate, and monitor frame rate all contend for the processor. Threads enable programs to behave as if several subprograms (threads) were running at once. Continuous events can be modeled discretely. Careful selection of measurement units can simplify program modifications. Video games can be viewed as simulations. Comp. Sci 4 Applets & Video Games 6. 18

Summary Applets v are like small applications run from a web browser. v have

Summary Applets v are like small applications run from a web browser. v have security restrictions. v require HTML code to be executed v are downloaded from a remote site and executed locally v use jar files to compress and combine all compiled code and supporting files Comp. Sci 4 Applets & Video Games 6. 19