+, textures(base + "textures/")
+, data(base + "data/") {
+
+}
+
+Assets::Assets(const AssetLoader &loader)
+: large_ui_font(loader.LoadFont("DejaVuSans", 24))
+, small_ui_font(loader.LoadFont("DejaVuSans", 16)) {
+
+}
+
+namespace {
+
+CuboidBounds block_shape({{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f }});
+StairBounds stair_shape({{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.5f, 0.5f }}, { 0.0f, 0.0f });
+CuboidBounds slab_shape({{ -0.5f, -0.5f, -0.5f }, { 0.5f, 0.0f, 0.5f }});
+
+}
+
+void AssetLoader::LoadBlockTypes(
+ const string &set_name,
+ BlockTypeRegistry ®,
+ TextureIndex &tex_index,
+ const ShapeRegistry &shapes
+) const {
+ string full = data + set_name + ".types";
+ std::ifstream file(full);
+ if (!file) {
+ throw std::runtime_error("failed to open block type file " + full);
+ }
+ TokenStreamReader in(file);
+ string type_name;
+ string name;
+ string tex_name;
+ string shape_name;
+ while (in.HasMore()) {
+ in.ReadIdentifier(type_name);
+ in.Skip(Token::EQUALS);
+ BlockType type;
+
+ // read block type
+ in.Skip(Token::ANGLE_BRACKET_OPEN);
+ while (in.Peek().type != Token::ANGLE_BRACKET_CLOSE) {
+ in.ReadIdentifier(name);
+ in.Skip(Token::EQUALS);
+ if (name == "visible") {
+ type.visible = in.GetBool();
+ } else if (name == "texture") {
+ in.ReadString(tex_name);
+ type.textures.push_back(tex_index.GetID(tex_name));
+ } else if (name == "textures") {
+ in.Skip(Token::BRACKET_OPEN);
+ while (in.Peek().type != Token::BRACKET_CLOSE) {
+ in.ReadString(tex_name);
+ type.textures.push_back(tex_index.GetID(tex_name));
+ if (in.Peek().type == Token::COMMA) {
+ in.Skip(Token::COMMA);
+ }
+ }
+ in.Skip(Token::BRACKET_CLOSE);
+ } else if (name == "rgb_mod") {
+ in.ReadVec(type.rgb_mod);
+ } else if (name == "hsl_mod") {
+ in.ReadVec(type.hsl_mod);
+ } else if (name == "outline") {
+ in.ReadVec(type.outline_color);
+ } else if (name == "label") {
+ in.ReadString(type.label);
+ } else if (name == "luminosity") {
+ type.luminosity = in.GetInt();
+ } else if (name == "block_light") {
+ type.block_light = in.GetBool();
+ } else if (name == "collision") {
+ type.collision = in.GetBool();
+ } else if (name == "collide_block") {
+ type.collide_block = in.GetBool();
+ } else if (name == "generate") {
+ type.generate = in.GetBool();
+ } else if (name == "min_solidity") {
+ type.min_solidity = in.GetFloat();
+ } else if (name == "mid_solidity") {
+ type.mid_solidity = in.GetFloat();
+ } else if (name == "max_solidity") {
+ type.max_solidity = in.GetFloat();
+ } else if (name == "min_humidity") {
+ type.min_humidity = in.GetFloat();
+ } else if (name == "mid_humidity") {
+ type.mid_humidity = in.GetFloat();
+ } else if (name == "max_humidity") {
+ type.max_humidity = in.GetFloat();
+ } else if (name == "min_temperature") {
+ type.min_temperature = in.GetFloat();
+ } else if (name == "mid_temperature") {
+ type.mid_temperature = in.GetFloat();
+ } else if (name == "max_temperature") {
+ type.max_temperature = in.GetFloat();
+ } else if (name == "min_richness") {
+ type.min_richness = in.GetFloat();
+ } else if (name == "mid_richness") {
+ type.mid_richness = in.GetFloat();
+ } else if (name == "max_richness") {
+ type.max_richness = in.GetFloat();
+ } else if (name == "commonness") {
+ type.commonness = in.GetFloat();
+ } else if (name == "shape") {
+ in.ReadIdentifier(shape_name);
+ type.shape = &shapes.Get(shape_name);
+ } else {
+ std::cerr << "warning: unknown block type property " << name << std::endl;
+ while (in.Peek().type != Token::SEMICOLON) {
+ in.Next();
+ }
+ }
+ in.Skip(Token::SEMICOLON);
+ }
+ in.Skip(Token::ANGLE_BRACKET_CLOSE);
+ in.Skip(Token::SEMICOLON);
+
+ reg.Add(type);
+ }
+}
+
+CubeMap AssetLoader::LoadCubeMap(const string &name) const {
+ string full = textures + name;
+ string right = full + "-right.png";
+ string left = full + "-left.png";
+ string top = full + "-top.png";
+ string bottom = full + "-bottom.png";
+ string back = full + "-back.png";
+ string front = full + "-front.png";
+
+ CubeMap cm;
+ cm.Bind();
+ SDL_Surface *srf;
+
+ if (!(srf = IMG_Load(right.c_str()))) throw SDLError("IMG_Load");
+ try {
+ cm.Data(CubeMap::RIGHT, *srf);
+ } catch (...) {
+ SDL_FreeSurface(srf);
+ throw;
+ }
+ SDL_FreeSurface(srf);
+
+ if (!(srf = IMG_Load(left.c_str()))) throw SDLError("IMG_Load");
+ try {
+ cm.Data(CubeMap::LEFT, *srf);
+ } catch (...) {
+ SDL_FreeSurface(srf);
+ throw;
+ }
+ SDL_FreeSurface(srf);
+
+ if (!(srf = IMG_Load(top.c_str()))) throw SDLError("IMG_Load");
+ try {
+ cm.Data(CubeMap::TOP, *srf);
+ } catch (...) {
+ SDL_FreeSurface(srf);
+ throw;
+ }
+ SDL_FreeSurface(srf);
+
+ if (!(srf = IMG_Load(bottom.c_str()))) throw SDLError("IMG_Load");
+ try {
+ cm.Data(CubeMap::BOTTOM, *srf);
+ } catch (...) {
+ SDL_FreeSurface(srf);
+ throw;
+ }
+ SDL_FreeSurface(srf);