game/mario/editor.cpp

666 lines
25 KiB
C++

#include "../sdlpp/sdlpp.hpp"
#include "sprites.hpp"
#ifdef _WIN32
#include "../sdlpp/SDL2/SDL2_framerate.h"
#include <ctime>
#include <string>
#include <windows.h>
#else
#include <SDL2/SDL2_framerate.h>
#endif // UNIX
#include <array>
#include <thread>
#include <mutex>
#include "global_vars.hpp"
#include "objectids.hpp"
#include "blocks.hpp"
#include "maploader.hpp"
#include "../sdlpp/sdlpp_mouse.hpp"
#include "edit_box.hpp"
#include "editor_visitor.hpp"
#include "tool_box.hpp"
#define MAP_WIDTH 18
#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 {
uint64_t cur_flags;
uint64_t prev_flags;
SDLPP::Vec2D< int > edit_box;
SDLPP::Vec2D< int > tool_box;
};
struct MapInfo {
int cur_page;
int max_page;
};
struct ToolInfo {
uint64_t index;
int cur_page;
int max_page;
};
struct GlobalVars {
MouseInfo mouse;
MapInfo map;
ToolInfo tool;
uint64_t flags;
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;
};
GlobalVars global_vars;
std::mutex destruction_mutex;
enum LandType::Value g_current_world_type = LandType::OVERWORLD;
void updateTool() {
auto tool_index = global_vars.tool.index;
auto tool_role = getBlockRole( possibleBlocks[tool_index] );
std::shared_ptr< SDLPP::Texture > target_texture = nullptr;
switch ( tool_role ) {
case BlockRole::TERRAIN:
target_texture = global_vars.translucent_terrain_texture;
break;
case BlockRole::MARIO:
target_texture = global_vars.translucent_mario_texture;
break;
case BlockRole::MODIFIER:
break;
case BlockRole::CHARACTER:
break;
}
global_vars.current_tool->setTexture(
target_texture,
getSourceRectByID( possibleBlocks[tool_index], g_current_world_type ) );
global_vars.current_tool->setId( possibleBlocks[tool_index] );
global_vars.current_tool->getCollisions()[0]->setId(
possibleBlocks[tool_index] );
}
void removeMario() {
if ( !global_vars.mario )
return;
auto prev = global_vars.objects[global_vars.mario_pos.getX()]
[global_vars.mario_pos.getY()];
// remove character/modifiers
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
};
global_vars.mario->destroy();
}
void updateToolSelection( int prev_index ) {
size_t prev = prev_index * 8;
size_t cur = global_vars.tool.cur_page * 8;
for ( size_t i = prev;
i < ( global_vars.tools.size() < prev + 8 ? global_vars.tools.size()
: prev + 8 );
i++ ) {
global_vars.tools[i]->setHidden( true );
}
for ( size_t i = cur;
i < ( global_vars.tools.size() < cur + 8 ? global_vars.tools.size()
: cur + 8 );
i++ ) {
global_vars.tools[i]->setHidden( false );
}
}
void moveToolsLeft() {
global_vars.tool.cur_page--;
updateToolSelection( global_vars.tool.cur_page + 1 );
}
void moveToolsRight() {
global_vars.tool.cur_page++;
updateToolSelection( global_vars.tool.cur_page - 1 );
}
// TODO add red outline to currently selected tool
// add WSAD navigation for the red highlight
// add mouse wheel navigation
void selectPrevTool() {
if ( global_vars.tool.index == 0 )
return;
if ( global_vars.tool.index % 8 == 0 ) {
moveToolsLeft();
}
global_vars.tool.index--;
updateTool();
}
void selectNextTool() {
if ( global_vars.tool.index == global_vars.tools.size() - 1 )
return;
if ( global_vars.tool.index % 8 == 7 ) {
moveToolsRight();
}
global_vars.tool.index++;
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 ) {
switch ( key ) {
case SDLK_ESCAPE:
setFlag( QUIT_FLAG );
break;
case SDLK_a:
selectPrevTool();
break;
case SDLK_d:
selectNextTool();
break;
case SDLK_r:
scene.getRenderer().setRenderColiders(
!scene.getRenderer().getRenderColiders() );
default:
break;
}
}
void getMousePositionFlags( SDLPP::Scene &scene ) {
auto mouse = scene.getObjects( { EDITOR_MOUSE_ID } )[0];
// move mouse colider to mouse position
mouse->setPos( SDLPP::Mouse::getMousePositionDouble(
scene.getRenderer(), SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER ) );
MouseVisitor visitor;
scene.visitCollisions( *mouse, visitor );
global_vars.mouse.cur_flags = visitor.getFlags();
global_vars.mouse.edit_box = visitor.getEditBoxIndexes();
global_vars.mouse.tool_box = visitor.getToolBoxIndexes();
// if we found an edit box, move tool icon to that box
if ( visitor.foundEditBox() ) {
const auto &box = global_vars.mouse.edit_box;
global_vars.current_tool->setPos( BLOCK_SIZE + box.getX() * BLOCK_SIZE,
( MAP_WIDTH - MAP_HEIGHT + 2 ) *
BLOCK_SIZE +
box.getY() * BLOCK_SIZE );
}
}
void mouseUpAction( uint64_t flags, SDLPP::Scene &scene ) {
if ( MouseVisitor::moveMapLeft( flags ) && global_vars.map.cur_page != 0 ) {
global_vars.map.cur_page--;
scene.moveEverything( BLOCK_SIZE, 0 );
}
if ( MouseVisitor::moveMapRight( flags ) ) {
if ( global_vars.map.cur_page == global_vars.map.max_page ) {
// add column
global_vars.objects.resize( global_vars.objects.size() + 1 );
global_vars.map.max_page++;
}
global_vars.map.cur_page += 1;
scene.moveEverything( -BLOCK_SIZE, 0 );
}
if ( MouseVisitor::moveToolsLeft( flags ) &&
global_vars.tool.cur_page != 0 ) {
global_vars.tool.cur_page--;
updateToolSelection( global_vars.tool.cur_page + 1 );
}
if ( MouseVisitor::moveToolsRight( flags ) &&
global_vars.tool.cur_page != global_vars.tool.max_page ) {
global_vars.tool.cur_page++;
updateToolSelection( global_vars.tool.cur_page - 1 );
}
}
SDLPP::Vec2D< int > getSelectedObjectPosition() {
return global_vars.mouse.edit_box +
SDLPP::Vec2D< int >( global_vars.map.cur_page, 0 );
}
mapObjectType &getSelectedObject() {
auto pos = getSelectedObjectPosition();
return global_vars.objects[pos.getX()][pos.getY()];
}
void placeTool( SDLPP::Scene &scene ) {
std::lock_guard< std::mutex > lock( destruction_mutex );
ToolVisitor visitor;
auto tool_type = getBlockRole( global_vars.current_tool->getId() );
switch ( tool_type ) {
case BlockRole::TERRAIN:
visitor.setVisitorType( VisitorType::Terrain );
break;
default:
visitor.setVisitorType( VisitorType::Modifier );
break;
}
scene.visitCollisions( *global_vars.current_tool, visitor );
if ( visitor.removeBlock() && !visitor.addBlock() ) {
auto &obj = getSelectedObject();
switch ( visitor.getVisitorType() ) {
case VisitorType::Terrain:
std::get< MapObject::TERRAIN_TYPE >( obj ) = LandType::OVERWORLD;
std::get< MapObject::TERRAIN_ID >( obj ) = 0;
break;
case VisitorType::Modifier:
std::get< MapObject::CHARACTER_TYPE >( obj ) = 0;
std::get< MapObject::CHARACTER_ID >( obj ) = 0;
std::get< MapObject::MODIFIER_TYPE >( obj ) = 0;
std::get< MapObject::MODIFIER_DATA >( obj ) = 0;
break;
default:
break;
}
} else if ( visitor.addBlock() ) {
auto &obj = getSelectedObject();
auto renderer = scene.getRendererShared();
int z_index = 1;
std::shared_ptr< SDLPP::RenderObject > new_obj = nullptr;
switch ( visitor.getVisitorType() ) {
case VisitorType::Terrain:
std::get< MapObject::TERRAIN_TYPE >( obj ) = LandType::OVERWORLD;
std::get< MapObject::TERRAIN_ID >( obj ) =
global_vars.current_tool->getId();
// TODO why 1 +?
new_obj = createTerrainBlock(
global_vars.current_tool->getId(), LandType::OVERWORLD,
renderer, 1 + global_vars.mouse.edit_box.getX(),
global_vars.mouse.edit_box.getY(), true );
new_obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID );
break;
case VisitorType::Modifier:
// TODO check if modifier or character
std::get< MapObject::CHARACTER_TYPE >( obj ) = LandType::OVERWORLD;
// TODO character ID
std::get< MapObject::CHARACTER_ID >( obj ) = MARIO_ID;
std::get< MapObject::MODIFIER_TYPE >( obj ) = 0;
std::get< MapObject::MODIFIER_DATA >( obj ) = 0;
new_obj = createMario( LandType::OVERWORLD, renderer,
1 + global_vars.mouse.edit_box.getX(),
global_vars.mouse.edit_box.getY() );
// remove mario if exists
removeMario();
global_vars.mario = new_obj;
global_vars.mario_pos = getSelectedObjectPosition();
new_obj->getCollisions()[0]->setId( EDITOR_CHARACTER_ID );
z_index = scene.getObjects().size() - 1;
break;
default:
break;
}
scene.addObject( new_obj );
scene.setZIndex( new_obj, z_index );
}
}
void pollEvents( SDLPP::Scene &scene ) {
SDL_Event event;
while ( SDLPP::getSDLEvent( event ) ) {
switch ( event.type ) {
case SDL_QUIT:
setFlag( QUIT_FLAG );
break;
case SDL_KEYUP:
handleKeyUp( event.key.keysym.sym, scene );
break;
case SDL_WINDOWEVENT:
if ( event.window.event == SDL_WINDOWEVENT_RESIZED ) {
setFlag( UPDATE_FLAG );
}
break;
case SDL_MOUSEMOTION:
getMousePositionFlags( scene );
break;
case SDL_MOUSEBUTTONUP:
if ( global_vars.mouse.cur_flags == global_vars.mouse.prev_flags ) {
mouseUpAction( global_vars.mouse.cur_flags, scene );
}
if ( global_vars.mouse.edit_box.getX() != -1 ) {
placeTool( scene );
}
if ( global_vars.mouse.tool_box.getX() != -1 ) {
auto &tool_box = global_vars.mouse.tool_box;
size_t index = tool_box.getY() * 4 + tool_box.getX();
if ( index < global_vars.tools.size() ) {
global_vars.tool.index =
global_vars.tool.cur_page * 8 + index;
updateTool();
}
}
break;
case SDL_MOUSEBUTTONDOWN:
// store current mouse flags in previous mouse flags
global_vars.mouse.prev_flags = global_vars.mouse.cur_flags;
break;
default:
break;
}
}
}
void doInput( std::shared_ptr< SDLPP::Scene > scene ) {
FPSmanager gFPS;
SDL_initFramerate( &gFPS );
SDL_setFramerate( &gFPS, 200 );
while ( true ) {
SDL_framerateDelay( &gFPS );
pollEvents( *scene );
scene->updateScene();
}
}
#ifdef _WIN32
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
PWSTR szCmdLine, int nCmdShow ) {
#else
int main() {
#endif
SDLPP::init();
SDLPP::Window w( "Mario editor!" );
w.setResizable( true );
BLOCK_SIZE = 1.0 / ( MAP_WIDTH + 2 );
auto renderer = std::make_shared< SDLPP::Renderer >( w );
renderer->setBlendMode( SDL_BLENDMODE_BLEND );
// prepare global vars
g_terrain_texture = std::make_shared< SDLPP::Texture >(
renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY );
g_mario_texture = std::make_shared< SDLPP::Texture >(
renderer, "sprites/mario.png", MARIO_OVERWORLD_COLORKEY );
auto scene = std::make_shared< SDLPP::Scene >( renderer );
auto bg = std::make_shared< SDLPP::RectangleRender >(
0, 0, 10, 10, renderer, MARIO_OVERWORLD_COLORKEY, true );
bg->setPermanent();
bg->setId( 1 );
scene->addObject( bg );
loadMap( scene, "test_binary.bin", renderer, global_vars.objects );
// grid
for ( int i = 1; i < ( MAP_WIDTH + 2 ); i++ ) {
auto line_vertical = std::make_shared< SDLPP::LineRenderer >(
i * BLOCK_SIZE, 1 - MAP_HEIGHT * BLOCK_SIZE, i * BLOCK_SIZE, 1.0,
renderer, "#282828" );
line_vertical->setPermanent();
line_vertical->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
scene->addObject( line_vertical );
if ( i > ( MAP_WIDTH - MAP_HEIGHT ) ) {
auto line_horizontal = std::make_shared< SDLPP::LineRenderer >(
BLOCK_SIZE, ( i + 1 ) * BLOCK_SIZE,
( MAP_WIDTH + 1 ) * BLOCK_SIZE, ( i + 1 ) * BLOCK_SIZE,
renderer, "#282828" );
line_horizontal->setPermanent();
line_horizontal->setAlignment( SDLPP::OBJ_CENTER,
SDLPP::OBJ_CENTER );
scene->addObject( line_horizontal );
}
}
// white rectangles
auto rectangle1 = std::make_shared< SDLPP::RectangleRender >(
0, ( MAP_WIDTH + 2 - MAP_HEIGHT ) * BLOCK_SIZE, BLOCK_SIZE,
MAP_HEIGHT * BLOCK_SIZE, renderer, "#FFFFFF88", true );
rectangle1->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
rectangle1->setId( EDITOR_LEFT_MAP_ID );
rectangle1->setPermanent();
rectangle1->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) );
scene->addObject( rectangle1 );
// white rectangles
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, renderer, "#FFFFFF88", true );
rectangle2->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
rectangle2->setId( EDITOR_RIGHT_MAP_ID );
rectangle2->setPermanent();
rectangle2->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) );
scene->addObject( rectangle2 );
auto font = std::make_shared< SDLPP::Font >( "testfont.ttf", 36 );
auto font_config = std::make_shared< SDLPP::FontConfiguration >(
font, "#000000", "#282828", 0.05 );
auto left = std::make_shared< SDLPP::TextRenderer >(
0, ( MAP_WIDTH - MAP_HEIGHT / 2.0 + 1.5 ) * BLOCK_SIZE, BLOCK_SIZE,
BLOCK_SIZE, renderer, "<", font_config );
left->setId( 0 );
left->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
left->setPermanent();
scene->addObject( left );
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, renderer, ">", font_config );
right->setId( 0 );
right->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
right->setPermanent();
scene->addObject( right );
for ( int i = 0; i < MAP_WIDTH; i++ ) {
for ( int j = 0; j < MAP_HEIGHT; j++ ) {
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,
renderer );
mouse->setMinWidth( 1 );
mouse->setMinHeight( 1 );
mouse->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
mouse->setId( EDITOR_MOUSE_ID );
mouse->setColiderColor( "#00FF00" );
mouse->addCollision( SDLPP::RectColider( { 0, 0 }, { 1, 1 } ) );
scene->addObject( mouse );
global_vars.map.max_page = global_vars.objects.size() - MAP_WIDTH;
// tools
global_vars.tool.max_page = ( possibleBlocks.size() - 1 ) / 8;
for ( int i = 0; i < 4; i++ ) {
auto tool_box1 = std::make_shared< ToolBox >( i, 0, MAP_WIDTH,
MAP_HEIGHT, renderer );
auto tool_box2 = std::make_shared< ToolBox >( i, 1, MAP_WIDTH,
MAP_HEIGHT, renderer );
scene->addObject( tool_box1 );
scene->addObject( tool_box2 );
// std::cout << "TOOL BOX POS: " << tool_box1->getPos().getX() <<
// ", " << tool_box1->getPos().getY() << std::endl; std::cout <<
// "TOOL BOX POS: " << tool_box2->getPos().getX() << ", " <<
// tool_box2->getPos().getY() << std::endl;
}
int tool_index = 0;
for ( auto &block : possibleBlocks ) {
if ( block == MARIO_ID ) {
global_vars.tools.push_back(
createMario( LandType::OVERWORLD, renderer, 0, 0 ) );
} else {
global_vars.tools.push_back( createTerrainBlock(
block, LandType::OVERWORLD, renderer, false ) );
}
global_vars.tools.back()->setHidden( true );
global_vars.tools.back()->setPermanent();
auto x = tool_index % 4;
auto y = tool_index / 4;
// TODO add 14 and 1 as constants somewhere
// TODO investigate when not permanent requires `-1` on x position
global_vars.tools.back()->setPos( ( MAP_WIDTH - 4 ) * BLOCK_SIZE +
x * BLOCK_SIZE,
BLOCK_SIZE + y * BLOCK_SIZE );
// std::cout << "TOOL POS: " << tools.back()->getPos().getX() <<
// ", " << tools.back()->getPos().getY() << std::endl;
scene->addObject( global_vars.tools.back() );
tool_index = ( tool_index + 1 ) % 8;
}
for ( int i = 0; i < 5; i++ ) {
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, 3 * BLOCK_SIZE,
renderer, "#282828" );
line->setPermanent();
line->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
scene->addObject( line );
}
for ( int i = 0; i < 3; i++ ) {
auto line = std::make_shared< SDLPP::LineRenderer >(
( MAP_WIDTH - 4 ) * BLOCK_SIZE, BLOCK_SIZE + i * BLOCK_SIZE,
( MAP_WIDTH - 4 ) * BLOCK_SIZE + 4 * BLOCK_SIZE,
BLOCK_SIZE + i * BLOCK_SIZE, renderer, "#282828" );
line->setPermanent();
line->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
scene->addObject( line );
}
auto tool_rect1 = std::make_shared< SDLPP::RectangleRender >(
( MAP_WIDTH - 5 ) * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
renderer, "#FFFFFF88", true );
tool_rect1->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
tool_rect1->setId( EDITOR_LEFT_TOOL_ID );
tool_rect1->setPermanent();
tool_rect1->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) );
scene->addObject( tool_rect1 );
// white rectangles
auto tool_rect2 = std::make_shared< SDLPP::RectangleRender >(
MAP_WIDTH * BLOCK_SIZE, 1 * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
renderer, "#FFFFFF88", true );
tool_rect2->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
tool_rect2->setId( EDITOR_RIGHT_TOOL_ID );
tool_rect2->setPermanent();
tool_rect2->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) );
scene->addObject( tool_rect2 );
auto left_tool = std::make_shared< SDLPP::TextRenderer >(
( MAP_WIDTH - 5 ) * BLOCK_SIZE, 1.5 * BLOCK_SIZE, BLOCK_SIZE,
BLOCK_SIZE, renderer, "<", font_config );
left_tool->setId( 0 );
left_tool->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
left_tool->setPermanent();
scene->addObject( left_tool );
auto right_tool = std::make_shared< SDLPP::TextRenderer >(
MAP_WIDTH * BLOCK_SIZE, 1.5 * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE,
renderer, ">", font_config );
right_tool->setId( 0 );
right_tool->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
right_tool->setPermanent();
scene->addObject( right_tool );
global_vars.translucent_terrain_texture =
std::make_shared< SDLPP::Texture >( renderer, "sprites/terrain.png",
MARIO_OVERWORLD_COLORKEY );
global_vars.translucent_terrain_texture->setAlpha( 100 );
global_vars.translucent_mario_texture = std::make_shared< SDLPP::Texture >(
renderer, "sprites/mario.png", MARIO_OVERWORLD_COLORKEY );
global_vars.translucent_mario_texture->setAlpha( 100 );
global_vars.current_tool = createTerrainBlock(
possibleBlocks[global_vars.tool.index], LandType::OVERWORLD, renderer,
global_vars.translucent_terrain_texture, false );
global_vars.current_tool->addCollision(
SDLPP::RectColider( 0.1, 0.1, 0.8, 0.8 ) );
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 );
FPSmanager gFPS;
SDL_initFramerate( &gFPS );
SDL_setFramerate( &gFPS, 60 );
updateToolSelection( 0 );
auto base = SDL_GetTicks();
int frames = 0;
std::thread inputThread( doInput, scene );
inputThread.detach();
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_framerateDelay( &gFPS );
std::lock_guard< std::mutex > lock( destruction_mutex );
scene->renderScene();
renderer->presentRenderer();
frames++;
if ( SDL_GetTicks() - base >= 1000 ) {
std::cout << "FPS: " << frames << std::endl;
frames = 0;
base = SDL_GetTicks();
}
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 );
} 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 );
}
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->changeText( "+" );
} 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->changeText( ">" );
}
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 );
} 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 );
}
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 );
} 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 );
}
if ( getFlag( UPDATE_FLAG ) ) {
scene->updateSizeAndPosition();
unsetFlag( UPDATE_FLAG );
}
}
saveMap( "test_binary2.bin", global_vars.objects );
return 0;
}