Skip to content

Commit

Permalink
noise background, back button for instruction, build script
Browse files Browse the repository at this point in the history
  • Loading branch information
shooshx committed Jul 21, 2015
1 parent f5429d8 commit 9858e85
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 28 deletions.
1 change: 1 addition & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css application/javascript application/json
AddType application/x-web-app-manifest+json .webapp

# you need to add to WAMP apache mod_filter,mod_deflate for these to work
130 changes: 116 additions & 14 deletions build_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import subprocess
import tempfile
import time
import shutil


def incBuildNum():
with open('src/build_number.js', 'r') as f:
Expand All @@ -22,10 +24,10 @@ def fileStat(filename):
def fileListStat(buf):
return (sum(1 for line in StringIO(buf)), len(buf))


jslist=[
'src/pack_header.js',
curdir = os.path.dirname(os.path.abspath(__file__))
jslist_bare=[
'src/jquery.cookie.js',
'src/browserDetect.js',
'src/webgl-utils.js',
Expand All @@ -44,18 +46,105 @@ def fileListStat(buf):
'src/build_number.js',
'src/gameControl.js',
'src/loadManager.js',
'src/background.js',
'src/main.js',
'src/pack_footer.js',
]
]

jslist=['src/pack_header.js'] + jslist_bare + ['src/pack_footer.js']

minjsout= 'cycleblob.min.js'

minjsout='../release/cycleblob.min.js'
resources={
'': [
'.htaccess',
'about.php',
'contact.php',
'src/jquery-1.4.4.min.js',
'page.css',
'shaders.html',
'favicon.ico',
'firefox_store_manifest.webapp',
],
'img': [ '.htaccess',
'icon_Desktop.png',
'icon_Forward.png',
'icon_Playb.png',
'icon_Refresh.png',
'instructions3.svgz',
'instructions_header.png',
'rep_image.png',
'speaker_off.svg',
'speaker_on.svg',
'title_text9.svg',
'rep_image_128.png',
'm_cube.png',
'm_dbl_sofa.png',
'm_diamond.png',
'm_inside_cube.png',
'm_mobius.png',
'm_plus.png',
'm_sofa.png',
'm_softsofa.png',
'm_tetra.png',
'm_torus.png',
'm_triCorner.png',
'tex2d.jpg',
],
'sound':['coin_up3.mp3',
'coin_up3.ogg',
'crash2.mp3',
'crash2.ogg',
'powerup2.mp3',
'powerup2.ogg',
'turn5.mp3',
'turn5.ogg',
],
'modelsz': ['.htaccess',
'cube5quads.jsonz',
'dbl_sofa_soft_4q.jsonz',
'distortDiamond5q.jsonz',
'mobius_10r_3q.jsonz',
'plus4q.jsonz',
'rot_dounut2.jsonz',
'sofa4q.jsonz',
'sofa4q_soft.jsonz',
'tetra1_4q.jsonz',
'torus_100_50s.jsonz',
'triCorner4.jsonz',
'triCornerOut4.jsonz',
],
'models': ['bikePlayer2.json',
'lifeWheel.json'
],
}

# node - https://nodejs.org/
# uglify2 - https://github.com/mishoo/UglifyJS2

def run(cmd, shell=False):
print "**", cmd
subprocess.call(cmd, shell=shell)

def minWithUglify2(alljs, out):
#with open('./tmp_%s.js' % time.time(), 'w') as tmp:
with tempfile.TemporaryFile('w+') as tmp: # '+' truncates
f = tmp.file
f.write(alljs)
f.flush()
run(['uglifyjs', tmp.name, '--screw-ie8', '-o', out,
'--mangle',
'--compress',
'--beautify', 'beautify=false,max-line-len=600',
'--reserved', 'cb'], shell=True)


# --reserve-domprops

def minWithUglify2(alljs):
with tempfile.TemporaryFile('w+') as tmp:
tmp.file.write(alljs)
tmp.file.flush()
p = subprocess.call(['node_modules\.bin\uglifyjs.cmd', tmp.name] + '-m -c -b beautify=false,max-line-len=600 -r "cb" -o'.split() + [minjsout] ) # --wrap cb
#def minWithUglify2(alljs):
# with tempfile.TemporaryFile('w+') as tmp:
# tmp.file.write(alljs)
# tmp.file.flush()
# p = subprocess.call(['uglifyjs', tmp.name] + '-m -c -b beautify=false,max-line-len=600 -r "cb" -o'.split() + [minjsout] ) # --wrap cb

def minWithClosure(alljs):
# NOT WORKING since it changes the names of fields from JSON
Expand All @@ -76,9 +165,22 @@ def main():
alljs = ''.join(open(name).read() for name in jslist)

print 'before: %d lines, %d bytes' % fileListStat(alljs)
minWithUglify2(alljs)

rdir = os.path.join(curdir, 'release', 'release_%s' % num)
os.makedirs(rdir)

jsout = os.path.join(rdir, minjsout)
minWithUglify2(alljs, jsout)

print 'after: %d lines, %d bytes' % fileStat(minjsout)
print 'after: %d lines, %d bytes' % fileStat(jsout)

for d,files in resources.iteritems():
absd = os.path.join(rdir, d)
if len(d) > 0:
os.mkdir(absd)
for f in files:
shutil.copy( os.path.join(curdir, d, f), absd )
shutil.copy( os.path.join(curdir, 'release.html'), os.path.join(rdir, 'index.html') )


if __name__ == '__main__':
Expand Down
Binary file added img/tex2d.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/tex2d_flipvert.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added modelsz/rot_dounut2.jsonz
Binary file not shown.
86 changes: 86 additions & 0 deletions shaders.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,92 @@
}
</script>

<script id="bkg-3dtex-fs" type="x-shader/x-fragment">
precision highp float;
varying vec3 pos;
uniform float time;


uniform sampler2D noisef;

const vec3 colorA = vec3(0.00, 0.23, 0.32); //(0.10, 0.00, 0.40);
const vec3 colorB = vec3(0.00, 0.00, 0.10); //(0.49, 0.00, 0.43);


float mod(int x, float y){
return float(x) - y * floor(float(x) / y);
}

float fmod(float x, float y){
return x - y * floor(float(x) / y);
}

// 128x128 tiles are 8x16
// tiles are taken bottom to top
vec4 flat_texture3D(vec3 p)
{
vec2 inimg = p.xy;
inimg.x = fmod(inimg.x, 1.0);
inimg.y = fmod(inimg.y, 1.0);
inimg.y = max(inimg.y, 0.00390625);
inimg.y = min(inimg.y, 0.99609375);
inimg.x = max(inimg.x, 0.00390625);
inimg.x = min(inimg.x, 0.99609375);

float fpz = p.z*128.0;
fpz = min(fpz, 127.0);
int d1 = int(fpz);
float ix1 = mod(d1, 8.0);
float iy1 = float(d1 / 8);
vec2 oc1 = inimg + vec2(ix1, iy1);
oc1 *= vec2(0.125, 0.0625); // 1/8,1/16

int d2 = d1 + 1;
float ix2 = mod(d2, 8.0);
float iy2 = float(d2 / 8);
vec2 oc2 = inimg + vec2(ix2, iy2);
oc2 *= vec2(0.125, 0.0625);

vec4 t1 = texture2D(noisef, oc1);
vec4 t2 = texture2D(noisef, oc2);

vec4 t = mix(t1, t2, fract(fpz));

return t;
}

void main (void)
{
// normalize -6.2:6.2 to 0:1
vec3 p = pos;
p *= 0.08;
p += vec3(0.5, 0.5, 0.5) ;

vec4 noisevec1 = flat_texture3D(p + vec3(sin(time * 0.4),0.0 ,0.0));
vec4 noisevec2 = flat_texture3D(p.yzx + vec3(0.0, cos(time * 0.4), 0.0));

float a = abs(noisevec1[0] - 0.4) * 2.0;
float b = abs(noisevec2[0] - 0.6) * 2.0;
float c = a + b;

c = min(max(c, 0.0), 1.0);

//vec4 noisevec = flat_texture3D(p);

//float a = noisevec[0];


//vec3 color = vec3(a,a,a);// mix(colorA, colorB, a);
//color *= LightIntensity;
vec3 color = mix(colorA, colorB, c);

gl_FragColor = vec4(color, 1.0);
return;

}

</script>

<script id="bkg-fs" type="x-shader/x-fragment">
precision highp float;
varying vec3 pos;
Expand Down
4 changes: 2 additions & 2 deletions src/build_number.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// this file is created by the build script
var BUILD_NUMBER=182;
// this file is created by the build script
var BUILD_NUMBER=213
21 changes: 11 additions & 10 deletions src/gameControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,19 @@ function startLife(lvlsel) {
startGameControls();
}

// compressed models created using 7zip archive to gzip
worldModels={
// cube: { file: "models/cube3.json", eyeDist:3.3 },
"cube": { file: "models/cube5quads.json", eyeDist:3.3 },
"triCorner": { file: "models/triCorner4.json", eyeDist: 7 },
"plus": { file: "models/plus4q.json", eyeDist: 7 },
"dblsofa": { file: "models/dbl_sofa_soft_4q.json", eyeDist: 3.3 },
"softsofa": { file: "models/sofa4q_soft.json", eyeDist: 3.54 }, // nice
"dDiamond": { file: "models/distortDiamond5q.json", eyeDist: 4 }, // nice
"torus": { file: "models/torus_100_50s.json", eyeDist: 3.66 }, // fun
"tetra": { file: "models/tetra1_4q.json", eyeDist: 3.4 },
"mobius": { file: "models/mobius_10r_3q.json", eyeDist: 1.0 },
"rotDounut": { file: "models/rot_dounut2.json", eyeDist: 4 }
"cube": { file: "modelsz/cube5quads.jsonz", eyeDist:3.3 },
"triCorner": { file: "modelsz/triCorner4.jsonz", eyeDist: 7 },
"plus": { file: "modelsz/plus4q.jsonz", eyeDist: 7 },
"dblsofa": { file: "modelsz/dbl_sofa_soft_4q.jsonz", eyeDist: 3.3 },
"softsofa": { file: "modelsz/sofa4q_soft.jsonz", eyeDist: 3.54 }, // nice
"dDiamond": { file: "modelsz/distortDiamond5q.jsonz", eyeDist: 4 }, // nice
"torus": { file: "modelsz/torus_100_50s.jsonz", eyeDist: 3.66 }, // fun
"tetra": { file: "modelsz/tetra1_4q.jsonz", eyeDist: 3.4 },
"mobius": { file: "modelsz/mobius_10r_3q.jsonz", eyeDist: 1.0 },
"rotDounut": { file: "modelsz/rot_dounut2.jsonz", eyeDist: 4 }
//sofa: { file: "modelsz/sofa4q.jsonz", eyeDist: 4 },
//triCornerOut: { file: "modelsz/triCornerOut4.jsonz", eyeDist: 6.95 },
// squashSofa: { file: "models/squashSofa5q.json", eyeDist: 2.78 }, // confusing, sickening
Expand Down
29 changes: 28 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,31 @@ function containterResize(event, bforce) {
writeDebug("canvas resized: " + canvas.width + " x " + canvas.height);
}

var noiseTex = null;

function handleTextureLoaded(image, texture) {
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);

gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);

// gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_BASE_LEVEL, 0);
// gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAX_LEVEL, 0);

// gl.bindTexture(gl.TEXTURE_2D, null);
}

function loadTexture() {
noiseTex = gl.createTexture();
img = new Image();
img.onload = function() { handleTextureLoaded(img, noiseTex); }
img.src = "img/tex2d.jpg";
}


function hack() {
game.userLivesCount=10
}
Expand All @@ -568,12 +593,14 @@ function webGLStart() {
shaderFrame = $('#shadersFrame').contents();
shaderProg.init(shaderFrame.find('#phong-fs'), shaderFrame.find('#phong-vs'));
shaderProg.initNormParams();
bkgProg.init(shaderFrame.find('#bkg-fs'), shaderFrame.find('#bkg-vs'));
bkgProg.init(shaderFrame.find('#bkg-3dtex-fs'), shaderFrame.find('#bkg-vs'));
bkgProg.initBkgParams();
Program.use(shaderProg);

window.onresize = containterResize;

loadTexture();

// startWorker(); //worker thread

// load the first 3 levels and process them async right at the start
Expand Down
2 changes: 1 addition & 1 deletion src/pack_footer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
return { webGLStart: webGLStart, hack=hack};
return { webGLStart: webGLStart, hack: hack};
}());
window["webGLStart"] = cb.webGLStart
Loading

0 comments on commit 9858e85

Please sign in to comment.