Skip to content

Commit 01fb52b

Browse files
committed
Added detection of which window the mouse is over
- Do not run scripts or redraw if the window is out of focus and the mouse is not over the window. Also the following reverts: Revert "Fix stuff for mingw-w64 only" This reverts commit 805e29c. Revert "Switch to blocking RunMessages when possible" This reverts commit 6d36731.
1 parent 9bed479 commit 01fb52b

16 files changed

Lines changed: 78 additions & 124 deletions

engine/common.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ class textBuffer_c {
8787
// Constants
8888
// =========
8989

90-
#ifndef M_PI
91-
# define M_PI 3.14159265358979323846f
92-
#endif
90+
#define M_PI 3.14159265358979323846f
9391

9492
static const char axchr[] = {'X', 'Y', 'Z', 'W'};
9593

engine/core/core_image.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,12 +370,12 @@ struct jpegError_s: public jpeg_error_mgr {
370370
char buffer[JMSG_LENGTH_MAX];
371371
(*cinfo->err->format_message)(cinfo, buffer);
372372
clientData_s* cd = (clientData_s*)cinfo->client_data;
373-
//cd->con->Warning("JPEG '%s': %s", cd->fileName, buffer);
373+
cd->con->Warning("JPEG '%s': %s", cd->fileName, buffer);
374374
}
375375
static void FatalError(j_common_ptr cinfo)
376376
{
377377
MSGOut(cinfo);
378-
//throw 1;
378+
throw 1;
379379
}
380380
};
381381

engine/core/core_main.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ class core_main_c: public core_IMain {
2727
void KeyEvent(int key, int type);
2828
bool CanExit();
2929

30-
int SubScriptCount();
31-
3230
// Encapsulated
3331
core_main_c(sys_IMain* sysHnd);
3432

@@ -83,8 +81,7 @@ void core_main_c::Init(int argc, char** argv)
8381

8482
void core_main_c::Frame()
8583
{
86-
// causes a livelock?
87-
// sys->con->Printf("Messages...\n");
84+
sys->con->Printf("Messages...\n");
8885

8986
// Execute commands
9087
sys->con->ExecCommands();
@@ -125,8 +122,3 @@ bool core_main_c::CanExit()
125122

126123
return ui->CanExit();
127124
}
128-
129-
int core_main_c::SubScriptCount()
130-
{
131-
return ui->SubScriptCount();
132-
}

engine/core/core_main.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,5 @@ class core_IMain {
1919
virtual void Shutdown() = 0;
2020
virtual void KeyEvent(int key, int type) = 0;
2121
virtual bool CanExit() = 0;
22-
23-
virtual int SubScriptCount() = 0;
2422
};
2523

engine/system/sys_console.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class sys_IConsole {
1414
static sys_IConsole* GetHandle(class sys_IMain* sysHnd);
1515
static void FreeHandle(sys_IConsole* hnd);
1616

17-
virtual void SetVisible(bool show) = 0; // Set window state
17+
virtual void SetVisible( bool show ) = 0; // Set window state
18+
virtual bool IsVisible() = 0; // Get window state
1819
virtual void SetTitle(const char* title) = 0; // Set window title
1920
};

engine/system/sys_video.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,10 @@ class sys_IVideo {
5555
virtual void PosChanged(int x, int y) = 0; // Respond to window position change
5656
virtual void GetMinSize(int &width, int &height) = 0; // Get minimum window size
5757
virtual void SetVisible(bool vis) = 0; // Show/hide window
58+
virtual bool IsVisible() = 0; // Get whether the window is shown
5859
virtual void SetTitle(const char* title) = 0;// Change window title
5960
virtual void* GetWindowHandle() = 0; // Get window handle
6061
virtual void GetRelativeCursor(int &x, int &y) = 0; // Get cursor position relative to window
6162
virtual void SetRelativeCursor(int x, int y) = 0; // Set cursor position relative to window
63+
virtual bool IsCursorOverWindow() = 0; // Get whether the cursor is over the window, including obstructions
6264
};

engine/system/win/sys_console.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class sys_console_c: public sys_IConsole, public conPrintHook_c, public thread_c
2424
public:
2525
// Interface
2626
void SetVisible(bool show);
27+
bool IsVisible();
2728
void SetTitle(const char* title);
2829

2930
// Encapsulated
@@ -69,8 +70,7 @@ sys_console_c::sys_console_c(sys_IMain* sysHnd)
6970
doRun = true;
7071

7172
ThreadStart(true);
72-
while ( !isRunning )
73-
Sleep(15);
73+
while ( !isRunning );
7474
}
7575

7676
void sys_console_c::ThreadProc()
@@ -132,17 +132,16 @@ void sys_console_c::ThreadProc()
132132
bBackground = CreateSolidBrush(CFG_SCON_TEXTBG);
133133

134134
// Flush any messages created
135-
sys->RunMessages(NULL, true);
135+
sys->RunMessages();
136136

137137
shown = true;
138138

139139
InstallPrintHook();
140140

141141
isRunning = true;
142-
143142
while (doRun) {
144-
sys->RunMessages(NULL, false, 100);
145-
//sys->Sleep(1);
143+
sys->RunMessages(hwMain);
144+
sys->Sleep(1);
146145
}
147146

148147
RemovePrintHook();
@@ -161,8 +160,7 @@ void sys_console_c::ThreadProc()
161160
sys_console_c::~sys_console_c()
162161
{
163162
doRun = false;
164-
while (isRunning)
165-
Sleep(15);
163+
while (isRunning);
166164
}
167165

168166
// ========================
@@ -214,7 +212,7 @@ void sys_console_c::SetVisible(bool show)
214212
Print(buffer);
215213
delete buffer;
216214

217-
sys->RunMessages(NULL, true);
215+
sys->RunMessages(hwMain);
218216
}
219217
} else {
220218
shown = false;
@@ -224,6 +222,11 @@ void sys_console_c::SetVisible(bool show)
224222
}
225223
}
226224

225+
bool sys_console_c::IsVisible()
226+
{
227+
return IsWindowVisible(hwMain);
228+
}
229+
227230
void sys_console_c::SetTitle(const char* title)
228231
{
229232
SetWindowText(hwMain, (title && *title)? title : CFG_SCON_TITLE);
@@ -272,7 +275,7 @@ void sys_console_c::Print(const char* text)
272275
Edit_SetSel(hwOut, Edit_GetTextLength(hwOut), -1);
273276
Edit_ReplaceSel(hwOut, winText);
274277
Edit_Scroll(hwOut, 0xFFFF, 0);
275-
sys->RunMessages(NULL, true);
278+
sys->RunMessages(hwMain);
276279
delete winText;
277280
}
278281

engine/system/win/sys_local.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#include "system.h"
1111

12-
#undef _WIN32_WINNT
1312
#define _WIN32_WINNT _WIN32_WINNT_WINXP
1413
#define WIN32_LEAN_AND_MEAN
1514
#include <windows.h>
@@ -45,7 +44,7 @@ class sys_main_c: public sys_IMain {
4544
bool Run(int argc, char** argv);
4645

4746
static LRESULT __stdcall WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
48-
int RunMessages(HWND hwnd, bool slurp, unsigned timeout = 0);
47+
void RunMessages(HWND hwnd = NULL);
4948
void PrintLastError(const char* msg);
5049

5150
int KeyToVirtual(byte key);

engine/system/win/sys_main.cpp

Lines changed: 15 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111

1212
#include <eh.h>
1313

14-
#if defined __MINGW32__
15-
# define _set_se_translator(x) ((void)0)
16-
#endif
17-
1814
// ======
1915
// Locals
2016
// ======
@@ -639,63 +635,17 @@ LRESULT __stdcall sys_main_c::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
639635
return DefWindowProc(hwnd, msg, wParam, lParam);
640636
}
641637

642-
int sys_main_c::RunMessages(HWND hwnd, bool slurp, unsigned timeout)
638+
void sys_main_c::RunMessages(HWND hwnd)
643639
{
640+
// Flush message queue
644641
MSG msg;
645-
unsigned ret;
646-
unsigned nmsg = 0;
647-
648-
if (timeout == 0)
649-
timeout = 250;
650-
651-
for (;;)
652-
{
653-
// take care of non-blocking, blocking, and block+timeout message reads
654-
if (slurp)
655-
{
656-
if (PeekMessage(&msg, hwnd, 0, 0, PM_NOREMOVE))
657-
{
658-
ret = GetMessage(&msg, hwnd, 0, 0);
659-
}
660-
else
661-
break;
662-
}
663-
else
664-
{
665-
static const UINT_PTR TIMER_ID = 1042;
666-
UINT_PTR id = hwnd ? TIMER_ID : 0;
667-
id = SetTimer(hwnd, id, timeout, NULL);
668-
ret = GetMessage(&msg, hwnd, 0, 0);
669-
(void) KillTimer(hwnd, id);
670-
if (ret != unsigned(-1) && ret != 0)
671-
{
672-
if (msg.message == WM_TIMER && msg.wParam == id)
673-
break;
674-
}
675-
}
676-
677-
// deal error, window destruction, and valid messages respectively
678-
if (ret == unsigned(-1))
679-
break;
680-
else if (ret == 0)
681-
{
682-
nmsg++;
642+
while (PeekMessage(&msg, hwnd, 0, 0, PM_NOREMOVE)) {
643+
if (GetMessage(&msg, hwnd, 0, 0) == 0) {
683644
Exit();
684-
break;
685645
}
686-
else
687-
{
688-
nmsg++;
689-
TranslateMessage(&msg);
690-
DispatchMessage(&msg);
691-
}
692-
693-
// one message is enough in case of blocking reads
694-
if (!slurp && !PeekMessage(&msg, hwnd, 0, 0, PM_NOREMOVE))
695-
break;
646+
TranslateMessage(&msg);
647+
DispatchMessage(&msg);
696648
}
697-
698-
return nmsg;
699649
}
700650

701651
// ==============================
@@ -729,8 +679,8 @@ void sys_main_c::Error(char *fmt, ...)
729679

730680
exitFlag = false;
731681
while (exitFlag == false) {
732-
RunMessages(NULL, false, 1000);
733-
//Sleep(50);
682+
RunMessages();
683+
Sleep(50);
734684
}
735685

736686
#ifdef _MEMTRAK_H
@@ -813,20 +763,21 @@ bool sys_main_c::Run(int argc, char** argv)
813763
con->Printf("\n");
814764

815765
initialised = true;
766+
816767
try {
817768
// Enable translation to catch C exceptions if debugger is not present
818769
if ( !debuggerRunning ) {
819770
_set_se_translator(SE_ErrorTrans);
820771
}
772+
821773
// Initialise engine
822774
core->Init(argc, argv);
775+
823776
// Run frame loop
824777
while (exitFlag == false) {
825-
int nsubscript = core->SubScriptCount();
826-
int nmsg = RunMessages(NULL, false);
778+
RunMessages();
827779

828-
if (nsubscript || nmsg)
829-
core->Frame();
780+
core->Frame();
830781

831782
if (threadError) {
832783
Error(threadError);
@@ -862,8 +813,8 @@ bool sys_main_c::Run(int argc, char** argv)
862813
exitMsg = NULL;
863814
}
864815
while (exitFlag == false) {
865-
RunMessages(NULL, false);
866-
//Sleep(50);
816+
RunMessages();
817+
Sleep(50);
867818
}
868819
}
869820

engine/system/win/sys_opengl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ void sys_openGL_c::Swap()
166166

167167
void* sys_openGL_c::GetProc(char* name)
168168
{
169-
return (void*) wglGetProcAddress(name);
169+
return wglGetProcAddress(name);
170170
}
171171

172172
bool sys_openGL_c::CaptureSecondary()

0 commit comments

Comments
 (0)