2021-04-30 19:02:14 +00:00
|
|
|
#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
|
|
|
|
|
2021-05-07 06:35:01 +00:00
|
|
|
#include <array>
|
2021-04-30 19:02:14 +00:00
|
|
|
#include <thread>
|
2021-05-02 12:14:11 +00:00
|
|
|
#include <mutex>
|
2021-04-30 19:02:14 +00:00
|
|
|
#include "global_vars.hpp"
|
|
|
|
#include "objectids.hpp"
|
|
|
|
#include "blocks.hpp"
|
|
|
|
#include "maploader.hpp"
|
2021-05-01 19:55:43 +00:00
|
|
|
#include "../sdlpp/sdlpp_mouse.hpp"
|
2021-05-02 12:14:11 +00:00
|
|
|
#include "edit_box.hpp"
|
|
|
|
#include "editor_visitor.hpp"
|
2021-05-07 07:43:57 +00:00
|
|
|
#include "tool_box.hpp"
|
2021-04-30 19:02:14 +00:00
|
|
|
|
2021-05-22 20:13:22 +00:00
|
|
|
#define MAP_WIDTH 18
|
2021-05-09 18:45:52 +00:00
|
|
|
#define MAP_HEIGHT 16
|
|
|
|
|
2021-05-22 20:13:22 +00:00
|
|
|
#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
|
|
|
|
|
2021-05-08 22:43:53 +00:00
|
|
|
struct MouseInfo {
|
2021-05-22 20:13:22 +00:00
|
|
|
uint64_t cur_flags;
|
|
|
|
uint64_t prev_flags;
|
|
|
|
SDLPP::Vec2D< int > edit_box;
|
|
|
|
SDLPP::Vec2D< int > tool_box;
|
2021-05-08 22:43:53 +00:00
|
|
|
};
|
|
|
|
|
2021-05-09 18:21:53 +00:00
|
|
|
struct MapInfo {
|
2021-05-22 20:13:22 +00:00
|
|
|
int cur_page;
|
|
|
|
int max_page;
|
2021-05-09 18:21:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ToolInfo {
|
2021-05-22 20:13:22 +00:00
|
|
|
uint64_t index;
|
|
|
|
int cur_page;
|
|
|
|
int max_page;
|
2021-05-09 18:21:53 +00:00
|
|
|
};
|
|
|
|
|
2021-05-22 20:13:22 +00:00
|
|
|
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;
|
|
|
|
};
|
2021-05-07 21:17:05 +00:00
|
|
|
|
2021-05-22 20:13:22 +00:00
|
|
|
GlobalVars global_vars;
|
|
|
|
std::mutex destruction_mutex;
|
2021-05-02 12:28:17 +00:00
|
|
|
|
2021-05-08 22:43:53 +00:00
|
|
|
enum LandType::Value g_current_world_type = LandType::OVERWORLD;
|
|
|
|
|
|
|
|
void updateTool() {
|
2021-05-22 20:13:22 +00:00
|
|
|
auto tool_index = global_vars.tool.index;
|
|
|
|
auto tool_role = getBlockRole( possibleBlocks[tool_index] );
|
2021-05-08 22:46:10 +00:00
|
|
|
std::shared_ptr< SDLPP::Texture > target_texture = nullptr;
|
|
|
|
switch ( tool_role ) {
|
|
|
|
case BlockRole::TERRAIN:
|
2021-05-22 20:13:22 +00:00
|
|
|
target_texture = global_vars.translucent_terrain_texture;
|
2021-05-08 22:46:10 +00:00
|
|
|
break;
|
|
|
|
case BlockRole::MARIO:
|
2021-05-22 20:13:22 +00:00
|
|
|
target_texture = global_vars.translucent_mario_texture;
|
2021-05-08 22:46:10 +00:00
|
|
|
break;
|
|
|
|
case BlockRole::MODIFIER:
|
2021-05-25 22:46:19 +00:00
|
|
|
target_texture = global_vars.translucent_terrain_texture;
|
2021-05-08 22:46:10 +00:00
|
|
|
break;
|
|
|
|
case BlockRole::CHARACTER:
|
|
|
|
break;
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
2021-05-22 20:13:22 +00:00
|
|
|
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] );
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void removeMario() {
|
2021-05-22 20:13:22 +00:00
|
|
|
if ( !global_vars.mario )
|
2021-05-08 22:43:53 +00:00
|
|
|
return;
|
2021-05-22 20:13:22 +00:00
|
|
|
auto prev = global_vars.objects[global_vars.mario_pos.getX()]
|
|
|
|
[global_vars.mario_pos.getY()];
|
2021-05-08 22:43:53 +00:00
|
|
|
// remove character/modifiers
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars
|
|
|
|
.objects[global_vars.mario_pos.getX()][global_vars.mario_pos.getY()] = {
|
2021-05-08 22:46:10 +00:00
|
|
|
std::get< 0 >( prev ), std::get< 1 >( prev ), 0, 0, 0, 0
|
|
|
|
};
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars.mario->destroy();
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
|
|
|
|
2021-05-08 22:46:10 +00:00
|
|
|
void updateToolSelection( int prev_index ) {
|
2021-05-08 22:43:53 +00:00
|
|
|
size_t prev = prev_index * 8;
|
2021-05-22 20:13:22 +00:00
|
|
|
size_t cur = global_vars.tool.cur_page * 8;
|
2021-05-08 22:46:10 +00:00
|
|
|
for ( size_t i = prev;
|
2021-05-22 20:13:22 +00:00
|
|
|
i < ( global_vars.tools.size() < prev + 8 ? global_vars.tools.size()
|
|
|
|
: prev + 8 );
|
|
|
|
i++ ) {
|
|
|
|
global_vars.tools[i]->setHidden( true );
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
2021-05-08 22:46:10 +00:00
|
|
|
for ( size_t i = cur;
|
2021-05-22 20:13:22 +00:00
|
|
|
i < ( global_vars.tools.size() < cur + 8 ? global_vars.tools.size()
|
|
|
|
: cur + 8 );
|
|
|
|
i++ ) {
|
|
|
|
global_vars.tools[i]->setHidden( false );
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void moveToolsLeft() {
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars.tool.cur_page--;
|
|
|
|
updateToolSelection( global_vars.tool.cur_page + 1 );
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void moveToolsRight() {
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars.tool.cur_page++;
|
|
|
|
updateToolSelection( global_vars.tool.cur_page - 1 );
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO add red outline to currently selected tool
|
|
|
|
// add WSAD navigation for the red highlight
|
2021-05-22 20:13:22 +00:00
|
|
|
// add mouse wheel navigation
|
2021-05-08 22:43:53 +00:00
|
|
|
void selectPrevTool() {
|
2021-05-22 20:13:22 +00:00
|
|
|
if ( global_vars.tool.index == 0 )
|
2021-05-08 22:43:53 +00:00
|
|
|
return;
|
2021-05-22 20:13:22 +00:00
|
|
|
if ( global_vars.tool.index % 8 == 0 ) {
|
2021-05-08 22:43:53 +00:00
|
|
|
moveToolsLeft();
|
|
|
|
}
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars.tool.index--;
|
2021-05-08 22:43:53 +00:00
|
|
|
updateTool();
|
|
|
|
}
|
|
|
|
|
|
|
|
void selectNextTool() {
|
2021-05-22 20:13:22 +00:00
|
|
|
if ( global_vars.tool.index == global_vars.tools.size() - 1 )
|
2021-05-08 22:43:53 +00:00
|
|
|
return;
|
2021-05-22 20:13:22 +00:00
|
|
|
if ( global_vars.tool.index % 8 == 7 ) {
|
2021-05-08 22:43:53 +00:00
|
|
|
moveToolsRight();
|
|
|
|
}
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars.tool.index++;
|
2021-05-08 22:43:53 +00:00
|
|
|
updateTool();
|
|
|
|
}
|
|
|
|
|
2021-05-22 20:13:22 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-05-08 22:43:53 +00:00
|
|
|
void handleKeyUp( SDL_Keycode key, SDLPP::Scene &scene ) {
|
2021-04-30 19:02:14 +00:00
|
|
|
switch ( key ) {
|
|
|
|
case SDLK_ESCAPE:
|
2021-05-22 20:13:22 +00:00
|
|
|
setFlag( QUIT_FLAG );
|
2021-04-30 19:02:14 +00:00
|
|
|
break;
|
|
|
|
case SDLK_a:
|
2021-05-08 22:43:53 +00:00
|
|
|
selectPrevTool();
|
2021-04-30 19:02:14 +00:00
|
|
|
break;
|
|
|
|
case SDLK_d:
|
2021-05-08 22:43:53 +00:00
|
|
|
selectNextTool();
|
2021-04-30 19:02:14 +00:00
|
|
|
break;
|
|
|
|
case SDLK_r:
|
|
|
|
scene.getRenderer().setRenderColiders(
|
|
|
|
!scene.getRenderer().getRenderColiders() );
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-08 22:46:10 +00:00
|
|
|
void getMousePositionFlags( SDLPP::Scene &scene ) {
|
|
|
|
auto mouse = scene.getObjects( { EDITOR_MOUSE_ID } )[0];
|
2021-05-08 22:43:53 +00:00
|
|
|
// move mouse colider to mouse position
|
2021-05-08 22:46:10 +00:00
|
|
|
mouse->setPos( SDLPP::Mouse::getMousePositionDouble(
|
|
|
|
scene.getRenderer(), SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER ) );
|
2021-05-02 12:28:17 +00:00
|
|
|
|
2021-05-08 22:43:53 +00:00
|
|
|
MouseVisitor visitor;
|
2021-05-08 22:46:10 +00:00
|
|
|
scene.visitCollisions( *mouse, visitor );
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars.mouse.cur_flags = visitor.getFlags();
|
|
|
|
global_vars.mouse.edit_box = visitor.getEditBoxIndexes();
|
|
|
|
global_vars.mouse.tool_box = visitor.getToolBoxIndexes();
|
2021-05-08 22:43:53 +00:00
|
|
|
// if we found an edit box, move tool icon to that box
|
2021-05-08 22:46:10 +00:00
|
|
|
if ( visitor.foundEditBox() ) {
|
2021-05-22 20:13:22 +00:00
|
|
|
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 );
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
2021-05-07 21:17:05 +00:00
|
|
|
}
|
|
|
|
|
2021-05-08 22:46:10 +00:00
|
|
|
void mouseUpAction( uint64_t flags, SDLPP::Scene &scene ) {
|
2021-05-22 20:13:22 +00:00
|
|
|
if ( MouseVisitor::moveMapLeft( flags ) && global_vars.map.cur_page != 0 ) {
|
|
|
|
global_vars.map.cur_page--;
|
2021-05-08 22:46:10 +00:00
|
|
|
scene.moveEverything( BLOCK_SIZE, 0 );
|
2021-05-07 08:08:41 +00:00
|
|
|
}
|
2021-05-08 22:46:10 +00:00
|
|
|
if ( MouseVisitor::moveMapRight( flags ) ) {
|
2021-05-22 20:13:22 +00:00
|
|
|
if ( global_vars.map.cur_page == global_vars.map.max_page ) {
|
2021-05-08 22:43:53 +00:00
|
|
|
// add column
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars.objects.resize( global_vars.objects.size() + 1 );
|
|
|
|
global_vars.map.max_page++;
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars.map.cur_page += 1;
|
2021-05-08 22:46:10 +00:00
|
|
|
scene.moveEverything( -BLOCK_SIZE, 0 );
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
2021-05-22 20:13:22 +00:00
|
|
|
if ( MouseVisitor::moveToolsLeft( flags ) &&
|
|
|
|
global_vars.tool.cur_page != 0 ) {
|
|
|
|
global_vars.tool.cur_page--;
|
|
|
|
updateToolSelection( global_vars.tool.cur_page + 1 );
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
2021-05-08 22:46:10 +00:00
|
|
|
if ( MouseVisitor::moveToolsRight( flags ) &&
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars.tool.cur_page != global_vars.tool.max_page ) {
|
|
|
|
global_vars.tool.cur_page++;
|
|
|
|
updateToolSelection( global_vars.tool.cur_page - 1 );
|
2021-05-07 08:08:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-08 22:46:10 +00:00
|
|
|
SDLPP::Vec2D< int > getSelectedObjectPosition() {
|
2021-05-22 20:13:22 +00:00
|
|
|
return global_vars.mouse.edit_box +
|
|
|
|
SDLPP::Vec2D< int >( global_vars.map.cur_page, 0 );
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mapObjectType &getSelectedObject() {
|
|
|
|
auto pos = getSelectedObjectPosition();
|
2021-05-22 20:13:22 +00:00
|
|
|
return global_vars.objects[pos.getX()][pos.getY()];
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
|
|
|
|
2021-05-08 22:46:10 +00:00
|
|
|
void placeTool( SDLPP::Scene &scene ) {
|
2021-05-22 20:13:22 +00:00
|
|
|
std::lock_guard< std::mutex > lock( destruction_mutex );
|
2021-05-08 22:43:53 +00:00
|
|
|
|
|
|
|
ToolVisitor visitor;
|
2021-05-22 20:13:22 +00:00
|
|
|
auto tool_type = getBlockRole( global_vars.current_tool->getId() );
|
2021-05-08 22:46:10 +00:00
|
|
|
switch ( tool_type ) {
|
|
|
|
case BlockRole::TERRAIN:
|
|
|
|
visitor.setVisitorType( VisitorType::Terrain );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
visitor.setVisitorType( VisitorType::Modifier );
|
|
|
|
break;
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
|
|
|
|
2021-05-22 20:13:22 +00:00
|
|
|
scene.visitCollisions( *global_vars.current_tool, visitor );
|
2021-05-08 22:46:10 +00:00
|
|
|
if ( visitor.removeBlock() && !visitor.addBlock() ) {
|
2021-05-08 22:43:53 +00:00
|
|
|
auto &obj = getSelectedObject();
|
2021-05-08 22:46:10 +00:00
|
|
|
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;
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
2021-05-08 22:46:10 +00:00
|
|
|
} else if ( visitor.addBlock() ) {
|
2021-05-08 22:43:53 +00:00
|
|
|
auto &obj = getSelectedObject();
|
2021-05-22 20:13:22 +00:00
|
|
|
auto renderer = scene.getRendererShared();
|
2021-05-08 22:43:53 +00:00
|
|
|
int z_index = 1;
|
2021-05-08 22:46:10 +00:00
|
|
|
std::shared_ptr< SDLPP::RenderObject > new_obj = nullptr;
|
|
|
|
switch ( visitor.getVisitorType() ) {
|
|
|
|
case VisitorType::Terrain:
|
|
|
|
std::get< MapObject::TERRAIN_TYPE >( obj ) = LandType::OVERWORLD;
|
2021-05-22 20:13:22 +00:00
|
|
|
std::get< MapObject::TERRAIN_ID >( obj ) =
|
|
|
|
global_vars.current_tool->getId();
|
2021-05-08 22:46:10 +00:00
|
|
|
// TODO why 1 +?
|
|
|
|
new_obj = createTerrainBlock(
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars.current_tool->getId(), LandType::OVERWORLD,
|
|
|
|
renderer, 1 + global_vars.mouse.edit_box.getX(),
|
|
|
|
global_vars.mouse.edit_box.getY(), true );
|
2021-05-08 22:46:10 +00:00
|
|
|
new_obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID );
|
|
|
|
break;
|
|
|
|
case VisitorType::Modifier:
|
2021-05-26 12:18:39 +00:00
|
|
|
if(tool_type == BlockRole::MARIO) {
|
2021-05-25 22:46:19 +00:00
|
|
|
std::get< MapObject::CHARACTER_TYPE >( obj ) = LandType::OVERWORLD;
|
|
|
|
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;
|
2021-05-26 12:18:39 +00:00
|
|
|
// TODO BlockRole::Character
|
2021-05-25 22:46:19 +00:00
|
|
|
} else {
|
|
|
|
// TODO data
|
|
|
|
std::cout << "Want to set: " << (int)std::get< MapObject::MODIFIER_TYPE >( obj ) << std::endl;
|
|
|
|
std::get< MapObject::MODIFIER_TYPE >( obj ) = global_vars.current_tool->getId();
|
|
|
|
std::get< MapObject::MODIFIER_DATA >( obj ) = 0;
|
|
|
|
std::cout << "SET MODIFIER_TYPE: " << (int)std::get< MapObject::MODIFIER_TYPE >( obj ) << std::endl;
|
|
|
|
new_obj = createTerrainBlock(
|
|
|
|
global_vars.current_tool->getId(), LandType::OVERWORLD,
|
|
|
|
renderer, 1 + global_vars.mouse.edit_box.getX(),
|
|
|
|
global_vars.mouse.edit_box.getY(), global_vars.translucent_terrain_texture, true );
|
|
|
|
new_obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID );
|
|
|
|
// TODO createModifierBlock
|
|
|
|
dynamic_cast<MarioBlock*>(new_obj.get())->setTerrain(false);
|
|
|
|
z_index = scene.getObjects().size() - 1;
|
|
|
|
}
|
2021-05-08 22:46:10 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
2021-05-08 22:46:10 +00:00
|
|
|
scene.addObject( new_obj );
|
|
|
|
scene.setZIndex( new_obj, z_index );
|
2021-04-30 19:02:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pollEvents( SDLPP::Scene &scene ) {
|
|
|
|
SDL_Event event;
|
|
|
|
while ( SDLPP::getSDLEvent( event ) ) {
|
|
|
|
switch ( event.type ) {
|
|
|
|
case SDL_QUIT:
|
2021-05-22 20:13:22 +00:00
|
|
|
setFlag( QUIT_FLAG );
|
2021-04-30 19:02:14 +00:00
|
|
|
break;
|
|
|
|
case SDL_KEYUP:
|
2021-05-08 22:43:53 +00:00
|
|
|
handleKeyUp( event.key.keysym.sym, scene );
|
2021-04-30 19:02:14 +00:00
|
|
|
break;
|
|
|
|
case SDL_WINDOWEVENT:
|
|
|
|
if ( event.window.event == SDL_WINDOWEVENT_RESIZED ) {
|
2021-05-22 20:13:22 +00:00
|
|
|
setFlag( UPDATE_FLAG );
|
2021-05-01 19:55:43 +00:00
|
|
|
}
|
|
|
|
break;
|
2021-05-08 22:43:53 +00:00
|
|
|
case SDL_MOUSEMOTION:
|
2021-05-08 22:46:10 +00:00
|
|
|
getMousePositionFlags( scene );
|
2021-05-01 19:55:43 +00:00
|
|
|
break;
|
|
|
|
case SDL_MOUSEBUTTONUP:
|
2021-05-22 20:13:22 +00:00
|
|
|
if ( global_vars.mouse.cur_flags == global_vars.mouse.prev_flags ) {
|
|
|
|
mouseUpAction( global_vars.mouse.cur_flags, scene );
|
2021-05-01 19:55:43 +00:00
|
|
|
}
|
2021-05-22 20:13:22 +00:00
|
|
|
if ( global_vars.mouse.edit_box.getX() != -1 ) {
|
2021-05-08 22:46:10 +00:00
|
|
|
placeTool( scene );
|
2021-04-30 19:02:14 +00:00
|
|
|
}
|
2021-05-22 20:13:22 +00:00
|
|
|
if ( global_vars.mouse.tool_box.getX() != -1 ) {
|
|
|
|
auto &tool_box = global_vars.mouse.tool_box;
|
2021-05-08 22:43:53 +00:00
|
|
|
size_t index = tool_box.getY() * 4 + tool_box.getX();
|
2021-05-22 20:13:22 +00:00
|
|
|
if ( index < global_vars.tools.size() ) {
|
|
|
|
global_vars.tool.index =
|
|
|
|
global_vars.tool.cur_page * 8 + index;
|
2021-05-07 07:43:57 +00:00
|
|
|
updateTool();
|
|
|
|
}
|
|
|
|
}
|
2021-05-01 19:55:43 +00:00
|
|
|
break;
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
2021-05-08 22:43:53 +00:00
|
|
|
// store current mouse flags in previous mouse flags
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars.mouse.prev_flags = global_vars.mouse.cur_flags;
|
2021-05-01 19:55:43 +00:00
|
|
|
break;
|
2021-04-30 19:02:14 +00:00
|
|
|
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();
|
2021-05-07 08:08:41 +00:00
|
|
|
SDLPP::Window w( "Mario editor!" );
|
2021-04-30 19:02:14 +00:00
|
|
|
w.setResizable( true );
|
2021-05-22 20:13:22 +00:00
|
|
|
BLOCK_SIZE = 1.0 / ( MAP_WIDTH + 2 );
|
2021-04-30 19:02:14 +00:00
|
|
|
|
2021-05-22 20:13:22 +00:00
|
|
|
auto renderer = std::make_shared< SDLPP::Renderer >( w );
|
|
|
|
renderer->setBlendMode( SDL_BLENDMODE_BLEND );
|
2021-04-30 19:02:14 +00:00
|
|
|
|
|
|
|
// prepare global vars
|
|
|
|
g_terrain_texture = std::make_shared< SDLPP::Texture >(
|
2021-05-22 20:13:22 +00:00
|
|
|
renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY );
|
2021-05-01 19:55:43 +00:00
|
|
|
g_mario_texture = std::make_shared< SDLPP::Texture >(
|
2021-05-22 20:13:22 +00:00
|
|
|
renderer, "sprites/mario.png", MARIO_OVERWORLD_COLORKEY );
|
2021-05-25 22:46:19 +00:00
|
|
|
g_translucent_terrain_texture =
|
|
|
|
std::make_shared< SDLPP::Texture >( renderer, "sprites/terrain.png",
|
|
|
|
MARIO_OVERWORLD_COLORKEY );
|
|
|
|
g_translucent_terrain_texture->setAlpha( 100 );
|
2021-04-30 19:02:14 +00:00
|
|
|
|
2021-05-22 20:13:22 +00:00
|
|
|
auto scene = std::make_shared< SDLPP::Scene >( renderer );
|
2021-04-30 19:02:14 +00:00
|
|
|
auto bg = std::make_shared< SDLPP::RectangleRender >(
|
2021-05-22 20:13:22 +00:00
|
|
|
0, 0, 10, 10, renderer, MARIO_OVERWORLD_COLORKEY, true );
|
2021-05-01 19:55:43 +00:00
|
|
|
bg->setPermanent();
|
2021-04-30 19:02:14 +00:00
|
|
|
bg->setId( 1 );
|
|
|
|
scene->addObject( bg );
|
|
|
|
|
2021-05-26 12:18:39 +00:00
|
|
|
loadMap( scene, global_vars.mario, "test_binary.bin", renderer, global_vars.objects );
|
2021-04-30 21:12:53 +00:00
|
|
|
|
|
|
|
// grid
|
2021-05-22 20:13:22 +00:00
|
|
|
for ( int i = 1; i < ( MAP_WIDTH + 2 ); i++ ) {
|
2021-04-30 21:12:53 +00:00
|
|
|
auto line_vertical = std::make_shared< SDLPP::LineRenderer >(
|
2021-05-09 18:45:52 +00:00
|
|
|
i * BLOCK_SIZE, 1 - MAP_HEIGHT * BLOCK_SIZE, i * BLOCK_SIZE, 1.0,
|
2021-05-22 20:13:22 +00:00
|
|
|
renderer, "#282828" );
|
2021-05-01 19:55:43 +00:00
|
|
|
line_vertical->setPermanent();
|
2021-04-30 21:12:53 +00:00
|
|
|
line_vertical->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
2021-05-08 22:46:10 +00:00
|
|
|
scene->addObject( line_vertical );
|
2021-05-22 20:13:22 +00:00
|
|
|
if ( i > ( MAP_WIDTH - MAP_HEIGHT ) ) {
|
2021-04-30 21:12:53 +00:00
|
|
|
auto line_horizontal = std::make_shared< SDLPP::LineRenderer >(
|
2021-05-22 20:13:22 +00:00
|
|
|
BLOCK_SIZE, ( i + 1 ) * BLOCK_SIZE,
|
|
|
|
( MAP_WIDTH + 1 ) * BLOCK_SIZE, ( i + 1 ) * BLOCK_SIZE,
|
|
|
|
renderer, "#282828" );
|
2021-05-01 19:55:43 +00:00
|
|
|
line_horizontal->setPermanent();
|
2021-05-08 22:46:10 +00:00
|
|
|
line_horizontal->setAlignment( SDLPP::OBJ_CENTER,
|
|
|
|
SDLPP::OBJ_CENTER );
|
|
|
|
scene->addObject( line_horizontal );
|
2021-04-30 21:12:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// white rectangles
|
|
|
|
auto rectangle1 = std::make_shared< SDLPP::RectangleRender >(
|
2021-05-22 20:13:22 +00:00
|
|
|
0, ( MAP_WIDTH + 2 - MAP_HEIGHT ) * BLOCK_SIZE, BLOCK_SIZE,
|
|
|
|
MAP_HEIGHT * BLOCK_SIZE, renderer, "#FFFFFF88", true );
|
2021-05-08 22:46:10 +00:00
|
|
|
rectangle1->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
|
|
|
rectangle1->setId( EDITOR_LEFT_MAP_ID );
|
2021-05-01 19:55:43 +00:00
|
|
|
rectangle1->setPermanent();
|
2021-05-08 22:46:10 +00:00
|
|
|
rectangle1->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) );
|
|
|
|
scene->addObject( rectangle1 );
|
2021-04-30 21:12:53 +00:00
|
|
|
// white rectangles
|
|
|
|
auto rectangle2 = std::make_shared< SDLPP::RectangleRender >(
|
2021-05-22 20:13:22 +00:00
|
|
|
( MAP_WIDTH + 1 ) * BLOCK_SIZE,
|
|
|
|
( MAP_WIDTH + 2 - MAP_HEIGHT ) * BLOCK_SIZE, BLOCK_SIZE,
|
|
|
|
MAP_HEIGHT * BLOCK_SIZE, renderer, "#FFFFFF88", true );
|
2021-05-08 22:46:10 +00:00
|
|
|
rectangle2->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
|
|
|
rectangle2->setId( EDITOR_RIGHT_MAP_ID );
|
2021-05-01 19:55:43 +00:00
|
|
|
rectangle2->setPermanent();
|
2021-05-08 22:46:10 +00:00
|
|
|
rectangle2->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) );
|
|
|
|
scene->addObject( rectangle2 );
|
2021-04-30 21:12:53 +00:00
|
|
|
|
2021-05-01 19:55:43 +00:00
|
|
|
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 >(
|
2021-05-22 20:13:22 +00:00
|
|
|
0, ( MAP_WIDTH - MAP_HEIGHT / 2.0 + 1.5 ) * BLOCK_SIZE, BLOCK_SIZE,
|
|
|
|
BLOCK_SIZE, renderer, "<", font_config );
|
2021-05-08 22:46:10 +00:00
|
|
|
left->setId( 0 );
|
|
|
|
left->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
2021-05-01 19:55:43 +00:00
|
|
|
left->setPermanent();
|
2021-05-08 22:46:10 +00:00
|
|
|
scene->addObject( left );
|
2021-05-01 19:55:43 +00:00
|
|
|
auto right = std::make_shared< SDLPP::TextRenderer >(
|
2021-05-22 20:13:22 +00:00
|
|
|
( MAP_WIDTH + 1 ) * BLOCK_SIZE,
|
|
|
|
( MAP_WIDTH - MAP_HEIGHT / 2.0 + 1.5 ) * BLOCK_SIZE, BLOCK_SIZE,
|
|
|
|
BLOCK_SIZE, renderer, ">", font_config );
|
2021-05-08 22:46:10 +00:00
|
|
|
right->setId( 0 );
|
|
|
|
right->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
2021-05-01 19:55:43 +00:00
|
|
|
right->setPermanent();
|
2021-05-08 22:46:10 +00:00
|
|
|
scene->addObject( right );
|
2021-05-01 19:55:43 +00:00
|
|
|
|
2021-05-09 18:45:52 +00:00
|
|
|
for ( int i = 0; i < MAP_WIDTH; i++ ) {
|
|
|
|
for ( int j = 0; j < MAP_HEIGHT; j++ ) {
|
2021-05-22 20:13:22 +00:00
|
|
|
scene->addObject( std::make_shared< EditBox >(
|
|
|
|
i, j, MAP_WIDTH, MAP_HEIGHT, renderer ) );
|
2021-05-01 19:55:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-08 22:46:10 +00:00
|
|
|
auto mouse = std::make_shared< SDLPP::RectangleRender >( 0.01, 0.01, 0, 0,
|
2021-05-22 20:13:22 +00:00
|
|
|
renderer );
|
2021-05-08 22:46:10 +00:00
|
|
|
mouse->setMinWidth( 1 );
|
|
|
|
mouse->setMinHeight( 1 );
|
2021-05-01 19:55:43 +00:00
|
|
|
mouse->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
2021-05-02 12:14:11 +00:00
|
|
|
mouse->setId( EDITOR_MOUSE_ID );
|
2021-05-08 22:46:10 +00:00
|
|
|
mouse->setColiderColor( "#00FF00" );
|
|
|
|
mouse->addCollision( SDLPP::RectColider( { 0, 0 }, { 1, 1 } ) );
|
2021-05-01 19:55:43 +00:00
|
|
|
scene->addObject( mouse );
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars.map.max_page = global_vars.objects.size() - MAP_WIDTH;
|
2021-04-30 19:02:14 +00:00
|
|
|
|
2021-05-07 07:43:57 +00:00
|
|
|
// tools
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars.tool.max_page = ( possibleBlocks.size() - 1 ) / 8;
|
2021-05-08 22:46:10 +00:00
|
|
|
for ( int i = 0; i < 4; i++ ) {
|
2021-05-22 20:13:22 +00:00
|
|
|
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 );
|
2021-05-08 22:46:10 +00:00
|
|
|
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;
|
2021-05-07 07:43:57 +00:00
|
|
|
}
|
|
|
|
int tool_index = 0;
|
2021-05-08 22:46:10 +00:00
|
|
|
for ( auto &block : possibleBlocks ) {
|
|
|
|
if ( block == MARIO_ID ) {
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars.tools.push_back(
|
|
|
|
createMario( LandType::OVERWORLD, renderer, 0, 0 ) );
|
2021-05-07 21:17:05 +00:00
|
|
|
} else {
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars.tools.push_back( createTerrainBlock(
|
|
|
|
block, LandType::OVERWORLD, renderer, false ) );
|
2021-05-07 21:17:05 +00:00
|
|
|
}
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars.tools.back()->setHidden( true );
|
|
|
|
global_vars.tools.back()->setPermanent();
|
2021-05-07 07:43:57 +00:00
|
|
|
auto x = tool_index % 4;
|
|
|
|
auto y = tool_index / 4;
|
|
|
|
// TODO add 14 and 1 as constants somewhere
|
2021-05-07 21:17:05 +00:00
|
|
|
// TODO investigate when not permanent requires `-1` on x position
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars.tools.back()->setPos( ( MAP_WIDTH - 4 ) * BLOCK_SIZE +
|
|
|
|
x * BLOCK_SIZE,
|
|
|
|
BLOCK_SIZE + y * BLOCK_SIZE );
|
2021-05-08 22:46:10 +00:00
|
|
|
// std::cout << "TOOL POS: " << tools.back()->getPos().getX() <<
|
|
|
|
// ", " << tools.back()->getPos().getY() << std::endl;
|
2021-05-22 20:13:22 +00:00
|
|
|
scene->addObject( global_vars.tools.back() );
|
2021-05-08 22:46:10 +00:00
|
|
|
tool_index = ( tool_index + 1 ) % 8;
|
2021-05-07 07:43:57 +00:00
|
|
|
}
|
2021-05-08 22:46:10 +00:00
|
|
|
for ( int i = 0; i < 5; i++ ) {
|
|
|
|
auto line = std::make_shared< SDLPP::LineRenderer >(
|
2021-05-22 20:13:22 +00:00
|
|
|
( MAP_WIDTH - 4 ) * BLOCK_SIZE + i * BLOCK_SIZE, BLOCK_SIZE,
|
|
|
|
( MAP_WIDTH - 4 ) * BLOCK_SIZE + i * BLOCK_SIZE, 3 * BLOCK_SIZE,
|
|
|
|
renderer, "#282828" );
|
2021-05-07 07:43:57 +00:00
|
|
|
line->setPermanent();
|
2021-05-08 22:46:10 +00:00
|
|
|
line->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
|
|
|
scene->addObject( line );
|
2021-05-07 07:43:57 +00:00
|
|
|
}
|
2021-05-08 22:46:10 +00:00
|
|
|
for ( int i = 0; i < 3; i++ ) {
|
|
|
|
auto line = std::make_shared< SDLPP::LineRenderer >(
|
2021-05-22 20:13:22 +00:00
|
|
|
( 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" );
|
2021-05-07 07:43:57 +00:00
|
|
|
line->setPermanent();
|
2021-05-08 22:46:10 +00:00
|
|
|
line->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
|
|
|
scene->addObject( line );
|
2021-05-07 07:43:57 +00:00
|
|
|
}
|
|
|
|
|
2021-05-07 08:08:41 +00:00
|
|
|
auto tool_rect1 = std::make_shared< SDLPP::RectangleRender >(
|
2021-05-22 20:13:22 +00:00
|
|
|
( MAP_WIDTH - 5 ) * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
|
|
|
renderer, "#FFFFFF88", true );
|
2021-05-08 22:46:10 +00:00
|
|
|
tool_rect1->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
|
|
|
tool_rect1->setId( EDITOR_LEFT_TOOL_ID );
|
2021-05-07 08:08:41 +00:00
|
|
|
tool_rect1->setPermanent();
|
2021-05-08 22:46:10 +00:00
|
|
|
tool_rect1->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) );
|
|
|
|
scene->addObject( tool_rect1 );
|
2021-05-07 08:08:41 +00:00
|
|
|
// white rectangles
|
|
|
|
auto tool_rect2 = std::make_shared< SDLPP::RectangleRender >(
|
2021-05-22 20:13:22 +00:00
|
|
|
MAP_WIDTH * BLOCK_SIZE, 1 * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
|
|
|
renderer, "#FFFFFF88", true );
|
2021-05-08 22:46:10 +00:00
|
|
|
tool_rect2->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
|
|
|
tool_rect2->setId( EDITOR_RIGHT_TOOL_ID );
|
2021-05-07 08:08:41 +00:00
|
|
|
tool_rect2->setPermanent();
|
2021-05-08 22:46:10 +00:00
|
|
|
tool_rect2->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) );
|
|
|
|
scene->addObject( tool_rect2 );
|
2021-05-07 08:08:41 +00:00
|
|
|
auto left_tool = std::make_shared< SDLPP::TextRenderer >(
|
2021-05-22 20:13:22 +00:00
|
|
|
( MAP_WIDTH - 5 ) * BLOCK_SIZE, 1.5 * BLOCK_SIZE, BLOCK_SIZE,
|
|
|
|
BLOCK_SIZE, renderer, "<", font_config );
|
2021-05-08 22:46:10 +00:00
|
|
|
left_tool->setId( 0 );
|
|
|
|
left_tool->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
2021-05-07 08:08:41 +00:00
|
|
|
left_tool->setPermanent();
|
2021-05-08 22:46:10 +00:00
|
|
|
scene->addObject( left_tool );
|
2021-05-07 08:08:41 +00:00
|
|
|
auto right_tool = std::make_shared< SDLPP::TextRenderer >(
|
2021-05-22 20:13:22 +00:00
|
|
|
MAP_WIDTH * BLOCK_SIZE, 1.5 * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE,
|
|
|
|
renderer, ">", font_config );
|
2021-05-08 22:46:10 +00:00
|
|
|
right_tool->setId( 0 );
|
|
|
|
right_tool->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
2021-05-07 08:08:41 +00:00
|
|
|
right_tool->setPermanent();
|
2021-05-08 22:46:10 +00:00
|
|
|
scene->addObject( right_tool );
|
2021-05-07 08:08:41 +00:00
|
|
|
|
2021-05-22 20:13:22 +00:00
|
|
|
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 );
|
2021-05-08 22:46:10 +00:00
|
|
|
|
|
|
|
scene->moveEverything( BLOCK_SIZE, 0 );
|
2021-04-30 19:02:14 +00:00
|
|
|
FPSmanager gFPS;
|
|
|
|
SDL_initFramerate( &gFPS );
|
|
|
|
SDL_setFramerate( &gFPS, 60 );
|
|
|
|
|
2021-05-08 22:46:10 +00:00
|
|
|
updateToolSelection( 0 );
|
2021-05-07 07:43:57 +00:00
|
|
|
|
2021-04-30 19:02:14 +00:00
|
|
|
auto base = SDL_GetTicks();
|
|
|
|
int frames = 0;
|
|
|
|
std::thread inputThread( doInput, scene );
|
|
|
|
inputThread.detach();
|
2021-05-22 20:13:22 +00:00
|
|
|
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 ) ) {
|
2021-04-30 19:02:14 +00:00
|
|
|
SDL_PumpEvents();
|
|
|
|
SDL_framerateDelay( &gFPS );
|
2021-05-22 20:13:22 +00:00
|
|
|
std::lock_guard< std::mutex > lock( destruction_mutex );
|
2021-04-30 19:02:14 +00:00
|
|
|
scene->renderScene();
|
2021-05-22 20:13:22 +00:00
|
|
|
renderer->presentRenderer();
|
2021-04-30 19:02:14 +00:00
|
|
|
frames++;
|
|
|
|
if ( SDL_GetTicks() - base >= 1000 ) {
|
|
|
|
std::cout << "FPS: " << frames << std::endl;
|
|
|
|
frames = 0;
|
|
|
|
base = SDL_GetTicks();
|
|
|
|
}
|
2021-05-22 20:13:22 +00:00
|
|
|
if ( global_vars.map.cur_page == 0 &&
|
|
|
|
getFlag( MAP_LEFT_ENABLED_FLAG ) ) {
|
|
|
|
setFlag( UPDATE_FLAG );
|
|
|
|
unsetFlag( MAP_LEFT_ENABLED_FLAG );
|
2021-05-08 22:46:10 +00:00
|
|
|
left->setTextColor( font, "#CCCCCC", "#CCCCCC", 0.05 );
|
2021-05-22 20:13:22 +00:00
|
|
|
} else if ( global_vars.map.cur_page != 0 &&
|
|
|
|
!getFlag( MAP_LEFT_ENABLED_FLAG ) ) {
|
|
|
|
setFlag( UPDATE_FLAG );
|
|
|
|
setFlag( MAP_LEFT_ENABLED_FLAG );
|
2021-05-08 22:46:10 +00:00
|
|
|
left->setTextColor( font, "#000000", "#282828", 0.05 );
|
2021-05-01 19:55:43 +00:00
|
|
|
}
|
2021-05-22 20:13:22 +00:00
|
|
|
if ( global_vars.map.cur_page == global_vars.map.max_page &&
|
|
|
|
getFlag( MAP_RIGHT_ENABLED_FLAG ) ) {
|
|
|
|
setFlag( UPDATE_FLAG );
|
|
|
|
unsetFlag( MAP_RIGHT_ENABLED_FLAG );
|
2021-05-08 22:46:10 +00:00
|
|
|
right->setTextColor( font, "#00FF00", "#000000", 0.1 );
|
|
|
|
right->changeText( "+" );
|
2021-05-22 20:13:22 +00:00
|
|
|
} 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 );
|
2021-05-08 22:46:10 +00:00
|
|
|
right->setTextColor( font, "#000000", "#282828", 0.05 );
|
|
|
|
right->changeText( ">" );
|
2021-05-01 19:55:43 +00:00
|
|
|
}
|
2021-05-22 20:13:22 +00:00
|
|
|
if ( global_vars.tool.cur_page == 0 &&
|
|
|
|
getFlag( TOOL_LEFT_ENABLED_FLAG ) ) {
|
|
|
|
setFlag( UPDATE_FLAG );
|
|
|
|
unsetFlag( TOOL_LEFT_ENABLED_FLAG );
|
2021-05-08 22:46:10 +00:00
|
|
|
left_tool->setTextColor( font, "#CCCCCC", "#CCCCCC", 0.05 );
|
2021-05-22 20:13:22 +00:00
|
|
|
} else if ( global_vars.tool.cur_page != 0 &&
|
|
|
|
!getFlag( TOOL_LEFT_ENABLED_FLAG ) ) {
|
|
|
|
setFlag( UPDATE_FLAG );
|
|
|
|
setFlag( TOOL_LEFT_ENABLED_FLAG );
|
2021-05-08 22:46:10 +00:00
|
|
|
left_tool->setTextColor( font, "#000000", "#282828", 0.05 );
|
2021-05-07 08:08:41 +00:00
|
|
|
}
|
2021-05-22 20:13:22 +00:00
|
|
|
if ( global_vars.tool.cur_page == global_vars.tool.max_page &&
|
|
|
|
getFlag( TOOL_RIGHT_ENABLED_FLAG ) ) {
|
|
|
|
setFlag( UPDATE_FLAG );
|
|
|
|
unsetFlag( TOOL_RIGHT_ENABLED_FLAG );
|
2021-05-08 22:46:10 +00:00
|
|
|
right_tool->setTextColor( font, "#CCCCCC", "#CCCCCC", 0.05 );
|
2021-05-22 20:13:22 +00:00
|
|
|
} 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 );
|
2021-05-08 22:46:10 +00:00
|
|
|
right_tool->setTextColor( font, "#000000", "#282828", 0.05 );
|
2021-05-07 08:08:41 +00:00
|
|
|
}
|
2021-05-22 20:13:22 +00:00
|
|
|
if ( getFlag( UPDATE_FLAG ) ) {
|
2021-05-01 19:55:43 +00:00
|
|
|
scene->updateSizeAndPosition();
|
2021-05-22 20:13:22 +00:00
|
|
|
unsetFlag( UPDATE_FLAG );
|
2021-05-01 19:55:43 +00:00
|
|
|
}
|
2021-04-30 19:02:14 +00:00
|
|
|
}
|
2021-05-22 20:13:22 +00:00
|
|
|
saveMap( "test_binary2.bin", global_vars.objects );
|
2021-04-30 19:02:14 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|