progress in handling variable window width/height (mostly only in imperative shell though)

This commit is contained in:
2024-12-16 00:58:59 +00:00
parent cc7f30f718
commit 20c4060124
7 changed files with 39 additions and 19 deletions

View File

@@ -236,7 +236,7 @@ struct
end end
end end
(* placeholder *) (* block is placeholder asset *)
fun getDrawVec ({x, y, ...}: player) = fun getDrawVec ({x, y, ...}: player, width, height) =
Block.lerp (x, y, realSize, realSize, 1920.0, 1080.0, 0.5, 0.5, 0.5) Block.lerp (x, y, realSize, realSize, width, height, 0.5, 0.5, 0.5)
end end

View File

@@ -23,6 +23,7 @@ struct
val {x, y, width, height, id = _} = wall val {x, y, width, height, id = _} = wall
val width = Real32.fromInt width val width = Real32.fromInt width
val height = Real32.fromInt height val height = Real32.fromInt height
val block = Block.lerp val block = Block.lerp
(x, y, width, height, winWidth, winHeight, 0.0, 0.0, 0.0) (x, y, width, height, winWidth, winHeight, 0.0, 0.0, 0.0)
val acc = block :: acc val acc = block :: acc
@@ -30,6 +31,6 @@ struct
helpGetDrawVec (pos + 1, wallVec, acc, winWidth, winHeight) helpGetDrawVec (pos + 1, wallVec, acc, winWidth, winHeight)
end end
fun getDrawVec wallVec = fun getDrawVec (wallVec, width, height) =
helpGetDrawVec (0, wallVec, [], 1920.0, 1080.0) helpGetDrawVec (0, wallVec, [], width, height)
end end

View File

@@ -158,6 +158,7 @@ extern "C" {
#endif #endif
MLLIB_PUBLIC(void mltonKeyCallback (Int32 x0, Int32 x1, Int32 x2, Int32 x3);) MLLIB_PUBLIC(void mltonKeyCallback (Int32 x0, Int32 x1, Int32 x2, Int32 x3);)
MLLIB_PUBLIC(void mltonFramebufferSizeCallback (Real32 x0, Real32 x1);)
#undef MLLIB_PRIVATE #undef MLLIB_PRIVATE
#undef MLLIB_PUBLIC #undef MLLIB_PUBLIC

View File

@@ -18,3 +18,13 @@ void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods
void setKeyCallback(GLFWwindow* window) { void setKeyCallback(GLFWwindow* window) {
glfwSetKeyCallback(window, keyCallback); glfwSetKeyCallback(window, keyCallback);
} }
void framebufferSizeCallback(GLFWwindow* window, int width, int height) {
glViewport(0, 0, width, height);
mltonFramebufferSizeCallback((float) width, (float) height);
}
void setFramebufferSizeCallback(GLFWwindow* window) {
glfwSetFramebufferSizeCallback(window, framebufferSizeCallback);
}

View File

@@ -31,4 +31,9 @@ struct
_export "mltonKeyCallback" public : (int * int * int * int -> unit) -> unit; _export "mltonKeyCallback" public : (int * int * int * int -> unit) -> unit;
val setKeyCallback = val setKeyCallback =
_import "setKeyCallback" public : window -> unit; _import "setKeyCallback" public : window -> unit;
val exportFramebufferSizeCallback =
_export "mltonFramebufferSizeCallback" public : (Real32.real * Real32.real -> unit) -> unit;
val setFramebufferSizeCallback =
_import "setFramebufferSizeCallback" public : window -> unit;
end end

View File

@@ -154,10 +154,13 @@ struct
* *) * *)
val input = InputState.getSnapshot () val input = InputState.getSnapshot ()
val width = InputState.getWidth ()
val height = InputState.getHeight ()
val game = GameUpdate.update (game, input) val game = GameUpdate.update (game, input)
val wallVec = Wall.getDrawVec (#walls game) val wallVec = Wall.getDrawVec (#walls game, width, height)
val playerVec = Player.getDrawVec (#player game) val playerVec = Player.getDrawVec (#player game, width, height)
val shellState = uploadWall (shellState, wallVec) val shellState = uploadWall (shellState, wallVec)
val shellState = uploadPlayer (shellState, playerVec) val shellState = uploadPlayer (shellState, playerVec)

View File

@@ -6,6 +6,8 @@ struct
, rightHeld = ref false , rightHeld = ref false
, upHeld = ref false , upHeld = ref false
, downHeld = ref false , downHeld = ref false
, width = ref (1920.0 : Real32.real)
, height = ref (1080.0 : Real32.real)
} }
fun getSnapshot () = fun getSnapshot () =
@@ -15,19 +17,14 @@ struct
, downHeld = !(#downHeld state) , downHeld = !(#downHeld state)
} }
fun getPlayerXAxis () = fun getWidth () =
let !(#width state)
val lh = #leftHeld state
val rh = #rightHeld state
open Player fun getHeight () =
in !(#height state)
case (!lh, !rh) of
(false, false) => STAY_STILL fun sizeCallback (width, height) =
| (false, true) => MOVE_RIGHT (#width state := width; #height state := height)
| (true, false) => MOVE_LEFT
| (true, true) => STAY_STILL
end
open Input open Input
@@ -60,6 +57,9 @@ struct
let let
val () = Input.exportKeyCallback keyCallback val () = Input.exportKeyCallback keyCallback
val () = Input.setKeyCallback window val () = Input.setKeyCallback window
val () = Input.exportFramebufferSizeCallback sizeCallback
val () = Input.setFramebufferSizeCallback window
in in
() ()
end end