Headless server should do less unnecessary work now, also tracking host and display concerns should be consistent now. Also redid movement so that balance radius can be calculated easily.
This commit is contained in:
parent
b0e5e89126
commit
be986c1d26
3
globals.gd
Normal file
3
globals.gd
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
extends Node
|
||||||
|
|
||||||
|
var multiplayer_type=0
|
1
globals.gd.uid
Normal file
1
globals.gd.uid
Normal file
@ -0,0 +1 @@
|
|||||||
|
uid://b8o32xf6kknhu
|
5
lobby.gd
5
lobby.gd
@ -25,7 +25,7 @@ func start(id,given_name):
|
|||||||
func add_player(pid):
|
func add_player(pid):
|
||||||
players[pid]={}
|
players[pid]={}
|
||||||
var a
|
var a
|
||||||
if multiplayer.get_unique_id()==1:
|
if Globals.multiplayer_type&1: # hosting
|
||||||
a=PLAYER_SCENE.instantiate()
|
a=PLAYER_SCENE.instantiate()
|
||||||
a.name=str(pid)
|
a.name=str(pid)
|
||||||
$fuck_layouts/player_list.add_child(a)
|
$fuck_layouts/player_list.add_child(a)
|
||||||
@ -50,6 +50,7 @@ func _on_send_message_pressed(message=""):
|
|||||||
|
|
||||||
@rpc("any_peer","call_local")
|
@rpc("any_peer","call_local")
|
||||||
func receive_message(pid,message):
|
func receive_message(pid,message):
|
||||||
|
if !Globals.multiplayer_type&2: return # displaying
|
||||||
var a=Label.new()
|
var a=Label.new()
|
||||||
a.text=str(pid)+": "+message
|
a.text=str(pid)+": "+message
|
||||||
var scroll=$fuck_layouts/menu_shiz/chats/elder
|
var scroll=$fuck_layouts/menu_shiz/chats/elder
|
||||||
@ -75,7 +76,7 @@ func _start_clicked():
|
|||||||
|
|
||||||
@rpc("any_peer","call_local")
|
@rpc("any_peer","call_local")
|
||||||
func gamestart(players):
|
func gamestart(players):
|
||||||
emit_signal('game_start',players)
|
emit_signal('game_start',players,Globals.multiplayer_type)
|
||||||
hide()
|
hide()
|
||||||
|
|
||||||
func _idk_clicked():
|
func _idk_clicked():
|
||||||
|
13
menu.gd
13
menu.gd
@ -14,9 +14,11 @@ func _ready():
|
|||||||
if DisplayServer.get_name() == "headless":
|
if DisplayServer.get_name() == "headless":
|
||||||
# Should attempt to pull port from config file
|
# Should attempt to pull port from config file
|
||||||
print("Automatically starting dedicated server.")
|
print("Automatically starting dedicated server.")
|
||||||
_on_host_pressed.call_deferred(true)
|
_on_host_pressed.call_deferred()
|
||||||
|
else:
|
||||||
|
Globals.multiplayer_type|=2 # displaying
|
||||||
|
|
||||||
func _on_host_pressed(headless=false):
|
func _on_host_pressed():
|
||||||
# Start as server.
|
# Start as server.
|
||||||
var peer = ENetMultiplayerPeer.new()
|
var peer = ENetMultiplayerPeer.new()
|
||||||
var port = $Net/Options/port.text
|
var port = $Net/Options/port.text
|
||||||
@ -25,8 +27,9 @@ func _on_host_pressed(headless=false):
|
|||||||
if peer.get_connection_status() == MultiplayerPeer.CONNECTION_DISCONNECTED:
|
if peer.get_connection_status() == MultiplayerPeer.CONNECTION_DISCONNECTED:
|
||||||
OS.alert("Failed to start multiplayer server.")
|
OS.alert("Failed to start multiplayer server.")
|
||||||
return
|
return
|
||||||
|
Globals.multiplayer_type|=1 # hosting
|
||||||
multiplayer.multiplayer_peer = peer
|
multiplayer.multiplayer_peer = peer
|
||||||
start_game(headless)
|
start_game()
|
||||||
|
|
||||||
func _on_join_pressed():
|
func _on_join_pressed():
|
||||||
# Start as client.
|
# Start as client.
|
||||||
@ -44,7 +47,7 @@ func _on_join_pressed():
|
|||||||
multiplayer.multiplayer_peer = peer
|
multiplayer.multiplayer_peer = peer
|
||||||
start_game() # Can't run a headless client lol what are you trying to bot the game
|
start_game() # Can't run a headless client lol what are you trying to bot the game
|
||||||
|
|
||||||
func start_game(headless=false):
|
func start_game():
|
||||||
if headless: return
|
if !Globals.multiplayer_type&2: return # displaying
|
||||||
emit_signal("lobby_join",multiplayer.get_unique_id(),$Net/pname/Name.text)
|
emit_signal("lobby_join",multiplayer.get_unique_id(),$Net/pname/Name.text)
|
||||||
hide()
|
hide()
|
||||||
|
@ -15,6 +15,10 @@ run/main_scene="res://ui.tscn"
|
|||||||
config/features=PackedStringArray("4.4", "GL Compatibility")
|
config/features=PackedStringArray("4.4", "GL Compatibility")
|
||||||
config/icon="res://icon.svg"
|
config/icon="res://icon.svg"
|
||||||
|
|
||||||
|
[autoload]
|
||||||
|
|
||||||
|
Globals="*res://globals.gd"
|
||||||
|
|
||||||
[dotnet]
|
[dotnet]
|
||||||
|
|
||||||
project/assembly_name="net-test"
|
project/assembly_name="net-test"
|
||||||
|
@ -19,10 +19,11 @@ Game::Game()
|
|||||||
}
|
}
|
||||||
Game::~Game(){}
|
Game::~Game(){}
|
||||||
|
|
||||||
void Game::start(const Dictionary &players)
|
void Game::start(const Dictionary &players, const int p_multiplayer_type)
|
||||||
{
|
{
|
||||||
show();
|
multiplayer_type=p_multiplayer_type;
|
||||||
if (get_multiplayer()->get_unique_id()!=1) return;
|
if (multiplayer_type&2) show(); // displaying
|
||||||
|
if (!(multiplayer_type&1)) return; // hosting
|
||||||
Array keys=players.keys();
|
Array keys=players.keys();
|
||||||
for (int i=0; i<keys.size(); i++)
|
for (int i=0; i<keys.size(); i++)
|
||||||
{
|
{
|
||||||
@ -40,6 +41,6 @@ Node* Game::kyaraspawn(const Variant &data)
|
|||||||
kya->set_name(dat["name"]);
|
kya->set_name(dat["name"]);
|
||||||
kya->multiplayerowner=dat["pid"];
|
kya->multiplayerowner=dat["pid"];
|
||||||
kya->set_position(Vector2(50,50));
|
kya->set_position(Vector2(50,50));
|
||||||
kya->set_texture(ImageTexture::create_from_image(Image::load_from_file("res://icon.svg")));
|
if (multiplayer_type&2) kya->set_texture(ResourceLoader::get_singleton()->load("res://icon.svg")); // displaying
|
||||||
return kya;
|
return kya;
|
||||||
}
|
}
|
@ -6,8 +6,7 @@
|
|||||||
#include "kyara.h"
|
#include "kyara.h"
|
||||||
#include <godot_cpp/classes/multiplayer_api.hpp>
|
#include <godot_cpp/classes/multiplayer_api.hpp>
|
||||||
#include <godot_cpp/classes/multiplayer_spawner.hpp>
|
#include <godot_cpp/classes/multiplayer_spawner.hpp>
|
||||||
#include <godot_cpp/classes/image_texture.hpp>
|
#include <godot_cpp/classes/resource_loader.hpp>
|
||||||
#include <godot_cpp/classes/image.hpp>
|
|
||||||
|
|
||||||
namespace godot
|
namespace godot
|
||||||
{
|
{
|
||||||
@ -15,13 +14,14 @@ class Game : public Node2D
|
|||||||
{
|
{
|
||||||
GDCLASS(Game, Node2D)
|
GDCLASS(Game, Node2D)
|
||||||
private:
|
private:
|
||||||
|
int multiplayer_type;
|
||||||
MultiplayerSpawner *spawn;
|
MultiplayerSpawner *spawn;
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
public:
|
public:
|
||||||
Game();
|
Game();
|
||||||
~Game();
|
~Game();
|
||||||
void start(const Dictionary &players);
|
void start(const Dictionary &players, const int p_multiplayer_type);
|
||||||
Node* kyaraspawn(const Variant &data);
|
Node* kyaraspawn(const Variant &data);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@ Character::Character()
|
|||||||
set_motion_mode(MOTION_MODE_FLOATING);
|
set_motion_mode(MOTION_MODE_FLOATING);
|
||||||
speed=1.0;
|
speed=1.0;
|
||||||
balance_radius=64.0;
|
balance_radius=64.0;
|
||||||
|
balance_radius_cur=8.0;
|
||||||
face=memnew(Sprite2D);
|
face=memnew(Sprite2D);
|
||||||
face->set_name("_face");
|
face->set_name("_face");
|
||||||
add_child(face,false,INTERNAL_MODE_BACK);
|
add_child(face,false,INTERNAL_MODE_BACK);
|
||||||
@ -42,10 +43,9 @@ Character::~Character(){}
|
|||||||
void Character::_process(double delta)
|
void Character::_process(double delta)
|
||||||
{
|
{
|
||||||
// これも嫌い
|
// これも嫌い
|
||||||
if (input->flags&1) move(0.0,-speed);
|
balance_radius_cur-=3.0;
|
||||||
if (input->flags&2) move(0.0,speed);
|
balance_radius_cur=godot::Math::max(balance_radius_cur,8.0);
|
||||||
if (input->flags&4) move(-speed,0.0);
|
move(input->flags);
|
||||||
if (input->flags&8) move(speed,0.0);
|
|
||||||
look_at(input->target);
|
look_at(input->target);
|
||||||
// Not sure if I should do this. Issues could occur if I'm wrong either side.
|
// Not sure if I should do this. Issues could occur if I'm wrong either side.
|
||||||
//CharacterBody2D::_process(delta);
|
//CharacterBody2D::_process(delta);
|
||||||
@ -65,9 +65,15 @@ void Character::_enter_tree()
|
|||||||
input->set_multiplayer_authority(multiplayerowner);
|
input->set_multiplayer_authority(multiplayerowner);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Character::move(double x,double y)
|
void Character::move(int flags)
|
||||||
{
|
{
|
||||||
// Collision detection needs to go in here, as well as adjusting and displaying balance radius, buncha shit
|
if (!flags) return;
|
||||||
|
// Collision detection needs to go in here, buncha shit
|
||||||
|
balance_radius_cur+=6.0;
|
||||||
|
balance_radius_cur=godot::Math::min(balance_radius_cur,balance_radius);
|
||||||
|
double x=speed*(((flags&8)>>3)-((flags&4)>>2));
|
||||||
|
double y=speed*(((flags&2)>>1)-((flags&1)>>0));
|
||||||
|
// Very C
|
||||||
set_position(get_position()+Vector2(x,y));
|
set_position(get_position()+Vector2(x,y));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,8 @@ class Character : public CharacterBody2D
|
|||||||
private:
|
private:
|
||||||
double speed;
|
double speed;
|
||||||
double balance_radius;
|
double balance_radius;
|
||||||
void move(double x,double y);
|
double balance_radius_cur;
|
||||||
|
void move(int flags);
|
||||||
Sprite2D *face;
|
Sprite2D *face;
|
||||||
Controller *input;
|
Controller *input;
|
||||||
MultiplayerSynchronizer *sync;
|
MultiplayerSynchronizer *sync;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include "kyara.h"
|
#include "kyara.h"
|
||||||
#include "controller.h"
|
#include "controller.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include "nodespawner.h"
|
//#include "nodespawner.h"
|
||||||
#include <gdextension_interface.h>
|
#include <gdextension_interface.h>
|
||||||
#include <godot_cpp/core/defs.hpp>
|
#include <godot_cpp/core/defs.hpp>
|
||||||
#include <godot_cpp/godot.hpp>
|
#include <godot_cpp/godot.hpp>
|
||||||
@ -15,7 +15,7 @@ void initialize_character_module(ModuleInitializationLevel p_level)
|
|||||||
GDREGISTER_RUNTIME_CLASS(Character);
|
GDREGISTER_RUNTIME_CLASS(Character);
|
||||||
GDREGISTER_RUNTIME_CLASS(Controller);
|
GDREGISTER_RUNTIME_CLASS(Controller);
|
||||||
GDREGISTER_RUNTIME_CLASS(Game);
|
GDREGISTER_RUNTIME_CLASS(Game);
|
||||||
GDREGISTER_RUNTIME_CLASS(NodeSpawner);
|
// GDREGISTER_RUNTIME_CLASS(NodeSpawner);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uninitialize_character_module(ModuleInitializationLevel p_level) {
|
void uninitialize_character_module(ModuleInitializationLevel p_level) {
|
||||||
|
1
ui.tscn
1
ui.tscn
@ -139,6 +139,7 @@ _spawnable_scenes = PackedStringArray("uid://b25q27admm4le")
|
|||||||
spawn_path = NodePath("..")
|
spawn_path = NodePath("..")
|
||||||
|
|
||||||
[node name="Game" type="Game" parent="."]
|
[node name="Game" type="Game" parent="."]
|
||||||
|
visible = false
|
||||||
|
|
||||||
[connection signal="lobby_join" from="main_menu" to="Lobby" method="start"]
|
[connection signal="lobby_join" from="main_menu" to="Lobby" method="start"]
|
||||||
[connection signal="pressed" from="main_menu/Net/buttons/Host" to="main_menu" method="_on_host_pressed"]
|
[connection signal="pressed" from="main_menu/Net/buttons/Host" to="main_menu" method="_on_host_pressed"]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user