From fc785702a636b2a44ccac833a14f3f393cf476ea Mon Sep 17 00:00:00 2001 From: Thomas Edvalson Date: Sun, 25 May 2014 23:19:21 -0400 Subject: [PATCH] Rename simulator -> emulator --- .gitignore | 3 +- CMakeLists.txt | 16 +- README.md | 4 +- cmake/emu/CMakeLists.txt | 38 + cmake/gresource.cmake | 58 -- cmake/sim/CMakeLists.txt | 37 - examples/gateway/CMakeLists.txt | 6 +- include/cpp3ds/Emulator.hpp | 15 + include/cpp3ds/Emulator/Emulator.hpp | 69 ++ .../{Simulator => Emulator}/SFMLWidget.hpp | 11 +- include/cpp3ds/Simulator.hpp | 15 - include/cpp3ds/Simulator/Simulator.hpp | 86 -- include/cpp3ds/System/utils.hpp | 4 +- .../System/{utils_sim.hpp => utils_emu.hpp} | 0 include/cpp3ds/Window/BottomScreen.hpp | 4 +- ...tomScreen_sim.hpp => BottomScreen_emu.hpp} | 4 +- include/cpp3ds/Window/Input_.hpp | 2 +- include/cpp3ds/Window/Keyboard.hpp | 4 +- .../{Keyboard_sim.hpp => Keyboard_emu.hpp} | 0 include/cpp3ds/Window/Screen.hpp | 4 +- .../Window/{Screen_sim.hpp => Screen_emu.hpp} | 2 +- include/cpp3ds/Window/TopScreen.hpp | 4 +- .../{TopScreen_sim.hpp => TopScreen_emu.hpp} | 4 +- res/emu/emulator.qrc | 12 + res/{sim => emu}/emulator.ui | 66 +- res/emu/icons/3d.svg | 28 + res/emu/icons/camera.svg | 18 + res/emu/icons/pause.svg | 14 + res/emu/icons/play.svg | 3 + res/emu/icons/stop.svg | 10 + res/emu/icons/volume.svg | 13 + res/emu/icons/wifi.svg | 21 + res/{sim => emu}/logo.svg | 0 res/sim/emulator.qrc | 7 - res/sim/icon-camera.svg | 835 ------------------ res/sim/icon-monitor.svg | 217 ----- src/cpp3ds/System/utils.cpp | 11 +- src/cpp3ds/syscalls.cpp | 9 +- .../Emulator/Emulator.cpp} | 152 ++-- .../Emulator}/SFMLWidget.cpp | 64 +- src/{sim3ds => emu3ds}/System/Sleep.cpp | 0 src/{sim3ds => emu3ds}/System/utils.cpp | 0 src/emu3ds/Window/Display.cpp | 17 + .../Window/EventManager.cpp | 26 +- src/{sim3ds => emu3ds}/Window/Input.cpp | 4 +- src/{sim3ds => emu3ds}/Window/Keyboard.cpp | 4 +- src/{sim3ds => emu3ds}/Window/Scene.cpp | 4 +- src/{sim3ds => emu3ds}/Window/Screen.cpp | 8 +- src/{sim3ds => emu3ds}/Window/TopScreen.cpp | 0 src/emu3ds/emu3ds.cpp | 22 + src/sim3ds/Window/Display.cpp | 17 - src/sim3ds/sim3ds.cpp | 19 - 52 files changed, 516 insertions(+), 1475 deletions(-) create mode 100644 cmake/emu/CMakeLists.txt delete mode 100644 cmake/gresource.cmake delete mode 100644 cmake/sim/CMakeLists.txt create mode 100644 include/cpp3ds/Emulator.hpp create mode 100644 include/cpp3ds/Emulator/Emulator.hpp rename include/cpp3ds/{Simulator => Emulator}/SFMLWidget.hpp (68%) delete mode 100644 include/cpp3ds/Simulator.hpp delete mode 100644 include/cpp3ds/Simulator/Simulator.hpp rename include/cpp3ds/System/{utils_sim.hpp => utils_emu.hpp} (100%) rename include/cpp3ds/Window/{BottomScreen_sim.hpp => BottomScreen_emu.hpp} (78%) rename include/cpp3ds/Window/{Keyboard_sim.hpp => Keyboard_emu.hpp} (100%) rename include/cpp3ds/Window/{Screen_sim.hpp => Screen_emu.hpp} (95%) rename include/cpp3ds/Window/{TopScreen_sim.hpp => TopScreen_emu.hpp} (87%) create mode 100644 res/emu/emulator.qrc rename res/{sim => emu}/emulator.ui (59%) create mode 100644 res/emu/icons/3d.svg create mode 100644 res/emu/icons/camera.svg create mode 100644 res/emu/icons/pause.svg create mode 100644 res/emu/icons/play.svg create mode 100644 res/emu/icons/stop.svg create mode 100644 res/emu/icons/volume.svg create mode 100644 res/emu/icons/wifi.svg rename res/{sim => emu}/logo.svg (100%) delete mode 100644 res/sim/emulator.qrc delete mode 100644 res/sim/icon-camera.svg delete mode 100644 res/sim/icon-monitor.svg rename src/{sim3ds/Simulator/Simulator.cpp => emu3ds/Emulator/Emulator.cpp} (54%) rename src/{sim3ds/Simulator => emu3ds/Emulator}/SFMLWidget.cpp (75%) rename src/{sim3ds => emu3ds}/System/Sleep.cpp (100%) rename src/{sim3ds => emu3ds}/System/utils.cpp (100%) create mode 100644 src/emu3ds/Window/Display.cpp rename src/{sim3ds => emu3ds}/Window/EventManager.cpp (83%) rename src/{sim3ds => emu3ds}/Window/Input.cpp (82%) rename src/{sim3ds => emu3ds}/Window/Keyboard.cpp (84%) rename src/{sim3ds => emu3ds}/Window/Scene.cpp (86%) rename src/{sim3ds => emu3ds}/Window/Screen.cpp (86%) rename src/{sim3ds => emu3ds}/Window/TopScreen.cpp (100%) create mode 100644 src/emu3ds/emu3ds.cpp delete mode 100644 src/sim3ds/Window/Display.cpp delete mode 100644 src/sim3ds/sim3ds.cpp diff --git a/.gitignore b/.gitignore index d038ec8..a9412fe 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,7 @@ build/ lib/ *.bin -include/cpp3ds/Simulator/simulator-res.h -src/sim3ds/Simulator/simulator-res.cpp +include/cpp3ds/Emulator/ui-emulator.h # Eclipse *.pydevproject diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e1d536..bf1934c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,12 +39,12 @@ endif() # Fetch all source files FILE(GLOB_RECURSE SRC ${SRCROOT}/cpp3ds/*.cpp) -FILE(GLOB_RECURSE SRC_SIM ${SRCROOT}/sim3ds/*.cpp) +FILE(GLOB_RECURSE SRC_EMU ${SRCROOT}/emu3ds/*.cpp) set(SRC_ARM ${SRC}) set(SRC_TEST ${SRC}) -# Remove duplicate files for simulator -foreach(test1 ${SRC_SIM}) +# Remove duplicate files for emulator +foreach(test1 ${SRC_EMU}) get_filename_component(filename1 ${test1} NAME) foreach(test2 ${SRC}) get_filename_component(filename2 ${test2} NAME) @@ -53,9 +53,9 @@ foreach(test1 ${SRC_SIM}) endif() endforeach(test2) endforeach(test1) -list(APPEND SRC_SIM ${SRC}) -list(REMOVE_ITEM SRC_SIM ${SRCROOT}/cpp3ds/syscalls.cpp) -list(REMOVE_ITEM SRC_SIM ${SRCROOT}/cpp3ds/cpp3ds.cpp) +list(APPEND SRC_EMU ${SRC}) +list(REMOVE_ITEM SRC_EMU ${SRCROOT}/cpp3ds/syscalls.cpp) +list(REMOVE_ITEM SRC_EMU ${SRCROOT}/cpp3ds/cpp3ds.cpp) list(REMOVE_ITEM SRC_TEST ${SRCROOT}/cpp3ds/cpp3ds.cpp) #source_group("" FILES ${SRC}) @@ -85,7 +85,7 @@ set(LIBRARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/lib") set(CPP3DS_ARM_FLAGS "-Wall -pedantic -O3 -march=armv6 -fdata-sections -fno-rtti -fno-exceptions") set(CPP3DS_TEST_FLAGS "-g -Wall -pedantic -O0 -fno-rtti -fno-exceptions") -set(CPP3DS_SIM_FLAGS "-g -Wall -pedantic -O0") +set(CPP3DS_EMU_FLAGS "-g -Wall -pedantic -O0") if(CPP3DS_BUILD_EXAMPLES) @@ -93,5 +93,5 @@ if(CPP3DS_BUILD_EXAMPLES) endif() add_subdirectory(cmake/arm) -add_subdirectory(cmake/sim) +add_subdirectory(cmake/emu) add_subdirectory(cmake/test) diff --git a/README.md b/README.md index da54982..7384b19 100644 --- a/README.md +++ b/README.md @@ -16,10 +16,10 @@ Requirements - GCC 4.8 (arm-none-eabi) - [Universal Tween Engine port](https://github.com/cpp3ds/universal-tween-engine-cpp) -For simulator: +For emulator: - [SFML 2.1](http://www.sfml-dev.org/index.php) -- [gtkmm 3](http://www.gtkmm.org/) +- [Qt 5](https://qt-project.org/) For unit tests: diff --git a/cmake/emu/CMakeLists.txt b/cmake/emu/CMakeLists.txt new file mode 100644 index 0000000..7ee54e6 --- /dev/null +++ b/cmake/emu/CMakeLists.txt @@ -0,0 +1,38 @@ +# Find includes in corresponding build directories +set(CMAKE_INCLUDE_CURRENT_DIR ON) +# Instruct CMake to run moc automatically when needed. +set(CMAKE_AUTOMOC ON) + +set(ui_header ${CMAKE_CURRENT_SOURCE_DIR}/../../include/cpp3ds/Emulator/ui_emulator.h) + +add_custom_command( + OUTPUT ${ui_header} + COMMAND uic ${CMAKE_CURRENT_SOURCE_DIR}/../../res/emu/emulator.ui -o ${ui_header} + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../../res/emu/emulator.ui + COMMENT "Generating ui_emulator.h" +) + +qt5_wrap_cpp(tst_hdr_moc ${CMAKE_CURRENT_SOURCE_DIR}/../../include/cpp3ds/Emulator/Emulator.hpp) +#qt5_wrap_ui(tst_form_hdr ${CMAKE_CURRENT_SOURCE_DIR}/../../res/emu/emulator.ui) +qt5_add_resources(RESOURCE_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/../../res/emu/emulator.qrc) + +#include_directories( ${GTKMM_INCLUDE_DIRS} ) +#link_directories( ${GTKMM_LIBRARY_DIRS} ) + + +add_library(cpp3ds-emu STATIC + ${SRC_EMU} + ${tst_hdr_moc} + ${tst_form_hdr} + ${RESOURCE_HEADER} +) +set_target_properties(cpp3ds-emu PROPERTIES COMPILE_DEFINITIONS "EMULATION") +set_target_properties(cpp3ds-emu PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${CPP3DS_EMU_FLAGS}") +#set_target_properties(cpp3ds-emu PROPERTIES LINK_FLAGS "${CMAKE_CXX_FLAGS} ${CPP3DS_EMU_FLAGS}") + +add_custom_target(ui ALL DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/../../include/cpp3ds/Emulator/ui_emulator.h +) +add_dependencies(cpp3ds-emu ui) +qt5_use_modules(cpp3ds-emu Core Gui Widgets) +#target_link_libraries(cpp3ds-emu ${GTKMM_LIBRARIES}) diff --git a/cmake/gresource.cmake b/cmake/gresource.cmake deleted file mode 100644 index 4facf5f..0000000 --- a/cmake/gresource.cmake +++ /dev/null @@ -1,58 +0,0 @@ -# Used for GResource. -# -# resource_dir: Directory where the .gresource.xml is located. -# resource_file: Filename of the .gresource.xml file (just the filename, not the complete path). -# source_output_dir: Directory where the C output file is written. -# header_output_dir: Directory where the H output file is written. -# output_source: This variable will be set with the complete path of the output C file. -# output_header: This variable will be set with the complete path of the output H file. - -function (gresource resource_dir resource_file source_output_dir header_output_dir output_source output_header) - -_pkgconfig_invoke("glib-2.0" GLIB2 PREFIX - "" "--variable=prefix") -find_program(GLIB_COMPILE_RESOURCES - NAMES glib-compile-resources - HINTS ${GLIB2_PREFIX}) - -if (NOT GLIB_COMPILE_RESOURCES) -message(FATAL "Could not find glib-compile-resources") -endif() - -# Get the output file path -get_filename_component (resource_name ${resource_file} NAME_WE) -set (output_c "${source_output_dir}/${resource_name}-res.cpp") -set (output_h "${header_output_dir}/${resource_name}-res.h") -set (${output_source} ${output_c} PARENT_SCOPE) -set (${output_header} ${output_h} PARENT_SCOPE) - -# Get the dependencies of the gresource -execute_process ( -OUTPUT_VARIABLE _files -WORKING_DIRECTORY ${resource_dir} -COMMAND ${GLIB_COMPILE_RESOURCES} --generate-dependencies ${resource_file} -) - -string (REPLACE "\n" ";" files ${_files}) - -set (depends "") -foreach (cur_file ${files}) -list (APPEND depends "${resource_dir}/${cur_file}") -endforeach () - -# Command to compile the resources -add_custom_command ( -OUTPUT ${output_c} -DEPENDS "${resource_dir}/${resource_file}" ${depends} -WORKING_DIRECTORY ${resource_dir} -COMMAND ${GLIB_COMPILE_RESOURCES} --generate-source --target=${output_c} ${resource_file} -) - -# Command to compile the resources -add_custom_command ( -OUTPUT ${output_h} -DEPENDS "${resource_dir}/${resource_file}" ${depends} -WORKING_DIRECTORY ${resource_dir} -COMMAND ${GLIB_COMPILE_RESOURCES} --generate-header --target=${output_h} ${resource_file} -) -endfunction () \ No newline at end of file diff --git a/cmake/sim/CMakeLists.txt b/cmake/sim/CMakeLists.txt deleted file mode 100644 index 4073811..0000000 --- a/cmake/sim/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -# Find includes in corresponding build directories -set(CMAKE_INCLUDE_CURRENT_DIR ON) -# Instruct CMake to run moc automatically when needed. -set(CMAKE_AUTOMOC ON) - -set(ui_header ${CMAKE_CURRENT_SOURCE_DIR}/../../include/cpp3ds/Simulator/ui_emulator.h) - -add_custom_command( - OUTPUT ${ui_header} - COMMAND uic ${CMAKE_CURRENT_SOURCE_DIR}/../../res/sim/emulator.ui -o ${ui_header} - COMMENT "Generating ui_emulator.h" -) - -qt5_wrap_cpp(tst_hdr_moc ${CMAKE_CURRENT_SOURCE_DIR}/../../include/cpp3ds/Simulator/Simulator.hpp) -#qt5_wrap_ui(tst_form_hdr ${CMAKE_CURRENT_SOURCE_DIR}/../../res/sim/emulator.ui) -qt5_add_resources(RESOURCE_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/../../res/sim/emulator.qrc) - -#include_directories( ${GTKMM_INCLUDE_DIRS} ) -#link_directories( ${GTKMM_LIBRARY_DIRS} ) - - -add_library(cpp3ds-sim STATIC - ${SRC_SIM} - ${tst_hdr_moc} - ${tst_form_hdr} - ${RESOURCE_HEADER} -) -set_target_properties(cpp3ds-sim PROPERTIES COMPILE_DEFINITIONS "SIMULATION") -set_target_properties(cpp3ds-sim PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${CPP3DS_SIM_FLAGS}") -#set_target_properties(cpp3ds-sim PROPERTIES LINK_FLAGS "${CMAKE_CXX_FLAGS} ${CPP3DS_SIM_FLAGS}") - -add_custom_target(ui ALL DEPENDS - ${CMAKE_CURRENT_SOURCE_DIR}/../../include/cpp3ds/Simulator/ui_emulator.h -) -add_dependencies(cpp3ds-sim ui) -qt5_use_modules(cpp3ds-sim Core Gui Widgets) -#target_link_libraries(cpp3ds-sim ${GTKMM_LIBRARIES}) diff --git a/examples/gateway/CMakeLists.txt b/examples/gateway/CMakeLists.txt index 4abafca..0f1def2 100644 --- a/examples/gateway/CMakeLists.txt +++ b/examples/gateway/CMakeLists.txt @@ -37,8 +37,8 @@ set(SOURCE_FILES add_executable(${PROJECT} ${SOURCE_FILES}) qt5_use_modules(${PROJECT} Core Gui Widgets) -target_link_libraries(${PROJECT} cpp3ds-sim tween-test sfml-graphics sfml-window sfml-system) +target_link_libraries(${PROJECT} cpp3ds-emu tween-test sfml-graphics sfml-window sfml-system) set_target_properties(${PROJECT} PROPERTIES COMPILE_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -O3") -set_target_properties(${PROJECT} PROPERTIES COMPILE_DEFINITIONS "SIMULATION") -#set_target_properties(${PROJECT} PROPERTIES LINK_FLAGS "${CMAKE_CXX_FLAGS} ${CPP3DS_SIM_FLAGS}") \ No newline at end of file +set_target_properties(${PROJECT} PROPERTIES COMPILE_DEFINITIONS "EMULATION") +#set_target_properties(${PROJECT} PROPERTIES LINK_FLAGS "${CMAKE_CXX_FLAGS} ${CPP3DS_EMU_FLAGS}") \ No newline at end of file diff --git a/include/cpp3ds/Emulator.hpp b/include/cpp3ds/Emulator.hpp new file mode 100644 index 0000000..1b8cebe --- /dev/null +++ b/include/cpp3ds/Emulator.hpp @@ -0,0 +1,15 @@ +#ifndef CPP3DS_EMULATOR_HPP +#define CPP3DS_EMULATOR_HPP + +#include + +#include + +#endif + +//////////////////////////////////////////////////////////// +/// \defgroup system Emulator module +/// +/// Module for emulator case base. +/// +//////////////////////////////////////////////////////////// diff --git a/include/cpp3ds/Emulator/Emulator.hpp b/include/cpp3ds/Emulator/Emulator.hpp new file mode 100644 index 0000000..997c91f --- /dev/null +++ b/include/cpp3ds/Emulator/Emulator.hpp @@ -0,0 +1,69 @@ +#ifndef CPP3DS_EMULATOR_EMU_HPP +#define CPP3DS_EMULATOR_EMU_HPP + +#include +#include +#include +#include + +#define EMU_OUTLINE_THICKNESS 1 + +extern void cpp3ds_main(); + +namespace cpp3ds { + +enum EmulatorState { + EMU_PLAYING, + EMU_PAUSED, + EMU_STOPPED +}; + +class Emulator : public QMainWindow, private Ui::MainWindow{ + Q_OBJECT +private: + QSlider* slider3D; + QWidget* spacer; + + sf::Thread* thread; + sf::Mutex mutex; + + sf::Texture pausedFrameTexture; + sf::Sprite pausedFrame; + + EmulatorState state = EMU_STOPPED; + + bool initialized = false; + + void runGame(); + void checkThreadState(); + void saveScreenshot(); + + void drawPausedFrame(); + +private slots: + void on_pushButton_clicked(); + void on_toolBar_orientationChanged(Qt::Orientation orientation); + +public: + QSFMLCanvas *screen; + + bool isThreadRunning = false; + + Emulator(QWidget *parent = 0); + ~Emulator(); + void run(); + void play(); + void pause(); + void stop(); + float get_slider3d(); + void updatePausedFrame(); + + EmulatorState getState(){ return state; } +}; + +// Emulator global to be accessed in-game +extern Emulator* _emulator; + +} + +#endif diff --git a/include/cpp3ds/Simulator/SFMLWidget.hpp b/include/cpp3ds/Emulator/SFMLWidget.hpp similarity index 68% rename from include/cpp3ds/Simulator/SFMLWidget.hpp rename to include/cpp3ds/Emulator/SFMLWidget.hpp index 0ceb3cb..70d2e8a 100644 --- a/include/cpp3ds/Simulator/SFMLWidget.hpp +++ b/include/cpp3ds/Emulator/SFMLWidget.hpp @@ -1,6 +1,7 @@ #ifndef CPP3DS_SFMLWIDGET_HPP #define CPP3DS_SFMLWIDGET_HPP +#include #include #include #include @@ -12,9 +13,10 @@ public : sf::RenderTexture topLeftScreen, topRightScreen, bottomScreen; QSFMLCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size, unsigned int FrameTime = 0); - virtual ~QSFMLCanvas(); + bool pollMouseEvent(sf::Event& event); + private : // virtual void OnInit(); @@ -24,11 +26,16 @@ private : virtual QPaintEngine* paintEngine() const; virtual void showEvent(QShowEvent*); - virtual void paintEvent(QPaintEvent*); + virtual void mousePressEvent(QMouseEvent* event); + virtual void mouseReleaseEvent(QMouseEvent* event); + virtual void mouseMoveEvent(QMouseEvent* event); + + void pushMouseEvent(const sf::Event& event); QTimer myTimer; bool myInitialized; + std::queue m_events; }; #endif diff --git a/include/cpp3ds/Simulator.hpp b/include/cpp3ds/Simulator.hpp deleted file mode 100644 index d23ad67..0000000 --- a/include/cpp3ds/Simulator.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef CPP3DS_SIMULATOR_HPP -#define CPP3DS_SIMULATOR_HPP - -#include - -#include - -#endif - -//////////////////////////////////////////////////////////// -/// \defgroup system Simulator module -/// -/// Module for simulator case base. -/// -//////////////////////////////////////////////////////////// diff --git a/include/cpp3ds/Simulator/Simulator.hpp b/include/cpp3ds/Simulator/Simulator.hpp deleted file mode 100644 index 66eaed5..0000000 --- a/include/cpp3ds/Simulator/Simulator.hpp +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef CPP3DS_SIMULATOR_SIM_HPP -#define CPP3DS_SIMULATOR_SIM_HPP - -//#include -#include -#include -#include -#include - -#define SIM_OUTLINE_THICKNESS 1 - -extern void cpp3ds_main(); - -namespace cpp3ds { - -enum SimulatorState { - SIM_PLAYING, - SIM_PAUSED, - SIM_STOPPED -}; - -class Simulator : public QMainWindow, private Ui::MainWindow{ - Q_OBJECT -private: -// Glib::RefPtr application; -// Gtk::Window *window; -// Gtk::Image *imageLogo; -// Gtk::MenuItem *menuAbout; -// Gtk::AboutDialog *aboutDialog; -// Gtk::FileChooserDialog *saveDialog; -// Gtk::Box *boxSFML; -// Gtk::ToolButton *buttonScreenshot, *buttonPlayPause, *buttonStop, *buttonTest; -// Gtk::ToggleToolButton *buttonToggle3D; -// Gtk::Scale *scale3D; - - sf::Thread* thread; - sf::Mutex mutex; - - sf::Texture pausedFrameTexture; - sf::Sprite pausedFrame; - - SimulatorState state = SIM_STOPPED; - - bool initialized = false; - - void runGame(); - void checkThreadState(); - void saveScreenshot(); - - void drawPausedFrame(); - -// void on_sfml_size_allocate(Gtk::Allocation& allocation); -// bool on_my_delete_event(GdkEventAny* event); -// void on_about_response(int response_id); -// void on_playpause_clicked(); -// void on_stop_clicked(); -// void on_toggle3d_clicked(); -// void on_about_clicked(); -// void on_test_clicked(); - -private slots: - void on_pushButton_clicked(); - -public: - QSFMLCanvas *screen; - - bool isThreadRunning = false; - - Simulator(QWidget *parent = 0); - ~Simulator(); - void run(); - void play(); - void pause(); - void stop(); - float get_slider3d(); - void updatePausedFrame(); - - SimulatorState getState(){ return state; } -}; - -// Simulator global to be accessed in-game -extern Simulator* _simulator; - -} - -#endif diff --git a/include/cpp3ds/System/utils.hpp b/include/cpp3ds/System/utils.hpp index 2089255..158dc2d 100644 --- a/include/cpp3ds/System/utils.hpp +++ b/include/cpp3ds/System/utils.hpp @@ -1,5 +1,5 @@ -#ifdef SIMULATION -#include +#ifdef EMULATION +#include #endif #ifndef CPP3DS_UTILS_HPP diff --git a/include/cpp3ds/System/utils_sim.hpp b/include/cpp3ds/System/utils_emu.hpp similarity index 100% rename from include/cpp3ds/System/utils_sim.hpp rename to include/cpp3ds/System/utils_emu.hpp diff --git a/include/cpp3ds/Window/BottomScreen.hpp b/include/cpp3ds/Window/BottomScreen.hpp index 6106323..5639238 100644 --- a/include/cpp3ds/Window/BottomScreen.hpp +++ b/include/cpp3ds/Window/BottomScreen.hpp @@ -1,5 +1,5 @@ -#ifdef SIMULATION -#include +#ifdef EMULATION +#include #endif #ifndef CPP3DS_BOTTOMSCREEN_HPP diff --git a/include/cpp3ds/Window/BottomScreen_sim.hpp b/include/cpp3ds/Window/BottomScreen_emu.hpp similarity index 78% rename from include/cpp3ds/Window/BottomScreen_sim.hpp rename to include/cpp3ds/Window/BottomScreen_emu.hpp index 1262996..08476aa 100644 --- a/include/cpp3ds/Window/BottomScreen_sim.hpp +++ b/include/cpp3ds/Window/BottomScreen_emu.hpp @@ -1,11 +1,11 @@ #ifndef CPP3DS_BOTTOMSCREEN_HPP #define CPP3DS_BOTTOMSCREEN_HPP -#include +#include #include #define BOTTOM_X ((400-320)/2) -#define BOTTOM_Y (240 + SIM_OUTLINE_THICKNESS*2) +#define BOTTOM_Y (240 + EMU_OUTLINE_THICKNESS*2) #define BOTTOM_WIDTH 320 #define BOTTOM_HEIGHT 240 diff --git a/include/cpp3ds/Window/Input_.hpp b/include/cpp3ds/Window/Input_.hpp index 713c582..90731f5 100644 --- a/include/cpp3ds/Window/Input_.hpp +++ b/include/cpp3ds/Window/Input_.hpp @@ -1,4 +1,4 @@ -#ifdef SIMULATION +#ifdef EMULATION #include #endif diff --git a/include/cpp3ds/Window/Keyboard.hpp b/include/cpp3ds/Window/Keyboard.hpp index 9278e95..f4b79f1 100644 --- a/include/cpp3ds/Window/Keyboard.hpp +++ b/include/cpp3ds/Window/Keyboard.hpp @@ -1,5 +1,5 @@ -#ifdef SIMULATION -#include +#ifdef EMULATION +#include #endif #ifndef CPP3DS_KEYBOARD_HPP diff --git a/include/cpp3ds/Window/Keyboard_sim.hpp b/include/cpp3ds/Window/Keyboard_emu.hpp similarity index 100% rename from include/cpp3ds/Window/Keyboard_sim.hpp rename to include/cpp3ds/Window/Keyboard_emu.hpp diff --git a/include/cpp3ds/Window/Screen.hpp b/include/cpp3ds/Window/Screen.hpp index 719a9b1..cfcef7e 100644 --- a/include/cpp3ds/Window/Screen.hpp +++ b/include/cpp3ds/Window/Screen.hpp @@ -1,5 +1,5 @@ -#ifdef SIMULATION -#include +#ifdef EMULATION +#include #endif #ifndef CPP3DS_SCREEN_HPP diff --git a/include/cpp3ds/Window/Screen_sim.hpp b/include/cpp3ds/Window/Screen_emu.hpp similarity index 95% rename from include/cpp3ds/Window/Screen_sim.hpp rename to include/cpp3ds/Window/Screen_emu.hpp index ea55107..a269453 100644 --- a/include/cpp3ds/Window/Screen_sim.hpp +++ b/include/cpp3ds/Window/Screen_emu.hpp @@ -2,7 +2,7 @@ #define CPP3DS_SCREEN_HPP #include -#include +#include #include namespace cpp3ds { diff --git a/include/cpp3ds/Window/TopScreen.hpp b/include/cpp3ds/Window/TopScreen.hpp index 4d40879..0cdaa78 100644 --- a/include/cpp3ds/Window/TopScreen.hpp +++ b/include/cpp3ds/Window/TopScreen.hpp @@ -1,5 +1,5 @@ -#ifdef SIMULATION -#include +#ifdef EMULATION +#include #endif #ifndef CPP3DS_TOPSCREEN_HPP diff --git a/include/cpp3ds/Window/TopScreen_sim.hpp b/include/cpp3ds/Window/TopScreen_emu.hpp similarity index 87% rename from include/cpp3ds/Window/TopScreen_sim.hpp rename to include/cpp3ds/Window/TopScreen_emu.hpp index 7861626..e48bd65 100644 --- a/include/cpp3ds/Window/TopScreen_sim.hpp +++ b/include/cpp3ds/Window/TopScreen_emu.hpp @@ -1,14 +1,14 @@ #ifndef CPP3DS_TOPSCREEN_HPP #define CPP3DS_TOPSCREEN_HPP -#include +#include #include #define TOP_HEIGHT 240 #define TOP_WIDTH 400 #define TOP_LEFT_X 0 #define TOP_LEFT_Y 0 -#define TOP_RIGHT_X 400 + SIM_OUTLINE_THICKNESS*2 +#define TOP_RIGHT_X 400 + EMU_OUTLINE_THICKNESS*2 #define TOP_RIGHT_Y 0 namespace cpp3ds { diff --git a/res/emu/emulator.qrc b/res/emu/emulator.qrc new file mode 100644 index 0000000..8f484f9 --- /dev/null +++ b/res/emu/emulator.qrc @@ -0,0 +1,12 @@ + + + logo.svg + icons/3d.svg + icons/camera.svg + icons/pause.svg + icons/play.svg + icons/stop.svg + icons/volume.svg + icons/wifi.svg + + diff --git a/res/sim/emulator.ui b/res/emu/emulator.ui similarity index 59% rename from res/sim/emulator.ui rename to res/emu/emulator.ui index 0591668..e926400 100644 --- a/res/sim/emulator.ui +++ b/res/emu/emulator.ui @@ -10,22 +10,49 @@ 385 + + + 0 + 0 + + MainWindow - :/sim/logo.svg:/sim/logo.svg + :/emu/logo.svg:/emu/logo.svg + + + + + + 0 + 0 + + + + 0 + + + 0 + + + 0 + + + 0 + - + 6 - QLayout::SetMaximumSize + QLayout::SetMinimumSize @@ -34,13 +61,6 @@ - - - - Qt::Horizontal - - - @@ -60,6 +80,12 @@ toolBar + + + 32 + 32 + + TopToolBarArea @@ -68,11 +94,12 @@ + - :/sim/icon-camera.svg:/sim/icon-camera.svg + :/emu/icons/camera.svg:/emu/icons/camera.svg Screenshot @@ -87,7 +114,7 @@ - :/sim/icon-monitor.svg:/sim/icon-monitor.svg + :/emu/icons/3d.svg:/emu/icons/3d.svg Toggle 3D @@ -96,6 +123,21 @@ Toggle 3D stereoscopy + + + true + + + + :/emu/icons/volume.svg:/emu/icons/volume.svg + + + Volume + + + Adjust audio volume + + diff --git a/res/emu/icons/3d.svg b/res/emu/icons/3d.svg new file mode 100644 index 0000000..8a094cc --- /dev/null +++ b/res/emu/icons/3d.svg @@ -0,0 +1,28 @@ + + + + + + diff --git a/res/emu/icons/camera.svg b/res/emu/icons/camera.svg new file mode 100644 index 0000000..d75297b --- /dev/null +++ b/res/emu/icons/camera.svg @@ -0,0 +1,18 @@ + + + + + + diff --git a/res/emu/icons/pause.svg b/res/emu/icons/pause.svg new file mode 100644 index 0000000..0442e2c --- /dev/null +++ b/res/emu/icons/pause.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + diff --git a/res/emu/icons/play.svg b/res/emu/icons/play.svg new file mode 100644 index 0000000..596b906 --- /dev/null +++ b/res/emu/icons/play.svg @@ -0,0 +1,3 @@ + + + diff --git a/res/emu/icons/stop.svg b/res/emu/icons/stop.svg new file mode 100644 index 0000000..6f3c47d --- /dev/null +++ b/res/emu/icons/stop.svg @@ -0,0 +1,10 @@ + + + + + + + + diff --git a/res/emu/icons/volume.svg b/res/emu/icons/volume.svg new file mode 100644 index 0000000..ecdbc21 --- /dev/null +++ b/res/emu/icons/volume.svg @@ -0,0 +1,13 @@ + + + + + + diff --git a/res/emu/icons/wifi.svg b/res/emu/icons/wifi.svg new file mode 100644 index 0000000..2ed7a50 --- /dev/null +++ b/res/emu/icons/wifi.svg @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + diff --git a/res/sim/logo.svg b/res/emu/logo.svg similarity index 100% rename from res/sim/logo.svg rename to res/emu/logo.svg diff --git a/res/sim/emulator.qrc b/res/sim/emulator.qrc deleted file mode 100644 index 31deda2..0000000 --- a/res/sim/emulator.qrc +++ /dev/null @@ -1,7 +0,0 @@ - - - icon-camera.svg - icon-monitor.svg - logo.svg - - diff --git a/res/sim/icon-camera.svg b/res/sim/icon-camera.svg deleted file mode 100644 index f49ab4e..0000000 --- a/res/sim/icon-camera.svg +++ /dev/null @@ -1,835 +0,0 @@ - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/res/sim/icon-monitor.svg b/res/sim/icon-monitor.svg deleted file mode 100644 index 8dfd963..0000000 --- a/res/sim/icon-monitor.svg +++ /dev/null @@ -1,217 +0,0 @@ - - - - - - - - image/svg+xml - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/cpp3ds/System/utils.cpp b/src/cpp3ds/System/utils.cpp index 6bf4500..7e111a1 100644 --- a/src/cpp3ds/System/utils.cpp +++ b/src/cpp3ds/System/utils.cpp @@ -36,7 +36,7 @@ int read_word(int address){ } uint64_t GetSystemTick() { - #if !defined(TESTING) && !defined(SIMULATION) + #if !defined(TESTING) && !defined(EMULATION) register unsigned long lo64 asm ("r0"); register unsigned long hi64 asm ("r1"); asm volatile ( "SVC 0x28" : "=r"(lo64), "=r"(hi64) ); @@ -46,15 +46,6 @@ uint64_t GetSystemTick() { #endif } -void SleepThread(uint64_t ms) { - #if !defined(TESTING) && !defined(SIMULATION) - ms *= 1000000; - unsigned long hi32 = (ms >> 32); - unsigned long lo32 = (ms & 0xffffffff); - asm volatile ( "SVC 0x0A" : : "r"(lo32), "r"(hi32) ); - #endif -} - void sleep(uint64_t ms) { uint64_t ticks = ms * TICKS_PER_MSEC; uint64_t start = GetSystemTick(); diff --git a/src/cpp3ds/syscalls.cpp b/src/cpp3ds/syscalls.cpp index ef9f32c..b171239 100644 --- a/src/cpp3ds/syscalls.cpp +++ b/src/cpp3ds/syscalls.cpp @@ -1,10 +1,10 @@ -#if !defined(TESTING) && !defined(SIMULATION) +#if !defined(TESTING) && !defined(EMULATION) #include #include #include -extern int __HEAP_START; +//extern int __HEAP_START; extern "C" { @@ -15,15 +15,18 @@ extern "C" { // TODO: Update syscalls when more hardware access is available. // https://sourceware.org/newlib/libc.html#Syscalls caddr_t _sbrk ( int incr ){ + /* static unsigned char *heap = NULL; unsigned char *prev_heap; if (heap == NULL) { heap = (unsigned char *)&__HEAP_START; } prev_heap = heap; - /* check removed to show basic approach */ + // check removed to show basic approach heap += incr; return (caddr_t) prev_heap; + */ + return NULL; } int _close(int file) { return -1; } int _fstat(int file, struct stat *st) { return 0; } diff --git a/src/sim3ds/Simulator/Simulator.cpp b/src/emu3ds/Emulator/Emulator.cpp similarity index 54% rename from src/sim3ds/Simulator/Simulator.cpp rename to src/emu3ds/Emulator/Emulator.cpp index 8cb1c58..46e3537 100644 --- a/src/sim3ds/Simulator/Simulator.cpp +++ b/src/emu3ds/Emulator/Emulator.cpp @@ -1,100 +1,64 @@ #include -//#include #include -#include +#include namespace cpp3ds { - Simulator::Simulator(QWidget *parent): QMainWindow(parent){ + Emulator::Emulator(QWidget *parent): QMainWindow(parent){ setupUi(this); -// application = app; - thread = new sf::Thread(&Simulator::runGame, this); -// builder->get_widget("window", window); -// builder->get_widget("boxSFML", boxSFML); -// -// builder->get_widget("aboutDialog", aboutDialog); -// builder->get_widget("imageLogo", imageLogo); -// Glib::RefPtr logo = imageLogo->get_pixbuf(); + + thread = new sf::Thread(&Emulator::runGame, this); + // float ratio = (float)logo->get_width() / logo->get_height(); // aboutDialog->set_logo(logo->scale_simple(100*ratio,100,Gdk::INTERP_BILINEAR)); -// -// -// builder->get_widget("saveDialog", saveDialog); -// saveDialog->add_button("gtk-cancel", Gtk::RESPONSE_CANCEL); -// saveDialog->add_button("gtk-save", Gtk::RESPONSE_OK); -// -// builder->get_widget("menuAbout", menuAbout); -// builder->get_widget("buttonTest", buttonTest); -// builder->get_widget("buttonScreenshot", buttonScreenshot); -// builder->get_widget("buttonPlayPause", buttonPlayPause); -// builder->get_widget("buttonStop", buttonStop); -// builder->get_widget("buttonToggle3D", buttonToggle3D); -// builder->get_widget("scale3D", scale3D); - // Create and add a SFMLWidget - screen = new QSFMLCanvas(this, QPoint(20, 20), QSize(360, 360)); + // Create and add a SFML widget + screen = new QSFMLCanvas(nullptr, QPoint(0, 0), QSize(400, 480)); // boxSFML->pack_start(*screen, true, true); - screen->show(); - - pausedFrameTexture.create(800 + SIM_OUTLINE_THICKNESS*2, 480 + SIM_OUTLINE_THICKNESS*2); - + verticalLayout->addWidget(screen); +// screen->show(); screen->setFramerateLimit(60); - // Connect all GTK signals -// Glib::signal_timeout().connect(sigc::bind_return(sigc::mem_fun(*this, -// &Simulator::checkThreadState ),true),200); -// -// menuAbout->signal_activate().connect(sigc::mem_fun(*this, -// &Simulator::on_about_clicked )); -// aboutDialog->signal_response().connect(sigc::mem_fun(*this, -// &Simulator::on_about_response )); -// -// screen->signal_size_allocate().connect(sigc::mem_fun(*this, -// &Simulator::on_sfml_size_allocate )); -// -// buttonTest->signal_clicked().connect(sigc::mem_fun(*this, -// &Simulator::on_test_clicked )); -// buttonScreenshot->signal_clicked().connect(sigc::mem_fun(*this, -// &Simulator::saveScreenshot )); -// buttonPlayPause->signal_clicked().connect(sigc::mem_fun(*this, -// &Simulator::on_playpause_clicked )); -// buttonStop->signal_clicked().connect(sigc::mem_fun(*this, -// &Simulator::on_stop_clicked )); -// buttonToggle3D->signal_toggled().connect(sigc::mem_fun(*this, -// &Simulator::on_toggle3d_clicked )); + slider3D = new QSlider(); + slider3D->setOrientation(Qt::Horizontal); + toolBar->insertWidget(actionVolume, slider3D); + + spacer = new QWidget(); + spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + toolBar->insertWidget(actionVolume, spacer); + + pausedFrameTexture.create(800 + EMU_OUTLINE_THICKNESS*2, 480 + EMU_OUTLINE_THICKNESS*2); + } - Simulator::~Simulator(){ + Emulator::~Emulator(){ stop(); delete thread; delete screen; - } - - void Simulator::run(){ -// application->run(*window); + delete slider3D; } // Meant to be run in another thread or will block the GUI. - void Simulator::runGame(){ + void Emulator::runGame(){ isThreadRunning = true; - std::cout << "Simulation starting..." << std::endl; + std::cout << "Emulation starting..." << std::endl; cpp3ds_main(); - std::cout << "Simulation ended. " << std::endl; + std::cout << "Emulation ended. " << std::endl; screen->setActive(false); isThreadRunning = false; } - void Simulator::checkThreadState(){ + void Emulator::checkThreadState(){ // Check to see if thread ended but GUI hasn't updated // (Can't easily update GUI inside thread) // if (!isThreadRunning && buttonStop->get_sensitive()) // on_stop_clicked(); } - void Simulator::play() { - if (state == SIM_PLAYING) + void Emulator::play() { + if (state == EMU_PLAYING) return; - state = SIM_PLAYING; + state = EMU_PLAYING; screen->setActive(false); // Clear event queue @@ -105,32 +69,32 @@ namespace cpp3ds { thread->launch(); } - void Simulator::pause() { - state = SIM_PAUSED; + void Emulator::pause() { + state = EMU_PAUSED; } - void Simulator::updatePausedFrame(){ + void Emulator::updatePausedFrame(){ pausedFrameTexture.update(*screen); pausedFrame.setTexture(pausedFrameTexture, true); screen->setActive(false); } - void Simulator::stop() { - if (state == SIM_STOPPED) + void Emulator::stop() { + if (state == EMU_STOPPED) return; // Set state first to trigger thread stop - state = SIM_STOPPED; + state = EMU_STOPPED; thread->wait(); } - float Simulator::get_slider3d(){ + float Emulator::get_slider3d(){ sf::Lock lock(mutex); // if (!buttonToggle3D->get_active()) return 0; // return scale3D->get_value(); } - void Simulator::saveScreenshot(){ + void Emulator::saveScreenshot(){ // if (state == SIM_PLAYING) // on_playpause_clicked(); // saveDialog->set_current_name("screenshot.png"); @@ -144,7 +108,7 @@ namespace cpp3ds { // saveDialog->close(); } - void Simulator::drawPausedFrame(){ + void Emulator::drawPausedFrame(){ if (!initialized){ initialized = true; screen->clear(); @@ -155,7 +119,7 @@ namespace cpp3ds { } // If paused/stopped, redraw paused frame - if (state != SIM_PLAYING){ + if (state != EMU_PLAYING){ screen->clear(); screen->draw(pausedFrame); screen->display(); @@ -166,11 +130,30 @@ namespace cpp3ds { UI Events ***********************/ - void Simulator::on_pushButton_clicked() { - play(); -// screen->clear(sf::Color(200,50,50)); -// screen->display(); - std::cout << "okok" << std::endl; + void Emulator::on_pushButton_clicked() { +// buttonStop->set_sensitive(true); + if (state != EMU_PLAYING){ +// buttonPlayPause->set_icon_name("gtk-media-pause"); + play(); + } else { +// buttonPlayPause->set_icon_name("gtk-media-play-ltr"); + pause(); + } + } + + void Emulator::on_toolBar_orientationChanged(Qt::Orientation orientation){ + slider3D->setOrientation(orientation); + if (orientation == Qt::Horizontal){ + slider3D->setMinimumWidth(50); + slider3D->setMaximumWidth(150); + slider3D->setMinimumHeight(0); + slider3D->setMaximumHeight(200); + } else { + slider3D->setMinimumWidth(0); + slider3D->setMaximumWidth(200); + slider3D->setMinimumHeight(50); + slider3D->setMaximumHeight(150); + } } /* void Simulator::on_sfml_size_allocate(Gtk::Allocation& allocation){ @@ -202,17 +185,6 @@ namespace cpp3ds { aboutDialog->hide(); } - void Simulator::on_playpause_clicked(){ - buttonStop->set_sensitive(true); - if (state != SIM_PLAYING){ - buttonPlayPause->set_icon_name("gtk-media-pause"); - play(); - } else { - buttonPlayPause->set_icon_name("gtk-media-play-ltr"); - pause(); - } - } - void Simulator::on_stop_clicked(){ buttonStop->set_sensitive(false); buttonPlayPause->set_sensitive(false); diff --git a/src/sim3ds/Simulator/SFMLWidget.cpp b/src/emu3ds/Emulator/SFMLWidget.cpp similarity index 75% rename from src/sim3ds/Simulator/SFMLWidget.cpp rename to src/emu3ds/Emulator/SFMLWidget.cpp index 474fc06..4b21223 100644 --- a/src/sim3ds/Simulator/SFMLWidget.cpp +++ b/src/emu3ds/Emulator/SFMLWidget.cpp @@ -5,7 +5,7 @@ #include #include #include -#include +#include QSFMLCanvas::QSFMLCanvas(QWidget* Parent, const QPoint& Position, const QSize& Size, unsigned int FrameTime) : QWidget (Parent), @@ -22,10 +22,13 @@ myInitialized (false) bottomScreen.create(BOTTOM_WIDTH, BOTTOM_HEIGHT, true); // Set strong focus to enable keyboard events to be received - setFocusPolicy(Qt::StrongFocus); + setFocusPolicy(Qt::WheelFocus); + + this->setMinimumHeight(480); + this->setMinimumWidth(400); // Setup the widget geometry - move(Position); +// move(Position); resize(Size); // Setup the timer @@ -36,8 +39,7 @@ QSFMLCanvas::~QSFMLCanvas(){} void QSFMLCanvas::showEvent(QShowEvent*) { - if (!myInitialized) - { + if (!myInitialized) { // Under X11, we need to flush the commands sent to the server to ensure that // SFML will get an updated view of the windows #ifdef Q_WS_X11 @@ -47,15 +49,6 @@ void QSFMLCanvas::showEvent(QShowEvent*) // Create the SFML window with the widget handle RenderWindow::create(winId()); -// RenderWindow::create((void *) winId()); - - // Let the derived class do its specific stuff -// OnInit(); - - // Setup the timer to trigger a refresh at specified framerate -// connect(&myTimer, SIGNAL(timeout()), this, SLOT(repaint())); -// myTimer.start(); - myInitialized = true; } } @@ -66,15 +59,46 @@ QPaintEngine* QSFMLCanvas::paintEngine() const { return nullptr; } -void QSFMLCanvas::paintEvent(QPaintEvent*) -{ - // Let the derived class do its specific stuff -// OnUpdate(); - - // Display on screen +void QSFMLCanvas::paintEvent(QPaintEvent*) { RenderWindow::display(); } +void QSFMLCanvas::mousePressEvent(QMouseEvent* event) { + sf::Event e; + e.type = sf::Event::MouseButtonPressed; + e.mouseButton.x = event->x(); + e.mouseButton.y = event->y(); + pushMouseEvent(e); +} +void QSFMLCanvas::mouseMoveEvent(QMouseEvent* event) { + sf::Event e; + e.type = sf::Event::MouseMoved; + e.mouseButton.x = event->x(); + e.mouseButton.y = event->y(); + pushMouseEvent(e); +} +void QSFMLCanvas::mouseReleaseEvent(QMouseEvent* event) { + sf::Event e; + e.type = sf::Event::MouseButtonReleased; + e.mouseButton.x = event->x(); + e.mouseButton.y = event->y(); + pushMouseEvent(e); +} + +void QSFMLCanvas::pushMouseEvent(const sf::Event& event) { + m_events.push(event); +} + +bool QSFMLCanvas::pollMouseEvent(sf::Event& event) { + // Pop the first event of the queue, if it is not empty + if (!m_events.empty()) { + event = m_events.front(); + m_events.pop(); + return true; + } + return false; +} + /* void SFMLWidget::on_size_allocate(Gtk::Allocation& allocation) { diff --git a/src/sim3ds/System/Sleep.cpp b/src/emu3ds/System/Sleep.cpp similarity index 100% rename from src/sim3ds/System/Sleep.cpp rename to src/emu3ds/System/Sleep.cpp diff --git a/src/sim3ds/System/utils.cpp b/src/emu3ds/System/utils.cpp similarity index 100% rename from src/sim3ds/System/utils.cpp rename to src/emu3ds/System/utils.cpp diff --git a/src/emu3ds/Window/Display.cpp b/src/emu3ds/Window/Display.cpp new file mode 100644 index 0000000..f790d43 --- /dev/null +++ b/src/emu3ds/Window/Display.cpp @@ -0,0 +1,17 @@ +#include +#include + +namespace cpp3ds { + + void display(){ + _emulator->screen->display(); + if (_emulator->getState() == EMU_PAUSED){ + _emulator->screen->setActive(false); + _emulator->updatePausedFrame(); + while (_emulator->getState() == EMU_PAUSED) + sf:sleep(sf::milliseconds(100)); + } + // _simulator->screen->renderWindow.clear(); + } + +} diff --git a/src/sim3ds/Window/EventManager.cpp b/src/emu3ds/Window/EventManager.cpp similarity index 83% rename from src/sim3ds/Window/EventManager.cpp rename to src/emu3ds/Window/EventManager.cpp index 2cb06d1..3ab86cb 100644 --- a/src/sim3ds/Window/EventManager.cpp +++ b/src/emu3ds/Window/EventManager.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -38,12 +38,8 @@ bool EventManager::filterEvent(const Event& event) { void EventManager::processEvents() { // Check all inputs and push Events that are triggered sf::Event event; - while (_simulator->screen->pollEvent(event)) { + while (_emulator->screen->pollMouseEvent(event)) { switch (event.type) { - case sf::Event::KeyPressed: - break; - case sf::Event::KeyReleased: - break; case sf::Event::MouseButtonPressed: if (event.mouseButton.x > BOTTOM_X && event.mouseButton.x < BOTTOM_X+BOTTOM_WIDTH && event.mouseButton.y > BOTTOM_Y){ cpp3ds::Event e; @@ -63,6 +59,24 @@ void EventManager::processEvents() { } break; case sf::Event::MouseMoved: + if (event.mouseButton.x > BOTTOM_X && event.mouseButton.x < BOTTOM_X+BOTTOM_WIDTH && event.mouseButton.y > BOTTOM_Y){ + cpp3ds::Event e; + e.type = Event::TouchMoved; + e.touch.x = event.mouseButton.x - BOTTOM_X; + e.touch.y = event.mouseButton.y - BOTTOM_Y; + pushEvent(e); + } + break; + default: + break; + } + } + while (_emulator->screen->pollEvent(event)) { +// std::cout << "EVENT: " << event.type << std::endl; + switch (event.type) { + case sf::Event::KeyPressed: + break; + case sf::Event::KeyReleased: break; case sf::Event::JoystickMoved: break; diff --git a/src/sim3ds/Window/Input.cpp b/src/emu3ds/Window/Input.cpp similarity index 82% rename from src/sim3ds/Window/Input.cpp rename to src/emu3ds/Window/Input.cpp index cda493d..4af5cf9 100644 --- a/src/sim3ds/Window/Input.cpp +++ b/src/emu3ds/Window/Input.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include @@ -19,7 +19,7 @@ namespace cpp3ds { } void Input::update(float deltaTime){ - Input::slider = _simulator->get_slider3d(); + Input::slider = _emulator->get_slider3d(); } } diff --git a/src/sim3ds/Window/Keyboard.cpp b/src/emu3ds/Window/Keyboard.cpp similarity index 84% rename from src/sim3ds/Window/Keyboard.cpp rename to src/emu3ds/Window/Keyboard.cpp index 9e1aae6..68d9779 100644 --- a/src/sim3ds/Window/Keyboard.cpp +++ b/src/emu3ds/Window/Keyboard.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -18,7 +18,7 @@ float Keyboard::get3DSlider() { } void Keyboard::update() { - m_slider = _simulator->get_slider3d(); + m_slider = _emulator->get_slider3d(); } } diff --git a/src/sim3ds/Window/Scene.cpp b/src/emu3ds/Window/Scene.cpp similarity index 86% rename from src/sim3ds/Window/Scene.cpp rename to src/emu3ds/Window/Scene.cpp index d1523eb..4463889 100644 --- a/src/sim3ds/Window/Scene.cpp +++ b/src/emu3ds/Window/Scene.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include #include @@ -13,7 +13,7 @@ namespace cpp3ds { sf::Clock clock; sf::Time deltaTime; while (ret == 0) { - if (_simulator->getState() == SIM_STOPPED) + if (_emulator->getState() == EMU_STOPPED) return -1; render(); if (useDisplay) diff --git a/src/sim3ds/Window/Screen.cpp b/src/emu3ds/Window/Screen.cpp similarity index 86% rename from src/sim3ds/Window/Screen.cpp rename to src/emu3ds/Window/Screen.cpp index 58fc05c..e3ff04d 100644 --- a/src/sim3ds/Window/Screen.cpp +++ b/src/emu3ds/Window/Screen.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include @@ -18,11 +18,11 @@ namespace cpp3ds { sf::Color outline(25,25,25); box.setFillColor(c); box.setOutlineColor(outline); - box.setOutlineThickness(SIM_OUTLINE_THICKNESS); + box.setOutlineThickness(EMU_OUTLINE_THICKNESS); box.setPosition(x,y); pixelImage.create(width, height, sf::Color::Transparent); // Should only clear the relevant screen area - _simulator->screen->draw(box); + _emulator->screen->draw(box); } void Screen::draw(Drawable& obj, float x, float y, bool use3D) { @@ -35,7 +35,7 @@ namespace cpp3ds { starsTexture.loadFromImage(pixelImage); sf::Sprite test(starsTexture); test.setPosition(x, y); - _simulator->screen->draw(test); + _emulator->screen->draw(test); } } diff --git a/src/sim3ds/Window/TopScreen.cpp b/src/emu3ds/Window/TopScreen.cpp similarity index 100% rename from src/sim3ds/Window/TopScreen.cpp rename to src/emu3ds/Window/TopScreen.cpp diff --git a/src/emu3ds/emu3ds.cpp b/src/emu3ds/emu3ds.cpp new file mode 100644 index 0000000..fed3dce --- /dev/null +++ b/src/emu3ds/emu3ds.cpp @@ -0,0 +1,22 @@ +#include +#include + +namespace cpp3ds { + // Define global pointer to emulator + Emulator* _emulator; +} + +int main(int argc, char **argv){ + QApplication a(argc, argv); + + // Force resource init because it's in archive lib + Q_INIT_RESOURCE(emulator); + + cpp3ds::_emulator = new cpp3ds::Emulator(); + cpp3ds::_emulator->show(); + + int ret = a.exec(); + + delete cpp3ds::_emulator; + return ret; +} diff --git a/src/sim3ds/Window/Display.cpp b/src/sim3ds/Window/Display.cpp deleted file mode 100644 index 0c9b806..0000000 --- a/src/sim3ds/Window/Display.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -namespace cpp3ds { - - void display(){ - _simulator->screen->display(); - if (_simulator->getState() == SIM_PAUSED){ - _simulator->screen->setActive(false); - _simulator->updatePausedFrame(); - while (_simulator->getState() == SIM_PAUSED) - sf:sleep(sf::milliseconds(100)); - } - // _simulator->screen->renderWindow.clear(); - } - -} diff --git a/src/sim3ds/sim3ds.cpp b/src/sim3ds/sim3ds.cpp deleted file mode 100644 index 0f6fdde..0000000 --- a/src/sim3ds/sim3ds.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include - -namespace cpp3ds { - Simulator* _simulator; -} - -int main(int argc, char **argv){ - QApplication a(argc, argv); - - // Force resource init because it's in archive lib - Q_INIT_RESOURCE(emulator); - - // Define global pointer to simulator - cpp3ds::_simulator = new cpp3ds::Simulator(); - cpp3ds::_simulator->show(); - - return a.exec(); -}