Skip to content

Commit

Permalink
standalone in 0.5 at feature parity with 0.4.x standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
dktr0 committed Sep 19, 2024
1 parent 9b9b875 commit 47d4858
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 60 deletions.
42 changes: 35 additions & 7 deletions index-0.5.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,58 @@

<script type="module">
import * as P from "./punctual.js";
window.footer = true;
window.info = false;
window.doLaunch = function () {
var cvs = document.getElementById('canvas');
window.punctual = new P.Punctual();
window.timeOfLastFPSUpdate = Date.now()/1000.0;
window.framesSinceFPSUpdate = 0;
window.requestAnimationFrame(animate);
setTimeout(updateFPS,1020);
}
function animate() {
window.requestAnimationFrame(animate);
var now = Date.now()/1000.0;
window.punctual.preRender({canDraw: true, nowTime: now});
window.punctual.render({canDraw: true, zone:0, nowTime: now});
window.punctual.postRender({canDraw: true, nowTime: now});
window.framesSinceFPSUpdate += 1;
}
function updateFPS() {
var now = Date.now()/1000.0;
var elapsed = now - window.timeOfLastFPSUpdate;
var fps = Math.round(window.framesSinceFPSUpdate/elapsed);
document.getElementById('fps').textContent = fps.toString() + " FPS";
setTimeout(updateFPS,1020);
}
window.doEval = function () {
var t = document.getElementById("editorArea").value;
window.punctual.define({zone:0,text:t,time: Date.now()/1000.0}).then( r => {
console.log(r);
document.getElementById('errors').textContent = r.error;
});
window.punctual.define({zone:0,text:t,time: Date.now()/1000.0})
.then( r => {
document.getElementById('info').textContent = r.info;
document.getElementById('errors').textContent = "";
})
.catch( e => {
var eString = e.toString();
document.getElementById('errors').textContent = eString;
});
}
window.addEventListener('keydown', function (e) {
e = e || window.event;
if(e.shiftKey && e.key=="Enter") {
e.preventDefault();
window.doEval();
}
if(e.ctrlKey && e.shiftKey && e.key=="F") {
window.footer = !window.footer;
document.getElementById('status').hidden = !window.footer;
}
if(e.ctrlKey && e.shiftKey && e.key=="Q") {
window.info = !window.info;
document.getElementById('info').hidden = !window.info;
}

});
</script>

Expand All @@ -56,9 +83,10 @@
gate 0.1 (maxp a (fb * 0.98)) >> add <> 5
</textarea>
</div>
<div class="status">
<!-- <button onClick="doEval()">eval</button> -->
<span id="errors"></span>
<pre class="info" id="info" hidden="true"></pre>
<div class="status" id="status">
<div class="errors" id="errors"></div>
<div class="fps" id="fps">-- FPS</div>
</div>
</div>
</body>
Expand Down
66 changes: 33 additions & 33 deletions punctual.js

Large diffs are not rendered by default.

22 changes: 13 additions & 9 deletions src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import Data.Newtype (unwrap)
import Control.Promise (fromAff,Promise)
import Effect.Class.Console (log)
import Effect.Class (liftEffect)
import Control.Monad.Error.Class (throwError)
import Effect.Exception (error)

import Signal (SignalInfo,emptySignalInfo)
import Program (Program,emptyProgram,programHasVisualOutput,programHasAudioOutput,programInfo)
Expand Down Expand Up @@ -52,21 +54,23 @@ launch = do
pure { sharedResources, programs, previousPrograms, programInfos, previousProgramInfos, combinedProgramInfo, webGLs, audioZones }


define :: Punctual -> { zone :: Int, time :: Number, text :: String } -> Effect (Promise { success :: Boolean, info :: String, error :: String })
define :: Punctual -> { zone :: Int, time :: Number, text :: String } -> Effect (Promise { info :: String })
define punctual args = fromAff $ do
log $ "define: " <> show args
-- log $ "define: " <> show args
t0 <- liftEffect $ nowDateTime
pr <- parseProgram punctual.sharedResources.libraries args.text (numberToDateTime args.time)
t1 <- liftEffect $ nowDateTime
log $ " parse time = " <> show (diff t1 t0 :: Milliseconds)
-- log $ " parse time = " <> show (diff t1 t0 :: Milliseconds)
case pr of
Left err -> do
log $ "error: " <> show err
pure { success: false, info: "", error: show err }
Right newProgram -> liftEffect $ _newProgramInZone punctual args.zone newProgram
let eString = show err
throwError $ error eString
Right newProgram -> do
info <- liftEffect $ _newProgramInZone punctual args.zone newProgram
pure { info }


_newProgramInZone :: Punctual -> Int -> Program -> Effect { success :: Boolean, info :: String, error :: String }
_newProgramInZone :: Punctual -> Int -> Program -> Effect String
_newProgramInZone punctual zone newProgram = do
programs <- read punctual.programs
previousPrograms <- read punctual.previousPrograms
Expand Down Expand Up @@ -99,14 +103,14 @@ _newProgramInZone punctual zone newProgram = do
case programHasAudioOutput newProgram of
true -> updateAudioForZone punctual zone newProgram
false -> deleteAudioForZone punctual zone
pure { success: true, info, error: "" }
pure info

_updateCombinedProgramInfo :: Punctual -> Effect Unit
_updateCombinedProgramInfo punctual = do
programsInfo <- fold <$> read punctual.programInfos
previousProgramsInfo <- fold <$> read punctual.previousProgramInfos
let combinedInfo = programsInfo <> previousProgramsInfo
log $ "_updateCombinedProgramInfo: " <> show combinedInfo
-- log $ "_updateCombinedProgramInfo: " <> show combinedInfo
write combinedInfo punctual.combinedProgramInfo

clear :: Punctual -> { zone :: Int } -> Effect Unit
Expand Down
20 changes: 9 additions & 11 deletions src/WebGL.purs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ updateFragmentShader glc tempo imgMap vidMap oldProg newProg = do
t0 <- nowDateTime
let shaderSrc = fragmentShader glc.webGL2 tempo imgMap vidMap oldProg newProg
t1 <- nowDateTime
log $ " GLSL transpile time = " <> show (diff t1 t0 :: Milliseconds)
-- log $ " GLSL transpile time = " <> show (diff t1 t0 :: Milliseconds)
glProg <- createProgram glc
vShader <- createVertexShader glc
attachShader glc glProg vShader
Expand All @@ -116,16 +116,14 @@ updateFragmentShader glc tempo imgMap vidMap oldProg newProg = do
linkProgram glc glProg
flush glc

-- WORKING HERE
vsStatus <- getShaderParameterCompileStatus glc vShader
vsLog <- getShaderInfoLog glc vShader
log $ " vertex shader status=" <> show vsStatus <> " log: " <> vsLog
fsStatus <- getShaderParameterCompileStatus glc fShader
fsLog <- getShaderInfoLog glc fShader
log $ " fragment shader status=" <> show fsStatus <> " log: " <> fsLog
pLog <- getProgramInfoLog glc glProg
log $ " program log: " <> pLog
--
-- vsStatus <- getShaderParameterCompileStatus glc vShader
-- vsLog <- getShaderInfoLog glc vShader
-- log $ " vertex shader status=" <> show vsStatus <> " log: " <> vsLog
-- fsStatus <- getShaderParameterCompileStatus glc fShader
-- fsLog <- getShaderInfoLog glc fShader
-- log $ " fragment shader status=" <> show fsStatus <> " log: " <> fsLog
-- pLog <- getProgramInfoLog glc glProg
-- log $ " program log: " <> pLog

pure $ Tuple shaderSrc glProg

Expand Down

0 comments on commit 47d4858

Please sign in to comment.