game/mario/editor.cpp
zvon 70f30b6767
All checks were successful
continuous-integration/drone/push Build is passing
Mario Editor: save to filename entered in editor
2022-07-22 22:18:01 +02:00

118 lines
3.7 KiB
C++

#include "../sdlpp/sdlpp.hpp"
#include "global_vars.hpp"
#include "gui/gui.hpp"
#include "sprites.hpp"
#include <memory>
#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 "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"
#include "blocks/coineditorblock.hpp"
#include "scenes/editor_scenes.hpp"
std::vector<SceneStruct> game_scenes{};
void doInput() {
FPSmanager gFPS;
SDL_initFramerate(&gFPS);
SDL_setFramerate(&gFPS, 200);
while (!g_quit) {
SDL_framerateDelay(&gFPS);
game_scenes.back().doInput(game_scenes.back().scene);
game_scenes.back().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 / 26;
auto font = std::make_shared<SDLPP::Font>("testfont.ttf", 36);
g_text_config = std::make_shared<SDLPP::FontConfiguration>(font, "#FFFFFF",
"#000000", 0.15);
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);
g_mod_texture =
std::make_shared<SDLPP::Texture>(renderer, "sprites/mods.png");
g_enemies_texture = std::make_shared<SDLPP::Texture>(
renderer, "sprites/enemies.png", MARIO_OVERWORLD_COLORKEY);
g_translucent_terrain_texture = std::make_shared<SDLPP::Texture>(
renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY);
g_translucent_terrain_texture->setAlpha(100);
g_translucent_mod_texture =
std::make_shared<SDLPP::Texture>(renderer, "sprites/mods.png");
g_translucent_mod_texture->setAlpha(100);
g_translucent_enemies_texture = std::make_shared<SDLPP::Texture>(
renderer, "sprites/enemies.png", MARIO_OVERWORLD_COLORKEY);
g_translucent_enemies_texture->setAlpha(100);
game_scenes.push_back(createEditorScene(renderer));
auto base = SDL_GetTicks();
int frames = 0;
std::thread inputThread(doInput);
SDL_PumpEvents();
game_scenes.back().scene->updateSizeAndPosition();
game_scenes.back().scene->renderScene();
renderer->presentRenderer();
FPSmanager gFPS;
SDL_initFramerate(&gFPS);
SDL_setFramerate(&gFPS, 60);
while (!g_quit) {
SDL_framerateDelay(&gFPS);
SDL_PumpEvents();
std::lock_guard<std::mutex> lock(render_mutex);
auto max_game_scenes = game_scenes.size();
for (size_t i = 0; i < max_game_scenes; i++) {
game_scenes[i].additionalRender(game_scenes[i].scene);
// additional renderer can remove scene from game_scenes, better
// check
if (i < game_scenes.size()) {
game_scenes[i].scene->renderScene(false);
}
}
renderer->presentRenderer();
frames++;
if (SDL_GetTicks() - base >= 1000) {
std::cout << "FPS: " << frames << std::endl;
frames = 0;
base = SDL_GetTicks();
}
}
inputThread.join();
return 0;
}