#include "database-sqlite3.h"
#include "serialization.h"
#include "guiscalingfilter.h"
-#include "script/clientscripting.h"
+#include "script/scripting_client.h"
#include "game.h"
extern gui::IGUIEnvironment* guienv;
IrrlichtDevice *device,
const char *playername,
const std::string &password,
+ const std::string &address_name,
MapDrawControl &control,
IWritableTextureSource *tsrc,
IWritableShaderSource *shsrc,
),
m_particle_manager(&m_env),
m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, ipv6, this),
+ m_address_name(address_name),
m_device(device),
m_camera(NULL),
m_minimap_disabled_by_server(false),
delete m_minimap;
}
-void Client::connect(Address address,
- const std::string &address_name,
- bool is_local_server)
+void Client::connect(Address address, bool is_local_server)
{
DSTACK(FUNCTION_NAME);
- initLocalMapSaving(address, address_name, is_local_server);
+ initLocalMapSaving(address, m_address_name, is_local_server);
m_con.SetTimeoutMs(0);
m_con.Connect(address);
// Step environment
m_env.step(dtime);
+ m_sound->step(dtime);
/*
Get events
*/
- for(;;) {
- ClientEnvEvent event = m_env.getClientEvent();
- if(event.type == CEE_NONE) {
- break;
- }
- else if(event.type == CEE_PLAYER_DAMAGE) {
- if(m_ignore_damage_timer <= 0) {
- u8 damage = event.player_damage.amount;
+ while (m_env.hasClientEnvEvents()) {
+ ClientEnvEvent envEvent = m_env.getClientEnvEvent();
+
+ if (envEvent.type == CEE_PLAYER_DAMAGE) {
+ if (m_ignore_damage_timer <= 0) {
+ u8 damage = envEvent.player_damage.amount;
- if(event.player_damage.send_to_server)
+ if (envEvent.player_damage.send_to_server)
sendDamage(damage);
// Add to ClientEvent queue
}
}
// Protocol v29 or greater obsoleted this event
- else if (event.type == CEE_PLAYER_BREATH && m_proto_ver < 29) {
- u16 breath = event.player_breath.amount;
+ else if (envEvent.type == CEE_PLAYER_BREATH && m_proto_ver < 29) {
+ u16 breath = envEvent.player_breath.amount;
sendBreath(breath);
}
}
minimap_mapblock = r.mesh->moveMinimapMapblock();
if (minimap_mapblock == NULL)
do_mapper_update = false;
- }
- if (r.mesh && r.mesh->getMesh()->getMeshBufferCount() == 0) {
- delete r.mesh;
- } else {
- // Replace with the new mesh
- block->mesh = r.mesh;
+ bool is_empty = true;
+ for (int l = 0; l < MAX_TILE_LAYERS; l++)
+ if (r.mesh->getMesh(l)->getMeshBufferCount() != 0)
+ is_empty = false;
+
+ if (is_empty)
+ delete r.mesh;
+ else
+ // Replace with the new mesh
+ block->mesh = r.mesh;
}
} else {
delete r.mesh;
if (m_media_downloader && m_media_downloader->isStarted()) {
m_media_downloader->step(this);
if (m_media_downloader->isDone()) {
- received_media();
delete m_media_downloader;
m_media_downloader = NULL;
}
<< file_requests.size() << " files. packet size)" << std::endl;
}
-void Client::received_media()
-{
- NetworkPacket pkt(TOSERVER_RECEIVED_MEDIA, 0);
- Send(&pkt);
- infostream << "Client: Notifying server that we received all media"
- << std::endl;
-}
-
void Client::initLocalMapSaving(const Address &address,
const std::string &hostname,
bool is_local_server)
fs::CreateAllDirs(world_path);
- m_localdb = new Database_SQLite3(world_path);
+ m_localdb = new MapDatabaseSQLite3(world_path);
m_localdb->beginSave();
actionstream << "Local map saving started, map will be saved at '" << world_path << "'" << std::endl;
}
void Client::ReceiveAll()
{
DSTACK(FUNCTION_NAME);
- u32 start_ms = porting::getTimeMs();
+ u64 start_ms = porting::getTimeMs();
for(;;)
{
// Limit time even if there would be huge amounts of data to
ClientEvent Client::getClientEvent()
{
- ClientEvent event;
- if (m_client_event_queue.empty()) {
- event.type = CE_NONE;
- }
- else {
- event = m_client_event_queue.front();
- m_client_event_queue.pop();
- }
+ FATAL_ERROR_IF(m_client_event_queue.empty(),
+ "Cannot getClientEvent, queue is empty.");
+
+ ClientEvent event = m_client_event_queue.front();
+ m_client_event_queue.pop();
return event;
}
typedef struct TextureUpdateArgs {
IrrlichtDevice *device;
gui::IGUIEnvironment *guienv;
- u32 last_time_ms;
+ u64 last_time_ms;
u16 last_percent;
const wchar_t* text_base;
ITextureSource *tsrc;
// update the loading menu -- if neccessary
bool do_draw = false;
- u32 time_ms = targs->last_time_ms;
+ u64 time_ms = targs->last_time_ms;
if (cur_percent != targs->last_percent) {
targs->last_percent = cur_percent;
- time_ms = getTimeMs();
+ time_ms = porting::getTimeMs();
// only draw when the user will notice something:
do_draw = (time_ms - targs->last_time_ms > 100);
}
TextureUpdateArgs tu_args;
tu_args.device = device;
tu_args.guienv = guienv;
- tu_args.last_time_ms = getTimeMs();
+ tu_args.last_time_ms = porting::getTimeMs();
tu_args.last_percent = 0;
tu_args.text_base = wgettext("Initializing nodes");
tu_args.tsrc = m_tsrc;