Lecture 1 Notes

Personal Introduction

Student Introduction

Course/Syllabus Introduction

Q & A

A Theory Of Fun

What are games?

What makes games fun?

What are your favorite games? (make a list)

What games would you like to write? (make a list)

 

 

Why Java?

Why Java - Is Java the right tool for game development?

Chapter 1 - P 1-12

Animation Loop

Chapter 2 - P 13-45

An animation framework

GamePanel (Update, Render, Sleep) thread

while (running) { gameUpdate(); gameRender(); repaint(); sleep(20); }

Double Buffering - Offscreen image vs. Hardware frame buffer

Timers

Chapter 2 P21-31

Timer Resolution in ms or ns and FPS

100FPS = 1000ms/100FPS = 10ms per update or sleep cycle
30FPS = 1000ms/30 = 33.33ms per update or sleep cycle

fractions of a second
Abbv Name Convert To Seconds Convert From Seconds
s second 1.0 1
cs centisecond (hundredth) 0.01 100
ms millisecond (thousandth) 0,001 1 000
µs microsecond (millionth) 0,000 001 1 000 000
ns nanosecond (billionth) 0,000 000 001 1 000 000 000
ps picosecond (trillionth) 0,000 000 000 001 1 000 000 000 000
fs femtosecond 0,000 000 000 000 001 1 000 000 000 000 000
as attosecond 0,000 000 000 000 000 001 1 000 000 000 000 000 000
zs zeptosecond 0,000 000 000 000 000 000 001 1 000 000 000 000 000 000 000
ys yoctosecond 0,000 000 000 000 000 000 000 001
1 000 000 000 000 000 000 000 000

 

long count = System.currentTimeMillis();
count = J3DTimer.getValue();
Perf perf = Perf.getPerf();
count = perf.highResCounter();
count = System.nanoTime();


c:\gamedev\book\timings
TimerRes.java
Win XP
Java 3D Timer Resolution: 279 nsecs
System Time resolution: 15500 microsecs = (15.5ms)
Perf resolution: 1257 nsecs; Perf Time: 10476 nsecs

 

Perf is an undocumented class 1.4.2+ (sun.misc.Perf)

System.nanoTime() requires JDK 1.5 use at own risk.

Sleep Accuracy

Chapter 2 p31-41

SleepAcc.java

-- Wood's Laptop
Slept: 1000 ms J3D: 999.59 ms err: 0.04 %
Slept: 500 ms J3D: 500.2 ms err: -0.04 %
Slept: 200 ms J3D: 200.36 ms err: -0.18 %
Slept: 100 ms J3D: 99.71 ms err: 0.29 %
Slept: 50 ms J3D: 49.6 ms err: 0.8 %
Slept: 20 ms J3D: 19.55 ms err: 2.28 %
Slept: 10 ms J3D: 9.55 ms err: 4.73 %
Slept: 5 ms J3D: 4.65 ms err: 7.42 %
Slept: 1 ms J3D: 0.69 ms err: 44.28 %

Questions to ask: Why isn't it exact? Is this a problem?

p33 solution.

sleepTime = (period - timeDiff) - overSleepTime; if (sleepTime>0) { Thread.sleep(sleepTime/1000000L); // nano->ms overSleepTime = (J3DTimer.getValue() - afterTime) - sleepTime; } else // sleepTime<=0; frame took longer than the period { overSleepTime = 0L noDelays++; if (noDelays>=NO_DELAYS_PER_YIELD) { Thread.yield(); noDelays = 0; } }

p34 - UPS - updates per second - could do multiple world updates per cycle

p35-36 - extra updates when redering gets behind

p40 - FPS calculator

java UtilTimerTest

~83 FPS

java SwingTimerTest

~50 FPS

Worms

P46 - Chapter 2.

book\worm\readmeForCh3.txt

c:\gamedev\book\work

/WormP a windowed application version of the WormChase game
using the Java 3D timer to drive the animation

/WormPMillis a windowed application version of the WormChase game
using System.currentTimeMillis() to drive the animation

/WormApplet an applet version of the WormChase game
using the Java 3D timer to drive the animation

javac *.java
java WormChase <FPS>

Take K16.java as a template from Worms. Convert it to an animation. Is a game an animation? Is animation required to make a game?

CPSC370 - Games Development
Chapman University
Instructor: W. Wood Harter
(c) copyright 2006 - W. Wood Harter - All Rights Reserved
Screen shots on banner (c) copyright their resprective owners