Skip to content

Commit

Permalink
fixed gif export OOM
Browse files Browse the repository at this point in the history
improved location arrow
removed mouse pointer scaling
  • Loading branch information
freds72 committed Dec 5, 2020
1 parent 673c105 commit b78f875
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 50 deletions.
5 changes: 2 additions & 3 deletions carts/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,7 @@ function draw_flats(v_cache,segs)
end
if otherside then
-- visible other side walls?
otop=otherside[1].ceil>>4
obottom=otherside[1].floor>>4
otop,obottom=otherside[1].ceil>>4,otherside[1].floor>>4
-- offset animated walls (doors)
yoffset=0
if ldef.dontpegtop then
Expand Down Expand Up @@ -1360,7 +1359,7 @@ function _update()

_update_state()
-- capture video!
if(peek(0x5f83)==1) extcmd("video") poke(0x5f83)
if(peek(0x5f83)==1) poke(0x5f83,0) extcmd("video")
_slow+=1
end

Expand Down
14 changes: 6 additions & 8 deletions carts/title.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function next_state(fn,...)
u()

-- gif capture handling
if(peek(0x5f83)==1) extcmd("video") poke(0x5f83)
if(peek(0x5f83)==1) poke(0x5f83,0) extcmd("video")
end
end

Expand Down Expand Up @@ -279,7 +279,7 @@ function launch_state(skill,id,level_time,kills,secrets)
rect(63-#s*2-2,texty-2,63+#s*2,texty+6,15)

-- left or right anchor
local xanchor=x<64 and 63-#s*2-2 or 63+#s*2
local xanchor=mid(x<64 and 63-#s*2-2 or 63+#s*2,32,96)
line(xanchor,texty+6,xanchor,y,15)
line(x,y)
circfill(x,y,2)
Expand All @@ -292,9 +292,7 @@ end


function credits_state()
local ttl=0
local dither_pat={0b1111111111111111,0b0111111111111111,0b0111111111011111,0b0101111111011111,0b0101111101011111,0b0101101101011111,0b0101101101011110,0b0101101001011110,0b0101101001011010,0b0001101001011010,0b0001101001001010,0b0000101001001010,0b0000101000001010,0b0000001000001010,0b0000001000001000,0b0000000000000000}
local t,creditsi={},0
local ttl,t,creditsi=0,{},0
return
-- update
function()
Expand Down Expand Up @@ -332,14 +330,14 @@ function credits_state()
local j=max(flr(#st*t[i]/3))+1
sp=sp..sub(st,j,j)
end
print(sp,64-#sp*2,80,4)
print(sp,64-#sp*2,80,15)

if(ttl>0 and time()%4<2) print("🅾️/❎\23MENU",44,122,4)
if(ttl>0 and time()%4<2) print("🅾️/❎\23MENU",44,122,15)

pal(endgame_gfx.pal,1)
end,
function()
endgame_gfx.pal[15]=0
endgame_gfx.pal[15]=1
unpack_gfx(endgame_gfx)
end
end
Expand Down
138 changes: 99 additions & 39 deletions plates/fps.html
Original file line number Diff line number Diff line change
Expand Up @@ -229,35 +229,32 @@
}

function track_mouse(e) {

// enable mouse reading
pico8_gpio[0] = 1;
// clamp value to -127/127
var canvas = document.getElementById("canvas");
var scale = 128 / canvas.width;
pico8_gpio[1] = 128 - Math.min(Math.max(-127,Math.round(scale * e.movementX)),127);
pico8_gpio[2] = 128 - Math.min(Math.max(-127,Math.round(scale * e.movementY)),127);
pico8_gpio[1] = 128 - Math.min(Math.max(-127,Math.round(e.movementX)),127);
pico8_gpio[2] = 128 - Math.min(Math.max(-127,Math.round(e.movementY)),127);
}

function track_click(e, step) {
if (!p8_is_running) return;
if (!p8_is_running) return;

// clear fire button
pico8_buttons[0] = 0;
// clear fire button
pico8_buttons[0] = 0;

// left (fire/ok)
if(e.buttons & 0x1) {
pico8_buttons[0] |= 0x10;
}
// right (open/cancel)
if(e.buttons & (0x2|0x8)) {
pico8_buttons[0] |= 0x20;
}
// middle
if(e.buttons & 0x4) {
pico8_buttons[0] |= 0x40;
// left (fire/ok)
if(e.buttons & 0x1) {
pico8_buttons[0] |= 0x10;
}
// right (open/cancel)
if(e.buttons & (0x2|0x8)) {
pico8_buttons[0] |= 0x20;
}
// middle
if(e.buttons & 0x4) {
pico8_buttons[0] |= 0x40;
}
}
}

// p8_update_layout_hash is used to decide when to update layout (expensive especially when part of a heavy page)
var p8_update_layout_hash = -1;
Expand Down Expand Up @@ -552,8 +549,8 @@
addEventListener("touchmove", function(event){ pico8_buttons_event(event, 1); }, {passive: false});
addEventListener("touchend", function(event){ pico8_buttons_event(event, 2); }, {passive: false});

// https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API
if(!p8_touch_detected) {
// https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API
if(!p8_touch_detected) {
// pointer lock object forking for cross browser
var canvas = document.getElementById("canvas");

Expand All @@ -562,30 +559,51 @@

document.exitPointerLock = document.exitPointerLock ||
document.mozExitPointerLock;

canvas.onclick = function() {
canvas.requestPointerLock();
};


canvas.addEventListener("click", function() {
// need to watch: https://www.chromestatus.com/feature/5723553087356928
canvas.requestPointerLock();
});

// pointer lock event listeners
function lockChangeAlert() {
if (document.pointerLockElement === canvas ||
document.mozPointerLockElement === canvas) {
document.addEventListener("mousemove", track_mouse, false);
document.addEventListener("mousedown", function(event){ track_click(event, 0); });
document.addEventListener("mouseup", function(event){ track_click(event, 1); });
canvas.addEventListener("mousemove", track_mouse, false);
canvas.addEventListener("mousedown", function(event){ track_click(event, 0); });
canvas.addEventListener("mouseup", function(event){ track_click(event, 1); });
} else {
// reset mouse values
pico8_gpio[0]=0
pico8_gpio[1]=0
document.removeEventListener("mousemove", track_mouse, false);
canvas.removeEventListener("mousemove", track_mouse, false);
// document.removeEventListener("click", function(event){ track_click(event, 0); }, false);
}
}

// Hook pointer lock state change events for different browsers
document.addEventListener('pointerlockchange', lockChangeAlert, false);
document.addEventListener('mozpointerlockchange', lockChangeAlert, false);

// gif clear handling
// https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
// Select the node that will be observed for mutations
const gifsNode = document.getElementById('p8_desktop');
const trashNode = document.getElementById('p8b_trash');

// Options for the observer (which mutations to observe)
const config = { childList: true };

// Callback function to execute when mutations are observed
const callback = function(mutationsList, observer) {
trashNode.style.display = gifsNode.childElementCount==0?"none":"table";
};

// Create an observer instance linked to the callback function
const observer = new MutationObserver(callback);

// Start observing the target node for configured mutations
observer.observe(gifsNode, config);
}

// load and run script
Expand Down Expand Up @@ -671,13 +689,31 @@
// key blocker. prevent cursor keys from scrolling page while playing cart.
// also don't act on M, R so that can mute / reset cart
document.addEventListener('keydown',
function (event) {
event = event || window.event;
if (!p8_is_running) return;
if (pico8_state.has_focus == 1)
if ([32, 37, 38, 39, 40, 77, 82, 80, 9].indexOf(event.keyCode) > -1) // block cursors, M R P, tab
if (event.preventDefault) event.preventDefault();
},{passive: false});
function (event) {
event = event || window.event;
if (!p8_is_running) return;
if (pico8_state.has_focus == 1) {
if(event.keyCode==32) {
// gpio pin 3 contains "use" button code
pico8_buttons[0] |= pico8_gpio[3];
}

if ([37, 38, 39, 40, 77, 82, 80, 9].indexOf(event.keyCode) > -1) // block cursors, M R P, tab
if (event.preventDefault) event.preventDefault();
}

},{passive: false});

document.addEventListener('keyup',
function (event) {
event = event || window.event;
if (!p8_is_running) return;
if (pico8_state.has_focus == 1)
if(event.keyCode==32) {
pico8_buttons[0] &= ~pico8_gpio[3];
if (event.preventDefault) event.preventDefault();
}
},{passive: false});

// when using codo_textarea to determine focus, need to explicitly hand focus back when clicking a p8_menu_button
function p8_give_focus()
Expand Down Expand Up @@ -741,6 +777,26 @@
opacity:1.0;
cursor:pointer;
}

.p8_trash_button{
opacity:0.3;
padding:4px;
display:table;
width:24px;
height:24px;
float:right;
}

@media screen and (min-width:512px) {
.p8_trash_button{
width:24px; margin-left:12px; margin-bottom:8px;
}
}

.p8_trash_button:hover{
opacity:1.0;
cursor:pointer;
}

canvas{
image-rendering: optimizeSpeed;
Expand Down Expand Up @@ -787,7 +843,9 @@
<!-- Add any content above the cart here -->


<div id="p8_desktop" style="display:block; position:absolute; top:10px; left:10px"></div> <!-- desktop for saving gifs / screenshots -->
<div class="p8_trash_button" style="display:none; position:absolute; top:20px; left:129px" id="p8b_trash" onclick="document.getElementById('p8_desktop').innerHTML = '';"><img src="img/trash.png"></div>
<div id="p8_desktop" style="display:block; position:absolute; top:20px; left:10px"></div> <!-- desktop for saving gifs / screenshots -->

<div id="p8_frame_0" style="max-width:800px; max-height:800px; margin:auto;"> <!-- double function: limit size, and display only this div for touch devices -->
<div id="p8_frame" style="display:flex; width:100%; max-width:95vw; height:100vw; max-height:95vh; margin:auto;">

Expand Down Expand Up @@ -820,6 +878,8 @@
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault();" >
</canvas>
<div class=p8_menu_buttons id="p8_menu_buttons" style="margin-left:10px;">
<!-- triggers pico8 native gif capture -->
<div class="p8_menu_button" style="position:absolute; bottom:165px" id="p8b_snap" onmousedown="document.getElementById('p8_desktop').innerHTML = '';" onmouseup="pico8_gpio[3]=1;"></div>
<div class="p8_menu_button" style="position:absolute; bottom:125px" id="p8b_controls" onClick="p8_give_focus(); Module.pico8ToggleControlMenu();"></div>
<div class="p8_menu_button" style="position:absolute; bottom:90px" id="p8b_pause" onClick="p8_give_focus(); Module.pico8TogglePaused(); p8_update_layout_hash = -22;"></div>
<div class="p8_menu_button" style="position:absolute; bottom:55px" id="p8b_sound" onClick="p8_give_focus(); p8_create_audio_context(); Module.pico8ToggleSound();"></div>
Expand Down

0 comments on commit b78f875

Please sign in to comment.