X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fsprite%2Fsprite_data.cpp;h=5f2fe752d593f4cfef6ab5838c7b79d394cd8d0e;hb=84abfaeb33c5bf8dac0cfd9499d9d4c3e7d39881;hp=58d22cf1b37edc1f6092d494b9f15b3ca0d7b0c4;hpb=85a02e771388b133940b45e29768e697a29c1a36;p=supertux.git diff --git a/src/sprite/sprite_data.cpp b/src/sprite/sprite_data.cpp index 58d22cf1b..5f2fe752d 100644 --- a/src/sprite/sprite_data.cpp +++ b/src/sprite/sprite_data.cpp @@ -1,12 +1,10 @@ -// $Id$ -// // SuperTux -// Copyright (C) 2004 Ingo Ruhnke +// Copyright (C) 2006 Matthias Braun // -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -14,25 +12,23 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#include +// along with this program. If not, see . + +#include "sprite/sprite_data.hpp" -#include -#include -#include #include +#include -#include "sprite_data.hpp" -#include "resources.hpp" -#include "video/drawing_context.hpp" #include "lisp/list_iterator.hpp" +#include "util/log.hpp" SpriteData::Action::Action() { x_offset = 0; y_offset = 0; - z_order = 0; + hitbox_w = 0; + hitbox_h = 0; + z_order = 0; fps = 10; } @@ -52,11 +48,11 @@ SpriteData::SpriteData(const lisp::Lisp* lisp, const std::string& basedir) } else if(iter.item() == "action") { parse_action(iter.lisp(), basedir); } else { - std::cerr << "Unknown sprite field: " << iter.item() << "\n"; + log_warning << "Unknown sprite field: " << iter.item() << std::endl; } } if(actions.empty()) - throw std::runtime_error("Error: Sprite wihtout actions."); + throw std::runtime_error("Error: Sprite without actions."); } SpriteData::~SpriteData() @@ -73,10 +69,16 @@ SpriteData::parse_action(const lisp::Lisp* lisp, const std::string& basedir) if(!lisp->get("name", action->name)) { if(!actions.empty()) throw std::runtime_error( - "If there are more than one action, they need names!"); + "If there are more than one action, they need names!"); + } + std::vector hitbox; + if (lisp->get("hitbox", hitbox)) { + if (hitbox.size() != 4) throw std::runtime_error("hitbox must specify exactly 4 coordinates"); + action->x_offset = hitbox[0]; + action->y_offset = hitbox[1]; + action->hitbox_w = hitbox[2]; + action->hitbox_h = hitbox[3]; } - lisp->get("x-offset", action->x_offset); - lisp->get("y-offset", action->y_offset); lisp->get("z-order", action->z_order); lisp->get("fps", action->fps); @@ -86,28 +88,39 @@ SpriteData::parse_action(const lisp::Lisp* lisp, const std::string& basedir) Action* act_tmp = get_action(mirror_action); if(act_tmp == NULL) { throw std::runtime_error("Could not mirror action. Action not found\n" - "Mirror actions must be defined after the real one!"); + "Mirror actions must be defined after the real one!"); } else { - for(int i = 0; static_cast(i) < act_tmp->surfaces.size(); - i++) { - Surface* surface = new Surface(sdl_surface_from_sdl_surface( - act_tmp->surfaces[i]->impl->get_sdl_surface()), true); - surface->apply_filter(HORIZONTAL_FLIP_FILTER); + float max_w = 0; + float max_h = 0; + for(int i = 0; static_cast(i) < act_tmp->surfaces.size(); i++) { + Surface* surface = new Surface(*(act_tmp->surfaces[i])); + surface->hflip(); + max_w = std::max(max_w, (float) surface->get_width()); + max_h = std::max(max_h, (float) surface->get_height()); action->surfaces.push_back(surface); } + if (action->hitbox_w < 1) action->hitbox_w = max_w; + if (action->hitbox_h < 1) action->hitbox_h = max_h; } } else { // Load images std::vector images; - if(!lisp->get_vector("images", images)) { + if(!lisp->get("images", images)) { std::stringstream msg; msg << "Sprite '" << name << "' contains no images in action '" << action->name << "'."; throw std::runtime_error(msg.str()); } + float max_w = 0; + float max_h = 0; for(std::vector::size_type i = 0; i < images.size(); i++) { - action->surfaces.push_back(new Surface(basedir + images[i], true)); + Surface* surface = new Surface(basedir + images[i]); + max_w = std::max(max_w, (float) surface->get_width()); + max_h = std::max(max_h, (float) surface->get_height()); + action->surfaces.push_back(surface); } + if (action->hitbox_w < 1) action->hitbox_w = max_w; + if (action->hitbox_h < 1) action->hitbox_h = max_h; } actions[action->name] = action; } @@ -122,3 +135,4 @@ SpriteData::get_action(std::string act) return i->second; } +/* EOF */