#include "../app/TextureIndex.hpp"
#include "../model/CompositeModel.hpp"
#include "../io/WorldSave.hpp"
+#include "../world/ChunkIndex.hpp"
#include "../world/ChunkStore.hpp"
#include <iostream>
}
TextureIndex tex_index;
master.GetEnv().loader.LoadBlockTypes("default", block_types, tex_index);
- interface.SetInventorySlots(block_types.Size() - 1);
+ interface.SetInventorySlots(block_types.size() - 1);
chunk_renderer.LoadTextures(master.GetEnv().loader, tex_index);
chunk_renderer.FogDensity(master.GetWorldConf().fog_density);
skeletons.Load();
loop_timer.Start();
+ if (save.Exists(player)) {
+ save.Read(player);
+ }
}
void InteractiveState::OnEnter() {
interface.Handle(event.wheel);
break;
case SDL_QUIT:
- master.Quit();
+ Exit();
break;
default:
break;
input.MergePlayerCorrection(pack, state);
}
+void InteractiveState::Handle(const Packet::BlockUpdate &pack) {
+ glm::ivec3 pos;
+ pack.ReadChunkCoords(pos);
+ Chunk *chunk = player.GetChunks().Get(pos);
+ if (!chunk) {
+ // this change doesn't concern us
+ return;
+ }
+ uint32_t count = 0;
+ pack.ReadBlockCount(count);
+ for (uint32_t i = 0; i < count; ++i) {
+ uint16_t index;
+ Block block;
+ pack.ReadIndex(index, i);
+ pack.ReadBlock(block, i);
+ if (index < Chunk::size && block.type < block_types.size()) {
+ manip.SetBlock(*chunk, index, block);
+ }
+ }
+}
+
void InteractiveState::SetAudio(bool b) {
master.GetConfig().audio.enabled = b;
if (b) {
}
void InteractiveState::Exit() {
+ save.Write(player);
master.Quit();
}
void MasterState::OnTimeout() {
if (client.GetConnection().Closed()) {
- // TODO: push disconnected message
- cout << "connection timed out" << endl;
Quit();
+ env.ShowMessage("connection timed out");
}
}
}
void MasterState::On(const Packet::Part &pack) {
+ Quit();
if (state) {
// kicked
- cout << "kicked by server" << endl;
+ env.ShowMessage("kicked by server");
} else {
// join refused
- cout << "login refused by server" << endl;
+ env.ShowMessage("login refused by server");
}
- Quit();
}
void MasterState::On(const Packet::SpawnEntity &pack) {
if (!state) {
cout << "got entity spawn before world was created" << endl;
- Quit();
return;
}
uint32_t entity_id;
void MasterState::On(const Packet::DespawnEntity &pack) {
if (!state) {
cout << "got entity despawn before world was created" << endl;
- Quit();
return;
}
uint32_t entity_id;
void MasterState::On(const Packet::EntityUpdate &pack) {
if (!state) {
cout << "got entity update before world was created" << endl;
- Quit();
return;
}
void MasterState::On(const Packet::PlayerCorrection &pack) {
if (!state) {
cout << "got player correction without a player :S" << endl;
- Quit();
return;
}
uint16_t pack_seq;
state->GetChunkReceiver().Handle(pack);
}
+void MasterState::On(const Packet::BlockUpdate &pack) {
+ if (!state) {
+ cout << "received block update, but the world has not been created yet" << endl;
+ return;
+ }
+ state->Handle(pack);
+}
+
}
}