Applets & Video GamesThe PlanAppletsDefinitionApplet vs. ApplicationRunning an AppletHTML for AppletJar filesDemoVideo GamesVideo Game as SimulationMeasurement UnitsDiscrete vs. Continuous TimeMonitor Frame RateModel Frame RateUser Interaction RateHow it happens “all at once”SummarySlide 19CompSci 46.1Applets & Video GamesApplets & Video GamesCompSci 46.2Applets & Video GamesThe PlanAppletsDemo on making and running a simple applet from scratchDemo on making and running a simple application from scratchVideo GamesMeasurements Frame ratesThreadsCompSci 46.3Applets & Video GamesAppletsDefinitionDifferences from applicationsDownload processUse of htmlUse of jar filesExampleCompSci 46.4Applets & Video GamesDefinitionFrom the Java 5.0 APIAn applet is a small program that is intended notto be run on its own, but rather to be embeddedinside another application.The name Applet is derived from the name Application.CompSci 46.5Applets & Video GamesApplet vs. ApplicationAppletsRun in web browserOften downloaded from untrusted siteRestricted from file system accessRestricted from outside network communicationApplicationsRun independentlyTypically obtained through trusted sourceAllow creation and modifications of filesAllow outside network communicationMust have a main methodCompSci 46.6Applets & Video GamesRunning an Applet1. Load a web page with an <applet> tag embedded in the HTML2. Load the compiled applet from website to local machine3. Run the compiled applet on the local machineCompSci 46.7Applets & Video GamesHTML for Applet<applet code=“pong/Pong.class” archive=“pong.jar” width=200 height=200></applet>code is the name of the class that extends JAppletarchive is the name of the jar file containing all classesCompSci 46.8Applets & Video GamesJar filesJar is short for Java ArchiveCompresses files and directories into a single fileCan be executed in compressed formatFiles and directories can be extractedCan contain any combination of source code, byte code, and other filesCompSci 46.9Applets & Video GamesDemoApplet DemoMake an applet in EclipseMake the html in composerSave both to network driveView from the webApplication DemoMake an application in EclipseRun in EclipseCompSci 46.10Applets & Video GamesVideo GamesSimulationMeasurement unitsDiscrete/ContinuousMonitor frame rate limitationModel frame rate limitationUser interaction rateThreads overviewCompSci 46.11Applets & Video GamesVideo Game as SimulationVideo 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.ExamplesFlight simulatorOregon trailPinballCompSci 46.12Applets & Video GamesMeasurement UnitsInitial setup in coordinate system with origin at top left and (1, 1) at bottom rightAllows simple scaling to varying screen resolutionsCan be done hierarchicallyDistances in pixelsTime in secondsVelocity in pixels/secondCompSci 46.13Applets & Video GamesDiscrete vs. Continuous TimeDiscreteUsed to approximate continuousSimple conceptually for good rough estimatesCauses problems when modeling continuous functions with too coarse grain estimatesContinuousRequires abstract representation or infinite precisionRequires analytical reasoningConceptually difficult to model directlyCompSci 46.14Applets & Video GamesMonitor Frame RateWhy 75-85 Hz (Frames/second)?Because we don’t actually visually process continuouslySmooth 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.CompSci 46.15Applets & Video GamesModel Frame RateModel 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 separate rates:Monitor frame rateModel frame rateCompSci 46.16Applets & Video GamesUser Interaction RateDevices such as the keyboard and mouse must also be polled at regular intervals.At what rate should they be polled?Depends on:Available compute powerIn contention with monitor frame rateIn contention with model frame rateWhich thread has priorityCompSci 46.17Applets & Video GamesHow it happens “all at once”Threads!Threads are like programs within programsSeem to run all at once, but typically share resources, primarily the processorCost overhead for switching the thread runningCompSci 46.18Applets & Video GamesSummaryUser interaction, model frame rate, and monitor frame rate all contend for the processor.Threads enable programs to behave as if several sub-programs (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.CompSci 46.19Applets & Video GamesSummaryApplets are like small applications run from a web browser.have security restrictions.require HTML code to be executedare downloaded from a remote site and executed locallyuse jar files to compress and combine all compiled code and supporting
View Full Document