From 7f0e8c7ef70c62814c274f110367db92f01cbb26 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Tue, 10 Mar 2015 00:41:59 -0400 Subject: C++11'd everything! Also moved location information from physics components into entity. --- src/map.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'src/map.cpp') diff --git a/src/map.cpp b/src/map.cpp index fda8009..87080e8 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1,7 +1,14 @@ #include "map.h" #include "game.h" +#include +#include -Map::Map(char* filename) +Map::Map() +{ + +} + +Map::Map(const char* filename) { FILE* f = fopen(filename, "r"); @@ -22,12 +29,44 @@ Map::Map(char* filename) fclose(f); } +Map::Map(Map& map) +{ + m_mapdata = (int*) malloc(MAP_WIDTH*(MAP_HEIGHT-1)*sizeof(int)); + memcpy(m_mapdata, map.m_mapdata, MAP_WIDTH*(MAP_HEIGHT-1)*sizeof(int)); + + m_title = (char*) malloc((MAP_WIDTH+1)*sizeof(char)); + strncpy(m_title, map.m_title, MAP_WIDTH+1); + + m_leftMap = map.m_leftMap; + m_rightMap = map.m_rightMap; +} + +Map::Map(Map&& map) : Map() +{ + swap(*this, map); +} + Map::~Map() { free(m_mapdata); free(m_title); } +Map& Map::operator= (Map map) +{ + swap(*this, map); + + return *this; +} + +void swap(Map& first, Map& second) +{ + std::swap(first.m_mapdata, second.m_mapdata); + std::swap(first.m_title, second.m_title); + std::swap(first.m_leftMap, second.m_leftMap); + std::swap(first.m_rightMap, second.m_rightMap); +} + const int* Map::mapdata() { return m_mapdata; -- cgit 1.4.1