Skip to content

Commit

Permalink
Version 1.0.3: Protects against calling Spritely methods within
Browse files Browse the repository at this point in the history
a keyboard or mouse handler, or from a different thread.
  • Loading branch information
wffoote committed Oct 7, 2018
1 parent 87abe66 commit d2270a9
Show file tree
Hide file tree
Showing 28 changed files with 70 additions and 54 deletions.
4 changes: 2 additions & 2 deletions docs/javadocs/allclasses-frame.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_181) on Sat Oct 06 14:53:23 PDT 2018 -->
<!-- Generated by javadoc (1.8.0_162) on Sun Oct 07 16:48:32 PDT 2018 -->
<title>All Classes</title>
<meta name="date" content="2018-10-06">
<meta name="date" content="2018-10-07">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
Expand Down
4 changes: 2 additions & 2 deletions docs/javadocs/allclasses-noframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_181) on Sat Oct 06 14:53:23 PDT 2018 -->
<!-- Generated by javadoc (1.8.0_162) on Sun Oct 07 16:48:32 PDT 2018 -->
<title>All Classes</title>
<meta name="date" content="2018-10-06">
<meta name="date" content="2018-10-07">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
Expand Down
4 changes: 2 additions & 2 deletions docs/javadocs/constant-values.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_181) on Sat Oct 06 14:53:23 PDT 2018 -->
<!-- Generated by javadoc (1.8.0_162) on Sun Oct 07 16:48:32 PDT 2018 -->
<title>Constant Field Values</title>
<meta name="date" content="2018-10-06">
<meta name="date" content="2018-10-07">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
Expand Down
4 changes: 2 additions & 2 deletions docs/javadocs/deprecated-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_181) on Sat Oct 06 14:53:23 PDT 2018 -->
<!-- Generated by javadoc (1.8.0_162) on Sun Oct 07 16:48:32 PDT 2018 -->
<title>Deprecated List</title>
<meta name="date" content="2018-10-06">
<meta name="date" content="2018-10-07">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
Expand Down
4 changes: 2 additions & 2 deletions docs/javadocs/edu/calpoly/spritely/AnimationController.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_181) on Sat Oct 06 14:53:23 PDT 2018 -->
<!-- Generated by javadoc (1.8.0_162) on Sun Oct 07 16:48:32 PDT 2018 -->
<title>AnimationController</title>
<meta name="date" content="2018-10-06">
<meta name="date" content="2018-10-07">
<link rel="stylesheet" type="text/css" href="../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../script.js"></script>
</head>
Expand Down
4 changes: 2 additions & 2 deletions docs/javadocs/edu/calpoly/spritely/AnimationFrame.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_181) on Sat Oct 06 14:53:23 PDT 2018 -->
<!-- Generated by javadoc (1.8.0_162) on Sun Oct 07 16:48:32 PDT 2018 -->
<title>AnimationFrame</title>
<meta name="date" content="2018-10-06">
<meta name="date" content="2018-10-07">
<link rel="stylesheet" type="text/css" href="../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../script.js"></script>
</head>
Expand Down
4 changes: 2 additions & 2 deletions docs/javadocs/edu/calpoly/spritely/AnimationWindow.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_181) on Sat Oct 06 14:53:23 PDT 2018 -->
<!-- Generated by javadoc (1.8.0_162) on Sun Oct 07 16:48:32 PDT 2018 -->
<title>AnimationWindow</title>
<meta name="date" content="2018-10-06">
<meta name="date" content="2018-10-07">
<link rel="stylesheet" type="text/css" href="../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../script.js"></script>
</head>
Expand Down
4 changes: 2 additions & 2 deletions docs/javadocs/edu/calpoly/spritely/Display.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_181) on Sat Oct 06 14:53:23 PDT 2018 -->
<!-- Generated by javadoc (1.8.0_162) on Sun Oct 07 16:48:32 PDT 2018 -->
<title>Display</title>
<meta name="date" content="2018-10-06">
<meta name="date" content="2018-10-07">
<link rel="stylesheet" type="text/css" href="../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../script.js"></script>
</head>
Expand Down
4 changes: 2 additions & 2 deletions docs/javadocs/edu/calpoly/spritely/GraphicsWindow.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_181) on Sat Oct 06 14:53:23 PDT 2018 -->
<!-- Generated by javadoc (1.8.0_162) on Sun Oct 07 16:48:32 PDT 2018 -->
<title>GraphicsWindow</title>
<meta name="date" content="2018-10-06">
<meta name="date" content="2018-10-07">
<link rel="stylesheet" type="text/css" href="../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../script.js"></script>
</head>
Expand Down
4 changes: 2 additions & 2 deletions docs/javadocs/edu/calpoly/spritely/ImageTile.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_181) on Sat Oct 06 14:53:23 PDT 2018 -->
<!-- Generated by javadoc (1.8.0_162) on Sun Oct 07 16:48:32 PDT 2018 -->
<title>ImageTile</title>
<meta name="date" content="2018-10-06">
<meta name="date" content="2018-10-07">
<link rel="stylesheet" type="text/css" href="../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../script.js"></script>
</head>
Expand Down
4 changes: 2 additions & 2 deletions docs/javadocs/edu/calpoly/spritely/KeyTypedHandler.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_181) on Sat Oct 06 14:53:23 PDT 2018 -->
<!-- Generated by javadoc (1.8.0_162) on Sun Oct 07 16:48:32 PDT 2018 -->
<title>KeyTypedHandler</title>
<meta name="date" content="2018-10-06">
<meta name="date" content="2018-10-07">
<link rel="stylesheet" type="text/css" href="../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../script.js"></script>
</head>
Expand Down
4 changes: 2 additions & 2 deletions docs/javadocs/edu/calpoly/spritely/MouseClickedHandler.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_181) on Sat Oct 06 14:53:23 PDT 2018 -->
<!-- Generated by javadoc (1.8.0_162) on Sun Oct 07 16:48:32 PDT 2018 -->
<title>MouseClickedHandler</title>
<meta name="date" content="2018-10-06">
<meta name="date" content="2018-10-07">
<link rel="stylesheet" type="text/css" href="../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../script.js"></script>
</head>
Expand Down
4 changes: 2 additions & 2 deletions docs/javadocs/edu/calpoly/spritely/Size.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_181) on Sat Oct 06 14:53:23 PDT 2018 -->
<!-- Generated by javadoc (1.8.0_162) on Sun Oct 07 16:48:32 PDT 2018 -->
<title>Size</title>
<meta name="date" content="2018-10-06">
<meta name="date" content="2018-10-07">
<link rel="stylesheet" type="text/css" href="../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../script.js"></script>
</head>
Expand Down
4 changes: 2 additions & 2 deletions docs/javadocs/edu/calpoly/spritely/SolidColorTile.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_181) on Sat Oct 06 14:53:23 PDT 2018 -->
<!-- Generated by javadoc (1.8.0_162) on Sun Oct 07 16:48:32 PDT 2018 -->
<title>SolidColorTile</title>
<meta name="date" content="2018-10-06">
<meta name="date" content="2018-10-07">
<link rel="stylesheet" type="text/css" href="../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../script.js"></script>
</head>
Expand Down
4 changes: 2 additions & 2 deletions docs/javadocs/edu/calpoly/spritely/SpriteWindow.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_181) on Sat Oct 06 14:53:23 PDT 2018 -->
<!-- Generated by javadoc (1.8.0_162) on Sun Oct 07 16:48:32 PDT 2018 -->
<title>SpriteWindow</title>
<meta name="date" content="2018-10-06">
<meta name="date" content="2018-10-07">
<link rel="stylesheet" type="text/css" href="../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../script.js"></script>
</head>
Expand Down
4 changes: 2 additions & 2 deletions docs/javadocs/edu/calpoly/spritely/Tile.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_181) on Sat Oct 06 14:53:23 PDT 2018 -->
<!-- Generated by javadoc (1.8.0_162) on Sun Oct 07 16:48:32 PDT 2018 -->
<title>Tile</title>
<meta name="date" content="2018-10-06">
<meta name="date" content="2018-10-07">
<link rel="stylesheet" type="text/css" href="../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../script.js"></script>
</head>
Expand Down
4 changes: 2 additions & 2 deletions docs/javadocs/edu/calpoly/spritely/package-frame.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_181) on Sat Oct 06 14:53:23 PDT 2018 -->
<!-- Generated by javadoc (1.8.0_162) on Sun Oct 07 16:48:32 PDT 2018 -->
<title>edu.calpoly.spritely</title>
<meta name="date" content="2018-10-06">
<meta name="date" content="2018-10-07">
<link rel="stylesheet" type="text/css" href="../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../script.js"></script>
</head>
Expand Down
4 changes: 2 additions & 2 deletions docs/javadocs/edu/calpoly/spritely/package-summary.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_181) on Sat Oct 06 14:53:23 PDT 2018 -->
<!-- Generated by javadoc (1.8.0_162) on Sun Oct 07 16:48:32 PDT 2018 -->
<title>edu.calpoly.spritely</title>
<meta name="date" content="2018-10-06">
<meta name="date" content="2018-10-07">
<link rel="stylesheet" type="text/css" href="../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../script.js"></script>
</head>
Expand Down
4 changes: 2 additions & 2 deletions docs/javadocs/edu/calpoly/spritely/package-tree.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_181) on Sat Oct 06 14:53:23 PDT 2018 -->
<!-- Generated by javadoc (1.8.0_162) on Sun Oct 07 16:48:32 PDT 2018 -->
<title>edu.calpoly.spritely Class Hierarchy</title>
<meta name="date" content="2018-10-06">
<meta name="date" content="2018-10-07">
<link rel="stylesheet" type="text/css" href="../../../stylesheet.css" title="Style">
<script type="text/javascript" src="../../../script.js"></script>
</head>
Expand Down
4 changes: 2 additions & 2 deletions docs/javadocs/help-doc.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_181) on Sat Oct 06 14:53:23 PDT 2018 -->
<!-- Generated by javadoc (1.8.0_162) on Sun Oct 07 16:48:32 PDT 2018 -->
<title>API Help</title>
<meta name="date" content="2018-10-06">
<meta name="date" content="2018-10-07">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
Expand Down
4 changes: 2 additions & 2 deletions docs/javadocs/index-all.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_181) on Sat Oct 06 14:53:23 PDT 2018 -->
<!-- Generated by javadoc (1.8.0_162) on Sun Oct 07 16:48:32 PDT 2018 -->
<title>Index</title>
<meta name="date" content="2018-10-06">
<meta name="date" content="2018-10-07">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
Expand Down
2 changes: 1 addition & 1 deletion docs/javadocs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_181) on Sat Oct 06 14:53:23 PDT 2018 -->
<!-- Generated by javadoc (1.8.0_162) on Sun Oct 07 16:48:32 PDT 2018 -->
<title>Generated Documentation (Untitled)</title>
<script type="text/javascript">
tmpTargetPage = "" + window.location.search;
Expand Down
4 changes: 2 additions & 2 deletions docs/javadocs/overview-tree.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- NewPage -->
<html lang="en">
<head>
<!-- Generated by javadoc (1.8.0_181) on Sat Oct 06 14:53:23 PDT 2018 -->
<!-- Generated by javadoc (1.8.0_162) on Sun Oct 07 16:48:32 PDT 2018 -->
<title>Class Hierarchy</title>
<meta name="date" content="2018-10-06">
<meta name="date" content="2018-10-07">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script type="text/javascript" src="script.js"></script>
</head>
Expand Down
19 changes: 10 additions & 9 deletions src/edu/calpoly/spritely/AnimationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,7 @@ public boolean waitForNextFrame() {
// hierarchy.
//
boolean waitForNextFrame(Display display, boolean mouseWanted) {
if (inWaitForNextFrame) {
System.out.println();
System.out.println("*** Spritely WARNING ***");
System.out.println(" Spritely detected a call to waitForNextFrame()");
System.out.println(" during a call to waitForNextFrame(). Perhaps you called it");
System.out.println(" from a mouse or keyboard handler? This is forbidden., and will");
System.out.println(" soon be turned into a hard failure.");
System.out.println();
}
checkNotWaiting();
inWaitForNextFrame = true;
currFrame++;
boolean excused = false;
Expand Down Expand Up @@ -347,6 +339,15 @@ boolean waitForNextFrame(Display display, boolean mouseWanted) {
return true;
}

//
// Fail if we're in the middle of a call to waitForNextFrame().
//
void checkNotWaiting() {
if (inWaitForNextFrame) {
throw new IllegalStateException("It is forbidden to call this while waitForNextFrame() is executing");
}
}


/**
* Pause the animation for the given time, and reset the animation
Expand Down
4 changes: 4 additions & 0 deletions src/edu/calpoly/spritely/AnimationWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ void checkStarted(boolean expected) {
controller.checkStarted(expected);
}

void checkNotWaiting() {
controller.checkNotWaiting();
}

/**
* Sets the number of frames/second that are displayed.
*
Expand Down
1 change: 1 addition & 0 deletions src/edu/calpoly/spritely/GraphicsWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public void showNextFrame() {
*/
public void showNextFrame(boolean drawingWasDone) {
checkStarted(true);
checkNotWaiting();
if (currGraphics == null) {
throw new IllegalStateException();
}
Expand Down
1 change: 1 addition & 0 deletions src/edu/calpoly/spritely/SpriteWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ public AnimationFrame waitForNextFrame() {
*/
public void showNextFrame() {
checkStarted(true);
checkNotWaiting();
if (currentAnimationFrame == null) {
throw new IllegalStateException();
}
Expand Down
9 changes: 9 additions & 0 deletions test/src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ public class Main {

private void mouseClicked(int x, int y) {
System.out.println("Mouse clicked: x=" + x + ", y=" + y + " ");
if (x == 0 && y == 0) {
System.out.println("Calling showNextFrame(). This should cause "
+ "an assertion failure.");
window.showNextFrame();
} else if (x == 1 && y == 0) {
System.out.println("Calling waitForNextFrame(). This should cause "
+ "an assertion failure.");
window.waitForNextFrame();
}
}

private void keyTyped(char ch) {
Expand Down

0 comments on commit d2270a9

Please sign in to comment.