Systems are working correctly, but needs cleaning
This commit is contained in:
+70
-3
@@ -21,12 +21,47 @@
|
||||
*/
|
||||
#include "editor_scene.hpp"
|
||||
|
||||
#include "utility.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
|
||||
using namespace std;
|
||||
|
||||
//-------------------------
|
||||
//Public access members
|
||||
//-------------------------
|
||||
|
||||
EditorScene::EditorScene() {
|
||||
//
|
||||
//32 * 32 sized tiles
|
||||
pager.SetWidth(32*4);
|
||||
pager.SetHeight(32*4);
|
||||
|
||||
pager.SetOnNew([](Region* const ptr){
|
||||
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());
|
||||
});
|
||||
|
||||
sheetList.push_front(TileSheet());
|
||||
TileSheet* sheetOne = &sheetList.front();
|
||||
sheetList.push_front(TileSheet());
|
||||
TileSheet* sheetTwo = &sheetList.front();
|
||||
|
||||
sheetOne->LoadSurface("rsc\\terrain.bmp", 32, 32);
|
||||
sheetTwo->LoadSurface("rsc\\terrain.bmp", 32, 32);
|
||||
|
||||
cout << "--Sheet debug data--" << endl;
|
||||
cout << "TileSheet::rangeEnd: " << TileSheet::GetRangeEnd() << endl;
|
||||
cout << "sheetOne.totalCount: " << sheetOne->GetTotalCount() << endl;
|
||||
cout << "sheetOne.begin: " << sheetOne->GetBegin() << endl;
|
||||
cout << "sheetOne.end: " << sheetOne->GetEnd() << endl;
|
||||
cout << "sheetTwo.totalCount: " << sheetTwo->GetTotalCount() << endl;
|
||||
cout << "sheetTwo.begin: " << sheetTwo->GetBegin() << endl;
|
||||
cout << "sheetTwo.end: " << sheetTwo->GetEnd() << endl;
|
||||
cout << "--end debug data--" << endl;
|
||||
}
|
||||
|
||||
EditorScene::~EditorScene() {
|
||||
@@ -50,7 +85,15 @@ void EditorScene::FrameEnd() {
|
||||
}
|
||||
|
||||
void EditorScene::Render(SDL_Surface* const screen) {
|
||||
//
|
||||
for (auto& regionIter : *pager.GetRegions()) {
|
||||
for (auto& tileIter : *regionIter.GetTiles()) {
|
||||
for (auto& sheetIter : sheetList) {
|
||||
if (sheetIter.InRange(tileIter.tileIndex)) {
|
||||
sheetIter.DrawTo(screen, tileIter.x + regionIter.GetX(), tileIter.y + regionIter.GetY(), tileIter.tileIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------
|
||||
@@ -62,7 +105,31 @@ void EditorScene::MouseMotion(SDL_MouseMotionEvent const& motion) {
|
||||
}
|
||||
|
||||
void EditorScene::MouseButtonDown(SDL_MouseButtonEvent const& button) {
|
||||
//
|
||||
switch(button.button) {
|
||||
case SDL_BUTTON_LEFT: {
|
||||
Region* ptr = pager.GetRegion(
|
||||
snapToBase(pager.GetWidth(), button.x),
|
||||
snapToBase(pager.GetHeight(), button.y)
|
||||
);
|
||||
|
||||
cout << "New Tile: " <<
|
||||
ptr->NewTileA({
|
||||
snapToBase(32, button.x),
|
||||
snapToBase(32, button.y),
|
||||
0,
|
||||
32,
|
||||
32,
|
||||
incrementer
|
||||
})
|
||||
<< endl;
|
||||
;
|
||||
|
||||
if (++incrementer >= 180) {
|
||||
incrementer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void EditorScene::MouseButtonUp(SDL_MouseButtonEvent const& button) {
|
||||
|
||||
@@ -24,6 +24,11 @@
|
||||
|
||||
#include "base_scene.hpp"
|
||||
|
||||
#include "region_pager.hpp"
|
||||
#include "tile_sheet.hpp"
|
||||
|
||||
#include <list>
|
||||
|
||||
class EditorScene : public BaseScene {
|
||||
public:
|
||||
//Public access members
|
||||
@@ -43,6 +48,13 @@ protected:
|
||||
void MouseButtonUp(SDL_MouseButtonEvent const&);
|
||||
void KeyDown(SDL_KeyboardEvent const&);
|
||||
void KeyUp(SDL_KeyboardEvent const&);
|
||||
|
||||
//members
|
||||
RegionPager pager;
|
||||
std::list<TileSheet> sheetList;
|
||||
|
||||
//debugging
|
||||
int incrementer = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+6
-13
@@ -40,18 +40,11 @@ SDL_Surface* TileSheet::LoadSurface(std::string fname, Uint16 w, Uint16 h) {
|
||||
|
||||
//cache the name
|
||||
name = truncatePath(fname);
|
||||
}
|
||||
|
||||
SDL_Surface* TileSheet::SetSurface(SDL_Surface* const ptr, Uint16 w, Uint16 h) {
|
||||
//setup the image
|
||||
image.SetSurface(ptr);
|
||||
image.SetClipW(w);
|
||||
image.SetClipH(h);
|
||||
|
||||
//get the tile counts
|
||||
xCount = image.GetSurface()->w / w;
|
||||
yCount = image.GetSurface()->h / h;
|
||||
totalCount = xCount * yCount;
|
||||
//set the range
|
||||
begin = rangeEnd;
|
||||
end = begin + totalCount;
|
||||
rangeEnd += totalCount;
|
||||
}
|
||||
|
||||
SDL_Surface* TileSheet::GetSurface() {
|
||||
@@ -69,8 +62,8 @@ void TileSheet::DrawTo(SDL_Surface* const dest, int x, int y, int tileIndex) {
|
||||
if (!InRange(tileIndex)) {
|
||||
throw(std::runtime_error("Tile index out of range of Tile Sheet"));
|
||||
}
|
||||
Sint16 clipX = tileIndex % xCount * image.GetClipW();
|
||||
Sint16 clipY = tileIndex / xCount * image.GetClipH();
|
||||
Sint16 clipX = (tileIndex-begin) % xCount * image.GetClipW();
|
||||
Sint16 clipY = (tileIndex-begin) / xCount * image.GetClipH();
|
||||
|
||||
image.SetClipX(clipX);
|
||||
image.SetClipY(clipY);
|
||||
|
||||
@@ -37,7 +37,6 @@ public:
|
||||
//these load/set functions need to be followed by bookkeeping code
|
||||
//w & h are the width & height of individual tiles
|
||||
SDL_Surface* LoadSurface(std::string fname, Uint16 w, Uint16 h);
|
||||
SDL_Surface* SetSurface(SDL_Surface* const, Uint16 w, Uint16 h);
|
||||
SDL_Surface* GetSurface();
|
||||
void FreeSurface();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user