Mario: editor - move all global vars into a single struct
This commit is contained in:
parent
d80ae9a4e2
commit
d04cbea02d
440
mario/editor.cpp
440
mario/editor.cpp
@ -21,142 +21,154 @@
|
|||||||
#include "editor_visitor.hpp"
|
#include "editor_visitor.hpp"
|
||||||
#include "tool_box.hpp"
|
#include "tool_box.hpp"
|
||||||
|
|
||||||
#define MAP_WIDTH 50
|
#define MAP_WIDTH 18
|
||||||
#define MAP_HEIGHT 16
|
#define MAP_HEIGHT 16
|
||||||
|
|
||||||
|
#define QUIT_FLAG 0x00000001
|
||||||
|
#define UPDATE_FLAG 0x00000002
|
||||||
|
#define MAP_LEFT_ENABLED_FLAG 0x00000004
|
||||||
|
#define MAP_RIGHT_ENABLED_FLAG 0x00000008
|
||||||
|
#define TOOL_LEFT_ENABLED_FLAG 0x00000010
|
||||||
|
#define TOOL_RIGHT_ENABLED_FLAG 0x00000020
|
||||||
|
|
||||||
struct MouseInfo {
|
struct MouseInfo {
|
||||||
enum Index {
|
uint64_t cur_flags;
|
||||||
CUR_FLAGS = 0,
|
uint64_t prev_flags;
|
||||||
PREV_FLAGS = 1,
|
SDLPP::Vec2D< int > edit_box;
|
||||||
EDIT_BOX = 2,
|
SDLPP::Vec2D< int > tool_box;
|
||||||
TOOL_BOX = 3,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MapInfo {
|
struct MapInfo {
|
||||||
enum Value {
|
int cur_page;
|
||||||
CUR_PAGE = 0,
|
int max_page;
|
||||||
MAX_PAGE = 1,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ToolInfo {
|
struct ToolInfo {
|
||||||
enum Value {
|
uint64_t index;
|
||||||
INDEX = 0,
|
int cur_page;
|
||||||
CUR_PAGE = 1,
|
int max_page;
|
||||||
MAX_PAGE = 2,
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
std::shared_ptr< SDLPP::Renderer > g_renderer = nullptr;
|
struct GlobalVars {
|
||||||
bool g_quit = false;
|
MouseInfo mouse;
|
||||||
bool g_update_size = false;
|
MapInfo map;
|
||||||
std::vector< mapColumnType > g_objects = {};
|
ToolInfo tool;
|
||||||
std::vector< std::shared_ptr< SDLPP::RenderObject > > g_tools{};
|
uint64_t flags;
|
||||||
std::shared_ptr< SDLPP::RenderObject > g_current_tool = nullptr;
|
std::vector< mapColumnType > objects;
|
||||||
|
std::vector< std::shared_ptr< SDLPP::RenderObject > > tools;
|
||||||
|
std::shared_ptr< SDLPP::RenderObject > current_tool;
|
||||||
|
std::shared_ptr< SDLPP::Texture > translucent_terrain_texture;
|
||||||
|
std::shared_ptr< SDLPP::Texture > translucent_mario_texture;
|
||||||
|
std::shared_ptr< SDLPP::RenderObject > mario;
|
||||||
|
SDLPP::Vec2D< int > mario_pos;
|
||||||
|
};
|
||||||
|
|
||||||
std::mutex g_destruction_mutex;
|
GlobalVars global_vars;
|
||||||
|
std::mutex destruction_mutex;
|
||||||
// current mouse flags, previous mouse flags, selected edit box, selected tool
|
|
||||||
// box
|
|
||||||
std::tuple< uint64_t, uint64_t, SDLPP::Vec2D< int >, SDLPP::Vec2D< int > >
|
|
||||||
g_mouse_info;
|
|
||||||
// current page, max page
|
|
||||||
std::tuple< int, int > g_map_info;
|
|
||||||
// tool index (in possibleBlocks), current pange, max page
|
|
||||||
std::tuple<uint64_t, int, int> g_tool_info;
|
|
||||||
|
|
||||||
std::shared_ptr< SDLPP::Texture > g_placeholder_texture = nullptr;
|
|
||||||
std::shared_ptr< SDLPP::Texture > g_placeholder_mario = nullptr;
|
|
||||||
|
|
||||||
std::shared_ptr< SDLPP::RenderObject > g_mario = nullptr;
|
|
||||||
SDLPP::Vec2D< int > g_mario_pos = { 0, 0 };
|
|
||||||
|
|
||||||
enum LandType::Value g_current_world_type = LandType::OVERWORLD;
|
enum LandType::Value g_current_world_type = LandType::OVERWORLD;
|
||||||
|
|
||||||
void updateTool() {
|
void updateTool() {
|
||||||
auto tool_role = getBlockRole( possibleBlocks[std::get<ToolInfo::INDEX>(g_tool_info)] );
|
auto tool_index = global_vars.tool.index;
|
||||||
|
auto tool_role = getBlockRole( possibleBlocks[tool_index] );
|
||||||
std::shared_ptr< SDLPP::Texture > target_texture = nullptr;
|
std::shared_ptr< SDLPP::Texture > target_texture = nullptr;
|
||||||
switch ( tool_role ) {
|
switch ( tool_role ) {
|
||||||
case BlockRole::TERRAIN:
|
case BlockRole::TERRAIN:
|
||||||
target_texture = g_placeholder_texture;
|
target_texture = global_vars.translucent_terrain_texture;
|
||||||
break;
|
break;
|
||||||
case BlockRole::MARIO:
|
case BlockRole::MARIO:
|
||||||
target_texture = g_placeholder_mario;
|
target_texture = global_vars.translucent_mario_texture;
|
||||||
break;
|
break;
|
||||||
case BlockRole::MODIFIER:
|
case BlockRole::MODIFIER:
|
||||||
break;
|
break;
|
||||||
case BlockRole::CHARACTER:
|
case BlockRole::CHARACTER:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
g_current_tool->setTexture(
|
global_vars.current_tool->setTexture(
|
||||||
target_texture, getSourceRectByID( possibleBlocks[std::get<ToolInfo::INDEX>(g_tool_info)],
|
target_texture,
|
||||||
g_current_world_type ) );
|
getSourceRectByID( possibleBlocks[tool_index], g_current_world_type ) );
|
||||||
g_current_tool->setId( possibleBlocks[std::get<ToolInfo::INDEX>(g_tool_info)] );
|
global_vars.current_tool->setId( possibleBlocks[tool_index] );
|
||||||
g_current_tool->getCollisions()[0]->setId(
|
global_vars.current_tool->getCollisions()[0]->setId(
|
||||||
possibleBlocks[std::get<ToolInfo::INDEX>(g_tool_info)] );
|
possibleBlocks[tool_index] );
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeMario() {
|
void removeMario() {
|
||||||
if ( !g_mario )
|
if ( !global_vars.mario )
|
||||||
return;
|
return;
|
||||||
auto prev = g_objects[g_mario_pos.getX()][g_mario_pos.getY()];
|
auto prev = global_vars.objects[global_vars.mario_pos.getX()]
|
||||||
|
[global_vars.mario_pos.getY()];
|
||||||
// remove character/modifiers
|
// remove character/modifiers
|
||||||
g_objects[g_mario_pos.getX()][g_mario_pos.getY()] = {
|
global_vars
|
||||||
|
.objects[global_vars.mario_pos.getX()][global_vars.mario_pos.getY()] = {
|
||||||
std::get< 0 >( prev ), std::get< 1 >( prev ), 0, 0, 0, 0
|
std::get< 0 >( prev ), std::get< 1 >( prev ), 0, 0, 0, 0
|
||||||
};
|
};
|
||||||
g_mario->destroy();
|
global_vars.mario->destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateToolSelection( int prev_index ) {
|
void updateToolSelection( int prev_index ) {
|
||||||
size_t prev = prev_index * 8;
|
size_t prev = prev_index * 8;
|
||||||
size_t cur = std::get<ToolInfo::CUR_PAGE>(g_tool_info) * 8;
|
size_t cur = global_vars.tool.cur_page * 8;
|
||||||
for ( size_t i = prev;
|
for ( size_t i = prev;
|
||||||
i < ( g_tools.size() < prev + 8 ? g_tools.size() : prev + 8 ); i++ ) {
|
i < ( global_vars.tools.size() < prev + 8 ? global_vars.tools.size()
|
||||||
g_tools[i]->setHidden( true );
|
: prev + 8 );
|
||||||
|
i++ ) {
|
||||||
|
global_vars.tools[i]->setHidden( true );
|
||||||
}
|
}
|
||||||
for ( size_t i = cur;
|
for ( size_t i = cur;
|
||||||
i < ( g_tools.size() < cur + 8 ? g_tools.size() : cur + 8 ); i++ ) {
|
i < ( global_vars.tools.size() < cur + 8 ? global_vars.tools.size()
|
||||||
g_tools[i]->setHidden( false );
|
: cur + 8 );
|
||||||
|
i++ ) {
|
||||||
|
global_vars.tools[i]->setHidden( false );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void moveToolsLeft() {
|
void moveToolsLeft() {
|
||||||
std::get<ToolInfo::CUR_PAGE>(g_tool_info)--;
|
global_vars.tool.cur_page--;
|
||||||
updateToolSelection( std::get<ToolInfo::CUR_PAGE>(g_tool_info) + 1 );
|
updateToolSelection( global_vars.tool.cur_page + 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
void moveToolsRight() {
|
void moveToolsRight() {
|
||||||
std::get<ToolInfo::CUR_PAGE>(g_tool_info)++;
|
global_vars.tool.cur_page++;
|
||||||
updateToolSelection( std::get<ToolInfo::CUR_PAGE>(g_tool_info) - 1 );
|
updateToolSelection( global_vars.tool.cur_page - 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO add red outline to currently selected tool
|
// TODO add red outline to currently selected tool
|
||||||
// add WSAD navigation for the red highlight
|
// add WSAD navigation for the red highlight
|
||||||
|
// add mouse wheel navigation
|
||||||
void selectPrevTool() {
|
void selectPrevTool() {
|
||||||
if ( std::get<ToolInfo::INDEX>(g_tool_info) == 0 )
|
if ( global_vars.tool.index == 0 )
|
||||||
return;
|
return;
|
||||||
if ( std::get<ToolInfo::INDEX>(g_tool_info) % 8 == 0 ) {
|
if ( global_vars.tool.index % 8 == 0 ) {
|
||||||
moveToolsLeft();
|
moveToolsLeft();
|
||||||
}
|
}
|
||||||
std::get<ToolInfo::INDEX>(g_tool_info)--;
|
global_vars.tool.index--;
|
||||||
updateTool();
|
updateTool();
|
||||||
}
|
}
|
||||||
|
|
||||||
void selectNextTool() {
|
void selectNextTool() {
|
||||||
if ( std::get<ToolInfo::INDEX>(g_tool_info) == g_tools.size() - 1 )
|
if ( global_vars.tool.index == global_vars.tools.size() - 1 )
|
||||||
return;
|
return;
|
||||||
if ( std::get<ToolInfo::INDEX>(g_tool_info) % 8 == 7 ) {
|
if ( global_vars.tool.index % 8 == 7 ) {
|
||||||
moveToolsRight();
|
moveToolsRight();
|
||||||
}
|
}
|
||||||
std::get<ToolInfo::INDEX>(g_tool_info)++;
|
global_vars.tool.index++;
|
||||||
updateTool();
|
updateTool();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setFlag( uint64_t flag ) {
|
||||||
|
global_vars.flags |= flag;
|
||||||
|
}
|
||||||
|
void unsetFlag( uint64_t flag ) {
|
||||||
|
global_vars.flags &= ~flag;
|
||||||
|
}
|
||||||
|
bool getFlag( uint64_t flag ) {
|
||||||
|
return global_vars.flags & flag;
|
||||||
|
}
|
||||||
|
|
||||||
void handleKeyUp( SDL_Keycode key, SDLPP::Scene &scene ) {
|
void handleKeyUp( SDL_Keycode key, SDLPP::Scene &scene ) {
|
||||||
switch ( key ) {
|
switch ( key ) {
|
||||||
case SDLK_ESCAPE:
|
case SDLK_ESCAPE:
|
||||||
g_quit = true;
|
setFlag( QUIT_FLAG );
|
||||||
break;
|
break;
|
||||||
case SDLK_a:
|
case SDLK_a:
|
||||||
selectPrevTool();
|
selectPrevTool();
|
||||||
@ -180,60 +192,60 @@ void getMousePositionFlags( SDLPP::Scene &scene ) {
|
|||||||
|
|
||||||
MouseVisitor visitor;
|
MouseVisitor visitor;
|
||||||
scene.visitCollisions( *mouse, visitor );
|
scene.visitCollisions( *mouse, visitor );
|
||||||
std::get< MouseInfo::CUR_FLAGS >( g_mouse_info ) = visitor.getFlags();
|
global_vars.mouse.cur_flags = visitor.getFlags();
|
||||||
std::get< MouseInfo::EDIT_BOX >( g_mouse_info ) =
|
global_vars.mouse.edit_box = visitor.getEditBoxIndexes();
|
||||||
visitor.getEditBoxIndexes();
|
global_vars.mouse.tool_box = visitor.getToolBoxIndexes();
|
||||||
std::get< MouseInfo::TOOL_BOX >( g_mouse_info ) =
|
|
||||||
visitor.getToolBoxIndexes();
|
|
||||||
// if we found an edit box, move tool icon to that box
|
// if we found an edit box, move tool icon to that box
|
||||||
if ( visitor.foundEditBox() ) {
|
if ( visitor.foundEditBox() ) {
|
||||||
const auto &box = std::get< MouseInfo::EDIT_BOX >( g_mouse_info );
|
const auto &box = global_vars.mouse.edit_box;
|
||||||
g_current_tool->setPos( BLOCK_SIZE + box.getX() * BLOCK_SIZE,
|
global_vars.current_tool->setPos( BLOCK_SIZE + box.getX() * BLOCK_SIZE,
|
||||||
(MAP_WIDTH - MAP_HEIGHT + 2) * BLOCK_SIZE + box.getY() * BLOCK_SIZE );
|
( MAP_WIDTH - MAP_HEIGHT + 2 ) *
|
||||||
|
BLOCK_SIZE +
|
||||||
|
box.getY() * BLOCK_SIZE );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouseUpAction( uint64_t flags, SDLPP::Scene &scene ) {
|
void mouseUpAction( uint64_t flags, SDLPP::Scene &scene ) {
|
||||||
if ( MouseVisitor::moveMapLeft( flags ) && std::get<MapInfo::CUR_PAGE>(g_map_info) != 0 ) {
|
if ( MouseVisitor::moveMapLeft( flags ) && global_vars.map.cur_page != 0 ) {
|
||||||
std::get<MapInfo::CUR_PAGE>(g_map_info)--;
|
global_vars.map.cur_page--;
|
||||||
scene.moveEverything( BLOCK_SIZE, 0 );
|
scene.moveEverything( BLOCK_SIZE, 0 );
|
||||||
}
|
}
|
||||||
if ( MouseVisitor::moveMapRight( flags ) ) {
|
if ( MouseVisitor::moveMapRight( flags ) ) {
|
||||||
if ( std::get<MapInfo::CUR_PAGE>(g_map_info) == std::get<MapInfo::MAX_PAGE>(g_map_info) ) {
|
if ( global_vars.map.cur_page == global_vars.map.max_page ) {
|
||||||
// add column
|
// add column
|
||||||
g_objects.resize( g_objects.size() + 1 );
|
global_vars.objects.resize( global_vars.objects.size() + 1 );
|
||||||
std::get<MapInfo::MAX_PAGE>(g_map_info)++;
|
global_vars.map.max_page++;
|
||||||
}
|
}
|
||||||
std::get<MapInfo::CUR_PAGE>(g_map_info) += 1;
|
global_vars.map.cur_page += 1;
|
||||||
scene.moveEverything( -BLOCK_SIZE, 0 );
|
scene.moveEverything( -BLOCK_SIZE, 0 );
|
||||||
}
|
}
|
||||||
if ( MouseVisitor::moveToolsLeft( flags ) && std::get<ToolInfo::CUR_PAGE>(g_tool_info) != 0 ) {
|
if ( MouseVisitor::moveToolsLeft( flags ) &&
|
||||||
std::get<ToolInfo::CUR_PAGE>(g_tool_info) -= 1;
|
global_vars.tool.cur_page != 0 ) {
|
||||||
updateToolSelection( std::get<ToolInfo::CUR_PAGE>(g_tool_info) + 1 );
|
global_vars.tool.cur_page--;
|
||||||
|
updateToolSelection( global_vars.tool.cur_page + 1 );
|
||||||
}
|
}
|
||||||
if ( MouseVisitor::moveToolsRight( flags ) &&
|
if ( MouseVisitor::moveToolsRight( flags ) &&
|
||||||
std::get<ToolInfo::CUR_PAGE>(g_tool_info) != std::get<ToolInfo::MAX_PAGE>(g_tool_info) ) {
|
global_vars.tool.cur_page != global_vars.tool.max_page ) {
|
||||||
std::get<ToolInfo::CUR_PAGE>(g_tool_info) += 1;
|
global_vars.tool.cur_page++;
|
||||||
updateToolSelection( std::get<ToolInfo::CUR_PAGE>(g_tool_info) - 1 );
|
updateToolSelection( global_vars.tool.cur_page - 1 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SDLPP::Vec2D< int > getSelectedObjectPosition() {
|
SDLPP::Vec2D< int > getSelectedObjectPosition() {
|
||||||
return { std::get<MapInfo::CUR_PAGE>(g_map_info) +
|
return global_vars.mouse.edit_box +
|
||||||
std::get< MouseInfo::EDIT_BOX >( g_mouse_info ).getX(),
|
SDLPP::Vec2D< int >( global_vars.map.cur_page, 0 );
|
||||||
std::get< MouseInfo::EDIT_BOX >( g_mouse_info ).getY() };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mapObjectType &getSelectedObject() {
|
mapObjectType &getSelectedObject() {
|
||||||
auto pos = getSelectedObjectPosition();
|
auto pos = getSelectedObjectPosition();
|
||||||
return g_objects[pos.getX()][pos.getY()];
|
return global_vars.objects[pos.getX()][pos.getY()];
|
||||||
}
|
}
|
||||||
|
|
||||||
void placeTool( SDLPP::Scene &scene ) {
|
void placeTool( SDLPP::Scene &scene ) {
|
||||||
std::lock_guard< std::mutex > lock( g_destruction_mutex );
|
std::lock_guard< std::mutex > lock( destruction_mutex );
|
||||||
|
|
||||||
ToolVisitor visitor;
|
ToolVisitor visitor;
|
||||||
auto tool_type = getBlockRole( g_current_tool->getId() );
|
auto tool_type = getBlockRole( global_vars.current_tool->getId() );
|
||||||
switch ( tool_type ) {
|
switch ( tool_type ) {
|
||||||
case BlockRole::TERRAIN:
|
case BlockRole::TERRAIN:
|
||||||
visitor.setVisitorType( VisitorType::Terrain );
|
visitor.setVisitorType( VisitorType::Terrain );
|
||||||
@ -243,7 +255,7 @@ void placeTool( SDLPP::Scene &scene ) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
scene.visitCollisions( *g_current_tool, visitor );
|
scene.visitCollisions( *global_vars.current_tool, visitor );
|
||||||
if ( visitor.removeBlock() && !visitor.addBlock() ) {
|
if ( visitor.removeBlock() && !visitor.addBlock() ) {
|
||||||
auto &obj = getSelectedObject();
|
auto &obj = getSelectedObject();
|
||||||
switch ( visitor.getVisitorType() ) {
|
switch ( visitor.getVisitorType() ) {
|
||||||
@ -262,17 +274,19 @@ void placeTool( SDLPP::Scene &scene ) {
|
|||||||
}
|
}
|
||||||
} else if ( visitor.addBlock() ) {
|
} else if ( visitor.addBlock() ) {
|
||||||
auto &obj = getSelectedObject();
|
auto &obj = getSelectedObject();
|
||||||
|
auto renderer = scene.getRendererShared();
|
||||||
int z_index = 1;
|
int z_index = 1;
|
||||||
std::shared_ptr< SDLPP::RenderObject > new_obj = nullptr;
|
std::shared_ptr< SDLPP::RenderObject > new_obj = nullptr;
|
||||||
switch ( visitor.getVisitorType() ) {
|
switch ( visitor.getVisitorType() ) {
|
||||||
case VisitorType::Terrain:
|
case VisitorType::Terrain:
|
||||||
std::get< MapObject::TERRAIN_TYPE >( obj ) = LandType::OVERWORLD;
|
std::get< MapObject::TERRAIN_TYPE >( obj ) = LandType::OVERWORLD;
|
||||||
std::get< MapObject::TERRAIN_ID >( obj ) = g_current_tool->getId();
|
std::get< MapObject::TERRAIN_ID >( obj ) =
|
||||||
|
global_vars.current_tool->getId();
|
||||||
// TODO why 1 +?
|
// TODO why 1 +?
|
||||||
new_obj = createTerrainBlock(
|
new_obj = createTerrainBlock(
|
||||||
g_current_tool->getId(), LandType::OVERWORLD, g_renderer,
|
global_vars.current_tool->getId(), LandType::OVERWORLD,
|
||||||
1 + std::get< MouseInfo::EDIT_BOX >( g_mouse_info ).getX(),
|
renderer, 1 + global_vars.mouse.edit_box.getX(),
|
||||||
std::get< MouseInfo::EDIT_BOX >( g_mouse_info ).getY(), true );
|
global_vars.mouse.edit_box.getY(), true );
|
||||||
new_obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID );
|
new_obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID );
|
||||||
break;
|
break;
|
||||||
case VisitorType::Modifier:
|
case VisitorType::Modifier:
|
||||||
@ -282,14 +296,13 @@ void placeTool( SDLPP::Scene &scene ) {
|
|||||||
std::get< MapObject::CHARACTER_ID >( obj ) = MARIO_ID;
|
std::get< MapObject::CHARACTER_ID >( obj ) = MARIO_ID;
|
||||||
std::get< MapObject::MODIFIER_TYPE >( obj ) = 0;
|
std::get< MapObject::MODIFIER_TYPE >( obj ) = 0;
|
||||||
std::get< MapObject::MODIFIER_DATA >( obj ) = 0;
|
std::get< MapObject::MODIFIER_DATA >( obj ) = 0;
|
||||||
new_obj = createMario(
|
new_obj = createMario( LandType::OVERWORLD, renderer,
|
||||||
LandType::OVERWORLD, g_renderer,
|
1 + global_vars.mouse.edit_box.getX(),
|
||||||
1 + std::get< MouseInfo::EDIT_BOX >( g_mouse_info ).getX(),
|
global_vars.mouse.edit_box.getY() );
|
||||||
std::get< MouseInfo::EDIT_BOX >( g_mouse_info ).getY() );
|
|
||||||
// remove mario if exists
|
// remove mario if exists
|
||||||
removeMario();
|
removeMario();
|
||||||
g_mario = new_obj;
|
global_vars.mario = new_obj;
|
||||||
g_mario_pos = getSelectedObjectPosition();
|
global_vars.mario_pos = getSelectedObjectPosition();
|
||||||
new_obj->getCollisions()[0]->setId( EDITOR_CHARACTER_ID );
|
new_obj->getCollisions()[0]->setId( EDITOR_CHARACTER_ID );
|
||||||
z_index = scene.getObjects().size() - 1;
|
z_index = scene.getObjects().size() - 1;
|
||||||
break;
|
break;
|
||||||
@ -306,44 +319,39 @@ void pollEvents( SDLPP::Scene &scene ) {
|
|||||||
while ( SDLPP::getSDLEvent( event ) ) {
|
while ( SDLPP::getSDLEvent( event ) ) {
|
||||||
switch ( event.type ) {
|
switch ( event.type ) {
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
g_quit = true;
|
setFlag( QUIT_FLAG );
|
||||||
break;
|
break;
|
||||||
case SDL_KEYUP:
|
case SDL_KEYUP:
|
||||||
handleKeyUp( event.key.keysym.sym, scene );
|
handleKeyUp( event.key.keysym.sym, scene );
|
||||||
break;
|
break;
|
||||||
case SDL_WINDOWEVENT:
|
case SDL_WINDOWEVENT:
|
||||||
if ( event.window.event == SDL_WINDOWEVENT_RESIZED ) {
|
if ( event.window.event == SDL_WINDOWEVENT_RESIZED ) {
|
||||||
g_update_size = true;
|
setFlag( UPDATE_FLAG );
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
getMousePositionFlags( scene );
|
getMousePositionFlags( scene );
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEBUTTONUP:
|
case SDL_MOUSEBUTTONUP:
|
||||||
if ( std::get< MouseInfo::CUR_FLAGS >( g_mouse_info ) ==
|
if ( global_vars.mouse.cur_flags == global_vars.mouse.prev_flags ) {
|
||||||
std::get< MouseInfo::PREV_FLAGS >( g_mouse_info ) ) {
|
mouseUpAction( global_vars.mouse.cur_flags, scene );
|
||||||
mouseUpAction( std::get< MouseInfo::CUR_FLAGS >( g_mouse_info ),
|
|
||||||
scene );
|
|
||||||
}
|
}
|
||||||
if ( std::get< MouseInfo::EDIT_BOX >( g_mouse_info ).getX() !=
|
if ( global_vars.mouse.edit_box.getX() != -1 ) {
|
||||||
-1 ) {
|
|
||||||
placeTool( scene );
|
placeTool( scene );
|
||||||
}
|
}
|
||||||
if ( std::get< MouseInfo::TOOL_BOX >( g_mouse_info ).getX() !=
|
if ( global_vars.mouse.tool_box.getX() != -1 ) {
|
||||||
-1 ) {
|
auto &tool_box = global_vars.mouse.tool_box;
|
||||||
auto &tool_box =
|
|
||||||
std::get< MouseInfo::TOOL_BOX >( g_mouse_info );
|
|
||||||
size_t index = tool_box.getY() * 4 + tool_box.getX();
|
size_t index = tool_box.getY() * 4 + tool_box.getX();
|
||||||
if ( index < g_tools.size() ) {
|
if ( index < global_vars.tools.size() ) {
|
||||||
std::get<ToolInfo::INDEX>(g_tool_info) = std::get<ToolInfo::CUR_PAGE>(g_tool_info) * 8 + index;
|
global_vars.tool.index =
|
||||||
|
global_vars.tool.cur_page * 8 + index;
|
||||||
updateTool();
|
updateTool();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
// store current mouse flags in previous mouse flags
|
// store current mouse flags in previous mouse flags
|
||||||
std::get< MouseInfo::PREV_FLAGS >( g_mouse_info ) =
|
global_vars.mouse.prev_flags = global_vars.mouse.cur_flags;
|
||||||
std::get< MouseInfo::CUR_FLAGS >( g_mouse_info );
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -371,38 +379,39 @@ int main() {
|
|||||||
SDLPP::init();
|
SDLPP::init();
|
||||||
SDLPP::Window w( "Mario editor!" );
|
SDLPP::Window w( "Mario editor!" );
|
||||||
w.setResizable( true );
|
w.setResizable( true );
|
||||||
BLOCK_SIZE = 1.0 / (MAP_WIDTH + 2);
|
BLOCK_SIZE = 1.0 / ( MAP_WIDTH + 2 );
|
||||||
|
|
||||||
g_renderer = std::make_shared< SDLPP::Renderer >( w );
|
auto renderer = std::make_shared< SDLPP::Renderer >( w );
|
||||||
g_renderer->setBlendMode( SDL_BLENDMODE_BLEND );
|
renderer->setBlendMode( SDL_BLENDMODE_BLEND );
|
||||||
|
|
||||||
// prepare global vars
|
// prepare global vars
|
||||||
g_terrain_texture = std::make_shared< SDLPP::Texture >(
|
g_terrain_texture = std::make_shared< SDLPP::Texture >(
|
||||||
g_renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY );
|
renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY );
|
||||||
g_mario_texture = std::make_shared< SDLPP::Texture >(
|
g_mario_texture = std::make_shared< SDLPP::Texture >(
|
||||||
g_renderer, "sprites/mario.png", MARIO_OVERWORLD_COLORKEY );
|
renderer, "sprites/mario.png", MARIO_OVERWORLD_COLORKEY );
|
||||||
|
|
||||||
auto scene = std::make_shared< SDLPP::Scene >( g_renderer );
|
auto scene = std::make_shared< SDLPP::Scene >( renderer );
|
||||||
auto bg = std::make_shared< SDLPP::RectangleRender >(
|
auto bg = std::make_shared< SDLPP::RectangleRender >(
|
||||||
0, 0, 10, 10, g_renderer, MARIO_OVERWORLD_COLORKEY, true );
|
0, 0, 10, 10, renderer, MARIO_OVERWORLD_COLORKEY, true );
|
||||||
bg->setPermanent();
|
bg->setPermanent();
|
||||||
bg->setId( 1 );
|
bg->setId( 1 );
|
||||||
scene->addObject( bg );
|
scene->addObject( bg );
|
||||||
|
|
||||||
loadMap( scene, "test_binary.bin", g_renderer, g_objects );
|
loadMap( scene, "test_binary.bin", renderer, global_vars.objects );
|
||||||
|
|
||||||
// grid
|
// grid
|
||||||
for ( int i = 1; i < (MAP_WIDTH + 2); i++ ) {
|
for ( int i = 1; i < ( MAP_WIDTH + 2 ); i++ ) {
|
||||||
auto line_vertical = std::make_shared< SDLPP::LineRenderer >(
|
auto line_vertical = std::make_shared< SDLPP::LineRenderer >(
|
||||||
i * BLOCK_SIZE, 1 - MAP_HEIGHT * BLOCK_SIZE, i * BLOCK_SIZE, 1.0,
|
i * BLOCK_SIZE, 1 - MAP_HEIGHT * BLOCK_SIZE, i * BLOCK_SIZE, 1.0,
|
||||||
g_renderer, "#282828" );
|
renderer, "#282828" );
|
||||||
line_vertical->setPermanent();
|
line_vertical->setPermanent();
|
||||||
line_vertical->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
line_vertical->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
scene->addObject( line_vertical );
|
scene->addObject( line_vertical );
|
||||||
if ( i > (MAP_WIDTH - MAP_HEIGHT) ) {
|
if ( i > ( MAP_WIDTH - MAP_HEIGHT ) ) {
|
||||||
auto line_horizontal = std::make_shared< SDLPP::LineRenderer >(
|
auto line_horizontal = std::make_shared< SDLPP::LineRenderer >(
|
||||||
BLOCK_SIZE, ( i + 1 ) * BLOCK_SIZE, (MAP_WIDTH+1) * BLOCK_SIZE,
|
BLOCK_SIZE, ( i + 1 ) * BLOCK_SIZE,
|
||||||
( i + 1 ) * BLOCK_SIZE, g_renderer, "#282828" );
|
( MAP_WIDTH + 1 ) * BLOCK_SIZE, ( i + 1 ) * BLOCK_SIZE,
|
||||||
|
renderer, "#282828" );
|
||||||
line_horizontal->setPermanent();
|
line_horizontal->setPermanent();
|
||||||
line_horizontal->setAlignment( SDLPP::OBJ_CENTER,
|
line_horizontal->setAlignment( SDLPP::OBJ_CENTER,
|
||||||
SDLPP::OBJ_CENTER );
|
SDLPP::OBJ_CENTER );
|
||||||
@ -411,8 +420,8 @@ int main() {
|
|||||||
}
|
}
|
||||||
// white rectangles
|
// white rectangles
|
||||||
auto rectangle1 = std::make_shared< SDLPP::RectangleRender >(
|
auto rectangle1 = std::make_shared< SDLPP::RectangleRender >(
|
||||||
0, (MAP_WIDTH + 2 - MAP_HEIGHT) * BLOCK_SIZE, BLOCK_SIZE, MAP_HEIGHT * BLOCK_SIZE, g_renderer, "#FFFFFF88",
|
0, ( MAP_WIDTH + 2 - MAP_HEIGHT ) * BLOCK_SIZE, BLOCK_SIZE,
|
||||||
true );
|
MAP_HEIGHT * BLOCK_SIZE, renderer, "#FFFFFF88", true );
|
||||||
rectangle1->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
rectangle1->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
rectangle1->setId( EDITOR_LEFT_MAP_ID );
|
rectangle1->setId( EDITOR_LEFT_MAP_ID );
|
||||||
rectangle1->setPermanent();
|
rectangle1->setPermanent();
|
||||||
@ -420,8 +429,9 @@ int main() {
|
|||||||
scene->addObject( rectangle1 );
|
scene->addObject( rectangle1 );
|
||||||
// white rectangles
|
// white rectangles
|
||||||
auto rectangle2 = std::make_shared< SDLPP::RectangleRender >(
|
auto rectangle2 = std::make_shared< SDLPP::RectangleRender >(
|
||||||
(MAP_WIDTH+1) * BLOCK_SIZE, (MAP_WIDTH + 2 - MAP_HEIGHT) * BLOCK_SIZE, BLOCK_SIZE, MAP_HEIGHT * BLOCK_SIZE,
|
( MAP_WIDTH + 1 ) * BLOCK_SIZE,
|
||||||
g_renderer, "#FFFFFF88", true );
|
( MAP_WIDTH + 2 - MAP_HEIGHT ) * BLOCK_SIZE, BLOCK_SIZE,
|
||||||
|
MAP_HEIGHT * BLOCK_SIZE, renderer, "#FFFFFF88", true );
|
||||||
rectangle2->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
rectangle2->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
rectangle2->setId( EDITOR_RIGHT_MAP_ID );
|
rectangle2->setId( EDITOR_RIGHT_MAP_ID );
|
||||||
rectangle2->setPermanent();
|
rectangle2->setPermanent();
|
||||||
@ -432,15 +442,16 @@ int main() {
|
|||||||
auto font_config = std::make_shared< SDLPP::FontConfiguration >(
|
auto font_config = std::make_shared< SDLPP::FontConfiguration >(
|
||||||
font, "#000000", "#282828", 0.05 );
|
font, "#000000", "#282828", 0.05 );
|
||||||
auto left = std::make_shared< SDLPP::TextRenderer >(
|
auto left = std::make_shared< SDLPP::TextRenderer >(
|
||||||
0, (MAP_WIDTH - MAP_HEIGHT/2.0 + 1.5) * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, g_renderer, "<",
|
0, ( MAP_WIDTH - MAP_HEIGHT / 2.0 + 1.5 ) * BLOCK_SIZE, BLOCK_SIZE,
|
||||||
font_config );
|
BLOCK_SIZE, renderer, "<", font_config );
|
||||||
left->setId( 0 );
|
left->setId( 0 );
|
||||||
left->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
left->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
left->setPermanent();
|
left->setPermanent();
|
||||||
scene->addObject( left );
|
scene->addObject( left );
|
||||||
auto right = std::make_shared< SDLPP::TextRenderer >(
|
auto right = std::make_shared< SDLPP::TextRenderer >(
|
||||||
(MAP_WIDTH+1) * BLOCK_SIZE, (MAP_WIDTH - MAP_HEIGHT/2.0 + 1.5) * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, g_renderer,
|
( MAP_WIDTH + 1 ) * BLOCK_SIZE,
|
||||||
">", font_config );
|
( MAP_WIDTH - MAP_HEIGHT / 2.0 + 1.5 ) * BLOCK_SIZE, BLOCK_SIZE,
|
||||||
|
BLOCK_SIZE, renderer, ">", font_config );
|
||||||
right->setId( 0 );
|
right->setId( 0 );
|
||||||
right->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
right->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
right->setPermanent();
|
right->setPermanent();
|
||||||
@ -448,12 +459,13 @@ int main() {
|
|||||||
|
|
||||||
for ( int i = 0; i < MAP_WIDTH; i++ ) {
|
for ( int i = 0; i < MAP_WIDTH; i++ ) {
|
||||||
for ( int j = 0; j < MAP_HEIGHT; j++ ) {
|
for ( int j = 0; j < MAP_HEIGHT; j++ ) {
|
||||||
scene->addObject( std::make_shared< EditBox >( i, j, MAP_WIDTH, MAP_HEIGHT, g_renderer ) );
|
scene->addObject( std::make_shared< EditBox >(
|
||||||
|
i, j, MAP_WIDTH, MAP_HEIGHT, renderer ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto mouse = std::make_shared< SDLPP::RectangleRender >( 0.01, 0.01, 0, 0,
|
auto mouse = std::make_shared< SDLPP::RectangleRender >( 0.01, 0.01, 0, 0,
|
||||||
g_renderer );
|
renderer );
|
||||||
mouse->setMinWidth( 1 );
|
mouse->setMinWidth( 1 );
|
||||||
mouse->setMinHeight( 1 );
|
mouse->setMinHeight( 1 );
|
||||||
mouse->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
mouse->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
@ -461,13 +473,15 @@ int main() {
|
|||||||
mouse->setColiderColor( "#00FF00" );
|
mouse->setColiderColor( "#00FF00" );
|
||||||
mouse->addCollision( SDLPP::RectColider( { 0, 0 }, { 1, 1 } ) );
|
mouse->addCollision( SDLPP::RectColider( { 0, 0 }, { 1, 1 } ) );
|
||||||
scene->addObject( mouse );
|
scene->addObject( mouse );
|
||||||
std::get<MapInfo::MAX_PAGE>(g_map_info) = g_objects.size() - MAP_WIDTH;
|
global_vars.map.max_page = global_vars.objects.size() - MAP_WIDTH;
|
||||||
|
|
||||||
// tools
|
// tools
|
||||||
std::get<ToolInfo::MAX_PAGE>(g_tool_info) = ( possibleBlocks.size() - 1 ) / 8;
|
global_vars.tool.max_page = ( possibleBlocks.size() - 1 ) / 8;
|
||||||
for ( int i = 0; i < 4; i++ ) {
|
for ( int i = 0; i < 4; i++ ) {
|
||||||
auto tool_box1 = std::make_shared< ToolBox >( i, 0, MAP_WIDTH, MAP_HEIGHT, g_renderer );
|
auto tool_box1 = std::make_shared< ToolBox >( i, 0, MAP_WIDTH,
|
||||||
auto tool_box2 = std::make_shared< ToolBox >( i, 1, MAP_WIDTH, MAP_HEIGHT, g_renderer );
|
MAP_HEIGHT, renderer );
|
||||||
|
auto tool_box2 = std::make_shared< ToolBox >( i, 1, MAP_WIDTH,
|
||||||
|
MAP_HEIGHT, renderer );
|
||||||
scene->addObject( tool_box1 );
|
scene->addObject( tool_box1 );
|
||||||
scene->addObject( tool_box2 );
|
scene->addObject( tool_box2 );
|
||||||
// std::cout << "TOOL BOX POS: " << tool_box1->getPos().getX() <<
|
// std::cout << "TOOL BOX POS: " << tool_box1->getPos().getX() <<
|
||||||
@ -478,47 +492,48 @@ int main() {
|
|||||||
int tool_index = 0;
|
int tool_index = 0;
|
||||||
for ( auto &block : possibleBlocks ) {
|
for ( auto &block : possibleBlocks ) {
|
||||||
if ( block == MARIO_ID ) {
|
if ( block == MARIO_ID ) {
|
||||||
g_tools.push_back(
|
global_vars.tools.push_back(
|
||||||
createMario( LandType::OVERWORLD, g_renderer, 0, 0 ) );
|
createMario( LandType::OVERWORLD, renderer, 0, 0 ) );
|
||||||
} else {
|
} else {
|
||||||
g_tools.push_back( createTerrainBlock( block, LandType::OVERWORLD,
|
global_vars.tools.push_back( createTerrainBlock(
|
||||||
g_renderer, false ) );
|
block, LandType::OVERWORLD, renderer, false ) );
|
||||||
}
|
}
|
||||||
g_tools.back()->setHidden( true );
|
global_vars.tools.back()->setHidden( true );
|
||||||
g_tools.back()->setPermanent();
|
global_vars.tools.back()->setPermanent();
|
||||||
auto x = tool_index % 4;
|
auto x = tool_index % 4;
|
||||||
auto y = tool_index / 4;
|
auto y = tool_index / 4;
|
||||||
// TODO add 14 and 1 as constants somewhere
|
// TODO add 14 and 1 as constants somewhere
|
||||||
// TODO investigate when not permanent requires `-1` on x position
|
// TODO investigate when not permanent requires `-1` on x position
|
||||||
g_tools.back()->setPos( (MAP_WIDTH - 4) * BLOCK_SIZE + x * BLOCK_SIZE,
|
global_vars.tools.back()->setPos( ( MAP_WIDTH - 4 ) * BLOCK_SIZE +
|
||||||
BLOCK_SIZE + y * BLOCK_SIZE );
|
x * BLOCK_SIZE,
|
||||||
|
BLOCK_SIZE + y * BLOCK_SIZE );
|
||||||
// std::cout << "TOOL POS: " << tools.back()->getPos().getX() <<
|
// std::cout << "TOOL POS: " << tools.back()->getPos().getX() <<
|
||||||
// ", " << tools.back()->getPos().getY() << std::endl;
|
// ", " << tools.back()->getPos().getY() << std::endl;
|
||||||
scene->addObject( g_tools.back() );
|
scene->addObject( global_vars.tools.back() );
|
||||||
tool_index = ( tool_index + 1 ) % 8;
|
tool_index = ( tool_index + 1 ) % 8;
|
||||||
}
|
}
|
||||||
for ( int i = 0; i < 5; i++ ) {
|
for ( int i = 0; i < 5; i++ ) {
|
||||||
auto line = std::make_shared< SDLPP::LineRenderer >(
|
auto line = std::make_shared< SDLPP::LineRenderer >(
|
||||||
(MAP_WIDTH - 4) * BLOCK_SIZE + i * BLOCK_SIZE, BLOCK_SIZE,
|
( MAP_WIDTH - 4 ) * BLOCK_SIZE + i * BLOCK_SIZE, BLOCK_SIZE,
|
||||||
(MAP_WIDTH - 4) * BLOCK_SIZE + i * BLOCK_SIZE, 3 * BLOCK_SIZE, g_renderer,
|
( MAP_WIDTH - 4 ) * BLOCK_SIZE + i * BLOCK_SIZE, 3 * BLOCK_SIZE,
|
||||||
"#282828" );
|
renderer, "#282828" );
|
||||||
line->setPermanent();
|
line->setPermanent();
|
||||||
line->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
line->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
scene->addObject( line );
|
scene->addObject( line );
|
||||||
}
|
}
|
||||||
for ( int i = 0; i < 3; i++ ) {
|
for ( int i = 0; i < 3; i++ ) {
|
||||||
auto line = std::make_shared< SDLPP::LineRenderer >(
|
auto line = std::make_shared< SDLPP::LineRenderer >(
|
||||||
(MAP_WIDTH - 4) * BLOCK_SIZE, BLOCK_SIZE + i * BLOCK_SIZE,
|
( MAP_WIDTH - 4 ) * BLOCK_SIZE, BLOCK_SIZE + i * BLOCK_SIZE,
|
||||||
(MAP_WIDTH - 4) * BLOCK_SIZE + 4 * BLOCK_SIZE, BLOCK_SIZE + i * BLOCK_SIZE,
|
( MAP_WIDTH - 4 ) * BLOCK_SIZE + 4 * BLOCK_SIZE,
|
||||||
g_renderer, "#282828" );
|
BLOCK_SIZE + i * BLOCK_SIZE, renderer, "#282828" );
|
||||||
line->setPermanent();
|
line->setPermanent();
|
||||||
line->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
line->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
scene->addObject( line );
|
scene->addObject( line );
|
||||||
}
|
}
|
||||||
|
|
||||||
auto tool_rect1 = std::make_shared< SDLPP::RectangleRender >(
|
auto tool_rect1 = std::make_shared< SDLPP::RectangleRender >(
|
||||||
(MAP_WIDTH-5) * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE, g_renderer,
|
( MAP_WIDTH - 5 ) * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
||||||
"#FFFFFF88", true );
|
renderer, "#FFFFFF88", true );
|
||||||
tool_rect1->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
tool_rect1->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
tool_rect1->setId( EDITOR_LEFT_TOOL_ID );
|
tool_rect1->setId( EDITOR_LEFT_TOOL_ID );
|
||||||
tool_rect1->setPermanent();
|
tool_rect1->setPermanent();
|
||||||
@ -526,41 +541,43 @@ int main() {
|
|||||||
scene->addObject( tool_rect1 );
|
scene->addObject( tool_rect1 );
|
||||||
// white rectangles
|
// white rectangles
|
||||||
auto tool_rect2 = std::make_shared< SDLPP::RectangleRender >(
|
auto tool_rect2 = std::make_shared< SDLPP::RectangleRender >(
|
||||||
MAP_WIDTH * BLOCK_SIZE, 1 * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE, g_renderer,
|
MAP_WIDTH * BLOCK_SIZE, 1 * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
||||||
"#FFFFFF88", true );
|
renderer, "#FFFFFF88", true );
|
||||||
tool_rect2->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
tool_rect2->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
tool_rect2->setId( EDITOR_RIGHT_TOOL_ID );
|
tool_rect2->setId( EDITOR_RIGHT_TOOL_ID );
|
||||||
tool_rect2->setPermanent();
|
tool_rect2->setPermanent();
|
||||||
tool_rect2->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) );
|
tool_rect2->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) );
|
||||||
scene->addObject( tool_rect2 );
|
scene->addObject( tool_rect2 );
|
||||||
auto left_tool = std::make_shared< SDLPP::TextRenderer >(
|
auto left_tool = std::make_shared< SDLPP::TextRenderer >(
|
||||||
(MAP_WIDTH-5) * BLOCK_SIZE, 1.5 * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, g_renderer,
|
( MAP_WIDTH - 5 ) * BLOCK_SIZE, 1.5 * BLOCK_SIZE, BLOCK_SIZE,
|
||||||
"<", font_config );
|
BLOCK_SIZE, renderer, "<", font_config );
|
||||||
left_tool->setId( 0 );
|
left_tool->setId( 0 );
|
||||||
left_tool->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
left_tool->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
left_tool->setPermanent();
|
left_tool->setPermanent();
|
||||||
scene->addObject( left_tool );
|
scene->addObject( left_tool );
|
||||||
auto right_tool = std::make_shared< SDLPP::TextRenderer >(
|
auto right_tool = std::make_shared< SDLPP::TextRenderer >(
|
||||||
MAP_WIDTH * BLOCK_SIZE, 1.5 * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, g_renderer,
|
MAP_WIDTH * BLOCK_SIZE, 1.5 * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE,
|
||||||
">", font_config );
|
renderer, ">", font_config );
|
||||||
right_tool->setId( 0 );
|
right_tool->setId( 0 );
|
||||||
right_tool->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
right_tool->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
right_tool->setPermanent();
|
right_tool->setPermanent();
|
||||||
scene->addObject( right_tool );
|
scene->addObject( right_tool );
|
||||||
|
|
||||||
g_placeholder_texture = std::make_shared< SDLPP::Texture >(
|
global_vars.translucent_terrain_texture =
|
||||||
g_renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY );
|
std::make_shared< SDLPP::Texture >( renderer, "sprites/terrain.png",
|
||||||
g_placeholder_texture->setAlpha( 100 );
|
MARIO_OVERWORLD_COLORKEY );
|
||||||
g_placeholder_mario = std::make_shared< SDLPP::Texture >(
|
global_vars.translucent_terrain_texture->setAlpha( 100 );
|
||||||
g_renderer, "sprites/mario.png", MARIO_OVERWORLD_COLORKEY );
|
global_vars.translucent_mario_texture = std::make_shared< SDLPP::Texture >(
|
||||||
g_placeholder_mario->setAlpha( 100 );
|
renderer, "sprites/mario.png", MARIO_OVERWORLD_COLORKEY );
|
||||||
g_current_tool = createTerrainBlock( possibleBlocks[std::get<ToolInfo::INDEX>(g_tool_info)],
|
global_vars.translucent_mario_texture->setAlpha( 100 );
|
||||||
LandType::OVERWORLD, g_renderer,
|
global_vars.current_tool = createTerrainBlock(
|
||||||
g_placeholder_texture, false );
|
possibleBlocks[global_vars.tool.index], LandType::OVERWORLD, renderer,
|
||||||
g_current_tool->addCollision( SDLPP::RectColider( 0.1, 0.1, 0.8, 0.8 ) );
|
global_vars.translucent_terrain_texture, false );
|
||||||
dynamic_cast< MarioBlock & >( *g_current_tool ).setTool();
|
global_vars.current_tool->addCollision(
|
||||||
scene->addObject( g_current_tool );
|
SDLPP::RectColider( 0.1, 0.1, 0.8, 0.8 ) );
|
||||||
scene->moveZTop( g_current_tool );
|
dynamic_cast< MarioBlock & >( *global_vars.current_tool ).setTool();
|
||||||
|
scene->addObject( global_vars.current_tool );
|
||||||
|
scene->moveZTop( global_vars.current_tool );
|
||||||
|
|
||||||
scene->moveEverything( BLOCK_SIZE, 0 );
|
scene->moveEverything( BLOCK_SIZE, 0 );
|
||||||
FPSmanager gFPS;
|
FPSmanager gFPS;
|
||||||
@ -573,45 +590,76 @@ int main() {
|
|||||||
int frames = 0;
|
int frames = 0;
|
||||||
std::thread inputThread( doInput, scene );
|
std::thread inputThread( doInput, scene );
|
||||||
inputThread.detach();
|
inputThread.detach();
|
||||||
while ( !g_quit ) {
|
setFlag( UPDATE_FLAG );
|
||||||
|
// required for initial correct rendering
|
||||||
|
setFlag( MAP_LEFT_ENABLED_FLAG );
|
||||||
|
setFlag( MAP_RIGHT_ENABLED_FLAG );
|
||||||
|
setFlag( TOOL_LEFT_ENABLED_FLAG );
|
||||||
|
setFlag( TOOL_RIGHT_ENABLED_FLAG );
|
||||||
|
while ( !getFlag( QUIT_FLAG ) ) {
|
||||||
SDL_PumpEvents();
|
SDL_PumpEvents();
|
||||||
SDL_framerateDelay( &gFPS );
|
SDL_framerateDelay( &gFPS );
|
||||||
std::lock_guard< std::mutex > lock( g_destruction_mutex );
|
std::lock_guard< std::mutex > lock( destruction_mutex );
|
||||||
scene->renderScene();
|
scene->renderScene();
|
||||||
g_renderer->presentRenderer();
|
renderer->presentRenderer();
|
||||||
frames++;
|
frames++;
|
||||||
if ( SDL_GetTicks() - base >= 1000 ) {
|
if ( SDL_GetTicks() - base >= 1000 ) {
|
||||||
std::cout << "FPS: " << frames << std::endl;
|
std::cout << "FPS: " << frames << std::endl;
|
||||||
frames = 0;
|
frames = 0;
|
||||||
base = SDL_GetTicks();
|
base = SDL_GetTicks();
|
||||||
}
|
}
|
||||||
if ( std::get<MapInfo::CUR_PAGE>(g_map_info) == 0 ) {
|
if ( global_vars.map.cur_page == 0 &&
|
||||||
|
getFlag( MAP_LEFT_ENABLED_FLAG ) ) {
|
||||||
|
setFlag( UPDATE_FLAG );
|
||||||
|
unsetFlag( MAP_LEFT_ENABLED_FLAG );
|
||||||
left->setTextColor( font, "#CCCCCC", "#CCCCCC", 0.05 );
|
left->setTextColor( font, "#CCCCCC", "#CCCCCC", 0.05 );
|
||||||
} else {
|
} else if ( global_vars.map.cur_page != 0 &&
|
||||||
|
!getFlag( MAP_LEFT_ENABLED_FLAG ) ) {
|
||||||
|
setFlag( UPDATE_FLAG );
|
||||||
|
setFlag( MAP_LEFT_ENABLED_FLAG );
|
||||||
left->setTextColor( font, "#000000", "#282828", 0.05 );
|
left->setTextColor( font, "#000000", "#282828", 0.05 );
|
||||||
}
|
}
|
||||||
if ( std::get<MapInfo::CUR_PAGE>(g_map_info) == std::get<MapInfo::MAX_PAGE>(g_map_info) ) {
|
if ( global_vars.map.cur_page == global_vars.map.max_page &&
|
||||||
|
getFlag( MAP_RIGHT_ENABLED_FLAG ) ) {
|
||||||
|
setFlag( UPDATE_FLAG );
|
||||||
|
unsetFlag( MAP_RIGHT_ENABLED_FLAG );
|
||||||
right->setTextColor( font, "#00FF00", "#000000", 0.1 );
|
right->setTextColor( font, "#00FF00", "#000000", 0.1 );
|
||||||
right->changeText( "+" );
|
right->changeText( "+" );
|
||||||
} else {
|
} else if ( global_vars.map.cur_page != global_vars.map.max_page &&
|
||||||
|
!getFlag( MAP_RIGHT_ENABLED_FLAG ) ) {
|
||||||
|
setFlag( UPDATE_FLAG );
|
||||||
|
setFlag( MAP_RIGHT_ENABLED_FLAG );
|
||||||
right->setTextColor( font, "#000000", "#282828", 0.05 );
|
right->setTextColor( font, "#000000", "#282828", 0.05 );
|
||||||
right->changeText( ">" );
|
right->changeText( ">" );
|
||||||
}
|
}
|
||||||
if ( std::get<ToolInfo::CUR_PAGE>(g_tool_info) == 0 ) {
|
if ( global_vars.tool.cur_page == 0 &&
|
||||||
|
getFlag( TOOL_LEFT_ENABLED_FLAG ) ) {
|
||||||
|
setFlag( UPDATE_FLAG );
|
||||||
|
unsetFlag( TOOL_LEFT_ENABLED_FLAG );
|
||||||
left_tool->setTextColor( font, "#CCCCCC", "#CCCCCC", 0.05 );
|
left_tool->setTextColor( font, "#CCCCCC", "#CCCCCC", 0.05 );
|
||||||
} else {
|
} else if ( global_vars.tool.cur_page != 0 &&
|
||||||
|
!getFlag( TOOL_LEFT_ENABLED_FLAG ) ) {
|
||||||
|
setFlag( UPDATE_FLAG );
|
||||||
|
setFlag( TOOL_LEFT_ENABLED_FLAG );
|
||||||
left_tool->setTextColor( font, "#000000", "#282828", 0.05 );
|
left_tool->setTextColor( font, "#000000", "#282828", 0.05 );
|
||||||
}
|
}
|
||||||
if ( std::get<ToolInfo::CUR_PAGE>(g_tool_info) == std::get<ToolInfo::MAX_PAGE>(g_tool_info) ) {
|
if ( global_vars.tool.cur_page == global_vars.tool.max_page &&
|
||||||
|
getFlag( TOOL_RIGHT_ENABLED_FLAG ) ) {
|
||||||
|
setFlag( UPDATE_FLAG );
|
||||||
|
unsetFlag( TOOL_RIGHT_ENABLED_FLAG );
|
||||||
right_tool->setTextColor( font, "#CCCCCC", "#CCCCCC", 0.05 );
|
right_tool->setTextColor( font, "#CCCCCC", "#CCCCCC", 0.05 );
|
||||||
} else {
|
} else if ( global_vars.tool.cur_page != global_vars.tool.max_page &&
|
||||||
|
!getFlag( TOOL_RIGHT_ENABLED_FLAG ) ) {
|
||||||
|
setFlag( UPDATE_FLAG );
|
||||||
|
setFlag( TOOL_RIGHT_ENABLED_FLAG );
|
||||||
right_tool->setTextColor( font, "#000000", "#282828", 0.05 );
|
right_tool->setTextColor( font, "#000000", "#282828", 0.05 );
|
||||||
}
|
}
|
||||||
if ( g_update_size ) {
|
if ( getFlag( UPDATE_FLAG ) ) {
|
||||||
scene->updateSizeAndPosition();
|
scene->updateSizeAndPosition();
|
||||||
|
unsetFlag( UPDATE_FLAG );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
saveMap( "test_binary2.bin", g_objects );
|
saveMap( "test_binary2.bin", global_vars.objects );
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user