|
Odamex
Setting the Standard in Multiplayer Doom
|
00001 // Emacs style mode select -*- C++ -*- 00002 //----------------------------------------------------------------------------- 00003 // 00004 // $Id: dlg_main.h 2042 2010-12-13 21:20:42Z russellrice $ 00005 // 00006 // Copyright (C) 2006-2010 by The Odamex Team. 00007 // 00008 // This program is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU General Public License 00010 // as published by the Free Software Foundation; either version 2 00011 // of the License, or (at your option) any later version. 00012 // 00013 // This program is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // DESCRIPTION: 00019 // User interface 00020 // AUTHOR: Russell Rice, John D Corrado 00021 // 00022 //----------------------------------------------------------------------------- 00023 00024 #ifndef DLG_MAIN_H 00025 #define DLG_MAIN_H 00026 00027 #include "lst_players.h" 00028 #include "lst_servers.h" 00029 #include "lst_srvdetails.h" 00030 00031 #include "dlg_about.h" 00032 #include "dlg_config.h" 00033 #include "dlg_servers.h" 00034 #include "frm_odaget.h" 00035 00036 #include <wx/frame.h> 00037 #include <wx/intl.h> 00038 #include <wx/settings.h> 00039 #include <wx/sizer.h> 00040 #include <wx/stattext.h> 00041 #include <wx/xrc/xmlres.h> 00042 #include <wx/splitter.h> 00043 #include "wx/dynarray.h" 00044 00045 #include <vector> 00046 00047 #include "query_thread.h" 00048 #include "net_packet.h" 00049 00050 // custom event declarations 00051 BEGIN_DECLARE_EVENT_TYPES() 00052 DECLARE_EVENT_TYPE(wxEVT_THREAD_MONITOR_SIGNAL, -1) 00053 DECLARE_EVENT_TYPE(wxEVT_THREAD_WORKER_SIGNAL, -1) 00054 END_DECLARE_EVENT_TYPES() 00055 00056 typedef enum 00057 { 00058 _oda_iav_MIN = 0 // Minimum range 00059 00060 ,_oda_iav_SUCCESS // Address is valid 00061 ,_oda_iav_FAILURE // Unknown error 00062 00063 ,_oda_iav_emptystr // Empty address parameter 00064 ,_oda_iav_interr // Internal error (regex comp error, bad regex) 00065 ,_oda_iav_colerr // Bad or nonexistant substring after colon 00066 00067 ,_oda_iav_NUMERR // Number of errors (incl min range) 00068 00069 ,_oda_iav_MAX // Maximum range 00070 } _oda_iav_err_t; 00071 00072 00073 class dlgMain : public wxFrame, wxThreadHelper 00074 { 00075 public: 00076 00077 dlgMain(wxWindow* parent,wxWindowID id = -1); 00078 virtual ~dlgMain(); 00079 00080 Server NullServer; 00081 Server *QServer; 00082 MasterServer MServer; 00083 00084 launchercfg_t launchercfg_s; 00085 protected: 00086 void OnMenuServers(wxCommandEvent& event); 00087 void OnManualConnect(wxCommandEvent& event); 00088 00089 void OnOpenSettingsDialog(wxCommandEvent& event); 00090 void OnOpenOdaGet(wxCommandEvent &event); 00091 void OnOpenWebsite(wxCommandEvent &event); 00092 void OnOpenForum(wxCommandEvent &event); 00093 void OnOpenWiki(wxCommandEvent &event); 00094 void OnOpenChangeLog(wxCommandEvent& event); 00095 void OnOpenReportBug(wxCommandEvent &event); 00096 void OnAbout(wxCommandEvent& event); 00097 00098 void OnQuickLaunch(wxCommandEvent &event); 00099 void OnLaunch(wxCommandEvent &event); 00100 void OnRefreshAll(wxCommandEvent &event); 00101 void OnGetList(wxCommandEvent &event); 00102 void OnRefreshServer(wxCommandEvent& event); 00103 00104 void OnServerListClick(wxListEvent& event); 00105 void OnServerListDoubleClick(wxListEvent& event); 00106 00107 void OnShow(wxShowEvent &event); 00108 void OnClose(wxCloseEvent &event); 00109 00110 void OnExit(wxCommandEvent& event); 00111 00112 wxInt32 FindServer(wxString); 00113 wxInt32 FindServerInList(wxString); 00114 wxInt32 GetSelectedServerListIndex(); 00115 wxInt32 GetSelectedServerArrayIndex(); 00116 00117 _oda_iav_err_t IsAddressValid(wxString, wxString &, long &); 00118 00119 void LaunchGame(const wxString &Address, const wxString &ODX_Path, 00120 const wxString &waddirs, const wxString &Password = wxT("")); 00121 00122 LstOdaServerList *m_LstCtrlServers; 00123 LstOdaPlayerList *m_LstCtrlPlayers; 00124 LstOdaSrvDetails *m_LstOdaSrvDetails; 00125 00126 dlgConfig *config_dlg; 00127 dlgServers *server_dlg; 00128 dlgAbout *AboutDialog; 00129 frmOdaGet *OdaGet; 00130 00131 wxInt32 TotalPlayers; 00132 wxInt32 QueriedServers; 00133 /* 00134 Our threading system 00135 00136 Monitor Thread: 00137 --------------- 00138 Stays in an infinite loop, continually monitoring the RequestSignal 00139 variable, if it encounters a signal change it will run the command 00140 and then call the OnMonitorSignal callback function with the 00141 appropriate parameters or nothing if it timed out. 00142 When I say "infinite loop", its more of a pseudo one obviously, 00143 have to terminate it when the user exits ;) 00144 00145 Worker Threads: 00146 --------------- 00147 These get activated by the monitor thread and are controlled by it. 00148 They are an array of threads which send signals to the monitor 00149 thread to tell it what the status is. 00150 00151 */ 00152 00153 // Monitor Thread Command Signals 00154 // Sends a signal to the monitoring thread to instruct it to carry out 00155 // a command of some sort (get a list of servers for example) 00156 typedef enum 00157 { 00158 mtcs_none 00159 ,mtcs_getmaster 00160 ,mtcs_getsingleserver 00161 ,mtcs_getservers 00162 ,mtcs_exit // Shutdown now! 00163 00164 ,mtcs_max 00165 } mtcs_t; 00166 00167 typedef struct 00168 { 00169 mtcs_t Signal; 00170 wxInt32 Index; 00171 wxInt32 ServerListIndex; 00172 } mtcs_struct_t; 00173 00174 // Only set these below if you got a response! 00175 // [Russell] - iirc, volatile on a struct doesn't work as well as it 00176 // should 00177 mtcs_struct_t mtcs_Request; 00178 00179 // Monitor Thread Return Signals 00180 // The result of the signal sent above, sent to the callback function 00181 // below 00182 typedef enum 00183 { 00184 mtrs_master_success 00185 ,mtrs_master_timeout // Dead 00186 00187 ,mtrs_server_singlesuccess // represents a single selected server 00188 ,mtrs_server_singletimeout 00189 00190 ,mtrs_server_noservers // There are no servers to query! 00191 00192 ,mtrs_servers_querydone // Query of all servers complete 00193 00194 ,mtrs_max 00195 } mtrs_t; 00196 00197 typedef struct 00198 { 00199 mtrs_t Signal; 00200 wxInt32 Index; 00201 wxInt32 ServerListIndex; 00202 } mtrs_struct_t; 00203 00204 mtrs_struct_t mtrs_Result; 00205 00206 typedef enum 00207 { 00208 wtrs_server_success 00209 ,wtrs_server_timeout 00210 00211 ,wtrs_max 00212 } wtrs_t; 00213 00214 typedef struct 00215 { 00216 wtrs_t Signal; 00217 wxInt32 Index; 00218 wxInt32 ServerListIndex; 00219 } wtrs_struct_t; 00220 00221 wtrs_struct_t wtrs_Result; 00222 00223 // Posts a message from the main thread to the monitor thread 00224 bool MainThrPostEvent(mtcs_t CommandSignal, wxInt32 Index = -1, 00225 wxInt32 ListIndex = -1); 00226 00227 // Posts a message from a secondary thread to the main thread 00228 void MonThrPostEvent(wxEventType EventType, int win_id, mtrs_t Signal, 00229 wxInt32 Index, wxInt32 ListIndex); 00230 00231 // Various functions for communicating with masters and servers 00232 bool MonThrGetMasterList(); 00233 void MonThrGetServerList(); 00234 void MonThrGetSingleServer(); 00235 00236 void OnMonitorSignal(wxCommandEvent&); 00237 void OnWorkerSignal(wxCommandEvent&); 00238 // Our monitoring thread entry point, from wxThreadHelper 00239 void *Entry(); 00240 00241 std::vector<QueryThread*> threadVector; 00242 00243 private: 00244 00245 DECLARE_EVENT_TABLE() 00246 }; 00247 00248 #endif