done merging draw thread with update thread
This commit is contained in:
@@ -1,2 +1,2 @@
|
|||||||
structure MailboxType =
|
structure MailboxType =
|
||||||
struct datatype t = DRAW of DrawMsg.t | SEARCH of LineGap.t * string * Time.time end
|
struct datatype t = DRAW of DrawMsg.t | SEARCH of SearchMsg.t end
|
||||||
|
|||||||
1
message-types/search-msg.sml
Normal file
1
message-types/search-msg.sml
Normal file
@@ -0,0 +1 @@
|
|||||||
|
structure SearchMsg = struct type t = LineGap.t * string * Time.time end
|
||||||
@@ -21,7 +21,6 @@ struct
|
|||||||
, bgProgram: Word32.word
|
, bgProgram: Word32.word
|
||||||
, bgDrawLength: int
|
, bgDrawLength: int
|
||||||
|
|
||||||
, drawMailbox: DrawMsg.t Mailbox.mbox
|
|
||||||
, window: MLton.Pointer.t
|
, window: MLton.Pointer.t
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +43,7 @@ struct
|
|||||||
program
|
program
|
||||||
end
|
end
|
||||||
|
|
||||||
fun create (drawMailbox, window) =
|
fun create window =
|
||||||
let
|
let
|
||||||
(* create vertex buffer, program, etc. for text. *)
|
(* create vertex buffer, program, etc. for text. *)
|
||||||
val textVertexBuffer = Gles3.createBuffer ()
|
val textVertexBuffer = Gles3.createBuffer ()
|
||||||
@@ -80,7 +79,6 @@ struct
|
|||||||
, bgProgram = bgProgram
|
, bgProgram = bgProgram
|
||||||
, bgDrawLength = 0
|
, bgDrawLength = 0
|
||||||
|
|
||||||
, drawMailbox = drawMailbox
|
|
||||||
, window = window
|
, window = window
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@@ -98,7 +96,6 @@ struct
|
|||||||
, bgProgram
|
, bgProgram
|
||||||
, bgDrawLength
|
, bgDrawLength
|
||||||
, window
|
, window
|
||||||
, drawMailbox
|
|
||||||
} = shellState
|
} = shellState
|
||||||
|
|
||||||
val _ = Gles3.bindBuffer textVertexBuffer
|
val _ = Gles3.bindBuffer textVertexBuffer
|
||||||
@@ -114,7 +111,6 @@ struct
|
|||||||
, bgVertexBuffer = bgVertexBuffer
|
, bgVertexBuffer = bgVertexBuffer
|
||||||
, bgProgram = bgProgram
|
, bgProgram = bgProgram
|
||||||
, bgDrawLength = bgDrawLength
|
, bgDrawLength = bgDrawLength
|
||||||
, drawMailbox = drawMailbox
|
|
||||||
, window = window
|
, window = window
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@@ -132,7 +128,6 @@ struct
|
|||||||
, bgProgram
|
, bgProgram
|
||||||
, bgDrawLength
|
, bgDrawLength
|
||||||
, window
|
, window
|
||||||
, drawMailbox
|
|
||||||
} = shellState
|
} = shellState
|
||||||
|
|
||||||
val _ = Gles3.bindBuffer cursorVertexBuffer
|
val _ = Gles3.bindBuffer cursorVertexBuffer
|
||||||
@@ -148,7 +143,6 @@ struct
|
|||||||
, bgVertexBuffer = bgVertexBuffer
|
, bgVertexBuffer = bgVertexBuffer
|
||||||
, bgProgram = bgProgram
|
, bgProgram = bgProgram
|
||||||
, bgDrawLength = bgDrawLength
|
, bgDrawLength = bgDrawLength
|
||||||
, drawMailbox = drawMailbox
|
|
||||||
, window = window
|
, window = window
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@@ -166,7 +160,6 @@ struct
|
|||||||
, bgProgram
|
, bgProgram
|
||||||
, bgDrawLength = _
|
, bgDrawLength = _
|
||||||
, window
|
, window
|
||||||
, drawMailbox
|
|
||||||
} = shellState
|
} = shellState
|
||||||
|
|
||||||
val _ = Gles3.bindBuffer bgVertexBuffer
|
val _ = Gles3.bindBuffer bgVertexBuffer
|
||||||
@@ -182,7 +175,6 @@ struct
|
|||||||
, bgVertexBuffer = bgVertexBuffer
|
, bgVertexBuffer = bgVertexBuffer
|
||||||
, bgProgram = bgProgram
|
, bgProgram = bgProgram
|
||||||
, bgDrawLength = newBgDrawLength
|
, bgDrawLength = newBgDrawLength
|
||||||
, drawMailbox = drawMailbox
|
|
||||||
, window = window
|
, window = window
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@@ -240,14 +232,8 @@ struct
|
|||||||
|
|
||||||
fun consumeDrawEvent (shellState, msg) =
|
fun consumeDrawEvent (shellState, msg) =
|
||||||
let
|
let
|
||||||
val
|
val {textVertexBuffer, textProgram, window, textDrawLength = _, ...} =
|
||||||
{ textVertexBuffer
|
shellState
|
||||||
, textProgram
|
|
||||||
, window
|
|
||||||
, drawMailbox
|
|
||||||
, textDrawLength = _
|
|
||||||
, ...
|
|
||||||
} = shellState
|
|
||||||
in
|
in
|
||||||
case msg of
|
case msg of
|
||||||
REDRAW_TEXT textVec => uploadText (shellState, textVec)
|
REDRAW_TEXT textVec => uploadText (shellState, textVec)
|
||||||
@@ -256,15 +242,39 @@ struct
|
|||||||
| YANK str => yank (shellState, str)
|
| YANK str => yank (shellState, str)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun consumeDrawEvents (shellState as {drawMailbox, ...}: t) =
|
local
|
||||||
case Mailbox.recvPoll drawMailbox of
|
fun loop (pos, msgVec, shellState) =
|
||||||
NONE => shellState
|
if pos = Vector.length msgVec then
|
||||||
| SOME msg =>
|
shellState
|
||||||
let val shellState = consumeDrawEvent (shellState, msg)
|
else
|
||||||
in consumeDrawEvents shellState
|
let
|
||||||
|
val msg = Vector.sub (msgVec, pos)
|
||||||
|
val shellState = consumeDrawEvent (shellState, msg)
|
||||||
|
in
|
||||||
|
loop (pos + 1, msgVec, shellState)
|
||||||
|
end
|
||||||
|
in
|
||||||
|
fun consumeDrawEvents shellState =
|
||||||
|
loop (0, DrawMailbox.getMessagesAndClear (), shellState)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun helpLoop (shellState as {window, ...}: t) =
|
local
|
||||||
|
fun updateLoop (pos, msgVec, app) =
|
||||||
|
if pos = Vector.length msgVec then
|
||||||
|
app
|
||||||
|
else
|
||||||
|
let
|
||||||
|
val msg = Vector.sub (msgVec, pos)
|
||||||
|
val app = UpdateThread.update (app, msg)
|
||||||
|
in
|
||||||
|
updateLoop (pos + 1, msgVec, app)
|
||||||
|
end
|
||||||
|
in
|
||||||
|
fun update app =
|
||||||
|
updateLoop (0, InputMailbox.getMessagesAndClear (), app)
|
||||||
|
end
|
||||||
|
|
||||||
|
fun helpLoop (app, shellState as {window, ...}: t) =
|
||||||
case Glfw.windowShouldClose window of
|
case Glfw.windowShouldClose window of
|
||||||
false =>
|
false =>
|
||||||
let
|
let
|
||||||
@@ -273,17 +283,18 @@ struct
|
|||||||
val _ = Gles3.clearColor (0.087, 0.095, 0.13, 1.0)
|
val _ = Gles3.clearColor (0.087, 0.095, 0.13, 1.0)
|
||||||
val _ = Gles3.clear ()
|
val _ = Gles3.clear ()
|
||||||
|
|
||||||
|
val app = update app
|
||||||
val _ = draw shellState
|
val _ = draw shellState
|
||||||
|
|
||||||
val _ = Glfw.swapBuffers window
|
val _ = Glfw.swapBuffers window
|
||||||
val _ = Glfw.waitEvents ()
|
val _ = Glfw.waitEvents ()
|
||||||
in
|
in
|
||||||
helpLoop shellState
|
helpLoop (app, shellState)
|
||||||
end
|
end
|
||||||
| true => Glfw.terminate ()
|
| true => Glfw.terminate ()
|
||||||
|
|
||||||
fun loop (drawMailbox, window) =
|
fun loop (app, window) =
|
||||||
let val shellState = create (drawMailbox, window)
|
let val shellState = create window
|
||||||
in helpLoop shellState
|
in helpLoop (app, shellState)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
2
shell/search-mailbox.sml
Normal file
2
shell/search-mailbox.sml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
structure SearchMailbox =
|
||||||
|
struct open CML val mailbox: SearchMsg.t Mailbox.mbox = Mailbox.mailbox () end
|
||||||
@@ -3,13 +3,13 @@ struct
|
|||||||
open CML
|
open CML
|
||||||
|
|
||||||
(* Prerequisite to sending message: move buffer to end. *)
|
(* Prerequisite to sending message: move buffer to end. *)
|
||||||
fun loop (searchMailbox, inputMailbox) =
|
fun loop () =
|
||||||
let
|
let
|
||||||
val (buffer, searchString, time) = Mailbox.recv searchMailbox
|
val (buffer, searchString, time) = Mailbox.recv SearchMailbox.mailbox
|
||||||
val searchList = SearchList.build (buffer, searchString)
|
val searchList = SearchList.build (buffer, searchString)
|
||||||
val msg = InputMsg.WITH_SEARCH_LIST (searchList, time)
|
val msg = InputMsg.WITH_SEARCH_LIST (searchList, time)
|
||||||
val () = Mailbox.send (inputMailbox, msg)
|
val () = InputMailbox.append msg
|
||||||
in
|
in
|
||||||
loop (searchMailbox, inputMailbox)
|
loop ()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,22 +1,16 @@
|
|||||||
structure Shell =
|
structure Shell =
|
||||||
struct
|
struct
|
||||||
open CML
|
|
||||||
open InputMsg
|
open InputMsg
|
||||||
|
|
||||||
(* create mailboxes for CML communication *)
|
|
||||||
val inputMailbox = Mailbox.mailbox ()
|
|
||||||
val drawMailbox = Mailbox.mailbox ()
|
|
||||||
val searchMailbox = Mailbox.mailbox ()
|
|
||||||
|
|
||||||
fun frameBufferSizeCallback (width, height) =
|
fun frameBufferSizeCallback (width, height) =
|
||||||
Mailbox.send (inputMailbox, RESIZE_EVENT (width, height))
|
InputMailbox.append (RESIZE_EVENT (width, height))
|
||||||
|
|
||||||
fun charCallback word =
|
fun charCallback word =
|
||||||
let
|
let
|
||||||
val word = Word32.toInt word
|
val word = Word32.toInt word
|
||||||
val chr = Char.chr word
|
val chr = Char.chr word
|
||||||
in
|
in
|
||||||
Mailbox.send (inputMailbox, CHAR_EVENT chr)
|
InputMailbox.append (CHAR_EVENT chr)
|
||||||
end
|
end
|
||||||
|
|
||||||
fun keyCallback (key, scancode, action, mods) =
|
fun keyCallback (key, scancode, action, mods) =
|
||||||
@@ -24,19 +18,19 @@ struct
|
|||||||
open Input
|
open Input
|
||||||
in
|
in
|
||||||
if key = KEY_ESC andalso action = PRESS andalso mods = 0 then
|
if key = KEY_ESC andalso action = PRESS andalso mods = 0 then
|
||||||
Mailbox.send (inputMailbox, InputMsg.KEY_ESC)
|
InputMailbox.append (InputMsg.KEY_ESC)
|
||||||
else if key = KEY_ENTER andalso action = PRESS andalso mods = 0 then
|
else if key = KEY_ENTER andalso action = PRESS andalso mods = 0 then
|
||||||
Mailbox.send (inputMailbox, InputMsg.KEY_ENTER)
|
InputMailbox.append (InputMsg.KEY_ENTER)
|
||||||
else if key = KEY_BACKSPACE andalso action <> RELEASE andalso mods = 0 then
|
else if key = KEY_BACKSPACE andalso action <> RELEASE andalso mods = 0 then
|
||||||
Mailbox.send (inputMailbox, InputMsg.KEY_BACKSPACE)
|
InputMailbox.append (InputMsg.KEY_BACKSPACE)
|
||||||
else if key = KEY_ARROW_LEFT andalso action <> RELEASE andalso mods = 0 then
|
else if key = KEY_ARROW_LEFT andalso action <> RELEASE andalso mods = 0 then
|
||||||
Mailbox.send (inputMailbox, InputMsg.ARROW_LEFT)
|
InputMailbox.append (InputMsg.ARROW_LEFT)
|
||||||
else if key = KEY_ARROW_RIGHT andalso action <> RELEASE andalso mods = 0 then
|
else if key = KEY_ARROW_RIGHT andalso action <> RELEASE andalso mods = 0 then
|
||||||
Mailbox.send (inputMailbox, InputMsg.ARROW_RIGHT)
|
InputMailbox.append (InputMsg.ARROW_RIGHT)
|
||||||
else if key = KEY_ARROW_UP andalso action <> RELEASE andalso mods = 0 then
|
else if key = KEY_ARROW_UP andalso action <> RELEASE andalso mods = 0 then
|
||||||
Mailbox.send (inputMailbox, InputMsg.ARROW_UP)
|
InputMailbox.append (InputMsg.ARROW_UP)
|
||||||
else if key = KEY_ARROW_DOWN andalso action <> RELEASE andalso mods = 0 then
|
else if key = KEY_ARROW_DOWN andalso action <> RELEASE andalso mods = 0 then
|
||||||
Mailbox.send (inputMailbox, InputMsg.ARROW_DOWN)
|
InputMailbox.append (InputMsg.ARROW_DOWN)
|
||||||
else
|
else
|
||||||
()
|
()
|
||||||
end
|
end
|
||||||
@@ -76,26 +70,10 @@ struct
|
|||||||
val _ = TextIO.closeIn io
|
val _ = TextIO.closeIn io
|
||||||
val app = AppType.init (lineGap, 1920, 1080, Time.now ())
|
val app = AppType.init (lineGap, 1920, 1080, Time.now ())
|
||||||
|
|
||||||
(* todo: remove temp line below which tests search list *)
|
|
||||||
val app =
|
|
||||||
let
|
|
||||||
val buffer = #buffer app
|
|
||||||
val buffer = LineGap.goToStart buffer
|
|
||||||
val searchString = "val "
|
|
||||||
val searchList = SearchList.build (buffer, searchString)
|
|
||||||
val buffer = LineGap.goToStart buffer
|
|
||||||
in
|
|
||||||
NormalModeWith.searchList
|
|
||||||
(app, searchList, buffer, searchString, Time.now ())
|
|
||||||
end
|
|
||||||
|
|
||||||
val () = registerCallbacks window
|
val () = registerCallbacks window
|
||||||
|
|
||||||
val _ = CML.spawn (fn () => GlDraw.loop (drawMailbox, window))
|
val _ = CML.spawn (fn () => GlDraw.loop (app, window))
|
||||||
val _ = CML.spawn (fn () =>
|
val _ = CML.spawn SearchThread.loop
|
||||||
UpdateThread.loop (app, inputMailbox, drawMailbox, searchMailbox))
|
|
||||||
val _ = CML.spawn (fn () =>
|
|
||||||
SearchThread.loop (searchMailbox, inputMailbox))
|
|
||||||
in
|
in
|
||||||
()
|
()
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,32 +4,28 @@ struct
|
|||||||
open MailboxType
|
open MailboxType
|
||||||
open InputMsg
|
open InputMsg
|
||||||
|
|
||||||
fun sendMsg (msg, drawMailbox, searchMailbox) =
|
fun sendMsg msg =
|
||||||
case msg of
|
case msg of
|
||||||
DRAW msg => Mailbox.send (drawMailbox, msg)
|
DRAW msg => DrawMailbox.append msg
|
||||||
| SEARCH (buffer, searchString, time) =>
|
| SEARCH (buffer, searchString, time) =>
|
||||||
Mailbox.send (searchMailbox, (buffer, searchString, time))
|
Mailbox.send (SearchMailbox.mailbox, (buffer, searchString, time))
|
||||||
|
|
||||||
fun sendMsgs (msgList, drawMailbox, searchMailbox) =
|
fun sendMsgs msgList =
|
||||||
case msgList of
|
case msgList of
|
||||||
hd :: tl =>
|
hd :: tl => let val () = sendMsg hd in sendMsgs tl end
|
||||||
let val _ = sendMsg (hd, drawMailbox, searchMailbox)
|
|
||||||
in sendMsgs (tl, drawMailbox, searchMailbox)
|
|
||||||
end
|
|
||||||
| [] => ()
|
| [] => ()
|
||||||
|
|
||||||
fun loop (app: AppType.app_type, inputMailbox, drawMailbox, searchMailbox) =
|
fun update (app: AppType.app_type, inputMsg) =
|
||||||
let
|
let
|
||||||
val time = Time.now ()
|
val time = Time.now ()
|
||||||
val inputMsg = Mailbox.recv inputMailbox
|
|
||||||
|
|
||||||
val () = ExceptionLogger.addCommand inputMsg
|
val () = ExceptionLogger.addCommand inputMsg
|
||||||
|
|
||||||
val app = AppUpdate.update (app, inputMsg, time)
|
val app = AppUpdate.update (app, inputMsg, time)
|
||||||
handle e => ExceptionLogger.log e
|
handle e => ExceptionLogger.log e
|
||||||
|
|
||||||
val () = sendMsgs (#msgs app, drawMailbox, searchMailbox)
|
val () = sendMsgs (#msgs app)
|
||||||
in
|
in
|
||||||
loop (app, inputMailbox, drawMailbox, searchMailbox)
|
app
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
2
shf.mlb
2
shf.mlb
@@ -8,6 +8,7 @@ lib/cozette-sml/fonts/cozette-ascii.mlb
|
|||||||
(* FUNCTIONAL CORE *)
|
(* FUNCTIONAL CORE *)
|
||||||
message-types/input-msg.sml
|
message-types/input-msg.sml
|
||||||
message-types/draw-msg.sml
|
message-types/draw-msg.sml
|
||||||
|
message-types/search-msg.sml
|
||||||
message-types/mailbox-type.sml
|
message-types/mailbox-type.sml
|
||||||
|
|
||||||
ann
|
ann
|
||||||
@@ -73,6 +74,7 @@ in
|
|||||||
end
|
end
|
||||||
shell/input-mailbox.sml
|
shell/input-mailbox.sml
|
||||||
shell/draw-mailbox.sml
|
shell/draw-mailbox.sml
|
||||||
|
shell/search-mailbox.sml
|
||||||
|
|
||||||
shell/exception-logger.sml
|
shell/exception-logger.sml
|
||||||
shell/search-thread.sml
|
shell/search-thread.sml
|
||||||
|
|||||||
Reference in New Issue
Block a user