Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 695f5c4bda6a141b3fee5f46e74e80178b8792df @robashton committed Dec 15, 2011
Showing with 544 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +39 −0 LICENSE
  3. +55 −0 config.js
  4. +86 −0 directorywalker.js
  5. +23 −0 package.json
  6. +70 −0 processor.js
  7. +28 −0 swallow-build.js
  8. +5 −0 test/in/assets/models/hovercraft.js
  9. +11 −0 test/in/assets/shaders/colour.fragment
  10. +13 −0 test/in/assets/shaders/colour.shader
  11. +6 −0 test/in/assets/shaders/default.fragment
  12. +8 −0 test/in/assets/shaders/default.shader
  13. +28 −0 test/in/assets/shaders/landscape.fragment
  14. +20 −0 test/in/assets/shaders/landscape.shader
  15. +15 −0 test/in/assets/shaders/particles.fragment
  16. +35 −0 test/in/assets/shaders/particles.shader
  17. +23 −0 test/in/assets/shaders/specular.fragment
  18. +33 −0 test/in/assets/shaders/specular.shader
  19. +19 −0 test/in/assets/shaders/texture.fragment
  20. +22 −0 test/in/assets/shaders/texture.shader
  21. BIN test/in/assets/sounds/pigeon.wav
  22. BIN test/in/assets/sounds/star.wav
  23. BIN test/in/assets/textures/Hovercraft.jpg
  24. BIN test/in/assets/textures/bars.jpg
  25. BIN test/in/assets/textures/cartoonterrain.jpg
  26. BIN test/in/assets/textures/cloud.png
  27. BIN test/in/assets/textures/grass.jpg
  28. BIN test/in/assets/textures/grassdetail.jpg
  29. BIN test/in/assets/textures/gridhigh.jpg
  30. BIN test/in/assets/textures/gridlow.jpg
  31. BIN test/in/assets/textures/particle.png
  32. BIN test/in/assets/textures/pigeon-particle.png
  33. BIN test/in/assets/textures/pigeon.png
  34. BIN test/in/assets/textures/plane.png
  35. BIN test/in/assets/textures/star-particle.png
  36. BIN test/in/assets/textures/star.png
  37. BIN test/in/assets/textures/testbump.jpg
  38. BIN test/in/assets/textures/tree.png
  39. +4 −0 test/in/config.json
@@ -0,0 +1 @@
+assets.json
39 LICENSE
@@ -0,0 +1,39 @@
+Copyright 2011 Rob Ashton (the "Author")
+All rights reserved.
+
+MIT +no-false-attribs License
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+Distributions of all or part of the Software intended to be used
+by the recipients as they would use the unmodified Software,
+containing modifications that substantially alter, remove, or
+disable functionality of the Software, outside of the documented
+configuration mechanisms provided by the Software, shall be
+modified such that the Author's bug reporting email addresses and
+urls are either replaced with the contact information of the
+parties responsible for the changes, or removed entirely.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+
+Except where noted, this license applies to any and all software
+programs and associated documentation files created by the
+Author, when distributed with the Software.
@@ -0,0 +1,55 @@
+var fs = require('fs');
+var path = require('path');
+
+var Config = function(data) {
+ var self = this;
+
+ data.in = path.join(data.baseDir, data.in);
+ data.out = path.join(data.baseDir, data.out);
+
+ self.forEachInput = function(callback) {
+ callback(data.in, {
+ out: data.out,
+ getHandlerForFile: self.getHandlerForFile
+ });
+ };
+
+ self.getHandlerForFile = function(filename) {
+ var extension = path.extname(filename);
+ switch(extension) {
+ case '.jpg':
+ case '.png':
+ case '.wav':
+ return processBinaryHandler;
+ default:
+ return unknownHandler;
+ };
+ };
+
+ var processBinaryHandler = function(input, callback) {
+ fs.readFile(input, function(err, data) {
+ var translated = new Buffer(data).toString('base64');
+ return callback(translated);
+ });
+ };
+
+ var unknownHandler = function(input, callback) {
+ return callback('');
+ };
+};
+
+Config.LoadFrom = function(filename, callback) {
+ fs.readFile(filename, function(err, data) {
+ if(err)
+ return callback(err);
+ var input = JSON.parse(data);
+ input.baseDir = input.baseDir || path.dirname(filename);
+ var config = new Config(input);
+
+ callback(null, config);
+ });
+};
+
+exports.Config = Config;
+
+
@@ -0,0 +1,86 @@
+var fs = require('fs');
+var path = require('path');
+var util = require('util');
+var EventEmitter = require('events').EventEmitter;
+
+var DirectoryWalker = function(directory) {
+ EventEmitter.call(this);
+
+ this.directory = directory;
+};
+util.inherits(DirectoryWalker, EventEmitter);
+
+DirectoryWalker.prototype.handleError = function(err) {
+ this.emit('error', err);
+};
+
+DirectoryWalker.prototype.run = function() {
+ var self = this;
+
+ var directoryChildren = null;
+ var processedCount = 0;
+ var directory = self.directory;
+
+ var onDirectoryRead = function(err, children) {
+ if(err)
+ return self.handleError(err);
+
+ directoryChildren = children;
+ processedCount = 0;
+ self.emit('started');
+ processChildren();
+ };
+
+ var processChildren = function() {
+ for(var i in directoryChildren) {
+ processChild(directoryChildren[i]);
+ }
+ };
+
+ var processChild = function(child) {
+ var fullPath = path.join(directory, child);
+ fs.stat(fullPath, function(err, stat) {
+ if(stat && stat.isDirectory())
+ processChildDirectory(fullPath);
+ else
+ processChildFile(fullPath);
+ });
+ };
+
+ var processChildDirectory = function(fullPath) {
+ self.emit('directory', fullPath);
+ var walker = new DirectoryWalker(fullPath);
+ walker.on('completed', onChildWalkerCompleted);
+ walker.on('file', onChildFile);
+ walker.run();
+ };
+
+ var onChildWalkerCompleted = function() {
+ increaseProcessedCount();
+ };
+
+ var onChildFile = function(fullPath) {
+ self.emit('file', fullPath);
+ };
+
+ var processChildFile = function(fullPath) {
+ self.emit('file', fullPath);
+ increaseProcessedCount();
+ };
+
+ var increaseProcessedCount = function() {
+ processedCount++;
+ if(processedCount === directoryChildren.length)
+ self.emit('completed');
+ };
+
+ var handleError = function(err) {
+ return self.emit('error', err);
+ };
+
+ fs.readdir(directory, onDirectoryRead);
+};
+
+exports.DirectoryWalker = DirectoryWalker;
+
+
@@ -0,0 +1,23 @@
+{ "name" : "Swallow"
+, "description" : "A resource manager for delivering and reading content in browser-based games, work in progress"
+, "keywords" : [ "resource manager", "resources", "games", "browser", "delivery" ]
+, "version" : "0.1"
+, "preferGlobal" : false
+, "homepage" : "http://github.com/robashton/swallow"
+, "author" : "Rob Ashton <robashton@codeofrob.com> (http://codeofrob.com)"
+, "repository" :
+ { "type" : "git"
+ , "url" : "https://github.com/robashton/swallow"
+ }
+, "bugs" :
+ { "email" : "swallow@codeofrob.com"
+ , "url" : "http://github.com/robashton/swallow/issues"
+ }
+, "main" : "./swallow-build.js"
+, "bin" : { "swallow" : "./swallow-build.js" }
+, "licenses" :
+ [ { "type" : "MIT +no-false-attribs"
+ , "url" : "http://github.com/robashton/swallow/raw/master/LICENSE"
+ }
+ ]
+}
@@ -0,0 +1,70 @@
+var DirectoryWalker = require('./directorywalker').DirectoryWalker;
+var EventEmitter = require('events').EventEmitter;
+var util = require('util');
+var fs = require('fs');
+
+var Processor = function(directory, inputConfig) {
+ this.directory = directory;
+ this.inputConfig = inputConfig;
+};
+util.inherits(Processor, EventEmitter);
+
+Processor.prototype.run = function() {
+ var self = this;
+
+ var completedScan = false;
+ var pendingCount = 0;
+ var directory = this.directory;
+ var inputConfig = this.inputConfig;
+ var data = {};
+
+ var execute = function() {
+ var walker = new DirectoryWalker(directory);
+ completedScan = false;
+ pendingCount = 0;
+
+ walker.on('file', function(fullPath) {
+ onFileStarted();
+ var handler = inputConfig.getHandlerForFile(fullPath);
+ var friendlyPath = fullPath.replace(directory, '');
+ handler(fullPath, function(transformed) {
+ data[friendlyPath] = transformed;
+ onFileProcessed(fullPath);
+ });
+ });
+ walker.on('completed', onCompletedScan);
+ walker.run();
+ };
+
+ var onFileStarted = function() {
+ pendingCount++;
+ };
+
+ var onFileProcessed = function(fullPath) {
+ self.emit('file', fullPath);
+ pendingCount--;
+ tryToFinish();
+ };
+
+ var onCompletedScan = function() {
+ completedScan = true;
+ tryToFinish();
+ };
+
+ var tryToFinish = function() {
+ if(pendingCount === 0 && completedScan) {
+ writeToOutputFile();
+ }
+ };
+
+ var writeToOutputFile = function() {
+ fs.writeFile(inputConfig.out, JSON.stringify(data), function(err) {
+ self.emit('completed');
+ });
+ };
+
+ execute();
+};
+
+exports.Processor = Processor;
+
@@ -0,0 +1,28 @@
+var fs = require('fs');
+var path = require('path');
+var util = require('util');
+
+var Config = require('./config').Config;
+var Processor = require('./processor').Processor;
+
+var configPath = process.argv[2];
+
+var onFileProcessed = function(fullPath) {
+ console.log('Processed: ' + fullPath);
+};
+
+var onProcessorCompleted = function() {
+ console.log('Completed');
+};
+
+var processInput = function(dir, input) {
+ var processor = new Processor(dir, input);
+ processor.on('file', onFileProcessed);
+ processor.on('completed', onProcessorCompleted);
+ processor.run();
+};
+
+Config.LoadFrom(configPath, function(err, config) {
+ if(err) throw err;
+ config.forEachInput(processInput);
+});
@@ -0,0 +1,5 @@
+{
+ vertices: [0,0,1,2,3,4,5],
+ indices: [2,4,5,6,7,7,8],
+ texture: [2,4,5,6,7,8,8]
+}
@@ -0,0 +1,11 @@
+#ifdef GL_ES
+precision highp float;
+#endif
+
+varying vec4 vColour;
+
+
+void main(void) {
+ gl_FragColor = vColour;
+
+}
@@ -0,0 +1,13 @@
+attribute vec3 aVertexPosition;
+attribute vec4 aVertexColour;
+
+uniform mat4 uProjection;
+uniform mat4 uView;
+uniform mat4 uWorld;
+
+varying vec4 vColour;
+
+void main(void){
+ gl_Position = uProjection * uView * uWorld * vec4(aVertexPosition, 1.0);
+ vColour = aVertexColour;
+}
@@ -0,0 +1,6 @@
+#ifdef GL_ES
+precision highp float;
+#endif
+void main(void) {
+ gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
+}
@@ -0,0 +1,8 @@
+attribute vec3 aVertexPosition;
+uniform mat4 uProjection;
+uniform mat4 uView;
+uniform mat4 uWorld;
+
+void main(void){
+ gl_Position = uProjection * uView * uWorld * vec4(aVertexPosition, 1.0);
+}
@@ -0,0 +1,28 @@
+#ifdef GL_ES
+precision highp float;
+#endif
+
+varying vec2 vTexCoords;
+varying vec3 vNormal;
+varying float vDistance;
+uniform sampler2D uSampler;
+
+bool isEdge(float value) {
+ return false;
+ if(floor(mod(value,10.0) * 5.0) == 0.0) { return true; }
+ return false;
+}
+
+void main(void) {
+ float x = vTexCoords.x * 100.0;
+ float y = vTexCoords.y * 100.0;
+
+ vec4 grid = vec4(1,1,1,1);
+ if(isEdge(x) || isEdge(y)) {
+ grid = vec4(0.4, 0.4, 0.4, 1.0);
+ }
+
+ gl_FragColor = texture2D(uSampler, vec2(vTexCoords.s, vTexCoords.t));
+ gl_FragColor *= grid;
+ gl_FragColor.g *= (vNormal.y * vNormal.y); // Want it a little darker k?
+}
Oops, something went wrong.

0 comments on commit 695f5c4

Please sign in to comment.