Skip to content
jmmonPublic

About

Multiplayer online game using Vim keybinds to interact

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

127 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Qwik City App ⚡️


Project Structure

This project is using Qwik with QwikCity. QwikCity is just an extra set of tools on top of Qwik to make it easier to build a full site, including directory-based routing, layouts, and more.

Inside your project, you'll see the following directory structure:

├── public/
│   └── ...
└── src/
    ├── components/
    │   └── ...
    └── routes/
        └── ...
  • src/routes: Provides the directory-based routing, which can include a hierarchy of layout.tsx layout files, and an index.tsx file as the page. Additionally, index.ts files are endpoints. Please see the routing docs for more info.

  • src/components: Recommended directory for components.

  • public: Any static assets, like images, can be placed in the public directory. Please see the Vite public directory for more info.

Add Integrations and deployment

Use the pnpm qwik add command to add additional integrations. Some examples of integrations includes: Cloudflare, Netlify or Express Server, and the Static Site Generator (SSG).

pnpm qwik add # or `pnpm qwik add`

Development

Development mode uses Vite's development server. The dev command will server-side render (SSR) the output during development.

npm start # or `pnpm start`

Note: during dev mode, Vite may request a significant number of .js files. This does not represent a Qwik production build.

Multiplayer in dev

The websocket server and the server tick loop also run under the dev server, so the game works in development without a production build: open the page, pick a name, and other browser tabs or clients on the same machine see each other. This works by loading the game modules through Vite's own module loader, the same one the route endpoints use, so /api/player and the socket share a single world.

Editing a server-side file (src/server, src/simulation, src/types, src/services/chunk.ts) reloads those modules, so the dev server stops the old tick loop, closes every open socket and starts a new one. Clients are sent back to the login screen and the in-memory world is rebuilt. That reset is inherent to keeping the world in memory; nothing is left half-updated in the meantime.

The artificial lag variables described below work in dev as well:

VIMWORLD_LAG_MS=120 pnpm dev

pnpm preview does not serve the websocket. Use pnpm dev or pnpm serve for multiplayer.

Preview

The preview command will create a production build of the client modules, a production build of src/entry.preview.tsx, and run a local server. The preview server is only for convenience to preview a production build locally and should not be used as a production server.

pnpm preview # or `pnpm preview`

Production

The production build will generate client and server modules by running both client and server build commands. The build command will use Typescript to run a type check on the source code.

pnpm build # or `pnpm build`

Node Server

This app has a minimal zero-dependencies server. Using the built-in http.createServer API. This should be faster and less overhead than Express or other frameworks.

After running a full build, you can preview the build using the command:

pnpm serve

Then visit http://localhost:3004/

Testing lag

The tick and reconciliation code is sensitive to message latency, so both the server and the network path can be given artificial delay.

The server delays every inbound websocket frame before processing it. It is off by default and enabled through the environment:

VIMWORLD_LAG_MS=120 pnpm serve
VIMWORLD_LAG_MS=120 VIMWORLD_LAG_JITTER_MS=40 pnpm serve

VIMWORLD_LAG_MS is the base delay, VIMWORLD_LAG_JITTER_MS is random extra delay on top of it. This covers the client to server direction only, so acks still return at full speed.

To test both directions, run the server behind toxiproxy. The checked-in toxiproxy.json forwards port 8400 to the server on port 3000, covering both the HTTP endpoints and the websocket upgrade:

toxiproxy-server -config toxiproxy.json

Then add latency while the game is running:

for stream in upstream downstream; do
  curl -s -X POST http://localhost:8474/proxies/vim-world/toxics \
    -d "{\"name\":\"lag-$stream\",\"type\":\"latency\",\"stream\":\"$stream\",\"toxicity\":1.0,\"attributes\":{\"latency\":40,\"jitter\":10}}"
done

Point the client at http://localhost:8400 and remove the toxics to restore normal conditions:

curl -s -X DELETE http://localhost:8474/proxies/vim-world/toxics/lag-upstream
curl -s -X DELETE http://localhost:8474/proxies/vim-world/toxics/lag-downstream

About

Multiplayer online game using Vim keybinds to interact

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages