WIP: Some stuff
This commit is contained in:
parent
396b28dba1
commit
0daaaac0f9
BIN
godot/assets/icons/home.svg
(Stored with Git LFS)
Normal file
BIN
godot/assets/icons/home.svg
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
godot/assets/icons/home.svg.import
(Stored with Git LFS)
Normal file
BIN
godot/assets/icons/home.svg.import
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
godot/assets/icons/settings.svg
(Stored with Git LFS)
Normal file
BIN
godot/assets/icons/settings.svg
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
godot/assets/icons/settings.svg.import
(Stored with Git LFS)
Normal file
BIN
godot/assets/icons/settings.svg.import
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
godot/assets/icons/web-window-xmark.svg
(Stored with Git LFS)
Normal file
BIN
godot/assets/icons/web-window-xmark.svg
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
godot/assets/icons/web-window-xmark.svg.import
(Stored with Git LFS)
Normal file
BIN
godot/assets/icons/web-window-xmark.svg.import
(Stored with Git LFS)
Normal file
Binary file not shown.
4
godot/examples/server_config/config.ini
Normal file
4
godot/examples/server_config/config.ini
Normal file
@ -0,0 +1,4 @@
|
||||
[main]
|
||||
starting_map="br_lowpoly"
|
||||
port=27015
|
||||
player_limit=10
|
1
godot/examples/server_config/map_list.txt
Normal file
1
godot/examples/server_config/map_list.txt
Normal file
@ -0,0 +1 @@
|
||||
lowpoly_tdm
|
@ -16,6 +16,12 @@ run/main_scene="res://src/entrypoint.tscn"
|
||||
config/features=PackedStringArray("4.3", "Forward Plus")
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
[autoload]
|
||||
|
||||
consts="*res://src/utils/consts.gd"
|
||||
helpers="*res://src/utils/functions.gd"
|
||||
logger="*res://src/utils/logger.gd"
|
||||
|
||||
[display]
|
||||
|
||||
window/size/mode=4
|
||||
|
@ -1,14 +1,21 @@
|
||||
extends EntryPoint
|
||||
class_name EntryPoint extends Node
|
||||
|
||||
|
||||
signal load_level(level: String)
|
||||
|
||||
func _on_load_level():
|
||||
pass
|
||||
# -- A path to the config file for setting up the dedicated server
|
||||
var config_file_path: String = ""
|
||||
|
||||
@export var main_menu: MainMenu = null
|
||||
@onready var main_menu: MainMenu = $MainMenu
|
||||
@onready var server: Server = $Server
|
||||
|
||||
# -- Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
parse_args()
|
||||
if OS.has_feature("dedicated_server") or DisplayServer.get_name() == "headless":
|
||||
main_menu.queue_free()
|
||||
var err := start_dedicated_server()
|
||||
if err != OK:
|
||||
push_error("Couldn't start the dedicated server, err: " + str(err))
|
||||
@ -16,6 +23,11 @@ func _ready() -> void:
|
||||
var err := start_game()
|
||||
if err != OK:
|
||||
push_error("Couldn't start the game, err: " + str(err))
|
||||
#load_level.connect(_on_load_level)
|
||||
main_menu.start_game.connect(start_server)
|
||||
|
||||
func start_server():
|
||||
server.start_server()
|
||||
|
||||
# -- Parse command line arguments
|
||||
func parse_args() -> void:
|
||||
@ -26,10 +38,16 @@ func parse_args() -> void:
|
||||
config_file_path = args[index + 1]
|
||||
|
||||
func start_dedicated_server() -> Error:
|
||||
push_error("Dedicated server is not yet implemented")
|
||||
return ERR_METHOD_NOT_FOUND
|
||||
# -- Build the server from the file
|
||||
var err := server.read_config_file(config_file_path)
|
||||
if err != OK:
|
||||
return err
|
||||
return OK
|
||||
|
||||
# -- When not dedicated server, just start the full game and load menu
|
||||
func start_game() -> Error:
|
||||
# -- Draw the main menu
|
||||
return OK
|
||||
|
||||
|
||||
func _on_main_menu_start_game() -> void:
|
||||
pass # Replace with function body.
|
||||
|
@ -1,18 +1,17 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://0hsqnr1kunv5"]
|
||||
[gd_scene load_steps=4 format=3 uid="uid://0hsqnr1kunv5"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/entrypoint.gd" id="1_ce80t"]
|
||||
[ext_resource type="Script" path="res://src/interfaces/main_menu/main_menu.gd" id="2_nmo60"]
|
||||
[ext_resource type="PackedScene" uid="uid://dt7rhpcor1wh7" path="res://src/interfaces/main_menu/main_menu.tscn" id="2_dd6gs"]
|
||||
[ext_resource type="PackedScene" uid="uid://dkvbrav2sgs7m" path="res://src/server/server.tscn" id="3_uv83k"]
|
||||
|
||||
[node name="Entrypoint" type="EntryPoint" node_paths=PackedStringArray("main_menu")]
|
||||
[node name="Entrypoint" type="EntryPoint"]
|
||||
script = ExtResource("1_ce80t")
|
||||
main_menu = NodePath("MainMenu")
|
||||
|
||||
[node name="LevelPlaceholder" type="Node3D" parent="."]
|
||||
editor_description = "This node should be used for storing the map that is currently loaded"
|
||||
|
||||
[node name="MainMenu" type="Control" parent="."]
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
script = ExtResource("2_nmo60")
|
||||
[node name="MainMenu" parent="." instance=ExtResource("2_dd6gs")]
|
||||
|
||||
[node name="Server" parent="." instance=ExtResource("3_uv83k")]
|
||||
|
||||
[connection signal="start_game" from="MainMenu" to="." method="_on_main_menu_start_game"]
|
||||
|
@ -1,11 +1,7 @@
|
||||
class_name MainMenu extends Control
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
signal start_game()
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
func _on_create_server_pressed() -> void:
|
||||
emit_signal("start_game")
|
||||
|
@ -1,6 +1,9 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dt7rhpcor1wh7"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://dt7rhpcor1wh7"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/interfaces/main_menu/main_menu.gd" id="1_dfg40"]
|
||||
[ext_resource type="Texture2D" uid="uid://dyymlervrwv87" path="res://assets/icons/home.svg" id="2_q7q32"]
|
||||
[ext_resource type="Texture2D" uid="uid://d0thk6bpmkkgo" path="res://assets/icons/settings.svg" id="3_7rsvq"]
|
||||
[ext_resource type="Texture2D" uid="uid://7pnrehlqgw0v" path="res://assets/icons/web-window-xmark.svg" id="4_svtqg"]
|
||||
|
||||
[node name="MainMenu" type="Control"]
|
||||
layout_mode = 3
|
||||
@ -9,4 +12,56 @@ anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
scale = Vector2(1.5, 1.5)
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
script = ExtResource("1_dfg40")
|
||||
|
||||
[node name="MainContainer" type="VBoxContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="MainButtonsRow" type="HBoxContainer" parent="MainContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 0
|
||||
|
||||
[node name="SystemButtons" type="HBoxContainer" parent="MainContainer/MainButtonsRow"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Home" type="Button" parent="MainContainer/MainButtonsRow/SystemButtons"]
|
||||
layout_mode = 2
|
||||
tooltip_text = "Show main menu"
|
||||
icon = ExtResource("2_q7q32")
|
||||
|
||||
[node name="Settings" type="Button" parent="MainContainer/MainButtonsRow/SystemButtons"]
|
||||
layout_mode = 2
|
||||
tooltip_text = "Settings"
|
||||
icon = ExtResource("3_7rsvq")
|
||||
|
||||
[node name="Exit" type="Button" parent="MainContainer/MainButtonsRow/SystemButtons"]
|
||||
layout_mode = 2
|
||||
tooltip_text = "Exit game"
|
||||
icon = ExtResource("4_svtqg")
|
||||
|
||||
[node name="MainButtons" type="HBoxContainer" parent="MainContainer/MainButtonsRow"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 4
|
||||
|
||||
[node name="Create Server" type="Button" parent="MainContainer/MainButtonsRow/MainButtons"]
|
||||
layout_mode = 2
|
||||
text = "Create server"
|
||||
|
||||
[node name="Join Server" type="Button" parent="MainContainer/MainButtonsRow/MainButtons"]
|
||||
layout_mode = 2
|
||||
text = "Join Server"
|
||||
|
||||
[node name="PlayContaner" type="HBoxContainer" parent="MainContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[connection signal="pressed" from="MainContainer/MainButtonsRow/MainButtons/Create Server" to="." method="_on_create_server_pressed"]
|
||||
|
27
godot/src/server/server.gd
Normal file
27
godot/src/server/server.gd
Normal file
@ -0,0 +1,27 @@
|
||||
class_name Server extends Node
|
||||
|
||||
# -- TODO: Server must have a list of maps instead of just one
|
||||
# var map_list_file_path: String = ""
|
||||
|
||||
@export var staring_map: String = ""
|
||||
var current_map_hash: String = ""
|
||||
|
||||
var port: int = 27015
|
||||
|
||||
@export var players: Dictionary = {}
|
||||
|
||||
func read_config_file(path: String) -> Error :
|
||||
var err : Error
|
||||
var config := ConfigFile.new()
|
||||
err = config.load("user://scores.cfg")
|
||||
if err != OK:
|
||||
return err
|
||||
staring_map = config.get_value("main", "staring_map", "br_lowpoly")
|
||||
port = int(config.get_value("main", "port", "27015"))
|
||||
|
||||
return OK
|
||||
|
||||
|
||||
func start_server() -> Error :
|
||||
print("Starting")
|
||||
return OK
|
6
godot/src/server/server.tscn
Normal file
6
godot/src/server/server.tscn
Normal file
@ -0,0 +1,6 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dkvbrav2sgs7m"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/server/server.gd" id="1_53ixn"]
|
||||
|
||||
[node name="Server" type="Node"]
|
||||
script = ExtResource("1_53ixn")
|
4
godot/src/utils/consts.gd
Normal file
4
godot/src/utils/consts.gd
Normal file
@ -0,0 +1,4 @@
|
||||
extends Node
|
||||
|
||||
const DEFAULT_JUMP_VELOCITY: float = 5
|
||||
const DEFAULT_CHARACTER_SPEED: float = 7.0
|
54
godot/src/utils/functions.gd
Normal file
54
godot/src/utils/functions.gd
Normal file
@ -0,0 +1,54 @@
|
||||
class_name Functions extends Node
|
||||
|
||||
|
||||
func get_root_node() -> EntryPoint:
|
||||
return get_tree().get_root().find_child("Entrypoint", true, false)
|
||||
|
||||
|
||||
#func get_server_node() -> ServerData:
|
||||
#return get_tree().get_root().find_child("ServerData", true, false)
|
||||
#
|
||||
#
|
||||
#func get_map_node() -> MapController:
|
||||
#return get_tree().get_root().find_child("Map", true, false)
|
||||
|
||||
|
||||
#func player_data_into_dict(player_data: PlayerData) -> Dictionary:
|
||||
#var result: Dictionary = {
|
||||
#"id": player_data.id,
|
||||
#"username": player_data.id,
|
||||
#"score": player_data.score,
|
||||
#"damage": player_data.damage,
|
||||
#"headshots": player_data.headshots,
|
||||
#"active": player_data.active
|
||||
#}
|
||||
#var side: String
|
||||
#match player_data.side:
|
||||
#-1:
|
||||
#side = PlayerData.underfined
|
||||
#0:
|
||||
#side = PlayerData.blue
|
||||
#1:
|
||||
#side = PlayerData.red
|
||||
#result["side"] = side
|
||||
#return result
|
||||
#
|
||||
#
|
||||
#func player_data_from_dict(player_data: Dictionary) -> PlayerData:
|
||||
#var result := PlayerData.new()
|
||||
#result.id = player_data.get("id")
|
||||
#result.username = player_data.get("username")
|
||||
#result.active = player_data.get("active")
|
||||
#result.damage = player_data.get("damage")
|
||||
#result.headshots = player_data.get("headshots")
|
||||
#result.score = player_data.get("score")
|
||||
#var side: int
|
||||
#match player_data.side:
|
||||
#"undefined":
|
||||
#side = -1
|
||||
#"attack":
|
||||
#side = 0
|
||||
#"defend":
|
||||
#side = 1
|
||||
#result.side = side
|
||||
#return result
|
54
godot/src/utils/logger.gd
Normal file
54
godot/src/utils/logger.gd
Normal file
@ -0,0 +1,54 @@
|
||||
extends Node
|
||||
class_name Logger
|
||||
|
||||
var thread: Thread = Thread.new()
|
||||
var mutex: Mutex = Mutex.new()
|
||||
var log_queue: Array[String] = []
|
||||
var running: bool = true
|
||||
|
||||
|
||||
func _ready():
|
||||
thread.start(log_writer)
|
||||
|
||||
|
||||
func info(msg: Variant):
|
||||
mutex.lock()
|
||||
log_queue.append("[color=white][b]INFO:[/b] [/color]" + msg)
|
||||
mutex.unlock()
|
||||
|
||||
|
||||
func debug(msg: Variant):
|
||||
mutex.lock()
|
||||
log_queue.append("[color=cyan][b]DEBUG:[/b] [/color]" + msg)
|
||||
mutex.unlock()
|
||||
|
||||
|
||||
func warning(msg: Variant):
|
||||
mutex.lock()
|
||||
log_queue.append("[color=yellow][b]WARN:[/b] [/color]" + msg)
|
||||
push_warning(msg)
|
||||
mutex.unlock()
|
||||
|
||||
|
||||
func error(msg: Variant):
|
||||
mutex.lock()
|
||||
log_queue.append("[color=red][b]ERROR:[/b] [/color]" + msg)
|
||||
push_error(msg)
|
||||
mutex.unlock()
|
||||
|
||||
|
||||
func log_writer():
|
||||
while running:
|
||||
mutex.lock()
|
||||
while log_queue.size() > 0:
|
||||
var log_message = log_queue.pop_front()
|
||||
print_rich(log_message)
|
||||
mutex.unlock()
|
||||
|
||||
# Prevent high CPU usage
|
||||
await get_tree().create_timer(0.1).timeout
|
||||
|
||||
|
||||
func _exit_tree():
|
||||
running = false
|
||||
thread.wait_to_finish()
|
@ -6,12 +6,12 @@ use std;
|
||||
#[class(base=Node)]
|
||||
// EntryPoint should decide whether the game should be launched in the
|
||||
// server or the playing mode and load corresponding resources
|
||||
struct EntryPoint {
|
||||
struct EntryPointRs {
|
||||
base: Base<Node>,
|
||||
}
|
||||
|
||||
#[godot_api]
|
||||
impl INode for EntryPoint {
|
||||
impl INode for EntryPointRs {
|
||||
fn init(base: Base<Node>) -> Self {
|
||||
Self { base }
|
||||
}
|
||||
@ -20,4 +20,4 @@ impl INode for EntryPoint {
|
||||
}
|
||||
|
||||
#[godot_api]
|
||||
impl EntryPoint {}
|
||||
impl EntryPointRs {}
|
||||
|
Loading…
Reference in New Issue
Block a user