PlugInManager.cpp 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666
  1. /*
  2. ===========================================================================
  3. Copyright (C) 1999-2005 Id Software, Inc.
  4. This file is part of Quake III Arena source code.
  5. Quake III Arena source code is free software; you can redistribute it
  6. and/or modify it under the terms of the GNU General Public License as
  7. published by the Free Software Foundation; either version 2 of the License,
  8. or (at your option) any later version.
  9. Quake III Arena source code is distributed in the hope that it will be
  10. useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with Foobar; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  16. ===========================================================================
  17. */
  18. // PlugInManager.cpp: implementation of the CPlugInManager class.
  19. //
  20. //////////////////////////////////////////////////////////////////////
  21. #include "stdafx.h"
  22. #include "io.h"
  23. #include "Radiant.h"
  24. #include "PlugInManager.h"
  25. #include "PlugIn.h"
  26. #include "DialogInfo.h"
  27. #include "pakstuff.h"
  28. #ifdef _DEBUG
  29. #undef THIS_FILE
  30. static char THIS_FILE[]=__FILE__;
  31. #define new DEBUG_NEW
  32. #endif
  33. //////////////////////////////////////////////////////////////////////
  34. // Construction/Destruction
  35. //////////////////////////////////////////////////////////////////////
  36. CPlugInManager::CPlugInManager()
  37. {
  38. m_pTexturePlug = NULL;
  39. m_pSurfaceListPlug = NULL;
  40. PatchesMode = EActivePatches;
  41. }
  42. CPlugInManager::~CPlugInManager()
  43. {
  44. Cleanup();
  45. }
  46. void CPlugInManager::Init(const char * pPath)
  47. {
  48. Cleanup();
  49. // set some globals
  50. g_qeglobals.bSurfacePropertiesPlugin = false;
  51. g_qeglobals.bBSPFrontendPlugin = false;
  52. CString strPath(pPath);
  53. strPath += "*.dll";
  54. bool bGo = true;
  55. struct _finddata_t fileinfo;
  56. int handle = _findfirst (strPath, &fileinfo);
  57. if (handle != -1)
  58. {
  59. do
  60. {
  61. strPath.Format("%s\\%s", pPath, fileinfo.name);
  62. CPlugIn *pPlug = new CPlugIn();
  63. if (pPlug->load(strPath))
  64. {
  65. if(FillFuncTable(pPlug)) // PGM
  66. {
  67. m_PlugIns.Add(pPlug);
  68. pPlug->RegisterPluginEntities();
  69. // if this thing handles surface properties
  70. pPlug->InitSurfacePlugin();
  71. // will test and init if it's a BSP frontend
  72. pPlug->InitBSPFrontendPlugin();
  73. g_pParentWnd->AddPlugInMenuItem(pPlug);
  74. // if this thing handles textures
  75. if (pPlug->getTextureInfo() != NULL)
  76. {
  77. this->m_pTexturePlug = pPlug;
  78. // if this is a wad style texture extension, have it load everything now
  79. if (pPlug->getTextureInfo()->m_bWadStyle)
  80. {
  81. CString strPath = ValueForKey(g_qeglobals.d_project_entity, "texturepath");
  82. pPlug->loadTexture(strPath);
  83. }
  84. }
  85. if (pPlug->getSurfaceFlags() != NULL)
  86. {
  87. this->m_pSurfaceListPlug = pPlug;
  88. }
  89. }
  90. else
  91. {
  92. delete pPlug; // PGM
  93. }
  94. }
  95. else
  96. {
  97. delete pPlug;
  98. }
  99. } while (_findnext( handle, &fileinfo ) != -1);
  100. _findclose (handle);
  101. }
  102. }
  103. void CPlugInManager::Cleanup()
  104. {
  105. int i;
  106. for (i = 0; i < m_PlugIns.GetSize(); i++)
  107. {
  108. CPlugIn *plug = reinterpret_cast<CPlugIn*>(m_PlugIns.GetAt(i));
  109. plug->free();
  110. delete plug;
  111. }
  112. m_PlugIns.RemoveAll();
  113. for (i = 0; i < m_BrushHandles.GetSize(); i++)
  114. {
  115. brush_t *pb = reinterpret_cast<brush_t*>(m_BrushHandles.GetAt(i));
  116. Brush_Free(pb);
  117. }
  118. m_BrushHandles.RemoveAll();
  119. for (i = 0; i < m_EntityHandles.GetSize(); i++)
  120. {
  121. entity_t *pe = reinterpret_cast<entity_t*>(m_EntityHandles.GetAt(i));
  122. Entity_Free(pe);
  123. }
  124. m_EntityHandles.RemoveAll();
  125. // patches
  126. // these are linked into the map
  127. m_PatchesHandles.RemoveAll();
  128. // these patches were allocated by Radiant on plugin request
  129. // if the list is not empty, it means either the plugin asked for allocation and never commited them to the map
  130. // in which case we are supposed to delete them
  131. // or it commited them but never called m_pfnReleasePatchHandles, in case the patches may have already been
  132. // erased and we are trying a second time, therefore crashing ..
  133. //++timo FIXME: for now I leave a leak warning, we'd need a table to keep track of commited patches
  134. #ifdef _DEBUG
  135. if (m_PluginPatches.GetSize() != 0)
  136. Sys_Printf("WARNING: m_PluginPatches.GetSize() != 0 in CPlugInManager::Cleanup, possible leak\n");
  137. #endif
  138. /* for (i = 0; i < m_PluginPatches.GetSize(); i++)
  139. {
  140. patchMesh_t *pMesh = reinterpret_cast<patchMesh_t*>(m_PluginPatches.GetAt(i));
  141. if (pMesh->pSymbiot)
  142. delete pMesh;
  143. }
  144. m_PluginPatches.RemoveAll(); */
  145. }
  146. void CPlugInManager::Dispatch(int n, const char * p)
  147. {
  148. for (int i = 0; i < m_PlugIns.GetSize(); i++)
  149. {
  150. CPlugIn *plug = reinterpret_cast<CPlugIn*>(m_PlugIns.GetAt(i));
  151. if (plug->ownsCommandID(n))
  152. {
  153. vec3_t vMin, vMax;
  154. if (selected_brushes.next == &selected_brushes)
  155. {
  156. vMin[0] = vMin[1] = vMin[2] = 0;
  157. VectorCopy(vMin, vMax);
  158. }
  159. else
  160. {
  161. Select_GetBounds (vMin, vMax);
  162. }
  163. plug->dispatchCommand(p, vMin, vMax, QE_SingleBrush(true)); // PGM -- added quiet
  164. break;
  165. }
  166. }
  167. }
  168. // creates a dummy brush in the active brushes list
  169. // FIXME : is this one really USED ?
  170. void WINAPI QERApp_CreateBrush(vec3_t vMin, vec3_t vMax)
  171. {
  172. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  173. brush_t* pBrush = Brush_Create(vMin, vMax, &g_qeglobals.d_texturewin.texdef);
  174. Entity_LinkBrush (world_entity, pBrush);
  175. Brush_Build(pBrush);
  176. Brush_AddToList (pBrush, &active_brushes);
  177. Select_Brush(pBrush);
  178. Sys_UpdateWindows(W_ALL);
  179. }
  180. LPVOID CPlugInManager::CreateBrushHandle()
  181. {
  182. brush_t *pb = Brush_Alloc();
  183. pb->numberId = g_nBrushId++;
  184. m_BrushHandles.Add(pb);
  185. return (LPVOID)pb;
  186. }
  187. void CPlugInManager::DeleteBrushHandle(void * vp)
  188. {
  189. CPtrArray* pHandles[3];
  190. pHandles[0] = &m_SelectedBrushHandles;
  191. pHandles[1] = &m_ActiveBrushHandles;
  192. pHandles[2] = &m_BrushHandles;
  193. for (int j = 0; j < 3; j++)
  194. {
  195. for (int i = 0; i < pHandles[j]->GetSize(); i++)
  196. {
  197. brush_t *pb = reinterpret_cast<brush_t*>(pHandles[j]->GetAt(i));
  198. if (pb == reinterpret_cast<brush_t*>(vp))
  199. {
  200. if (j == 2)
  201. {
  202. // only remove it from the list if it is work area
  203. // this allows the selected and active list indexes to remain constant
  204. // throughout a session (i.e. between an allocate and release)
  205. pHandles[j]->RemoveAt(i);
  206. }
  207. Brush_Free(pb);
  208. Sys_MarkMapModified(); // PGM
  209. return;
  210. }
  211. }
  212. }
  213. }
  214. void CPlugInManager::CommitBrushHandleToMap(void * vp)
  215. {
  216. g_bScreenUpdates = false;
  217. for (int i = 0; i < m_BrushHandles.GetSize(); i++)
  218. {
  219. brush_t *pb = reinterpret_cast<brush_t*>(m_BrushHandles.GetAt(i));
  220. if (pb == reinterpret_cast<brush_t*>(vp))
  221. {
  222. m_BrushHandles.RemoveAt(i);
  223. Entity_LinkBrush (world_entity, pb);
  224. Brush_Build(pb);
  225. Brush_AddToList (pb, &active_brushes);
  226. Select_Brush(pb);
  227. }
  228. }
  229. g_bScreenUpdates = true;
  230. Sys_UpdateWindows(W_ALL);
  231. }
  232. void CPlugInManager::AddFaceToBrushHandle(void * vp, vec3_t v1, vec3_t v2, vec3_t v3)
  233. {
  234. brush_t *bp = FindBrushHandle(vp);
  235. if (bp != NULL)
  236. {
  237. face_t *f = Face_Alloc();
  238. f->texdef = g_qeglobals.d_texturewin.texdef;
  239. f->texdef.flags &= ~SURF_KEEP;
  240. f->texdef.contents &= ~CONTENTS_KEEP;
  241. f->next = bp->brush_faces;
  242. bp->brush_faces = f;
  243. VectorCopy (v1, f->planepts[0]);
  244. VectorCopy (v2, f->planepts[1]);
  245. VectorCopy (v3, f->planepts[2]);
  246. }
  247. }
  248. brush_t* CPlugInManager::FindBrushHandle(void * vp)
  249. {
  250. CPtrArray* pHandles[4];
  251. pHandles[0] = &m_SelectedBrushHandles;
  252. pHandles[1] = &m_ActiveBrushHandles;
  253. pHandles[2] = &m_BrushHandles;
  254. pHandles[3] = &m_EntityBrushHandles;
  255. for (int j = 0; j < 4; j++)
  256. {
  257. for (int i = 0; i < pHandles[j]->GetSize(); i++)
  258. {
  259. brush_t *pb = reinterpret_cast<brush_t*>(pHandles[j]->GetAt(i));
  260. if (pb == reinterpret_cast<brush_t*>(vp))
  261. {
  262. return pb;
  263. }
  264. }
  265. }
  266. return NULL;
  267. }
  268. patchMesh_t* CPlugInManager::FindPatchHandle(int index)
  269. {
  270. switch (PatchesMode)
  271. {
  272. case EActivePatches:
  273. case ESelectedPatches:
  274. if ( index < m_PatchesHandles.GetSize() )
  275. {
  276. brush_t *pb = reinterpret_cast<brush_t *>(m_PatchesHandles.GetAt(index));
  277. return pb->pPatch;
  278. }
  279. #ifdef _DEBUG
  280. Sys_Printf("WARNING: out of bounds in CPlugInManager::FindPatchHandle\n");
  281. #endif
  282. break;
  283. case EAllocatedPatches:
  284. if ( index < m_PluginPatches.GetSize() )
  285. {
  286. patchMesh_t *pPatch = reinterpret_cast<patchMesh_t *>(m_PluginPatches.GetAt(index));
  287. return pPatch;
  288. }
  289. #ifdef _DEBUG
  290. Sys_Printf("WARNING: out of bounds in CPlugInManager::FindPatchHandle\n");
  291. #endif
  292. break;
  293. }
  294. return NULL;
  295. }
  296. LPVOID WINAPI QERApp_CreateBrushHandle()
  297. {
  298. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  299. return g_pParentWnd->GetPlugInMgr().CreateBrushHandle();
  300. }
  301. void WINAPI QERApp_DeleteBrushHandle(LPVOID vp)
  302. {
  303. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  304. g_pParentWnd->GetPlugInMgr().DeleteBrushHandle(vp);
  305. }
  306. void WINAPI QERApp_CommitBrushHandleToMap(LPVOID vp)
  307. {
  308. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  309. g_pParentWnd->GetPlugInMgr().CommitBrushHandleToMap(vp);
  310. }
  311. void WINAPI QERApp_AddFace(LPVOID vp, vec3_t v1, vec3_t v2, vec3_t v3)
  312. {
  313. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  314. g_pParentWnd->GetPlugInMgr().AddFaceToBrushHandle(vp, v1, v2, v3);
  315. }
  316. void WINAPI QERApp_DeleteSelection()
  317. {
  318. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  319. Select_Delete();
  320. }
  321. void WINAPI QERApp_SysMsg(LPCSTR pMsg)
  322. {
  323. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  324. CString str = pMsg;
  325. Sys_Printf(str.GetBuffer(0));
  326. }
  327. // NOTE: called only in case of plugin error. We can try a plugin refresh instead of a straight crash ?
  328. void WINAPI QERApp_ErrorMsg(LPCSTR pMsg)
  329. {
  330. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  331. CString str = pMsg;
  332. Error(str.GetBuffer(0));
  333. }
  334. void WINAPI QERApp_InfoMsg(LPCSTR pMsg)
  335. {
  336. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  337. ShowInfoDialog(pMsg);
  338. }
  339. void WINAPI QERApp_HideInfoMsg()
  340. {
  341. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  342. HideInfoDialog();
  343. }
  344. //=====
  345. //PGM
  346. void WINAPI QERApp_PositionView(vec3_t v1, vec3_t v2)
  347. {
  348. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  349. g_pParentWnd->ActiveXY()->SetOrigin(v1);
  350. // FIXME - implement this!
  351. Sys_UpdateWindows(W_ALL);
  352. }
  353. //PGM
  354. //=====
  355. //FIXME: this AcquirePath stuff is pretty much a mess and needs cleaned up
  356. bool g_bPlugWait = false;
  357. bool g_bPlugOK = false;
  358. int g_nPlugCount = 0;
  359. void _PlugDone(bool b, int n)
  360. {
  361. g_bPlugWait = false;
  362. g_bPlugOK = b;
  363. g_nPlugCount = n;
  364. }
  365. void WINAPI QERApp_GetPoints(int nMax, _QERPointData *pData, LPCSTR pMsg)
  366. {
  367. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  368. ShowInfoDialog(pMsg);
  369. g_bPlugWait = true;
  370. g_bPlugOK = false;
  371. g_nPlugCount = 0;
  372. // g_nPlugCount=nMax-1;
  373. AcquirePath(nMax, &_PlugDone);
  374. while (g_bPlugWait)
  375. {
  376. MSG msg;
  377. if (::PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ))
  378. {
  379. TranslateMessage(&msg);
  380. DispatchMessage(&msg);
  381. }
  382. }
  383. HideInfoDialog();
  384. pData->m_nCount = 0;
  385. pData->m_pVectors = NULL;
  386. if (g_bPlugOK && g_nPlugCount > 0)
  387. {
  388. pData->m_nCount = g_nPlugCount;
  389. pData->m_pVectors = reinterpret_cast<vec3_t*>(qmalloc(g_nPlugCount * sizeof(vec3_t)));
  390. vec3_t *pOut = pData->m_pVectors;
  391. for (int i = 0; i < g_nPlugCount; i++)
  392. {
  393. memcpy(pOut, &g_PathPoints[i],sizeof(vec3_t));
  394. pOut++;
  395. }
  396. }
  397. }
  398. void WINAPI QERApp_AddFaceData(LPVOID pv, _QERFaceData *pData)
  399. {
  400. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  401. brush_t* pBrush = g_pParentWnd->GetPlugInMgr().FindBrushHandle(pv);
  402. if (pBrush != NULL)
  403. {
  404. face_t *f = Face_Alloc();
  405. f->texdef = g_qeglobals.d_texturewin.texdef;
  406. f->texdef.flags = pData->m_nFlags;
  407. f->texdef.contents = pData->m_nContents;
  408. f->texdef.value = pData->m_nValue;
  409. f->texdef.rotate = pData->m_fRotate;
  410. f->texdef.shift[0] = pData->m_fShift[0];
  411. f->texdef.shift[1] = pData->m_fShift[1];
  412. f->texdef.scale[0] = pData->m_fScale[0];
  413. f->texdef.scale[1] = pData->m_fScale[1];
  414. //strcpy(f->texdef.name, pData->m_TextureName);
  415. f->texdef.SetName(pData->m_TextureName);
  416. f->next = pBrush->brush_faces;
  417. pBrush->brush_faces = f;
  418. VectorCopy (pData->m_v1, f->planepts[0]);
  419. VectorCopy (pData->m_v2, f->planepts[1]);
  420. VectorCopy (pData->m_v3, f->planepts[2]);
  421. Sys_MarkMapModified(); // PGM
  422. }
  423. }
  424. int WINAPI QERApp_GetFaceCount(LPVOID pv)
  425. {
  426. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  427. int n = 0;
  428. brush_t *pBrush = g_pParentWnd->GetPlugInMgr().FindBrushHandle(pv);
  429. if (pBrush != NULL)
  430. {
  431. for (face_t *f = pBrush->brush_faces ; f; f = f->next)
  432. {
  433. n++;
  434. }
  435. }
  436. return n;
  437. }
  438. _QERFaceData* WINAPI QERApp_GetFaceData(LPVOID pv, int nFaceIndex)
  439. {
  440. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  441. static _QERFaceData face;
  442. int n = 0;
  443. brush_t *pBrush = g_pParentWnd->GetPlugInMgr().FindBrushHandle(pv);
  444. if (pBrush != NULL)
  445. {
  446. for (face_t *f = pBrush->brush_faces ; f; f = f->next)
  447. {
  448. #ifdef _DEBUG
  449. if (!pBrush->brush_faces)
  450. {
  451. Sys_Printf( "Warning : pBrush->brush_faces is NULL in QERApp_GetFaceData\n" );
  452. return NULL;
  453. }
  454. #endif
  455. if (n == nFaceIndex)
  456. {
  457. face.m_nContents = f->texdef.contents;
  458. face.m_nFlags = f->texdef.flags;
  459. face.m_fRotate = f->texdef.rotate;
  460. face.m_fScale[0] = f->texdef.scale[0];
  461. face.m_fScale[1] = f->texdef.scale[1];
  462. face.m_fShift[0] = f->texdef.shift[0];
  463. face.m_fShift[1] = f->texdef.shift[1];
  464. face.m_nValue = f->texdef.value;
  465. strcpy(face.m_TextureName, f->texdef.name);
  466. VectorCopy(f->planepts[0], face.m_v1);
  467. VectorCopy(f->planepts[1], face.m_v2);
  468. VectorCopy(f->planepts[2], face.m_v3);
  469. return &face;
  470. }
  471. n++;
  472. }
  473. }
  474. return NULL;
  475. }
  476. void WINAPI QERApp_SetFaceData(LPVOID pv, int nFaceIndex, _QERFaceData *pData)
  477. {
  478. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  479. int n = 0;
  480. brush_t *pBrush = g_pParentWnd->GetPlugInMgr().FindBrushHandle(pv);
  481. if (pBrush != NULL)
  482. {
  483. for (face_t *f = pBrush->brush_faces ; f; f = f->next)
  484. {
  485. if (n == nFaceIndex)
  486. {
  487. f->texdef.flags = pData->m_nFlags;
  488. f->texdef.contents = pData->m_nContents;
  489. f->texdef.value = pData->m_nValue;
  490. f->texdef.rotate = pData->m_fRotate;
  491. f->texdef.shift[0] = pData->m_fShift[0];
  492. f->texdef.shift[1] = pData->m_fShift[1];
  493. f->texdef.scale[0] = pData->m_fScale[0];
  494. f->texdef.scale[1] = pData->m_fScale[1];
  495. //strcpy(f->texdef.name, pData->m_TextureName);
  496. f->texdef.SetName(pData->m_TextureName);
  497. VectorCopy(pData->m_v1, f->planepts[0]);
  498. VectorCopy(pData->m_v2, f->planepts[1]);
  499. VectorCopy(pData->m_v3, f->planepts[2]);
  500. Sys_MarkMapModified(); // PGM
  501. return; // PGM
  502. }
  503. n++;
  504. }
  505. }
  506. }
  507. void WINAPI QERApp_DeleteFace(LPVOID pv, int nFaceIndex)
  508. {
  509. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  510. int n = 0;
  511. brush_t *pBrush = g_pParentWnd->GetPlugInMgr().FindBrushHandle(pv);
  512. if (pBrush != NULL)
  513. {
  514. face_t *pPrev = pBrush->brush_faces;
  515. for (face_t *f = pBrush->brush_faces; f; f = f->next)
  516. {
  517. if (n == nFaceIndex)
  518. {
  519. pPrev->next = f->next;
  520. Face_Free (f);
  521. Sys_MarkMapModified(); // PGM
  522. return;
  523. }
  524. n++;
  525. pPrev = f;
  526. }
  527. }
  528. }
  529. //==========
  530. //PGM
  531. void WINAPI QERApp_BuildBrush (LPVOID pv)
  532. {
  533. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  534. brush_t *pBrush = g_pParentWnd->GetPlugInMgr().FindBrushHandle(pv);
  535. if (pBrush != NULL)
  536. {
  537. Brush_Build(pBrush);
  538. Sys_UpdateWindows(W_ALL);
  539. }
  540. }
  541. //Timo : another version with bConvert flag
  542. //++timo since 1.7 is not compatible with earlier plugin versions, remove this one and update QERApp_BuildBrush
  543. void WINAPI QERApp_BuildBrush2 (LPVOID pv, int bConvert)
  544. {
  545. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  546. brush_t *pBrush = g_pParentWnd->GetPlugInMgr().FindBrushHandle(pv);
  547. if (pBrush != NULL)
  548. {
  549. Brush_Build( pBrush, true, true, bConvert );
  550. Sys_UpdateWindows(W_ALL);
  551. }
  552. }
  553. void WINAPI QERApp_SelectBrush (LPVOID pv)
  554. {
  555. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  556. brush_t *pBrush = g_pParentWnd->GetPlugInMgr().FindBrushHandle(pv);
  557. if (pBrush != NULL)
  558. {
  559. Select_Brush(pBrush, false);
  560. Sys_UpdateWindows(W_ALL);
  561. }
  562. }
  563. void WINAPI QERApp_DeselectBrush (LPVOID pv)
  564. {
  565. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  566. // FIXME - implement this!
  567. }
  568. void WINAPI QERApp_ResetPlugins()
  569. {
  570. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  571. g_pParentWnd->OnPluginsRefresh();
  572. }
  573. void WINAPI QERApp_DeselectAllBrushes ()
  574. {
  575. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  576. Select_Deselect();
  577. Sys_UpdateWindows(W_ALL);
  578. }
  579. //PGM
  580. //==========
  581. void WINAPI QERApp_TextureBrush(LPVOID pv, LPCSTR pName)
  582. {
  583. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  584. brush_t *pBrush = g_pParentWnd->GetPlugInMgr().FindBrushHandle(pv);
  585. if (pBrush != NULL)
  586. {
  587. for (face_t *f = pBrush->brush_faces ; f; f = f->next)
  588. {
  589. //strcpy(f->texdef.name, pName);
  590. f->texdef.SetName(pName);
  591. }
  592. Sys_MarkMapModified(); // PGM
  593. }
  594. }
  595. int WINAPI QERApp_SelectedBrushCount()
  596. {
  597. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  598. int n = 0;
  599. for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  600. {
  601. n++;
  602. }
  603. return n;
  604. }
  605. int WINAPI QERApp_ActiveBrushCount()
  606. {
  607. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  608. int n = 0;
  609. for (brush_t *pb = active_brushes.next ; pb != &active_brushes ; pb = pb->next)
  610. {
  611. n++;
  612. }
  613. return n;
  614. }
  615. int WINAPI QERApp_AllocateSelectedBrushHandles()
  616. {
  617. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  618. int n = 0;
  619. for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  620. {
  621. n++;
  622. g_pParentWnd->GetPlugInMgr().GetSelectedHandles().Add(pb);
  623. }
  624. return n;
  625. }
  626. int WINAPI QERApp_AllocateActiveBrushHandles()
  627. {
  628. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  629. int n = 0;
  630. for (brush_t *pb = active_brushes.next ; pb != &active_brushes ; pb = pb->next)
  631. {
  632. n++;
  633. g_pParentWnd->GetPlugInMgr().GetActiveHandles().Add(pb);
  634. }
  635. return n;
  636. }
  637. void WINAPI QERApp_ReleaseSelectedBrushHandles()
  638. {
  639. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  640. g_pParentWnd->GetPlugInMgr().GetSelectedHandles().RemoveAll();
  641. Sys_UpdateWindows(W_ALL);
  642. }
  643. void WINAPI QERApp_ReleaseActiveBrushHandles()
  644. {
  645. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  646. g_pParentWnd->GetPlugInMgr().GetActiveHandles().RemoveAll();
  647. Sys_UpdateWindows(W_ALL);
  648. }
  649. LPVOID WINAPI QERApp_GetActiveBrushHandle(int nIndex)
  650. {
  651. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  652. if (nIndex < g_pParentWnd->GetPlugInMgr().GetActiveHandles().GetSize())
  653. {
  654. return reinterpret_cast<LPVOID>(g_pParentWnd->GetPlugInMgr().GetActiveHandles().GetAt(nIndex));
  655. }
  656. return NULL;
  657. }
  658. LPVOID WINAPI QERApp_GetSelectedBrushHandle(int nIndex)
  659. {
  660. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  661. if (nIndex < g_pParentWnd->GetPlugInMgr().GetSelectedHandles().GetSize())
  662. {
  663. return reinterpret_cast<LPVOID>(g_pParentWnd->GetPlugInMgr().GetSelectedHandles().GetAt(nIndex));
  664. }
  665. return NULL;
  666. }
  667. int WINAPI QERApp_TextureCount()
  668. {
  669. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  670. Texture_StartPos ();
  671. int x, y;
  672. int n = 0;
  673. while (1)
  674. {
  675. qtexture_t *q = Texture_NextPos (&x, &y);
  676. if (!q)
  677. break;
  678. n++;
  679. }
  680. return n;
  681. }
  682. LPCSTR WINAPI QERApp_GetTexture(int nIndex)
  683. {
  684. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  685. static char name[QER_MAX_NAMELEN];
  686. Texture_StartPos ();
  687. int x, y;
  688. int n = 0;
  689. while (1)
  690. {
  691. qtexture_t *q = Texture_NextPos (&x, &y);
  692. if (!q)
  693. break;
  694. if (n == nIndex)
  695. {
  696. strcpy(name, q->name);
  697. return name;
  698. }
  699. n++;
  700. }
  701. return NULL;
  702. }
  703. LPCSTR WINAPI QERApp_GetCurrentTexture()
  704. {
  705. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  706. return g_qeglobals.d_texturewin.texdef.name;
  707. }
  708. void WINAPI QERApp_SetCurrentTexture(LPCSTR strName)
  709. {
  710. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  711. //++timo hu ?? tex is not initialized ?? can be any value ..
  712. texdef_t tex;
  713. //++timo added a brushprimit_texdef ..
  714. // smthg to be done here
  715. brushprimit_texdef_t brushprimit_tex;
  716. //strcpy(tex.name, strName);
  717. tex.SetName(strName);
  718. Texture_SetTexture(&tex,&brushprimit_tex);
  719. }
  720. int WINAPI QERApp_GetEClassCount()
  721. {
  722. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  723. int n = 0;
  724. for (eclass_t *e = eclass ; e ; e = e->next)
  725. {
  726. n++;
  727. }
  728. return n;
  729. }
  730. LPCSTR WINAPI QERApp_GetEClass(int nIndex)
  731. {
  732. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  733. int n = 0;
  734. for (eclass_t *e = eclass ; e ; e = e->next)
  735. {
  736. if (n == nIndex)
  737. {
  738. return e->name;
  739. }
  740. }
  741. return NULL;
  742. }
  743. void WINAPI QERApp_LoadTextureRGBA(LPVOID vp)
  744. {
  745. Texture_LoadFromPlugIn(vp);
  746. }
  747. // v1.70 code
  748. // world_entity holds the worldspawn and is indexed as 0
  749. // other entities are in the entities doubly linked list
  750. // QERApp_GetEntityCount counts the entities like in any C array: [0..length-1]
  751. int WINAPI QERApp_GetEntityCount()
  752. {
  753. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  754. int n = 1;
  755. for (entity_t *pe = entities.next ; pe != &entities ; pe = pe->next)
  756. {
  757. n++;
  758. }
  759. return n;
  760. }
  761. // We don't store entities in CPtrArray, we need to walk the list
  762. LPVOID WINAPI QERApp_GetEntityHandle(int nIndex)
  763. {
  764. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  765. if (nIndex==0)
  766. // looks for the worldspawn
  767. return static_cast<LPVOID>(world_entity);
  768. entity_t *pe = &entities;
  769. int n = 0;
  770. while ( n < nIndex )
  771. {
  772. pe = pe->next;
  773. n++;
  774. }
  775. return static_cast<LPVOID>(pe);
  776. }
  777. epair_t** WINAPI QERApp_GetEntityKeyValList(LPVOID vp)
  778. {
  779. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  780. entity_t *pe = static_cast<entity_t *>(vp);
  781. return &pe->epairs;
  782. }
  783. epair_t* WINAPI QERApp_AllocateEpair( char *key, char *val )
  784. {
  785. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  786. epair_t *e = (epair_t*)qmalloc (sizeof(*e));
  787. e->key = (char*)qmalloc(strlen(key)+1);
  788. strcpy (e->key, key);
  789. e->value = (char*)qmalloc(strlen(val)+1);
  790. strcpy (e->value, val);
  791. return e;
  792. }
  793. void WINAPI QERApp_SetEntityKeyValList(LPVOID vp, epair_t* ep)
  794. {
  795. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  796. entity_t *pe = static_cast<entity_t *>(vp);
  797. if (pe->epairs)
  798. Sys_Printf( "Warning : pe->epairs != NULL in QERApp_SetEntityKeyValList, will not set\n" );
  799. else
  800. pe->epairs = ep;
  801. }
  802. int WINAPI QERApp_AllocateEntityBrushHandles(LPVOID vp)
  803. {
  804. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  805. entity_t *pe = static_cast<entity_t *>(vp);
  806. int n = 0;
  807. if (!pe->brushes.onext)
  808. return 0;
  809. g_pParentWnd->GetPlugInMgr().GetEntityBrushHandles().RemoveAll();
  810. for (brush_t *pb = pe->brushes.onext ; pb != &pe->brushes ; pb=pb->onext)
  811. {
  812. n++;
  813. g_pParentWnd->GetPlugInMgr().GetEntityBrushHandles().Add(pb);
  814. }
  815. return n;
  816. }
  817. void WINAPI QERApp_ReleaseEntityBrushHandles()
  818. {
  819. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  820. g_pParentWnd->GetPlugInMgr().GetEntityBrushHandles().RemoveAll();
  821. }
  822. LPVOID WINAPI QERApp_GetEntityBrushHandle(int nIndex)
  823. {
  824. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  825. if (nIndex < g_pParentWnd->GetPlugInMgr().GetEntityBrushHandles().GetSize())
  826. return g_pParentWnd->GetPlugInMgr().GetEntityBrushHandles().GetAt(nIndex);
  827. return NULL;
  828. }
  829. LPVOID WINAPI QERApp_CreateEntityHandle()
  830. {
  831. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  832. entity_t *pe = reinterpret_cast<entity_t*>(qmalloc(sizeof(entity_t)));
  833. pe->brushes.onext = pe->brushes.oprev = &pe->brushes;
  834. g_pParentWnd->GetPlugInMgr().GetEntityHandles().Add(static_cast<LPVOID>(pe));
  835. return static_cast<LPVOID>(pe);
  836. }
  837. // the vpBrush needs to be in m_BrushHandles
  838. //++timo we don't have allocation nor storage for vpEntity, no checks for this one
  839. void WINAPI QERApp_CommitBrushHandleToEntity(LPVOID vpBrush, LPVOID vpEntity)
  840. {
  841. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  842. g_pParentWnd->GetPlugInMgr().CommitBrushHandleToEntity(vpBrush, vpEntity);
  843. return;
  844. }
  845. char* WINAPI QERApp_ReadProjectKey(char* key)
  846. {
  847. return ValueForKey(g_qeglobals.d_project_entity, key);
  848. }
  849. int WINAPI QERApp_ScanFileForEClass(char *filename )
  850. {
  851. // set single class parsing
  852. parsing_single = true;
  853. Eclass_ScanFile(filename);
  854. if (eclass_found)
  855. {
  856. eclass_e->nShowFlags |= ECLASS_PLUGINENTITY;
  857. return 1;
  858. }
  859. return 0;
  860. }
  861. // the vpBrush needs to be in m_BrushHandles
  862. //++timo add a debug check to see if we found the brush handle
  863. // NOTE : seems there's no way to check vpEntity is valid .. this is dangerous
  864. // links the brush to its entity, everything else is done when commiting the entity to the map
  865. void CPlugInManager::CommitBrushHandleToEntity(LPVOID vpBrush, LPVOID vpEntity)
  866. {
  867. brush_t* pb;
  868. entity_t* pe;
  869. for (int i=0 ; i < m_BrushHandles.GetSize() ; i++)
  870. {
  871. if (vpBrush == m_BrushHandles.GetAt(i))
  872. {
  873. m_BrushHandles.RemoveAt(i);
  874. pb = reinterpret_cast<brush_t*>(vpBrush);
  875. pe = reinterpret_cast<entity_t *>(vpEntity);
  876. Entity_LinkBrush (pe, pb);
  877. }
  878. }
  879. Sys_UpdateWindows(W_ALL);
  880. }
  881. // the vpEntity must be in m_EntityHandles
  882. void WINAPI QERApp_CommitEntityHandleToMap(LPVOID vpEntity)
  883. {
  884. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  885. g_pParentWnd->GetPlugInMgr().CommitEntityHandleToMap(vpEntity);
  886. return;
  887. }
  888. int WINAPI QERApp_LoadFile( const char *pLocation, void ** buffer )
  889. {
  890. char cPath[1024];
  891. sprintf( cPath, "%s/%s", ValueForKey(g_qeglobals.d_project_entity, "basepath"), pLocation);
  892. int nSize = LoadFile( cPath, buffer);
  893. if (nSize == -1)
  894. {
  895. nSize = PakLoadAnyFile(cPath, buffer);
  896. }
  897. return nSize;
  898. }
  899. char * WINAPI QERApp_ExpandReletivePath (char *p)
  900. {
  901. return ExpandReletivePath(p);
  902. }
  903. // NOTE: this is a simplified version
  904. int WINAPI QERApp_HasShader( const char *pName )
  905. {
  906. CShaderInfo *pInfo = hasShader( pName );
  907. if (pInfo)
  908. return 1;
  909. return 0;
  910. }
  911. qtexture_t* WINAPI QERApp_Texture_ForName (const char *name)
  912. {
  913. // if the texture is not loaded yet, this call will get it loaded
  914. // but: when we assign a GL bind number, we need to be in the g_qeglobals.d_hdcBase , g_qeglobals.d_hglrcBase GL context
  915. // the plugin may set the GL context to whatever he likes, but then load would fail
  916. // NOTE: is context switching time-consuming? then maybe the plugin could handle the context switch and only add a
  917. // sanity check in debug mode here
  918. // read current context
  919. HDC pluginHDC = qwglGetCurrentDC();
  920. HGLRC pluginHGLRC = qwglGetCurrentContext();
  921. qwglMakeCurrent( g_qeglobals.d_hdcBase, g_qeglobals.d_hglrcBase );
  922. qtexture_t* qtex = Texture_ForName( name );
  923. return qtex;
  924. qwglMakeCurrent( pluginHDC, pluginHGLRC );
  925. }
  926. void WINAPI QERApp_RadiantFree( void * buf )
  927. {
  928. free( buf );
  929. }
  930. char* WINAPI QERApp_Token()
  931. {
  932. return token;
  933. }
  934. char* WINAPI QERApp_GetMapName()
  935. {
  936. return currentmap;
  937. }
  938. void CPlugInManager::CommitEntityHandleToMap(LPVOID vpEntity)
  939. {
  940. entity_t *pe;
  941. eclass_t *e;
  942. brush_t *b;
  943. vec3_t mins,maxs;
  944. bool has_brushes;
  945. for (int i=0 ; i < m_EntityHandles.GetSize() ; i++ )
  946. {
  947. if (vpEntity == m_EntityHandles.GetAt(i))
  948. {
  949. m_EntityHandles.RemoveAt(i);
  950. pe = reinterpret_cast<entity_t*>(vpEntity);
  951. // fill additional fields
  952. // straight copy from Entity_Parse
  953. // entity_t::origin
  954. GetVectorForKey (pe, "origin", pe->origin);
  955. // entity_t::eclass
  956. if (pe->brushes.onext == &pe->brushes)
  957. has_brushes = false;
  958. else
  959. has_brushes = true;
  960. e = Eclass_ForName (ValueForKey (pe, "classname"), has_brushes);
  961. pe->eclass = e;
  962. // fixedsize
  963. if (e->fixedsize)
  964. {
  965. if (pe->brushes.onext != &pe->brushes)
  966. {
  967. Sys_Printf("Warning : Fixed size entity with brushes in CPlugInManager::CommitEntityHandleToMap\n");
  968. }
  969. // create a custom brush
  970. VectorAdd(e->mins, pe->origin, mins);
  971. VectorAdd(e->maxs, pe->origin, maxs);
  972. float a = 0;
  973. if (e->nShowFlags & ECLASS_MISCMODEL)
  974. {
  975. char* p = ValueForKey(pe, "model");
  976. if (p != NULL && strlen(p) > 0)
  977. {
  978. vec3_t vMin, vMax;
  979. a = FloatForKey (pe, "angle");
  980. if (GetCachedModel(pe, p, vMin, vMax))
  981. {
  982. // create a custom brush
  983. VectorAdd (pe->md3Class->mins, pe->origin, mins);
  984. VectorAdd (pe->md3Class->maxs, pe->origin, maxs);
  985. }
  986. }
  987. }
  988. b = Brush_Create (mins, maxs, &e->texdef);
  989. if (a)
  990. {
  991. vec3_t vAngle;
  992. vAngle[0] = vAngle[1] = 0;
  993. vAngle[2] = a;
  994. Brush_Rotate(b, vAngle, pe->origin, false);
  995. }
  996. b->owner = pe;
  997. b->onext = pe->brushes.onext;
  998. b->oprev = &pe->brushes;
  999. pe->brushes.onext->oprev = b;
  1000. pe->brushes.onext = b;
  1001. }
  1002. else
  1003. { // brush entity
  1004. if (pe->brushes.next == &pe->brushes)
  1005. Sys_Printf ("Warning: Brush entity with no brushes in CPlugInManager::CommitEntityHandleToMap\n");
  1006. }
  1007. // add brushes to the active brushes list
  1008. // and build them along the way
  1009. for (b=pe->brushes.onext ; b != &pe->brushes ; b=b->onext)
  1010. {
  1011. // convert between old brushes and brush primitive
  1012. if (g_qeglobals.m_bBrushPrimitMode)
  1013. {
  1014. // we only filled the shift scale rot fields, needs conversion
  1015. Brush_Build( b, true, true, true );
  1016. }
  1017. else
  1018. {
  1019. // we are using old brushes
  1020. Brush_Build( b );
  1021. }
  1022. b->next = active_brushes.next;
  1023. active_brushes.next->prev = b;
  1024. b->prev = &active_brushes;
  1025. active_brushes.next = b;
  1026. }
  1027. // handle worldspawn entities
  1028. // if worldspawn has no brushes, use the new one
  1029. if (!strcmp(ValueForKey (pe, "classname"), "worldspawn"))
  1030. {
  1031. if ( world_entity && ( world_entity->brushes.onext != &world_entity->brushes ) )
  1032. {
  1033. // worldspawn already has brushes
  1034. Sys_Printf ("Commiting worldspawn as func_group\n");
  1035. SetKeyValue(pe, "classname", "func_group");
  1036. // add the entity to the end of the entity list
  1037. pe->next = &entities;
  1038. pe->prev = entities.prev;
  1039. entities.prev->next = pe;
  1040. entities.prev = pe;
  1041. g_qeglobals.d_num_entities++;
  1042. }
  1043. else
  1044. {
  1045. // there's a worldspawn with no brushes, we assume the map is empty
  1046. if ( world_entity )
  1047. {
  1048. Entity_Free( world_entity );
  1049. world_entity = pe;
  1050. }
  1051. else
  1052. Sys_Printf("Warning : unexpected world_entity == NULL in CommitEntityHandleToMap\n");
  1053. }
  1054. }
  1055. else
  1056. {
  1057. // add the entity to the end of the entity list
  1058. pe->next = &entities;
  1059. pe->prev = entities.prev;
  1060. entities.prev->next = pe;
  1061. entities.prev = pe;
  1062. g_qeglobals.d_num_entities++;
  1063. }
  1064. }
  1065. }
  1066. }
  1067. void WINAPI QERApp_SetScreenUpdate(int bScreenUpdates)
  1068. {
  1069. g_bScreenUpdates = bScreenUpdates;
  1070. }
  1071. texturewin_t* WINAPI QERApp_QeglobalsTexturewin()
  1072. {
  1073. return &g_qeglobals.d_texturewin;
  1074. }
  1075. _QERTextureInfo* CPlugInManager::GetTextureInfo()
  1076. {
  1077. if (m_pTexturePlug != NULL)
  1078. {
  1079. return m_pTexturePlug->getTextureInfo();
  1080. }
  1081. else
  1082. {
  1083. return NULL;
  1084. }
  1085. }
  1086. LPVOID CPlugInManager::GetSurfaceFlags()
  1087. {
  1088. if (m_pSurfaceListPlug != NULL)
  1089. {
  1090. return m_pSurfaceListPlug->getSurfaceFlags();
  1091. }
  1092. else
  1093. {
  1094. return NULL;
  1095. }
  1096. }
  1097. void CPlugInManager::LoadTexture(const char *pFilename)
  1098. {
  1099. if (m_pTexturePlug != NULL)
  1100. {
  1101. m_pTexturePlug->loadTexture(pFilename);
  1102. }
  1103. }
  1104. patchMesh_t* WINAPI QERApp_GetSelectedPatch( )
  1105. {
  1106. for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  1107. {
  1108. if (pb->patchBrush)
  1109. {
  1110. return pb->pPatch;
  1111. }
  1112. }
  1113. #ifdef _DEBUG
  1114. Sys_Printf("WARNING: QERApp_GetSelectedPatchTexdef called with no patch selected\n");
  1115. #endif
  1116. return NULL;
  1117. }
  1118. char* WINAPI QERApp_GetGamePath()
  1119. {
  1120. return g_PrefsDlg.m_strQuake2.GetBuffer(0);
  1121. }
  1122. char* WINAPI QERApp_GetQERPath()
  1123. {
  1124. return g_strAppPath.GetBuffer(0);
  1125. }
  1126. // patches in/out -----------------------------------
  1127. int WINAPI QERApp_AllocateActivePatchHandles()
  1128. {
  1129. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1130. return g_pParentWnd->GetPlugInMgr().AllocateActivePatchHandles();
  1131. }
  1132. int CPlugInManager::AllocateActivePatchHandles()
  1133. {
  1134. int n = 0;
  1135. for (brush_t *pb = active_brushes.next ; pb != &active_brushes ; pb = pb->next)
  1136. {
  1137. if (pb->patchBrush)
  1138. {
  1139. n++;
  1140. m_PatchesHandles.Add(pb);
  1141. }
  1142. }
  1143. return n;
  1144. }
  1145. int WINAPI QERApp_AllocateSelectedPatchHandles()
  1146. {
  1147. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1148. return g_pParentWnd->GetPlugInMgr().AllocateSelectedPatchHandles();
  1149. }
  1150. int CPlugInManager::AllocateSelectedPatchHandles()
  1151. {
  1152. int n = 0;
  1153. for (brush_t *pb = selected_brushes.next ; pb != &selected_brushes ; pb = pb->next)
  1154. {
  1155. if (pb->patchBrush)
  1156. {
  1157. n++;
  1158. m_PatchesHandles.Add(pb);
  1159. }
  1160. }
  1161. return n;
  1162. }
  1163. void WINAPI QERApp_ReleasePatchHandles()
  1164. {
  1165. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1166. g_pParentWnd->GetPlugInMgr().ReleasePatchesHandles();
  1167. }
  1168. patchMesh_t* WINAPI QERApp_GetPatchData(int index)
  1169. {
  1170. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1171. static patchMesh_t patch;
  1172. patchMesh_t *pPatch = g_pParentWnd->GetPlugInMgr().FindPatchHandle(index);
  1173. if (pPatch)
  1174. {
  1175. memcpy( &patch, pPatch, sizeof(patchMesh_t) );
  1176. return &patch;
  1177. }
  1178. return NULL;
  1179. }
  1180. void WINAPI QERApp_DeletePatch(int index)
  1181. {
  1182. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1183. patchMesh_t *pPatch = g_pParentWnd->GetPlugInMgr().FindPatchHandle(index);
  1184. if (pPatch)
  1185. {
  1186. brush_t *pb = pPatch->pSymbiot;
  1187. Patch_Delete( pPatch );
  1188. if (pb)
  1189. Brush_Free( pb );
  1190. }
  1191. #ifdef _DEBUG
  1192. Sys_Printf("Warning: QERApp_DeletePatch: FindPatchHandle failed\n");
  1193. #endif
  1194. }
  1195. int WINAPI QERApp_CreatePatchHandle()
  1196. {
  1197. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1198. return g_pParentWnd->GetPlugInMgr().CreatePatchHandle();
  1199. }
  1200. int CPlugInManager::CreatePatchHandle()
  1201. {
  1202. // NOTE: we can't call the AddBrushForPatch until we have filled the patchMesh_t structure
  1203. patchMesh_t *pPatch = MakeNewPatch();
  1204. m_PluginPatches.Add( pPatch );
  1205. // change mode
  1206. PatchesMode = EAllocatedPatches;
  1207. return m_PluginPatches.GetSize()-1;
  1208. }
  1209. void WINAPI QERApp_CommitPatchHandleToMap(int index, patchMesh_t *pMesh, char *texName)
  1210. {
  1211. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  1212. g_pParentWnd->GetPlugInMgr().CommitPatchHandleToMap(index, pMesh, texName);
  1213. }
  1214. void CPlugInManager::CommitPatchHandleToMap(int index, patchMesh_t *pMesh, char *texName)
  1215. {
  1216. if (PatchesMode==EAllocatedPatches)
  1217. {
  1218. patchMesh_t *pPatch = reinterpret_cast<patchMesh_t *>( m_PluginPatches.GetAt(index) );
  1219. memcpy( pPatch, pMesh, sizeof( patchMesh_t ) );
  1220. // patch texturing, if none given use current texture
  1221. if (texName)
  1222. pPatch->d_texture = Texture_ForName(texName);
  1223. if ( !pPatch->d_texture )
  1224. {
  1225. pPatch->d_texture = Texture_ForName(g_qeglobals.d_texturewin.texdef.name);
  1226. // checking .. just in case
  1227. if (!pPatch->d_texture)
  1228. {
  1229. #ifdef _DEBUG
  1230. Sys_Printf("WARNING: failed to set patch to current texture in CPlugInManager::CommitPatchHandleToMap\n");
  1231. #endif
  1232. pPatch->d_texture = notexture;
  1233. }
  1234. }
  1235. g_bScreenUpdates = false;
  1236. // the bLinkToWorld flag in AddBrushForPatch takes care of Brush_AddToList Entity_linkBrush and Brush_Build
  1237. brush_t *pb = AddBrushForPatch( pPatch, true );
  1238. Select_Brush( pb );
  1239. g_bScreenUpdates = true;
  1240. Sys_UpdateWindows(W_ALL);
  1241. }
  1242. else
  1243. {
  1244. brush_t *pBrush = reinterpret_cast<brush_t *>( m_PatchesHandles.GetAt(index) );
  1245. patchMesh_t *pPatch = pBrush->pPatch;
  1246. pPatch->width = pMesh->width;
  1247. pPatch->height = pMesh->height;
  1248. pPatch->contents = pMesh->contents;
  1249. pPatch->flags = pMesh->flags;
  1250. pPatch->value = pMesh->value;
  1251. pPatch->type = pMesh->type;
  1252. memcpy( pPatch->ctrl, pMesh->ctrl, sizeof(drawVert_t)*MAX_PATCH_HEIGHT*MAX_PATCH_WIDTH );
  1253. pPatch->bDirty = true;
  1254. }
  1255. }
  1256. // this gets called when the plugin needs specific services, for example the OpenGL drawing interface
  1257. //++timo plugins should be able to dynamically register their own interfaces in there
  1258. int WINAPI QERApp_RequestInterface( REFGUID refGUID, LPVOID pInterface )
  1259. {
  1260. if (IsEqualGUID( refGUID, QERQglTable_GUID ))
  1261. {
  1262. _QERQglTable *pQglTable = static_cast<_QERQglTable *>(pInterface);
  1263. if ( pQglTable->m_nSize != sizeof(_QERQglTable) )
  1264. {
  1265. Sys_Printf("wrong m_nSize in plugin-requested _QERQglTable interface\n");
  1266. return 0;
  1267. }
  1268. pQglTable->m_pfn_qglAlphaFunc = qglAlphaFunc;
  1269. pQglTable->m_pfn_qglBegin = qglBegin;
  1270. pQglTable->m_pfn_qglBindTexture = qglBindTexture;
  1271. pQglTable->m_pfn_qglBlendFunc = qglBlendFunc;
  1272. pQglTable->m_pfn_qglCallList = qglCallList;
  1273. pQglTable->m_pfn_qglCallLists = qglCallLists;
  1274. pQglTable->m_pfn_qglClear = qglClear;
  1275. pQglTable->m_pfn_qglClearColor = qglClearColor;
  1276. pQglTable->m_pfn_qglClearDepth = qglClearDepth;
  1277. pQglTable->m_pfn_qglColor3f = qglColor3f;
  1278. pQglTable->m_pfn_qglColor4f = qglColor4f;
  1279. pQglTable->m_pfn_qglCullFace = qglCullFace;
  1280. pQglTable->m_pfn_qglDisable = qglDisable;
  1281. pQglTable->m_pfn_qglDeleteLists = qglDeleteLists;
  1282. pQglTable->m_pfn_qglEnable = qglEnable;
  1283. pQglTable->m_pfn_qglEnd = qglEnd;
  1284. pQglTable->m_pfn_qglEndList = qglEndList;
  1285. pQglTable->m_pfn_qglGenLists = qglGenLists;
  1286. pQglTable->m_pfn_qglListBase = qglListBase;
  1287. pQglTable->m_pfn_qglLoadIdentity = qglLoadIdentity;
  1288. pQglTable->m_pfn_qglMatrixMode = qglMatrixMode;
  1289. pQglTable->m_pfn_qglNewList = qglNewList;
  1290. pQglTable->m_pfn_qglNormal3f = qglNormal3f;
  1291. pQglTable->m_pfn_qglOrtho = qglOrtho;
  1292. pQglTable->m_pfn_qglPointSize = qglPointSize;
  1293. pQglTable->m_pfn_qglPolygonMode = qglPolygonMode;
  1294. pQglTable->m_pfn_qglPopMatrix = qglPopMatrix;
  1295. pQglTable->m_pfn_qglPushMatrix = qglPushMatrix;
  1296. pQglTable->m_pfn_qglRotated = qglRotated;
  1297. pQglTable->m_pfn_qglRotatef = qglRotatef;
  1298. pQglTable->m_pfn_qglScalef = qglScalef;
  1299. pQglTable->m_pfn_qglTexCoord2f = qglTexCoord2f;
  1300. pQglTable->m_pfn_qglTexEnvf = qglTexEnvf;
  1301. pQglTable->m_pfn_qglTexGenf = qglTexGenf;
  1302. pQglTable->m_pfn_qglTexParameterf = qglTexParameterf;
  1303. pQglTable->m_pfn_qglTranslated = qglTranslated;
  1304. pQglTable->m_pfn_qglTranslatef = qglTranslatef;
  1305. pQglTable->m_pfn_qglVertex2f = qglVertex2f;
  1306. pQglTable->m_pfn_qglVertex3f = qglVertex3f;
  1307. pQglTable->m_pfn_qglViewport = qglViewport;
  1308. pQglTable->m_pfn_QE_CheckOpenGLForErrors = &QE_CheckOpenGLForErrors;
  1309. pQglTable->m_pfn_QEW_SetupPixelFormat = &QEW_SetupPixelFormat;
  1310. pQglTable->m_pfn_qwglCreateContext = qwglCreateContext;
  1311. pQglTable->m_pfn_qwglDeleteContext = qwglDeleteContext;
  1312. pQglTable->m_pfn_qwglMakeCurrent = qwglMakeCurrent;
  1313. pQglTable->m_pfn_qwglShareLists = qwglShareLists;
  1314. pQglTable->m_pfn_qwglSwapBuffers = qwglSwapBuffers;
  1315. pQglTable->m_pfn_qwglUseFontBitmaps = qwglUseFontBitmaps;
  1316. pQglTable->m_pfnGetQeglobalsHGLRC = &QERApp_GetQeglobalsHGLRC;
  1317. pQglTable->m_pfn_qgluPerspective = qgluPerspective;
  1318. pQglTable->m_pfn_qgluLookAt = qgluLookAt;
  1319. pQglTable->m_pfnHookXYGLWindow = QERApp_HookXYGLWindow;
  1320. pQglTable->m_pfnUnHookGLWindow = QERApp_UnHookGLWindow;
  1321. return 1;
  1322. }
  1323. else if (IsEqualGUID( refGUID, QERSelectedFaceTable_GUID ))
  1324. {
  1325. _QERSelectedFaceTable *pSelectedFaceTable = static_cast<_QERSelectedFaceTable *>(pInterface);
  1326. if ( pSelectedFaceTable->m_nSize != sizeof(_QERSelectedFaceTable) )
  1327. {
  1328. Sys_Printf("wrong m_nSize in plugin-requested _QERSelectedFaceTable interface\n");
  1329. return 0;
  1330. }
  1331. pSelectedFaceTable->m_pfnGetTextureNumber = &QERApp_ISelectedFace_GetTextureNumber;
  1332. pSelectedFaceTable->m_pfnGetFaceInfo = &QERApp_GetFaceInfo;
  1333. pSelectedFaceTable->m_pfnSetFaceInfo = &QERApp_SetFaceInfo;
  1334. pSelectedFaceTable->m_pfnGetTextureSize = &QERApp_GetTextureSize;
  1335. pSelectedFaceTable->m_pfnTextureForName = &QERApp_Texture_ForName;
  1336. pSelectedFaceTable->m_pfnSelect_SetTexture = &Select_SetTexture;
  1337. return 1;
  1338. }
  1339. else if (IsEqualGUID( refGUID, QERPluginEntitiesTable_GUID ))
  1340. {
  1341. _QERPluginEntitiesTable *pPluginEntitiesTable = static_cast<_QERPluginEntitiesTable *>(pInterface);
  1342. if ( pPluginEntitiesTable->m_nSize != sizeof(_QERPluginEntitiesTable) )
  1343. {
  1344. Sys_Printf("wrong m_nSize in plugin-requested _QERPluginEntitiesTable interface\n");
  1345. return 0;
  1346. }
  1347. pPluginEntitiesTable->m_pfnEClassScanDir = &QERApp_EClassScanDir;
  1348. return 1;
  1349. }
  1350. else if (IsEqualGUID( refGUID, QERScripLibTable_GUID ))
  1351. {
  1352. _QERScripLibTable *pScripLibTable = static_cast<_QERScripLibTable *>(pInterface);
  1353. if ( pScripLibTable->m_nSize != sizeof( _QERScripLibTable ) )
  1354. {
  1355. Sys_Printf("wrong m_nSize in plugin-requested _QERScripLibTable\n");
  1356. return 0;
  1357. }
  1358. pScripLibTable->m_pfnGetToken = &GetToken;
  1359. pScripLibTable->m_pfnToken = &QERApp_Token;
  1360. pScripLibTable->m_pfnUnGetToken = &UngetToken;
  1361. return 1;
  1362. }
  1363. else if (IsEqualGUID( refGUID, QERAppSurfaceTable_GUID ))
  1364. {
  1365. _QERAppSurfaceTable *pSurfaceTable = static_cast<_QERAppSurfaceTable *>(pInterface);
  1366. if ( pSurfaceTable->m_nSize != sizeof( _QERAppSurfaceTable ) )
  1367. {
  1368. Sys_Printf("wrong m_nSize in plugin-requested _QERAppSurfaceTable\n");
  1369. return 0;
  1370. }
  1371. pSurfaceTable->m_pfnAnyPatchesSelected = &AnyPatchesSelected;
  1372. pSurfaceTable->m_pfnOnlyPatchesSelected = &OnlyPatchesSelected;
  1373. pSurfaceTable->m_pfnQeglobalsTexturewin = &QERApp_QeglobalsTexturewin;
  1374. pSurfaceTable->m_pfnGetSelectedPatch = &QERApp_GetSelectedPatch;
  1375. pSurfaceTable->m_pfnPatchRebuild = &Patch_Rebuild;
  1376. pSurfaceTable->m_pfnGetTwoSelectedPatch = &QERApp_GetTwoSelectedPatch;
  1377. return 1;
  1378. }
  1379. else if (IsEqualGUID( refGUID, QERAppBSPFrontendTable_GUID ))
  1380. {
  1381. _QERAppBSPFrontendTable *pBSPFrontendTable = static_cast<_QERAppBSPFrontendTable *>(pInterface);
  1382. if ( pBSPFrontendTable->m_nSize != sizeof( _QERAppBSPFrontendTable ) )
  1383. {
  1384. Sys_Printf("wrong m_nSize in plugin-requested _QERAppBSPFrontendTable\n");
  1385. return 0;
  1386. }
  1387. pBSPFrontendTable->m_pfnGetMapName = &QERApp_GetMapName;
  1388. pBSPFrontendTable->m_pfnLoadPointFile = &Pointfile_Check;
  1389. return 1;
  1390. }
  1391. else if (IsEqualGUID( refGUID, QERMessaging_GUID ))
  1392. {
  1393. _QERMessagingTable *pMessagingTable = static_cast<_QERMessagingTable *>(pInterface);
  1394. if ( pMessagingTable->m_nSize != sizeof( _QERMessagingTable ) )
  1395. {
  1396. Sys_Printf("wrong m_nSize in plugin-requested _QERMessagingTable\n");
  1397. return 0;
  1398. }
  1399. pMessagingTable->m_pfnHookWindow = QERApp_HookWindow;
  1400. pMessagingTable->m_pfnUnHookWindow = QERApp_UnHookWindow;
  1401. pMessagingTable->m_pfnGetXYWndWrapper = QERApp_GetXYWndWrapper;
  1402. pMessagingTable->m_pfnHookListener = QERApp_HookListener;
  1403. pMessagingTable->m_pfnUnHookListener = QERApp_UnHookListener;
  1404. return 1;
  1405. }
  1406. else if (IsEqualGUID( refGUID, QERShadersTable_GUID ))
  1407. {
  1408. _QERShadersTable *pShadersTable = static_cast<_QERShadersTable *>(pInterface);
  1409. if ( pShadersTable->m_nSize != sizeof( _QERShadersTable ) )
  1410. {
  1411. Sys_Printf("wring m_nSize in plugin-requested _QERShadersTable\n");
  1412. return 0;
  1413. }
  1414. pShadersTable->m_pfnTryTextureForName = QERApp_TryTextureForName;
  1415. return 1;
  1416. }
  1417. return 0;
  1418. }
  1419. int CPlugInManager::FillFuncTable(CPlugIn *pPlug)
  1420. {
  1421. _QERFuncTable_1 *pTable = reinterpret_cast<_QERFuncTable_1*>(pPlug->getFuncTable());
  1422. if (pTable != NULL)
  1423. {
  1424. if (pTable->m_fVersion != QER_PLUG_VERSION)
  1425. {
  1426. Sys_Printf("Radiant plugin manager was built with version %.2f, Plugin %s is version %.2f\n", QER_PLUG_VERSION, pPlug->getVersionStr() , pTable->m_fVersion);
  1427. }
  1428. if (pTable->m_fVersion >= QER_PLUG_VERSION_1)
  1429. {
  1430. pTable->m_pfnCreateBrush = &QERApp_CreateBrush;
  1431. pTable->m_pfnCreateBrushHandle = &QERApp_CreateBrushHandle;
  1432. pTable->m_pfnDeleteBrushHandle = &QERApp_DeleteBrushHandle;
  1433. pTable->m_pfnCommitBrushHandle = &QERApp_CommitBrushHandleToMap;
  1434. pTable->m_pfnAddFace = &QERApp_AddFace;
  1435. pTable->m_pfnAddFaceData = &QERApp_AddFaceData;
  1436. pTable->m_pfnGetFaceData = &QERApp_GetFaceData;
  1437. pTable->m_pfnGetFaceCount = &QERApp_GetFaceCount;
  1438. pTable->m_pfnSetFaceData = &QERApp_SetFaceData;
  1439. pTable->m_pfnDeleteFace = &QERApp_DeleteFace;
  1440. pTable->m_pfnTextureBrush = &QERApp_TextureBrush;
  1441. pTable->m_pfnBuildBrush = &QERApp_BuildBrush; // PGM
  1442. pTable->m_pfnSelectBrush = &QERApp_SelectBrush; // PGM
  1443. pTable->m_pfnDeselectBrush = &QERApp_DeselectBrush; // PGM
  1444. pTable->m_pfnDeselectAllBrushes = &QERApp_DeselectAllBrushes; // PGM
  1445. pTable->m_pfnDeleteSelection = &QERApp_DeleteSelection;
  1446. pTable->m_pfnGetPoints = &QERApp_GetPoints;
  1447. pTable->m_pfnSysMsg = &QERApp_SysMsg;
  1448. pTable->m_pfnInfoMsg = &QERApp_InfoMsg;
  1449. pTable->m_pfnHideInfoMsg = &QERApp_HideInfoMsg;
  1450. pTable->m_pfnPositionView = &QERApp_PositionView; // PGM
  1451. pTable->m_pfnSelectedBrushCount = &QERApp_SelectedBrushCount;
  1452. pTable->m_pfnAllocateSelectedBrushHandles = &QERApp_AllocateSelectedBrushHandles;
  1453. pTable->m_pfnReleaseSelectedBrushHandles = &QERApp_ReleaseSelectedBrushHandles;
  1454. pTable->m_pfnGetSelectedBrushHandle = &QERApp_GetSelectedBrushHandle;
  1455. pTable->m_pfnActiveBrushCount = &QERApp_ActiveBrushCount;
  1456. pTable->m_pfnAllocateActiveBrushHandles = &QERApp_AllocateActiveBrushHandles;
  1457. pTable->m_pfnReleaseActiveBrushHandles = &QERApp_ReleaseActiveBrushHandles;
  1458. pTable->m_pfnGetActiveBrushHandle = &QERApp_GetActiveBrushHandle;
  1459. pTable->m_pfnTextureCount = &QERApp_TextureCount;
  1460. pTable->m_pfnGetTexture = &QERApp_GetTexture;
  1461. pTable->m_pfnGetCurrentTexture = &QERApp_GetCurrentTexture;
  1462. pTable->m_pfnSetCurrentTexture = &QERApp_SetCurrentTexture;
  1463. pTable->m_pfnGetEClassCount = &QERApp_GetEClassCount;
  1464. pTable->m_pfnGetEClass = &QERApp_GetEClass;
  1465. pTable->m_pfnResetPlugins = &QERApp_ResetPlugins;
  1466. }
  1467. // end of v1.00
  1468. if (pTable->m_fVersion >= 1.5f)
  1469. {
  1470. // v1.50 starts
  1471. pTable->m_pfnLoadTextureRGBA = &QERApp_LoadTextureRGBA;
  1472. // end of v1.50
  1473. }
  1474. if (pTable->m_fVersion >= 1.7f)
  1475. {
  1476. pTable->m_pfnGetEntityCount = &QERApp_GetEntityCount;
  1477. pTable->m_pfnGetEntityHandle = &QERApp_GetEntityHandle;
  1478. pTable->m_pfnGetEntityKeyValList = &QERApp_GetEntityKeyValList;
  1479. pTable->m_pfnAllocateEpair = &QERApp_AllocateEpair;
  1480. pTable->m_pfnSetEntityKeyValList = &QERApp_SetEntityKeyValList;
  1481. pTable->m_pfnAllocateEntityBrushHandles = &QERApp_AllocateEntityBrushHandles;
  1482. pTable->m_pfnReleaseEntityBrushHandles = &QERApp_ReleaseEntityBrushHandles;
  1483. pTable->m_pfnGetEntityBrushHandle = &QERApp_GetEntityBrushHandle;
  1484. pTable->m_pfnCreateEntityHandle = &QERApp_CreateEntityHandle;
  1485. pTable->m_pfnCommitBrushHandleToEntity = &QERApp_CommitBrushHandleToEntity;
  1486. pTable->m_pfnCommitEntityHandleToMap = &QERApp_CommitEntityHandleToMap;
  1487. pTable->m_pfnSetScreenUpdate = &QERApp_SetScreenUpdate;
  1488. pTable->m_pfnSysUpdateWindows = &Sys_UpdateWindows;
  1489. pTable->m_pfnBuildBrush2 = &QERApp_BuildBrush2;
  1490. pTable->m_pfnReadProjectKey = &QERApp_ReadProjectKey;
  1491. pTable->m_pfnScanFileForEClass = &QERApp_ScanFileForEClass;
  1492. pTable->m_pfnRequestInterface = &QERApp_RequestInterface;
  1493. pTable->m_pfnErrorMsg = &QERApp_ErrorMsg;
  1494. pTable->m_pfnLoadFile = &QERApp_LoadFile;
  1495. pTable->m_pfnExpandReletivePath = &QERApp_ExpandReletivePath;
  1496. pTable->m_pfnQE_ConvertDOSToUnixName = &QE_ConvertDOSToUnixName;
  1497. pTable->m_pfnHasShader = &QERApp_HasShader;
  1498. pTable->m_pfnTexture_LoadSkin = &Texture_LoadSkin;
  1499. pTable->m_pfnRadiantFree = &QERApp_RadiantFree;
  1500. pTable->m_pfnGetGamePath = &QERApp_GetGamePath;
  1501. pTable->m_pfnGetQERPath = &QERApp_GetQERPath;
  1502. // patches
  1503. pTable->m_pfnAllocateActivePatchHandles = &QERApp_AllocateActivePatchHandles;
  1504. pTable->m_pfnAllocateSelectedPatchHandles = &QERApp_AllocateSelectedPatchHandles;
  1505. pTable->m_pfnReleasePatchHandles = &QERApp_ReleasePatchHandles;
  1506. pTable->m_pfnGetPatchData = &QERApp_GetPatchData;
  1507. pTable->m_pfnDeletePatch = &QERApp_DeletePatch;
  1508. pTable->m_pfnCreatePatchHandle = &QERApp_CreatePatchHandle;
  1509. pTable->m_pfnCommitPatchHandleToMap = &QERApp_CommitPatchHandleToMap;
  1510. }
  1511. return true;
  1512. }
  1513. else
  1514. {
  1515. Sys_Printf("Unable to load %s because the function tables are not the same size\n", pPlug->getVersionStr());
  1516. }
  1517. return false;
  1518. }
  1519. CPlugIn * CPlugInManager::PluginForModule(HMODULE hPlug)
  1520. {
  1521. int i;
  1522. for( i=0; i!=m_PlugIns.GetSize(); i++ )
  1523. {
  1524. if ( reinterpret_cast<CPlugIn *>(m_PlugIns[i])->GetDLLModule() == hPlug )
  1525. return reinterpret_cast<CPlugIn *>(m_PlugIns[i]);
  1526. }
  1527. return NULL;
  1528. }