Skip to content
This repository was archived by the owner on Sep 15, 2024. It is now read-only.

Commit c95c0cd

Browse files
2 parents 59e8773 + f276634 commit c95c0cd

File tree

6 files changed

+151
-36
lines changed

6 files changed

+151
-36
lines changed

.github/COMMON_MISTAKES.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
## Thread Safety
2-
THREAD SAFETY IS NO JOKE. Really really weird things will happen if you don't follow thread safety (as seen [here](https://github.com/valkyrienyanko/GodotModules/issues/13)) :(
1+
## Export settings not setup properly
2+
![image](https://user-images.githubusercontent.com/6277739/176059155-de5edd40-3529-4e39-9769-aff75832ad7b.png)
3+
4+
Make sure export resource settings look exactly like this or you may run into the error
5+
`[Warning]: Failed to open res://Scripts/Lua, Error: 'InvalidParameter'`
36

4-
Note that tasks are surrounded with try catch so you will see error in console unlike with issue above.
7+
## Thread Safety
8+
The netcode uses a while loop that runs constantly and thus needs to be on a separate thread from the Godot thread. Two methods are used to safely send data between threads, ConcurrentQueue<T> and Interlocked.Read(). ConcurrentQueue<T> allows any kind of data to be enqueued on one thread and dequeued on another. Interlocked.Read() is a nice and easy way to read a bool from any thread. If data is not accessed through one of these methods, then the rules of thread safety are being violated and will vastly increase the chances of the program crashing with no errors. Trying to debug errors that do not appear in the console is a nightmare, please be mindful when sending data between threads.
59

610
## Reading data from packets
7-
I make this mistake all the time, the app will continue to run like normal except you will always yet the default value of whatever type you are reading. In this case it is a bool, it would always be false.
11+
You may forget to assign the value that `reader.readXXXX();` returns. If this happens then in this case the `Ready` bool will always have the default value `false`.
812
```cs
913
public bool Ready { get; set; }
1014

@@ -20,17 +24,20 @@ public override void Read(PacketReader reader)
2024
}
2125
```
2226

23-
Also forgetting to extend from `PacketServerPeerId` if for example telling everyone else in the server about changes to a peer.
24-
And forgetting to write `base.Write(writer);` and `base.Read(reader);`
27+
Also, forgetting to extend from `PacketServerPeerId` (if, for example, telling everyone else in the server about changes to a peer) is a common misake. Forgetting to write `base.Write(writer)` and `base.Read(reader)` in this case can also lead to problems.
28+
2529

2630
## Removing and adding a child in the same frame
27-
Adding and removing a child within the same frame almost always this leads to many errors (sometimes game crashing errors), and generally the work-a-around is to wait 1 idle_frame between removing and adding the child
31+
Adding and removing a child within the same frame almost always this leads to errors (sometimes game crashing errors). Generally, the workaround is to wait 1 idle_frame between removing and adding the child. Perhaps there is a better solution to what you are trying to do like re-assigning the parent of the child instead.
32+
2833

2934
## Changing the location of a script
30-
Do not change the location of a script inside vscode, instead do it inside Godot. Changing the location of the script in Godot will update the necessary references unlike in Vscode.
35+
If a script in Godot is attached to a node, do not change the location of the script inside VSCode, instead do it inside Godot. Changing the location of the script in Godot will update the necessary references whereas doing so in VSCode will not.
36+
3137

3238
## Renaming export node paths
33-
Generally a good idea to keep the script as close as you can to the NodePaths so when renaming nodes you won't have to worry about re-assigning the nodepaths.
39+
Generally, it's a good idea to keep the script as close as you can to the NodePaths so when renaming nodes you won't have to worry about re-assigning the nodepaths.
40+
3441

35-
## Host.Create(address, byte)
42+
## `Host.Create(address, byte)`
3643
Host.Create(address, byte) will always fail. Always do Host.Create(address, int) and don't even try casting from byte to int, it will fail. Client will not connect and you won't know why.

.github/CONTRIBUTING.md

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
# Contributing
2-
Contributions / pull requests are very much welcomed. If you want to help contribute, get the project running on your PC and see how everything works. My code isn't the best and it would be nice if others peer reviewed it pointing out things I could do better.
2+
Contributions and pull requests are very much welcomed. If you want to help contribute, get the project running on your PC and see how everything works. My code isn't the best and it would be nice if others peer reviewed it and pointed out things I could do better.
3+
4+
5+
> ⚠️ **IMPORTANT**: The whole project is being done from scratch on the [dev branch](https://github.com/GodotModules/GodotModulesCSharp/tree/dev).
6+
7+
8+
You can discuss about the project in the [Godot Modules Discord Server](https://discord.gg/866cg8yfxZ). If you have any questions, contact `valk#9904` though the server.
39

4-
[Godot Modules Discord](https://discord.gg/866cg8yfxZ) (if you have any questions, contact valk#9904 though here)
510

611
## Setup
12+
13+
714
### Godot Mono (C#)
815
1. Install [Godot Mono 64 Bit](https://godotengine.org)
916
2. Install [.NET SDK from this link](https://dotnet.microsoft.com/en-us/download)
1017
3. Install [.NET Framework 4.7.2](https://duckduckgo.com/?q=.net+framework+4.7.2)
1118
4. Launch Godot through [VSCode](#vscode)
12-
5. In Godot Editor > Editor Settings > Mono > Builds > Make sure `Build Tool` is set to `dotnet CLI`
13-
14-
If the startup scene is the main menu, the [game server](https://github.com/Raccoons-Rise-Up/server/blob/main/.github/CONTRIBUTING.md#setup) and [web server](https://github.com/Raccoons-Rise-Up/website/blob/main/.github/CONTRIBUTING.md) will need to be running to get past the login screen to the main game scene, otherwise you can change the startup scene to the main game scene by going to `Godot > Project Settings > Application > Run > Main Scene`.
19+
5. In `Godot Editor > Editor Settings > Mono > Builds`: Make sure `Build Tool` is set to `dotnet CLI`
1520

16-
[Common Mistakes](https://github.com/valkyrienyanko/GodotModules/blob/main/.github/COMMON_MISTAKES.md)
21+
The Godot startup scene should be set to `res://Scenes/Main.tscn`, if it is not then the game server and web server will not start and a lot of other code that needs to be initialized will not be initialized. To fix this go to `Godot > Project Settings > Application > Run > Main Scene` and set it to the main scene.
1722

1823
### VSCode
1924
VSCode is a UI friendly text editor for developers
@@ -26,14 +31,24 @@ VSCode is a UI friendly text editor for developers
2631
- [MoonSharp Debug](https://marketplace.visualstudio.com/items?itemName=xanathar.moonsharp-debug) (only if debugging lua)
2732
3. Launch Godot through VSCode by hitting `F1` to open up VSCode command and run `godot tools: open workspace with godot editor` or simply click the `Open Godot Editor` button bottom right
2833

29-
## Debugging C#
30-
Launch the VSCode configuration `Play in Editor` (if configuration is set to this already then just press `F5`)
34+
### GitHub
35+
1. Fork this repo
36+
2. Clone your fork with `git clone https://github.com/<USERNAME>/GodotModules` (replace `<USERNAME>` with your GitHub username)
37+
- *If you get `'git' is not recognized as an internal or external command` then install [Git scm](https://git-scm.com/downloads)*
38+
3. Extract the zip and open the folder in VSCode
39+
4. Go to the source control tab
40+
5. Click the 3 dots icon, click `Checkout to...`, switch to the `dev` branch
41+
- *If you want to see the netcode working in action then stay on `main`*
42+
6. All the files you make changes to should appear here as well, you can stage the files you want to commit, give the commit a message and then push it to your fork
43+
7. Once you have some commits on your fork, you can go [here](https://github.com/GodotModules/GodotModulesCSharp/pulls) and open up a new pull request and request to merge your work with the main repo
44+
45+
> ⚠️ Before committing anything please talk to `valk#9904` in the [Godot Modules Discord Server](https://discord.gg/866cg8yfxZ) so we can mitigate potential merge conflicts.
46+
47+
> Some development has been moved to a [separate repo](https://github.com/GodotModules/Sandbox) as it's nice to work with a clean environment and sometimes the main repo gets too messy in some areas. Once the code has been refined here, it will be merged back with the main repo.
48+
49+
> You can have a look at the projects roadmap [here](https://github.com/GodotModules/GodotModulesCSharp/issues/124).
3150
32-
## Debugging Lua
33-
While the C# debugger is running in the editor launch the VSCode configuration `MoonSharp Attach`
3451

35-
## Debugging Netcode
36-
Export a release of the game to a folder. Open cmd in this folder and run exe. Do again for another client.
52+
### [Useful Tips](https://github.com/GodotModules/GodotModulesCSharp/blob/main/.github/USEFUL_TIPS.md)
3753

38-
## Exporting
39-
Do not forget to copy enet.dll to exported release folder
54+
### [Common Mistakes](https://github.com/valkyrienyanko/GodotModules/blob/main/.github/COMMON_MISTAKES.md)

.github/NETCODE.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,3 @@ namespace GodotModules.Netcode
9090
Have a look at the other packets for more examples.
9191

9292
Consider size of data types when sending them over the network https://condor.depaul.edu/sjost/nwdp/notes/cs1/CSDatatypes.htm (the smaller the better but keep it practical)
93-
94-
- [x] Post created servers to [NodeJS web server](https://github.com/valkyrienyanko/GodotListServers) / fetch all servers

.github/USEFUL_TIPS.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Useful Tips
2+
3+
## Logging packet opcodes
4+
If you don't see the opcodes, these lines of code might be commented out. Feel free to un-comment them when debugging the netcode.
5+
6+
> ⚠️ Lobby packets have 2 opcodes, the first is the 'Lobby' opcode and the next is the lobby opcode type, e.g. 'LobbyJoin'. Perhaps this information should be logged too.
7+
8+
### Server packets
9+
https://github.com/GodotModules/GodotModulesCSharp/blob/4e1f6b20c99256a5ac2164b463412f64d87f942d/Scripts/Netcode/Server/GameServer.cs#L101-L103
10+
11+
### Client Packets
12+
https://github.com/GodotModules/GodotModulesCSharp/blob/4e1f6b20c99256a5ac2164b463412f64d87f942d/Scripts/Msc/GodotCommands.cs#L25-L30

.github/UTILITY_SCRIPTS.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
## Scripts
2+
### Notifications
3+
![image](https://user-images.githubusercontent.com/6277739/173916833-1e9caa62-62d5-4239-843e-7b28dfba5788.png)
4+
![image](https://user-images.githubusercontent.com/6277739/173916937-bc433fc0-c1e0-44c5-8a88-0cd3896a3f06.png)
5+
26
### Music Manager
37
```cs
48
// Load and play music
@@ -63,18 +67,42 @@ GameManager.Exit();
6367

6468
### Utils
6569
```cs
66-
"hello world".ToTitleCase(); // Hello World
70+
// string extensions
6771
"helloWorld".AddSpaceBeforeEachCapitol(); // hello World
6872
73+
"player_move_up".Replace("_", " ").ToTitleCase().SmallWordsToUpper(2, (word) => {
74+
var words = new string[] {"Up", "In"};
75+
return !words.Contains(word);
76+
}); // Player Move UP
77+
78+
// collection extensions
6979
var list = new List<int>{1,2,3};
7080
list.Print(); // 1, 2, 3
7181
7282
var dict = new Dictionary<int, int>{ {1,1}, {2,3} };
7383
dict.Print(); // 1 1, 2 3
7484
85+
// utils
7586
var someValue = 24f;
7687
someValue.Remap(0, 100, -40, 80); //remap someValue from range 0-100 to range -40-80
7788
89+
Vector2 newPos = Utils.Lerp(playerPos, targetPos, 0.1f);
90+
91+
Vector2 randomDir = Utils.RandomDir();
92+
enemy.Position = randomDir * 10;
93+
94+
myList.ForEach(x => x.DoSomething()); // functional programming with ForEach extension (do not abuse as hard to debug)
95+
96+
// timers
97+
var gTimer = new GTimer(this, nameof(Method)); // wrapper for Godot timer
98+
var sTimer = new STimer(action); // wrapper for System timer
99+
sTimer.Dispose();
100+
101+
// filters for LineEdit nodes with realtime feedback
102+
inputName.Filter((text) => text.IsMatch("^[A-Za-z ]+$"));
103+
inputPort.FilterRange(ushort.MaxValue);
104+
105+
// quick and dirty encryption
78106
var encryptedPassword = EncryptionHelper.Encrypt("epicPa55w0rd");
79107
var password = EncryptionHelper.Decrypt(encryptedPassword);
80108
```

README.md

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,100 @@
11
# Godot Modules
2-
## About
3-
A collection of useful modules and scripts for C# Godot games.
2+
[![](https://img.shields.io/github/forks/GodotModules/GodotModules?label=forks&logo=github&style=flat-square&color=purple)](https://github.com/GodotModules/GodotModulesCSharp/fork)
3+
[![](https://img.shields.io/static/v1?style=flat-square&logo=discord&logoColor=white&color=blue&label=discord&message=valks%20games)](https://discord.gg/866cg8yfxZ)
4+
5+
6+
[Godot Modules](https://github.com/GodotModules/GodotModulesCSharp) is a collection of useful modules and scripts writing [Godot](https://godotengine.org/) games in C#.
7+
8+
9+
## Table of Contents
10+
11+
- [Godot Modules](#godot-modules)
12+
- [Table of Contents](#table-of-contents)
13+
- [Why make this?](#why-make-this)
14+
- [Modules](#modules)
15+
- [Core](#core)
16+
- [ModLoader](#modloader)
17+
- [Netcode](#netcode)
18+
- [Tech Tree](#tech-tree)
19+
- [Helper Scripts](#helper-scripts)
20+
- [Contributing](#contributing)
21+
- [Credit](#credit)
22+
- [Programming](#programming)
23+
- [Testers](#testers)
424

525
## Why make this?
6-
I was thinking to myself, I want to make a bullet hell game, but I am also going to be making more then just one game in the future. I do not want to redo the same things over again. If I want multiplayer, I can just grab it from here. If I want a modloader, I can find it here. That is the motivation behind this project.
26+
I was thinking to myself, *I want to make a bullet hell game, but I am also going to be making more then just one game in the future*.
27+
28+
I do not want to redo the same things over again. If I want multiplayer, I can just grab it from here. If I want a modloader, I can find it here. If I want hotkeys, I can just get it from here. And so on.. That is the motivation behind this project!
29+
30+
> ⚠️ A lot of things showcased here are not on the main branch. Check out the main branch for a working multiplayer scenario and the dev branch for everything else. The main branch is where all the old code is at, dev branch is where all the latest and the greatest is at. Eventually the dev branch will be merged with the main branch.
31+
32+
![Menu](https://user-images.githubusercontent.com/6277739/176084227-c1f748bf-2cc0-4492-b132-b68f49ea1301.gif)
33+
Quick look at the menus
34+
35+
![Cat with sword](https://user-images.githubusercontent.com/6277739/176084038-5483a55f-5698-4dc3-8a9c-0d08b7257d7c.gif)
36+
Attack animation
37+
38+
![2DDungeon](https://user-images.githubusercontent.com/6277739/176084389-33209fb7-b793-47ba-827c-33aeff9a9381.gif)
39+
Dungeon environment
40+
41+
![inv](https://user-images.githubusercontent.com/6277739/176084833-ea29cf7b-f7ef-46ec-8b56-5531ec735b7c.gif)
42+
Working on a inventory
43+
44+
https://user-images.githubusercontent.com/6277739/176085117-7e61e96a-02ef-4f62-9aa0-c185abd94e90.mp4
45+
46+
Attempting to make a FPS
747

848
## Modules
49+
950
### Core
10-
In-game console on pressing F12, supports custom commands, useful for in-game testing / debugging.
51+
There is an in-game console (shown by pressing F12) that supports custom commands, useful for in-game testing and debugging.
1152

1253
![image](https://user-images.githubusercontent.com/6277739/166569933-de699808-6de9-4f7f-ac90-1a8ae460e262.png)
1354

14-
There are also popup error / message windows and the bottom right corner of the screen shows a small red box which notifies you of any errors with the total error count every second.
55+
There are also popup error and message windows. The bottom right corner of the screen shows a small red box which notifies you of any errors (along with the total error count every second).
56+
1557

1658
### [ModLoader](https://github.com/valkyrienyanko/GodotModules/blob/main/.github/MOD_LOADER.md)
17-
![image](https://user-images.githubusercontent.com/6277739/162651881-b8f98aa5-da2a-4499-b4dd-737a64dec4a9.png)
59+
60+
![image](https://user-images.githubusercontent.com/6277739/176084658-e5bbdf50-3569-484c-a3b1-3f123969b306.png)
61+
62+
1863

1964
### [Netcode](https://github.com/valkyrienyanko/GodotModules/blob/main/.github/NETCODE.md)
65+
2066
![image](https://user-images.githubusercontent.com/6277739/164528687-8ce3891f-2aa2-4c43-b9d2-404620aefad2.png)
67+
![image](https://user-images.githubusercontent.com/6277739/176084492-d642fac2-569b-4f0e-a14e-a02a6e95bd38.png)
2168
![image](https://user-images.githubusercontent.com/6277739/164519290-fcd96048-3267-4278-bbd9-34bd7c0a86c0.png)
2269
![image](https://user-images.githubusercontent.com/6277739/164519339-a23cc3be-29dd-4df8-ad3b-e975508f5ec8.png)
2370

2471
https://user-images.githubusercontent.com/6277739/165597959-cb42938a-d680-45ec-99f0-d2ba4495a534.mp4
2572

26-
### Tech Tree (coming soon)
73+
[Click here to see an attempt at trying to sync enemy physics with server and client](https://www.reddit.com/r/opensourcegames/comments/umbqn1/my_first_time_with_server_simulated_enemies_what/)
74+
75+
76+
### Tech Tree
2777
Tech tree where nodes in tree are positioned automatically via script
2878

29-
### Options
30-
![image](https://user-images.githubusercontent.com/6277739/163117944-e350b70c-aaaa-426f-8719-3c28648d5747.png)
79+
The code for this has not been merged to this repository yet and can be found [here](https://github.com/Raccoons-Rise-Up/client-godot/blob/main/Scripts/UI/UITechTreeResearch.cs)
80+
3181

3282
### [Helper Scripts](https://github.com/valkyrienyanko/GodotModules/blob/main/.github/UTILITY_SCRIPTS.md)
3383

84+
3485
## Contributing
3586
See [CONTRIBUTING.md](https://github.com/valkyrienyanko/GodotModules/blob/main/.github/CONTRIBUTING.md)
3687

88+
3789
## Credit
3890
Thank you to the following wonderful people who helped make this project become something even greater!
3991

92+
4093
### Programming
94+
- irj [[GitHub]](https://github.com/irj)
4195
- LazerGoat [[GitHub]](https://github.com/LazerGoat)
4296
- Scorpieth [[GitHub]](https://github.com/Scorpieth)
4397

98+
4499
### Testers
45100
- SCUDSTORM [[Twitch]](https://www.twitch.tv/perezdispenser)

0 commit comments

Comments
 (0)