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:
2025-07-07 08:27:29 +10:00
parent b0e5e89126
commit be986c1d26
13 changed files with 44 additions and 23 deletions

View File

@@ -19,10 +19,11 @@ Game::Game()
}
Game::~Game(){}
void Game::start(const Dictionary &players)
void Game::start(const Dictionary &players, const int p_multiplayer_type)
{
show();
if (get_multiplayer()->get_unique_id()!=1) return;
multiplayer_type=p_multiplayer_type;
if (multiplayer_type&2) show(); // displaying
if (!(multiplayer_type&1)) return; // hosting
Array keys=players.keys();
for (int i=0; i<keys.size(); i++)
{
@@ -40,6 +41,6 @@ Node* Game::kyaraspawn(const Variant &data)
kya->set_name(dat["name"]);
kya->multiplayerowner=dat["pid"];
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;
}

View File

@@ -6,8 +6,7 @@
#include "kyara.h"
#include <godot_cpp/classes/multiplayer_api.hpp>
#include <godot_cpp/classes/multiplayer_spawner.hpp>
#include <godot_cpp/classes/image_texture.hpp>
#include <godot_cpp/classes/image.hpp>
#include <godot_cpp/classes/resource_loader.hpp>
namespace godot
{
@@ -15,13 +14,14 @@ class Game : public Node2D
{
GDCLASS(Game, Node2D)
private:
int multiplayer_type;
MultiplayerSpawner *spawn;
protected:
static void _bind_methods();
public:
Game();
~Game();
void start(const Dictionary &players);
void start(const Dictionary &players, const int p_multiplayer_type);
Node* kyaraspawn(const Variant &data);
};
}

View File

@@ -23,6 +23,7 @@ Character::Character()
set_motion_mode(MOTION_MODE_FLOATING);
speed=1.0;
balance_radius=64.0;
balance_radius_cur=8.0;
face=memnew(Sprite2D);
face->set_name("_face");
add_child(face,false,INTERNAL_MODE_BACK);
@@ -42,10 +43,9 @@ Character::~Character(){}
void Character::_process(double delta)
{
// これも嫌い
if (input->flags&1) move(0.0,-speed);
if (input->flags&2) move(0.0,speed);
if (input->flags&4) move(-speed,0.0);
if (input->flags&8) move(speed,0.0);
balance_radius_cur-=3.0;
balance_radius_cur=godot::Math::max(balance_radius_cur,8.0);
move(input->flags);
look_at(input->target);
// Not sure if I should do this. Issues could occur if I'm wrong either side.
//CharacterBody2D::_process(delta);
@@ -65,9 +65,15 @@ void Character::_enter_tree()
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));
}

View File

@@ -21,7 +21,8 @@ class Character : public CharacterBody2D
private:
double speed;
double balance_radius;
void move(double x,double y);
double balance_radius_cur;
void move(int flags);
Sprite2D *face;
Controller *input;
MultiplayerSynchronizer *sync;

View File

@@ -2,7 +2,7 @@
#include "kyara.h"
#include "controller.h"
#include "game.h"
#include "nodespawner.h"
//#include "nodespawner.h"
#include <gdextension_interface.h>
#include <godot_cpp/core/defs.hpp>
#include <godot_cpp/godot.hpp>
@@ -15,7 +15,7 @@ void initialize_character_module(ModuleInitializationLevel p_level)
GDREGISTER_RUNTIME_CLASS(Character);
GDREGISTER_RUNTIME_CLASS(Controller);
GDREGISTER_RUNTIME_CLASS(Game);
GDREGISTER_RUNTIME_CLASS(NodeSpawner);
// GDREGISTER_RUNTIME_CLASS(NodeSpawner);
}
void uninitialize_character_module(ModuleInitializationLevel p_level) {