#include "GameEngine.h" #include "MenuScene.h" //#include "UITestScene.h" #include "ActionCode.h" #include "McRFPy_API.h" //#include "PythonScene.h" #include "PyScene.h" #include "UITestScene.h" #include "Resources.h" GameEngine::GameEngine() { Resources::font.loadFromFile("./assets/JetbrainsMono.ttf"); Resources::game = this; window_title = "McRogueFace - 7DRL 2024 Engine Demo"; window.create(sf::VideoMode(1024, 768), window_title); visible = window.getDefaultView(); window.setFramerateLimit(30); scene = "uitest"; //std::cout << "Constructing MenuScene" << std::endl; scenes["menu"] = new MenuScene(this); scenes["uitest"] = new UITestScene(this); //std::cout << "Constructed MenuScene" <update(); sUserInput(); if (!paused) { } currentScene()->sRender(); currentFrame++; frameTime = clock.restart().asSeconds(); fps = 1 / frameTime; window.setTitle(window_title + " " + std::to_string(fps) + " FPS"); } } void GameEngine::sUserInput() { sf::Event event; while (window.pollEvent(event)) { std::string actionType; int actionCode = 0; if (event.type == sf::Event::Closed) { running = false; continue; } // TODO: add resize event to Scene to react; call it after constructor too, maybe else if (event.type == sf::Event::Resized) { sf::FloatRect area(0.f, 0.f, event.size.width, event.size.height); visible = sf::View(area); window.setView(visible); //std::cout << "Visible area set to (0, 0, " << event.size.width << ", " << event.size.height <<")"< " << (actionCode && ActionCode::WHEEL_NEG) << "; actionCode && WHEEL_DEL -> " << (actionCode && ActionCode::WHEEL_DEL) << ";" << std::endl; */ } // float d = event.MouseWheelScrollEvent.delta; // actionCode = ActionCode::keycode(0, d); } else continue; //std::cout << "Event produced action code " << actionCode << ": " << actionType << std::endl; if (currentScene()->hasAction(actionCode)) { std::string name = currentScene()->action(actionCode); currentScene()->doAction(name, actionType); } else if (currentScene()->key_callable != NULL && currentScene()->key_callable != Py_None) { PyObject* args = Py_BuildValue("(ss)", ActionCode::key_str(event.key.code).c_str(), actionType.c_str()); PyObject_Call(currentScene()->key_callable, args, NULL); } else { //std::cout << "[GameEngine] Action not registered for input: " << actionCode << ": " << actionType << std::endl; } } } std::shared_ptr>> GameEngine::scene_ui(std::string target) { /* // facts about maps // You just can't do this during scenes["new_menu"] being assigned. std::cout << "Current scene is: " << scene << ". Searching for: " << target << ".\n"; std::cout << "scenes.size(): " << scenes.size() << std::endl; std::cout << "scenes.count(target): " << scenes.count(target) << std::endl; std::cout << "scenes.find(target): " << std::distance(scenes.begin(), scenes.find(target)) << std::endl; std::cout << "iterators: " << std::distance(scenes.begin(), scenes.begin()) << " " << std::distance(scenes.begin(), scenes.end()) << std::endl; std::cout << "scenes.contains(target): " << scenes.contains(target) << std::endl; std::cout << "scenes[target]: " << (long)(scenes[target]) << std::endl; */ if (scenes.count(target) == 0) return NULL; return scenes[target]->ui_elements; }