Skip to content

Commit

Permalink
Initialize subsystems on first TApplication construction
Browse files Browse the repository at this point in the history
Commit 6ece4c2 restored the original subsystem initialization code. However, this code always ends up calling TScreen::resume. Setting up the display does not work in headless environments or when TERM is not set. Non-graphic applications linking against the library would thus fail to run.

Therefore, it's best to initialize them on the first TApplication construction instead of before main().
  • Loading branch information
magiblot committed Sep 19, 2023
1 parent a70073c commit 3018453
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 17 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ The following are new features not available in Borland's release of Turbo Visio
* Many functions which originally had null-terminated string parameters now receive `TStringView` instead. `TStringView` is compatible with `std::string_view`, `std::string` and `const char *` (even `nullptr`).
* New class `TSpan<T>`, inspired by `std::span`.
* New classes `TDrawSurface` and `TSurfaceView`, see `<tvision/surface.h>`.
* The system integration subsystems (`THardwareInfo`, `TScreen`, `TEventQueue`...) are now initialized when constructing a `TApplication` for the first time, rather than before `main`. They are still destroyed on exit from `main`.
* New method `TVMemMgr::reallocateDiscardable()` which can be used along `allocateDiscardable` and `freeDiscardable`.
* New method `TView::textEvent()` which allows receiving text in an efficient manner, see [Clipboard interaction](#clipboard).
* New class `TClipboard`, see [Clipboard interaction](#clipboard).
Expand Down
11 changes: 10 additions & 1 deletion include/tvision/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,16 @@ class TProgram : public TGroup, public virtual TProgInit
#if defined( Uses_TApplication ) && !defined( __TApplication )
#define __TApplication

class TApplication : public TProgram
class TSubsystemsInit
{

public:

TSubsystemsInit() noexcept;

};

class TApplication : public virtual TSubsystemsInit, public TProgram
{

protected:
Expand Down
1 change: 0 additions & 1 deletion include/tvision/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ class TEventQueue

private:

static TMouse _NEAR mouse;
static Boolean getMouseState( TEvent& ) noexcept;
static Boolean getPasteEvent( TEvent& ) noexcept;
static void getKeyOrPasteEvent( TEvent& ) noexcept;
Expand Down
16 changes: 9 additions & 7 deletions source/tvision/tapplica.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#define Uses_THardwareInfo
#define Uses_TScreen
#define Uses_TObject
#define Uses_TMouse
#define Uses_TApplication
#define Uses_TDeskTop
#include <tvision/tv.h>
Expand All @@ -26,15 +25,18 @@
#include <stdlib.h>
#include <signal.h>

static THardwareInfo hwInfoManager;
TMouse _NEAR TEventQueue::mouse;
static TScreen tsc;
static TEventQueue teq;
static TSystemError sysErr;

void initHistory();
void doneHistory();

TSubsystemsInit::TSubsystemsInit() noexcept
{
static THardwareInfo hwInfoManager;
static TMouse tms;
static TScreen tsc;
static TEventQueue teq;
static TSystemError sysErr;
}

TApplication::TApplication() noexcept :
TProgInit( &TApplication::initStatusLine,
&TApplication::initMenuBar,
Expand Down
12 changes: 6 additions & 6 deletions source/tvision/tevent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,18 @@ TEventQueue::TEventQueue() noexcept

void TEventQueue::resume() noexcept
{
if( mouse.present() == False )
mouse.resume();
if( mouse.present() == False )
if( TMouse::present() == False )
TMouse::resume();
if( TMouse::present() == False )
return;

mouse.getEvent( curMouse );
TMouse::getEvent( curMouse );
lastMouse = curMouse;

#if defined( __FLAT__ )
THardwareInfo::clearPendingEvent();
#else
mouse.registerHandler( 0xFFFF, (void (_FAR *)()) mouseInt );
TMouse::registerHandler( 0xFFFF, (void (_FAR *)()) mouseInt );
#endif

mouseEvents = True;
Expand All @@ -95,7 +95,7 @@ void TEventQueue::resume() noexcept

void TEventQueue::suspend() noexcept
{
mouse.suspend();
TMouse::suspend();
}

TEventQueue::~TEventQueue()
Expand Down
4 changes: 2 additions & 2 deletions source/tvision/tprogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ void TProgram::setScreenMode( ushort mode )
{
TRect r;

TEventQueue::mouse.hide(); //HideMouse();
TMouse::hide();
TScreen::setVideoMode( mode );
initScreen();
buffer = TScreen::screenBuffer;
Expand All @@ -325,7 +325,7 @@ void TProgram::setScreenMode( ushort mode )
setState(sfExposed, False);
setState(sfExposed, True);
redraw();
TEventQueue::mouse.show(); //ShowMouse();
TMouse::show();
}

TTimerId TProgram::setTimer( uint timeoutMs, int periodMs )
Expand Down

0 comments on commit 3018453

Please sign in to comment.