Mercurial > LightClone
view LightClone/Source/Loader.cpp @ 51:efd2b1ca5b77
Clean up gui
author | koryspansel <koryspansel@bendbroadband.com> |
---|---|
date | Tue, 27 Sep 2011 09:42:01 -0700 |
parents | 58a16d529d95 |
children | 6d4437a24aeb |
line wrap: on
line source
/* * Loader */ #include "Loader.h" #include "Util.h" /* * Loader */ Loader::Loader() { kSize.X = 0; kSize.Y = 0; pType = 0; pHeight = 0; kPosition.X = 0; kPosition.Y = 0; kDirection = Direction_North; } /* * ~Loader */ Loader::~Loader() { if(pType) { delete[] pType; pType = 0; } if(pHeight) { delete[] pHeight; pHeight = 0; } } /* * Load */ ErrorCode Loader::Load(const char* pName) { if(pType) { delete[] pType; pType = 0; } if(pHeight) { delete[] pHeight; pHeight = 0; } Buffer kBuffer = LoadFile(pName); if(kBuffer.Read(&kSize.X) != Error_Success) return Error_Fail; if(kBuffer.Read(&kSize.Y) != Error_Success) return Error_Fail; if(kBuffer.Read(&kPosition.X) != Error_Success) return Error_Fail; if(kBuffer.Read(&kPosition.Y) != Error_Success) return Error_Fail; if(kBuffer.Read(&kDirection) != Error_Success) return Error_Fail; if(kSize.X == 0 || kSize.Y == 0) return Error_Fail; pHeight = new uint32[kSize.X * kSize.Y]; pType = new uint32[kSize.X * kSize.Y]; for(uint32 nY = 0; nY < kSize.Y; ++nY) { for(uint32 nX = 0; nX < kSize.X; ++nX) { const uint32 nIndex = nY * kSize.X + nX; if(kBuffer.Read(pHeight + nIndex) != Error_Success) return Error_Fail; if(kBuffer.Read(pType + nIndex) != Error_Success) return Error_Fail; } } return Error_Success; } /* * GetSize */ const Size& Loader::GetSize() const { return kSize; } /* * GetTowerType */ uint32 Loader::GetTowerType(uint32 nX, uint32 nY) { return pType[nY * kSize.X + nX]; } /* * GetTowerHeight */ uint32 Loader::GetTowerHeight(uint32 nX, uint32 nY) { return pHeight[nY * kSize.X + nX]; } /* * GetInitialPosition */ const Position& Loader::GetInitialPosition() const { return kPosition; } /* * GetInitialDirection */ const Direction& Loader::GetInitialDirection() const { return kDirection; }