Skip to content

Commit

Permalink
Only mark deadcells as called within an element type
Browse files Browse the repository at this point in the history
closes #28
  • Loading branch information
Lazerbeak12345 committed Feb 16, 2022
1 parent 60ffe43 commit 76450f6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pixelmanipulator",
"version": "4.5.0",
"version": "4.5.1",
"description": "Run any cellular automata on an html5 canvas.",
"main": "pixelmanipulator.js",
"repository": "[email protected]:Lazerbeak12345/pixelmanipulator.git",
Expand All @@ -11,15 +11,13 @@
"cellular automata",
"game of life",
"highlife",
"brians brain",
"brians-brain",
"wireworld",
"wolfram",
"rule 30",
"rule 90",
"rule 110",
"rule 184",
"grid",
"engine",
"rule-30",
"rule-90",
"rule-110",
"rule-184",
"conway",
"pixel",
"game",
Expand All @@ -29,9 +27,11 @@
"automaton",
"gameoflife",
"gol",
"brian's brain",
"canvas",
"particle physics",
"simulation"
"brian's-brain",
"particle",
"simulation",
"engine",
"grid",
"canvas"
]
}
10 changes: 6 additions & 4 deletions pixelmanipulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// Concerning the function commments, # is number, [] means array, {} means object, () means function, true means boolean and, "" means string. ? means optional, seperated with : means that it could be one or the other
(function(g) {
'use strict';
var pxversion="4.5.0";
var pxversion="4.5.1";
function pix(require,exports,module) {//done like this for better support for things like require.js and Dojo
/*function ret(v) {
return (function() {
Expand Down Expand Up @@ -564,7 +564,7 @@
mooreNearbyCounter:innerP.__MooreNearbyCounter(confirmOldElm),
wolframNearbyCounter:innerP.__WolframNearbyCounter(confirmOldElm),
},
updatedDeadPixel=new Uint8Array(Math.ceil((w*h)/8));
typedUpdatedDead=new Array(innerP.elementNumList.length);
innerP.pixelCounts={};
for(var x=0;x<w;x++){
for(var y=0;y<h;y++){ //iterate through x and y
Expand All @@ -582,14 +582,16 @@
innerP.pixelCounts[currentPix]=1;
}else innerP.pixelCounts[currentPix]++;
if (typeof elm.deadCell==="function") {
if(!typedUpdatedDead[currentPixId])
typedUpdatedDead[currentPixId]=new Uint8Array(Math.ceil((w*h)/8));
for(var hi=0;hi<elm.hitbox.length;hi++){
var pixel=elm.hitbox[hi];
rel.x=(x+pixel.x)%w;
if(rel.x<0)rel.x+=w;
rel.y=(y+pixel.y)%h;
if(rel.y<0)rel.y+=h;
var index=Math.floor((w*rel.y+rel.x)/8),
oldValue=updatedDeadPixel[index],
oldValue=typedUpdatedDead[currentPixId][index],
bitMask=1<<(rel.x%8);
if((oldValue&bitMask)>0)
continue;
Expand All @@ -598,7 +600,7 @@
continue;
rel.oldId=innerP.defaultElm;
elm.deadCell(rel);
updatedDeadPixel[index]=oldValue|bitMask;
typedUpdatedDead[currentPixId][index]=oldValue|bitMask;
}
}
}
Expand Down

0 comments on commit 76450f6

Please sign in to comment.