Logo Search packages:      
Sourcecode: gaia version File versions  Download package

Tile.cc

/*
 * gaia - opensource 3D interface to the planet
 * Copyright (C) 2006 gaia project
 *
 * 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.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "Tile.h"

00022 Tile::Tile(int x, int y, int level) {
      if (pthread_mutex_init(&m_RefCountMutex, 0) != 0)
            throw ErrnoException("pthread_mutex_init() failed", errno);

      m_RefCount = 0;

      m_X = x;
      m_Y = y;
      m_Level = level;

      m_LastUsed = Timer::Instance()->GetFrame();

      m_RawData = 0;
      m_IsNull = 0;
}

00038 Tile::~Tile() {
      delete m_RawData;
      pthread_mutex_destroy(&m_RefCountMutex);
}

/* coord ops */
00044 int Tile::GetX() {
      return m_X;
}

00048 int Tile::GetY() {
      return m_Y;
}

00052 int Tile::GetLevel() {
      return m_Level;
}

00056 int Tile::GetType() {
      return TILETYPE_NONE;
}

/* age ops */
00061 void Tile::Touch() {
      m_LastUsed = Timer::Instance()->GetFrame();
}

00065 ticks_t Tile::GetAge() {
      return Timer::Instance()->GetFrame() - m_LastUsed;
}

00069 int Tile::IsOld() {
      return GetAge() > 2;
}

/* null ops */
00074 void Tile::Null() {
      m_IsNull = 1;
}

00078 int Tile::IsNull() {
      return m_IsNull;
}

/* load/save */
00083 void Tile::Load(RawBuffer *data, int keep) {
      if (keep)
            m_RawData = data;
      else 
            delete data;
}

00090 RawBuffer *Tile::ReleaseRawData() {
      RawBuffer *raw = m_RawData;
      m_RawData = 0;
      return raw;
}

00096 int Tile::IsSaveable() {
      return m_RawData != 0;
}

00100 int Tile::IsLoaded() {
      return IsNull();
}

00104 int Tile::IsReady() {
      return !IsNull() && IsLoaded();
}

/* reference counting */
00109 unsigned int Tile::IncRef() {
      pthread_mutex_lock(&m_RefCountMutex);
      unsigned int rc = ++m_RefCount;
      pthread_mutex_unlock(&m_RefCountMutex);
      return rc;
}

00116 unsigned int Tile::DecRef() {
      pthread_mutex_lock(&m_RefCountMutex);
      unsigned int rc = --m_RefCount;
      pthread_mutex_unlock(&m_RefCountMutex);
      return rc;
}

Generated by  Doxygen 1.6.0   Back to index