Compare commits

..
Author SHA1 Message Date
Stefan MaierandClaude Opus 5.5 24e4123882 VR performance diagnostics: the frame's parts, the layer copies, Mesa's GL thread switch
- vr.log_performance: frames with game ticks and without, how many late,
  and their time by part (input, ticks, camera, draw, present)
- with XR_META_performance_metrics: per frame, each layer copy's time, the
  waits for swapchain images and xrEndFrame
- debug.gl_thread: Mesa's GL thread on or off (mesa_glthread) for trying

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 21:33:00 +02:00
Stefan MaierandClaude Opus 5.5 8466846d45 Steam Frame: the frames' thread kept on the fast cores
Without XR_EXT_performance_settings (SteamVR in Lepton) the scheduler may
put the game's busy thread on the 2.3 GHz cores; frames then come late to
the compositor and the picture doubles as the head turns, now and then,
at a steady 72 fps. On SteamVR the thread that ends the frames is kept on
the cores no slower than 90% of the fastest (HALO_XR_ANY_CORE: not); the
metrics line says which core it is on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 19:53:47 +02:00
Stefan MaierandClaude Opus 5.5 bc580cf1cf VR: the compositor's performance counters in the log (XR_META_performance_metrics)
Every five seconds, where the runtime offers them (SteamVR on the Steam
Frame): to tell frames the compositor showed late or reprojected from the
game's own pace.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 19:46:54 +02:00
Stefan MaierandClaude Opus 5.5 3d575f32ed Bots on foot: ramps, rails, door frames and things out of reach
- a way is clear only at the knees and the chest (a rail with room under
  it, a slit in a wall), and for a shortcut along a path at the shoulders
  too (a door frame)
- stuck below a near point (a step, a ramp's lip): a jump on towards it
- a thing to pick up it comes no nearer to for 2.5 s is given up
- stuck three times in five seconds: the goal given up, somewhere away
- at the point it walks to: arrived, not stuck

Emulator, Blood Gulch, 15 bots: CTF stuck events 264 -> 153, mid-field
26% -> 32%, kills 26 -> 33; team slayer stuck events 860 -> 560.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 19:33:16 +02:00
Stefan MaierandClaude Opus 5.5 727b9ca80d Bots on foot: no crowding at things out of reach, spread over the enemies, hold spots they can reach
- a thing to pick up that it stands by and is not offered (on a ledge,
  out of reach) is given up for 20 s; up to four remembered, in the
  fight too (the crowds jumping at the base's weapons)
- stuck: the side step goes to the open side
- goals: each bot one of the three nearest enemies, and beside them while
  far, so a team spreads out
- holding a spot: stops near it, and one it cannot reach falls back to
  the place's centre

Emulator, Blood Gulch, 15 bots: CTF stuck events 1793 -> 264; team slayer
stuck windows 32% -> 9-15%, time by the bases 85% -> 68-73%.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 18:52:30 +02:00
Stefan MaierandClaude Opus 5.5 99d7c924db Bots: a person joining a lobby the bots fill takes a bot's place
The bots fill the game up to its maximum; a machine joining the lobby
keeps its place (no bot added for it) and its player takes the last
bot's; the game lists as open while a bot could leave.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 18:00:31 +02:00
Stefan MaierandClaude Opus 5.5 57d96e4681 VR PC menus: fixes from the first Frame test
- bots: no more than the game's MAXIMUM PLAYERS has room for beside the
  people (instead of raising it); the host options show and change the
  bots there are
- VR options hint on the PC main menu drawn whole (left-aligned)
- the online and host panels: a click beside them or on their key's B
  closes them, on the online panel's X enters a code
- spinners' arrows (drawn just outside them) clickable
- Android flat (the emulator): the mouse drives the menus' pointer, for
  testing the menus' clicks with adb shell input mouse
- Frame launcher: Lepton's logcat of the game's container in logcat.txt

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 17:45:41 +02:00
Stefan MaierandClaude Opus 5.5 177ad4d40d VR: the PC version's menus (vr.menus, on by default)
- menu_tags.c builds the PC menus in VR too unless vr.menus = "xbox"
- their text fields (Server Setup's game name) typed on the Xbox's
  on-screen keyboard in VR
- join code / online panel on the PC Server Browser (X or click its hint),
  host options (Y or click) and join code on the PC lobby, VR options on
  the PC main menu
- bots: room made for them beside the people (Server Setup's maximum
  players), none in co-op
- player_name_valid accepts trailing spaces (Xbox menus pad new profile
  names, "New001     ", which the PC lobby refused)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 17:17:16 +02:00
Stefan MaierandClaude Opus 5.5 bfb668d498 Merge branch 'merge/upstream-2026-10-05'
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 17:00:26 +02:00
Stefan MaierandClaude Opus 5.5 fc2b6551ca Merge upstream (OpenCE 13c14df9): online co-op campaign, online split screen, network version 16
Upstream's online co-op (network_actors.c, network_coop.c) ticks beside the
VR port's VR relay and bots; its message types end at 77, below the VR
port's from 240. The look and move flags the action test reads moved into
player_control_action_test_note: the head's turning goes there too. The
vertex shader's screen-space undo is upstream's on every platform now, with
the multiview eye offset after it on Android. The APK carries upstream's
brokers.txt beside the FDM layer stub; the updaters keep the VR port's own
repository (upstream's now points at OpenCommunityEdition/OpenCE).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 16:22:05 +02:00
Stefan Maier 5316a6b145 Merge branch 'frame/launcher' 2026-10-05 16:19:02 +02:00
Stefan MaierandClaude Opus 5.5 59b1fb422b Steam Frame: a library button that starts, updates and quits the game
The launcher gives Lepton what Steam gives an Android title of its own (a
compat data path, which the app's data links to after an install, and the
shader path), keeps a container id of its own, tries a start that ends at
once again (a new APK's first start only installs it), and stops when the
game was quit. Steam's "Exit game" cannot reach the game in Lepton's
container: the VR options get "Quit Halo" (asked twice), which on Android
now ends the process and leaves quit_requested.txt for the launcher. The
library's pictures are in port/android/steam_frame_grid.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 16:17:35 +02:00
Stefan MaierandClaude Opus 5.5 5ecd3075a0 Steam Frame: a launcher that starts the game as Steam starts Android titles
Lepton runs the APK in a container of its own, kept between starts, and
installs it anew whenever the APK is newer; the script starts it a second
time after a new APK's first start, which only installs it. With the APK in
~/Documents/HaloCE, updating the game is replacing that file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 15:17:54 +02:00
MrBruh 13c14df95c Merge pull request #101 from xshxdex98/coop-bsp-sync
Co-op: every machine stays on the host's BSP (network version 16)
2026-10-06 02:13:10 +13:00
xshxdex98 b525bf8514 Network version 16
A client's input says which structure BSP it has loaded (co-op).
2026-10-05 08:09:47 -05:00
xshxdex98 087ca8a875 Co-op: every machine stays on the host's BSP
Players in big sessions ended up on different BSPs:

- The host told clients about a switch only every half second, and not
  reliably, so a client could predict its player for a while in a BSP it
  hadn't loaded. A switch is now sent at once, reliably, ahead of the
  players' new positions.
- A client still loading reports so: its input carries the BSP it has
  loaded. Until it has the host's, the host takes none of its movement
  (which falls there with no floor) and none of its loading zones.
- After a switch, by a trigger, a script or a skipped cutscene, no trigger
  can switch again until every machine has loaded the new BSP (at most
  ten seconds), so no client falls two switches behind.
- A player the host can't place beside whoever crossed, when a big team
  runs out of room there, is placed beside another teammate instead of
  being left where they were.
2026-10-05 08:09:46 -05:00
MrBruh 24957ff6a0 Network version 15 2026-10-06 01:28:04 +13:00
MrBruh 402d4b8351 Merge pull request #97 from xshxdex98/coop-dead-vehicles 2026-10-06 01:24:23 +13:00
MrBruh d1825ab08d Merge pull request #96 from xshxdex98/coop-backtrack-gate 2026-10-06 01:24:22 +13:00
MrBruh 268ec84b74 Merge pull request #95 from xshxdex98/coop-allegiances 2026-10-06 01:24:21 +13:00
xshxdex98 8dc796028e Co-op: going back to a visited BSP needs two thirds of the team
One player who stayed behind or went AFK no longer blocks the team.
2026-10-05 07:14:28 -05:00
xshxdex98 8aa381ed14 Co-op: vehicles the host destroys explode on clients
Clients only had a kill path for bipeds, so a Ghost, Banshee or Wraith the
host destroyed stayed intact on clients. A vehicle the host's state says
is dead is now destroyed there too, with its explosion.
2026-10-05 07:01:37 -05:00
xshxdex98 c3f82fa9b2 Co-op: going back to a BSP already visited needs the whole team there
A loading zone brings the whole team to whoever crosses it. Into a new part
of the level that's what you want, but it let one player drag everyone
back. A switch back to a BSP the team has been in now waits until every
living player is in the trigger or near the player in it.
2026-10-05 07:01:32 -05:00
xshxdex98 5ff4b6ee8d Co-op: clients take the host's allegiances
The scripts make allegiances (ai_allegiance player human) and only the host
runs them, so on clients marines stayed enemies of the players: red reticles
and the wrong team. The host sends its ally and friend tables with the
presentation each tick.
2026-10-05 07:01:26 -05:00
MrBruh 91e838e2f6 Network version 14 2026-10-06 00:54:11 +13:00
MrBruh 520b8401db Merge pull request #93 from xshxdex98/test-death-timing-coop 2026-10-06 00:51:37 +13:00
MrBruh 2ed4a7b49d Merge pull request #92 from xshxdex98/coop-flood-dropships 2026-10-06 00:51:36 +13:00
MrBruh 503992d544 Merge pull request #91 from xshxdex98/coop-device-states 2026-10-06 00:51:35 +13:00
MrBruh ccc7df6611 Merge pull request #90 from xshxdex98/coop-loading-zones 2026-10-06 00:51:35 +13:00
xshxdex98 ddcbe79283 test_death_timing.py: stubs for the network co-op paths
The test compiles main.c's and players.c's death handlers against a fake
world; their network co-op branches call functions it had none of, so it
no longer compiled. Stubbed off, it covers the local game it was written
for, and passes.
2026-10-05 06:41:27 -05:00
xshxdex98 862d88737e Co-op: Flood bodies get up on clients; dropship doors open and close there
- A body the host's unit got back up from (a Flood combat form feigning
  death) gets up on the clients too, instead of its ragdoll being dragged
  about. The resurrection is one function both use (unit_port_resurrect).
- The scripts' unit_open and unit_close go to the clients, so dropships'
  doors aren't left open there.
2026-10-05 06:36:27 -05:00
xshxdex98 8610b28376 Co-op: doors and elevators are where the host has them
The host sends each device's position and power when they change (and with
the resent state), and a client puts its device there when the host's is at
rest and they differ, or when they drift apart while it moves. Clients only
had the device groups' values, which aim a device: a door could stop half
open, and an elevator be somewhere else on a client, so its players fell.
2026-10-05 06:36:27 -05:00
xshxdex98 9e6247e0cb Co-op: a loading zone brings the team along; only someone falling is rescued
- Crossing a BSP loading zone moves every other player to whoever crossed,
  as split screen does. Moving only some players left the rest where the
  next switch threw them back to a hallway, or under a floor.
- The rescue for a player outside the loaded BSP waits two seconds and
  only takes someone falling: a player riding an elevator through its
  shaft is left alone.
2026-10-05 06:34:00 -05:00
MrBruh dea5fe3b1e Fix crash past 256 actors 2026-10-06 00:29:42 +13:00
MrBruh f0804aa587 Extra enemies: per player or static multiplier 2026-10-06 00:08:26 +13:00
MrBruh 16ad4cc900 25% extra enemies option 2026-10-05 23:45:31 +13:00
MrBruh a38ede078a Co-op extra enemies per player 2026-10-05 23:25:15 +13:00
MrBruh fa85aa53f5 Kick command; co-op friendly fire on by default 2026-10-05 22:51:05 +13:00
MrBruh 8be9a038a1 Co-op friendly fire setting 2026-10-05 22:40:34 +13:00
MrBruh 783b591a6a Co-op defaults to 16 players and private 2026-10-05 22:27:36 +13:00
MrBruh e82d880060 Singleplayer and multiplayer map choice 2026-10-05 22:17:22 +13:00
MrBruh 7d0e587c51 Co-op review fixes 2026-10-05 21:02:04 +13:00
MrBruh 01586cfebf Merge pull request #89 from xshxdex98/coop-campaign 2026-10-05 20:29:19 +13:00
MrBruh de52060644 Host takes grenade damage only from grenades thrown 2026-10-05 19:54:33 +13:00
MrBruh ab7c507a29 Leaving the lobby after a game goes to the main menu 2026-10-05 19:39:57 +13:00
xshxdex98 ba6fe0a826 AI sync: any team the host's unit has goes with it, not only the campaign's 2026-10-05 00:59:33 -05:00
MrBruh 3f6c0c37a4 Friendly fire stops teammates' instant kills 2026-10-05 18:47:39 +13:00
xshxdex98 606109551d Co-op: friendly reticles, skipped cutscenes' sound, the end of a level, tutorial prompts
- AI units' teams go with their states, so friendlies aren't red on
  clients' reticles.
- A skipped cutscene's music and dialogue stop on the clients.
- Winning a level returns every machine to the lobby with the next level
  set up, instead of leaving them on its last screen.
- Help text carries whether the host shows it, so no prompt is dropped.
2026-10-05 00:46:51 -05:00
xshxdex98 8194c5a00b Online co-op: play the campaign together over LAN and the internet
Hosting a co-op level from the Map screen (CO-OP CAMPAIGN, a level and its
difficulty, then Server Setup) makes a network game on the campaign map
with no game engine, which is what co-op is. Only the host runs the
scripts and the AI; port/linux/game/network_coop.c sends clients what the
scripts do (cutscenes, camera, fades, HUD, sounds, devices, named objects,
animations), and network_actors.c drives the host's AI units on every
machine. Players spawn beside each other, respawn beside a safe teammate,
and spectate while dead or waiting. Skipping a cutscene is a vote.
Players can join a game in progress at any time.
2026-10-05 00:31:30 -05:00
MrBruh 737551fd51 Resolution, scaling and window size settings 2026-10-05 18:28:58 +13:00
xshxdex98 7a56c624f5 Merge upstream main 2026-10-05 00:07:13 -05:00
MrBruh 3ae09c3d2c Fade the radar wedge out fully 2026-10-05 17:23:47 +13:00
MrBruh 3a22816c2f Merge pull request #81 from FDervish/fix/antenna-stepped-per-tick 2026-10-05 17:15:38 +13:00
MrBruh 2853a42253 Clear an antenna's shape record when it is created 2026-10-05 17:13:27 +13:00
Fadi DerouicheandClaude Opus 5 39ece781ee Step the antenna chain in the tick and draw the frames between the ticks
An antenna's chain is a simulation of the Xbox's own step, an update a tick,
and the port was stepping it once a frame with the frame's own time. Its
springs, its carry and the points' physics then acted against the frames'
movement of it, so how far the chain moved per update depended on the frame
rate, and a vehicle at speed swung it far wider than a tick's step does.

- game.c steps the chain in the tick, beside the effects, which are already
  stepped there.
- antenna.c records the shape each tick leaves, relative to the point the
  vehicle's marker carries the base by. A frame drawn between two ticks is the
  part of the way between those two shapes that it is, carried to where the
  marker is now, so the chain stays on the vehicle it hangs from instead of
  lagging a tick behind it. The gate that left a chain that had not been drawn
  for five updates unstepped counted frames; it counts ticks now, which is
  what it counted on the Xbox.
- widgets.c no longer steps the chain from the widget update, which ran once a
  frame.
- game_time.c draws the per-frame effects and widgets that hang off objects
  (game_frame) with the pose between the last two ticks, the pose the renderer
  draws with, so what they place on an object is drawn where they put it.
- objects.c hands markers the matrices the renderer draws with, so an effect,
  a particle system or a contrail attached to a moving object follows it
  between the ticks too.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-10-05 17:13:27 +13:00
MrBruh cf17201ec8 Split screen divider spans wide screens 2026-10-05 17:13:27 +13:00
MrBruh 45de17116b Merge pull request #82 from addisonbair/gamescope-fullscreen
Count a fullscreen window that gamescope never confirms as fullscreen
2026-10-05 17:01:51 +13:00
xshxdex98 7d56f34b83 Map screen: choose co-op campaign or multiplayer, then vanilla or custom maps
Hosting over LAN or the internet, the Map screen's list first offers CO-OP
CAMPAIGN or MULTIPLAYER. CO-OP CAMPAIGN offers CAMPAIGN or CUSTOM CAMPAIGN,
then a level and its difficulty. MULTIPLAYER offers VANILLA MAPS or CUSTOM
MAPS, then the maps, and goes on to the gametypes as before. B steps back
through the choices and leaves the screen from the first. Split screen
starts at VANILLA MAPS / CUSTOM MAPS.

The custom lists stay empty and a co-op level cannot be hosted yet: network
co-op and Custom Edition maps come in their own pull requests, which fill
them in.
2026-10-04 22:54:24 -05:00
MrBruh 3c7ba95ff5 Merge pull request #70 from startupfoundry/windows-no-console
Release builds of Windows without a console window
2026-10-05 16:51:22 +13:00
MrBruh 092505224a Merge pull request #25 from garfbargle/macos-android-build
Build the Android port on macOS hosts
2026-10-05 16:48:39 +13:00
MrBruh 079883d640 Merge pull request #59 from saulob/fix/startup-color-flash
Fix incorrect Colors on the initial menu frame
2026-10-05 16:39:03 +13:00
MrBruh 54faa1dab6 Merge pull request #87 from eltanschauung/fix/death-camera-timing-pr
Fix death camera and co-op respawn timing at high frame rates
2026-10-05 16:33:14 +13:00
MrBruh 273152cc25 Merge pull request #80 from FDervish/fix/vertex-explosion
Fix vertices exploding to the screen centre near the camera plane
2026-10-05 16:07:31 +13:00
MrBruh 9bdd7f30c0 Merge pull request #86 from thelinkin3000/fix/host-again-after-backing-out
Make a new game each time Create is chosen
2026-10-05 15:53:59 +13:00
MrBruh 685bf260a0 Either co-op player picks the level 2026-10-05 14:47:11 +13:00
MrBruh 933ed2b7b8 Point updates at OpenCommunityEdition/OpenCE 2026-10-05 14:21:03 +13:00
MrBruh c115f5292d Split screen joins of games under way 2026-10-05 14:06:51 +13:00
eltanschauung 0f22c1d592 Add standalone death and co-op regression tests 2026-10-04 20:33:17 -04:00
eltanschauung fb1abedd8b Keep dead camera target when no living player exists 2026-10-04 20:32:59 -04:00
eltanschauung cd345aac7c Count death and co-op respawn delays in game ticks 2026-10-04 20:32:31 -04:00
MrBruh 7e00135d31 Fix menu crash with no network client 2026-10-05 12:59:15 +13:00
thelinkin3000andClaude Opus 5.5 95416b2cfc Make a new game each time Create is chosen
Backing out of a hosted game keeps its server: the lobby's last local
player leaving pauses it (netgame_unjoin_player). Choosing Create again
threw the host's client away, but network_game_start_new_server makes and
joins a server only when there is none, so the new client never joined the
one left over. The lobby then had nobody in it: START added no player, B
could not leave (not in pregame), and the server's map changes failed to
reach the client that was gone.

Create now disposes the client and server first, so it always makes a new
game and joins it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 23:37:36 +00:00
MrBruh ffc1512dcb Read brokers.txt without SDL on Android 2026-10-05 11:27:05 +13:00
MrBruh 88a7c07ec7 Brokers in brokers.txt 2026-10-05 11:15:11 +13:00
Stefan Maier 8e8713681d Merge remote-tracking branch 'origin/fix/multiview-desktop-compile' 2026-10-04 22:59:55 +02:00
Stefan Maier d7099f3e40 Fix desktop link: bot machine check and glClearDepthf were Android-only
network_game_server_is_bot_machine (cea7abfc, Bots as players of the
host) was written into the HALO_ANDROID block of network_server_manager.c
while bots.c calls it on every platform, and so was the array it reads;
both move out of the guard (on the desktop nothing marks a bot machine,
so the check is always false there, the writes stay Android-only).

glClearDepthf (dc21f4b4, Play in VR on OpenXR headsets) is ES-only:
GL_FUNCTIONS declares it for Android's loader and the define at the top
maps glClearDepth to it, but the desktop context links against GL's
glClearDepth. The clear now calls glClearDepth, which the Android define
turns into glClearDepthf as before.
2026-10-04 22:37:17 +02:00
Stefan Maier 4ba36d7305 VR: fix desktop build, targets_multiview was Android-only
6c3f4ce2 (VR: draw both eyes in one pass) changed prepare_draw to pass
targets_multiview to vertex_shader_get, but the variable is declared and
kept inside the HALO_ANDROID guard (L887): Linux and Windows failed to
compile with 'use of undeclared identifier targets_multiview', Android
was fine. On the desktop there are no multiview layers to stand in for
the back buffer, so the desktop call passes FALSE.
2026-10-04 22:25:21 +02:00
MrBruh e3389991ac Online split screen 2026-10-05 09:18:40 +13:00
Stefan Maier 855f083117 Merge branch 'frame/performance' 2026-10-04 22:04:33 +02:00
Stefan Maier 6f3786de91 Merge branch 'fix/vr-shot-origin' 2026-10-04 22:04:33 +02:00
Stefan MaierandClaude Opus 5.5 493713b0a6 Steam Frame: the refresh rates offered in the log; its rate and speed noted
The runtime offers only the rate SteamOS is set to. At 72 Hz the game holds
it with multiview (about 11.6 ms a frame); at 90 Hz it cannot, and the
frames SteamVR makes up showed as a doubled picture when the head turned.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 21:47:56 +02:00
Stefan Maier bf356fc58a Merge branch 'fix/vr-shot-origin' into frame/controllers 2026-10-04 21:42:21 +02:00
Stefan MaierandClaude Opus 5.5 6a7b919522 VR: shots fly along the aim, not above it
A shot fired from the muzzle of the weapon in the hand was kept inside the
level by the game's test of the line from the eyes to it, which in VR runs
down through the player's own body: the test hit it and moved the shot up
towards the eyes, from where it flew parallel to the aim, a few centimetres
above the crosshair and the laser (measured: up to 7 cm at 3 m). In VR the
line is tested against the level alone (a hand through a wall still does
not fire through it); measured after: the impacts on their rays, on
average within a millimetre.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 21:42:07 +02:00
Addison Bair 20861c06d2 Count a fullscreen window that gamescope never confirms as fullscreen
gamescope (the Steam Deck's Game Mode) makes the window the size of the
display but never confirms the fullscreen request, so SDL leaves
SDL_WINDOW_FULLSCREEN unset. platform_screen_mode then reported a window,
the game drew the Xbox's 640x480, and gamescope stretched it to the
screen, soft and 4:3. A window that was asked to be fullscreen and covers
its display now counts as fullscreen too, so the game draws at the
display's resolution and shape (1280x800 on the Deck).
2026-10-04 19:30:07 +00:00
Fadi DerouicheandClaude Opus 5 fc7271fd52 Step the antenna chain in the tick and draw the frames between the ticks
An antenna's chain is a simulation of the Xbox's own step, an update a tick,
and the port was stepping it once a frame with the frame's own time. Its
springs, its carry and the points' physics then acted against the frames'
movement of it, so how far the chain moved per update depended on the frame
rate, and a vehicle at speed swung it far wider than a tick's step does.

- game.c steps the chain in the tick, beside the effects, which are already
  stepped there.
- antenna.c records the shape each tick leaves, relative to the point the
  vehicle's marker carries the base by. A frame drawn between two ticks is the
  part of the way between those two shapes that it is, carried to where the
  marker is now, so the chain stays on the vehicle it hangs from instead of
  lagging a tick behind it. The gate that left a chain that had not been drawn
  for five updates unstepped counted frames; it counts ticks now, which is
  what it counted on the Xbox.
- widgets.c no longer steps the chain from the widget update, which ran once a
  frame.
- game_time.c draws the per-frame effects and widgets that hang off objects
  (game_frame) with the pose between the last two ticks, the pose the renderer
  draws with, so what they place on an object is drawn where they put it.
- objects.c hands markers the matrices the renderer draws with, so an effect,
  a particle system or a contrail attached to a moving object follows it
  between the ticks too.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-10-04 19:45:28 +01:00
Stefan MaierandClaude Opus 5.5 c1305fa94f Steam Frame: its controllers as themselves, with the Xbox's layout
SteamVR offers the Frame's controllers by their own profile
(XR_VALVE_frame_controller_interaction); without bindings for it, it mapped
the Quest's onto them, and X and Y landed on the left one's D-pad. Now: the
right one's A, B, X, Y and menu button are the game's A, B, X, Y and Start
(the Xbox's layout), the left one's View is Back and its D-pad the D-pad,
the bumpers switch grenades and the flashlight. The VR options' page of
buttons shows the Frame's layout there. The runtime's extensions and the
controllers' profile are in the log.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 20:28:13 +02:00
Fadi DerouicheandClaude Opus 5 3d2c04d675 Fix vertices exploding to the screen centre near the camera plane
The screen-space conversion that the Xbox's vertex shaders do is undone by
multiplying the screen position by w again, which is lossy near the camera
plane: the conversion takes the reciprocal of w (rcc), which clamps there, and
1/w rounds differently on each GPU.

Worse, where w is zero or not a number the reconstruction leaves the vertex at
the clip-space origin. That point is inside the frustum, so nothing clips the
triangle away, and OpenGL's zero divided by zero puts the vertex in the middle
of the screen: the triangle is then drawn from wherever its other vertices are
out to there. On the first-person weapon, whose pose follows the camera and so
reaches the camera plane, that is a streak across the whole view. The Xbox's
own divide sends such a vertex to infinity and its clipper discards the
triangle.

Compute the final position from the clip-space position that the shader keeps
whenever it takes the reciprocal of w, so that nothing is reconstructed by
dividing; and where w is zero or not a number, put the vertex behind the
camera (w = -1), which the clipper also discards, as the Xbox did.

Both paths were behind the Android build's #ifdef, so desktop GL only ever
used the lossy reconstruction. The y flip and depth range that follow remain
per platform.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-10-04 19:27:35 +01:00
Stefan MaierandClaude Opus 5.5 0fc85d6c67 Steam Frame: the overlays' alpha from their colour on SteamVR
SteamVR draws a quad's texels by their alpha alone, and the game's menus,
HUD and text have none in their additive parts: on the Frame nothing showed.
On SteamVR (the runtime's name says) the copy into the quads' images takes
their alpha from their colour where it is higher; HALO_XR_QUAD_ALPHA
(colour, keep) overrides, for trying. The Frame's notes updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 20:17:43 +02:00
Stefan MaierandClaude Opus 5.5 c0a08f395e Steam Frame: the game's data in the SteamOS user's Documents when it is there
Lepton empties the app's own folders (and uninstalls the app) whenever it
starts again; Documents is the SteamOS user's and kept. When
/home/steamos/Documents/HaloCE holds the maps and is writable, the launcher
and the game take it as the data folder (maps, config.toml, saves, logs).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 19:51:08 +02:00
Stefan MaierandClaude Opus 5.5 06cb70fb58 Steam Frame: notes, and no variable the Android loader never reads
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 18:27:28 +02:00
Stefan MaierandClaude Opus 5.5 1709698053 Start on the Steam Frame (Lepton)
Lepton has no clipboard service, and SDL3's activity died taking one for
granted: the build now patches SDL's clipboard handler to do without.
The Frame lists an implicit OpenXR layer for Vulkan apps whose library an
app cannot load, which failed xrCreateInstance (and the Android loader
reads no variable to turn it off): the app now carries a pass-through
layer under that library's name. With both, the game runs on the Frame
and its OpenXR session starts (SteamVR, 1728x1728 an eye, 72 Hz).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 18:26:39 +02:00
Stefan Maier cb72dca40f Merge branch 'merge/upstream-2026-10-04' 2026-10-04 14:00:26 +02:00
Stefan MaierandClaude Opus 5.5 bbea2a2bff The online panel's game by its row past the fixed rows
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 13:47:56 +02:00
Stefan MaierandClaude Opus 5.5 57cdbd8f80 Merge upstream (cybersecurity/halo-ce-universal 193cbf59): server browser, split-screen co-op
Upstream's server browser of public internet games (p2p_lobby.c) and the VR
port's own public list share the brokers: its topics are a table now, and
the VR port's (join codes' and public games') are entries of it; the VR
port's retained publishes carry MQTT 5's empty properties. The VR port's
public toggle lists the game in the server browser too, and the VR online
panel shows the server browser's games (PC, phones, VR) first, joined by
their invites, then its own list's that it has not.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 13:47:29 +02:00
Stefan Maier c5c5a8eaeb Merge branch 'feature/bots-vehicles' 2026-10-04 13:33:07 +02:00
Stefan Maier a3ee36b5ef Merge branch 'feature/vr-hud-fixes' 2026-10-04 13:33:07 +02:00
Stefan Maier 30a1e0f40e Merge branch 'feature/vr-menu-lists' 2026-10-04 13:33:07 +02:00
Stefan Maier 327cf96d6f Merge branch 'feature/vr-options' 2026-10-04 13:33:07 +02:00
Stefan MaierandClaude Opus 5.5 867855d388 Bot drivers see walls and rocks ahead, back off when stuck, go round teammates
Driving a jeep or a scout, a bot looks ahead (farther the faster) along the
way it turns: a wall or a rock there (not ground it can drive up) is passed
on the most open side nearest its way, slower, and boxed in it backs off.
Stuck is now making no way along its heading for a second and a half, which
spinning wheels no longer hide. A teammate in the way is gone round slowly
on the other side instead of waited for.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 13:25:15 +02:00
Stefan MaierandClaude Opus 5.5 9e7fd75f57 Bots: a vehicle left stuck is left alone a while; every third bot follows a person
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 11:41:40 +02:00
Stefan MaierandClaude Opus 5.5 6754403d68 VR: the menu pointer leaves the stick's choice be; clicks beside a list step it
A choice the stick moved to (a map among the tiles) is no longer taken back
by the pointer resting on another, until the pointer moves well away; and a
click beside a list's slots or a value's box, along the way it steps (where
its arrows are drawn), steps it back or on.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 11:41:09 +02:00
Stefan MaierandClaude Opus 5.5 aedf5ff9bc Bot drivers wait for those coming to get in, and brake for teammates
Just in, a bot driver waits up to six seconds while a bot goes for its
vehicle or a person of its team stands near it with a gun's seat free; it
brakes (backing, if fast) for a teammate on foot in its way. A bot takes a
vehicle only when the nearest enemy (or the objective) is a long way off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 11:39:24 +02:00
MrBruh 193cbf59c7 Split-screen co-op 2026-10-04 22:27:13 +13:00
Stefan MaierandClaude Opus 5.5 fe160e9dbe Bots man turrets while an enemy is about
A turret near a bot (15 world units) is manned while an enemy is within 35
of it, and left once there has been no one to shoot for ten seconds; at it
the bot aims and fires as at a vehicle's gun. The map's vehicles are named
in the log once a game.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 11:23:49 +02:00
MrBruhandClaude Opus 5.5 d578f88bd0 Validate server browser names as player names
The server browser cleans each game's name as a host cleans the names
of the players and machines that join it, and leaves out a game whose
name has nothing left that names it. A host lists a Latin letter with
a mark as its plain letter, as player names are read.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-04 20:53:00 +13:00
MrBruhandClaude Opus 5.5 d3fc997fdc Ready walked-over weapons, swap out the selected one
In multiplayer a second weapon is picked up into the empty slot on
walking over it and readied, as in campaign; a client readies the
weapon the host says it picked up once it has it. A swap drops the
weapon the player selected, not the one still in hand mid-switch.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-04 20:47:06 +13:00
MrBruh a227872ccb Merge pull request #73 from thelinkin3000/fix/unarmed-melee-campaign
Leave an unarmed melee alone where the map has no multiplayer weapons
2026-10-04 20:28:01 +13:00
MrBruh 812ffeea33 Outline the focused server browser row 2026-10-04 20:19:12 +13:00
MrBruh c05864b3fc Leave quit players off the scoreboard 2026-10-04 20:06:28 +13:00
thelinkin3000andClaude Opus 5.5 ce77db8404 Leave an unarmed melee alone where the map has no multiplayer weapons
A player with no weapon, whose biped has no blow of its own, borrows the
melee of the globals' first multiplayer weapon. A campaign map's globals
list no multiplayer weapons, and a10 starts the player unarmed, so a melee
in the cryo tube's tutorial asked for element 0 of an empty block and
halted in tag_groups.c. With no multiplayer weapon there is no blow to
borrow, and the melee does what the game's always did there: nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 06:22:42 +00:00
MrBruh 39350fb81f Enemy names to the motion sensor's range and setting 2026-10-04 18:57:11 +13:00
MrBruh 1a15a171ac No unarmed grenades or melee from vehicle seats 2026-10-04 17:54:34 +13:00
MrBruh 2e3841ff7d Left-align the shotgun's ammo meter 2026-10-04 17:47:55 +13:00
MrBruh 46edf53657 Settings and End Game in the pause menu 2026-10-04 17:20:32 +13:00
Paul Hontz cd747c23c5 Log of the port to halo.log without a console
The release build no longer has a console, and the platform layer's log
(platform_log to stderr: invite links, the data root, crash reports)
went only there. When stderr goes nowhere, halo.log next to halo.exe
gets it instead.
2026-10-03 22:43:14 -04:00
Paul Hontz f148dbd6d9 Release builds of Windows without a console window
The release halo.exe was a console-subsystem PE, so Windows and Wine
open an empty console window next to the game. Under Proton in
gamescope the console can take focus and leave a black screen. Nothing
reads the console (the log is debug.txt), so release builds now link as
GUI with mainCRTStartup; debug builds keep the console.
2026-10-03 22:26:20 -04:00
MrBruh c3adcfe5bf Deflate the release zips again 2026-10-04 14:22:11 +13:00
MrBruh 3304965653 Lobby check test past the compiler launcher 2026-10-04 13:43:13 +13:00
MrBruh c04765d7f4 Server browser of public internet games 2026-10-04 13:34:23 +13:00
MrBruh 933aac6175 No map weapons option, grenades with no weapon 2026-10-04 10:44:37 +13:00
MrBruh 809408c663 Survive kills and joins in departed players' slots 2026-10-04 10:12:32 +13:00
MrBruh 601a4c1f50 Unload the menu map before a client's next game 2026-10-04 09:51:47 +13:00
MrBruh 133d6a5dc1 Free quit players' slots 2026-10-04 09:07:47 +13:00
Stefan MaierandClaude Opus 5.5 12c97ffa85 Bots take vehicles: drive, man the gun, ride along; and race
A bot whose way is long takes an empty vehicle it can drive near it (a
Warthog, a Ghost, a Scorpion), walking to the driver's door and standing
there until the game offers the seat. Driving, it follows a vehicle's path
(from the vehicle's surface, wider, its steps further apart), turning a
Warthog or a Ghost by facing where it goes and pushing a Scorpion there from
where its gun faces; it runs an enemy down, circles one with a gunner
aboard, fires a Ghost's and a Scorpion's guns, backs off what it is stuck
on, roams between the map's spawn points, and gets out at the objective,
overturned, stuck again and again, or with an enemy close while it stands.
In a game of teams a bot mans the gun of a teammate's vehicle, a person's
first (or rides along with a person), aims and fires it, and gets out once
no one drives. Overturned vehicles near it are turned upright.

In a race a bot heads for the flag it is to touch next
(game_engine_race_next_flag), in a vehicle if it can have one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 16:48:59 +02:00
saulo benigno 61623e68d5 Fix texture bindings after first upload 2026-10-03 11:41:54 -03:00
MrBruh 23b542601f Unarmed melee and infinite grenades for any player count 2026-10-04 03:22:16 +13:00
MrBruh 62b630a261 Remove the flamethrower and gravity rifle 2026-10-04 03:05:59 +13:00
Stefan MaierandClaude Opus 5.5 0e6327cadf The controls page lists switching grenades (B held) on a line of its own
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 15:41:56 +02:00
Stefan MaierandClaude Opus 5.5 5f82df71f0 VR options: Y on the main menu or the pause menu
A panel of the VR settings one may change while playing (turning, snap
angle, smooth speed, the vehicles' comfort vignette, the Warthog's wheel,
the weapon laser, the crosshair, the motion tracker on the wrist), written
to config.toml, which vr.c reads again as they change; and a page of what
the controllers' buttons do, on foot, in vehicles and in the menus. The
pointer works both, and its hint opens the panel. The menus' screens are
named in the log as they come up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-03 15:37:10 +02:00
MrBruh e8e0c2215a Find the port's headers in Windows game units 2026-10-04 02:08:45 +13:00
MrBruh 383355381c Kills to win up to 500 in the PC menus 2026-10-04 02:04:14 +13:00
Milenko 2b0103a0ef Slayer's kills to win up to 500, for big games
The game type editor's kills to win (Slayer and Team Slayer) went up to
50, which a game of many players reaches in moments: it now also offers 75,
100, 150, 200, 250 and 500. The spinner's items are its string list's
(ui.map's 5, 10, 15, 25, 50) and then strings of the port's own, each with
its description; the options list's descriptions count only a spinner's
items of the tag's own, so those of the rows after it are where they were.
A spinner with extra items is a little wider, for three digits.
2026-10-04 01:58:26 +13:00
codi 557c0b486c Build the Android port on macOS hosts
configure.py hardcoded the NDK's linux-x86_64 toolchain folder, so the
Android build could not find the NDK on a Mac. Pick the host's folder
(darwin-x86_64, windows-x86_64 or linux-x86_64), or the only one the NDK
has.

On a case-insensitive file system, the game's <StdDef.h> shim found itself
again through its own <stddef.h> inclusion and recursed. Use include_next,
as the port's other header shims do.
2026-09-29 20:51:24 -06:00
178 changed files with 22319 additions and 976 deletions

No files matched your search

+1 -4
View File
@@ -242,10 +242,7 @@ jobs:
mkdir release
for build in artifacts/*/; do
name="$(basename "$build")"
# stored, not deflated: the updater in builds up to 57 waits for
# an end of stream the game's zlib 1.1 does not always report,
# and fails on a deflated entry that unpacked correctly
(cd "$build" && zip -0 -qr "$GITHUB_WORKSPACE/release/$name.zip" .)
(cd "$build" && zip -qr "$GITHUB_WORKSPACE/release/$name.zip" .)
done
ls -l release
+4 -4
View File
@@ -19,9 +19,9 @@ builds of the latest release:
| Platform | Release | Debug |
| --- | --- | --- |
| Linux | [halo-linux-release.zip](https://github.com/cybersecurity/halo-ce-universal/releases/latest/download/halo-linux-release.zip) | [halo-linux-debug.zip](https://github.com/cybersecurity/halo-ce-universal/releases/latest/download/halo-linux-debug.zip) |
| Windows | [halo-windows-release.zip](https://github.com/cybersecurity/halo-ce-universal/releases/latest/download/halo-windows-release.zip) | [halo-windows-debug.zip](https://github.com/cybersecurity/halo-ce-universal/releases/latest/download/halo-windows-debug.zip) |
| Android | [halo-android-release.zip](https://github.com/cybersecurity/halo-ce-universal/releases/latest/download/halo-android-release.zip) | [halo-android-debug.zip](https://github.com/cybersecurity/halo-ce-universal/releases/latest/download/halo-android-debug.zip) |
| Linux | [halo-linux-release.zip](https://github.com/OpenCommunityEdition/OpenCE/releases/latest/download/halo-linux-release.zip) | [halo-linux-debug.zip](https://github.com/OpenCommunityEdition/OpenCE/releases/latest/download/halo-linux-debug.zip) |
| Windows | [halo-windows-release.zip](https://github.com/OpenCommunityEdition/OpenCE/releases/latest/download/halo-windows-release.zip) | [halo-windows-debug.zip](https://github.com/OpenCommunityEdition/OpenCE/releases/latest/download/halo-windows-debug.zip) |
| Android | [halo-android-release.zip](https://github.com/OpenCommunityEdition/OpenCE/releases/latest/download/halo-android-release.zip) | [halo-android-debug.zip](https://github.com/OpenCommunityEdition/OpenCE/releases/latest/download/halo-android-debug.zip) |
Use the release build to play. The debug build stops at the first failed
assertion and writes it to the log. Use the debug build to find and report
@@ -32,7 +32,7 @@ if you want to install it. Refer to "Updates" in
[port/linux/README.md](port/linux/README.md#updates).
Each build of the `main` branch that passes on all three platforms is a new
release. The [Releases](https://github.com/cybersecurity/halo-ce-universal/releases)
release. The [Releases](https://github.com/OpenCommunityEdition/OpenCE/releases)
page keeps the last five releases. If the latest build has a problem, get
an older build from that page.
+125
View File
@@ -0,0 +1,125 @@
# Steam Frame
The same APK as for the Quest runs on the Steam Frame, in Lepton (SteamOS's
Android, a Waydroid fork: Android 11, arm64), with SteamVR's OpenXR runtime.
What differs is found at run time, not by a build of its own.
## The device
- Steam Settings > System > Enable Developer Mode; then start "Lepton
Development" from the library. While the headset sleeps Lepton stops, and
adb with it.
- adb over the network: `adb connect <frame-ip>:5555`; over USB:
`adb forward tcp:5555 tcp:5555` then `adb connect localhost:5555`.
Always name the device (`adb -s <frame-ip>:5555 ...`): a Quest may be
connected as well.
- Install with `adb install -r --no-streaming`. It prints "Lepton post
installation failed due to APP_PATH being unset", but installs. Start the
game with `am start -n com.halo.decomp/.LauncherActivity`.
- Lepton empties `/sdcard/Android/data` whenever it starts again: the game's
data must live elsewhere (stage 2). `/sdcard/Documents` and
`/sdcard/Download` are the SteamOS user's folders and are kept.
## What the port does for it
- SDL3's clipboard handler takes a clipboard service for granted, which
Lepton has not: `tools/android_build.py` patches it to do without.
- SteamVR lists an implicit OpenXR layer for Vulkan apps whose library an
app cannot load: the APK carries a pass-through layer under its name
(`port/android/xr_layer/fdm_injection_stub.c`).
## Stages
| # | Stage | State |
| --- | --- | --- |
| 1 | Base: the fixes above on the current main | done |
| 2 | The game's data where Lepton keeps it | done: `/home/steamos/Documents/HaloCE` |
| 3 | Menus, HUD and text visible (quad layers) | done: their alpha from their colour |
| 4 | The freeze at the cryo bay's calibration | not seen again (2026-10-04) |
| 5 | The Frame's controllers | done: their own profile, the Xbox's layout |
| 6 | Frame rate, resolution | done: 72 Hz steady, multiview on |
| 7 | Multiplayer, voice, cross-play with the Quest | |
| 8 | A button in the Steam library | done: `steam_frame_launch.sh` |
## Starting it on the Frame
A button in the Steam library ("Halo VR", a non-Steam game) runs
`~/Documents/HaloCE/halo-vr.sh` (`port/android/steam_frame_launch.sh`),
which starts the game as Steam starts an Android title of its own:
`lepton waitforexitandrun -- ~/Documents/HaloCE/HaloVR.apk`, in a container
of its own (`steamlaunch-4290000001`) that Lepton installs the APK into
anew whenever the file is newer. Updating the game is replacing that APK.
What the script does that Steam would for an Android title:
- a compat data path (`steamapps/compatdata/4290000001/internal`): after an
install Lepton links the app's data to it, a dangling link without it;
and the shader path, which Lepton reads Steam's shader dump path against;
- a container id of its own: with the shortcut's id, SteamVR's client in the
container stalled in xrCreateInstance;
- a few starts: a new APK's first start only installs it, and a start that
ends within 30 s is tried again (up to three times), unless the game was
quit (it writes `quit_requested.txt`).
Steam's "Exit game" does not reach the game (its process is the container's,
not Steam's): quit it with the VR options' "Quit Halo" (Y in the main or
pause menu, twice). A container ended within 30 s of its start makes
Lepton drop the app's install, so the next start installs it again.
The shortcut is in `userdata/<id>/config/shortcuts.vdf` (Steam reads it when
it starts; appid 3151454348 for this name and path), its pictures in
`userdata/<id>/config/grid/` (from `port/android/steam_frame_grid/`). From
the Mac, over USB the Frame's SteamOS is an adb device of its own, `frame`,
beside Lepton's `<frame-ip>:5555`.
## The game's data
Lepton uninstalls the app and empties its folders whenever it starts again.
The game's data lives in the SteamOS user's Documents instead: when
`/home/steamos/Documents/HaloCE` holds `maps/ui.map` and is writable, the
launcher and the game take it as their data folder (config.toml, saves and
debug.txt go there too). Once:
adb -s <frame-ip>:5555 shell mkdir -p /home/steamos/Documents/HaloCE/maps
adb -s <frame-ip>:5555 push assets/maps/. /home/steamos/Documents/HaloCE/maps/
adb -s <frame-ip>:5555 shell chmod -R 777 /home/steamos/Documents/HaloCE
After a Lepton restart only the APK is installed again. (Use the path under
/home, not /sdcard/Documents: Android 11's scoped storage stands between the
app and the latter.)
## The controllers
SteamVR offers the Frame's controllers as themselves
(`XR_VALVE_frame_controller_interaction`,
`/interaction_profiles/valve/frame_controller_valve`; Valve's "Steam Frame
Input" page). Without bindings for it, SteamVR maps the Quest's onto them,
and the left Touch controller's X and Y land on the D-pad. With them the
game gets the Xbox's layout, as the right controller has it: A jump, B
flashlight (held: switch grenades), X action and reload, Y switch weapon,
menu pause; the left one's View is Back (scores), its D-pad the D-pad, the
bumpers switch grenades (left) and the flashlight (right). The VR options'
page of buttons shows this layout on the Frame.
## Findings
- 2026-10-02: runs flat and in VR (GLES 3.2 by Mesa zink on Turnip, eyes
1728x1728, 72 Hz, XR_FB_display_refresh_rate absent). Quad layers
(menus, HUD, instructions) are not shown; the projection layer is. Froze
at the cryo bay's look calibration; its log was lost to Lepton's wipe.
- 2026-10-04: SteamVR draws a quad's texels by their alpha alone; the
game's menus and HUD have none in their additive parts, so nothing showed.
On SteamVR (by the runtime's name) the overlays' alpha now comes from their
colour (host_xr.c; `HALO_XR_QUAD_ALPHA=colour|keep` overrides). With it,
menus, HUD and the campaign ran well (the user: "lief 1a"); no freeze.
- 2026-10-04: no online games found: the public MQTT brokers had banned the
home connection for a while (too many connections from tests that day);
broker.emqx.io came back within minutes. Lepton's network is the Frame's
own (same IP), DNS works.
- 2026-10-04: the refresh rate is SteamOS's setting; the runtime offers
only that one (the game asks for the highest at or below
`vr.refresh_rate`, and logs the rates offered). At 72 Hz the game holds
72 fps (about 11.6 ms a frame with multiview, eyes 7.6 ms; without it
eyes about 9 ms). At 90 Hz it cannot (11.1 ms a frame), and SteamVR's
making up of the missed frames showed as a doubled picture when turning
the head. Keep the Frame at 72 Hz, or lower `vr.resolution_scale` (about
0.85) for 90.
@@ -35,6 +35,7 @@ import java.nio.channels.FileChannel;
*/
public class LauncherActivity extends Activity {
private static final int PICK_IMAGE = 1;
private static final String SHARED_DATA_ROOT = "/home/steamos/Documents/HaloCE";
private File dataRoot;
private TextView status;
@@ -46,6 +47,12 @@ public class LauncherActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
dataRoot = getExternalFilesDir(null);
// the Steam Frame: Lepton empties the app's own folders whenever it
// starts again; the game's data lives in the SteamOS user's
// Documents instead, when it is there (port/android/STEAM_FRAME.md;
// the same choice as host_main.c's)
if (new File(SHARED_DATA_ROOT, "maps/ui.map").isFile() && new File(SHARED_DATA_ROOT).canWrite())
dataRoot = new File(SHARED_DATA_ROOT);
// created by the app, so that files pushed into it with adb stay
// readable (a directory adb creates there belongs to the shell user)
if (dataRoot != null)
+32
View File
@@ -90,6 +90,8 @@ int host_errno(void)
static char data_root[512];
static char save_root[512];
/* where a device that empties the app's folders keeps the game's data */
#define SHARED_DATA_ROOT "/home/steamos/Documents/HaloCE"
void host_android_path(int which, char *buffer, uint32_t size)
{
@@ -269,6 +271,12 @@ static void *game_main(void *unused)
external = SDL_GetAndroidExternalStoragePath();
if (!external)
host_fatal("Android storage is unavailable: %s", SDL_GetError());
/* the Steam Frame: Lepton empties the app's own folders whenever it
starts again; the game's data lives in the SteamOS user's Documents
instead, when it is there (port/android/STEAM_FRAME.md; the same choice
as LauncherActivity's) */
if (directory_has_maps(SHARED_DATA_ROOT) && access(SHARED_DATA_ROOT, W_OK) == 0)
external = SHARED_DATA_ROOT;
snprintf(data_root, sizeof(data_root), "%s", external);
snprintf(save_root, sizeof(save_root), "%s/save", external);
/* readable by adb (the shell user), for managing saves */
@@ -293,6 +301,19 @@ static void *game_main(void *unused)
environment_set(&environment, "HALO_SAVE_ROOT", save_root);
time_zone(zone, sizeof(zone));
environment_set(&environment, "TZ", zone);
/* internet play's MQTT brokers (network.brokers_file): the APK's list,
written beside config.toml at each start, as a desktop update replaces
the file beside its game */
{
size_t brokers_size = 0;
void *brokers = SDL_LoadFile("brokers.txt", &brokers_size);
snprintf(path, sizeof(path), "%s/brokers.txt", data_root);
if (!brokers || !SDL_SaveFile(path, brokers, brokers_size))
host_logf(HOST_LOG_ERROR, "cannot write %s: %s", path, SDL_GetError());
SDL_free(brokers);
}
snprintf(path, sizeof(path), "%s/config.toml", data_root);
image = SDL_LoadFile("halo_guest.elf", &image_size);
if (!image)
@@ -305,6 +326,17 @@ static void *game_main(void *unused)
ranges: the headset's runtime, loaded by the probe, maps its libraries
wherever there is room, the Xbox window at 0x80000000 included */
snprintf(path, sizeof(path), "%s/config.toml", data_root);
{
/* (debug.gl_thread: Mesa's GL thread on or off, as the driver's
mesa_glthread, before the GL context is made; -1 leaves it be) */
double gl_thread = config_number(path, "debug.gl_thread", -1.0);
if (gl_thread >= 0.0)
{
setenv("mesa_glthread", gl_thread != 0.0 ? "true" : "false", 1);
host_logf(HOST_LOG_INFO, "Mesa's GL thread %s (debug.gl_thread)", gl_thread != 0.0 ? "on" : "off");
}
}
{
int eye_width, eye_height;
+358 -4
View File
@@ -38,6 +38,8 @@ picture; the copy flips them to GL's bottom-up images.
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sched.h>
#include <stdio.h>
#define XR_USE_PLATFORM_ANDROID
#define XR_USE_GRAPHICS_API_OPENGL_ES
@@ -102,6 +104,14 @@ static struct
XrAction button_b; /* B on the right controller, Y on the left */
XrAction menu;
XrAction thumbrest;
/* the Steam Frame's controllers' own (XR_VALVE_frame_controller_interaction) */
int has_frame_controller;
int frame_layout;
XrAction button_x;
XrAction button_y;
XrAction view;
XrAction bumper;
XrAction dpad[4];
XrAction haptic;
struct xr_hand_actions hands[HALO_XR_HAND_COUNT];
@@ -111,6 +121,22 @@ static struct
int left_grip_valid;
int has_performance_settings;
/* (XR_META_performance_metrics: the compositor's counts, in the log,
for telling frames shown late from the game's own pace) */
int has_metrics;
PFN_xrQueryPerformanceMetricsCounterMETA query_metric;
XrPath metric_paths[16];
uint32_t metric_count;
struct timespec metrics_logged;
/* (SteamVR: the frames' thread kept on the fast cores, xr_fast_cores) */
int steamvr;
int cores_pinned;
/* (with the metrics: the time the copies into the layers' images and
xrEndFrame took, since the last line, and the frames) */
double copy_seconds[HALO_XR_LAYER_COUNT];
double end_seconds;
double acquire_seconds;
int timed_frames;
int has_refresh_rate;
PFN_xrRequestDisplayRefreshRateFB request_refresh_rate;
PFN_xrGetDisplayRefreshRateFB get_refresh_rate;
@@ -122,6 +148,11 @@ static struct
GLint rect_uniform;
GLint cut_disc_uniform;
GLint vignette_uniform;
GLint alpha_from_colour_uniform;
/* the runtime draws a quad's texels by their alpha alone, ignoring the
colour of those with none (SteamVR on the Steam Frame): the game's
overlays, whose additive parts have none, get alpha from their colour */
int quad_alpha_from_colour;
GLint tangents_uniform;
float vignette;
/* the same copy from a layer of a texture array (the eyes drawn at
@@ -223,6 +254,7 @@ static const char copy_fragment_shader[] =
"precision highp float;\n"
"uniform sampler2D source;\n"
"uniform float cut_disc;\n"
"uniform float alpha_from_colour; /* 1: as opaque as it is bright (a quad's, SteamVR) */\n"
"uniform float vignette; /* 0..1: the eye images darken from their edges */\n"
"uniform vec4 tangents; /* the eye's edges: left, right, down, up */\n"
"in vec2 coordinate;\n"
@@ -236,6 +268,8 @@ static const char copy_fragment_shader[] =
"{\n"
" vec4 texel = texture(source, coordinate);\n"
" color = vec4(to_linear(texel.rgb), texel.a);\n"
" if (alpha_from_colour > 0.5)\n"
" color.a = max(color.a, max(color.r, max(color.g, color.b)));\n"
" if (cut_disc > 0.5)\n"
" {\n"
" float inside = 1.0 - smoothstep(0.95, 1.0, length(disc));\n"
@@ -326,6 +360,7 @@ static int copy_initialize(void)
xr.rect_uniform = glGetUniformLocation(xr.program, "rect");
xr.cut_disc_uniform = glGetUniformLocation(xr.program, "cut_disc");
xr.vignette_uniform = glGetUniformLocation(xr.program, "vignette");
xr.alpha_from_colour_uniform = glGetUniformLocation(xr.program, "alpha_from_colour");
xr.tangents_uniform = glGetUniformLocation(xr.program, "tangents");
xr.copy_array_layer = -1;
{
@@ -580,6 +615,14 @@ static int actions_initialize(void)
xr.button_b = action_create("button_upper", "B / Y", XR_ACTION_TYPE_BOOLEAN_INPUT);
xr.menu = action_create("menu", "Menu", XR_ACTION_TYPE_BOOLEAN_INPUT);
xr.thumbrest = action_create("thumbrest", "Thumb rest", XR_ACTION_TYPE_BOOLEAN_INPUT);
xr.button_x = action_create("button_x", "X", XR_ACTION_TYPE_BOOLEAN_INPUT);
xr.button_y = action_create("button_y", "Y", XR_ACTION_TYPE_BOOLEAN_INPUT);
xr.view = action_create("view", "View", XR_ACTION_TYPE_BOOLEAN_INPUT);
xr.bumper = action_create("bumper", "Bumper", XR_ACTION_TYPE_BOOLEAN_INPUT);
xr.dpad[0] = action_create("dpad_up", "D-pad up", XR_ACTION_TYPE_BOOLEAN_INPUT);
xr.dpad[1] = action_create("dpad_down", "D-pad down", XR_ACTION_TYPE_BOOLEAN_INPUT);
xr.dpad[2] = action_create("dpad_left", "D-pad left", XR_ACTION_TYPE_BOOLEAN_INPUT);
xr.dpad[3] = action_create("dpad_right", "D-pad right", XR_ACTION_TYPE_BOOLEAN_INPUT);
xr.haptic = action_create("haptic", "Rumble", XR_ACTION_TYPE_VIBRATION_OUTPUT);
{
@@ -644,6 +687,44 @@ static int actions_initialize(void)
{ &xr.haptic, "/user/hand/right/output/haptic" },
};
/* the Steam Frame's controllers, as themselves: the right one has
A, B, X, Y and a menu button, the left one a D-pad and a View button
(port/android/STEAM_FRAME.md) */
static const struct binding frame_controller[] =
{
{ &xr.grip_pose, "/user/hand/left/input/grip/pose" },
{ &xr.grip_pose, "/user/hand/right/input/grip/pose" },
{ &xr.aim_pose, "/user/hand/left/input/aim/pose" },
{ &xr.aim_pose, "/user/hand/right/input/aim/pose" },
{ &xr.trigger, "/user/hand/left/input/trigger/value" },
{ &xr.trigger, "/user/hand/right/input/trigger/value" },
{ &xr.squeeze, "/user/hand/left/input/squeeze/value" },
{ &xr.squeeze, "/user/hand/right/input/squeeze/value" },
{ &xr.thumbstick, "/user/hand/left/input/thumbstick" },
{ &xr.thumbstick, "/user/hand/right/input/thumbstick" },
{ &xr.thumbstick_click, "/user/hand/left/input/thumbstick/click" },
{ &xr.thumbstick_click, "/user/hand/right/input/thumbstick/click" },
{ &xr.button_a, "/user/hand/right/input/a/click" },
{ &xr.button_b, "/user/hand/right/input/b/click" },
{ &xr.button_x, "/user/hand/right/input/x/click" },
{ &xr.button_y, "/user/hand/right/input/y/click" },
{ &xr.menu, "/user/hand/right/input/menu/click" },
{ &xr.view, "/user/hand/left/input/view/click" },
{ &xr.bumper, "/user/hand/left/input/bumper/click" },
{ &xr.bumper, "/user/hand/right/input/bumper/click" },
{ &xr.dpad[0], "/user/hand/left/input/dpad_up/click" },
{ &xr.dpad[1], "/user/hand/left/input/dpad_down/click" },
{ &xr.dpad[2], "/user/hand/left/input/dpad_left/click" },
{ &xr.dpad[3], "/user/hand/left/input/dpad_right/click" },
{ &xr.haptic, "/user/hand/left/output/haptic" },
{ &xr.haptic, "/user/hand/right/output/haptic" },
};
if (xr.has_frame_controller)
{
suggest("/interaction_profiles/valve/frame_controller_valve", frame_controller,
sizeof(frame_controller) / sizeof(frame_controller[0]));
}
suggest("/interaction_profiles/oculus/touch_controller", touch, sizeof(touch) / sizeof(touch[0]));
suggest("/interaction_profiles/valve/index_controller", index, sizeof(index) / sizeof(index[0]));
suggest("/interaction_profiles/khr/simple_controller", simple, sizeof(simple) / sizeof(simple[0]));
@@ -713,6 +794,30 @@ static void hands_read(struct halo_xr_frame *frame)
sync.activeActionSets = &active;
if (!XR_SUCCEEDED(xrSyncActions(xr.session, &sync)))
return;
{
/* (the controllers' profile the runtime chose, in the log as it
changes) */
static XrPath logged[HALO_XR_HAND_COUNT];
for (hand = 0; hand < HALO_XR_HAND_COUNT; hand++)
{
XrInteractionProfileState state = { XR_TYPE_INTERACTION_PROFILE_STATE };
if (XR_SUCCEEDED(xrGetCurrentInteractionProfile(xr.session, xr.hands[hand].path, &state)) &&
state.interactionProfile != logged[hand])
{
char name[XR_MAX_PATH_LENGTH] = "none";
uint32_t length = 0;
logged[hand] = state.interactionProfile;
if (state.interactionProfile != XR_NULL_PATH)
xrPathToString(xr.instance, state.interactionProfile, sizeof(name), &length, name);
if (hand == HALO_XR_HAND_RIGHT)
xr.frame_layout = strstr(name, "frame_controller") != NULL;
host_logf(HOST_LOG_INFO, "xr: the %s hand's controller: %s", hand ? "right" : "left", name);
}
}
}
for (hand = 0; hand < HALO_XR_HAND_COUNT; hand++)
{
struct halo_xr_hand *out = &frame->hands[hand];
@@ -757,7 +862,31 @@ static void hands_read(struct halo_xr_frame *frame)
(action_boolean(xr.menu, hand) ? HALO_XR_BUTTON_MENU : 0) |
(action_boolean(xr.thumbrest, hand) ? HALO_XR_BUTTON_THUMBREST : 0) |
(out->trigger > 0.5f ? HALO_XR_BUTTON_TRIGGER : 0) |
(out->squeeze > 0.5f ? HALO_XR_BUTTON_SQUEEZE : 0);
(out->squeeze > 0.5f ? HALO_XR_BUTTON_SQUEEZE : 0) |
(action_boolean(xr.view, hand) ? HALO_XR_BUTTON_VIEW : 0) |
(action_boolean(xr.bumper, hand) ? HALO_XR_BUTTON_BUMPER : 0) |
(action_boolean(xr.dpad[0], hand) ? HALO_XR_BUTTON_DPAD_UP : 0) |
(action_boolean(xr.dpad[1], hand) ? HALO_XR_BUTTON_DPAD_DOWN : 0) |
(action_boolean(xr.dpad[2], hand) ? HALO_XR_BUTTON_DPAD_LEFT : 0) |
(action_boolean(xr.dpad[3], hand) ? HALO_XR_BUTTON_DPAD_RIGHT : 0);
}
frame->controller_layout = xr.frame_layout ? HALO_XR_LAYOUT_FRAME : HALO_XR_LAYOUT_TOUCH;
if (xr.frame_layout)
{
/* (the Frame's right X, Y and menu button: the game's X, Y and Start,
which the Quest has on the left) */
struct halo_xr_hand *left = &frame->hands[HALO_XR_HAND_LEFT];
struct halo_xr_hand *right = &frame->hands[HALO_XR_HAND_RIGHT];
if (action_boolean(xr.button_x, HALO_XR_HAND_RIGHT))
left->buttons |= HALO_XR_BUTTON_A;
if (action_boolean(xr.button_y, HALO_XR_HAND_RIGHT))
left->buttons |= HALO_XR_BUTTON_B;
if (right->buttons & HALO_XR_BUTTON_MENU)
{
right->buttons &= ~HALO_XR_BUTTON_MENU;
left->buttons |= HALO_XR_BUTTON_MENU;
}
}
}
@@ -774,6 +903,13 @@ static void refresh_rate_choose(float wanted)
{
return;
}
{
char line[128] = "";
for (index = 0; index < count; index++)
snprintf(line + strlen(line), sizeof(line) - strlen(line), " %.0f", rates[index]);
host_logf(HOST_LOG_INFO, "xr: refresh rates offered:%s Hz", line);
}
/* the highest rate not above the one wanted (0: the highest) */
for (index = 0; index < count; index++)
{
@@ -895,6 +1031,12 @@ int host_xr_probe(float resolution_scale, int *eye_width, int *eye_height)
/* the loader and the runtime keep the activity */
activity = (*environment)->NewGlobalRef(environment, activity);
/* (The Steam Frame lists an implicit API layer of its own for Vulkan
apps, XR_APILAYER_VALVE_fdm_injection, whose library an app cannot load
from its namespace, failing xrCreateInstance; the Android loader reads
no variable to turn it off, so the app carries a pass-through layer
under that library's name: port/android/xr_layer/fdm_injection_stub.c) */
if (!XR_SUCCEEDED(xrGetInstanceProcAddr(XR_NULL_HANDLE, "xrInitializeLoaderKHR",
(PFN_xrVoidFunction *)&initialize_loader)) || !initialize_loader)
{
@@ -922,6 +1064,23 @@ int host_xr_probe(float resolution_scale, int *eye_width, int *eye_height)
extensions[index].next = NULL;
}
xrEnumerateInstanceExtensionProperties(NULL, extension_count, &extension_count, extensions);
{
/* (the runtime's extensions, in the log: what a headset offers) */
char line[512] = "";
for (index = 0; index < extension_count; index++)
{
if (strlen(line) + strlen(extensions[index].extensionName) + 2 >= sizeof(line))
{
host_logf(HOST_LOG_INFO, "xr: extensions %s", line);
line[0] = 0;
}
strcat(line, " ");
strcat(line, extensions[index].extensionName);
}
if (line[0])
host_logf(HOST_LOG_INFO, "xr: extensions %s", line);
}
if (!has_extension(extensions, extension_count, XR_KHR_OPENGL_ES_ENABLE_EXTENSION_NAME))
{
host_logf(HOST_LOG_ERROR, "xr: the runtime has no OpenGL ES support");
@@ -933,9 +1092,15 @@ int host_xr_probe(float resolution_scale, int *eye_width, int *eye_height)
xr.has_performance_settings = has_extension(extensions, extension_count, XR_EXT_PERFORMANCE_SETTINGS_EXTENSION_NAME);
if (xr.has_performance_settings)
enabled[enabled_count++] = XR_EXT_PERFORMANCE_SETTINGS_EXTENSION_NAME;
xr.has_frame_controller = has_extension(extensions, extension_count, "XR_VALVE_frame_controller_interaction");
if (xr.has_frame_controller)
enabled[enabled_count++] = "XR_VALVE_frame_controller_interaction";
xr.has_refresh_rate = has_extension(extensions, extension_count, XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME);
if (xr.has_refresh_rate)
enabled[enabled_count++] = XR_FB_DISPLAY_REFRESH_RATE_EXTENSION_NAME;
xr.has_metrics = has_extension(extensions, extension_count, XR_META_PERFORMANCE_METRICS_EXTENSION_NAME);
if (xr.has_metrics)
enabled[enabled_count++] = XR_META_PERFORMANCE_METRICS_EXTENSION_NAME;
android.applicationVM = machine;
android.applicationActivity = activity;
@@ -960,6 +1125,23 @@ int host_xr_probe(float resolution_scale, int *eye_width, int *eye_height)
}
xrGetSystemProperties(xr.instance, xr.system, &properties);
strncpy(xr.system_name, properties.systemName, sizeof(xr.system_name) - 1);
{
/* (SteamVR: the quads' alpha from their colour; HALO_XR_QUAD_ALPHA
"colour" or "keep" says otherwise, for trying) */
XrInstanceProperties instance = { XR_TYPE_INSTANCE_PROPERTIES };
const char *choice = getenv("HALO_XR_QUAD_ALPHA");
if (XR_SUCCEEDED(xrGetInstanceProperties(xr.instance, &instance)))
{
xr.quad_alpha_from_colour = strstr(instance.runtimeName, "SteamVR") != NULL;
xr.steamvr = xr.quad_alpha_from_colour;
host_logf(HOST_LOG_INFO, "xr: runtime %s", instance.runtimeName);
}
if (choice)
xr.quad_alpha_from_colour = !strcmp(choice, "colour");
if (xr.quad_alpha_from_colour)
host_logf(HOST_LOG_INFO, "xr: the overlays' alpha from their colour");
}
views[0].type = views[1].type = XR_TYPE_VIEW_CONFIGURATION_VIEW;
views[0].next = views[1].next = NULL;
@@ -1066,6 +1248,25 @@ int host_xr_initialize(struct halo_xr_info *info, float wanted_refresh_rate)
xr.get_refresh_rate(xr.session, &info->refresh_rate);
}
if (xr.has_metrics)
{
PFN_xrEnumeratePerformanceMetricsCounterPathsMETA enumerate = NULL;
PFN_xrSetPerformanceMetricsStateMETA set_state = NULL;
XrPerformanceMetricsStateMETA state = { XR_TYPE_PERFORMANCE_METRICS_STATE_META };
xrGetInstanceProcAddr(xr.instance, "xrEnumeratePerformanceMetricsCounterPathsMETA",
(PFN_xrVoidFunction *)&enumerate);
xrGetInstanceProcAddr(xr.instance, "xrSetPerformanceMetricsStateMETA", (PFN_xrVoidFunction *)&set_state);
xrGetInstanceProcAddr(xr.instance, "xrQueryPerformanceMetricsCounterMETA",
(PFN_xrVoidFunction *)&xr.query_metric);
state.enabled = XR_TRUE;
xr.has_metrics = enumerate && set_state && xr.query_metric &&
XR_SUCCEEDED(enumerate(xr.instance, 16, &xr.metric_count, xr.metric_paths)) &&
XR_SUCCEEDED(set_state(xr.session, &state));
host_logf(HOST_LOG_INFO, "xr: performance metrics %s (%u counters)", xr.has_metrics ? "on" : "off",
xr.has_metrics ? xr.metric_count : 0);
}
if (xr.has_performance_settings)
{
/* the game's one busy thread and its GPU work both need the clocks
@@ -1245,8 +1446,30 @@ int host_xr_copy_layer_array(int layer, uint32_t texture, int array_layer)
/* copies part of a render target (left, top, right, bottom, 0..1 from its
top left) into a layer's image */
static double seconds_now(void)
{
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
return (double)now.tv_sec + (double)now.tv_nsec * 1e-9;
}
static int copy_layer_region(int layer, uint32_t texture, int clear_alpha, float left, float top, float right,
float bottom);
int host_xr_copy_layer_region(int layer, uint32_t texture, int clear_alpha, float left, float top, float right,
float bottom)
{
double start = xr.has_metrics ? seconds_now() : 0.0;
int copied = copy_layer_region(layer, texture, clear_alpha, left, top, right, bottom);
if (xr.has_metrics && layer >= 0 && layer < HALO_XR_LAYER_COUNT)
xr.copy_seconds[layer] += seconds_now() - start;
return copied;
}
static int copy_layer_region(int layer, uint32_t texture, int clear_alpha, float left, float top, float right,
float bottom)
{
struct xr_swapchain *swapchain;
XrSwapchainImageAcquireInfo acquire = { XR_TYPE_SWAPCHAIN_IMAGE_ACQUIRE_INFO };
@@ -1265,8 +1488,14 @@ int host_xr_copy_layer_region(int layer, uint32_t texture, int clear_alpha, floa
return 0;
}
wait.timeout = XR_INFINITE_DURATION;
if (!xr_ok(xrWaitSwapchainImage(swapchain->handle, &wait), "xrWaitSwapchainImage"))
return 0;
{
double start = xr.has_metrics ? seconds_now() : 0.0;
if (!xr_ok(xrWaitSwapchainImage(swapchain->handle, &wait), "xrWaitSwapchainImage"))
return 0;
if (xr.has_metrics)
xr.acquire_seconds += seconds_now() - start;
}
gl_save(&saved);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, swapchain->framebuffers[swapchain->acquired_index]);
@@ -1316,6 +1545,8 @@ int host_xr_copy_layer_region(int layer, uint32_t texture, int clear_alpha, floa
glUniform1i(xr.source_uniform, 0);
glUniform4f(xr.rect_uniform, left, top, right, bottom);
glUniform1f(xr.cut_disc_uniform, clear_alpha == HALO_XR_COPY_DISC ? 1.0f : 0.0f);
glUniform1f(xr.alpha_from_colour_uniform, xr.quad_alpha_from_colour && clear_alpha == HALO_XR_COPY_ALPHA &&
layer != HALO_XR_LAYER_EYE_LEFT && layer != HALO_XR_LAYER_EYE_RIGHT ? 1.0f : 0.0f);
if ((layer == HALO_XR_LAYER_EYE_LEFT || layer == HALO_XR_LAYER_EYE_RIGHT) && xr.vignette > 0.001f)
{
const XrFovf *fov = &xr.views[layer - HALO_XR_LAYER_EYE_LEFT].fov;
@@ -1358,6 +1589,59 @@ int host_xr_copy_layer_region(int layer, uint32_t texture, int clear_alpha, floa
return 1;
}
/* The Steam Frame: Android in a container, without XR_EXT_performance_settings
to ask for the clocks, and the scheduler free to put the game's one busy
thread, which simulates and draws each frame, on a slow core (its two
2.3 GHz ones) now and then: frames late to the compositor, shown twice,
the picture doubled as the head turns. The thread that ends the frames is
kept on the cores no slower than nine tenths of the fastest. */
static void xr_fast_cores(void)
{
cpu_set_t set;
long fastest = 0, speeds[CPU_SETSIZE];
int cpu, count = 0;
char line[128] = "";
for (cpu = 0; cpu < CPU_SETSIZE && cpu < 64; cpu++)
{
char path[96];
FILE *file;
speeds[cpu] = 0;
snprintf(path, sizeof(path), "/sys/devices/system/cpu/cpu%d/cpufreq/cpuinfo_max_freq", cpu);
file = fopen(path, "r");
if (!file)
continue;
if (fscanf(file, "%ld", &speeds[cpu]) != 1)
speeds[cpu] = 0;
fclose(file);
if (speeds[cpu] > fastest)
fastest = speeds[cpu];
}
if (!fastest)
{
host_logf(HOST_LOG_INFO, "xr: the cores' speeds unknown: the frames' thread left where it runs");
return;
}
CPU_ZERO(&set);
for (cpu = 0; cpu < CPU_SETSIZE && cpu < 64; cpu++)
{
if (speeds[cpu] && speeds[cpu] * 10 >= fastest * 9)
{
char item[8];
CPU_SET(cpu, &set);
count++;
snprintf(item, sizeof(item), " %d", cpu);
strcat(line, item);
}
}
if (count && sched_setaffinity(0, sizeof(set), &set) == 0)
host_logf(HOST_LOG_INFO, "xr: the frames' thread on the fast cores:%s (fastest %ld MHz)", line, fastest / 1000);
else
host_logf(HOST_LOG_INFO, "xr: the frames' thread could not be kept on the fast cores");
}
int host_xr_end_frame(const struct halo_xr_submit *submit)
{
XrFrameEndInfo end = { XR_TYPE_FRAME_END_INFO };
@@ -1500,11 +1784,81 @@ int host_xr_end_frame(const struct halo_xr_submit *submit)
}
}
if (xr.steamvr && !xr.cores_pinned)
{
xr.cores_pinned = 1;
if (!getenv("HALO_XR_ANY_CORE"))
xr_fast_cores();
}
/* (every five seconds, the compositor's counters, and the core the
frames' thread is on) */
if (xr.has_metrics)
{
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
if (now.tv_sec - xr.metrics_logged.tv_sec >= 5)
{
char line[768] = "";
uint32_t counter;
xr.metrics_logged = now;
for (counter = 0; counter < xr.metric_count && counter < 16; counter++)
{
XrPerformanceMetricsCounterMETA value = { XR_TYPE_PERFORMANCE_METRICS_COUNTER_META };
char name[XR_MAX_PATH_LENGTH];
uint32_t length = 0;
char item[96];
if (!XR_SUCCEEDED(xr.query_metric(xr.session, xr.metric_paths[counter], &value)) ||
!XR_SUCCEEDED(xrPathToString(xr.instance, xr.metric_paths[counter], sizeof(name), &length, name)))
{
continue;
}
snprintf(item, sizeof(item), " %s=%g", strrchr(name, '/') ? strrchr(name, '/') + 1 : name,
(value.counterFlags & XR_PERFORMANCE_METRICS_COUNTER_FLOAT_VALUE_VALID_BIT_META) ?
(double)value.floatValue : (double)value.uintValue);
if (strlen(line) + strlen(item) < sizeof(line))
strcat(line, item);
}
host_logf(HOST_LOG_INFO, "xr: metrics%s, on core %d", line, sched_getcpu());
if (xr.timed_frames)
{
double frames = (double)xr.timed_frames;
char copies[256] = "";
int timed;
for (timed = 0; timed < HALO_XR_LAYER_COUNT; timed++)
{
char item[24];
snprintf(item, sizeof(item), " %d:%.2f", timed, xr.copy_seconds[timed] * 1e3 / frames);
strcat(copies, item);
xr.copy_seconds[timed] = 0.0;
}
host_logf(HOST_LOG_INFO, "xr: per frame ms: copies (layer:ms)%s; of them waiting for images %.2f; "
"xrEndFrame %.2f", copies, xr.acquire_seconds * 1e3 / frames, xr.end_seconds * 1e3 / frames);
xr.acquire_seconds = xr.end_seconds = 0.0;
xr.timed_frames = 0;
}
}
}
end.displayTime = xr.frame_state.predictedDisplayTime;
end.environmentBlendMode = XR_ENVIRONMENT_BLEND_MODE_OPAQUE;
end.layerCount = layer_count;
end.layers = layers;
return xr_ok(xrEndFrame(xr.session, &end), "xrEndFrame");
{
double start = xr.has_metrics ? seconds_now() : 0.0;
int ended = xr_ok(xrEndFrame(xr.session, &end), "xrEndFrame");
if (xr.has_metrics)
{
xr.end_seconds += seconds_now() - start;
xr.timed_frames++;
}
return ended;
}
}
void host_xr_set_vignette(float strength)
+18
View File
@@ -53,6 +53,23 @@ enum
HALO_XR_BUTTON_TRIGGER = 1 << 4, /* trigger past its click point */
HALO_XR_BUTTON_SQUEEZE = 1 << 5, /* grip past its click point */
HALO_XR_BUTTON_THUMBREST = 1 << 6, /* thumb resting (touch) */
/* the Steam Frame's controllers' (HALO_XR_LAYOUT_FRAME): the left one's
View button and D-pad, either one's bumper (their right one's X, Y and
menu button come as the left hand's A, B and MENU: the game's X, Y and
Start, as on the Quest) */
HALO_XR_BUTTON_VIEW = 1 << 7,
HALO_XR_BUTTON_BUMPER = 1 << 8,
HALO_XR_BUTTON_DPAD_UP = 1 << 9,
HALO_XR_BUTTON_DPAD_DOWN = 1 << 10,
HALO_XR_BUTTON_DPAD_LEFT = 1 << 11,
HALO_XR_BUTTON_DPAD_RIGHT = 1 << 12,
};
/* the controllers' layout, for what the game tells the player */
enum
{
HALO_XR_LAYOUT_TOUCH = 0, /* the Quest's: X, Y and menu on the left */
HALO_XR_LAYOUT_FRAME = 1, /* the Steam Frame's: A, B, X, Y and menu on the right, a D-pad on the left */
};
/* halo_xr_hand.flags, halo_xr_view.flags, halo_xr_frame.head_flags */
@@ -112,6 +129,7 @@ struct halo_xr_frame
struct halo_xr_pose head;
struct halo_xr_view views[HALO_XR_EYE_COUNT];
struct halo_xr_hand hands[HALO_XR_HAND_COUNT];
int controller_layout; /* HALO_XR_LAYOUT_* */
};
/* halo_xr_submit.overlay_mode */
Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

+85
View File
@@ -0,0 +1,85 @@
#!/bin/bash
# Halo VR on the Steam Frame: Lepton runs the APK in a container of its own,
# and installs it anew whenever the APK is newer than the installed one
# (port/android/STEAM_FRAME.md). The game's data: ~/Documents/HaloCE.
# (a container of its own, not the shortcut's id: with that, SteamVR's
# client in the container waited on xrCreateInstance)
export SteamAppId="${HALO_LEPTON_APP_ID:-4290000001}"
# (what Steam gives an Android title of its own, and a non-Steam game not:
# the app's data in the container links to the compat data path's
# internal/, a dangling link without it; and the shader paths: Lepton reads
# the dump path against the other)
export STEAM_COMPAT_DATA_PATH="$HOME/.local/share/Steam/steamapps/compatdata/$SteamAppId"
export STEAM_COMPAT_SHADER_PATH="$HOME/.local/share/Steam/steamapps/shadercache/$SteamAppId"
mkdir -p "$STEAM_COMPAT_DATA_PATH/internal" "$STEAM_COMPAT_SHADER_PATH"
unset STEAM_FOSSILIZE_DUMP_PATH LD_PRELOAD
LEPTON="$HOME/.local/share/Steam/steamapps/common/Lepton/lepton"
APK="$HOME/Documents/HaloCE/HaloVR.apk"
LOG="$HOME/Documents/HaloCE/launcher.log"
# (written by the game when the player quits it: no start again)
QUIT="$HOME/Documents/HaloCE/quit_requested.txt"
rm -f "$QUIT"
CONTEXT="steamlaunch-$SteamAppId"
log() { echo "$(date '+%F %T') $*" >> "$LOG"; }
log "start (pid $$, parent $PPID)"
# Steam's "Exit game" ends the game's processes as Steam knows them (this
# script, under Steam's reaper), not the container, which podman runs: a
# signal here is passed on to Lepton, and a watcher of its own takes the
# container down once this script is gone (killed)
stopping=0
child=0
stop()
{
log "signal $1"
stopping=1
[ "$child" -gt 0 ] && kill -TERM "$child" 2>/dev/null
}
trap 'stop TERM' TERM
trap 'stop INT' INT
trap 'stop HUP' HUP
script=$$
setsid bash -c '
while kill -0 '"$script"' 2>/dev/null; do sleep 1; done
echo "$(date "+%F %T") watcher: the game was ended, so its container" >> "'"$LOG"'"
"'"$LEPTON"'" kill "'"$CONTEXT"'" >/dev/null 2>&1
' </dev/null >/dev/null 2>&1 &
# the game's log while it runs (Lepton's logcat of its container), for
# looking into problems: logcat.txt, anew each start
LOGCAT="$HOME/Documents/HaloCE/logcat.txt"
: > "$LOGCAT"
setsid bash -c '
while kill -0 '"$script"' 2>/dev/null; do
"'"$LEPTON"'" logcat "'"$CONTEXT"'" 2>/dev/null | grep -v "^ERROR: \|^steamlaunch-\|^$" >> "'"$LOGCAT"'"
sleep 3
done
' </dev/null >/dev/null 2>&1 &
run()
{
"$LEPTON" waitforexitandrun -- "$APK" &
child=$!
# (wait returns early when a signal comes: until Lepton is gone)
while kill -0 "$child" 2>/dev/null; do
wait "$child"
done
child=0
}
# (a new APK is only installed on its first start, not started; and a start
# right after a game that was ended hard can fail in SteamVR, which then
# needs a moment: again, up to three times, while it ends within 30 s)
for attempt in 1 2 3; do
started=$SECONDS
run
if (( stopping || SECONDS - started >= 30 )) || [ -e "$QUIT" ]; then
break
fi
log "ended within $((SECONDS - started)) s: again"
sleep 5
done
rm -f "$QUIT"
log "end"
@@ -0,0 +1,62 @@
/*
FDM_INJECTION_STUB.C
An OpenXR API layer that does nothing, named as the Steam Frame's
XR_APILAYER_VALVE_fdm_injection names its library
(libVkLayer_VALVE_fdm_injection.so). The Frame lists that layer as implicit
for every OpenXR app (/vendor/etc/openxr/1/api_layers/implicit.d), but an
Android app (in Lepton) cannot load the system's library from its own
namespace, and the Khronos loader then fails xrCreateInstance altogether;
nor does the Android loader read the variable that would turn the layer
off. With this one in the app's libraries the loader finds a layer of that
name, which hands every call on to the next. (The real layer adds fragment
density maps to Vulkan apps; this game draws with OpenGL ES.) On a Quest no
manifest names it and it is never loaded.
*/
#include <openxr/openxr.h>
#include <openxr/openxr_loader_negotiation.h>
#include <stddef.h>
static PFN_xrGetInstanceProcAddr next_get_instance_proc_addr;
static XRAPI_ATTR XrResult XRAPI_CALL layer_get_instance_proc_addr(XrInstance instance, const char *name,
PFN_xrVoidFunction *function)
{
if (!next_get_instance_proc_addr)
return XR_ERROR_HANDLE_INVALID;
return next_get_instance_proc_addr(instance, name, function);
}
static XRAPI_ATTR XrResult XRAPI_CALL layer_create_api_layer_instance(const XrInstanceCreateInfo *info,
const XrApiLayerCreateInfo *layer_info, XrInstance *instance)
{
XrApiLayerCreateInfo next_layer_info;
if (!layer_info || !layer_info->nextInfo)
return XR_ERROR_INITIALIZATION_FAILED;
next_get_instance_proc_addr = layer_info->nextInfo->nextGetInstanceProcAddr;
next_layer_info = *layer_info;
next_layer_info.nextInfo = layer_info->nextInfo->next;
return layer_info->nextInfo->nextCreateApiLayerInstance(info, &next_layer_info, instance);
}
__attribute__((visibility("default")))
XRAPI_ATTR XrResult XRAPI_CALL xrNegotiateLoaderApiLayerInterface(const XrNegotiateLoaderInfo *loader_info,
const char *layer_name, XrNegotiateApiLayerRequest *request)
{
(void)layer_name;
if (!loader_info || !request || loader_info->structType != XR_LOADER_INTERFACE_STRUCT_LOADER_INFO ||
request->structType != XR_LOADER_INTERFACE_STRUCT_API_LAYER_REQUEST ||
loader_info->minInterfaceVersion > XR_CURRENT_LOADER_API_LAYER_VERSION ||
loader_info->maxInterfaceVersion < XR_CURRENT_LOADER_API_LAYER_VERSION)
{
return XR_ERROR_INITIALIZATION_FAILED;
}
request->layerInterfaceVersion = XR_CURRENT_LOADER_API_LAYER_VERSION;
request->layerApiVersion = loader_info->maxApiVersion < XR_CURRENT_API_VERSION ? loader_info->maxApiVersion :
XR_CURRENT_API_VERSION;
request->getInstanceProcAddr = layer_get_instance_proc_addr;
request->createApiLayerInstance = layer_create_api_layer_instance;
return XR_SUCCESS;
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 369 KiB

After

Width:  |  Height:  |  Size: 369 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 15 KiB

+2 -2
View File
@@ -314,7 +314,7 @@
"svg": "hud_xbox_order__bitmaps__combined__hud_ammo_meters.svg",
"source_scale": 4,
"source": [
-34,
-2,
108
],
"clip": [
@@ -380,7 +380,7 @@
"svg": "hud_xbox_order__bitmaps__combined__hud_ammo_meters.svg",
"source_scale": 4,
"source": [
-25,
-5,
312
],
"clip": [
@@ -2,7 +2,7 @@
<defs>
<radialGradient id="cone" gradientUnits="userSpaceOnUse" cx="167.994" cy="346.437" r="165.922"><stop offset="0" stop-color="#fff"/><stop offset="1" stop-color="#000"/></radialGradient><radialGradient id="coned" gradientUnits="userSpaceOnUse" cx="167.994" cy="346.437" r="165.922"><stop offset="0" stop-color="#fff"/><stop offset="1" stop-color="#878787"/></radialGradient>
<g id="art">
<path d="M167.994,346.437 L69.695,202.598 L266.292,202.598 Z" fill="url(#cone)"/>
<path d="M167.994,346.437 L54.604,180.515 L281.384,180.515 Z" fill="url(#cone)"/>
<circle cx="167.994" cy="345.987" r="53.201" fill="#878787"/>
<path d="M167.994,346.437 L137.767,302.207 A53.201,53.201 0 0 1 198.220,302.207 Z" fill="url(#coned)"/>
<!-- "15m" pixel label -->

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

@@ -2,7 +2,7 @@
<defs>
<radialGradient id="cone" gradientUnits="userSpaceOnUse" cx="126.000" cy="130.342" r="128.840"><stop offset="0" stop-color="#fff"/><stop offset="1" stop-color="#000"/></radialGradient><radialGradient id="coned" gradientUnits="userSpaceOnUse" cx="126.000" cy="130.342" r="128.840"><stop offset="0" stop-color="#fff"/><stop offset="1" stop-color="#878787"/></radialGradient>
<g id="art">
<path d="M126.000,130.342 L49.632,18.677 L202.368,18.677 Z" fill="url(#cone)"/>
<path d="M126.000,130.342 L37.886,1.502 L214.114,1.502 Z" fill="url(#cone)"/>
<circle cx="126.000" cy="129.985" r="41.776" fill="#878787"/>
<path d="M126.000,130.342 L102.251,95.616 A41.776,41.776 0 0 1 149.749,95.616 Z" fill="url(#coned)"/>
<!-- "15m" pixel label -->

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

+1 -1
View File
@@ -51,7 +51,7 @@ until it is redrawn.
| `ce/shell/main_menu/settings_select/player_setup/player_profile_edit/profile_options__6.png` | 512x256 | `shell/main_menu/settings_select/player_setup/player_profile_edit/profile_options__6.png` |
| `ce/shell/main_menu/settings_select/player_setup/player_profile_edit/profile_options__8.png` | 512x256 | `shell/main_menu/settings_select/player_setup/player_profile_edit/profile_options__8.png` |
13 of 147 frames are placeholders.
13 of 156 frames are placeholders.
The PC version's `ui\gamespy` and `ui\ticker` fonts are drawn with `ui\small_ui`, which
the Xbox's map has.
+3 -4
View File
@@ -10,11 +10,10 @@ do (save a setting, join a game) does not happen; the screens open and close as
| Function | Uses | |
| --- | --- | --- |
| `common button bar update` | 24 | PC function |
| `common button bar update` | 25 | PC function |
| `direct ip connect init` | 1 | PC function |
| `direct ip connect update` | 1 | PC function |
| `direct ip edit field` | 4 | PC function |
| `gamespy screen dispose` | 1 | PC function |
| `gamespy screen update` | 1 | PC function |
| `gamespy select button` | 8 | PC function |
| `gamespy select header` | 22 | PC function |
@@ -22,7 +21,7 @@ do (save a setting, join a game) does not happen; the screens open and close as
| `gamespy update filter settings` | 2 | PC function |
| `gt edit list update` | 1 | PC function |
| `gt select list update` | 1 | PC function |
| `mouse spinner 1wide click` | 64 | PC function |
| `mouse spinner 1wide click` | 66 | PC function |
| `mp map list update` | 1 | PC function |
| `mp prof init teamplay options` | 1 | PC function |
| `mp prof init vehicle options` | 1 | PC function |
@@ -34,4 +33,4 @@ do (save a setting, join a game) does not happen; the screens open and close as
| `ss edit server name` | 2 | PC function |
| `ss start game` | 2 | PC function |
Wired: `campaign menu continue`, `campaign menu init`, `controls back handler`, `controls begin binding`, `controls screen change set`, `controls screen defaults`, `controls screen init`, `controls update menu`, `difficulty item select`, `direct ip connect go`, `emit custom activation event`, `gamespy back handler`, `gamespy dismiss error`, `gamespy dismiss filters`, `gamespy screen init`, `load game list update`, `load game menu activated`, `load game menu delete finish`, `load game menu delete request`, `load game menu dispose`, `load game menu init`, `main menu quit game`, `mouse emit accept event`, `mouse emit back event`, `mouse emit x event`, `mp type set mode`, `profile manager select`, `profile set edit begin`, `single prev cl item activated`, `solo map list update`.
Wired: `campaign menu continue`, `campaign menu init`, `controls back handler`, `controls begin binding`, `controls screen change set`, `controls screen defaults`, `controls screen init`, `controls update menu`, `difficulty item select`, `direct ip connect go`, `emit custom activation event`, `gamespy back handler`, `gamespy dismiss error`, `gamespy dismiss filters`, `gamespy screen dispose`, `gamespy screen init`, `load game list update`, `load game menu activated`, `load game menu delete finish`, `load game menu delete request`, `load game menu dispose`, `load game menu init`, `main menu quit game`, `mouse emit accept event`, `mouse emit back event`, `mouse emit x event`, `mp type set mode`, `profile manager select`, `profile set edit begin`, `single prev cl item activated`, `solo map list update`.
+21
View File
@@ -309,13 +309,34 @@
<bitmap name="main_menu/solo_level_select/header_load_level">
<frame png="ce/shell/main_menu/solo_level_select/header_load_level__0.png" width="512" height="64"/>
</bitmap>
<bitmap name="main_menu/multiplayer_type_select/coop/header_player_2">
<frame png="ce/port/main_menu/multiplayer_type_select/coop/header_player_2.png" width="512" height="64"/>
</bitmap>
<bitmap name="main_menu/multiplayer_type_select/join_game/header_direct_link">
<frame png="ce/port/main_menu/multiplayer_type_select/join_game/header_direct_link.png" width="512" height="64"/>
</bitmap>
<bitmap name="main_menu/multiplayer_type_select/join_game/header_server_browser">
<frame png="ce/port/main_menu/multiplayer_type_select/join_game/header_server_browser.png" width="512" height="64"/>
</bitmap>
<bitmap name="main_menu/multiplayer_type_select/lobby/header_add_player">
<frame png="ce/port/main_menu/multiplayer_type_select/lobby/header_add_player.png" width="512" height="64"/>
</bitmap>
<bitmap name="main_menu/multiplayer_type_select/lobby/header_lobby">
<frame png="ce/port/main_menu/multiplayer_type_select/lobby/header_lobby.png" width="512" height="64"/>
</bitmap>
<bitmap name="pause/pausebox_left">
<frame png="ce/port/pause/pausebox_left__0.png" width="16" height="256"/>
<frame png="ce/port/pause/pausebox_left__1.png" width="16" height="256"/>
</bitmap>
<bitmap name="pause/pausebox_center">
<frame png="ce/port/pause/pausebox_center__0.png" width="4" height="256"/>
<frame png="ce/port/pause/pausebox_center__1.png" width="4" height="256"/>
</bitmap>
<bitmap name="pause/pausebox_right">
<frame png="ce/port/pause/pausebox_right__0.png" width="16" height="256"/>
<frame png="ce/port/pause/pausebox_right__1.png" width="16" height="256"/>
</bitmap>
<bitmap name="blank">
<frame png="ce/port/blank__0.png" width="4" height="4"/>
</bitmap>
</menus>
@@ -0,0 +1,119 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- The port's multiplayer screens, in the PC version's style (tools/port_settings.py) -->
<menus>
<widget name="main_menu/multiplayer_type_select/multiplayer_type_coop_item" type="text" left="51" width="232" height="32" bitmap="bitmaps/list_item_bkd" string_list="main_menu/multiplayer_type_select/multiplayer_options" string_index="7" font="ui\large_ui" color="#FF2896FF" text_x="13" text_y="5">
<on event="a" run="port coop begin" open="main_menu/multiplayer_type_select/coop/player_2_profile_screen" branch="true"/>
<on event="start" run="port coop begin" open="main_menu/multiplayer_type_select/coop/player_2_profile_screen" branch="true"/>
<on event="left_mouse" run="mouse emit accept event"/>
</widget>
<widget name="main_menu/multiplayer_type_select/coop/player_2_profile_screen" width="640" height="480" flags="pass_unhandled_to_focused_child" bitmap="bitmaps/gradient">
<child widget="main_menu/new_select/sel_list_desc_bkd"/>
<child widget="main_menu/multiplayer_type_select/coop/player_2_profile_list"/>
<child widget="main_menu/multiplayer_type_select/coop/header_player_2"/>
<child widget="main_menu/multiplayer_type_select/coop/player_2_help" x="20" y="416"/>
</widget>
<widget name="main_menu/multiplayer_type_select/coop/header_player_2" controller="1" left="35" top="11" width="363" height="59" bitmap="main_menu/multiplayer_type_select/coop/header_player_2">
</widget>
<widget name="main_menu/multiplayer_type_select/coop/player_2_profile_list" type="column_list" width="640" height="480" flags="pass_unhandled_to_focused_child up_down_tabs_children" description="main_menu/profile_manager/player_profile_extended_desc">
<data input="3wide player profile list update"/>
<on event="created" run="port coop player 2 list initialize"/>
<on event="deleted" run="player profile list dispose"/>
<on event="custom_activation" run="port coop player 2" open="main_menu/solo_level_select/solo_level_select_screen" branch="true"/>
<child widget="main_menu/multiplayer_type_select/coop/list_item_0" x="20" y="73"/>
<child widget="main_menu/multiplayer_type_select/coop/list_item_1" x="20" y="103"/>
<child widget="main_menu/multiplayer_type_select/coop/list_item_2" x="20" y="133"/>
<child widget="main_menu/multiplayer_type_select/coop/list_item_3" x="20" y="163"/>
<child widget="main_menu/multiplayer_type_select/coop/list_item_4" x="20" y="193"/>
<child widget="main_menu/multiplayer_type_select/coop/list_item_5" x="20" y="223"/>
<child widget="main_menu/multiplayer_type_select/coop/list_item_6" x="20" y="253"/>
<child widget="main_menu/multiplayer_type_select/coop/list_item_7" x="20" y="283"/>
<child widget="main_menu/multiplayer_type_select/coop/list_item_8" x="20" y="313"/>
<child widget="main_menu/multiplayer_type_select/coop/list_item_9" x="20" y="343"/>
<child widget="main_menu/multiplayer_type_select/coop/list_item_10" x="20" y="373"/>
<child widget="main_menu/multiplayer_type_select/coop/player_2_button_bar" y="414"/>
</widget>
<widget name="main_menu/multiplayer_type_select/coop/list_item_0" width="390" height="28" bitmap="bitmaps/sel_list_item_bkd_top" font="ui\large_ui" color="#FF2896FF" align="center" text_y="3">
<on event="a" run="single prev cl item activated"/>
<on event="start" run="single prev cl item activated"/>
<on event="left_mouse" run="mouse emit accept event"/>
<child widget="main_menu/new_select/list_item_text" x="25"/>
<child widget="main_menu/new_select/list_item_arrows"/>
</widget>
<widget name="main_menu/multiplayer_type_select/coop/list_item_1" width="390" height="28" bitmap="bitmaps/sel_list_item_bkd" font="ui\large_ui" color="#FF2896FF" align="center" text_y="3">
<on event="a" run="single prev cl item activated"/>
<on event="start" run="single prev cl item activated"/>
<on event="left_mouse" run="mouse emit accept event"/>
<child widget="main_menu/new_select/list_item_text" x="25"/>
<child widget="main_menu/new_select/list_item_arrows"/>
</widget>
<widget name="main_menu/multiplayer_type_select/coop/list_item_2" width="390" height="28" bitmap="bitmaps/sel_list_item_bkd" font="ui\large_ui" color="#FF2896FF" align="center" text_y="3">
<on event="a" run="single prev cl item activated"/>
<on event="start" run="single prev cl item activated"/>
<on event="left_mouse" run="mouse emit accept event"/>
<child widget="main_menu/new_select/list_item_text" x="25"/>
<child widget="main_menu/new_select/list_item_arrows"/>
</widget>
<widget name="main_menu/multiplayer_type_select/coop/list_item_3" width="390" height="28" bitmap="bitmaps/sel_list_item_bkd" font="ui\large_ui" color="#FF2896FF" align="center" text_y="3">
<on event="a" run="single prev cl item activated"/>
<on event="start" run="single prev cl item activated"/>
<on event="left_mouse" run="mouse emit accept event"/>
<child widget="main_menu/new_select/list_item_text" x="25"/>
<child widget="main_menu/new_select/list_item_arrows"/>
</widget>
<widget name="main_menu/multiplayer_type_select/coop/list_item_4" width="390" height="28" bitmap="bitmaps/sel_list_item_bkd" font="ui\large_ui" color="#FF2896FF" align="center" text_y="3">
<on event="a" run="single prev cl item activated"/>
<on event="start" run="single prev cl item activated"/>
<on event="left_mouse" run="mouse emit accept event"/>
<child widget="main_menu/new_select/list_item_text" x="25"/>
<child widget="main_menu/new_select/list_item_arrows"/>
</widget>
<widget name="main_menu/multiplayer_type_select/coop/list_item_5" width="390" height="28" bitmap="bitmaps/sel_list_item_bkd" font="ui\large_ui" color="#FF2896FF" align="center" text_y="3">
<on event="a" run="single prev cl item activated"/>
<on event="start" run="single prev cl item activated"/>
<on event="left_mouse" run="mouse emit accept event"/>
<child widget="main_menu/new_select/list_item_text" x="25"/>
<child widget="main_menu/new_select/list_item_arrows"/>
</widget>
<widget name="main_menu/multiplayer_type_select/coop/list_item_6" width="390" height="28" bitmap="bitmaps/sel_list_item_bkd" font="ui\large_ui" color="#FF2896FF" align="center" text_y="3">
<on event="a" run="single prev cl item activated"/>
<on event="start" run="single prev cl item activated"/>
<on event="left_mouse" run="mouse emit accept event"/>
<child widget="main_menu/new_select/list_item_text" x="25"/>
<child widget="main_menu/new_select/list_item_arrows"/>
</widget>
<widget name="main_menu/multiplayer_type_select/coop/list_item_7" width="390" height="28" bitmap="bitmaps/sel_list_item_bkd" font="ui\large_ui" color="#FF2896FF" align="center" text_y="3">
<on event="a" run="single prev cl item activated"/>
<on event="start" run="single prev cl item activated"/>
<on event="left_mouse" run="mouse emit accept event"/>
<child widget="main_menu/new_select/list_item_text" x="25"/>
<child widget="main_menu/new_select/list_item_arrows"/>
</widget>
<widget name="main_menu/multiplayer_type_select/coop/list_item_8" width="390" height="28" bitmap="bitmaps/sel_list_item_bkd" font="ui\large_ui" color="#FF2896FF" align="center" text_y="3">
<on event="a" run="single prev cl item activated"/>
<on event="start" run="single prev cl item activated"/>
<on event="left_mouse" run="mouse emit accept event"/>
<child widget="main_menu/new_select/list_item_text" x="25"/>
<child widget="main_menu/new_select/list_item_arrows"/>
</widget>
<widget name="main_menu/multiplayer_type_select/coop/list_item_9" width="390" height="28" bitmap="bitmaps/sel_list_item_bkd" font="ui\large_ui" color="#FF2896FF" align="center" text_y="3">
<on event="a" run="single prev cl item activated"/>
<on event="start" run="single prev cl item activated"/>
<on event="left_mouse" run="mouse emit accept event"/>
<child widget="main_menu/new_select/list_item_text" x="25"/>
<child widget="main_menu/new_select/list_item_arrows"/>
</widget>
<widget name="main_menu/multiplayer_type_select/coop/list_item_10" width="390" height="28" bitmap="bitmaps/sel_list_item_bkd" font="ui\large_ui" color="#FF2896FF" align="center" text_y="3">
<on event="a" run="single prev cl item activated"/>
<on event="start" run="single prev cl item activated"/>
<on event="left_mouse" run="mouse emit accept event"/>
<child widget="main_menu/new_select/list_item_text" x="25"/>
<child widget="main_menu/new_select/list_item_arrows"/>
</widget>
<widget name="main_menu/multiplayer_type_select/coop/player_2_help" type="text" width="350" height="24" text="Player 2: choose with your controller." font="ui\small_ui" color="#FF2896FF" text_y="5" text_flags="no_focus_test">
</widget>
<widget name="main_menu/multiplayer_type_select/coop/player_2_button_bar" type="column_list" width="640" height="28" flags="pass_unhandled_to_focused_child left_right_tabs_items">
<data input="common button bar update"/>
<child widget="main_menu/profile_manager/profile_manager_button_ok" x="380" y="1"/>
<child widget="common_button_back" x="510" y="1"/>
</widget>
</menus>
@@ -39,7 +39,7 @@
<child widget="main_menu/multiplayer_type_select/join_game/ticker_rules_info" x="80"/>
</widget>
<widget name="main_menu/multiplayer_type_select/join_game/join_game_button_bar" type="column_list" width="640" height="28" flags="pass_unhandled_to_focused_child left_right_tabs_items">
<child widget="main_menu/multiplayer_type_select/join_game/join_game_button_update" y="1"/>
<child widget="main_menu/multiplayer_type_select/join_game/join_game_button_refresh" y="1"/>
<child widget="main_menu/multiplayer_type_select/join_game/button_clipboard" x="128" y="1"/>
<child widget="main_menu/multiplayer_type_select/join_game/join_game_button_filters" x="256" y="1"/>
<child widget="main_menu/multiplayer_type_select/join_game/join_game_button_join" x="384" y="1"/>
@@ -1,34 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- The port's multiplayer screens, in the PC version's style (tools/port_settings.py) -->
<menus>
<widget name="main_menu/multiplayer_type_select/lobby/lobby_screen" width="640" height="480" flags="pass_unhandled_to_focused_child" bitmap="bitmaps/gradient">
<widget name="main_menu/multiplayer_type_select/lobby/lobby_screen" width="640" height="480" flags="pass_unhandled_to_focused_child main_menu_if_no_history" bitmap="bitmaps/gradient">
<on event="created" run="port lobby open"/>
<on event="created" run="net server accept conx"/>
<on event="created" run="net server allow start"/>
<on event="b" run="net game unjoin player" back="true"/>
<on event="back" run="net game unjoin player" back="true"/>
<on event="b" run="port lobby leave" back="true"/>
<on event="back" run="port lobby leave" back="true"/>
<on event="start" run="port lobby join" open="main_menu/multiplayer_type_select/lobby/player_profile_screen" branch="true"/>
<child widget="main_menu/new_select/sel_list_desc_bkd"/>
<child widget="main_menu/multiplayer_type_select/lobby/lobby_list"/>
<child widget="main_menu/multiplayer_type_select/lobby/header_lobby"/>
<child widget="main_menu/multiplayer_type_select/lobby/lobby_join_help"/>
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/header_lobby" controller="1" left="35" top="11" width="363" height="59" bitmap="main_menu/multiplayer_type_select/lobby/header_lobby">
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/lobby_join_help" type="text" controller="1" left="355" top="446" width="275" height="24" font="ui\small_ui" color="#FF2896FF" align="right" text_y="5" text_flags="no_focus_test">
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/lobby_list" type="column_list" width="640" height="480" flags="pass_unhandled_to_focused_child up_down_tabs_children" description="main_menu/multiplayer_type_select/lobby/lobby_desc">
<data input="net splitscreen prejoin players"/>
<data input="port lobby update"/>
<on event="left right" run="swap player team"/>
<child widget="main_menu/new_select/list_item_0" x="20" y="73"/>
<child widget="main_menu/new_select/list_item_1" x="20" y="103"/>
<child widget="main_menu/new_select/list_item_2" x="20" y="133"/>
<child widget="main_menu/new_select/list_item_3" x="20" y="163"/>
<child widget="main_menu/new_select/list_item_4" x="20" y="193"/>
<child widget="main_menu/new_select/list_item_5" x="20" y="223"/>
<child widget="main_menu/new_select/list_item_6" x="20" y="253"/>
<child widget="main_menu/new_select/list_item_7" x="20" y="283"/>
<child widget="main_menu/new_select/list_item_8" x="20" y="313"/>
<child widget="main_menu/new_select/list_item_9" x="20" y="343"/>
<child widget="main_menu/new_select/list_item_10" x="20" y="373"/>
<child widget="main_menu/multiplayer_type_select/lobby/list_item_0" x="20" y="73"/>
<child widget="main_menu/multiplayer_type_select/lobby/list_item_1" x="20" y="103"/>
<child widget="main_menu/multiplayer_type_select/lobby/list_item_2" x="20" y="133"/>
<child widget="main_menu/multiplayer_type_select/lobby/list_item_3" x="20" y="163"/>
<child widget="main_menu/multiplayer_type_select/lobby/list_item_4" x="20" y="193"/>
<child widget="main_menu/multiplayer_type_select/lobby/list_item_5" x="20" y="223"/>
<child widget="main_menu/multiplayer_type_select/lobby/list_item_6" x="20" y="253"/>
<child widget="main_menu/multiplayer_type_select/lobby/list_item_7" x="20" y="283"/>
<child widget="main_menu/multiplayer_type_select/lobby/list_item_8" x="20" y="313"/>
<child widget="main_menu/multiplayer_type_select/lobby/list_item_9" x="20" y="343"/>
<child widget="main_menu/multiplayer_type_select/lobby/list_item_10" x="20" y="373"/>
<child widget="main_menu/multiplayer_type_select/lobby/lobby_button_bar" y="414"/>
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/list_item_0" width="390" height="28" bitmap="bitmaps/sel_list_item_bkd_top" font="ui\large_ui" color="#FF2896FF" align="center" text_y="3">
<on event="left right" run="swap player team"/>
<child widget="main_menu/new_select/list_item_text" x="25"/>
<child widget="main_menu/new_select/list_item_arrows"/>
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/list_item_1" width="390" height="28" bitmap="bitmaps/sel_list_item_bkd" font="ui\large_ui" color="#FF2896FF" align="center" text_y="3">
<on event="left right" run="swap player team"/>
<child widget="main_menu/new_select/list_item_text" x="25"/>
<child widget="main_menu/new_select/list_item_arrows"/>
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/list_item_2" width="390" height="28" bitmap="bitmaps/sel_list_item_bkd" font="ui\large_ui" color="#FF2896FF" align="center" text_y="3">
<on event="left right" run="swap player team"/>
<child widget="main_menu/new_select/list_item_text" x="25"/>
<child widget="main_menu/new_select/list_item_arrows"/>
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/list_item_3" width="390" height="28" bitmap="bitmaps/sel_list_item_bkd" font="ui\large_ui" color="#FF2896FF" align="center" text_y="3">
<on event="left right" run="swap player team"/>
<child widget="main_menu/new_select/list_item_text" x="25"/>
<child widget="main_menu/new_select/list_item_arrows"/>
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/list_item_4" width="390" height="28" bitmap="bitmaps/sel_list_item_bkd" font="ui\large_ui" color="#FF2896FF" align="center" text_y="3">
<on event="left right" run="swap player team"/>
<child widget="main_menu/new_select/list_item_text" x="25"/>
<child widget="main_menu/new_select/list_item_arrows"/>
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/list_item_5" width="390" height="28" bitmap="bitmaps/sel_list_item_bkd" font="ui\large_ui" color="#FF2896FF" align="center" text_y="3">
<on event="left right" run="swap player team"/>
<child widget="main_menu/new_select/list_item_text" x="25"/>
<child widget="main_menu/new_select/list_item_arrows"/>
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/list_item_6" width="390" height="28" bitmap="bitmaps/sel_list_item_bkd" font="ui\large_ui" color="#FF2896FF" align="center" text_y="3">
<on event="left right" run="swap player team"/>
<child widget="main_menu/new_select/list_item_text" x="25"/>
<child widget="main_menu/new_select/list_item_arrows"/>
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/list_item_7" width="390" height="28" bitmap="bitmaps/sel_list_item_bkd" font="ui\large_ui" color="#FF2896FF" align="center" text_y="3">
<on event="left right" run="swap player team"/>
<child widget="main_menu/new_select/list_item_text" x="25"/>
<child widget="main_menu/new_select/list_item_arrows"/>
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/list_item_8" width="390" height="28" bitmap="bitmaps/sel_list_item_bkd" font="ui\large_ui" color="#FF2896FF" align="center" text_y="3">
<on event="left right" run="swap player team"/>
<child widget="main_menu/new_select/list_item_text" x="25"/>
<child widget="main_menu/new_select/list_item_arrows"/>
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/list_item_9" width="390" height="28" bitmap="bitmaps/sel_list_item_bkd" font="ui\large_ui" color="#FF2896FF" align="center" text_y="3">
<on event="left right" run="swap player team"/>
<child widget="main_menu/new_select/list_item_text" x="25"/>
<child widget="main_menu/new_select/list_item_arrows"/>
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/list_item_10" width="390" height="28" bitmap="bitmaps/sel_list_item_bkd" font="ui\large_ui" color="#FF2896FF" align="center" text_y="3">
<on event="left right" run="swap player team"/>
<child widget="main_menu/new_select/list_item_text" x="25"/>
<child widget="main_menu/new_select/list_item_arrows"/>
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/lobby_desc" width="640" height="480">
<child widget="main_menu/current_profile_name"/>
<child widget="main_menu/multiplayer_type_select/lobby/lobby_right_item" x="22" y="2"/>
@@ -36,6 +95,8 @@
<widget name="main_menu/multiplayer_type_select/lobby/lobby_right_item" controller="1" left="406" top="75" width="162" height="326" bitmap="bitmaps/spinner_list_3_wide_item_background">
<child widget="main_menu/multiplayer_type_select/lobby/lobby_map_pic"/>
<child widget="main_menu/multiplayer_type_select/lobby/lobby_map_name"/>
<child widget="main_menu/solo_level_select/replay_level_right_pic"/>
<child widget="main_menu/solo_level_select/replay_level_right_name"/>
<child widget="main_menu/multiplayer_type_select/lobby/lobby_game_data"/>
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/lobby_map_pic" controller="1" left="419" top="87" width="140" height="114" bitmap="ui\shell\bitmaps\mp_map_grafix">
@@ -45,10 +106,16 @@
<widget name="main_menu/multiplayer_type_select/lobby/lobby_game_data" type="text" controller="1" left="417" top="250" width="146" height="144" font="ui\small_ui" color="#FF2896FF">
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/lobby_button_bar" type="column_list" width="640" height="28" flags="pass_unhandled_to_focused_child left_right_tabs_items">
<child widget="main_menu/multiplayer_type_select/lobby/lobby_button_team" x="250" y="1"/>
<child widget="main_menu/multiplayer_type_select/lobby/lobby_button_start" x="380" y="1"/>
<child widget="main_menu/multiplayer_type_select/lobby/lobby_button_team" x="120" y="1"/>
<child widget="main_menu/multiplayer_type_select/lobby/lobby_button_start" x="250" y="1"/>
<child widget="main_menu/multiplayer_type_select/lobby/lobby_button_add" x="380" y="1"/>
<child widget="main_menu/multiplayer_type_select/lobby/lobby_button_leave" x="510" y="1"/>
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/lobby_button_add" type="text" width="128" height="24" bitmap="bitmaps/text_button_background" text="ADD PLAYER" font="ui\small_ui" color="#FFFFFFFF" align="center" text_y="2">
<on event="a" run="port lobby add player"/>
<on event="start" run="port lobby add player"/>
<on event="left_mouse" run="mouse emit accept event"/>
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/lobby_button_team" type="text" width="128" height="24" bitmap="bitmaps/text_button_background" text="SWITCH TEAM" font="ui\small_ui" color="#FFFFFFFF" align="center" text_y="2">
<on event="a" run="swap player team"/>
<on event="start" run="swap player team"/>
@@ -64,14 +131,46 @@
<on event="start" run="mouse emit back event"/>
<on event="left_mouse" run="mouse emit accept event"/>
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/player_profile_screen" width="640" height="480" flags="pass_unhandled_to_focused_child" bitmap="bitmaps/gradient">
<on event="created" run="net server defer start"/>
<child widget="main_menu/new_select/sel_list_desc_bkd"/>
<child widget="main_menu/multiplayer_type_select/lobby/player_profile_list"/>
<child widget="main_menu/multiplayer_type_select/lobby/header_add_player"/>
<child widget="main_menu/multiplayer_type_select/lobby/player_profile_help" x="20" y="416"/>
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/header_add_player" controller="1" left="35" top="11" width="363" height="59" bitmap="main_menu/multiplayer_type_select/lobby/header_add_player">
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/player_profile_list" type="column_list" width="640" height="480" flags="pass_unhandled_to_focused_child up_down_tabs_children" description="main_menu/profile_manager/player_profile_extended_desc">
<data input="3wide player profile list update"/>
<on event="created" run="port lobby player list initialize"/>
<on event="deleted" run="player profile list dispose"/>
<on event="custom_activation" run="port lobby player choose" back="true" branch="true"/>
<child widget="main_menu/multiplayer_type_select/coop/list_item_0" x="20" y="73"/>
<child widget="main_menu/multiplayer_type_select/coop/list_item_1" x="20" y="103"/>
<child widget="main_menu/multiplayer_type_select/coop/list_item_2" x="20" y="133"/>
<child widget="main_menu/multiplayer_type_select/coop/list_item_3" x="20" y="163"/>
<child widget="main_menu/multiplayer_type_select/coop/list_item_4" x="20" y="193"/>
<child widget="main_menu/multiplayer_type_select/coop/list_item_5" x="20" y="223"/>
<child widget="main_menu/multiplayer_type_select/coop/list_item_6" x="20" y="253"/>
<child widget="main_menu/multiplayer_type_select/coop/list_item_7" x="20" y="283"/>
<child widget="main_menu/multiplayer_type_select/coop/list_item_8" x="20" y="313"/>
<child widget="main_menu/multiplayer_type_select/coop/list_item_9" x="20" y="343"/>
<child widget="main_menu/multiplayer_type_select/coop/list_item_10" x="20" y="373"/>
<child widget="main_menu/multiplayer_type_select/coop/player_2_button_bar" y="414"/>
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/player_profile_help" type="text" width="350" height="24" text="The new player's profile." font="ui\small_ui" color="#FF2896FF" text_y="5" text_flags="no_focus_test">
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/preview_screen" width="640" height="480" flags="pass_unhandled_to_focused_child" bitmap="bitmaps/gradient">
<on event="b" back="true"/>
<on event="back" back="true"/>
<on event="created" run="port lobby open"/>
<on event="b" run="port lobby preview leave" back="true"/>
<on event="back" run="port lobby preview leave" back="true"/>
<on event="start" run="port lobby preview add" open="main_menu/multiplayer_type_select/lobby/player_profile_screen" branch="true"/>
<child widget="main_menu/new_select/sel_list_desc_bkd"/>
<child widget="main_menu/multiplayer_type_select/lobby/preview_list"/>
<child widget="main_menu/multiplayer_type_select/lobby/header_lobby"/>
<child widget="main_menu/multiplayer_type_select/lobby/lobby_join_help"/>
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/preview_list" type="column_list" width="640" height="480" flags="pass_unhandled_to_focused_child left_right_tabs_items" description="main_menu/multiplayer_type_select/lobby/lobby_desc">
<widget name="main_menu/multiplayer_type_select/lobby/preview_list" type="column_list" width="640" height="480" flags="pass_unhandled_to_focused_child up_down_tabs_children" description="main_menu/multiplayer_type_select/lobby/lobby_desc">
<data input="port lobby preview update"/>
<child widget="main_menu/multiplayer_type_select/lobby/preview_status" x="30" y="75"/>
<child widget="main_menu/multiplayer_type_select/lobby/preview_button_bar" y="414"/>
@@ -79,7 +178,8 @@
<widget name="main_menu/multiplayer_type_select/lobby/preview_status" type="text" controller="1" width="360" height="300" font="ui\large_ui" color="#FF2896FF">
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/preview_button_bar" type="column_list" width="640" height="28" flags="pass_unhandled_to_focused_child left_right_tabs_items">
<child widget="main_menu/multiplayer_type_select/lobby/preview_button_join" x="380" y="1"/>
<child widget="main_menu/multiplayer_type_select/lobby/preview_button_join" x="250" y="1"/>
<child widget="main_menu/multiplayer_type_select/lobby/preview_button_add" x="380" y="1"/>
<child widget="main_menu/multiplayer_type_select/lobby/preview_button_back" x="510" y="1"/>
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/preview_button_join" type="text" width="128" height="24" bitmap="bitmaps/text_button_background" text="JOIN GAME" font="ui\small_ui" color="#FFFFFFFF" align="center" text_y="2">
@@ -87,6 +187,11 @@
<on event="start" run="port lobby preview join"/>
<on event="left_mouse" run="mouse emit accept event"/>
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/preview_button_add" type="text" width="128" height="24" bitmap="bitmaps/text_button_background" text="ADD PLAYER" font="ui\small_ui" color="#FFFFFFFF" align="center" text_y="2">
<on event="a" run="port lobby add player"/>
<on event="start" run="port lobby add player"/>
<on event="left_mouse" run="mouse emit accept event"/>
</widget>
<widget name="main_menu/multiplayer_type_select/lobby/preview_button_back" type="text" width="128" height="24" bitmap="bitmaps/text_button_background" text="BACK" font="ui\small_ui" color="#FFFFFFFF" align="center" text_y="2">
<on event="a" run="mouse emit back event"/>
<on event="start" run="mouse emit back event"/>
@@ -13,6 +13,9 @@
<child widget="main_menu/multiplayer_type_select/mp_map_select/mp_map_right_name"/>
<child widget="main_menu/multiplayer_type_select/mp_map_select/mp_map_right_pic"/>
<child widget="main_menu/multiplayer_type_select/mp_map_select/mp_map_right_data"/>
<child widget="main_menu/solo_level_select/replay_level_right_name"/>
<child widget="main_menu/solo_level_select/replay_level_right_pic"/>
<child widget="main_menu/solo_level_select/replay_level_right_data"/>
</widget>
<widget name="main_menu/multiplayer_type_select/mp_map_select/mp_map_right_name" type="text" controller="1" left="417" top="204" width="146" height="43" string_list="main_menu/mp_map_list" string_index="2" font="ui\large_ui" color="#FF2896FF">
</widget>
@@ -33,7 +36,9 @@
<on event="created" run="mp level list initialize"/>
<on event="deleted" run="mp level list dispose"/>
<on event="custom_activation" run="mp level select" open="main_menu/multiplayer_type_select/connected/gametype_select_screen_wrapper"/>
<child widget="main_menu/new_select/list_item_0" x="20" y="73"/>
<on event="b" run="port map list back"/>
<on event="back" run="port map list back"/>
<child widget="main_menu/new_select/list_item_0_map_kind" x="82" y="73"/>
<child widget="main_menu/new_select/list_item_1" x="20" y="103"/>
<child widget="main_menu/new_select/list_item_2" x="20" y="133"/>
<child widget="main_menu/new_select/list_item_3" x="20" y="163"/>
@@ -9,20 +9,25 @@
</widget>
<widget name="main_menu/multiplayer_type_select/server_settings/header_server_settings" controller="1" left="35" top="11" width="605" height="59" bitmap="main_menu/multiplayer_type_select/server_settings/header_server_settings">
</widget>
<widget name="main_menu/multiplayer_type_select/server_settings/help" type="text" controller="1" left="68" top="350" width="482" height="60" string_list="main_menu/multiplayer_type_select/server_settings/help_strings" font="ui\large_ui" color="#FFFFFFFF">
<widget name="main_menu/multiplayer_type_select/server_settings/help" type="text" controller="1" left="68" top="358" width="482" height="60" string_list="main_menu/multiplayer_type_select/server_settings/help_strings" font="ui\large_ui" color="#FFFFFFFF">
</widget>
<widget name="main_menu/multiplayer_type_select/server_settings/options_menu" type="column_list" width="640" height="480" flags="pass_unhandled_to_focused_child up_down_tabs_children" description="main_menu/multiplayer_type_select/server_settings/help">
<data input="server settings update"/>
<on event="created" run="server settings init"/>
<child widget="main_menu/multiplayer_type_select/server_settings/op_server_name" x="54" y="73"/>
<child widget="main_menu/multiplayer_type_select/server_settings/op_max_players" x="54" y="103"/>
<child widget="main_menu/multiplayer_type_select/server_settings/op_invite" x="54" y="133"/>
<child widget="main_menu/multiplayer_type_select/server_settings/op_game_type" x="54" y="163"/>
<child widget="main_menu/multiplayer_type_select/server_settings/op_player_options" x="54" y="193"/>
<child widget="main_menu/multiplayer_type_select/server_settings/op_item_options" x="54" y="223"/>
<child widget="main_menu/multiplayer_type_select/server_settings/op_vehicle_options" x="54" y="253"/>
<child widget="main_menu/multiplayer_type_select/server_settings/op_indicator_options" x="54" y="283"/>
<child widget="main_menu/multiplayer_type_select/server_settings/op_team_options" x="54" y="313"/>
<child widget="main_menu/multiplayer_type_select/server_settings/op_max_players" x="54" y="101"/>
<child widget="main_menu/multiplayer_type_select/server_settings/op_invite" x="54" y="129"/>
<child widget="main_menu/multiplayer_type_select/server_settings/op_listing" x="54" y="157"/>
<child widget="main_menu/multiplayer_type_select/server_settings/op_friendly_fire" x="54" y="185"/>
<child widget="main_menu/multiplayer_type_select/server_settings/op_extra_enemies" x="54" y="213"/>
<child widget="main_menu/multiplayer_type_select/server_settings/op_enemies_per_player" x="54" y="241"/>
<child widget="main_menu/multiplayer_type_select/server_settings/op_enemies_multiplier" x="54" y="241"/>
<child widget="main_menu/multiplayer_type_select/server_settings/op_game_type" x="54" y="185"/>
<child widget="main_menu/multiplayer_type_select/server_settings/op_player_options" x="54" y="213"/>
<child widget="main_menu/multiplayer_type_select/server_settings/op_item_options" x="54" y="241"/>
<child widget="main_menu/multiplayer_type_select/server_settings/op_vehicle_options" x="54" y="269"/>
<child widget="main_menu/multiplayer_type_select/server_settings/op_indicator_options" x="54" y="297"/>
<child widget="main_menu/multiplayer_type_select/server_settings/op_team_options" x="54" y="325"/>
<child widget="main_menu/multiplayer_type_select/server_settings/button_bar" y="414"/>
</widget>
<widget name="main_menu/multiplayer_type_select/server_settings/button_bar" type="column_list" width="640" height="28" flags="pass_unhandled_to_focused_child left_right_tabs_items">
@@ -64,6 +69,59 @@
</widget>
<widget name="main_menu/multiplayer_type_select/server_settings/invite_value" type="text" controller="1" width="280" height="22" font="ui\small_ui" color="#FF2896FF" align="center" text_y="5" text_flags="no_focus_test">
</widget>
<widget name="main_menu/multiplayer_type_select/server_settings/op_listing" width="512" height="28" flags="pass_unhandled_to_focused_child" bitmap="bitmaps/option_bkds" color="#FF2896FF">
<child widget="main_menu/multiplayer_type_select/server_settings/listing_label"/>
<child widget="main_menu/multiplayer_type_select/server_settings/listing_spinner" x="320" y="1"/>
</widget>
<widget name="main_menu/multiplayer_type_select/server_settings/listing_label" type="text" controller="1" width="300" height="22" string_list="main_menu/multiplayer_type_select/server_settings/labels" string_index="9" font="ui\large_ui" color="#FF2896FF" text_x="13" text_y="4">
</widget>
<widget name="main_menu/multiplayer_type_select/server_settings/listing_spinner" type="spinner" left="3" top="2" width="147" height="20" flags="pass_unhandled_to_focused_child left_right_tabs_items" strings="PUBLIC|PRIVATE" font="ui\large_ui" color="#FF2896FF" align="center" text_y="1" header_bitmap="bitmaps/arrow_sm_left" footer_bitmap="bitmaps/arrow_sm_right" header_bounds="7 -6 19 0" footer_bounds="7 150 19 156">
<on event="left_mouse" run="mouse spinner 1wide click"/>
</widget>
<widget name="main_menu/multiplayer_type_select/server_settings/op_friendly_fire" width="512" height="28" flags="pass_unhandled_to_focused_child" bitmap="bitmaps/option_bkds" color="#FF2896FF">
<child widget="main_menu/multiplayer_type_select/server_settings/friendly_fire_label"/>
<child widget="main_menu/multiplayer_type_select/server_settings/friendly_fire_spinner" x="286" y="1"/>
</widget>
<widget name="main_menu/multiplayer_type_select/server_settings/friendly_fire_label" type="text" controller="1" width="300" height="22" string_list="main_menu/multiplayer_type_select/server_settings/labels" string_index="10" font="ui\large_ui" color="#FF2896FF" text_x="13" text_y="4">
</widget>
<widget name="main_menu/multiplayer_type_select/server_settings/friendly_fire_spinner" type="spinner" top="2" width="206" height="20" flags="pass_unhandled_to_focused_child left_right_tabs_items" strings="OFF|ON|SHIELD ONLY|EXPLOSIVES ONLY" setting="network.coop_friendly_fire" values="off|on|shields_only|explosives_only" font="ui\large_ui" color="#FF2896FF" align="center" text_y="4" header_bitmap="bitmaps/arrow_sm_left" footer_bitmap="bitmaps/arrow_sm_right" header_bounds="7 -13 19 -7" footer_bounds="7 208 19 214">
<on event="created" run="port setting load"/>
<on event="deleted" run="port setting save"/>
<on event="left_mouse" run="mouse spinner 1wide click"/>
</widget>
<widget name="main_menu/multiplayer_type_select/server_settings/op_extra_enemies" width="512" height="28" flags="pass_unhandled_to_focused_child" bitmap="bitmaps/option_bkds" color="#FF2896FF">
<child widget="main_menu/multiplayer_type_select/server_settings/extra_enemies_label"/>
<child widget="main_menu/multiplayer_type_select/server_settings/extra_enemies_spinner" x="286" y="1"/>
</widget>
<widget name="main_menu/multiplayer_type_select/server_settings/extra_enemies_label" type="text" controller="1" width="300" height="22" string_list="main_menu/multiplayer_type_select/server_settings/labels" string_index="11" font="ui\large_ui" color="#FF2896FF" text_x="13" text_y="4">
</widget>
<widget name="main_menu/multiplayer_type_select/server_settings/extra_enemies_spinner" type="spinner" top="2" width="206" height="20" flags="pass_unhandled_to_focused_child left_right_tabs_items" strings="NONE|PER PLAYER|STATIC MULTIPLIER" setting="network.coop_enemies_mode" values="none|per_player|multiplier" font="ui\large_ui" color="#FF2896FF" align="center" text_y="4" header_bitmap="bitmaps/arrow_sm_left" footer_bitmap="bitmaps/arrow_sm_right" header_bounds="7 -13 19 -7" footer_bounds="7 208 19 214">
<on event="created" run="port setting load"/>
<on event="deleted" run="port setting save"/>
<on event="left_mouse" run="mouse spinner 1wide click"/>
</widget>
<widget name="main_menu/multiplayer_type_select/server_settings/op_enemies_per_player" width="512" height="28" flags="pass_unhandled_to_focused_child" bitmap="bitmaps/option_bkds" color="#FF2896FF">
<child widget="main_menu/multiplayer_type_select/server_settings/enemies_per_player_label"/>
<child widget="main_menu/multiplayer_type_select/server_settings/enemies_per_player_spinner" x="286" y="1"/>
</widget>
<widget name="main_menu/multiplayer_type_select/server_settings/enemies_per_player_label" type="text" controller="1" width="300" height="22" string_list="main_menu/multiplayer_type_select/server_settings/labels" string_index="12" font="ui\large_ui" color="#FF2896FF" text_x="13" text_y="4">
</widget>
<widget name="main_menu/multiplayer_type_select/server_settings/enemies_per_player_spinner" type="spinner" top="2" width="206" height="20" flags="pass_unhandled_to_focused_child left_right_tabs_items" strings="25%|50%|100%|150%|200%" setting="network.coop_enemies" values="25|50|100|150|200" font="ui\large_ui" color="#FF2896FF" align="center" text_y="4" header_bitmap="bitmaps/arrow_sm_left" footer_bitmap="bitmaps/arrow_sm_right" header_bounds="7 -13 19 -7" footer_bounds="7 208 19 214">
<on event="created" run="port setting load"/>
<on event="deleted" run="port setting save"/>
<on event="left_mouse" run="mouse spinner 1wide click"/>
</widget>
<widget name="main_menu/multiplayer_type_select/server_settings/op_enemies_multiplier" width="512" height="28" flags="pass_unhandled_to_focused_child" bitmap="bitmaps/option_bkds" color="#FF2896FF">
<child widget="main_menu/multiplayer_type_select/server_settings/enemies_multiplier_label"/>
<child widget="main_menu/multiplayer_type_select/server_settings/enemies_multiplier_spinner" x="286" y="1"/>
</widget>
<widget name="main_menu/multiplayer_type_select/server_settings/enemies_multiplier_label" type="text" controller="1" width="300" height="22" string_list="main_menu/multiplayer_type_select/server_settings/labels" string_index="13" font="ui\large_ui" color="#FF2896FF" text_x="13" text_y="4">
</widget>
<widget name="main_menu/multiplayer_type_select/server_settings/enemies_multiplier_spinner" type="spinner" top="2" width="206" height="20" flags="pass_unhandled_to_focused_child left_right_tabs_items" strings="2X|4X|8X|16X|32X" setting="network.coop_enemies_multiplier" values="2|4|8|16|32" font="ui\large_ui" color="#FF2896FF" align="center" text_y="4" header_bitmap="bitmaps/arrow_sm_left" footer_bitmap="bitmaps/arrow_sm_right" header_bounds="7 -13 19 -7" footer_bounds="7 208 19 214">
<on event="created" run="port setting load"/>
<on event="deleted" run="port setting save"/>
<on event="left_mouse" run="mouse spinner 1wide click"/>
</widget>
<widget name="main_menu/multiplayer_type_select/server_settings/op_game_type" width="512" height="28" flags="pass_unhandled_to_focused_child" bitmap="bitmaps/option_bkds" color="#FF2896FF">
<on event="a" run="port setup edit" open="main_menu/settings_select/multiplayer_setup/playlist_edit/game_type_select/gametype_select_screen"/>
<on event="start" run="port setup edit" open="main_menu/settings_select/multiplayer_setup/playlist_edit/game_type_select/gametype_select_screen"/>
@@ -148,6 +206,11 @@
<string text="VEHICLE OPTIONS:"/>
<string text="INDICATOR OPTIONS:"/>
<string text="TEAMPLAY OPTIONS:"/>
<string text="LISTING:"/>
<string text="FRIENDLY FIRE:"/>
<string text="EXTRA ENEMIES:"/>
<string text="PER PLAYER:"/>
<string text="MULTIPLIER:"/>
</strings>
<strings name="main_menu/multiplayer_type_select/server_settings/help_strings">
<string text=""/>
@@ -160,5 +223,16 @@
<string text="Each team's vehicles and their respawn time, for\nthis game."/>
<string text="The motion tracker and nav points, for this game."/>
<string text="Friendly fire and team balance, for this game."/>
<string text="Anyone can see and join your game: it is listed\nin everyone's Server Browser."/>
<string text="Only players with your invite link can join."/>
<string text="Players can not be hurt by weapons and explosives\nfired by the other players."/>
<string text="Players can be hurt by weapons or explosives\nfired by the other players."/>
<string text="Damage from the other players will only reduce\nshields. Health will be unaffected."/>
<string text="Players can be hurt by damage from explosives\nfired by the other players."/>
<string text="Enemy squads are as the campaign has them."/>
<string text="Enemy squads grow with the players: by the amount\nbelow for each player past the first."/>
<string text="Enemy squads are the amount below times as large,\nhowever many players there are."/>
<string text="For each player past the first, enemy squads get\nthis much more of themselves (100%: as many again)."/>
<string text="Each enemy squad is this many times as large."/>
</strings>
</menus>
@@ -59,13 +59,14 @@
<child widget="main_menu/multiplayer_type_select/multiplayer_type_create_item" x="-32" y="210"/>
<child widget="main_menu/multiplayer_type_select/multiplayer_type_create_internet_item" y="243"/>
<child widget="main_menu/multiplayer_type_select/multiplayer_type_create_lan_item" y="276"/>
<child widget="main_menu/multiplayer_type_select/multiplayer_type_gametypes_item" y="342"/>
<child widget="main_menu/multiplayer_type_select/multiplayer_type_coop_item" y="309"/>
<child widget="main_menu/multiplayer_type_select/multiplayer_type_gametypes_item" y="375"/>
<child widget="main_menu/multiplayer_type_select/multiplayer_type_button_bar" y="414"/>
</widget>
<widget name="main_menu/multiplayer_type_select/multiplayer_type_select_screen" width="640" height="480" flags="pass_unhandled_to_focused_child" bitmap="bitmaps/gradient">
<on event="created" run="mp type menu initialize"/>
<child widget="main_menu/multiplayer_type_select/header_multiplayer"/>
<child widget="main_menu/multiplayer_type_select/multiplayer_type_select_list"/>
<child widget="main_menu/blueline" x="64" y="325"/>
<child widget="main_menu/blueline" x="64" y="358"/>
</widget>
</menus>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- The port's multiplayer screens, in the PC version's style (tools/port_settings.py) -->
<menus>
<widget name="main_menu/new_select/list_item_0_map_kind" width="256" height="28" flags="pass_unhandled_to_focused_child" bitmap="bitmaps/option_bkds_sm" font="ui\large_ui" color="#FF2896FF" align="center" text_y="3">
<child widget="main_menu/new_select/list_item_0_map_kind_spinner" x="15" y="2"/>
</widget>
<widget name="main_menu/new_select/list_item_0_map_kind_spinner" type="spinner" width="226" height="22" flags="left_right_tabs_items" string_list="main_menu/new_select/var_map_kinds" font="ui\large_ui" color="#FF2896FF" align="center" text_y="1" list_flags="items_from_strings" header_bitmap="bitmaps/arrow_sm_left" footer_bitmap="bitmaps/arrow_sm_right" header_bounds="7 -6 19 0" footer_bounds="7 226 19 232">
<on event="left_mouse" run="mouse spinner 1wide click"/>
</widget>
<strings name="main_menu/new_select/var_map_kinds">
<string text="SINGLEPLAYER"/>
<string text="MULTIPLAYER"/>
</strings>
</menus>
@@ -1,6 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- The port's multiplayer screens, in the PC version's style (tools/port_settings.py) -->
<menus>
<widget name="main_menu/settings_select/multiplayer_setup/item_options_edit/op_map_weapons" width="512" height="28" flags="pass_unhandled_to_focused_child" bitmap="bitmaps/option_bkds" color="#FF2896FF">
<child widget="main_menu/settings_select/multiplayer_setup/item_options_edit/map_weapons_label"/>
<child widget="main_menu/settings_select/multiplayer_setup/item_options_edit/map_weapons_spinner" x="286" y="1"/>
</widget>
<widget name="main_menu/settings_select/multiplayer_setup/item_options_edit/map_weapons_label" type="text" controller="1" width="300" height="22" string_list="main_menu/settings_select/multiplayer_setup/item_options_edit/item_options_labels" string_index="8" font="ui\large_ui" color="#FF2896FF" text_x="13" text_y="4">
</widget>
<widget name="main_menu/settings_select/multiplayer_setup/item_options_edit/map_weapons_spinner" type="spinner" top="2" width="206" height="20" flags="pass_unhandled_to_focused_child left_right_tabs_items" string_list="main_menu/settings_select/multiplayer_setup/item_options_edit/var_map_weapons" font="ui\large_ui" color="#FF2896FF" align="center" text_y="4" list_flags="items_from_strings" header_bitmap="bitmaps/arrow_sm_left" footer_bitmap="bitmaps/arrow_sm_right" header_bounds="7 -13 19 -7" footer_bounds="7 208 19 214">
<on event="left_mouse" run="mouse spinner 1wide click"/>
</widget>
<widget name="main_menu/settings_select/multiplayer_setup/item_options_edit/op_loadout" width="512" height="28" flags="pass_unhandled_to_focused_child" bitmap="bitmaps/option_bkds" color="#FF2896FF">
<child widget="main_menu/settings_select/multiplayer_setup/item_options_edit/loadout_label"/>
<child widget="main_menu/settings_select/multiplayer_setup/item_options_edit/loadout_spinner" x="286" y="1"/>
@@ -28,6 +37,10 @@
<widget name="main_menu/settings_select/multiplayer_setup/item_options_edit/secondary_weapon_spinner" type="spinner" top="2" width="206" height="20" flags="pass_unhandled_to_focused_child left_right_tabs_items" string_list="main_menu/settings_select/multiplayer_setup/item_options_edit/var_loadout_weapon" font="ui\large_ui" color="#FF2896FF" align="center" text_y="4" list_flags="items_from_strings" header_bitmap="bitmaps/arrow_sm_left" footer_bitmap="bitmaps/arrow_sm_right" header_bounds="7 -13 19 -7" footer_bounds="7 208 19 214">
<on event="left_mouse" run="mouse spinner 1wide click"/>
</widget>
<strings name="main_menu/settings_select/multiplayer_setup/item_options_edit/var_map_weapons">
<string text="YES"/>
<string text="NO"/>
</strings>
<strings name="main_menu/settings_select/multiplayer_setup/item_options_edit/var_loadout">
<string text="CATEGORY"/>
<string text="CUSTOM"/>
@@ -43,7 +56,5 @@
<string text="PLASMA PISTOL"/>
<string text="PLASMA RIFLE"/>
<string text="NEEDLER"/>
<string text="FUEL ROD"/>
<string text="FLAMETHROWER"/>
</strings>
</menus>
@@ -26,9 +26,10 @@
<child widget="main_menu/settings_select/multiplayer_setup/item_options_edit/op_infinite_grenades" x="54" y="73"/>
<child widget="main_menu/settings_select/multiplayer_setup/item_options_edit/op_weapon_set" x="54" y="103"/>
<child widget="main_menu/settings_select/multiplayer_setup/item_options_edit/op_starting_equipment" x="54" y="133"/>
<child widget="main_menu/settings_select/multiplayer_setup/item_options_edit/op_loadout" x="54" y="163"/>
<child widget="main_menu/settings_select/multiplayer_setup/item_options_edit/op_primary_weapon" x="54" y="193"/>
<child widget="main_menu/settings_select/multiplayer_setup/item_options_edit/op_secondary_weapon" x="54" y="223"/>
<child widget="main_menu/settings_select/multiplayer_setup/item_options_edit/op_map_weapons" x="54" y="163"/>
<child widget="main_menu/settings_select/multiplayer_setup/item_options_edit/op_loadout" x="54" y="193"/>
<child widget="main_menu/settings_select/multiplayer_setup/item_options_edit/op_primary_weapon" x="54" y="223"/>
<child widget="main_menu/settings_select/multiplayer_setup/item_options_edit/op_secondary_weapon" x="54" y="253"/>
<child widget="main_menu/settings_select/multiplayer_setup/item_options_edit/item_button_bar" y="414"/>
</widget>
<widget name="main_menu/settings_select/multiplayer_setup/item_options_edit/item_options_screen" width="640" height="480" flags="pass_unhandled_to_focused_child" bitmap="bitmaps/gradient">
@@ -14,13 +14,15 @@
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/options_menu" type="column_list" width="640" height="480" flags="pass_unhandled_to_focused_child up_down_tabs_children" description="main_menu/settings_select/player_setup/player_profile_edit/video_settings/help">
<data input="port settings help"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/op_mode" x="54" y="73" platform="desktop"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/op_window_scale" x="54" y="99" platform="desktop"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/op_vsync" x="54" y="125"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/op_max_fps" x="54" y="151" platform="desktop"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/op_interpolation" x="54" y="177"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/op_direct_camera" x="54" y="203" platform="desktop"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/op_high_res_hud" x="54" y="229"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/op_high_res_text" x="54" y="255"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/op_resolution" x="54" y="99" platform="desktop"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/op_window_size" x="54" y="99" platform="desktop"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/op_resolution_scaling" x="54" y="125" platform="desktop"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/op_vsync" x="54" y="151"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/op_max_fps" x="54" y="177" platform="desktop"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/op_interpolation" x="54" y="203"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/op_direct_camera" x="54" y="229" platform="desktop"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/op_high_res_hud" x="54" y="255"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/op_high_res_text" x="54" y="281"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/button_bar" y="414"/>
</widget>
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/button_bar" type="column_list" width="640" height="28" flags="pass_unhandled_to_focused_child left_right_tabs_items">
@@ -37,20 +39,38 @@
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/mode_spinner" type="spinner" left="3" top="2" width="147" height="20" flags="pass_unhandled_to_focused_child left_right_tabs_items" strings="FULLSCREEN|BORDERLESS|WINDOWED" setting="display.mode" values="fullscreen|borderless|windowed" font="ui\large_ui" color="#FF2896FF" align="center" text_y="1" header_bitmap="bitmaps/arrow_sm_left" footer_bitmap="bitmaps/arrow_sm_right" header_bounds="7 -6 19 0" footer_bounds="7 150 19 156">
<on event="created" run="port setting load"/>
</widget>
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/op_window_scale" width="512" height="28" flags="pass_unhandled_to_focused_child" bitmap="bitmaps/option_bkds" color="#FF2896FF" platform="desktop">
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/window_scale_label"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/window_scale_spinner" x="320" y="1"/>
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/op_resolution" width="512" height="28" flags="pass_unhandled_to_focused_child" bitmap="bitmaps/option_bkds" color="#FF2896FF" platform="desktop">
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/resolution_label"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/resolution_spinner" x="320" y="1"/>
</widget>
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/window_scale_label" type="text" controller="1" width="300" height="22" string_list="main_menu/settings_select/player_setup/player_profile_edit/video_settings/labels" string_index="1" font="ui\large_ui" color="#FF2896FF" text_x="13" text_y="4">
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/resolution_label" type="text" controller="1" width="300" height="22" string_list="main_menu/settings_select/player_setup/player_profile_edit/video_settings/labels" string_index="1" font="ui\large_ui" color="#FF2896FF" text_x="13" text_y="4">
</widget>
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/window_scale_spinner" type="spinner" left="3" top="2" width="147" height="20" flags="pass_unhandled_to_focused_child left_right_tabs_items" strings="640 x 480|1280 x 960|1920 x 1440|2560 x 1920" setting="display.window_scale" values="1|2|3|4" font="ui\large_ui" color="#FF2896FF" align="center" text_y="1" header_bitmap="bitmaps/arrow_sm_left" footer_bitmap="bitmaps/arrow_sm_right" header_bounds="7 -6 19 0" footer_bounds="7 150 19 156">
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/resolution_spinner" type="spinner" left="3" top="2" width="147" height="20" flags="pass_unhandled_to_focused_child left_right_tabs_items" strings="NATIVE" setting="display.resolution" values="native" font="ui\large_ui" color="#FF2896FF" align="center" text_y="1" header_bitmap="bitmaps/arrow_sm_left" footer_bitmap="bitmaps/arrow_sm_right" header_bounds="7 -6 19 0" footer_bounds="7 150 19 156">
<on event="created" run="port setting load"/>
</widget>
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/op_window_size" width="512" height="28" flags="pass_unhandled_to_focused_child" bitmap="bitmaps/option_bkds" color="#FF2896FF" platform="desktop">
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/window_size_label"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/window_size_spinner" x="320" y="1"/>
</widget>
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/window_size_label" type="text" controller="1" width="300" height="22" string_list="main_menu/settings_select/player_setup/player_profile_edit/video_settings/labels" string_index="2" font="ui\large_ui" color="#FF2896FF" text_x="13" text_y="4">
</widget>
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/window_size_spinner" type="spinner" left="3" top="2" width="147" height="20" flags="pass_unhandled_to_focused_child left_right_tabs_items" strings="1280 x 960" setting="display.window_size" values="1280x960" font="ui\large_ui" color="#FF2896FF" align="center" text_y="1" header_bitmap="bitmaps/arrow_sm_left" footer_bitmap="bitmaps/arrow_sm_right" header_bounds="7 -6 19 0" footer_bounds="7 150 19 156">
<on event="created" run="port setting load"/>
</widget>
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/op_resolution_scaling" width="512" height="28" flags="pass_unhandled_to_focused_child" bitmap="bitmaps/option_bkds" color="#FF2896FF" platform="desktop">
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/resolution_scaling_label"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/resolution_scaling_spinner" x="320" y="1"/>
</widget>
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/resolution_scaling_label" type="text" controller="1" width="300" height="22" string_list="main_menu/settings_select/player_setup/player_profile_edit/video_settings/labels" string_index="3" font="ui\large_ui" color="#FF2896FF" text_x="13" text_y="4">
</widget>
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/resolution_scaling_spinner" type="spinner" left="3" top="2" width="147" height="20" flags="pass_unhandled_to_focused_child left_right_tabs_items" strings="NATIVE|ORIGINAL" setting="display.resolution_scaling" values="native|original" font="ui\large_ui" color="#FF2896FF" align="center" text_y="1" header_bitmap="bitmaps/arrow_sm_left" footer_bitmap="bitmaps/arrow_sm_right" header_bounds="7 -6 19 0" footer_bounds="7 150 19 156">
<on event="created" run="port setting load"/>
</widget>
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/op_vsync" width="512" height="28" flags="pass_unhandled_to_focused_child" bitmap="bitmaps/option_bkds" color="#FF2896FF">
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/vsync_label"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/vsync_spinner" x="320" y="1"/>
</widget>
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/vsync_label" type="text" controller="1" width="300" height="22" string_list="main_menu/settings_select/player_setup/player_profile_edit/video_settings/labels" string_index="2" font="ui\large_ui" color="#FF2896FF" text_x="13" text_y="4">
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/vsync_label" type="text" controller="1" width="300" height="22" string_list="main_menu/settings_select/player_setup/player_profile_edit/video_settings/labels" string_index="4" font="ui\large_ui" color="#FF2896FF" text_x="13" text_y="4">
</widget>
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/vsync_spinner" type="spinner" left="3" top="2" width="147" height="20" flags="pass_unhandled_to_focused_child left_right_tabs_items" strings="ON|OFF" setting="display.vsync" values="true|false" font="ui\large_ui" color="#FF2896FF" align="center" text_y="1" header_bitmap="bitmaps/arrow_sm_left" footer_bitmap="bitmaps/arrow_sm_right" header_bounds="7 -6 19 0" footer_bounds="7 150 19 156">
<on event="created" run="port setting load"/>
@@ -59,7 +79,7 @@
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/max_fps_label"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/max_fps_spinner" x="320" y="1"/>
</widget>
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/max_fps_label" type="text" controller="1" width="300" height="22" string_list="main_menu/settings_select/player_setup/player_profile_edit/video_settings/labels" string_index="3" font="ui\large_ui" color="#FF2896FF" text_x="13" text_y="4">
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/max_fps_label" type="text" controller="1" width="300" height="22" string_list="main_menu/settings_select/player_setup/player_profile_edit/video_settings/labels" string_index="5" font="ui\large_ui" color="#FF2896FF" text_x="13" text_y="4">
</widget>
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/max_fps_spinner" type="spinner" left="3" top="2" width="147" height="20" flags="pass_unhandled_to_focused_child left_right_tabs_items" strings="AUTO|30|60|120|144|165|240|NONE" setting="display.max_fps" values="0|30|60|120|144|165|240|-1" font="ui\large_ui" color="#FF2896FF" align="center" text_y="1" header_bitmap="bitmaps/arrow_sm_left" footer_bitmap="bitmaps/arrow_sm_right" header_bounds="7 -6 19 0" footer_bounds="7 150 19 156">
<on event="created" run="port setting load"/>
@@ -68,7 +88,7 @@
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/interpolation_label"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/interpolation_spinner" x="320" y="1"/>
</widget>
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/interpolation_label" type="text" controller="1" width="300" height="22" string_list="main_menu/settings_select/player_setup/player_profile_edit/video_settings/labels" string_index="4" font="ui\large_ui" color="#FF2896FF" text_x="13" text_y="4">
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/interpolation_label" type="text" controller="1" width="300" height="22" string_list="main_menu/settings_select/player_setup/player_profile_edit/video_settings/labels" string_index="6" font="ui\large_ui" color="#FF2896FF" text_x="13" text_y="4">
</widget>
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/interpolation_spinner" type="spinner" left="3" top="2" width="147" height="20" flags="pass_unhandled_to_focused_child left_right_tabs_items" strings="ON|OFF" setting="display.interpolation" values="true|false" font="ui\large_ui" color="#FF2896FF" align="center" text_y="1" header_bitmap="bitmaps/arrow_sm_left" footer_bitmap="bitmaps/arrow_sm_right" header_bounds="7 -6 19 0" footer_bounds="7 150 19 156">
<on event="created" run="port setting load"/>
@@ -77,7 +97,7 @@
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/direct_camera_label"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/direct_camera_spinner" x="320" y="1"/>
</widget>
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/direct_camera_label" type="text" controller="1" width="300" height="22" string_list="main_menu/settings_select/player_setup/player_profile_edit/video_settings/labels" string_index="5" font="ui\large_ui" color="#FF2896FF" text_x="13" text_y="4">
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/direct_camera_label" type="text" controller="1" width="300" height="22" string_list="main_menu/settings_select/player_setup/player_profile_edit/video_settings/labels" string_index="7" font="ui\large_ui" color="#FF2896FF" text_x="13" text_y="4">
</widget>
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/direct_camera_spinner" type="spinner" left="3" top="2" width="147" height="20" flags="pass_unhandled_to_focused_child left_right_tabs_items" strings="ON|OFF" setting="display.direct_camera" values="true|false" font="ui\large_ui" color="#FF2896FF" align="center" text_y="1" header_bitmap="bitmaps/arrow_sm_left" footer_bitmap="bitmaps/arrow_sm_right" header_bounds="7 -6 19 0" footer_bounds="7 150 19 156">
<on event="created" run="port setting load"/>
@@ -86,7 +106,7 @@
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/high_res_hud_label"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/high_res_hud_spinner" x="320" y="1"/>
</widget>
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/high_res_hud_label" type="text" controller="1" width="300" height="22" string_list="main_menu/settings_select/player_setup/player_profile_edit/video_settings/labels" string_index="6" font="ui\large_ui" color="#FF2896FF" text_x="13" text_y="4">
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/high_res_hud_label" type="text" controller="1" width="300" height="22" string_list="main_menu/settings_select/player_setup/player_profile_edit/video_settings/labels" string_index="8" font="ui\large_ui" color="#FF2896FF" text_x="13" text_y="4">
</widget>
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/high_res_hud_spinner" type="spinner" left="3" top="2" width="147" height="20" flags="pass_unhandled_to_focused_child left_right_tabs_items" strings="ON|OFF" setting="display.high_res_hud" values="true|false" font="ui\large_ui" color="#FF2896FF" align="center" text_y="1" header_bitmap="bitmaps/arrow_sm_left" footer_bitmap="bitmaps/arrow_sm_right" header_bounds="7 -6 19 0" footer_bounds="7 150 19 156">
<on event="created" run="port setting load"/>
@@ -95,7 +115,7 @@
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/high_res_text_label"/>
<child widget="main_menu/settings_select/player_setup/player_profile_edit/video_settings/high_res_text_spinner" x="320" y="1"/>
</widget>
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/high_res_text_label" type="text" controller="1" width="300" height="22" string_list="main_menu/settings_select/player_setup/player_profile_edit/video_settings/labels" string_index="7" font="ui\large_ui" color="#FF2896FF" text_x="13" text_y="4">
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/high_res_text_label" type="text" controller="1" width="300" height="22" string_list="main_menu/settings_select/player_setup/player_profile_edit/video_settings/labels" string_index="9" font="ui\large_ui" color="#FF2896FF" text_x="13" text_y="4">
</widget>
<widget name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/high_res_text_spinner" type="spinner" left="3" top="2" width="147" height="20" flags="pass_unhandled_to_focused_child left_right_tabs_items" strings="ON|OFF" setting="display.high_res_text" values="true|false" font="ui\large_ui" color="#FF2896FF" align="center" text_y="1" header_bitmap="bitmaps/arrow_sm_left" footer_bitmap="bitmaps/arrow_sm_right" header_bounds="7 -6 19 0" footer_bounds="7 150 19 156">
<on event="created" run="port setting load"/>
@@ -112,7 +132,9 @@
</widget>
<strings name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/labels">
<string text="DISPLAY MODE:"/>
<string text="RESOLUTION:"/>
<string text="WINDOW SIZE:"/>
<string text="RESOLUTION SCALING:"/>
<string text="V-SYNC:"/>
<string text="FRAME RATE LIMIT:"/>
<string text="SMOOTH MOTION:"/>
@@ -122,8 +144,10 @@
</strings>
<strings name="main_menu/settings_select/player_setup/player_profile_edit/video_settings/help_strings">
<string text=""/>
<string text="Fullscreen and borderless draw at the display's\nresolution; windowed, 640x480 scaled. F11: window."/>
<string text="The window's size when windowed (its edges can\nalso be dragged)."/>
<string text="Fullscreen takes the display; borderless covers it\nwith a window. F11 switches to the window."/>
<string text="What fullscreen and borderless draw at. Fullscreen\nsets the display to it; borderless scales it."/>
<string text="The window's size: 4:3, then 16:10, 16:9 and 21:9\n(its edges can also be dragged)."/>
<string text="Native draws at the resolution; Original draws\nthe Xbox's 640x480 and scales it up."/>
<string text="Wait for the display between frames, so that the\npicture never tears."/>
<string text="With V-Sync off, the most frames a second. Auto:\ntwice the display's refresh rate."/>
<string text="Draw a frame for every display refresh, blending\nbetween the game's 30 ticks a second."/>
@@ -14,6 +14,9 @@
<child widget="main_menu/solo_level_select/difficulty_indicator" x="416" y="343"/>
<child widget="main_menu/solo_level_select/difficulty_indicator" x="466" y="343"/>
<child widget="main_menu/solo_level_select/difficulty_indicator" x="516" y="343"/>
<child widget="main_menu/multiplayer_type_select/mp_map_select/mp_map_right_name"/>
<child widget="main_menu/multiplayer_type_select/mp_map_select/mp_map_right_pic"/>
<child widget="main_menu/multiplayer_type_select/mp_map_select/mp_map_right_data"/>
</widget>
<widget name="main_menu/solo_level_select/replay_level_right_name" type="text" controller="1" left="417" top="204" width="146" height="43" string_list="main_menu/map_list" string_index="2" font="ui\large_ui" color="#FF2896FF">
</widget>
@@ -38,7 +41,7 @@
<on event="created" run="initialize sp level list solo"/>
<on event="deleted" run="dispose sp level list"/>
<on event="custom_activation" run="solo level set map" open="main_menu/difficulty_select/difficulty_select_list_screen"/>
<child widget="main_menu/new_select/list_item_0" x="20" y="73"/>
<child widget="main_menu/new_select/list_item_0_map_kind" x="82" y="73"/>
<child widget="main_menu/new_select/list_item_1" x="20" y="103"/>
<child widget="main_menu/new_select/list_item_2" x="20" y="133"/>
<child widget="main_menu/new_select/list_item_3" x="20" y="163"/>
Binary file not shown.

After

Width:  |  Height:  |  Size: 75 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 305 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 323 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

+17 -4
View File
@@ -374,6 +374,7 @@
<string text="Join a game by its invite link,\nor one a Discord invite\nreached."/>
<string text="Host a game on the Internet:\nplayers join by its invite\nlink or Discord."/>
<string text="Host a game on your LAN\nonly."/>
<string text="Play the campaign with a\nfriend in split screen:\nplayer 2 on a gamepad."/>
<string text="Set all the attributes for your \nmultiplayer gametypes and\nkeep them for future use."/>
</strings>
<strings name="main_menu/multiplayer_type_select/multiplayer_options">
@@ -384,6 +385,7 @@
<string text="DIRECT LINK"/>
<string text="EDIT GAMETYPES"/>
<string text="SERVER BROWSER"/>
<string text="CO-OP CAMPAIGN"/>
</strings>
<strings name="main_menu/multiplayer_type_select/server_settings/cap_server_settings_options">
<string text="Enter a name for your server."/>
@@ -498,6 +500,8 @@
<string text="The map's weapons, without any grenades."/>
<string text="You will start the game with the weapon set that the \nmap designers custom tailored for it."/>
<string text="Use the generic starting weapons across all maps."/>
<string text="The map's weapons appear where its designers\nplaced them."/>
<string text="No weapons appear on the map: with a loadout of\nNONE and NONE, melee and grenades only."/>
<string text="The weapons follow the weapon set above."/>
<string text="Everyone starts with the primary and secondary\nweapons below; the map's weapons are its own."/>
<string text="No primary weapon."/>
@@ -510,8 +514,6 @@
<string text="Everyone spawns with a plasma pistol as their primary\nweapon (where the map has one)."/>
<string text="Everyone spawns with a plasma rifle as their primary\nweapon (where the map has one)."/>
<string text="Everyone spawns with a needler as their primary\nweapon (where the map has one)."/>
<string text="Everyone spawns with a fuel rod as their primary\nweapon (where the map has one)."/>
<string text="Everyone spawns with a flamethrower as their primary\nweapon (where the map has one)."/>
<string text="No secondary weapon."/>
<string text="A random secondary weapon, of those the map has,\neach time you spawn."/>
<string text="Everyone spawns with a assault rifle as their secondary\nweapon (where the map has one)."/>
@@ -522,8 +524,6 @@
<string text="Everyone spawns with a plasma pistol as their secondary\nweapon (where the map has one)."/>
<string text="Everyone spawns with a plasma rifle as their secondary\nweapon (where the map has one)."/>
<string text="Everyone spawns with a needler as their secondary\nweapon (where the map has one)."/>
<string text="Everyone spawns with a fuel rod as their secondary\nweapon (where the map has one)."/>
<string text="Everyone spawns with a flamethrower as their secondary\nweapon (where the map has one)."/>
</strings>
<strings name="main_menu/settings_select/multiplayer_setup/item_options_edit/item_options_labels">
<string text="INFINITE GRENADES:"/>
@@ -534,6 +534,7 @@
<string text="LOADOUT:"/>
<string text="PRIMARY WEAPON:"/>
<string text="SECONDARY WEAPON:"/>
<string text="MAP WEAPONS:"/>
</strings>
<strings name="main_menu/settings_select/multiplayer_setup/item_options_edit/var_infinite_grenades">
<string text="YES"/>
@@ -963,6 +964,12 @@
<string text="At the end of this game there will be fifteen angry\nmen. Angry because the winning player killed them."/>
<string text="You'll need to secure twenty-five kills in order to\nwin the game."/>
<string text="We hope you've got plenty of time, because you'll\nneed to make a full fifty kills to win this one."/>
<string text="Seventy-five kills to win. Settle in for a long\nfight."/>
<string text="A hundred kills to win. Made for big games."/>
<string text="A hundred and fifty kills to win. Only a crowded\nserver gets there."/>
<string text="Two hundred kills to win. Bring friends. Lots of\nthem."/>
<string text="Two hundred and fifty kills to win."/>
<string text="Five hundred kills to win. You'll be here a while."/>
<string text="This is a team game."/>
<string text="It's every man for himself."/>
<string text="The game will have no time limit. It will only end\nwhen someone wins."/>
@@ -994,6 +1001,12 @@
<string text="15"/>
<string text="25"/>
<string text="50"/>
<string text="75"/>
<string text="100"/>
<string text="150"/>
<string text="200"/>
<string text="250"/>
<string text="500"/>
</strings>
<strings name="main_menu/settings_select/multiplayer_setup/playlist_edit/slayer_edit/var_team_play">
<string text="YES"/>
+11
View File
@@ -8,6 +8,7 @@
"ce/main_menu.gametype_select.xml",
"ce/main_menu.multiplayer_type_select.connected.4way_profile_select.xml",
"ce/main_menu.multiplayer_type_select.connected.xml",
"ce/main_menu.multiplayer_type_select.coop.xml",
"ce/main_menu.multiplayer_type_select.direct_ip.xml",
"ce/main_menu.multiplayer_type_select.join_game.filters.xml",
"ce/main_menu.multiplayer_type_select.join_game.port.xml",
@@ -16,6 +17,7 @@
"ce/main_menu.multiplayer_type_select.mp_map_select.xml",
"ce/main_menu.multiplayer_type_select.server_settings.xml",
"ce/main_menu.multiplayer_type_select.xml",
"ce/main_menu.new_select.port.xml",
"ce/main_menu.new_select.xml",
"ce/main_menu.player_profiles_select.xml",
"ce/main_menu.profile_manager.xml",
@@ -49,9 +51,18 @@
"ce/main_menu.xml",
"ce/shell.xml",
"ce/strings.xml",
"ce/port/blank__0.png",
"ce/port/main_menu/multiplayer_type_select/coop/header_player_2.png",
"ce/port/main_menu/multiplayer_type_select/join_game/header_direct_link.png",
"ce/port/main_menu/multiplayer_type_select/join_game/header_server_browser.png",
"ce/port/main_menu/multiplayer_type_select/lobby/header_add_player.png",
"ce/port/main_menu/multiplayer_type_select/lobby/header_lobby.png",
"ce/port/pause/pausebox_center__0.png",
"ce/port/pause/pausebox_center__1.png",
"ce/port/pause/pausebox_left__0.png",
"ce/port/pause/pausebox_left__1.png",
"ce/port/pause/pausebox_right__0.png",
"ce/port/pause/pausebox_right__1.png",
"ce/shell/bitmaps/alert_bkd__0.png",
"ce/shell/bitmaps/arrow_sm_down__0.png",
"ce/shell/bitmaps/arrow_sm_down__1.png",
+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="4" height="4" viewBox="0 0 4 4"/>

After

Width:  |  Height:  |  Size: 81 B

@@ -0,0 +1,13 @@
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="64" viewBox="0 0 512 64">
<defs>
<filter id="soft" filterUnits="userSpaceOnUse" x="-60" y="-60" width="632" height="184">
<feGaussianBlur stdDeviation="14.23 13.06"/>
</filter>
<mask id="cut" maskUnits="userSpaceOnUse" x="0" y="0" width="512" height="64">
<rect width="512" height="59" fill="#fff"/>
</mask>
</defs>
<g mask="url(#cut)">
<rect x="29.08" y="28.05" width="323.93" height="40.95" fill="#021931" fill-opacity="0.893" filter="url(#soft)"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 563 B

@@ -0,0 +1,13 @@
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="64" viewBox="0 0 512 64">
<defs>
<filter id="soft" filterUnits="userSpaceOnUse" x="-60" y="-60" width="632" height="184">
<feGaussianBlur stdDeviation="14.23 13.06"/>
</filter>
<mask id="cut" maskUnits="userSpaceOnUse" x="0" y="0" width="512" height="64">
<rect width="512" height="59" fill="#fff"/>
</mask>
</defs>
<g mask="url(#cut)">
<rect x="29.08" y="28.05" width="226.48" height="40.95" fill="#021931" fill-opacity="0.893" filter="url(#soft)"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 563 B

@@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" width="4" height="256" viewBox="0 0 4 256">
<rect x="0" y="2" width="4" height="190" fill="#0a2649" fill-opacity="0.75"/>
<rect x="0" y="0" width="4" height="2" fill="#2896ff"/>
<rect x="0" y="192" width="4" height="2" fill="#2896ff"/>
</svg>

After

Width:  |  Height:  |  Size: 289 B

@@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" width="4" height="256" viewBox="0 0 4 256">
<rect x="0" y="2" width="4" height="225" fill="#0a2649" fill-opacity="0.75"/>
<rect x="0" y="0" width="4" height="2" fill="#2896ff"/>
<rect x="0" y="227" width="4" height="2" fill="#2896ff"/>
</svg>

After

Width:  |  Height:  |  Size: 289 B

@@ -0,0 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="256" viewBox="0 0 16 256">
<path d="M9.5,1 H17 V193 H9.5 A8.5,8.5 0 0 1 1,184.5 V9.5 A8.5,8.5 0 0 1 9.5,1 Z" fill="#0a2649" fill-opacity="0.75" fill-rule="evenodd"/>
<path d="M17,1 H9.5 A8.5,8.5 0 0 0 1,9.5 V184.5 A8.5,8.5 0 0 0 9.5,193 H17" fill="none" stroke="#2896ff" stroke-width="2"/>
</svg>

After

Width:  |  Height:  |  Size: 360 B

@@ -0,0 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="256" viewBox="0 0 16 256">
<path d="M9.5,1 H17 V228 H9.5 A8.5,8.5 0 0 1 1,219.5 V9.5 A8.5,8.5 0 0 1 9.5,1 Z" fill="#0a2649" fill-opacity="0.75" fill-rule="evenodd"/>
<path d="M17,1 H9.5 A8.5,8.5 0 0 0 1,9.5 V219.5 A8.5,8.5 0 0 0 9.5,228 H17" fill="none" stroke="#2896ff" stroke-width="2"/>
</svg>

After

Width:  |  Height:  |  Size: 360 B

@@ -0,0 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="256" viewBox="0 0 16 256">
<g transform="matrix(-1 0 0 1 16 0)">
<path d="M9.5,1 H17 V193 H9.5 A8.5,8.5 0 0 1 1,184.5 V9.5 A8.5,8.5 0 0 1 9.5,1 Z" fill="#0a2649" fill-opacity="0.75" fill-rule="evenodd"/>
<path d="M17,1 H9.5 A8.5,8.5 0 0 0 1,9.5 V184.5 A8.5,8.5 0 0 0 9.5,193 H17" fill="none" stroke="#2896ff" stroke-width="2"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 411 B

@@ -0,0 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="256" viewBox="0 0 16 256">
<g transform="matrix(-1 0 0 1 16 0)">
<path d="M9.5,1 H17 V228 H9.5 A8.5,8.5 0 0 1 1,219.5 V9.5 A8.5,8.5 0 0 1 9.5,1 Z" fill="#0a2649" fill-opacity="0.75" fill-rule="evenodd"/>
<path d="M17,1 H9.5 A8.5,8.5 0 0 0 1,9.5 V219.5 A8.5,8.5 0 0 0 9.5,228 H17" fill="none" stroke="#2896ff" stroke-width="2"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 411 B

+10
View File
@@ -0,0 +1,10 @@
# The public MQTT brokers of internet play: the machines of an invite find
# each other through them, and the server browser's listings go through
# them. The game uses every one at once (up to 4), so any one working is
# enough. One host:port on each line; "#" starts a comment.
# (The game reads this file beside config.toml: network.brokers_file. An
# update replaces it; keep a list of your own under another name.)
opence.milenko.org:1883
broker.emqx.io:1883
broker.hivemq.com:1883
test.mosquitto.org:1883
+74 -4
View File
@@ -21,6 +21,64 @@ with ideas from VALORANT's netcode articles, keeping the 30 Hz tick:
vehicle it drives) from its local input at once. Remote players are
driven by the inputs the host relays every tick, the latest one held
until a newer arrives.
- **Actors driven.** Only the host runs the AI. Each tick it sends its
clients the control its actors gave their units (how they move, where
they face, aim and look, their trigger and buttons, their animation
impulses) with the units' state, those near a client's players every
tick and others less often; a client drives each unit with the latest
it has, as it drives a remote player's, until it hears nothing of it for
two seconds (`port/linux/game/network_actors.c`).
- **Co-op.** A network game on a campaign level with no game engine
(Create Game's Map screen, its SINGLEPLAYER maps, over LAN and the
internet) is co-op. Only the host runs the
level's scripts and spawns players. `network_coop.c` sends the clients
everything the scripts do that they would otherwise miss:
- every tick: the cinematic, camera, screen fade, the HUD settings the
scripts control (what is shown, the mission timer), the skip vote, and
which teams are allies and friends (the scripts' allegiances, so the
marines are the players' allies on every machine);
- once each, numbered so nothing is applied twice: script sounds,
chapter titles, help and objective text, "Checkpoint" messages, screen
shake, nav points, custom animations on units and scenery, and units
opening and closing (dropships' doors);
- device groups (doors, elevators, switches; a client sets none itself,
and its player's use of one is relayed to the host), and each device's
position and power as it changes: a client puts its device where the
host's is once that stops, or if they drift apart while it moves;
- which named objects exist, so scripted creates and deletes match.
Every machine follows the host's structure BSP: a switch is sent at once
and reliably, and each client's input says which BSP it has loaded.
Until a client has the host's, the host takes none of its players'
movement and none of its loading zones, and after any switch no loading
zone switches again until every machine has the new BSP (ten seconds at
most). A loading zone into a
BSP the team hasn't been in brings every player to whoever crossed it,
as split screen does; one back into a BSP it has been in switches only
with two thirds of the living players at it (in the trigger, or within
4 world units of the player in it), so one player can't drag the team
back through the level. A player outside the loaded BSP and falling for
two seconds is brought back beside a teammate. A dead player watches a
living teammate (`coop_spectate.c`) and comes back beside one once it is
safe. With everyone dead they come back where they were at the last
checkpoint, since only the host could revert. A level won ends the round
as in multiplayer, and the next round is the campaign's next level.
Cutscenes are skipped by vote: more than half the machines must press
skip. The host then reverts as single player does, but keeps its clock
moving forward (the netcode depends on that) and moves the script
threads' wake times along with it. The object, device and name syncs
bring the clients up to date.
The host's EXTRA ENEMIES (`coop_enemies.c`, `network.coop_enemies_mode`)
give each squad of enemies a level places more of itself: PER PLAYER, a
percentage of itself for each player past the first; STATIC MULTIPLIER,
that many times itself for any number of players. They stand in rings
about its starting locations where the ground is open, and never take the
actors a level needs for its own (the actor pool, `halo_port_capacity.h`,
holds 1024). Riders a dropship has no seats for are kept, and placed
beside its riders once they get out. Only the host runs the AI, so the
clients see them as the host's other actors.
- **Host authoritative.** The host alone decides damage, deaths, spawns,
pickups, scores and the game's objects; clients do not decide them but
apply what the host sends.
@@ -93,7 +151,15 @@ is dead; version 8 is the first whose clients play by the host's rules
(below), so a build without them joins no host of it; version 9 tells
every machine of a player the host dropped for cheating, each client
tells the host its Discord user, and a machine's join request carries its
hardware id; version 10 sends every player's ping for the scoreboard.
hardware id; version 10 sends every player's ping for the scoreboard;
version 11 sends with the game's settings its gametype's PC options;
version 12 plays the campaign together (co-op, above), drives the host's
actors on its clients and sends the flinches and deaths the host picked;
version 13 drives up to 1056 of the host's AI units on its clients (co-op's
extra enemies), where 12 drove 288; version 14 sends co-op's device positions
and its units opening and closing; version 15 sends co-op's allegiances with
its presentation, a message of another size; version 16 has a client's input
say which structure BSP it has loaded (co-op).
A client plays by its host's rules: in another's game (searching for it,
in its lobby, or playing it) the developer console, the telnet console
@@ -138,7 +204,9 @@ added to `bans.txt` beside `debug.txt` (a line each, as in `cheaters.txt`,
with `ip=` and `hwid=`): the host refuses a machine joining whose address or
hardware id is in it (a line taken out unbans). Both are as the player's
machine tells them: anyone with administrator or root access can change
them, and players behind one address share it.
them, and players behind one address share it. The console's `kick <player
name>` drops a player as `ban` does (every machine told), but adds no line
and keeps no address out: the player may join again at once.
A speed hack of less than a tenth is let be: the host's bounds on how far
and how fast a client's player moves and fires hold it to the host's time
anyway.
@@ -282,8 +350,10 @@ a pregame keep-alive every five seconds from the host
host's latest tick it had heard of when it made the report.
- The host deals a report once it has checked it: from that machine's
player; damage one of their weapons (a vehicle's a driver's or
gunner's; now or in the last ten seconds), their grenades (while they
have them, and for a while after) or the vehicle they drove (in the
gunner's; now or in the last ten seconds), a grenade the host's own game
saw them throw in the last ten seconds that has not gone off (each
throw's explosion is taken once, its other hits that tick with it:
holding grenades deals nothing) or the vehicle they drove (in the
last ten seconds: its collisions) can deal (its projectiles' impacts
and detonations, followed through the tags), no harder than it can be
(all of it, but an airborne melee blow's half again); of the shape the
+120 -16
View File
@@ -83,7 +83,8 @@ These files are in the data root:
| `init.txt` | Console commands that the game does at start-up. For example, `map_name levels\a10\a10` starts the first campaign level. |
The settings are in `config.toml` next to the executable. Refer to
"Settings".
"Settings". Internet play's MQTT brokers are in `brokers.txt` next to it
(`network.brokers_file`).
If the game stops because of a fatal signal, it writes the address and a
backtrace to the standard error. To find the function at the address, enter
@@ -95,8 +96,12 @@ The keyboard and the mouse are a control scheme of their own for the player
of controller 1: each action has up to two keys or mouse buttons, which
Settings > Controls Setup (or `[controls]` in `config.toml`) changes. The
game adds the input of the first gamepad to controller 1. The other
gamepads operate controllers 2 to 4. The profile's button layout (Settings >
Gamepads) is the gamepads' only.
gamepads operate controllers 2 to 4. With two or more players on this
computer (co-op, or split screen in a network game) and only one gamepad,
that gamepad is controller 2 (player 2) and the keyboard and mouse stay
controller 1. The gamepad changes controller only when none of its buttons
is held. The profile's button layout (Settings > Gamepads) is the
gamepads' only.
| Action | Keys and buttons (default) |
| --- | --- |
@@ -157,6 +162,37 @@ change. The screens open, close and move between each other as the PC
version's. `display.menus = "xbox"` gives the Xbox's menus, which start every
kind of game.
Multiplayer > CO-OP CAMPAIGN is the Xbox's cooperative play, which the PC
version does not have: two players on this computer play the campaign in
split screen. Player 1 is the player who chose it, on the current profile.
Player 2 then chooses a profile with their own controller (a gamepad), and
New Game's levels are those either profile has reached. Either player's
controller chooses the level and the difficulty. A co-op game does
not continue a saved game of one player.
Network games have split screen too: up to 4 players on each computer. In
the game lobby, another controller presses START to join, and the new
player's profile is chosen on the ADD PLAYER screen that opens (with any
controller). With one gamepad, choose the lobby's ADD PLAYER button first:
until then that gamepad shares controller 1 with the keyboard. Two players on one profile get different names from the host. A
player's B in the lobby leaves the game alone, and the last player of the
computer leaves it for all of them. In the game, each player's pause menu
opens on their part of the screen, and its LEAVE GAME is theirs: their part
of the screen stays until the game ends. A game under way shows its own
screen before JOIN GAME: players join there the same way, START or ADD
PLAYER then START, and JOIN GAME brings them all into the game.
In a multiplayer game, the pause menu (escape) has SETTINGS, which opens
the profile's settings while the game goes on, and for the host END GAME.
END GAME ends the game as its time limit does: the players stay, and after
the carnage report the host picks the next map and gametype (PICK GAME).
LEAVE GAME of the host still ends the game for everyone. The buttons go into
the map's own pause menu, before LEAVE GAME, so the buttons of a custom map
stay. The Xbox's pause box is drawn taller to hold them (a redraw,
`port/assets/menus/port_svg/pause`); a custom map's box keeps its size, and
what is below its list moves down. The few pictures of the settings that
come from the main menu's map are not drawn there.
The menus are XML files in `port/assets/menus` (`tools/ce_menus.py` writes
them from the PC version's tags), which the game contains. To change them,
put files in a `menus` folder next to `config.toml`: a file with the same
@@ -184,18 +220,21 @@ the setting for one start of the game. It has priority over the file.
| Setting | Default | Environment variable | Function |
| --- | --- | --- | --- |
| `display.mode` | `""` | `HALO_DISPLAY_MODE` | `"fullscreen"`: the display, taken at its desktop resolution. `"borderless"`: a window over the whole desktop. Both draw at the resolution of the display, the picture 480 lines of the game and the width of the display. `"windowed"`: a window with the 640x480 picture of the Xbox, scaled. Empty: `display.fullscreen` decides (`true`: borderless). F11 changes between the window and the fullscreen mode. Video Setup sets it. |
| `display.fullscreen` | `true` | `HALO_FULLSCREEN` | `true`: fullscreen at the resolution of the display. The picture has 480 lines of the game and the width of the display. `false`: a window with the 640x480 picture of the Xbox. Used when `display.mode` is empty. |
| `display.window_scale` | `2` | `HALO_WINDOW_SCALE` | The size of the window, as a multiple of 640x480. You can change the size of the window. |
| `display.mode` | `""` | `HALO_DISPLAY_MODE` | `"fullscreen"`: the display, taken at the mode of `display.resolution` (the nearest the display has), or at its desktop mode. `"borderless"`: a window over the whole desktop, whose mode does not change. `"windowed"`: a window of `display.window_size`. Empty: `display.fullscreen` decides (`true`: borderless). F11 changes between the window and the fullscreen mode. Video Setup sets it. |
| `display.fullscreen` | `true` | `HALO_FULLSCREEN` | `true`: borderless, as `display.mode = "borderless"`. `false`: a window, as `display.mode = "windowed"`. Used when `display.mode` is empty. |
| `display.resolution` | `"native"` | `HALO_RESOLUTION` | What fullscreen and borderless draw at: `"native"`, the display's own resolution, or `"<width>x<height>"`, such as `"1920x1080"`, 640x480 or more. Fullscreen sets the display to it. Borderless draws at it and scales the picture to the display, where the display has room for it. The picture has 480 lines of the game and the width of the resolution's shape. A window draws at its own size instead. Video Setup's Resolution sets it, from the display's modes; it shows with Fullscreen and Borderless. |
| `display.resolution_scaling` | `"native"` | `HALO_RESOLUTION_SCALING` | `"native"`: the game draws at the resolution of the window, or of the display (or `display.resolution`) fullscreen. `"original"`: the game draws the 640x480 picture of the Xbox and scales it up to the window or the display, whatever `display.mode` is. Video Setup sets it. |
| `display.window_size` | `""` | `HALO_WINDOW_SIZE` | The size of the window, as `"<width>x<height>"`, such as `"1920x1080"`, 640x480 or more. You can change the size of the window; the game's picture takes its shape. Empty: `display.window_scale` decides. Video Setup's Window Size sets it, from sizes of each shape (4:3, 16:10, 16:9 and 21:9) that fit the desktop; it shows with Windowed. |
| `display.window_scale` | `2` | `HALO_WINDOW_SCALE` | Used when `display.window_size` is empty: the size of the window, as a multiple of 640x480. |
| `display.vsync` | `true` | `HALO_NO_VSYNC=1` sets `false` | `true`: each frame waits for the display. |
| `display.max_fps` | `0` | `HALO_MAX_FPS` | With vsync off, the most frames each second. `0`: twice the display's refresh rate. `-1`: no limit, which can hang some Intel graphics (Raptor Lake), resetting the desktop's graphics too. |
| `debug.gpu_flush_draws` | `-1` | `HALO_GPU_FLUSH_DRAWS` | Flush the GPU's pipeline every this many draws. `-1`: every 3 on Intel graphics with Mesa's driver, which can otherwise hang in the game's long runs of small draws and reset the desktop's graphics too. `0`: never. |
| `display.interpolation` | `true` | `HALO_INTERPOLATION` | `true`: one frame for each refresh of the display. `false`: 30 frames each second, as on the Xbox. Refer to "Frame rate". |
| `display.direct_camera` | `true` | `HALO_DIRECT_CAMERA` | `true`: in first person, on foot, the view points where the player aims in each frame, not where the last tick left it. Refer to "Frame rate". |
| `display.high_res_hud` | `true` | `HALO_HIGH_RES_HUD` | `true`: the HUD (meters, counters, panels and their outlines, the motion sensor, reticles, waypoints, scopes) is drawn from the high-res assets in `port/assets/hud`, 8x the size of the maps' bitmaps. The bitmaps with English text keep the maps' own. `false`: the maps' own bitmaps. |
| `display.high_res_text` | `true` | `HALO_HIGH_RES_TEXT` | `true`: the menus' and HUD's text is drawn with the fonts in `port/assets/fonts` (Overpass, in place of the maps' Interstate) at the display's resolution, laid out as before, and the menus' titles are drawn from the high-res pictures in `port/assets/titles`. `false`: the maps' bitmap fonts and titles. |
| `display.high_res_text` | `true` | `HALO_HIGH_RES_TEXT` | `true`: the menus' and HUD's text is drawn with the fonts in `port/assets/fonts` (Overpass, in place of the maps' Interstate) at the resolution the game draws at, laid out as before, and the menus' titles are drawn from the high-res pictures in `port/assets/titles`. `false`: the maps' bitmap fonts and titles. |
| `display.menus` | `"pc"` | `HALO_MENUS` | `"pc"`: the PC version's menus, from the files in `port/assets/menus` and a `menus` folder next to `config.toml`. Refer to "Menus". `"xbox"`: the Xbox's menus. |
| `display.player_names` | `"all"` | `HALO_PLAYER_NAMES` | In multiplayer, whose names are drawn above their heads: `"all"`, `"allies"`, `"enemies"` or `"none"`. An ally's name is drawn above the triangle the game shows over teammates. An enemy's name shows only while the enemy is in sight and not camouflaged, so it never shows where an enemy hides, and only as far away as the weapon in hand turns its reticle red over an enemy (at least 20 world units, the motion sensor's reach, and at most 70). |
| `display.player_names` | `"all"` | `HALO_PLAYER_NAMES` | In multiplayer, whose names are drawn above their heads: `"all"`, `"allies"`, `"enemies"` or `"none"`. An ally's name is drawn above the triangle the game shows over teammates. An enemy's name shows only within the motion sensor's reach, while the enemy is in sight and not camouflaged, so it never shows where an enemy hides. The gametype's motion tracker setting also applies: no names if it shows no players, only allies' if it shows only friends. |
| `display.player_name_scale` | `1.0` | `HALO_PLAYER_NAME_SCALE` | How large the players' names are drawn: `1.0` is three quarters of the size of the HUD's text, from `0.25` to `4`. With high-res text, larger names are rasterized at their size, so they stay sharp. |
| `display.scoreboard_team_layout` | `"teams"` | `HALO_SCOREBOARD_TEAM_LAYOUT` | How the multiplayer scoreboard (hold BACK, or tab) lists a team game's players. `"teams"`: a column for each team, red on the left and blue on the right. `"score"`: all the players in order of score. With more players than fit, the mouse wheel and Page Up / Page Down scroll the scoreboard. |
| `display.scoreboard_background` | `true` | `HALO_SCOREBOARD_BACKGROUND` | `true`: the multiplayer scoreboard (hold BACK, or tab) has a panel behind its text, for clearer text. |
@@ -219,7 +258,14 @@ the setting for one start of the game. It has priority over the file.
| `network.join_from_clipboard` | `true` | `HALO_NET_JOIN_FROM_CLIPBOARD` | `true`: when the game comes to the front, it joins the game of an invite link on the clipboard. |
| `network.tunnel_port` | `0` | `HALO_NET_TUNNEL_PORT` | The UDP port for internet play. `0`: the game selects a port. Refer to "Internet play". |
| `network.allow_upnp` | `true` | `HALO_NET_ALLOW_UPNP` | `true`: internet play can ask the router to forward its port (UPnP). `false`: the game does not ask. Refer to "Internet play". |
| `network.signalling_brokers` | three public brokers | `HALO_NET_BROKERS` | The public MQTT brokers (`host:port`, with commas between them) that let the machines of an invite find each other. |
| `network.public_lobby` | `true` | `HALO_NET_PUBLIC_LOBBY` | `true`: the server browser. Public games are listed, and Join Game > Server Browser shows them. `false`: no games are listed or shown. Refer to "Server browser". |
| `network.host_public` | `true` | `HALO_NET_HOST_PUBLIC` | `true`: a new game of Create Game > Internet starts as PUBLIC. `false`: it starts as PRIVATE. LISTING in Server Setup changes it for each game. Refer to "Server browser". |
| `network.coop_friendly_fire` | `"on"` | `HALO_NET_COOP_FRIENDLY_FIRE` | Whether the players of an online co-op game hurt each other: `"off"`, `"on"`, `"shields_only"` or `"explosives_only"`. FRIENDLY FIRE in co-op's Server Setup writes its choice here. Their AI allies they always can, as in the campaign. |
| `network.coop_enemies_mode` | `"per_player"` | `HALO_NET_COOP_ENEMIES_MODE` | Online co-op's extra enemies: `"none"`; `"per_player"`, each squad of enemies that a level places grows by `network.coop_enemies` for each player past the first; or `"multiplier"`, each squad is `network.coop_enemies_multiplier` times as large, for any number of players. The extra enemies stand around the squad's places, and those that a dropship has no seats for drop out of it after its passengers. EXTRA ENEMIES in co-op's Server Setup writes its choice here. |
| `network.coop_enemies` | `50` | `HALO_NET_COOP_ENEMIES` | The extra enemies per player, a percentage from `25` to `200`: for each player past the first, each squad of enemies gets this much of itself more (`100`: as many again, so four players meet four times the squad). PER PLAYER in co-op's Server Setup writes its choice here. |
| `network.coop_enemies_multiplier` | `2` | `HALO_NET_COOP_ENEMIES_MULTIPLIER` | The static multiplier of the enemies, `2` to `32`: each squad of enemies is this many times as large. MULTIPLIER in co-op's Server Setup writes its choice here. |
| `network.coop_public` | `false` | `HALO_NET_COOP_PUBLIC` | `true`: an online co-op game (Create Game > Internet, a SINGLEPLAYER map) starts as PUBLIC. `false`: it starts as PRIVATE. LISTING in co-op's Server Setup writes its choice here. Refer to "Server browser". |
| `network.brokers_file` | `"brokers.txt"` | `HALO_NET_BROKERS_FILE` | The file of the public MQTT brokers that let the machines of an invite find each other, and that carry the listings of the server browser: next to `config.toml`, unless a full path. One `host:port` on each line, up to 4; `#` starts a comment. |
| `network.stun_servers` | Google and Cloudflare | `HALO_NET_STUN` | The public STUN servers (`host:port`, with commas between them) that give the internet address of a machine. |
| `discord.application_id` | the application of the project | `HALO_DISCORD_APPLICATION` | The Discord application for invites. Empty: no Discord. |
| `update.auto` | `true` | `HALO_UPDATE_AUTO` | `true`: at start-up, the game looks for a new version. Refer to "Updates". `false`: the game does not look. |
@@ -402,17 +448,73 @@ When the machines connect, the game of the host shows in Multiplayer,
System Link. Join the game as on a local network. System link on a local
network does not need an invite.
### Server browser
Server Setup in Create Game > Internet has a LISTING row:
- PUBLIC (the default): the game also shows in Join Game > Server Browser
on every machine. Anyone can see and join the game.
- PRIVATE: only players with the invite link can join.
Each new game starts as PUBLIC (`network.host_public = false` makes new
games start as PRIVATE). An online co-op game starts as PRIVATE, and keeps
the last choice of its LISTING (`network.coop_public`). A LAN game is never listed. `network.public_lobby = false` turns the server browser off.
In the Server Browser, select a game to join it. The game joins the invite
of the game, as for a link. When it reaches the host, it opens the lobby.
If it cannot reach the host in 30 seconds, it marks the game FAILED. REFRESH
asks the hosts for their listings again.
How it operates (`src/p2p_lobby.c`):
- The host of a public game publishes a listing: the invite, and the name,
map, gametype and player counts of the game. The listing goes to the
same MQTT brokers as the invites (`network.brokers_file`), retained,
to a topic of the host (`hceu/3/lobby/s/<hash of its key>`).
- The key of the host signs the listing (Ed25519). The key is the key of the
invite, so no other machine can list the invite of the host, change its
listing, or list a game with false details.
- The host publishes the listing again every 30 seconds, when the game
changes, and when a browser asks. If the topic of the host is empty or
holds another listing, the host publishes again in 5 seconds or less. Thus
a broker that deletes the listing does not remove the game.
- When the host stops (it stops hosting, the game becomes private, or the
game quits), it publishes a closed listing, and then empties its topic.
If the host loses its connection, the broker empties its topic (the will
of the connection). A browser removes a game that it does not hear for 90
seconds.
- When a public game becomes private, the host makes a new invite. Thus a
player who saw the listing cannot join with the old invite.
A public game does not publish the address of the host. But any machine
with the invite can ask the host to connect, and the host then sends its
addresses. Thus anyone can learn the address of the host of a public game,
as for any public server.
The brokers are in `brokers.txt` next to the executable (from
`port/assets/network/brokers.txt`; on Android, the app writes it next to
`config.toml` at each start), one `host:port` on each line. The game uses
all of them at once (up to 4), so one that works is enough. An update
replaces `brokers.txt`: to use brokers of your own, put them in another
file and name it in `network.brokers_file`. All the players must use the
same broker to see each other's games. The game uses
MQTT 5 if the broker has it, else MQTT 3.1.1. A broker that does not keep
retained messages, or does not let clients subscribe with wildcards, carries
only invites, not listings.
### Security
Only machines with the invite can find the game:
- Each copy of the game makes an X25519 key pair when it starts. Its
identifier is from the hash of its public key.
- Each copy of the game makes an Ed25519 key pair when it starts, and from
it an X25519 key pair (Monocypher, `port/third_party/monocypher`). Its
identifier is from the hash of its X25519 public key. The Ed25519 key
signs the listing of a public game.
- The link contains a 16-byte hash of the public key of the host and a
random 16-byte token. The identifier of the host is from the first 6
bytes of the hash.
- The machines exchange their public keys and addresses through public MQTT
brokers (`network.signalling_brokers`). The topics are HMACs of the token.
brokers (`network.brokers_file`). The topics are HMACs of the token.
A key from the token encrypts and authenticates the messages
(`src/p2p_signal.c`, `src/p2p_crypto.c`). The host authenticates its answer
with a key that only it and the player can calculate. Its public key must
@@ -452,7 +554,9 @@ Only machines with the invite can find the game:
`bans.txt`, and refuses a machine whose address or hardware id is in it.
- The host can ban a player with `ban <player name>` in the developer
console (Tab completes the name). Remove a line from `bans.txt` to unban.
Refer to `NETCODE.md`. So that every player can be named, the host trims
Refer to `NETCODE.md`. `kick <player name>` drops the player the same
way, but keeps nothing: no line in `bans.txt`, and the player can join
again at once. So that every player can be named, the host trims
the spaces around a name and removes characters that draw as nothing. A
letter with a mark is typed as the plain letter (`ban jose` for "José").
A name with nothing left to type becomes "Player", and a name that another
@@ -522,7 +626,7 @@ The game sends the activity only to a Discord client of the same user.
| Game code | All 466 C files of the game. The changes are in "Game source changes". |
| Graphics | Direct3D 8 on OpenGL 4.5 core through SDL3 (`src/d3d8_gl.c`). The port translates the NV2A vertex shaders and register combiners to GLSL. It decodes all the Xbox texture formats. The vertex and index buffers come from a GL copy of the Xbox memory. |
| High-res HUD | The HUD is drawn from high-res assets: redraws at 8x the size of the maps' bitmaps (4x for the largest), in `port/assets/hud`. They cover the meters, counters, panels and their outlines, the motion sensor, reticles, waypoints and scopes, but no bitmap with English text. `tools/hud_assets.py` makes them from the SVG redraws, and the build embeds them in the executable. When the game uploads one of those bitmaps, `src/hud_hires.c` gives the high-res texture in its place, if the bitmap's pixels are those of the English maps: another language's maps keep their own. The game sizes and places the HUD from its tags as before. `display.high_res_hud = false` turns this off. |
| High-res text | The menus' and HUD's text is drawn with Overpass (`port/assets/fonts`, SIL Open Font License) in place of the maps' bitmap fonts, which are Interstate. `src/text_hires.c` rasterizes each glyph with stb_truetype (`port/third_party/stb`) at the display's resolution, into an atlas that a placeholder bitmap of the game stands for. The game lays the text out from its font tags as before. The menus' titles (the screens' headers and the main menu's items) are pictures of text in the maps, so they are drawn as the high-res HUD is: `tools/title_assets.py` sets each one again in OpenCE, Roger White's public-domain Newtown respaced to match the maps' commercial title typeface (`tools/title_font.py`), at 4x the bitmap's size over its own plate or glow, each letter placed where the map's letter is, in `port/assets/titles`. The postgame carnage report's title is set over a hand-made SVG redraw of its panel (`port/assets/titles/svg`) instead. `display.high_res_text = false` turns it off. |
| High-res text | The menus' and HUD's text is drawn with Overpass (`port/assets/fonts`, SIL Open Font License) in place of the maps' bitmap fonts, which are Interstate. `src/text_hires.c` rasterizes each glyph with stb_truetype (`port/third_party/stb`) at the resolution the game draws at, into an atlas that a placeholder bitmap of the game stands for. The game lays the text out from its font tags as before. The menus' titles (the screens' headers and the main menu's items) are pictures of text in the maps, so they are drawn as the high-res HUD is: `tools/title_assets.py` sets each one again in OpenCE, Roger White's public-domain Newtown respaced to match the maps' commercial title typeface (`tools/title_font.py`), at 4x the bitmap's size over its own plate or glow, each letter placed where the map's letter is, in `port/assets/titles`. The postgame carnage report's title is set over a hand-made SVG redraw of its panel (`port/assets/titles/svg`) instead. `display.high_res_text = false` turns it off. |
| Sound | Xbox DirectSound on SDL3 audio (`src/dsound_sdl.c`): PCM and Xbox ADPCM, mixed at 48 kHz, with volume, pitch, mix bins, distance, stereo pan, occlusion and obstruction. There is no Doppler effect, no cones and no reverb. |
| Input | XInput on SDL3 (`src/xinput_sdl.c`): keyboard, mouse, gamepads with rumble, and the debug keyboard for the console. |
| Files | The Win32 file functions and the MSVC file functions on POSIX, with the translation of Xbox paths. |
@@ -608,11 +712,11 @@ Other changes:
| `networking/`, `game/`, `interface/`, `bungie_net/network/` and the pools of objects, effects and sounds | The system link limits and the memory for them. |
| `game/`, `objects/`, `units/`, `networking/` | The distributed netcode. Refer to `NETCODE.md`. |
| `cache/cache_files.c` | When a map's tags load and unload, the port finds the bitmaps that the high-res HUD replaces (`game/hud_hires_tags.c`), and adds the tags of the menus to the menus' map (`game/menu_tags.c`). |
| `interface/ui_widget.c`, `interface/ui_widget_event_handler_functions.c`, `interface/ui_widget_game_data_input_functions.c` | The main menu is the PC version's from `port/assets/menus` (`display.menus`); the menus' widgets can call the port's functions (`game/menu_functions.c`) and send the PC version's custom activation event; the widgets' memory is 256 KB, not 16 KB. |
| `interface/ui_widget.c`, `interface/ui_widget_event_handler_functions.c`, `interface/ui_widget_game_data_input_functions.c` | The main menu is the PC version's from `port/assets/menus` (`display.menus`); the menus' widgets can call the port's functions (`game/menu_functions.c`) and send the PC version's custom activation event; the widgets' memory is 256 KB, not 16 KB; the main menu and Multiplayer clear co-op's controllers, so that a gamepad going back to controller 1 is not a controller unplugged; the lobby's split screen players leave alone, and one who quits in game is not joined to the next game (`interface/player_ui.c`). |
| `input/input_abstraction.c`, `game/player_control.c`, `game/players.c`, `game/player_queues_new.c`, `units/units.h` | The keyboard and mouse's actions (`src/xinput_sdl.c`, `include/halo_keyboard.h`) join controller 1's game controls; their reload key reloads on its own, and their action key only acts (a control flag of the port's, sent with the player's action, stops the reload the controller's X falls back to). |
| `sound/sound_manager.c`, `interface/hud.c`, `game/game_engine.c` | The music's and the other sounds' volumes; the HUD's and the scoreboard's settings are read again when Settings changes them. |
| `interface/hud.c` | In multiplayer, players' names are drawn above their heads (`display.player_names`, `display.player_name_scale`). |
| `rasterizer/rasterizer_text.c`, `text/draw_string.c` | Text is drawn from an atlas of the fonts' glyphs, rasterized at the display's resolution (`src/text_hires.c`), when the font has every character of the string. Text can be drawn scaled about a point (`rasterizer_text_set_scale`), as the players' names are. Each glyph's advance is centred on the font tag character's, so the layout is the same, and a glyph is cut at a text box only where the font tag's character visibly was. |
| `rasterizer/rasterizer_text.c`, `text/draw_string.c` | Text is drawn from an atlas of the fonts' glyphs, rasterized at the resolution the game draws at (`src/text_hires.c`), when the font has every character of the string. Text can be drawn scaled about a point (`rasterizer_text_set_scale`), as the players' names are. Each glyph's advance is centred on the font tag character's, so the layout is the same, and a glyph is cut at a text box only where the font tag's character visibly was. |
The x86 inline assembly of the game is replaced by C. Thus the compiler
can optimize that code for each processor:
+1332 -40
View File
File diff suppressed because it is too large. Load diff
+523
View File
@@ -0,0 +1,523 @@
/*
COOP_ENEMIES.C
Network co-op's extra enemies: Server Setup's EXTRA ENEMIES
(network.coop_enemies_mode). PER PLAYER (network.coop_enemies, a
percentage): for each player past the first, each squad of the players'
enemies that a level places (encounters.c's encounter_create) gets that
much of its count more; at 100%, two players meet twice the squad, four
players four times it. STATIC MULTIPLIER (network.coop_enemies_multiplier):
each squad is that many times as large, for any number of players. The
extra enemies stand in rings about the squad's starting locations, on
open ground, so they do not start inside each other.
A squad a script loads into a dropship (vehicle_load_magic) can be larger
than the dropship's seats. The riders left without a seat are erased, and
kept: once the dropship's own riders get out (vehicle_unload, or any other
way), they are placed beside those riders, a few ticks apart, and drop and
fight as they do. A dropship gone first takes them with it.
Only the host runs the AI, so all of this is the host's.
*/
#include "cseries.h"
#include "ai/actor_placement.h"
#include "ai/actors.h"
#include "ai/ai_scenario_definitions.h"
#include "ai/encounters.h"
#include "game/game.h"
#include "game/game_allegiance.h"
#include "game/players.h"
#include "networking/network_game_globals.h"
#include "networking/network_game_manager.h"
#include "objects/objects.h"
#include "physics/collisions.h"
#include "scenario/scenario.h"
#include "scenario/scenario_definitions.h"
#include "units/units.h"
#include "units/unit_definitions.h"
#include "coop_enemies.h"
#include "network_coop.h"
#include <math.h>
#include <string.h>
/* port_config.c's */
long config_integer(char const *name);
char const *config_string(char const *name);
/* ---------- constants */
enum
{
/* the actors a level keeps for its own placements, which the extra
enemies never take: as many as the Xbox's whole pool */
COOP_ENEMIES_LEVEL_ACTORS = 256,
/* EXTRA ENEMIES' amounts, as Server Setup has them: 25 to 200% per
player, or 2 to 32 times (none is its NONE) */
COOP_ENEMIES_MINIMUM_PERCENT = 25,
COOP_ENEMIES_MAXIMUM_PERCENT = 200,
COOP_ENEMIES_MINIMUM_MULTIPLIER = 2,
COOP_ENEMIES_MAXIMUM_MULTIPLIER = 32,
/* the places tried for an extra enemy, a ring further out each */
SPREAD_ATTEMPTS = 8,
SPREAD_PLACES_PER_RING = 6,
MAXIMUM_RIDING_VEHICLES = 32,
MAXIMUM_SEATED_RIDERS = 16,
MAXIMUM_KEPT_RIDERS = 512,
/* a kept rider placed every this many ticks, as the seated ones
jumped out */
RIDER_RELEASE_TICKS = 4,
};
/* the rings' spacing, and the height over the ground the way to a place is
looked along, and the ground looked for below it */
#define SPREAD_SPACING 0.8f
#define SPREAD_STEP_HEIGHT 0.6f
#define SPREAD_GROUND_DEPTH 2.0f
/* a kept rider's place beside a rider who got out, each a little apart */
#define RIDER_SPACING 0.5f
/* EXTRA ENEMIES' choices (network.coop_enemies_mode's values) */
enum
{
_coop_enemies_none,
_coop_enemies_per_player,
_coop_enemies_multiplier,
};
/* ---------- structures */
/* a vehicle a script loaded riders into: its seated ones, and whether they
have begun to get out */
struct coop_riding_vehicle
{
long vehicle_index;
long seated_unit_indices[MAXIMUM_SEATED_RIDERS];
short seat_indices[MAXIMUM_SEATED_RIDERS];
short seated_count;
boolean releasing;
short released_count;
long next_release_time;
};
/* a rider left without a seat, to place once its vehicle's get out */
struct coop_kept_rider
{
long vehicle_index;
long variant_definition_index;
long encounter_index;
short squad_index;
};
/* ---------- globals */
static struct
{
/* EXTRA ENEMIES, as the game began with it: its choice, and the amount
of PER PLAYER (a percentage) and of STATIC MULTIPLIER */
short mode;
short percent;
short multiplier;
struct coop_riding_vehicle vehicles[MAXIMUM_RIDING_VEHICLES];
short vehicle_count;
struct coop_kept_rider riders[MAXIMUM_KEPT_RIDERS];
short rider_count;
} coop_enemies;
/* ---------- private code */
static boolean coop_enemies_host(
void)
{
return game_connection() == _game_connection_network_server && network_coop_active();
}
/* whether this game has extra enemies (it is a co-op host's, with some
chosen) */
static boolean coop_enemies_on(
void)
{
return coop_enemies.mode != _coop_enemies_none && coop_enemies_host();
}
/* the players in the game, every machine's: the network game's (a level
places its first enemies before the players' units are made, as it loads:
game_initialize_for_new_map) */
static short coop_enemies_player_count(
void)
{
struct network_game *game = network_game_get_game();
short count = 0;
short index;
for (index = 0; game && index < HALO_PORT_MAXIMUM_NETWORK_PLAYERS; index++)
{
if (network_player_is_valid(&game->players[index]))
count++;
}
return count;
}
/* whether the way from a to b is open (no structure between them) */
static boolean coop_enemies_open(
real_point3d const *a,
real_point3d const *b)
{
struct collision_result collision;
real_vector3d vector;
vector.i = b->x - a->x;
vector.j = b->y - a->y;
vector.k = b->z - a->z;
return !collision_test_vector(FLAG(_collision_test_structure_bit) | FLAG(_collision_test_front_facing_surfaces_bit) |
FLAG(_collision_test_back_facing_surfaces_bit), a, &vector, NONE, &collision);
}
/* the ground below a point, within SPREAD_GROUND_DEPTH of it */
static boolean coop_enemies_ground(
real_point3d const *point,
real_point3d *ground)
{
struct collision_result collision;
real_vector3d vector = { 0.0f, 0.0f, -(SPREAD_STEP_HEIGHT + SPREAD_GROUND_DEPTH) };
if (!collision_test_vector(FLAG(_collision_test_structure_bit) | FLAG(_collision_test_front_facing_surfaces_bit),
point, &vector, NONE, &collision))
{
return FALSE;
}
*ground = collision.point;
return TRUE;
}
static struct coop_riding_vehicle *coop_enemies_riding_vehicle(
long vehicle_index,
boolean create)
{
short index;
for (index = 0; index < coop_enemies.vehicle_count; index++)
{
if (coop_enemies.vehicles[index].vehicle_index == vehicle_index)
return &coop_enemies.vehicles[index];
}
if (!create || coop_enemies.vehicle_count >= MAXIMUM_RIDING_VEHICLES)
return NULL;
csmemset(&coop_enemies.vehicles[coop_enemies.vehicle_count], 0, sizeof(coop_enemies.vehicles[0]));
coop_enemies.vehicles[coop_enemies.vehicle_count].vehicle_index = vehicle_index;
return &coop_enemies.vehicles[coop_enemies.vehicle_count++];
}
/* the riders kept for a vehicle forgotten, and the vehicle with them */
static void coop_enemies_forget_vehicle(
short vehicle_number)
{
long vehicle_index = coop_enemies.vehicles[vehicle_number].vehicle_index;
short index, kept = 0;
for (index = 0; index < coop_enemies.rider_count; index++)
{
if (coop_enemies.riders[index].vehicle_index != vehicle_index)
coop_enemies.riders[kept++] = coop_enemies.riders[index];
}
coop_enemies.rider_count = kept;
coop_enemies.vehicles[vehicle_number] = coop_enemies.vehicles[--coop_enemies.vehicle_count];
}
/* whether a vehicle's seated riders have begun to get out: one alive and
out of it (one killed in its seat is not getting out) */
static boolean coop_enemies_riders_getting_out(
struct coop_riding_vehicle const *vehicle)
{
short index;
for (index = 0; index < vehicle->seated_count; index++)
{
struct object_datum *unit = object_try_and_get_and_verify_type(vehicle->seated_unit_indices[index],
_object_mask_unit);
if (unit && !TEST_FLAG(unit->object.damage_flags, _object_dead_bit) &&
unit->object.parent_object_index != vehicle->vehicle_index)
{
return TRUE;
}
}
return FALSE;
}
/* where a vehicle's `number`th kept rider is placed: beside one of the
riders who got out of it (where it is now: out of the vehicle, in the
open), a ring further about them each round; else at a seat's marker, else
the vehicle's place */
static void coop_enemies_rider_place(
struct coop_riding_vehicle const *vehicle,
short number,
real_point3d *position,
real *facing)
{
struct object_datum *object = object_get(vehicle->vehicle_index);
struct unit_definition *definition = unit_definition_get(object->definition_index);
long out_unit_indices[MAXIMUM_SEATED_RIDERS];
short out_count = 0;
short index, round;
real angle;
*position = object->object.position;
*facing = (real)atan2(object->object.forward.j, object->object.forward.i);
for (index = 0; index < vehicle->seated_count; index++)
{
struct object_datum *unit = object_try_and_get_and_verify_type(vehicle->seated_unit_indices[index],
_object_mask_unit);
if (unit && !TEST_FLAG(unit->object.damage_flags, _object_dead_bit) &&
unit->object.parent_object_index != vehicle->vehicle_index)
{
out_unit_indices[out_count++] = vehicle->seated_unit_indices[index];
}
}
if (out_count > 0)
{
*position = object_get(out_unit_indices[number % out_count])->object.position;
round = (short)(number / out_count);
}
else
{
struct object_marker marker;
round = number;
if (vehicle->seated_count > 0 && VALID_INDEX(vehicle->seat_indices[0], definition->unit.seats.count))
{
struct unit_seat *seat = TAG_BLOCK_GET_ELEMENT(&definition->unit.seats, vehicle->seat_indices[0],
struct unit_seat);
if (seat->marker_name[0] &&
object_get_marker_by_name(vehicle->vehicle_index, seat->marker_name, &marker, 1) > 0)
{
*position = marker.matrix.position;
}
}
}
/* (never on the rider's own place: a ring about it, further each round) */
angle = (real)number * (_pi * 2.0f / SPREAD_PLACES_PER_RING);
position->x += (real)cos(angle) * RIDER_SPACING * (real)(round / SPREAD_PLACES_PER_RING + 1);
position->y += (real)sin(angle) * RIDER_SPACING * (real)(round / SPREAD_PLACES_PER_RING + 1);
}
/* ---------- public code */
void coop_enemies_new_game(
void)
{
char const *mode = config_string("network.coop_enemies_mode");
csmemset(&coop_enemies, 0, sizeof(coop_enemies));
/* (an amount past Server Setup's, as it shows it: its nearest choice's
end) */
coop_enemies.percent = (short)PIN(config_integer("network.coop_enemies"), COOP_ENEMIES_MINIMUM_PERCENT,
COOP_ENEMIES_MAXIMUM_PERCENT);
coop_enemies.multiplier = (short)PIN(config_integer("network.coop_enemies_multiplier"),
COOP_ENEMIES_MINIMUM_MULTIPLIER, COOP_ENEMIES_MAXIMUM_MULTIPLIER);
coop_enemies.mode = !strcmp(mode, "per_player") ? _coop_enemies_per_player :
!strcmp(mode, "multiplier") ? _coop_enemies_multiplier : _coop_enemies_none;
}
void coop_enemies_reset(
void)
{
coop_enemies.vehicle_count = 0;
coop_enemies.rider_count = 0;
}
short coop_enemies_extra_count(
long encounter_index,
short count)
{
struct encounter_datum *encounter;
long extra, room;
short players;
if (count <= 0 || !coop_enemies_on())
return 0;
encounter = encounter_get(encounter_index);
if (!game_team_is_enemy(_game_team_player, encounter->team_index))
return 0;
if (coop_enemies.mode == _coop_enemies_multiplier)
extra = (long)count * (coop_enemies.multiplier - 1);
else
{
players = coop_enemies_player_count();
if (players <= 1)
return 0;
extra = ((long)count * coop_enemies.percent * (players - 1) + 50) / 100;
}
room = MAXIMUM_ACTORS - COOP_ENEMIES_LEVEL_ACTORS - actor_data->actual_count;
return (short)PIN(extra, 0, MAX(room, 0));
}
boolean coop_enemies_spread_position(
real_point3d const *origin,
short number,
real_point3d *position)
{
real_point3d from = *origin;
short place = (short)((number - 1) % SPREAD_PLACES_PER_RING);
short ring = (short)((number - 1) / SPREAD_PLACES_PER_RING);
short attempt;
from.z += SPREAD_STEP_HEIGHT;
for (attempt = 0; attempt < SPREAD_ATTEMPTS; attempt++, ring++)
{
/* (each ring turned half a place from the last, so its places fall
between the last's) */
real angle = ((real)place + 0.5f * (real)(ring % 2)) * (_pi * 2.0f / SPREAD_PLACES_PER_RING);
real radius = SPREAD_SPACING * (real)(ring + 1);
real_point3d to = from;
to.x += (real)cos(angle) * radius;
to.y += (real)sin(angle) * radius;
if (coop_enemies_open(&from, &to) && coop_enemies_ground(&to, position))
return TRUE;
}
return FALSE;
}
void coop_enemies_rider_seated(
long vehicle_index,
long unit_index)
{
struct coop_riding_vehicle *vehicle;
struct unit_datum *unit;
if (!coop_enemies_on())
return;
vehicle = coop_enemies_riding_vehicle(vehicle_index, TRUE);
unit = unit_get(unit_index);
if (!vehicle)
return;
/* (a vehicle loaded again: the riders that got out of it before are not
this load's) */
{
short index, kept = 0;
for (index = 0; index < vehicle->seated_count; index++)
{
struct object_datum *seated = object_try_and_get_and_verify_type(vehicle->seated_unit_indices[index],
_object_mask_unit);
if (seated && seated->object.parent_object_index == vehicle_index)
{
vehicle->seated_unit_indices[kept] = vehicle->seated_unit_indices[index];
vehicle->seat_indices[kept++] = vehicle->seat_indices[index];
}
}
vehicle->seated_count = kept;
}
if (vehicle->seated_count >= MAXIMUM_SEATED_RIDERS)
return;
vehicle->seated_unit_indices[vehicle->seated_count] = unit_index;
vehicle->seat_indices[vehicle->seated_count] = unit->unit.parent_seat_index;
vehicle->seated_count++;
/* (a vehicle loaded again, after its riders got out: they get out again) */
vehicle->releasing = FALSE;
}
boolean coop_enemies_rider_unseated(
long vehicle_index,
long unit_index)
{
struct unit_datum *unit;
struct actor_datum *actor;
struct coop_kept_rider *rider;
struct coop_riding_vehicle *vehicle;
if (!coop_enemies_on() || coop_enemies.rider_count >= MAXIMUM_KEPT_RIDERS)
return FALSE;
unit = unit_get(unit_index);
vehicle = coop_enemies_riding_vehicle(vehicle_index, FALSE);
/* (kept only for a vehicle with riders seated, whose getting out places
it: one of a load that seated nobody is left where it is) */
if (unit->object.type != _object_type_biped || unit->unit.actor_index == NONE || !vehicle ||
vehicle->seated_count == 0)
{
return FALSE;
}
actor = actor_get(unit->unit.actor_index);
if (actor->meta.swarm || actor->meta.encounter_index == NONE ||
!game_team_is_enemy(_game_team_player, encounter_get(actor->meta.encounter_index)->team_index))
{
return FALSE;
}
rider = &coop_enemies.riders[coop_enemies.rider_count++];
rider->vehicle_index = vehicle_index;
rider->variant_definition_index = actor->meta.variant_definition_index;
rider->encounter_index = actor->meta.encounter_index;
rider->squad_index = actor->meta.squad_index;
return TRUE;
}
void coop_enemies_update(
void)
{
long now = game_time_get();
short vehicle_number;
if (!coop_enemies_host())
return;
for (vehicle_number = coop_enemies.vehicle_count - 1; vehicle_number >= 0; vehicle_number--)
{
struct coop_riding_vehicle *vehicle = &coop_enemies.vehicles[vehicle_number];
struct object_datum *object = object_try_and_get_and_verify_type(vehicle->vehicle_index, _object_mask_unit);
short index;
/* (the vehicle's next kept rider) */
for (index = 0; index < coop_enemies.rider_count; index++)
{
if (coop_enemies.riders[index].vehicle_index == vehicle->vehicle_index)
break;
}
/* (a vehicle gone, or destroyed, takes its kept riders with it; one
with none kept, every one loaded seated or all placed, is done with) */
if (!object || TEST_FLAG(object->object.damage_flags, _object_dead_bit) || index >= coop_enemies.rider_count)
{
coop_enemies_forget_vehicle(vehicle_number);
continue;
}
if (!vehicle->releasing)
{
if (!coop_enemies_riders_getting_out(vehicle))
continue;
vehicle->releasing = TRUE;
vehicle->released_count = 0;
vehicle->next_release_time = now;
}
if (now < vehicle->next_release_time)
continue;
{
struct coop_kept_rider rider = coop_enemies.riders[index];
struct encounter_definition *encounter_definition;
struct squad_definition *squad_definition;
struct actor_starting_location location;
coop_enemies.riders[index] = coop_enemies.riders[--coop_enemies.rider_count];
encounter_definition = TAG_BLOCK_GET_ELEMENT(&global_scenario_get()->ai_encounters,
DATUM_INDEX_TO_ABSOLUTE_INDEX(rider.encounter_index), struct encounter_definition);
squad_definition = TAG_BLOCK_GET_ELEMENT(&encounter_definition->squads, rider.squad_index,
struct squad_definition);
/* (as the squad's: its states, no command list of a starting
location's) */
csmemset(&location, 0, sizeof(location));
coop_enemies_rider_place(vehicle, vehicle->released_count++, &location.position, &location.facing);
location.cluster_index = NONE;
location.noncombat_sequence_id = NONE;
location.default_state = squad_definition->default_state;
location.initial_state = squad_definition->initial_state;
location.actor_variant_index = NONE;
location.command_list_index = NONE;
actor_place(rider.variant_definition_index, rider.encounter_index, rider.squad_index, &location, FALSE, 0);
encounter_update_status(rider.encounter_index);
}
vehicle->next_release_time = now + RIDER_RELEASE_TICKS;
}
}
+48
View File
@@ -0,0 +1,48 @@
/*
COOP_ENEMIES.H
Network co-op's extra enemies, for its players (coop_enemies.c).
*/
#ifndef __COOP_ENEMIES_H
#define __COOP_ENEMIES_H
/* network_coop.c: a game begins (its EXTRA ENEMIES read), or the host's
game state went back (a cutscene skipped): the dropships' riders kept are
forgotten */
void coop_enemies_new_game(
void);
void coop_enemies_reset(
void);
/* encounters.c: how many enemies more a squad placed with `count` gets
(none but on a co-op host, for an encounter of the players' enemies) */
short coop_enemies_extra_count(
long encounter_index,
short count);
/* encounters.c: the place of a squad's `number`th extra enemy (from 1) at
its starting location `origin`: rings about it, on open ground; FALSE if
none is (the starting location itself then) */
boolean coop_enemies_spread_position(
real_point3d const *origin,
short number,
real_point3d *position);
/* units.c's vehicle_scripting_load_magic: a rider seated, and one left
without a seat (the vehicle's seats taken: an extra enemy), which is kept,
off the map, until the vehicle's riders get out (TRUE: kept, the caller
erases it) */
void coop_enemies_rider_seated(
long vehicle_index,
long unit_index);
boolean coop_enemies_rider_unseated(
long vehicle_index,
long unit_index);
/* network_coop.c, after each of the host's ticks: the riders kept placed
at their vehicle's seats once its own riders get out */
void coop_enemies_update(
void);
#endif
+285
View File
@@ -0,0 +1,285 @@
/*
COOP_SPECTATE.C
Spectating in network co-op. A dead player watches a living teammate
until they respawn (players.c respawns them beside a teammate once it is
safe). The campaign's dead camera would watch the body; instead this
follows a teammate from behind, and A (jump on the keyboard) switches to
the next one. director.c and hud.c call in here.
It also draws the line telling players about the vote to skip a cutscene
(network_coop.c counts the votes).
*/
#include "cseries.h"
#include "camera/dead_camera.h"
#include "game/game.h"
#include "game/game_engine.h"
#include "game/players.h"
#include "input/input.h"
#include "interface/hud_messaging.h"
#include "objects/objects.h"
#include "rasterizer/rasterizer.h"
#include "render/render.h"
#include "text/draw_string.h"
#include "text/font_group.h"
#include "text/unicode.h"
#include "units/units.h"
#include "coop_spectate.h"
#include "network_coop.h"
#include <math.h>
/* ---------- constants */
/* camera distance behind the unit, pitch (radians), and how much of the
turn toward the unit's facing it makes each frame */
#define SPECTATE_DISTANCE 3.5f
#define SPECTATE_PITCH -0.3f
#define SPECTATE_TURN 0.15f
/* a passenger (riding a Pelican) is watched from in front of them, above
and looking down, so the camera stays inside the vehicle; a wide view (the
observer allows up to 90 degrees) takes in all of them from that close */
#define SPECTATE_PASSENGER_DISTANCE 1.0f
#define SPECTATE_PASSENGER_PITCH -0.5f
#define SPECTATE_PASSENGER_FIELD_OF_VIEW DEGREES_TO_RADIANS(85.0f)
/* field of view for every other spectate view (dead_camera.c's default) */
#define SPECTATE_FIELD_OF_VIEW DEGREES_TO_RADIANS(70.0f)
/* a teammate the scripts hold (Pillar of Autumn's cryo tube) is watched from
in front, far enough back to see all of what holds them */
#define SPECTATE_HELD_DISTANCE 2.0f
#define SPECTATE_HELD_PITCH -0.1f
/* ---------- globals */
/* the player each local player is watching, or NONE */
static long coop_spectate_watched[MAXIMUM_LOCAL_PLAYERS] = { NONE, NONE, NONE, NONE };
/* input_abstraction.c: how many ticks the keyboard's jump key has been held */
byte input_abstraction_port_accept(short controller_index);
/* ---------- private code */
/* The next living player after `after` (or the first, if `after` is NONE),
skipping `self` and wrapping around. NONE if nobody else is alive. */
static long next_living_player(long self, long after)
{
struct data_iterator iterator;
struct player_datum *player;
long first = NONE;
boolean passed = after == NONE;
data_iterator_new(&iterator, player_data);
while ((player = data_iterator_next(&iterator)) != NULL)
{
if (iterator.datum_index == after)
{
passed = TRUE;
continue;
}
if (iterator.datum_index == self || player->unit_index == NONE)
continue;
if (passed)
return iterator.datum_index;
if (first == NONE)
first = iterator.datum_index;
}
return first;
}
/* Returns TRUE once per press of A (or jump on the keyboard), however long
it is held. The buttons count ticks, and one tick can span several frames,
so testing "held" alone would switch more than once. */
static boolean next_pressed(short controller_index)
{
static boolean held[MAXIMUM_GAMEPADS];
struct gamepad_state const *gamepad;
boolean down;
boolean pressed;
if (controller_index < 0 || controller_index >= MAXIMUM_GAMEPADS)
return FALSE;
gamepad = input_get_gamepad_state(controller_index);
down = (gamepad && gamepad->buttons[FIRST_GAMEPAD_ANALOG_BUTTON + _gamepad_analog_button_a] > 0) ||
input_abstraction_port_accept(controller_index) > 0;
pressed = down && !held[controller_index];
held[controller_index] = down;
return pressed;
}
/* whether the unit rides in a vehicle it isn't driving */
static boolean unit_is_passenger(
long unit_index)
{
long vehicle_index = object_get(unit_index)->object.parent_object_index;
return vehicle_index != NONE && object_try_and_get_and_verify_type(vehicle_index, _object_mask_unit) &&
unit_get(vehicle_index)->unit.driver_object_index != unit_index;
}
/* ---------- public code */
boolean coop_spectating(
void)
{
return network_coop_active();
}
long coop_spectate_unit(
short local_player_index)
{
long self = local_player_get_player_index(local_player_index);
long *watched = &coop_spectate_watched[local_player_index];
struct player_datum *player;
boolean next;
if (self == NONE)
return NONE;
player = player_get(self);
/* checked every frame so a press is never missed or counted twice */
next = next_pressed(player->network_player_data.controller_index);
/* alive: keep `watched`, so the next death starts on the same teammate */
if (player->unit_index != NONE)
return NONE;
if (*watched == NONE || !player_try_and_get(*watched) || player_get(*watched)->unit_index == NONE || next)
{
*watched = next_living_player(self, *watched);
}
return *watched != NONE ? player_get(*watched)->unit_index : NONE;
}
boolean coop_spectate_watching_rider(
short local_player_index)
{
long self = local_player_get_player_index(local_player_index);
long watched = coop_spectate_watched[local_player_index];
long unit_index;
long driver_index;
if (self == NONE || player_get(self)->unit_index != NONE)
return FALSE;
/* the scripted camera may have been running since before this player
died, so nobody has been picked to watch yet */
if (watched == NONE || !player_try_and_get(watched) || player_get(watched)->unit_index == NONE)
watched = next_living_player(self, NONE);
unit_index = watched != NONE ? player_get(watched)->unit_index : NONE;
if (unit_index == NONE || !unit_is_passenger(unit_index))
return FALSE;
driver_index = unit_get(object_get(unit_index)->object.parent_object_index)->unit.driver_object_index;
return driver_index == NONE || unit_get(driver_index)->unit.player_index == NONE;
}
boolean coop_spectate_nothing_to_watch(
short local_player_index)
{
long self = local_player_get_player_index(local_player_index);
return self != NONE && player_get(self)->unit_index == NONE && next_living_player(self, NONE) == NONE;
}
void coop_spectate_camera(
struct dead_camera *camera)
{
struct object_datum *unit = camera->unit_index != NONE ? object_try_and_get(camera->unit_index) : NULL;
real yaw, turn;
if (!unit)
return;
yaw = (real)atan2(unit->object.forward.j, unit->object.forward.i);
if (unit_is_passenger(camera->unit_index))
{
/* fixed in front of the seat, turning with the vehicle */
camera->facing.yaw = yaw + _pi;
camera->facing.pitch = SPECTATE_PASSENGER_PITCH;
camera->distance = SPECTATE_PASSENGER_DISTANCE;
camera->field_of_view = SPECTATE_PASSENGER_FIELD_OF_VIEW;
return;
}
camera->field_of_view = SPECTATE_FIELD_OF_VIEW;
if (!player_input_enabled())
{
camera->facing.yaw = yaw + _pi;
camera->facing.pitch = SPECTATE_HELD_PITCH;
camera->distance = SPECTATE_HELD_DISTANCE;
return;
}
/* ease the camera round behind the unit */
turn = yaw - camera->facing.yaw;
while (turn > _pi)
turn -= 2.0f * _pi;
while (turn < -_pi)
turn += 2.0f * _pi;
camera->facing.yaw += turn * SPECTATE_TURN;
camera->facing.pitch = SPECTATE_PITCH;
camera->distance = SPECTATE_DISTANCE;
}
/* centred text near the bottom of the screen, in the HUD's font */
static void draw_bottom_text(
wchar_t const *text)
{
long font_index = hud_get_font_index();
struct font_header *font;
real_argb_color color = *global_real_argb_white;
rectangle2d bounds;
short height;
if (font_index == NONE)
return;
font = font_definition_get(font_index);
height = (short)(font->ascending_height + font->descending_height);
bounds = render.camera.window_bounds;
bounds.y0 = (short)(bounds.y1 - 3 * height - 24);
bounds.y1 = (short)(bounds.y1 - 24);
/* draw mode 2: centered */
draw_string_set_draw_mode(font_index, NONE, 2, 0, &color);
rasterizer_draw_unicode_string(&bounds, NULL, NULL, 0, text);
}
void coop_spectate_draw(
short local_player_index)
{
long watched = coop_spectate_watched[local_player_index];
wchar_t text[96];
wchar_t const *hint;
/* nobody to watch yet (still joining): network_coop.c shows the host's
view from behind instead */
if (watched == NONE || !player_try_and_get(watched))
{
if (coop_spectate_nothing_to_watch(local_player_index))
draw_bottom_text(L"JOINING THE GAME\r\nYou spawn beside a teammate once it is safe");
return;
}
if (!players_coop_waiting_to_start(local_player_get_player_index(local_player_index)))
hint = L"You come back beside them once it is safe";
else
hint = L"You join them when they're on foot";
usnprintf(text, NUMBEROF(text) - 1, L"SPECTATING %.12s (A: NEXT)\r\n%s", player_get(watched)->name, hint);
text[NUMBEROF(text) - 1] = 0;
draw_bottom_text(text);
}
void coop_skip_vote_draw(
short local_player_index)
{
short votes, voters;
boolean voted;
wchar_t text[96];
/* once, for the first local player */
if (local_player_index != local_player_get_next(NONE) || !network_coop_skip_vote_status(&votes, &voters, &voted))
return;
if (voted)
usnprintf(text, NUMBEROF(text) - 1, L"VOTED TO SKIP %d OF %d", votes, voters);
else
usnprintf(text, NUMBEROF(text) - 1, L"PRESS SPACE OR A TO VOTE TO SKIP %d OF %d", votes, voters);
text[NUMBEROF(text) - 1] = 0;
draw_bottom_text(text);
}
+45
View File
@@ -0,0 +1,45 @@
/*
COOP_SPECTATE.H
Spectating in network co-op, and the cutscene skip vote's line
(coop_spectate.c).
*/
#ifndef __COOP_SPECTATE_H
#define __COOP_SPECTATE_H
struct dead_camera;
/* whether this is network co-op: a network game with no game engine (a campaign map) */
boolean coop_spectating(
void);
/* the unit a dead local player watches (A switches teammate), or NONE if
the player is alive or nobody else is */
long coop_spectate_unit(
short local_player_index);
/* TRUE if the teammate this local player is spectating (while dead or not
yet spawned) rides in an AI-driven vehicle, such as an insertion Pelican.
network_coop.c then shows that seat instead of the scripted camera. */
boolean coop_spectate_watching_rider(
short local_player_index);
/* whether a local player has nothing to look at: no unit of its own and
no living teammate to watch (network_coop.c shows it the host's view) */
boolean coop_spectate_nothing_to_watch(
short local_player_index);
/* keeps the dead camera behind the watched unit as it turns */
void coop_spectate_camera(
struct dead_camera *camera);
/* the HUD line saying who a dead local player is watching */
void coop_spectate_draw(
short local_player_index);
/* during a skippable cutscene in network co-op, the vote count and how to vote */
void coop_skip_vote_draw(
short local_player_index);
#endif
File diff suppressed because it is too large. Load diff
+389 -16
View File
@@ -23,6 +23,11 @@ game keeps its own menus.
The tag table cannot grow where it is (the tags' names follow it), so it
is copied, with ours after it; every existing tag keeps its index. All of it
is let go in scenario_tags_unload, before the next map's tags load.
A multiplayer map gets them too, for its in-game pause menu's SETTINGS
(pause_patch): there the map's tags they name that it has not (ui.map's
pictures, sounds and screens) are none, a missing picture drawn blank, and
no screen pauses the game (a network game's clock runs on).
*/
#include "cseries.h"
@@ -40,6 +45,11 @@ is let go in scenario_tags_unload, before the next map's tags load.
/* the platform layer's (port/linux/src) */
void platform_log(char const *format, ...);
char const *config_string(char const *name);
int platform_display_resolutions(long *widths, long *heights, int maximum);
int platform_window_sizes(long *widths, long *heights, int maximum);
/* the game's network server (this machine hosts: network_game_globals.c) */
void *global_network_game_server_get(void);
/* cache_files.c's (port) */
void *cache_files_tag_instances(long *count);
@@ -59,6 +69,13 @@ boolean pc_menu_tag(long tag_index);
/* ---------- constants */
#define PC_MENU_TAG_PREFIX "pc\\"
/* the multiplayer maps' widget collection, whose pause screens pause_patch
adds to */
#define MULTIPLAYER_COLLECTION "ui\\shell\\multiplayer"
/* the tags pause_patch adds: two buttons and their texts */
#define PAUSE_PATCH_TAGS 4
/* what a frame of ui.map's is drawn as in a game map, which has not got it */
#define BLANK_PNG "ce/port/blank__0.png"
#define UI_WIDGET_DEFINITION_TAG 'DeLa'
#define UNICODE_STRING_LIST_TAG 'ustr'
#define FONT_TAG 'font'
@@ -326,6 +343,12 @@ static char const *const port_function_names[] =
"mp level select", "mp profiles list initialize", "mp profiles list dispose", "mp profile set for game",
"port lobby preview join",
"port setup edit",
"port map list back",
"port pause end game",
"port coop begin", "port coop player 2 list initialize", "port coop player 2",
"port lobby open", "port lobby add player", "port lobby join", "port lobby leave",
"port lobby player list initialize", "port lobby player choose",
"port lobby preview add", "port lobby preview leave",
/* (the gametype editor's: the Xbox's walk their rows by place, which the
PC version's screens changed) */
"mp profile begin editing", "mp profile save changes", "request del playlist profile", "final del playlist profile",
@@ -335,6 +358,9 @@ static char const *const port_function_names[] =
"mp profile init indicator opts", "mp profile set ctf rules", "mp profile set koth rules",
"mp profile set slayer rules", "mp profile set oddball rules", "mp profile set racing rules",
"mp profile set player options", "mp profile set item options", "mp profile set indicator opts",
/* (Settings' OK: the Xbox's fails when the profile has no changes, the
settings' screens having written theirs to config.toml) */
"player profile save changes",
};
/* the PC version's game data functions that the Xbox's have not, from
@@ -384,6 +410,9 @@ static struct
long *text_tags;
long *spinner_tags;
boolean failed;
/* a multiplayer map's build (the pause menu's SETTINGS): what the map
has not got is none, not a failure */
boolean game_map;
} build;
/* ---------- private code */
@@ -497,7 +526,8 @@ static long map_tag(long group_tag, char const *name, char const *file, long lin
{
long index = tag_loaded(group_tag, name);
if (index == NONE)
/* (a game map has few of ui.map's: those are none) */
if (index == NONE && !build.game_map)
problem(file, line, "the map has no tag", name);
return index;
}
@@ -674,6 +704,41 @@ static long split(char const *text, char const **pieces)
return count;
}
/* a spinner's strings, or its values, split: its own, but Video Setup's
sizes are the display's (sdl_platform.c), shown "1920 x 1080" and set
"1920x1080": its resolutions after Resolution's own (NATIVE), and the
window sizes that fit it in place of Window Size's own */
static long spinner_split(struct halo_menu_widget const *widget, boolean values, char const **pieces)
{
long count = split(values ? widget->values : widget->strings, pieces);
long widths[MAXIMUM_STRINGS], heights[MAXIMUM_STRINGS];
long added, index;
if (widget->setting && !strcmp(widget->setting, "display.resolution"))
added = platform_display_resolutions(widths, heights, (int)(MAXIMUM_STRINGS - count));
else if (widget->setting && !strcmp(widget->setting, "display.window_size"))
{
added = platform_window_sizes(widths, heights, MAXIMUM_STRINGS);
if (added > 0)
count = 0;
}
else
return count;
for (index = 0; index < added; index++)
{
char text[32];
char *piece;
snprintf(text, sizeof(text), values ? "%ldx%ld" : "%ld x %ld", widths[index], heights[index]);
piece = allocate((long)strlen(text) + 1);
if (!piece)
break;
strcpy(piece, text);
pieces[count++] = piece;
}
return count;
}
static void *bitmap_build(struct halo_menu_bitmap const *source, long tag_index)
{
struct bitmap_group *group = allocate(sizeof(struct bitmap_group));
@@ -698,10 +763,18 @@ static void *bitmap_build(struct halo_menu_bitmap const *source, long tag_index)
{
struct halo_menu_frame const *data = &build.menus->frames[source->first_frame + frame];
struct bitmap_data *bitmap = &bitmaps[frame];
char const *png = data->png;
long width = data->width, height = data->height;
/* (a frame of the map's: a copy of its bitmap, which the texture cache
loads from the map as its own) */
if (data->map)
loads from the map as its own; in a game map that has not got it,
nothing) */
if (data->map && build.game_map && tag_loaded(BITMAP_GROUP_TAG, data->map) == NONE)
{
png = BLANK_PNG;
width = height = PLACEHOLDER_SIZE;
}
else if (data->map)
{
long group_index = map_tag(BITMAP_GROUP_TAG, data->map, source->file, source->line);
struct bitmap_group *group_source;
@@ -720,9 +793,9 @@ static void *bitmap_build(struct halo_menu_bitmap const *source, long tag_index)
continue;
}
if (data->width <= 0 || data->height <= 0 || data->width > 2048 || data->height > 2048)
if (width <= 0 || height <= 0 || width > 2048 || height > 2048)
{
problem(source->file, source->line, "a frame is 1 to 2048 wide and high:", data->png);
problem(source->file, source->line, "a frame is 1 to 2048 wide and high:", png);
return group;
}
/* (its D3D texture is a small one, which its PNG is drawn for: the
@@ -741,13 +814,13 @@ static void *bitmap_build(struct halo_menu_bitmap const *source, long tag_index)
problem(source->file, source->line, "could not make the texture of bitmap", source->name);
return group;
}
bitmap->width = (short)data->width;
bitmap->height = (short)data->height;
bitmap->width = (short)width;
bitmap->height = (short)height;
menu_tags.bitmaps = realloc(menu_tags.bitmaps, (menu_tags.bitmap_count + 1) * sizeof(*menu_tags.bitmaps));
menu_tags.bitmaps[menu_tags.bitmap_count++] = bitmap;
/* (none without a renderer: debug.null_renderer) */
if (bitmap->hardware_format)
halo_menus_art_register(bitmap->hardware_format, data->png);
halo_menus_art_register(bitmap->hardware_format, png);
}
return group;
}
@@ -880,7 +953,7 @@ static void setting_add(struct halo_menu_widget const *source, long definition_i
setting->definition_index = definition_index;
setting->setting = source->setting;
setting->loaded_index = NONE;
setting->value_count = split(source->values, setting->values);
setting->value_count = spinner_split(source, TRUE, setting->values);
}
/* a font: large, small, terminal, or the map's by its path */
@@ -928,6 +1001,9 @@ static void *widget_build(long widget_index)
definition->bounds.x1 = (short)(source->left + (source->has_width ? source->width : 640));
definition->flags = flags_parse(source->flags, widget_flag_names, NUMBEROF(widget_flag_names),
source->file, source->line);
/* (in a network game the clock runs on) */
if (build.game_map)
definition->flags &= ~FLAG(1); /* pause_game */
definition->milliseconds_to_auto_close = source->auto_close;
definition->auto_close_fade_time = source->auto_close_fade;
reference_clear(&definition->background_bitmap, BITMAP_GROUP_TAG);
@@ -1250,6 +1326,281 @@ static void menu_tags_release(void)
/* ---------- public code */
/* ---------- the in-game pause menu (a multiplayer map's)
Its list (RESUME GAME, LEAVE GAME; a custom map's own buttons too) gets
SETTINGS, the menus' settings (as the main menu's SETTINGS opens them), and
for the host END GAME, which ends the game as its time limit would: its
players stay, and the host picks the next map after the carnage report.
They are copies of the map's LEAVE GAME button (its look), put before it.
The map's pause screens move to fit them: on the Xbox's own (its box of
pausebox2 pieces), the box is the port's taller one (pause/pausebox_*:
tools/port_settings.py), centred where the old one was; on a custom map's,
what is below the list moves down. */
#define PAUSE_SETTINGS_SCREEN "main_menu/settings_select/player_setup/player_profile_edit/player_profile_edit_screen"
#define PAUSE_BUTTON_SPACING 35
#define PAUSE_BOX_FIRST_BUTTONS 3
static long ui_function_named(char const *name)
{
long index;
for (index = 0; index < 512; index++)
{
char const *function = ui_widget_event_handler_function_name(index);
if (!function)
break;
if (!strcmp(function, name))
return index;
}
return NONE;
}
static boolean tag_name_ends(long tag_index, char const *end)
{
char const *name = tag_index == NONE ? NULL : tag_get_name(tag_index);
size_t length = name ? strlen(name) : 0, end_length = strlen(end);
return name && length >= end_length && !strcmp(name + length - end_length, end);
}
/* the index of the list's button that runs the function (LEAVE GAME's),
else NONE */
static long pause_quit_button(struct ui_widget_definition const *list, long quit_function)
{
struct ui_widget_child_reference const *children = list->child_widgets.address;
long child;
for (child = 0; child < list->child_widgets.count; child++)
{
struct ui_widget_definition const *button;
struct ui_widget_event_handler_reference const *handlers;
long handler;
if (children[child].widget_tag.index == NONE)
continue;
button = tag_get(UI_WIDGET_DEFINITION_TAG, children[child].widget_tag.index);
handlers = button->event_handlers.address;
for (handler = 0; handler < button->event_handlers.count; handler++)
{
if (handlers[handler].function == quit_function &&
TEST_FLAG(handlers[handler].flags, _event_handler_run_function_bit))
{
return child;
}
}
}
return NONE;
}
/* a button like the model (its look), its own text, each of the model's
events (its A and Start) running the function and opening the widget (if
not NONE) */
static void *pause_button(struct cache_file_tag_instance *instances, struct ui_widget_definition const *model,
char const *name, char const *text, long function, long widget_tag)
{
struct ui_widget_definition *button = allocate(sizeof(*button));
struct ui_widget_event_handler_reference *handlers =
allocate(model->event_handlers.count * sizeof(struct ui_widget_event_handler_reference));
long text_tag = next_tag(), handler;
if (!button || !handlers)
return NULL;
memcpy(button, model, sizeof(*button));
instance_set(instances, UNICODE_STRING_LIST_TAG, text_tag, name, " text", string_list_build(&text, 1));
reference_set(&button->text_label_string_list, UNICODE_STRING_LIST_TAG, text_tag);
button->string_list_index = 0;
button->game_data_inputs.count = 0;
button->game_data_inputs.address = NULL;
/* (the game's memcpy asserts on a NULL source, even for nothing) */
if (model->event_handlers.count)
memcpy(handlers, model->event_handlers.address, model->event_handlers.count * sizeof(*handlers));
for (handler = 0; handler < model->event_handlers.count; handler++)
{
handlers[handler].flags = FLAG(_event_handler_run_function_bit);
handlers[handler].function = (short)function;
handlers[handler].script[0] = 0;
reference_set(&handlers[handler].widget_tag, UI_WIDGET_DEFINITION_TAG, widget_tag);
if (widget_tag != NONE)
{
handlers[handler].flags |= FLAG(_event_handler_open_widget_bit) |
FLAG(_event_handler_try_to_branch_on_failure_bit);
}
}
button->event_handlers.address = handlers;
return button;
}
/* the list's buttons: SETTINGS (and the host's END GAME) put before LEAVE
GAME (quit); returns how many were added */
static long pause_list_patch(struct cache_file_tag_instance *instances, struct ui_widget_definition *list, long quit,
boolean host)
{
struct ui_widget_child_reference *children = list->child_widgets.address;
long count = list->child_widgets.count, added = host ? 2 : 1, child;
struct ui_widget_child_reference *grown = allocate((count + added) * sizeof(struct ui_widget_child_reference));
struct ui_widget_definition const *model = tag_get(UI_WIDGET_DEFINITION_TAG, children[quit].widget_tag.index);
long settings_widget = widget_named(PAUSE_SETTINGS_SCREEN);
short spacing = count >= 2 ? (short)(children[count - 1].vertical_offset - children[count - 2].vertical_offset) :
PAUSE_BUTTON_SPACING;
void *buttons[2];
long tags[2];
if (!grown || settings_widget == NONE || spacing <= 0)
return 0;
tags[0] = next_tag();
buttons[0] = pause_button(instances, model, "pause/settings_button", "SETTINGS",
function_index("profile set edit begin", "pause", 0), build.widget_tags[settings_widget]);
tags[1] = host ? next_tag() : NONE;
buttons[1] = host ? pause_button(instances, model, "pause/end_game_button", "END GAME",
function_index("port pause end game", "pause", 0), NONE) : NULL;
if (!buttons[0] || (host && !buttons[1]))
return 0;
for (child = 0; child < added; child++)
{
instance_set(instances, UI_WIDGET_DEFINITION_TAG, tags[child],
child ? "pause/end_game_button" : "pause/settings_button", "", buttons[child]);
}
if (quit)
memcpy(grown, children, quit * sizeof(*grown));
for (child = 0; child < added; child++)
{
grown[quit + child] = children[quit];
reference_set(&grown[quit + child].widget_tag, UI_WIDGET_DEFINITION_TAG, tags[child]);
grown[quit + child].vertical_offset = (short)(children[quit].vertical_offset + child * spacing);
}
for (child = quit; child < count; child++)
{
grown[child + added] = children[child];
grown[child + added].vertical_offset = (short)(children[child].vertical_offset + added * spacing);
}
list->child_widgets.address = grown;
list->child_widgets.count = count + added;
/* (the list draws within its bounds) */
list->bounds.y1 = (short)(list->bounds.y1 + added * spacing);
return added;
}
/* the Xbox's own box: a widget of the three pausebox2 pieces */
static boolean pause_box_stock(struct ui_widget_definition const *box)
{
struct ui_widget_child_reference const *pieces = box->child_widgets.address;
return box->child_widgets.count == 3 && tag_name_ends(pieces[0].widget_tag.index, "\\pausebox2_left") &&
tag_name_ends(pieces[1].widget_tag.index, "\\pausebox2_left_center") &&
tag_name_ends(pieces[2].widget_tag.index, "\\pausebox2_right");
}
/* the stock box's pieces drawn with the port's taller box: its frame for
the number of buttons */
static void pause_box_redraw(struct ui_widget_definition const *box, long buttons)
{
static char const *const names[] = { "pause/pausebox_left", "pause/pausebox_center", "pause/pausebox_right" };
struct ui_widget_child_reference const *pieces = box->child_widgets.address;
long piece;
for (piece = 0; piece < 3; piece++)
{
struct ui_widget_definition *definition = tag_get(UI_WIDGET_DEFINITION_TAG, pieces[piece].widget_tag.index);
long bitmap = find(names[piece], build.menus->bitmap_count, bitmap_name);
struct bitmap_group *group;
struct bitmap_group_sequence *sequence;
if (bitmap == NONE)
continue;
group = bitmap_group_get(build.bitmap_tags[bitmap]);
sequence = group->sequences.address;
/* (one frame: the one for the number of buttons) */
sequence->first_bitmap_index = (short)PIN(buttons - PAUSE_BOX_FIRST_BUTTONS, 0, group->bitmaps.count - 1);
sequence->bitmap_count = 1;
reference_set(&definition->background_bitmap, BITMAP_GROUP_TAG, build.bitmap_tags[bitmap]);
definition->bounds.y1 = (short)(definition->bounds.y0 + 256);
}
}
static void pause_patch(struct cache_file_tag_instance *instances)
{
long collection = tag_loaded('Soul', MULTIPLAYER_COLLECTION);
long quit_function = ui_function_named("mp game player quit");
boolean host = global_network_game_server_get() != NULL;
struct tag_block const *screens;
long patched_list = NONE, added = 0, buttons = 0, screen;
boolean box_redrawn = FALSE;
if (collection == NONE || quit_function == NONE)
return;
screens = tag_get('Soul', collection);
for (screen = 0; screen < screens->count; screen++)
{
long screen_tag = ((struct tag_reference const *)screens->address)[screen].index;
struct ui_widget_definition *definition;
struct ui_widget_child_reference *children;
long child, list_child = NONE, box_child = NONE;
short grow, list_top;
if (screen_tag == NONE)
continue;
definition = tag_get(UI_WIDGET_DEFINITION_TAG, screen_tag);
children = definition->child_widgets.address;
for (child = 0; child < definition->child_widgets.count && list_child == NONE; child++)
{
struct ui_widget_definition *list;
long quit;
if (children[child].widget_tag.index == NONE)
continue;
list = tag_get(UI_WIDGET_DEFINITION_TAG, children[child].widget_tag.index);
if (list->type != _widget_type_column_list)
continue;
/* (one list, which the screens share: patched once) */
if (children[child].widget_tag.index == patched_list)
{
list_child = child;
continue;
}
quit = pause_quit_button(list, quit_function);
if (quit == NONE || patched_list != NONE)
continue;
added = pause_list_patch(instances, list, quit, host);
if (!added)
return;
buttons = list->child_widgets.count;
patched_list = children[child].widget_tag.index;
list_child = child;
}
if (list_child == NONE)
continue;
for (child = 0; child < definition->child_widgets.count; child++)
{
if (child != list_child && children[child].widget_tag.index != NONE &&
pause_box_stock(tag_get(UI_WIDGET_DEFINITION_TAG, children[child].widget_tag.index)))
{
box_child = child;
}
}
/* the stock box: taller, centred where it was, the list with it, and
what is below it moved down; else only what is below the list */
grow = (short)(added * PAUSE_BUTTON_SPACING);
list_top = children[list_child].vertical_offset;
for (child = 0; child < definition->child_widgets.count; child++)
{
if (box_child != NONE && (child == box_child || child == list_child))
children[child].vertical_offset -= grow / 2;
else if (children[child].vertical_offset > list_top)
children[child].vertical_offset += box_child != NONE ? grow - grow / 2 : grow;
}
if (box_child != NONE && !box_redrawn)
{
pause_box_redraw(tag_get(UI_WIDGET_DEFINITION_TAG, children[box_child].widget_tag.index), buttons);
box_redrawn = TRUE;
}
}
if (patched_list != NONE)
platform_log("menus: the pause menu has SETTINGS%s", host ? " and END GAME" : "");
}
void menu_tags_loaded(
char const *map_name)
{
@@ -1257,17 +1608,23 @@ void menu_tags_loaded(
struct cache_file_tag_instance *instances;
long widget_count, own_lists = 0, total, index;
if (strcmp(map_name, "ui") || strcmp(config_string("display.menus"), "pc"))
boolean game_map = strcmp(map_name, "ui") != 0;
/* (ui.map, and a multiplayer map: its pause menu's SETTINGS) */
if ((game_map && tag_loaded('Soul', MULTIPLAYER_COLLECTION) == NONE) ||
strcmp(config_string("display.menus"), "pc"))
{
return;
/* (in VR, the Xbox's: the VR port's join codes, game list, host options
and keyboard pointer are built into its screens) */
if (halo_vr_active())
}
/* (in VR, the Xbox's unless vr.menus asks for the PC version's) */
if (halo_vr_active() && strcmp(config_string("vr.menus"), "pc"))
return;
menus = halo_menus_load();
if (!menus)
return;
memset(&build, 0, sizeof(build));
build.menus = menus;
build.game_map = game_map;
widget_count = menus->widget_count;
build.widget_tags = malloc((widget_count + 1) * sizeof(long));
build.text_tags = malloc((widget_count + 1) * sizeof(long));
@@ -1282,7 +1639,8 @@ void menu_tags_loaded(
problem(menus->widgets[index].file, menus->widgets[index].line, "two widgets are named",
menus->widgets[index].name);
}
total = widget_count + own_lists + menus->string_list_count + menus->bitmap_count;
total = widget_count + own_lists + menus->string_list_count + menus->bitmap_count +
(game_map ? PAUSE_PATCH_TAGS : 0);
instances = build.failed ? NULL : instances_grow(total, &build.first_index, &build.first_salt);
if (!instances)
goto failed;
@@ -1323,7 +1681,7 @@ void menu_tags_loaded(
if (widget->strings)
{
char const *pieces[MAXIMUM_STRINGS];
long count = split(widget->strings, pieces);
long count = spinner_split(widget, FALSE, pieces);
instance_set(instances, UNICODE_STRING_LIST_TAG, build.spinner_tags[index], widget->name, " strings",
string_list_build(pieces, count));
@@ -1332,12 +1690,27 @@ void menu_tags_loaded(
}
if (build.failed)
goto failed;
/* (pause_patch's, until it makes them: nothing a name finds) */
for (index = build.first_index + build.next; index < build.first_index + total; index++)
{
instances[index].group_tag = NONE;
instances[index].tag_index = NONE;
instances[index].name = "";
}
cache_files_set_tag_instances(instances, build.first_index + total);
for (index = 0; index < widget_count && !build.failed; index++)
instances[DATUM_INDEX_TO_ABSOLUTE_INDEX(build.widget_tags[index])].base_address = widget_build(index);
if (build.failed)
goto failed;
if (widget_named(menus->root) != NONE)
if (game_map)
{
pause_patch(instances);
if (build.failed)
goto failed;
/* (those it made) */
cache_files_set_tag_instances(instances, build.first_index + build.next);
}
else if (widget_named(menus->root) != NONE)
{
snprintf(menu_tags.root, sizeof(menu_tags.root), "%s%s", PC_MENU_TAG_PREFIX, menus->root);
for (index = 0; menu_tags.root[index]; index++)
+901
View File
@@ -0,0 +1,901 @@
/*
NETWORK_ACTORS.C
AI sync (port/linux/NETCODE.md).
Only the host runs the AI (game.c skips ai_update on clients). An actor
drives its unit the way a player does, through unit_control. The clients
have the units (network_objects.c); this file makes them move like the
host's.
Each tick the host records the control every actor gave its unit (a hook
in unit_control, and the bursts it holds the trigger for) and sends it to
each client with the unit's state: position, seat, shields and health,
camouflage, and whether it flees in a panic. Units near a client's players
are sent every tick, others less often, but a unit starting a one-tick
action (a jump, a grenade) goes to everyone that tick. Each tick a client
feeds the latest control into unit_control, the same path that drives a
remote player's unit, so the unit walks, aims, fires and throws as it does
on the host. The state corrects any drift.
What the AI starts once is numbered, so a client plays each once however
many times it receives it: animation impulses (dives, vaults), melee
attacks and leaps (which the AI starts directly, not through the control),
speech, and custom animations (outside co-op, whose events carry them).
Pain and death sounds aren't sent: a client plays those itself as it
replays the host's damage.
A client creates no actors of its own (actors.c): the host's are the only
ones. Deaths need nothing here: network_damage.c kills a client's copy of
an AI unit the same way it kills a player's.
*/
/* ---------- headers */
#include "cseries.h"
#include "game/game.h"
#include "networking/network_game_globals.h"
#include "objects/objects.h"
#include "objects/damage.h"
#include "sound/game_sound.h"
#include "sound/sound_definitions.h"
#include "units/units.h"
#include "units/unit_control_data.h"
#include "network_coop.h"
#include "network_distributed.h"
#include <math.h>
/* ---------- constants */
enum
{
/* AI units tracked at once: every actor (halo_port_capacity.h's
HALO_PORT_MAXIMUM_ACTORS) and the units the cutscenes' recorded
animations drive */
MAXIMUM_NETWORK_ACTORS = HALO_PORT_MAXIMUM_ACTORS + 32,
MAXIMUM_ENTRIES_PER_MESSAGE = 64,
/* A client keeps applying a control for this long after the host last
sent one. After that the unit is left alone: the actor let go of it, or
the host went quiet. */
CONTROL_HELD_TICKS = 2 * TICKS_PER_SECOND,
/* an impulse is repeated in this many entries, in case one is lost */
IMPULSE_REPEAT_TICKS = 3,
/* the number of unit_start_animation_impulse impulses (private to units.c) */
NUMBER_OF_UNIT_ANIMATION_IMPULSES = 14,
NO_IMPULSE = 0xFF,
NO_TEAM = 0xFF,
/* An entry's impulse is one of the animation impulses or, past them, an
action the AI starts directly: a melee attack (unit_melee_attack_begin)
or a leap (unit_leap_begin). */
_actor_action_melee = NUMBER_OF_UNIT_ANIMATION_IMPULSES,
_actor_action_leap,
NUMBER_OF_ACTOR_ACTIONS,
/* control flags a unit acts on in one tick: a unit that sets one goes to
every client that tick, however far away, so the action isn't missed */
ONE_SHOT_CONTROL_FLAGS = FLAG(_unit_control_jump_bit) | FLAG(_unit_control_action_bit) |
FLAG(_unit_control_weapon_reload_bit) | FLAG(_unit_control_throw_grenade_bit) |
FLAG(_unit_control_swap_weapons_bit),
};
/* struct distributed_actor_state flags */
enum
{
_distributed_actor_rides_bit = 0,
_distributed_actor_shield_depleted_bit,
_distributed_actor_shield_charging_bit,
_distributed_actor_shield_over_charging_bit,
_distributed_actor_camouflaged_bit,
_distributed_actor_super_camouflaged_bit,
/* the impulse turns the unit to impulse_alignment */
_distributed_actor_impulse_aligned_bit,
/* fleeing in a panic, toward run_blindly_angle (unit_start_running_blindly) */
_distributed_actor_running_blindly_bit,
};
/* facing, aiming and looking vectors are sent as yaw and pitch */
enum
{
_angle_yaw,
_angle_pitch,
NUMBER_OF_ANGLES
};
/* ---------- structures */
/* an AI unit's control and state at the end of the host's tick (like
struct distributed_unit_state for players) */
struct distributed_actor_state
{
long unit_index;
long vehicle_index;
short seat_index;
byte flags;
/* the impulse's sequence number; impulse is NO_IMPULSE when there is none */
byte impulse_number;
byte impulse;
byte animation_state;
byte aiming_speed;
byte primary_trigger;
word control_flags;
signed char throttle[3];
byte active_camouflage;
/* the speech's sequence number; 0 when there is none */
byte speech_number;
/* the unit's team (NO_TEAM for none): the AI sets it after the unit is
made, so a client's copy would keep the team it was made with */
byte team;
short facing[NUMBER_OF_ANGLES];
short aiming[NUMBER_OF_ANGLES];
short looking[NUMBER_OF_ANGLES];
short impulse_alignment;
short run_blindly_angle;
word body_vitality;
word shield_vitality;
/* the sound the unit started saying (a sound tag) */
long speech_sound;
/* the custom animation it started (unit_start_user_animation), and its
sequence number; the graph is NONE when there is none */
long user_animation_graph;
short user_animation;
byte user_animation_number;
byte user_animation_interpolate;
real_point3d position;
struct distributed_vector velocity;
struct distributed_vector forward;
struct distributed_vector up;
};
/* the damage an AI unit is taking: its shield's flare and its body's wounds
are drawn by it */
struct distributed_actor_damage
{
long unit_index;
word current_shield_damage;
word recent_shield_damage;
word current_body_damage;
word recent_body_damage;
};
struct distributed_actor_damage_message
{
struct distributed_message_header header;
struct distributed_actor_damage units[MAXIMUM_ENTRIES_PER_MESSAGE];
};
struct distributed_actor_state_message
{
struct distributed_message_header header;
struct distributed_actor_state states[MAXIMUM_ENTRIES_PER_MESSAGE];
};
/* host: what an actor gave its unit this tick */
struct host_actor
{
long unit_index;
/* got a control since the last send (noted during game_tick, sent after it) */
boolean noted;
/* its damage was sent last tick (and once more when it ends) */
boolean damaged;
struct unit_control_data control;
/* the control flags of the last tick's entry */
word sent_control_flags;
/* the latest impulse, how many more entries carry it, and its number */
short impulse;
short impulse_sends;
byte impulse_number;
boolean impulse_aligned;
real_vector2d impulse_alignment;
/* the latest speech, how many more entries carry it, and its number */
long speech_sound;
short speech_sends;
byte speech_number;
/* the latest custom animation, the same way */
long user_animation_graph;
short user_animation;
boolean user_animation_interpolate;
short user_animation_sends;
byte user_animation_number;
};
/* client: the latest the host sent about an AI unit */
struct client_actor
{
long unit_index;
long received_time;
struct unit_control_data control;
/* the impulse to play, and the number of the last one played */
short impulse;
byte impulse_number;
byte played_impulse_number;
boolean impulse_aligned;
real_vector2d impulse_alignment;
/* the speech to play (NONE when there is none), and the number of the last played */
long speech_sound;
byte speech_number;
byte played_speech_number;
/* the custom animation to play (graph NONE when there is none), and the
number of the last played */
long user_animation_graph;
short user_animation;
boolean user_animation_interpolate;
byte user_animation_number;
byte played_user_animation_number;
boolean driven;
};
/* ---------- globals */
static struct host_actor host_actors[MAXIMUM_NETWORK_ACTORS];
static short host_actor_count;
/* host: the numbers of every unit's impulses, speech and animations, from
one counter, so a unit that drops out of the table and comes back can't
repeat the number a client last played */
static byte host_event_number;
static struct client_actor client_actors[MAXIMUM_NETWORK_ACTORS];
static short client_actor_count;
/* ---------- private code */
static void angles_pack(
real_vector3d const *vector,
short *angles)
{
angles[_angle_yaw] = distributed_angle_pack((real)atan2(vector->j, vector->i));
angles[_angle_pitch] = distributed_angle_pack((real)asin(PIN(vector->k, -1.0f, 1.0f)));
}
static void angles_unpack(
short const *angles,
real_vector3d *vector)
{
real yaw = distributed_angle_unpack(angles[_angle_yaw], FALSE);
real pitch = distributed_angle_unpack(angles[_angle_pitch], TRUE);
vector->i = (real)(cos(pitch) * cos(yaw));
vector->j = (real)(cos(pitch) * sin(yaw));
vector->k = (real)sin(pitch);
}
/* host: the next event's number (never 0, which a client's new entry has
as played) */
static byte next_event_number(
void)
{
if (++host_event_number == 0)
host_event_number = 1;
return host_event_number;
}
/* the unit's entry, adding one if needed; NULL if the table is full */
static struct host_actor *host_actor_for(
long unit_index)
{
short index;
for (index = 0; index < host_actor_count; index++)
{
if (host_actors[index].unit_index == unit_index)
return &host_actors[index];
}
if (host_actor_count >= MAXIMUM_NETWORK_ACTORS)
return NULL;
csmemset(&host_actors[host_actor_count], 0, sizeof(host_actors[0]));
host_actors[host_actor_count].unit_index = unit_index;
host_actors[host_actor_count].impulse = NONE;
host_actors[host_actor_count].speech_sound = NONE;
host_actors[host_actor_count].user_animation_graph = NONE;
return &host_actors[host_actor_count++];
}
static struct client_actor *client_actor_for(
long unit_index)
{
short index;
for (index = 0; index < client_actor_count; index++)
{
if (client_actors[index].unit_index == unit_index)
return &client_actors[index];
}
if (client_actor_count >= MAXIMUM_NETWORK_ACTORS)
return NULL;
csmemset(&client_actors[client_actor_count], 0, sizeof(client_actors[0]));
client_actors[client_actor_count].unit_index = unit_index;
client_actors[client_actor_count].impulse = NONE;
client_actors[client_actor_count].speech_sound = NONE;
client_actors[client_actor_count].user_animation_graph = NONE;
return &client_actors[client_actor_count++];
}
/* whether the unit exists, is alive, and isn't a player's */
static boolean actor_unit_valid(
long unit_index)
{
struct unit_datum *unit;
if (!object_try_and_get_and_verify_type(unit_index, _object_mask_unit))
return FALSE;
unit = unit_get(unit_index);
return !TEST_FLAG(unit->object.damage_flags, _object_dead_bit) && unit->unit.player_index == NONE;
}
/* host: builds the entry to send for an AI unit */
static void actor_state_from_unit(
struct host_actor const *actor,
struct distributed_actor_state *state)
{
struct unit_datum *unit = unit_get(actor->unit_index);
struct damage_network_state damage;
real camouflage = PIN(unit->unit.active_camouflage, 0.0f, 1.0f);
csmemset(state, 0, sizeof(*state));
state->unit_index = actor->unit_index;
state->vehicle_index = NONE;
state->seat_index = NONE;
if (unit->object.parent_object_index != NONE && unit->unit.parent_seat_index != NONE)
{
SET_FLAG(state->flags, _distributed_actor_rides_bit, TRUE);
state->vehicle_index = unit->object.parent_object_index;
state->seat_index = unit->unit.parent_seat_index;
}
state->animation_state = (byte)actor->control.animation_state;
state->aiming_speed = (byte)actor->control.aiming_speed;
state->primary_trigger = (byte)(long)floor(PIN(actor->control.primary_trigger, 0.0f, 1.0f) * 255.0f + 0.5f);
state->control_flags = actor->control.control_flags;
/* for a burst the AI holds the trigger for (unit_persistent_control),
send the flags and trigger the unit's update produced this tick */
if (unit->unit.persistent_control_timer > 0)
{
state->control_flags = (word)(unit->unit.control_flags & (FLAG(NUMBER_OF_UNIT_CONTROL_FLAGS) - 1));
state->primary_trigger = (byte)(long)floor(PIN(unit->unit.primary_trigger, 0.0f, 1.0f) * 255.0f + 0.5f);
}
state->throttle[0] = (signed char)(long)floor(PIN(actor->control.throttle.i, -1.0f, 1.0f) * 127.0f + 0.5f);
state->throttle[1] = (signed char)(long)floor(PIN(actor->control.throttle.j, -1.0f, 1.0f) * 127.0f + 0.5f);
state->throttle[2] = (signed char)(long)floor(PIN(actor->control.throttle.k, -1.0f, 1.0f) * 127.0f + 0.5f);
angles_pack(&actor->control.facing_vector, state->facing);
angles_pack(&actor->control.aiming_vector, state->aiming);
angles_pack(&actor->control.looking_vector, state->looking);
state->impulse = NO_IMPULSE;
if (actor->impulse != NONE && actor->impulse_sends > 0)
{
state->impulse = (byte)actor->impulse;
state->impulse_number = actor->impulse_number;
SET_FLAG(state->flags, _distributed_actor_impulse_aligned_bit, actor->impulse_aligned);
if (actor->impulse_aligned)
{
state->impulse_alignment = distributed_angle_pack(
(real)atan2(actor->impulse_alignment.j, actor->impulse_alignment.i));
}
}
state->speech_sound = NONE;
if (actor->speech_sound != NONE && actor->speech_sends > 0)
{
state->speech_sound = actor->speech_sound;
state->speech_number = actor->speech_number;
}
state->user_animation_graph = NONE;
if (actor->user_animation_graph != NONE && actor->user_animation_sends > 0)
{
state->user_animation_graph = actor->user_animation_graph;
state->user_animation = actor->user_animation;
state->user_animation_interpolate = (byte)actor->user_animation_interpolate;
state->user_animation_number = actor->user_animation_number;
}
if (TEST_FLAG(unit->unit.flags, _unit_running_blindly_bit))
{
SET_FLAG(state->flags, _distributed_actor_running_blindly_bit, TRUE);
state->run_blindly_angle = distributed_angle_pack(unit->unit.run_blindly_angle);
}
damage_get_network_state(actor->unit_index, &damage);
SET_FLAG(state->flags, _distributed_actor_shield_depleted_bit, damage.shield_depleted);
SET_FLAG(state->flags, _distributed_actor_shield_charging_bit, damage.shield_charging);
SET_FLAG(state->flags, _distributed_actor_shield_over_charging_bit, damage.shield_over_charging);
state->body_vitality = distributed_vitality_pack(damage.body_vitality);
state->shield_vitality = distributed_vitality_pack(damage.shield_vitality);
SET_FLAG(state->flags, _distributed_actor_camouflaged_bit,
TEST_FLAG(unit->unit.flags, _unit_active_camouflaged_bit));
SET_FLAG(state->flags, _distributed_actor_super_camouflaged_bit,
TEST_FLAG(unit->unit.flags, _unit_super_camouflaged_bit));
state->active_camouflage = (byte)(long)floor(camouflage * 255.0f + 0.5f);
state->team = unit->object.owner_team_index >= 0 && unit->object.owner_team_index < NO_TEAM ?
(byte)unit->object.owner_team_index : NO_TEAM;
state->position = unit->object.position;
distributed_vector_pack(&unit->object.translational_velocity, DISTRIBUTED_VELOCITY_SCALE, &state->velocity);
distributed_vector_pack(&unit->object.forward, DISTRIBUTED_UNIT_SCALE, &state->forward);
distributed_vector_pack(&unit->object.up, DISTRIBUTED_UNIT_SCALE, &state->up);
}
/* Client: stores the entry's control and applies its state to the unit.
Returns FALSE for an entry with invalid values. */
static boolean actor_state_apply(
struct distributed_actor_state const *state,
long now)
{
struct client_actor *actor;
struct unit_datum *unit;
struct damage_network_state damage;
real_vector3d velocity;
real_vector3d forward;
real_vector3d up;
if (!distributed_object_index_valid(state->unit_index) || !network_objects_client_has(state->unit_index))
return FALSE;
/* (a body the host's unit got back up from: a Flood combat form that
feigned death, which it does only once its body is at rest. Left dead,
the ragdoll was dragged about by the host's positions. The host sends
only living units.) */
if (object_try_and_get_and_verify_type(state->unit_index, _object_mask_unit) &&
TEST_FLAG(unit_get(state->unit_index)->object.damage_flags, _object_dead_bit) &&
TEST_FLAG(unit_get(state->unit_index)->object.flags, _object_at_rest_bit) &&
unit_get(state->unit_index)->unit.player_index == NONE && state->body_vitality > 0)
{
unit_port_resurrect(state->unit_index);
}
if (!actor_unit_valid(state->unit_index) ||
state->animation_state >= NUMBER_OF_UNIT_ANIMATION_STATES ||
state->aiming_speed >= NUMBER_OF_UNIT_AIMING_SPEEDS ||
!VALID_FLAGS(state->control_flags, NUMBER_OF_UNIT_CONTROL_FLAGS) ||
(state->impulse != NO_IMPULSE && state->impulse >= NUMBER_OF_ACTOR_ACTIONS) ||
(state->speech_sound != NONE && !distributed_tag_of_group(state->speech_sound, SOUND_DEFINITION_TAG)) ||
(state->user_animation_graph != NONE &&
!distributed_graph_animation(state->user_animation_graph, state->user_animation)) ||
!distributed_point_valid(&state->position, UNIT_WORLD_BOUND))
{
return FALSE;
}
distributed_vector_unpack(&state->velocity, DISTRIBUTED_VELOCITY_SCALE, &velocity);
distributed_vector_unpack(&state->forward, DISTRIBUTED_UNIT_SCALE, &forward);
distributed_vector_unpack(&state->up, DISTRIBUTED_UNIT_SCALE, &up);
if (!distributed_axes_make_valid(&forward, &up))
return FALSE;
actor = client_actor_for(state->unit_index);
if (!actor)
return TRUE;
/* the control, applied every tick until the next entry */
actor->received_time = now;
actor->control.animation_state = (char)state->animation_state;
actor->control.aiming_speed = (char)state->aiming_speed;
actor->control.control_flags = state->control_flags;
actor->control.weapon_index = NONE;
actor->control.grenade_index = NONE;
actor->control.zoom_level = NONE;
actor->control.throttle.i = (real)state->throttle[0] / 127.0f;
actor->control.throttle.j = (real)state->throttle[1] / 127.0f;
actor->control.throttle.k = (real)state->throttle[2] / 127.0f;
actor->control.primary_trigger = (real)state->primary_trigger / 255.0f;
angles_unpack(state->facing, &actor->control.facing_vector);
angles_unpack(state->aiming, &actor->control.aiming_vector);
angles_unpack(state->looking, &actor->control.looking_vector);
if (state->impulse != NO_IMPULSE && state->impulse_number != actor->played_impulse_number)
{
real yaw = distributed_angle_unpack(state->impulse_alignment, FALSE);
actor->impulse = state->impulse;
actor->impulse_number = state->impulse_number;
actor->impulse_aligned = TEST_FLAG(state->flags, _distributed_actor_impulse_aligned_bit);
actor->impulse_alignment.i = (real)cos(yaw);
actor->impulse_alignment.j = (real)sin(yaw);
}
if (state->speech_sound != NONE && state->speech_number != actor->played_speech_number)
{
actor->speech_sound = state->speech_sound;
actor->speech_number = state->speech_number;
}
if (state->user_animation_graph != NONE && state->user_animation_number != actor->played_user_animation_number)
{
actor->user_animation_graph = state->user_animation_graph;
actor->user_animation = state->user_animation;
actor->user_animation_interpolate = state->user_animation_interpolate != 0;
actor->user_animation_number = state->user_animation_number;
}
/* the state: seat, shields and health, camouflage, running blindly, and
position (a unit in a vehicle goes where the vehicle goes) */
unit = unit_get(state->unit_index);
if (TEST_FLAG(state->flags, _distributed_actor_rides_bit))
{
if (unit->object.parent_object_index != state->vehicle_index ||
unit->unit.parent_seat_index != state->seat_index)
{
network_objects_set_seat(state->unit_index, state->vehicle_index, state->seat_index);
}
}
else if (unit->object.parent_object_index != NONE)
{
network_objects_set_seat(state->unit_index, NONE, NONE);
}
damage_get_network_state(state->unit_index, &damage);
damage.shield_depleted = TEST_FLAG(state->flags, _distributed_actor_shield_depleted_bit);
damage.shield_charging = TEST_FLAG(state->flags, _distributed_actor_shield_charging_bit);
damage.shield_over_charging = TEST_FLAG(state->flags, _distributed_actor_shield_over_charging_bit);
damage.body_vitality = distributed_vitality_unpack(state->body_vitality);
damage.shield_vitality = distributed_vitality_unpack(state->shield_vitality);
damage_set_network_state(state->unit_index, &damage);
SET_FLAG(unit->unit.flags, _unit_active_camouflaged_bit,
TEST_FLAG(state->flags, _distributed_actor_camouflaged_bit));
SET_FLAG(unit->unit.flags, _unit_super_camouflaged_bit,
TEST_FLAG(state->flags, _distributed_actor_super_camouflaged_bit));
unit->unit.active_camouflage = (real)state->active_camouflage / 255.0f;
if (state->team != NO_TEAM)
unit->object.owner_team_index = state->team;
SET_FLAG(unit->unit.flags, _unit_running_blindly_bit,
TEST_FLAG(state->flags, _distributed_actor_running_blindly_bit));
if (TEST_FLAG(state->flags, _distributed_actor_running_blindly_bit))
unit->unit.run_blindly_angle = distributed_angle_unpack(state->run_blindly_angle, FALSE);
/* vehicles are placed only by the host's object states (network_objects.c) */
if (unit->object.parent_object_index == NONE && unit->object.type != _object_type_vehicle)
{
real dx = state->position.x - unit->object.position.x;
real dy = state->position.y - unit->object.position.y;
real dz = state->position.z - unit->object.position.z;
if (dx * dx + dy * dy + dz * dz > REMOTE_CORRECTION_TOLERANCE * REMOTE_CORRECTION_TOLERANCE &&
network_objects_reconcile(state->unit_index, &state->position, &forward, &up, &velocity, NULL,
REMOTE_BLEND_DISTANCE))
{
distributed_count_correction();
}
}
return TRUE;
}
/* Client: plays a sound at the unit's head, as unit_dialogue_update starts
a unit's speech. */
static void speech_play(
long unit_index,
long sound_definition_index)
{
struct object_marker marker;
real_point3d position = *global_origin3d;
real_vector3d forward = *global_forward3d;
short node_index = 0;
if (object_get_marker_by_name(unit_index, "head", &marker, 1))
{
node_index = marker.node_index;
position = marker.node_matrix.position;
forward = marker.node_matrix.forward;
}
object_impulse_sound_new(unit_index, sound_definition_index, node_index, &position, &forward, 1.0f);
}
/* ---------- public code */
void network_actors_new_game(
void)
{
host_actor_count = 0;
client_actor_count = 0;
}
/* host: unit_control calls this when an actor drives its unit */
void network_actors_note_control(
long unit_index,
struct unit_control_data const *control_data)
{
struct host_actor *actor;
if (game_connection() != _game_connection_network_server)
return;
actor = host_actor_for(unit_index);
if (!actor)
return;
actor->noted = TRUE;
actor->control = *control_data;
}
/* host: an impulse or action for an AI unit, sent in the next few entries */
static void note_action(
long unit_index,
short action,
real_vector2d const *alignment_vector)
{
struct host_actor *actor;
if (game_connection() != _game_connection_network_server)
return;
actor = host_actor_for(unit_index);
if (!actor)
return;
actor->impulse = action;
actor->impulse_sends = IMPULSE_REPEAT_TICKS;
actor->impulse_number = next_event_number();
actor->impulse_aligned = alignment_vector != NULL;
if (alignment_vector)
actor->impulse_alignment = *alignment_vector;
}
/* host: unit_start_animation_impulse calls this for an AI unit */
void network_actors_note_impulse(
long unit_index,
short animation_impulse,
real_vector2d const *alignment_vector)
{
note_action(unit_index, animation_impulse, alignment_vector);
}
/* host: unit_melee_attack_begin calls this when an AI unit starts a melee attack */
void network_actors_note_melee(
long unit_index,
real_vector2d const *alignment_vector)
{
note_action(unit_index, _actor_action_melee, alignment_vector);
}
/* host: unit_leap_begin calls this when an AI unit leaps */
void network_actors_note_leap(
long unit_index,
real_vector2d const *alignment_vector)
{
note_action(unit_index, _actor_action_leap, alignment_vector);
}
/* host: unit_dialogue_update calls this when an AI unit starts saying
something (not a pain or death sound, which clients play themselves) */
void network_actors_note_speech(
long unit_index,
long sound_definition_index)
{
struct host_actor *actor;
if (game_connection() != _game_connection_network_server)
return;
actor = host_actor_for(unit_index);
if (!actor)
return;
actor->speech_sound = sound_definition_index;
actor->speech_sends = IMPULSE_REPEAT_TICKS;
actor->speech_number = next_event_number();
}
/* host: unit_start_user_animation calls this when an AI unit starts a
custom animation (co-op's events carry them in co-op) */
void network_actors_note_user_animation(
long unit_index,
long animation_graph_index,
short animation_index,
boolean interpolate)
{
struct host_actor *actor;
if (game_connection() != _game_connection_network_server || network_coop_active())
return;
actor = host_actor_for(unit_index);
if (!actor)
return;
actor->user_animation_graph = animation_graph_index;
actor->user_animation = animation_index;
actor->user_animation_interpolate = interpolate;
actor->user_animation_sends = IMPULSE_REPEAT_TICKS;
actor->user_animation_number = next_event_number();
}
/* host: the damage of the AI units taking some, to every client (and once
more when it ends, so a flare goes) */
static void host_send_damage(
void)
{
struct distributed_actor_damage_message message;
short count = 0;
short index;
for (index = 0; index < host_actor_count; index++)
{
struct host_actor *actor = &host_actors[index];
struct damage_network_state damage;
boolean damaged;
if (!actor_unit_valid(actor->unit_index))
continue;
damage_get_network_state(actor->unit_index, &damage);
damaged = damage.current_shield_damage > 0.0f || damage.recent_shield_damage > 0.0f ||
damage.current_body_damage > 0.0f || damage.recent_body_damage > 0.0f;
if (!damaged && !actor->damaged)
continue;
actor->damaged = damaged;
message.units[count].unit_index = actor->unit_index;
message.units[count].current_shield_damage = distributed_vitality_pack(damage.current_shield_damage);
message.units[count].recent_shield_damage = distributed_vitality_pack(damage.recent_shield_damage);
message.units[count].current_body_damage = distributed_vitality_pack(damage.current_body_damage);
message.units[count].recent_body_damage = distributed_vitality_pack(damage.recent_body_damage);
if (++count == MAXIMUM_ENTRIES_PER_MESSAGE)
{
distributed_send(&message, _distributed_message_actor_damage, count,
(word)(sizeof(message.header) + count * sizeof(message.units[0])), _distributed_to_clients);
count = 0;
}
}
if (count)
{
distributed_send(&message, _distributed_message_actor_damage, count,
(word)(sizeof(message.header) + count * sizeof(message.units[0])), _distributed_to_clients);
}
}
/* Host, after each tick: sends each client the AI units driven this tick.
Units near the client's players go every tick, others less often. A unit
with a fresh impulse, action, speech or animation goes to everyone in each
of the next IMPULSE_REPEAT_TICKS ticks, and one starting a one-tick action
goes that tick. A unit no actor drove this tick is dropped from the table,
unless it is fleeing: a unit running blindly moves by itself, without its
actor's control, and dropped it stood running in place on the clients. */
void network_actors_host_tick(
void)
{
static struct distributed_actor_state states[MAXIMUM_NETWORK_ACTORS];
/* sent to every client this tick, whatever its period */
static boolean urgent[MAXIMUM_NETWORK_ACTORS];
struct distributed_actor_state_message message;
long machine_indices[HALO_PORT_MAXIMUM_NETWORK_MACHINES];
short machine_count = distributed_client_machines(machine_indices, HALO_PORT_MAXIMUM_NETWORK_MACHINES);
long now = game_time_get();
short state_count = 0;
short index;
short machine_number;
for (index = 0; index < host_actor_count; index++)
{
struct host_actor *actor = &host_actors[index];
if (!actor_unit_valid(actor->unit_index) ||
(!actor->noted && !TEST_FLAG(unit_get(actor->unit_index)->unit.flags, _unit_running_blindly_bit)))
{
host_actors[index--] = host_actors[--host_actor_count];
continue;
}
actor_state_from_unit(actor, &states[state_count]);
urgent[state_count] = states[state_count].impulse != NO_IMPULSE || states[state_count].speech_sound != NONE ||
states[state_count].user_animation_graph != NONE ||
(states[state_count].control_flags & ~actor->sent_control_flags & ONE_SHOT_CONTROL_FLAGS) != 0;
actor->sent_control_flags = states[state_count].control_flags;
state_count++;
actor->noted = FALSE;
if (actor->impulse_sends > 0)
actor->impulse_sends--;
if (actor->speech_sends > 0)
actor->speech_sends--;
if (actor->user_animation_sends > 0)
actor->user_animation_sends--;
}
host_send_damage();
for (machine_number = 0; machine_number < machine_count; machine_number++)
{
long machine_index = machine_indices[machine_number];
short count = 0;
for (index = 0; index < state_count; index++)
{
struct distributed_actor_state const *state = &states[index];
short period = network_objects_send_period(machine_index, &state->position);
if (!urgent[index] && (now + DATUM_INDEX_TO_ABSOLUTE_INDEX(state->unit_index)) % period != 0)
continue;
message.states[count++] = *state;
if (count == MAXIMUM_ENTRIES_PER_MESSAGE || count == DATAGRAM_ENTRIES(struct distributed_actor_state))
{
distributed_send_to_machine(machine_index, &message, _distributed_message_actor_states, count,
(word)(sizeof(message.header) + count * sizeof(struct distributed_actor_state)));
count = 0;
}
}
if (count)
{
distributed_send_to_machine(machine_index, &message, _distributed_message_actor_states, count,
(word)(sizeof(message.header) + count * sizeof(struct distributed_actor_state)));
}
}
}
word network_actors_damage_entry_size(
void)
{
return sizeof(struct distributed_actor_damage);
}
/* client: the damage the host's AI units are taking */
void network_actors_handle_damage(
void const *entries,
short count)
{
struct distributed_actor_damage const *units = entries;
short index;
for (index = 0; index < count; index++)
{
struct damage_network_state damage;
if (!distributed_object_index_valid(units[index].unit_index) ||
!network_objects_client_has(units[index].unit_index) || !actor_unit_valid(units[index].unit_index))
{
continue;
}
damage_get_network_state(units[index].unit_index, &damage);
damage.current_shield_damage = distributed_vitality_unpack(units[index].current_shield_damage);
damage.recent_shield_damage = distributed_vitality_unpack(units[index].recent_shield_damage);
damage.current_body_damage = distributed_vitality_unpack(units[index].current_body_damage);
damage.recent_body_damage = distributed_vitality_unpack(units[index].recent_body_damage);
damage_set_network_state(units[index].unit_index, &damage);
}
}
word network_actors_entry_size(
void)
{
return sizeof(struct distributed_actor_state);
}
/* client: entries from the host */
void network_actors_handle_states(
void const *entries,
short count)
{
struct distributed_actor_state const *states = entries;
long now = game_time_get();
short index;
for (index = 0; index < count; index++)
actor_state_apply(&states[index], now);
}
/* Client: called at the point in the tick where the host runs the AI.
Drives each AI unit with the last control the host sent. */
void network_actors_drive(
void)
{
long now = game_time_get();
short index;
for (index = 0; index < client_actor_count; index++)
{
struct client_actor *actor = &client_actors[index];
if (!actor_unit_valid(actor->unit_index) || now - actor->received_time > CONTROL_HELD_TICKS)
{
if (actor->driven && object_try_and_get_and_verify_type(actor->unit_index, _object_mask_unit))
unit_set_actively_controlled(actor->unit_index, FALSE);
client_actors[index--] = client_actors[--client_actor_count];
continue;
}
/* vehicles follow the host's transform instead (network_objects.c) */
if (object_get(actor->unit_index)->object.type == _object_type_vehicle)
continue;
if (!actor->driven)
{
unit_set_actively_controlled(actor->unit_index, TRUE);
actor->driven = TRUE;
}
unit_control(actor->unit_index, &actor->control);
if (actor->impulse != NONE && actor->impulse_number != actor->played_impulse_number)
{
real_vector2d *alignment = actor->impulse_aligned ? &actor->impulse_alignment : NULL;
if (actor->impulse == _actor_action_melee)
unit_melee_attack_begin(actor->unit_index, FALSE, alignment);
else if (actor->impulse == _actor_action_leap)
unit_leap_begin(actor->unit_index, alignment);
else
unit_start_animation_impulse(actor->unit_index, actor->impulse, alignment);
actor->played_impulse_number = actor->impulse_number;
actor->impulse = NONE;
}
if (actor->speech_sound != NONE)
{
speech_play(actor->unit_index, actor->speech_sound);
actor->played_speech_number = actor->speech_number;
actor->speech_sound = NONE;
}
if (actor->user_animation_graph != NONE)
{
unit_port_play_user_animation(actor->unit_index, actor->user_animation_graph, actor->user_animation,
actor->user_animation_interpolate, 0);
actor->played_user_animation_number = actor->user_animation_number;
actor->user_animation_graph = NONE;
}
}
}
File diff suppressed because it is too large. Load diff
+105
View File
@@ -0,0 +1,105 @@
/*
NETWORK_COOP.H
The calls Halo's own code (source/) makes into network_coop.c. On a co-op
host the note_ functions send what the scripts just did to the clients; on
any other machine they do nothing, so the clients can call the same engine
functions to apply what they receive.
*/
#ifndef __NETWORK_COOP_H
#define __NETWORK_COOP_H
/* ---------- constants */
/* network_coop_note_hud */
enum
{
_coop_hud_help_text,
_coop_hud_objective,
_coop_hud_help_flash,
_coop_hud_messages_clear,
_coop_hud_checkpoint,
};
/* network_coop_note_player_effect */
enum
{
_coop_player_effect_translation,
_coop_player_effect_rotation,
_coop_player_effect_start,
_coop_player_effect_stop,
};
/* network_coop_note_nav_point */
enum
{
_coop_nav_point_team_flag,
_coop_nav_point_team_object,
_coop_nav_point_unit_flag,
_coop_nav_point_unit_object,
};
/* ---------- prototypes/NETWORK_COOP.C */
/* whether this is a network co-op game (not its lobby, whose menu scene also
has no game engine) */
boolean network_coop_active(void);
/* whether this machine is a co-op client, whose devices only the host moves */
boolean network_coop_devices_remote(void);
/* devices.c: a group's devices were set straight to its value */
void network_coop_note_device_snap(short group_index);
/* unit_scripting_commands.c: a script set a unit's maximum or current
vitality; TRUE if it was a co-op player's, now set on every player's */
boolean network_coop_set_players_vitality(long unit_index, boolean maximum, real body, real shield);
/* host: whether the player's machine has the host's structure BSP loaded
(always outside co-op, and for the host's own players). Until a client has,
the host takes none of its players' movement, which falls there with no
floor, and lets them trigger no BSP switch (players.c). */
boolean network_coop_player_has_structure_bsp(long player_index);
/* network_distributed.c: the structure BSP a client's input says it has */
void network_coop_note_player_structure_bsp(short player_index, short structure_bsp_index);
/* units.c: a vehicle left the vehicle carrying it (a Pelican's Warthog drop) */
void network_coop_vehicle_dropped(long vehicle_index, long carrier_index);
/* cinematics.c: a chapter title */
void network_coop_note_title(short title_index, real delay);
/* hud_messaging.c, hud.c: value is a message index, or TRUE/FALSE */
void network_coop_note_hud(short kind, short value);
/* player_effects.c: the script screen shake (a, b, c as the function takes them) */
void network_coop_note_player_effect(short kind, real a, real b, real c);
/* hud_nav_points.c: activate (or, with nav_index NONE, deactivate) a nav point.
target is the team or the unit; marker is the cutscene flag or the object. */
void network_coop_note_nav_point(short kind, short nav_index, long target, long marker, real vertical_offset);
/* units.c: a unit started a custom animation (animation_index NONE: stopped) */
void network_coop_note_unit_animation(long unit_index, long animation_graph_index, short animation_index,
boolean interpolate);
/* units.c: a unit (a dropship) opened or closed (unit_open, unit_close) */
void network_coop_note_unit_open(long unit_index, boolean open);
/* units.c: unit_custom_animation_at_frame moved it to a frame */
void network_coop_note_unit_animation_frame(long unit_index, short frame_index);
/* scenery.c: a scenery animation started */
/* the scripts' effects (hs_library_external.c): at a cutscene flag, or on an
object's marker */
void network_coop_note_effect(long effect_definition_index, short cutscene_flag_index);
/* the scripts' objects_attach and objects_detach (objects.c) */
void network_coop_note_attach(long parent_index, char const *parent_marker_name, long child_index,
char const *child_marker_name);
void network_coop_note_detach(long parent_index, long child_index);
void network_coop_note_object_effect(long effect_definition_index, long object_index, char const *marker_name);
void network_coop_note_scenery_animation(long object_index, long animation_graph_index, short animation_index,
short frame_index);
/* player_control.c: whether the skip key should do anything, and the press.
network_coop_vote_skip returns FALSE outside network co-op, where the
cinematic is skipped as usual. */
boolean network_coop_skip_offered(void);
boolean network_coop_vote_skip(void);
/* main.c: after a co-op host reverts to skip a cinematic; now is the game
time before the revert */
void network_coop_skip_reverted(long now);
/* the vote count to show, if a skippable cinematic is playing */
boolean network_coop_skip_vote_status(short *votes, short *voters, boolean *voted);
#endif
+189 -37
View File
@@ -16,8 +16,9 @@ being hit looks and feels like on the clients).
- A client deals no damage itself. What its own players' shots, grenades,
melee and vehicles hit it reports to the host, which deals it once it has
checked it: the report is of that machine's player, the damage one that
player's weapons (now or lately), grenades or the vehicle they drove
deal, of the shape the game gives it (at a point, a melee blow from the
player's weapons (now or lately), a grenade the host saw them throw
(each throw's explosion once) or the vehicle they drove deal, of the
shape the game gives it (at a point, a melee blow from the
striker, a collision from the vehicle), the target about where the host
had it when the shooter saw it (the host keeps a second of where
players' units and vehicles were, and looks back as far as the report
@@ -36,6 +37,7 @@ being hit looks and feels like on the clients).
*/
#include "cseries.h"
#include "cseries/errors.h"
#include "game/game.h"
#include "game/game_globals.h"
#include "game/players.h"
@@ -81,6 +83,13 @@ enum
died or dropped the launcher) */
MAXIMUM_RECENT_WEAPONS = 8,
RECENT_WEAPON_TICKS = 10 * TICKS_PER_SECOND,
/* the grenades a player has thrown lately, as the host's own game threw
them, whose damage the host takes from them: each goes off once, within
RECENT_WEAPON_TICKS of its throw. Each player has their own (all of
MAXIMUM_TRACKED_PLAYERS); one that hits nothing is kept the whole time,
so this is more than a player throws in it, infinite grenades and all
(a throw takes most of a second); past it the oldest gives way */
MAXIMUM_GRENADE_THROWS = 32,
/* a player's hits: a bucket of this many seconds of fire, filling at a
second a second, a hit taking what one of its weapon's projectiles
takes to fire (at twice the weapon's fastest rate: a shotgun's
@@ -341,8 +350,14 @@ static struct
{
long definition_indices[MAXIMUM_RECENT_WEAPONS];
long times[MAXIMUM_RECENT_WEAPONS];
long grenade_times[NUMBER_OF_UNIT_GRENADE_TYPES];
/* (the grenades thrown, not yet gone off: NONE for none) */
long throw_times[MAXIMUM_GRENADE_THROWS];
short throw_types[MAXIMUM_GRENADE_THROWS];
long driven_time;
/* (the blow of the player's unit with no weapon: units.c's
unit_unarmed_melee_damage) */
long unarmed_melee_damage_index;
long unarmed_time;
real hit_seconds;
long hit_seconds_time;
} damage_players[MAXIMUM_TRACKED_PLAYERS];
@@ -1074,21 +1089,74 @@ static real distributed_source_deals(
return distributed_source_deals_uncached(source_index, damage_index, grenade, kinds, reach);
}
/* the oldest grenade of the type the host saw the player throw within
RECENT_WEAPON_TICKS that has not gone off yet (network_damage_note_grenade),
NONE for none */
static short distributed_grenade_throw(
short player_index,
short grenade_type)
{
short index;
short oldest = NONE;
for (index = 0; index < MAXIMUM_GRENADE_THROWS; index++)
{
long time = damage_players[player_index].throw_times[index];
if (time != NONE && damage_players[player_index].throw_types[index] == grenade_type &&
game_time_get() - time <= RECENT_WEAPON_TICKS &&
(oldest == NONE || time < damage_players[player_index].throw_times[oldest]))
{
oldest = index;
}
}
return oldest;
}
/* whether an explosion of the damage is among the player's this tick
(distributed_report_paid): at the epicenter, or (NULL) anywhere */
static boolean distributed_explosion_this_tick(
short player_index,
long damage_index,
real_point3d const *epicenter)
{
short index;
if (damage_explosions[player_index].time != game_time_get())
return FALSE;
for (index = 0; index < damage_explosions[player_index].count; index++)
{
if (damage_explosions[player_index].explosions[index].definition_index == damage_index &&
(!epicenter || (damage_explosions[player_index].explosions[index].epicenter.x == epicenter->x &&
damage_explosions[player_index].explosions[index].epicenter.y == epicenter->y &&
damage_explosions[player_index].explosions[index].epicenter.z == epicenter->z)))
{
return TRUE;
}
}
return FALSE;
}
/* how many hits a second the player could deal of the damage: their
weapons, lately, their grenades, the vehicle they drove lately; 0 when none
of them deals it; how they deal it (the _damage_source flags); and how far
from them what they fire deals it */
weapons, lately, a grenade the host saw them throw that has not gone off
(or one going off this tick, hitting more than one object), the vehicle
they drove lately; 0 when none of them deals it; how they deal it (the
_damage_source flags); how far from them what they fire deals it; and the
type of grenade when nothing but a grenade of theirs deals it, else NONE */
static real distributed_player_deals(
short player_index,
long damage_index,
byte *kinds,
struct damage_reach *reach)
struct damage_reach *reach,
short *grenade_type)
{
struct game_globals *globals = scenario_get_game_globals();
short index;
real rate = 0.0f;
real grenade_rate = 0.0f;
*kinds = 0;
*grenade_type = NONE;
reach->distance = 0.0f;
reach->ticks = 0.0f;
reach->carried_ticks = 0.0f;
@@ -1108,24 +1176,12 @@ static real distributed_player_deals(
*kinds |= weapon_kinds;
}
}
for (index = 0; index < globals->grenades.count && index < NUMBER_OF_UNIT_GRENADE_TYPES; index++)
/* (a blow with no weapon: the unit's own, units.c) */
if (damage_players[player_index].unarmed_melee_damage_index == damage_index && damage_index != NONE &&
game_time_get() - damage_players[player_index].unarmed_time <= RECENT_WEAPON_TICKS)
{
struct game_globals_grenade *grenade = TAG_BLOCK_GET_ELEMENT(&globals->grenades, index,
struct game_globals_grenade);
if (game_time_get() - damage_players[player_index].grenade_times[index] <= RECENT_WEAPON_TICKS &&
grenade->projectile.index != NONE)
{
byte grenade_kinds;
struct damage_reach grenade_reach;
real grenade_rate = distributed_source_deals(grenade->projectile.index, damage_index, TRUE, &grenade_kinds,
&grenade_reach);
if (grenade_rate > 0.0f)
distributed_reach_combine(reach, &grenade_reach);
rate = MAX(rate, grenade_rate);
*kinds |= grenade_kinds;
}
rate = MAX(rate, MELEE_HITS_PER_SECOND);
SET_FLAG(*kinds, _damage_source_melee_bit, TRUE);
}
/* (a vehicle's collision is its driver's, physics.c; the damage it deals
a unit it kills is no one's) */
@@ -1141,6 +1197,36 @@ static real distributed_player_deals(
SET_FLAG(*kinds, _damage_source_collision_bit, TRUE);
}
}
/* (a grenade's damage only from one thrown: holding grenades deals
nothing) */
for (index = 0; index < globals->grenades.count && index < NUMBER_OF_UNIT_GRENADE_TYPES; index++)
{
struct game_globals_grenade *grenade = TAG_BLOCK_GET_ELEMENT(&globals->grenades, index,
struct game_globals_grenade);
boolean thrown = distributed_grenade_throw(player_index, index) != NONE;
if ((thrown || distributed_explosion_this_tick(player_index, damage_index, NULL)) &&
grenade->projectile.index != NONE)
{
byte this_kinds;
struct damage_reach this_reach;
real this_rate = distributed_source_deals(grenade->projectile.index, damage_index, TRUE, &this_kinds,
&this_reach);
if (this_rate > 0.0f)
{
distributed_reach_combine(reach, &this_reach);
/* (one with a throw left before one only going off now) */
if (*grenade_type == NONE || thrown)
*grenade_type = index;
}
grenade_rate = MAX(grenade_rate, this_rate);
*kinds |= this_kinds;
}
}
if (rate > 0.0f)
*grenade_type = NONE;
rate = MAX(rate, grenade_rate);
return rate * HIT_REPORT_RATE_MARGIN;
}
@@ -1409,6 +1495,8 @@ static void distributed_note_weapons(
if (player_index >= MAXIMUM_TRACKED_PLAYERS || unit_index == NONE)
continue;
damage_players[player_index].unarmed_melee_damage_index = unit_unarmed_melee_damage(unit_index);
damage_players[player_index].unarmed_time = game_time_get();
units[0] = unit_index;
units[1] = object_get(unit_index)->object.parent_object_index;
/* (a vehicle's collisions are its driver's, physics.c) */
@@ -1419,16 +1507,6 @@ static void distributed_note_weapons(
if (vehicle && vehicle->unit.driver_object_index == unit_index)
damage_players[player_index].driven_time = game_time_get();
}
{
struct unit_datum *unit = unit_get(unit_index);
short grenade_index;
for (grenade_index = 0; grenade_index < NUMBER_OF_UNIT_GRENADE_TYPES; grenade_index++)
{
if (unit->unit.grenade_counts[grenade_index] > 0)
damage_players[player_index].grenade_times[grenade_index] = game_time_get();
}
}
for (unit_number = 0; unit_number < 2; unit_number++)
{
struct unit_datum *unit = units[unit_number] != NONE ?
@@ -1626,6 +1704,8 @@ static boolean distributed_report_valid(
real reach;
struct damage_reach fired_reach;
short seen;
short grenade_type;
short throw_index = NONE;
/* that machine's player */
if (player_index == NO_PLAYER || player_index >= MAXIMUM_TRACKED_PLAYERS ||
@@ -1658,7 +1738,8 @@ static boolean distributed_report_valid(
return FALSE;
ticks = MIN(now - report->host_time + TARGET_HISTORY_SLACK_TICKS, TARGET_HISTORY_TICKS - 1);
/* damage that player could deal, and how they deal it */
rate = distributed_player_deals(player_index, report->damage.definition_index, &kinds, &fired_reach);
rate = distributed_player_deals(player_index, report->damage.definition_index, &kinds, &fired_reach,
&grenade_type);
if (rate <= 0.0f)
return FALSE;
/* ... of its shape: at a point, else a melee blow, else a collision; and
@@ -1700,12 +1781,26 @@ static boolean distributed_report_valid(
reach += definition->cutoff_radius;
if (!(distributed_distance_squared(&report->damage.origin, &report->target_position) <= reach * reach))
return FALSE;
/* what only a grenade of theirs deals, from one the host saw them throw
that has not gone off: its explosion once (the explosion's other objects
that tick come free, distributed_report_paid), what it hits at a point
while it is about */
if (grenade_type != NONE &&
!distributed_explosion_this_tick(player_index, report->damage.definition_index, &report->damage.epicenter))
{
throw_index = distributed_grenade_throw(player_index, grenade_type);
if (throw_index == NONE)
return FALSE;
}
/* no more than the weapon fires */
if (!distributed_report_paid(player_index, report, rate, area && !melee && !collision,
definition->cutoff_radius > 0.0f))
{
return FALSE;
}
/* (the grenade gone off: its throw spent) */
if (throw_index != NONE && area && !melee && !collision)
damage_players[player_index].throw_times[throw_index] = NONE;
/* a melee blow from where the host had the player (its origin their
head, its epicenter their body); a collision from the vehicle they
drove */
@@ -1926,6 +2021,26 @@ static boolean distributed_event_goes_to(
return FALSE;
}
/* How often the host logs how many client hits it accepted and refused
(only when it refused some). Tells "my shots don't register" apart from
"I missed". */
#define REPORT_LOG_TICKS (30 * TICKS_PER_SECOND)
static void distributed_log_reports(
void)
{
static long logged_dealt;
static long logged_rejected;
if (game_time_get() % REPORT_LOG_TICKS != 0 || damage_rejected_reports == logged_rejected)
return;
error(_error_silent, "damage: clients' hits in the last %d seconds: %ld dealt, %ld refused",
REPORT_LOG_TICKS / TICKS_PER_SECOND, damage_dealt_reports - logged_dealt,
damage_rejected_reports - logged_rejected);
logged_dealt = damage_dealt_reports;
logged_rejected = damage_rejected_reports;
}
void network_damage_host_tick(
void)
{
@@ -1936,6 +2051,7 @@ void network_damage_host_tick(
distributed_client_machines(machine_indices, HALO_PORT_MAXIMUM_NETWORK_MACHINES) : 0;
short machine_number;
distributed_log_reports();
distributed_note_weapons();
distributed_note_targets();
distributed_note_event_destinations();
@@ -2089,6 +2205,41 @@ void network_damage_statistics(
*replayed_events = damage_replayed_events;
}
/* the host: a grenade a player's unit threw (units.c), as the host's own
game threw it, which that player's machine reports the damage of
(distributed_report_valid) */
void network_damage_note_grenade(
long unit_index,
short grenade_type)
{
struct unit_datum *unit = unit_get(unit_index);
long player_index;
short index;
short slot = 0;
if (game_connection() != _game_connection_network_server || unit->unit.player_index == NONE ||
grenade_type < 0 || grenade_type >= NUMBER_OF_UNIT_GRENADE_TYPES)
{
return;
}
player_index = DATUM_INDEX_TO_ABSOLUTE_INDEX(unit->unit.player_index);
if (player_index >= MAXIMUM_TRACKED_PLAYERS)
return;
/* (in a free place, else the oldest's) */
for (index = 0; index < MAXIMUM_GRENADE_THROWS; index++)
{
if (damage_players[player_index].throw_times[index] == NONE)
{
slot = index;
break;
}
if (damage_players[player_index].throw_times[index] < damage_players[player_index].throw_times[slot])
slot = index;
}
damage_players[player_index].throw_times[slot] = game_time_get();
damage_players[player_index].throw_types[slot] = grenade_type;
}
void network_damage_new_game(
void)
{
@@ -2107,8 +2258,9 @@ void network_damage_new_game(
for (index = 0; index < MAXIMUM_RECENT_WEAPONS; index++)
damage_players[player_index].definition_indices[index] = NONE;
for (index = 0; index < NUMBER_OF_UNIT_GRENADE_TYPES; index++)
damage_players[player_index].grenade_times[index] = -RECENT_WEAPON_TICKS - 1;
damage_players[player_index].unarmed_melee_damage_index = NONE;
for (index = 0; index < MAXIMUM_GRENADE_THROWS; index++)
damage_players[player_index].throw_times[index] = NONE;
damage_players[player_index].driven_time = -RECENT_WEAPON_TICKS - 1;
damage_players[player_index].hit_seconds = HIT_REPORT_BURST_SECONDS;
damage_explosions[player_index].time = NONE;
+250 -13
View File
@@ -53,18 +53,24 @@ machine (their datum identifiers need not be).
#include "cseries.h"
#include "cseries/errors.h"
#include "cache/cache_files.h"
#include "models/model_animation_definitions.h"
#include "game/game.h"
#include "game/game_globals.h"
#include "game/players.h"
#include "game/game_engine.h"
#include "main/main.h"
#include "game/player_queues_new.h"
#include "networking/network_game_globals.h"
#include "objects/objects.h"
#include "objects/damage.h"
#include "scenario/scenario.h"
#include "scenario/scenario_definitions.h"
#include "structures/structure_bsp_definitions.h"
#include "units/units.h"
#include "units/biped_definitions.h"
#include "units/bipeds.h"
#include "network_coop.h"
#include "network_distributed.h"
#include <limits.h>
@@ -238,11 +244,8 @@ before the host takes it no longer, and before the client is put where the
host has it (no further than that: between the two they would disagree for
good, the host's player somewhere its own is not) */
#define HOST_ACCEPT_TOLERANCE 3.5f
#define REMOTE_CORRECTION_TOLERANCE 0.05f
#define LOCAL_CORRECTION_TOLERANCE 3.0f
/* how far from the origin a unit is (world units), and how fast a client's
own player's unit moves at most (world units a tick) */
#define UNIT_WORLD_BOUND 32768.0f
/* how fast a client's own player's unit moves at most (world units a tick) */
#define MAXIMUM_PREDICTED_SPEED 2.0f
/* ... on foot: this many times as fast as a player runs and jumps, or as
fast as the host's ticks threw its copy lately, whichever is more; and how
@@ -317,7 +320,9 @@ ticks before it */
struct distributed_player_input
{
byte player_index;
byte pad[3];
/* co-op: the structure BSP the client has loaded */
byte structure_bsp_index;
byte pad[2];
/* the client's tick */
long tick;
/* the latest host tick the client has had a message of (the host
@@ -666,6 +671,40 @@ boolean distributed_point_valid(
return fabsf(point->x) <= bound && fabsf(point->y) <= bound && fabsf(point->z) <= bound;
}
/* whether a tag index from the host really is a tag of that group */
boolean distributed_tag_of_group(
long tag_index,
unsigned long group_tag)
{
struct tag_iterator iterator;
long index;
tag_iterator_new(&iterator, group_tag);
while ((index = tag_iterator_next(&iterator)) != NONE)
{
if (index == tag_index)
return TRUE;
}
return FALSE;
}
/* the graph's animation, if the graph tag and index are valid */
struct animation *distributed_graph_animation(
long animation_graph_index,
short animation_index)
{
struct animation_graph *graph;
if (!distributed_tag_of_group(animation_graph_index, ANIMATION_GRAPH_TAG))
return NULL;
graph = animation_graph_definition_get(animation_graph_index);
if (animation_index < 0 || animation_index >= graph->animations.count)
return NULL;
return TAG_BLOCK_GET_ELEMENT(&graph->animations, animation_index, struct animation);
}
boolean distributed_object_index_valid(
long object_index)
{
@@ -749,7 +788,7 @@ void distributed_unit_vector_unpack(
}
}
static word distributed_vitality_pack(
word distributed_vitality_pack(
real value)
{
value *= VITALITY_SCALE;
@@ -757,15 +796,13 @@ static word distributed_vitality_pack(
return (word)(long)floor(value + 0.5f);
}
static real distributed_vitality_unpack(
real distributed_vitality_unpack(
word value)
{
return (real)value / VITALITY_SCALE;
}
/* an angle as a 16-bit fraction of a turn, and back (yaw from 0 to 2 pi,
pitch from -pi to pi) */
static short distributed_angle_pack(
short distributed_angle_pack(
real angle)
{
real turns = angle / (2.0f * _pi);
@@ -774,7 +811,7 @@ static short distributed_angle_pack(
return (short)(word)((long)floor(turns * 65536.0f + 0.5f) & 0xFFFF);
}
static real distributed_angle_unpack(
real distributed_angle_unpack(
short value,
boolean signed_angle)
{
@@ -2048,9 +2085,14 @@ static void distributed_apply_predictions(
{
distributed_predictions[player_index].valid = FALSE;
distributed_predictions[player_index].taken_host_time = NONE;
/* (of the unit it has now: not one of a life before) */
if (unit_index != NONE && unit_index == state->unit_index)
/* (of the unit it has now: not one of a life before; and not
from a co-op client still loading the host's BSP, whose player
falls there with no floor under it) */
if (unit_index != NONE && unit_index == state->unit_index &&
network_coop_player_has_structure_bsp(unit_get(unit_index)->unit.player_index))
{
distributed_take_prediction(player_index, unit_index, &bound);
}
}
/* (what the host's next tick starts from) */
if (unit_index != NONE)
@@ -2222,6 +2264,7 @@ static void distributed_client_send_inputs(
if (!update_client_distributed_input(local_player_index, &input->tick, &input->action, input->control_flags))
continue;
input->player_index = distributed_player_to_byte(player_index);
input->structure_bsp_index = (byte)global_structure_bsp_index_get();
input->host_time = distributed_host_time;
count++;
}
@@ -2232,6 +2275,37 @@ static void distributed_client_send_inputs(
}
}
/* (the host, in co-op) where each client player's input last faced, by
absolute index: how far it turns between inputs is its looking around */
static struct
{
boolean valid;
real_euler_angles2d facing;
} distributed_input_facings[MAXIMUM_TRACKED_PLAYERS];
/* (the host, in co-op) a client player's input counted in the scripts'
action tests, as a local player's is (player_control_action_test_note) */
static void distributed_note_input_actions(
short player_index,
struct player_action const *action)
{
real_euler_angles2d turn = { 0.0f, 0.0f };
if (distributed_input_facings[player_index].valid)
{
turn.yaw = action->desired_facing.yaw - distributed_input_facings[player_index].facing.yaw;
turn.pitch = action->desired_facing.pitch - distributed_input_facings[player_index].facing.pitch;
/* (the short way round) */
if (turn.yaw > _pi)
turn.yaw -= 2.0f * _pi;
else if (turn.yaw < -_pi)
turn.yaw += 2.0f * _pi;
}
distributed_input_facings[player_index].valid = TRUE;
distributed_input_facings[player_index].facing = action->desired_facing;
player_control_action_test_note(action->control_flags, &turn, &action->throttle, action->primary_trigger);
}
/* (the host) a client's players' input, and from it (once a message) how
long a message takes that client and back */
static void distributed_handle_inputs(
@@ -2261,6 +2335,10 @@ static void distributed_handle_inputs(
action.throttle.i = PIN(action.throttle.i, -1.0f, 1.0f);
action.throttle.j = PIN(action.throttle.j, -1.0f, 1.0f);
action.primary_trigger = PIN(action.primary_trigger, 0.0f, 1.0f);
/* (a spectator's buttons pick whom it watches: not counted) */
if (network_coop_active() && player->unit_index != NONE)
distributed_note_input_actions(input->player_index, &action);
network_coop_note_player_structure_bsp(input->player_index, input->structure_bsp_index);
update_server_handle_distributed_input(DATUM_INDEX_NEW(input->player_index, player->identifier), input->tick,
&action, input->control_flags, DISTRIBUTED_INPUT_HISTORY);
if (input->host_time != NONE && (host_time == NONE || input->host_time > host_time))
@@ -2931,6 +3009,52 @@ static void distributed_send_pings(
}
}
/* Co-op: the host's structure BSP. Clients switch BSP only when told
(their own trigger volumes don't, players.c). A switch is sent at once and
reliably; it is also resent regularly so a client that joined late catches
up. */
#define STRUCTURE_BSP_INTERVAL_TICKS (TICKS_PER_SECOND / 2)
static short distributed_sent_structure_bsp_index = NONE;
struct distributed_structure_bsp
{
short structure_bsp_index;
short pad;
};
struct distributed_structure_bsp_message
{
struct distributed_message_header header;
struct distributed_structure_bsp structure_bsp;
};
static void distributed_send_structure_bsp(
void)
{
struct distributed_structure_bsp_message message;
short index = global_structure_bsp_index_get();
boolean switched = index != distributed_sent_structure_bsp_index;
message.structure_bsp.structure_bsp_index = index;
message.structure_bsp.pad = 0;
distributed_send(&message, _distributed_message_structure_bsp, 1, (word)sizeof(message),
switched ? _distributed_to_clients_reliably : _distributed_to_clients);
distributed_sent_structure_bsp_index = index;
}
static void distributed_handle_structure_bsp(
struct distributed_structure_bsp const *structure_bsp)
{
short index = structure_bsp->structure_bsp_index;
if (network_coop_active() && index >= 0 && index < global_scenario_get()->structure_bsp_references.count &&
index != global_structure_bsp_index_get())
{
main_switch_structure_bsp(index);
}
}
/* the players' statistics that changed since they were last sent, and when
refreshing, STATISTICS_REFRESH_PLAYERS more whatever they are, round them
all (a client that lost a change has it again within eight seconds) */
@@ -3076,6 +3200,7 @@ void network_distributed_new_game(
csmemset(distributed_accepted, 0, sizeof(distributed_accepted));
csmemset(distributed_host_speeds, 0, sizeof(distributed_host_speeds));
csmemset(distributed_round_trips, 0, sizeof(distributed_round_trips));
csmemset(distributed_input_facings, 0, sizeof(distributed_input_facings));
csmemset(distributed_client_clocks, 0, sizeof(distributed_client_clocks));
csmemset(distributed_client_identities, 0, sizeof(distributed_client_identities));
distributed_identity_sent = FALSE;
@@ -3136,6 +3261,8 @@ void network_distributed_new_game(
network_damage_new_game();
network_vr_new_game();
bots_new_game();
network_actors_new_game();
network_coop_new_game();
}
/* after each tick (game_time.c) */
@@ -3178,9 +3305,18 @@ void network_distributed_tick(
distributed_statistics_due = FALSE;
if (game_time_get() % PING_INTERVAL_TICKS == 0)
distributed_send_pings();
/* (before the players, so clients load a new BSP before they hear
where the host moved everyone into it) */
if (network_coop_active() && (global_structure_bsp_index_get() != distributed_sent_structure_bsp_index ||
game_time_get() % STRUCTURE_BSP_INTERVAL_TICKS == 0))
{
distributed_send_structure_bsp();
}
distributed_host_send_players();
network_vr_tick();
bots_tick();
network_actors_host_tick();
network_coop_host_tick();
distributed_send_pickups();
if (game_time_get() % GAME_STATE_INTERVAL_TICKS == 0)
distributed_send_game_state(NONE);
@@ -3193,6 +3329,7 @@ void network_distributed_tick(
distributed_client_send_predictions();
network_objects_client_tick();
network_damage_client_tick();
network_coop_client_tick();
}
distributed_batches_flush();
distributed_machines.in_tick = FALSE;
@@ -3221,6 +3358,19 @@ static boolean distributed_message_stale(
case _distributed_message_damage_events:
case _distributed_message_vr_poses:
case _distributed_message_pings:
case _distributed_message_actor_states:
case _distributed_message_structure_bsp:
case _distributed_message_coop_presentation:
case _distributed_message_coop_device_groups:
case _distributed_message_coop_object_names:
case _distributed_message_coop_skip_vote:
case _distributed_message_coop_events:
case _distributed_message_coop_object_transforms:
case _distributed_message_actor_damage:
case _distributed_message_coop_object_looks:
case _distributed_message_damage_animations:
case _distributed_message_coop_screen_effect:
case _distributed_message_coop_device_states:
break;
default:
return FALSE;
@@ -3523,6 +3673,27 @@ void network_distributed_ban(
}
}
/* (the host: network_server_manager.c, its kick command) players kicked by
the host, which may join again: every machine told, nothing kept (no line
in BANS_FILE) */
void network_distributed_kick(
char const *names)
{
char kept_names[64];
char notice[MAXIMUM_NOTICE_LENGTH];
distributed_printable(kept_names, sizeof(kept_names), names);
snprintf(notice, sizeof(notice), "%s kicked by the host", kept_names);
/* (to every client in the game: in the lobby, the host's own) */
if (game_in_progress())
distributed_send_notice(notice);
else
{
console_warning("%s", notice);
error(_error_log, "%s", notice);
}
}
/* (the host) a client machine's tick, which one of its messages is
stamped with: its clock measured, each window, against the host's; one
whose game runs fast (distributed_client_clock) has its players'
@@ -3658,6 +3829,19 @@ void network_distributed_handle_message(
case _distributed_message_unit_states: entry_size = DISTRIBUTED_UNIT_STATE_MINIMUM_SIZE; break;
case _distributed_message_player_statistics: entry_size = sizeof(struct distributed_player_statistics); break;
case _distributed_message_pings: entry_size = sizeof(struct distributed_player_ping); break;
case _distributed_message_actor_states: entry_size = network_actors_entry_size(); break;
case _distributed_message_structure_bsp: entry_size = sizeof(struct distributed_structure_bsp); break;
case _distributed_message_coop_presentation: entry_size = network_coop_presentation_entry_size(); break;
case _distributed_message_coop_events: entry_size = network_coop_event_entry_size(); break;
case _distributed_message_coop_skip_vote: entry_size = network_coop_skip_vote_entry_size(); break;
case _distributed_message_coop_device_groups: entry_size = network_coop_device_group_entry_size(); break;
case _distributed_message_coop_object_names: entry_size = network_coop_object_names_entry_size(); break;
case _distributed_message_coop_object_transforms: entry_size = network_coop_object_transform_entry_size(); break;
case _distributed_message_actor_damage: entry_size = network_actors_damage_entry_size(); break;
case _distributed_message_coop_object_looks: entry_size = network_coop_object_look_entry_size(); break;
case _distributed_message_damage_animations: entry_size = network_objects_damage_animation_entry_size(); break;
case _distributed_message_coop_screen_effect: entry_size = network_coop_screen_effect_entry_size(); break;
case _distributed_message_coop_device_states: entry_size = network_coop_device_state_entry_size(); break;
case _distributed_message_pickups: entry_size = sizeof(struct distributed_pickup); break;
case _distributed_message_player_inputs: entry_size = sizeof(struct distributed_player_input); break;
case _distributed_message_relayed_actions: entry_size = DISTRIBUTED_RELAYED_ACTION_MINIMUM_SIZE; break;
@@ -3676,6 +3860,19 @@ void network_distributed_handle_message(
{
return;
}
/* (the kinds whose handlers read one entry: not without it) */
switch (header.type)
{
case _distributed_message_structure_bsp:
case _distributed_message_coop_presentation:
case _distributed_message_coop_object_names:
case _distributed_message_coop_skip_vote:
if (header.count < 1)
return;
break;
default:
break;
}
distributed_statistics.received++;
/* (each kind from the host, or from a client; a VR player's hands
@@ -3699,6 +3896,7 @@ void network_distributed_handle_message(
case _distributed_message_hit_reports:
case _distributed_message_vehicle_prediction:
case _distributed_message_player_inputs:
case _distributed_message_coop_skip_vote:
if (machine_index == NONE || game_connection() != _game_connection_network_server)
return;
break;
@@ -3735,6 +3933,45 @@ void network_distributed_handle_message(
case _distributed_message_unit_states:
distributed_handle_unit_states((byte const *)entries, (byte const *)message + size, header.count);
break;
case _distributed_message_actor_states:
network_actors_handle_states(entries, header.count);
break;
case _distributed_message_structure_bsp:
distributed_handle_structure_bsp((struct distributed_structure_bsp const *)entries);
break;
case _distributed_message_coop_presentation:
network_coop_handle_presentation(entries, header.game_time);
break;
case _distributed_message_coop_events:
network_coop_handle_events(entries, header.count);
break;
case _distributed_message_coop_skip_vote:
network_coop_handle_skip_vote(machine_index, entries);
break;
case _distributed_message_coop_device_groups:
network_coop_handle_device_groups(entries, header.count);
break;
case _distributed_message_coop_object_names:
network_coop_handle_object_names(entries);
break;
case _distributed_message_coop_object_transforms:
network_coop_handle_object_transforms(entries, header.count);
break;
case _distributed_message_actor_damage:
network_actors_handle_damage(entries, header.count);
break;
case _distributed_message_coop_object_looks:
network_coop_handle_object_looks(entries, header.count);
break;
case _distributed_message_damage_animations:
network_objects_handle_damage_animations(entries, header.count);
break;
case _distributed_message_coop_screen_effect:
network_coop_handle_screen_effect(entries, header.count);
break;
case _distributed_message_coop_device_states:
network_coop_handle_device_states(entries, header.count);
break;
case _distributed_message_player_statistics:
{
/* the host's count of kills, deaths, ... */
+115
View File
@@ -65,6 +65,47 @@ enum
/* every player's ping as the host measures it, every two seconds, for
the scoreboard (unreliable) */
_distributed_message_pings,
/* the host's actors' units: their control and state (network_actors.c).
A number of its own, clear of the kinds upstream adds: a build without
it drops the message as a kind it does not know, so the network version
stays upstream's and its players join as before */
_distributed_message_actor_states = 64,
/* co-op (a campaign map, no game engine): the host's structure BSP,
twice a second, for a client to switch to; numbered as actor_states */
_distributed_message_structure_bsp,
/* co-op: the host's cinematic, camera and screen fade, every tick
(network_coop.c) */
_distributed_message_coop_presentation,
/* (0.2.0's co-op script sounds; now part of coop_events. The number
stays taken so a 0.2.0 build never misreads a newer message.) */
_distributed_message_coop_sounds_retired,
/* co-op: device group state (network_coop.c) */
_distributed_message_coop_device_groups,
/* co-op: which named objects exist on the host (network_coop.c) */
_distributed_message_coop_object_names,
/* co-op: a client's vote to skip the cutscene, to the host (network_coop.c) */
_distributed_message_coop_skip_vote,
/* co-op: what the host's scripts did once: sounds, titles, HUD text,
animations (network_coop.c) */
_distributed_message_coop_events,
/* co-op: where the host's scenery and machines are, when they move
(network_coop.c) */
_distributed_message_coop_object_transforms,
/* the damage the host's AI units are taking, which their shields'
flares are drawn by (network_actors.c); 73 in upstream's AI sync too */
_distributed_message_actor_damage = 73,
/* co-op: how the host's objects look (their permutations, scale), when
that changes (network_coop.c) */
_distributed_message_coop_object_looks,
/* the flinch and death animations the host picked for its units, which a
client plays rather than its own picks (network_objects.c) */
_distributed_message_damage_animations = 75,
/* co-op: the host's cinematic screen effect (blur, filters, video), when
it changes and every two seconds (network_coop.c) */
_distributed_message_coop_screen_effect = 76,
/* co-op: where the host's devices are (doors, elevators), when they move
(network_coop.c) */
_distributed_message_coop_device_states = 77,
/* The VR port's own messages, numbered far past the game's (240 on),
so that messages upstream adds never take their numbers: a build
@@ -93,6 +134,10 @@ tick, drawn as it goes; further, it is put there, drawn gliding
#define HOST_BLEND_DISTANCE 0.25f
#define HOST_VEHICLE_BLEND_DISTANCE 0.5f
#define REMOTE_BLEND_DISTANCE 1.0f
/* world units: how far a remote unit may be from where the host says
before it is put there, and how far from the origin a unit can be */
#define REMOTE_CORRECTION_TOLERANCE 0.05f
#define UNIT_WORLD_BOUND 32768.0f
#define REMOTE_VEHICLE_BLEND_DISTANCE 2.0f
enum
@@ -190,6 +235,10 @@ never 0, which any object at the index matches) */
boolean distributed_real_valid(real value);
boolean distributed_point_valid(real_point3d const *point, real bound);
boolean distributed_object_index_valid(long object_index);
/* whether a tag index from the host really is a tag of that group */
boolean distributed_tag_of_group(long tag_index, unsigned long group_tag);
/* the graph's animation, if a graph tag and animation index from the host are valid */
struct animation *distributed_graph_animation(long animation_graph_index, short animation_index);
/* ... an orientation's two axes (unpacked): TRUE when they are one long
and about square, then made exactly so */
boolean distributed_axes_make_valid(real_vector3d *forward, real_vector3d *up);
@@ -200,12 +249,70 @@ void distributed_unit_vector_unpack(struct distributed_vector const *vector, rea
#define DISTRIBUTED_UNIT_SCALE 32767.0f
#define DISTRIBUTED_VELOCITY_SCALE 1024.0f
#define DISTRIBUTED_ANGULAR_VELOCITY_SCALE 4096.0f
/* an angle as a 16-bit fraction of a turn, and back (yaw from 0 to 2 pi,
pitch from -pi to pi) */
short distributed_angle_pack(real angle);
real distributed_angle_unpack(short value, boolean signed_angle);
/* shields and health in 16 bits */
word distributed_vitality_pack(real value);
real distributed_vitality_unpack(word value);
/* ---------- prototypes/NETWORK_ACTORS.C */
void network_actors_new_game(void);
/* (the host, after each tick) the units its actors drove this tick, to
each client */
void network_actors_host_tick(void);
/* (a client) the host's word on its actors' units */
void network_actors_handle_states(void const *entries, short count);
word network_actors_entry_size(void);
/* (a client, in its tick where the host runs its actors) each actor's unit
given the control the host last sent for it */
void network_actors_drive(void);
/* ---------- prototypes/NETWORK_COOP.C */
void network_coop_new_game(void);
/* after each tick, on the host and on a client */
void network_coop_host_tick(void);
void network_coop_client_tick(void);
/* the message handlers, and their entry sizes */
word network_coop_presentation_entry_size(void);
void network_coop_handle_presentation(void const *entries, long host_time);
word network_coop_event_entry_size(void);
void network_coop_handle_events(void const *entries, short count);
word network_coop_device_group_entry_size(void);
void network_coop_handle_device_groups(void const *entries, short count);
word network_coop_object_names_entry_size(void);
void network_coop_handle_object_names(void const *entries);
word network_coop_object_transform_entry_size(void);
word network_coop_object_look_entry_size(void);
void network_coop_handle_object_looks(void const *entries, short count);
word network_coop_screen_effect_entry_size(void);
word network_coop_device_state_entry_size(void);
void network_coop_handle_device_states(void const *entries, short count);
void network_coop_handle_screen_effect(void const *entries, short count);
word network_actors_damage_entry_size(void);
void network_actors_handle_damage(void const *entries, short count);
void network_coop_handle_object_transforms(void const *entries, short count);
word network_coop_skip_vote_entry_size(void);
void network_coop_handle_skip_vote(long machine_index, void const *entries);
/* game_sound.c: a sound the host's scripts played */
enum
{
_coop_sound_impulse,
_coop_sound_looping_start,
_coop_sound_looping_stop,
};
void network_coop_note_sound(short kind, long definition_index, long object_index, real scale);
/* ---------- prototypes/NETWORK_OBJECTS.C */
void network_objects_new_game(void);
/* after each tick */
void network_objects_host_tick(void);
word network_objects_damage_animation_entry_size(void);
void network_objects_handle_damage_animations(void const *entries, short count);
void network_objects_client_tick(void);
/* (the host) a client has loaded the game and asks for the host's objects:
again, having failed to make one of them */
@@ -214,6 +321,8 @@ void network_objects_handle_changes(void const *entries, short count);
void network_objects_handle_synchronized(void);
void network_objects_handle_states(void const *entries, short count);
void network_objects_handle_inventories(void const *entries, short count);
/* (a client) its own player picked up the weapon, to ready once its unit has it */
void network_objects_client_picked_up_weapon(short local_player_index, long unit_index, long definition_index);
void network_objects_handle_vehicle_prediction(long machine_index, void const *entries, short count);
/* (the host) the vehicle predictions come in since the last tick, taken */
void network_objects_apply_vehicle_predictions(void);
@@ -230,10 +339,16 @@ boolean network_objects_reconcile(long object_index, real_point3d const *positio
real blend_distance);
/* a unit in the vehicle's seat as the host has it (NONE: in none) */
void network_objects_set_seat(long unit_index, long vehicle_index, short seat_index);
/* (the host) the ticks between sends to a machine of a unit at position, by
how near that machine's players are (network_actors.c) */
short network_objects_send_period(long machine_index, real_point3d const *position);
/* ---------- prototypes/NETWORK_DAMAGE.C */
void network_damage_new_game(void);
/* the host: a grenade a player's unit threw (units.c), whose damage that
player's machine reports */
void network_damage_note_grenade(long unit_index, short grenade_type);
void network_damage_host_tick(void);
void network_damage_client_tick(void);
void network_damage_handle_events(void const *entries, short count);
+482 -20
View File
@@ -50,6 +50,7 @@ same datum index (identifier and all), so that any message can name one:
#include "objects/objects.h"
#include "objects/damage.h"
#include "objects/object_definitions.h"
#include "models/model_animation_definitions.h"
#include "models/model_definitions.h"
#include "units/units.h"
#include "units/biped_definitions.h"
@@ -59,6 +60,8 @@ same datum index (identifier and all), so that any message can name one:
#include "items/weapons.h"
#include "items/weapon_definitions.h"
#include "items/equipment_definitions.h"
#include "cutscene/cinematics.h"
#include "network_coop.h"
#include "network_distributed.h"
#include <math.h>
@@ -175,6 +178,9 @@ enum
/* ... the round trip without one measured, and the most */
DEFAULT_OWN_ROUND_TRIP_TICKS = 6,
MAXIMUM_OWN_ROUND_TRIP_TICKS = 60,
/* ... how long the weapon the host says it picked up may take to reach
its unit, to be readied (the host's messages are not in step) */
PICKED_UP_WEAPON_TICKS = 3 * TICKS_PER_SECOND,
/* the most grenades of a kind a unit carries, as the host says (a dead
unit drops each) */
MAXIMUM_INVENTORY_GRENADES = 16,
@@ -326,11 +332,14 @@ static struct
} objects_host_inventories[MAXIMUM_TRACKED_OBJECTS];
/* ... each client machine, found once a tick: where its players' living
units are, those units, and the vehicles they drive (with the player's
absolute index) */
absolute index); and where every player's living unit is, for a machine
with none (dead or joining, it watches one of them) */
static struct
{
short count;
long indices[HALO_PORT_MAXIMUM_NETWORK_MACHINES];
short player_unit_count;
real_point3d player_unit_origins[MAXIMUM_TRACKED_PLAYERS];
struct
{
short unit_count;
@@ -422,6 +431,14 @@ static struct distributed_own_inventory
long fired_times[MAXIMUM_WEAPONS_PER_UNIT];
long weapon_times[MAXIMUM_WEAPONS_PER_UNIT];
} objects_client_own_inventories[MAXIMUM_LOCAL_PLAYERS];
/* ... the weapon each of them last picked up (the host said so), its unit
and when, until it is readied (definition NONE: none) */
static struct distributed_picked_up_weapon
{
long unit_index;
long definition_index;
long time;
} objects_client_picked_up_weapons[MAXIMUM_LOCAL_PLAYERS];
/* ... whether it failed to make one of the host's objects since it last
asked for them (it says so when it asks again) */
static boolean objects_client_ask_again;
@@ -626,6 +643,32 @@ static void distributed_vector_clamp(
}
}
/* Whether the object is a vehicle no player drives in co-op (a Pelican on
its flight path): nothing on a client steers it, so its copy is kept at rest
there (no physics of its own) and moved only to where the host has it. In
multiplayer an empty vehicle (one bailed out of, or tumbling) keeps its own
physics between updates. */
static boolean distributed_vehicle_unsteered(
long object_index)
{
struct unit_datum *vehicle;
if (!network_coop_active() || object_get(object_index)->object.type != _object_type_vehicle)
return FALSE;
vehicle = unit_get(object_index);
return vehicle->unit.driver_object_index == NONE ||
unit_get(vehicle->unit.driver_object_index)->unit.player_index == NONE;
}
/* Whether a client puts its copy exactly where the host has it, rather than
closing on it: an unsteered vehicle, and anything in a co-op cutscene
(where it keeps up with the host's camera). */
static boolean distributed_object_follows_host(
long object_index)
{
return (network_coop_active() && cinematic_in_progress()) || distributed_vehicle_unsteered(object_index);
}
/* (the transform checked) */
static void distributed_object_move(
long object_index,
@@ -647,7 +690,10 @@ static void distributed_object_move(
object->object.translational_velocity = *velocity;
if (angular_velocity)
object->object.angular_velocity = *angular_velocity;
render_interpolation_correct_object(object_index, &offset);
if (!distributed_object_follows_host(object_index))
render_interpolation_correct_object(object_index, &offset);
if (distributed_vehicle_unsteered(object_index))
SET_FLAG(object->object.flags, _object_at_rest_bit, TRUE);
}
void network_objects_correct(
@@ -692,15 +738,33 @@ boolean network_objects_reconcile(
distributed_object_move(object_index, position, &valid_forward, &valid_up, velocity, angular_velocity);
return TRUE;
}
/* (half of the way: the tick's snapshots draw it moving, no jump) */
blended.x = object->object.position.x + dx * 0.5f;
blended.y = object->object.position.y + dy * 0.5f;
blended.z = object->object.position.z + dz * 0.5f;
object_set_position(object_index, &blended, &valid_forward, &valid_up);
/* Move halfway, and draw the move as a glide over the next few frames,
as larger corrections are. Drawn as one step, a unit corrected every tick
or two (a distant enemy) visibly hitched each time. */
if (distributed_object_follows_host(object_index))
blended = *position;
else
{
blended.x = object->object.position.x + dx * 0.5f;
blended.y = object->object.position.y + dy * 0.5f;
blended.z = object->object.position.z + dz * 0.5f;
}
{
real_vector3d offset;
offset.i = object->object.position.x - blended.x;
offset.j = object->object.position.y - blended.y;
offset.k = object->object.position.z - blended.z;
object_set_position(object_index, &blended, &valid_forward, &valid_up);
if (!distributed_object_follows_host(object_index))
render_interpolation_correct_object(object_index, &offset);
}
if (velocity)
object->object.translational_velocity = *velocity;
if (angular_velocity)
object->object.angular_velocity = *angular_velocity;
if (distributed_vehicle_unsteered(object_index))
SET_FLAG(object->object.flags, _object_at_rest_bit, TRUE);
return FALSE;
}
@@ -755,6 +819,175 @@ static long distributed_driven_vehicle(
object_get(unit_index)->object.parent_object_index : NONE;
}
/* ---------- damage animations
A unit's flinches and deaths are animations picked by where the damage came
from and at random among their permutations, so a client replaying the
host's damage could pick others. The host sends its picks (each in three
ticks' messages, in case one is lost). A client plays the host's pick when
it gets there first, or switches to it if its own has only just begun
(unit_port_correct_damage_animation). */
enum
{
DAMAGE_ANIMATION_SENDS = 3,
MAXIMUM_QUEUED_DAMAGE_ANIMATIONS = 32,
/* how long a client keeps the host's pick for a hit it hasn't replayed yet */
DAMAGE_ANIMATION_KEPT_TICKS = 2 * TICKS_PER_SECOND,
};
/* type: units.h's _unit_damage_animation_soft_ping and the rest; number:
the pick's, so a client tells a pick sent again from a new one */
struct distributed_damage_animation
{
long unit_index;
short animation_index;
byte type;
byte number;
};
struct distributed_damage_animations_message
{
struct distributed_message_header header;
struct distributed_damage_animation animations[MAXIMUM_QUEUED_DAMAGE_ANIMATIONS];
};
/* host: the picks still to be sent */
static struct
{
struct distributed_damage_animation animation;
short sends;
} host_damage_animations[MAXIMUM_QUEUED_DAMAGE_ANIMATIONS];
static short host_damage_animation_count;
static byte host_damage_animation_number;
/* client: the host's latest pick of each type for each unit, by absolute
index: its number, and when it came (NONE once played) */
static struct
{
long unit_index;
short animation_index[NUMBER_OF_UNIT_DAMAGE_ANIMATIONS];
byte number[NUMBER_OF_UNIT_DAMAGE_ANIMATIONS];
long time[NUMBER_OF_UNIT_DAMAGE_ANIMATIONS];
} client_damage_animations[MAXIMUM_TRACKED_OBJECTS];
/* whether the animation is one of the unit's graph */
static boolean distributed_unit_has_animation(
long unit_index,
short animation_index)
{
long graph_index = unit_definition_get(unit_get(unit_index)->definition_index)->object.animation_graph.index;
return graph_index != NONE && animation_index >= 0 &&
animation_index < animation_graph_definition_get(graph_index)->animations.count;
}
/* units.c, as a unit flinches or dies: the host notes the animation it
picked; a client takes the host's pick when it has one */
short network_objects_damage_animation(
long unit_index,
short type,
short animation_index)
{
short connection = game_connection();
long absolute_index = DATUM_INDEX_TO_ABSOLUTE_INDEX(unit_index);
if (type < 0 || type >= NUMBER_OF_UNIT_DAMAGE_ANIMATIONS)
return animation_index;
if (connection == _game_connection_network_server && animation_index != NONE &&
host_damage_animation_count < MAXIMUM_QUEUED_DAMAGE_ANIMATIONS)
{
struct distributed_damage_animation *animation =
&host_damage_animations[host_damage_animation_count].animation;
animation->unit_index = unit_index;
animation->animation_index = animation_index;
animation->type = (byte)type;
animation->number = ++host_damage_animation_number;
host_damage_animations[host_damage_animation_count++].sends = DAMAGE_ANIMATION_SENDS;
}
else if (connection == _game_connection_network_client && absolute_index >= 0 &&
absolute_index < MAXIMUM_TRACKED_OBJECTS && client_damage_animations[absolute_index].unit_index == unit_index)
{
long *time = &client_damage_animations[absolute_index].time[type];
if (*time != NONE && game_time_get() - *time < DAMAGE_ANIMATION_KEPT_TICKS)
{
*time = NONE;
return client_damage_animations[absolute_index].animation_index[type];
}
}
return animation_index;
}
/* host, each tick: the picks still to be sent, to every client */
static void distributed_host_send_damage_animations(
void)
{
struct distributed_damage_animations_message message;
short count = 0;
short index;
for (index = 0; index < host_damage_animation_count; index++)
{
message.animations[count++] = host_damage_animations[index].animation;
if (--host_damage_animations[index].sends <= 0)
host_damage_animations[index--] = host_damage_animations[--host_damage_animation_count];
}
if (count > 0)
{
distributed_send(&message, _distributed_message_damage_animations, count,
(word)(sizeof(message.header) + count * sizeof(message.animations[0])), _distributed_to_clients);
}
}
word network_objects_damage_animation_entry_size(
void)
{
return sizeof(struct distributed_damage_animation);
}
void network_objects_handle_damage_animations(
void const *entries,
short count)
{
struct distributed_damage_animation const *animations = entries;
short index;
for (index = 0; index < count; index++)
{
struct distributed_damage_animation const *animation = &animations[index];
long absolute_index = DATUM_INDEX_TO_ABSOLUTE_INDEX(animation->unit_index);
short type;
if (!distributed_object_index_valid(animation->unit_index) || absolute_index >= MAXIMUM_TRACKED_OBJECTS ||
animation->type >= NUMBER_OF_UNIT_DAMAGE_ANIMATIONS || !network_objects_client_has(animation->unit_index) ||
!object_try_and_get_and_verify_type(animation->unit_index, _object_mask_unit) ||
!distributed_unit_has_animation(animation->unit_index, animation->animation_index))
{
continue;
}
if (client_damage_animations[absolute_index].unit_index != animation->unit_index)
{
csmemset(&client_damage_animations[absolute_index], 0, sizeof(client_damage_animations[absolute_index]));
client_damage_animations[absolute_index].unit_index = animation->unit_index;
for (type = 0; type < NUMBER_OF_UNIT_DAMAGE_ANIMATIONS; type++)
client_damage_animations[absolute_index].time[type] = NONE;
}
/* (a pick sent again) */
else if (client_damage_animations[absolute_index].number[animation->type] == animation->number)
{
continue;
}
client_damage_animations[absolute_index].number[animation->type] = animation->number;
client_damage_animations[absolute_index].animation_index[animation->type] = animation->animation_index;
/* (replayed here already: switched to the host's if it has only just begun) */
client_damage_animations[absolute_index].time[animation->type] =
unit_port_correct_damage_animation(animation->unit_index, animation->type, animation->animation_index) ?
NONE : game_time_get();
}
}
/* ---------- the host */
static void distributed_change_from_object(
@@ -866,6 +1099,30 @@ static void distributed_host_update_objects(
}
}
/* The order a newly loaded client receives the host's objects in, most
needed first: players' units (it may spectate them), the vehicles players
and AI ride, other units, then everything else. */
enum
{
_send_rank_player_unit,
_send_rank_vehicle,
_send_rank_unit,
_send_rank_other,
NUMBER_OF_SEND_RANKS
};
static short distributed_object_send_rank(
long object_index)
{
struct object_datum *object = object_get(object_index);
if (object->object.type == _object_type_vehicle)
return _send_rank_vehicle;
if (object_try_and_get_and_verify_type(object_index, _object_mask_unit))
return unit_get(object_index)->unit.player_index != NONE ? _send_rank_player_unit : _send_rank_unit;
return _send_rank_other;
}
/* a client has loaded the game: every object the host has, to it alone,
and word that that is all of them; asked again, only the word (they are on
their way ahead of it), unless it failed to make one since it last asked
@@ -878,6 +1135,7 @@ void network_objects_client_asked(
short count = 0;
short limit = MIN(MAXIMUM_ENTRIES_PER_MESSAGE, RELIABLE_ENTRIES(struct distributed_object_change));
long absolute_index;
short rank;
long *player_list;
if (machine_index < 0 || machine_index >= HALO_PORT_MAXIMUM_NETWORK_MACHINES)
@@ -905,14 +1163,22 @@ void network_objects_client_asked(
/* (what every unit carries, with the next of them) */
objects_host_inventories[absolute_index].checksum = 0;
objects_host_inventories[absolute_index].weapons_checksum = 0;
if (objects_host_told[absolute_index] == NONE)
continue;
distributed_change_from_object(objects_host_told[absolute_index], &message.changes[count]);
if (++count == limit)
}
for (rank = 0; rank < NUMBER_OF_SEND_RANKS; rank++)
{
for (absolute_index = 0; absolute_index < objects_host_told_count; absolute_index++)
{
distributed_send_to_machine_reliably(machine_index, &message, _distributed_message_object_changes, count,
(word)(sizeof(message.header) + count * sizeof(struct distributed_object_change)));
count = 0;
long object_index = objects_host_told[absolute_index];
if (object_index == NONE || distributed_object_send_rank(object_index) != rank)
continue;
distributed_change_from_object(object_index, &message.changes[count]);
if (++count == limit)
{
distributed_send_to_machine_reliably(machine_index, &message, _distributed_message_object_changes, count,
(word)(sizeof(message.header) + count * sizeof(struct distributed_object_change)));
count = 0;
}
}
}
if (count)
@@ -957,8 +1223,24 @@ static void distributed_host_find_viewers(
{
short machine_number;
struct data_iterator iterator;
struct player_datum *player;
objects_host_viewers.count = distributed_client_machines(objects_host_viewers.indices,
HALO_PORT_MAXIMUM_NETWORK_MACHINES);
objects_host_viewers.player_unit_count = 0;
data_iterator_new(&iterator, player_data);
while ((player = data_iterator_next(&iterator)) != NULL &&
objects_host_viewers.player_unit_count < MAXIMUM_TRACKED_PLAYERS)
{
long unit_index = distributed_living_unit(player);
if (unit_index != NONE)
{
object_get_origin(unit_index,
&objects_host_viewers.player_unit_origins[objects_host_viewers.player_unit_count++]);
}
}
for (machine_number = 0; machine_number < objects_host_viewers.count; machine_number++)
{
long *player_list = machine_get_player_list(objects_host_viewers.indices[machine_number]);
@@ -990,19 +1272,32 @@ static void distributed_host_find_viewers(
}
}
/* how often (ticks) the host sends that client machine an object where it
is, moving: by its nearest player; every tick to one with none in the
world (dead, it watches anyone) */
/* How often, in ticks, the host sends a moving object's position to a
client machine, based on its distance from that machine's nearest player.
A machine with no player in the world (dead or joining) spectates someone,
so the distance is measured from every player instead. Sending such a
machine every moving object every tick flooded it on campaign levels and
threw everything it saw out of sync. */
static short distributed_host_object_period(
short machine_number,
real_point3d const *position)
{
short count = objects_host_viewers.machines[machine_number].unit_count;
real_point3d const *origins = objects_host_viewers.machines[machine_number].origins;
real nearest = -1.0f;
short index;
for (index = 0; index < objects_host_viewers.machines[machine_number].unit_count; index++)
if (!count)
{
real_point3d const *origin = &objects_host_viewers.machines[machine_number].origins[index];
count = objects_host_viewers.player_unit_count;
origins = objects_host_viewers.player_unit_origins;
}
/* nobody is alive anywhere, so nothing needs to be sent often */
if (!count)
return MAXIMUM_OBJECT_PERIOD_TICKS;
for (index = 0; index < count; index++)
{
real_point3d const *origin = &origins[index];
real dx = position->x - origin->x;
real dy = position->y - origin->y;
real dz = position->z - origin->z;
@@ -1016,6 +1311,21 @@ static short distributed_host_object_period(
nearest < FAR_OBJECT_DISTANCE * FAR_OBJECT_DISTANCE ? 3 : MAXIMUM_OBJECT_PERIOD_TICKS;
}
/* ... for other units sent by a machine's index (network_actors.c) */
short network_objects_send_period(
long machine_index,
real_point3d const *position)
{
short machine_number;
for (machine_number = 0; machine_number < objects_host_viewers.count; machine_number++)
{
if (objects_host_viewers.indices[machine_number] == machine_index)
return distributed_host_object_period(machine_number, position);
}
return 1;
}
/* the kinds of states sent this tick */
enum
{
@@ -1485,6 +1795,10 @@ void network_objects_apply_vehicle_predictions(
{
continue;
}
/* (not from a co-op client still loading the host's BSP: the
vehicle falls there with no ground under it) */
if (!network_coop_player_has_structure_bsp(driver->unit.player_index))
continue;
dx = state->position.x - vehicle->object.position.x;
dy = state->position.y - vehicle->object.position.y;
dz = state->position.z - vehicle->object.position.z;
@@ -1633,6 +1947,7 @@ void network_objects_host_tick(
distributed_host_send_states();
if (game_time_get() % INVENTORY_INTERVAL_TICKS == 0)
distributed_host_send_inventories();
distributed_host_send_damage_animations();
}
/* ---------- a client */
@@ -1827,6 +2142,19 @@ static void distributed_client_apply_change(
struct object_datum *object = object_get(object_index);
csmemcpy(object->object.base_change_colors, change->change_colors, sizeof(object->object.base_change_colors));
/* (and the colors drawn, which object_new chose from the tag: an AI unit's
are its variant's, set after it was made, actors.c) */
{
short color_index;
for (color_index = 0; color_index < NUMBER_OF_OBJECT_CHANGE_COLORS; color_index++)
{
object->object.outgoing_change_colors[color_index].red = PIN(change->change_colors[color_index].red, 0.0f, 1.0f);
object->object.outgoing_change_colors[color_index].green =
PIN(change->change_colors[color_index].green, 0.0f, 1.0f);
object->object.outgoing_change_colors[color_index].blue = PIN(change->change_colors[color_index].blue, 0.0f, 1.0f);
}
}
/* (a permutation the model has, or none: the model's renderer takes it
as it is) */
{
@@ -2081,6 +2409,20 @@ static void distributed_client_dead_biped(
}
}
/* client: a vehicle the host says is dead is destroyed here too, with its
explosion. No killing blow comes for vehicles, only for bipeds. */
static void distributed_client_dead_vehicle(
long object_index)
{
struct unit_datum *vehicle = (struct unit_datum *)object_try_and_get_and_verify_type(object_index,
_object_mask_vehicle);
if (!vehicle || TEST_FLAG(vehicle->object.damage_flags, _object_dead_bit))
return;
unit_kill_no_statistics(object_index);
object_damage_update(object_index);
}
void network_objects_handle_states(
void const *entries,
short count)
@@ -2104,6 +2446,7 @@ void network_objects_handle_states(
if (TEST_FLAG(state->flags, _distributed_object_dead_bit))
{
distributed_client_dead_biped(state->object_index);
distributed_client_dead_vehicle(state->object_index);
/* (a body its tag destroys at once is gone) */
if (!object_try_and_get_and_verify_type(state->object_index, _object_mask_all))
continue;
@@ -2136,6 +2479,12 @@ void network_objects_handle_states(
if (blend_distance > 0.0f)
blend_distance = REMOTE_VEHICLE_BLEND_DISTANCE;
/* (one no player drives follows every move the host sends, however small) */
if (distributed_vehicle_unsteered(state->object_index))
{
tolerance = 0.0f;
angle_tolerance = 2.0f;
}
if (vehicle->unit.driver_object_index != NONE &&
distributed_player_is_local(unit_get(vehicle->unit.driver_object_index)->unit.player_index))
{
@@ -2166,7 +2515,8 @@ void network_objects_handle_states(
{
distributed_count_correction();
}
SET_FLAG(object->object.flags, _object_at_rest_bit, TEST_FLAG(state->flags, _distributed_object_at_rest_bit));
SET_FLAG(object->object.flags, _object_at_rest_bit, TEST_FLAG(state->flags, _distributed_object_at_rest_bit) ||
distributed_vehicle_unsteered(state->object_index));
}
}
@@ -2377,6 +2727,68 @@ static void distributed_client_apply_inventory(
distributed_client_note_own_inventory(own, inventory->unit_index, FALSE);
}
/* a client's own player picked up a weapon (network_player_show_pickup) */
void network_objects_client_picked_up_weapon(
short local_player_index,
long unit_index,
long definition_index)
{
struct distributed_picked_up_weapon *picked_up;
if (local_player_index < 0 || local_player_index >= MAXIMUM_LOCAL_PLAYERS)
return;
picked_up = &objects_client_picked_up_weapons[local_player_index];
picked_up->unit_index = unit_index;
picked_up->definition_index = definition_index;
picked_up->time = game_time_get();
}
/* the weapons its own players picked up readied once they have them, as
unit_add_weapon_to_inventory readies a pickup where it decides it (not
while firing): the client chooses its players' weapons in hand
(distributed_client_apply_inventory), and the host follows */
static void distributed_client_ready_picked_up_weapons(
void)
{
short local_player_index;
for (local_player_index = 0; local_player_index < MAXIMUM_LOCAL_PLAYERS; local_player_index++)
{
struct distributed_picked_up_weapon *picked_up = &objects_client_picked_up_weapons[local_player_index];
long player_index = local_player_get_player_index(local_player_index);
struct player_datum *player = player_index != NONE ? player_try_and_get(player_index) : NULL;
long unit_index = distributed_living_unit(player);
struct unit_datum *unit;
short weapon_slot;
if (picked_up->definition_index == NONE)
continue;
if (unit_index == NONE || unit_index != picked_up->unit_index ||
game_time_get() - picked_up->time > PICKED_UP_WEAPON_TICKS)
{
picked_up->definition_index = NONE;
continue;
}
unit = unit_get(unit_index);
for (weapon_slot = 0; weapon_slot < MAXIMUM_WEAPONS_PER_UNIT; weapon_slot++)
{
long weapon_index = unit->unit.weapon_object_indices[weapon_slot];
struct weapon_datum *weapon = weapon_index != NONE ? weapon_try_and_get(weapon_index) : NULL;
if (weapon && weapon->definition_index == picked_up->definition_index)
break;
}
if (weapon_slot == MAXIMUM_WEAPONS_PER_UNIT)
continue;
if (!TEST_FLAG(unit->unit.control_flags, _unit_control_weapon_primary_trigger_bit))
{
player_control_set_desired_weapon(unit_index, weapon_slot);
unit->unit.desired_weapon_index = weapon_slot;
}
picked_up->definition_index = NONE;
}
}
void network_objects_handle_inventories(
void const *entries,
short count)
@@ -2525,6 +2937,51 @@ static void distributed_client_remove_own_objects(
objects_client_new_object_count = 0;
}
/* Client: keeps each AI-driven vehicle (such as a Pelican on its flight
path) moving at the velocity the host last sent. These vehicles are held at
rest here, and a distant one is only updated every few ticks, so otherwise
it would stop between updates and jump on each one. */
static void distributed_client_carry_unsteered_vehicles(
void)
{
struct object_iterator iterator;
struct object_datum *object;
object_iterator_new(&iterator, _object_mask_vehicle, 0);
while ((object = object_iterator_next(&iterator)) != NULL)
{
real_vector3d const *velocity = &object->object.translational_velocity;
real_vector3d axis = object->object.angular_velocity;
real_vector3d forward = object->object.forward;
real_vector3d up = object->object.up;
real_point3d position;
real angle;
if (object->object.parent_object_index != NONE || unit_get(iterator.index)->unit.driver_object_index == NONE ||
!distributed_vehicle_unsteered(iterator.index))
{
continue;
}
angle = normalize3d(&axis);
if (velocity->i == 0.0f && velocity->j == 0.0f && velocity->k == 0.0f && angle == 0.0f)
continue;
position.x = object->object.position.x + velocity->i;
position.y = object->object.position.y + velocity->j;
position.z = object->object.position.z + velocity->k;
/* rotate the same way physics.c applies angular velocity */
if (angle != 0.0f)
{
real_matrix4x3 rotation;
matrix4x3_rotation_from_axis_and_angle(&rotation, &axis, (real)sin(angle), (real)cos(angle));
matrix4x3_transform_vector(&rotation, &object->object.forward, &forward);
matrix4x3_transform_vector(&rotation, &object->object.up, &up);
}
if (distributed_transform_valid(&position, &forward, &up, NULL, NULL, &forward, &up))
object_set_position(iterator.index, &position, &forward, &up);
}
}
void network_objects_client_tick(
void)
{
@@ -2549,8 +3006,10 @@ void network_objects_client_tick(
/* (too many to look at one by one later: all of them) */
else if (objects_client_new_object_count >= MAXIMUM_CLIENT_NEW_OBJECTS)
objects_client_check_all = TRUE;
distributed_client_ready_picked_up_weapons();
distributed_client_note_own_inventories();
distributed_client_send_vehicles();
distributed_client_carry_unsteered_vehicles();
/* (who it is, as its Discord told it: once its ready went, which makes
it a machine the host takes messages of) */
if (objects_client_ready_time != NONE)
@@ -2568,6 +3027,8 @@ void network_objects_new_game(
short index;
csmemset(objects_host_inventories, 0, sizeof(objects_host_inventories));
host_damage_animation_count = 0;
csmemset(client_damage_animations, 0, sizeof(client_damage_animations));
for (absolute_index = 0; absolute_index < MAXIMUM_TRACKED_OBJECTS; absolute_index++)
{
objects_host_told[absolute_index] = NONE;
@@ -2606,6 +3067,7 @@ void network_objects_new_game(
for (local_player_index = 0; local_player_index < MAXIMUM_LOCAL_PLAYERS; local_player_index++)
{
objects_client_own_inventories[local_player_index].unit_index = NONE;
objects_client_picked_up_weapons[local_player_index].definition_index = NONE;
for (index = 0; index < OWN_VEHICLE_POSITION_TICKS; index++)
{
objects_client_own_vehicles[local_player_index][index].time = NONE;
+3 -3
View File
@@ -1,4 +1,4 @@
/* the game includes <StdDef.h>; Linux file names are case sensitive.
#include_next, since on a case-insensitive file system (macOS) this file
is also what <stddef.h> finds */
/* the game includes <StdDef.h>; Linux file names are case sensitive. On a
case-insensitive file system (macOS) a plain <stddef.h> would find this file
again; include_next goes to the real one, as the other shims do. */
#include_next <stddef.h>
+15 -3
View File
@@ -24,15 +24,27 @@ state above the tag cache (which ends at 0x819A6000), inside the Xbox memory
window (0x80000000-0x88000000, port/linux/src/platform.h) and below everything
the window hands out top-down (texture and sound caches, Direct3D resources).
The CPU part holds about 13.6 MB of pools at the sizes below (the Xbox pools
The CPU part holds about 17.2 MB of pools at the sizes below (the Xbox pools
fill 3,165,260 of its 0x305000 bytes); the GPU part holds only the decal
vertices, as on the Xbox. */
vertices, as on the Xbox. A change to a pool's size changes the game state's
layout: saved games of builds before it no longer load. */
#define HALO_PORT_GAME_STATE_BASE_ADDRESS 0x81A00000 /* (0x80061000) */
#define HALO_PORT_GAME_STATE_CPU_SIZE 0xFC0000 /* (0x305000) */
#define HALO_PORT_GAME_STATE_CPU_SIZE 0x13C0000 /* (0x305000) */
#define HALO_PORT_GAME_STATE_GPU_SIZE 0x40000 /* (0x40000) */
#define HALO_PORT_GAME_STATE_SIZE (HALO_PORT_GAME_STATE_CPU_SIZE+HALO_PORT_GAME_STATE_GPU_SIZE)
/* ---------- AI
Network co-op adds enemies for its players (port/linux/game/coop_enemies.c):
the actors, and their knowledge of the units about them (props: with many
players, more each), have room for several times a level's own. */
#define HALO_PORT_MAXIMUM_ACTORS 1024 /* (256) */
#define HALO_PORT_MAXIMUM_PROPS 8192 /* (768) */
#define HALO_PORT_MAXIMUM_SWARMS 128 /* (32) */
#define HALO_PORT_MAXIMUM_SWARM_COMPONENTS 1024 /* (256) */
/* ---------- objects */
#define HALO_PORT_MAXIMUM_OBJECTS_PER_MAP 8192 /* (2048) */
+1 -1
View File
@@ -66,7 +66,7 @@ is newer (network_client_manager.c). A host advertises it, with its netcode,
in its game's advertisement's reserved bytes (network_server_message_handler.c),
which hosts built before there was a version send as zeros: version 0.
Raise it with any change to what the machines send each other. */
#define HALO_PORT_NETWORK_VERSION 11
#define HALO_PORT_NETWORK_VERSION 16
/* ... the advertisement's reserved bytes: the version (a little-endian word),
then flags */
#define HALO_PORT_ADVERTISED_VERSION_OFFSET 0
+15
View File
@@ -201,6 +201,9 @@ driver's hands on it as drawn (world units, from the game's camera), or
NULL; the player's own hands turn it. And whether they hold it. */
void halo_vr_set_wheel(short local_player_index, const float left[3], const float right[3]);
int halo_vr_wheel_held(void);
/* the controllers' layout (HALO_XR_LAYOUT_*: 0 the Quest's, 1 the Steam
Frame's), for what the game tells the player */
int halo_vr_controller_layout(void);
/* whether a seated player's view stays in first person (director.c) */
int halo_vr_vehicle_first_person(void);
/* VR test aid (debug.vehicle_spawn): both sticks held in for a moment asks
@@ -244,6 +247,18 @@ void halo_vr_network_grenade_thrown(short local_player_index, long unit_index, c
/* the platform layer's side (vr.c) */
void halo_vr_initialize(void);
void halo_vr_frame_begin(void);
/* vr.log_performance: the end of a part of the frame, for the report: the
input and network, the game's ticks (how many), the camera and director,
the drawing; the rest is presenting */
enum
{
HALO_VR_PHASE_INPUT,
HALO_VR_PHASE_TICKS,
HALO_VR_PHASE_CAMERA,
HALO_VR_PHASE_DRAW,
HALO_VR_PHASE_COUNT
};
void halo_vr_phase(int phase, int ticks);
void halo_vr_present(unsigned int back_buffer_texture);
/* the eye image size: the back buffer's size in pixels in VR */
int halo_vr_eye_size(int *width, int *height);
+73 -31
View File
@@ -61,17 +61,19 @@ struct xgpu_capabilities xgpu_capabilities;
The Xbox screen is 640x480. The native ports can draw a wider one: 480
lines, and as many columns as the display's shape gives. On Android that is
display.screen_width (port_config.c; 640 keeps 4:3); on the desktop, the
display's shape while the game is fullscreen, and 640 in a window. The
game's camera derives its horizontal field of view from the viewport, so the
3D view simply widens. The menus and full-screen overlays are laid out for
640 columns; while they draw (halo_screen_ui_offset), everything shifts right
to center them.
shape of the window (of the display while the game is fullscreen, or of
display.resolution), and 640 where display.resolution_scaling is "original".
The game's camera derives its horizontal field of view from the viewport, so
the 3D view simply widens. The menus and full-screen overlays are laid out
for 640 columns; while they draw (halo_screen_ui_offset), everything shifts
right to center them.
Fullscreen on the desktop also draws at the display's resolution: render
The desktop also draws at that resolution (platform_screen_mode): render
targets the size of the screen get that many pixels (screen_scale), and
viewports, clears and visibility counts are scaled to match, so the game
still works in its 480 lines. The width and the scale change only between
frames, after one is presented (halo_screen_commit). */
still works in its 480 lines; "original" draws 640x480, scaled up at
presentation. The width and the scale change only between frames, after one
is presented (halo_screen_commit). */
#define SCREEN_HEIGHT 480
#define SCREEN_MAXIMUM_WIDTH 1920
@@ -1364,25 +1366,6 @@ HRESULT WINAPI Direct3D_CreateDevice(UINT adapter, D3DDEVTYPE device_type, void
/* ---------- the menus' pointer */
#ifdef HALO_ANDROID
/* the controller pointing at the menus' screen in VR (halo_vr_menu_pointer) */
int halo_ui_pointer_update(int menus_active, struct halo_ui_pointer *pointer)
{
int x, y, click_x, click_y, moved, clicks;
platform_menus_set_active(menus_active != 0);
if (!menus_active || !halo_vr_menu_pointer(&x, &y, &click_x, &click_y, &moved, &clicks))
return 0;
memset(pointer, 0, sizeof(*pointer));
pointer->x = (short)(x - (halo_screen_width() - 640) / 2);
pointer->y = (short)y;
pointer->click_x = (short)(click_x - (halo_screen_width() - 640) / 2);
pointer->click_y = (short)click_y;
pointer->moved = (unsigned char)(moved != 0);
pointer->left_clicks = (unsigned char)(clicks < 255 ? clicks : 255);
return 1;
}
#else
/* a point in the window, as SDL reports it, in the menus' coordinates: the
inverse of the letterboxed display blit at presentation, the screen's
width and the menus' centering (halo_screen_ui_offset) */
@@ -1414,6 +1397,47 @@ static void ui_point_from_window(float window_x, float window_y, short *x, short
*y = (short)floorf(screen_y);
}
#ifdef HALO_ANDROID
BOOL platform_flat_mouse(float *x, float *y);
/* the controller pointing at the menus' screen in VR (halo_vr_menu_pointer);
flat (the emulator), the mouse */
int halo_ui_pointer_update(int menus_active, struct halo_ui_pointer *pointer)
{
int x, y, click_x, click_y, moved, clicks;
platform_menus_set_active(menus_active != 0);
if (menus_active && !halo_vr_active() && device.gl_ready)
{
static BOOL was_down;
static short last_x, last_y;
float window_x, window_y;
BOOL down = platform_flat_mouse(&window_x, &window_y);
memset(pointer, 0, sizeof(*pointer));
ui_point_from_window(window_x, window_y, &pointer->x, &pointer->y);
pointer->click_x = pointer->x;
pointer->click_y = pointer->y;
pointer->moved = pointer->x != last_x || pointer->y != last_y;
pointer->left_clicks = (unsigned char)(down && !was_down);
last_x = pointer->x;
last_y = pointer->y;
was_down = down;
return 1;
}
if (!menus_active || !halo_vr_menu_pointer(&x, &y, &click_x, &click_y, &moved, &clicks))
return 0;
memset(pointer, 0, sizeof(*pointer));
pointer->x = (short)(x - (halo_screen_width() - 640) / 2);
pointer->y = (short)y;
pointer->click_x = (short)(click_x - (halo_screen_width() - 640) / 2);
pointer->click_y = (short)click_y;
pointer->moved = (unsigned char)(moved != 0);
pointer->left_clicks = (unsigned char)(clicks < 255 ? clicks : 255);
return 1;
}
#else
int halo_ui_pointer_update(int menus_active, struct halo_ui_pointer *pointer)
{
struct platform_ui_pointer state;
@@ -2463,6 +2487,10 @@ static GLuint mip_composite_get(const struct xgpu_texture_description *descripti
static void bind_textures(struct nv2a_pixel_shader_key *key, float texture_scale[4][4])
{
/* Bind only after resolving every stage, since texture uploads can
overwrite the active unit's binding. */
GLenum gl_targets[D3DTSS_MAXSTAGES];
GLuint gl_textures[D3DTSS_MAXSTAGES];
int stage;
for (stage = 0; stage < D3DTSS_MAXSTAGES; stage++)
@@ -2474,7 +2502,8 @@ static void bind_textures(struct nv2a_pixel_shader_key *key, float texture_scale
texture_scale[stage][2] = texture_scale[stage][3] = 1.0f;
if (!texture || !texture->Data || mode == 0 || mode == 0x04 || mode == 0x05 || mode == 0x11)
{
state_texture(stage, GL_TEXTURE_2D, 0);
gl_targets[stage] = GL_TEXTURE_2D;
gl_textures[stage] = 0;
key->sampler_type[stage] = mode == 0x11 ? _xgpu_sampler_2d : _xgpu_sampler_none;
continue;
}
@@ -2530,7 +2559,8 @@ static void bind_textures(struct nv2a_pixel_shader_key *key, float texture_scale
texture_scale[stage][1] = 1.0f / (float)description.height;
}
}
state_texture(stage, gl_target, gl_texture);
gl_targets[stage] = gl_target;
gl_textures[stage] = gl_texture;
state_sampler(stage, device.samplers[stage]);
configure_sampler(stage, description.levels > 1, description.hires);
if (stage == 0)
@@ -2539,6 +2569,8 @@ static void bind_textures(struct nv2a_pixel_shader_key *key, float texture_scale
gl_target == GL_TEXTURE_3D ? _xgpu_sampler_3d : _xgpu_sampler_2d;
}
}
for (stage = 0; stage < D3DTSS_MAXSTAGES; stage++)
state_texture(stage, gl_targets[stage], gl_textures[stage]);
}
static GLenum stencil_operation(DWORD operation)
@@ -2863,7 +2895,15 @@ static struct program_entry *prepare_draw(BOOL immediate)
key.count_samples = device.visibility_test_active && xgpu_capabilities.atomic_counters;
#endif
entry = program_get(vertex_shader_get(program, immediate, targets_multiview), fragment_shader_get(&key));
entry = program_get(vertex_shader_get(program, immediate,
#ifdef HALO_ANDROID
/* the bound targets are the layers (Android's GL_OVR_multiview2);
on the desktop there are no layers to stand in for the back buffer */
targets_multiview
#else
FALSE
#endif
), fragment_shader_get(&key));
if (!entry)
{
stats.skipped_link++;
@@ -4023,7 +4063,9 @@ void d3d8_clear_back_buffer(float red, float green, float blue, float alpha)
glDepthMask(GL_TRUE);
glStencilMask(0xff);
glClearColor(red, green, blue, alpha);
glClearDepthf(1.0f);
/* (glClearDepth: on Android the define above maps it to glClearDepthf,
ES's float entry point) */
glClearDepth(1.0f);
glClearStencil(0);
glClear(GL_COLOR_BUFFER_BIT | (depth_buffer ? GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT : 0));
xgpu_gl_state_invalidate();
+22 -14
View File
@@ -249,9 +249,7 @@ char *nv2a_vertex_shader_to_glsl(const DWORD *instructions, unsigned long instru
"\tvec4 oFog = vec4(1.0), oPts = vec4(point_size), oUnused = vec4(0.0);\n"
"\tint a0 = 0;\n"
"\tvec4 A, B, C, mac, ilu;\n");
#ifdef HALO_ANDROID
xgpu_text_append(&text, "\tvec4 clip_position = vec4(0.0);\n\tbool clip_captured = false;\n");
#endif
for (index = 0; index < instruction_count; index++)
{
@@ -303,7 +301,6 @@ char *nv2a_vertex_shader_to_glsl(const DWORD *instructions, unsigned long instru
case _ilu_lit: xgpu_text_append(&text, "\tilu = nv2a_lit(C);\n"); break;
default: xgpu_text_append(&text, "\tilu = vec4(0.0);\n"); break;
}
#ifdef HALO_ANDROID
/* the screen-space conversion takes the reciprocal of the clip-space
position's w (rcc of r12.w); keep the position it converts */
if (ilu == _ilu_rcc && field(instruction, 3, 28, 2) == _mux_temporary &&
@@ -311,7 +308,6 @@ char *nv2a_vertex_shader_to_glsl(const DWORD *instructions, unsigned long instru
{
xgpu_text_append(&text, "\tclip_position = oPos;\n\tclip_captured = true;\n");
}
#endif
/* results are written only after both units have read their inputs */
if (mac == _mac_arl)
@@ -357,21 +353,33 @@ char *nv2a_vertex_shader_to_glsl(const DWORD *instructions, unsigned long instru
/* Direct3D 8 puts pixel centres on integer screen coordinates (the
game offsets its screen-space quads by -0.5 to match), OpenGL on
half-integers */
#ifdef HALO_ANDROID
/* The conversion is screen = clip * c[-38] * rcc(w) + c[-37]; undoing
it by multiplying by w again is lossy near the camera plane, where
rcc clamps and 1/w rounds differently on each GPU (Mali put vertices
of the first-person weapon at the vanishing point). Where the clip
position was kept, the same result is computed without dividing. */
"\tvec4 position;\n"
"\tif (clip_captured)\n"
"\t\tgl_Position = vec4((clip_position.xyz * c[%d].xyz + (c[%d].xyz + vec3(0.5 + screen_offset, 0.5, 0.0)\n"
"\t\tposition = vec4((clip_position.xyz * c[%d].xyz + (c[%d].xyz + vec3(0.5 + screen_offset, 0.5, 0.0)\n"
"\t\t\t- viewport_offset.xyz) * clip_position.w) / scale, clip_position.w);\n"
"\telse\n"
"\t\tgl_Position = vec4((vec3(oPos.xy + vec2(0.5 + screen_offset, 0.5), oPos.z) - viewport_offset.xyz) / scale * oPos.w, oPos.w);\n"
#else
"\tvec3 ndc = (vec3(oPos.xy + vec2(0.5 + screen_offset, 0.5), oPos.z) - viewport_offset.xyz) / scale;\n"
"\tgl_Position = vec4(ndc * oPos.w, oPos.w);\n"
#endif
"\t{\n"
"\t\tvec3 ndc = (vec3(oPos.xy + vec2(0.5 + screen_offset, 0.5), oPos.z) - viewport_offset.xyz) / scale;\n"
"\t\tposition = vec4(ndc * oPos.w, oPos.w);\n"
"\t}\n"
/* A position whose w is zero, or is not a number, is the clip-space
origin: the screen conversion's reciprocal is clamped rather than
infinite, so a large position times a w of zero is exactly zero, and
the origin is inside the frustum. Nothing then clips the triangle
away and OpenGL divides zero by zero there: the vertex lands on the
middle of the screen and the triangle is drawn out to it from the
first-person weapon, whose pose follows the camera and so reaches the
camera plane. The divide on the Xbox sends such a vertex to infinity
and the clipper takes the triangle; put it behind the camera instead,
which the clipper also takes. */
"\tif (!(abs(position.w) > 0.0))\n"
"\t\tposition = vec4(0.0, 0.0, 0.0, -1.0);\n"
"\tgl_Position = position;\n"
#ifdef HALO_ANDROID
/* what glClipControl(GL_UPPER_LEFT, GL_ZERO_TO_ONE) does on desktop
GL: rows from the top, depth 0..1 */
@@ -389,16 +397,16 @@ char *nv2a_vertex_shader_to_glsl(const DWORD *instructions, unsigned long instru
"\txT2 = oT2;\n"
"\txT3 = oT3;\n"
"\txFog = oFog.x;\n"
"}\n"
"}\n",
XGPU_VERTEX_CONSTANT_BIAS - 38, XGPU_VERTEX_CONSTANT_BIAS - 37
#ifdef HALO_ANDROID
, XGPU_VERTEX_CONSTANT_BIAS - 38, XGPU_VERTEX_CONSTANT_BIAS - 37,
/* (what is drawn in screen space, which kept no clip position, is
taken to each view as though infinitely far: a lens flare's sun
lands where the sky's does) */
/* (what the game projects itself, a sprite or a lens flare's
test, comes as a screen position with w 1 and its depth in z: its
eye's offset is by that depth, where it is depth tested) */
multiview ?
, multiview ?
"\t{\n"
"\t\tint row = int(gl_ViewID_OVR) * 2;\n"
"\t\tfloat near = 0.0;\n"
+135 -21
View File
@@ -274,7 +274,7 @@ struct stun_server
struct p2p_candidate mapped;
};
static pthread_mutex_t p2p_lock = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t p2p_lock = PTHREAD_MUTEX_INITIALIZER;
static struct
{
@@ -316,6 +316,11 @@ static struct
int hosting_lan_only;
int has_token;
unsigned char token[P2P_TOKEN_SIZE];
/* whether the server browser's exit hook is set (lobby_quit) */
int lobby_quit_registered;
/* whether the server browser listed this token (p2p_lobby.c): going
private makes a new one */
int token_listed;
char invite[P2P_LINK_SIZE];
int invite_copied;
/* the game's players and its most (p2p_set_game_player_counts; 0: not
@@ -355,7 +360,11 @@ p2p.local_address) */
static unsigned short proxy_by_port[65536];
static unsigned char identifier[P2P_IDENTIFIER_SIZE];
/* this run's X25519 keys, which the identifier comes from */
/* this run's X25519 keys, which the identifier comes from: from an Ed25519
seed, whose key signs the listing of a public game (p2p_lobby.c), so that a
listing's key is also the invite's */
static unsigned char seed[P2P_SEED_SIZE];
static unsigned char signing_key[P2P_KEY_SIZE];
static unsigned char secret_key[P2P_KEY_SIZE];
static unsigned char public_key[P2P_KEY_SIZE];
static int has_identifier;
@@ -503,7 +512,8 @@ const unsigned char *p2p_identifier(void)
pthread_mutex_lock(&identifier_lock);
if (!has_identifier)
{
posix_random_bytes(secret_key, sizeof(secret_key));
posix_random_bytes(seed, sizeof(seed));
p2p_ed25519_public(seed, signing_key, secret_key);
p2p_x25519(public_key, secret_key, NULL);
p2p_identifier_for(public_key, identifier);
has_identifier = 1;
@@ -542,6 +552,18 @@ const unsigned char *p2p_public_key(void)
return public_key;
}
const unsigned char *p2p_signing_key(void)
{
p2p_identifier();
return signing_key;
}
void p2p_sign(const void *message, int size, unsigned char *signature)
{
p2p_identifier();
p2p_ed25519_sign(seed, signing_key, message, size, signature);
}
int p2p_shared_secret(const unsigned char *key, unsigned char *shared)
{
static const unsigned char zero[P2P_KEY_SIZE];
@@ -2362,6 +2384,8 @@ void p2p_set_public_game(int public_game)
pthread_mutex_lock(&p2p_lock);
p2p_list_set_public(public_game);
pthread_mutex_unlock(&p2p_lock);
/* (and in the server browser of every build: p2p_lobby.c) */
p2p_set_hosting_public(public_game);
}
int p2p_public_game(void)
@@ -2382,13 +2406,47 @@ void p2p_set_game_description(const char *name, const char *map, const char *mod
pthread_mutex_unlock(&p2p_lock);
}
/* the server browser's games first (every build lists its public games
there: PC, phones, VR), then the VR port's own list's that it has not */
int p2p_public_games(struct p2p_public_game *games, int maximum)
{
int count;
struct p2p_listing listings[32];
struct p2p_public_game own[32];
int listing_count;
int own_count;
int count = 0;
int index;
p2p_lobby_browse(1);
listing_count = p2p_lobby_games(listings, 32);
for (index = 0; index < listing_count && count < maximum; index++)
{
struct p2p_public_game *game = &games[count++];
memset(game, 0, sizeof(*game));
snprintf(game->name, sizeof(game->name), "%s", listings[index].name);
snprintf(game->map, sizeof(game->map), "%s", listings[index].map);
snprintf(game->mode, sizeof(game->mode), "%s", listings[index].gametype);
snprintf(game->invite, sizeof(game->invite), "%s", listings[index].invite);
game->players = listings[index].player_count;
game->maximum_players = listings[index].maximum_player_count;
}
pthread_mutex_lock(&p2p_lock);
count = p2p.running ? p2p_list_games(games, maximum) : 0;
own_count = p2p.running ? p2p_list_games(own, 32) : 0;
pthread_mutex_unlock(&p2p_lock);
for (index = 0; index < own_count && count < maximum; index++)
{
int other;
int listed = 0;
for (other = 0; other < listing_count; other++)
{
if (!strcmp(own[index].name, listings[other].name) && !strcmp(own[index].map, listings[other].map))
listed = 1;
}
if (!listed)
games[count++] = own[index];
}
return count;
}
@@ -2455,27 +2513,55 @@ static int connected_player_count(void)
return count;
}
/* a new invite (a new token) */
static void make_invite(void)
{
unsigned char bytes[P2P_KEY_HASH_SIZE + P2P_TOKEN_SIZE];
char text[2 * (P2P_KEY_HASH_SIZE + P2P_TOKEN_SIZE) + 1];
posix_random_bytes(p2p.token, sizeof(p2p.token));
p2p.has_token = 1;
p2p.token_listed = 0;
p2p_key_hash(p2p_public_key(), bytes);
memcpy(bytes + P2P_KEY_HASH_SIZE, p2p.token, P2P_TOKEN_SIZE);
p2p_hex(bytes, sizeof(bytes), text);
snprintf(p2p.invite, sizeof(p2p.invite), "halo://join/%s", text);
}
void p2p_new_invite_if_listed(void)
{
if (!p2p.has_token || !p2p.token_listed)
return;
make_invite();
platform_log("Internet play: the game is private now, with a new invite: %s", p2p.invite);
if (p2p.hosting)
{
p2p_signal_host(p2p.token);
memcpy(p2p.clipboard, p2p.invite, sizeof(p2p.clipboard));
p2p.has_clipboard = 1;
/* (Discord is told the new one) */
p2p.reported_player_count = -1;
}
}
/* the hosted game's players, as the game says; else the host and the
machines the tunnel reaches */
static void hosted_player_counts(int *count, int *maximum)
{
*count = p2p.game_player_maximum > 0 ? p2p.game_player_count : connected_player_count() + 1;
*maximum = p2p.game_player_maximum > 0 ? p2p.game_player_maximum : P2P_MAXIMUM_PEERS + 1;
}
static void update_hosting(void)
{
int want = p2p.hosting_socket >= 0 && !p2p.hosting_lan_only;
if (want && !p2p.hosting)
{
char text[2 * (P2P_KEY_HASH_SIZE + P2P_TOKEN_SIZE) + 1];
/* one invite for the whole run, so a link keeps working from game
to game */
if (!p2p.has_token)
{
unsigned char bytes[P2P_KEY_HASH_SIZE + P2P_TOKEN_SIZE];
posix_random_bytes(p2p.token, sizeof(p2p.token));
p2p.has_token = 1;
p2p_key_hash(p2p_public_key(), bytes);
memcpy(bytes + P2P_KEY_HASH_SIZE, p2p.token, P2P_TOKEN_SIZE);
p2p_hex(bytes, sizeof(bytes), text);
snprintf(p2p.invite, sizeof(p2p.invite), "halo://join/%s", text);
}
make_invite();
p2p.hosting = 1;
p2p.stun_started = 1;
p2p_signal_start();
@@ -2507,11 +2593,9 @@ static void update_hosting(void)
}
if (p2p.hosting)
{
/* the game's players, as the game says; else the host and the
machines the tunnel reaches */
int count = p2p.game_player_maximum > 0 ? p2p.game_player_count : connected_player_count() + 1;
int maximum = p2p.game_player_maximum > 0 ? p2p.game_player_maximum : P2P_MAXIMUM_PEERS + 1;
int count, maximum;
hosted_player_counts(&count, &maximum);
if (count != p2p.reported_player_count || maximum != p2p.reported_player_maximum)
{
p2p.reported_player_count = count;
@@ -2601,6 +2685,15 @@ static void *upnp_thread(void *unused)
return NULL;
}
/* quitting: a game listed in the server browser is taken out of it at once
(not when its listing lapses), as when it stops being hosted */
static void lobby_quit(void)
{
pthread_mutex_lock(&p2p_lock);
p2p_lobby_quit();
pthread_mutex_unlock(&p2p_lock);
}
/* the game exits: the router forwards the port no longer (after a request
under way, which may forward one, if it ends soon) */
static void upnp_release(void)
@@ -2637,6 +2730,9 @@ static int upnp_needed(void)
if (p2p.joining && elapsed(p2p.join_time, UPNP_JOIN_DELAY))
return 1;
/* a game in the server browser: at once (more joiners get through) */
if (p2p_lobby_listed())
return 1;
for (index = 0; index < P2P_MAXIMUM_PEERS; index++)
{
struct peer const *peer = &p2p.peers[index];
@@ -3013,6 +3109,24 @@ static void *p2p_thread(void *unused)
expire_proxies();
stun_update();
update_hosting();
/* the server browser (p2p_lobby.c): signalling while browsing too */
if (p2p_lobby_browsing())
p2p_signal_start();
{
int count, maximum;
hosted_player_counts(&count, &maximum);
p2p_lobby_update(p2p.hosting && p2p.has_token ? p2p.token : NULL, count, maximum);
if (p2p_lobby_listed())
{
p2p.token_listed = 1;
if (!p2p.lobby_quit_registered)
{
p2p.lobby_quit_registered = 1;
atexit(lobby_quit);
}
}
}
update_joining();
update_upnp();
p2p_discord_update();
+50
View File
@@ -74,6 +74,8 @@ struct p2p_public_game
char code[12];
int players;
int maximum_players;
/* (a game of the server browser's: no code, its invite) */
char invite[77];
};
void p2p_set_public_game(int public_game);
int p2p_public_game(void);
@@ -140,6 +142,54 @@ are shown). The game's server calls it as they change (calling it with the
same counts again costs little) */
void p2p_set_game_player_counts(int count, int maximum);
/* ---- the server browser's public games (p2p_lobby.c) */
/* whether the game this machine hosts for the internet (not LAN) is listed
in everyone's server browser: Create Game's PUBLIC; a private game is
reached only by its invite. Going private makes a new invite, if the old one
was listed */
void p2p_set_hosting_public(int public);
/* the hosted game's details as listed (printable ASCII is kept; NULL leaves
one as it was): the game's server calls it as they change (calling it with
the same again costs little) */
void p2p_set_game_listing(const char *name, const char *map, const char *gametype, int engine_type, int open,
int in_progress, int has_teams);
/* the server browser: while on, the public games are gathered (asked for
when turned on, and by p2p_lobby_refresh) */
void p2p_lobby_browse(int on);
void p2p_lobby_refresh(void);
enum
{
P2P_LISTING_NAME_SIZE = 32,
P2P_LISTING_MAP_SIZE = 32,
P2P_LISTING_GAMETYPE_SIZE = 24,
/* an invite link's text (P2P_LINK_SIZE) */
P2P_LISTING_INVITE_SIZE = 77,
/* (struct p2p_public_game's invite is as large) */
};
struct p2p_listing
{
char invite[P2P_LISTING_INVITE_SIZE];
/* the host's (its XNADDR's abEnet once reached) */
unsigned char identifier[6];
char name[P2P_LISTING_NAME_SIZE + 1];
char map[P2P_LISTING_MAP_SIZE + 1];
char gametype[P2P_LISTING_GAMETYPE_SIZE + 1];
unsigned char player_count, maximum_player_count, engine_type;
unsigned char open, in_progress, has_teams;
/* joining it failed this run (p2p_lobby_mark_failed) */
unsigned char failed;
/* milliseconds, -1 if not known */
short ping;
};
/* a copy of the public games found, in the order shown (the most players
first; then those not failed, the open ones, by name); returns their count */
int p2p_lobby_games(struct p2p_listing *games, int maximum_count);
/* a game the browser could not join: kept, marked failed, for this run */
void p2p_lobby_mark_failed(const unsigned char *identifier);
/* the sizes of a Discord user's id and name as kept (with their end), and
the text kept of either as told: only the characters allowed (digits in an
id; letters, digits, "_", "." and "-" in a name), no longer than that */
+73 -4
View File
@@ -6,16 +6,20 @@ private (p2p.c): SHA-256 (FIPS 180-4) and HMAC-SHA256 (RFC 2104), from
which an invite's topics and keys are derived; ChaCha20-Poly1305 (RFC 8439)
with additional data, which seals the tunnel's packets (a counter for their
nonce) and, with a random nonce sent ahead of the ciphertext, signalling's
messages; and X25519 (RFC 7748), with which two machines agree on their
tunnel's keys without sending them. The public brokers carry sealed
messages, so only holders of the invite read them; the tunnel's packets are
sealed with keys only its two machines have.
messages; X25519 (RFC 7748), with which two machines agree on their
tunnel's keys without sending them; and Ed25519 (RFC 8032, Monocypher's),
with which a host signs its public game's listing (p2p_lobby.c). The public
brokers carry sealed messages, so only holders of the invite read them; the
tunnel's packets are sealed with keys only its two machines have.
*/
#include "platform.h"
#include "posix.h"
#include "p2p_internal.h"
#include "monocypher.h"
#include "monocypher-ed25519.h"
#include <string.h>
/* ---------- SHA-256 */
@@ -590,3 +594,68 @@ void p2p_x25519(unsigned char *result, const unsigned char *scalar, const unsign
field_multiply(a, a, c);
field_pack(result, a);
}
/* ---------- Ed25519 (RFC 8032, with SHA-512), from Monocypher
(port/third_party/monocypher): a run's key, from which its X25519 key also
comes, signs the listing of a public game (p2p_lobby.c) */
void p2p_sha512(const void *data, int size, unsigned char *digest)
{
crypto_sha512(digest, data, (size_t)size);
}
void p2p_ed25519_public(const unsigned char *seed, unsigned char *public_key, unsigned char *x25519_secret)
{
unsigned char copy[P2P_SEED_SIZE];
unsigned char secret_key[64];
unsigned char hash[64];
/* (the key pair's making wipes the seed it is given) */
memcpy(copy, seed, sizeof(copy));
crypto_ed25519_key_pair(secret_key, public_key, copy);
if (x25519_secret)
{
/* the scalar Ed25519 signs with: X25519 clamps it the same way */
p2p_sha512(seed, P2P_SEED_SIZE, hash);
memcpy(x25519_secret, hash, P2P_KEY_SIZE);
}
crypto_wipe(secret_key, sizeof(secret_key));
crypto_wipe(hash, sizeof(hash));
}
void p2p_ed25519_sign(const unsigned char *seed, const unsigned char *public_key, const void *message, int size,
unsigned char *signature)
{
unsigned char secret_key[64];
/* (Monocypher's secret key: the seed, then the public key) */
memcpy(secret_key, seed, P2P_SEED_SIZE);
memcpy(secret_key + P2P_SEED_SIZE, public_key, P2P_KEY_SIZE);
crypto_ed25519_sign(signature, secret_key, message, (size_t)size);
crypto_wipe(secret_key, sizeof(secret_key));
}
int p2p_ed25519_to_x25519(const unsigned char *public_key, unsigned char *x25519_public)
{
static const unsigned char zero[P2P_KEY_SIZE];
static const unsigned char scalar[P2P_KEY_SIZE] = { 1 };
unsigned char product[P2P_KEY_SIZE];
crypto_eddsa_to_x25519(x25519_public, public_key);
/* a point of small order (whose multiple by a clamped scalar, a
multiple of 8, is 0) has signatures anyone can make, and secrets anyone
knows */
crypto_x25519(product, scalar, x25519_public);
return !p2p_equal(product, zero, P2P_KEY_SIZE);
}
int p2p_ed25519_verify(const unsigned char *public_key, const void *message, int size,
const unsigned char *signature)
{
unsigned char x25519_public[P2P_KEY_SIZE];
/* (Monocypher's check turns away an S past the group's order: one
signature a message) */
return p2p_ed25519_to_x25519(public_key, x25519_public) &&
crypto_ed25519_check(signature, public_key, message, (size_t)size) == 0;
}
+76
View File
@@ -10,6 +10,8 @@ p2p_discord.c; see p2p.c for the design).
#include "p2p.h"
#include <pthread.h>
enum
{
/* a machine's identifier: from the hash of its public key (which is new
@@ -31,6 +33,17 @@ enum
P2P_MAXIMUM_PEERS = 127,
};
typedef char p2p_listing_invite_size_assert[P2P_LISTING_INVITE_SIZE == P2P_LINK_SIZE ? 1 : -1];
/* the prefix of a public game's slot (a key hash in hex follows), and the
topic of queries (p2p_lobby.c) */
#define P2P_LOBBY_SLOT_PREFIX "hceu/3/lobby/s/"
#define P2P_LOBBY_QUERY_TOPIC "hceu/3/lobby/q"
/* internet play's state (p2p.c), which the game's threads and the p2p
thread share */
extern pthread_mutex_t p2p_lock;
struct p2p_candidate
{
/* network byte order */
@@ -57,6 +70,10 @@ int p2p_local_candidates(struct p2p_candidate *candidates, int maximum_count);
/* this run's X25519 public key (P2P_KEY_SIZE bytes), whose hash the
identifier is (p2p_identifier) */
const unsigned char *p2p_public_key(void);
/* this run's Ed25519 public key (the X25519 one's, p2p_ed25519_to_x25519),
and a signature with it */
const unsigned char *p2p_signing_key(void);
void p2p_sign(const void *message, int size, unsigned char *signature);
/* the identifier of the machine with this public key */
void p2p_identifier_for(const unsigned char *public_key, unsigned char *identifier);
/* the hash of a public key an invite holds (P2P_KEY_HASH_SIZE bytes), and
@@ -87,6 +104,10 @@ int p2p_peer_reoffered(const unsigned char *identifier, const unsigned char *sec
/* an invite that arrived on the p2p thread (from Discord, or another copy
of the game) */
void p2p_invite_received(const char *text);
/* a new invite (token) for the game hosted, if its invite was listed in the
server browser (going private: those who saw it must not get in); under
p2p_lock */
void p2p_new_invite_if_listed(void);
/* ---------- p2p_signal.c: signalling through public MQTT brokers */
@@ -154,6 +175,20 @@ const char *p2p_list_topic(void);
int p2p_list_received(const char *topic, const unsigned char *payload, int size);
void p2p_list_update(int hosting);
/* the server browser's topics: the own slot and the queries (a listed
game), and every slot (browsing) */
void p2p_signal_lobby_topics(int listed, int browsing);
/* publishes a listing to the own slot on every broker, retained, and again
on each broker that connects later; closing: a tombstone, after which the
slot is cleared and nothing is published again */
void p2p_signal_lobby_publish(const unsigned char *listing, int size, int closing);
/* asks the hosts to publish again */
void p2p_signal_lobby_query(void);
/* the game is quitting: the tombstone published (p2p_signal_lobby_publish)
and the slot cleared on every ready broker now, whatever their buckets, and
the connections closed cleanly */
void p2p_signal_lobby_quit(void);
/* ---------- p2p_crypto.c */
enum
@@ -189,6 +224,47 @@ int p2p_equal(const void *first, const void *second, int size);
key of the secret key scalar) */
void p2p_x25519(unsigned char *result, const unsigned char *scalar, const unsigned char *point);
enum
{
/* an Ed25519 seed (a run's key comes from one) and signature */
P2P_SEED_SIZE = 32,
P2P_SIGNATURE_SIZE = 64,
P2P_SHA512_SIZE = 64,
};
void p2p_sha512(const void *data, int size, unsigned char *digest);
/* Ed25519 (with SHA-512): a seed's public key (P2P_KEY_SIZE bytes) and,
unless NULL, its X25519 secret key (the scalar it signs with, whose X25519
public key is p2p_ed25519_to_x25519 of the Ed25519 one) */
void p2p_ed25519_public(const unsigned char *seed, unsigned char *public_key, unsigned char *x25519_secret);
void p2p_ed25519_sign(const unsigned char *seed, const unsigned char *public_key, const void *message, int size,
unsigned char *signature);
/* whether the signature is the key's, of the message (never for a key of
small order, which anyone can sign for) */
int p2p_ed25519_verify(const unsigned char *public_key, const void *message, int size,
const unsigned char *signature);
/* the X25519 public key of an Ed25519 one; 0 if it has a small order */
int p2p_ed25519_to_x25519(const unsigned char *public_key, unsigned char *x25519_public);
/* ---------- p2p_lobby.c: public games' listings */
/* the p2p thread's pass: the token of the game hosted for the internet
(NULL if none) and its player counts */
void p2p_lobby_update(const unsigned char *token, int player_count, int maximum_player_count);
/* whether the game hosted is listed now, and whether the browser is open */
int p2p_lobby_listed(void);
int p2p_lobby_browsing(void);
/* a message on a slot (its key hash in hex) through a broker; retained: the
slot's retained copy, sent on subscribing */
void p2p_lobby_slot_heard(const char *hash_text, const unsigned char *payload, int size, int retained);
/* a query was heard */
void p2p_lobby_query_heard(void);
/* the game is quitting: a listed game's tombstone, and its slot cleared,
written to the brokers at once; under p2p_lock */
void p2p_lobby_quit(void);
/* a key hash's slot */
void p2p_lobby_slot_topic(const unsigned char *key_hash, char *topic, int size);
/* ---------- p2p_discord.c: rich presence and invites through the Discord
desktop client */
+774
View File
@@ -0,0 +1,774 @@
/*
P2P_LOBBY.C
Internet play's public games (the server browser, Join Game > Server
Browser): a public game's host publishes a signed listing of it through the
signalling brokers (p2p_signal.c), and browsers gather the listings and join
a game by the invite a listing holds, as an invite link would.
The listing (network byte order) is signed with the host's Ed25519 key,
whose X25519 form's hash is the invite's host part (p2p.c), so no one but
the host can list its invite, alter its listing, or list another's under
false details:
"HL", format 1, the lobby version (2: HALO_PORT_NETWORK_VERSION; browsers
hide others), flags (open, under way, teams, closed), sequence (4: newest
wins), Unix time (4), the Ed25519 key (32), the invite's token (16),
players, most players, the gametype's engine (1 each), the game's name,
map and gametype (a length byte, then up to 32, 32 and 24 characters of
printable ASCII), a stamp (8, reserved: zero), and the signature (64) of
"hceu-lobby-1" and all before it.
Each host has a slot, hceu/3/lobby/s/<its key's hash in hex>: its listing,
retained on every broker (and expiring there after LISTING_EXPIRY seconds
on MQTT 5), and the broker's will (set at the connection, p2p_signal.c)
clears it if the host vanishes. Browsers subscribe to every slot and ask the
hosts to publish again (hceu/3/lobby/q). Brokers are other people's: what
one deletes or keeps is no authority, so
- a host publishes every REPUBLISH_INTERVAL, and sooner (at most once each
TRIGGER_INTERVAL) when its game changes, when asked, and when its slot is
heard to hold anything but its listing (cleared, another's, or an older
one of its own): a deletion is undone in seconds;
- a browser takes only a signed listing whose key's hash is its slot's,
keeps the newest of each host (by sequence), drops one not heard in
GAME_EXPIRY (on its own clock; a retained copy is taken only if its time
is within RETAINED_WINDOW of this machine's, from a host that died and
left it), takes a host's closing listing (a tombstone) as its end, and
ignores an emptied slot (a wipe is not a delete).
A host that stops publishes a tombstone, then clears its slot. Going private
makes a new invite (p2p.c), so a listing seen before lets no one in.
Checking signatures takes work, and anyone can send listings: at most
VERIFY_BUDGET milliseconds of it each pass of the p2p thread, from a queue
of MAXIMUM_QUEUED; the rest is dropped (hosts publish again).
*/
#include "platform.h"
#include "posix.h"
#include "port_config.h"
#include "p2p_internal.h"
#include "halo_port_limits.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
enum
{
LISTING_FORMAT = 1,
_listing_open = 1,
_listing_in_progress = 2,
_listing_has_teams = 4,
/* a tombstone: the host stopped */
_listing_closed = 8,
/* (reserved) */
_listing_password = 16,
STAMP_SIZE = 8,
/* the signed part's end: everything but the signature */
MAXIMUM_LISTING_SIZE = 2 + 1 + 2 + 1 + 4 + 4 + P2P_KEY_SIZE + P2P_TOKEN_SIZE + 3 +
(1 + P2P_LISTING_NAME_SIZE) + (1 + P2P_LISTING_MAP_SIZE) + (1 + P2P_LISTING_GAMETYPE_SIZE) + STAMP_SIZE +
P2P_SIGNATURE_SIZE,
MINIMUM_LISTING_SIZE = 2 + 1 + 2 + 1 + 4 + 4 + P2P_KEY_SIZE + P2P_TOKEN_SIZE + 3 + 3 + STAMP_SIZE +
P2P_SIGNATURE_SIZE,
MAXIMUM_GAMES = 256,
MAXIMUM_TOMBSTONES = 256,
MAXIMUM_QUEUED = 64,
/* milliseconds */
REPUBLISH_INTERVAL = 30000,
TRIGGER_INTERVAL = 5000,
QUERY_JITTER = 2000,
GAME_EXPIRY = 90000,
TOMBSTONE_TIME = 600000,
VERIFY_BUDGET = 2,
/* seconds */
RETAINED_WINDOW = 600,
};
static const char signature_label[] = "hceu-lobby-1";
/* a listing, read */
struct listing
{
int version;
int flags;
unsigned long sequence;
unsigned long time;
unsigned char key[P2P_KEY_SIZE];
unsigned char token[P2P_TOKEN_SIZE];
int player_count, maximum_player_count, engine_type;
char name[P2P_LISTING_NAME_SIZE + 1];
char map[P2P_LISTING_MAP_SIZE + 1];
char gametype[P2P_LISTING_GAMETYPE_SIZE + 1];
/* the signed part's size */
int signed_size;
};
struct game
{
int used;
unsigned char key_hash[P2P_KEY_HASH_SIZE];
unsigned long sequence;
unsigned long heard_time;
/* as it came (one the same again needs no check) */
unsigned char payload[MAXIMUM_LISTING_SIZE];
int payload_size;
struct p2p_listing listing;
};
struct tombstone
{
unsigned char key_hash[P2P_KEY_HASH_SIZE];
unsigned long sequence;
unsigned long time;
};
struct queued
{
unsigned char key_hash[P2P_KEY_HASH_SIZE];
unsigned char payload[MAXIMUM_LISTING_SIZE];
int size;
int retained;
};
static struct
{
/* hosting: the game as the game's server tells it
(p2p_set_game_listing), and whether it is public (p2p_set_hosting_public) */
int public;
char name[P2P_LISTING_NAME_SIZE + 1];
char map[P2P_LISTING_MAP_SIZE + 1];
char gametype[P2P_LISTING_GAMETYPE_SIZE + 1];
int engine_type;
int flags;
int player_count, maximum_player_count;
/* listed: with this token; its listing as last published */
int listed;
unsigned char token[P2P_TOKEN_SIZE];
unsigned long sequence;
unsigned char listing[MAXIMUM_LISTING_SIZE];
int listing_size;
unsigned long published_time;
/* a publish wanted (the game changed, a query, the slot needs mending),
not before this */
int republish_wanted;
unsigned long republish_time;
/* browsing */
int browsing;
int query_wanted;
struct queued queue[MAXIMUM_QUEUED];
int queue_count;
struct game games[MAXIMUM_GAMES];
struct tombstone tombstones[MAXIMUM_TOMBSTONES];
int next_tombstone;
/* the identifiers of games joining failed */
unsigned char failed[MAXIMUM_GAMES][P2P_IDENTIFIER_SIZE];
int failed_count;
} lobby;
static int elapsed(unsigned long since, unsigned long time)
{
return (unsigned int)(p2p_now() - since) >= (unsigned int)time;
}
/* printable ASCII, as the menus' font has it (others: '?'), cut to size */
static void sanitize(char *destination, int size, const char *source, int source_size)
{
int index;
for (index = 0; index < size && index < source_size && source[index]; index++)
{
unsigned char character = (unsigned char)source[index];
destination[index] = character >= 0x20 && character < 0x7F ? (char)character : '?';
}
destination[index] = 0;
}
void p2p_lobby_slot_topic(const unsigned char *key_hash, char *topic, int size)
{
char text[2 * P2P_KEY_HASH_SIZE + 1];
p2p_hex(key_hash, P2P_KEY_HASH_SIZE, text);
snprintf(topic, (size_t)size, "%s%s", P2P_LOBBY_SLOT_PREFIX, text);
}
/* the hash of an Ed25519 key's X25519 form (an invite's host part); 0 if
the key has a small order */
static int signing_key_hash(const unsigned char *key, unsigned char *hash)
{
unsigned char x25519[P2P_KEY_SIZE];
if (!p2p_ed25519_to_x25519(key, x25519))
return 0;
p2p_key_hash(x25519, hash);
return 1;
}
/* ---------- the listing */
static void put_long(unsigned char *bytes, unsigned long value)
{
bytes[0] = (unsigned char)(value >> 24);
bytes[1] = (unsigned char)(value >> 16);
bytes[2] = (unsigned char)(value >> 8);
bytes[3] = (unsigned char)value;
}
static unsigned long get_long(const unsigned char *bytes)
{
return (unsigned long)bytes[0] << 24 | (unsigned long)bytes[1] << 16 | (unsigned long)bytes[2] << 8 | bytes[3];
}
static int put_text(unsigned char *bytes, const char *text, int maximum)
{
int length = (int)strlen(text);
length = length > maximum ? maximum : length;
bytes[0] = (unsigned char)length;
memcpy(bytes + 1, text, (size_t)length);
return 1 + length;
}
/* the listing of the game hosted, signed: flags (_listing_closed for a
tombstone) */
static int listing_make(unsigned char *bytes, int flags)
{
unsigned char *signed_part = bytes;
unsigned char data[sizeof(signature_label) - 1 + MAXIMUM_LISTING_SIZE];
int size = 0;
bytes[size++] = 'H';
bytes[size++] = 'L';
bytes[size++] = LISTING_FORMAT;
bytes[size++] = (unsigned char)(HALO_PORT_NETWORK_VERSION >> 8);
bytes[size++] = (unsigned char)HALO_PORT_NETWORK_VERSION;
bytes[size++] = (unsigned char)flags;
put_long(bytes + size, ++lobby.sequence);
size += 4;
put_long(bytes + size, (unsigned long)time(NULL));
size += 4;
memcpy(bytes + size, p2p_signing_key(), P2P_KEY_SIZE);
size += P2P_KEY_SIZE;
memcpy(bytes + size, lobby.token, P2P_TOKEN_SIZE);
size += P2P_TOKEN_SIZE;
bytes[size++] = (unsigned char)(lobby.player_count > 255 ? 255 : lobby.player_count);
bytes[size++] = (unsigned char)(lobby.maximum_player_count > 255 ? 255 : lobby.maximum_player_count);
bytes[size++] = (unsigned char)lobby.engine_type;
size += put_text(bytes + size, lobby.name, P2P_LISTING_NAME_SIZE);
size += put_text(bytes + size, lobby.map, P2P_LISTING_MAP_SIZE);
size += put_text(bytes + size, lobby.gametype, P2P_LISTING_GAMETYPE_SIZE);
memset(bytes + size, 0, STAMP_SIZE);
size += STAMP_SIZE;
memcpy(data, signature_label, sizeof(signature_label) - 1);
memcpy(data + sizeof(signature_label) - 1, signed_part, (size_t)size);
p2p_sign(data, (int)(sizeof(signature_label) - 1) + size, bytes + size);
return size + P2P_SIGNATURE_SIZE;
}
static int get_text(const unsigned char *bytes, int size, int *offset, char *text, int maximum)
{
int length;
if (*offset >= size)
return 0;
length = bytes[(*offset)++];
if (length > maximum || *offset + length > size)
return 0;
sanitize(text, maximum, (const char *)bytes + *offset, length);
*offset += length;
return 1;
}
/* reads a listing (not its signature); 0 if it is malformed */
static int listing_read(const unsigned char *bytes, int size, struct listing *listing)
{
int offset = 0;
if (size < MINIMUM_LISTING_SIZE || size > MAXIMUM_LISTING_SIZE || bytes[0] != 'H' || bytes[1] != 'L' ||
bytes[2] != LISTING_FORMAT)
{
return 0;
}
offset = 3;
listing->version = bytes[offset] << 8 | bytes[offset + 1];
offset += 2;
listing->flags = bytes[offset++];
listing->sequence = get_long(bytes + offset);
offset += 4;
listing->time = get_long(bytes + offset);
offset += 4;
memcpy(listing->key, bytes + offset, P2P_KEY_SIZE);
offset += P2P_KEY_SIZE;
memcpy(listing->token, bytes + offset, P2P_TOKEN_SIZE);
offset += P2P_TOKEN_SIZE;
listing->player_count = bytes[offset++];
listing->maximum_player_count = bytes[offset++];
listing->engine_type = bytes[offset++];
if (!get_text(bytes, size, &offset, listing->name, P2P_LISTING_NAME_SIZE) ||
!get_text(bytes, size, &offset, listing->map, P2P_LISTING_MAP_SIZE) ||
!get_text(bytes, size, &offset, listing->gametype, P2P_LISTING_GAMETYPE_SIZE))
{
return 0;
}
offset += STAMP_SIZE;
if (offset + P2P_SIGNATURE_SIZE != size)
return 0;
listing->signed_size = offset;
return 1;
}
static int listing_signed(const unsigned char *bytes, const struct listing *listing)
{
unsigned char data[sizeof(signature_label) - 1 + MAXIMUM_LISTING_SIZE];
memcpy(data, signature_label, sizeof(signature_label) - 1);
memcpy(data + sizeof(signature_label) - 1, bytes, (size_t)listing->signed_size);
return p2p_ed25519_verify(listing->key, data, (int)(sizeof(signature_label) - 1) + listing->signed_size,
bytes + listing->signed_size);
}
/* ---------- hosting */
static void publish(void)
{
lobby.listing_size = listing_make(lobby.listing, lobby.flags);
lobby.published_time = p2p_now();
lobby.republish_wanted = 0;
p2p_signal_lobby_publish(lobby.listing, lobby.listing_size, 0);
}
/* a publish soon: at once if none was lately, else when TRIGGER_INTERVAL
has passed (plus jitter) */
static void republish_soon(unsigned long jitter)
{
unsigned long earliest = lobby.published_time + TRIGGER_INTERVAL;
unsigned long when = p2p_now() + jitter;
if ((long)(earliest - when) > 0)
when = earliest;
if (!lobby.republish_wanted || (long)(lobby.republish_time - when) > 0)
lobby.republish_time = when;
lobby.republish_wanted = 1;
}
static void stop_listing(void)
{
unsigned char tombstone[MAXIMUM_LISTING_SIZE];
int size = listing_make(tombstone, _listing_closed);
lobby.listed = 0;
lobby.republish_wanted = 0;
p2p_signal_lobby_publish(tombstone, size, 1);
p2p_signal_lobby_topics(0, lobby.browsing);
platform_log("Internet play: the game is no longer listed in the server browser");
}
static void update_hosting(const unsigned char *token, int player_count, int maximum_player_count)
{
int want = token && lobby.public && config_boolean("network.public_lobby");
if (lobby.listed && (!want || memcmp(token, lobby.token, P2P_TOKEN_SIZE)))
stop_listing();
if (!want)
return;
if (player_count != lobby.player_count || maximum_player_count != lobby.maximum_player_count)
{
lobby.player_count = player_count;
lobby.maximum_player_count = maximum_player_count;
if (lobby.listed)
republish_soon(0);
}
if (!lobby.listed)
{
memcpy(lobby.token, token, P2P_TOKEN_SIZE);
lobby.listed = 1;
p2p_signal_lobby_topics(1, lobby.browsing);
publish();
platform_log("Internet play: the game is listed in everyone's server browser (public)");
return;
}
if ((lobby.republish_wanted && (long)(p2p_now() - lobby.republish_time) >= 0) ||
elapsed(lobby.published_time, REPUBLISH_INTERVAL))
{
publish();
}
}
void p2p_lobby_query_heard(void)
{
if (lobby.listed)
{
unsigned short jitter;
posix_random_bytes(&jitter, sizeof(jitter));
republish_soon(jitter % QUERY_JITTER);
}
}
/* the host's own slot was heard: anything but its listing is mended */
static void own_slot_heard(const unsigned char *payload, int size, int retained)
{
struct listing listing;
if (!lobby.listed || (size == lobby.listing_size && !memcmp(payload, lobby.listing, (size_t)size)))
return;
/* (an older listing of its own, forwarded live, is the echo of a publish
before the last; as the slot's retained copy, the slot holds it) */
if (!retained && listing_read(payload, size, &listing) && !memcmp(listing.key, p2p_signing_key(), P2P_KEY_SIZE) &&
listing.sequence < lobby.sequence)
{
return;
}
republish_soon(0);
}
/* ---------- browsing */
static struct game *find_game(const unsigned char *key_hash)
{
int index;
for (index = 0; index < MAXIMUM_GAMES; index++)
{
if (lobby.games[index].used && !memcmp(lobby.games[index].key_hash, key_hash, P2P_KEY_HASH_SIZE))
return &lobby.games[index];
}
return NULL;
}
static struct tombstone *find_tombstone(const unsigned char *key_hash)
{
int index;
for (index = 0; index < MAXIMUM_TOMBSTONES; index++)
{
struct tombstone *tombstone = &lobby.tombstones[index];
if (tombstone->time && !elapsed(tombstone->time, TOMBSTONE_TIME) &&
!memcmp(tombstone->key_hash, key_hash, P2P_KEY_HASH_SIZE))
{
return tombstone;
}
}
return NULL;
}
static int identifier_failed(const unsigned char *identifier)
{
int index;
for (index = 0; index < lobby.failed_count; index++)
{
if (!memcmp(lobby.failed[index], identifier, P2P_IDENTIFIER_SIZE))
return 1;
}
return 0;
}
void p2p_lobby_slot_heard(const char *hash_text, const unsigned char *payload, int size, int retained)
{
unsigned char key_hash[P2P_KEY_HASH_SIZE];
struct game *game;
struct queued *queued;
int index;
if (strlen(hash_text) != 2 * P2P_KEY_HASH_SIZE || strspn(hash_text, "0123456789abcdef") != 2 * P2P_KEY_HASH_SIZE)
return;
for (index = 0; index < P2P_KEY_HASH_SIZE; index++)
{
unsigned int byte;
sscanf(hash_text + 2 * index, "%2x", &byte);
key_hash[index] = (unsigned char)byte;
}
{
unsigned char own[P2P_KEY_HASH_SIZE];
p2p_key_hash(p2p_public_key(), own);
if (!memcmp(own, key_hash, P2P_KEY_HASH_SIZE))
own_slot_heard(payload, size, retained);
}
/* (an emptied slot is no news: a wipe is not a delete) */
if (!lobby.browsing || size < MINIMUM_LISTING_SIZE || size > MAXIMUM_LISTING_SIZE)
return;
/* the same listing again: heard, no work */
game = find_game(key_hash);
if (game && game->payload_size == size && !memcmp(game->payload, payload, (size_t)size))
{
game->heard_time = p2p_now();
return;
}
for (index = 0; index < lobby.queue_count; index++)
{
if (lobby.queue[index].size == size && !memcmp(lobby.queue[index].payload, payload, (size_t)size))
return;
}
if (lobby.queue_count == MAXIMUM_QUEUED)
return;
queued = &lobby.queue[lobby.queue_count++];
memcpy(queued->key_hash, key_hash, P2P_KEY_HASH_SIZE);
memcpy(queued->payload, payload, (size_t)size);
queued->size = size;
queued->retained = retained;
}
/* a queued listing, its signature checked: taken or not */
static void listing_take(const struct queued *queued, const struct listing *listing)
{
struct tombstone *tombstone = find_tombstone(queued->key_hash);
struct game *game = find_game(queued->key_hash);
struct p2p_listing *shown;
unsigned char bytes[P2P_KEY_HASH_SIZE + P2P_TOKEN_SIZE];
char text[2 * (P2P_KEY_HASH_SIZE + P2P_TOKEN_SIZE) + 1];
int index;
if (tombstone && listing->sequence <= tombstone->sequence)
return;
if (game && listing->sequence <= game->sequence)
return;
if (listing->flags & _listing_closed)
{
if (!tombstone)
{
tombstone = &lobby.tombstones[lobby.next_tombstone];
lobby.next_tombstone = (lobby.next_tombstone + 1) % MAXIMUM_TOMBSTONES;
memcpy(tombstone->key_hash, queued->key_hash, P2P_KEY_HASH_SIZE);
}
tombstone->sequence = listing->sequence;
tombstone->time = p2p_now() ? p2p_now() : 1;
if (game)
game->used = 0;
return;
}
if (!game)
{
/* the room of one gone longest, if there is none free */
for (index = 0; index < MAXIMUM_GAMES && lobby.games[index].used; index++)
;
if (index == MAXIMUM_GAMES)
{
int oldest = 0;
for (index = 1; index < MAXIMUM_GAMES; index++)
{
if ((long)(lobby.games[index].heard_time - lobby.games[oldest].heard_time) < 0)
oldest = index;
}
index = oldest;
}
game = &lobby.games[index];
memset(game, 0, sizeof(*game));
memcpy(game->key_hash, queued->key_hash, P2P_KEY_HASH_SIZE);
game->used = 1;
}
game->sequence = listing->sequence;
game->heard_time = p2p_now();
memcpy(game->payload, queued->payload, (size_t)queued->size);
game->payload_size = queued->size;
shown = &game->listing;
memcpy(bytes, queued->key_hash, P2P_KEY_HASH_SIZE);
memcpy(bytes + P2P_KEY_HASH_SIZE, listing->token, P2P_TOKEN_SIZE);
p2p_hex(bytes, sizeof(bytes), text);
snprintf(shown->invite, sizeof(shown->invite), "halo://join/%s", text);
p2p_identifier_from_hash(queued->key_hash, shown->identifier);
memcpy(shown->name, listing->name, sizeof(shown->name));
memcpy(shown->map, listing->map, sizeof(shown->map));
memcpy(shown->gametype, listing->gametype, sizeof(shown->gametype));
shown->player_count = (unsigned char)listing->player_count;
shown->maximum_player_count = (unsigned char)listing->maximum_player_count;
shown->engine_type = (unsigned char)listing->engine_type;
shown->open = (listing->flags & _listing_open) != 0;
shown->in_progress = (listing->flags & _listing_in_progress) != 0;
shown->has_teams = (listing->flags & _listing_has_teams) != 0;
shown->ping = -1;
}
static void update_browsing(void)
{
unsigned long start = p2p_now();
int index;
if (lobby.query_wanted)
{
lobby.query_wanted = 0;
p2p_signal_lobby_query();
}
/* the queue, within the budget (one at least) */
while (lobby.queue_count && (p2p_now() == start || !elapsed(start, VERIFY_BUDGET)))
{
struct queued queued = lobby.queue[0];
struct listing listing;
unsigned char key_hash[P2P_KEY_HASH_SIZE];
int good;
memmove(lobby.queue, lobby.queue + 1, sizeof(*lobby.queue) * (size_t)(--lobby.queue_count));
if (!listing_read(queued.payload, queued.size, &listing) || listing.version != HALO_PORT_NETWORK_VERSION ||
!signing_key_hash(listing.key, key_hash) || memcmp(key_hash, queued.key_hash, P2P_KEY_HASH_SIZE))
{
continue;
}
/* a slot's retained copy: only one of about now (a host that died
left it, and nothing cleared it) */
if (queued.retained)
{
long difference = (long)(listing.time - (unsigned long)time(NULL));
if (difference > RETAINED_WINDOW || difference < -RETAINED_WINDOW)
continue;
}
/* (the work, without the lock: the game's threads need not wait) */
pthread_mutex_unlock(&p2p_lock);
good = listing_signed(queued.payload, &listing);
pthread_mutex_lock(&p2p_lock);
if (good && lobby.browsing)
listing_take(&queued, &listing);
}
if (lobby.queue_count && !lobby.browsing)
lobby.queue_count = 0;
for (index = 0; index < MAXIMUM_GAMES; index++)
{
if (lobby.games[index].used && elapsed(lobby.games[index].heard_time, GAME_EXPIRY))
lobby.games[index].used = 0;
}
}
/* ---------- p2p.c's side */
void p2p_lobby_update(const unsigned char *token, int player_count, int maximum_player_count)
{
update_hosting(token, player_count, maximum_player_count);
update_browsing();
}
int p2p_lobby_listed(void)
{
return lobby.listed;
}
void p2p_lobby_quit(void)
{
if (!lobby.listed)
return;
stop_listing();
/* (the game is ending: written now, not on the coming passes) */
p2p_signal_lobby_quit();
}
/* ---------- the game's side */
void p2p_set_hosting_public(int public)
{
pthread_mutex_lock(&p2p_lock);
/* (a new invite going private: p2p.c) */
if (lobby.public && !public)
p2p_new_invite_if_listed();
lobby.public = public ? 1 : 0;
pthread_mutex_unlock(&p2p_lock);
}
void p2p_set_game_listing(const char *name, const char *map, const char *gametype, int engine_type, int open,
int in_progress, int has_teams)
{
char new_name[P2P_LISTING_NAME_SIZE + 1];
char new_map[P2P_LISTING_MAP_SIZE + 1];
char new_gametype[P2P_LISTING_GAMETYPE_SIZE + 1];
int flags = (open ? _listing_open : 0) | (in_progress ? _listing_in_progress : 0) |
(has_teams ? _listing_has_teams : 0);
sanitize(new_name, P2P_LISTING_NAME_SIZE, name ? name : lobby.name, P2P_LISTING_NAME_SIZE);
sanitize(new_map, P2P_LISTING_MAP_SIZE, map ? map : lobby.map, P2P_LISTING_MAP_SIZE);
sanitize(new_gametype, P2P_LISTING_GAMETYPE_SIZE, gametype ? gametype : lobby.gametype,
P2P_LISTING_GAMETYPE_SIZE);
/* (only the game's server writes these: unchanged, it need not wait for
the lock) */
if (!strcmp(new_name, lobby.name) && !strcmp(new_map, lobby.map) && !strcmp(new_gametype, lobby.gametype) &&
engine_type == lobby.engine_type && flags == lobby.flags)
{
return;
}
pthread_mutex_lock(&p2p_lock);
memcpy(lobby.name, new_name, sizeof(lobby.name));
memcpy(lobby.map, new_map, sizeof(lobby.map));
memcpy(lobby.gametype, new_gametype, sizeof(lobby.gametype));
lobby.engine_type = engine_type;
lobby.flags = flags;
if (lobby.listed)
republish_soon(0);
pthread_mutex_unlock(&p2p_lock);
}
void p2p_lobby_browse(int on)
{
pthread_mutex_lock(&p2p_lock);
on = on && config_boolean("network.public_lobby") ? 1 : 0;
if (on != lobby.browsing)
{
lobby.browsing = on;
if (!on)
{
memset(lobby.games, 0, sizeof(lobby.games));
lobby.queue_count = 0;
}
lobby.query_wanted = on;
p2p_signal_lobby_topics(lobby.listed, on);
}
pthread_mutex_unlock(&p2p_lock);
}
void p2p_lobby_refresh(void)
{
pthread_mutex_lock(&p2p_lock);
if (lobby.browsing)
lobby.query_wanted = 1;
pthread_mutex_unlock(&p2p_lock);
}
int p2p_lobby_browsing(void)
{
return lobby.browsing;
}
/* the order shown: the most players first; then those joining has not
failed, the open ones, and by name */
static int listing_order(const void *first, const void *second)
{
const struct p2p_listing *a = first, *b = second;
if (a->player_count != b->player_count)
return b->player_count - a->player_count;
if (a->failed != b->failed)
return a->failed - b->failed;
if (a->open != b->open)
return b->open - a->open;
return strcmp(a->name, b->name);
}
int p2p_lobby_games(struct p2p_listing *games, int maximum_count)
{
int count = 0;
int index;
pthread_mutex_lock(&p2p_lock);
for (index = 0; index < MAXIMUM_GAMES && count < maximum_count; index++)
{
if (!lobby.games[index].used)
continue;
games[count] = lobby.games[index].listing;
games[count].failed = (unsigned char)identifier_failed(games[count].identifier);
count++;
}
pthread_mutex_unlock(&p2p_lock);
qsort(games, (size_t)count, sizeof(*games), listing_order);
return count;
}
void p2p_lobby_mark_failed(const unsigned char *identifier)
{
pthread_mutex_lock(&p2p_lock);
if (!identifier_failed(identifier) && lobby.failed_count < MAXIMUM_GAMES)
memcpy(lobby.failed[lobby.failed_count++], identifier, P2P_IDENTIFIER_SIZE);
pthread_mutex_unlock(&p2p_lock);
}
+648 -85
View File
@@ -3,9 +3,23 @@ P2P_SIGNAL.C
Internet play's signalling (p2p.c): how a joiner and the host of an invite
tell each other where they can be reached, through public MQTT brokers
(network.signalling_brokers; MQTT 3.1.1 over TCP). Every broker is used at
once, so any one of them working is enough (an answer goes back through
each broker a request came through).
(those in brokers.txt, network.brokers_file; MQTT 5 over TCP, or 3.1.1 with
a broker that refuses 5). Every broker is used at once, so any one of them
working is enough (an answer goes back through each broker a request came
through).
They also carry the server browser's listings of public games (p2p_lobby.c):
retained in each host's slot, published at least once (QoS 1, sent again
until the broker acknowledges them), expiring at the broker after
LISTING_EXPIRY seconds (MQTT 5), and cleared by the broker if the host's
connection dies (the will every connection sets: harmless when not hosting).
A broker may drop a connection's publishes past about 10 a second without a
word (EMQX), and a host's answers to a flood of JOINs would reach that: each
broker's publishes spend from a bucket (PUBLISH_BURST at once, one more each
PUBLISH_INTERVAL). Answers to proven joiners come first, then the listing
(kept to publish later), then a joiner's requests and the browser's queries;
answers to requests not proven yet only while some are left over (the
joiner asks again).
Everything that passes through them is sealed with a key derived from the
invite's token, and goes to topics that are hashes of it, so the brokers
@@ -81,20 +95,42 @@ enum
host takes at most a few new players a minute: this is hours of them;
one is not forgotten while its host nonce lasts: USED_REQUEST_TIME) */
MAXIMUM_USED_REQUESTS = 1024,
TOPIC_SIZE = 7 + 32 + 1,
/* (p2p_code.c's are as long) */
TOPIC_SIZE_CHECK = 1 / (TOPIC_SIZE == P2P_CODE_TOPIC_SIZE),
/* (a slot's: hceu/3/lobby/s/ and a key hash in hex) */
TOPIC_SIZE = 64,
NONCE_SIZE = 8,
/* an ACCEPT's or a proven JOIN's tag: the first half of an HMAC-SHA256 */
TAG_SIZE = 16,
/* a proven JOIN's end: the host's nonce, and the tag */
PROOF_SIZE = NONCE_SIZE + TAG_SIZE,
BUFFER_SIZE = 4096,
MAXIMUM_MESSAGE_SIZE = 256,
MAXIMUM_MESSAGE_SIZE = 512,
/* a listing's most (p2p_lobby.c's MAXIMUM_LISTING_SIZE, and some) */
MAXIMUM_LISTING_SIZE = 256,
/* the publishes awaiting acknowledgement on a broker */
MAXIMUM_IN_FLIGHT = 4,
/* the topics a broker is subscribed to (_topic_*) */
NUMBER_OF_TOPICS = 8,
/* a broker's publishes: at most PUBLISH_BURST at once, one more each
PUBLISH_INTERVAL milliseconds (EMQX drops a connection's publishes past
about 10 a second, without a word) */
PUBLISH_BURST = 8,
PUBLISH_INTERVAL = 125,
/* what is kept back of the bucket for answers to proven joiners and the
listing: a request's answer, and a query, need this many left */
UNPROVEN_RESERVE = 3,
/* seconds a listing lasts at the broker (MQTT 5's Message Expiry
Interval): a dead host's goes even from a broker that kept it through a
restart */
LISTING_EXPIRY = 90,
/* milliseconds */
CONNECT_TIMEOUT = 10000,
/* a broker that failed is tried again after this, twice as long each
failure after, to MAXIMUM_RETRY_INTERVAL */
RETRY_INTERVAL = 15000,
MAXIMUM_RETRY_INTERVAL = 120000,
/* a publish at least once not acknowledged is sent again */
RESEND_INTERVAL = 5000,
KEEP_ALIVE_SECONDS = 60,
PING_INTERVAL = 30000,
SILENCE_TIMEOUT = 90000,
@@ -130,6 +166,31 @@ enum
_broker_ready,
};
enum
{
_topic_host,
_topic_join,
/* the server browser's (p2p_lobby.c): the own slot, queries, all slots */
_topic_own_slot,
_topic_query,
_topic_slots,
/* the VR port's: a hosted join code's, a looked up one's, the public
games' (p2p_code.c, p2p_list.c) */
_topic_code_host,
_topic_code_look,
_topic_list,
};
/* MQTT 5's properties */
enum
{
_property_message_expiry = 0x02,
_property_server_keep_alive = 0x13,
_property_receive_maximum = 0x21,
_property_retain_available = 0x25,
_property_wildcard_available = 0x28,
};
enum
{
_message_join = 'J',
@@ -151,14 +212,41 @@ struct broker
unsigned long heard_time;
int failures;
unsigned short packet_identifier;
/* the topics it has been asked for */
char host_topic[TOPIC_SIZE];
char join_topic[TOPIC_SIZE];
/* (join codes' topics: p2p_code.c) */
char code_host_topic[TOPIC_SIZE];
char code_look_topic[TOPIC_SIZE];
/* (public games': p2p_list.c) */
char list_topic[TOPIC_SIZE];
/* 5 (MQTT 5), or 4 (3.1.1: the broker refused 5) */
int protocol;
/* as its CONNACK said (MQTT 5; 3.1.1 brokers have both): without
either, it carries only signalling, not listings */
int retain_available;
int wildcard_available;
/* seconds; its own if it said */
int keep_alive;
int receive_maximum;
/* the bucket its publishes spend from */
int publish_tokens;
unsigned long publish_time;
/* the topics it has been asked for (_topic_*) */
char topics[NUMBER_OF_TOPICS][TOPIC_SIZE];
/* the listing's version it was given (signalling.lobby_version); and
whether it has yet to have its slot cleared (after a tombstone) */
int lobby_version;
int lobby_clear_pending;
/* a query to send once subscribed to the slots */
int query_pending;
/* publishes at least once, awaiting PUBACK */
struct
{
int used;
unsigned short identifier;
unsigned long sent_time;
/* a listing, which a newer one replaces (not a tombstone or a
clearing) */
int listing;
/* refused (MQTT 5's PUBACK said why): sent again as a new publish
(the refusal ended the old one's identifier) */
int refused;
int size;
unsigned char payload[MAXIMUM_LISTING_SIZE];
} in_flight[MAXIMUM_IN_FLIGHT];
unsigned char input[BUFFER_SIZE];
int input_size;
unsigned char output[BUFFER_SIZE];
@@ -210,6 +298,18 @@ static struct
int broker_count;
char client_identifier[24];
/* the server browser (p2p_lobby.c): this machine's slot (its will
clears it), whether its game is listed and whether it browses; the
listing to publish (none: size 0), its version, and whether it is a
tombstone (the slot is cleared after it) */
char own_slot[TOPIC_SIZE];
int lobby_listed;
int lobby_browsing;
unsigned char lobby_listing[MAXIMUM_LISTING_SIZE];
int lobby_listing_size;
int lobby_version;
int lobby_closing;
/* hosting */
int hosting;
unsigned char host_token[P2P_TOKEN_SIZE];
@@ -326,11 +426,12 @@ static void broker_close(struct broker *broker, int failed)
broker->state_time = p2p_now();
broker->input_size = 0;
broker->output_size = 0;
broker->host_topic[0] = 0;
broker->join_topic[0] = 0;
broker->code_host_topic[0] = 0;
broker->code_look_topic[0] = 0;
broker->list_topic[0] = 0;
memset(broker->topics, 0, sizeof(broker->topics));
memset(broker->in_flight, 0, sizeof(broker->in_flight));
/* (the will cleared the slot: the listing again once connected) */
broker->lobby_version = 0;
broker->lobby_clear_pending = 0;
broker->query_pending = 0;
if (failed)
broker->failures++;
}
@@ -354,23 +455,50 @@ static void broker_flush(struct broker *broker)
}
}
static int put_variable(unsigned char *bytes, int value)
{
int size = 0;
do
{
unsigned char byte = (unsigned char)(value & 127);
value >>= 7;
bytes[size++] = (unsigned char)(value ? byte | 128 : byte);
} while (value);
return size;
}
/* reads a variable byte integer; 0 if it does not fit */
static int get_variable(const unsigned char *bytes, int size, int *offset, int *value)
{
int shift = 0;
*value = 0;
for (;;)
{
unsigned char byte;
if (*offset >= size || shift > 21)
return 0;
byte = bytes[(*offset)++];
*value |= (byte & 127) << shift;
shift += 7;
if (!(byte & 128))
return 1;
}
}
/* queues a packet: its fixed header's first byte, and its body */
static void broker_send(struct broker *broker, unsigned char type, const unsigned char *body, int size)
{
unsigned char header[5];
int header_size = 1;
int remaining = size;
int header_size;
if (broker->socket < 0)
return;
header[0] = type;
do
{
unsigned char byte = (unsigned char)(remaining & 127);
remaining >>= 7;
header[header_size++] = (unsigned char)(remaining ? byte | 128 : byte);
} while (remaining);
header_size = 1 + put_variable(header + 1, size);
if (broker->output_size + header_size + size > BUFFER_SIZE)
{
broker_close(broker, 1);
@@ -393,57 +521,170 @@ static int put_string(unsigned char *body, const char *text)
return size + 2;
}
static void broker_topic(struct broker *broker, const char *topic, int subscribe)
static unsigned short next_packet_identifier(struct broker *broker)
{
unsigned char body[4 + TOPIC_SIZE + 1];
int size = 0;
if (++broker->packet_identifier == 0)
broker->packet_identifier = 1;
body[size++] = (unsigned char)(broker->packet_identifier >> 8);
body[size++] = (unsigned char)broker->packet_identifier;
return broker->packet_identifier;
}
/* whether the broker may publish now, spending from its bucket: reserve is
how many must be left after (UNPROVEN_RESERVE for what may wait) */
static int broker_may_publish(struct broker *broker, int reserve)
{
unsigned long now = p2p_now();
int gained = (int)((now - broker->publish_time) / PUBLISH_INTERVAL);
if (gained > 0)
{
broker->publish_tokens = broker->publish_tokens + gained > PUBLISH_BURST ? PUBLISH_BURST :
broker->publish_tokens + gained;
broker->publish_time += (unsigned long)gained * PUBLISH_INTERVAL;
if (broker->publish_tokens == PUBLISH_BURST)
broker->publish_time = now;
}
if (broker->publish_tokens <= reserve)
return 0;
broker->publish_tokens--;
return 1;
}
static void broker_topic(struct broker *broker, const char *topic, int subscribe, int no_local)
{
unsigned char body[5 + TOPIC_SIZE + 1];
unsigned short identifier = next_packet_identifier(broker);
int size = 0;
body[size++] = (unsigned char)(identifier >> 8);
body[size++] = (unsigned char)identifier;
/* (MQTT 5: no properties) */
if (broker->protocol == 5)
body[size++] = 0;
size += put_string(body + size, topic);
/* at most once; MQTT 5: No Local, not this connection's own publishes */
if (subscribe)
body[size++] = 0; /* at most once */
body[size++] = (unsigned char)(broker->protocol == 5 && no_local ? 0x04 : 0);
broker_send(broker, subscribe ? 0x82 : 0xA2, body, size);
}
/* a publish at most once, not retained: signalling's, and queries */
static void broker_publish(struct broker *broker, const char *topic, const unsigned char *payload, int payload_size)
{
unsigned char body[2 + TOPIC_SIZE + MAXIMUM_MESSAGE_SIZE + P2P_SEAL_OVERHEAD];
unsigned char body[3 + TOPIC_SIZE + MAXIMUM_MESSAGE_SIZE + P2P_SEAL_OVERHEAD];
int size = put_string(body, topic);
if (broker->protocol == 5)
body[size++] = 0;
memcpy(body + size, payload, (size_t)payload_size);
broker_send(broker, 0x30, body, size + payload_size);
}
/* a publish at least once to the own slot, retained: a listing (expiring
at the broker), or an empty one, which clears it; again (duplicate) if the
first was not acknowledged */
static void broker_publish_slot(struct broker *broker, unsigned short identifier, const unsigned char *payload,
int payload_size, int duplicate)
{
unsigned char body[2 + TOPIC_SIZE + 2 + 8 + MAXIMUM_LISTING_SIZE];
int size = put_string(body, signalling.own_slot);
body[size++] = (unsigned char)(identifier >> 8);
body[size++] = (unsigned char)identifier;
if (broker->protocol == 5)
{
if (payload_size)
{
body[size++] = 5;
body[size++] = _property_message_expiry;
body[size++] = 0;
body[size++] = 0;
body[size++] = 0;
body[size++] = LISTING_EXPIRY;
}
else
{
body[size++] = 0;
}
}
if (payload_size)
memcpy(body + size, payload, (size_t)payload_size);
/* PUBLISH, QoS 1, retained */
broker_send(broker, (unsigned char)(0x30 | (duplicate ? 0x08 : 0) | 0x02 | 0x01), body, size + payload_size);
broker->sent_time = p2p_now();
}
/* a listing (or a clearing: size 0) to the own slot, at least once: 0 if
there is no room for it yet */
static int broker_publish_listing(struct broker *broker, const unsigned char *payload, int size, int listing)
{
int maximum = broker->receive_maximum < MAXIMUM_IN_FLIGHT ? broker->receive_maximum : MAXIMUM_IN_FLIGHT;
int count = 0;
int free_index = -1;
int index;
/* (a listing replaces an older one not acknowledged yet) */
for (index = 0; index < MAXIMUM_IN_FLIGHT; index++)
{
if (broker->in_flight[index].used && broker->in_flight[index].listing && listing)
broker->in_flight[index].used = 0;
if (broker->in_flight[index].used)
count++;
else if (free_index < 0)
free_index = index;
}
if (free_index < 0 || count >= maximum || !broker_may_publish(broker, 0))
return 0;
broker->in_flight[free_index].used = 1;
broker->in_flight[free_index].identifier = next_packet_identifier(broker);
broker->in_flight[free_index].sent_time = p2p_now();
broker->in_flight[free_index].listing = listing;
broker->in_flight[free_index].refused = 0;
broker->in_flight[free_index].size = size;
if (size)
memcpy(broker->in_flight[free_index].payload, payload, (size_t)size);
broker_publish_slot(broker, broker->in_flight[free_index].identifier, payload, size, 0);
return 1;
}
/* whether the broker carries the server browser: retained messages and
wildcards */
static int broker_carries_lobby(const struct broker *broker)
{
return broker->retain_available && broker->wildcard_available;
}
/* the topics a ready broker should be subscribed to */
static void broker_sync_topics(struct broker *broker)
{
const char *wanted[5];
char *had[5];
const char *wanted[NUMBER_OF_TOPICS];
int lobby = broker_carries_lobby(broker);
int index;
if (broker->state != _broker_ready)
return;
wanted[0] = signalling.hosting ? signalling.host_topic : "";
wanted[1] = signalling.joining ? signalling.join_topic : "";
p2p_code_topics(&wanted[2], &wanted[3]);
wanted[4] = p2p_list_topic();
had[0] = broker->host_topic;
had[1] = broker->join_topic;
had[2] = broker->code_host_topic;
had[3] = broker->code_look_topic;
had[4] = broker->list_topic;
for (index = 0; index < 5; index++)
wanted[_topic_host] = signalling.hosting ? signalling.host_topic : "";
wanted[_topic_join] = signalling.joining ? signalling.join_topic : "";
wanted[_topic_own_slot] = lobby && signalling.lobby_listed ? signalling.own_slot : "";
wanted[_topic_query] = lobby && signalling.lobby_listed ? P2P_LOBBY_QUERY_TOPIC : "";
wanted[_topic_slots] = lobby && signalling.lobby_browsing ? P2P_LOBBY_SLOT_PREFIX "+" : "";
/* (the VR port's join codes and public games: p2p_code.c, p2p_list.c) */
p2p_code_topics(&wanted[_topic_code_host], &wanted[_topic_code_look]);
wanted[_topic_list] = p2p_list_topic();
for (index = 0; index < NUMBER_OF_TOPICS; index++)
{
if (!strcmp(wanted[index], had[index]))
char *had = broker->topics[index];
if (!strcmp(wanted[index], had))
continue;
if (had[index][0])
broker_topic(broker, had[index], 0);
if (had[0])
broker_topic(broker, had, 0, 0);
if (wanted[index][0])
broker_topic(broker, wanted[index], 1);
strcpy(had[index], wanted[index]);
broker_topic(broker, wanted[index], 1, index == _topic_own_slot);
/* (once subscribed to the slots, the hosts are asked to publish:
retained copies come at once, but may be old) */
if (index == _topic_slots && wanted[index][0])
broker->query_pending = 1;
strcpy(had, wanted[index]);
}
}
@@ -453,22 +694,80 @@ static void publish_everywhere(const char *topic, const unsigned char *payload,
for (index = 0; index < signalling.broker_count; index++)
{
if (signalling.brokers[index].state == _broker_ready)
broker_publish(&signalling.brokers[index], topic, payload, size);
struct broker *broker = &signalling.brokers[index];
if (broker->state == _broker_ready && broker_may_publish(broker, 0))
broker_publish(broker, topic, payload, size);
}
}
/* the listing's publishes due on a broker: the listing, or a tombstone and
then the slot's clearing; acknowledgements not come sent again */
static void broker_update_lobby(struct broker *broker)
{
int index;
if (broker->state != _broker_ready || !broker_carries_lobby(broker))
return;
for (index = 0; index < MAXIMUM_IN_FLIGHT; index++)
{
if (broker->in_flight[index].used && elapsed(broker->in_flight[index].sent_time, RESEND_INTERVAL) &&
broker_may_publish(broker, 0))
{
int duplicate = !broker->in_flight[index].refused;
if (!duplicate)
broker->in_flight[index].identifier = next_packet_identifier(broker);
broker->in_flight[index].refused = 0;
broker->in_flight[index].sent_time = p2p_now();
broker_publish_slot(broker, broker->in_flight[index].identifier, broker->in_flight[index].payload,
broker->in_flight[index].size, duplicate);
}
}
if (broker->lobby_version != signalling.lobby_version && signalling.lobby_listing_size &&
broker_publish_listing(broker, signalling.lobby_listing, signalling.lobby_listing_size,
!signalling.lobby_closing))
{
broker->lobby_version = signalling.lobby_version;
broker->lobby_clear_pending = signalling.lobby_closing;
}
if (broker->lobby_clear_pending && broker->lobby_version == signalling.lobby_version &&
broker_publish_listing(broker, NULL, 0, 0))
{
broker->lobby_clear_pending = 0;
}
if (broker->query_pending && broker->topics[_topic_slots][0] && broker_may_publish(broker, UNPROVEN_RESERVE))
{
unsigned char nonce[NONCE_SIZE];
posix_random_bytes(nonce, sizeof(nonce));
broker_publish(broker, P2P_LOBBY_QUERY_TOPIC, nonce, sizeof(nonce));
broker->query_pending = 0;
}
}
static void broker_connected(struct broker *broker)
{
unsigned char body[64];
unsigned char body[32 + sizeof(signalling.client_identifier) + TOPIC_SIZE];
int size = 0;
if (!broker->protocol)
broker->protocol = 5;
size += put_string(body, "MQTT");
body[size++] = 4; /* 3.1.1 */
body[size++] = 0x02; /* a clean session */
body[size++] = (unsigned char)broker->protocol;
/* a clean session, and a will: an empty retained message to this
machine's slot, which clears its listing if the connection dies */
body[size++] = 0x02 | 0x04 | 0x20;
body[size++] = 0;
body[size++] = KEEP_ALIVE_SECONDS;
if (broker->protocol == 5)
body[size++] = 0;
size += put_string(body + size, signalling.client_identifier);
if (broker->protocol == 5)
body[size++] = 0;
size += put_string(body + size, signalling.own_slot);
body[size++] = 0;
body[size++] = 0;
broker->state = _broker_awaiting_acknowledgement;
broker->state_time = p2p_now();
broker_send(broker, 0x10, body, size);
@@ -726,7 +1025,7 @@ static int request_used(const unsigned char *request)
/* the host's answer to a request, through the broker it came through */
static void send_accept(struct broker *broker, const unsigned char *identifier, const unsigned char *nonce,
const unsigned char *host_nonce, const unsigned char *base)
const unsigned char *host_nonce, const unsigned char *base, int proven)
{
unsigned char answer[MAXIMUM_MESSAGE_SIZE];
unsigned char sealed[MAXIMUM_MESSAGE_SIZE + P2P_SEAL_OVERHEAD];
@@ -746,7 +1045,8 @@ static void send_accept(struct broker *broker, const unsigned char *identifier,
size += TAG_SIZE;
size = p2p_seal(signalling.host_key, answer, size, sealed);
make_topic(signalling.host_token, "joiner", identifier, topic);
if (broker->state == _broker_ready)
/* (a proven joiner's first: its session is made; others ask again) */
if (broker->state == _broker_ready && broker_may_publish(broker, proven ? 0 : UNPROVEN_RESERVE))
broker_publish(broker, topic, sealed, size);
}
@@ -799,7 +1099,7 @@ static void join_received(struct broker *broker, const unsigned char *message, i
}
joiner->answered_time = p2p_now();
joiner->answered_broker_times[broker_index] = joiner->answered_time;
send_accept(broker, identifier, joiner->nonce, joiner->host_nonce, joiner->base);
send_accept(broker, identifier, joiner->nonce, joiner->host_nonce, joiner->base, proven);
return;
}
memcpy(request, identifier, P2P_IDENTIFIER_SIZE);
@@ -860,7 +1160,7 @@ static void join_received(struct broker *broker, const unsigned char *message, i
asker->answered_nonce_brokers[slot] = (signed char)broker_index;
asker->answered_nonce_times[slot] = asker->answered_time;
host_nonce_for(public_key, nonce, p2p_now() / HOST_NONCE_PERIOD, host_nonce);
send_accept(broker, identifier, nonce, host_nonce, asker->base);
send_accept(broker, identifier, nonce, host_nonce, asker->base, 0);
return;
}
/* proven: with a nonce the host answered the request with lately, and a
@@ -897,7 +1197,7 @@ static void join_received(struct broker *broker, const unsigned char *message, i
memset(joiner->answered_broker_times, 0, sizeof(joiner->answered_broker_times));
joiner->answered_broker_times[broker_index] = joiner->answered_time;
joiner->used = 1;
send_accept(broker, identifier, nonce, host_nonce, base);
send_accept(broker, identifier, nonce, host_nonce, base, 1);
}
/* the joiner: the host answered */
@@ -947,7 +1247,8 @@ static void accept_received(const unsigned char *message, int size)
send_join();
}
static void publish_received(struct broker *broker, const char *topic, const unsigned char *payload, int size)
static void publish_received(struct broker *broker, const char *topic, const unsigned char *payload, int size,
int retained)
{
unsigned char message[MAXIMUM_MESSAGE_SIZE];
int message_size;
@@ -956,6 +1257,16 @@ static void publish_received(struct broker *broker, const char *topic, const uns
return;
if (p2p_code_received(topic, payload, size) || p2p_list_received(topic, payload, size))
return;
if (!strncmp(topic, P2P_LOBBY_SLOT_PREFIX, sizeof(P2P_LOBBY_SLOT_PREFIX) - 1))
{
p2p_lobby_slot_heard(topic + sizeof(P2P_LOBBY_SLOT_PREFIX) - 1, payload, size, retained);
return;
}
if (!strcmp(topic, P2P_LOBBY_QUERY_TOPIC))
{
p2p_lobby_query_heard();
return;
}
if (signalling.hosting && !strcmp(topic, signalling.host_topic))
{
message_size = p2p_open(signalling.host_key, payload, size, message);
@@ -970,6 +1281,112 @@ static void publish_received(struct broker *broker, const char *topic, const uns
}
}
/* a CONNACK: 0 if the connection is closed (refused, or to try 3.1.1) */
static int broker_acknowledged(struct broker *broker, const unsigned char *body, int size)
{
int code = body[1];
int offset = 2;
int properties = 0;
broker->retain_available = 1;
broker->wildcard_available = 1;
broker->keep_alive = KEEP_ALIVE_SECONDS;
broker->receive_maximum = MAXIMUM_IN_FLIGHT;
/* a broker that has not MQTT 5 answers 0x84 (5's unsupported protocol
version), or 3.1.1's 1 (unacceptable protocol version) */
if (broker->protocol == 5 && (code == 0x84 || (size == 2 && code == 1)))
{
platform_log("Internet play: the signalling broker %s has not MQTT 5; using 3.1.1", broker->host);
broker->protocol = 4;
broker_close(broker, 0);
/* (again at once) */
broker->state_time = p2p_now() - MAXIMUM_RETRY_INTERVAL;
return 0;
}
if (code != 0)
{
platform_log("Internet play: the signalling broker %s refused the connection", broker->host);
broker_close(broker, 1);
return 0;
}
if (broker->protocol == 5 && get_variable(body, size, &offset, &properties))
{
int end = offset + properties > size ? size : offset + properties;
while (offset < end)
{
int property = body[offset++];
switch (property)
{
/* a byte */
case 0x01: case 0x17: case 0x19: case 0x24: case 0x25: case 0x28: case 0x29: case 0x2A:
if (offset < end)
{
if (property == _property_retain_available)
broker->retain_available = body[offset];
else if (property == _property_wildcard_available)
broker->wildcard_available = body[offset];
}
offset += 1;
break;
/* two */
case 0x13: case 0x21: case 0x22: case 0x23:
if (offset + 2 <= end)
{
int value = body[offset] << 8 | body[offset + 1];
if (property == _property_server_keep_alive && value > 0)
broker->keep_alive = value;
else if (property == _property_receive_maximum && value > 0)
broker->receive_maximum = value;
}
offset += 2;
break;
/* four */
case 0x02: case 0x11: case 0x18: case 0x27:
offset += 4;
break;
/* a variable byte integer */
case 0x0B:
{
int value;
if (!get_variable(body, end, &offset, &value))
offset = end;
break;
}
/* a string or binary data: a length, then that */
case 0x03: case 0x08: case 0x09: case 0x12: case 0x15: case 0x16: case 0x1A: case 0x1C: case 0x1F:
offset += offset + 2 <= end ? 2 + (body[offset] << 8 | body[offset + 1]) : 2;
break;
/* a pair of strings */
case 0x26:
{
int pair;
for (pair = 0; pair < 2; pair++)
offset += offset + 2 <= end ? 2 + (body[offset] << 8 | body[offset + 1]) : 2;
break;
}
default:
/* (unknown: the rest can't be read) */
offset = end;
break;
}
}
}
broker->state = _broker_ready;
broker->failures = 0;
broker->publish_tokens = PUBLISH_BURST;
broker->publish_time = p2p_now();
broker_sync_topics(broker);
/* a joiner's first request need not wait for the next repeat */
if (signalling.joining)
send_join();
return 1;
}
/* the packets that arrived whole */
static void broker_parse(struct broker *broker)
{
@@ -1009,36 +1426,61 @@ static void broker_parse(struct broker *broker)
type = broker->input[0];
if ((type & 0xF0) == 0x20 && remaining >= 2)
{
/* CONNACK */
if (broker->input[header_size + 1] != 0)
{
platform_log("Internet play: the signalling broker %s refused the connection", broker->host);
broker_close(broker, 1);
if (!broker_acknowledged(broker, broker->input + header_size, remaining))
return;
}
broker->state = _broker_ready;
broker->failures = 0;
broker_sync_topics(broker);
/* a joiner's first request need not wait for the next repeat */
if (signalling.joining)
send_join();
}
else if ((type & 0xF0) == 0x30 && remaining >= 2)
{
/* PUBLISH */
const unsigned char *body = broker->input + header_size;
int topic_size = body[0] << 8 | body[1];
int offset = 2 + topic_size + (((type >> 1) & 3) ? 2 : 0);
int quality = (type >> 1) & 3;
int offset = 2 + topic_size;
int properties = 0;
if (quality)
{
/* (subscriptions ask for at most once; acknowledged all the
same) */
if (offset + 2 <= remaining && quality == 1)
broker_send(broker, 0x40, body + offset, 2);
offset += 2;
}
if (broker->protocol == 5 && get_variable(body, remaining, &offset, &properties))
offset += properties;
if (topic_size < TOPIC_SIZE && offset <= remaining)
{
char topic[TOPIC_SIZE];
memcpy(topic, body + 2, (size_t)topic_size);
topic[topic_size] = 0;
publish_received(broker, topic, body + offset, remaining - offset);
publish_received(broker, topic, body + offset, remaining - offset, type & 1);
}
}
else if ((type & 0xF0) == 0x40 && remaining >= 2)
{
/* PUBACK: MQTT 5's reason, if any, of 0x80 or more is a refusal
(a quota, a rate): sent again later */
const unsigned char *body = broker->input + header_size;
unsigned short identifier = (unsigned short)(body[0] << 8 | body[1]);
int refused = remaining >= 3 && body[2] >= 0x80;
int index;
for (index = 0; index < MAXIMUM_IN_FLIGHT; index++)
{
if (broker->in_flight[index].used && broker->in_flight[index].identifier == identifier)
{
broker->in_flight[index].used = refused;
broker->in_flight[index].refused = refused;
}
}
}
else if ((type & 0xF0) == 0xE0)
{
/* DISCONNECT (MQTT 5): the broker's */
broker_close(broker, 1);
return;
}
/* (what it sent in answer may have closed it, emptying input) */
if (broker->socket < 0)
return;
@@ -1080,8 +1522,50 @@ static void broker_readable(struct broker *broker)
/* ---------- p2p.c's side */
/* the brokers in network.brokers_file (beside config.toml, unless a full
path: port/assets/network/brokers.txt, which the builds put there), one on
each line, "#" starting a comment, into text: host:port entries separated by
commas; empty if the file cannot be read */
static void brokers_list(char *text, size_t size)
{
const char *name = config_string("network.brokers_file");
char path[1024];
char *file;
size_t file_size = 0, index, length = 0;
int comment = 0;
text[0] = 0;
if (name[0] == '/' || name[0] == '\\' || (name[0] && name[1] == ':'))
snprintf(path, sizeof(path), "%s", name);
else
{
config_folder(path, sizeof(path));
snprintf(path + strlen(path), sizeof(path) - strlen(path), "%s", name);
}
file = config_file_read(path, &file_size);
if (!file)
{
platform_log("Internet play: the brokers' file %s cannot be read (network.brokers_file)", path);
return;
}
for (index = 0; index < file_size && length + 1 < size; index++)
{
char character = file[index];
if (character == '\n' || character == '\r')
comment = 0;
else if (character == '#')
comment = 1;
if (!comment)
text[length++] = character == '\n' || character == '\r' || character == '\t' ? ',' : character;
}
text[length] = 0;
free(file);
}
void p2p_signal_start(void)
{
char list[1024];
const char *text;
unsigned char random[8];
char hex[17];
@@ -1092,7 +1576,14 @@ void p2p_signal_start(void)
posix_random_bytes(random, sizeof(random));
p2p_hex(random, sizeof(random), hex);
snprintf(signalling.client_identifier, sizeof(signalling.client_identifier), "hceu-%s", hex);
text = config_string("network.signalling_brokers");
{
unsigned char hash[P2P_KEY_HASH_SIZE];
p2p_key_hash(p2p_public_key(), hash);
p2p_lobby_slot_topic(hash, signalling.own_slot, sizeof(signalling.own_slot));
}
brokers_list(list, sizeof(list));
text = list;
while (*text && signalling.broker_count < MAXIMUM_BROKERS)
{
const char *end = text + strcspn(text, ",");
@@ -1124,7 +1615,9 @@ void p2p_signal_start(void)
text = *end ? end + 1 : end;
}
if (!signalling.broker_count)
platform_log("Internet play: no signalling brokers (network.signalling_brokers), so invites cannot work");
platform_log("Internet play: no signalling brokers (network.brokers_file), so invites cannot work");
else if (text[strspn(text, ", ")])
platform_log("Internet play: only the first %d signalling brokers are used", MAXIMUM_BROKERS);
}
void p2p_signal_select_sets(int *read, int *read_count, int *write, int *write_count, int maximum_count)
@@ -1164,7 +1657,8 @@ void p2p_signal_update(const int *read, int read_count, const int *write, int wr
for (index = 0; index < signalling.broker_count; index++)
{
struct broker *broker = &signalling.brokers[index];
int retry = RETRY_INTERVAL * (broker->failures < 4 ? broker->failures + 1 : 4);
int retry = broker->failures < 1 ? RETRY_INTERVAL :
broker->failures >= 4 ? MAXIMUM_RETRY_INTERVAL : RETRY_INTERVAL << (broker->failures - 1);
switch (broker->state)
{
@@ -1191,13 +1685,18 @@ void p2p_signal_update(const int *read, int read_count, const int *write, int wr
broker_readable(broker);
if (broker->state != _broker_ready)
continue;
if (elapsed(broker->heard_time, SILENCE_TIMEOUT))
if (elapsed(broker->heard_time, (unsigned long)broker->keep_alive * 1500 > SILENCE_TIMEOUT ?
(unsigned long)broker->keep_alive * 1500 : SILENCE_TIMEOUT))
{
broker_close(broker, 1);
continue;
}
if (elapsed(broker->sent_time, PING_INTERVAL))
if (elapsed(broker->sent_time, (unsigned long)broker->keep_alive * 500 < PING_INTERVAL ?
(unsigned long)broker->keep_alive * 500 : PING_INTERVAL))
{
broker_send(broker, 0xC0, NULL, 0);
}
broker_update_lobby(broker);
}
if (signalling.joining && !signalling.join_answered && elapsed(signalling.join_nonce_time, UNANSWERED_TIME))
{
@@ -1244,7 +1743,7 @@ void p2p_signal_publish(const char *topic, const unsigned char *payload, int siz
void p2p_signal_publish_retained(const char *topic, const unsigned char *payload, int size)
{
unsigned char body[2 + TOPIC_SIZE + MAXIMUM_MESSAGE_SIZE];
unsigned char body[3 + TOPIC_SIZE + MAXIMUM_MESSAGE_SIZE];
int index;
if (size > MAXIMUM_MESSAGE_SIZE)
@@ -1257,6 +1756,9 @@ void p2p_signal_publish_retained(const char *topic, const unsigned char *payload
if (broker->state != _broker_ready)
continue;
body_size = put_string(body, topic);
/* (MQTT 5: no properties) */
if (broker->protocol == 5)
body[body_size++] = 0;
if (size)
memcpy(body + body_size, payload, (size_t)size);
/* (PUBLISH, at most once, retained: an empty one clears it) */
@@ -1307,3 +1809,64 @@ void p2p_signal_stop_joining(void)
signalling.joining = 0;
sync_all_topics();
}
void p2p_signal_lobby_topics(int listed, int browsing)
{
signalling.lobby_listed = listed;
signalling.lobby_browsing = browsing;
sync_all_topics();
}
void p2p_signal_lobby_publish(const unsigned char *listing, int size, int closing)
{
if (size > MAXIMUM_LISTING_SIZE)
return;
memcpy(signalling.lobby_listing, listing, (size_t)size);
signalling.lobby_listing_size = size;
signalling.lobby_closing = closing;
signalling.lobby_version++;
/* (at once where the bucket allows; the rest in the coming passes) */
{
int index;
for (index = 0; index < signalling.broker_count; index++)
broker_update_lobby(&signalling.brokers[index]);
}
}
void p2p_signal_lobby_query(void)
{
int index;
for (index = 0; index < signalling.broker_count; index++)
{
if (signalling.brokers[index].topics[_topic_slots][0])
signalling.brokers[index].query_pending = 1;
broker_update_lobby(&signalling.brokers[index]);
}
}
void p2p_signal_lobby_quit(void)
{
int index;
for (index = 0; index < signalling.broker_count; index++)
{
struct broker *broker = &signalling.brokers[index];
static const unsigned char disconnect[2] = { 0, 0 };
if (broker->state != _broker_ready)
continue;
/* (unless sent already: the tombstone and the clearing) */
if (broker_carries_lobby(broker) && signalling.lobby_listing_size &&
(broker->lobby_version != signalling.lobby_version || broker->lobby_clear_pending))
{
broker_publish_slot(broker, next_packet_identifier(broker), signalling.lobby_listing,
signalling.lobby_listing_size, 0);
broker_publish_slot(broker, next_packet_identifier(broker), NULL, 0, 0);
}
/* DISCONNECT (MQTT 5: a normal one, its reason and no properties) */
broker_send(broker, 0xE0, disconnect, broker->protocol == 5 ? 2 : 0);
broker_flush(broker);
}
}
+79 -16
View File
@@ -66,15 +66,28 @@ struct config_setting
static const struct config_setting config_settings[] =
{
{ "display.fullscreen", _config_boolean, "true", "HALO_FULLSCREEN", _environment_value, _platform_desktop,
"Start fullscreen, drawing at the display's resolution and shape; false\n"
"starts in a window, which draws the Xbox's 640x480. F11 switches." },
"Where display.mode is empty: start borderless over the whole display;\n"
"false starts in a window. F11 switches." },
{ "display.mode", _config_string, "\"\"", "HALO_DISPLAY_MODE", _environment_value, _platform_desktop,
"\"fullscreen\" takes the display at its desktop resolution, \"borderless\"\n"
"is a window over the whole desktop (both draw at the display's\n"
"resolution), \"windowed\" a window of the Xbox's 640x480, scaled. Empty:\n"
"display.fullscreen's (true: borderless). F11 switches to the window and back." },
"\"fullscreen\" takes the display (at display.resolution's mode),\n"
"\"borderless\" is a window over the whole desktop, \"windowed\" a window\n"
"(display.window_size). Empty: display.fullscreen's (true: borderless).\n"
"F11 switches to the window and back." },
{ "display.resolution", _config_string, "\"native\"", "HALO_RESOLUTION", _environment_value, _platform_desktop,
"What fullscreen and borderless draw at: \"native\", the display's own, or\n"
"\"<width>x<height>\" (\"1920x1080\"), 640x480 or more. Fullscreen sets the\n"
"display to it; borderless draws it scaled to the display." },
{ "display.resolution_scaling", _config_string, "\"native\"", "HALO_RESOLUTION_SCALING", _environment_value,
_platform_desktop,
"\"native\" draws at the window's resolution (fullscreen, the display's or\n"
"display.resolution); \"original\" draws the Xbox's 640x480 and scales it\n"
"up." },
{ "display.window_size", _config_string, "\"\"", "HALO_WINDOW_SIZE", _environment_value, _platform_desktop,
"The window's size, \"<width>x<height>\" (\"1920x1080\"), 640x480 or more (it\n"
"can be resized). Empty: display.window_scale's." },
{ "display.window_scale", _config_integer, "2", "HALO_WINDOW_SCALE", _environment_value, _platform_desktop,
"The window's size as a multiple of 640x480 (it can be resized)." },
"Where display.window_size is empty: the window's size as a multiple of\n"
"640x480." },
{ "display.screen_width", _config_integer, "0", "HALO_SCREEN_WIDTH", _environment_value, _platform_android,
"Columns of the 480-line picture: 0 for the display's shape, 640 for the\n"
"Xbox's 4:3." },
@@ -96,15 +109,17 @@ static const struct config_setting config_settings[] =
"false draws the maps' own bitmaps." },
{ "display.high_res_text", _config_boolean, "true", "HALO_HIGH_RES_TEXT", _environment_value, _platform_all,
"Draw the menus' and HUD's text with the fonts in port/assets/fonts\n"
"(Overpass) at the display's resolution, and the menus' titles from\n"
"port/assets/titles; false draws the maps' bitmap fonts and titles." },
"(Overpass) at the resolution the game draws at, and the menus' titles\n"
"from port/assets/titles; false draws the maps' bitmap fonts and titles." },
{ "display.menus", _config_string, "\"pc\"", "HALO_MENUS", _environment_value, _platform_all,
"The menus: \"pc\" for the PC version's main menu (port/assets/menus,\n"
"and a menus folder here for your own), \"xbox\" for the Xbox's." },
{ "display.player_names", _config_string, "\"all\"", "HALO_PLAYER_NAMES", _environment_value, _platform_all,
"In multiplayer, whose names are drawn above their heads: \"all\",\n"
"\"allies\", \"enemies\" or \"none\". An enemy's shows only while in sight\n"
"and not camouflaged." },
"\"allies\", \"enemies\" or \"none\". An enemy's shows only within the\n"
"motion sensor's reach, in sight and not camouflaged; none show if the\n"
"gametype's motion tracker shows no players, only allies' if it shows\n"
"only friends." },
{ "display.player_name_scale", _config_real, "1.0", "HALO_PLAYER_NAME_SCALE", _environment_value, _platform_all,
"How large the players' names are drawn: 1.0 three quarters of the size of\n"
"the HUD's text, 0.25 to 4." },
@@ -124,6 +139,9 @@ static const struct config_setting config_settings[] =
{ "vr.enabled", _config_boolean, "true", "HALO_VR_ENABLED", _environment_value, _platform_android,
"On a VR headset (Quest, Steam Frame), play in VR; false shows the game\n"
"on a flat panel instead. Read when the app starts." },
{ "vr.menus", _config_string, "\"pc\"", "HALO_VR_MENUS", _environment_value, _platform_android,
"The menus in VR: \"pc\" for the PC version's (as display.menus), \"xbox\"\n"
"for the Xbox's. Read when the menus' map loads." },
{ "vr.resolution_scale", _config_real, "1.0", "HALO_VR_RESOLUTION_SCALE", _environment_value, _platform_android,
"The eye images' size as a multiple of what the headset recommends;\n"
"lower is faster. Read when the app starts." },
@@ -388,11 +406,48 @@ static const struct config_setting config_settings[] =
"networks whose NAT stops connections: when a player joins this\n"
"machine's game, and when joining a game takes too long. False never\n"
"asks." },
{ "network.signalling_brokers", _config_string,
"\"broker.emqx.io:1883,broker.hivemq.com:1883,test.mosquitto.org:1883\"",
"HALO_NET_BROKERS", _environment_value, _platform_all,
"Public MQTT brokers through which the machines of an invite find each\n"
"other (its messages are encrypted); comma-separated host:port." },
{ "network.public_lobby", _config_boolean, "true", "HALO_NET_PUBLIC_LOBBY", _environment_value, _platform_all,
"The server browser: public games are listed through the signalling\n"
"brokers, and Join Game > Server Browser shows them. False lists no\n"
"game of this machine's and shows none." },
{ "network.host_public", _config_boolean, "true", "HALO_NET_HOST_PUBLIC", _environment_value, _platform_all,
"Whether a new game of Create Game > Internet starts as PUBLIC (listed\n"
"in everyone's server browser: anyone can see and join it) or, false,\n"
"PRIVATE (only players with its invite link can join). Server Setup's\n"
"LISTING changes it for each game." },
{ "network.coop_public", _config_boolean, "false", "HALO_NET_COOP_PUBLIC", _environment_value, _platform_all,
"Whether an online co-op game (Create Game > Internet, a SINGLEPLAYER\n"
"map) starts as PUBLIC or, false, PRIVATE: Server Setup's LISTING in\n"
"co-op, which writes its choice here." },
{ "network.coop_friendly_fire", _config_string, "\"on\"", "HALO_NET_COOP_FRIENDLY_FIRE", _environment_value,
_platform_all,
"Whether the players of an online co-op game hurt each other: \"off\",\n"
"\"on\", \"shields_only\" or \"explosives_only\" (Server Setup's FRIENDLY\n"
"FIRE in co-op, which writes its choice here). Their AI allies they\n"
"always can, as in the campaign." },
{ "network.coop_enemies_mode", _config_string, "\"per_player\"", "HALO_NET_COOP_ENEMIES_MODE", _environment_value,
_platform_all,
"Online co-op's extra enemies: \"none\", \"per_player\" (each squad of\n"
"enemies grows by coop_enemies for each player past the first) or\n"
"\"multiplier\" (each is coop_enemies_multiplier times as large, for any\n"
"number of players). Server Setup's EXTRA ENEMIES in co-op writes its\n"
"choice here." },
{ "network.coop_enemies", _config_integer, "50", "HALO_NET_COOP_ENEMIES", _environment_value, _platform_all,
"Online co-op's extra enemies per player, a percentage: for each player\n"
"past the first, each squad of enemies a level places gets this much of\n"
"itself more (100: as many again; 25 to 200). Server Setup's PER PLAYER\n"
"in co-op writes its choice here." },
{ "network.coop_enemies_multiplier", _config_integer, "2", "HALO_NET_COOP_ENEMIES_MULTIPLIER", _environment_value,
_platform_all,
"Online co-op's static multiplier of its enemies: each squad of enemies\n"
"a level places is this many times as large (2 to 32). Server Setup's\n"
"MULTIPLIER in co-op writes its choice here." },
{ "network.brokers_file", _config_string, "\"brokers.txt\"",
"HALO_NET_BROKERS_FILE", _environment_value, _platform_all,
"The file of the public MQTT brokers through which the machines of an\n"
"invite find each other (its messages are encrypted), beside this file\n"
"unless a full path: one host:port on each line, up to 4. Updates\n"
"replace brokers.txt: keep a list of your own under another name." },
{ "network.stun_servers", _config_string, "\"stun.l.google.com:19302,stun.cloudflare.com:3478\"",
"HALO_NET_STUN", _environment_value, _platform_all,
"Public STUN servers that tell this machine its internet address;\n"
@@ -450,6 +505,9 @@ static const struct config_setting config_settings[] =
"machines of twice it), to test the netcode as over the internet; 0 none." },
{ "debug.network_loss", _config_real, "0.0", "HALO_NETWORK_LOSS", _environment_value, _platform_all,
"Percent of datagrams received that are dropped, for the same; 0 none." },
{ "debug.gl_thread", _config_integer, "-1", "HALO_GL_THREAD", _environment_value, _platform_android,
"Mesa's GL thread (its drivers: the Steam Frame's): 1 on, 0 off, -1 as the\n"
"driver chooses. Read when the app starts." },
{ "debug.test_input", _config_string, "\"\"", "HALO_TEST_INPUT", _environment_value, _platform_all,
"\"bot:<seed>\" plays controller 1 with a scripted pattern (automated\n"
"network tests); \"look:<seed>\" stands still, only turning and looking\n"
@@ -1239,6 +1297,11 @@ int config_write_integer(const char *name, long value)
/* ---------- public code */
char *config_file_read(const char *path, size_t *size)
{
return config_read_file(path, size);
}
unsigned long config_changes(void)
{
return config_change_count;
+3
View File
@@ -30,6 +30,9 @@ such setting */
int config_text(const char *name, char *text, size_t size);
/* the folder config.toml is in, with its separator */
void config_folder(char *path, size_t size);
/* a whole file (a UTF-8 path), NUL terminated, or NULL; free() it (the Android
guest has no SDL_LoadFile) */
char *config_file_read(const char *path, size_t *size);
/* a setting's default, as text; 0 if there is no such setting */
int config_default(const char *name, char *text, size_t size);
/* how many times config_write has changed a setting: what keeps one reads
+359 -55
View File
@@ -62,6 +62,10 @@ gone, ends: else the keyboard stays held from the game) */
static Uint64 binding_polled_ms;
#define BINDING_ABANDONED_MS 500
static unsigned mouse_buttons_down;
#ifdef HALO_ANDROID
/* the mouse's place, flat (platform_flat_mouse) */
static float flat_mouse_x, flat_mouse_y;
#endif
/* (an input taken that nothing asks for is let go after this) */
#define BINDING_UNCLAIMED_MS 2000
/* the multiplayer scoreboard is open (platform_scoreboard_scroll): the wheel
@@ -379,38 +383,43 @@ static BOOL platform_fullscreen_setting(void)
return !config_boolean("debug.hidden_window") && platform_display_mode() != _display_mode_windowed;
}
/* the window's fullscreen kind (display.mode): borderless, a window over
the whole desktop (SDL's fullscreen without a mode), or fullscreen, the
display taken at its desktop resolution. Either draws at the display's
resolution (platform_screen_mode); F11 switches to the kind set. */
static void platform_fullscreen_kind_apply(void)
/* a size as a setting has it, "<width>x<height>": whether it is one, and
the Xbox's 640x480 or more */
static BOOL platform_size_parse(const char *text, long *width, long *height)
{
static int applied = -1;
int exclusive = platform_display_mode() == _display_mode_fullscreen ? 1 : 0;
SDL_DisplayID display;
char *end;
if (!platform_window || exclusive == applied)
return;
applied = exclusive;
display = SDL_GetDisplayForWindow(platform_window);
SDL_SetWindowFullscreenMode(platform_window,
exclusive && display ? SDL_GetDesktopDisplayMode(display) : NULL);
*width = strtol(text, &end, 10);
*height = *end == 'x' || *end == 'X' ? strtol(end + 1, &end, 10) : 0;
return !*end && *width >= 640 && *height >= 480;
}
/* whether the game is, or is to be, fullscreen, and if so the size in
pixels of the display it fills (d3d8_gl.c draws at that resolution) */
BOOL platform_screen_mode(long *width, long *height)
/* display.resolution in pixels, or 0x0 for the display's own ("native"),
as for one the game cannot draw at */
static void platform_resolution_setting(long *width, long *height)
{
SDL_DisplayID display;
const SDL_DisplayMode *mode;
if (!platform_size_parse(config_string("display.resolution"), width, height))
*width = *height = 0;
}
if (platform_window ? !(SDL_GetWindowFlags(platform_window) & SDL_WINDOW_FULLSCREEN) :
!platform_fullscreen_setting() || !platform_sdl_initialize())
/* the window's size (display.window_size), else the Xbox's 640x480 times
display.window_scale, as older versions set it */
static void platform_window_size_setting(long *width, long *height)
{
long scale = config_integer("display.window_scale");
if (!platform_size_parse(config_string("display.window_size"), width, height))
{
return FALSE;
*width = 640 * (scale < 1 ? 1 : scale);
*height = 480 * (scale < 1 ? 1 : scale);
}
display = platform_window ? SDL_GetDisplayForWindow(platform_window) : SDL_GetPrimaryDisplay();
mode = display ? SDL_GetDesktopDisplayMode(display) : NULL;
}
/* a display's own size in pixels (its desktop mode) */
static BOOL platform_display_size(SDL_DisplayID display, long *width, long *height)
{
const SDL_DisplayMode *mode = display ? SDL_GetDesktopDisplayMode(display) : NULL;
if (!mode)
return FALSE;
*width = (long)(mode->w * mode->pixel_density + 0.5f);
@@ -418,23 +427,263 @@ BOOL platform_screen_mode(long *width, long *height)
return TRUE;
}
/* the window's fullscreen kind (display.mode): borderless, a window over
the whole desktop (SDL's fullscreen without a mode), or fullscreen, the
display taken at display.resolution's mode (the one nearest it), else at its
desktop one. F11 switches to the kind set. */
static void platform_fullscreen_kind_apply(void)
{
static int applied = -1;
static long applied_width, applied_height;
int exclusive = platform_display_mode() == _display_mode_fullscreen ? 1 : 0;
long width = 0, height = 0;
SDL_DisplayID display;
SDL_DisplayMode closest;
const SDL_DisplayMode *mode = NULL;
if (!platform_window)
return;
if (exclusive)
platform_resolution_setting(&width, &height);
if (exclusive == applied && width == applied_width && height == applied_height)
return;
applied = exclusive;
applied_width = width;
applied_height = height;
display = SDL_GetDisplayForWindow(platform_window);
if (exclusive && display)
{
if (width && SDL_GetClosestFullscreenDisplayMode(display, (int)width, (int)height, 0.0f, false, &closest))
mode = &closest;
else
mode = SDL_GetDesktopDisplayMode(display);
}
SDL_SetWindowFullscreenMode(platform_window, mode);
}
/* whether the game last asked for the window to be fullscreen */
static BOOL platform_fullscreen_requested = FALSE;
static void platform_window_set_fullscreen(BOOL fullscreen)
{
platform_fullscreen_requested = fullscreen;
SDL_SetWindowFullscreen(platform_window, fullscreen ? true : false);
}
/* whether the window is fullscreen. SDL sets its flag when the window
manager confirms the request, and some never do: gamescope (the Steam
Deck's Game Mode) makes the window the size of the display but leaves the
flag unset, so the game drew 640x480 and gamescope stretched it. A window
that was asked to be fullscreen and covers its display counts too. */
static BOOL platform_window_fullscreen(void)
{
SDL_DisplayID display;
const SDL_DisplayMode *mode;
int width, height;
if (SDL_GetWindowFlags(platform_window) & SDL_WINDOW_FULLSCREEN)
return TRUE;
if (!platform_fullscreen_requested)
return FALSE;
display = SDL_GetDisplayForWindow(platform_window);
mode = display ? SDL_GetDesktopDisplayMode(display) : NULL;
if (!mode || !SDL_GetWindowSizeInPixels(platform_window, &width, &height))
return FALSE;
return width >= (int)(mode->w * mode->pixel_density + 0.5f) &&
height >= (int)(mode->h * mode->pixel_density + 0.5f);
}
/* the size in pixels the game draws its picture at (d3d8_gl.c): the
window's, the display's while fullscreen, or display.resolution's while
fullscreen (either kind) where the display has room for it; before the
window opens, what it will be. FALSE where display.resolution_scaling is
"original": the Xbox's 640x480, scaled to the window. */
BOOL platform_screen_mode(long *width, long *height)
{
/* (the size last given, for a window that has none: minimized) */
static long last_width, last_height;
long resolution_width, resolution_height;
BOOL fullscreen;
if (!strcmp(config_string("display.resolution_scaling"), "original"))
return FALSE;
if (platform_window)
{
int pixel_width = 0, pixel_height = 0;
SDL_GetWindowSizeInPixels(platform_window, &pixel_width, &pixel_height);
if (pixel_width <= 0 || pixel_height <= 0)
{
*width = last_width;
*height = last_height;
return last_width > 0;
}
*width = pixel_width;
*height = pixel_height;
fullscreen = platform_window_fullscreen();
}
else
{
if (!platform_sdl_initialize())
return FALSE;
fullscreen = platform_fullscreen_setting();
platform_window_size_setting(width, height);
if (fullscreen && !platform_display_size(SDL_GetPrimaryDisplay(), width, height))
return FALSE;
}
/* (fullscreen's display is at the resolution already, where it has that
mode: platform_fullscreen_kind_apply; borderless's is scaled to) */
platform_resolution_setting(&resolution_width, &resolution_height);
if (fullscreen && resolution_width && resolution_width <= *width && resolution_height <= *height)
{
*width = resolution_width;
*height = resolution_height;
}
last_width = *width;
last_height = *height;
return TRUE;
}
/* the size added to the list unless it has it already; the count */
static int platform_resolution_add(long *widths, long *heights, int count, int maximum, long width, long height)
{
int index;
for (index = 0; index < count; index++)
{
if (widths[index] == width && heights[index] == height)
return count;
}
if (count < maximum)
{
widths[count] = width;
heights[count] = height;
count++;
}
return count;
}
int platform_display_resolutions(long *widths, long *heights, int maximum)
{
SDL_DisplayID display;
SDL_DisplayMode **modes;
long display_width, display_height, width, height;
int mode_count = 0, count = 0, index;
if (maximum < 1 || !platform_sdl_initialize())
return 0;
display = platform_window ? SDL_GetDisplayForWindow(platform_window) : 0;
if (!display)
display = SDL_GetPrimaryDisplay();
if (!platform_display_size(display, &display_width, &display_height))
return 0;
modes = SDL_GetFullscreenDisplayModes(display, &mode_count);
for (index = 0; modes && index < mode_count; index++)
{
width = (long)(modes[index]->w * modes[index]->pixel_density + 0.5f);
height = (long)(modes[index]->h * modes[index]->pixel_density + 0.5f);
if (width >= 640 && height >= 480 && width <= display_width && height <= display_height &&
(width != display_width || height != display_height))
{
count = platform_resolution_add(widths, heights, count, maximum, width, height);
}
}
SDL_free(modes);
/* (the one set, though this display has no such mode, so that Video
Setup shows it) */
platform_resolution_setting(&width, &height);
if (width && (width != display_width || height != display_height))
count = platform_resolution_add(widths, heights, count, maximum, width, height);
/* largest first */
for (index = 1; index < count; index++)
{
int place;
width = widths[index];
height = heights[index];
for (place = index; place > 0 && (widths[place - 1] < width ||
(widths[place - 1] == width && heights[place - 1] < height)); place--)
{
widths[place] = widths[place - 1];
heights[place] = heights[place - 1];
}
widths[place] = width;
heights[place] = height;
}
return count;
}
/* Video Setup's window sizes, by shape (4:3, 16:10, 16:9, 21:9), each from
the smallest */
static const short platform_window_sizes_offered[][2] =
{
{ 640, 480 }, { 800, 600 }, { 1024, 768 }, { 1280, 960 }, { 1600, 1200 }, { 1920, 1440 }, { 2560, 1920 },
{ 1280, 800 }, { 1440, 900 }, { 1680, 1050 }, { 1920, 1200 }, { 2560, 1600 },
{ 1280, 720 }, { 1600, 900 }, { 1920, 1080 }, { 2560, 1440 }, { 3840, 2160 },
{ 2560, 1080 }, { 3440, 1440 }, { 3840, 1600 }, { 5120, 2160 },
};
int platform_window_sizes(long *widths, long *heights, int maximum)
{
SDL_DisplayID display;
SDL_Rect usable;
long width, height;
int count = 0, index;
if (maximum < 1 || !platform_sdl_initialize())
return 0;
display = platform_window ? SDL_GetDisplayForWindow(platform_window) : 0;
if (!display)
display = SDL_GetPrimaryDisplay();
if (!display || !SDL_GetDisplayUsableBounds(display, &usable))
usable.w = usable.h = 0;
for (index = 0; index < (int)(sizeof(platform_window_sizes_offered) / sizeof(*platform_window_sizes_offered));
index++)
{
width = platform_window_sizes_offered[index][0];
height = platform_window_sizes_offered[index][1];
/* (the Xbox's own whatever the desktop's size) */
if (!index || (width <= usable.w && height <= usable.h))
count = platform_resolution_add(widths, heights, count, maximum, width, height);
}
/* (the one set, though it is none of them or too big for this desktop,
so that Video Setup shows it) */
platform_window_size_setting(&width, &height);
return platform_resolution_add(widths, heights, count, maximum, width, height);
}
#else
int platform_display_resolutions(long *widths, long *heights, int maximum)
{
(void)widths;
(void)heights;
(void)maximum;
return 0;
}
int platform_window_sizes(long *widths, long *heights, int maximum)
{
(void)widths;
(void)heights;
(void)maximum;
return 0;
}
#endif
#ifndef HALO_ANDROID
/* the window's size (platform_window_size_setting), as the window was made
or last resized: platform_display_apply */
static long platform_window_width = -1, platform_window_height = -1;
#endif
/* the window's scale (display.window_scale, as the window was made or last
resized: platform_display_apply) */
static long platform_window_scale = -1;
BOOL platform_video_initialize(unsigned long width, unsigned long height)
{
int scale = (int)config_integer("display.window_scale");
int version;
if (platform_window)
return TRUE;
if (!platform_sdl_initialize())
return FALSE;
if (scale < 1)
scale = 1;
platform_window_scale = scale;
#ifdef HALO_ANDROID
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
@@ -459,14 +708,23 @@ BOOL platform_video_initialize(unsigned long width, unsigned long height)
#endif
#ifdef HALO_ANDROID
platform_window = SDL_CreateWindow("Halo", (int)(width * scale), (int)(height * scale),
SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN);
{
int scale = (int)config_integer("display.window_scale");
if (scale < 1)
scale = 1;
platform_window = SDL_CreateWindow("Halo", (int)(width * scale), (int)(height * scale),
SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN);
}
#else
/* fullscreen at the desktop's resolution unless display.fullscreen is
false, where the game draws the display's shape at its resolution
(d3d8_gl.c); the window size is the windowed mode F11 switches to and
from, where it draws 640x480 */
platform_window = SDL_CreateWindow("Halo", (int)(width * scale), (int)(height * scale),
/* fullscreen (either kind) unless display.mode is the window, which F11
switches to and from: display.window_size, whatever shape the fullscreen
picture has. The game draws at the size platform_screen_mode gives
(d3d8_gl.c). */
(void)width;
(void)height;
platform_window_size_setting(&platform_window_width, &platform_window_height);
platform_window = SDL_CreateWindow("Halo", (int)platform_window_width, (int)platform_window_height,
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_HIGH_PIXEL_DENSITY |
(config_boolean("debug.hidden_window") ? SDL_WINDOW_HIDDEN : 0) |
(platform_fullscreen_setting() ? SDL_WINDOW_FULLSCREEN : 0));
@@ -477,6 +735,7 @@ BOOL platform_video_initialize(unsigned long width, unsigned long height)
return FALSE;
}
#ifndef HALO_ANDROID
platform_fullscreen_requested = platform_fullscreen_setting();
platform_fullscreen_kind_apply();
#endif
platform_gl_context = SDL_GL_CreateContext(platform_window);
@@ -512,23 +771,28 @@ BOOL platform_video_initialize(unsigned long width, unsigned long height)
return TRUE;
}
/* display.fullscreen, display.window_scale (when it changes: the window can
be resized) and display.vsync, as Settings has written them */
/* display.mode, display.resolution (fullscreen's display mode),
display.window_size (when it changes: the window can be resized) and
display.vsync, as Settings has written them; display.resolution_scaling
and borderless's resolution are taken up between frames
(halo_screen_commit) */
void platform_display_apply(void)
{
#ifndef HALO_ANDROID
BOOL fullscreen = platform_fullscreen_setting();
long scale = config_integer("display.window_scale");
long width, height;
if (!platform_window)
return;
platform_fullscreen_kind_apply();
if (((SDL_GetWindowFlags(platform_window) & SDL_WINDOW_FULLSCREEN) != 0) != (fullscreen != FALSE))
SDL_SetWindowFullscreen(platform_window, fullscreen ? true : false);
if (scale != platform_window_scale && scale >= 1)
if (platform_window_fullscreen() != (fullscreen != FALSE))
platform_window_set_fullscreen(fullscreen);
platform_window_size_setting(&width, &height);
if (width != platform_window_width || height != platform_window_height)
{
platform_window_scale = scale;
SDL_SetWindowSize(platform_window, (int)(640 * scale), (int)(480 * scale));
platform_window_width = width;
platform_window_height = height;
SDL_SetWindowSize(platform_window, (int)width, (int)height);
}
#else
if (!platform_window)
@@ -911,13 +1175,13 @@ static void platform_show_pending_message(void)
#else
{
/* (a box cannot show above a fullscreen game) */
int fullscreen = (SDL_GetWindowFlags(platform_window) & SDL_WINDOW_FULLSCREEN) != 0;
BOOL fullscreen = platform_window_fullscreen();
if (fullscreen)
SDL_SetWindowFullscreen(platform_window, false);
platform_window_set_fullscreen(FALSE);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, title, text, platform_window);
if (fullscreen)
SDL_SetWindowFullscreen(platform_window, true);
platform_window_set_fullscreen(TRUE);
}
#endif
}
@@ -925,8 +1189,10 @@ static void platform_show_pending_message(void)
/* ---------- events */
/* quits as closing the window does, when the events are next read (the
menus' Quit: port/linux/game/menu_functions.c); Android's menus have none,
as the system closes its apps */
menus' Quit: port/linux/game/menu_functions.c); on Android, where the
system closes its apps, the VR options' Quit (ui_widget.c) ends the process
at once: on the Steam Frame, Steam cannot end the game, which runs in
Lepton's container (port/android/STEAM_FRAME.md) */
void platform_request_quit(void)
{
#ifndef HALO_ANDROID
@@ -935,6 +1201,20 @@ void platform_request_quit(void)
memset(&event, 0, sizeof(event));
event.type = SDL_EVENT_QUIT;
SDL_PushEvent(&event);
#else
{
/* (and says so beside the game's data: the Steam Frame's launcher
does not then take it for a start that failed and start it again) */
char path[512];
FILE *file;
snprintf(path, sizeof(path), "%s/quit_requested.txt", platform_data_root());
file = fopen(path, "wb");
if (file)
fclose(file);
}
platform_log("quit: the player asked");
exit(EXIT_SUCCESS);
#endif
}
@@ -1032,13 +1312,15 @@ void platform_pump_events(void)
window's size and place while fullscreen) */
if (event.key.down && !event.key.repeat && event.key.scancode == SDL_SCANCODE_F11)
{
SDL_SetWindowFullscreen(platform_window,
(SDL_GetWindowFlags(platform_window) & SDL_WINDOW_FULLSCREEN) ? false : true);
platform_window_set_fullscreen(!platform_window_fullscreen());
}
#endif
break;
case SDL_EVENT_MOUSE_MOTION:
#ifndef HALO_ANDROID
#ifdef HALO_ANDROID
flat_mouse_x = event.motion.x;
flat_mouse_y = event.motion.y;
#else
/* in the menus the mouse moves the pointer, not the view */
if (input_state.ui_pointer)
{
@@ -1198,6 +1480,23 @@ int platform_binding_capture_poll(int *input)
return result;
}
#ifdef HALO_ANDROID
/* flat, not in VR (the emulator, for testing the menus): the mouse's place
in the window and whether its left button is down, polled */
BOOL platform_flat_mouse(float *x, float *y)
{
BOOL down;
pthread_mutex_lock(&input_lock);
*x = flat_mouse_x;
*y = flat_mouse_y;
/* (an injected mouse's, adb shell input mouse: button 0) */
down = (mouse_buttons_down & ((1u << SDL_BUTTON_LEFT) | 1u)) != 0;
pthread_mutex_unlock(&input_lock);
return down;
}
#endif
#ifndef HALO_ANDROID
/* ---------- the menus' pointer */
@@ -1248,12 +1547,17 @@ BOOL platform_ui_pointer_read(struct platform_ui_pointer *pointer)
return active;
}
#endif
void platform_video_window_size(int *width, int *height)
{
#ifdef HALO_ANDROID
SDL_GetWindowSizeInPixels(platform_window, width, height);
#else
SDL_GetWindowSize(platform_window, width, height);
#endif
}
#endif
void platform_input_read(struct platform_input_state *state, BOOL consume_motion)
{
pthread_mutex_lock(&input_lock);
+10 -1
View File
@@ -62,6 +62,15 @@ BOOL platform_video_initialize(unsigned long width, unsigned long height);
#ifndef HALO_ANDROID
BOOL platform_screen_mode(long *width, long *height);
#endif
/* Video Setup's resolutions (port/linux/game/menu_tags.c), in pixels: the
display's modes the game can draw at, largest first, each once, but the
display's own (Native), and display.resolution's where it is none of them;
how many. None on Android. */
int platform_display_resolutions(long *widths, long *heights, int maximum);
/* Video Setup's window sizes: those of each shape (4:3, 16:10, 16:9, 21:9)
that fit the desktop, and display.window_size's; how many. None on
Android. */
int platform_window_sizes(long *widths, long *heights, int maximum);
void platform_video_drawable_size(int *width, int *height);
/* the window's mode and size and V-Sync, from config.toml as Settings has
just written it (the main thread's) */
@@ -89,8 +98,8 @@ struct platform_ui_pointer
};
void platform_ui_pointer_set_active(BOOL active);
BOOL platform_ui_pointer_read(struct platform_ui_pointer *pointer);
void platform_video_window_size(int *width, int *height);
#endif
void platform_video_window_size(int *width, int *height);
BOOL platform_next_keystroke(struct platform_keystroke *keystroke);
/* the multiplayer scoreboard (game_engine.c) open or not: while it is, the
mouse wheel and Page Up/Down scroll it instead of switching weapons; how
+117 -10
View File
@@ -69,6 +69,14 @@ static struct
unsigned long long wait_us;
int report_frames;
int report_stereo_frames;
/* (the frame's parts, halo_vr_phase: when each ended, and the game's
ticks in it; summed apart for frames with ticks and without, with how
many took longer than the headset's frame) */
unsigned long long phase_end_us[HALO_VR_PHASE_COUNT];
int frame_ticks;
unsigned long long phase_us[2][HALO_VR_PHASE_COUNT + 1];
int phase_frames[2];
int phase_late[2];
/* the view's turning, gathered for halo_vr_look_delta */
float look_yaw;
@@ -132,6 +140,7 @@ static struct
unsigned long long last_frame_ms;
/* settings (config.toml, [vr]) */
unsigned long settings_read_at; /* config_changes() when the live ones were read */
int smooth_turn;
float snap_turn_degrees;
float smooth_turn_degrees_per_second;
@@ -418,22 +427,33 @@ static void world_to_local(const float world[3], float local[3])
/* ---------- platform side */
/* the settings the VR options (ui_widget.c) change while the game runs:
read at the start, and again whenever one changes */
static void vr_read_live_settings(void)
{
vr.settings_read_at = config_changes();
vr.smooth_turn = config_boolean("vr.smooth_turn");
vr.snap_turn_degrees = (float)config_real("vr.snap_turn_degrees");
vr.smooth_turn_degrees_per_second = (float)config_real("vr.smooth_turn_speed");
vr.motion_tracker_on_wrist = config_boolean("vr.motion_tracker_on_wrist");
vr.crosshair = config_boolean("vr.crosshair");
vr.laser = config_boolean("vr.laser");
vr.vehicle_wheel = config_boolean("vr.vehicle_wheel");
vr.comfort_vignette = (float)config_real("vr.comfort_vignette");
}
void halo_vr_initialize(void)
{
if (vr.active || !getenv("HALO_VR"))
return;
vr.smooth_turn = config_boolean("vr.smooth_turn");
vr.snap_turn_degrees = (float)config_real("vr.snap_turn_degrees");
vr.smooth_turn_degrees_per_second = (float)config_real("vr.smooth_turn_speed");
vr_read_live_settings();
vr.cinematics_3d = config_boolean("vr.cinematics_in_3d");
vr.hud_distance = (float)config_real("vr.hud_distance");
vr.hud_width = 2.0f * vr.hud_distance * tanf((float)config_real("vr.hud_field_of_view") * PI / 360.0f);
vr.screen_distance = (float)config_real("vr.screen_distance");
vr.screen_width = (float)config_real("vr.screen_width");
vr.positional_tracking = config_boolean("vr.positional_tracking");
vr.motion_tracker_on_wrist = config_boolean("vr.motion_tracker_on_wrist");
vr.scope_size = (float)config_real("vr.scope_size");
vr.crosshair = config_boolean("vr.crosshair");
vr.motion_tracker_size = (float)config_real("vr.motion_tracker_size");
vr.motion_tracker_turn = (float)config_real("vr.motion_tracker_turn");
vr.motion_tracker_right = (float)config_real("vr.motion_tracker_right");
@@ -443,7 +463,6 @@ void halo_vr_initialize(void)
vr.rise_limit = 0.25f;
vr.log_performance = config_boolean("vr.log_performance");
vr.aim_with_controller = strcmp(config_string("vr.aim_with"), "head") != 0;
vr.laser = config_boolean("vr.laser");
vr.weapon_offset[0] = (float)config_real("vr.weapon_forward");
vr.weapon_offset[1] = (float)config_real("vr.weapon_right");
vr.weapon_offset[2] = (float)config_real("vr.weapon_down");
@@ -465,13 +484,11 @@ void halo_vr_initialize(void)
vr.vehicle_steer_angle = (float)config_real("vr.vehicle_steer_degrees") * PI / 180.0f;
vr.vehicle_gun_steer_angle = (float)config_real("vr.vehicle_gun_steer_degrees") * PI / 180.0f;
vr.vehicle_pitch_angle = (float)config_real("vr.vehicle_pitch_degrees") * PI / 180.0f;
vr.vehicle_wheel = config_boolean("vr.vehicle_wheel");
vr.vehicle_wheel_angle = (float)config_real("vr.vehicle_wheel_degrees") * PI / 180.0f;
if (vr.vehicle_wheel_angle < 10.0f * PI / 180.0f)
vr.vehicle_wheel_angle = 10.0f * PI / 180.0f;
vr.vehicle_steer_curve = (float)config_real("vr.vehicle_steer_curve");
vr.vehicle_steer_smoothing = (float)config_real("vr.vehicle_steer_smoothing");
vr.comfort_vignette = (float)config_real("vr.comfort_vignette");
vr.grenade_scale = (float)config_real("vr.grenade_scale");
vr.grenade_offset[0] = (float)config_real("vr.grenade_right");
vr.grenade_offset[1] = 0.0f;
@@ -493,6 +510,11 @@ int halo_vr_active(void)
return vr.active;
}
int halo_vr_controller_layout(void)
{
return vr.active ? vr.frame.controller_layout : HALO_XR_LAYOUT_TOUCH;
}
int halo_vr_eye_size(int *width, int *height)
{
const char *eye_width = getenv("HALO_VR_EYE_WIDTH");
@@ -516,10 +538,47 @@ static unsigned long long now_us(void)
/* vr.log_performance: every five seconds, the frames the game gave the
headset, and where their time went: waiting for the headset (xrWaitFrame),
drawing the eyes, and the rest (the game's update, the overlay, the copies) */
void halo_vr_phase(int phase, int ticks)
{
if (!vr.active || !vr.log_performance || phase < 0 || phase >= HALO_VR_PHASE_COUNT)
return;
vr.phase_end_us[phase] = now_us();
if (phase == HALO_VR_PHASE_TICKS)
vr.frame_ticks = ticks;
}
/* the frame's parts, from the marks halo_vr_phase left (a part not marked
this frame: none) */
static void performance_phases(unsigned long long now)
{
int kind = vr.frame_ticks > 0;
unsigned long long last = vr.frame_start_us;
int phase;
for (phase = 0; phase < HALO_VR_PHASE_COUNT; phase++)
{
unsigned long long end = vr.phase_end_us[phase];
if (end >= last && end <= now)
{
vr.phase_us[kind][phase] += end - last;
last = end;
}
}
vr.phase_us[kind][HALO_VR_PHASE_COUNT] += now - last;
vr.phase_frames[kind]++;
/* (late: longer than the headset's frame, less a millisecond) */
if (vr.info.refresh_rate > 1.0f && (float)(now - vr.frame_start_us + 1000) > 1e6f / vr.info.refresh_rate)
vr.phase_late[kind]++;
memset(vr.phase_end_us, 0, sizeof(vr.phase_end_us));
vr.frame_ticks = 0;
}
static void performance_report(int stereo)
{
unsigned long long now = now_us();
performance_phases(now);
vr.work_us += now - vr.frame_start_us;
vr.report_frames++;
vr.report_stereo_frames += stereo != 0;
@@ -534,6 +593,25 @@ static void performance_report(int stereo)
platform_log("VR: %.1f fps (%d%% stereo); per frame %.1f ms working (eyes %.1f ms), %.1f ms waiting "
"for the headset", frames / seconds, (int)(100.0f * vr.report_stereo_frames / frames),
vr.work_us * 1e-3f / frames, vr.eyes_us * 1e-3f / frames, vr.wait_us * 1e-3f / frames);
{
int kind;
for (kind = 1; kind >= 0; kind--)
{
float count = (float)(vr.phase_frames[kind] ? vr.phase_frames[kind] : 1);
platform_log("VR: %s: %d frames, %d late; ms input %.1f, ticks %.1f, camera %.1f, draw %.1f, "
"present %.1f", kind ? "with ticks" : "no ticks", vr.phase_frames[kind], vr.phase_late[kind],
vr.phase_us[kind][HALO_VR_PHASE_INPUT] * 1e-3f / count,
vr.phase_us[kind][HALO_VR_PHASE_TICKS] * 1e-3f / count,
vr.phase_us[kind][HALO_VR_PHASE_CAMERA] * 1e-3f / count,
vr.phase_us[kind][HALO_VR_PHASE_DRAW] * 1e-3f / count,
vr.phase_us[kind][HALO_VR_PHASE_COUNT] * 1e-3f / count);
}
}
memset(vr.phase_us, 0, sizeof(vr.phase_us));
memset(vr.phase_frames, 0, sizeof(vr.phase_frames));
memset(vr.phase_late, 0, sizeof(vr.phase_late));
}
vr.report_start_us = now;
vr.report_frames = vr.report_stereo_frames = 0;
@@ -1191,6 +1269,8 @@ void halo_vr_frame_begin(void)
vr.recentre_frames--;
vr_recentre();
}
if (vr.settings_read_at != config_changes())
vr_read_live_settings();
turn_update();
wheel_update();
vignette_update();
@@ -2139,6 +2219,10 @@ static struct
int valid;
float x, y;
float reported_x, reported_y;
/* (a stick moved the menu's choice: the pointer, not moved far from
here since, leaves it be) */
int stick_quiet;
float stick_x, stick_y;
int hand;
int trigger_down[HALO_XR_HAND_COUNT];
int clicks;
@@ -2233,9 +2317,31 @@ int halo_vr_menu_pointer(int *x, int *y, int *click_x, int *click_y, int *moved,
return 0;
*x = (int)menu_pointer.x;
*y = (int)menu_pointer.y;
/* (a stick pushed: what it chooses stays chosen until the pointer
moves well away) */
{
int index;
for (index = 0; index < HALO_XR_HAND_COUNT; index++)
{
const struct halo_xr_hand *hand = &vr.frame.hands[index];
if (hand->active && (fabsf(hand->thumbstick[0]) > 0.4f || fabsf(hand->thumbstick[1]) > 0.4f))
{
menu_pointer.stick_quiet = 1;
menu_pointer.stick_x = menu_pointer.x;
menu_pointer.stick_y = menu_pointer.y;
}
}
if (menu_pointer.stick_quiet && (fabsf(menu_pointer.x - menu_pointer.stick_x) > 25.0f ||
fabsf(menu_pointer.y - menu_pointer.stick_y) > 25.0f))
{
menu_pointer.stick_quiet = 0;
}
}
/* (moved past a hand's tremor: a few pixels) */
*moved = fabsf(menu_pointer.x - menu_pointer.reported_x) >= 3.0f ||
fabsf(menu_pointer.y - menu_pointer.reported_y) >= 3.0f;
*moved = !menu_pointer.stick_quiet && (fabsf(menu_pointer.x - menu_pointer.reported_x) >= 3.0f ||
fabsf(menu_pointer.y - menu_pointer.reported_y) >= 3.0f);
if (*moved)
{
menu_pointer.reported_x = menu_pointer.x;
@@ -2442,6 +2548,7 @@ int halo_vr_controllers(struct halo_xr_hand hands[HALO_XR_HAND_COUNT], int *menu
#else
int halo_vr_controller_layout(void) { return 0; }
int halo_vr_active(void) { return 0; }
int halo_vr_stereo_frame(void) { return 0; }
int halo_vr_stereo_player(short local_player_index, int cinematic) { (void)local_player_index; (void)cinematic; return 0; }
+64 -8
View File
@@ -55,6 +55,9 @@ drive the controller.
/* main/console.c */
extern unsigned char console_is_active(void);
/* port/linux/game/menu_functions.c: two or more players on this machine
(co-op, or split screen in a network game) */
extern unsigned char pc_menu_split_players(void);
/* ---------- device tables */
@@ -635,6 +638,46 @@ static int sdl_gamepads(SDL_Gamepad *gamepads[PORT_COUNT])
return found;
}
/* whether one gamepad is port 1's (port_gamepad) */
static BOOL lone_gamepad_split;
/* no button of the gamepad held, its sticks and triggers at rest */
static BOOL gamepad_idle(SDL_Gamepad *gamepad)
{
int index;
for (index = 0; index < SDL_GAMEPAD_BUTTON_COUNT; index++)
{
if (SDL_GetGamepadButton(gamepad, (SDL_GamepadButton)index))
return FALSE;
}
for (index = 0; index < SDL_GAMEPAD_AXIS_COUNT; index++)
{
if (abs(SDL_GetGamepadAxis(gamepad, (SDL_GamepadAxis)index)) > 8000)
return FALSE;
}
return TRUE;
}
/* the gamepad of a port: the first shares port 0 with the keyboard, but for
two or more players with one gamepad (co-op, split screen), port 1 has it
(the keyboard's player is 1, the gamepad's 2). It changes port only at rest:
a button held across the change would be pressed again on the other port
(the B that leaves a profile screen leaving the game as player 1's) */
static SDL_Gamepad *port_gamepad(SDL_Gamepad *gamepads[PORT_COUNT], int count, int port)
{
if (count == 1)
{
BOOL split = pc_menu_split_players() != 0;
if (split != lone_gamepad_split && gamepad_idle(gamepads[0]))
lone_gamepad_split = split;
if (lone_gamepad_split)
return port == 1 ? gamepads[0] : NULL;
}
return port < count ? gamepads[port] : NULL;
}
static SHORT stick(Sint16 value, BOOL flip)
{
int result = flip ? -(int)value - 1 : value;
@@ -718,9 +761,12 @@ static DWORD connected_gamepads(void)
DWORD mask = XDEVICE_PORT0_MASK;
int port;
/* the first pad shares port 0 with the keyboard */
for (port = 1; port < count; port++)
mask |= 1UL << port;
/* the first pad shares port 0 with the keyboard (port_gamepad) */
for (port = 1; port < PORT_COUNT; port++)
{
if (port_gamepad(gamepads, count, port))
mask |= 1UL << port;
}
return mask;
}
@@ -846,6 +892,12 @@ static void vr_gamepad_state(XINPUT_GAMEPAD *pad)
value = vr_stick(left->thumbstick[1]);
if (abs(value) > abs(pad->sThumbLY)) pad->sThumbLY = value;
if (left->buttons & HALO_XR_BUTTON_MENU) pad->wButtons |= XINPUT_GAMEPAD_START;
/* (the Steam Frame's controllers: the left one's View button and D-pad) */
if (left->buttons & HALO_XR_BUTTON_VIEW) pad->wButtons |= XINPUT_GAMEPAD_BACK;
if (left->buttons & HALO_XR_BUTTON_DPAD_UP) pad->wButtons |= XINPUT_GAMEPAD_DPAD_UP;
if (left->buttons & HALO_XR_BUTTON_DPAD_DOWN) pad->wButtons |= XINPUT_GAMEPAD_DPAD_DOWN;
if (left->buttons & HALO_XR_BUTTON_DPAD_LEFT) pad->wButtons |= XINPUT_GAMEPAD_DPAD_LEFT;
if (left->buttons & HALO_XR_BUTTON_DPAD_RIGHT) pad->wButtons |= XINPUT_GAMEPAD_DPAD_RIGHT;
if (left->buttons & HALO_XR_BUTTON_THUMBSTICK) pad->wButtons |= XINPUT_GAMEPAD_LEFT_THUMB;
if (right->buttons & HALO_XR_BUTTON_THUMBSTICK) pad->wButtons |= XINPUT_GAMEPAD_RIGHT_THUMB;
/* (in the menus the triggers click the pointer: halo_vr_menu_pointer) */
@@ -881,6 +933,10 @@ static void vr_gamepad_state(XINPUT_GAMEPAD *pad)
merge_button(pad, XINPUT_GAMEPAD_B,
((right->buttons & HALO_XR_BUTTON_SQUEEZE) != 0 && !halo_vr_wheel_held()) || halo_vr_melee());
merge_button(pad, XINPUT_GAMEPAD_Y, (left->buttons & HALO_XR_BUTTON_B) != 0);
/* (the Steam Frame's bumpers: the left switches grenades, the right is
the flashlight) */
merge_button(pad, XINPUT_GAMEPAD_BLACK, (left->buttons & HALO_XR_BUTTON_BUMPER) != 0);
merge_button(pad, XINPUT_GAMEPAD_WHITE, (right->buttons & HALO_XR_BUTTON_BUMPER) != 0);
{
/* B: a tap is the flashlight, holding it switches grenades; the
game sees a short press of either */
@@ -942,7 +998,7 @@ DWORD WINAPI XInputGetState(HANDLE device, PXINPUT_STATE state)
else
keyboard_controls(&input, &state->Gamepad);
}
if (count > 0)
if (port_gamepad(gamepads, count, 0))
sdl_gamepad_state(gamepads[0], &state->Gamepad);
#ifdef HALO_ANDROID
vr_gamepad_state(&state->Gamepad);
@@ -956,9 +1012,9 @@ DWORD WINAPI XInputGetState(HANDLE device, PXINPUT_STATE state)
pthread_mutex_unlock(&mouse_lock);
}
}
else if (port < count)
else if (port_gamepad(gamepads, count, port))
{
sdl_gamepad_state(gamepads[port], &state->Gamepad);
sdl_gamepad_state(port_gamepad(gamepads, count, port), &state->Gamepad);
}
if (memcmp(&state->Gamepad, &controllers[port].previous, sizeof(state->Gamepad)))
@@ -991,11 +1047,11 @@ DWORD WINAPI XInputSetState(HANDLE device, PXINPUT_FEEDBACK feedback)
}
#endif
count = sdl_gamepads(gamepads);
if (port < count)
if (port_gamepad(gamepads, count, port))
{
/* the game refreshes the motors every frame; rumble a little longer
than that so they do not stutter */
SDL_RumbleGamepad(gamepads[port], feedback->Rumble.wLeftMotorSpeed,
SDL_RumbleGamepad(port_gamepad(gamepads, count, port), feedback->Rumble.wLeftMotorSpeed,
feedback->Rumble.wRightMotorSpeed, 100);
}
return ERROR_SUCCESS;
+167
View File
@@ -0,0 +1,167 @@
Monocypher as a whole is dual-licensed. Choose whichever licence you
want from the two licences listed below.
The first licence is a regular 2-clause BSD licence. The second licence
is the CC-0 from Creative Commons. It is intended to release Monocypher
to the public domain. The BSD licence serves as a fallback option.
See the individual files for specific information about who contributed
to what file during which years. See below for special notes.
Licence 1 (2-clause BSD)
------------------------
Copyright (c) 2017-2023, Loup Vaillant
Copyright (c) 2017-2019, Michael Savage
Copyright (c) 2017-2023, Fabio Scotoni
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Licence 2 (CC-0)
----------------
> CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
> LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
> ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
> INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
> REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
> PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
> THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
> HEREUNDER.
### Statement of Purpose
The laws of most jurisdictions throughout the world automatically confer
exclusive Copyright and Related Rights (defined below) upon the creator
and subsequent owner(s) (each and all, an "owner") of an original work
of authorship and/or a database (each, a "Work").
Certain owners wish to permanently relinquish those rights to a Work for
the purpose of contributing to a commons of creative, cultural and
scientific works ("Commons") that the public can reliably and without
fear of later claims of infringement build upon, modify, incorporate in
other works, reuse and redistribute as freely as possible in any form
whatsoever and for any purposes, including without limitation commercial
purposes. These owners may contribute to the Commons to promote the
ideal of a free culture and the further production of creative, cultural
and scientific works, or to gain reputation or greater distribution for
their Work in part through the use and efforts of others.
For these and/or other purposes and motivations, and without any
expectation of additional consideration or compensation, the person
associating CC0 with a Work (the "Affirmer"), to the extent that he or
she is an owner of Copyright and Related Rights in the Work, voluntarily
elects to apply CC0 to the Work and publicly distribute the Work under
its terms, with knowledge of his or her Copyright and Related Rights in
the Work and the meaning and intended legal effect of CC0 on those
rights.
1. **Copyright and Related Rights.** A Work made available under CC0 may
be protected by copyright and related or neighboring rights
("Copyright and Related Rights"). Copyright and Related Rights
include, but are not limited to, the following:
- the right to reproduce, adapt, distribute, perform, display,
communicate, and translate a Work;
- moral rights retained by the original author(s) and/or
performer(s); publicity and privacy rights pertaining to a person's
image or likeness depicted in a Work;
- rights protecting against unfair competition in regards to a Work,
subject to the limitations in paragraph 4(a), below;
- rights protecting the extraction, dissemination, use and reuse of
data in a Work;
- database rights (such as those arising under Directive 96/9/EC of
the European Parliament and of the Council of 11 March 1996 on the
legal protection of databases, and under any national
implementation thereof, including any amended or successor version
of such directive); and
- other similar, equivalent or corresponding rights throughout the
world based on applicable law or treaty, and any national
implementations thereof.
2. **Waiver.** To the greatest extent permitted by, but not in
contravention of, applicable law, Affirmer hereby overtly, fully,
permanently, irrevocably and unconditionally waives, abandons, and
surrenders all of Affirmer's Copyright and Related Rights and
associated claims and causes of action, whether now known or unknown
(including existing as well as future claims and causes of action),
in the Work (i) in all territories worldwide, (ii) for the maximum
duration provided by applicable law or treaty (including future time
extensions), (iii) in any current or future medium and for any number
of copies, and (iv) for any purpose whatsoever, including without
limitation commercial, advertising or promotional purposes (the
"Waiver"). Affirmer makes the Waiver for the benefit of each member
of the public at large and to the detriment of Affirmer's heirs and
successors, fully intending that such Waiver shall not be subject to
revocation, rescission, cancellation, termination, or any other legal
or equitable action to disrupt the quiet enjoyment of the Work by the
public as contemplated by Affirmer's express Statement of Purpose.
3. **Public License Fallback.** Should any part of the Waiver for any
reason be judged legally invalid or ineffective under applicable law,
then the Waiver shall be preserved to the maximum extent permitted
taking into account Affirmer's express Statement of Purpose. In
addition, to the extent the Waiver is so judged Affirmer hereby
grants to each affected person a royalty-free, non transferable, non
sublicensable, non exclusive, irrevocable and unconditional license
to exercise Affirmer's Copyright and Related Rights in the Work (i)
in all territories worldwide, (ii) for the maximum duration provided
by applicable law or treaty (including future time extensions), (iii)
in any current or future medium and for any number of copies, and
(iv) for any purpose whatsoever, including without limitation
commercial, advertising or promotional purposes (the "License"). The
License shall be deemed effective as of the date CC0 was applied by
Affirmer to the Work. Should any part of the License for any reason
be judged legally invalid or ineffective under applicable law, such
partial invalidity or ineffectiveness shall not invalidate the
remainder of the License, and in such case Affirmer hereby affirms
that he or she will not (i) exercise any of his or her remaining
Copyright and Related Rights in the Work or (ii) assert any
associated claims and causes of action with respect to the Work, in
either case contrary to Affirmer's express Statement of Purpose.
4. **Limitations and Disclaimers.**
- No trademark or patent rights held by Affirmer are waived,
abandoned, surrendered, licensed or otherwise affected by this
document.
- Affirmer offers the Work as-is and makes no representations or
warranties of any kind concerning the Work, express, implied,
statutory or otherwise, including without limitation warranties of
title, merchantability, fitness for a particular purpose, non
infringement, or the absence of latent or other defects, accuracy,
or the present or absence of errors, whether or not discoverable,
all to the greatest extent permissible under applicable law.
- Affirmer disclaims responsibility for clearing rights of other
persons that may apply to the Work or any use thereof, including
without limitation any person's Copyright and Related Rights in the
Work. Further, Affirmer disclaims responsibility for obtaining any
necessary consents, permissions or other rights required for any
use of the Work.
- Affirmer understands and acknowledges that Creative Commons is not
a party to this document and has no duty or obligation with respect
to this CC0 or use of the Work.
+19
View File
@@ -0,0 +1,19 @@
# Monocypher
A small cryptography library in C, by Loup Vaillant, Michael Savage and
Fabio Scotoni, dual-licensed CC0-1.0 or BSD 2-Clause (see `LICENCE.md`).
Upstream: https://monocypher.org (https://github.com/LoupVaillant/Monocypher),
release `4.0.3`, `monocypher-4.0.3.tar.gz`, SHA-256
`8cc9bc341a66249016db9bd70e9142d8d0aef9945973744b1ac05dbc55d8ee66`
(its sources match the repository's `4.0.3` tag but for their first line,
where the release writes its version).
Only `src/monocypher.c`, `src/monocypher.h`, `src/optional/monocypher-ed25519.c`,
`src/optional/monocypher-ed25519.h` and `LICENCE.md` are kept, unchanged.
Internet play (`port/linux/src/p2p_crypto.c`) uses its Ed25519 (with
SHA-512) and its conversion of Ed25519 public keys to X25519: a run's key
signs the listing of a public game in the server browser
(`port/linux/src/p2p_lobby.c`). It builds into the Linux, Windows and
Android platform layers.
+503
View File
@@ -0,0 +1,503 @@
// Monocypher version 4.0.3
//
// This file is dual-licensed. Choose whichever licence you want from
// the two licences listed below.
//
// The first licence is a regular 2-clause BSD licence. The second licence
// is the CC-0 from Creative Commons. It is intended to release Monocypher
// to the public domain. The BSD licence serves as a fallback option.
//
// SPDX-License-Identifier: BSD-2-Clause OR CC0-1.0
//
// ------------------------------------------------------------------------
//
// Copyright (c) 2017-2019, Loup Vaillant
// All rights reserved.
//
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// ------------------------------------------------------------------------
//
// Written in 2017-2019 by Loup Vaillant
//
// To the extent possible under law, the author(s) have dedicated all copyright
// and related neighboring rights to this software to the public domain
// worldwide. This software is distributed without any warranty.
//
// You should have received a copy of the CC0 Public Domain Dedication along
// with this software. If not, see
// <https://creativecommons.org/publicdomain/zero/1.0/>
#include "monocypher-ed25519.h"
#ifdef MONOCYPHER_CPP_NAMESPACE
namespace MONOCYPHER_CPP_NAMESPACE {
#endif
/////////////////
/// Utilities ///
/////////////////
#define FOR(i, min, max) for (size_t i = min; i < max; i++)
#define COPY(dst, src, size) FOR(_i_, 0, size) (dst)[_i_] = (src)[_i_]
#define ZERO(buf, size) FOR(_i_, 0, size) (buf)[_i_] = 0
#define WIPE_CTX(ctx) crypto_wipe(ctx , sizeof(*(ctx)))
#define WIPE_BUFFER(buffer) crypto_wipe(buffer, sizeof(buffer))
#define MIN(a, b) ((a) <= (b) ? (a) : (b))
typedef uint8_t u8;
typedef uint64_t u64;
// Returns the smallest positive integer y such that
// (x + y) % pow_2 == 0
// Basically, it's how many bytes we need to add to "align" x.
// Only works when pow_2 is a power of 2.
// Note: we use ~x+1 instead of -x to avoid compiler warnings
static size_t align(size_t x, size_t pow_2)
{
return (~x + 1) & (pow_2 - 1);
}
static u64 load64_be(const u8 s[8])
{
return((u64)s[0] << 56)
| ((u64)s[1] << 48)
| ((u64)s[2] << 40)
| ((u64)s[3] << 32)
| ((u64)s[4] << 24)
| ((u64)s[5] << 16)
| ((u64)s[6] << 8)
| (u64)s[7];
}
static void store64_be(u8 out[8], u64 in)
{
out[0] = (u8)(in >> 56);
out[1] = (u8)(in >> 48);
out[2] = (u8)(in >> 40);
out[3] = (u8)(in >> 32);
out[4] = (u8)(in >> 24);
out[5] = (u8)(in >> 16);
out[6] = (u8)(in >> 8);
out[7] = (u8) in ;
}
static void load64_be_buf (u64 *dst, const u8 *src, size_t size) {
FOR(i, 0, size) { dst[i] = load64_be(src + i*8); }
}
///////////////
/// SHA 512 ///
///////////////
static u64 rot(u64 x, int c ) { return (x >> c) | (x << (64 - c)); }
static u64 ch (u64 x, u64 y, u64 z) { return (x & y) ^ (~x & z); }
static u64 maj(u64 x, u64 y, u64 z) { return (x & y) ^ ( x & z) ^ (y & z); }
static u64 big_sigma0(u64 x) { return rot(x, 28) ^ rot(x, 34) ^ rot(x, 39); }
static u64 big_sigma1(u64 x) { return rot(x, 14) ^ rot(x, 18) ^ rot(x, 41); }
static u64 lit_sigma0(u64 x) { return rot(x, 1) ^ rot(x, 8) ^ (x >> 7); }
static u64 lit_sigma1(u64 x) { return rot(x, 19) ^ rot(x, 61) ^ (x >> 6); }
static const u64 K[80] = {
0x428a2f98d728ae22,0x7137449123ef65cd,0xb5c0fbcfec4d3b2f,0xe9b5dba58189dbbc,
0x3956c25bf348b538,0x59f111f1b605d019,0x923f82a4af194f9b,0xab1c5ed5da6d8118,
0xd807aa98a3030242,0x12835b0145706fbe,0x243185be4ee4b28c,0x550c7dc3d5ffb4e2,
0x72be5d74f27b896f,0x80deb1fe3b1696b1,0x9bdc06a725c71235,0xc19bf174cf692694,
0xe49b69c19ef14ad2,0xefbe4786384f25e3,0x0fc19dc68b8cd5b5,0x240ca1cc77ac9c65,
0x2de92c6f592b0275,0x4a7484aa6ea6e483,0x5cb0a9dcbd41fbd4,0x76f988da831153b5,
0x983e5152ee66dfab,0xa831c66d2db43210,0xb00327c898fb213f,0xbf597fc7beef0ee4,
0xc6e00bf33da88fc2,0xd5a79147930aa725,0x06ca6351e003826f,0x142929670a0e6e70,
0x27b70a8546d22ffc,0x2e1b21385c26c926,0x4d2c6dfc5ac42aed,0x53380d139d95b3df,
0x650a73548baf63de,0x766a0abb3c77b2a8,0x81c2c92e47edaee6,0x92722c851482353b,
0xa2bfe8a14cf10364,0xa81a664bbc423001,0xc24b8b70d0f89791,0xc76c51a30654be30,
0xd192e819d6ef5218,0xd69906245565a910,0xf40e35855771202a,0x106aa07032bbd1b8,
0x19a4c116b8d2d0c8,0x1e376c085141ab53,0x2748774cdf8eeb99,0x34b0bcb5e19b48a8,
0x391c0cb3c5c95a63,0x4ed8aa4ae3418acb,0x5b9cca4f7763e373,0x682e6ff3d6b2b8a3,
0x748f82ee5defb2fc,0x78a5636f43172f60,0x84c87814a1f0ab72,0x8cc702081a6439ec,
0x90befffa23631e28,0xa4506cebde82bde9,0xbef9a3f7b2c67915,0xc67178f2e372532b,
0xca273eceea26619c,0xd186b8c721c0c207,0xeada7dd6cde0eb1e,0xf57d4f7fee6ed178,
0x06f067aa72176fba,0x0a637dc5a2c898a6,0x113f9804bef90dae,0x1b710b35131c471b,
0x28db77f523047d84,0x32caab7b40c72493,0x3c9ebe0a15c9bebc,0x431d67c49c100d4c,
0x4cc5d4becb3e42b6,0x597f299cfc657e2a,0x5fcb6fab3ad6faec,0x6c44198c4a475817
};
static void sha512_compress(crypto_sha512_ctx *ctx)
{
u64 a = ctx->hash[0]; u64 b = ctx->hash[1];
u64 c = ctx->hash[2]; u64 d = ctx->hash[3];
u64 e = ctx->hash[4]; u64 f = ctx->hash[5];
u64 g = ctx->hash[6]; u64 h = ctx->hash[7];
FOR (j, 0, 16) {
u64 in = K[j] + ctx->input[j];
u64 t1 = big_sigma1(e) + ch (e, f, g) + h + in;
u64 t2 = big_sigma0(a) + maj(a, b, c);
h = g; g = f; f = e; e = d + t1;
d = c; c = b; b = a; a = t1 + t2;
}
size_t i16 = 0;
FOR(i, 1, 5) {
i16 += 16;
FOR (j, 0, 16) {
ctx->input[j] += lit_sigma1(ctx->input[(j- 2) & 15]);
ctx->input[j] += lit_sigma0(ctx->input[(j-15) & 15]);
ctx->input[j] += ctx->input[(j- 7) & 15];
u64 in = K[i16 + j] + ctx->input[j];
u64 t1 = big_sigma1(e) + ch (e, f, g) + h + in;
u64 t2 = big_sigma0(a) + maj(a, b, c);
h = g; g = f; f = e; e = d + t1;
d = c; c = b; b = a; a = t1 + t2;
}
}
ctx->hash[0] += a; ctx->hash[1] += b;
ctx->hash[2] += c; ctx->hash[3] += d;
ctx->hash[4] += e; ctx->hash[5] += f;
ctx->hash[6] += g; ctx->hash[7] += h;
}
// Write 1 input byte
static void sha512_set_input(crypto_sha512_ctx *ctx, u8 input)
{
size_t word = ctx->input_idx >> 3;
size_t byte = ctx->input_idx & 7;
ctx->input[word] |= (u64)input << (8 * (7 - byte));
}
// Increment a 128-bit "word".
static void sha512_incr(u64 x[2], u64 y)
{
x[1] += y;
if (x[1] < y) {
x[0]++;
}
}
void crypto_sha512_init(crypto_sha512_ctx *ctx)
{
ctx->hash[0] = 0x6a09e667f3bcc908;
ctx->hash[1] = 0xbb67ae8584caa73b;
ctx->hash[2] = 0x3c6ef372fe94f82b;
ctx->hash[3] = 0xa54ff53a5f1d36f1;
ctx->hash[4] = 0x510e527fade682d1;
ctx->hash[5] = 0x9b05688c2b3e6c1f;
ctx->hash[6] = 0x1f83d9abfb41bd6b;
ctx->hash[7] = 0x5be0cd19137e2179;
ctx->input_size[0] = 0;
ctx->input_size[1] = 0;
ctx->input_idx = 0;
ZERO(ctx->input, 16);
}
void crypto_sha512_update(crypto_sha512_ctx *ctx,
const u8 *message, size_t message_size)
{
// Avoid undefined NULL pointer increments with empty messages
if (message_size == 0) {
return;
}
// Align ourselves with word boundaries
if ((ctx->input_idx & 7) != 0) {
size_t nb_bytes = MIN(align(ctx->input_idx, 8), message_size);
FOR (i, 0, nb_bytes) {
sha512_set_input(ctx, message[i]);
ctx->input_idx++;
}
message += nb_bytes;
message_size -= nb_bytes;
}
// Align ourselves with block boundaries
if ((ctx->input_idx & 127) != 0) {
size_t nb_words = MIN(align(ctx->input_idx, 128), message_size) >> 3;
load64_be_buf(ctx->input + (ctx->input_idx >> 3), message, nb_words);
ctx->input_idx += nb_words << 3;
message += nb_words << 3;
message_size -= nb_words << 3;
}
// Compress block if needed
if (ctx->input_idx == 128) {
sha512_incr(ctx->input_size, 1024); // size is in bits
sha512_compress(ctx);
ctx->input_idx = 0;
ZERO(ctx->input, 16);
}
// Process the message block by block
FOR (i, 0, message_size >> 7) { // number of blocks
load64_be_buf(ctx->input, message, 16);
sha512_incr(ctx->input_size, 1024); // size is in bits
sha512_compress(ctx);
ctx->input_idx = 0;
ZERO(ctx->input, 16);
message += 128;
}
message_size &= 127;
if (message_size != 0) {
// Remaining words
size_t nb_words = message_size >> 3;
load64_be_buf(ctx->input, message, nb_words);
ctx->input_idx += nb_words << 3;
message += nb_words << 3;
message_size -= nb_words << 3;
// Remaining bytes
FOR (i, 0, message_size) {
sha512_set_input(ctx, message[i]);
ctx->input_idx++;
}
}
}
void crypto_sha512_final(crypto_sha512_ctx *ctx, u8 hash[64])
{
// Add padding bit
if (ctx->input_idx == 0) {
ZERO(ctx->input, 16);
}
sha512_set_input(ctx, 128);
// Update size
sha512_incr(ctx->input_size, ctx->input_idx * 8);
// Compress penultimate block (if any)
if (ctx->input_idx > 111) {
sha512_compress(ctx);
ZERO(ctx->input, 14);
}
// Compress last block
ctx->input[14] = ctx->input_size[0];
ctx->input[15] = ctx->input_size[1];
sha512_compress(ctx);
// Copy hash to output (big endian)
FOR (i, 0, 8) {
store64_be(hash + i*8, ctx->hash[i]);
}
WIPE_CTX(ctx);
}
void crypto_sha512(u8 hash[64], const u8 *message, size_t message_size)
{
crypto_sha512_ctx ctx;
crypto_sha512_init (&ctx);
crypto_sha512_update(&ctx, message, message_size);
crypto_sha512_final (&ctx, hash);
}
////////////////////
/// HMAC SHA 512 ///
////////////////////
void crypto_sha512_hmac_init(crypto_sha512_hmac_ctx *ctx,
const u8 *key, size_t key_size)
{
// hash key if it is too long
if (key_size > 128) {
crypto_sha512(ctx->key, key, key_size);
key = ctx->key;
key_size = 64;
}
// Compute inner key: padded key XOR 0x36
FOR (i, 0, key_size) { ctx->key[i] = key[i] ^ 0x36; }
FOR (i, key_size, 128) { ctx->key[i] = 0x36; }
// Start computing inner hash
crypto_sha512_init (&ctx->ctx);
crypto_sha512_update(&ctx->ctx, ctx->key, 128);
}
void crypto_sha512_hmac_update(crypto_sha512_hmac_ctx *ctx,
const u8 *message, size_t message_size)
{
crypto_sha512_update(&ctx->ctx, message, message_size);
}
void crypto_sha512_hmac_final(crypto_sha512_hmac_ctx *ctx, u8 hmac[64])
{
// Finish computing inner hash
crypto_sha512_final(&ctx->ctx, hmac);
// Compute outer key: padded key XOR 0x5c
FOR (i, 0, 128) {
ctx->key[i] ^= 0x36 ^ 0x5c;
}
// Compute outer hash
crypto_sha512_init (&ctx->ctx);
crypto_sha512_update(&ctx->ctx, ctx->key , 128);
crypto_sha512_update(&ctx->ctx, hmac, 64);
crypto_sha512_final (&ctx->ctx, hmac); // outer hash
WIPE_CTX(ctx);
}
void crypto_sha512_hmac(u8 hmac[64], const u8 *key, size_t key_size,
const u8 *message, size_t message_size)
{
crypto_sha512_hmac_ctx ctx;
crypto_sha512_hmac_init (&ctx, key, key_size);
crypto_sha512_hmac_update(&ctx, message, message_size);
crypto_sha512_hmac_final (&ctx, hmac);
}
////////////////////
/// HKDF SHA 512 ///
////////////////////
void crypto_sha512_hkdf_expand(u8 *okm, size_t okm_size,
const u8 *prk, size_t prk_size,
const u8 *info, size_t info_size)
{
int not_first = 0;
u8 ctr = 1;
u8 blk[64];
while (okm_size > 0) {
size_t out_size = MIN(okm_size, sizeof(blk));
crypto_sha512_hmac_ctx ctx;
crypto_sha512_hmac_init(&ctx, prk , prk_size);
if (not_first) {
// For some reason HKDF uses some kind of CBC mode.
// For some reason CTR mode alone wasn't enough.
// Like what, they didn't trust HMAC in 2010? Really??
crypto_sha512_hmac_update(&ctx, blk , sizeof(blk));
}
crypto_sha512_hmac_update(&ctx, info, info_size);
crypto_sha512_hmac_update(&ctx, &ctr, 1);
crypto_sha512_hmac_final(&ctx, blk);
COPY(okm, blk, out_size);
not_first = 1;
okm += out_size;
okm_size -= out_size;
ctr++;
}
WIPE_BUFFER(blk);
}
void crypto_sha512_hkdf(u8 *okm , size_t okm_size,
const u8 *ikm , size_t ikm_size,
const u8 *salt, size_t salt_size,
const u8 *info, size_t info_size)
{
// Extract
u8 prk[64];
crypto_sha512_hmac(prk, salt, salt_size, ikm, ikm_size);
// Expand
crypto_sha512_hkdf_expand(okm, okm_size, prk, sizeof(prk), info, info_size);
WIPE_BUFFER(prk);
}
///////////////
/// Ed25519 ///
///////////////
void crypto_ed25519_key_pair(u8 secret_key[64], u8 public_key[32], u8 seed[32])
{
u8 a[64];
COPY(a, seed, 32); // a[ 0..31] = seed
crypto_wipe(seed, 32);
COPY(secret_key, a, 32); // secret key = seed
crypto_sha512(a, a, 32); // a[ 0..31] = scalar
crypto_eddsa_trim_scalar(a, a); // a[ 0..31] = trimmed scalar
crypto_eddsa_scalarbase(public_key, a); // public key = [trimmed scalar]B
COPY(secret_key + 32, public_key, 32); // secret key includes public half
WIPE_BUFFER(a);
}
static void hash_reduce(u8 h[32],
const u8 *a, size_t a_size,
const u8 *b, size_t b_size,
const u8 *c, size_t c_size,
const u8 *d, size_t d_size)
{
u8 hash[64];
crypto_sha512_ctx ctx;
crypto_sha512_init (&ctx);
crypto_sha512_update(&ctx, a, a_size);
crypto_sha512_update(&ctx, b, b_size);
crypto_sha512_update(&ctx, c, c_size);
crypto_sha512_update(&ctx, d, d_size);
crypto_sha512_final (&ctx, hash);
crypto_eddsa_reduce(h, hash);
}
static void ed25519_dom_sign(u8 signature[64], const u8 secret_key[64],
const u8 *dom, size_t dom_size,
const u8 *message, size_t message_size)
{
u8 a[64]; // secret scalar and prefix
u8 r[32]; // secret deterministic "random" nonce
u8 h[32]; // publically verifiable hash of the message (not wiped)
u8 R[32]; // first half of the signature (allows overlapping inputs)
const u8 *pk = secret_key + 32;
crypto_sha512(a, secret_key, 32);
crypto_eddsa_trim_scalar(a, a);
hash_reduce(r, dom, dom_size, a + 32, 32, message, message_size, 0, 0);
crypto_eddsa_scalarbase(R, r);
hash_reduce(h, dom, dom_size, R, 32, pk, 32, message, message_size);
COPY(signature, R, 32);
crypto_eddsa_mul_add(signature + 32, h, a, r);
WIPE_BUFFER(a);
WIPE_BUFFER(r);
}
void crypto_ed25519_sign(u8 signature [64], const u8 secret_key[64],
const u8 *message, size_t message_size)
{
ed25519_dom_sign(signature, secret_key, 0, 0, message, message_size);
}
int crypto_ed25519_check(const u8 signature[64], const u8 public_key[32],
const u8 *msg, size_t msg_size)
{
u8 h_ram[32];
hash_reduce(h_ram, signature, 32, public_key, 32, msg, msg_size, 0, 0);
return crypto_eddsa_check_equation(signature, public_key, h_ram);
}
static const u8 domain[34] = "SigEd25519 no Ed25519 collisions\1";
void crypto_ed25519_ph_sign(uint8_t signature[64], const uint8_t secret_key[64],
const uint8_t message_hash[64])
{
ed25519_dom_sign(signature, secret_key, domain, sizeof(domain),
message_hash, 64);
}
int crypto_ed25519_ph_check(const uint8_t sig[64], const uint8_t pk[32],
const uint8_t msg_hash[64])
{
u8 h_ram[32];
hash_reduce(h_ram, domain, sizeof(domain), sig, 32, pk, 32, msg_hash, 64);
return crypto_eddsa_check_equation(sig, pk, h_ram);
}
#ifdef MONOCYPHER_CPP_NAMESPACE
}
#endif
+140
View File
@@ -0,0 +1,140 @@
// Monocypher version 4.0.3
//
// This file is dual-licensed. Choose whichever licence you want from
// the two licences listed below.
//
// The first licence is a regular 2-clause BSD licence. The second licence
// is the CC-0 from Creative Commons. It is intended to release Monocypher
// to the public domain. The BSD licence serves as a fallback option.
//
// SPDX-License-Identifier: BSD-2-Clause OR CC0-1.0
//
// ------------------------------------------------------------------------
//
// Copyright (c) 2017-2019, Loup Vaillant
// All rights reserved.
//
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// ------------------------------------------------------------------------
//
// Written in 2017-2019 by Loup Vaillant
//
// To the extent possible under law, the author(s) have dedicated all copyright
// and related neighboring rights to this software to the public domain
// worldwide. This software is distributed without any warranty.
//
// You should have received a copy of the CC0 Public Domain Dedication along
// with this software. If not, see
// <https://creativecommons.org/publicdomain/zero/1.0/>
#ifndef ED25519_H
#define ED25519_H
#include "monocypher.h"
#ifdef MONOCYPHER_CPP_NAMESPACE
namespace MONOCYPHER_CPP_NAMESPACE {
#elif defined(__cplusplus)
extern "C" {
#endif
////////////////////////
/// Type definitions ///
////////////////////////
// Do not rely on the size or content on any of those types,
// they may change without notice.
typedef struct {
uint64_t hash[8];
uint64_t input[16];
uint64_t input_size[2];
size_t input_idx;
} crypto_sha512_ctx;
typedef struct {
uint8_t key[128];
crypto_sha512_ctx ctx;
} crypto_sha512_hmac_ctx;
// SHA 512
// -------
void crypto_sha512_init (crypto_sha512_ctx *ctx);
void crypto_sha512_update(crypto_sha512_ctx *ctx,
const uint8_t *message, size_t message_size);
void crypto_sha512_final (crypto_sha512_ctx *ctx, uint8_t hash[64]);
void crypto_sha512(uint8_t hash[64],
const uint8_t *message, size_t message_size);
// SHA 512 HMAC
// ------------
void crypto_sha512_hmac_init(crypto_sha512_hmac_ctx *ctx,
const uint8_t *key, size_t key_size);
void crypto_sha512_hmac_update(crypto_sha512_hmac_ctx *ctx,
const uint8_t *message, size_t message_size);
void crypto_sha512_hmac_final(crypto_sha512_hmac_ctx *ctx, uint8_t hmac[64]);
void crypto_sha512_hmac(uint8_t hmac[64],
const uint8_t *key , size_t key_size,
const uint8_t *message, size_t message_size);
// SHA 512 HKDF
// ------------
void crypto_sha512_hkdf_expand(uint8_t *okm, size_t okm_size,
const uint8_t *prk, size_t prk_size,
const uint8_t *info, size_t info_size);
void crypto_sha512_hkdf(uint8_t *okm , size_t okm_size,
const uint8_t *ikm , size_t ikm_size,
const uint8_t *salt, size_t salt_size,
const uint8_t *info, size_t info_size);
// Ed25519
// -------
// Signatures (EdDSA with curve25519 + SHA-512)
// --------------------------------------------
void crypto_ed25519_key_pair(uint8_t secret_key[64],
uint8_t public_key[32],
uint8_t seed[32]);
void crypto_ed25519_sign(uint8_t signature [64],
const uint8_t secret_key[64],
const uint8_t *message, size_t message_size);
int crypto_ed25519_check(const uint8_t signature [64],
const uint8_t public_key[32],
const uint8_t *message, size_t message_size);
// Pre-hash variants
void crypto_ed25519_ph_sign(uint8_t signature [64],
const uint8_t secret_key [64],
const uint8_t message_hash[64]);
int crypto_ed25519_ph_check(const uint8_t signature [64],
const uint8_t public_key [32],
const uint8_t message_hash[64]);
#ifdef __cplusplus
}
#endif
#endif // ED25519_H
File diff suppressed because it is too large. Load diff
+321
View File
@@ -0,0 +1,321 @@
// Monocypher version 4.0.3
//
// This file is dual-licensed. Choose whichever licence you want from
// the two licences listed below.
//
// The first licence is a regular 2-clause BSD licence. The second licence
// is the CC-0 from Creative Commons. It is intended to release Monocypher
// to the public domain. The BSD licence serves as a fallback option.
//
// SPDX-License-Identifier: BSD-2-Clause OR CC0-1.0
//
// ------------------------------------------------------------------------
//
// Copyright (c) 2017-2019, Loup Vaillant
// All rights reserved.
//
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// ------------------------------------------------------------------------
//
// Written in 2017-2019 by Loup Vaillant
//
// To the extent possible under law, the author(s) have dedicated all copyright
// and related neighboring rights to this software to the public domain
// worldwide. This software is distributed without any warranty.
//
// You should have received a copy of the CC0 Public Domain Dedication along
// with this software. If not, see
// <https://creativecommons.org/publicdomain/zero/1.0/>
#ifndef MONOCYPHER_H
#define MONOCYPHER_H
#include <stddef.h>
#include <stdint.h>
#ifdef MONOCYPHER_CPP_NAMESPACE
namespace MONOCYPHER_CPP_NAMESPACE {
#elif defined(__cplusplus)
extern "C" {
#endif
// Constant time comparisons
// -------------------------
// Return 0 if a and b are equal, -1 otherwise
int crypto_verify16(const uint8_t a[16], const uint8_t b[16]);
int crypto_verify32(const uint8_t a[32], const uint8_t b[32]);
int crypto_verify64(const uint8_t a[64], const uint8_t b[64]);
// Erase sensitive data
// --------------------
void crypto_wipe(void *secret, size_t size);
// Authenticated encryption
// ------------------------
void crypto_aead_lock(uint8_t *cipher_text,
uint8_t mac [16],
const uint8_t key [32],
const uint8_t nonce[24],
const uint8_t *ad, size_t ad_size,
const uint8_t *plain_text, size_t text_size);
int crypto_aead_unlock(uint8_t *plain_text,
const uint8_t mac [16],
const uint8_t key [32],
const uint8_t nonce[24],
const uint8_t *ad, size_t ad_size,
const uint8_t *cipher_text, size_t text_size);
// Authenticated stream
// --------------------
typedef struct {
uint64_t counter;
uint8_t key[32];
uint8_t nonce[8];
} crypto_aead_ctx;
void crypto_aead_init_x(crypto_aead_ctx *ctx,
const uint8_t key[32], const uint8_t nonce[24]);
void crypto_aead_init_djb(crypto_aead_ctx *ctx,
const uint8_t key[32], const uint8_t nonce[8]);
void crypto_aead_init_ietf(crypto_aead_ctx *ctx,
const uint8_t key[32], const uint8_t nonce[12]);
void crypto_aead_write(crypto_aead_ctx *ctx,
uint8_t *cipher_text,
uint8_t mac[16],
const uint8_t *ad , size_t ad_size,
const uint8_t *plain_text, size_t text_size);
int crypto_aead_read(crypto_aead_ctx *ctx,
uint8_t *plain_text,
const uint8_t mac[16],
const uint8_t *ad , size_t ad_size,
const uint8_t *cipher_text, size_t text_size);
// General purpose hash (BLAKE2b)
// ------------------------------
// Direct interface
void crypto_blake2b(uint8_t *hash, size_t hash_size,
const uint8_t *message, size_t message_size);
void crypto_blake2b_keyed(uint8_t *hash, size_t hash_size,
const uint8_t *key, size_t key_size,
const uint8_t *message, size_t message_size);
// Incremental interface
typedef struct {
// Do not rely on the size or contents of this type,
// for they may change without notice.
uint64_t hash[8];
uint64_t input_offset[2];
uint64_t input[16];
size_t input_idx;
size_t hash_size;
} crypto_blake2b_ctx;
void crypto_blake2b_init(crypto_blake2b_ctx *ctx, size_t hash_size);
void crypto_blake2b_keyed_init(crypto_blake2b_ctx *ctx, size_t hash_size,
const uint8_t *key, size_t key_size);
void crypto_blake2b_update(crypto_blake2b_ctx *ctx,
const uint8_t *message, size_t message_size);
void crypto_blake2b_final(crypto_blake2b_ctx *ctx, uint8_t *hash);
// Password key derivation (Argon2)
// --------------------------------
#define CRYPTO_ARGON2_D 0
#define CRYPTO_ARGON2_I 1
#define CRYPTO_ARGON2_ID 2
typedef struct {
uint32_t algorithm; // Argon2d, Argon2i, Argon2id
uint32_t nb_blocks; // memory hardness, >= 8 * nb_lanes
uint32_t nb_passes; // CPU hardness, >= 1 (>= 3 recommended for Argon2i)
uint32_t nb_lanes; // parallelism level (single threaded anyway)
} crypto_argon2_config;
typedef struct {
const uint8_t *pass;
const uint8_t *salt;
uint32_t pass_size;
uint32_t salt_size; // 16 bytes recommended
} crypto_argon2_inputs;
typedef struct {
const uint8_t *key; // may be NULL if no key
const uint8_t *ad; // may be NULL if no additional data
uint32_t key_size; // 0 if no key (32 bytes recommended otherwise)
uint32_t ad_size; // 0 if no additional data
} crypto_argon2_extras;
extern const crypto_argon2_extras crypto_argon2_no_extras;
void crypto_argon2(uint8_t *hash, uint32_t hash_size, void *work_area,
crypto_argon2_config config,
crypto_argon2_inputs inputs,
crypto_argon2_extras extras);
// Key exchange (X-25519)
// ----------------------
// Shared secrets are not quite random.
// Hash them to derive an actual shared key.
void crypto_x25519_public_key(uint8_t public_key[32],
const uint8_t secret_key[32]);
void crypto_x25519(uint8_t raw_shared_secret[32],
const uint8_t your_secret_key [32],
const uint8_t their_public_key [32]);
// Conversion to EdDSA
void crypto_x25519_to_eddsa(uint8_t eddsa[32], const uint8_t x25519[32]);
// scalar "division"
// Used for OPRF. Be aware that exponential blinding is less secure
// than Diffie-Hellman key exchange.
void crypto_x25519_inverse(uint8_t blind_salt [32],
const uint8_t private_key[32],
const uint8_t curve_point[32]);
// "Dirty" versions of x25519_public_key().
// Use with crypto_elligator_rev().
// Leaks 3 bits of the private key.
void crypto_x25519_dirty_small(uint8_t pk[32], const uint8_t sk[32]);
void crypto_x25519_dirty_fast (uint8_t pk[32], const uint8_t sk[32]);
// Signatures
// ----------
// EdDSA with curve25519 + BLAKE2b
void crypto_eddsa_key_pair(uint8_t secret_key[64],
uint8_t public_key[32],
uint8_t seed[32]);
void crypto_eddsa_sign(uint8_t signature [64],
const uint8_t secret_key[64],
const uint8_t *message, size_t message_size);
int crypto_eddsa_check(const uint8_t signature [64],
const uint8_t public_key[32],
const uint8_t *message, size_t message_size);
// Conversion to X25519
void crypto_eddsa_to_x25519(uint8_t x25519[32], const uint8_t eddsa[32]);
// EdDSA building blocks
void crypto_eddsa_trim_scalar(uint8_t out[32], const uint8_t in[32]);
void crypto_eddsa_reduce(uint8_t reduced[32], const uint8_t expanded[64]);
void crypto_eddsa_mul_add(uint8_t r[32],
const uint8_t a[32],
const uint8_t b[32],
const uint8_t c[32]);
void crypto_eddsa_scalarbase(uint8_t point[32], const uint8_t scalar[32]);
int crypto_eddsa_check_equation(const uint8_t signature[64],
const uint8_t public_key[32],
const uint8_t h_ram[32]);
// Chacha20
// --------
// Specialised hash.
// Used to hash X25519 shared secrets.
void crypto_chacha20_h(uint8_t out[32],
const uint8_t key[32],
const uint8_t in [16]);
// Unauthenticated stream cipher.
// Don't forget to add authentication.
uint64_t crypto_chacha20_djb(uint8_t *cipher_text,
const uint8_t *plain_text,
size_t text_size,
const uint8_t key[32],
const uint8_t nonce[8],
uint64_t ctr);
uint32_t crypto_chacha20_ietf(uint8_t *cipher_text,
const uint8_t *plain_text,
size_t text_size,
const uint8_t key[32],
const uint8_t nonce[12],
uint32_t ctr);
uint64_t crypto_chacha20_x(uint8_t *cipher_text,
const uint8_t *plain_text,
size_t text_size,
const uint8_t key[32],
const uint8_t nonce[24],
uint64_t ctr);
// Poly 1305
// ---------
// This is a *one time* authenticator.
// Disclosing the mac reveals the key.
// See crypto_lock() on how to use it properly.
// Direct interface
void crypto_poly1305(uint8_t mac[16],
const uint8_t *message, size_t message_size,
const uint8_t key[32]);
// Incremental interface
typedef struct {
// Do not rely on the size or contents of this type,
// for they may change without notice.
uint8_t c[16]; // chunk of the message
size_t c_idx; // How many bytes are there in the chunk.
uint32_t r [4]; // constant multiplier (from the secret key)
uint32_t pad[4]; // random number added at the end (from the secret key)
uint32_t h [5]; // accumulated hash
} crypto_poly1305_ctx;
void crypto_poly1305_init (crypto_poly1305_ctx *ctx, const uint8_t key[32]);
void crypto_poly1305_update(crypto_poly1305_ctx *ctx,
const uint8_t *message, size_t message_size);
void crypto_poly1305_final (crypto_poly1305_ctx *ctx, uint8_t mac[16]);
// Elligator 2
// -----------
// Elligator mappings proper
void crypto_elligator_map(uint8_t curve [32], const uint8_t hidden[32]);
int crypto_elligator_rev(uint8_t hidden[32], const uint8_t curve [32],
uint8_t tweak);
// Easy to use key pair generation
void crypto_elligator_key_pair(uint8_t hidden[32], uint8_t secret_key[32],
uint8_t seed[32]);
#ifdef __cplusplus
}
#endif
#endif // MONOCYPHER_H
+1
View File
@@ -52,6 +52,7 @@ The game finds the game data as on Linux. Refer to "Start the game" in
| Settings | `config.toml` next to `halo.exe` |
| Saved games | `%APPDATA%\halo`, or `paths.saves` in `config.toml` |
| Log | `debug.txt` in the data root (the folder that contains `maps\`) |
| Log of the port | The console. The release build has no console: `halo.log` next to `halo.exe` |
## How the port operates
+18
View File
@@ -37,6 +37,24 @@ static void windows_startup(void)
/* Sleep() waits in 1 ms steps rather than the default 15.6 ms: the
game's frame pacing sleeps for short intervals */
timeBeginPeriod(1);
/* a release build has no console (/SUBSYSTEM:WINDOWS), so the platform
layer's log (platform_log's stderr: invite links, the data root, crash
reports) goes to halo.log next to halo.exe, unless stderr already goes
somewhere (a pipe or a file the game was started with) */
if (_fileno(stderr) < 0)
{
char path[MAX_PATH];
DWORD length = GetModuleFileNameA(NULL, path, sizeof(path));
char *slash;
if (length && length < sizeof(path) && (slash = strrchr(path, '\\')) &&
(size_t)(slash + 1 - path) + sizeof("halo.log") <= sizeof(path))
{
strcpy(slash + 1, "halo.log");
if (freopen(path, "w", stderr))
setvbuf(stderr, NULL, _IONBF, 0);
}
}
}
static int errno_from_windows_error(DWORD error)
+12 -1
View File
@@ -317,6 +317,7 @@ symbols in this file:
#include "units/units.h"
#include "units/vehicle_definitions.h"
#include "units/vehicles.h"
#include "networking/network_game_globals.h"
/* ---------- constants */
@@ -2224,6 +2225,12 @@ long actor_new(
long actor_definition_index;
long actor_index = NONE;
/* port: a client of the distributed netcode runs no AI: it has the host's
actors' units, driven as the host sends them (port/linux/game/network_actors.c),
and its own (placed at the map's start or by its scripts) would be extras
the host doesn't have */
if (network_game_distributed_client())
return NONE;
if (actor_variant_definition_index != NONE)
{
actor_variant_definition = actor_variant_definition_get(actor_variant_definition_index);
@@ -2662,6 +2669,9 @@ long actor_place(
long unit_index;
match_assert("c:\\halo\\SOURCE\\ai\\actors.c", 603, starting_location);
/* port: none on a client of the distributed netcode (actor_new) */
if (network_game_distributed_client())
return NONE;
objects_garbage_collection();
actor_variant_definition =
@@ -2831,7 +2841,8 @@ short actors_spawn_from_unit(
{
short spawned_actor_count = 0;
if (actor_variant_definition_index != NONE && actor_count > 0)
/* port: none on a client of the distributed netcode (actor_new) */
if (actor_variant_definition_index != NONE && actor_count > 0 && !network_game_distributed_client())
{
struct unit_datum *source_unit = unit_get(unit_index);
long source_actor_index = source_unit->unit.swarm_actor_index != NONE ?
+9 -4
View File
@@ -25,9 +25,10 @@ enum
enum
{
MAXIMUM_ACTORS = 256,
MAXIMUM_SWARMS = 32,
MAXIMUM_SWARM_COMPONENTS = 256,
/* port: the native builds' larger pools (halo_port_capacity.h) */
MAXIMUM_ACTORS = HALO_PORT_MAXIMUM_ACTORS,
MAXIMUM_SWARMS = HALO_PORT_MAXIMUM_SWARMS,
MAXIMUM_SWARM_COMPONENTS = HALO_PORT_MAXIMUM_SWARM_COMPONENTS,
SWARM_COMPONENT_DATUM_SIZE = 0x40,
};
@@ -255,7 +256,11 @@ enum
NUMBER_OF_ACTOR_PERCEPTION_TYPES,
};
#define MAXIMUM_NUMBER_OF_ACTORS 256
/* port: the debug information's actors (ai_debug.c's actor_debug_array,
by actor index): every actor of the native builds' larger pool
(halo_port_capacity.h), else one past the Xbox's 256 is written past its
end */
#define MAXIMUM_NUMBER_OF_ACTORS HALO_PORT_MAXIMUM_ACTORS
#define MAXIMUM_NUMBER_OF_ACTOR_PATHS 32
#define MAXIMUM_UNIT_INDICES_PER_SWARM 16
+17 -5
View File
@@ -465,7 +465,8 @@ typedef char ai_prop_unopposable_enemy_offset_assert[
static void ai_place_pending_mounted_weapons(
void);
static boolean ai_enemies_endanger_player(
boolean must_be_attacking);
boolean must_be_attacking,
long unit_index);
static void ai_flush_spatial_effects(
void);
@@ -1971,8 +1972,11 @@ void ai_update(
return;
}
/* port: unit_index NONE is any player's unit (the game's own check); else
only enemies of that unit count (network co-op's respawn, players.c) */
static boolean ai_enemies_endanger_player(
boolean must_be_attacking)
boolean must_be_attacking,
long unit_index)
{
long current_time = game_time_get();
struct data_iterator iterator;
@@ -1985,7 +1989,8 @@ static boolean ai_enemies_endanger_player(
{
if (prop->player &&
prop->enemy &&
unit_get(prop->unit_index)->unit.player_index != NONE)
unit_get(prop->unit_index)->unit.player_index != NONE &&
(unit_index == NONE || prop->unit_index == unit_index))
{
struct actor_datum *actor = actor_get(prop->owner_actor_index);
long object_index = actor->meta.swarm
@@ -2068,13 +2073,20 @@ static boolean ai_enemies_endanger_player(
boolean ai_enemies_can_see_player(
void)
{
return ai_enemies_endanger_player(FALSE);
return ai_enemies_endanger_player(FALSE, NONE);
}
boolean ai_enemies_attacking_player(
void)
{
return ai_enemies_endanger_player(TRUE);
return ai_enemies_endanger_player(TRUE, NONE);
}
/* port: whether enemies are attacking this player's unit */
boolean ai_port_enemies_attacking_unit(
long unit_index)
{
return ai_enemies_endanger_player(TRUE, unit_index);
}
long ai_get_race_from_team_index(
+3
View File
@@ -142,6 +142,9 @@ boolean ai_consider_major_upgrade(
short squad_index,
real chance);
/* port: network co-op's respawn (players.c) */
boolean ai_port_enemies_attacking_unit(
long unit_index);
boolean ai_enemies_attacking_player(
void);
boolean ai_enemies_can_see_player(
Loaded 100 of 178 files, more files were not shown because too many files have changed in this diff. Show more