adding step to store message received (use to synchronize)

This commit is contained in:
AleaJactaEst 2020-04-02 21:07:38 +02:00
parent 0e1db657d6
commit e40e7de052
5 changed files with 156 additions and 104 deletions

View file

@ -6,49 +6,49 @@
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
pass # Replace with function body. pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta): #func _process(delta):
# pass # pass
func test_resize(): func test_resize():
#var bitset = preload("res://bitset.gdns").new() #var bitset = preload("res://bitset.gdns").new()
var bitset = BitSet.new() var bitset = BitSet.new()
print ("[bitset:test_resize]") print ("[bitset:test_resize]")
bitset.resize(1024) bitset.resize(1024)
func test_write(): func test_write():
#var bitset = preload("res://bitset.gdns").new() #var bitset = preload("res://bitset.gdns").new()
var bitset = BitSet.new() var bitset = BitSet.new()
print ("[bitset:test_put]") print ("[bitset:test_put]")
bitset.resize(1024) bitset.resize(1024)
#print ("[bitset:test_put] " + bitset.show()) print ("[bitset:test_put] " + bitset.show())
assert( bitset.show() == "0000000000000000000000000000010000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") assert( bitset.show() == "0000000000000000000000000000010000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
bitset.write(1, 1) bitset.write(1, 1)
#print ("[bitset:test_put] " + bitset.show()) print ("[bitset:test_put] " + bitset.show())
assert( bitset.show() == "0000000000000000000000000000010000000000000000000000000000000000001000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") assert( bitset.show() == "0000000000000000000000000000010000000000000000000000000000000000001000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
bitset.write(2, 1) bitset.write(2, 1)
#print ("[bitset:test_put] " + bitset.show()) print ("[bitset:test_put] " + bitset.show())
assert( bitset.show() == "0000000000000000000000000000010000000000000000000000000000000000001000000000000000000000000000000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") assert( bitset.show() == "0000000000000000000000000000010000000000000000000000000000000000001000000000000000000000000000000000011000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
bitset.write(1, 0) bitset.write(1, 0)
#print ("[bitset:test_put] " + bitset.show()) print ("[bitset:test_put] " + bitset.show())
assert( bitset.show() == "0000000000000000000000000000010000000000000000000000000000000000001000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") assert( bitset.show() == "0000000000000000000000000000010000000000000000000000000000000000001000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
func test_alloc(): func test_alloc():
#var BitSet = preload("res://bitset.gdns") #var BitSet = preload("res://bitset.gdns")
print ("[bitset:test_alloc]") print ("[bitset:test_alloc]")
var tab = {} var tab = {}
tab[1478] = BitSet.new() tab[1478] = BitSet.new()
assert( tab.size() == 1 ) assert( tab.size() == 1 )
tab[1479] = BitSet.new() tab[1479] = BitSet.new()
assert( tab.size() == 2 ) assert( tab.size() == 2 )
tab.erase(1478) tab.erase(1478)
assert( tab.size() == 1 ) assert( tab.size() == 1 )
func test(): func test():
print("[bitset] Start check -> start") print("[bitset] Start check -> start")
test_resize() test_resize()
test_write() test_write()
test_alloc() test_alloc()
print("[bitset] Start check -> end") print("[bitset] Start check -> end")

View file

@ -4,96 +4,96 @@ signal character_creation_finished
func _ready(): func _ready():
$login_menu.show() $login_menu.show()
self.connect( "character_creation_finished", global, "_on_login_scene_character_creation_finished" ) self.connect( "character_creation_finished", global, "_on_login_scene_character_creation_finished" )
global.get_node( "audio_stream_player" ).stream = load( "res://assets/musics/pre-mix_menu_pantin_remake.ogg" ) global.get_node( "audio_stream_player" ).stream = load( "res://assets/musics/pre-mix_menu_pantin_remake.ogg" )
global.get_node( "audio_stream_player" ).play() global.get_node( "audio_stream_player" ).play()
$login_menu.show() $login_menu.show()
$register_menu.hide() $register_menu.hide()
$license_menu.hide() $license_menu.hide()
$settings_menu.hide() $settings_menu.hide()
func _on_login_menu_login_button_pressed(): func _on_login_menu_login_button_pressed():
print("[login_scene] Launch game") print("[login_scene] Launch game")
$login_menu.hide() $login_menu.hide()
$character_selection_menu.show() $character_selection_menu.show()
func _on_character_selection_menu_return_button_pressed(): func _on_character_selection_menu_return_button_pressed():
$login_menu.show() $login_menu.show()
$character_selection_menu.hide() $character_selection_menu.hide()
func _on_character_selection_menu_character_selected( slot ): func _on_character_selection_menu_character_selected( slot ):
var config_file = ConfigFile.new() var config_file = ConfigFile.new()
var err = config_file.load( "user://player.cfg" ) var err = config_file.load( "user://player.cfg" )
if err: if err:
print("Error code when loading player config file player.cfg: ", err) print("Error code when loading player config file player.cfg: ", err)
character.slot = slot character.slot = slot
character.pseudo = config_file.get_value( str(slot), "name", "player" ) character.pseudo = config_file.get_value( str(slot), "name", "player" )
character.gender = config_file.get_value( str(slot), "gender", 1 ) character.gender = config_file.get_value( str(slot), "gender", 1 )
character.color = config_file.get_value( str(slot), "color", Color(1.0, 0.25, 0.25, 1.0) ) character.color = config_file.get_value( str(slot), "color", Color(1.0, 0.25, 0.25, 1.0) )
character.size = config_file.get_value( str(slot), "size", 1.0 ) character.size = config_file.get_value( str(slot), "size", 1.0 )
character.ears_size = config_file.get_value( str(slot), "ears_size", 0.0 ) character.ears_size = config_file.get_value( str(slot), "ears_size", 0.0 )
character.eyes_color = config_file.get_value( str(slot), "eyes_color", Color( 0.0, 1.0, 0.0, 1.0 ) ) character.eyes_color = config_file.get_value( str(slot), "eyes_color", Color( 0.0, 1.0, 0.0, 1.0 ) )
character.update() character.update()
emit_signal( "character_creation_finished" ) emit_signal( "character_creation_finished" )
func _on_quit_button_pressed(): func _on_quit_button_pressed():
print("[login_scene:_on_quit_button_pressed] Stop application") print("[login_scene:_on_quit_button_pressed] Stop application")
net_low_level.disconnect_server() net_low_level.disconnect_server()
self.get_tree().quit() self.get_tree().quit()
func _on_sound_button_toggled(button_pressed): func _on_sound_button_toggled(button_pressed):
if button_pressed: if button_pressed:
global.get_node( "audio_stream_player" ).stop() global.get_node( "audio_stream_player" ).stop()
else: else:
global.get_node( "audio_stream_player" ).play() global.get_node( "audio_stream_player" ).play()
func _on_login_menu_register_button_pressed(): func _on_login_menu_register_button_pressed():
$login_menu.hide() $login_menu.hide()
$register_menu.show() $register_menu.show()
$license_menu.hide() $license_menu.hide()
$settings_menu.hide() $settings_menu.hide()
func _on_register_menu_cancel_button_pressed(): func _on_register_menu_cancel_button_pressed():
$login_menu.show() $login_menu.show()
$register_menu.hide() $register_menu.hide()
$license_menu.hide() $license_menu.hide()
$settings_menu.hide() $settings_menu.hide()
func _on_register_menu_license_button_pressed(): func _on_register_menu_license_button_pressed():
$login_menu.hide() $login_menu.hide()
$register_menu.hide() $register_menu.hide()
$license_menu.show() $license_menu.show()
$settings_menu.hide() $settings_menu.hide()
func _on_license_menu_return_button_pressed(): func _on_license_menu_return_button_pressed():
$login_menu.hide() $login_menu.hide()
$register_menu.show() $register_menu.show()
$license_menu.hide() $license_menu.hide()
$settings_menu.hide() $settings_menu.hide()
func _on_register_menu_register_account_created(): func _on_register_menu_register_account_created():
$login_menu.show() $login_menu.show()
$register_menu.hide() $register_menu.hide()
$license_menu.hide() $license_menu.hide()
$settings_menu.hide() $settings_menu.hide()
func _on_Settings_menu_return_pressed(): func _on_Settings_menu_return_pressed():
$login_menu.show() $login_menu.show()
$register_menu.hide() $register_menu.hide()
$license_menu.hide() $license_menu.hide()
$settings_menu.hide() $settings_menu.hide()
func _on_settings_button_pressed(): func _on_settings_button_pressed():
$login_menu.hide() $login_menu.hide()
$register_menu.hide() $register_menu.hide()
$license_menu.hide() $license_menu.hide()
$settings_menu.load_settings() $settings_menu.load_settings()
$settings_menu.show() $settings_menu.show()

View file

@ -63,12 +63,13 @@ int BitSet::size()
{ {
return this->_size_byte; return this->_size_byte;
} }
#include "core/os/os.h"
void BitSet::resize(uint32_t num_bits) void BitSet::resize(uint32_t num_bits)
{ {
uint32_t n_last_bits; uint32_t n_last_bits;
uint32_t new_size_byte = (num_bits + BITSET_SIZE - 1) / BITSET_SIZE; uint32_t new_size_byte = (num_bits + BITSET_SIZE - 1) / BITSET_SIZE;
OS::get_singleton()->print((String("INFO [") + String(__FILE__) + String(":") + String(uitos(__LINE__)) + String("] Resize") + String("\n")).utf8());
new_size_byte = (num_bits + BITSET_SIZE - 1) / BITSET_SIZE; new_size_byte = (num_bits + BITSET_SIZE - 1) / BITSET_SIZE;
if (this->_size_byte != new_size_byte ) if (this->_size_byte != new_size_byte )
{ {
@ -92,17 +93,20 @@ void BitSet::resize(uint32_t num_bits)
void BitSet::clear() void BitSet::clear()
{ {
OS::get_singleton()->print((String("INFO [") + String(__FILE__) + String(":") + String(uitos(__LINE__)) + String("] Clear") + String("\n")).utf8());
this->resize(1); this->resize(1);
} }
void BitSet::clear_data() void BitSet::clear_data()
{ {
OS::get_singleton()->print((String("INFO [") + String(__FILE__) + String(":") + String(uitos(__LINE__)) + String("] clear_data") + String("\n")).utf8());
for(uint32_t i = 0;i < this->_size_byte; ++i) for(uint32_t i = 0;i < this->_size_byte; ++i)
this->_data[i] = 0; this->_data[i] = 0;
} }
void BitSet::set_bit(uint32_t bit_number) void BitSet::set_bit(uint32_t bit_number)
{ {
OS::get_singleton()->print((String("INFO [") + String(__FILE__) + String(":") + String(uitos(__LINE__)) + String("] set_bit") + String("\n")).utf8());
if (bit_number >= this->_num_bits) if (bit_number >= this->_num_bits)
{ {
ERR_PRINTS("[BitSet::set_bit] Out of range (size:" + itos(this->_size_byte) + ", pos:" + itos(bit_number) + ")" ); ERR_PRINTS("[BitSet::set_bit] Out of range (size:" + itos(this->_size_byte) + ", pos:" + itos(bit_number) + ")" );
@ -115,6 +119,7 @@ void BitSet::set_bit(uint32_t bit_number)
void BitSet::clear_bit(uint32_t bit_number) void BitSet::clear_bit(uint32_t bit_number)
{ {
OS::get_singleton()->print((String("INFO [") + String(__FILE__) + String(":") + String(uitos(__LINE__)) + String("] clear_bit") + String("\n")).utf8());
if (bit_number >= this->_num_bits) if (bit_number >= this->_num_bits)
{ {
ERR_PRINTS("[BitSet::clear_bit] Out of range (size:" + itos(this->_size_byte) + ", pos:" + itos(bit_number) + ")" ); ERR_PRINTS("[BitSet::clear_bit] Out of range (size:" + itos(this->_size_byte) + ", pos:" + itos(bit_number) + ")" );
@ -122,7 +127,7 @@ void BitSet::clear_bit(uint32_t bit_number)
} }
uint32_t mask = bit_number & (BITSET_SIZE - 1); uint32_t mask = bit_number & (BITSET_SIZE - 1);
mask = 1 << mask; mask = 1 << mask;
this->_data[bit_number>>5] &= mask; this->_data[bit_number>>5] &= ~ mask;
} }
void BitSet::write(uint32_t bit_number, bool value) void BitSet::write(uint32_t bit_number, bool value)

View file

@ -21,7 +21,8 @@
#include "core/error_macros.h" #include "core/error_macros.h"
#ifdef DEBUG_ENABLED #ifdef DEBUG_ENABLED
#include "core/os/os.h" #include "core/os/os.h"
#define DBG_PRINT(m_string) OS::get_singleton()->print((String("[") + String(__FILE__) + String(":") + String(uitos(__LINE__)) + String("] ") + String(m_string) + String("\n")).utf8()) #define DBG_PRINT(m_string) OS::get_singleton()->print((String("DEBUG [") + String(__FILE__) + String(":") + String(uitos(__LINE__)) + String("] ") + String(m_string) + String("\n")).utf8())
#else #else
#define DBG_PRINT(m_string) #define DBG_PRINT(m_string)
#endif #endif
#define INF_PRINT(m_string) OS::get_singleton()->print((String("INFO [") + String(__FILE__) + String(":") + String(uitos(__LINE__)) + String("] ") + String(m_string) + String("\n")).utf8())

View file

@ -22,12 +22,52 @@
#include "state_connexion.h" #include "state_connexion.h"
#include "network_connection_core.h" #include "network_connection_core.h"
#include "modules/debug/debug.h" #include "modules/debug/debug.h"
#include "modules/networkconnection/network_data.h"
// We need managed when number 'uint32_t' exceed the capacity (32bits => 4294967296)
// So, we split in two group.
// < 0...1073741824 > < 1073741825 ... 3221225472 > < 3221225472 ... 4294967295 > inline uint32_t diff_uint32_circulate(uint32_t a, uint32_t b)
// Group 1 : < 0...1073741824 > + < 3221225472 ... 4294967295 > => number value : 2147483648 {
// Group 2 : < 1073741825 ... 3221225472 > => number value : 2147483648 // We need managed when number 'uint32_t' exceed the capacity (32bits => 4294967296)
//
// So, we split in two group.
// < 0...1073741824 > < 1073741825 ... 3221225472 > < 3221225472 ... 4294967295 >
// Group 1 : < 0...1073741824 > + < 3221225472 ... 4294967295 > => number value : 2147483648
// Group 2 : < 1073741825 ... 3221225472 > => number value : 2147483648
//
if ( a >= 1073741825 && a <= 3221225472 )
return a - b;
a += 1073741825;
b += 1073741825;
return a - b;
}
inline void calculate_ack_bit(NetworkData * _data, bool ackBool)
{
// bool ackBool = (!_SystemMode && (_ConnectionState == Connected || _ConnectionState == Synchronize));
uint32_t i;
uint32_t ackBit = (ackBool ? 1 : 0);
if ( _data->_current_received_number - _data->_last_received_number < 32)
{
_data->_ack_bit_mask <<= _data->_current_received_number - _data->_last_received_number;
_data->_ack_bit_mask |= _data->_last_ack_bit << (_data->_current_received_number - _data->_last_received_number - 1);
}
else
{
_data->_ack_bit_mask = (_data->_current_received_number - _data->_last_received_number == 32 && _data->_last_ack_bit != 0) ? 0x80000000 : 0x00000000;
}
_data->_last_ack_bit = ackBit;
for(i=_data->_last_received_number+1;i<_data->_current_received_number;++i)
_data->_long_ack_bit_field.clear_bit(i & 511);
_data->_long_ack_bit_field.write(_data->_current_received_number & 0x1ff, ackBool);
if ( diff_uint32_circulate(_data->_last_ack_in_long_ack, _data->_current_received_number) > 512 )
{
_data->_last_ack_in_long_ack = _data->_current_received_number - 511;
}
_data->_last_received_number = _data->_current_received_number;
}
/* /*
* StateConnectionBase * StateConnectionBase
@ -370,6 +410,8 @@ void StateConnectionConnected::receive_message(int index)
// SHOW_USAGE_MEMORY // SHOW_USAGE_MEMORY
bool system_mode; bool system_mode;
//INF_PRINT("Receive application message");
Ref<BitStreamField> field = this->_network->_queue.get_msg(index); Ref<BitStreamField> field = this->_network->_queue.get_msg(index);
uint32_t current_received_number = field->get_id(); uint32_t current_received_number = field->get_id();
@ -417,6 +459,10 @@ void StateConnectionConnected::receive_message(int index)
{ {
DBG_PRINT("Receive application message (" + itos(current_received_number) + ") [" + uitos(this->_network->_queue.length()) + "]"); DBG_PRINT("Receive application message (" + itos(current_received_number) + ") [" + uitos(this->_network->_queue.length()) + "]");
} }
calculate_ack_bit(this->_data, system_mode);
//DBG_PRINT("Ack:" + this->_data->_long_ack_bit_field.show());
this->_network->_queue.erase_index(index); this->_network->_queue.erase_index(index);
// Check in buffer if we have next // Check in buffer if we have next
if ( this->_network->_queue.is_index(index + 1) ) if ( this->_network->_queue.is_index(index + 1) )