void NetworkedMultiplayerENet::_setup_compressor() { switch(compression_mode) { case COMPRESS_NONE: { enet_host_compress(host,NULL); } break; case COMPRESS_RANGE_CODER: { enet_host_compress_with_range_coder(host); } break; case COMPRESS_FASTLZ: case COMPRESS_ZLIB: { enet_host_compress(host,&enet_compressor); } break; } }
/** Sets the packet compressor the host should use to the default range coder. @param host host to enable the range coder for @returns 0 on success, < 0 on failure */ int enet_host_compress_with_range_coder(ENetHost *host) { ENetCompressor compressor; memset(&compressor, 0, sizeof(compressor)); compressor.context = enet_range_coder_create(); if (compressor.context == NULL) return -1; compressor.compress = enet_range_coder_compress; compressor.decompress = enet_range_coder_decompress; compressor.destroy = enet_range_coder_destroy; enet_host_compress(host, &compressor); return 0; }
VALUE renet_server_use_compression(VALUE self, VALUE flag) { Server* server; Data_Get_Struct(self, Server, server); VALUE lock = rb_iv_get(self, "@lock"); rb_mutex_lock(lock); if (flag == Qtrue) { enet_host_compress_with_range_coder(server->host); } else { enet_host_compress(server->host, NULL); } rb_mutex_unlock(lock); return Qnil; }
VALUE renet_connection_use_compression(VALUE self, VALUE flag) { Connection* connection; Data_Get_Struct(self, Connection, connection); VALUE lock = rb_iv_get(self, "@lock"); rb_mutex_lock(lock); if (flag == Qtrue) { enet_host_compress_with_range_coder(connection->host); } else { enet_host_compress(connection->host, NULL); } rb_mutex_unlock(lock); return Qnil; }