games/digger: Show worldgen queue size on client

This commit is contained in:
Perttu Ahola 2014-10-28 01:53:01 +02:00
parent 8d4fc82919
commit 24636e9dd7
2 changed files with 35 additions and 4 deletions

View File

@ -212,6 +212,7 @@ end
-- Add some text
local title_text = magic.ui.root:CreateChild("Text")
local misc_text = magic.ui.root:CreateChild("Text")
local worldgen_text = magic.ui.root:CreateChild("Text")
do
title_text:SetText("digger/init.lua")
title_text:SetFont(magic.cache:GetResource("Font", "Fonts/Anonymous Pro.ttf"), 15)
@ -224,6 +225,15 @@ do
misc_text.horizontalAlignment = magic.HA_CENTER
misc_text.verticalAlignment = magic.VA_CENTER
misc_text:SetPosition(0, -magic.ui.root.height/2 + 40)
worldgen_text:SetText("")
worldgen_text:SetFont(magic.cache:GetResource("Font", "Fonts/Anonymous Pro.ttf"), 15)
--[[worldgen_text.horizontalAlignment = magic.HA_LEFT
worldgen_text.verticalAlignment = magic.VA_TOP
worldgen_text:SetPosition(0, 0)--]]
worldgen_text.horizontalAlignment = magic.HA_CENTER
worldgen_text.verticalAlignment = magic.VA_CENTER
worldgen_text:SetPosition(0, -magic.ui.root.height/2 + 60)
end
-- Unfocus UI
@ -487,4 +497,13 @@ voxelworld.sub_ready(function()
end)
end)
buildat.sub_packet("main:worldgen_queue_size", function(data)
local queue_size = tonumber(data)
if queue_size > 0 then
worldgen_text:SetText("Worldgen queue size: "..queue_size)
else
worldgen_text:SetText("")
end
end)
-- vim: set noet ts=4 sw=4:

View File

@ -4,6 +4,7 @@
#include "replicate/api.h"
#include "voxelworld/api.h"
#include "main_context/api.h"
#include "worldgen/api.h"
#include "interface/module.h"
#include "interface/server.h"
#include "interface/event.h"
@ -80,6 +81,7 @@ struct Module: public interface::Module
"network:packet_received/main:place_voxel"));
m_server->sub_event(this, Event::t(
"network:packet_received/main:dig_voxel"));
m_server->sub_event(this, Event::t("worldgen:queue_modified"));
}
void event(const Event::Type &type, const Event::Private *p)
@ -94,6 +96,8 @@ struct Module: public interface::Module
on_place_voxel, network::Packet)
EVENT_TYPEN("network:packet_received/main:dig_voxel",
on_dig_voxel, network::Packet)
EVENT_TYPEN("worldgen:queue_modified",
on_worldgen_queue_modified, worldgen::QueueModifiedEvent);
}
void on_start()
@ -158,10 +162,6 @@ struct Module: public interface::Module
});
}
void update_scene()
{
}
void on_tick(const interface::TickEvent &event)
{
/*main_context::access(m_server, [&](main_context::Interface *imc)
@ -226,6 +226,18 @@ struct Module: public interface::Module
ivoxelworld->set_voxel(voxel_p, VoxelInstance(1));
});
}
void on_worldgen_queue_modified(const worldgen::QueueModifiedEvent &event)
{
log_t(MODULE, "on_worldgen_queue_modified()");
network::access(m_server, [&](network::Interface *inetwork){
sv_<network::PeerInfo::Id> peers = inetwork->list_peers();
for(auto &peer: peers){
inetwork->send(peer, "main:worldgen_queue_size",
itos(event.queue_size));
}
});
}
};
extern "C" {