Skip to content

Commit

Permalink
m
Browse files Browse the repository at this point in the history
  • Loading branch information
shooshx committed Jan 18, 2013
1 parent c173102 commit 92cbf53
Show file tree
Hide file tree
Showing 20 changed files with 1,065 additions and 675 deletions.
31 changes: 24 additions & 7 deletions build_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from StringIO import StringIO
import subprocess
import tempfile
import time

def incBuildNum():
with open('src/build_number.js', 'r') as f:
Expand Down Expand Up @@ -38,6 +39,7 @@ def fileListStat(buf):
'src/aiControl.js',
'src/sfx.js',
'src/viewPoint.js',
'src/widgets2d.js',
'src/screens2d.js',
'src/build_number.js',
'src/gameControl.js',
Expand All @@ -49,20 +51,35 @@ def fileListStat(buf):
minjsout='../release/cycleblob.min.js'


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 minWithClosure(alljs):
# NOT WORKING since it changes the names of fields from JSON
#subprocess.call(['java', '-jar', '../minify/closure/compiler.jar', '--js_output_file', minjsout, '--compilation_level', 'ADVANCED_OPTIMIZATIONS'] \
# + sum((['--js',x] for x in jslist), []))

name = './tmp_%s.js' % time.time()
with open(name, 'w') as tmp:
tmp.write(alljs)
print 'tmp: ', name
subprocess.call(['java', '-jar', '../minify/closure/compiler.jar', '--third_party', '--js_output_file', minjsout, \
'--compilation_level', 'ADVANCED_OPTIMIZATIONS', '--js', name, '--externs', '../minify/closure/jquery144_externs.js'])


def main():
num = incBuildNum()
print 'build number', num
alljs = ''.join(open(name).read() for name in jslist)

print 'before: %d lines, %d bytes' % fileListStat(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

minWithUglify2(alljs)

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


if __name__ == '__main__':
main()
main()
2 changes: 2 additions & 0 deletions cycleblob.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@
</ItemDefinitionGroup>
<ItemGroup>
<None Include="about.php" />
<None Include="build_release.py" />
<None Include="contact.php" />
<None Include="favicon.ico" />
<None Include="page.css" />
<None Include="page.html" />
<None Include="release.html" />
<None Include="shaders.html" />
<None Include="src\aiControl.js" />
<None Include="src\background.js" />
<None Include="src\browserDetect.js" />
<None Include="src\build_number.js" />
<None Include="src\debug.js" />
Expand Down
4 changes: 4 additions & 0 deletions cycleblob.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@
<None Include="contact.php">
<Filter>html</Filter>
</None>
<None Include="build_release.py" />
<None Include="src\background.js">
<Filter>js</Filter>
</None>
</ItemGroup>
<ItemGroup>
<Filter Include="js">
Expand Down
18 changes: 12 additions & 6 deletions page.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@
<script type="text/javascript" src="src/aiControl.js"></script>
<script type="text/javascript" src="src/sfx.js"></script>
<script type="text/javascript" src="src/viewPoint.js"></script>
<script type="text/javascript" src="src/widgets2d.js"></script>
<script type="text/javascript" src="src/screens2d.js"></script>
<script type="text/javascript" src="src/build_number.js"></script>
<script type="text/javascript" src="src/gameControl.js"></script>
<script type="text/javascript" src="src/loadManager.js"></script>
<script type="text/javascript" src="src/background.js"></script>
<script type="text/javascript" src="src/main.js"></script>

<!--<script type="text/javascript" src="worker.js"></script> <!-- here just for listing in the debugger -->
Expand Down Expand Up @@ -74,14 +76,18 @@
slideval3 = 0;

acolor = Raphael.colorwheel($("#acolor"), 150);
acolor.onchange(function(c) { $("#acoltext").text(c.hex); if (acolor.onchange2) acolor.onchange2(); });
acolor.onchange(function(c) { $("#acoltext").val(c.hex); if (acolor.onchange2) acolor.onchange2(); });
$("#acoltext").change(function() { acolor.color($("#acoltext").val()); })
acolor.color("#Fff");
bcolor = Raphael.colorwheel($("#bcolor"), 150);
bcolor.onchange(function(c) { $("#bcoltext").text(c.hex); if (bcolor.onchange2) bcolor.onchange2(); });
bcolor.onchange(function(c) { $("#bcoltext").val(c.hex); if (bcolor.onchange2) bcolor.onchange2(); });
$("#bcoltext").change(function() { bcolor.color($("#bcoltext").val()); })
bcolor.color("#F00");
ccolor = Raphael.colorwheel($("#ccolor"), 150);
ccolor.onchange(function(c) { $("#ccoltext").text(c.hex); if (ccolor.onchange2) ccolor.onchange2(); });
ccolor.onchange(function(c) { $("#ccoltext").val(c.hex); if (ccolor.onchange2) ccolor.onchange2(); });
$("#ccoltext").change(function() { ccolor.color($("#ccoltext").val()); })
ccolor.color("#F00");
// use with acolor.color().hex
});

function writeModel(vtxBuf, normBuf, triBuf) {
Expand Down Expand Up @@ -187,9 +193,9 @@ <h2>You have JavaScript disabled</h2>
</tbody>
</table>
<table>
<tr><td>a: <span id="acoltext"></span></td>
<td>b: <span id="bcoltext"></span></td>
<td>c: <span id="ccoltext"></span></td></tr>
<tr><td>a: <input id="acoltext" type="text"></input></td>
<td>b: <input id="bcoltext" type="text"></input></td>
<td>c: <input id="ccoltext" type="text"></input></td></tr>
<tr><td><div class="color" id="acolor"></div></td>
<td><div class="color" id="bcolor"></div></td>
<td><div class="color" id="ccolor"></div></td>
Expand Down
106 changes: 81 additions & 25 deletions shaders.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,41 @@
<!doctype html>
<html><head>
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-Equiv="Pragma" Content="no-cache">
<meta http-Equiv="Expires" Content="0">
</head>

<script id="phong-vs" type="x-shader/x-vertex">
precision highp float;

attribute vec3 aVertexPosition;
attribute vec3 aVertexNormal;
// attribute vec2 aTextureCoord;

uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
//uniform mat4 uNMatrix;

// varying vec2 vTextureCoord;
varying vec3 vTransformedNormal;
varying vec3 vPosition;

void main(void) {
vec4 tpos = uMVMatrix * vec4(aVertexPosition, 1.0);
vPosition = tpos.xyz;
gl_Position = uPMatrix * tpos;

// vTextureCoord = aTextureCoord;
tpos = uMVMatrix * vec4(aVertexNormal, 0.0);
vTransformedNormal = tpos.xyz;
}
</script>

<script id="phong-fs" type="x-shader/x-fragment">
precision highp float;
// varying vec2 vTextureCoord;
varying vec4 vTransformedNormal;
varying vec4 vPosition;
varying vec3 vTransformedNormal;
varying vec3 vPosition;

uniform bool uUseLighting;
uniform bool uTwoSided;
Expand All @@ -23,9 +51,10 @@
vec3 lightWeighting;
if (!uUseLighting) {
lightWeighting = vec3(1.0, 1.0, 1.0);
} else {
vec3 lightDirection = normalize(uPointLightingLocation - vPosition.xyz);
vec3 normal = normalize(vTransformedNormal.xyz);
}
else {
vec3 lightDirection = normalize(uPointLightingLocation - vPosition);
vec3 normal = normalize(vTransformedNormal);

float specularLightWeighting = 0.0;

Expand All @@ -34,39 +63,66 @@
diffuseLightWeighting = abs(diffuseLightWeighting);
diffuseLightWeighting = max(diffuseLightWeighting, 0.0);

lightWeighting = uAmbientColor
+ uPointLightingDiffuseColor * diffuseLightWeighting;
lightWeighting = uAmbientColor + uPointLightingDiffuseColor * diffuseLightWeighting;
}

gl_FragColor = vec4(uGlobColor.rgb * lightWeighting, uGlobColor.a);

}
</script>

<script id="phong-vs" type="x-shader/x-vertex">
<script id="bkg-vs" type="x-shader/x-vertex">
precision highp float;

attribute vec3 aVertexPosition;
attribute vec3 aVertexNormal;
// attribute vec2 aTextureCoord;

uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
//uniform mat4 uNMatrix;
uniform vec4 uGlobColor;

// varying vec2 vTextureCoord;
varying vec4 vTransformedNormal;
varying vec4 vPosition;

void main(void) {
vPosition = uMVMatrix * vec4(aVertexPosition, 1.0);
gl_Position = uPMatrix * vPosition;
varying vec3 pos;

// vTextureCoord = aTextureCoord;
//vTransformedNormal = uNMatrix * vec4(aVertexNormal, 1.0);
vTransformedNormal = uMVMatrix * vec4(aVertexNormal, 0.0);
void main(void) {
pos = aVertexPosition;
gl_Position = uPMatrix * uMVMatrix * vec4(aVertexPosition, 1.0);
}
</script>

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

#define L1 0.2,0.2,1.0, 1.0,3.0,+1.0,0.07, 5.0,+1.0,0.5, vec3(0.2,0.0,0.5)
#define L2 0.2,0.2,1.0, 0.0,2.1,+1.5,0.05, 7.0,-0.5,0.2, vec3(0.2,0.0,0.5)
#define L3 -0.2,-0.2,1.0, 0.0,2.5,+1.1,0.1, 6.0,-1.0,0.2, vec3(0.1,0.0,0.4)
#define L4 -0.2,-0.2,1.0, 1.0,3.5,-1.1,0.06, 8.0,1.0,0.3, vec3(0.1,0.0,0.4)

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

vec3 makeLine(float ax, float ay, float az,
float hOffs, float hRep, float hTimeMult, float hSlit,
float dPiDiv, float dTimeMult, float dSlit,
vec3 color,
float t, float at)
{
bool p = true;
float a = az*pos.z + ay*pos.y + ax*pos.x;
p = p && (mfmod(abs(a + t*hTimeMult) + hOffs, hRep) < hSlit);
float deg = mfmod(abs(at + t*dTimeMult), 3.14126 / dPiDiv);
p = p && (deg < dSlit);
return float(p) * color;
}

void main() {
float t = time / 4.0;
vec3 c = vec3(0.0, 0.0, 0.0);
float at = atan(pos.x / pos.y);
c += makeLine(L1, t, at);
c += makeLine(L2, t, at);
c += makeLine(L3, t, at);
c += makeLine(L4, t, at);

gl_FragColor = vec4(c, 1.0);
}
</script>

<body></body></html>
48 changes: 43 additions & 5 deletions src/aiControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var AiLevels = [
// created in startLife
function Ai(player, level)
{
this.player = player;
this.player = player; // player object
var ailevel = AiLevels[level];

this.stepsAhead = ailevel.stepsAhead;
Expand All @@ -36,7 +36,9 @@ function isOccupied(point) {
return (w !== undefined && w >= 0) // (occupied) can be equal to 0.. for player 0
}

Ai.prototype.turnToAvailableSide = function(nei)


Ai.prototype.turnToAvailableSide = function(nei, fwdBlocked)
{
this.occRight = isOccupied(nei.toRight);
this.occLeft = isOccupied(nei.toLeft);
Expand All @@ -45,7 +47,8 @@ Ai.prototype.turnToAvailableSide = function(nei)
return; // we're screwed, nothing to do but die.
if (!this.occRight && !this.occLeft)
{ // both are clear, choose one

if (fwdBlocked && this.checkWallHeading(nei)) // returns true if made a decision
return;
if (this.checkFarBlocks()) // returns true if made a decision
return;
if (randomChoise(0.5))
Expand Down Expand Up @@ -99,6 +102,41 @@ function countFree(vw, togo, went) {
return went;
}

function pieceIsPlayer(piece, playerId) {
return piece >= 100 && piece < 200 && (piece - 100 == playerId);
}

Ai.prototype.checkWallHeading = function (nei) {
var thisPlayerId = this.player.id;
var fwdVal = world.map.get(nei.toFwd);
var fwdPiece = PieceMap.piece(fwdVal);
if (!pieceIsPlayer(fwdPiece, thisPlayerId)) {
return false; // only consider my wall
}
var fwdWc = PieceMap.meta(fwdVal); // wall-count

var p = this.player.point, l = this.player.last.point;
this.look.init(p, l).goLeft();
this.look.goRight();
var leftPnt = this.look.point;
this.look.init(p, l).goRight();
this.look.goLeft();
var rightPnt = this.look.point;

var leftVal = world.map.get(leftPnt), rightVal = world.map.get(rightPnt);
var leftPiece = PieceMap.piece(leftVal), rightPiece = PieceMap.piece(rightVal);
var leftWc = PieceMap.meta(leftVal), rightWc = PieceMap.meta(rightVal);
writeDebug("wall-h " + leftPiece + ":" + leftWc + " - " + rightPiece + ":" + rightWc);
if (!pieceIsPlayer(leftPiece, thisPlayerId) || !pieceIsPlayer(rightPiece, thisPlayerId))
return false;

if (leftWc < fwdWc)
this.turnLeft();
else
this.turnRight();
return true;
}


// advance several steps forward, right and left to see if there is something blocking
Ai.prototype.checkFarBlocks = function()
Expand Down Expand Up @@ -129,13 +167,13 @@ Ai.prototype.moveControl = function(world)
var occFwd = isOccupied(nei.toFwd);
if (occFwd) // the point up ahead is occupied
{
this.turnToAvailableSide(nei);
this.turnToAvailableSide(nei, true);
return;
}

// random turning for no reason (2% chance)
if (randomChoise(2)) {
this.turnToAvailableSide(nei);
this.turnToAvailableSide(nei, false);
return;
}

Expand Down
Loading

0 comments on commit 92cbf53

Please sign in to comment.