, sounds()
, save(master.GetEnv().config.GetWorldPath(master.GetWorldConf().name, master.GetConfig().net.host))
, world(res.block_types, master.GetWorldConf())
-, player(*world.AddPlayer(master.GetConfig().player.name))
+, player(*world.AddPlayer(master.GetConfig().player.name, player_id))
, hud(master.GetEnv(), master.GetConfig(), player)
, manip(master.GetEnv().audio, sounds, player.GetEntity())
, input(world, player, master.GetClient())
}
}
-void InteractiveState::OnEnter() {
- master.GetEnv().window.GrabMouse();
+void InteractiveState::OnResume() {
+ OnFocus();
+}
+
+void InteractiveState::OnPause() {
+ OnBlur();
+}
+
+void InteractiveState::OnFocus() {
+ if (master.GetConfig().input.mouse) {
+ master.GetEnv().window.GrabMouse();
+ }
+ interface.Unlock();
+}
+
+void InteractiveState::OnBlur() {
+ master.GetEnv().window.ReleaseMouse();
+ interface.Lock();
}
void InteractiveState::Handle(const SDL_Event &event) {
}
void InteractiveState::Update(int dt) {
- input.Update(dt);
- if (input.BlockFocus()) {
- hud.FocusBlock(input.BlockFocus().GetChunk(), input.BlockFocus().block);
- } else if (input.EntityFocus()) {
- hud.FocusEntity(*input.EntityFocus().entity);
- } else {
- hud.FocusNone();
- }
- hud.Display(res.block_types[player.GetInventorySlot() + 1]);
loop_timer.Update(dt);
master.Update(dt);
chunk_receiver.Update(dt);
- hud.Update(dt);
int world_dt = 0;
while (loop_timer.HitOnce()) {
world.Update(loop_timer.Interval());
}
chunk_renderer.Update(dt);
+ if (input.BlockFocus()) {
+ hud.FocusBlock(input.BlockFocus().GetChunk(), input.BlockFocus().block);
+ } else if (input.EntityFocus()) {
+ hud.FocusEntity(*input.EntityFocus().entity);
+ } else {
+ hud.FocusNone();
+ }
if (world_dt > 0) {
input.PushPlayerUpdate(world_dt);
}
+ hud.Display(res.block_types[player.GetInventorySlot() + 1]);
+ hud.Update(dt);
glm::mat4 trans = player.GetEntity().Transform(player.GetEntity().ChunkCoords());
glm::vec3 dir(trans * glm::vec4(0.0f, 0.0f, -1.0f, 0.0f));
Entity &entity = world.ForceAddEntity(entity_id);
UpdateEntity(entity_id, pack.Seq());
pack.ReadEntity(entity);
- uint32_t skel_id;
- pack.ReadSkeletonID(skel_id);
- if (skel_id > 0 && skel_id <= res.models.size()) {
- Model &skel = res.models.Get(skel_id);
- skel.Instantiate(entity.GetModel());
+ uint32_t model_id;
+ pack.ReadModelID(model_id);
+ if (model_id > 0 && model_id <= res.models.size()) {
+ res.models.Get(model_id).Instantiate(entity.GetModel());
}
cout << "spawned entity #" << entity_id << " (" << entity.Name()
<< ") at " << entity.AbsolutePosition() << endl;
auto world_end = world.Entities().end();
uint32_t count = 0;
+ glm::ivec3 base;
pack.ReadEntityCount(count);
+ pack.ReadChunkBase(base);
+ EntityState state;
for (uint32_t i = 0; i < count; ++i) {
uint32_t entity_id = 0;
}
if (world_iter->ID() == entity_id) {
if (UpdateEntity(entity_id, pack.Seq())) {
- pack.ReadEntityState(world_iter->GetState(), i);
+ pack.ReadEntityState(state, base, i);
+ world_iter->SetState(state);
}
}
}
}
void InteractiveState::OnLineSubmit(const string &line) {
- master.GetClient().SendMessage(1, 0, line);
+ if (!line.empty()) {
+ master.GetClient().SendMessage(1, 0, line);
+ }
}
pack.ReadPlayerID(player_id);
state.reset(new InteractiveState(*this, player_id));
- pack.ReadPlayerState(state->GetPlayer().GetEntity().GetState());
- glm::vec3 orient(glm::eulerAngles(state->GetPlayer().GetEntity().Orientation()));
- state->GetPlayerController().TurnHead(orient.x, orient.y);
+ EntityState player_state;
+ pack.ReadPlayerState(player_state);
+ state->GetPlayer().GetEntity().SetState(player_state);
env.state.PopAfter(this);
env.state.Push(state.get());