generated from Persson-dev/Godot-Xmake
make world abstract
All checks were successful
Linux arm64 / Build (pull_request) Successful in 1m36s
All checks were successful
Linux arm64 / Build (pull_request) Successful in 1m36s
This commit is contained in:
7
godot/Scenes/Levels/client_world.tscn
Normal file
7
godot/Scenes/Levels/client_world.tscn
Normal file
@@ -0,0 +1,7 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://bqv0m8kbr300b"]
|
||||
|
||||
[ext_resource type="PackedScene" path="res://Scenes/Levels/world.tscn" id="1_ajsqk"]
|
||||
|
||||
[node name="World" type="ClientWorld"]
|
||||
|
||||
[node name="WorldContent" parent="." instance=ExtResource("1_ajsqk")]
|
||||
7
godot/Scenes/Levels/server_world.tscn
Normal file
7
godot/Scenes/Levels/server_world.tscn
Normal file
@@ -0,0 +1,7 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://c2p67anlxe3mk"]
|
||||
|
||||
[ext_resource type="PackedScene" path="res://Scenes/Levels/world.tscn" id="1_tecss"]
|
||||
|
||||
[node name="World" type="ServerWorld"]
|
||||
|
||||
[node name="WorldContent" parent="." instance=ExtResource("1_tecss")]
|
||||
@@ -1,12 +1,12 @@
|
||||
[gd_scene load_steps=17 format=3 uid="uid://coue2qehpn4fr"]
|
||||
[gd_scene load_steps=17 format=3 uid="uid://cl8gww414apoq"]
|
||||
|
||||
[ext_resource type="Texture2D" path="res://Assets/Textures/Sky.png" id="1_mnexj"]
|
||||
[ext_resource type="Texture2D" path="res://Assets/Textures/Black.png" id="2_fkwcn"]
|
||||
[ext_resource type="Texture2D" path="res://Assets/Textures/Orange.png" id="3_ux02w"]
|
||||
[ext_resource type="Texture2D" path="res://Assets/Textures/Green.png" id="4_wp15n"]
|
||||
[ext_resource type="Texture2D" path="res://Assets/Textures/Sky.png" id="1_tcyn8"]
|
||||
[ext_resource type="Texture2D" path="res://Assets/Textures/Black.png" id="2_j33w8"]
|
||||
[ext_resource type="Texture2D" path="res://Assets/Textures/Orange.png" id="3_n1lus"]
|
||||
[ext_resource type="Texture2D" path="res://Assets/Textures/Green.png" id="4_klpsf"]
|
||||
|
||||
[sub_resource type="PanoramaSkyMaterial" id="PanoramaSkyMaterial_6c4vd"]
|
||||
panorama = ExtResource("1_mnexj")
|
||||
panorama = ExtResource("1_tcyn8")
|
||||
|
||||
[sub_resource type="Sky" id="Sky_5ngqa"]
|
||||
sky_material = SubResource("PanoramaSkyMaterial_6c4vd")
|
||||
@@ -18,7 +18,7 @@ tonemap_mode = 2
|
||||
glow_enabled = true
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_ajchh"]
|
||||
albedo_texture = ExtResource("2_fkwcn")
|
||||
albedo_texture = ExtResource("2_j33w8")
|
||||
uv1_triplanar = true
|
||||
|
||||
[sub_resource type="PlaneMesh" id="PlaneMesh_mmup0"]
|
||||
@@ -29,7 +29,7 @@ size = Vector2(50, 50)
|
||||
data = PackedVector3Array(25, 0, 25, -25, 0, 25, 25, 0, -25, -25, 0, 25, -25, 0, -25, 25, 0, -25)
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_jkvud"]
|
||||
albedo_texture = ExtResource("3_ux02w")
|
||||
albedo_texture = ExtResource("3_n1lus")
|
||||
uv1_triplanar = true
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_plpqy"]
|
||||
@@ -44,13 +44,13 @@ left_to_right = -2.0
|
||||
size = Vector3(5, 5, 5)
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_pfpgv"]
|
||||
albedo_texture = ExtResource("4_wp15n")
|
||||
albedo_texture = ExtResource("4_klpsf")
|
||||
uv1_triplanar = true
|
||||
|
||||
[sub_resource type="ConcavePolygonShape3D" id="ConcavePolygonShape3D_rit6o"]
|
||||
data = PackedVector3Array(-12.5, 2.5, 2.5, 2.5, -2.5, 2.5, -2.5, -2.5, 2.5, -12.5, 2.5, -2.5, -2.5, -2.5, -2.5, 2.5, -2.5, -2.5, -12.5, 2.5, 2.5, -12.5, 2.5, -2.5, 2.5, -2.5, 2.5, -12.5, 2.5, -2.5, 2.5, -2.5, -2.5, 2.5, -2.5, 2.5, -12.5, 2.5, -2.5, -12.5, 2.5, 2.5, -2.5, -2.5, -2.5, -12.5, 2.5, 2.5, -2.5, -2.5, 2.5, -2.5, -2.5, -2.5, -2.5, -2.5, 2.5, 2.5, -2.5, 2.5, -2.5, -2.5, -2.5, 2.5, -2.5, 2.5, 2.5, -2.5, -2.5, -2.5, -2.5, -2.5)
|
||||
|
||||
[node name="World" type="World"]
|
||||
[node name="World" type="Node3D"]
|
||||
|
||||
[node name="WorldEnvironment" type="WorldEnvironment" parent="."]
|
||||
environment = SubResource("Environment_ctwiv")
|
||||
|
||||
@@ -8,5 +8,3 @@
|
||||
[node name="Network" parent="." instance=ExtResource("1_06ibn")]
|
||||
|
||||
[node name="MainMenu" parent="." instance=ExtResource("2_lavg1")]
|
||||
|
||||
[connection signal="change_scene" from="MainMenu" to="." method="change_scene"]
|
||||
|
||||
@@ -14,13 +14,12 @@ class World : public godot::Node3D, public protocol::PacketHandler {
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
World();
|
||||
~World();
|
||||
|
||||
public:
|
||||
// Godot overrides
|
||||
void _ready() override;
|
||||
void _process(float delta);
|
||||
|
||||
Player* GetPlayerById(PlayerID a_PlayerId);
|
||||
|
||||
@@ -28,7 +27,7 @@ class World : public godot::Node3D, public protocol::PacketHandler {
|
||||
void HandlePacket(const protocol::packets::PlayerLeave&) override;
|
||||
void HandlePacket(const protocol::packets::PlayerPositionAndRotation&) override;
|
||||
|
||||
private:
|
||||
protected:
|
||||
NetworkInterface* m_NetworkInterface;
|
||||
godot::Node* m_Players;
|
||||
float m_PassedTime;
|
||||
19
include/client/ClientWorld.h
Normal file
19
include/client/ClientWorld.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <blitz/godot/World.h>
|
||||
|
||||
namespace blitz {
|
||||
|
||||
class ClientWorld : public World {
|
||||
GDCLASS(ClientWorld, World)
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
ClientWorld();
|
||||
~ClientWorld();
|
||||
void _process(float delta);
|
||||
|
||||
private:
|
||||
void UpdatePlayerPos();
|
||||
};
|
||||
|
||||
} // namespace blitz
|
||||
@@ -13,7 +13,9 @@ class Main : public godot::Node {
|
||||
Main();
|
||||
~Main();
|
||||
|
||||
void ChangeScene();
|
||||
void _ready() override;
|
||||
|
||||
void ChangeScene(bool a_Server);
|
||||
};
|
||||
|
||||
} // namespace blitz
|
||||
19
include/server/ServerWorld.h
Normal file
19
include/server/ServerWorld.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <blitz/godot/World.h>
|
||||
|
||||
namespace blitz {
|
||||
|
||||
class ServerWorld : public World {
|
||||
GDCLASS(ServerWorld, World)
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
ServerWorld();
|
||||
~ServerWorld();
|
||||
void _process(float delta);
|
||||
|
||||
private:
|
||||
void SyncPlayersPos();
|
||||
};
|
||||
|
||||
} // namespace blitz
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <client/World.h>
|
||||
#include <blitz/godot/World.h>
|
||||
|
||||
#include <blitz/godot/NetworkInterface.h>
|
||||
#include <client/FirstPersonPlayer.h>
|
||||
@@ -44,37 +44,6 @@ World::~World() {
|
||||
m_NetworkInterface->UnregisterHandler(*this);
|
||||
}
|
||||
|
||||
void World::_process(float delta) {
|
||||
#if DEBUG_ENABLED
|
||||
if (Engine::get_singleton()->is_editor_hint())
|
||||
return;
|
||||
#endif
|
||||
m_PassedTime += delta;
|
||||
if (m_PassedTime < 0.05f)
|
||||
return;
|
||||
|
||||
// UtilityFunctions::print(m_PassedTime);
|
||||
|
||||
// m_PassedTime -= 0.05f;
|
||||
// if (m_PassedTime > 0.5f)
|
||||
// m_PassedTime = 0.0f;
|
||||
|
||||
if (get_multiplayer()->is_server()) {
|
||||
for (int i = 0; i < m_Players->get_child_count(); i++) {
|
||||
Player* player = Object::cast_to<Player>(m_Players->get_child(i));
|
||||
DEV_ASSERT(player);
|
||||
m_NetworkInterface->BroadcastPacket(
|
||||
protocol::packets::PlayerPositionAndRotation({player->GetId(), player->get_position(), player->GetCameraRotation()}));
|
||||
}
|
||||
} else {
|
||||
Player* player = GetPlayerById(get_multiplayer()->get_unique_id());
|
||||
if (player) {
|
||||
m_NetworkInterface->BroadcastPacket(protocol::packets::PlayerPositionAndRotation(
|
||||
{get_multiplayer()->get_unique_id(), player->get_position(), player->GetCameraRotation()}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Player* World::GetPlayerById(PlayerID a_PlayerId) {
|
||||
String stringId = UtilityFunctions::var_to_str(a_PlayerId);
|
||||
for (int i = 0; i < m_Players->get_child_count(); i++) {
|
||||
39
src/client/ClientWorld.cpp
Normal file
39
src/client/ClientWorld.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <client/ClientWorld.h>
|
||||
|
||||
#include <blitz/godot/NetworkInterface.h>
|
||||
#include <client/Player.h>
|
||||
#include <godot_cpp/classes/engine.hpp>
|
||||
#include <godot_cpp/classes/multiplayer_api.hpp>
|
||||
|
||||
namespace blitz {
|
||||
|
||||
using namespace godot;
|
||||
|
||||
void ClientWorld::_bind_methods() {}
|
||||
|
||||
ClientWorld::ClientWorld() {}
|
||||
|
||||
ClientWorld::~ClientWorld() {}
|
||||
|
||||
void ClientWorld::_process(float delta) {
|
||||
#if DEBUG_ENABLED
|
||||
if (Engine::get_singleton()->is_editor_hint())
|
||||
return;
|
||||
#endif
|
||||
m_PassedTime += delta;
|
||||
if (m_PassedTime < 0.05f)
|
||||
return;
|
||||
|
||||
|
||||
UpdatePlayerPos();
|
||||
}
|
||||
|
||||
void ClientWorld::UpdatePlayerPos() {
|
||||
Player* player = GetPlayerById(get_multiplayer()->get_unique_id());
|
||||
if (player) {
|
||||
m_NetworkInterface->BroadcastPacket(protocol::packets::PlayerPositionAndRotation(
|
||||
{get_multiplayer()->get_unique_id(), player->get_position(), player->GetCameraRotation()}));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace blitz
|
||||
@@ -7,26 +7,36 @@
|
||||
#include <godot_cpp/classes/window.hpp>
|
||||
#include <godot_cpp/variant/utility_functions.hpp>
|
||||
|
||||
#include <client/World.h>
|
||||
#include <client/ClientWorld.h>
|
||||
#include <server/ServerWorld.h>
|
||||
|
||||
using namespace godot;
|
||||
|
||||
namespace blitz {
|
||||
|
||||
static constexpr char MainScenePath[] = "res://Scenes/Levels/world.tscn";
|
||||
static constexpr char ClientWorldScenePath[] = "res://Scenes/Levels/client_world.tscn";
|
||||
static constexpr char ServerWorldScenePath[] = "res://Scenes/Levels/server_world.tscn";
|
||||
|
||||
void Main::_bind_methods() {
|
||||
godot::ClassDB::bind_method(godot::D_METHOD("change_scene"), &Main::ChangeScene);
|
||||
void Main::_bind_methods() {}
|
||||
|
||||
void Main::_ready() {
|
||||
auto* mainMenu = find_child("MainMenu");
|
||||
DEV_ASSERT(mainMenu);
|
||||
mainMenu->connect("change_scene_to_game", callable_mp(this, &Main::ChangeScene));
|
||||
}
|
||||
|
||||
Main::Main() {}
|
||||
|
||||
Main::~Main() {}
|
||||
|
||||
void Main::ChangeScene() {
|
||||
Ref<PackedScene> sceneData = ResourceLoader::get_singleton()->load(MainScenePath);
|
||||
World* world = Object::cast_to<World>(sceneData->instantiate());
|
||||
add_child(world);
|
||||
void Main::ChangeScene(bool a_Server) {
|
||||
Ref<PackedScene> sceneData;
|
||||
if (a_Server)
|
||||
sceneData = ResourceLoader::get_singleton()->load(ServerWorldScenePath);
|
||||
else
|
||||
sceneData = ResourceLoader::get_singleton()->load(ClientWorldScenePath);
|
||||
|
||||
add_child(sceneData->instantiate());
|
||||
}
|
||||
|
||||
} // namespace blitz
|
||||
@@ -1,5 +1,7 @@
|
||||
#include <client/MainMenu.h>
|
||||
|
||||
#include <godot_cpp/classes/engine.hpp>
|
||||
#include <godot_cpp/classes/multiplayer_api.hpp>
|
||||
#include <godot_cpp/classes/resource_loader.hpp>
|
||||
#include <godot_cpp/classes/scene_tree.hpp>
|
||||
|
||||
@@ -9,7 +11,7 @@ namespace blitz {
|
||||
|
||||
void MainMenu::_bind_methods() {
|
||||
godot::ClassDB::bind_method(godot::D_METHOD("on_connected"), &MainMenu::OnConnected);
|
||||
ADD_SIGNAL(MethodInfo("change_scene"));
|
||||
ADD_SIGNAL(MethodInfo("change_scene_to_game", PropertyInfo(Variant::BOOL, "server")));
|
||||
}
|
||||
|
||||
MainMenu::MainMenu() {}
|
||||
@@ -28,19 +30,22 @@ void MainMenu::_ready() {
|
||||
DEV_ASSERT(m_CreateButton);
|
||||
DEV_ASSERT(m_QuitButton);
|
||||
|
||||
m_NetworkInterface = Object::cast_to<NetworkInterface>(get_parent()->find_child("Network"));
|
||||
DEV_ASSERT(m_NetworkInterface);
|
||||
|
||||
m_JoinButton->connect("pressed", callable_mp(this, &MainMenu::OnJoinPressed));
|
||||
m_CreateButton->connect("pressed", callable_mp(this, &MainMenu::OnCreatePressed));
|
||||
m_QuitButton->connect("pressed", callable_mp(this, &MainMenu::OnQuitPressed));
|
||||
|
||||
|
||||
if (!Engine::get_singleton()->is_editor_hint()) {
|
||||
m_NetworkInterface = Object::cast_to<NetworkInterface>(get_parent()->find_child("Network"));
|
||||
DEV_ASSERT(m_NetworkInterface);
|
||||
|
||||
m_NetworkInterface->connect("local_player_connected", callable_mp(this, &MainMenu::OnConnected));
|
||||
m_NetworkInterface->connect("server_disconnected", callable_mp(this, &MainMenu::OnDisconnected));
|
||||
}
|
||||
}
|
||||
|
||||
void MainMenu::OnConnected() {
|
||||
emit_signal("change_scene");
|
||||
emit_signal("change_scene_to_game", get_multiplayer()->is_server());
|
||||
set_visible(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#include <blitz/godot/NetworkInterface.h>
|
||||
#include <client/ClientWorld.h>
|
||||
#include <client/FirstPersonPlayer.h>
|
||||
#include <client/Main.h>
|
||||
#include <client/MainMenu.h>
|
||||
#include <client/Player.h>
|
||||
#include <server/Server.h>
|
||||
#include <client/World.h>
|
||||
#include <server/ServerWorld.h>
|
||||
|
||||
#include <gdextension_interface.h>
|
||||
#include <godot_cpp/core/defs.hpp>
|
||||
@@ -16,10 +17,12 @@ static void RegisterClasses() {
|
||||
GDREGISTER_CLASS(blitz::Player);
|
||||
GDREGISTER_CLASS(blitz::FirstPersonPlayer);
|
||||
GDREGISTER_CLASS(blitz::MainMenu);
|
||||
GDREGISTER_CLASS(blitz::World);
|
||||
GDREGISTER_CLASS(blitz::Main);
|
||||
GDREGISTER_CLASS(blitz::NetworkInterface);
|
||||
GDREGISTER_CLASS(blitz::Server);
|
||||
GDREGISTER_ABSTRACT_CLASS(blitz::World);
|
||||
GDREGISTER_CLASS(blitz::ClientWorld);
|
||||
GDREGISTER_CLASS(blitz::ServerWorld);
|
||||
}
|
||||
|
||||
static void initialize_blitz_module(ModuleInitializationLevel p_level) {
|
||||
|
||||
38
src/server/ServerWorld.cpp
Normal file
38
src/server/ServerWorld.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <server/ServerWorld.h>
|
||||
|
||||
#include <blitz/godot/NetworkInterface.h>
|
||||
#include <client/Player.h>
|
||||
#include <godot_cpp/classes/engine.hpp>
|
||||
|
||||
namespace blitz {
|
||||
|
||||
using namespace godot;
|
||||
|
||||
void ServerWorld::_bind_methods() {}
|
||||
|
||||
ServerWorld::ServerWorld() {}
|
||||
|
||||
ServerWorld::~ServerWorld() {}
|
||||
|
||||
void ServerWorld::_process(float delta) {
|
||||
#if DEBUG_ENABLED
|
||||
if (Engine::get_singleton()->is_editor_hint())
|
||||
return;
|
||||
#endif
|
||||
m_PassedTime += delta;
|
||||
if (m_PassedTime < 0.05f)
|
||||
return;
|
||||
|
||||
SyncPlayersPos();
|
||||
}
|
||||
|
||||
void ServerWorld::SyncPlayersPos() {
|
||||
for (int i = 0; i < m_Players->get_child_count(); i++) {
|
||||
Player* player = Object::cast_to<Player>(m_Players->get_child(i));
|
||||
DEV_ASSERT(player);
|
||||
m_NetworkInterface->BroadcastPacket(
|
||||
protocol::packets::PlayerPositionAndRotation({player->GetId(), player->get_position(), player->GetCameraRotation()}));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace blitz
|
||||
Reference in New Issue
Block a user