Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tidy up wall time calculation

  • Loading branch information...
commit 69e4520891410b061063780e11aa67ec3bfe2939 1 parent e123af0
Brian Birtles birtles authored
4 wall/database/create.sql
View
@@ -3,7 +3,7 @@ CREATE TABLE `designs` (
`designId` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL COMMENT 'A descriptive name for the type of design. This will need to be localized eventually.',
`thumbUrl` varchar(255) DEFAULT NULL COMMENT 'A URL to a thumbnail image of the design. Relative paths should probably be relative to some designs folder.',
- `duration` int(8) DEFAULT NULL COMMENT 'Default duration of this design',
+ `duration` int(8) DEFAULT NULL COMMENT 'Default duration of this design in milliseconds',
PRIMARY KEY (`designId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Catalogue of wall styles';
@@ -29,7 +29,7 @@ CREATE TABLE `walls` (
`urlPath` varchar(255) NOT NULL COMMENT 'The path component of the URL, e.g. ''fukushima-100''',
`shortUrl` varchar(40) DEFAULT NULL COMMENT 'Shortened URL for the wall',
`editorShortUrl` varchar(40) DEFAULT NULL COMMENT 'Shortened URL for the editor associated with this wall',
- `duration` int(8) DEFAULT NULL COMMENT 'The number of milliseconds for a single iteration?',
+ `duration` int(8) DEFAULT NULL COMMENT 'The number of milliseconds for a single iteration',
`createDate` datetime NOT NULL COMMENT 'Creation datetime in UTC',
`modifyDate` datetime NOT NULL COMMENT 'Modification datetime in UTC',
PRIMARY KEY (`wallId`),
6 wall/lib/characters.inc
View
@@ -28,9 +28,9 @@ function addCharacter($wallId, $svg, $metadata) {
// Insert record
$date = gmdate('Y-m-d H:i:s');
// calculate X value
- $currentWallDuration = getCurrentWallDuration($wallId);
- $currentWallTime = getCurrentWallTimeByDuration($currentWallDuration);
- $x = floor($currentWallTime / $currentWallDuration * 1000);
+ $duration = getWallDuration($wallId);
+ $currentWallTime = getCurrentWallTimeForDuration($duration);
+ $x = floor($currentWallTime / $duration * 1000);
$query =
'INSERT INTO characters'
32 wall/lib/walls.inc
View
@@ -355,10 +355,13 @@ function recordExists($table, $field, $value, $type) {
return $exists;
}
-function getCurrentWallTimeByWallId($wallId) {
+function getWallDuration($wallId) {
$conn =& getDbConnection();
$res =& $conn->query(
- 'SELECT walls.duration AS duration,designs.duration AS defaultduration FROM walls,designs WHERE walls.designId = designs.designId AND wallId = '
+ 'SELECT walls.duration AS duration,'
+ . ' designs.duration AS defaultduration'
+ . ' FROM walls, designs WHERE'
+ . ' walls.designId = designs.designId AND wallId = '
. $conn->quote($wallId, 'integer')
);
if (PEAR::isError($res)) {
@@ -373,31 +376,14 @@ function getCurrentWallTimeByWallId($wallId) {
$currentDuration = $duration != 0 ? $duration : $defaultDuration;
}
$conn->disconnect();
- return getCurrentWallTimeByDuration($currentDuration);
+ return $currentDuration;
}
-function getCurrentWallDuration($wallId) {
- $conn =& getDbConnection();
- $res =& $conn->query(
- 'SELECT walls.duration AS duration,designs.duration AS defaultduration FROM walls,designs WHERE walls.designId = designs.designId AND wallId = '
- . $conn->quote($wallId, 'integer')
- );
- if (PEAR::isError($res)) {
- error_log($res->getMessage() . ', ' . $res->getDebugInfo());
- throw new KeyedException('db-error');
- }
- $conn->setFetchMode(MDB2_FETCHMODE_ASSOC);
- $currentDuration = 0;
- if ($row = $res->fetchRow()) {
- $duration = intval($row['duration']);
- $defaultDuration = intval($row['defaultduration']);
- $currentDuration = $duration != 0 ? $duration : $defaultDuration;
- }
- $conn->disconnect();
- return $currentDuration;
+function getCurrentWallTime($wallId) {
+ return getCurrentWallTimeForDuration(getWallDuration($wallId));
}
-function getCurrentWallTimeByDuration($duration) {
+function getCurrentWallTimeForDuration($duration) {
$currentTimeMillis = bcmul(microtime(true), 1000);
return bcmod($currentTimeMillis, $duration);
}
15 wall/public/wall/index.php
View
@@ -13,7 +13,6 @@
// Parse wall name
$url = $_SERVER["REDIRECT_URL"];
$match = preg_match('/^\/wall\/([^\/]+)$/', $url, $matches);
-// $match = preg_match('/wall\/([^\/]+)$/', $url, $matches);
if ($match != 1) {
throwException("no wall found");
}
@@ -24,11 +23,9 @@
}
$connection = getConnection();
- $query = "SELECT W.duration AS duration,D.name AS design, D.duration AS defaultduration, S.sessionId AS sessionId, S.endDate AS endDate FROM walls AS W ,designs AS D, sessions AS S WHERE W.wallId=$wallId AND D.designId=W.designId AND W.wallId=S.wallId ORDER BY S.sessionId DESC LIMIT 1";
+ $query = "SELECT D.name AS design, S.sessionId AS sessionId, S.endDate AS endDate FROM walls AS W ,designs AS D, sessions AS S WHERE W.wallId=$wallId AND D.designId=W.designId AND W.wallId=S.wallId ORDER BY S.sessionId DESC LIMIT 1";
$resultset = mysql_query($query, $connection) or throwException(mysql_error());
if ($row = mysql_fetch_array($resultset)) {
- $duration = intval($row["duration"]);
- $defaultduration = intval($row["defaultduration"]);
$design = $row["design"];
$endDate = $row["endDate"];
$sessionId = $row["sessionId"];
@@ -51,8 +48,8 @@
$walltype = $design;
$templatepath = "./templates/$walltype";
$database = $endDate == NULL ? "database4live.js" : "database4gallery.js";
-$basetime = $duration == 0 ? $defaultduration : $duration;
-$begintime = getCurrentWallTimeByDuration($basetime);
+$duration = getWallDuration($wallId);
+$beginTime = getCurrentWallTimeForDuration($duration);
?>
<?xml version="1.0" standalone="no"?>
@@ -66,8 +63,8 @@
<script>
var WALL_ID = <?php echo $wallId ?>;
var SESSION_ID = <?php echo $sessionId ?>;
- var BASE_TIME = <?php echo $basetime ?>;
- var BEGIN_TIME = <?php echo $begintime ?>;
+ var BASE_TIME = <?php echo $duration ?>;
+ var BEGIN_TIME = <?php echo $beginTime ?>;
var BEFORE_LOADED_TIME = (new Date()).getTime();
</script>
<script xlink:href="js/jquery-1.7.1.min.js"></script>
@@ -75,4 +72,4 @@
<script xlink:href="js/<?php echo $database; ?>"></script>
<script xlink:href="<?php echo $templatepath; ?>/main.js"></script>
<?php require("$templatepath/wall.svg.inc"); ?>
-</svg>
+</svg>
Please sign in to comment.
Something went wrong with that request. Please try again.