Skip to content

Commit

Permalink
Add docs source code to main repo
Browse files Browse the repository at this point in the history
  • Loading branch information
arthuro555 committed Sep 22, 2022
1 parent c304c95 commit c57976b
Show file tree
Hide file tree
Showing 44 changed files with 8,702 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Dependencies
/node_modules

# Production
/build

# Generated files
.docusaurus
.cache-loader

# Misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
25 changes: 25 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Website

The THNK website and docs are built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator.

## Contributing

Contributing is simple and welcome! Just submit a PR with your changes.

### Installation

```
$ yarn
```

### Display the website with local changes

```
$ yarn start
```

This command starts a local development server and opens it up in a browser window. Most changes are reflected live without having to restart the server.

### Creating pages

Creating and editing pages is as simple as editing markdown files in the `docs` folder. To create a new page simply make an empty text file, rename it to end in .md, and start writing!
3 changes: 3 additions & 0 deletions docs/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: [require.resolve('@docusaurus/core/lib/babel/preset')],
};
27 changes: 27 additions & 0 deletions docs/blog/2022-05-08-docs-released.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
slug: website-released
title: The THNK website has been released!
description: I am happy to announce the opening of the THNK website!
image: /img/THNK-thumbnail.png
authors: [arthuro555]
tags: [website, docs, announcement]
keywords:
[
thnk,
release,
docs,
website,
gdevelop,
p2p,
multiplayer,
network,
beta,
preview,
]
---

THNK now has a website!

It is built upon Docusaurus 2.0, and will be home to the documentation and the blog/devlog of THNK. You can submit modifications to it via GitHub, and are welcome to help. I hope to achieve to build together a quality resource for understanding THNK.

That's it for now, there is not much to say yet. See you later for more 😉!
5 changes: 5 additions & 0 deletions docs/blog/authors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
arthuro555:
name: Arthur Pacaud
title: Maintainer of THNK
url: https://github.com/arthuro555
image_url: https://github.com/arthuro555.png
14 changes: 14 additions & 0 deletions docs/docs/base-concepts/THNK-Server-Client-Diagram.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions docs/docs/base-concepts/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"label": "Base concepts",
"position": 3,
"link": {
"type": "generated-index",
"description": "Learn the most important THNK concepts here!"
}
}
32 changes: 32 additions & 0 deletions docs/docs/base-concepts/adapters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
description: Learn what adapters are and how they can help you!
sidebar_position: 2
---

# Adapters

THNK by itself does not care about the networking itself, only about the multiplayer. Ironically though, the THNK core extension therefore only allows you to play your game in singleplayer. If you want to play it in multiplayer, you will have to plug an _adapter_ into THNK.

An adapter tells THNK how to communicate with servers or clients in a specific way. You can theoretically build your own via JavaScript, but THNK provides a few official adapter extensions that should cover all your needs.

## P2P Adapter

:::warning

P2P is not meant for MMOs! It leaks one's IP address, and that is _by design_. You should always see P2P as a kind of _super LAN_ that can sometimes also work over the internet - You can use it to connect to a trusted friend and play with them, but you should _never_ use it to connect with a lot of strangers.

:::

The P2P adapter simply allows a THNK game to be hosted onto your P2P connection, and to connect to servers using their P2P ID.

To use it, you need to first connect your game to a broker server. It is up to you wehter to use the default one or a custom one - THNK works with either. Then, you can use the actions to host a server. When hosting the server, give a way to copy your P2P ID, for example with the text input object. Finally, you can use the connection action to connect as a client to a P2P server using the server's ID.

## Planned Adapters

Here is the list of adapters planned for the future:

- WebSockets
- Split screen multiplayer
- THNK Cloud

Don't hesitate to [submit other suggestions](https://github.com/arthuro555/THNK/issues/new)!
44 changes: 44 additions & 0 deletions docs/docs/base-concepts/clients-and-servers.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
description: Learn everythong about THNK servers and clients, and how they work together!
sidebar_position: 1
---

import Diagram from "./THNK-Server-Client-Diagram.svg";

# Clients and servers

A THNK game is always split in two parts: the server and client. They are different modes THNK can run your game in:

## Servers

THNK is authoritative, which means that only one instance of the game runs the game logic. This instance is the server. The server will then send to every client the new positions of the objects, the variables, etc. All of this data is called the game state.

The server can be provided as different entities: it can be the local PC in singleplayer, a player's game instance, a player's dedicated game server, game servers you provide for your players...

Unless the server is also a client (e.g. if you start a scene as a THNK server on a normal build of the game), the server will not run the client code. Server code is always ran on the server.

## Clients

A client is a game instance connected to a server. It does never runs server code, but always runs the client code. The client's responsibilities include:

1. Apparence related events (animations, camera, juice, HUD, menus...)
2. Player input (key presses to move the character, actions in menus, sending a message in chat...)

A client cannot falsify the game state that the other players interact with, since all actions and game state synchronization are actually performed by the server. This makes cheating hard and unlikely for your game. Of course, if the server gives too much control on the player input, the protection all falls appart! Keep the client commands simple and as much controlled by the server as possible.

## Interation between server and client

The client and server communicate differently. The client communicates with the server by sending it _commands_, and the server answers with _game state_.

The typical flow looks like this:

<Diagram />

The player, by interacting with the game, produces commands. The server regularely
runs the server events, a server tick. Within it, any clients commands may be processed.
At the end of the tick, the THNK server creates a patch describing the differences
in the game state between before and after the server tick, and sends it to all clients.
The client applies the patch to its local copy of the game state, thereby changing
the objects positions and variables's values as the server code ordered.

The server doesn't has commands it can send the player back, only state. So if you want to make some data only available on request because it is fairly big, you can do a request-response system by sending a command to the server, and then waiting for it to respond with the requested information with the next game state update as a player-only state variable.
8 changes: 8 additions & 0 deletions docs/docs/getting-started/_category_.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"label": "Getting started",
"position": 2,
"link": {
"type": "generated-index",
"description": "A thorough introduction to THNK. This is the recommended way to learn THNK."
}
}
35 changes: 35 additions & 0 deletions docs/docs/getting-started/creating-a-scene.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
sidebar_position: 2
---

# Creating a THNK scene

THNK doesn't have a lot of requirements for yu to create a scene it can work with; All you got to do is separate client code from server code.

:::tip Remember!

**Client code** is the part that players use to interact with the game. Any presentational elements, like the camera, object & layer effects, sprite animations, the music, or interactions with the game, like inputs, menus, HUDs...

**Server code** is the part that defines your game's logic and state, that a hacker should be unable to tamper with. Things like object positions & movement, states of different objects, collisions, player stats, combat damage calculations...

:::

The most basic valid THNK scene looks like this:

![A simple scene with a "Start server code" and "Start client code" conditions in separate events](img/base-THNK-events.png)

:::tip Remember!

Every THNK scene must respect three rules:

1. Code needs to be under either a client or server condition. Group and comments are fine, but actual events cannot be
2. There can be only 1 server and 1 client code condition. Use subevents instead of repeating the condition.
3. The client code must always go before the server code.

While it won't break your game immediately to disrespect those rules, they can lead to unexpected behavior and bugs that will be hard for you to diagnose and fix.

![The genie of THNK warns you about respecting the three rules. If you don't respect them, you'll regret it, and, well, don't say he didn't warn you.](img/Genie-warning.png)

:::

Enough lecturing, [let's get started creating](/docs/getting-started/simple-platformer)!
Binary file added docs/docs/getting-started/img/Genie-warning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions docs/docs/getting-started/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
sidebar_position: 1
---

# Installing THNK

:::caution

THNK is currently in early stages. It is still usable and a much better experience than building multiplayer by yourself, but it may have bugs or features that are important for you that are not yet available. Be aware of this when considering THNK!

:::

## Pre-requisites

THNK is a GDevelop framework, so you will need to have GDevelop downloaded. It is recommended to have some base GDevelop knowledge before getting started with THNK. [You can find resources to learn GDevelop on the GDevelop wiki.](https://wiki.gdevelop.io/gdevelop5/tutorials/basic-game-making-concepts)

## Installation

To get started with THNK, the first step is to download the core THNK extension. Currently, it is not available yet in the extention gallery, and has to be installed manually.

To do so, download the [latest release of THNK from github](https://github.com/arthuro555/THNK/releases) (or you can [get the latest nightly build](https://raw.githubusercontent.com/arthuro555/THNK/master/extensions/THNK.json)).

![GIF showing how to download THNK](./install-gifs/dl-thnk.gif)

To import it, go into the Project Manager, click on Functions/Behaviors, select "Create or search for new extensions", and finally click "Import extension" button at the bottom left. It will open a file selector that will allow you to open the THNK extension file.

![GIF showing how to install THNK](./install-gifs/install-thnk.gif)

## Install an adapter

THNK by itself doesn't provide much value, make sure you follow the same steps
7 changes: 7 additions & 0 deletions docs/docs/getting-started/simple-platformer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
sidebar_position: 3
---

# Making a simple platformer with THNK

TODO
13 changes: 13 additions & 0 deletions docs/docs/migrating.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
sidebar_position: 4
---

# Migrating to THNK

Have you started to create a game without THNK, and want to move to it? Here is a small guide to help you!

:::note

The guide has not been written yet, lol

:::
91 changes: 91 additions & 0 deletions docs/docs/why-thnk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
sidebar_position: 1
title: What is THNK?
description: A brief introduction to THNK - What is it? Why would I want to use it? How do I get started? All of those questions will be answered here. It is the recommended starting point to get started with the THNK framework.
keywords: [getting started, intro]
---

<head>
<script type="application/ld+json">
{JSON.stringify({
"@context": "https://schema.org",
"@type": "Organization",
"url": "https://thnk.arthuro555.com/docs/why-thnk/",
"logo": "https://thnk.arthuro555.com/img/thnk.png"
})}
</script>
</head>

# Getting started with THNK - What is THNK anyways?

> THNK is a framework for building GDevelop games with multiplayer in mind.
:::info

THNK is a framework, and not a simple extension - it's a whole way of structuring and coding your games. It is made to be very flexible despite forcing a structure onto your events, so no need to worry if you already started making your game and want to add THNK to it. Check out the [Migration Guide](/docs/migrating) for more informations.

:::

## Why THNK?

Building your game on top of THNK provides multiple benefits. Here are the most notable ones:

### It makes your game work in both single- and multi-player without any extra changes

THNK by itself doesn't makes your game multiplayer games per-se, by default it still works in singleplayer as normal. You can switch to scenes built with THNK and they will work just like they would if not made with it. You are not committing to multiplayer by using THNK - only making it super easy to add a high quality multiplayer feature to the game.

### Multiplayer can be enabled in a single action

The real magic of THNK lies in its numerous adapter extensions. An adapter extension allows you to launch a server or client for a specifc networking backend in 1 action. The currently available adapters include:

- P2P (World-Wide LAN-like experience)
- WebSockets (True LAN experience) (coming soon!)
- Split-screen (coming soon!)

This allows for a variety of types of multiplayers to be implemented without any efforts in mere minutes!

### THNK multiplayer is always authoritative

Multiplayer games can be done in a lot of ways. All there is to it in the end is to synchronize objects across instances of a game. But certain ways of doing it can be bad: if we let everyone synchronize any object of the game, a hacker could easily send malicious updates to other clients in order to cheat or crash their games.

Authoritative multiplayer is an architecture that aims to protect against this. In an authoritative architecture, there is a single designated server that runs all of the game code. This is the so-called _source of truth_: all instances of the game will trust it and only that servers. That way, for a hacker to manipulate the game, they would have to control the server.

This technique is not 100% infaillible either, especially in a context where anyone can host a server and the host may be a hacker, but it should still protects against 99% the hacking & cheating techniques & attempts.

In THNK, all multiplayer, regardless of the adapter, will always be authoritative. Simply by making your game with THNK, you highly decrease the chances of someone managing to hack or cheat in your game.

### Server builds

THNK is made to be able to create a special server build out of your game. This build can then be shared with players for them to host their own game servers (like minecraft), or you can use it to host optimized game servers on your own, allowing to create MMOs for example.

In the future, a THNK Cloud is planned. This would be a platform that would take care of creating server builds for you and hosting your game servers, _for free_! If you want it to see the light of day, consider [making a donation to help buy the servers](https://ko-fi.com/arthuro555).

### Dead simple object & variables synchronization

Synchronizing objects and variables can be a pain when doing multiplayer by yourself. In THNK, it is a simple as putting a behavior on objects you want to be synchronized, and prefix the names of variables you want to be synchornized with `State.`. You can focus on your game instead of the netwroking and synchronizing of different things.

### It provides an optimized solution for synchronizing objects and variables across server and clients.

THNK is as optimized as it gets for making your games server and client super fast.

- It uses a custom binary protocol based on [FlatBuffers](https://google.github.io/flatbuffers/) and [msgpackr](https://github.com/kriszyp/msgpackr), instead of much heavier formats like JSON, and additionally, all messages are compressed using the defalte algorithm, the same as the one used in zip files, to use the most minimal bandwidth and provide faster packing and unpacking of messages.
- It synchronizes in a smart way: it only synchronizes the parts you care about, and only if they changed since the last server tick.
- It allows to have a server update rate slower than the client, and interpolate results on the client, to use up less server resources and bandwidth. (WIP)
- It never runs server code on the client or client code on server builds (Note that THNK servers in non-server builds of the game also act as a client to itself)

:::note

It is planned to add the possibility to leverage the optimized binary snapshotting of a scene to allow adding saving and loading easily in the future.

:::

### And much more!

- Linking objects to players
- Authentication (coming soon!)
- Server replication (designating and keeping up to date a secondary server as a failsafe) (coming soon!)
- Etc...

## How do I get started?

Are you convinced yet? If so, [continue to the next page to learn how to get started using THNK.](/docs/category/getting-started/)
Loading

0 comments on commit c57976b

Please sign in to comment.