2021-04-30 19:02:14 +00:00
|
|
|
#include "../sdlpp/sdlpp.hpp"
|
2022-06-26 13:13:06 +00:00
|
|
|
#include "global_vars.hpp"
|
2022-06-21 12:52:36 +00:00
|
|
|
#include "gui/gui.hpp"
|
2021-04-30 19:02:14 +00:00
|
|
|
#include "sprites.hpp"
|
2022-06-23 08:31:58 +00:00
|
|
|
#include <memory>
|
2021-04-30 19:02:14 +00:00
|
|
|
#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 "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-07-24 17:59:25 +00:00
|
|
|
#include "blocks/coineditorblock.hpp"
|
2022-06-26 13:13:06 +00:00
|
|
|
#include "scenes/editor_scenes.hpp"
|
2021-04-30 19:02:14 +00:00
|
|
|
|
2022-06-26 13:13:06 +00:00
|
|
|
std::vector<SceneStruct> game_scenes{};
|
2021-05-31 12:03:11 +00:00
|
|
|
|
2022-06-26 13:13:06 +00:00
|
|
|
void doInput() {
|
2021-04-30 19:02:14 +00:00
|
|
|
FPSmanager gFPS;
|
2021-10-18 07:08:35 +00:00
|
|
|
SDL_initFramerate(&gFPS);
|
|
|
|
SDL_setFramerate(&gFPS, 200);
|
2022-06-26 13:13:06 +00:00
|
|
|
while (!g_quit) {
|
2021-10-18 07:08:35 +00:00
|
|
|
SDL_framerateDelay(&gFPS);
|
2022-06-26 13:13:06 +00:00
|
|
|
game_scenes.back().doInput(game_scenes.back().scene);
|
|
|
|
game_scenes.back().scene->updateScene();
|
2021-05-29 09:38:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-30 19:02:14 +00:00
|
|
|
#ifdef _WIN32
|
2021-10-18 07:08:35 +00:00
|
|
|
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
|
|
|
PWSTR szCmdLine, int nCmdShow) {
|
2021-04-30 19:02:14 +00:00
|
|
|
#else
|
|
|
|
int main() {
|
|
|
|
#endif
|
|
|
|
SDLPP::init();
|
2021-10-18 07:08:35 +00:00
|
|
|
SDLPP::Window w("Mario editor!");
|
|
|
|
w.setResizable(true);
|
2021-06-01 08:18:33 +00:00
|
|
|
BLOCK_SIZE = 1.0 / 26;
|
2021-04-30 19:02:14 +00:00
|
|
|
|
2021-10-18 07:08:35 +00:00
|
|
|
auto font = std::make_shared<SDLPP::Font>("testfont.ttf", 36);
|
|
|
|
g_text_config = std::make_shared<SDLPP::FontConfiguration>(font, "#FFFFFF",
|
|
|
|
"#000000", 0.15);
|
2021-07-22 22:08:05 +00:00
|
|
|
|
2021-10-18 07:08:35 +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
|
2021-10-18 07:08:35 +00:00
|
|
|
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);
|
2021-07-24 17:59:25 +00:00
|
|
|
g_mod_texture =
|
2021-10-18 07:08:35 +00:00
|
|
|
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);
|
2021-07-24 17:59:25 +00:00
|
|
|
g_translucent_mod_texture =
|
2021-10-18 07:08:35 +00:00
|
|
|
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);
|
|
|
|
|
2022-06-26 13:13:06 +00:00
|
|
|
game_scenes.push_back(createEditorScene(renderer));
|
2022-06-21 12:52:36 +00:00
|
|
|
|
2021-04-30 19:02:14 +00:00
|
|
|
auto base = SDL_GetTicks();
|
|
|
|
int frames = 0;
|
2022-06-26 13:13:06 +00:00
|
|
|
std::thread inputThread(doInput);
|
2021-05-29 11:21:01 +00:00
|
|
|
|
2021-08-08 19:22:00 +00:00
|
|
|
SDL_PumpEvents();
|
2022-06-26 13:13:06 +00:00
|
|
|
game_scenes.back().scene->updateSizeAndPosition();
|
|
|
|
game_scenes.back().scene->renderScene();
|
2021-08-08 19:22:00 +00:00
|
|
|
renderer->presentRenderer();
|
|
|
|
|
2022-06-26 13:13:06 +00:00
|
|
|
FPSmanager gFPS;
|
|
|
|
SDL_initFramerate(&gFPS);
|
|
|
|
SDL_setFramerate(&gFPS, 60);
|
|
|
|
|
|
|
|
while (!g_quit) {
|
2021-10-18 07:08:35 +00:00
|
|
|
SDL_framerateDelay(&gFPS);
|
2021-08-08 19:22:00 +00:00
|
|
|
SDL_PumpEvents();
|
2022-06-26 13:13:06 +00:00
|
|
|
std::lock_guard<std::mutex> lock(render_mutex);
|
|
|
|
for(auto &scene : game_scenes) {
|
|
|
|
scene.additionalRender(scene.scene);
|
|
|
|
scene.scene->renderScene(false);
|
|
|
|
}
|
2022-06-24 19:51:47 +00:00
|
|
|
renderer->presentRenderer();
|
2021-04-30 19:02:14 +00:00
|
|
|
frames++;
|
2021-10-18 07:08:35 +00:00
|
|
|
if (SDL_GetTicks() - base >= 1000) {
|
2021-04-30 19:02:14 +00:00
|
|
|
std::cout << "FPS: " << frames << std::endl;
|
|
|
|
frames = 0;
|
|
|
|
base = SDL_GetTicks();
|
|
|
|
}
|
|
|
|
}
|
2022-06-26 13:13:06 +00:00
|
|
|
inputThread.join();
|
2021-04-30 19:02:14 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|