or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
WebRTC architecture
This is for Snopek Games' WebRTC with Nakama demo.
NON EXHAUSTIVE, EDITS WELCOME
Singletons
any script in the project can access all of these files
Build
useless, only used by GitLab CI when building the game
GameState
for now, just tells your if the game is in Local or Online mode
Nakama
a singleton for communicating with a Nakama server - part of the Nakama client library from Heroic Labs. Don't change unless you need an uncommitted patch to the upstream library.
OnlineMatch
sets up all of your webrtc stuff. Don't touch this either, unless you know what your doing.
(TODO: Go back and document how all of this works, theres a lot of important stuff in here)
(I haven't covered everything in here yet, but I want to.)
Exposes these variables:
Networking enums:
- MatchState{LOBBY, MATCHING, CONNECTING, WAITING_FOR_ENOUGH_PLAYERS, READY, PLAYING}
- MatchMode{NONE, CREATE, JOIN, MATCHMAKER}
- PlayerStatus{CONNECTING, CONNECTED}
- MatchOpCode{WEBRTC_PEER_METHOD, JOIN_SUCCESS, JOIN_ERROR}
Exposes these signals:
Player
SUPER IMPORTANT: Online Match has its own class called Player that is used for many of the signals seen above. It's purpose is to connect a Nakama user to a Godot peer, and includes within it a lot of important information.
Variables:
Methods:
Online
Boilerplate networking stuff.
Exposes these variables:
Implements these functions:
get_nakama_client
set_nakama_session:
sets nakama_session to the new session passed in. Closes out the old session for you
Emits signal "session_changed" if changed to any session.
However, emits "session_connected" only if the session is valid.
connect_nakama_socket
In-game Networking Scripts
These are the scripts that, while not being tied to the actual gameplay, help set up with the networking stuff and keeps it running.
Important note: There are a bunch of functions that are "remotesync" functions. What this means is that it can be called as a normal function, but it can also be called by remote clients on the local client. (Ex. Client B can call player_ready in an rpc call and say they want it called on Client A). When you rpc a remotesync function, you call it on both the local AND remote clients.
Game
Sets up the players and does match/player life cycle stuff
Exposes these variables:
Exposes these signals for callbacks:
Implements these functions:
Main
Gets you connected to Nakama and also sets up the WebRTC connections
(We will ignore the UI stuff as it's not really relevant and its pretty self-explanatory.)
Before we dive into this code, there are a few functions that use "get_tree().is_network_server()", so lets quickly explain what that is.
Exposes these variables:
We'll skip over most of the UI related functions, but there's one important one:
_on_ReadyScreen_ready_pressed() -> void:
OnlineMatch callback functions
Gameplay methods and callbacks
The following are callbacks from Game to Main, but they are all declared in the scene (Main.tscn)
(TODO: Document this function more. It's late and I'm tired)
Gameplay scripts w/ Networking
Map
Constants:
Exposes these functions:
map_start()
.Player
Exposes thses variables:
player_name_label - reference to the UI label
hitbox - Hitbox reference
animation_player - animation player reference
player_controlled - boolean saying if this player node is the one being controlled by local inputs
input_prefix - tells which port the inputs are coming from.
speed - speed of the player
Has these signals:
player_dead() - called when the player dies.
Implements these functions:
set_player_name(player_name: String)
attack()
hurt()
die()
_physics_process(delta: float)
update_remote_player(_position: Vector2, is_attacking: bool)
puppet
because you only want it run on peers that aren't the master of this player (as set inplayer.set_network_master()
)