540 UnInitializeGame(); |
540 UnInitializeGame(); |
541 |
541 |
542 return 0; |
542 return 0; |
543 } |
543 } |
544 |
544 |
|
545 /** Mutex so that only one thread can communicate with the main program |
|
546 * at any given time */ |
|
547 static ThreadMsg _message = 0; |
|
548 |
|
549 static inline void OTTD_ReleaseMutex(void) {_message = 0;} |
|
550 static inline ThreadMsg OTTD_PollThreadEvent(void) {return _message;} |
|
551 |
|
552 /** Called by running thread to execute some action in the main game. |
|
553 * It will stall as long as the mutex is not freed (handled) by the game */ |
|
554 void OTTD_SendThreadMessage(ThreadMsg msg) |
|
555 { |
|
556 while (_message != 0) CSleep(10); |
|
557 |
|
558 _message = msg; |
|
559 } |
|
560 |
|
561 |
|
562 /** Handle the user-messages sent to us |
|
563 * @param message message sent |
|
564 */ |
|
565 void ProcessSentMessage(ThreadMsg message) |
|
566 { |
|
567 switch (message) { |
|
568 case MSG_OTTD_SAVETHREAD_START: SaveFileStart(); break; |
|
569 case MSG_OTTD_SAVETHREAD_DONE: SaveFileDone(); break; |
|
570 case MSG_OTTD_SAVETHREAD_ERROR: SaveFileError(); break; |
|
571 default: NOT_REACHED(); |
|
572 } |
|
573 |
|
574 OTTD_ReleaseMutex(); // release mutex so that other threads, messages can be handled |
|
575 } |
|
576 |
545 static void ShowScreenshotResult(bool b) |
577 static void ShowScreenshotResult(bool b) |
546 { |
578 { |
547 if (b) { |
579 if (b) { |
548 SetDParamStr(0, _screenshot_name); |
580 SetDParamStr(0, _screenshot_name); |
549 ShowErrorMessage(INVALID_STRING_ID, STR_031B_SCREENSHOT_SUCCESSFULLY, 0, 0); |
581 ShowErrorMessage(INVALID_STRING_ID, STR_031B_SCREENSHOT_SUCCESSFULLY, 0, 0); |