Merge branch 'master' into stable
Even though some parts of the new map system are a stub, I feel confident enough to merge this branch back onto the stable branch. On the whole, I've reduced the complexity of the system, while also allowing acceptable restrictions. The RegionPager class works correctly. The Update() member is empty, but it's still usable. I've removed TileSheetManager, so the maps can only have one tileset each; that's fine. The tiles are voxel integers. The editor needs an entire overhaul. I think some of the GUI components are too complex. The sooner I can implement the map in the main client/server system the better.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -21,39 +21,21 @@
|
|||||||
*/
|
*/
|
||||||
#include "tile_sheet.hpp"
|
#include "tile_sheet.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
void TileSheet::Load(std::string fname, int xc, int yc) {
|
||||||
|
XCount = xc;
|
||||||
void TileSheet::Load(std::string fname, Uint16 w, Uint16 h) {
|
YCount = yc;
|
||||||
//setup the image
|
|
||||||
image.LoadSurface(fname);
|
image.LoadSurface(fname);
|
||||||
image.SetClipW(w);
|
image.SetClipW(image.GetClipW()/XCount);
|
||||||
image.SetClipH(h);
|
image.SetClipH(image.GetClipH()/YCount);
|
||||||
|
|
||||||
//get the tile counts
|
|
||||||
xCount = image.GetSurface()->w / w;
|
|
||||||
yCount = image.GetSurface()->h / h;
|
|
||||||
totalCount = xCount * yCount;
|
|
||||||
|
|
||||||
//set begin & end (usually temporary)
|
|
||||||
begin = 0;
|
|
||||||
end = totalCount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileSheet::Unload() {
|
void TileSheet::Unload() {
|
||||||
image.FreeSurface();
|
image.FreeSurface();
|
||||||
totalCount = xCount = yCount = 0;
|
XCount = YCount = 0;
|
||||||
begin = end = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TileSheet::DrawTo(SDL_Surface* const dest, int x, int y, int tileIndex) {
|
void TileSheet::DrawTo(SDL_Surface* const dest, int x, int y, int tile) {
|
||||||
if (!InRange(tileIndex)) {
|
image.SetClipX(tile % XCount * image.GetClipW());
|
||||||
throw(std::invalid_argument("Tile index out of range"));
|
image.SetClipY(tile / XCount * image.GetClipH());
|
||||||
}
|
|
||||||
Sint16 clipX = (tileIndex-begin) % xCount * image.GetClipW();
|
|
||||||
Sint16 clipY = (tileIndex-begin) / xCount * image.GetClipH();
|
|
||||||
|
|
||||||
image.SetClipX(clipX);
|
|
||||||
image.SetClipY(clipY);
|
|
||||||
|
|
||||||
image.DrawTo(dest, x, y);
|
image.DrawTo(dest, x, y);
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -19,33 +19,33 @@
|
|||||||
* 3. This notice may not be removed or altered from any source
|
* 3. This notice may not be removed or altered from any source
|
||||||
* distribution.
|
* distribution.
|
||||||
*/
|
*/
|
||||||
#ifndef TILESHEETMANAGER_HPP_
|
#ifndef TILESHEET_HPP_
|
||||||
#define TILESHEETMANAGER_HPP_
|
#define TILESHEET_HPP_
|
||||||
|
|
||||||
#include "tile_sheet.hpp"
|
#include "image.hpp"
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
class TileSheetManager {
|
class TileSheet {
|
||||||
public:
|
public:
|
||||||
TileSheetManager() = default;
|
TileSheet() = default;
|
||||||
~TileSheetManager() = default;
|
TileSheet(std::string f, int x, int y) { Load(f, x, y); }
|
||||||
|
~TileSheet() = default;
|
||||||
|
|
||||||
TileSheet* LoadSheet(std::string fname, Uint16 w, Uint16 h);
|
void Load(std::string fname, int XCount, int YCount);
|
||||||
TileSheet* GetSheet(std::string name);
|
void Unload();
|
||||||
TileSheet* GetSheetByIndex(int tileIndex);
|
|
||||||
void UnloadSheet(std::string name);
|
|
||||||
|
|
||||||
void DrawTo(SDL_Surface* const, int x, int y, int tileIndex);
|
void DrawTo(SDL_Surface* const dest, int x, int y, int tile);
|
||||||
|
|
||||||
int SetRangeEnd(int i) { return rangeEnd += i; }
|
//accessors
|
||||||
int GetRangeEnd() const { return rangeEnd; }
|
Image* GetImage() { return ℑ }
|
||||||
|
int GetXCount() { return XCount; }
|
||||||
std::map<std::string, TileSheet>* GetSheetMap() { return &sheetMap; }
|
int GetYCount() { return YCount; }
|
||||||
|
int GetTileW() { return image.GetClipW(); }
|
||||||
|
int GetTileH() { return image.GetClipH(); }
|
||||||
private:
|
private:
|
||||||
std::map<std::string, TileSheet> sheetMap;
|
Image image;
|
||||||
int rangeEnd = 0;
|
int XCount = 0, YCount = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -19,26 +19,12 @@
|
|||||||
* 3. This notice may not be removed or altered from any source
|
* 3. This notice may not be removed or altered from any source
|
||||||
* distribution.
|
* distribution.
|
||||||
*/
|
*/
|
||||||
#include "tile.hpp"
|
#include "map_file_format.hpp"
|
||||||
|
|
||||||
bool operator<(Tile const& lhs, Tile const& rhs) {
|
void MapFileFormat::Load(Region** const ptr, int x, int y) {
|
||||||
//sort by depth -> y -> x
|
//TODO
|
||||||
if (lhs.depth == rhs.depth) {
|
|
||||||
if (lhs.y == rhs.y) {
|
|
||||||
return lhs.x < rhs.x;
|
|
||||||
}
|
|
||||||
return lhs.y < rhs.y;
|
|
||||||
}
|
|
||||||
return lhs.depth < rhs.depth;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator>(Tile const& lhs, Tile const& rhs) {
|
void MapFileFormat::Save(Region* const ptr) {
|
||||||
//wrap the other operator
|
//TODO
|
||||||
return rhs < lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool operator==(Tile const& lhs, Tile const& rhs) {
|
|
||||||
//comparisons work on the location ONLY
|
|
||||||
//this function is redundant as far as the std::set object is concerned
|
|
||||||
return (lhs.x == rhs.x) && (lhs.y == rhs.y) && (lhs.depth == rhs.depth);
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -19,32 +19,17 @@
|
|||||||
* 3. This notice may not be removed or altered from any source
|
* 3. This notice may not be removed or altered from any source
|
||||||
* distribution.
|
* distribution.
|
||||||
*/
|
*/
|
||||||
#ifndef TILE_HPP_
|
#ifndef MAPFILEFORMAT_HPP_
|
||||||
#define TILE_HPP_
|
#define MAPFILEFORMAT_HPP_
|
||||||
|
|
||||||
//explicitly a POD
|
#include "region.hpp"
|
||||||
struct Tile {
|
|
||||||
//position relative to the Region
|
|
||||||
int x, y, depth;
|
|
||||||
|
|
||||||
//graphics
|
class MapFileFormat {
|
||||||
int width, height;
|
public:
|
||||||
int tileIndex;
|
void Load(Region** const, int x, int y);
|
||||||
|
void Save(Region* const);
|
||||||
Tile() = default;
|
private:
|
||||||
Tile(int _x, int _y, int _depth, int _width, int _height, int _tileIndex) {
|
//
|
||||||
//The order of the arguments should be explicit
|
|
||||||
x = _x;
|
|
||||||
y = _y;
|
|
||||||
depth = _depth;
|
|
||||||
width = _width;
|
|
||||||
height = _height;
|
|
||||||
tileIndex = _tileIndex;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
bool operator<(Tile const& lhs, Tile const& rhs);
|
|
||||||
bool operator>(Tile const& lhs, Tile const& rhs);
|
|
||||||
bool operator==(Tile const& lhs, Tile const& rhs);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/* 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 "map_generator.hpp"
|
||||||
|
|
||||||
|
void MapGenerator::Create(Region** const ptr, int width, int height, int depth, int x, int y) {
|
||||||
|
(*ptr) = new Region(width, height, depth, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapGenerator::Unload(Region* const ptr) {
|
||||||
|
delete ptr;
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/* 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.
|
||||||
|
*/
|
||||||
|
#ifndef MAPGENERATOR_HPP_
|
||||||
|
#define MAPGENERATOR_HPP_
|
||||||
|
|
||||||
|
#include "region.hpp"
|
||||||
|
|
||||||
|
class MapGenerator {
|
||||||
|
public:
|
||||||
|
void Create(Region** const, int width, int height, int depth, int x, int y);
|
||||||
|
void Unload(Region* const);
|
||||||
|
private:
|
||||||
|
//
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
+28
-92
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -21,103 +21,39 @@
|
|||||||
*/
|
*/
|
||||||
#include "region.hpp"
|
#include "region.hpp"
|
||||||
|
|
||||||
#include "utility.hpp"
|
Region::Region(int argWidth, int argHeight, int argDepth, int argX, int argY):
|
||||||
|
width(argWidth),
|
||||||
#include <stdexcept>
|
height(argHeight),
|
||||||
#include <sstream>
|
depth(argDepth),
|
||||||
|
x(argX),
|
||||||
Region::Region(int _x, int _y, int _w, int _h):
|
y(argY)
|
||||||
x(_x),
|
|
||||||
y(_y),
|
|
||||||
width(_w),
|
|
||||||
height(_h)
|
|
||||||
{
|
{
|
||||||
//make sure that the region's position lines up
|
tiles = new int**[width];
|
||||||
if (x != snapToBase(width, x) || y != snapToBase(height, y)) {
|
for (int i = 0; i < width; ++i) {
|
||||||
std::ostringstream os;
|
tiles[i] = new int*[height];
|
||||||
os << "Region is unaligned; x: " << x << ", y: " << y << ", width: " << width << ", height: " << height;
|
for (int j = 0; j < height; ++j) {
|
||||||
throw(std::runtime_error(os.str()));
|
tiles[i][j] = new int[depth];
|
||||||
|
for (int k = 0; k < depth; ++k) {
|
||||||
|
tiles[i][j][k] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int Region::NewTileR(Tile const& tile) {
|
Region::~Region() {
|
||||||
//return 1 for overwrite, 0 for insert
|
for (int i = 0; i < width; ++i) {
|
||||||
if (!InBoundsR(tile.x, tile.y)) {
|
for (int j = 0; j < height; j++) {
|
||||||
std::ostringstream os;
|
delete tiles[i][j];
|
||||||
os << "New tile location out of bounds: " <<
|
}
|
||||||
"(" << x << "," << y << ")->" <<
|
delete tiles[i];
|
||||||
"(" << tile.x << "," << tile.y << ")"
|
}
|
||||||
;
|
delete tiles;
|
||||||
throw(std::runtime_error(os.str()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ret = tiles.erase(tile);
|
int Region::SetTile(int x, int y, int z, int v) {
|
||||||
tiles.insert(tile);
|
return tiles[x][y][z] = v;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Tile Region::GetTileR(int tx, int ty, int minDepth) {
|
int Region::GetTile(int x, int y, int z) {
|
||||||
std::set<Tile>::iterator ptr = tiles.begin();
|
return tiles[x][y][z];
|
||||||
|
|
||||||
//skip the tiles that are too deep
|
|
||||||
while(ptr != tiles.end()) {
|
|
||||||
if (ptr->depth >= minDepth) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ptr++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//find the first tile here
|
|
||||||
while(ptr != tiles.end()) {
|
|
||||||
//bounds
|
|
||||||
if ((ptr->x <= tx) && (ptr->y <= ty) && (ptr->x + ptr->width > tx) && (ptr->y + ptr->height > ty)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ptr++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//found it
|
|
||||||
if (ptr != tiles.end()) {
|
|
||||||
return *ptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
//a tileIndex of -1 is an error code, the rest is for show
|
|
||||||
return {0,0,0,-1,-1,-1};
|
|
||||||
}
|
|
||||||
|
|
||||||
int Region::DeleteTileR(Tile const& tile) {
|
|
||||||
if (!InBoundsR(tile.x, tile.y)) {
|
|
||||||
throw(std::runtime_error("Deleted tile location out of bounds"));
|
|
||||||
|
|
||||||
std::ostringstream os;
|
|
||||||
os << "Deleted tile location out of bounds: " <<
|
|
||||||
"(" << x << "," << y << ")->" <<
|
|
||||||
"(" << tile.x << "," << tile.y << ")"
|
|
||||||
;
|
|
||||||
throw(std::runtime_error(os.str()));
|
|
||||||
}
|
|
||||||
//sentinel/error code
|
|
||||||
if (tile.tileIndex == -1) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return tiles.erase(tile);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool operator<(Region const& lhs, Region const& rhs) {
|
|
||||||
//sort by y -> x
|
|
||||||
if (lhs.y == rhs.y) {
|
|
||||||
return lhs.x < rhs.x;
|
|
||||||
}
|
|
||||||
return lhs.y < rhs.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool operator>(Region const& lhs, Region const& rhs) {
|
|
||||||
//wrap the other operator
|
|
||||||
return rhs < lhs;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool operator==(Region const& lhs, Region const& rhs) {
|
|
||||||
//comparisons work on the location ONLY
|
|
||||||
//this function is redundant as far as the std::set object is concerned
|
|
||||||
return (lhs.x == rhs.x) && (lhs.y == rhs.y);
|
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-80
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -22,91 +22,29 @@
|
|||||||
#ifndef REGION_HPP_
|
#ifndef REGION_HPP_
|
||||||
#define REGION_HPP_
|
#define REGION_HPP_
|
||||||
|
|
||||||
#include "tile.hpp"
|
|
||||||
|
|
||||||
#include <set>
|
|
||||||
|
|
||||||
/* A single section of the map.
|
|
||||||
* This class stores the tiles relative to it's own position, but
|
|
||||||
* there are functions for referencing the tiles' absolute position.
|
|
||||||
* These functions simply wrap the normal functions.
|
|
||||||
*/
|
|
||||||
class Region {
|
class Region {
|
||||||
public:
|
public:
|
||||||
Region() = delete;
|
Region() = delete;
|
||||||
Region(int x, int y, int width, int height);
|
Region(int width, int height, int depth, int x, int y);
|
||||||
~Region() = default;
|
~Region();
|
||||||
|
|
||||||
//create and insert a new tile, overwriting an existing tile at that location
|
int SetTile(int x, int y, int z, int v);
|
||||||
int NewTileR(Tile const& tile);
|
int GetTile(int x, int y, int z);
|
||||||
int NewTileA(Tile const& tile) {
|
|
||||||
//these can change, if the Tile class is changed
|
|
||||||
return NewTileR({
|
|
||||||
tile.x - x,
|
|
||||||
tile.y - y,
|
|
||||||
tile.depth,
|
|
||||||
tile.width,
|
|
||||||
tile.height,
|
|
||||||
tile.tileIndex
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//find the first tile at this location, with the specified minimum depth
|
|
||||||
Tile GetTileR(int tx, int ty, int minDepth);
|
|
||||||
Tile GetTileA(int tx, int ty, int minDepth) {
|
|
||||||
return GetTileR(tx - x, ty - y, minDepth);
|
|
||||||
}
|
|
||||||
|
|
||||||
//wrap the other delete functions
|
|
||||||
int DeleteTileR(int tx, int ty, int minDepth) {
|
|
||||||
return DeleteTileR(GetTileR(tx, ty, minDepth));
|
|
||||||
}
|
|
||||||
int DeleteTileA(int tx, int ty, int minDepth) {
|
|
||||||
//explicitly skip one function call by adjusting from A to R
|
|
||||||
return DeleteTileR(GetTileR(tx - x, ty - y, minDepth));
|
|
||||||
}
|
|
||||||
|
|
||||||
//delete the specified tile
|
|
||||||
int DeleteTileR(Tile const& tile);
|
|
||||||
int DeleteTileA(Tile const& tile) {
|
|
||||||
//these can change, if the Tile class is changed
|
|
||||||
return DeleteTileR({
|
|
||||||
tile.x - x,
|
|
||||||
tile.y - y,
|
|
||||||
tile.depth,
|
|
||||||
tile.width,
|
|
||||||
tile.height,
|
|
||||||
tile.tileIndex
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
//find if the specified location exists within the region's bounds
|
|
||||||
bool InBoundsR(int i, int j) {
|
|
||||||
return (i >= 0) && (j >= 0) && (i < width) && (j < height);
|
|
||||||
}
|
|
||||||
bool InBoundsA(int i, int j) {
|
|
||||||
return InBoundsR(i - x, j - y);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Raw accessors & mutators
|
|
||||||
int GetX() const { return x; }
|
|
||||||
int GetY() const { return y; }
|
|
||||||
int GetWidth() const { return width; }
|
|
||||||
int GetHeight() const { return height; }
|
|
||||||
|
|
||||||
std::set<Tile>* GetTiles() { return &tiles; }
|
|
||||||
|
|
||||||
//sorting the regions by the locations
|
|
||||||
friend bool operator<(Region const& lhs, Region const& rhs);
|
|
||||||
friend bool operator>(Region const& lhs, Region const& rhs);
|
|
||||||
friend bool operator==(Region const& lhs, Region const& rhs);
|
|
||||||
|
|
||||||
|
//accessors
|
||||||
|
int GetWidth() { return width; }
|
||||||
|
int GetHeight() { return height; }
|
||||||
|
int GetDepth() { return depth; }
|
||||||
|
int GetX() { return x; }
|
||||||
|
int GetY() { return y; }
|
||||||
private:
|
private:
|
||||||
int const x;
|
const int width;
|
||||||
int const y;
|
const int height;
|
||||||
int const width;
|
const int depth;
|
||||||
int const height;
|
const int x;
|
||||||
std::set<Tile> tiles;
|
const int y;
|
||||||
|
|
||||||
|
int*** tiles = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+35
-88
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -23,99 +23,46 @@
|
|||||||
|
|
||||||
#include "utility.hpp"
|
#include "utility.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
RegionPagerBase::RegionPagerBase(int argWidth, int argHeight, int argDepth):
|
||||||
#include <string>
|
regionWidth(argWidth),
|
||||||
|
regionHeight(argHeight),
|
||||||
RegionPager::RegionPager() {
|
regionDepth(argDepth)
|
||||||
//
|
{
|
||||||
|
//EMPTY
|
||||||
}
|
}
|
||||||
|
|
||||||
RegionPager::~RegionPager() {
|
RegionPagerBase::~RegionPagerBase() {
|
||||||
if (onDelete) {
|
//EMPTY
|
||||||
for (auto& i : regionList) {
|
|
||||||
onDelete(&i);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int RegionPagerBase::SetTile(int x, int y, int z, int v) {
|
||||||
|
Region* ptr = GetRegion(x, y);
|
||||||
|
return ptr->SetTile(x - ptr->GetX(), y - ptr->GetY(), z, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
int RegionPagerBase::GetTile(int x, int y, int z) {
|
||||||
|
Region* ptr = GetRegion(x, y);
|
||||||
|
return ptr->GetTile(x - ptr->GetX(), y - ptr->GetY(), z);
|
||||||
|
}
|
||||||
|
|
||||||
|
Region* RegionPagerBase::GetRegion(int x, int y) {
|
||||||
|
//snap the coords
|
||||||
|
x = snapToBase(regionWidth, x);
|
||||||
|
y = snapToBase(regionHeight, y);
|
||||||
|
|
||||||
|
//find the region
|
||||||
|
for (std::list<Region*>::iterator it = regionList.begin(); it != regionList.end(); it++) {
|
||||||
|
if ((*it)->GetX() == x && (*it)->GetY() == y) {
|
||||||
|
return *it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Region* RegionPager::NewRegion(int x, int y) {
|
//get the region by other means
|
||||||
for (auto& i : regionList) {
|
Region* ptr = LoadRegion(x, y);
|
||||||
if (i.GetX() == x && i.GetY() == y) {
|
if (ptr) return ptr;
|
||||||
throw(std::runtime_error("Duplicate Regions detected"));
|
return CreateRegion(x, y);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
regionList.push_front({x, y, regionWidth, regionHeight});
|
void RegionPagerBase::Update() {
|
||||||
if (onNew) {
|
//TODO
|
||||||
onNew(®ionList.front());
|
|
||||||
}
|
|
||||||
return ®ionList.front();
|
|
||||||
}
|
|
||||||
|
|
||||||
Region* RegionPager::GetRegion(int x, int y) {
|
|
||||||
for (auto& i : regionList) {
|
|
||||||
if (i.GetX() == x && i.GetY() == y) {
|
|
||||||
return &i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//create, insert and return
|
|
||||||
regionList.push_front({x, y, regionWidth, regionHeight});
|
|
||||||
if (onNew) {
|
|
||||||
onNew(®ionList.front());
|
|
||||||
}
|
|
||||||
return ®ionList.front();
|
|
||||||
}
|
|
||||||
|
|
||||||
void RegionPager::DeleteRegion(int x, int y) {
|
|
||||||
for (std::list<Region>::iterator i = regionList.begin(); i != regionList.end(); i++) {
|
|
||||||
if (i->GetX() == x && i->GetY() == y) {
|
|
||||||
if (onDelete) {
|
|
||||||
onDelete(&(*i));
|
|
||||||
}
|
|
||||||
regionList.erase(i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void RegionPager::DrawTo(SDL_Surface* const dest, TileSheetManager* const sheetMgr, int camX, int camY) {
|
|
||||||
for (auto& regionIter : regionList) {
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
//draw the region's location
|
|
||||||
SDL_Rect box = {
|
|
||||||
Sint16(regionIter.GetX() - camX),
|
|
||||||
Sint16(regionIter.GetY() - camY),
|
|
||||||
Uint16(regionIter.GetWidth()),
|
|
||||||
Uint16(regionIter.GetHeight())
|
|
||||||
};
|
|
||||||
SDL_FillRect(dest, &box, SDL_MapRGB(dest->format, 10, 10, 20));
|
|
||||||
#endif
|
|
||||||
|
|
||||||
//draw each tile
|
|
||||||
for (auto& tileIter : *regionIter.GetTiles()) {
|
|
||||||
sheetMgr->DrawTo(
|
|
||||||
dest,
|
|
||||||
tileIter.x + regionIter.GetX() - camX,
|
|
||||||
tileIter.y + regionIter.GetY() - camY,
|
|
||||||
tileIter.tileIndex
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void RegionPager::Prune(int left, int top, int right, int bottom) {
|
|
||||||
std::list<Region>::iterator it = regionList.begin();
|
|
||||||
|
|
||||||
while(it != regionList.end()) {
|
|
||||||
if (it->GetX() >= right || it->GetY() >= bottom || it->GetX() + it->GetWidth() < left || it->GetY() + it->GetHeight() < top) {
|
|
||||||
if (onDelete) {
|
|
||||||
onDelete(&(*it));
|
|
||||||
}
|
|
||||||
regionList.erase(it);
|
|
||||||
it = regionList.begin();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
it++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+98
-28
@@ -1,4 +1,4 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
/* Copyright: (c) Kayne Ruse 2014
|
||||||
*
|
*
|
||||||
* This software is provided 'as-is', without any express or implied
|
* This software is provided 'as-is', without any express or implied
|
||||||
* warranty. In no event will the authors be held liable for any damages
|
* warranty. In no event will the authors be held liable for any damages
|
||||||
@@ -23,47 +23,117 @@
|
|||||||
#define REGIONPAGER_HPP_
|
#define REGIONPAGER_HPP_
|
||||||
|
|
||||||
#include "region.hpp"
|
#include "region.hpp"
|
||||||
#include "tile_sheet_manager.hpp"
|
#include "utility.hpp"
|
||||||
|
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
class RegionPager {
|
class RegionPagerBase {
|
||||||
public:
|
public:
|
||||||
//for simplicity and consistency
|
RegionPagerBase() = delete;
|
||||||
typedef void (*regionCallback_t)(Region* const);
|
RegionPagerBase(int regionWidth, int regionHeight, int regionDepth);
|
||||||
|
virtual ~RegionPagerBase();
|
||||||
|
|
||||||
RegionPager();
|
int SetTile(int x, int y, int z, int v);
|
||||||
~RegionPager();
|
int GetTile(int x, int y, int z);
|
||||||
|
|
||||||
|
void Update();
|
||||||
|
|
||||||
//these parameters MUST be multiples of the width & height
|
|
||||||
Region* NewRegion(int x, int y);
|
|
||||||
Region* GetRegion(int x, int y);
|
Region* GetRegion(int x, int y);
|
||||||
void DeleteRegion(int x, int y);
|
|
||||||
|
|
||||||
//call this to draw to the screen
|
//interface
|
||||||
void DrawTo(SDL_Surface* const, TileSheetManager* const, int camX, int camY);
|
virtual Region* LoadRegion(int x, int y) = 0;
|
||||||
|
virtual Region* SaveRegion(int x, int y) = 0;
|
||||||
|
virtual Region* CreateRegion(int x, int y) = 0;
|
||||||
|
virtual void UnloadRegion(int x, int y) = 0;
|
||||||
|
|
||||||
//callback hooks
|
//accessors
|
||||||
void SetOnNew(regionCallback_t f) { onNew = f; }
|
int GetRegionWidth() { return regionWidth; }
|
||||||
void SetOnDelete(regionCallback_t f) { onDelete = f; }
|
int GetRegionHeight() { return regionHeight; }
|
||||||
|
int GetRegionDepth() { return regionDepth; }
|
||||||
|
protected:
|
||||||
|
const int regionWidth;
|
||||||
|
const int regionHeight;
|
||||||
|
const int regionDepth;
|
||||||
|
std::list<Region*> regionList;
|
||||||
|
};
|
||||||
|
|
||||||
//params: Absolute values
|
template<typename MapGenerator, typename MapFileFormat>
|
||||||
void Prune(int left, int top, int right, int bottom);
|
class RegionPager : public RegionPagerBase {
|
||||||
|
public:
|
||||||
|
RegionPager() = delete;
|
||||||
|
RegionPager(int w, int h, int d):
|
||||||
|
RegionPagerBase(w, h, d)
|
||||||
|
{
|
||||||
|
//EMPTY
|
||||||
|
}
|
||||||
|
~RegionPager() = default;
|
||||||
|
|
||||||
//accessors and mutators
|
Region* LoadRegion(int x, int y) {
|
||||||
int SetWidth(int i) { return regionWidth = i; }
|
//snap the coords
|
||||||
int SetHeight(int i) { return regionHeight = i; }
|
x = snapToBase(regionWidth, x);
|
||||||
|
y = snapToBase(regionHeight, y);
|
||||||
|
|
||||||
int GetWidth() const { return regionWidth; }
|
//load the region if possible
|
||||||
int GetHeight() const { return regionHeight; }
|
Region* ptr = nullptr;
|
||||||
|
format.Load(&ptr, x, y);
|
||||||
|
if (ptr) {
|
||||||
|
regionList.push_back(ptr);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
std::list<Region>* GetRegions() { return ®ionList; }
|
Region* SaveRegion(int x, int y) {
|
||||||
private:
|
//snap the coords
|
||||||
std::list<Region> regionList;
|
x = snapToBase(regionWidth, x);
|
||||||
int regionWidth = 0, regionHeight = 0;
|
y = snapToBase(regionHeight, y);
|
||||||
|
|
||||||
regionCallback_t onNew = nullptr;
|
//find & save the region
|
||||||
regionCallback_t onDelete = nullptr;
|
for (std::list<Region*>::iterator it = regionList.begin(); it != regionList.end(); it++) {
|
||||||
|
if ((*it)->GetX() == x && (*it)->GetY() == y) {
|
||||||
|
format.Save(*it);
|
||||||
|
return *it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Region* CreateRegion(int x, int y) {
|
||||||
|
//snap the coords
|
||||||
|
x = snapToBase(regionWidth, x);
|
||||||
|
y = snapToBase(regionHeight, y);
|
||||||
|
|
||||||
|
//create and push the object
|
||||||
|
Region* ptr = nullptr;
|
||||||
|
generator.Create(&ptr, regionWidth, regionHeight, regionDepth, x, y);
|
||||||
|
regionList.push_back(ptr);
|
||||||
|
return ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnloadRegion(int x, int y) {
|
||||||
|
//snap the coords
|
||||||
|
x = snapToBase(regionWidth, x);
|
||||||
|
y = snapToBase(regionHeight, y);
|
||||||
|
|
||||||
|
for (std::list<Region*>::iterator it = regionList.begin(); it != regionList.end(); /* EMPTY */) {
|
||||||
|
if ((*it)->GetX() == x && (*it)->GetY() == y) {
|
||||||
|
generator.Unload(*it);
|
||||||
|
regionList.erase(it);
|
||||||
|
|
||||||
|
//reset the loop, because of reasons
|
||||||
|
it = regionList.begin();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//accessors
|
||||||
|
MapGenerator* GetGenerator() { return &generator; }
|
||||||
|
MapFileFormat* GetFormat() { return &format; }
|
||||||
|
protected:
|
||||||
|
MapGenerator generator;
|
||||||
|
MapFileFormat format;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,70 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
|
||||||
*
|
|
||||||
* 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.
|
|
||||||
*/
|
|
||||||
#ifndef TILESHEET_HPP_
|
|
||||||
#define TILESHEET_HPP_
|
|
||||||
|
|
||||||
#include "image.hpp"
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
/* The TileSheet class is used for drawing tiles of the map to the screen.
|
|
||||||
* This class also tracks the range of the tile images.
|
|
||||||
*/
|
|
||||||
class TileSheet {
|
|
||||||
public:
|
|
||||||
TileSheet() = default;
|
|
||||||
~TileSheet() = default;
|
|
||||||
|
|
||||||
//these load/set functions need to be followed by bookkeeping code
|
|
||||||
//w & h are the width & height of individual tiles
|
|
||||||
//TODO: rename these
|
|
||||||
void Load(std::string fname, Uint16 w, Uint16 h);
|
|
||||||
void Unload();
|
|
||||||
|
|
||||||
void DrawTo(SDL_Surface* const dest, int x, int y, int tileIndex);
|
|
||||||
|
|
||||||
bool InRange(int i) { return i >= begin && i < end; }
|
|
||||||
|
|
||||||
//accessors and mutators
|
|
||||||
Image* GetImage() { return ℑ }
|
|
||||||
|
|
||||||
int GetTileW() const { return image.GetClipW(); }
|
|
||||||
int GetTileH() const { return image.GetClipH(); }
|
|
||||||
|
|
||||||
int GetTotalCount() const { return totalCount; }
|
|
||||||
int GetXCount() const { return xCount; }
|
|
||||||
int GetYCount() const { return yCount; }
|
|
||||||
|
|
||||||
int SetBegin(int i) { return begin = i; }
|
|
||||||
int SetEnd(int i) { return end = i; }
|
|
||||||
|
|
||||||
int GetBegin() const { return begin; }
|
|
||||||
int GetEnd() const { return end; }
|
|
||||||
private:
|
|
||||||
Image image;
|
|
||||||
|
|
||||||
//these are generated and used by internal processes
|
|
||||||
int totalCount = 0, xCount = 0, yCount = 0;
|
|
||||||
int begin = -1, end = -1;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
/* Copyright: (c) Kayne Ruse 2013
|
|
||||||
*
|
|
||||||
* 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 "tile_sheet_manager.hpp"
|
|
||||||
|
|
||||||
#include "utility.hpp"
|
|
||||||
|
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
TileSheet* TileSheetManager::LoadSheet(std::string fname, Uint16 w, Uint16 h) {
|
|
||||||
//get the key
|
|
||||||
std::string key = truncatePath(fname);
|
|
||||||
|
|
||||||
//don't override what's already here
|
|
||||||
if (sheetMap.find(key) != sheetMap.end()) {
|
|
||||||
throw(std::runtime_error("Cannot load duplicate tile sheets"));
|
|
||||||
}
|
|
||||||
|
|
||||||
//load & setup the sheet object
|
|
||||||
sheetMap[key].Load(fname, w, h);
|
|
||||||
sheetMap[key].SetBegin(rangeEnd);
|
|
||||||
rangeEnd += sheetMap[key].GetTotalCount();
|
|
||||||
sheetMap[key].SetEnd(rangeEnd);
|
|
||||||
|
|
||||||
//you can modify the object, say, during the save & load routines...
|
|
||||||
return &sheetMap[key];
|
|
||||||
}
|
|
||||||
|
|
||||||
TileSheet* TileSheetManager::GetSheet(std::string name) {
|
|
||||||
return &sheetMap.at(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
TileSheet* TileSheetManager::GetSheetByIndex(int tileIndex) {
|
|
||||||
for (auto& it : sheetMap) {
|
|
||||||
if (it.second.InRange(tileIndex)) {
|
|
||||||
return &it.second;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void TileSheetManager::UnloadSheet(std::string name) {
|
|
||||||
sheetMap.erase(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void TileSheetManager::DrawTo(SDL_Surface* const dest, int x, int y, int tileIndex) {
|
|
||||||
for (auto& it : sheetMap) {
|
|
||||||
if (it.second.InRange(tileIndex)) {
|
|
||||||
it.second.DrawTo(dest, x, y, tileIndex);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//No matching tile index
|
|
||||||
throw(std::invalid_argument("Tile index is out of range of all tile sheets"));
|
|
||||||
}
|
|
||||||
+2
-2
@@ -27,9 +27,9 @@ int snapToBase(int base, int x) {
|
|||||||
//snap to a grid
|
//snap to a grid
|
||||||
if (x < 0) {
|
if (x < 0) {
|
||||||
x++;
|
x++;
|
||||||
return x - x % base - base;
|
return x / base * base - base;
|
||||||
}
|
}
|
||||||
return x - x % base;
|
return x / base * base;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string truncatePath(std::string pathname) {
|
std::string truncatePath(std::string pathname) {
|
||||||
|
|||||||
+21
-57
@@ -34,7 +34,8 @@ using namespace std;
|
|||||||
//-------------------------
|
//-------------------------
|
||||||
|
|
||||||
EditorScene::EditorScene(ConfigUtility* const arg1):
|
EditorScene::EditorScene(ConfigUtility* const arg1):
|
||||||
config(*arg1)
|
config(*arg1),
|
||||||
|
pager(20, 20, 3)
|
||||||
{
|
{
|
||||||
//create the debugging "window"
|
//create the debugging "window"
|
||||||
debugInfo.CreateSurface(256, 256);
|
debugInfo.CreateSurface(256, 256);
|
||||||
@@ -50,25 +51,13 @@ EditorScene::EditorScene(ConfigUtility* const arg1):
|
|||||||
menuBar.SetImage(&buttonImage);
|
menuBar.SetImage(&buttonImage);
|
||||||
|
|
||||||
menuBar.SetEntries({
|
menuBar.SetEntries({
|
||||||
{"File", "-New", "-Open", "-Save", "-Save As...", "-Close", "Exit"},
|
{"File", "New", "Open", "Save", "Save As...", "Close", "Exit"},
|
||||||
{"Edit", "-Set Tile", "-Load Sheet", "-Delete Sheet", "-Metadata", "-Run Script"},
|
{"Edit", "Set Tile", "Load Sheet", "Delete Sheet", "Metadata", "Run Script"},
|
||||||
{"Debugging", "Debug On", "Debug Off", "Toggle Debug", "Testificate"}
|
{"Debugging", "Debug On", "Debug Off", "Toggle Debug", "Testificate"}
|
||||||
});
|
});
|
||||||
|
|
||||||
//setup the pager
|
//debug
|
||||||
pager.SetOnNew([](Region* const ptr){
|
tsheet.Load("rsc\\graphics\\tilesets\\sand.bmp", 12, 3);
|
||||||
printf("New Region: %d, %d\n", ptr->GetX(), ptr->GetY());
|
|
||||||
});
|
|
||||||
|
|
||||||
pager.SetOnDelete([](Region* const ptr){
|
|
||||||
printf("Delete Region: %d, %d\n", ptr->GetX(), ptr->GetY());
|
|
||||||
});
|
|
||||||
|
|
||||||
//Set a resonable size for the regions
|
|
||||||
pager.SetWidth(32*4);
|
|
||||||
pager.SetHeight(32*4);
|
|
||||||
|
|
||||||
sheetMgr.LoadSheet(config["dir.tilesets"] + "terrain.bmp", 32, 32);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EditorScene::~EditorScene() {
|
EditorScene::~EditorScene() {
|
||||||
@@ -84,7 +73,7 @@ void EditorScene::FrameStart() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EditorScene::Update(double delta) {
|
void EditorScene::Update(double delta) {
|
||||||
pager.Prune(camera.x, camera.y, camera.x + GetScreen()->w, camera.y + GetScreen()->h);
|
//
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorScene::FrameEnd() {
|
void EditorScene::FrameEnd() {
|
||||||
@@ -92,8 +81,19 @@ void EditorScene::FrameEnd() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EditorScene::Render(SDL_Surface* const screen) {
|
void EditorScene::Render(SDL_Surface* const screen) {
|
||||||
//draw the map
|
//debug
|
||||||
pager.DrawTo(screen, &sheetMgr, camera.x, camera.y);
|
for (int i = 0; i < pager.GetRegionWidth()*2; i++) {
|
||||||
|
for (int j = 0; j < pager.GetRegionHeight()*2; j++) {
|
||||||
|
for (int k = 0; k < pager.GetRegionDepth(); k++) {
|
||||||
|
tsheet.DrawTo(
|
||||||
|
screen,
|
||||||
|
i*tsheet.GetTileW()-camera.x,
|
||||||
|
j*tsheet.GetTileH()-camera.y,
|
||||||
|
pager.GetTile(i,j,k)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//draw a big bar across the top
|
//draw a big bar across the top
|
||||||
buttonImage.SetClipY(0);
|
buttonImage.SetClipY(0);
|
||||||
@@ -130,24 +130,6 @@ void EditorScene::DrawToDebugInfo(std::string str, int line) {
|
|||||||
void EditorScene::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
void EditorScene::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||||
menuBar.MouseMotion(motion);
|
menuBar.MouseMotion(motion);
|
||||||
|
|
||||||
if (motion.state & SDL_BUTTON_LMASK && motion.y >= buttonImage.GetClipH()) {
|
|
||||||
Region* regionPtr = pager.GetRegion(
|
|
||||||
snapToBase(pager.GetWidth(), motion.x + camera.x),
|
|
||||||
snapToBase(pager.GetHeight(), motion.y + camera.y)
|
|
||||||
);
|
|
||||||
|
|
||||||
TileSheet* sheetPtr = sheetMgr.GetSheetByIndex(tileCounter);
|
|
||||||
|
|
||||||
regionPtr->NewTileA({
|
|
||||||
snapToBase(sheetPtr->GetTileW(), motion.x + camera.x), //x
|
|
||||||
snapToBase(sheetPtr->GetTileH(), motion.y + camera.y), //y
|
|
||||||
0, //depth
|
|
||||||
sheetPtr->GetTileW(), //width
|
|
||||||
sheetPtr->GetTileH(), //height
|
|
||||||
tileCounter++ //value
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (motion.state & SDL_BUTTON_RMASK) {
|
if (motion.state & SDL_BUTTON_RMASK) {
|
||||||
camera.x -= motion.xrel;
|
camera.x -= motion.xrel;
|
||||||
camera.y -= motion.yrel;
|
camera.y -= motion.yrel;
|
||||||
@@ -156,24 +138,6 @@ void EditorScene::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
|||||||
|
|
||||||
void EditorScene::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
void EditorScene::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
||||||
menuBar.MouseButtonDown(button);
|
menuBar.MouseButtonDown(button);
|
||||||
|
|
||||||
if (button.button == SDL_BUTTON_LEFT && button.y >= buttonImage.GetClipH()) {
|
|
||||||
Region* regionPtr = pager.GetRegion(
|
|
||||||
snapToBase(pager.GetWidth(), button.x + camera.x),
|
|
||||||
snapToBase(pager.GetHeight(), button.y + camera.y)
|
|
||||||
);
|
|
||||||
|
|
||||||
TileSheet* sheetPtr = sheetMgr.GetSheetByIndex(tileCounter);
|
|
||||||
|
|
||||||
regionPtr->NewTileA({
|
|
||||||
snapToBase(sheetPtr->GetTileW(), button.x + camera.x), //x
|
|
||||||
snapToBase(sheetPtr->GetTileH(), button.y + camera.y), //y
|
|
||||||
0, //depth
|
|
||||||
sheetPtr->GetTileW(), //width
|
|
||||||
sheetPtr->GetTileH(), //height
|
|
||||||
tileCounter++ //value
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorScene::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
void EditorScene::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||||
@@ -205,7 +169,7 @@ void EditorScene::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 5: {
|
case 5: {
|
||||||
//Quit
|
//EXIT
|
||||||
SDL_Event e;
|
SDL_Event e;
|
||||||
e.type = SDL_QUIT;
|
e.type = SDL_QUIT;
|
||||||
SDL_PushEvent(&e);
|
SDL_PushEvent(&e);
|
||||||
|
|||||||
@@ -24,15 +24,15 @@
|
|||||||
|
|
||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
#include "region_pager.hpp"
|
|
||||||
#include "tile_sheet_manager.hpp"
|
|
||||||
|
|
||||||
#include "config_utility.hpp"
|
#include "config_utility.hpp"
|
||||||
#include "image.hpp"
|
#include "image.hpp"
|
||||||
#include "raster_font.hpp"
|
#include "raster_font.hpp"
|
||||||
#include "menu_bar.hpp"
|
#include "menu_bar.hpp"
|
||||||
|
|
||||||
//#include "map_loader.hpp"
|
#include "region_pager.hpp"
|
||||||
|
#include "map_generator.hpp"
|
||||||
|
#include "map_file_format.hpp"
|
||||||
|
#include "tile_sheet.hpp"
|
||||||
|
|
||||||
class EditorScene : public BaseScene {
|
class EditorScene : public BaseScene {
|
||||||
public:
|
public:
|
||||||
@@ -62,19 +62,16 @@ protected:
|
|||||||
Image debugInfo;
|
Image debugInfo;
|
||||||
bool debugOpen = true;
|
bool debugOpen = true;
|
||||||
|
|
||||||
RegionPager pager;
|
|
||||||
TileSheetManager sheetMgr;
|
|
||||||
|
|
||||||
RasterFont font;
|
RasterFont font;
|
||||||
Image buttonImage;
|
Image buttonImage;
|
||||||
|
|
||||||
MenuBar menuBar;
|
MenuBar menuBar;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
int x = 0, y = 0;
|
int x = 0, y = 0;
|
||||||
} camera;
|
} camera;
|
||||||
|
|
||||||
int tileCounter = 0;
|
RegionPager<MapGenerator, MapFileFormat> pager;
|
||||||
|
TileSheet tsheet;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -33,18 +33,7 @@ using std::endl;
|
|||||||
TestificateScene::TestificateScene(ConfigUtility* const arg1):
|
TestificateScene::TestificateScene(ConfigUtility* const arg1):
|
||||||
config(*arg1)
|
config(*arg1)
|
||||||
{
|
{
|
||||||
sheetMgr.LoadSheet(config["dir.tilesets"] + "grass.bmp", 32, 32);
|
//
|
||||||
sheetMgr.LoadSheet(config["dir.tilesets"] + "longgrass.bmp", 32, 32);
|
|
||||||
sheetMgr.LoadSheet(config["dir.tilesets"] + "sand.bmp", 32, 32);
|
|
||||||
sheetMgr.LoadSheet(config["dir.tilesets"] + "dirt.bmp", 32, 32);
|
|
||||||
sheetMgr.LoadSheet(config["dir.tilesets"] + "water.bmp", 32, 32);
|
|
||||||
|
|
||||||
cout << "Range End: " << sheetMgr.GetRangeEnd() << endl;
|
|
||||||
|
|
||||||
pager.SetWidth(128);
|
|
||||||
pager.SetHeight(128);
|
|
||||||
|
|
||||||
pager.GetRegion(0, 0)->NewTileR({0, 0, 0, 32, 32, 0});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TestificateScene::~TestificateScene() {
|
TestificateScene::~TestificateScene() {
|
||||||
@@ -68,12 +57,7 @@ void TestificateScene::FrameEnd() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TestificateScene::Render(SDL_Surface* const screen) {
|
void TestificateScene::Render(SDL_Surface* const screen) {
|
||||||
//dump all tile graphics to the screen
|
//
|
||||||
for (int i = 0; i < sheetMgr.GetRangeEnd(); i++) {
|
|
||||||
sheetMgr.DrawTo(screen, i * 32 % screen->w, i * 32 / screen->w * 32, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
// pager.DrawTo(screen, &sheetMgr, 0, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------
|
//-------------------------
|
||||||
|
|||||||
@@ -25,8 +25,6 @@
|
|||||||
#include "base_scene.hpp"
|
#include "base_scene.hpp"
|
||||||
|
|
||||||
#include "config_utility.hpp"
|
#include "config_utility.hpp"
|
||||||
#include "tile_Sheet_manager.hpp"
|
|
||||||
#include "region_pager.hpp"
|
|
||||||
|
|
||||||
class TestificateScene : public BaseScene {
|
class TestificateScene : public BaseScene {
|
||||||
public:
|
public:
|
||||||
@@ -50,10 +48,6 @@ protected:
|
|||||||
|
|
||||||
//globals
|
//globals
|
||||||
ConfigUtility& config;
|
ConfigUtility& config;
|
||||||
|
|
||||||
//members
|
|
||||||
TileSheetManager sheetMgr;
|
|
||||||
RegionPager pager;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user