File indexing completed on 2021-12-21 12:50:21

0001 /*
0002  *  ksokoban - a Sokoban game by KDE
0003  *  Copyright (C) 1998  Anders Widell  <d95-awi@nada.kth.se>
0004  *
0005  *  This program is free software; you can redistribute it and/or modify
0006  *  it under the terms of the GNU General Public License as published by
0007  *  the Free Software Foundation; either version 2 of the License, or
0008  *  (at your option) any later version.
0009  *
0010  *  This program is distributed in the hope that it will be useful,
0011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  *  GNU General Public License for more details.
0014  *
0015  *  You should have received a copy of the GNU General Public License
0016  *  along with this program; if not, write to the Free Software
0017  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0018  */
0019 
0020 #include <string.h>
0021 
0022 #include "MapDelta.h"
0023 
0024 
0025 MapDelta::MapDelta (Map *m) {
0026   source_ = m;
0027   ended_ = true;
0028   start ();
0029 }
0030 
0031 void
0032 MapDelta::start () {
0033   assert (ended_);
0034   ((Map &) *this) = *source_;
0035 
0036 #if 0
0037   memcpy (map_, source_->currentMap_, (MAX_Y+3)*(MAX_X+3)*sizeof (int));
0038   for (int y=1; y<MAX_Y+2; y++) {
0039     for (int x=1; x<MAX_X+2; x++) {
0040       map_[y][x] = source_->currentMap_[y][x];
0041     }
0042   }
0043   xpos_ = source_->xpos_;
0044   ypos_ = source_->ypos_;
0045 #endif
0046 
0047   ended_ = false;
0048 }
0049 
0050 void
0051 MapDelta::end () {
0052   assert (!ended_);
0053   for (int y=0; y<=MAX_Y; y++) {
0054     for (int x=0; x<=MAX_X; x++) {
0055       map (x, y, map (x, y) != source_->map (x, y));
0056     }
0057   }
0058   if (xpos_ != source_->xpos_ || ypos_ != source_->ypos_) {
0059     map (xpos_, ypos_, 1);
0060     map (source_->xpos_, source_->ypos_, 1);
0061   }
0062   ended_ = true;
0063 }