Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

FinderField.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Ivo Danihelka (ivo@danihelka.net)
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  */
00009 #include "FinderField.h"
00010 
00011 #include "V2.h"
00012 
00013 #include <string.h> // memset()
00014 
00015 //-----------------------------------------------------------------
00016 /**
00017  * Two dimensional array of booleans.
00018  */
00019 FinderField::FinderField(int w, int h)
00020 {
00021     m_w = w;
00022     m_h = h;
00023 
00024     //NOTE: [y][x] indexes
00025     m_closed = new bool*[m_h];
00026     for (int y = 0; y < m_h; ++y) {
00027         m_closed[y] = new bool[m_w];
00028         memset(m_closed[y], false, sizeof(bool) * m_w);
00029     }
00030 }
00031 //-----------------------------------------------------------------
00032 FinderField::~FinderField()
00033 {
00034     for (int y = 0; y < m_h; ++y) {
00035         delete[] m_closed[y];
00036     }
00037     delete[] m_closed;
00038 }
00039 //-----------------------------------------------------------------
00040 /**
00041  * Erase all marks.
00042  */
00043 void
00044 FinderField::reset()
00045 {
00046     for (int y = 0; y < m_h; ++y) {
00047         memset(m_closed[y], false, sizeof(bool) * m_w);
00048     }
00049 }
00050 //-----------------------------------------------------------------
00051 /**
00052  * Mark given place as closed.
00053  */
00054 void
00055 FinderField::markClosed(const V2 &loc)
00056 {
00057     int x = loc.getX();
00058     int y = loc.getY();
00059 
00060     if ((0 <= x && x < m_w) && (0 <= y && y < m_h)) {
00061         m_closed[y][x] = true;
00062     }
00063 }
00064 //-----------------------------------------------------------------
00065 /**
00066  * Returns true when place is closed.
00067  * NOTE: all places outside array are marked as closed
00068  */
00069 bool
00070 FinderField::isClosed(const V2 &loc) const
00071 {
00072     int x = loc.getX();
00073     int y = loc.getY();
00074 
00075     bool result = true;
00076     if ((0 <= x && x < m_w) && (0 <= y && y < m_h)) {
00077         result = m_closed[y][x];
00078     }
00079     return result;
00080 }
00081 
00082 

Generated on Wed Jun 1 09:54:31 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2