Code Monkey home page Code Monkey logo

kapp's People

Contributors

kettle11 avatar lunabunn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

kapp's Issues

Implement MouseDelta for Windows and Web

  • Windows

  • Web

Windows and Web should report MouseDelta events in addition to PointerMoved events. MouseDelta events should be sent even when the mouse cursor position is locked.

Implement `set_mouse_position` for Web

https://github.com/kettle11/kettlewin/blob/e0bb32b4e9083493bafcc53e5e97f00a24978536/platforms/web/src/application_web.rs#L30

set_mouse_position should set the mouse position relative to the current window (or canvas?)

Investigate pointer lock API here:
https://developer.mozilla.org/en-US/docs/Web/API/Pointer_Lock_API

Perhaps other platforms should be implemented to have a similar API, as "locking" the pointer seems to be the most common use case for moving the mouse.

objc macros are fairly heavy in terms of generated code. Should they be used?

The events_mac file expands with cargo expand to ~3300 lines due to macros when the non-expanded version is ~660 lines.

I partially began a transition away from using the objc macros in 0d96c59 however I did not fully complete the transition. The partial reduction of the macro shaved ~6% off the build time.

However I'm now having second thoughts. Now to use new classes and selectors code must be declared in multiple additional places instead of one macro that handles it all. It makes kapp's code base aesthetically a bit messier and adds a little friction to implementing new changes.

Implement mouse lock for Mac, Windows, and Web. Remove set_mouse_position.

set_mouse_position should be implemented here:
https://github.com/kettle11/kettlewin/blob/e0bb32b4e9083493bafcc53e5e97f00a24978536/platforms/macos/src/application_mac.rs#L259

The function accepts an x and y value expressed in physical screen coordinates.

The coordinates should be converted to the appropriate coordinate space for the mouse's current screen.

This function call should only move a mouse within the current screen, which is what most games would need.

Project Goals for Portability

The README states:

kApp strives to be unsurprising, quick to build, and straightforward to maintain.

Now, of course at this point in time kapp is nowhere near as production-ready/battletested as SDL2, winit/glutin, etc. However, to me it's unclear if it's a project goal in the first place to eventually be production-usable. To me, an unsurprising, production-usable windowing library is one that "just works" on Windows XP+ & OSX Mountain Lion+ or something along those lines. Will kapp ever fit that bill or does it have a smaller scope in mind? Clarifications in the README would be appreciated.

Consistent DPI handling

Presently Windows works in logical coordinates and MacOS works in physical coordinates. Both should work in physical coordinates.

'Physical' isn't exactly the right term as the scale may not be physical, but it is unscaled and more similar to the native resolution.

Why 2 dummy windows for GL Context creation? (Windows)

// Create the second dummy window.
let dummy_window2 = create_dummy_window(h_instance, &window_class_name);
error_if_null(dummy_window2)?;
// DC is 'device context'
let dummy_window_dc2 = GetDC(dummy_window2);
error_if_null(dummy_window_dc2)?;
// Setup the actual pixel format we'll use.
// Later this is where we'll specify pixel format parameters.
// Documentation about these flags here:
// https://www.khronos.org/registry/OpenGL/extensions/ARB/WGL_ARB_pixel_format.txt
let pixel_attributes = vec![
WGL_DRAW_TO_WINDOW_ARB,
TRUE as i32,
WGL_SUPPORT_OPENGL_ARB,
TRUE as i32,
WGL_DOUBLE_BUFFER_ARB,
TRUE as i32,
WGL_PIXEL_TYPE_ARB,
WGL_TYPE_RGBA_ARB,
WGL_ACCELERATION_ARB,
WGL_FULL_ACCELERATION_ARB,
WGL_COLOR_BITS_ARB,
color_bits as i32,
WGL_ALPHA_BITS_ARB,
alpha_bits as i32,
WGL_DEPTH_BITS_ARB,
depth_bits as i32,
WGL_STENCIL_BITS_ARB,
stencil_bits as i32,
WGL_SAMPLE_BUFFERS_ARB,
1,
WGL_SAMPLES_ARB,
msaa_samples as i32,
WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB,
if srgb { TRUE as i32 } else { FALSE as i32 },
0,
];
let mut pixel_format_id = 0;
let mut number_of_formats = 0;
error_if_false(wglChoosePixelFormatARB(
dummy_window_dc2,
pixel_attributes.as_ptr(),
null_mut(),
1,
&mut pixel_format_id,
&mut number_of_formats,
))?;
error_if_false(number_of_formats as i32)?; // error_if_false just errors if the argument is 0, which is what we need here
// PFD stands for 'pixel format descriptor'
// It's unclear why this call to DescribePixelFormat is needed?
// DescribePixelFormat fills the pfd with a description of the pixel format.
// But why does this window need the same pixel format as the previous one?
// Just it just need a valid pixel format?
let mut pfd: PIXELFORMATDESCRIPTOR = std::mem::zeroed();
DescribePixelFormat(
dummy_window_dc2,
pixel_format_id,
size_of::<PIXELFORMATDESCRIPTOR>() as u32,
&mut pfd,
);
SetPixelFormat(dummy_window_dc2, pixel_format_id, &pfd);
// Finally we can create the OpenGL context!
// Need to allow for choosing major and minor version.
let major_version_minimum = 4;
let minor_version_minimum = 5;
let context_attributes = [
WGL_CONTEXT_MAJOR_VERSION_ARB,
major_version_minimum,
WGL_CONTEXT_MINOR_VERSION_ARB,
minor_version_minimum,
WGL_CONTEXT_PROFILE_MASK_ARB,
WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
0,
];
let opengl_context = wglCreateContextAttribsARB(
dummy_window_dc2,
0 as HGLRC, // An existing OpenGL context to share resources with. 0 means none.
context_attributes.as_ptr(),
);

Why exactly are we creating a second dummy window here?

Add function to get current timestamp.

Presently it's annoying to work with timestamps on events as there's no frame of reference to compare them to.

There should be a mechanism to get the current timestamp. It could be exposed as a function on application, or perhaps a function more globally available.

Text input

Right now key events are received, but they are a poor substitute for platform native character input.

  • Mac
  • Web
  • Windows

In addition setting the text box for IME input may need to be supported as well, probably as a function that can be called on a window. Presently on Mac it appears in the lower left corner, which isn't ideal.

Ensure all modifier keys are handed

Windows in particular may not be reporting modifier keys at all.

On Windows MapVirtualKeyW(scancode, MAPVK_VSC_TO_VK_EX) needs to be used.

Mac may be missing some modifiers as well.

Some investigation is required here to see which keys work properly and which do not.

Consider dropping `wasm-bindgen` dependency on Web

wasm-bindgen and it's ecosystem is massively useful but also very complex.

It is possible to interact with web APIs with a thin wrapper API instead of wasm-bindgen

Pros:

  • Cut web build times dramatically (Web would become the fastest platform to build)
  • May unblock WebWorker and AudioWorklet capabilities that wasm-bindgen cannot currently handle.
  • More kapp logic can exist on the Javascript side, instead of trying to awkwardly put it into Rust.
  • Much simpler stack
  • Potentially better performance by reducing back and forth between Wasm and JS (but may be insignificant)
  • More control over destiny: wasm-bindgen leadership has been focused on other things over the last year, development might slow down.

Cons:

  • Web APIs are not automatically wrapped. There are a ton of them and kapp would have to add them as needed. Adds more friction to new features.
  • Losing expertise of wasm-bindgen.
  • Harder to integrate with other Rust crates that use the Rust ecosystem standard of wasm-bindgen
  • wasm-bindgen-cli performs some optimizations that would be lost.
  • Potentially more difficult to integrate with Javascript libraries.
  • Obviously it takes time to port libraries to the new thin wrapper. In particular glow depends on wasm-bindgen so new GL bindings would be needed, which would not be hard but would take some time.

Some of this work is already started on the kwasm branch: https://github.com/kettle11/kapp/tree/KWasm
I intend to investigate / continue work on the branch in the near future.

Linux Support?

Does kapp plan to add Linux support for the future? Wayland? X11? Both?

Investigate adding SDL backend for kapp (kapp-sdl)

Tracking issue for investigating (not necessarily actually implementing) an SDL backend for kapp. This should be a separate crate (kapp-sdl) within this repository that is exposed through kapp via a feature-gated dependency.

Benefits:

  • Have a portable, production-ready, and battle-tested alternative implementation for production builds
  • Verify that kapp's API is sensible and matches certain "expectations" set by SDL
  • Easier to implement features that aren't yet available in core kapp (more freedom to play around with the API if stuff is actually implemented, we can aim for eventual feature parity)
  • Act as a nice, Rusty wrapper around SDL

Points for consideration:

  • This would obviously be more work to maintain
  • #44 mentions smooth window resizing as one of kapp's goals, but SDL can't do this
  • Which set of SDL bindings should we use? fermium? sdl2? Own set of bindings?

Thoughts?

sRGB support?

EDIT:

Add an srgb flag to GLContextAttributes and implement it for different platforms.

  • Windows
  • Mac

Web currently doesn't support specifying the color space, see: https://github.com/WICG/canvas-color-space/blob/master/CanvasColorSpaceProposal.md


Original Issue:

Currently, I'm using a fork that changes

into true, but that's obviously not a great solution πŸ˜…

Why is that a false, anyway? Is it a placeholder? Shouldn't there be a flag for this in GLContextAttributes?

Async waker should actually wake callback

Right now another event must awake the program async callback if it's awaiting something.

For example if an asset is loaded the parent callback won't be woken until another event (like user input) occurs.

Slight stutters when resizing windows on Windows

Resizing a window can produce slight stuttering.

This is seen in the platformer.rs example.

It appears the redrawing of the window becomes out of sync with the presentation of the window. I don't remember this always being the case, and it should be possible to fix it.

Segfault running helloworld

rustc 1.45.0-nightly
kApp 0.1.0

    Finished dev [unoptimized + debuginfo] target(s) in 0.15s
     Running `target/debug/examples/hello`
[1]    24666 segmentation fault  cargo run --example hello

Proper IME (Input method editor) support

kapp's IME support should make it easy to implement correct behavior. Proper IME input is critical for inputting characters in most non-English languages.

Probably events need to be emitted when the intermediate results change and when a final text input occurs.

Previously the CharacterReceived event handled the latter. Instead a TextInput (or a better name?) event with a String should be sent as it's closer to the platform native behavior. Allocating a String shouldn't be a problem for these events as they're relatively infrequent.

Implement double click for Web and Windows

  • Windows (However no "Double Click Up" event is sent)
  • Web

Note that double click on web by default triggers on the second up, which is different than other platforms. Perhaps this should be reconciled.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.