Commit graph

306 commits

Author SHA1 Message Date
iddev5
3dc131d4fa mach: Implement fullscreen window support for native platforms (glfw)
This feature remembers the last position of window before turning to
fullscreen.
2022-06-11 16:00:02 -07:00
Stephen Gutekanst
c5432a9353 mach: zig fmt
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-06-10 16:56:40 -07:00
David Vanderson
ade26b24b1 ditch setTimeout 2022-06-10 12:57:31 -07:00
David Vanderson
4eb872944a wait event stuff for wasm backend 2022-06-10 12:57:31 -07:00
David Vanderson
0f7c34a5ad review updates 2022-06-10 12:57:31 -07:00
David Vanderson
9354c178eb native: switch to setWaitEvent() 2022-06-10 12:57:31 -07:00
iddev5
772a821ce1 mach: wasm: Implement setShouldClose for wasm 2022-06-08 07:31:53 -07:00
iddev5
40c0659cc9 mach: App.update will now return !void instead of !bool
In order to close the application, there is already
Engine.setShouldClose() which would roughly do the same thing.
2022-06-08 07:31:53 -07:00
iddev5
db377459c4 mach: Listen to resize event for canvas and thus store window and
framebuffer size
2022-06-06 00:37:38 -07:00
iddev5
99dc10e58a mach: wasm: Implement mouse press, release, motion and scroll events 2022-06-05 13:34:24 -07:00
iddev5
efe90fc64f mach: Rename scroll -> mouse_scroll and use f32 for offsets 2022-06-05 13:34:24 -07:00
David Vanderson
a2a6c2a288
mach: add mouse motion and mouse button events (#325)
* add mouse motion and mouse button events
* add scroll events
* switch from button/action to mouse_press and mouse_release events
2022-06-04 06:29:23 -07:00
iddev5
176554fe4d mach: Make size limits part of runtime options (mach.Options)
Removed method Engine.setSizeLimits and added two new fields to
mach.Options called ``size_min`` and ``size_max`` which does the same
thing.
2022-06-01 23:45:56 -07:00
iddev5
ed0e6f5c61 mach: Added runtime application options
Reused mach.Options for run time options. It is set with
Engine.setOptions function. ``pub const options`` on top level App has
no effect and will be ignored completely.

Added a blank struct StartupOptions which would be used for startup time
options in future. Currently they aren't used for anything.
2022-06-01 23:45:56 -07:00
iddev5
50fe649ab1 mach: merge and remove the extra layer of indirection caused by Core and
GpuDriver

Core and GpuDriver both are merged into one type called Platform. Also
previously the fields and methods which were called as
``engine.core.field`` will now be ``engine.field`` i.e an extra layer is
removed.
2022-06-01 23:45:56 -07:00
David Vanderson
3961073084
{mach,examples}: followups to getWindowSize / getFramebufferSize (#322)
* followup to window size saving, getWindowSize and getFramebufferSize no longer return errors
* updated the examples
2022-05-31 11:39:53 -07:00
David Vanderson
c0e0b7c686 mach: save window and framebuffer size from glfw callbacks
Previously if user code called core.getWindowSize() (or
getFramebufferSize) during their update they could get sizes that did
not match engine.gpu_driver.target_desc because the window had changed
size.

Now core.getWindowSize() returns the last size we got from a glfw
callback instead of directly querying the window.  So all sizes should
agree during a single frame.

This relies on glfw callbacks only happening when we call
glfw.pollEvents().  This isn't strictly true - a callback could happen
during any glfw call.  Might have to revisit this later.
2022-05-30 12:17:04 -07:00
iddev5
ff126c0054 mach/platform: check for App functions in all platforms 2022-05-30 10:22:42 -07:00
iddev5
21c49ff9be mach: Move all platform specific files to platform/ directory 2022-05-30 10:22:42 -07:00
iddev5
32c12f0eaa mach: wasm: implement key press and release events 2022-05-25 09:10:13 -07:00
iddev5
d8afc9c88c mach: wasm: enable lapping of engine timer every frame 2022-05-25 09:10:13 -07:00
iddev5
8d9ca11b45 mach: wasm: add note about vsync support and move VSyncMode to enums.zig 2022-05-25 09:10:13 -07:00
iddev5
488131ecbb mach: wasm: Adjust width and height for HiDpi/Retina
Also implements getFramebufferSize() and getWindowSize() properly.
2022-05-25 09:10:13 -07:00
iddev5
f3e2b8b74c mach: add a standard way to access platform specific structs
This is done by adding platform.zig which is a file providing types like
``CoreType``, ``GpuDriverType`` and ``BackingTimerType``.
2022-05-23 01:03:43 -07:00
iddev5
e5050e856e mach: Timer: wasm implementation using performance.now() 2022-05-23 01:03:43 -07:00
iddev5
9b7b8be285 mach: Timer: mark all wrapper functions as inline 2022-05-23 01:03:43 -07:00
iddev5
281b1e75c0 mach: wasm: implement getWindowSize 2022-05-22 11:44:21 -07:00
iddev5
f7301cc242 mach: wasm: implement logging and panic handler 2022-05-22 11:44:21 -07:00
iddev5
c8c6dab65b mach: wasm: initial implementation of Core, added js polyfill and
application html
2022-05-22 11:44:21 -07:00
iddev5
ccb1063e3f mach: wasm: Add initial framework bones 2022-05-22 11:44:21 -07:00
Stephen Gutekanst
a7e7dc800d mach: expose window size (pixel units, vs. framebuffer subpixel units)
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-05-22 09:12:48 -07:00
iddev5
7bd841a638 mach: free EventNode(s) after poping from queue 2022-05-20 09:14:32 -07:00
iddev5
f1e7c10fbb mach: remove Action enum and all references to it 2022-05-20 09:14:32 -07:00
iddev5
7486b0ebea mach: Implement key input handling as event loop
This commit changes the former callback based design to handle key input
(GLFW-like) to an event loop based design (SDL-like). This uses a
TailQueue to store the events from inside of standard glfw callbacks.
This Queue is then popped while polling, thereby emulating event loop.

Removes from Engine the function: ``setKeyCallback`` and adds the
function: ``pollEvent`` which may return an event or null.

This change was done for two reasons:
1) Removing dependence of Engine on App. This was a circular dependency
   and a genuine bad design.
2) Solve the recent regression due to the same which was (i) preventing
   using types declared in Engine.zig and (ii) preventing usage of
   multiple source files in an application.

Currently only key press and release events are implemented as these are
the ones currently used in examples.
2022-05-20 09:14:32 -07:00
iddev5
3bb45c75a1 mach: introduce cross platform Timer abstraction
This Timer uses std.time.Timer as backing timer in native platforms, and
will use custom timers for special platforms (wasm, android?, ios?).

Unlike std.time.Timer, its primary API is focused on floats. Also meant
to provides some convenient functions alongside base ones.

Follows std.time.Timer API, but methods by default return f32 i.e
non-precise variant with precise variants available returning u64.
2022-05-17 23:56:41 -07:00
iddev5
657091ed65 mach: Reorganised native backend files, moved structs and fixed circular
dependency
2022-05-15 10:36:08 -07:00
iddev5
8b46f46cf8 mach: Create binding methods for all glfw methods in use and update
examples
2022-05-13 16:17:18 -07:00
iddev5
5396769227 mach: implement all glfw -> mach key mappings 2022-05-09 08:08:01 -07:00
iddev5
71b7473ee7 mach: implement key press/release callback 2022-05-09 08:08:01 -07:00
iddev5
7a392b2780 mach: Add enums for keys and actions 2022-05-09 08:08:01 -07:00
iddev5
8904536632 mach: comptime interface-like implementation of engine cores 2022-05-01 17:07:29 -07:00
iddev5
5c984d9795 mach: finalizing changes for now 2022-04-29 12:48:47 -07:00
iddev5
5249e72408 example: finalize triangle example to new API 2022-04-29 12:48:47 -07:00
iddev5
60fd89ec45 mach: make App.options optional 2022-04-29 12:48:47 -07:00
iddev5
7598c2d7b8 mach: Enable App.resize() and verify if all necessary functions are exported by App 2022-04-29 12:48:47 -07:00
iddev5
2aedc4ca01 mach: implement App struct in terms of unified entry point 2022-04-29 12:48:47 -07:00
iddev5
d99359421e mach: begin unified entry point interface 2022-04-29 12:48:47 -07:00
d3m1gd
ce1aeafa84
choose first adapter (#251)
Related to hexops/mach#216

Co-authored-by: d3m1gd <mach+d3m1gd@users.noreply.github.com>
2022-04-22 18:50:42 -07:00
iddev5
a922b4b29b mach: set error message to be shown on glfw error
This uses glfw.setErrorCallback to set a global callback in mach's App
which would work across all mach applications
2022-04-17 11:50:33 -07:00
Stephen Gutekanst
305c446aa2 add delta time calculation for frame-rate independent movement
Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-04-17 10:06:56 -07:00