Implements support for receiving chat messages from the server, the
first step towards #63 chat support. Long way to go, but is a start.
* server: handle ServerMessage_* packets, on_servermessage
* format: get the with arguments of translations
* format: hardcode chat types
* format: support bare strings, used in chat.type.text
* format: use extra text if present, fixes missing username on 1.16.5
* console/main/server: activate on receiving chat messages
* console: write to log file (configdir/client.log)
* console: change to log only Info and more important to terminal (but all to file)
* console: configurable log levels
Updates to enhance GitHub Actions continuous integration:
* ci: add macOS app bundle packaging using cargo-bundle, closes#352
based on https://github.com/EndlessSkyCommunity/ESLauncher2/blob/master/Cargo.toml
* ci: add web target, building using wasm-pack (for #446)
* ci: refactor and cleanup targets, split out instead of using matrix
* main: save config in consistent OS-specific dirs::config_dir()
Instead of storing and loading in the current working directory, change
to a consistent dedicated configuration directory. This is necessary for
.app launching since cwd is set to /. To preserve compatibility with
existing installations, if conf.cfg exists in cwd then it will be used instead,
but otherwise we will use the operating system specific config dirs:
// Lin: Some(/home/alice/.config)
// Win: Some(C:\Users\Alice\AppData\Roaming)
// Mac: Some(/Users/Alice/Library/Application Support)
* macos: add icons based on screenshotted logo
* macos: add Cmd-Q to quit
PlayerInfo post-1.7.10 has the UUID, so it populates the self.players map,
in 1.7.10 there is only enough information for the client <tab> list. To fix
this, instead populate self.players in SpawnPlayer, for the 1.7.10 variant.
Fixes player name tags showing as "MISSING" on 1.7.10 servers.
* Fix Cmd-V typing v, suppress key_type on ctrl/logo, closes#432
Only send key_type() when modifiers are not pressed.
* Fix backspace repeat and inserting ⌂, closes#476
Handle backspace in key_type instead of key_press, so we get
auto-repeat for free, and can suppress typing the character.
Since the unflattening in 1.13.x, block IDs are no longer stable across versions, and
can be shifted by the addition of new block states. To get the right block IDs across
multiple protocol versions, add a new `offsets` token to `define_blocks!`, which
is similar to `offset` (used post-flattening, compare to `data` used pre-flattening),
but accepts a protocol_version argument to enable block states _per-version_:
* Add 'offsets' for protocol_version-specific blockstates
As part of this change, by_vanilla_id is now a method of a VanillaIDMap instance,
instead of a method of Block, so it can know the protocol version. Previously, the
ID map was lazily computed statically, once, but this change allows it to be
computed based on protocol version:
* Move by_vanilla_id to VanillaIDMap instance
Tools to help debug blocks:
* Add DEBUG_BLOCKS environment variable to dump block states
* Add dump_block command-line tool
The block `offset`s were previously only correct for 1.13.2, to take advantage of
the new version-specific `offsets` capability, blocks were updated for 1.14.x:
1.14+ (protocol_version >= 477):
* Add NoteBlock instruments
* Add FlowerPot and RedFlowerVariant cornflower, wither rose, lily of the valley
* Add StandingSign wood variants
* Add WallSign tree variants
* Add StoneSlab smooth stone, cut sandstone, cut red sandstone
This fixes#467, where grass was misinterpreted as fire on 1.14+ because of the
ID shifts caused by NoteBlock, among other block misassignments (though not 100%).
Refactor the chunk builder to use multithreading on native, but no threads on
wasm, at least until we have web workers or wasm threads. With this change
and the shader fix, chunks now render on Chrome (albeit with no textures).
Another step towards 🕸️ Web support #446.
* Single-threaded chunk builder
* shaders: chunk_frag: consistently enable outputs, fixes GL_INVALID_OPERATION on WebGL
On the web, we have a separate render_loop (for window.requestAnimationFrame)
and events_loop (for winit/window events), so `game` and `ui_container` are shared
using an `Rc<RefCell>`, and `winit_window` as well for wasm only (on native,
`glutin_window` which provides access to the winit window is used instead).
With these changes, events (hover, click, etc.) and rendering now work in the web.
Another step towards 🕸️ Web support (#446)
* wasm: enable events loop
* Use Rc<RefCell>'s for winit_window
* Use Rc<RefCell> for game and ui_container
* main: disable set_cursor_grab() call on wasm to get further until Pointer Lock is available
At this point, the UI renders in the browser through WebGL, with no GL errors.
Progress towards #446🕸️ Web support
* main: enable render loop on wasm, disable events_loop on wasm for now
Allow for testing rendering on WebGL
* chunk_builder: disable on wasm due to no threads on wasm
Chunks will not be correctly rendered, but other parts of the program now can be tested instead of crashing in std::thread
* chunk_frag: glBindFragDataLocation is only on native, WebGL 2 uses in-shader specification layout(location=), which works on native in OpenGL 4.1 but we're on OpenGL 3.2 - see https://www.khronos.org/opengl/wiki/Fragment_Shader#Output_buffers
* std_or_web: always fail File::open() to avoid servers.json empty string JSON parse failing
* www: update installation instructions
* render: fix apparent TEXTURE_MAX_LEVEL -> TEXTURE_MAG_FILTER typo
* render: correct type for internalFormat DEPTH_COMPONENT24
Valid combinations of format, type, and internalFormat are listed at https://www.khronos.org/registry/OpenGL/specs/es/3.0/es_spec_3.0.pdf#page=124&zoom=100,168,206. We had UNSIGNED_BYTE for DEPTH_COMPONENT24, but only UNSIGNED_INT is a valid type for this internal format.
Fixes texImage: Mismatched internalFormat and format/type: 0x81a6 and 0x1902/0x1401
and fixes the subsequent GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT error.
* render: gl::MULTISAMPLE (0x809d) is not available on WebGL
Fixes WebGL warning: enabled: cap: Invalid enum value <enum 0x809d> 0.bootstrap.js line 11 > eval:851:21
* gl: replace set_float_multi_raw with a safer set_float_multi
Removes use of passing raw pointers in set_float_multi_raw parameters
Instead, casts raw pointers to flatten, similar to set_matrix_multi
Fixes uniform setter: (uniform colorMul[0]) values length (1) must be a positive integer multiple of size of <enum 0x8b52>.
* render: model: send BYTE to id attrib, fixes type mismatch
Fixes drawElementsInstanced: Vertex attrib 0 requires data of type INT, but is being supplied with type UINT
* Add getrandom with js feature for JavaScript web compatibility
* Update to rand 0.8.0, closes#440
* Update to rand_pcg 0.3.0, closes#434
* Update rsa_public_encrypt_pkcs1 to 0.3.0, updates rand 0.8.0
Replace std::time with the `instant` crate, which bridges to std::time on
native but on wasm calls performance.now() instead of panicking.
A step towards 🕸️ Web support #446
* logo: replace SystemTime/UNIX_EPOCH with Instant
Steven used multisampled textures from the beginning, but this caused
incompatibilities: https://github.com/Thinkofname/steven/issues/74.
Subsequently fixed by increasing the number of samples, but increasing
it beyond the limit caused more incompatibilities, so it was clamped to
the maximum samples reported as supported by the system.
Fast-forward to now, as part of adding WebGL support (#446), the use of
multisampled textures via the glTexImage2DMultisample() call is
unsupported on this platform. Replace the following:
* glTexImage2DMultisample -> glTexImage2D
* TEXTURE_2D_MULTISAMPLE -> TEXTURE_2D
* sampler2DMS -> sampler2D
This disables the custom multisampling anti-aliasing algorithm (MSAA)
implemented in the chunk fragment shader, increasing compatibility:
* Update to glow release, remove image_2d_sample()
MSAA may be added back at a later date using multisampled renderbuffers
instead, see #442.
A small step for #446🕸️ Web support, use web-sys to interface to the web.
Previously, we would try to use glutin on the web, which is not supported;
now glutin is only used on native: fixes#171 could not find Context in platform_impl.
winit is still used on both, but the GL context is created with web-sys and glow
(on the web), and created with glutin and used with glow (on native). stdweb is
no longer used, being replaced by web-sys.
Substantial refactoring to allow reusing the code between web/native:
* settings: use VirtualKeyCode from winit, not reexported from glutin
* std_or_web: remove broken localstoragefs/stdweb, add File placeholder
* render: disable skin_thread on wasm since we don't have threads
* gl: use glow types in gl wrapper (integers in native, but Web*Key in web)
* gl: web-sys WebGlUniformLocation does not implement Copy trait, so glow::UniformLocation doesn't so gl::Uniform can't
* gl: refactor context initialization, pass glow::Context to gl::init for consistency between native/web
* gl: update to glow with panicking tex_image_2d_multisample web-sys wrapper
* glsl: use shader version in GLSL for WebGL 2 and OpenGL 3.2
* shaders: add explicit float/int type conversions, required for WebGL
* shaders: specify mediump precision, required for WebGL
* shaders: specify fragment shader output locations for WebGL
* main: refactor handle_window_event to take a winit window, not glutin context
* main: handle resize outside of handle_window_event since it updates the glutin window (the only event which does this)
* main: use winit events in handle_window_event not reexported glutin events
* main: refactor game loop handling into tick_all()
* main: create winit window for WebGL, and use winit_window from glutin
* main: restore console_error_panic_hook, mistakingly removed in (#260)
* main: remove force setting env RUST_BACKTRACE=1, no longer can set env on web
* www: index.js: fix wasm import path
* www: npm update, npm audit fix
* www: update readme to link to status on #446🕸️ Web support
Replaces the use of gl_generator with the glow wrapper:
* Add glow dependency, based on glow 0.6.1
* Pin version of glow fork for https://github.com/iceiix/glow/pull/1 until #442 renderbuffer
* Remove gl module, steven_gl
Porting details:
* Initialize glow in src/gl/mod.rs
* Call gl methods on glow context
* glow uses camelcase
* Import glow::HasContext trait, finds draw_elements etc.
* Fix mismatched types, glow uses Option and &str instead of raw pointers
* Fix uniform_location, glow already returns Some(u32)
* uniform_location: convert i32 to u32 for Uniform
* Fix attribute_location
* Fix shader creation Result u32 type
* Fix passing GLvoid and 2d/3d
* Fix missing Options type mismatches
* Offsets are i32 in glow, not GLvoid
* Fix clear_buffer using _f32_slice
* Delete methods are singular not plural
* glBufferData -> buffer_data_u8_slice
* buffer_sub_data_u8_slice
* Update more glow method wrapper names found by reviewing glow native platform
* Remove unused multi_draw_elements, can be replaced by draw_elements in a loop and it has no WebGL equivalent
* glow implements glMapBufferRange
* Remove unused read_buffer
* glow's deletes automatically pass 1 and take no reference
* shader_source() accepts &str directly; removes last of std::ptr
* Pass uniform Option<u32>
* Fix bool passing normalized parameter
* Fix draw_buffers parameter
* Stop unnecessarily returning context from gl::init
* Getting shader info is unsafe
* Unwrapping static mut is unsafe
* Use unsafe raw pointers for global mutable context
* Fix initializing GL objects wrappers from glow wrappers
* Unbinding framebuffers uses None
* Uppercase global to fix warning
* Shaders return Some instead of None
* Unbox the context to a raw pointer
* Use tex_image_2d_multisample added in glow fork
* Implement uniform_location, fixing unwrap None failed
* Add tex_sub_image_3d, using PixelUnpackData::Slice
* set_matrix4: transmute the Matrix4 since it is repr(C)
* get_pixels -> get_tex_image -> glGetTexImage, with PixelPackData::Slice
* Wrap sub_image_2d (glTexSubImage2D) and fix warnings
* Implement set_float_multi_raw and set_matrix4_multi, using from_raw_parts
* Update for ModifiersChanged event
* Consistently use logical position and size
CursorMoved gives us a PhysicalPosition, which needs to be converted
to LogicalPosition to properly track the mouse movement. Change the
width/height passed to be a LogicalSize instead of a PhysicalPosition,
matching the LogicalPosition.
Adds support for 1.16.4 (754) / 1.16.3 (753) / 1.16.2 (751) protocols
* Update packet IDs and readme
* Add and handle ChunkData_Biomes3D_VarInt variant
* Support world chunk data padded bit map array
* Add and handle JoinGame_WorldNames_IsHard variant
* Add and handle MultiBlockChange_Packed variant
* Add UnlockRecipes_WithBlastSmoker variant
* Add SetDisplayedRecipe and SetRecipeBookState packets
The server list ping response contains a base64-encoded favicon image,
which in pre-1.13 servers can have embedded newlines:
https://wiki.vg/Server_List_Ping#Response
> The favicon should be a PNG image that is Base64 encoded (without
> newlines: \n, new lines no longer work since 1.13) and prepended
> with data:image/png;base64,.
If this was the case, base64 decode would fail with a DecodeError,
similar to Invalid byte (76, 10). We now strip the whitespace, so the
base64 favicon can be decoded properly.
* Update shifted packet ids
* Add new smithing recipe type
* Also support 1.16 (735), same packets as 1.16.1 (736)
New packets:
* GenerateStructure
New packet variants:
* UseEntity_Sneakflag, split from UseEntity_Hand
* ClientAbilities_u8, split from ClientAbilities_f32
* UpdateJigsawBlock_Joint, split from UpdateJigsawBlock_Type
* ServerMessage_Sender, split from ServerMessage_Position
* ChunkData_Biomes3D_bool, split from ChunkData_Biomes3D
* JoinGame_WorldNames, split from JoinGame_HashedSeed_Respawn
* Respawn_WorldName, split from Respawn_Gamemode
* EntityEquipment_VarInt renamed
* UpdateLight_WithTrust, split from UpdateLight_NoTrust
* LoginSuccess_UUID, split from LoginSuccess_String
Thanks to @mwkroening (#317) and @martijnberger (#323) for helping fix this update.
* Update to glutin 0.22.0 and winit 0.20.0 release, removing alpha pinning
* scale_factor() replaces hidpi_factor()
* Listen for ScaleFactorChanged, separate from Resized event
* Fix getting physical size of window
* Fix logical mouse event coordinates
Completes the move of the protocol implementation into a new
crate, named steven_protocol, in the protocol/ subdirectory.
* Add Cargo.toml for steven_protocol
* Add steven_protocol entrypoint in protocol/src/lib.rs
* Use steven_protocol in main
* Remove protocol in main, replaced by steven_protocol
* Remove unused dependencies moved into steven_protocol
Update from glutin 0.21.x fork to glutin 0.22.0-alpha5 and corresponding
compatible version of winit. This removes our custom temporary wasm_stub
branches, back to mainline glutin and winit, and is a step towards WebAssembly
compatibility, most importantly merging the game loop and event loops as
required by winit _which now supports wasm_. Not yet functional on the web
because other web dependencies have to be added, see #171 and #34, but native
functionality is preserved.
* Update for 0.22 glutin API changes:
* Move game logic into event loop, run() replacing poll_events()
* Specify fullscreen Borderless mode
* Pass generic parameter of Event through handle_window_event
* hidpi_factor() replaces get_hidpi_factor()
* with_inner_size() replaces with_dimensions()
* No longer need to unwrap() LogicalSize
* set_cursor_grab/visible() replaces grab/hide_cursor()
* Fix modifiers deprecated warnings by destructuring only event fields we use, ignoring the rest with '..'
* Remove unnecessary mutability from events_loop
* Listen for ModifiersChanged event, fixing deprecated modifiers field
* Change to stdweb for web backend, replacing web-sys
* Pin to glutin =0.22.0-alpha5 and winit =0.20.0-alpha6
The Display trait is already implemented, so this is only a code
deletion. Fixes 1.42-nightly warning:
warning: use of deprecated item 'std::error::Error::description': use the Display impl or to_string()
--> src/protocol/mod.rs:981:40
|
981 | Error::IOError(ref e) => e.description(),
| ^^^^^^^^^^^
|
= note: `#[warn(deprecated)]` on by default
warning: this method call currently resolves to `<&[T; N] as IntoIterator>::into_iter` (due to autoref coercions), but that might change in the future when `IntoIterator` impls for arrays are added.
--> src/entity/player.rs:363:11
|
363 | ].into_iter().enumerate() {
| ^^^^^^^^^ help: use `.iter()` instead of `.into_iter()` to avoid ambiguity: `iter`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #66145 <https://github.com/rust-lang/rust/issues/66145>
From investigation for #115, now three targets:
- wasm32-unknown-unknown: build with `wasm-pack build`, uses
the #[wasm_bindgen] directive on main()
- wasm32-wasi: build with `cargo +nightly build --target wasm32-wasi`,
requires normal main()
- native targets: same as wasm32-wasi
Logging from the `log` facade goes to the colorized in-game GUI console (opened with the backtick key), as well as standard output using `println!` on the native build. To make this work on the wasm build, web-sys is used to access the `console` object, to call `console.log`, `console.warn`, and so on corresponding to the log levels. Extends #92, fails later (see also #115) but now outputs the starting up message:
[main.rs:206][INFO] Starting steven
* Add println! logging to console.log on wasm
* Initialize logger before config (called 'console variables' for some reason) to avoid having to disable it to reach the first logging statement
* Add web-sys crate for browser console access, wasm32-only
* Refactor logger to call println_level on both web/native
* Add multiple log levels, console.warn etc., matching console_log crate
https://github.com/iamcodemaker/console_log#details