diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-10 00:41:59 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2015-03-10 00:41:59 -0400 |
commit | 7f0e8c7ef70c62814c274f110367db92f01cbb26 (patch) | |
tree | 750bcfec923a826609034ebe9185014521400c68 /src/map.cpp | |
parent | b53826079429939cdfbda073608cb85be8ba0738 (diff) | |
download | therapy-7f0e8c7ef70c62814c274f110367db92f01cbb26.tar.gz therapy-7f0e8c7ef70c62814c274f110367db92f01cbb26.tar.bz2 therapy-7f0e8c7ef70c62814c274f110367db92f01cbb26.zip |
C++11'd everything!
Also moved location information from physics components into entity.
Diffstat (limited to 'src/map.cpp')
-rw-r--r-- | src/map.cpp | 41 |
1 files changed, 40 insertions, 1 deletions
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 @@ | |||
1 | #include "map.h" | 1 | #include "map.h" |
2 | #include "game.h" | 2 | #include "game.h" |
3 | #include <cstdlib> | ||
4 | #include <cstring> | ||
3 | 5 | ||
4 | Map::Map(char* filename) | 6 | Map::Map() |
7 | { | ||
8 | |||
9 | } | ||
10 | |||
11 | Map::Map(const char* filename) | ||
5 | { | 12 | { |
6 | FILE* f = fopen(filename, "r"); | 13 | FILE* f = fopen(filename, "r"); |
7 | 14 | ||
@@ -22,12 +29,44 @@ Map::Map(char* filename) | |||
22 | fclose(f); | 29 | fclose(f); |
23 | } | 30 | } |
24 | 31 | ||
32 | Map::Map(Map& map) | ||
33 | { | ||
34 | m_mapdata = (int*) malloc(MAP_WIDTH*(MAP_HEIGHT-1)*sizeof(int)); | ||
35 | memcpy(m_mapdata, map.m_mapdata, MAP_WIDTH*(MAP_HEIGHT-1)*sizeof(int)); | ||
36 | |||
37 | m_title = (char*) malloc((MAP_WIDTH+1)*sizeof(char)); | ||
38 | strncpy(m_title, map.m_title, MAP_WIDTH+1); | ||
39 | |||
40 | m_leftMap = map.m_leftMap; | ||
41 | m_rightMap = map.m_rightMap; | ||
42 | } | ||
43 | |||
44 | Map::Map(Map&& map) : Map() | ||
45 | { | ||
46 | swap(*this, map); | ||
47 | } | ||
48 | |||
25 | Map::~Map() | 49 | Map::~Map() |
26 | { | 50 | { |
27 | free(m_mapdata); | 51 | free(m_mapdata); |
28 | free(m_title); | 52 | free(m_title); |
29 | } | 53 | } |
30 | 54 | ||
55 | Map& Map::operator= (Map map) | ||
56 | { | ||
57 | swap(*this, map); | ||
58 | |||
59 | return *this; | ||
60 | } | ||
61 | |||
62 | void swap(Map& first, Map& second) | ||
63 | { | ||
64 | std::swap(first.m_mapdata, second.m_mapdata); | ||
65 | std::swap(first.m_title, second.m_title); | ||
66 | std::swap(first.m_leftMap, second.m_leftMap); | ||
67 | std::swap(first.m_rightMap, second.m_rightMap); | ||
68 | } | ||
69 | |||
31 | const int* Map::mapdata() | 70 | const int* Map::mapdata() |
32 | { | 71 | { |
33 | return m_mapdata; | 72 | return m_mapdata; |