// $Id: log.cc,v 1.4 2006/08/05 09:08:59 matthew Exp $ // Fish Supper // Copyright (C) 2006 Matthew Clarke // // 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 distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 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 "log.h" #include // ******************* // *** CONSTRUCTOR *** // ******************* FS::Log::Log(int _y, int _width, int _height, int _map_x, int _row, int _row_length_pixels, Direction _direction, LogColor _color) { y = _y; width = _width; height = _height; map_x = _map_x; row = _row; row_length_pixels = _row_length_pixels; my_direction = _direction; original_color = current_color = _color; sprite_rect.y = y; sprite_rect.w = width; sprite_rect.h = height; erase_rect.y = y; erase_rect.h = height; fill_rect.y = y; fill_rect.h = height; sprite_size_rect.x = 0; sprite_size_rect.y = 0; sprite_size_rect.w = width; sprite_size_rect.h = height; coll_box_x_offset = 0; coll_box_y_offset = 0; coll_box.w = width; coll_box.h = height; end_rect_src.x = 242; end_rect_src.y = 0; end_rect_src.w = 8; end_rect_src.h = 50; end_rect_dest.y = y; } // FS::Log::Log() // ****************** // *** DESTRUCTOR *** // ****************** FS::Log::~Log() { // NYI } // FS::Log::~Log() // ************************ // *** MEMBER FUNCTIONS *** // ************************ // ************************************************** void FS::Log::process_first_pass() { // Remember that x has already been set! fill_rect.x = x; fill_rect.w = width; fill_visible = adjust_rect(&fill_rect); trace_visible = false; } // FS::Log::process_first_pass() // ************************************************** void FS::Log::print_data() { std::cout << "sprite_visible = " << sprite_visible << ": " << sprite_rect.x << "," << sprite_rect.w << std::endl; std::cout << " fill_visible = " << fill_visible << ": " << fill_rect.x << "," << fill_rect.w << " (rlp=" << row_length_pixels << ")" << std::endl; std::cout << " trace_visible = " << trace_visible << ": " << erase_rect.x << "," << erase_rect.w << std::endl; std::cout << "***width=" << width << "***\n"; } // FS::Log::print_data() // ************************************************** /* void FS::Log::schedule_drawing(PlayDisplay * pd) { // FIXME: need better variable names // send requests to PlayDisplay... // does anything need erasing? if (trace_visible) { pd->request_erase(&erase_rect); pd->request_update(erase_rect); } // if // drawing? if (fill_visible) { pd->request_update(fill_rect); } // if if (sprite_visible) { pd->request_blit( ((ImageIDs) (my_color + IMAGE_ID_LOG_OFFSET)), &sprite_size_rect, &sprite_rect ); } // if } // FS::Log::schedule_drawing() */ // ************************************************** void FS::Log::schedule_drawing(PlayDisplay * pd) { // FIXME: need better variable names // send requests to PlayDisplay... // does anything need erasing? if (trace_visible) { pd->request_erase(&erase_rect); pd->request_update(erase_rect); } // if if (sprite_visible) { pd->request_blit( ((ImageIDs) (current_color + IMAGE_ID_LOG_OFFSET)), &sprite_size_rect, &sprite_rect ); if (width < 250) { pd->request_blit( ((ImageIDs) (current_color + IMAGE_ID_LOG_OFFSET)), &end_rect_src, &end_rect_dest ); } // if } // if } // FS::Log::schedule_drawing() // ************************************************** /* void FS::Log::update(const int * current_start_pixels, const int * pixels_to_move, const int * old_pixels_to_move, bool is_first_pass, PlayDisplay * pd) { num_pixels_moved = pixels_to_move[row] - old_pixels_to_move[row]; calc_x(current_start_pixels[row]); calc_sprite_rect(); // If this is the first pass (i.e. frame) of a new level, the logs need // to be drawn in their entirety without any erasing... if (is_first_pass) { process_first_pass(); schedule_drawing(pd); return; } // if switch (my_direction) { case LEFT_TO_RIGHT: erase_rect.x = x - num_pixels_moved; if (erase_rect.x < 0) { erase_rect.x += row_length_pixels; } // if // What if pixels_moved > width? fill_rect.x = (x + width - num_pixels_moved) % row_length_pixels; break; case RIGHT_TO_LEFT: erase_rect.x = (x + width) % row_length_pixels; fill_rect.x = x; break; } // switch erase_rect.w = num_pixels_moved; erase_rect.h = height; fill_rect.w = num_pixels_moved; trace_visible = adjust_rect(&erase_rect); fill_visible = adjust_rect(&fill_rect); schedule_drawing(pd); } // FS::Log::update() */ // ************************************************** void FS::Log::update(const int * current_start_pixels, const int * pixels_to_move, const int * old_pixels_to_move, const Direction * directions, bool is_first_pass, PlayDisplay * pd) { num_pixels_moved = pixels_to_move[row] - old_pixels_to_move[row]; calc_x(current_start_pixels[row]); calc_sprite_rect(); // Initial values for erase_rect structure. switch ( (my_direction = directions[row]) ) { case LEFT_TO_RIGHT: erase_rect.x = x - num_pixels_moved; if (erase_rect.x < 0) { erase_rect.x += row_length_pixels; } // if break; case RIGHT_TO_LEFT: erase_rect.x = x; break; } // switch erase_rect.w = width + num_pixels_moved; end_rect_dest.x = (x + width - end_rect_src.w) % row_length_pixels; trace_visible = adjust_rect(&erase_rect); schedule_drawing(pd); } // FS::Log::update() // ************************************************** // ************************************************** // **************************************************