2b3ea5eb80
Project compiles and runs, multiplayer works, but the map is not visible
There are a number of major changes to the map system, beth directly from the
jam branch and from the splicing process. The changes that are listed here have
been noted as they were added to the index for committing.
* tile_sheet.*pp moved from 'common/graphics/' to 'common/map/'
* Minor method and member name changes to TileSheet
* TileSheet has a lua API, but it isn't used anywhere
NOTE: Nothing uses both lua and graphics, but a theoretical editor might
* Region API's glue functions have been changed from triggers to simple dummy
methods. These should simply be over written.
* RegionPagerBase::GetRegion(int x, int y) now snaps it's parameters
Presicely why is unknown, but I do remember there was a bug without it
* RegionPagerLua has been rewritten to use the Region API's methods, rather
than the triggers.
* RegionPagerLua no longer stores the map's save directory, or passes it to the
the Region API's methods.
* RegionPagerLua::luaState renamed to RegionPagerLua::lua
conforms to changes elsewhere
* Removed the directory glue functions from the RegionPager API
* region_pager_api.hpp preprocessor guard changed
* Adjusted makefiles to account for TileSheet's movement
100 lines
3.0 KiB
C++
100 lines
3.0 KiB
C++
/* Copyright: (c) Kayne Ruse 2014
|
|
*
|
|
* This software is provided 'as-is', without any express or implied
|
|
* warranty. In no event will the authors be held liable for any damages
|
|
* arising from the use of this software.
|
|
*
|
|
* Permission is granted to anyone to use this software for any purpose,
|
|
* including commercial applications, and to alter it and redistribute it
|
|
* freely, subject to the following restrictions:
|
|
*
|
|
* 1. The origin of this software must not be misrepresented; you must not
|
|
* claim that you wrote the original software. If you use this software
|
|
* in a product, an acknowledgment in the product documentation would be
|
|
* appreciated but is not required.
|
|
*
|
|
* 2. Altered source versions must be plainly marked as such, and must not be
|
|
* misrepresented as being the original software.
|
|
*
|
|
* 3. This notice may not be removed or altered from any source
|
|
* distribution.
|
|
*/
|
|
#include "region_pager_base.hpp"
|
|
|
|
#include "utility.hpp"
|
|
|
|
#include <stdexcept>
|
|
#include <algorithm>
|
|
|
|
Region::type_t RegionPagerBase::SetTile(int x, int y, int z, Region::type_t v) {
|
|
Region* ptr = GetRegion(x, y);
|
|
return ptr->SetTile(x - ptr->GetX(), y - ptr->GetY(), z, v);
|
|
}
|
|
|
|
Region::type_t RegionPagerBase::GetTile(int x, int y, int z) {
|
|
Region* ptr = GetRegion(x, y);
|
|
return ptr->GetTile(x - ptr->GetX(), y - ptr->GetY(), z);
|
|
}
|
|
|
|
bool RegionPagerBase::SetSolid(int x, int y, int b) {
|
|
Region* ptr = GetRegion(x, y);
|
|
return ptr->SetSolid(x - ptr->GetX(), y - ptr->GetY(), b);
|
|
}
|
|
|
|
bool RegionPagerBase::GetSolid(int x, int y) {
|
|
Region* ptr = GetRegion(x, y);
|
|
return ptr->GetSolid(x - ptr->GetX(), y - ptr->GetY());
|
|
}
|
|
|
|
Region* RegionPagerBase::GetRegion(int x, int y) {
|
|
x = snapToBase(REGION_WIDTH, x);
|
|
y = snapToBase(REGION_HEIGHT, y);
|
|
|
|
//get the region by various means
|
|
Region* ptr = nullptr;
|
|
ptr = FindRegion(x, y);
|
|
if (ptr) return ptr;
|
|
ptr = LoadRegion(x, y);
|
|
if (ptr) return ptr;
|
|
return CreateRegion(x, y);
|
|
}
|
|
|
|
Region* RegionPagerBase::FindRegion(int x, int y) {
|
|
//find the region
|
|
std::list<Region>::iterator it = find_if(regionList.begin(), regionList.end(), [x, y](Region& region) -> bool {
|
|
return region.GetX() == x && region.GetY() == y;
|
|
});
|
|
return it != regionList.end() ? &(*it) : nullptr;
|
|
}
|
|
|
|
Region* RegionPagerBase::PushRegion(Region* const ptr) {
|
|
regionList.push_front(*ptr);
|
|
return ®ionList.front();
|
|
}
|
|
|
|
Region* RegionPagerBase::LoadRegion(int x, int y) {
|
|
//TODO: load the region if possible
|
|
return nullptr;
|
|
}
|
|
|
|
Region* RegionPagerBase::SaveRegion(int x, int y) {
|
|
//TODO: find & save the region
|
|
return nullptr;
|
|
}
|
|
|
|
Region* RegionPagerBase::CreateRegion(int x, int y) {
|
|
if (FindRegion(x, y)) {
|
|
throw(std::logic_error("Cannot overwrite an existing region"));
|
|
}
|
|
regionList.emplace_front(x, y);
|
|
return ®ionList.front();
|
|
}
|
|
|
|
void RegionPagerBase::UnloadRegion(int x, int y) {
|
|
//custom loop, not FindRegion()
|
|
regionList.remove_if([x, y](Region& region) -> bool { return region.GetX() == x && region.GetY() == y; });
|
|
}
|
|
|
|
void RegionPagerBase::UnloadAll() {
|
|
regionList.clear();
|
|
} |