diff --git a/C64.emu/src/main/EmuMenuViews.cc b/C64.emu/src/main/EmuMenuViews.cc index f22ecf8c4..a9412b42f 100644 --- a/C64.emu/src/main/EmuMenuViews.cc +++ b/C64.emu/src/main/EmuMenuViews.cc @@ -528,7 +528,7 @@ class DatasetteControlsView : public TableView, public MainAppHelper void onShow() final { updateTapeCounter(); - tapeCounter.compile(); + tapeCounter.place(); } }; @@ -546,7 +546,7 @@ class C64IOControlView : public TableView, public MainAppHelper void onTapeMediaChange() { updateTapeText(); - tapeSlot.compile(); + tapeSlot.place(); } void addTapeFilePickerView(Input::Event e, bool dismissPreviousView) @@ -621,7 +621,7 @@ class C64IOControlView : public TableView, public MainAppHelper void onROMMediaChange() { updateROMText(); - romSlot.compile(); + romSlot.place(); } void addCartFilePickerView(Input::Event e, bool dismissPreviousView) @@ -682,7 +682,7 @@ class C64IOControlView : public TableView, public MainAppHelper void onDiskMediaChange(int slot) { updateDiskText(slot); - diskSlot[slot].compile(); + diskSlot[slot].place(); } void addDiskFilePickerView(Input::Event e, uint8_t slot, bool dismissPreviousView) diff --git a/EmuFramework/include/emuframework/ButtonConfigView.hh b/EmuFramework/include/emuframework/ButtonConfigView.hh index e3338c869..83bfe662f 100644 --- a/EmuFramework/include/emuframework/ButtonConfigView.hh +++ b/EmuFramework/include/emuframework/ButtonConfigView.hh @@ -40,8 +40,8 @@ public: ButtonConfigSetView(ViewAttachParams attach, InputManagerView &rootIMView, Input::Device &dev, std::string_view actionName, SetDelegate onSet); void place() final; - bool inputEvent(const Input::Event &) final; - void draw(Gfx::RendererCommands &__restrict__) final; + bool inputEvent(const Input::Event&, ViewInputEventParams p = {}) final; + void draw(Gfx::RendererCommands&__restrict__, ViewDrawParams p = {}) const final; void onAddedToController(ViewController *, const Input::Event &) final; private: @@ -57,7 +57,7 @@ private: MappedKeys pushedKeys; void initPointerUI(); - bool pointerUIIsInit(); + bool pointerUIIsInit() const; void finalize(); }; @@ -65,7 +65,7 @@ class ButtonConfigView : public TableView, public EmuAppHelper { public: ButtonConfigView(ViewAttachParams attach, InputManagerView &rootIMView, const KeyCategory &cat, InputDeviceConfig &devConf); - bool inputEvent(const Input::Event &) final; + bool inputEvent(const Input::Event&, ViewInputEventParams p = {}) final; private: InputManagerView &rootIMView; diff --git a/EmuFramework/include/emuframework/CreditsView.hh b/EmuFramework/include/emuframework/CreditsView.hh index 9bef65236..903efa0a4 100644 --- a/EmuFramework/include/emuframework/CreditsView.hh +++ b/EmuFramework/include/emuframework/CreditsView.hh @@ -30,9 +30,9 @@ public: CreditsView(ViewAttachParams attach, UTF16String str); ~CreditsView(); void prepareDraw() final; - void draw(Gfx::RendererCommands &__restrict__) final; + void draw(Gfx::RendererCommands&__restrict__, ViewDrawParams p = {}) const final; void place() final; - bool inputEvent(const Input::Event &) final; + bool inputEvent(const Input::Event&, ViewInputEventParams p = {}) final; std::u16string_view name() const final; private: diff --git a/EmuFramework/include/emuframework/EmuApp.hh b/EmuFramework/include/emuframework/EmuApp.hh index 7b28bf2f8..57c5c139c 100644 --- a/EmuFramework/include/emuframework/EmuApp.hh +++ b/EmuFramework/include/emuframework/EmuApp.hh @@ -190,9 +190,7 @@ public: bool loadState(CStringView path); bool loadStateWithSlot(int slot); bool shouldOverwriteExistingState() const; - const auto &contentSearchPath() const { return contentSearchPath_; } - FS::PathString contentSearchPath(std::string_view name) const; - void setContentSearchPath(auto &&path) { contentSearchPath_ = IG_forward(path); } + FS::PathString inContentSearchPath(std::string_view name) const; FS::PathString validSearchPath(const FS::PathString &) const; static void updateLegacySavePath(IG::ApplicationContext, CStringView path); auto screenshotDirectory() const { return system().userPath(userScreenshotPath); } @@ -219,6 +217,7 @@ public: void unsetDisabledInputKeys(); Gfx::TextureSpan asset(AssetID) const; Gfx::TextureSpan asset(AssetDesc) const; + Gfx::TextureSpan collectTextCloseAsset() const; VController &defaultVController() { return inputManager.vController; } std::unique_ptr makeView(ViewAttachParams, ViewID); std::unique_ptr makeCloseContentView(); @@ -331,11 +330,10 @@ public: postMessage(secs, true, IG_forward(msg)); } -protected: +public: IG::FontManager fontManager; mutable Gfx::Renderer renderer; ViewManager viewManager; -public: EmuAudio audio; EmuVideo video; EmuVideoLayer videoLayer; @@ -349,7 +347,6 @@ protected: EmuSystemTask emuSystemTask{*this}; mutable Gfx::Texture assetBuffImg[wise_enum::size]; int savedAdvancedFrames{}; - FS::PathString contentSearchPath_; [[no_unique_address]] IG::Data::PixmapReader pixmapReader; [[no_unique_address]] IG::Data::PixmapWriter pixmapWriter; [[no_unique_address]] PerformanceHintManager perfHintManager; @@ -361,6 +358,7 @@ protected: public: BluetoothAdapter bluetoothAdapter; RecentContent recentContent; + FS::PathString contentSearchPath; std::string userScreenshotPath; Property{.isValid = renderPixelFormatIsValid}> renderPixelFormat; @@ -418,13 +416,13 @@ public: ConditionalMember presentationTimeMode{PresentationTimeMode::basic}; Property allowBlankFrameInsertion; +protected: struct ConfigParams { Gfx::DrawableConfig windowDrawableConf{}; }; void onMainWindowCreated(ViewAttachParams, const Input::Event &); - Gfx::TextureSpan collectTextCloseAsset() const; ConfigParams loadConfigFile(IG::ApplicationContext); void saveConfigFile(IG::ApplicationContext); void saveConfigFile(FileIO &); diff --git a/EmuFramework/include/emuframework/EmuInputView.hh b/EmuFramework/include/emuframework/EmuInputView.hh index 7daf93236..4470e0706 100644 --- a/EmuFramework/include/emuframework/EmuInputView.hh +++ b/EmuFramework/include/emuframework/EmuInputView.hh @@ -34,8 +34,8 @@ public: EmuInputView(); EmuInputView(ViewAttachParams attach, VController &vCtrl, EmuVideoLayer &videoLayer); void place() final; - void draw(Gfx::RendererCommands &__restrict__) final; - bool inputEvent(const Input::Event &) final; + void draw(Gfx::RendererCommands &__restrict__, ViewDrawParams p = {}) const final; + bool inputEvent(const Input::Event&, ViewInputEventParams p = {}) final; void resetInput(); bool toggleAltSpeedMode(AltSpeedMode); bool setAltSpeedMode(AltSpeedMode, bool on); diff --git a/EmuFramework/include/emuframework/EmuSystemTask.hh b/EmuFramework/include/emuframework/EmuSystemTask.hh index c5f884827..b0767c72f 100644 --- a/EmuFramework/include/emuframework/EmuSystemTask.hh +++ b/EmuFramework/include/emuframework/EmuSystemTask.hh @@ -18,7 +18,7 @@ #include #include #include -#include +#include namespace EmuEx { @@ -42,11 +42,17 @@ public: struct ExitCommand {}; using CommandVariant = std::variant; + class Command: public CommandVariant, public AddVisit + { + public: + using CommandVariant::CommandVariant; + using AddVisit::visit; + }; struct CommandMessage { std::binary_semaphore *semPtr{}; - CommandVariant command{PauseCommand{}}; + Command command{PauseCommand{}}; void setReplySemaphore(std::binary_semaphore *semPtr_) { assert(!semPtr); semPtr = semPtr_; }; }; diff --git a/EmuFramework/include/emuframework/EmuVideo.hh b/EmuFramework/include/emuframework/EmuVideo.hh index aa252843b..5cf304508 100644 --- a/EmuFramework/include/emuframework/EmuVideo.hh +++ b/EmuFramework/include/emuframework/EmuVideo.hh @@ -53,7 +53,7 @@ public: void setRendererTask(Gfx::RendererTask &); bool hasRendererTask() const; bool setFormat(IG::PixmapDesc desc, EmuSystemTaskContext task = {}); - void dispatchFormatChanged(); + void dispatchFormatChanged() { onFormatChanged(*this); } void resetImage(IG::PixelFormat newFmt = {}); IG::PixmapDesc deleteImage(); EmuVideoImage startFrame(EmuSystemTaskContext); @@ -64,7 +64,7 @@ public: void startUnchangedFrame(EmuSystemTaskContext); void finishFrame(EmuSystemTaskContext, Gfx::LockedTextureBuffer texBuff); void finishFrame(EmuSystemTaskContext, IG::PixmapView pix); - void dispatchFrameFinished(); + void dispatchFrameFinished() { onFrameFinished(*this); } void clear(); void takeGameScreenshot(); bool isExternalTexture() const; @@ -73,8 +73,6 @@ public: IG::ApplicationContext appContext() const; WSize size() const; bool formatIsEqual(IG::PixmapDesc desc) const; - void setOnFrameFinished(FrameFinishedDelegate del); - void setOnFormatChanged(FormatChangedDelegate del); void setTextureBufferMode(EmuSystem &, Gfx::TextureBufferMode mode); void setSampler(Gfx::TextureSamplerConfig); constexpr auto colorSpace() const { return colSpace; } @@ -87,8 +85,10 @@ public: protected: Gfx::RendererTask *rTask{}; Gfx::PixmapBufferTexture vidImg; +public: FrameFinishedDelegate onFrameFinished; FormatChangedDelegate onFormatChanged; +protected: IG::PixelFormat renderFmt; Gfx::TextureBufferMode bufferMode{}; bool screenshotNextFrame{}; diff --git a/EmuFramework/include/emuframework/EmuView.hh b/EmuFramework/include/emuframework/EmuView.hh index 39b26c62b..6868f9d70 100644 --- a/EmuFramework/include/emuframework/EmuView.hh +++ b/EmuFramework/include/emuframework/EmuView.hh @@ -36,16 +36,15 @@ public: EmuView(ViewAttachParams, EmuVideoLayer *, EmuSystem &); void place() final; void prepareDraw() final; - void draw(Gfx::RendererCommands &__restrict__) final; + void draw(Gfx::RendererCommands &__restrict__, ViewDrawParams p = {}) const final; void drawframeTimeStatsText(Gfx::RendererCommands &__restrict__); - bool inputEvent(const Input::Event &) final; bool hasLayer() const { return layer; } void setLayoutInputView(EmuInputView *view) { inputView = view; } void updateFrameTimeStats(FrameTimeStats, SteadyClockTimePoint currentFrameTimestamp); void updateAudioStats(int underruns, int overruns, int callbacks, double avgCallbackFrames, int frames); void clearAudioStats(); EmuVideoLayer *videoLayer() const { return layer; } - EmuSystem &system() { return *sysPtr; } + auto& system(this auto&& self) { return *self.sysPtr; } private: EmuVideoLayer *layer{}; diff --git a/EmuFramework/include/emuframework/EmuViewController.hh b/EmuFramework/include/emuframework/EmuViewController.hh index db30eac66..bc98b652e 100644 --- a/EmuFramework/include/emuframework/EmuViewController.hh +++ b/EmuFramework/include/emuframework/EmuViewController.hh @@ -51,7 +51,7 @@ class EmuMenuViewStack : public ViewStack { public: EmuMenuViewStack(ViewAttachParams, EmuApp &); - bool inputEvent(const Input::Event &) final; + bool inputEvent(const Input::Event&) final; constexpr EmuApp &app() { return *emuAppPtr; } protected: @@ -70,7 +70,7 @@ public: void popTo(View &v) final; void dismissView(View &v, bool refreshLayout) final; void dismissView(int idx, bool refreshLayout) final; - bool inputEvent(const Input::Event &) final; + bool inputEvent(const Input::Event&) final; bool extraWindowInputEvent(const Input::Event &e); void showEmulationView(FrameTimeConfig); void showMenuView(bool updateTopView); diff --git a/EmuFramework/include/emuframework/InputManagerView.hh b/EmuFramework/include/emuframework/InputManagerView.hh index 5f7408ea6..17753b425 100644 --- a/EmuFramework/include/emuframework/InputManagerView.hh +++ b/EmuFramework/include/emuframework/InputManagerView.hh @@ -43,8 +43,8 @@ public: IdentInputDeviceView(ViewAttachParams attach); void place() final; - bool inputEvent(const Input::Event &) final; - void draw(Gfx::RendererCommands &__restrict__) final; + bool inputEvent(const Input::Event&, ViewInputEventParams p = {}) final; + void draw(Gfx::RendererCommands&__restrict__, ViewDrawParams p = {}) const final; private: Gfx::Text text; diff --git a/EmuFramework/include/emuframework/LoadProgressView.hh b/EmuFramework/include/emuframework/LoadProgressView.hh index 836f6f2fc..776569c5f 100644 --- a/EmuFramework/include/emuframework/LoadProgressView.hh +++ b/EmuFramework/include/emuframework/LoadProgressView.hh @@ -35,8 +35,7 @@ public: void setPos(int val); void setLabel(UTF16Convertible auto &&label) { text.resetString(IG_forward(label)); } void place() final; - bool inputEvent(const Input::Event &) final; - void draw(Gfx::RendererCommands &__restrict__) final; + void draw(Gfx::RendererCommands&__restrict__, ViewDrawParams p = {}) const final; MessagePortType &messagePort(); private: diff --git a/EmuFramework/include/emuframework/TouchConfigView.hh b/EmuFramework/include/emuframework/TouchConfigView.hh index c4b814b92..9c0f2ee4a 100644 --- a/EmuFramework/include/emuframework/TouchConfigView.hh +++ b/EmuFramework/include/emuframework/TouchConfigView.hh @@ -35,7 +35,7 @@ class TouchConfigView final: public TableView, public EmuAppHelper public: TouchConfigView(ViewAttachParams attach, VController &vController); void place() final; - void draw(Gfx::RendererCommands &__restrict__) final; + void draw(Gfx::RendererCommands&__restrict__, ViewDrawParams p = {}) const final; void reloadItems(); void onShow() final; diff --git a/EmuFramework/src/ConfigFile.cc b/EmuFramework/src/ConfigFile.cc index eb14b2dd8..ec6cc979c 100644 --- a/EmuFramework/src/ConfigFile.cc +++ b/EmuFramework/src/ConfigFile.cc @@ -103,7 +103,7 @@ void EmuApp::saveConfigFile(FileIO &io) writeOptionValueIfNotDefault(io, presentMode); if(renderer.supportsPresentationTime()) writeOptionValueIfNotDefault(io, CFGKEY_RENDERER_PRESENTATION_TIME, presentationTimeMode, PresentationTimeMode::basic); - writeStringOptionValue(io, CFGKEY_LAST_DIR, contentSearchPath()); + writeStringOptionValue(io, CFGKEY_LAST_DIR, contentSearchPath); writeStringOptionValue(io, CFGKEY_SAVE_PATH, system().userSaveDirectory()); writeStringOptionValue(io, CFGKEY_SCREENSHOTS_PATH, userScreenshotPath); system().writeConfig(ConfigType::MAIN, io); @@ -171,7 +171,7 @@ EmuApp::ConfigParams EmuApp::loadConfigFile(IG::ApplicationContext ctx) case CFGKEY_FRAME_RATE: return readOptionValue(io, [&](auto &&val){outputTimingManager.setFrameTimeOption(VideoSystem::NATIVE_NTSC, val);}); case CFGKEY_FRAME_RATE_PAL: return readOptionValue(io, [&](auto &&val){outputTimingManager.setFrameTimeOption(VideoSystem::PAL, val);}); case CFGKEY_LAST_DIR: - return readStringOptionValue(io, [&](auto &&path){setContentSearchPath(path);}); + return readStringOptionValue(io, [&](auto &&path){contentSearchPath = path;}); case CFGKEY_FONT_Y_SIZE: return readOptionValue(io, fontSize); case CFGKEY_GAME_ORIENTATION: return readOptionValue(io, emuOrientation); case CFGKEY_MENU_ORIENTATION: return readOptionValue(io, menuOrientation); diff --git a/EmuFramework/src/EmuApp.cc b/EmuFramework/src/EmuApp.cc index 918145098..6bf4b88b3 100644 --- a/EmuFramework/src/EmuApp.cc +++ b/EmuFramework/src/EmuApp.cc @@ -110,17 +110,17 @@ EmuApp::EmuApp(ApplicationInitParams initParams, ApplicationContext &ctx): if(needsGlobalInstance) gAppPtr = this; ctx.setAcceptIPC(true); - onEvent = [this](ApplicationContext ctx, ApplicationEvent appEvent) + onEvent = [this](ApplicationContext ctx, const ApplicationEvent& appEvent) { - visit(overloaded + appEvent.visit(overloaded { - [&](DocumentPickerEvent& e) + [&](const DocumentPickerEvent& e) { log.info("document picked with URI:{}", e.uri); system().setInitialLoadPath(e.uri); }, [](auto &) {} - }, appEvent); + }); }; initOptions(ctx); } @@ -144,7 +144,7 @@ class ExitConfirmAlertView : public AlertView, public EmuAppHelper } } - bool inputEvent(const Input::Event &e) final + bool inputEvent(const Input::Event &e, ViewInputEventParams) final { if(e.keyEvent() && e.keyEvent()->pushed(Input::DefaultKey::CANCEL)) { @@ -459,12 +459,11 @@ void EmuApp::mainInitCommon(IG::ApplicationInitParams initParams, IG::Applicatio winData.viewController.placeElements(); winData.viewController.pushAndShow(makeView(viewAttach, ViewID::MAIN_MENU)); configureSecondaryScreens(); - video.setOnFormatChanged( - [this, &viewController = winData.viewController](EmuVideo &) - { - videoLayer.onVideoFormatChanged(videoEffectPixelFormat()); - viewController.placeEmuViews(); - }); + video.onFormatChanged = [this, &viewController = winData.viewController](EmuVideo&) + { + videoLayer.onVideoFormatChanged(videoEffectPixelFormat()); + viewController.placeEmuViews(); + }; video.setRendererTask(renderer.task()); video.setTextureBufferMode(system(), textureBufferMode); videoLayer.setRendererTask(renderer.task()); @@ -476,18 +475,18 @@ void EmuApp::mainInitCommon(IG::ApplicationInitParams initParams, IG::Applicatio return true; }; - win.onEvent = [this](Window &win, WindowEvent winEvent) + win.onEvent = [this](Window& win, const WindowEvent& winEvent) { - return visit(overloaded + return winEvent.visit(overloaded { - [&](Input::Event &e) { return viewController().inputEvent(e); }, - [&](DrawEvent &e) + [&](const Input::Event& e) { return viewController().inputEvent(e); }, + [&](const DrawEvent& e) { record(FrameTimeStatEvent::startOfDraw); auto reportTime = scopeGuard([&]{ reportFrameWorkTime(); }); return viewController().drawMainWindow(win, e.params, renderer.task()); }, - [&](WindowSurfaceChangeEvent &e) + [&](const WindowSurfaceChangeEvent& e) { if(e.change.resized()) { @@ -496,36 +495,36 @@ void EmuApp::mainInitCommon(IG::ApplicationInitParams initParams, IG::Applicatio renderer.task().updateDrawableForSurfaceChange(win, e.change); return true; }, - [&](DragDropEvent &e) + [&](const DragDropEvent& e) { log.info("got DnD:{}", e.filename); handleOpenFileCommand(e.filename); return true; }, - [&](FocusChangeEvent &e) + [&](const FocusChangeEvent& e) { windowData(win).focused = e.in; onFocusChange(e.in); return true; }, - [](auto &){ return false; } - }, winEvent); + [](auto&){ return false; } + }); }; onMainWindowCreated(viewAttach, ctx.defaultInputEvent()); - onEvent = [this](ApplicationContext ctx, ApplicationEvent appEvent) + onEvent = [this](ApplicationContext ctx, const ApplicationEvent& appEvent) { - visit(overloaded + appEvent.visit(overloaded { - [&](DocumentPickerEvent& e) + [&](const DocumentPickerEvent& e) { log.info("document picked with URI:{}", e.uri); if(!viewController().isShowingEmulation() && viewController().top().onDocumentPicked(e)) return; handleOpenFileCommand(e.uri); }, - [&](ScreenChangeEvent &e) + [&](const ScreenChangeEvent &e) { if(e.change == ScreenChange::added) { @@ -554,12 +553,12 @@ void EmuApp::mainInitCommon(IG::ApplicationInitParams initParams, IG::Applicatio } } }, - [&](Input::DevicesEnumeratedEvent &) + [&](const Input::DevicesEnumeratedEvent &) { log.info("input devs enumerated"); inputManager.updateInputDevices(ctx); }, - [&](Input::DeviceChangeEvent &e) + [&](const Input::DeviceChangeEvent &e) { log.info("got input dev change"); inputManager.updateInputDevices(ctx); @@ -573,7 +572,7 @@ void EmuApp::mainInitCommon(IG::ApplicationInitParams initParams, IG::Applicatio } viewController().onInputDevicesChanged(); }, - [&](FreeCachesEvent &e) + [&](const FreeCachesEvent &e) { viewManager.defaultFace.freeCaches(); viewManager.defaultBoldFace.freeCaches(); @@ -581,7 +580,7 @@ void EmuApp::mainInitCommon(IG::ApplicationInitParams initParams, IG::Applicatio viewController().prepareDraw(); }, [](auto &) {} - }, appEvent); + }); }; ctx.addOnExit( @@ -792,7 +791,7 @@ void EmuApp::handleOpenFileCommand(CStringView path) log.info("changing to dir {} from external command", path); showUI(false); viewController().popToRoot(); - setContentSearchPath(path); + contentSearchPath = path; viewController().pushAndShow( FilePicker::forLoading(attachParams(), appContext().defaultInputEvent()), appContext().defaultInputEvent(), @@ -834,14 +833,13 @@ void EmuApp::startEmulation() if(!viewController().isShowingEmulation()) return; videoLayer.setBrightnessScale(1.f); - video.setOnFrameFinished( - [&, &viewController = viewController()](EmuVideo &) - { - auto &win = viewController.emuWindow(); - record(FrameTimeStatEvent::aboutToPostDraw); - win.setDrawEventPriority(1); - win.postDraw(1); - }); + video.onFrameFinished = [&, &viewController = viewController()](EmuVideo&) + { + auto &win = viewController.emuWindow(); + record(FrameTimeStatEvent::aboutToPostDraw); + win.setDrawEventPriority(1); + win.postDraw(1); + }; frameTimeStats = {}; emuSystemTask.start(); setCPUNeedsLowLatency(appContext(), true); @@ -863,7 +861,7 @@ void EmuApp::pauseEmulation() { setCPUNeedsLowLatency(appContext(), false); emuSystemTask.pause(); - video.setOnFrameFinished([](EmuVideo &){}); + video.onFrameFinished = [](EmuVideo&){}; system().pause(*this); setRunSpeed(1.); videoLayer.setBrightnessScale(pausedVideoBrightnessScale); @@ -1115,16 +1113,16 @@ bool EmuApp::loadStateWithSlot(int slot) return loadState(system().statePath(slot)); } -FS::PathString EmuApp::contentSearchPath(std::string_view name) const +FS::PathString EmuApp::inContentSearchPath(std::string_view name) const { - return FS::uriString(contentSearchPath_, name); + return FS::uriString(contentSearchPath, name); } FS::PathString EmuApp::validSearchPath(const FS::PathString &path) const { auto ctx = appContext(); if(path.empty()) - return contentSearchPath(); + return contentSearchPath; return hasArchiveExtension(path) ? FS::dirnameUri(path) : path; } @@ -1456,17 +1454,17 @@ void EmuApp::setEmuViewOnExtraWindow(bool on, IG::Screen &screen) extraWinData.updateWindowViewport(win, makeViewport(win), renderer); viewController().moveEmuViewToWindow(win); - win.onEvent = [this](Window &win, WindowEvent winEvent) + win.onEvent = [this](Window& win, const WindowEvent& winEvent) { - return visit(overloaded + return winEvent.visit(overloaded { - [&](Input::Event &e) { return viewController().extraWindowInputEvent(e); }, - [&](DrawEvent &e) + [&](const Input::Event& e) { return viewController().extraWindowInputEvent(e); }, + [&](const DrawEvent& e) { auto reportTime = scopeGuard([&]{ reportFrameWorkTime(); }); return viewController().drawExtraWindow(win, e.params, renderer.task()); }, - [&](WindowSurfaceChangeEvent &e) + [&](const WindowSurfaceChangeEvent& e) { if(e.change.resized()) { @@ -1475,24 +1473,24 @@ void EmuApp::setEmuViewOnExtraWindow(bool on, IG::Screen &screen) renderer.task().updateDrawableForSurfaceChange(win, e.change); return true; }, - [&](DragDropEvent &e) + [&](const DragDropEvent& e) { log.info("got DnD:{}", e.filename); handleOpenFileCommand(e.filename); return true; }, - [&](FocusChangeEvent &e) + [&](const FocusChangeEvent& e) { windowData(win).focused = e.in; onFocusChange(e.in); return true; }, - [&](DismissRequestEvent &e) + [&](const DismissRequestEvent& e) { win.dismiss(); return true; }, - [&](DismissEvent &e) + [&](const DismissEvent& e) { system().resetFrameTime(); log.info("setting emu view on main window"); @@ -1508,8 +1506,8 @@ void EmuApp::setEmuViewOnExtraWindow(bool on, IG::Screen &screen) } return true; }, - [](auto &){ return false; } - }, winEvent); + [](auto&){ return false; } + }); }; win.show(); diff --git a/EmuFramework/src/EmuSystemTask.cc b/EmuFramework/src/EmuSystemTask.cc index ee400b725..1f912dd28 100644 --- a/EmuFramework/src/EmuSystemTask.cc +++ b/EmuFramework/src/EmuSystemTask.cc @@ -46,7 +46,7 @@ void EmuSystemTask::start() std::binary_semaphore *syncSemPtr{}; for(auto msg : msgs) { - bool threadIsRunning = visit(overloaded + bool threadIsRunning = msg.command.visit(overloaded { [&](FrameParamsCommand &cmd) { @@ -71,7 +71,7 @@ void EmuSystemTask::start() EventLoop::forThread().stop(); return false; }, - }, msg.command); + }); if(!threadIsRunning) return false; } diff --git a/EmuFramework/src/EmuVideo.cc b/EmuFramework/src/EmuVideo.cc index 3dc289ef9..b2be43cec 100644 --- a/EmuFramework/src/EmuVideo.cc +++ b/EmuFramework/src/EmuVideo.cc @@ -90,11 +90,6 @@ bool EmuVideo::setFormat(IG::PixmapDesc desc, EmuSystemTaskContext taskCtx) return true; } -void EmuVideo::dispatchFormatChanged() -{ - onFormatChanged(*this); -} - EmuVideoImage EmuVideo::startFrame(EmuSystemTaskContext taskCtx) { auto lockedTex = vidImg.lock(); @@ -142,12 +137,6 @@ void EmuVideo::startUnchangedFrame(EmuSystemTaskContext taskCtx) postFrameFinished(taskCtx); } -void EmuVideo::dispatchFrameFinished() -{ - //log.debug("frame finished"); - onFrameFinished(*this); -} - void EmuVideo::postFrameFinished(EmuSystemTaskContext taskCtx) { if(taskCtx) @@ -259,16 +248,6 @@ bool EmuVideo::formatIsEqual(IG::PixmapDesc desc) const return vidImg && desc == vidImg.pixmapDesc(); } -void EmuVideo::setOnFrameFinished(FrameFinishedDelegate del) -{ - onFrameFinished = del; -} - -void EmuVideo::setOnFormatChanged(FormatChangedDelegate del) -{ - onFormatChanged = del; -} - void EmuVideo::setTextureBufferMode(EmuSystem &sys, Gfx::TextureBufferMode mode) { mode = renderer().evalTextureBufferMode(mode); diff --git a/EmuFramework/src/gui/ButtonConfigView.cc b/EmuFramework/src/gui/ButtonConfigView.cc index 6c73f09c5..9961e55fa 100644 --- a/EmuFramework/src/gui/ButtonConfigView.cc +++ b/EmuFramework/src/gui/ButtonConfigView.cc @@ -50,7 +50,7 @@ ButtonConfigView::ButtonConfigView(ViewAttachParams attach, InputManagerView &ro attach, [this](ItemMessage msg) -> ItemReply { - return visit(overloaded + return msg.visit(overloaded { [&](const ItemsMessage &m) -> ItemReply { return resetItemsSize + cat.keys.size(); }, [&](const GetItemMessage &m) -> ItemReply @@ -62,7 +62,7 @@ ButtonConfigView::ButtonConfigView(ViewAttachParams attach, InputManagerView &ro else return &btn[m.idx - resetItemsSize]; }, - }, msg); + }); } }, rootIMView{rootIMView_}, @@ -141,10 +141,10 @@ void ButtonConfigView::onSet(int catIdx, MappedKeys mapKey) devConf.buildKeyMap(app().inputManager); auto &b = btn[catIdx]; b.set2ndName(keyNames(mapKey, devConf.device())); - b.compile2nd(); + b.place2nd(); } -bool ButtonConfigView::inputEvent(const Input::Event &e) +bool ButtonConfigView::inputEvent(const Input::Event& e, ViewInputEventParams) { if(e.keyEvent() && e.keyEvent()->pushed(Input::DefaultKey::LEFT) && selected >= resetItemsSize) { @@ -171,7 +171,7 @@ void ButtonConfigView::updateKeyNames(const KeyConfig &conf) for(auto &&[i, key]: enumerate(cat.keys)) { btn[i].set2ndName(keyNames(conf.get(key), devConf.device())); - btn[i].compile2nd(); + btn[i].place2nd(); } } @@ -186,7 +186,7 @@ ButtonConfigSetView::ButtonConfigSetView(ViewAttachParams attach, rootIMView{rootIMView}, actionStr{actionName} {} -bool ButtonConfigSetView::pointerUIIsInit() +bool ButtonConfigSetView::pointerUIIsInit() const { return unbindB.x != unbindB.x2; } @@ -224,7 +224,7 @@ void ButtonConfigSetView::place() } } -bool ButtonConfigSetView::inputEvent(const Input::Event &e) +bool ButtonConfigSetView::inputEvent(const Input::Event& e, ViewInputEventParams) { return e.visit(overloaded { @@ -311,7 +311,7 @@ void ButtonConfigSetView::finalize() onSet(mappedKeys); } -void ButtonConfigSetView::draw(Gfx::RendererCommands &__restrict__ cmds) +void ButtonConfigSetView::draw(Gfx::RendererCommands&__restrict__ cmds, ViewDrawParams) const { using namespace IG::Gfx; auto &basicEffect = cmds.basicEffect(); diff --git a/EmuFramework/src/gui/Cheats.cc b/EmuFramework/src/gui/Cheats.cc index 0fa3de9f6..a2272ead5 100644 --- a/EmuFramework/src/gui/Cheats.cc +++ b/EmuFramework/src/gui/Cheats.cc @@ -27,7 +27,7 @@ BaseCheatsView::BaseCheatsView(ViewAttachParams attach): attach, [this](ItemMessage msg) -> ItemReply { - return visit(overloaded + return msg.visit(overloaded { [&](const ItemsMessage &m) -> ItemReply { return 1 + cheat.size(); }, [&](const GetItemMessage &m) -> ItemReply @@ -37,7 +37,7 @@ BaseCheatsView::BaseCheatsView(ViewAttachParams attach): else return &cheat[m.idx - 1]; }, - }, msg); + }); } }, edit diff --git a/EmuFramework/src/gui/CreditsView.cc b/EmuFramework/src/gui/CreditsView.cc index 7f3d218fc..fa15e7045 100644 --- a/EmuFramework/src/gui/CreditsView.cc +++ b/EmuFramework/src/gui/CreditsView.cc @@ -45,7 +45,7 @@ void CreditsView::prepareDraw() text.makeGlyphs(); } -void CreditsView::draw(Gfx::RendererCommands &__restrict__ cmds) +void CreditsView::draw(Gfx::RendererCommands&__restrict__ cmds, ViewDrawParams) const { using namespace IG::Gfx; cmds.basicEffect().enableAlphaTexture(cmds); @@ -57,7 +57,7 @@ void CreditsView::place() text.compile({.alignment = Gfx::TextAlignment::center}); } -bool CreditsView::inputEvent(const Input::Event &e) +bool CreditsView::inputEvent(const Input::Event& e, ViewInputEventParams) { if(e.visit(overloaded { diff --git a/EmuFramework/src/gui/EmuInputView.cc b/EmuFramework/src/gui/EmuInputView.cc index 206c6938a..c56333a87 100644 --- a/EmuFramework/src/gui/EmuInputView.cc +++ b/EmuFramework/src/gui/EmuInputView.cc @@ -36,7 +36,7 @@ EmuInputView::EmuInputView(ViewAttachParams attach, VController &vCtrl, EmuVideo vController{&vCtrl}, videoLayer{&videoLayer} {} -void EmuInputView::draw(Gfx::RendererCommands &__restrict__ cmds) +void EmuInputView::draw(Gfx::RendererCommands&__restrict__ cmds, ViewDrawParams) const { vController->draw(cmds); } @@ -73,7 +73,7 @@ void EmuInputView::updateRunSpeed(AltSpeedMode mode) app().setRunSpeed(speedToggleActive ? app().altSpeedAsDouble(mode) : 1.); } -bool EmuInputView::inputEvent(const Input::Event &e) +bool EmuInputView::inputEvent(const Input::Event& e, ViewInputEventParams) { return e.visit(overloaded { diff --git a/EmuFramework/src/gui/EmuView.cc b/EmuFramework/src/gui/EmuView.cc index 8d211afc3..b87581856 100644 --- a/EmuFramework/src/gui/EmuView.cc +++ b/EmuFramework/src/gui/EmuView.cc @@ -39,7 +39,7 @@ void EmuView::prepareDraw() #endif } -void EmuView::draw(Gfx::RendererCommands &__restrict__ cmds) +void EmuView::draw(Gfx::RendererCommands&__restrict__ cmds, ViewDrawParams) const { using namespace IG::Gfx; if(layer && system().isStarted()) @@ -108,11 +108,6 @@ void EmuView::placeFrameTimeStats() }); } -bool EmuView::inputEvent(const Input::Event &e) -{ - return false; -} - void EmuView::updateFrameTimeStats(FrameTimeStats stats, SteadyClockTimePoint currentFrameTimestamp) { auto screenFrameTime = duration_cast(screen()->frameTime()); diff --git a/EmuFramework/src/gui/EmuViewController.cc b/EmuFramework/src/gui/EmuViewController.cc index a696d2cb6..90d11ecd6 100644 --- a/EmuFramework/src/gui/EmuViewController.cc +++ b/EmuFramework/src/gui/EmuViewController.cc @@ -85,7 +85,7 @@ static bool shouldExitFromViewRootWithoutPrompt(const Input::KeyEvent &e) EmuMenuViewStack::EmuMenuViewStack(ViewAttachParams attach, EmuApp &app): ViewStack(attach), emuAppPtr{&app} {} -bool EmuMenuViewStack::inputEvent(const Input::Event &e) +bool EmuMenuViewStack::inputEvent(const Input::Event& e) { if(ViewStack::inputEvent(e)) { @@ -154,7 +154,7 @@ void EmuViewController::dismissView(int idx, bool refreshLayout) viewStack.dismissView(idx, showingEmulation ? false : refreshLayout); } -bool EmuViewController::inputEvent(const Input::Event &e) +bool EmuViewController::inputEvent(const Input::Event& e) { if(showingEmulation) { diff --git a/EmuFramework/src/gui/FilePathOptionView.cc b/EmuFramework/src/gui/FilePathOptionView.cc index c1836a2e5..117d4fb14 100644 --- a/EmuFramework/src/gui/FilePathOptionView.cc +++ b/EmuFramework/src/gui/FilePathOptionView.cc @@ -70,7 +70,7 @@ FilePathOptionView::FilePathOptionView(ViewAttachParams attach, bool customMenu) auto fPicker = makeView(FSPicker::Mode::DIR, EmuSystem::NameFilterFunc{}, e); auto userSavePath = system().userSaveDirectory(); fPicker->setPath(userSavePath.size() && userSavePath != optionSavePathDefaultToken ? userSavePath - : app().contentSearchPath(), e); + : app().contentSearchPath, e); fPicker->setOnSelectPath( [this](FSPicker &picker, CStringView path, std::string_view displayName, const Input::Event &e) { diff --git a/EmuFramework/src/gui/FilePicker.cc b/EmuFramework/src/gui/FilePicker.cc index d305a96a5..d485ecf1f 100644 --- a/EmuFramework/src/gui/FilePicker.cc +++ b/EmuFramework/src/gui/FilePicker.cc @@ -64,11 +64,11 @@ std::unique_ptr FilePicker::forBenchmarking(ViewAttachParams attach, auto &app = EmuApp::get(attach.appContext()); auto mode = singleDir ? FSPicker::Mode::FILE_IN_DIR : FSPicker::Mode::FILE; auto picker = std::make_unique(attach, app, mode, EmuSystem::defaultFsFilter, e); - picker->setPath(app.contentSearchPath(), e); + picker->setPath(app.contentSearchPath, e); picker->setOnChangePath( [&app](FSPicker &picker, const Input::Event &) { - app.setContentSearchPath(picker.path()); + app.contentSearchPath = picker.path(); }); picker->setOnSelectPath( [&app](FSPicker &picker, CStringView path, std::string_view displayName, const Input::Event &e) @@ -89,11 +89,11 @@ std::unique_ptr FilePicker::forLoading(ViewAttachParams attach, cons auto &app = EmuApp::get(attach.appContext()); auto mode = singleDir ? FSPicker::Mode::FILE_IN_DIR : FSPicker::Mode::FILE; auto picker = std::make_unique(attach, app, mode, EmuSystem::defaultFsFilter, e); - picker->setPath(app.contentSearchPath(), e); + picker->setPath(app.contentSearchPath, e); picker->setOnChangePath( [&app](FSPicker &picker, const Input::Event &) { - app.setContentSearchPath(picker.path()); + app.contentSearchPath = picker.path(); }); picker->setOnSelectPath( [=, &app](FSPicker &picker, CStringView path, std::string_view displayName, const Input::Event &e) @@ -119,7 +119,7 @@ std::unique_ptr FilePicker::forMediaCreation(ViewAttachParams attach auto &app = EmuApp::get(attach.appContext()); auto mode = FSPicker::Mode::DIR; auto picker = std::make_unique(attach, app, mode, EmuSystem::NameFilterFunc{}, e); - picker->setPath(app.contentSearchPath(), e); + picker->setPath(app.contentSearchPath, e); return picker; } diff --git a/EmuFramework/src/gui/FrameTimingView.cc b/EmuFramework/src/gui/FrameTimingView.cc index 097aa9c92..bc01f532e 100644 --- a/EmuFramework/src/gui/FrameTimingView.cc +++ b/EmuFramework/src/gui/FrameTimingView.cc @@ -66,7 +66,7 @@ class DetectFrameRateView final: public View, public EmuAppHelper fpsText.compile(); } - bool inputEvent(const Input::Event &e) final + bool inputEvent(const Input::Event& e, ViewInputEventParams) final { if(e.keyEvent() && e.keyEvent()->pushed(Input::DefaultKey::CANCEL)) { @@ -77,7 +77,7 @@ class DetectFrameRateView final: public View, public EmuAppHelper return false; } - void draw(Gfx::RendererCommands &__restrict__ cmds) final + void draw(Gfx::RendererCommands&__restrict__ cmds, ViewDrawParams) const final { using namespace IG::Gfx; cmds.basicEffect().enableAlphaTexture(cmds); diff --git a/EmuFramework/src/gui/InputManagerView.cc b/EmuFramework/src/gui/InputManagerView.cc index d65c18479..13856d2c3 100644 --- a/EmuFramework/src/gui/InputManagerView.cc +++ b/EmuFramework/src/gui/InputManagerView.cc @@ -51,7 +51,7 @@ void IdentInputDeviceView::place() text.compile({.maxLineSize = int(viewRect().xSize() * 0.95f)}); } -bool IdentInputDeviceView::inputEvent(const Input::Event &e) +bool IdentInputDeviceView::inputEvent(const Input::Event& e, ViewInputEventParams) { return e.visit(overloaded { @@ -78,7 +78,7 @@ bool IdentInputDeviceView::inputEvent(const Input::Event &e) }); } -void IdentInputDeviceView::draw(Gfx::RendererCommands &__restrict__ cmds) +void IdentInputDeviceView::draw(Gfx::RendererCommands&__restrict__ cmds, ViewDrawParams) const { using namespace IG::Gfx; auto &basicEffect = cmds.basicEffect(); diff --git a/EmuFramework/src/gui/LoadProgressView.cc b/EmuFramework/src/gui/LoadProgressView.cc index 064ef521b..a7cae2d36 100644 --- a/EmuFramework/src/gui/LoadProgressView.cc +++ b/EmuFramework/src/gui/LoadProgressView.cc @@ -127,12 +127,7 @@ void LoadProgressView::place() updateProgressRect(); } -bool LoadProgressView::inputEvent(const Input::Event &e) -{ - return true; -} - -void LoadProgressView::draw(Gfx::RendererCommands &__restrict__ cmds) +void LoadProgressView::draw(Gfx::RendererCommands&__restrict__ cmds, ViewDrawParams) const { if(!text.isVisible()) return; diff --git a/EmuFramework/src/gui/MainMenuView.cc b/EmuFramework/src/gui/MainMenuView.cc index 0684e91bb..c368e2523 100644 --- a/EmuFramework/src/gui/MainMenuView.cc +++ b/EmuFramework/src/gui/MainMenuView.cc @@ -346,11 +346,11 @@ OptionCategoryView::OptionCategoryView(ViewAttachParams attach): attach, [this](ItemMessage msg) -> ItemReply { - return visit(overloaded + return msg.visit(overloaded { [&](const ItemsMessage &m) -> ItemReply { return EmuApp::hasGooglePlayStoreFeatures() ? std::size(subConfig) : std::size(subConfig)-1; }, [&](const GetItemMessage &m) -> ItemReply { return &subConfig[m.idx]; }, - }, msg); + }); } }, subConfig diff --git a/EmuFramework/src/gui/PlaceVControlsView.cc b/EmuFramework/src/gui/PlaceVControlsView.cc index 04d08ec03..7018a78ee 100644 --- a/EmuFramework/src/gui/PlaceVControlsView.cc +++ b/EmuFramework/src/gui/PlaceVControlsView.cc @@ -82,7 +82,7 @@ void PlaceVControlsView::place() gridIdxs.reset(2 + hLines + vLines); } -bool PlaceVControlsView::inputEvent(const Input::Event &e) +bool PlaceVControlsView::inputEvent(const Input::Event& e, ViewInputEventParams) { return e.visit(overloaded { @@ -173,7 +173,7 @@ bool PlaceVControlsView::inputEvent(const Input::Event &e) }); } -void PlaceVControlsView::draw(Gfx::RendererCommands &__restrict__ cmds) +void PlaceVControlsView::draw(Gfx::RendererCommands &__restrict__ cmds, ViewDrawParams) const { using namespace IG::Gfx; cmds.setColor({.5, .5, .5}); diff --git a/EmuFramework/src/gui/PlaceVControlsView.hh b/EmuFramework/src/gui/PlaceVControlsView.hh index ff91ca944..de64b1c23 100644 --- a/EmuFramework/src/gui/PlaceVControlsView.hh +++ b/EmuFramework/src/gui/PlaceVControlsView.hh @@ -35,8 +35,8 @@ public: PlaceVControlsView(ViewAttachParams attach, VController &vController); ~PlaceVControlsView() final; void place() final; - bool inputEvent(const Input::Event &e) final; - void draw(Gfx::RendererCommands &__restrict__ cmds) final; + bool inputEvent(const Input::Event&, ViewInputEventParams p = {}) final; + void draw(Gfx::RendererCommands &__restrict__ cmds, ViewDrawParams p = {}) const final; void onShow() final; private: diff --git a/EmuFramework/src/gui/PlaceVideoView.cc b/EmuFramework/src/gui/PlaceVideoView.cc index 059c884eb..e920087d0 100644 --- a/EmuFramework/src/gui/PlaceVideoView.cc +++ b/EmuFramework/src/gui/PlaceVideoView.cc @@ -63,7 +63,7 @@ void PlaceVideoView::place() Quad{{.bounds = resetBounds.as()}}.write(map, 3); } -bool PlaceVideoView::inputEvent(const Input::Event &e) +bool PlaceVideoView::inputEvent(const Input::Event& e, ViewInputEventParams) { return e.visit(overloaded { @@ -153,7 +153,7 @@ bool PlaceVideoView::inputEvent(const Input::Event &e) }); } -void PlaceVideoView::draw(Gfx::RendererCommands &__restrict__ cmds) +void PlaceVideoView::draw(Gfx::RendererCommands&__restrict__ cmds, ViewDrawParams) const { using namespace IG::Gfx; vController.draw(cmds, true); diff --git a/EmuFramework/src/gui/PlaceVideoView.hh b/EmuFramework/src/gui/PlaceVideoView.hh index 5a7be76c1..730d63ecc 100644 --- a/EmuFramework/src/gui/PlaceVideoView.hh +++ b/EmuFramework/src/gui/PlaceVideoView.hh @@ -35,8 +35,8 @@ public: PlaceVideoView(ViewAttachParams, EmuVideoLayer &, VController &); ~PlaceVideoView() final; void place() final; - bool inputEvent(const Input::Event &e) final; - void draw(Gfx::RendererCommands &__restrict__) final; + bool inputEvent(const Input::Event& e, ViewInputEventParams p = {}) final; + void draw(Gfx::RendererCommands&__restrict__, ViewDrawParams p = {}) const final; void onShow() final; private: diff --git a/EmuFramework/src/gui/RecentContentView.cc b/EmuFramework/src/gui/RecentContentView.cc index b486b2af9..c52d8b11e 100644 --- a/EmuFramework/src/gui/RecentContentView.cc +++ b/EmuFramework/src/gui/RecentContentView.cc @@ -28,11 +28,11 @@ RecentContentView::RecentContentView(ViewAttachParams attach, RecentContent &rec "Recent Content", attach, [this](TableView::ItemMessage msg) { - return visit(overloaded + return msg.visit(overloaded { [&](const ItemsMessage &m) -> ItemReply { return 1 + recentItems.size(); }, [&](const GetItemMessage &m) -> ItemReply { return m.idx < recentItems.size() ? &recentItems[m.idx] : &clear; }, - }, msg); + }); } }, clear diff --git a/EmuFramework/src/gui/TouchConfigView.cc b/EmuFramework/src/gui/TouchConfigView.cc index de1049c9b..65c3ee110 100644 --- a/EmuFramework/src/gui/TouchConfigView.cc +++ b/EmuFramework/src/gui/TouchConfigView.cc @@ -216,7 +216,7 @@ class DPadElementConfigView : public TableView, public EmuAppHelper } } {} - void draw(Gfx::RendererCommands &__restrict__ cmds) final + void draw(Gfx::RendererCommands &__restrict__ cmds, ViewDrawParams) const final { vCtrl.draw(cmds, elem, true); TableView::draw(cmds); @@ -313,7 +313,7 @@ class ButtonElementConfigView : public TableView, public EmuAppHelper { btn.key.flags.turbo = item.flipBoolValue(*this); key.set2ndName(app().inputManager.toString(btn.key)); - key.compile2nd(); + key.place2nd(); onChange.callSafe(); } }, @@ -325,7 +325,7 @@ class ButtonElementConfigView : public TableView, public EmuAppHelper { btn.key.flags.toggle = item.flipBoolValue(*this); key.set2ndName(app().inputManager.toString(btn.key)); - key.compile2nd(); + key.place2nd(); onChange.callSafe(); } }, @@ -627,7 +627,7 @@ class ButtonGroupElementConfigView : public TableView, public EmuAppHelper reloadItems(); } - void draw(Gfx::RendererCommands &__restrict__ cmds) final + void draw(Gfx::RendererCommands &__restrict__ cmds, ViewDrawParams) const final { vCtrl.draw(cmds, elem, true); TableView::draw(cmds); @@ -736,7 +736,7 @@ class AddNewButtonView : public TableView, public EmuAppHelper } }; -void TouchConfigView::draw(Gfx::RendererCommands &__restrict__ cmds) +void TouchConfigView::draw(Gfx::RendererCommands &__restrict__ cmds, ViewDrawParams) const { vController.draw(cmds, true); TableView::draw(cmds); diff --git a/GBA.emu/src/main/Cheats.cc b/GBA.emu/src/main/Cheats.cc index d2dacbaa9..d8e54dbf8 100644 --- a/GBA.emu/src/main/Cheats.cc +++ b/GBA.emu/src/main/Cheats.cc @@ -155,7 +155,7 @@ EmuEditCheatListView::EmuEditCheatListView(ViewAttachParams attach): attach, [this](ItemMessage msg) -> ItemReply { - return visit(overloaded + return msg.visit(overloaded { [&](const ItemsMessage &m) -> ItemReply { return 2 + cheat.size(); }, [&](const GetItemMessage &m) -> ItemReply @@ -167,7 +167,7 @@ EmuEditCheatListView::EmuEditCheatListView(ViewAttachParams attach): default: return &cheat[m.idx - 2]; } }, - }, msg); + }); } }, addGS12CBCode diff --git a/GBC.emu/src/main/Cheats.cc b/GBC.emu/src/main/Cheats.cc index a7ede80a3..06ec29fb6 100644 --- a/GBC.emu/src/main/Cheats.cc +++ b/GBC.emu/src/main/Cheats.cc @@ -181,7 +181,7 @@ EmuEditCheatView::EmuEditCheatView(ViewAttachParams attach, GbcCheat &cheat_, Re writeCheatFile(system()); static_cast(app().system()).applyCheats(); ggCode.set2ndName(str); - ggCode.compile(); + ggCode.place(); postDraw(); return true; }); @@ -207,7 +207,7 @@ EmuEditCheatListView::EmuEditCheatListView(ViewAttachParams attach): attach, [this](ItemMessage msg) -> ItemReply { - return visit(overloaded + return msg.visit(overloaded { [&](const ItemsMessage &m) -> ItemReply { return 1 + cheat.size(); }, [&](const GetItemMessage &m) -> ItemReply @@ -218,7 +218,7 @@ EmuEditCheatListView::EmuEditCheatListView(ViewAttachParams attach): default: return &cheat[m.idx - 1]; } }, - }, msg); + }); } }, addGGGS diff --git a/MD.emu/src/main/Cheats.cc b/MD.emu/src/main/Cheats.cc index 92d181439..096d2f92b 100644 --- a/MD.emu/src/main/Cheats.cc +++ b/MD.emu/src/main/Cheats.cc @@ -535,7 +535,7 @@ EmuEditCheatView::EmuEditCheatView(ViewAttachParams attach, MdCheat &cheat_, Ref updateCheats(); writeCheatFile(system()); code.set2ndName(str); - code.compile(); + code.place(); postDraw(); return true; }); @@ -579,7 +579,7 @@ EmuEditCheatListView::EmuEditCheatListView(ViewAttachParams attach): attach, [this](ItemMessage msg) -> ItemReply { - return visit(overloaded + return msg.visit(overloaded { [&](const ItemsMessage &m) -> ItemReply { return 1 + cheat.size(); }, [&](const GetItemMessage &m) -> ItemReply @@ -590,7 +590,7 @@ EmuEditCheatListView::EmuEditCheatListView(ViewAttachParams attach): default: return &cheat[m.idx - 1]; } }, - }, msg); + }); } }, addCode diff --git a/MSX.emu/src/main/EmuMenuViews.cc b/MSX.emu/src/main/EmuMenuViews.cc index 3bc26a86d..7a9d7f364 100644 --- a/MSX.emu/src/main/EmuMenuViews.cc +++ b/MSX.emu/src/main/EmuMenuViews.cc @@ -294,7 +294,7 @@ class MsxIOControlView : public TableView, public MainAppHelper { hdName[slot] = name; updateHDText(slot); - hdSlot[slot].compile(); + hdSlot[slot].place(); } void addHDFilePickerView(Input::Event e, uint8_t slot, bool dismissPreviousView) @@ -362,7 +362,7 @@ class MsxIOControlView : public TableView, public MainAppHelper { system().cartName[slot] = name; updateROMText(slot); - romSlot[slot].compile(); + romSlot[slot].place(); updateHDStatusFromCartSlot(slot); } @@ -444,7 +444,7 @@ class MsxIOControlView : public TableView, public MainAppHelper { system().diskName[slot] = name; updateDiskText(slot); - diskSlot[slot].compile(); + diskSlot[slot].place(); } void addDiskFilePickerView(Input::Event e, uint8_t slot, bool dismissPreviousView) diff --git a/NEO.emu/src/main/EmuMenuViews.cc b/NEO.emu/src/main/EmuMenuViews.cc index fad9a68fa..0ac4a49d7 100644 --- a/NEO.emu/src/main/EmuMenuViews.cc +++ b/NEO.emu/src/main/EmuMenuViews.cc @@ -454,7 +454,7 @@ constexpr RomListEntry romlist[] static FS::PathString gameFilePath(EmuApp &app, std::string_view name) { - auto basePath = app.contentSearchPath(name); + auto basePath = app.inContentSearchPath(name); auto ctx = app.appContext(); if(auto zipPath = basePath + ".zip"; ctx.fileUriExists(zipPath)) @@ -506,7 +506,7 @@ class GameListView : public TableView, public MainAppHelper fileList.reserve(4095); // avoid initial small re-allocations try { - ctx.forEachInDirectoryUri(app().contentSearchPath(), + ctx.forEachInDirectoryUri(app().contentSearchPath, [&](auto &entry) { if(entry.type() == FS::file_type::directory) diff --git a/NES.emu/src/fceu/asm.cpp b/NES.emu/src/fceu/asm.cpp index 533bb0b16..79c155d8b 100644 --- a/NES.emu/src/fceu/asm.cpp +++ b/NES.emu/src/fceu/asm.cpp @@ -337,10 +337,8 @@ char *Disassemble(int addr, uint8 *opcode) { case 0xE1: chr = "SBC"; goto _indirectx; _indirectx: indirectX(tmp); - indReg = 'X'; - _indirect: - sb << chr << " (" << sb_addr(opcode[1], 2) << ',' << indReg << ") @ " << sb_addr(tmp) << " = " << sb_lit(GetMem(tmp)); + sb << chr << " (" << sb_addr(opcode[1], 2) << ",X) @ " << sb_addr(tmp) << " = " << sb_lit(GetMem(tmp)); break; //Zero Page @@ -445,9 +443,9 @@ char *Disassemble(int addr, uint8 *opcode) { case 0xF1: chr = "SBC"; goto _indirecty; _indirecty: indirectY(tmp); - indReg = 'Y'; - goto _indirect; + sb << chr << " (" << sb_addr(opcode[1], 2) << "),Y @ " << sb_addr(tmp) << " = " << sb_lit(GetMem(tmp)); + break; //Zero Page,X case 0x15: chr = "ORA"; goto _zeropagex; diff --git a/NES.emu/src/fceu/boards/mmc3.cpp b/NES.emu/src/fceu/boards/mmc3.cpp index 64ad1cd79..afb399689 100644 --- a/NES.emu/src/fceu/boards/mmc3.cpp +++ b/NES.emu/src/fceu/boards/mmc3.cpp @@ -363,8 +363,10 @@ static void M4Power(void) { void Mapper4_Init(CartInfo *info) { int ws = 8; - if ((info->CRC32 == 0x93991433 || info->CRC32 == 0xaf65aa84)) { - FCEU_printf("Low-G-Man can not work normally in the iNES format.\nThis game has been recognized by its CRC32 value, and the appropriate changes will be made so it will run.\nIf you wish to hack this game, you should use the UNIF format for your hack.\n\n"); + if (info->ines2) { + ws = (info->wram_size + info->battery_wram_size) / 1024; + } else if ((info->CRC32 == 0x93991433 || info->CRC32 == 0xaf65aa84)) { + FCEU_printf("Low-G-Man can not work normally in the iNES format.\nThis game has been recognized by its CRC32 value, and the appropriate changes will be made so it will run.\nIf you wish to hack this game, you should use the NES 2.0 format for your hack.\n\n"); ws = 0; } GenMMC3_Init(info, 512, 256, ws, info->battery); diff --git a/NES.emu/src/fceu/boards/unrom512.cpp b/NES.emu/src/fceu/boards/unrom512.cpp index f2599f3a4..b28ce7fcb 100644 --- a/NES.emu/src/fceu/boards/unrom512.cpp +++ b/NES.emu/src/fceu/boards/unrom512.cpp @@ -55,9 +55,9 @@ static void UNROM512_Sync() { chip = !flash_id_mode ? FLASH_CHIP : CFI_CHIP; else chip = ROM_CHIP; - setprg16r(chip, 0x8000, latche & 0b11111); + setprg16r(chip, 0x8000, latche); setprg16r(chip, 0xc000, ~0); - setchr8((latche >> 5) & 0b11); + setchr8(latche >> 5); setmirror(MI_0 + ((latche >> 7) & 1)); } diff --git a/NES.emu/src/fceu/cheat.cpp b/NES.emu/src/fceu/cheat.cpp index 8f3179eda..97590e4c3 100644 --- a/NES.emu/src/fceu/cheat.cpp +++ b/NES.emu/src/fceu/cheat.cpp @@ -58,6 +58,15 @@ void FCEU_CheatAddRAM(int s, uint32 A, uint8 *p) CheatRPtrs[AB+x]=p-A; } +// Cheat change event callback. Called whenever cheat map is changed or recalculated. +static void (*cheatsChangeEventCB)(void*) = nullptr; +static void* cheatsChangeEventUserData = nullptr; + +void FCEU_SetCheatChangeEventCallback( void (*func)(void*), void* userData ) +{ + cheatsChangeEventCB = func; + cheatsChangeEventUserData = userData; +} CHEATF_SUBFAST SubCheats[256]; uint32 numsubcheats = 0; @@ -132,6 +141,11 @@ void RebuildSubCheats(void) } FrozenAddressCount = numsubcheats; //Update the frozen address list + // Notify the system of a change + if (cheatsChangeEventCB != nullptr) + { + cheatsChangeEventCB( cheatsChangeEventUserData ); + } } void FCEU_PowerCheats() @@ -371,12 +385,15 @@ void FCEU_FlushGameCheats(FILE *override, int nosave, bool freeCheats) } -int FCEUI_AddCheat(const char *name, uint32 addr, uint8 val, int compare, int type) +int FCEUI_AddCheat(const char *name, uint32 addr, uint8 val, int compare, int type, int status, bool rebuild) { - AddCheatEntry(name, addr, val, compare, 1, type); + AddCheatEntry(name, addr, val, compare, status, type); savecheats = 1; - RebuildSubCheats(); + if (rebuild) + { + RebuildSubCheats(); + } return 1; } diff --git a/NES.emu/src/fceu/cheat.h b/NES.emu/src/fceu/cheat.h index 640662c43..fc7202531 100644 --- a/NES.emu/src/fceu/cheat.h +++ b/NES.emu/src/fceu/cheat.h @@ -33,6 +33,8 @@ extern int disableAutoLSCheats; int FCEU_DisableAllCheats(void); int FCEU_DeleteAllCheats(void); +void FCEU_SetCheatChangeEventCallback( void (*func)(void*) = nullptr, void* userData = nullptr ); + struct CHEATF_SUBFAST { uint16 addr; diff --git a/NES.emu/src/fceu/debug.cpp b/NES.emu/src/fceu/debug.cpp index fad9c6f6e..eef528e56 100644 --- a/NES.emu/src/fceu/debug.cpp +++ b/NES.emu/src/fceu/debug.cpp @@ -19,6 +19,14 @@ unsigned int debuggerPageSize = 14; int vblankScanLines = 0; //Used to calculate scanlines 240-261 (vblank) int vblankPixel = 0; //Used to calculate the pixels in vblank + +struct TraceInstructionCallback +{ + void (*func)(uint8 *opcode, int size) = nullptr; + TraceInstructionCallback* next = nullptr; +}; +static TraceInstructionCallback* traceInstructionCB = nullptr; + int offsetStringToInt(unsigned int type, const char* offsetBuffer, bool *conversionOk) { int offset = -1; @@ -989,5 +997,82 @@ void DebugCycle() if(debug_loggingCD) LogCDData(opcode, A, size); +#ifdef __WIN_DRIVER__ FCEUD_TraceInstruction(opcode, size); +#else + // Use callback pointer that can be null checked, this saves on the overhead + // of calling a function for every instruction when we aren't tracing. + if (traceInstructionCB != nullptr) + { + auto* cb = traceInstructionCB; + while (cb != nullptr) + { + cb->func(opcode, size); + cb = cb->next; + } + } +#endif } + +void* FCEUI_TraceInstructionRegister( void (*func)(uint8*,int) ) +{ + TraceInstructionCallback* cb = nullptr; + + if (traceInstructionCB == nullptr) + { + cb = traceInstructionCB = new TraceInstructionCallback(); + cb->func = func; + } + else + { + cb = traceInstructionCB; + + while (cb != nullptr) + { + if (cb->func == func) + { + // This function has already been registered, don't double add. + return nullptr; + } + if (cb->next == nullptr) + { + auto* newCB = new TraceInstructionCallback(); + newCB->func = func; + cb->next = newCB; + return newCB; + } + cb = cb->next; + } + } + return cb; +} + +bool FCEUI_TraceInstructionUnregisterHandle( void* handle ) +{ + TraceInstructionCallback* cb, *cb_prev, *cb_handle; + + cb_handle = static_cast(handle); + cb_prev = nullptr; + cb = traceInstructionCB; + + while (cb != nullptr) + { + if (cb == cb_handle) + { // Match we are going to remove from list and delete + if (cb_prev != nullptr) + { + cb_prev = cb->next; + } + else + { + traceInstructionCB = cb->next; + } + delete cb; + return true; + } + cb_prev = cb; + cb = cb->next; + } + return false; +} + diff --git a/NES.emu/src/fceu/debug.h b/NES.emu/src/fceu/debug.h index 708c12efc..f8805a32d 100644 --- a/NES.emu/src/fceu/debug.h +++ b/NES.emu/src/fceu/debug.h @@ -175,4 +175,7 @@ DebuggerState &FCEUI_Debugger(); int offsetStringToInt(unsigned int type, const char* offsetBuffer, bool *conversionOk = nullptr); unsigned int NewBreak(const char* name, int start, int end, unsigned int type, const char* condition, unsigned int num, bool enable); +void* FCEUI_TraceInstructionRegister( void (*func)(uint8*,int) ); +bool FCEUI_TraceInstructionUnregisterHandle( void* handle ); + #endif diff --git a/NES.emu/src/fceu/driver.h b/NES.emu/src/fceu/driver.h index 318ff76fa..b2c38aecf 100644 --- a/NES.emu/src/fceu/driver.h +++ b/NES.emu/src/fceu/driver.h @@ -206,7 +206,7 @@ void FCEU_DispMessage( __FCEU_PRINTF_FORMAT const char *format, int disppos, ... int FCEUI_DecodePAR(const char *code, int *a, int *v, int *c, int *type); int FCEUI_DecodeGG(const char *str, int *a, int *v, int *c); -int FCEUI_AddCheat(const char *name, uint32 addr, uint8 val, int compare, int type); +int FCEUI_AddCheat(const char *name, uint32 addr, uint8 val, int compare, int type, int status = 1, bool rebuild = true); int FCEUI_DelCheat(uint32 which); int FCEUI_ToggleCheat(uint32 which); int FCEUI_GlobalToggleCheat(int global_enable); diff --git a/NES.emu/src/fceu/fceu.cpp b/NES.emu/src/fceu/fceu.cpp index dfe716d17..5b29b171e 100644 --- a/NES.emu/src/fceu/fceu.cpp +++ b/NES.emu/src/fceu/fceu.cpp @@ -204,7 +204,7 @@ static void FCEU_CloseGame(void) FCEU_CloseGenie(); delete GameInfo; - GameInfo = NULL; + GameInfo = nullptr; currFrameCounter = 0; @@ -223,7 +223,7 @@ static void FCEU_CloseGame(void) uint64 timestampbase; -FCEUGI *GameInfo = NULL; +FCEUGI *GameInfo = nullptr; void (*GameInterface)(GI h); void (*GameStateRestore)(int version); @@ -288,8 +288,8 @@ void FlushGenieRW(void) { } free(AReadG); free(BWriteG); - AReadG = NULL; - BWriteG = NULL; + AReadG = nullptr; + BWriteG = nullptr; RWWrap = 0; } } @@ -355,7 +355,7 @@ static void AllocBuffers() { static void FreeBuffers() { FCEU_free(RAM); - RAM = NULL; + RAM = nullptr; } //------ @@ -382,14 +382,14 @@ void ResetGameLoaded(void) { if (GameInfo) FCEU_CloseGame(); EmulationPaused = 0; //mbg 5/8/08 - loading games while paused was bad news. maybe this fixes it GameStateRestore = 0; - PPU_hook = NULL; - GameHBIRQHook = NULL; - FFCEUX_PPURead = NULL; - FFCEUX_PPUWrite = NULL; + PPU_hook = nullptr; + GameHBIRQHook = nullptr; + FFCEUX_PPURead = nullptr; + FFCEUX_PPUWrite = nullptr; if (GameExpSound.Kill) GameExpSound.Kill(); memset(&GameExpSound, 0, sizeof(GameExpSound)); - MapIRQHook = NULL; + MapIRQHook = nullptr; MMC5Hack = 0; PEC586Hack = 0; QTAIHack = 0; @@ -458,6 +458,7 @@ FCEUGI *FCEUI_LoadGameWithFileVirtual(FCEUFILE *fp, const char *name, int Overwr if (fp->archiveFilename != "") GameInfo->archiveFilename = fp->archiveFilename; GameInfo->archiveCount = fp->archiveCount; + GameInfo->archiveIndex = fp->archiveIndex; GameInfo->soundchan = 0; GameInfo->soundrate = 0; @@ -1329,7 +1330,7 @@ void UpdateAutosave(void) { FCEUSS_Save(f, false); AutoSS = true; //Flag that an auto-savestate was made free(f); - f = NULL; + f = nullptr; AutosaveStatus[AutosaveIndex] = 1; } } @@ -1343,7 +1344,7 @@ void FCEUI_RewindToLastAutosave(void) { f = strdup(FCEU_MakeFName(FCEUMKF_AUTOSTATE, AutosaveIndex, 0).c_str()); FCEUSS_Load(f); free(f); - f = NULL; + f = nullptr; //Set pointer to previous available slot if (AutosaveStatus[(AutosaveIndex + AutosaveQty - 1) % AutosaveQty] == 1) { diff --git a/NES.emu/src/fceu/git.h b/NES.emu/src/fceu/git.h index 67e3c5f6e..611f984a5 100644 --- a/NES.emu/src/fceu/git.h +++ b/NES.emu/src/fceu/git.h @@ -153,26 +153,28 @@ inline const char* ESIFC_Name(ESIFC esifc) struct FCEUGI { std::string name; //Game name, UTF8 encoding - int mappernum{}; + int mappernum = 0; - EGIT type{}; - EGIV vidsys{}; //Current emulated video system; - ESI input[2]{}; //Desired input for emulated input ports 1 and 2; -1 for unknown desired input. - ESIFC inputfc{}; //Desired Famicom expansion port device. -1 for unknown desired input. - ESIS cspecial{}; //Special cart expansion: DIP switches, barcode reader, etc. - EGIPPU vs_ppu; //PPU type for Vs. System - EGIVS vs_type; //Vs. System type - uint8 vs_cswitch; // Switch first and second controllers for Vs. System + EGIT type = GIT_CART; + EGIV vidsys = GIV_USER; //Current emulated video system; + ESI input[2] = { SI_UNSET, SI_UNSET }; //Desired input for emulated input ports 1 and 2; -1 for unknown desired input. + ESIFC inputfc = SIFC_UNSET; //Desired Famicom expansion port device. -1 for unknown desired input. + ESIS cspecial = SIS_NONE; //Special cart expansion: DIP switches, barcode reader, etc. + EGIPPU vs_ppu = GIPPU_USER; //PPU type for Vs. System + EGIVS vs_type = EGIVS_NORMAL; //Vs. System type + uint8 vs_cswitch = SIS_NONE; // Switch first and second controllers for Vs. System - MD5DATA MD5{}; + MD5DATA MD5; //mbg 6/8/08 - ??? - int soundrate{}; //For Ogg Vorbis expansion sound wacky support. 0 for default. - int soundchan{}; //Number of sound channels. + int soundrate = 0; //For Ogg Vorbis expansion sound wacky support. 0 for default. + int soundchan = 0; //Number of sound channels. std::string filename; std::string archiveFilename; - int archiveCount{}; + int archiveCount = 0; // the number of files that were in the archive + int archiveIndex = -1; // the index of the file within the archive + bool loadedFromTmpFile = false; // Was loaded from temporary file, file most likely no longer exists }; #endif diff --git a/NES.emu/src/fceu/state.cpp b/NES.emu/src/fceu/state.cpp index 2f1c228d4..5109e5e95 100644 --- a/NES.emu/src/fceu/state.cpp +++ b/NES.emu/src/fceu/state.cpp @@ -63,6 +63,7 @@ using namespace std; static void (*SPreSave)(void) = NULL; static void (*SPostSave)(void) = NULL; +static void (*SPostLoad)(bool) = NULL; static int SaveStateStatus[10]; static int StateShow; @@ -640,6 +641,11 @@ int FCEUSS_LoadFP_old(EMUFILE* is, ENUM_SSLOADPARAMS params) return(x); } +#ifdef __QT_DRIVER__ +// Qt Driver NetPlay state load handler. This is to control state loading +// during netplay, only hosts can load states and clients can request loads. +bool NetPlayStateLoadReq(EMUFILE* is); +#endif bool FCEUSS_LoadFP(EMUFILE* is, ENUM_SSLOADPARAMS params) { @@ -666,6 +672,13 @@ bool FCEUSS_LoadFP(EMUFILE* is, ENUM_SSLOADPARAMS params) return ret; } +#ifdef __QT_DRIVER__ + if ( NetPlayStateLoadReq(is) ) + { + return false; + } +#endif + size_t totalsize = FCEU_de32lsb(header + 4); int stateversion = FCEU_de32lsb(header + 8); uint32_t comprlen = FCEU_de32lsb(header + 12); @@ -688,7 +701,8 @@ bool FCEUSS_LoadFP(EMUFILE* is, ENUM_SSLOADPARAMS params) int error = uncompress(memory_savestate.buf(), &uncomprlen, &compressed_buf[0], comprlen); if(error != Z_OK || uncomprlen != totalsize) return false; // we dont need to restore the backup here because we havent messed with the emulator state yet - } else + } + else { // the savestate is not compressed: just read from is to memory_savestate.vec is->fread(memory_savestate.buf(), totalsize); @@ -711,15 +725,25 @@ bool FCEUSS_LoadFP(EMUFILE* is, ENUM_SSLOADPARAMS params) FCEUPPU_LoadState(stateversion); FCEUSND_LoadState(stateversion); x=FCEUMOV_PostLoad(); - } else if (backup) + } + else if (backup) { msBackupSavestate.fseek(0,SEEK_SET); FCEUSS_LoadFP(&msBackupSavestate,SSLOADPARAM_NOBACKUP); } + // Post state load callback that is used to notify driver code that a new state load occurred. + if (SPostLoad != NULL) + { + SPostLoad(x); + } return x; } +void FCEUSS_SetLoadCallback( void (*cb)(bool) ) +{ + SPostLoad = cb; +} bool FCEUSS_Load(const char *fname, bool display_message) { diff --git a/NES.emu/src/fceu/state.h b/NES.emu/src/fceu/state.h index 91265d16f..7407a5797 100644 --- a/NES.emu/src/fceu/state.h +++ b/NES.emu/src/fceu/state.h @@ -28,6 +28,7 @@ enum ENUM_SSLOADPARAMS bool FCEUSS_Save(const char *, bool display_message=true); bool FCEUSS_Load(const char *, bool display_message=true); +void FCEUSS_SetLoadCallback( void (*cb)(bool) ); //zlib values: 0 (none) through 9 (max) or -1 (default) bool FCEUSS_SaveMS(EMUFILE* outstream, int compressionLevel); diff --git a/NES.emu/src/main/Cheats.cc b/NES.emu/src/main/Cheats.cc index 97554ea83..1902d6e6b 100644 --- a/NES.emu/src/main/Cheats.cc +++ b/NES.emu/src/main/Cheats.cc @@ -55,7 +55,7 @@ EmuEditCheatView::EmuEditCheatView(ViewAttachParams attach, unsigned cheatIdx, R u"", [this](ItemMessage msg) -> ItemReply { - return visit(overloaded + return msg.visit(overloaded { [&](const ItemsMessage &m) -> ItemReply { return type ? 3uz : 5uz; }, [&](const GetItemMessage &m) -> ItemReply @@ -81,7 +81,7 @@ EmuEditCheatView::EmuEditCheatView(ViewAttachParams attach, unsigned cheatIdx, R } } }, - }, msg); + }); }, [this](TextMenuItem &, View &, Input::Event) { @@ -116,7 +116,7 @@ EmuEditCheatView::EmuEditCheatView(ViewAttachParams attach, unsigned cheatIdx, R addrStr = a ? str : "0"; syncCheat(); addr.set2ndName(addrStr); - addr.compile(); + addr.place(); postDraw(); return true; }); @@ -143,7 +143,7 @@ EmuEditCheatView::EmuEditCheatView(ViewAttachParams attach, unsigned cheatIdx, R valueStr = a ? str : "0"; syncCheat(); value.set2ndName(valueStr); - value.compile(); + value.place(); postDraw(); return true; }); @@ -179,7 +179,7 @@ EmuEditCheatView::EmuEditCheatView(ViewAttachParams attach, unsigned cheatIdx, R comp.set2ndName(); } syncCheat(); - comp.compile(); + comp.place(); postDraw(); } view.dismiss(); @@ -205,7 +205,7 @@ EmuEditCheatView::EmuEditCheatView(ViewAttachParams attach, unsigned cheatIdx, R ggCodeStr = str; syncCheat(); ggCode.set2ndName(str); - ggCode.compile(); + ggCode.place(); postDraw(); return true; }); @@ -312,7 +312,7 @@ EmuEditCheatListView::EmuEditCheatListView(ViewAttachParams attach): attach, [this](ItemMessage msg) -> ItemReply { - return visit(overloaded + return msg.visit(overloaded { [&](const ItemsMessage &m) -> ItemReply { return 2 + cheat.size(); }, [&](const GetItemMessage &m) -> ItemReply @@ -324,7 +324,7 @@ EmuEditCheatListView::EmuEditCheatListView(ViewAttachParams attach): default: return &cheat[m.idx - 2]; } }, - }, msg); + }); } }, addGG diff --git a/NES.emu/src/main/EmuMenuViews.cc b/NES.emu/src/main/EmuMenuViews.cc index 462475d4b..ac2d5e88d 100644 --- a/NES.emu/src/main/EmuMenuViews.cc +++ b/NES.emu/src/main/EmuMenuViews.cc @@ -369,7 +369,7 @@ class CustomVideoOptionView : public VideoOptionView, public MainAppHelper dismissPrevious(); picker.dismiss(); }); - fPicker->setPath(app().contentSearchPath(), e); + fPicker->setPath(app().contentSearchPath, e); app().pushAndShowModalView(std::move(fPicker), e); return false; }}, diff --git a/Snes9x/src/main/Cheats.cc b/Snes9x/src/main/Cheats.cc index 23fd8389e..3f7628fbb 100644 --- a/Snes9x/src/main/Cheats.cc +++ b/Snes9x/src/main/Cheats.cc @@ -231,7 +231,7 @@ EmuEditCheatView::EmuEditCheatView(ViewAttachParams attach, int cheatIdx, Refres } writeCheatsFile(system()); addr.set2ndName(addrStr); - addr.compile(); + addr.place(); postDraw(); return true; }); @@ -266,7 +266,7 @@ EmuEditCheatView::EmuEditCheatView(ViewAttachParams attach, int cheatIdx, Refres } writeCheatsFile(system()); value.set2ndName(valueStr); - value.compile(); + value.place(); postDraw(); return true; }); @@ -322,7 +322,7 @@ EmuEditCheatView::EmuEditCheatView(ViewAttachParams attach, int cheatIdx, Refres } writeCheatsFile(system()); saved.set2ndName(savedStr); - saved.compile(); + saved.place(); postDraw(); } view.dismiss(); @@ -381,7 +381,7 @@ EmuEditCheatListView::EmuEditCheatListView(ViewAttachParams attach): attach, [this](ItemMessage msg) -> ItemReply { - return visit(overloaded + return msg.visit(overloaded { [&](const ItemsMessage &m) -> ItemReply { return 1 + cheat.size(); }, [&](const GetItemMessage &m) -> ItemReply @@ -392,7 +392,7 @@ EmuEditCheatListView::EmuEditCheatListView(ViewAttachParams attach): default: return &cheat[m.idx - 1]; } }, - }, msg); + }); } }, addCode diff --git a/Snes9x/src/main/S9XApi.cc b/Snes9x/src/main/S9XApi.cc index 8068e70cf..43b15f0a3 100755 --- a/Snes9x/src/main/S9XApi.cc +++ b/Snes9x/src/main/S9XApi.cc @@ -27,6 +27,7 @@ using namespace EmuEx; uint16 SSettings::DisplayColor{}; uint32 SSettings::SkipFrames{}; uint32 SSettings::TurboSkipFrames{}; +bool8 SSettings::StopEmulation{}; std::string SGFX::InfoString; uint32 SGFX::InfoStringTimeout{}; char SGFX::FrameDisplayString[256]{}; diff --git a/Snes9x/src/snes9x/cheats2.cpp b/Snes9x/src/snes9x/cheats2.cpp index 16dd99f98..01a18a55c 100644 --- a/Snes9x/src/snes9x/cheats2.cpp +++ b/Snes9x/src/snes9x/cheats2.cpp @@ -8,6 +8,7 @@ #include "cheats.h" #include "snes9x.h" #include "memmap.h" +#include #include
static inline uint8 S9xGetByteFree(uint32 Address) @@ -323,6 +324,8 @@ void S9xEnableCheat(SCheat &c) void S9xEnableCheatGroup(uint32 num) { + assert(num < Cheat.group.size()); + for (auto &c : Cheat.group[num].cheat) S9xEnableCheat(c); @@ -516,10 +519,14 @@ int S9xModifyCheatGroup(uint32 num, const std::string &name, const std::string & if (num >= Cheat.group.size()) return -1; + bool enabled = Cheat.group[num].enabled; S9xDisableCheatGroup(num); Cheat.group[num] = S9xCreateCheatGroup(name, cheat); + if (enabled) + S9xEnableCheatGroup(num); + return num; } diff --git a/Snes9x/src/snes9x/cpuexec.cpp b/Snes9x/src/snes9x/cpuexec.cpp index 5004446c0..f7cadedfb 100644 --- a/Snes9x/src/snes9x/cpuexec.cpp +++ b/Snes9x/src/snes9x/cpuexec.cpp @@ -144,6 +144,16 @@ void S9xMainLoop2 (void) Op = CPU.PCBase[Registers.PCw]; CPU.Cycles += CPU.MemSpeed; Opcodes = ICPU.S9xOpcodes; + + #ifndef NDEBUG + if (CPU.Cycles > 1000000) + { + Settings.StopEmulation = true; + CPU.Flags |= HALTED_FLAG; + S9xMessage(S9X_FATAL_ERROR, 0, "CPU is deadlocked"); + return; + } + #endif } else { diff --git a/Snes9x/src/snes9x/fxemu.cpp b/Snes9x/src/snes9x/fxemu.cpp index a6e4979c5..59bc0f7de 100644 --- a/Snes9x/src/snes9x/fxemu.cpp +++ b/Snes9x/src/snes9x/fxemu.cpp @@ -153,7 +153,7 @@ uint8 S9xGetSuperFX (uint16 address) void S9xSuperFXExec (void) { - if ((Memory.FillRAM[0x3000 + GSU_SFR] & FLG_G) && (Memory.FillRAM[0x3000 + GSU_SCMR] & 0x18) == 0x18) + if ((Memory.FillRAM[0x3000 + GSU_SFR] & FLG_G) && (Memory.FillRAM[0x3000 + GSU_SCMR] & 0x18) != 0) { FxEmulate((Memory.FillRAM[0x3000 + GSU_CLSR] & 1) ? SuperFX.speedPerLine2x : SuperFX.speedPerLine); @@ -350,29 +350,19 @@ static bool8 fx_checkStartAddress (void) { // Check if we start inside the cache if (GSU.bCacheActive && R15 >= GSU.vCacheBaseReg && R15 < (GSU.vCacheBaseReg + 512)) - return (TRUE); + return true; - /* - // Check if we're in an unused area - if (GSU.vPrgBankReg < 0x40 && R15 < 0x8000) - return (FALSE); - */ - - if (GSU.vPrgBankReg >= 0x60 && GSU.vPrgBankReg <= 0x6f) - return (FALSE); - if (GSU.vPrgBankReg >= 0x74) - return (FALSE); - - // Check if we're in RAM and the RAN flag is not set - if (GSU.vPrgBankReg >= 0x70 && GSU.vPrgBankReg <= 0x73 && !(SCMR & (1 << 3))) - return (FALSE); + if (SCMR & (1 << 4)) + { + if (GSU.vPrgBankReg <= 0x5f || GSU.vPrgBankReg >= 0x80) + return true; + } - // If not, we're in ROM, so check if the RON flag is set - if (!(SCMR & (1 << 4))) - return (FALSE); + if (GSU.vPrgBankReg <= 0x7f && (SCMR & (1 << 3))) + return true; - return (TRUE); + return false; } // Execute until the next stop instruction diff --git a/Snes9x/src/snes9x/gfx.cpp b/Snes9x/src/snes9x/gfx.cpp index 59368d831..552fa12ba 100644 --- a/Snes9x/src/snes9x/gfx.cpp +++ b/Snes9x/src/snes9x/gfx.cpp @@ -52,7 +52,7 @@ bool8 S9xGraphicsInit (void) GFX.ScreenBuffer.resize(MAX_SNES_WIDTH * (MAX_SNES_HEIGHT + 64)); GFX.Screen = &GFX.ScreenBuffer[GFX.RealPPL * 32]; - GFX.ZERO = (uint16 *) calloc(sizeof(uint16), 0x10000); + GFX.ZERO = (uint16 *) calloc(0x10000, sizeof(uint16)); GFX.SubScreen = (uint16 *) calloc(GFX.ScreenSize, sizeof(uint16)); GFX.ZBuffer = (uint8 *) calloc(GFX.ScreenSize, 1); GFX.SubZBuffer = (uint8 *) calloc(GFX.ScreenSize, 1); diff --git a/Snes9x/src/snes9x/memmap.cpp b/Snes9x/src/snes9x/memmap.cpp index 1e53eb060..9e3d84541 100644 --- a/Snes9x/src/snes9x/memmap.cpp +++ b/Snes9x/src/snes9x/memmap.cpp @@ -2884,10 +2884,10 @@ void CMemory::Map_SuperFXLoROMMap (void) if (CalculatedSize > 0x400000) { map_lorom(0x00, 0x3f, 0x8000, 0xffff, 0x200000); - map_lorom_offset(0x80, 0xbf, 0x8000, 0xffff, 0x200000, 0x200000); + map_lorom(0x80, 0xbf, 0x8000, 0xffff, 0x200000); map_hirom_offset(0x40, 0x5f, 0x0000, 0xffff, 0x200000, 0); - map_hirom_offset(0xc0, 0xff, 0x0000, 0xffff, CalculatedSize - 0x400000, 0x400000); + map_hirom_offset(0xc0, 0xff, 0x0000, 0xffff, CalculatedSize, 0); map_space(0x00, 0x3f, 0x6000, 0x7fff, SRAM - 0x6000); map_space(0x80, 0xbf, 0x6000, 0x7fff, SRAM - 0x6000); @@ -2897,10 +2897,10 @@ void CMemory::Map_SuperFXLoROMMap (void) else if (CalculatedSize > 0x200000) { map_lorom(0x00, 0x3f, 0x8000, 0xffff, 0x200000); - map_lorom_offset(0x80, 0xbf, 0x8000, 0xffff, CalculatedSize - 0x200000, 0x200000); + map_lorom(0x80, 0xbf, 0x8000, 0xffff, 0x200000); map_hirom_offset(0x40, 0x5f, 0x0000, 0xffff, 0x200000, 0); - map_hirom_offset(0xc0, 0xff, 0x0000, 0xffff, CalculatedSize - 0x200000, 0x200000); + map_hirom_offset(0xc0, 0xff, 0x0000, 0xffff, CalculatedSize, 0); map_space(0x00, 0x3f, 0x6000, 0x7fff, SRAM - 0x6000); map_space(0x80, 0xbf, 0x6000, 0x7fff, SRAM - 0x6000); diff --git a/Snes9x/src/snes9x/port.h b/Snes9x/src/snes9x/port.h index 734c2e13a..ddddb1f11 100644 --- a/Snes9x/src/snes9x/port.h +++ b/Snes9x/src/snes9x/port.h @@ -32,6 +32,7 @@ #define RIGHTSHIFT_int16_IS_SAR #define RIGHTSHIFT_int32_IS_SAR #ifndef __LIBRETRO__ + #endif //__LIBRETRO__ #endif @@ -124,6 +125,10 @@ typedef size_t pint; #define S9xDisplayString DisplayStringFromBottom #ifdef __WIN32__ +#if !defined(SNES9X_QT) && !defined(__LIBRETRO__) +void SetInfoDlgColor(unsigned char, unsigned char, unsigned char); +#define SET_UI_COLOR(r,g,b) SetInfoDlgColor(r,g,b) +#endif #ifndef snprintf #define snprintf _snprintf #endif diff --git a/Snes9x/src/snes9x/snes9x.h b/Snes9x/src/snes9x/snes9x.h index 46c206451..00c10e7eb 100644 --- a/Snes9x/src/snes9x/snes9x.h +++ b/Snes9x/src/snes9x/snes9x.h @@ -8,7 +8,7 @@ #define _SNES9X_H_ #ifndef VERSION -#define VERSION "1.62.3" +#define VERSION "1.63" #endif #include "port.h" @@ -279,7 +279,7 @@ struct SSettings static const bool8 ForcedPause = 0; static const bool8 Paused = 0; - static const bool8 StopEmulation = 0; + static bool8 StopEmulation; static uint32 SkipFrames; static uint32 TurboSkipFrames; diff --git a/imagine/bundle/all/src/xz/common.mk b/imagine/bundle/all/src/xz/common.mk index 8fed42928..43e40e35a 100644 --- a/imagine/bundle/all/src/xz/common.mk +++ b/imagine/bundle/all/src/xz/common.mk @@ -4,7 +4,7 @@ endif include $(buildSysPath)/imagineSDKPath.mk -xzVer := 5.6.1 +xzVer := 5.6.2 xzSrcDir := $(tempDir)/xz-$(xzVer) xzSrcArchive := xz-$(xzVer).tar.xz diff --git a/imagine/bundle/all/src/xz/xz-5.6.1.tar.xz b/imagine/bundle/all/src/xz/xz-5.6.1.tar.xz deleted file mode 100644 index 9d083cfaa..000000000 Binary files a/imagine/bundle/all/src/xz/xz-5.6.1.tar.xz and /dev/null differ diff --git a/imagine/bundle/all/src/xz/xz-5.6.2.tar.xz b/imagine/bundle/all/src/xz/xz-5.6.2.tar.xz new file mode 100644 index 000000000..7ef732d7f Binary files /dev/null and b/imagine/bundle/all/src/xz/xz-5.6.2.tar.xz differ diff --git a/imagine/include/imagine/base/BaseWindow.hh b/imagine/include/imagine/base/BaseWindow.hh index c4b803d1b..a96d44a2f 100644 --- a/imagine/include/imagine/base/BaseWindow.hh +++ b/imagine/include/imagine/base/BaseWindow.hh @@ -28,6 +28,13 @@ namespace IG { +class WindowEvent: public WindowEventVariant, public AddVisit +{ +public: + using WindowEventVariant::WindowEventVariant; + using AddVisit::visit; +}; + class BaseWindow { public: diff --git a/imagine/include/imagine/base/EGLContextBase.hh b/imagine/include/imagine/base/EGLContextBase.hh index 7f7ef964a..34893b8bd 100644 --- a/imagine/include/imagine/base/EGLContextBase.hh +++ b/imagine/include/imagine/base/EGLContextBase.hh @@ -31,6 +31,7 @@ namespace IG::GL { enum class API; +struct Version; } namespace IG @@ -38,8 +39,8 @@ namespace IG class GLDisplay; class GLDrawable; -class GLContextAttributes; -class GLBufferConfigAttributes; +struct GLContextAttributes; +struct GLBufferConfigAttributes; using NativeGLDrawable = EGLSurface; using NativeGLContext = EGLContext; @@ -134,7 +135,7 @@ public: constexpr EGLManager() = default; static const char *errorString(EGLint error); - static int makeRenderableType(GL::API, int majorVersion); + static int makeRenderableType(GL::API, GL::Version version); explicit operator bool() const { return (bool)dpy; } protected: diff --git a/imagine/include/imagine/base/GLContext.hh b/imagine/include/imagine/base/GLContext.hh index 4a6f86a55..301a0220b 100644 --- a/imagine/include/imagine/base/GLContext.hh +++ b/imagine/include/imagine/base/GLContext.hh @@ -34,7 +34,29 @@ namespace IG::GL { -enum class API {OPENGL, OPENGL_ES}; + +enum class API {OpenGL, OpenGLES}; + +struct Version +{ + int major{1}, minor{}; +}; + +#if defined CONFIG_OS_IOS || defined __ANDROID__ +constexpr auto defaultApi = IG::GL::API::OpenGLES; +#else +constexpr auto defaultApi = IG::GL::API::OpenGL; +#endif + +} + +namespace Config +{ +#if !defined NDEBUG && !defined __APPLE__ +constexpr bool OpenGLDebugContext = true; +#else +constexpr bool OpenGLDebugContext = false; +#endif } namespace IG @@ -46,9 +68,8 @@ class ApplicationContext; constexpr bool useEGLPlatformAPI = Config::envIsLinux && !Config::MACHINE_IS_PANDORA; -class GLBufferConfigAttributes +struct GLBufferConfigAttributes { -public: PixelFormat pixelFormat{}; bool useAlpha{}; bool useDepth{}; @@ -56,21 +77,21 @@ public: bool translucentWindow{}; }; -class GLContextAttributes +struct GLBufferRenderConfigAttributes { -public: - int majorVersion{1}; - int minorVersion{}; - bool glesApi{}; - bool debug{}; - bool noError{}; + GLBufferConfigAttributes bufferAttrs{}; + GL::Version version{}; + GL::API api{}; - constexpr GLContextAttributes() = default; + constexpr operator GLBufferConfigAttributes() const { return bufferAttrs; } +}; - constexpr GLContextAttributes(int majorVer, int minorVer, GL::API api): - majorVersion{majorVer}, - minorVersion{minorVer}, - glesApi{api == GL::API::OPENGL_ES} {} +struct GLContextAttributes +{ + GL::Version version{}; + GL::API api{}; + bool debug{}; + bool noError{}; }; enum class GLColorSpace : uint8_t @@ -79,9 +100,8 @@ enum class GLColorSpace : uint8_t SRGB }; -class GLDrawableAttributes +struct GLDrawableAttributes { -public: GLBufferConfig bufferConfig{}; GLColorSpace colorSpace{}; int wantedRenderBuffers{}; @@ -136,7 +156,9 @@ public: GLManager(NativeDisplayConnection, GL::API); GLDisplay display() const; GLDisplay getDefaultDisplay(NativeDisplayConnection) const; - std::optional makeBufferConfig(ApplicationContext, GLBufferConfigAttributes, GL::API, int majorVersion = 0) const; + std::optional tryBufferConfig(ApplicationContext, const GLBufferRenderConfigAttributes&) const; + GLBufferConfig makeBufferConfig(ApplicationContext, const GLBufferRenderConfigAttributes&) const; + GLBufferConfig makeBufferConfig(ApplicationContext, std::span) const; NativeWindowFormat nativeWindowFormat(ApplicationContext, GLBufferConfig) const; GLContext makeContext(GLContextAttributes, GLBufferConfig, NativeGLContext shareContext); GLContext makeContext(GLContextAttributes, GLBufferConfig); diff --git a/imagine/include/imagine/base/baseDefs.hh b/imagine/include/imagine/base/baseDefs.hh index 62a1d2b95..42b79d976 100644 --- a/imagine/include/imagine/base/baseDefs.hh +++ b/imagine/include/imagine/base/baseDefs.hh @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -266,10 +267,17 @@ struct FreeCachesEvent{bool running;}; // Sent when a Screen is connected/disconnected or its properties change struct ScreenChangeEvent{Screen &screen; ScreenChange change;}; -using ApplicationEvent = std::variant; -using OnApplicationEvent = DelegateFunc; +class ApplicationEvent: public ApplicationEventVariant, public AddVisit +{ +public: + using ApplicationEventVariant::ApplicationEventVariant; + using AddVisit::visit; +}; + +using OnApplicationEvent = DelegateFunc; using MainThreadMessageDelegate = DelegateFunc; using ResumeDelegate = DelegateFunc; using ExitDelegate = DelegateFunc; @@ -303,12 +311,14 @@ struct DismissRequestEvent{}; // Sent when the window is dismissed struct DismissEvent{}; -using WindowEvent = std::variant; -using OnWindowEvent = DelegateFunc; -using WindowInitDelegate = DelegateFunc; +class WindowEvent; + +using OnWindowEvent = DelegateFunc; +using WindowInitDelegate = DelegateFunc; using PollEventDelegate = DelegateFunc; diff --git a/imagine/include/imagine/base/iphone/IOSGL.hh b/imagine/include/imagine/base/iphone/IOSGL.hh index 211986280..567e113b5 100644 --- a/imagine/include/imagine/base/iphone/IOSGL.hh +++ b/imagine/include/imagine/base/iphone/IOSGL.hh @@ -31,7 +31,7 @@ namespace IG class GLDisplay; class GLContext; -class GLContextAttributes; +struct GLContextAttributes; class GLManagerImpl { diff --git a/imagine/include/imagine/gfx/opengl/GLRenderer.hh b/imagine/include/imagine/gfx/opengl/GLRenderer.hh index 07234874f..94f5847c1 100644 --- a/imagine/include/imagine/gfx/opengl/GLRenderer.hh +++ b/imagine/include/imagine/gfx/opengl/GLRenderer.hh @@ -124,13 +124,8 @@ public: #ifdef __ANDROID__ void (GL_APIENTRYP glEGLImageTargetTexStorageEXT)(GLenum target, GLeglImageOES image, const GLint* attrib_list){}; #endif - #if defined CONFIG_GFX_OPENGL_DEBUG_CONTEXT && defined CONFIG_GFX_OPENGL_ES - void GL_APIENTRY (*glDebugMessageCallback)(GLDEBUGPROCKHR callback, const void *userParam){}; - static constexpr auto DEBUG_OUTPUT = GL_DEBUG_OUTPUT_KHR; - #elif defined CONFIG_GFX_OPENGL_DEBUG_CONTEXT - void GL_APIENTRY (*glDebugMessageCallback)(GLDEBUGPROC callback, const void *userParam){}; - static constexpr auto DEBUG_OUTPUT = GL_DEBUG_OUTPUT; - #endif + using GLDebugMessageCallback = void (GL_APIENTRY *)(GLDEBUGPROC callback, const void *userParam); + ConditionalMember glDebugMessageCallback{}; ConditionalMemberOr<(bool)Config::Gfx::OPENGL_ES, GLenum, GL_RED> luminanceFormat{GL_LUMINANCE}; ConditionalMemberOr<(bool)Config::Gfx::OPENGL_ES, GLenum, GL_R8> luminanceInternalFormat{GL_LUMINANCE8}; ConditionalMemberOr<(bool)Config::Gfx::OPENGL_ES, GLenum, GL_RG> luminanceAlphaFormat{GL_LUMINANCE_ALPHA}; @@ -147,7 +142,7 @@ public: ConditionalMemberOr<(bool)Config::Gfx::OPENGL_ES, bool, true> hasPBOFuncs{}; ConditionalMemberOr<(bool)Config::Gfx::OPENGL_ES, bool, false> useLegacyGLSL{true}; ConditionalMemberOr<(bool)Config::Gfx::OPENGL_ES, bool, true> hasSrgbWriteControl{}; - ConditionalMember hasDebugOutput{}; + ConditionalMember hasDebugOutput{}; ConditionalMember hasBufferStorage{}; ConditionalMember hasEGLImages{}; ConditionalMember hasExternalEGLImages{}; @@ -199,7 +194,6 @@ protected: void setupAppleFenceSync(); void setupEglFenceSync(std::string_view eglExtenstionStr); void checkExtensionString(std::string_view extStr); - void checkFullExtensionString(const char *fullExtStr); bool attachWindow(Window &, GLBufferConfig, GLColorSpace); NativeWindowFormat nativeWindowFormat(GLBufferConfig) const; bool initBasicEffect(); diff --git a/imagine/include/imagine/gfx/opengl/GLRendererTask.hh b/imagine/include/imagine/gfx/opengl/GLRendererTask.hh index abd0c835f..c125b76d5 100644 --- a/imagine/include/imagine/gfx/opengl/GLRendererTask.hh +++ b/imagine/include/imagine/gfx/opengl/GLRendererTask.hh @@ -81,7 +81,7 @@ protected: Renderer *r{}; ConditionalMember defaultFB{}; GLuint fbo = 0; - ConditionalMember debugEnabled{}; + ConditionalMember debugEnabled{}; void doPreDraw(Window &win, WindowDrawParams winParams, DrawParams ¶ms) const; void updateDrawable(Drawable, IRect viewportRect, int swapInterval); diff --git a/imagine/include/imagine/gfx/opengl/defs.hh b/imagine/include/imagine/gfx/opengl/defs.hh index e820c38d2..35b848cea 100644 --- a/imagine/include/imagine/gfx/opengl/defs.hh +++ b/imagine/include/imagine/gfx/opengl/defs.hh @@ -45,13 +45,6 @@ namespace Config static constexpr bool OPENGL_TEXTURE_TARGET_EXTERNAL = false; #endif - #if !defined NDEBUG && !defined __APPLE__ - #define CONFIG_GFX_OPENGL_DEBUG_CONTEXT - static constexpr bool OPENGL_DEBUG_CONTEXT = true; - #else - static constexpr bool OPENGL_DEBUG_CONTEXT = false; - #endif - #if defined CONFIG_OS_IOS static constexpr bool GLDRAWABLE_NEEDS_FRAMEBUFFER = true; #else @@ -62,51 +55,10 @@ namespace Config // Header Locations For Platform -#if defined CONFIG_OS_IOS -#import -#import -#elif defined CONFIG_BASE_MACOSX -#import -#import -#elif defined CONFIG_BASE_WIN32 -#include -#define GLEW_STATIC -#include -#include -#elif defined CONFIG_GFX_OPENGL_ES // Generic OpenGL ES headers -#define GL_GLEXT_PROTOTYPES -#include -#include -#undef GL_GLEXT_PROTOTYPES -#else // Generic OpenGL headers -#define GL_GLEXT_PROTOTYPES -#include -#include -#undef GL_GLEXT_PROTOTYPES -#endif - -// Symbol Re-mapping - #if defined CONFIG_GFX_OPENGL_ES - #ifndef GL_BGRA - #define GL_BGRA GL_BGRA_EXT - #endif - #ifndef GL_ALPHA8 - #define GL_ALPHA8 0x803C - #endif - #ifndef GL_LUMINANCE8 - #define GL_LUMINANCE8 0x8040 - #endif - #ifndef GL_LUMINANCE8_ALPHA8 - #define GL_LUMINANCE8_ALPHA8 0x8045 - #endif - #ifndef GL_SYNC_FLUSH_COMMANDS_BIT - #define GL_SYNC_FLUSH_COMMANDS_BIT 0x00000001 - #endif -#endif - -#ifndef GL_APIENTRY -#define GL_APIENTRY GLAPIENTRY +#include +#else +#include #endif namespace IG::Gfx diff --git a/imagine/include/imagine/gui/AlertView.hh b/imagine/include/imagine/gui/AlertView.hh index ff47d2807..950b9cd26 100644 --- a/imagine/include/imagine/gui/AlertView.hh +++ b/imagine/include/imagine/gui/AlertView.hh @@ -41,9 +41,9 @@ public: } { init(); } void place() override; - bool inputEvent(const Input::Event &) override; + bool inputEvent(const Input::Event&, ViewInputEventParams p = {}) override; void prepareDraw() override; - void draw(Gfx::RendererCommands &__restrict__) override; + void draw(Gfx::RendererCommands &__restrict__, ViewDrawParams p = {}) const override; void onAddedToController(ViewController *, const Input::Event &) override; void setLabel(UTF16Convertible auto &&label) { text.resetString(IG_forward(label)); } diff --git a/imagine/include/imagine/gui/FSPicker.hh b/imagine/include/imagine/gui/FSPicker.hh index aaf745fb9..38fb51486 100644 --- a/imagine/include/imagine/gui/FSPicker.hh +++ b/imagine/include/imagine/gui/FSPicker.hh @@ -65,9 +65,9 @@ public: FSPicker(ViewAttachParams attach, Gfx::TextureSpan backRes, Gfx::TextureSpan closeRes, FilterFunc filter = {}, Mode mode = Mode::FILE, Gfx::GlyphTextureSet *face = {}); void place() override; - bool inputEvent(const Input::Event &) override; + bool inputEvent(const Input::Event&, ViewInputEventParams p = {}) override; void prepareDraw() override; - void draw(Gfx::RendererCommands &__restrict__) override; + void draw(Gfx::RendererCommands &__restrict__, ViewDrawParams p = {}) const override; void onAddedToController(ViewController *, const Input::Event &) override; void setOnChangePath(OnChangePathDelegate); void setOnSelectPath(OnSelectPathDelegate); diff --git a/imagine/include/imagine/gui/MenuItem.hh b/imagine/include/imagine/gui/MenuItem.hh index 7cabc9ec3..350d783d2 100644 --- a/imagine/include/imagine/gui/MenuItem.hh +++ b/imagine/include/imagine/gui/MenuItem.hh @@ -122,9 +122,26 @@ struct MenuId constexpr operator Type() const { return val; } }; +struct MenuItemDrawAttrs +{ + WindowRect rect{}; + int xIndent{}; + Gfx::Color color{}; + _2DOrigin align{}; +}; + +struct MenuItemI +{ + virtual ~MenuItemI() = default; + virtual void place() = 0; + virtual void prepareDraw() = 0; + virtual void draw(Gfx::RendererCommands&__restrict__, MenuItemDrawAttrs a = {}) const = 0; + virtual bool inputEvent(const Input::Event&, ViewInputEventParams p = {}); +}; + constexpr MenuId defaultMenuId{std::numeric_limits::min()}; -class MenuItem +class MenuItem: public MenuItemI { public: struct Config @@ -142,16 +159,13 @@ public: id{conf.id}, t{attach.rendererTask, IG_forward(name), conf.face ?: &attach.viewManager.defaultFace} {} - MenuItem(MenuItem &&) = default; - MenuItem &operator=(MenuItem &&) = default; - virtual ~MenuItem() = default; - virtual void prepareDraw(); - virtual void draw(Gfx::RendererCommands &__restrict__, int xPos, int yPos, int xSize, int ySize, - int xIndent, _2DOrigin align, Gfx::Color) const; - virtual void compile(); + MenuItem(MenuItem&&) = default; + MenuItem &operator=(MenuItem&&) = default; + void prepareDraw() override; + void draw(Gfx::RendererCommands&__restrict__, MenuItemDrawAttrs) const override; + void place() override; int ySize() const; int xSize() const; - virtual bool select(View &, const Input::Event &) = 0; constexpr bool selectable() const { return flags.selectable; } constexpr void setSelectable(bool on) { flags.selectable = on; } constexpr bool active() const { return flags.active; } @@ -162,10 +176,10 @@ public: void compile(UTF16Convertible auto &&name) { t.resetString(IG_forward(name)); - compile(); + place(); } - void setName(UTF16Convertible auto &&name, Gfx::GlyphTextureSet *face = nullptr) + void setName(UTF16Convertible auto &&name, Gfx::GlyphTextureSet *face = {}) { t.resetString(IG_forward(name)); if(face) @@ -196,7 +210,7 @@ public: TextMenuItem(UTF16Convertible auto &&name, ViewAttachParams attach, Config conf): MenuItem{IG_forward(name), attach, conf} {} - bool select(View &parent, const Input::Event &e) override { return onSelect.callCopySafe(*this, parent, e); } + bool inputEvent(const Input::Event& e, ViewInputEventParams p) override; }; class TextHeadingMenuItem : public MenuItem @@ -211,8 +225,6 @@ public: { setSelectable(false); } - - bool select(View &, const Input::Event &) override { return true; } }; class BaseDualTextMenuItem : public MenuItem @@ -226,13 +238,11 @@ public: void set2ndName(UTF16Convertible auto &&name) { t2.resetString(IG_forward(name)); } void set2ndName() { t2.resetString(); } - void compile() override; - void compile2nd(); + void place() override; + void place2nd(); void prepareDraw() override; - void draw2ndText(Gfx::RendererCommands &, int xPos, int yPos, int xSize, int ySize, - int xIndent, _2DOrigin align, Gfx::Color) const; - void draw(Gfx::RendererCommands &__restrict__, int xPos, int yPos, int xSize, int ySize, - int xIndent, _2DOrigin align, Gfx::Color) const override; + void draw2ndText(Gfx::RendererCommands&__restrict__, MenuItemDrawAttrs) const; + void draw(Gfx::RendererCommands&__restrict__, MenuItemDrawAttrs) const override; protected: Gfx::Text t2; @@ -253,9 +263,8 @@ public: BaseDualTextMenuItem{IG_forward(name), IG_forward(name2), attach, conf}, onSelect{onSelect} {} - void draw(Gfx::RendererCommands &__restrict__, int xPos, int yPos, int xSize, int ySize, - int xIndent, _2DOrigin align, Gfx::Color) const override; - bool select(View &, const Input::Event &) override; + void draw(Gfx::RendererCommands&__restrict__, MenuItemDrawAttrs) const override; + bool inputEvent(const Input::Event&, ViewInputEventParams) override; }; @@ -296,9 +305,8 @@ public: bool setBoolValue(bool val); bool flipBoolValue(View &view); bool flipBoolValue(); - void draw(Gfx::RendererCommands &__restrict__, int xPos, int yPos, int xSize, int ySize, - int xIndent, _2DOrigin align, Gfx::Color) const override; - bool select(View &, const Input::Event &) override; + void draw(Gfx::RendererCommands&__restrict__, MenuItemDrawAttrs) const override; + bool inputEvent(const Input::Event&, ViewInputEventParams) override; protected: UTF16String offStr{u"Off"}, onStr{u"On"}; @@ -309,7 +317,13 @@ class MultiChoiceMenuItem : public BaseDualTextMenuItem public: struct ItemsMessage {const MultiChoiceMenuItem& item;}; struct GetItemMessage {const MultiChoiceMenuItem& item; size_t idx;}; - using ItemMessage = std::variant; + using ItemMessageVariant = std::variant; + class ItemMessage: public ItemMessageVariant, public AddVisit + { + public: + using ItemMessageVariant::ItemMessageVariant; + using AddVisit::visit; + }; using ItemReply = std::variant; using ItemSourceDelegate = MenuItemSourceDelegate; using SelectDelegate = DelegateFunc; @@ -372,9 +386,8 @@ public: } } - void draw(Gfx::RendererCommands &__restrict__, int xPos, int yPos, int xSize, int ySize, - int xIndent, _2DOrigin align, Gfx::Color) const override; - void compile() override; + void draw(Gfx::RendererCommands&__restrict__, MenuItemDrawAttrs) const override; + void place() override; int selected() const; size_t items() const; TextMenuItem& item(size_t idx) { return item(itemSrc, idx); } @@ -384,7 +397,7 @@ public: bool setSelected(MenuId); int cycleSelected(int offset, View &view); int cycleSelected(int offset); - bool select(View &, const Input::Event &) override; + bool inputEvent(const Input::Event&, ViewInputEventParams) override; std::unique_ptr makeTableView(ViewAttachParams attach); void defaultOnSelect(View &, const Input::Event &); void updateDisplayString(); diff --git a/imagine/include/imagine/gui/NavView.hh b/imagine/include/imagine/gui/NavView.hh index a004a4677..5d6a9446b 100644 --- a/imagine/include/imagine/gui/NavView.hh +++ b/imagine/include/imagine/gui/NavView.hh @@ -40,7 +40,7 @@ public: void setTitle(UTF16Convertible auto &&title) { text.resetString(IG_forward(title)); } void prepareDraw() override; void place() override; - bool inputEvent(const Input::Event &) override; + bool inputEvent(const Input::Event&, ViewInputEventParams p = {}) override; void clearSelection() override; virtual void showLeftBtn(bool show) = 0; virtual void showRightBtn(bool show) = 0; @@ -70,7 +70,7 @@ public: BasicNavView(ViewAttachParams attach, Gfx::GlyphTextureSet *face, Gfx::TextureSpan leftRes, Gfx::TextureSpan rightRes); void setBackImage(Gfx::TextureSpan img); void setBackgroundGradient(std::span gradStops); - void draw(Gfx::RendererCommands &__restrict__) override; + void draw(Gfx::RendererCommands &__restrict__, ViewDrawParams p = {}) const override; void place() override; void showLeftBtn(bool show) override; void showRightBtn(bool show) override; diff --git a/imagine/include/imagine/gui/ScrollView.hh b/imagine/include/imagine/gui/ScrollView.hh index cc3abe530..a49d6e551 100644 --- a/imagine/include/imagine/gui/ScrollView.hh +++ b/imagine/include/imagine/gui/ScrollView.hh @@ -64,7 +64,7 @@ protected: bool allowScrollWholeArea_{}; void setContentSize(WSize size); - void drawScrollContent(Gfx::RendererCommands &cmds); + void drawScrollContent(Gfx::RendererCommands &cmds) const; bool scrollInputEvent(const Input::MotionEvent &); void stopScrollAnimation(); }; diff --git a/imagine/include/imagine/gui/TableView.hh b/imagine/include/imagine/gui/TableView.hh index 2edfa3cd8..ec07d7009 100644 --- a/imagine/include/imagine/gui/TableView.hh +++ b/imagine/include/imagine/gui/TableView.hh @@ -21,6 +21,7 @@ #include #include #include +#include #include namespace IG::Input @@ -38,7 +39,13 @@ class TableView : public ScrollView public: struct ItemsMessage {const TableView& item;}; struct GetItemMessage {const TableView& item; size_t idx;}; - using ItemMessage = std::variant; + using ItemMessageVariant = std::variant; + class ItemMessage: public ItemMessageVariant, public AddVisit + { + public: + using ItemMessageVariant::ItemMessageVariant; + using AddVisit::visit; + }; using ItemReply = std::variant; using ItemSourceDelegate = MenuItemSourceDelegate; using SelectElementDelegate = DelegateFunc; @@ -52,19 +59,19 @@ public: TableView{UTF16String{}, attach, itemSrc} {} void prepareDraw() override; - void draw(Gfx::RendererCommands &__restrict__) override; + void draw(Gfx::RendererCommands &__restrict__, ViewDrawParams p = {}) const override; void place() override; void setScrollableIfNeeded(bool yes); void scrollToFocusRect(); void resetScroll(); - bool inputEvent(const Input::Event &) override; + bool inputEvent(const Input::Event&, ViewInputEventParams p = {}) override; void clearSelection() override; void onShow() override; void onHide() override; void onAddedToController(ViewController *, const Input::Event &) override; void setFocus(bool focused) override; void setOnSelectElement(SelectElementDelegate del); - MenuItem& item(size_t idx) { return item(itemSrc, idx); } + auto& item(this auto&& self, size_t idx) { return self.item(self.itemSrc, idx); } size_t cells() const; WSize cellSize() const; void highlightCell(int idx); @@ -95,12 +102,15 @@ protected: void setYCellSize(int s); WRect focusRect(); void onSelectElement(const Input::Event &, size_t i, MenuItem &); - bool elementIsSelectable(MenuItem &item); int nextSelectableElement(int start, int items); int prevSelectableElement(int start, int items); bool handleTableInput(const Input::Event &, bool &movedSelected); virtual void drawElement(Gfx::RendererCommands &__restrict__, size_t i, MenuItem &item, WRect rect, int xIndent) const; - MenuItem& item(ItemSourceDelegate, size_t idx); + + auto& item(this auto&& self, ItemSourceDelegate src, size_t idx) + { + return *getAs(src(GetItemMessage{self, idx})); + } }; } diff --git a/imagine/include/imagine/gui/TextEntry.hh b/imagine/include/imagine/gui/TextEntry.hh index b619f6bab..74721001c 100644 --- a/imagine/include/imagine/gui/TextEntry.hh +++ b/imagine/include/imagine/gui/TextEntry.hh @@ -36,7 +36,7 @@ public: bool isAcceptingInput() const; bool inputEvent(View &parentView, const Input::Event &); void prepareDraw(Gfx::Renderer &r); - void draw(Gfx::RendererCommands &__restrict__); + void draw(Gfx::RendererCommands &__restrict__) const; void place(Gfx::Renderer &r); void place(Gfx::Renderer &r, WRect rect); const char *textStr() const; @@ -62,9 +62,9 @@ public: Gfx::TextureSpan closeRes, OnTextDelegate onText, Gfx::GlyphTextureSet *face = {}): CollectTextInputView(attach, msgText, "", closeRes, onText, face) {} void place() override; - bool inputEvent(const Input::Event &) override; + bool inputEvent(const Input::Event&, ViewInputEventParams p = {}) override; void prepareDraw() override; - void draw(Gfx::RendererCommands &__restrict__) override; + void draw(Gfx::RendererCommands &__restrict__, ViewDrawParams p = {}) const override; protected: struct CancelButton diff --git a/imagine/include/imagine/gui/ToastView.hh b/imagine/include/imagine/gui/ToastView.hh index 8ca7d6f8c..173c54347 100644 --- a/imagine/include/imagine/gui/ToastView.hh +++ b/imagine/include/imagine/gui/ToastView.hh @@ -44,8 +44,7 @@ public: void postError(UTF16Convertible auto &&msg, int secs) { post(IG_forward(msg), secs, true); } void unpost(); void prepareDraw() final; - void draw(Gfx::RendererCommands &__restrict__) final; - bool inputEvent(const Input::Event &) final; + void draw(Gfx::RendererCommands &__restrict__, ViewDrawParams p = {}) const final; private: Gfx::Text text; diff --git a/imagine/include/imagine/gui/View.hh b/imagine/include/imagine/gui/View.hh index 2718de3c8..29820fd4a 100644 --- a/imagine/include/imagine/gui/View.hh +++ b/imagine/include/imagine/gui/View.hh @@ -61,7 +61,7 @@ public: virtual View* parentView(View&); }; -class View +class View: public ViewI { public: static constexpr auto imageSamplerConfig = ViewDefs::imageSamplerConfig; @@ -77,27 +77,15 @@ public: rendererTask_{&attach.rendererTask}, manager_{&attach.viewManager} {} - virtual ~View() = default; View &operator=(View &&) = delete; - virtual void place() = 0; - virtual void prepareDraw(); - virtual void draw(Gfx::RendererCommands &__restrict__) = 0; - virtual bool inputEvent(const Input::Event &event) = 0; - virtual void clearSelection(); // de-select any items from previous input - virtual void onShow(); - virtual void onHide(); - virtual void onAddedToController(ViewController *c, const Input::Event &e); - virtual void setFocus(bool focused); - virtual std::u16string_view name() const; - virtual bool onDocumentPicked(const DocumentPickerEvent&); - + bool onDocumentPicked(const DocumentPickerEvent&) override; void setViewRect(WindowRect viewRect, WindowRect displayRect); void setViewRect(WindowRect viewRect); void postDraw(); Window &window() const; Gfx::Renderer &renderer() const; Gfx::RendererTask &rendererTask() const; - ViewManager &manager(); + auto &manager(this auto&& self) { return *self.manager_; } ViewAttachParams attachParams() const; Screen *screen() const; ApplicationContext appContext() const; diff --git a/imagine/include/imagine/gui/viewDefs.hh b/imagine/include/imagine/gui/viewDefs.hh index 1cf1c29f7..9cb1f37ed 100644 --- a/imagine/include/imagine/gui/viewDefs.hh +++ b/imagine/include/imagine/gui/viewDefs.hh @@ -103,4 +103,28 @@ public: } }; +struct ViewInputEventParams +{ + View* parentPtr{}; +}; + +struct ViewDrawParams{}; + +struct ViewI +{ + constexpr ViewI() = default; + virtual ~ViewI() = default; + virtual void place() = 0; + virtual void prepareDraw(); + virtual void draw(Gfx::RendererCommands&__restrict__, ViewDrawParams p = {}) const = 0; + virtual bool inputEvent(const Input::Event&, ViewInputEventParams p = {}); + virtual void clearSelection(); // de-select any items from previous input + virtual void onShow(); + virtual void onHide(); + virtual void onAddedToController(ViewController*, const Input::Event&); + virtual void setFocus(bool focused); + virtual std::u16string_view name() const; + virtual bool onDocumentPicked(const DocumentPickerEvent&); +}; + } diff --git a/imagine/include/imagine/logger/logger.h b/imagine/include/imagine/logger/logger.h index a005daae9..24dde5828 100755 --- a/imagine/include/imagine/logger/logger.h +++ b/imagine/include/imagine/logger/logger.h @@ -46,12 +46,40 @@ static const uint8_t LOG_E = LOGGER_ERROR; #ifdef __cplusplus +#include #include namespace IG::Log { -void print(LoggerSeverity lv, std::string_view tag, std::string_view format, std::format_args args); +void print(LoggerSeverity, std::string_view tag, std::string_view format, std::format_args); +void printMsg(LoggerSeverity, const char* str, size_t strSize); + +constexpr auto severityToColorCode(LoggerSeverity severity) +{ + switch(severity) + { + case LOGGER_DEBUG_MESSAGE: return "\033[1;36m"; + default: [[fallthrough]]; + case LOGGER_MESSAGE: return "\033[0m"; + case LOGGER_WARNING: return "\033[1;33m"; + case LOGGER_ERROR: return "\033[1;31m"; + } +} + +constexpr void beginMsg(auto& str, LoggerSeverity lv, std::string_view tag, std::string_view format, std::format_args args) +{ + if(Config::envIsLinux) + { + str += severityToColorCode(lv); + } + if(tag.size()) + { + str += tag; + str += ": "; + } + std::vformat_to(std::back_inserter(str), format, args); +} } @@ -92,6 +120,46 @@ class SystemLogger { Log::print(LOG_E, tag, format.get(), std::make_format_args(args...)); } + + template + void beginMsg(auto& str, LoggerSeverity lv, std::format_string format, T&&... args) const + { + Log::beginMsg(str, lv, tag, format.get(), std::make_format_args(args...)); + } + + template + void beginInfo(auto& str, std::format_string format, T&&... args) const + { + Log::beginMsg(str, LOG_M, tag, format.get(), std::make_format_args(args...)); + } + + template + void beginDebug(auto& str, std::format_string format, T&&... args) const + { + Log::beginMsg(str, LOG_D, tag, format.get(), std::make_format_args(args...)); + } + + template + void beginWarn(auto& str, std::format_string format, T&&... args) const + { + Log::beginMsg(str, LOG_W, tag, format.get(), std::make_format_args(args...)); + } + + template + void beginError(auto& str, std::format_string format, T&&... args) const + { + Log::beginMsg(str, LOG_E, tag, format.get(), std::make_format_args(args...)); + } + + void printMsg(LoggerSeverity lv, auto& str) const + { + Log::printMsg(lv, str.c_str(), str.size()); + } + + void printInfo(auto& str) const { printMsg(LOG_M, str); } + void printDebug(auto& str) const { printMsg(LOG_D, str); } + void printWarn(auto& str) const { printMsg(LOG_W, str); } + void printError(auto& str) const { printMsg(LOG_E, str); } }; } diff --git a/imagine/include/imagine/util/opengl/glDefs.h b/imagine/include/imagine/util/opengl/glDefs.h new file mode 100644 index 000000000..31f146933 --- /dev/null +++ b/imagine/include/imagine/util/opengl/glDefs.h @@ -0,0 +1,24 @@ +#pragma once + +#if defined __APPLE__ +#import +#import +#else // Generic OpenGL headers +#define GL_GLEXT_PROTOTYPES +#include +#include +#undef GL_GLEXT_PROTOTYPES +#endif + +#define IG_GL_API_OGL + +#ifndef GL_APIENTRY +#define GL_APIENTRY GLAPIENTRY +#endif + +namespace IG +{ + +constexpr auto glDebugMessageCallbackName = "glDebugMessageCallback"; + +} diff --git a/imagine/include/imagine/util/opengl/glUtils.hh b/imagine/include/imagine/util/opengl/glUtils.hh new file mode 100644 index 000000000..4be7cf5e2 --- /dev/null +++ b/imagine/include/imagine/util/opengl/glUtils.hh @@ -0,0 +1,72 @@ +#pragma once + +/* This file is part of Imagine. + + Imagine is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Imagine is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Imagine. If not, see */ + +#include + +#ifdef IG_GL_API_OGL +#include +#elif defined IG_GL_API_OGL_ES +#include +#else + #if defined CONFIG_OS_IOS || defined __ANDROID__ + #include + #else + #include + #endif +#endif + +#include +#include +#include +#include + +namespace IG +{ + +inline int glVersionFromStr(const char* versionStr) +{ + // skip to version number + while(!isDigit(*versionStr) && *versionStr != '\0') + versionStr++; + int major = 1, minor = 0; + if(sscanf(versionStr, "%d.%d", &major, &minor) != 2) + { + return 10 * major; + } + return 10 * major + minor; +} + +inline void forEachOpenGLExtension(auto &&func) +{ + #ifdef IG_GL_API_OGL + GLint numExtensions; + glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions); + for(auto i : iotaCount(numExtensions)) + { + auto extStr = reinterpret_cast(glGetStringi(GL_EXTENSIONS, i)); + func(std::string_view{extStr}); + } + #else + auto extStr = reinterpret_cast(glGetString(GL_EXTENSIONS)); + for(auto s: std::string_view{extStr} | std::views::split(' ')) + { + func(std::string_view{s}); + } + #endif +} + +} diff --git a/imagine/include/imagine/util/opengl/glesDefs.h b/imagine/include/imagine/util/opengl/glesDefs.h new file mode 100644 index 000000000..f07d632b7 --- /dev/null +++ b/imagine/include/imagine/util/opengl/glesDefs.h @@ -0,0 +1,49 @@ +#pragma once + +#if defined __APPLE__ +#import +#import +#else // Generic OpenGL ES headers +#define GL_GLEXT_PROTOTYPES +#include +#include +#undef GL_GLEXT_PROTOTYPES +#endif + +#define IG_GL_API_OGL_ES + +// Symbol Re-mapping + +#ifndef GL_BGRA +#define GL_BGRA GL_BGRA_EXT +#endif +#ifndef GL_ALPHA8 +#define GL_ALPHA8 0x803C +#endif +#ifndef GL_LUMINANCE8 +#define GL_LUMINANCE8 0x8040 +#endif +#ifndef GL_LUMINANCE8_ALPHA8 +#define GL_LUMINANCE8_ALPHA8 0x8045 +#endif +#ifndef GL_SYNC_FLUSH_COMMANDS_BIT +#define GL_SYNC_FLUSH_COMMANDS_BIT 0x00000001 +#endif + +#ifndef GL_KHR_debug +typedef void (GL_APIENTRY *GLDEBUGPROCKHR)(GLenum, GLenum, GLuint, GLenum, GLsizei, const GLchar*, const void *); +#define GL_DEBUG_OUTPUT_KHR 0x92E0 +#endif + +#ifndef GL_DEBUG_OUTPUT +#define GL_DEBUG_OUTPUT GL_DEBUG_OUTPUT_KHR +#endif + +using GLDEBUGPROC = GLDEBUGPROCKHR; + +namespace IG +{ + +constexpr auto glDebugMessageCallbackName = "glDebugMessageCallbackKHR"; + +} diff --git a/imagine/make/linux-gcc.mk b/imagine/make/linux-gcc.mk index ac503511a..0d250903b 100644 --- a/imagine/make/linux-gcc.mk +++ b/imagine/make/linux-gcc.mk @@ -32,8 +32,4 @@ endif LDLIBS += -lpthread -lm LDFLAGS_SYSTEM += -Wl,-O3,--gc-sections,--as-needed,--compress-debug-sections=$(COMPRESS_DEBUG_SECTIONS),--icf=all -ifneq ($(ARCH),arm) - LDFLAGS_SYSTEM += -fuse-ld=mold -else - LDFLAGS_SYSTEM += -fuse-ld=gold -endif \ No newline at end of file +LDFLAGS_SYSTEM += -fuse-ld=mold \ No newline at end of file diff --git a/imagine/src/base/android/AndroidGLContext.cc b/imagine/src/base/android/AndroidGLContext.cc index 4ede2c8bd..c4b1ce222 100644 --- a/imagine/src/base/android/AndroidGLContext.cc +++ b/imagine/src/base/android/AndroidGLContext.cc @@ -29,18 +29,18 @@ GLDisplay GLManager::getDefaultDisplay(NativeDisplayConnection) const bool GLManager::bindAPI(GL::API api) { - return api == GL::API::OPENGL_ES; + return api == GL::API::OpenGLES; } -std::optional GLManager::makeBufferConfig(ApplicationContext ctx, GLBufferConfigAttributes attr, GL::API api, int majorVersion) const +std::optional GLManager::tryBufferConfig(ApplicationContext ctx, const GLBufferRenderConfigAttributes& attrs) const { - if(majorVersion > 2 && ctx.androidSDK() < 18) + if(attrs.version.major > 2 && ctx.androidSDK() < 18) { // need at least Android 4.3 to use ES 3 attributes return {}; } - auto renderableType = makeRenderableType(GL::API::OPENGL_ES, majorVersion); - return chooseConfig(display(), renderableType, attr); + auto renderableType = makeRenderableType(GL::API::OpenGLES, attrs.version); + return chooseConfig(display(), renderableType, attrs); } NativeWindowFormat GLManager::nativeWindowFormat(ApplicationContext, GLBufferConfig glConfig) const diff --git a/imagine/src/base/common/Base.cc b/imagine/src/base/common/Base.cc index 68f2b00cc..67eddf523 100755 --- a/imagine/src/base/common/Base.cc +++ b/imagine/src/base/common/Base.cc @@ -106,6 +106,22 @@ void GLManager::resetCurrentContext() const display().resetCurrentContext(); } +GLBufferConfig GLManager::makeBufferConfig(ApplicationContext ctx, const GLBufferRenderConfigAttributes& attrs) const +{ + return makeBufferConfig(ctx, std::span{&attrs, 1}); +} + +GLBufferConfig GLManager::makeBufferConfig(ApplicationContext ctx, std::span attrsSpan) const +{ + for(const auto &attrs : attrsSpan) + { + auto config = tryBufferConfig(ctx, attrs); + if(config) + return *config; + } + throw std::runtime_error("Error finding a GL configuration"); +} + SteadyClockTimePoint FrameParams::presentTime(int frames) const { if(frames <= 0) diff --git a/imagine/src/base/common/EGLContextBase.cc b/imagine/src/base/common/EGLContextBase.cc index e7d73dbca..bb241edad 100644 --- a/imagine/src/base/common/EGLContextBase.cc +++ b/imagine/src/base/common/EGLContextBase.cc @@ -92,21 +92,21 @@ static EGLContextAttrList glContextAttrsToEGLAttrs(GLContextAttributes attr) { EGLContextAttrList list; - if(attr.glesApi) + if(attr.api == GL::API::OpenGLES) { list.push_back(EGL_CONTEXT_CLIENT_VERSION); - list.push_back(attr.majorVersion); + list.push_back(attr.version.major); //log.debug("using OpenGL ES client version:{}", attr.majorVersion()); } else { list.push_back(EGL_CONTEXT_MAJOR_VERSION_KHR); - list.push_back(attr.majorVersion); + list.push_back(attr.version.major); list.push_back(EGL_CONTEXT_MINOR_VERSION_KHR); - list.push_back(attr.minorVersion); + list.push_back(attr.version.minor); - if(attr.majorVersion > 3 - || (attr.majorVersion == 3 && attr.minorVersion >= 2)) + if(attr.version.major > 3 + || (attr.version.major == 3 && attr.version.minor >= 2)) { list.push_back(EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR); list.push_back(EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR); @@ -301,10 +301,7 @@ void GLContext::setSwapInterval(int i) GLManager::GLManager(NativeDisplayConnection ctx, GL::API api) { if(!bindAPI(api)) - { - log.error("error binding requested API"); - return; - } + throw std::runtime_error("Error binding requested EGL API"); auto display = getDefaultDisplay(ctx); if(!initDisplay(display)) throw std::runtime_error("Error initializing EGL"); @@ -438,10 +435,10 @@ GLContext GLManager::makeContext(GLContextAttributes attr, GLBufferConfig config if(!hasNoErrorContextAttribute()) attr.noError = false; log.info("making context with version: {}.{} config:{} share context:{}", - attr.majorVersion, attr.minorVersion, (EGLConfig)config, shareContext); + attr.version.major, attr.version.minor, (EGLConfig)config, shareContext); // Ignore surfaceless context support when using GL versions below 3.0 due to possible driver issues, // such as on Tegra 3 GPUs - bool savePBuffConfig = attr.majorVersion <= 2 || !supportsSurfaceless; + bool savePBuffConfig = attr.version.major <= 2 || !supportsSurfaceless; GLContext ctx{display(), attr, config, shareContext, savePBuffConfig}; if(!ctx) return {}; @@ -476,15 +473,15 @@ const char *EGLManager::errorString(EGLint error) return "Unknown error"; } -int EGLManager::makeRenderableType(GL::API api, int majorVersion) +int EGLManager::makeRenderableType(GL::API api, GL::Version version) { - if(api == GL::API::OPENGL) + if(api == GL::API::OpenGL) { return EGL_OPENGL_BIT; } else { - switch(majorVersion) + switch(version.major) { default: return 0; case 2: return EGL_OPENGL_ES2_BIT; diff --git a/imagine/src/base/iphone/IOSGLContext.mm b/imagine/src/base/iphone/IOSGLContext.mm index 36b389793..7798c92ec 100644 --- a/imagine/src/base/iphone/IOSGLContext.mm +++ b/imagine/src/base/iphone/IOSGLContext.mm @@ -75,7 +75,7 @@ static EAGLRenderingAPI majorVersionToAPI(int version) IOSGLContext::IOSGLContext(GLContextAttributes attr, NativeGLContext shareContext_) { - assert(attr.glesApi); + assert(attr.api == GL::API::OpenGLES); EAGLRenderingAPI api = majorVersionToAPI(attr.majorVersion); auto shareContext = (__bridge EAGLContext*)shareContext_; EAGLSharegroup *sharegroup = [shareContext sharegroup]; @@ -140,7 +140,7 @@ static EAGLRenderingAPI majorVersionToAPI(int version) bool GLManager::bindAPI(GL::API api) { - return api == GL::API::OPENGL_ES; + return api == GL::API::OpenGLES; } GLDrawable GLManager::makeDrawable(Window &win, GLDrawableAttributes config) const @@ -177,10 +177,10 @@ static EAGLRenderingAPI majorVersionToAPI(int version) GLDisplay GLManager::display() const { return {}; } -std::optional GLManager::makeBufferConfig(ApplicationContext, GLBufferConfigAttributes attr, GL::API, int) const +std::optional GLManager::tryBufferConfig(ApplicationContext, const GLBufferRenderConfigAttributes& attrs) const { GLBufferConfig conf; - if(attr.pixelFormat == PixelFmtRGB565) + if(attrs.bufferAttrs.pixelFormat == PixelFmtRGB565) { conf.useRGB565 = true; } diff --git a/imagine/src/base/x11/XGLContextEGL.cc b/imagine/src/base/x11/XGLContextEGL.cc index 3a3e98b99..19545dd47 100644 --- a/imagine/src/base/x11/XGLContextEGL.cc +++ b/imagine/src/base/x11/XGLContextEGL.cc @@ -58,19 +58,19 @@ GLDisplay GLManager::getDefaultDisplay(NativeDisplayConnection nativeDpy) const bool GLManager::bindAPI(GL::API api) { - if(api == GL::API::OPENGL_ES) + if(api == GL::API::OpenGLES) return eglBindAPI(EGL_OPENGL_ES_API); else return eglBindAPI(EGL_OPENGL_API); } -std::optional GLManager::makeBufferConfig(ApplicationContext ctx, GLBufferConfigAttributes attr, GL::API api, int majorVersion) const +std::optional GLManager::tryBufferConfig(ApplicationContext ctx, const GLBufferRenderConfigAttributes& attrs) const { - auto renderableType = makeRenderableType(api, majorVersion); - if(attr.translucentWindow) + auto renderableType = makeRenderableType(attrs.api, attrs.version); + if(attrs.bufferAttrs.translucentWindow) { std::array configs; - auto configCount = chooseConfigs(display(), renderableType, attr, configs); + auto configCount = chooseConfigs(display(), renderableType, attrs, configs); if(!configCount) { log.error("no usable EGL configs found with renderable type:{}", eglRenderableTypeToStr(renderableType)); @@ -96,7 +96,7 @@ std::optional GLManager::makeBufferConfig(ApplicationContext ctx } else { - return chooseConfig(display(), renderableType, attr); + return chooseConfig(display(), renderableType, attrs); } } diff --git a/imagine/src/gfx/opengl/DrawContextSupport.cc b/imagine/src/gfx/opengl/DrawContextSupport.cc index 59a8249a0..d9178f15b 100644 --- a/imagine/src/gfx/opengl/DrawContextSupport.cc +++ b/imagine/src/gfx/opengl/DrawContextSupport.cc @@ -234,21 +234,18 @@ static LoggerSeverity severityToLogger(GLenum severity) void DrawContextSupport::setGLDebugOutput(bool on) { - #ifdef CONFIG_GFX_OPENGL_DEBUG_CONTEXT if(!hasDebugOutput) return; if(!on) { - glDisable(DEBUG_OUTPUT); + glDisable(GL_DEBUG_OUTPUT); } else { if(!glDebugMessageCallback) [[unlikely]] { - auto glDebugMessageCallbackStr = - Config::Gfx::OPENGL_ES ? "glDebugMessageCallbackKHR" : "glDebugMessageCallback"; - log.warn("enabling debug output with {}", glDebugMessageCallbackStr); - glDebugMessageCallback = (typeof(glDebugMessageCallback))GLManager::procAddress(glDebugMessageCallbackStr); + log.warn("enabling debug output with {}", glDebugMessageCallbackName); + glDebugMessageCallback = (typeof(glDebugMessageCallback))GLManager::procAddress(glDebugMessageCallbackName); } glDebugMessageCallback( GL_APIENTRY [](GLenum source, GLenum type, GLuint id, @@ -266,9 +263,8 @@ void DrawContextSupport::setGLDebugOutput(bool on) if(severity == GL_DEBUG_SEVERITY_HIGH && type != GL_DEBUG_TYPE_PERFORMANCE) abort(); }, nullptr); - glEnable(DEBUG_OUTPUT); + glEnable(GL_DEBUG_OUTPUT); } - #endif } } diff --git a/imagine/src/gfx/opengl/GLTask.cc b/imagine/src/gfx/opengl/GLTask.cc index 781f856e5..ee39637bc 100644 --- a/imagine/src/gfx/opengl/GLTask.cc +++ b/imagine/src/gfx/opengl/GLTask.cc @@ -149,9 +149,9 @@ void GLTask::TaskContext::markSemaphoreNotified() *semaphoreNeedsNotifyPtr = false; } -static GLContextAttributes makeGLContextAttributes(int majorVersion, int minorVersion) +static GLContextAttributes makeGLContextAttributes(GL::Version version) { - GLContextAttributes glAttr{majorVersion, minorVersion, glAPI}; + GLContextAttributes glAttr{version, glAPI}; if(Config::DEBUG_BUILD) glAttr.debug = true; else @@ -159,10 +159,9 @@ static GLContextAttributes makeGLContextAttributes(int majorVersion, int minorVe return glAttr; } -static GLContext makeVersionedGLContext(GLManager &mgr, GLBufferConfig config, - int majorVersion, int minorVersion) +static GLContext makeVersionedGLContext(GLManager &mgr, GLBufferConfig config, GL::Version version) { - auto glAttr = makeGLContextAttributes(majorVersion, minorVersion); + auto glAttr = makeGLContextAttributes(version); try { return mgr.makeContext(glAttr, config); @@ -179,18 +178,18 @@ GLContext GLTask::makeGLContext(GLManager &mgr, GLBufferConfig bufferConf) { if(bufferConf.maySupportGLES(mgr.display(), 3)) { - auto ctx = makeVersionedGLContext(mgr, bufferConf, 3, 0); + auto ctx = makeVersionedGLContext(mgr, bufferConf, {3}); if(ctx) { return ctx; } } // fall back to OpenGL ES 2.0 - return makeVersionedGLContext(mgr, bufferConf, 2, 0); + return makeVersionedGLContext(mgr, bufferConf, {2}); } else { - auto ctx = makeVersionedGLContext(mgr, bufferConf, 3, 3); + auto ctx = makeVersionedGLContext(mgr, bufferConf, {3, 3}); if(ctx) { return ctx; diff --git a/imagine/src/gfx/opengl/Renderer.cc b/imagine/src/gfx/opengl/Renderer.cc index f91ccdd2d..6051bb76f 100755 --- a/imagine/src/gfx/opengl/Renderer.cc +++ b/imagine/src/gfx/opengl/Renderer.cc @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include "internalDefs.hh" namespace IG::Gfx @@ -549,7 +549,7 @@ void Renderer::setCorrectnessChecks(bool on) static void printFeatures(DrawContextSupport support) { - if(!Config::DEBUG_BUILD) + if constexpr(!Config::DEBUG_BUILD) return; std::string featuresStr{}; featuresStr.reserve(256); @@ -558,9 +558,9 @@ static void printFeatures(DrawContextSupport support) featuresStr.append(std::format("{}", support.textureSizeSupport.maxXSize)); featuresStr.append("]"); if(support.textureSizeSupport.nonPow2CanRepeat) - featuresStr.append("[NPOT Textures w/ Mipmap+Repeat]"); + featuresStr.append(" [NPOT Textures w/ Mipmap+Repeat]"); else if(support.textureSizeSupport.nonPow2CanMipmap) - featuresStr.append("[NPOT Textures w/ Mipmap]"); + featuresStr.append(" [NPOT Textures w/ Mipmap]"); #ifdef CONFIG_GFX_OPENGL_ES if(support.hasBGRPixels) { @@ -806,7 +806,7 @@ void GLRenderer::setupEglFenceSync(std::string_view eglExtenstionStr) void GLRenderer::checkExtensionString(std::string_view extStr) { //logMsg("checking %s", extStr); - if(Config::DEBUG_BUILD && Config::Gfx::OPENGL_DEBUG_CONTEXT && extStr == "GL_KHR_debug") + if(Config::DEBUG_BUILD && Config::OpenGLDebugContext && extStr == "GL_KHR_debug") { support.hasDebugOutput = true; #ifdef __ANDROID__ @@ -926,29 +926,18 @@ void GLRenderer::checkExtensionString(std::string_view extStr) #endif } -void GLRenderer::checkFullExtensionString(const char *fullExtStr) +static void printGLExtensions() { - std::string fullExtStrTemp{fullExtStr}; - char *savePtr; - auto extStr = strtok_r(fullExtStrTemp.data(), " ", &savePtr); - while(extStr) - { - checkExtensionString(extStr); - extStr = strtok_r(nullptr, " ", &savePtr); - } -} - -static int glVersionFromStr(const char *versionStr) -{ - // skip to version number - while(!isDigit(*versionStr) && *versionStr != '\0') - versionStr++; - int major = 1, minor = 0; - if(sscanf(versionStr, "%d.%d", &major, &minor) != 2) + if constexpr(!Config::DEBUG_BUILD) + return; + std::string allExtStr; + log.beginInfo(allExtStr, "extensions: "); + forEachOpenGLExtension([&](const auto &extStr) { - logErr("unable to parse GL version string"); - } - return 10 * major + minor; + allExtStr += extStr; + allExtStr += ' '; + }); + log.printInfo(allExtStr); } void Renderer::configureRenderer() @@ -977,22 +966,6 @@ void Renderer::configureRenderer() #ifndef CONFIG_GFX_OPENGL_ES assert(glVer >= 33); - // extension functionality - GLint numExtensions; - glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions); - if(Config::DEBUG_BUILD) - { - logMsgNoBreak("extensions: "); - for(auto i : iotaCount(numExtensions)) - { - logger_printf(LOG_M, "%s ", (const char*)glGetStringi(GL_EXTENSIONS, i)); - } - logger_printf(LOG_M, "\n"); - } - for(auto i : iotaCount(numExtensions)) - { - checkExtensionString((const char*)glGetStringi(GL_EXTENSIONS, i)); - } #else // core functionality assumeExpr(glVer >= 20); @@ -1020,13 +993,14 @@ void Renderer::configureRenderer() { setupMemoryBarrier(); } + #endif // CONFIG_GFX_OPENGL_ES // extension functionality - auto extensions = (const char*)glGetString(GL_EXTENSIONS); - assert(extensions); - logMsg("extensions: %s", extensions); - checkFullExtensionString(extensions); - #endif // CONFIG_GFX_OPENGL_ES + forEachOpenGLExtension([&](const auto &extStr) + { + checkExtensionString(extStr); + }); + printGLExtensions(); GLint texSize; glGetIntegerv(GL_MAX_TEXTURE_SIZE, &texSize); @@ -1087,22 +1061,23 @@ std::optional GLRenderer::makeGLBufferConfig(ApplicationContext else pixelFormat = ctx.defaultWindowPixelFormat(); } - GLBufferConfigAttributes glBuffAttr{.pixelFormat = pixelFormat}; - if constexpr(Config::Gfx::OPENGL_ES) + try { - if(auto config = glManager.makeBufferConfig(ctx, glBuffAttr, glAPI, 3); - config) + if constexpr(Config::Gfx::OPENGL_ES) { - return config; + // prefer ES 3.x and fall back to 2.0 + const GLBufferRenderConfigAttributes gl3Attrs{.bufferAttrs{.pixelFormat = pixelFormat}, .version = {3}, .api = glAPI}; + const GLBufferRenderConfigAttributes gl2Attrs{.bufferAttrs{.pixelFormat = pixelFormat}, .version = {2}, .api = glAPI}; + return glManager.makeBufferConfig(ctx, std::array{gl3Attrs, gl2Attrs}); + } + else + { + // full OpenGL + const GLBufferRenderConfigAttributes gl3Attrs{.bufferAttrs{.pixelFormat = pixelFormat}, .version = {3, 3}, .api = glAPI}; + return glManager.makeBufferConfig(ctx, gl3Attrs); } - // fall back to OpenGL ES 2.0 - return glManager.makeBufferConfig(ctx, glBuffAttr, glAPI, 2); - } - else - { - // full OpenGL - return glManager.makeBufferConfig(ctx, glBuffAttr, glAPI); } + catch(...) { return {}; } } } diff --git a/imagine/src/gfx/opengl/internalDefs.hh b/imagine/src/gfx/opengl/internalDefs.hh index 51b89f264..848aa2f1d 100644 --- a/imagine/src/gfx/opengl/internalDefs.hh +++ b/imagine/src/gfx/opengl/internalDefs.hh @@ -35,8 +35,7 @@ constexpr bool forceNoVAOs = false; // for testing non-VAO code paths constexpr bool defaultToFullErrorChecks = true; constexpr GLuint VATTR_POS = 0, VATTR_TEX_UV = 1, VATTR_COLOR = 2; -static constexpr GL::API glAPI = - Config::Gfx::OPENGL_ES ? GL::API::OPENGL_ES : GL::API::OPENGL; +constexpr GL::API glAPI = Config::Gfx::OPENGL_ES ? GL::API::OpenGLES : GL::API::OpenGL; int toSwapInterval(Window &win, PresentMode mode); diff --git a/imagine/src/gui/AlertView.cc b/imagine/src/gui/AlertView.cc index 0a78ce2dc..95d7e7d54 100644 --- a/imagine/src/gui/AlertView.cc +++ b/imagine/src/gui/AlertView.cc @@ -31,16 +31,15 @@ void BaseAlertView::init() { menu.setAlign(C2DO); menu.setScrollableIfNeeded(true); - menu.setOnSelectElement( - [this](const Input::Event &e, int i, MenuItem &item) + menu.setOnSelectElement([this](const Input::Event& e, int i, MenuItem& item) + { + bool shouldDismiss = item.inputEvent(e, {.parentPtr = this}); + if(shouldDismiss) { - bool shouldDismiss = item.select(*this, e); - if(shouldDismiss) - { - logMsg("dismissing"); - dismiss(); - } - }); + logMsg("dismissing"); + dismiss(); + } + }); } void BaseAlertView::place() @@ -66,7 +65,7 @@ void BaseAlertView::place() bgQuads.write(1, {.bounds = menu.viewRect().as()}); } -bool BaseAlertView::inputEvent(const Input::Event &e) +bool BaseAlertView::inputEvent(const Input::Event& e, ViewInputEventParams) { if(e.keyEvent() && e.keyEvent()->pushed(Input::DefaultKey::CANCEL)) { @@ -82,7 +81,7 @@ void BaseAlertView::prepareDraw() menu.prepareDraw(); } -void BaseAlertView::draw(Gfx::RendererCommands &__restrict__ cmds) +void BaseAlertView::draw(Gfx::RendererCommands &__restrict__ cmds, ViewDrawParams) const { using namespace IG::Gfx; auto &basicEffect = cmds.basicEffect(); diff --git a/imagine/src/gui/FSPicker.cc b/imagine/src/gui/FSPicker.cc index d8ca5a29e..6a28ca9e8 100644 --- a/imagine/src/gui/FSPicker.cc +++ b/imagine/src/gui/FSPicker.cc @@ -140,7 +140,7 @@ void FSPicker::onRightNavBtn(const Input::Event &e) dismiss(); } -bool FSPicker::inputEvent(const Input::Event &e) +bool FSPicker::inputEvent(const Input::Event& e, ViewInputEventParams) { if(e.keyEvent()) { @@ -177,7 +177,7 @@ void FSPicker::prepareDraw() msgText.makeGlyphs(); } -void FSPicker::draw(Gfx::RendererCommands &__restrict__ cmds) +void FSPicker::draw(Gfx::RendererCommands &__restrict__ cmds, ViewDrawParams) const { if(!dirListThread.isWorking()) { diff --git a/imagine/src/gui/MenuItem.cc b/imagine/src/gui/MenuItem.cc index cfa22ea8b..5cc15f030 100644 --- a/imagine/src/gui/MenuItem.cc +++ b/imagine/src/gui/MenuItem.cc @@ -23,30 +23,33 @@ namespace IG { +bool MenuItemI::inputEvent(const Input::Event&, ViewInputEventParams) { return false; } + void MenuItem::prepareDraw() { t.makeGlyphs(); } -void MenuItem::draw(Gfx::RendererCommands &__restrict__ cmds, int xPos, int yPos, int xSize, int ySize, - int xIndent, _2DOrigin align, Gfx::Color color) const +void MenuItem::draw(Gfx::RendererCommands&__restrict__ cmds, MenuItemDrawAttrs attrs) const { + auto [xPos, yPos] = attrs.rect.pos(LT2DO); + auto xSize = attrs.rect.size().x; if(!active()) { // half-bright color - color.r /= 2.f; - color.g /= 2.f; - color.b /= 2.f; + attrs.color.r /= 2.f; + attrs.color.g /= 2.f; + attrs.color.b /= 2.f; } - if(align.isXCentered()) - xPos += xSize/2; + if(attrs.align.isXCentered()) + xPos += xSize / 2; else - xPos += xIndent; + xPos += attrs.xIndent; cmds.basicEffect().enableAlphaTexture(cmds); - t.draw(cmds, {xPos, yPos}, align,color); + t.draw(cmds, {xPos, yPos}, attrs.align, attrs.color); } -void MenuItem::compile() +void MenuItem::place() { t.compile(); } @@ -66,13 +69,15 @@ const Gfx::Text &MenuItem::text() const return t; } -void BaseDualTextMenuItem::compile() +bool TextMenuItem::inputEvent(const Input::Event& e, ViewInputEventParams p) { return onSelect.callCopySafe(*this, *p.parentPtr, e); } + +void BaseDualTextMenuItem::place() { - MenuItem::compile(); - compile2nd(); + MenuItem::place(); + place2nd(); } -void BaseDualTextMenuItem::compile2nd() +void BaseDualTextMenuItem::place2nd() { t2.compile(); } @@ -83,38 +88,38 @@ void BaseDualTextMenuItem::prepareDraw() t2.makeGlyphs(); } -void BaseDualTextMenuItem::draw2ndText(Gfx::RendererCommands &cmds, int xPos, int yPos, int xSize, int ySize, - int xIndent, _2DOrigin align, Gfx::Color color) const +void BaseDualTextMenuItem::draw2ndText(Gfx::RendererCommands &cmds, MenuItemDrawAttrs attrs) const { cmds.basicEffect().enableAlphaTexture(cmds); - t2.draw(cmds, {(xPos + xSize) - xIndent, yPos}, RC2DO, color); + auto [xPos, yPos] = attrs.rect.pos(LT2DO); + auto xSize = attrs.rect.size().x; + t2.draw(cmds, {(xPos + xSize) - attrs.xIndent, yPos}, RC2DO, attrs.color); } -void BaseDualTextMenuItem::draw(Gfx::RendererCommands &__restrict__ cmds, int xPos, int yPos, int xSize, int ySize, - int xIndent, _2DOrigin align, Gfx::Color color) const +void BaseDualTextMenuItem::draw(Gfx::RendererCommands&__restrict__ cmds, MenuItemDrawAttrs attrs) const { - MenuItem::draw(cmds, xPos, yPos, xSize, ySize, xIndent, align, color); - BaseDualTextMenuItem::draw2ndText(cmds, xPos, yPos, xSize, ySize, xIndent, align, color); + MenuItem::draw(cmds, attrs); + BaseDualTextMenuItem::draw2ndText(cmds, attrs); } -void DualTextMenuItem::draw(Gfx::RendererCommands &__restrict__ cmds, int xPos, int yPos, int xSize, int ySize, - int xIndent, _2DOrigin align, Gfx::Color color) const +void DualTextMenuItem::draw(Gfx::RendererCommands&__restrict__ cmds, MenuItemDrawAttrs attrs) const { - MenuItem::draw(cmds, xPos, yPos, xSize, ySize, xIndent, align, color); - Gfx::Color color2 = text2Color != Gfx::Color{} ? text2Color : color; - draw2ndText(cmds, xPos, yPos, xSize, ySize, xIndent, align, color2); + MenuItem::draw(cmds, attrs); + if(text2Color != Gfx::Color{}) + attrs.color = text2Color; + draw2ndText(cmds, attrs); } -bool DualTextMenuItem::select(View &parent, const Input::Event &e) +bool DualTextMenuItem::inputEvent(const Input::Event& e, ViewInputEventParams p) { //logMsg("calling delegate"); - onSelect.callCopySafe(*this, parent, e); + onSelect.callCopySafe(*this, *p.parentPtr, e); return true; } -bool BoolMenuItem::select(View &parent, const Input::Event &e) +bool BoolMenuItem::inputEvent(const Input::Event& e, ViewInputEventParams p) { - onSelect.callCopySafe(*this, parent, e); + onSelect.callCopySafe(*this, *p.parentPtr, e); return true; } @@ -159,18 +164,16 @@ bool BoolMenuItem::flipBoolValue() return boolValue(); } -void BoolMenuItem::draw(Gfx::RendererCommands &__restrict__ cmds, int xPos, int yPos, int xSize, int ySize, - int xIndent, _2DOrigin align, Gfx::Color color) const +void BoolMenuItem::draw(Gfx::RendererCommands &__restrict__ cmds, MenuItemDrawAttrs attrs) const { - MenuItem::draw(cmds, xPos, yPos, xSize, ySize, xIndent, align, color); - Gfx::Color color2; + MenuItem::draw(cmds, attrs); if(!(flags.impl & onOffStyleFlag)) // custom strings - color2 = Gfx::Color{0.f, .8f, 1.f}; + attrs.color = Gfx::Color{0.f, .8f, 1.f}; else if(boolValue()) - color2 = Gfx::Color{.27f, 1.f, .27f}; + attrs.color = Gfx::Color{.27f, 1.f, .27f}; else - color2 = Gfx::Color{1.f, .27f, .27f}; - draw2ndText(cmds, xPos, yPos, xSize, ySize, xIndent, align, color2); + attrs.color = Gfx::Color{1.f, .27f, .27f}; + draw2ndText(cmds, attrs); } class MenuItemTableView : public TableView @@ -184,15 +187,14 @@ class MenuItemTableView : public TableView activeItem{active}, src{src} { - setOnSelectElement( - [this](const Input::Event &e, int i, MenuItem &item) + setOnSelectElement([this](const Input::Event& e, int i, MenuItem& item) + { + if(item.inputEvent(e, {.parentPtr = this})) { - if(item.select(*this, e)) - { - this->src.setSelected(i, *this); - dismiss(); - } - }); + this->src.setSelected(i, *this); + dismiss(); + } + }); } void onAddedToController(ViewController *, const Input::Event &e) final @@ -203,22 +205,23 @@ class MenuItemTableView : public TableView void drawElement(Gfx::RendererCommands &__restrict__ cmds, size_t i, MenuItem &item, WRect rect, int xIndent) const final { - item.draw(cmds, rect.x, rect.pos(C2DO).y, rect.xSize(), rect.ySize(), xIndent, TableView::align, menuTextColor((int)i == activeItem)); + MenuItemDrawAttrs attrs{.rect = {{rect.x, rect.pos(C2DO).y}, rect.size()}, + .xIndent = xIndent, .color = menuTextColor((int)i == activeItem), .align = TableView::align}; + item.draw(cmds, attrs); } }; -void MultiChoiceMenuItem::draw(Gfx::RendererCommands &__restrict__ cmds, int xPos, int yPos, int xSize, int ySize, - int xIndent, _2DOrigin align, Gfx::Color color) const +void MultiChoiceMenuItem::draw(Gfx::RendererCommands &__restrict__ cmds, MenuItemDrawAttrs attrs) const { - MenuItem::draw(cmds, xPos, yPos, xSize, ySize, xIndent, align, color); - auto color2 = Gfx::Color{0.f, .8f, 1.f}; - BaseDualTextMenuItem::draw2ndText(cmds, xPos, yPos, xSize, ySize, xIndent, align, color2); + MenuItem::draw(cmds, attrs); + attrs.color = Gfx::Color{0.f, .8f, 1.f}; + BaseDualTextMenuItem::draw2ndText(cmds, attrs); } -void MultiChoiceMenuItem::compile() +void MultiChoiceMenuItem::place() { setDisplayString(selected_); - BaseDualTextMenuItem::compile(); + BaseDualTextMenuItem::place(); } int MultiChoiceMenuItem::selected() const @@ -290,10 +293,10 @@ int MultiChoiceMenuItem::cycleSelected(int offset) return selected_; } -bool MultiChoiceMenuItem::select(View &parent, const Input::Event &e) +bool MultiChoiceMenuItem::inputEvent(const Input::Event& e, ViewInputEventParams p) { //logMsg("calling delegate"); - onSelect.callCopySafe(*this, parent, e); + onSelect.callCopySafe(*this, *p.parentPtr, e); return true; } @@ -306,11 +309,11 @@ std::unique_ptr MultiChoiceMenuItem::makeTableView(ViewAttachParams a selected_ < (ssize_t)items() ? selected_ : -1, [this](TableView::ItemMessage msg) -> TableView::ItemReply { - return visit(overloaded + return msg.visit(overloaded { [&](const TableView::ItemsMessage &m) -> TableView::ItemReply { return items(); }, [&](const TableView::GetItemMessage &m) -> TableView::ItemReply { return &item(m.idx); }, - }, msg); + }); }, *this ); diff --git a/imagine/src/gui/NavView.cc b/imagine/src/gui/NavView.cc index d25a9b3ef..873fa4cec 100644 --- a/imagine/src/gui/NavView.cc +++ b/imagine/src/gui/NavView.cc @@ -83,9 +83,9 @@ bool NavView::selectNextRightButton() return false; } -bool NavView::inputEvent(const Input::Event &e) +bool NavView::inputEvent(const Input::Event &e, ViewInputEventParams) { - return visit(overloaded + return e.visit(overloaded { [&](const Input::KeyEvent &keyEv) { @@ -141,7 +141,7 @@ bool NavView::inputEvent(const Input::Event &e) } return false; } - }, e); + }); } void NavView::prepareDraw() @@ -222,7 +222,7 @@ void BasicNavView::setBackgroundGradient(std::span std::ranges::copy(gradStops, gradientStops.begin()); } -void BasicNavView::draw(Gfx::RendererCommands &__restrict__ cmds) +void BasicNavView::draw(Gfx::RendererCommands &__restrict__ cmds, ViewDrawParams) const { using namespace IG::Gfx; auto const &textRect = control[1].rect; diff --git a/imagine/src/gui/ScrollView.cc b/imagine/src/gui/ScrollView.cc index e61d96e2b..f630df2aa 100644 --- a/imagine/src/gui/ScrollView.cc +++ b/imagine/src/gui/ScrollView.cc @@ -150,7 +150,7 @@ void ScrollView::setContentSize(WSize contentSize) scrollBarQuads.write(0, {.bounds = scrollBarRect.as()}); } -void ScrollView::drawScrollContent(Gfx::RendererCommands &cmds) +void ScrollView::drawScrollContent(Gfx::RendererCommands &cmds) const { using namespace IG::Gfx; if(contentIsBiggerThanView && (allowScrollWholeArea_ || dragTracker.isDragging())) diff --git a/imagine/src/gui/TableView.cc b/imagine/src/gui/TableView.cc index f21eb4345..7c3bc7dbf 100755 --- a/imagine/src/gui/TableView.cc +++ b/imagine/src/gui/TableView.cc @@ -67,7 +67,7 @@ void TableView::prepareDraw() } } -void TableView::draw(Gfx::RendererCommands &__restrict__ cmds) +void TableView::draw(Gfx::RendererCommands &__restrict__ cmds, ViewDrawParams) const { ssize_t cells_ = cells(); if(!cells_) @@ -121,7 +121,7 @@ void TableView::draw(Gfx::RendererCommands &__restrict__ cmds) { int ySize = regularYSize; auto color = regularColor; - if(!elementIsSelectable(item(src, i - 1))) + if(!item(src, i - 1).selectable()) { ySize = headingYSize; color = headingColor; @@ -175,8 +175,8 @@ void TableView::place() auto src = itemSrc; for(auto i : iotaCount(cells_)) { - //log.debug("compile item:{}", i); - item(src, i).compile(); + //log.debug("place item:{}", i); + item(src, i).place(); } if(cells_) { @@ -246,7 +246,7 @@ void TableView::resetScroll() setScrollOffset(0); } -bool TableView::inputEvent(const Input::Event &e) +bool TableView::inputEvent(const Input::Event& e, ViewInputEventParams) { bool handleScroll = !onlyScrollIfNeeded || contentIsBiggerThanView; auto motionEv = e.motionEvent(); @@ -292,7 +292,7 @@ int TableView::nextSelectableElement(int start, int items) auto src = itemSrc; for(auto i : iotaCount(items)) { - if(elementIsSelectable(item(src, elem))) + if(item(src, elem).selectable()) { return elem; } @@ -307,7 +307,7 @@ int TableView::prevSelectableElement(int start, int items) auto src = itemSrc; for(auto i : iotaCount(items)) { - if(elementIsSelectable(item(src, elem))) + if(item(src, elem).selectable()) { return elem; } @@ -319,7 +319,7 @@ int TableView::prevSelectableElement(int start, int items) bool TableView::handleTableInput(const Input::Event &e, bool &movedSelected) { ssize_t cells_ = cells(); - return visit(overloaded + return e.visit(overloaded { [&](const Input::KeyEvent &keyEv) { @@ -467,7 +467,7 @@ bool TableView::handleTableInput(const Input::Event &e, bool &movedSelected) { //log.info("input pushed on cell:{}", i); hasFocus = true; - if(i >= 0 && i < cells_ && elementIsSelectable(it)) + if(i >= 0 && i < cells_ && it.selectable()) { selected = i; postDraw(); @@ -476,7 +476,7 @@ bool TableView::handleTableInput(const Input::Event &e, bool &movedSelected) else if(motionEv.isOff()) // TODO, need to check that Input::PUSHED was sent on entry { //log.info("input released on cell:{}", i); - if(i >= 0 && i < cells_ && selected == i && elementIsSelectable(it)) + if(i >= 0 && i < cells_ && selected == i && it.selectable()) { postDraw(); selected = -1; @@ -490,14 +490,15 @@ bool TableView::handleTableInput(const Input::Event &e, bool &movedSelected) } return true; } - }, e); + }); } void TableView::drawElement(Gfx::RendererCommands &__restrict__ cmds, size_t i, MenuItem &item, WRect rect, int xIndent) const { static constexpr Gfx::Color highlightColor{0.f, .8f, 1.f}; - item.draw(cmds, rect.x, rect.pos(C2DO).y, rect.xSize(), rect.ySize(), xIndent, align, - item.highlighted() ? highlightColor : Gfx::Color(Gfx::ColorName::WHITE)); + MenuItemDrawAttrs attrs{.rect = {{rect.x, rect.pos(C2DO).y}, rect.size()}, + .xIndent = xIndent, .color = item.highlighted() ? highlightColor : Gfx::Color(Gfx::ColorName::WHITE), .align = align}; + item.draw(cmds, attrs); } void TableView::onSelectElement(const Input::Event &e, size_t i, MenuItem &item) @@ -505,12 +506,7 @@ void TableView::onSelectElement(const Input::Event &e, size_t i, MenuItem &item) if(selectElementDel) selectElementDel(e, i, item); else - item.select(*this, e); -} - -bool TableView::elementIsSelectable(MenuItem &item) -{ - return item.selectable(); + item.inputEvent(e, {.parentPtr = this}); } std::u16string_view TableView::name() const @@ -523,11 +519,6 @@ TableUIState TableView::saveUIState() const return {.highlightedCell = highlightedCell(), .scrollOffset = scrollOffset()}; } -MenuItem& TableView::item(ItemSourceDelegate src, size_t idx) -{ - return *getAs(src(GetItemMessage{*this, idx})); -} - void TableView::restoreUIState(TableUIState state) { if(state.highlightedCell != -1) diff --git a/imagine/src/gui/TextEntry.cc b/imagine/src/gui/TextEntry.cc index 5db47537b..42c64d3e0 100644 --- a/imagine/src/gui/TextEntry.cc +++ b/imagine/src/gui/TextEntry.cc @@ -53,7 +53,7 @@ bool TextEntry::isAcceptingInput() const bool TextEntry::inputEvent(View &parentView, const Input::Event &e) { - return visit(overloaded + return e.visit(overloaded { [&](const Input::MotionEvent &motionEv) { @@ -109,7 +109,7 @@ bool TextEntry::inputEvent(View &parentView, const Input::Event &e) } return false; } - }, e); + }); } void TextEntry::prepareDraw(Gfx::Renderer &r) @@ -117,7 +117,7 @@ void TextEntry::prepareDraw(Gfx::Renderer &r) t.makeGlyphs(); } -void TextEntry::draw(Gfx::RendererCommands &__restrict__ cmds) +void TextEntry::draw(Gfx::RendererCommands &__restrict__ cmds) const { using namespace Gfx; cmds.basicEffect().enableAlphaTexture(cmds); @@ -227,9 +227,9 @@ void CollectTextInputView::place() }); } -bool CollectTextInputView::inputEvent(const Input::Event &e) +bool CollectTextInputView::inputEvent(const Input::Event& e, ViewInputEventParams) { - if(visit(overloaded + if(e.visit(overloaded { [&](const Input::MotionEvent &e) -> bool { @@ -239,7 +239,7 @@ bool CollectTextInputView::inputEvent(const Input::Event &e) }); }, [&](const Input::KeyEvent &e) { return e.pushed(Input::DefaultKey::CANCEL); } - }, e)) + })) { dismiss(); return true; @@ -275,7 +275,7 @@ void CollectTextInputView::prepareDraw() }); } -void CollectTextInputView::draw(Gfx::RendererCommands &__restrict__ cmds) +void CollectTextInputView::draw(Gfx::RendererCommands &__restrict__ cmds, ViewDrawParams) const { using namespace Gfx; auto &basicEffect = cmds.basicEffect(); diff --git a/imagine/src/gui/TextTableView.cc b/imagine/src/gui/TextTableView.cc index 196d660d6..414710fab 100644 --- a/imagine/src/gui/TextTableView.cc +++ b/imagine/src/gui/TextTableView.cc @@ -39,8 +39,9 @@ void TextTableView::onAddedToController(ViewController *c, const Input::Event &e void TextTableView::drawElement(Gfx::RendererCommands &__restrict__ cmds, size_t i, MenuItem &item, WRect rect, int xIndent) const { - item.draw(cmds, rect.x, rect.pos(C2DO).y, rect.xSize(), rect.ySize(), - xIndent, TableView::align, menuTextColor((int)i == activeItem)); + MenuItemDrawAttrs attrs{.rect = {{rect.x, rect.pos(C2DO).y}, rect.size()}, + .xIndent = xIndent, .color = menuTextColor((int)i == activeItem), .align = TableView::align}; + item.draw(cmds, attrs); } } diff --git a/imagine/src/gui/ToastView.cc b/imagine/src/gui/ToastView.cc index 130466dbb..db63cc11a 100644 --- a/imagine/src/gui/ToastView.cc +++ b/imagine/src/gui/ToastView.cc @@ -83,7 +83,7 @@ void ToastView::prepareDraw() text.makeGlyphs(); } -void ToastView::draw(Gfx::RendererCommands &__restrict__ cmds) +void ToastView::draw(Gfx::RendererCommands &__restrict__ cmds, ViewDrawParams) const { using namespace IG::Gfx; if(!text.isVisible()) @@ -101,9 +101,4 @@ void ToastView::draw(Gfx::RendererCommands &__restrict__ cmds) text.draw(cmds, {msgFrame.xCenter(), msgFrame.pos(C2DO).y}, C2DO, ColorName::WHITE); } -bool ToastView::inputEvent(const Input::Event &event) -{ - return false; -} - } diff --git a/imagine/src/gui/View.cc b/imagine/src/gui/View.cc index 545ddf942..4d99065ec 100644 --- a/imagine/src/gui/View.cc +++ b/imagine/src/gui/View.cc @@ -28,6 +28,24 @@ namespace IG constexpr SystemLogger log{"View"}; +void ViewI::prepareDraw() {} + +bool ViewI::inputEvent(const Input::Event&, ViewInputEventParams) { return false; } + +void ViewI::clearSelection() {} + +void ViewI::onShow() {} + +void ViewI::onHide() {} + +void ViewI::onAddedToController(ViewController *, const Input::Event &) {} + +void ViewI::setFocus(bool) {} + +std::u16string_view ViewI::name() const { return u""; } + +bool ViewI::onDocumentPicked(const DocumentPickerEvent& e) { return false; } + Gfx::Renderer &ViewAttachParams::renderer() const { return rendererTask.renderer(); @@ -163,18 +181,6 @@ int View::navBarHeight(const Gfx::GlyphTextureSet &face) return makeEvenRoundedUp(int(face.nominalHeight() * 1.75f)); } -void View::clearSelection() {} - -void View::onShow() {} - -void View::onHide() {} - -void View::onAddedToController(ViewController *, const Input::Event &) {} - -void View::prepareDraw() {} - -void View::setFocus(bool) {} - void View::setViewRect(WindowRect viewRect, WindowRect displayRect) { this->viewRect_ = viewRect; @@ -210,11 +216,6 @@ Gfx::RendererTask &View::rendererTask() const return *rendererTask_; } -ViewManager &View::manager() -{ - return *manager_; -} - ViewAttachParams View::attachParams() const { return {*manager_, *win, *rendererTask_}; @@ -230,11 +231,6 @@ ApplicationContext View::appContext() const return window().appContext(); } -std::u16string_view View::name() const -{ - return u""; -} - bool View::onDocumentPicked(const DocumentPickerEvent& e) { auto vPtr = parentView(); diff --git a/imagine/src/gui/ViewStack.cc b/imagine/src/gui/ViewStack.cc index deb4f74b6..5b74bf5bd 100644 --- a/imagine/src/gui/ViewStack.cc +++ b/imagine/src/gui/ViewStack.cc @@ -82,7 +82,7 @@ void BasicViewController::place() view->place(); } -bool BasicViewController::inputEvent(const Input::Event &e) +bool BasicViewController::inputEvent(const Input::Event& e) { return view->inputEvent(e); } diff --git a/imagine/src/logger/stdio/logger.cc b/imagine/src/logger/stdio/logger.cc index b62e2cb4e..b118448a3 100755 --- a/imagine/src/logger/stdio/logger.cc +++ b/imagine/src/logger/stdio/logger.cc @@ -107,18 +107,6 @@ static int severityToLogLevel(LoggerSeverity severity) #endif } -constexpr std::string_view severityToColorCode(LoggerSeverity severity) -{ - switch(severity) - { - case LOGGER_DEBUG_MESSAGE: return "\033[1;36m"; - default: [[fallthrough]]; - case LOGGER_MESSAGE: return "\033[0m"; - case LOGGER_WARNING: return "\033[1;33m"; - case LOGGER_ERROR: return "\033[1;31m"; - } -} - void logger_vprintf(LoggerSeverity severity, const char* msg, va_list args) { if(!logEnabled) @@ -159,7 +147,7 @@ void logger_vprintf(LoggerSeverity severity, const char* msg, va_list args) else asl_vlog(nullptr, nullptr, severityToLogLevel(severity), msg, args); #else - fprintf(stderr, "%s", severityToColorCode(severity).data()); + fprintf(stderr, "%s", IG::Log::severityToColorCode(severity)); vfprintf(stderr, msg, args); #endif } @@ -177,34 +165,32 @@ void logger_printf(LoggerSeverity severity, const char* msg, ...) namespace IG::Log { -void print(LoggerSeverity lv, std::string_view tag, std::string_view format, std::format_args args) +void printMsg(LoggerSeverity lv, const char* str, size_t strSize) { - if(!logEnabled || lv > loggerVerbosity) - return; - StaticString<4096> str; - if(Config::envIsLinux) - { - str += severityToColorCode(lv); - } - if(tag.size()) - { - str += tag; - str += ": "; - } - std::vformat_to(std::back_inserter(str), format, args); + const char newLine = '\n'; if(logExternalFile) { - fwrite(str.data(), 1, str.size(), logExternalFile); + fwrite(str, 1, strSize, logExternalFile); + fwrite(&newLine, 1, 1, logExternalFile); fflush(logExternalFile); } #ifdef __ANDROID__ - __android_log_write(severityToLogLevel(lv), "imagine", str.c_str()); + __android_log_write(severityToLogLevel(lv), "imagine", str); #elif defined __APPLE__ - asl_log(nullptr, nullptr, severityToLogLevel(lv), "%s", str.c_str()); + asl_log(nullptr, nullptr, severityToLogLevel(lv), "%s", str); #else - str += '\n'; - fwrite(str.data(), 1, str.size(), stderr); + fwrite(str, 1, strSize, stderr); + fwrite(&newLine, 1, 1, stderr); #endif } +void print(LoggerSeverity lv, std::string_view tag, std::string_view format, std::format_args args) +{ + if(!logEnabled || lv > loggerVerbosity) + return; + StaticString<4096> str; + Log::beginMsg(str, lv, tag, format, args); + printMsg(lv, str.c_str(), str.size()); +} + } diff --git a/imagine/tests/FrameRateTest/src/main/main.cc b/imagine/tests/FrameRateTest/src/main/main.cc index 4bf4a33e7..0c4d3c173 100755 --- a/imagine/tests/FrameRateTest/src/main/main.cc +++ b/imagine/tests/FrameRateTest/src/main/main.cc @@ -137,18 +137,18 @@ void FrameRateTestApplication::updateWindowSurface(Window &win, Window::SurfaceC renderer.task().updateDrawableForSurfaceChange(win, change); } -void FrameRateTestApplication::setPickerHandlers(IG::Window &win) +void FrameRateTestApplication::setPickerHandlers(IG::Window& win) { - win.onEvent = [this, &task = renderer.task()](Window &win, WindowEvent winEvent) + win.onEvent = [this, &task = renderer.task()](Window& win, const WindowEvent& winEvent) { - return visit(overloaded + return winEvent.visit(overloaded { - [&](WindowSurfaceChangeEvent &e) + [&](const WindowSurfaceChangeEvent& e) { updateWindowSurface(win, e.change); return true; }, - [&](DrawEvent &e) + [&](const DrawEvent& e) { return task.draw(win, e.params, {}, [](Window &win, Gfx::RendererCommands &cmds) { @@ -161,7 +161,7 @@ void FrameRateTestApplication::setPickerHandlers(IG::Window &win) cmds.present(); }); }, - [&](Input::Event &e) + [&](const Input::Event& e) { if(e.keyEvent() && e.keyEvent()->pushed(Input::DefaultKey::CANCEL) && !e.keyEvent()->repeated()) { @@ -170,8 +170,8 @@ void FrameRateTestApplication::setPickerHandlers(IG::Window &win) } return windowData(win).picker.inputEvent(e); }, - [](auto &){ return false; } - }, winEvent); + [](auto&){ return false; } + }); }; } @@ -207,16 +207,16 @@ void FrameRateTestApplication::setActiveTestHandlers(IG::Window &win) return true; } }); - win.onEvent = [this, &task = renderer.task()](Window &win, WindowEvent winEvent) + win.onEvent = [this, &task = renderer.task()](Window& win, const WindowEvent& winEvent) { - return visit(overloaded + return winEvent.visit(overloaded { - [&](WindowSurfaceChangeEvent &e) + [&](const WindowSurfaceChangeEvent& e) { updateWindowSurface(win, e.change); return true; }, - [&](DrawEvent &e) + [&](const DrawEvent& e) { auto xIndent = viewManager.tableXIndentPx; return task.draw(win, e.params, {}, [xIndent](IG::Window &win, Gfx::RendererCommands &cmds) @@ -230,12 +230,12 @@ void FrameRateTestApplication::setActiveTestHandlers(IG::Window &win) cmds.present(activeTest->presentTime); }); }, - [&](Input::Event &e) + [&](const Input::Event& e) { auto &activeTest = windowData(win).activeTest; return e.visit(overloaded { - [&](const Input::MotionEvent &motionEv) + [&](const Input::MotionEvent& motionEv) { if(motionEv.pushed() && Config::envIsIOS) { @@ -245,7 +245,7 @@ void FrameRateTestApplication::setActiveTestHandlers(IG::Window &win) } return false; }, - [&](const Input::KeyEvent &keyEv) + [&](const Input::KeyEvent& keyEv) { if(keyEv.pushed(Input::DefaultKey::CANCEL)) { @@ -263,8 +263,8 @@ void FrameRateTestApplication::setActiveTestHandlers(IG::Window &win) } }); }, - [](auto &){ return false; } - }, winEvent); + [](auto&){ return false; } + }); }; }