Try / Tempest

API abstraction layer for 3D graphics, UI and sound. Written in C++17 with Vulkan, DX12 and Metal support.
MIT License
107 stars 27 forks source link

X11 improvements #8

Closed d10sfan closed 4 years ago

d10sfan commented 4 years ago

This is a work in progress implementation for a few of the missing X11 graphics features, mainly full screen and cursor support.

The X11 fullscreen and isFullScreen should now work, along with the cursor hiding.

I had some questions regarding the rest:

Try commented 4 years ago

recommended way to log

#include <Tempest/Log>
// functions:
Log::i - info
Log::d - debug
Log::e - error
// usage example
Log::d("x = ", npc->position().x," y = ",npc->position().y);

Could there be an issue with my implementation of looking for the full screen flag?

Normally it not suppose to work like that. The idea is: implCreateWindow(Tempest::Window*,SystemApi::ShowMode) - creates a windows with default size, and specified show-mode. Possible usage - implCreateWindow(nullptr,SystemApi::Maximized) implCreateWindow(Tempest::Window *owner, uint32_t w, uint32_t h) - creates a window with specified size and ShowMode = Normal.

Workflow for opengothic:

  1. create 1x1 Hidden window to query Vulkan-queues properties
  2. delete this hidden window
  3. create Maximized window for game itself
  4. switch to fullscreen, if necessary(mainwindow.cpp):
    if(!gothic.isWindowMode())
    setFullscreen(true);

    When is this function usually called?

There is only one place:

void MainWindow::mouseMoveEvent(MouseEvent &event) {
  const bool fs = SystemApi::isFullscreen(hwnd());
  if(fs) {
    if(auto camera = gothic.gameCamera())
      spin = camera->getSpin();
    processMouse(event,true);
    mpos = Point(w()/2,h()/2);
    SystemApi::setCursorPosition(mpos.x,mpos.y);
    }
  }

Idea is similar to behavior of original game: read mouse position change in mouseMoveEvent and then return cursor to center of game window.

d10sfan commented 4 years ago

I've pushed some improvements to this:

Remaining issues:

Other than that, the graphics side of things seem to be working ok from a quick glance.

Try commented 4 years ago

I've tried to setup window creation on VirtualMachine: have a similar result: for simple X11 app XChangeProperty doesn't take any effect on already created window, meanwhile XSenEvent works:

bool X11Api::implSetAsFullscreen(SystemApi::Window *w, bool fullScreen) {
  XEvent e = {};
  e.xclient.type         = ClientMessage;
  e.xclient.window       = HWND(w);
  e.xclient.message_type = _NET_WM_STATE();
  e.xclient.format       = 32;
  e.xclient.data.l[0]    = 2;    // _NET_WM_STATE_TOGGLE
  e.xclient.data.l[1]    = _NET_WM_STATE_FULLSCREEN();
  e.xclient.data.l[2]    = 0;    // no second property to toggle
  e.xclient.data.l[3]    = 1;

  XSendEvent(dpy, DefaultRootWindow(dpy), False, SubstructureRedirectMask | SubstructureNotifyMask, &e);
  return true;
  }

Unfortunately, still can't figure-out what is wrong about XChangeProperty

d10sfan commented 4 years ago

Thanks, I tried XSendEvent and that seemed to work, as the extra call for setFullScreen was no longer needed. I went ahead and pushed that change up.

I updated implSetCursorPosition to use the root window instead of the windows->first. I tried doing the same to implShowCursor but that resulted in the cursor still being visible.

Try commented 4 years ago

Hi, @d10sfan !

Your PR look good to me, since it still marked as WIP, just want to ask: Are you ok to merge now, and create a followup tickets for known linux issues:

d10sfan commented 4 years ago

Yeah I think this one is good to merge. I'll see what I can find out above the left and right issue. I believe it may have been introduced in a recent game update. I'll try to narrow it down which commit may have done it, or if it's something in my code.

d10sfan commented 4 years ago

I created a ticket for the mouse movement issue (https://github.com/Try/MoltenTempest/issues/12). Figured you could assign that to me if you want and I'll research into it what could be happening.